source: rtems-docs/c_user/partition_manager.rst @ 25d55d4

4.115
Last change on this file since 25d55d4 was 25d55d4, checked in by Chris Johns <chrisj@…>, on 02/18/16 at 04:41:28

Change code to code-block.

  • Property mode set to 100644
File size: 12.8 KB
Line 
1.. COMMENT: COPYRIGHT (c) 1988-2008.
2.. COMMENT: On-Line Applications Research Corporation (OAR).
3.. COMMENT: All rights reserved.
4
5Partition Manager
6#################
7
8.. index:: partitions
9
10Introduction
11============
12
13The partition manager provides facilities to dynamically allocate memory in
14fixed-size units.  The directives provided by the partition manager are:
15
16- rtems_partition_create_ - Create a partition
17
18- rtems_partition_ident_ - Get ID of a partition
19
20- rtems_partition_delete_ - Delete a partition
21
22- rtems_partition_get_buffer_ - Get buffer from a partition
23
24- rtems_partition_return_buffer_ - Return buffer to a partition
25
26Background
27==========
28
29Partition Manager Definitions
30-----------------------------
31.. index:: partition, definition
32
33A partition is a physically contiguous memory area divided into fixed-size
34buffers that can be dynamically allocated and deallocated.
35
36.. index:: buffers, definition
37
38Partitions are managed and maintained as a list of buffers.  Buffers are
39obtained from the front of the partition's free buffer chain and returned to
40the rear of the same chain.  When a buffer is on the free buffer chain, RTEMS
41uses two pointers of memory from each buffer as the free buffer chain.  When a
42buffer is allocated, the entire buffer is available for application use.
43Therefore, modifying memory that is outside of an allocated buffer could
44destroy the free buffer chain or the contents of an adjacent allocated buffer.
45
46Building a Partition Attribute Set
47----------------------------------
48.. index:: partition attribute set, building
49
50In general, an attribute set is built by a bitwise OR of the desired attribute
51components.  The set of valid partition attributes is provided in the following
52table:
53
54.. list-table::
55 :class: rtems-table
56
57 * - ``RTEMS_LOCAL``
58   - local partition (default)
59 * - ``RTEMS_GLOBAL``
60   - global partition
61
62Attribute values are specifically designed to be mutually exclusive, therefore
63bitwise OR and addition operations are equivalent as long as each attribute
64appears exactly once in the component list.  An attribute listed as a default
65is not required to appear in the attribute list, although it is a good
66programming practice to specify default attributes.  If all defaults are
67desired, the attribute ``RTEMS_DEFAULT_ATTRIBUTES`` should be specified on this
68call.  The attribute_set parameter should be ``RTEMS_GLOBAL`` to indicate that
69the partition is to be known globally.
70
71Operations
72==========
73
74Creating a Partition
75--------------------
76
77The ``rtems_partition_create`` directive creates a partition with a
78user-specified name.  The partition's name, starting address, length and buffer
79size are all specified to the ``rtems_partition_create`` directive.  RTEMS
80allocates a Partition Control Block (PTCB) from the PTCB free list.  This data
81structure is used by RTEMS to manage the newly created partition.  The number
82of buffers in the partition is calculated based upon the specified partition
83length and buffer size. If successful,the unique partition ID is returned to
84the calling task.
85
86Obtaining Partition IDs
87-----------------------
88
89When a partition is created, RTEMS generates a unique partition ID and assigned
90it to the created partition until it is deleted.  The partition ID may be
91obtained by either of two methods.  First, as the result of an invocation of
92the ``rtems_partition_create`` directive, the partition ID is stored in a user
93provided location.  Second, the partition ID may be obtained later using the
94``rtems_partition_ident`` directive.  The partition ID is used by other
95partition manager directives to access this partition.
96
97Acquiring a Buffer
98------------------
99
100A buffer can be obtained by calling the ``rtems_partition_get_buffer``
101directive.  If a buffer is available, then it is returned immediately with a
102successful return code.  Otherwise, an unsuccessful return code is returned
103immediately to the caller.  Tasks cannot block to wait for a buffer to become
104available.
105
106Releasing a Buffer
107------------------
108
109Buffers are returned to a partition's free buffer chain with the
110``rtems_partition_return_buffer`` directive.  This directive returns an error
111status code if the returned buffer was not previously allocated from this
112partition.
113
114Deleting a Partition
115--------------------
116
117The ``rtems_partition_delete`` directive allows a partition to be removed and
118returned to RTEMS.  When a partition is deleted, the PTCB for that partition is
119returned to the PTCB free list.  A partition with buffers still allocated
120cannot be deleted.  Any task attempting to do so will be returned an error
121status code.
122
123Directives
124==========
125
126This section details the partition manager's directives.  A subsection is
127dedicated to each of this manager's directives and describes the calling
128sequence, related constants, usage, and status codes.
129
130.. _rtems_partition_create:
131
132PARTITION_CREATE - Create a partition
133-------------------------------------
134.. index:: create a partition
135
136**CALLING SEQUENCE:**
137
138.. index:: rtems_partition_create
139
140.. code-block:: c
141
142    rtems_status_code rtems_partition_create(
143        rtems_name       name,
144        void            *starting_address,
145        uint32_t         length,
146        uint32_t         buffer_size,
147        rtems_attribute  attribute_set,
148        rtems_id        *id
149    );
150
151**DIRECTIVE STATUS CODES:**
152
153.. list-table::
154 :class: rtems-table
155
156 * - ``RTEMS_SUCCESSFUL``
157   - partition created successfully
158 * - ``RTEMS_INVALID_NAME``
159   - invalid partition name
160 * - ``RTEMS_TOO_MANY``
161   - too many partitions created
162 * - ``RTEMS_INVALID_ADDRESS``
163   - address not on four byte boundary
164 * - ``RTEMS_INVALID_ADDRESS``
165   - ``starting_address`` is NULL
166 * - ``RTEMS_INVALID_ADDRESS``
167   - ``id`` is NULL
168 * - ``RTEMS_INVALID_SIZE``
169   - length or buffer size is 0
170 * - ``RTEMS_INVALID_SIZE``
171   - length is less than the buffer size
172 * - ``RTEMS_INVALID_SIZE``
173   - buffer size not a multiple of 4
174 * - ``RTEMS_MP_NOT_CONFIGURED``
175   - multiprocessing not configured
176 * - ``RTEMS_TOO_MANY``
177   - too many global objects
178
179**DESCRIPTION:**
180
181This directive creates a partition of fixed size buffers from a physically
182contiguous memory space which starts at starting_address and is length bytes in
183size.  Each allocated buffer is to be of ``buffer_size`` in bytes.  The
184assigned partition id is returned in ``id``.  This partition id is used to
185access the partition with other partition related directives.  For control and
186maintenance of the partition, RTEMS allocates a PTCB from the local PTCB free
187pool and initializes it.
188
189**NOTES:**
190
191This directive will not cause the calling task to be preempted.
192
193The ``starting_address`` must be properly aligned for the target architecture.
194
195The ``buffer_size`` parameter must be a multiple of the CPU alignment factor.
196Additionally, ``buffer_size`` must be large enough to hold two pointers on the
197target architecture.  This is required for RTEMS to manage the buffers when
198they are free.
199
200Memory from the partition is not used by RTEMS to store the Partition Control
201Block.
202
203The following partition attribute constants are defined by RTEMS:
204
205.. list-table::
206 :class: rtems-table
207
208 * - ``RTEMS_LOCAL``
209   - local partition (default)
210 * - ``RTEMS_GLOBAL``
211   - global partition
212
213The PTCB for a global partition is allocated on the local node.  The memory
214space used for the partition must reside in shared memory. Partitions should
215not be made global unless remote tasks must interact with the partition.  This
216is to avoid the overhead incurred by the creation of a global partition.  When
217a global partition is created, the partition's name and id must be transmitted
218to every node in the system for insertion in the local copy of the global
219object table.
220
221The total number of global objects, including partitions, is limited by the
222maximum_global_objects field in the Configuration Table.
223
224.. _rtems_partition_ident:
225
226PARTITION_IDENT - Get ID of a partition
227---------------------------------------
228.. index:: get ID of a partition
229.. index:: obtain ID of a partition
230
231**CALLING SEQUENCE:**
232
233.. index:: rtems_partition_ident
234
235.. code-block:: c
236
237    rtems_status_code rtems_partition_ident(
238        rtems_name  name,
239        uint32_t    node,
240        rtems_id   *id
241    );
242
243**DIRECTIVE STATUS CODES:**
244
245.. list-table::
246 :class: rtems-table
247
248 * - ``RTEMS_SUCCESSFUL``
249   - partition identified successfully
250 * - ``RTEMS_INVALID_ADDRESS``
251   - ``id`` is NULL
252 * - ``RTEMS_INVALID_NAME``
253   - partition name not found
254 * - ``RTEMS_INVALID_NODE``
255   - invalid node id
256
257**DESCRIPTION:**
258
259This directive obtains the partition id associated with the partition name.  If
260the partition name is not unique, then the partition id will match one of the
261partitions with that name.  However, this partition id is not guaranteed to
262correspond to the desired partition.  The partition id is used with other
263partition related directives to access the partition.
264
265**NOTES:**
266
267This directive will not cause the running task to be preempted.
268
269If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the local
270node being searched first.  All other nodes are searched with the lowest
271numbered node searched first.
272
273If node is a valid node number which does not represent the local node, then
274only the partitions exported by the designated node are searched.
275
276This directive does not generate activity on remote nodes.  It accesses only
277the local copy of the global object table.
278
279.. _rtems_partition_delete:
280
281PARTITION_DELETE - Delete a partition
282-------------------------------------
283.. index:: delete a partition
284
285**CALLING SEQUENCE:**
286
287.. index:: rtems_partition_delete
288
289.. code-block:: c
290
291    rtems_status_code rtems_partition_delete(
292        rtems_id id
293    );
294
295**DIRECTIVE STATUS CODES:**
296
297.. list-table::
298 :class: rtems-table
299
300 * - ``RTEMS_SUCCESSFUL``
301   - partition deleted successfully
302 * - ``RTEMS_INVALID_ID``
303   - invalid partition id
304 * - ``RTEMS_RESOURCE_IN_USE``
305   - buffers still in use
306 * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
307   - cannot delete remote partition
308
309**DESCRIPTION:**
310
311This directive deletes the partition specified by id.  The partition cannot be
312deleted if any of its buffers are still allocated.  The PTCB for the deleted
313partition is reclaimed by RTEMS.
314
315**NOTES:**
316
317This directive will not cause the calling task to be preempted.
318
319The calling task does not have to be the task that created the partition.  Any
320local task that knows the partition id can delete the partition.
321
322When a global partition is deleted, the partition id must be transmitted to
323every node in the system for deletion from the local copy of the global object
324table.
325
326The partition must reside on the local node, even if the partition was created
327with the ``RTEMS_GLOBAL`` option.
328
329.. _rtems_partition_get_buffer:
330
331PARTITION_GET_BUFFER - Get buffer from a partition
332--------------------------------------------------
333.. index:: get buffer from partition
334.. index:: obtain buffer from partition
335
336**CALLING SEQUENCE:**
337
338.. index:: rtems_partition_get_buffer
339
340.. code-block:: c
341
342    rtems_status_code rtems_partition_get_buffer(
343        rtems_id   id,
344        void     **buffer
345    );
346
347**DIRECTIVE STATUS CODES:**
348
349.. list-table::
350 :class: rtems-table
351
352 * - ``RTEMS_SUCCESSFUL``
353   - buffer obtained successfully
354 * - ``RTEMS_INVALID_ADDRESS``
355   - ``buffer`` is NULL
356 * - ``RTEMS_INVALID_ID``
357   - invalid partition id
358 * - ``RTEMS_UNSATISFIED``
359   - all buffers are allocated
360
361**DESCRIPTION:**
362
363This directive allows a buffer to be obtained from the partition specified
364in id.  The address of the allocated buffer is returned in buffer.
365
366**NOTES:**
367
368This directive will not cause the running task to be preempted.
369
370All buffers begin on a four byte boundary.
371
372A task cannot wait on a buffer to become available.
373
374Getting a buffer from a global partition which does not reside on the local
375node will generate a request telling the remote node to allocate a buffer from
376the specified partition.
377
378.. _rtems_partition_return_buffer:
379
380PARTITION_RETURN_BUFFER - Return buffer to a partition
381------------------------------------------------------
382.. index:: return buffer to partitition
383
384**CALLING SEQUENCE:**
385
386.. index:: rtems_partition_return_buffer
387
388.. code-block:: c
389
390    rtems_status_code rtems_partition_return_buffer(
391        rtems_id  id,
392        void     *buffer
393    );
394
395**DIRECTIVE STATUS CODES:**
396
397.. list-table::
398 :class: rtems-table
399
400 * - ``RTEMS_SUCCESSFUL``
401   - buffer returned successfully
402 * - ``RTEMS_INVALID_ADDRESS``
403   - ``buffer`` is NULL
404 * - ``RTEMS_INVALID_ID``
405   - invalid partition id
406 * - ``RTEMS_INVALID_ADDRESS``
407   - buffer address not in partition
408
409**DESCRIPTION:**
410
411This directive returns the buffer specified by buffer to the partition
412specified by id.
413
414**NOTES:**
415
416This directive will not cause the running task to be preempted.
417
418Returning a buffer to a global partition which does not reside on the local
419node will generate a request telling the remote node to return the buffer to
420the specified partition.
421
422Returning a buffer multiple times is an error.  It will corrupt the internal
423state of the partition.
Note: See TracBrowser for help on using the repository browser.