source: rtems-docs/c-user/partition_manager.rst @ e52906b

5
Last change on this file since e52906b was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

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