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

5
Last change on this file since 0c4f2be was 0c4f2be, checked in by Sebastian Huber <sebastian.huber@…>, on 08/10/18 at 05:19:31

c-user: Adjust integer types in partition create

Close #3486.

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