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

5
Last change on this file since 4de0da1 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
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2008.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7.. index:: partitions
8
9Partition Manager
10*****************
11
12Introduction
13============
14
15The partition manager provides facilities to dynamically allocate memory in
16fixed-size units.  The directives provided by the partition manager are:
17
18- rtems_partition_create_ - Create a partition
19
20- rtems_partition_ident_ - Get ID of a partition
21
22- rtems_partition_delete_ - Delete a partition
23
24- rtems_partition_get_buffer_ - Get buffer from a partition
25
26- rtems_partition_return_buffer_ - Return buffer to a partition
27
28Background
29==========
30
31.. index:: partition, definition
32
33Partition Manager Definitions
34-----------------------------
35
36A partition is a physically contiguous memory area divided into fixed-size
37buffers that can be dynamically allocated and deallocated.
38
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.
48
49.. index:: partition attribute set, building
50
51Building a Partition Attribute Set
52----------------------------------
53
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:
57
58.. list-table::
59 :class: rtems-table
60
61 * - ``RTEMS_LOCAL``
62   - local partition (default)
63 * - ``RTEMS_GLOBAL``
64   - global partition
65
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.
74
75Operations
76==========
77
78Creating a Partition
79--------------------
80
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.
89
90Obtaining Partition IDs
91-----------------------
92
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.
100
101Acquiring a Buffer
102------------------
103
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.
109
110Releasing a Buffer
111------------------
112
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.
117
118Deleting a Partition
119--------------------
120
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.
126
127Directives
128==========
129
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
134.. raw:: latex
135
136   \clearpage
137
138.. index:: create a partition
139.. index:: rtems_partition_create
140
141.. _rtems_partition_create:
142
143PARTITION_CREATE - Create a partition
144-------------------------------------
145
146CALLING SEQUENCE:
147    .. code-block:: c
148
149        rtems_status_code rtems_partition_create(
150            rtems_name       name,
151            void            *starting_address,
152            uintptr_t        length,
153            size_t           buffer_size,
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``
165       - invalid partition ``name``
166     * - ``RTEMS_TOO_MANY``
167       - too many partitions created
168     * - ``RTEMS_INVALID_ADDRESS``
169       - ``starting_address`` is not on a pointer size boundary
170     * - ``RTEMS_INVALID_ADDRESS``
171       - ``starting_address`` is NULL
172     * - ``RTEMS_INVALID_ADDRESS``
173       - ``id`` is NULL
174     * - ``RTEMS_INVALID_SIZE``
175       - ``length`` or ``buffer_size`` is 0
176     * - ``RTEMS_INVALID_SIZE``
177       - ``length`` is less than the ``buffer_size``
178     * - ``RTEMS_INVALID_SIZE``
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
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
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.
206
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.
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
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
272.. raw:: latex
273
274   \clearpage
275
276.. index:: get ID of a partition
277.. index:: obtain ID of a partition
278.. index:: rtems_partition_ident
279
280.. _rtems_partition_ident:
281
282PARTITION_IDENT - Get ID of a partition
283---------------------------------------
284
285CALLING SEQUENCE:
286    .. code-block:: c
287
288        rtems_status_code rtems_partition_ident(
289            rtems_name  name,
290            uint32_t    node,
291            rtems_id   *id
292        );
293
294DIRECTIVE STATUS CODES:
295    .. list-table::
296     :class: rtems-table
297
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
306
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.
313
314NOTES:
315    This directive will not cause the running task to be preempted.
316
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.
320
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.
323
324    This directive does not generate activity on remote nodes.  It accesses
325    only the local copy of the global object table.
326
327.. raw:: latex
328
329   \clearpage
330
331.. index:: delete a partition
332.. index:: rtems_partition_delete
333
334.. _rtems_partition_delete:
335
336PARTITION_DELETE - Delete a partition
337-------------------------------------
338
339CALLING SEQUENCE:
340    .. code-block:: c
341
342        rtems_status_code rtems_partition_delete(
343            rtems_id id
344        );
345
346DIRECTIVE STATUS CODES:
347    .. list-table::
348     :class: rtems-table
349
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
358
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.
363
364NOTES:
365    This directive will not cause the calling task to be preempted.
366
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.
369
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.
373
374    The partition must reside on the local node, even if the partition was
375    created with the ``RTEMS_GLOBAL`` option.
376
377.. raw:: latex
378
379   \clearpage
380
381.. index:: get buffer from partition
382.. index:: obtain buffer from partition
383.. index:: rtems_partition_get_buffer
384
385.. _rtems_partition_get_buffer:
386
387PARTITION_GET_BUFFER - Get buffer from a partition
388--------------------------------------------------
389
390CALLING SEQUENCE:
391    .. code-block:: c
392
393        rtems_status_code rtems_partition_get_buffer(
394            rtems_id   id,
395            void     **buffer
396        );
397
398DIRECTIVE STATUS CODES:
399    .. list-table::
400     :class: rtems-table
401
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
410
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.
414
415NOTES:
416    This directive will not cause the running task to be preempted.
417
418    All buffers begin on a four byte boundary.
419
420    A task cannot wait on a buffer to become available.
421
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.
425
426.. raw:: latex
427
428   \clearpage
429
430.. index:: return buffer to partitition
431.. index:: rtems_partition_return_buffer
432
433.. _rtems_partition_return_buffer:
434
435PARTITION_RETURN_BUFFER - Return buffer to a partition
436------------------------------------------------------
437
438CALLING SEQUENCE:
439    .. code-block:: c
440
441        rtems_status_code rtems_partition_return_buffer(
442            rtems_id  id,
443            void     *buffer
444        );
445
446DIRECTIVE STATUS CODES:
447    .. list-table::
448     :class: rtems-table
449
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
458
459DESCRIPTION:
460    This directive returns the buffer specified by buffer to the partition
461    specified by id.
462
463NOTES:
464    This directive will not cause the running task to be preempted.
465
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.
469
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.