source: rtems-docs/c_user/partition_manager.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

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