OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [doc/] [user/] [region.t] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
@c
2
@c  COPYRIGHT (c) 1988-2002.
3
@c  On-Line Applications Research Corporation (OAR).
4
@c  All rights reserved.
5
@c
6
@c  region.t,v 1.14 2002/01/17 21:47:47 joel Exp
7
@c
8
 
9
@chapter Region Manager
10
 
11
@cindex regions
12
 
13
@section Introduction
14
 
15
The region manager provides facilities to dynamically
16
allocate memory in variable sized units.  The directives
17
provided 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
 
36
A region makes up a physically contiguous memory
37
space with user-defined boundaries from which variable-sized
38
segments are dynamically allocated and deallocated.  A segment
39
is a variable size section of memory which is allocated in
40
multiples of a user-defined page size.  This page size is
41
required to be a multiple of four greater than or equal to four.
42
For example, if a request for a 350-byte segment is made in a
43
region with 256-byte pages, then a 512-byte segment is allocated.
44
 
45
Regions are organized as doubly linked chains of
46
variable sized memory blocks.  Memory requests are allocated
47
using a first-fit algorithm.  If available, the requester
48
receives the number of bytes requested (rounded up to the next
49
page size).  RTEMS requires some overhead from the region's
50
memory for each segment that is allocated.  Therefore, an
51
application should only modify the memory of a segment that has
52
been obtained from the region.  The application should NOT
53
modify the memory outside of any obtained segments and within
54
the region's boundaries while the region is currently active in
55
the system.
56
 
57
Upon return to the region, the free block is
58
coalesced with its neighbors (if free) on both sides to produce
59
the largest possible unused block.
60
 
61
@subsection Building an Attribute Set
62
 
63
@cindex region attribute set, building
64
 
65
In general, an attribute set is built by a bitwise OR
66
of the desired attribute components.  The set of valid region
67
attributes 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
 
74
Attribute values are specifically designed to be
75
mutually exclusive, therefore bitwise OR and addition operations
76
are equivalent as long as each attribute appears exactly once in
77
the component list.  An attribute listed as a default is not
78
required to appear in the attribute list, although it is a good
79
programming practice to specify default attributes.  If all
80
defaults are desired, the attribute
81
@code{@value{RPREFIX}DEFAULT_ATTRIBUTES} should be
82
specified on this call.
83
 
84
This example demonstrates the attribute_set parameter
85
needed to create a region with the task priority waiting queue
86
discipline.  The attribute_set parameter to the
87
@code{@value{DIRPREFIX}region_create}
88
directive should be @code{@value{RPREFIX}PRIORITY}.
89
 
90
@subsection Building an Option Set
91
 
92
In general, an option is built by a bitwise OR of the
93
desired option components.  The set of valid options for the
94
@code{@value{DIRPREFIX}region_get_segment} directive are
95
listed 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
 
102
Option values are specifically designed to be
103
mutually exclusive, therefore bitwise OR and addition operations
104
are equivalent as long as each option appears exactly once in
105
the component list.  An option listed as a default is not
106
required to appear in the option list, although it is a good
107
programming practice to specify default options.  If all
108
defaults are desired, the option
109
@code{@value{RPREFIX}DEFAULT_OPTIONS} should be
110
specified on this call.
111
 
112
This example demonstrates the option parameter needed
113
to poll for a segment.  The option parameter passed to the
114
@code{@value{DIRPREFIX}region_get_segment} directive should
115
be @code{@value{RPREFIX}NO_WAIT}.
116
 
117
@section Operations
118
 
119
@subsection Creating a Region
120
 
121
The @code{@value{DIRPREFIX}region_create} directive creates a region with the
122
user-defined name.  The user may select FIFO or task priority as
123
the method for placing waiting tasks in the task wait queue.
124
RTEMS allocates a Region Control Block (RNCB) from the RNCB free
125
list to maintain the newly created region.  RTEMS also generates
126
a unique region ID which is returned to the calling task.
127
 
128
It is not possible to calculate the exact number of
129
bytes available to the user since RTEMS requires overhead for
130
each segment allocated.  For example, a region with one segment
131
that is the size of the entire region has more available bytes
132
than a region with two segments that collectively are the size
133
of the entire region.  This is because the region with one
134
segment requires only the overhead for one segment, while the
135
other region requires the overhead for two segments.
136
 
137
Due to automatic coalescing, the number of segments
138
in the region dynamically changes.  Therefore, the total
139
overhead required by RTEMS dynamically changes.
140
 
141
@subsection Obtaining Region IDs
142
 
143
When a region is created, RTEMS generates a unique
144
region ID and assigns it to the created region until it is
145
deleted.  The region ID may be obtained by either of two
146
methods.  First, as the result of an invocation of the
147
@code{@value{DIRPREFIX}region_create} directive,
148
the region ID is stored in a user
149
provided location.  Second, the region ID may be obtained later
150
using the @code{@value{DIRPREFIX}region_ident} directive.
151
The region ID is used by other region manager directives to
152
access this region.
153
 
154
@subsection Adding Memory to a Region
155
 
156
The @code{@value{DIRPREFIX}region_extend} directive may be used to add memory
157
to an existing region.  The caller specifies the size in bytes
158
and starting address of the memory being added.
159
 
160
NOTE:  Please see the release notes or RTEMS source
161
code for information regarding restrictions on the location of
162
the memory being added in relation to memory already in the
163
region.
164
 
165
@subsection Acquiring a Segment
166
 
167
The @code{@value{DIRPREFIX}region_get_segment} directive attempts to acquire
168
a segment from a specified region.  If the region has enough
169
available free memory, then a segment is returned successfully
170
to the caller.  When the segment cannot be allocated, one of the
171
following 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
177
an immediate return with an error status code.
178
 
179
@item Specifying a timeout limits the interval the task will
180
wait before returning with an error status code.
181
@end itemize
182
 
183
If the task waits for the segment, then it is placed
184
in the region's task wait queue in either FIFO or task priority
185
order.  All tasks waiting on a region are returned an error when
186
the message queue is deleted.
187
 
188
@subsection Releasing a Segment
189
 
190
When a segment is returned to a region by the
191
@code{@value{DIRPREFIX}region_return_segment} directive, it is merged with its
192
unallocated neighbors to form the largest possible segment.  The
193
first task on the wait queue is examined to determine if its
194
segment request can now be satisfied.  If so, it is given a
195
segment and unblocked.  This process is repeated until the first
196
task's segment request cannot be satisfied.
197
 
198
@subsection Obtaining the Size of a Segment
199
 
200
The @code{@value{DIRPREFIX}region_get_segment_size} directive returns the
201
size in bytes of the specified segment.  The size returned
202
includes any "extra" memory included in the segment because of
203
rounding up to a page size boundary.
204
 
205
@subsection Deleting a Region
206
 
207
A region can be removed from the system and returned
208
to RTEMS with the @code{@value{DIRPREFIX}region_delete}
209
directive.  When a region is
210
deleted, its control block is returned to the RNCB free list.  A
211
region with segments still allocated is not allowed to be
212
deleted.  Any task attempting to do so will be returned an
213
error.  As a result of this directive, all tasks blocked waiting
214
to obtain a segment from the region will be readied and returned
215
a status code which indicates that the region was deleted.
216
 
217
@section Directives
218
 
219
This section details the region manager's directives.
220
A subsection is dedicated to each of this manager's directives
221
and describes the calling sequence, related constants, usage,
222
and 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
237
rtems_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
250
procedure 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
 
272
This directive creates a region from a physically
273
contiguous memory space which starts at starting_address and is
274
length bytes long.  Segments allocated from the region will be a
275
multiple of page_size bytes in length.  The assigned region id
276
is returned in id.  This region id is used as an argument to
277
other region related directives to access the region.
278
 
279
For control and maintenance of the region, RTEMS
280
allocates and initializes an RNCB from the RNCB free pool.  Thus
281
memory from the region is not used to store the RNCB.  However,
282
some overhead within the region is required by RTEMS each time a
283
segment is constructed in the region.
284
 
285
Specifying @code{@value{RPREFIX}PRIORITY} in attribute_set causes tasks
286
waiting for a segment to be serviced according to task priority.
287
Specifying @code{@value{RPREFIX}FIFO} in attribute_set or selecting
288
@code{@value{RPREFIX}DEFAULT_ATTRIBUTES} will cause waiting tasks to
289
be serviced in First In-First Out order.
290
 
291
The starting_address parameter must be aligned on a
292
four byte boundary.  The page_size parameter must be a multiple
293
of four greater than or equal to four.
294
 
295
@subheading NOTES:
296
 
297
This directive will not cause the calling task to be
298
preempted.
299
 
300
The following region attribute constants are defined
301
by 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
322
rtems_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
331
procedure 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
 
346
This directive obtains the region id associated with
347
the region name to be acquired.  If the region name is not
348
unique, then the region id will match one of the regions with
349
that name.  However, this region id is not guaranteed to
350
correspond to the desired region.  The region id is used to
351
access this region in other region manager directives.
352
 
353
@subheading NOTES:
354
 
355
This 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
370
rtems_status_code rtems_region_delete(
371
  rtems_id id
372
);
373
@end example
374
@end ifset
375
 
376
@ifset is-Ada
377
@example
378
procedure 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
 
393
This directive deletes the region specified by id.
394
The region cannot be deleted if any of its segments are still
395
allocated.  The RNCB for the deleted region is reclaimed by
396
RTEMS.
397
 
398
@subheading NOTES:
399
 
400
This directive will not cause the calling task to be preempted.
401
 
402
The calling task does not have to be the task that
403
created the region.  Any local task that knows the region id can
404
delete 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
420
rtems_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
430
procedure 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
 
447
This directive adds the memory which starts at
448
starting_address for length bytes to the region specified by id.
449
 
450
@subheading NOTES:
451
 
452
This directive will not cause the calling task to be preempted.
453
 
454
The calling task does not have to be the task that
455
created the region.  Any local task that knows the region id can
456
extend 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
471
rtems_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
483
procedure 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
499
the 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
 
506
This directive obtains a variable size segment from
507
the region specified by id.  The address of the allocated
508
segment is returned in segment.  The @code{@value{RPREFIX}WAIT}
509
and @code{@value{RPREFIX}NO_WAIT} components
510
of the options parameter are used to specify whether the calling
511
tasks wish to wait for a segment to become available or return
512
immediately if no segment is available.  For either option, if a
513
sufficiently sized segment is available, then the segment is
514
successfully acquired by returning immediately with  the
515
@code{@value{RPREFIX}SUCCESSFUL} status code.
516
 
517
If the calling task chooses to return immediately and
518
a segment large enough is not available, then an error code
519
indicating this fact is returned.  If the calling task chooses
520
to wait for the segment and a segment large enough is not
521
available, then the calling task is placed on the region's
522
segment wait queue and blocked.  If the region was created with
523
the @code{@value{RPREFIX}PRIORITY} option, then the calling
524
task is inserted into the
525
wait queue according to its priority.  However, if the region
526
was created with the @code{@value{RPREFIX}FIFO} option, then the calling
527
task is placed at the rear of the wait queue.
528
 
529
The timeout parameter specifies the maximum interval
530
that a task is willing to wait to obtain a segment.  If timeout
531
is set to @code{@value{RPREFIX}NO_TIMEOUT}, then the
532
calling task will wait forever.
533
 
534
@subheading NOTES:
535
 
536
The actual length of the allocated segment may be
537
larger than the requested size because a segment size is always
538
a multiple of the region's page size.
539
 
540
The following segment acquisition option constants
541
are 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
 
548
A clock tick is required to support the timeout functionality of
549
this 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
564
rtems_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
573
procedure 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
 
589
This directive returns the segment specified by
590
segment to the region specified by id.  The returned segment is
591
merged with its neighbors to form the largest possible segment.
592
The first task on the wait queue is examined to determine if its
593
segment request can now be satisfied.  If so, it is given a
594
segment and unblocked.  This process is repeated until the first
595
task's segment request cannot be satisfied.
596
 
597
@subheading NOTES:
598
 
599
This directive will cause the calling task to be
600
preempted if one or more local tasks are waiting for a segment
601
and 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
607
is 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
623
rtems_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
633
procedure 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
 
650
This directive obtains the size in bytes of the specified segment.
651
 
652
@subheading NOTES:
653
 
654
The actual length of the allocated segment may be
655
larger than the requested size because a segment size is always
656
a multiple of the region's page size.
657
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.