source: rtems/doc/user/region.t @ 106942b

Last change on this file since 106942b was 6449498, checked in by Joel Sherrill <joel.sherrill@…>, on 01/17/02 at 21:47:47

2001-01-17 Joel Sherrill <joel@…>

  • SUPPORT, LICENSE: New files.
  • Numerous files touched as part of merging the 4.5 branch onto the mainline development trunk and ensuring that the script that cuts snapshots and releases works on the documentation.
  • Property mode set to 100644
File size: 20.1 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2002.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@chapter Region Manager
10
11@cindex regions
12
13@section Introduction
14
15The region manager provides facilities to dynamically
16allocate memory in variable sized units.  The directives
17provided by the region manager are:
18
19@itemize @bullet
20@item @code{@value{DIRPREFIX}region_create} - Create a region
21@item @code{@value{DIRPREFIX}region_ident} - Get ID of a region
22@item @code{@value{DIRPREFIX}region_delete} - Delete a region
23@item @code{@value{DIRPREFIX}region_extend} - Add memory to a region
24@item @code{@value{DIRPREFIX}region_get_segment} - Get segment from a region
25@item @code{@value{DIRPREFIX}region_return_segment} - Return segment to a region
26@item @code{@value{DIRPREFIX}region_get_segment_size} - Obtain size of a segment
27@end itemize
28
29@section Background
30
31@subsection Region Manager Definitions
32
33@cindex region, definition
34@cindex segment, definition
35
36A region makes up a physically contiguous memory
37space with user-defined boundaries from which variable-sized
38segments are dynamically allocated and deallocated.  A segment
39is a variable size section of memory which is allocated in
40multiples of a user-defined page size.  This page size is
41required to be a multiple of four greater than or equal to four.
42For example, if a request for a 350-byte segment is made in a
43region with 256-byte pages, then a 512-byte segment is allocated.
44
45Regions are organized as doubly linked chains of
46variable sized memory blocks.  Memory requests are allocated
47using a first-fit algorithm.  If available, the requester
48receives the number of bytes requested (rounded up to the next
49page size).  RTEMS requires some overhead from the region's
50memory for each segment that is allocated.  Therefore, an
51application should only modify the memory of a segment that has
52been obtained from the region.  The application should NOT
53modify the memory outside of any obtained segments and within
54the region's boundaries while the region is currently active in
55the system.
56
57Upon return to the region, the free block is
58coalesced with its neighbors (if free) on both sides to produce
59the largest possible unused block.
60
61@subsection Building an Attribute Set
62
63@cindex region attribute set, building
64
65In general, an attribute set is built by a bitwise OR
66of the desired attribute components.  The set of valid region
67attributes is provided in the following table:
68
69@itemize @bullet
70@item @code{@value{RPREFIX}FIFO} - tasks wait by FIFO (default)
71@item @code{@value{RPREFIX}PRIORITY} - tasks wait by priority
72@end itemize
73
74Attribute values are specifically designed to be
75mutually exclusive, therefore bitwise OR and addition operations
76are equivalent as long as each attribute appears exactly once in
77the component list.  An attribute listed as a default is not
78required to appear in the attribute list, although it is a good
79programming practice to specify default attributes.  If all
80defaults are desired, the attribute
81@code{@value{RPREFIX}DEFAULT_ATTRIBUTES} should be
82specified on this call.
83
84This example demonstrates the attribute_set parameter
85needed to create a region with the task priority waiting queue
86discipline.  The attribute_set parameter to the
87@code{@value{DIRPREFIX}region_create}
88directive should be @code{@value{RPREFIX}PRIORITY}.
89
90@subsection Building an Option Set
91
92In general, an option is built by a bitwise OR of the
93desired option components.  The set of valid options for the
94@code{@value{DIRPREFIX}region_get_segment} directive are
95listed in the following table:
96
97@itemize @bullet
98@item @code{@value{RPREFIX}WAIT} - task will wait for semaphore (default)
99@item @code{@value{RPREFIX}NO_WAIT} - task should not wait
100@end itemize
101
102Option values are specifically designed to be
103mutually exclusive, therefore bitwise OR and addition operations
104are equivalent as long as each option appears exactly once in
105the component list.  An option listed as a default is not
106required to appear in the option list, although it is a good
107programming practice to specify default options.  If all
108defaults are desired, the option
109@code{@value{RPREFIX}DEFAULT_OPTIONS} should be
110specified on this call.
111
112This example demonstrates the option parameter needed
113to poll for a segment.  The option parameter passed to the
114@code{@value{DIRPREFIX}region_get_segment} directive should
115be @code{@value{RPREFIX}NO_WAIT}.
116
117@section Operations
118
119@subsection Creating a Region
120
121The @code{@value{DIRPREFIX}region_create} directive creates a region with the
122user-defined name.  The user may select FIFO or task priority as
123the method for placing waiting tasks in the task wait queue.
124RTEMS allocates a Region Control Block (RNCB) from the RNCB free
125list to maintain the newly created region.  RTEMS also generates
126a unique region ID which is returned to the calling task.
127
128It is not possible to calculate the exact number of
129bytes available to the user since RTEMS requires overhead for
130each segment allocated.  For example, a region with one segment
131that is the size of the entire region has more available bytes
132than a region with two segments that collectively are the size
133of the entire region.  This is because the region with one
134segment requires only the overhead for one segment, while the
135other region requires the overhead for two segments.
136
137Due to automatic coalescing, the number of segments
138in the region dynamically changes.  Therefore, the total
139overhead required by RTEMS dynamically changes.
140
141@subsection Obtaining Region IDs
142
143When a region is created, RTEMS generates a unique
144region ID and assigns it to the created region until it is
145deleted.  The region ID may be obtained by either of two
146methods.  First, as the result of an invocation of the
147@code{@value{DIRPREFIX}region_create} directive,
148the region ID is stored in a user
149provided location.  Second, the region ID may be obtained later
150using the @code{@value{DIRPREFIX}region_ident} directive. 
151The region ID is used by other region manager directives to
152access this region.
153
154@subsection Adding Memory to a Region
155
156The @code{@value{DIRPREFIX}region_extend} directive may be used to add memory
157to an existing region.  The caller specifies the size in bytes
158and starting address of the memory being added.
159
160NOTE:  Please see the release notes or RTEMS source
161code for information regarding restrictions on the location of
162the memory being added in relation to memory already in the
163region.
164
165@subsection Acquiring a Segment
166
167The @code{@value{DIRPREFIX}region_get_segment} directive attempts to acquire
168a segment from a specified region.  If the region has enough
169available free memory, then a segment is returned successfully
170to the caller.  When the segment cannot be allocated, one of the
171following situations applies:
172
173@itemize @bullet
174@item By default, the calling task will wait forever to acquire the segment.
175
176@item Specifying the @code{@value{RPREFIX}NO_WAIT} option forces
177an immediate return with an error status code.
178
179@item Specifying a timeout limits the interval the task will
180wait before returning with an error status code.
181@end itemize
182
183If the task waits for the segment, then it is placed
184in the region's task wait queue in either FIFO or task priority
185order.  All tasks waiting on a region are returned an error when
186the message queue is deleted.
187
188@subsection Releasing a Segment
189
190When a segment is returned to a region by the
191@code{@value{DIRPREFIX}region_return_segment} directive, it is merged with its
192unallocated neighbors to form the largest possible segment.  The
193first task on the wait queue is examined to determine if its
194segment request can now be satisfied.  If so, it is given a
195segment and unblocked.  This process is repeated until the first
196task's segment request cannot be satisfied.
197
198@subsection Obtaining the Size of a Segment
199
200The @code{@value{DIRPREFIX}region_get_segment_size} directive returns the
201size in bytes of the specified segment.  The size returned
202includes any "extra" memory included in the segment because of
203rounding up to a page size boundary.
204
205@subsection Deleting a Region
206
207A region can be removed from the system and returned
208to RTEMS with the @code{@value{DIRPREFIX}region_delete}
209directive.  When a region is
210deleted, its control block is returned to the RNCB free list.  A
211region with segments still allocated is not allowed to be
212deleted.  Any task attempting to do so will be returned an
213error.  As a result of this directive, all tasks blocked waiting
214to obtain a segment from the region will be readied and returned
215a status code which indicates that the region was deleted.
216
217@section Directives
218
219This section details the region manager's directives.
220A subsection is dedicated to each of this manager's directives
221and describes the calling sequence, related constants, usage,
222and status codes.
223
224@c
225@c
226@c
227@page
228@subsection REGION_CREATE - Create a region
229
230@cindex create a region
231
232@subheading CALLING SEQUENCE:
233
234@ifset is-C
235@findex rtems_region_create
236@example
237rtems_status_code rtems_region_create(
238  rtems_name        name,
239  void             *starting_address,
240  rtems_unsigned32  length,
241  rtems_unsigned32  page_size,
242  rtems_attribute   attribute_set,
243  rtems_id         *id
244);
245@end example
246@end ifset
247
248@ifset is-Ada
249@example
250procedure Region_Create (
251   Name             : in     RTEMS.Name;
252   Starting_Address : in     RTEMS.Address;
253   Length           : in     RTEMS.Unsigned32;
254   Page_Size        : in     RTEMS.Unsigned32;
255   Attribute_Set    : in     RTEMS.Attribute;
256   ID               :    out RTEMS.ID;
257   Result           :    out RTEMS.Status_Codes
258);
259@end example
260@end ifset
261
262@subheading DIRECTIVE STATUS CODES:
263
264@code{@value{RPREFIX}SUCCESSFUL} - region created successfully@*
265@code{@value{RPREFIX}INVALID_NAME} - invalid task name@*
266@code{@value{RPREFIX}INVALID_ADDRESS} - address not on four byte boundary@*
267@code{@value{RPREFIX}TOO_MANY} - too many regions created@*
268@code{@value{RPREFIX}INVALID_SIZE} - invalid page size
269
270@subheading DESCRIPTION:
271
272This directive creates a region from a physically
273contiguous memory space which starts at starting_address and is
274length bytes long.  Segments allocated from the region will be a
275multiple of page_size bytes in length.  The assigned region id
276is returned in id.  This region id is used as an argument to
277other region related directives to access the region.
278
279For control and maintenance of the region, RTEMS
280allocates and initializes an RNCB from the RNCB free pool.  Thus
281memory from the region is not used to store the RNCB.  However,
282some overhead within the region is required by RTEMS each time a
283segment is constructed in the region.
284
285Specifying @code{@value{RPREFIX}PRIORITY} in attribute_set causes tasks
286waiting for a segment to be serviced according to task priority.
287Specifying @code{@value{RPREFIX}FIFO} in attribute_set or selecting
288@code{@value{RPREFIX}DEFAULT_ATTRIBUTES} will cause waiting tasks to
289be serviced in First In-First Out order.
290
291The starting_address parameter must be aligned on a
292four byte boundary.  The page_size parameter must be a multiple
293of four greater than or equal to four.
294
295@subheading NOTES:
296
297This directive will not cause the calling task to be
298preempted.
299
300The following region attribute constants are defined
301by RTEMS:
302
303@itemize @bullet
304@item @code{@value{RPREFIX}FIFO} - tasks wait by FIFO (default)
305@item @code{@value{RPREFIX}PRIORITY} - tasks wait by priority
306@end itemize
307
308@c
309@c
310@c
311@page
312@subsection REGION_IDENT - Get ID of a region
313
314@cindex get ID of a region
315@cindex obtain ID of a region
316
317@subheading CALLING SEQUENCE:
318
319@ifset is-C
320@findex rtems_region_ident
321@example
322rtems_status_code rtems_region_ident(
323  rtems_name  name,
324  rtems_id   *id
325);
326@end example
327@end ifset
328
329@ifset is-Ada
330@example
331procedure Region_Ident (
332   Name   : in     RTEMS.Name;
333   ID     :    out RTEMS.ID;
334   Result :    out RTEMS.Status_Codes
335);
336@end example
337@end ifset
338
339@subheading DIRECTIVE STATUS CODES:
340
341@code{@value{RPREFIX}SUCCESSFUL} - region identified successfully@*
342@code{@value{RPREFIX}INVALID_NAME} - region name not found
343
344@subheading DESCRIPTION:
345
346This directive obtains the region id associated with
347the region name to be acquired.  If the region name is not
348unique, then the region id will match one of the regions with
349that name.  However, this region id is not guaranteed to
350correspond to the desired region.  The region id is used to
351access this region in other region manager directives.
352
353@subheading NOTES:
354
355This directive will not cause the running task to be preempted.
356
357@c
358@c
359@c
360@page
361@subsection REGION_DELETE - Delete a region
362
363@cindex delete a region
364
365@subheading CALLING SEQUENCE:
366
367@ifset is-C
368@findex rtems_region_delete
369@example
370rtems_status_code rtems_region_delete(
371  rtems_id id
372);
373@end example
374@end ifset
375
376@ifset is-Ada
377@example
378procedure Region_Delete (
379   ID     : in     RTEMS.ID;
380   Result :    out RTEMS.Status_Codes
381);
382@end example
383@end ifset
384
385@subheading DIRECTIVE STATUS CODES:
386
387@code{@value{RPREFIX}SUCCESSFUL} - region deleted successfully@*
388@code{@value{RPREFIX}INVALID_ID} - invalid region id@*
389@code{@value{RPREFIX}RESOURCE_IN_USE} - segments still in use
390
391@subheading DESCRIPTION:
392
393This directive deletes the region specified by id.
394The region cannot be deleted if any of its segments are still
395allocated.  The RNCB for the deleted region is reclaimed by
396RTEMS.
397
398@subheading NOTES:
399
400This directive will not cause the calling task to be preempted.
401
402The calling task does not have to be the task that
403created the region.  Any local task that knows the region id can
404delete the region.
405
406@c
407@c
408@c
409@page
410@subsection REGION_EXTEND - Add memory to a region
411
412@cindex add memory to a region
413@cindex region, add memory
414
415@subheading CALLING SEQUENCE:
416
417@ifset is-C
418@findex rtems_region_extend
419@example
420rtems_status_code rtems_region_extend(
421  rtems_id            id,
422  void               *starting_address,
423  rtems_unsigned32    length
424);
425@end example
426@end ifset
427
428@ifset is-Ada
429@example
430procedure Region_Extend (
431   ID               : in     RTEMS.ID;
432   Starting_Address : in     RTEMS.Address;
433   Length           : in     RTEMS.Unsigned32;
434   Result           :    out RTEMS.Status_Codes
435);
436@end example
437@end ifset
438
439@subheading DIRECTIVE STATUS CODES:
440
441@code{@value{RPREFIX}SUCCESSFUL} - region extended successfully@*
442@code{@value{RPREFIX}INVALID_ID} - invalid region id@*
443@code{@value{RPREFIX}INVALID_ADDRESS} - invalid address of area to add
444
445@subheading DESCRIPTION:
446
447This directive adds the memory which starts at
448starting_address for length bytes to the region specified by id.
449
450@subheading NOTES:
451
452This directive will not cause the calling task to be preempted.
453
454The calling task does not have to be the task that
455created the region.  Any local task that knows the region id can
456extend the region.
457
458@c
459@c
460@c
461@page
462@subsection REGION_GET_SEGMENT - Get segment from a region
463
464@cindex get segment from region
465
466@subheading CALLING SEQUENCE:
467
468@ifset is-C
469@findex rtems_region_get_segment
470@example
471rtems_status_code rtems_region_get_segment(
472  rtems_id            id,
473  rtems_unsigned32    size,
474  rtems_option        option_set,
475  rtems_interval      timeout,
476  void              **segment
477);
478@end example
479@end ifset
480
481@ifset is-Ada
482@example
483procedure Region_Get_Segment (
484   ID         : in     RTEMS.ID;
485   Size       : in     RTEMS.Unsigned32;
486   Option_Set : in     RTEMS.Option;
487   Timeout    : in     RTEMS.Interval;
488   Segment    :    out RTEMS.Address;
489   Result     :    out RTEMS.Status_Codes
490);
491@end example
492@end ifset
493
494@subheading DIRECTIVE STATUS CODES:
495
496@code{@value{RPREFIX}SUCCESSFUL} - segment obtained successfully@*
497@code{@value{RPREFIX}INVALID_ID} - invalid region id@*
498@code{@value{RPREFIX}INVALID_SIZE} - request is for zero bytes or exceeds
499the size of maximum segment which is possible for this region@*
500@code{@value{RPREFIX}UNSATISFIED} - segment of requested size not available@*
501@code{@value{RPREFIX}TIMEOUT} - timed out waiting for segment@*
502@code{@value{RPREFIX}OBJECT_WAS_DELETED} - semaphore deleted while waiting
503
504@subheading DESCRIPTION:
505
506This directive obtains a variable size segment from
507the region specified by id.  The address of the allocated
508segment is returned in segment.  The @code{@value{RPREFIX}WAIT}
509and @code{@value{RPREFIX}NO_WAIT} components
510of the options parameter are used to specify whether the calling
511tasks wish to wait for a segment to become available or return
512immediately if no segment is available.  For either option, if a
513sufficiently sized segment is available, then the segment is
514successfully acquired by returning immediately with  the
515@code{@value{RPREFIX}SUCCESSFUL} status code.
516
517If the calling task chooses to return immediately and
518a segment large enough is not available, then an error code
519indicating this fact is returned.  If the calling task chooses
520to wait for the segment and a segment large enough is not
521available, then the calling task is placed on the region's
522segment wait queue and blocked.  If the region was created with
523the @code{@value{RPREFIX}PRIORITY} option, then the calling
524task is inserted into the
525wait queue according to its priority.  However, if the region
526was created with the @code{@value{RPREFIX}FIFO} option, then the calling
527task is placed at the rear of the wait queue.
528
529The timeout parameter specifies the maximum interval
530that a task is willing to wait to obtain a segment.  If timeout
531is set to @code{@value{RPREFIX}NO_TIMEOUT}, then the
532calling task will wait forever.
533
534@subheading NOTES:
535
536The actual length of the allocated segment may be
537larger than the requested size because a segment size is always
538a multiple of the region's page size.
539
540The following segment acquisition option constants
541are defined by RTEMS:
542
543@itemize @bullet
544@item @code{@value{RPREFIX}WAIT} - task will wait for semaphore (default)
545@item @code{@value{RPREFIX}NO_WAIT} - task should not wait
546@end itemize
547
548A clock tick is required to support the timeout functionality of
549this directive.
550
551@c
552@c
553@c
554@page
555@subsection REGION_RETURN_SEGMENT - Return segment to a region
556
557@cindex return segment to region
558
559@subheading CALLING SEQUENCE:
560
561@ifset is-C
562@findex rtems_region_return_segment
563@example
564rtems_status_code rtems_region_return_segment(
565  rtems_id  id,
566  void     *segment
567);
568@end example
569@end ifset
570
571@ifset is-Ada
572@example
573procedure Region_Return_Segment (
574   ID      : in     RTEMS.ID;
575   Segment : in     RTEMS.Address;
576   Result  :    out RTEMS.Status_Codes
577);
578@end example
579@end ifset
580
581@subheading DIRECTIVE STATUS CODES:
582
583@code{@value{RPREFIX}SUCCESSFUL} - segment returned successfully@*
584@code{@value{RPREFIX}INVALID_ID} - invalid region id@*
585@code{@value{RPREFIX}INVALID_ADDRESS} - segment address not in region
586
587@subheading DESCRIPTION:
588
589This directive returns the segment specified by
590segment to the region specified by id.  The returned segment is
591merged with its neighbors to form the largest possible segment.
592The first task on the wait queue is examined to determine if its
593segment request can now be satisfied.  If so, it is given a
594segment and unblocked.  This process is repeated until the first
595task's segment request cannot be satisfied.
596
597@subheading NOTES:
598
599This directive will cause the calling task to be
600preempted if one or more local tasks are waiting for a segment
601and the following conditions exist:
602
603@itemize @bullet
604@item a waiting task has a higher priority than the calling task
605
606@item the size of the segment required by the waiting task
607is less than or equal to the size of the segment returned.
608@end itemize
609
610@c
611@c
612@c
613@page
614@subsection REGION_GET_SEGMENT_SIZE - Obtain size of a segment
615
616@cindex get size of segment
617
618@subheading CALLING SEQUENCE:
619
620@ifset is-C
621@findex rtems_region_get_segment_size
622@example
623rtems_status_code rtems_region_get_segment_size(
624  rtems_id            id,
625  void               *segment,
626  rtems_unsigned32   *size
627);
628@end example
629@end ifset
630
631@ifset is-Ada
632@example
633procedure Region_Get_Segment_Size (
634   ID         : in     RTEMS.ID;
635   Segment    : in     RTEMS.Address;
636   Size       :    out RTEMS.Unsigned32;
637   Result     :    out RTEMS.Status_Codes
638);
639@end example
640@end ifset
641
642@subheading DIRECTIVE STATUS CODES:
643
644@code{@value{RPREFIX}SUCCESSFUL} - segment obtained successfully@*
645@code{@value{RPREFIX}INVALID_ID} - invalid region id@*
646@code{@value{RPREFIX}INVALID_ADDRESS} - segment address not in region
647
648@subheading DESCRIPTION:
649
650This directive obtains the size in bytes of the specified segment.
651
652@subheading NOTES:
653
654The actual length of the allocated segment may be
655larger than the requested size because a segment size is always
656a multiple of the region's page size.
657
Note: See TracBrowser for help on using the repository browser.