1 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
2 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
3 | .. COMMENT: All rights reserved. |
---|
4 | |
---|
5 | Partition Manager |
---|
6 | ################# |
---|
7 | |
---|
8 | .. index:: partitions |
---|
9 | |
---|
10 | Introduction |
---|
11 | ============ |
---|
12 | |
---|
13 | The partition manager provides facilities to dynamically allocate memory in |
---|
14 | fixed-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 | |
---|
26 | Background |
---|
27 | ========== |
---|
28 | |
---|
29 | Partition Manager Definitions |
---|
30 | ----------------------------- |
---|
31 | .. index:: partition, definition |
---|
32 | |
---|
33 | A partition is a physically contiguous memory area divided into fixed-size |
---|
34 | buffers that can be dynamically allocated and deallocated. |
---|
35 | |
---|
36 | .. index:: buffers, definition |
---|
37 | |
---|
38 | Partitions are managed and maintained as a list of buffers. Buffers are |
---|
39 | obtained from the front of the partition's free buffer chain and returned to |
---|
40 | the rear of the same chain. When a buffer is on the free buffer chain, RTEMS |
---|
41 | uses two pointers of memory from each buffer as the free buffer chain. When a |
---|
42 | buffer is allocated, the entire buffer is available for application use. |
---|
43 | Therefore, modifying memory that is outside of an allocated buffer could |
---|
44 | destroy the free buffer chain or the contents of an adjacent allocated buffer. |
---|
45 | |
---|
46 | Building a Partition Attribute Set |
---|
47 | ---------------------------------- |
---|
48 | .. index:: partition attribute set, building |
---|
49 | |
---|
50 | In general, an attribute set is built by a bitwise OR of the desired attribute |
---|
51 | components. The set of valid partition attributes is provided in the following |
---|
52 | table: |
---|
53 | |
---|
54 | .. list-table:: |
---|
55 | :class: rtems-table |
---|
56 | |
---|
57 | * - ``RTEMS_LOCAL`` |
---|
58 | - local partition (default) |
---|
59 | * - ``RTEMS_GLOBAL`` |
---|
60 | - global partition |
---|
61 | |
---|
62 | Attribute values are specifically designed to be mutually exclusive, therefore |
---|
63 | bitwise OR and addition operations are equivalent as long as each attribute |
---|
64 | appears exactly once in the component list. An attribute listed as a default |
---|
65 | is not required to appear in the attribute list, although it is a good |
---|
66 | programming practice to specify default attributes. If all defaults are |
---|
67 | desired, the attribute ``RTEMS_DEFAULT_ATTRIBUTES`` should be specified on this |
---|
68 | call. The attribute_set parameter should be ``RTEMS_GLOBAL`` to indicate that |
---|
69 | the partition is to be known globally. |
---|
70 | |
---|
71 | Operations |
---|
72 | ========== |
---|
73 | |
---|
74 | Creating a Partition |
---|
75 | -------------------- |
---|
76 | |
---|
77 | The ``rtems_partition_create`` directive creates a partition with a |
---|
78 | user-specified name. The partition's name, starting address, length and buffer |
---|
79 | size are all specified to the ``rtems_partition_create`` directive. RTEMS |
---|
80 | allocates a Partition Control Block (PTCB) from the PTCB free list. This data |
---|
81 | structure is used by RTEMS to manage the newly created partition. The number |
---|
82 | of buffers in the partition is calculated based upon the specified partition |
---|
83 | length and buffer size. If successful,the unique partition ID is returned to |
---|
84 | the calling task. |
---|
85 | |
---|
86 | Obtaining Partition IDs |
---|
87 | ----------------------- |
---|
88 | |
---|
89 | When a partition is created, RTEMS generates a unique partition ID and assigned |
---|
90 | it to the created partition until it is deleted. The partition ID may be |
---|
91 | obtained by either of two methods. First, as the result of an invocation of |
---|
92 | the ``rtems_partition_create`` directive, the partition ID is stored in a user |
---|
93 | provided location. Second, the partition ID may be obtained later using the |
---|
94 | ``rtems_partition_ident`` directive. The partition ID is used by other |
---|
95 | partition manager directives to access this partition. |
---|
96 | |
---|
97 | Acquiring a Buffer |
---|
98 | ------------------ |
---|
99 | |
---|
100 | A buffer can be obtained by calling the ``rtems_partition_get_buffer`` |
---|
101 | directive. If a buffer is available, then it is returned immediately with a |
---|
102 | successful return code. Otherwise, an unsuccessful return code is returned |
---|
103 | immediately to the caller. Tasks cannot block to wait for a buffer to become |
---|
104 | available. |
---|
105 | |
---|
106 | Releasing a Buffer |
---|
107 | ------------------ |
---|
108 | |
---|
109 | Buffers are returned to a partition's free buffer chain with the |
---|
110 | ``rtems_partition_return_buffer`` directive. This directive returns an error |
---|
111 | status code if the returned buffer was not previously allocated from this |
---|
112 | partition. |
---|
113 | |
---|
114 | Deleting a Partition |
---|
115 | -------------------- |
---|
116 | |
---|
117 | The ``rtems_partition_delete`` directive allows a partition to be removed and |
---|
118 | returned to RTEMS. When a partition is deleted, the PTCB for that partition is |
---|
119 | returned to the PTCB free list. A partition with buffers still allocated |
---|
120 | cannot be deleted. Any task attempting to do so will be returned an error |
---|
121 | status code. |
---|
122 | |
---|
123 | Directives |
---|
124 | ========== |
---|
125 | |
---|
126 | This section details the partition manager's directives. A subsection is |
---|
127 | dedicated to each of this manager's directives and describes the calling |
---|
128 | sequence, related constants, usage, and status codes. |
---|
129 | |
---|
130 | .. _rtems_partition_create: |
---|
131 | |
---|
132 | PARTITION_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 | |
---|
181 | This directive creates a partition of fixed size buffers from a physically |
---|
182 | contiguous memory space which starts at starting_address and is length bytes in |
---|
183 | size. Each allocated buffer is to be of ``buffer_size`` in bytes. The |
---|
184 | assigned partition id is returned in ``id``. This partition id is used to |
---|
185 | access the partition with other partition related directives. For control and |
---|
186 | maintenance of the partition, RTEMS allocates a PTCB from the local PTCB free |
---|
187 | pool and initializes it. |
---|
188 | |
---|
189 | **NOTES:** |
---|
190 | |
---|
191 | This directive will not cause the calling task to be preempted. |
---|
192 | |
---|
193 | The ``starting_address`` must be properly aligned for the target architecture. |
---|
194 | |
---|
195 | The ``buffer_size`` parameter must be a multiple of the CPU alignment factor. |
---|
196 | Additionally, ``buffer_size`` must be large enough to hold two pointers on the |
---|
197 | target architecture. This is required for RTEMS to manage the buffers when |
---|
198 | they are free. |
---|
199 | |
---|
200 | Memory from the partition is not used by RTEMS to store the Partition Control |
---|
201 | Block. |
---|
202 | |
---|
203 | The 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 | |
---|
213 | The PTCB for a global partition is allocated on the local node. The memory |
---|
214 | space used for the partition must reside in shared memory. Partitions should |
---|
215 | not be made global unless remote tasks must interact with the partition. This |
---|
216 | is to avoid the overhead incurred by the creation of a global partition. When |
---|
217 | a global partition is created, the partition's name and id must be transmitted |
---|
218 | to every node in the system for insertion in the local copy of the global |
---|
219 | object table. |
---|
220 | |
---|
221 | The total number of global objects, including partitions, is limited by the |
---|
222 | maximum_global_objects field in the Configuration Table. |
---|
223 | |
---|
224 | .. _rtems_partition_ident: |
---|
225 | |
---|
226 | PARTITION_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 | |
---|
259 | This directive obtains the partition id associated with the partition name. If |
---|
260 | the partition name is not unique, then the partition id will match one of the |
---|
261 | partitions with that name. However, this partition id is not guaranteed to |
---|
262 | correspond to the desired partition. The partition id is used with other |
---|
263 | partition related directives to access the partition. |
---|
264 | |
---|
265 | **NOTES:** |
---|
266 | |
---|
267 | This directive will not cause the running task to be preempted. |
---|
268 | |
---|
269 | If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the local |
---|
270 | node being searched first. All other nodes are searched with the lowest |
---|
271 | numbered node searched first. |
---|
272 | |
---|
273 | If node is a valid node number which does not represent the local node, then |
---|
274 | only the partitions exported by the designated node are searched. |
---|
275 | |
---|
276 | This directive does not generate activity on remote nodes. It accesses only |
---|
277 | the local copy of the global object table. |
---|
278 | |
---|
279 | .. _rtems_partition_delete: |
---|
280 | |
---|
281 | PARTITION_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 | |
---|
311 | This directive deletes the partition specified by id. The partition cannot be |
---|
312 | deleted if any of its buffers are still allocated. The PTCB for the deleted |
---|
313 | partition is reclaimed by RTEMS. |
---|
314 | |
---|
315 | **NOTES:** |
---|
316 | |
---|
317 | This directive will not cause the calling task to be preempted. |
---|
318 | |
---|
319 | The calling task does not have to be the task that created the partition. Any |
---|
320 | local task that knows the partition id can delete the partition. |
---|
321 | |
---|
322 | When a global partition is deleted, the partition id must be transmitted to |
---|
323 | every node in the system for deletion from the local copy of the global object |
---|
324 | table. |
---|
325 | |
---|
326 | The partition must reside on the local node, even if the partition was created |
---|
327 | with the ``RTEMS_GLOBAL`` option. |
---|
328 | |
---|
329 | .. _rtems_partition_get_buffer: |
---|
330 | |
---|
331 | PARTITION_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 | |
---|
363 | This directive allows a buffer to be obtained from the partition specified |
---|
364 | in id. The address of the allocated buffer is returned in buffer. |
---|
365 | |
---|
366 | **NOTES:** |
---|
367 | |
---|
368 | This directive will not cause the running task to be preempted. |
---|
369 | |
---|
370 | All buffers begin on a four byte boundary. |
---|
371 | |
---|
372 | A task cannot wait on a buffer to become available. |
---|
373 | |
---|
374 | Getting a buffer from a global partition which does not reside on the local |
---|
375 | node will generate a request telling the remote node to allocate a buffer from |
---|
376 | the specified partition. |
---|
377 | |
---|
378 | .. _rtems_partition_return_buffer: |
---|
379 | |
---|
380 | PARTITION_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 | |
---|
411 | This directive returns the buffer specified by buffer to the partition |
---|
412 | specified by id. |
---|
413 | |
---|
414 | **NOTES:** |
---|
415 | |
---|
416 | This directive will not cause the running task to be preempted. |
---|
417 | |
---|
418 | Returning a buffer to a global partition which does not reside on the local |
---|
419 | node will generate a request telling the remote node to return the buffer to |
---|
420 | the specified partition. |
---|
421 | |
---|
422 | Returning a buffer multiple times is an error. It will corrupt the internal |
---|
423 | state of the partition. |
---|