Memory heap services.
[Native Xenomai API.]

Collaboration diagram for Memory heap services.:

Detailed Description

Memory heaps are regions of memory used for dynamic memory allocation in a time-bounded fashion. Blocks of memory are allocated and freed in an arbitrary order and the pattern of allocation and size of blocks is not known until run time.

The implementation of the memory allocator follows the algorithm described in a USENIX 1988 paper called "Design of a General Purpose Memory Allocator for the 4.3BSD Unix Kernel" by Marshall K. McKusick and Michael J. Karels.

Xenomai memory heaps are built over the nucleus's heap objects, which in turn provide the needed support for sharing a memory area between kernel and user-space using direct memory mapping.


Files

file  heap.c
 This file is part of the Xenomai project.

Functions

int rt_heap_create (RT_HEAP *heap, const char *name, size_t heapsize, int mode)
 Create a memory heap or a shared memory segment.
int rt_heap_delete (RT_HEAP *heap)
int rt_heap_alloc (RT_HEAP *heap, size_t size, RTIME timeout, void **blockp)
int rt_heap_free (RT_HEAP *heap, void *block)
int rt_heap_inquire (RT_HEAP *heap, RT_HEAP_INFO *info)
int rt_heap_bind (RT_HEAP *heap, const char *name, RTIME timeout)
int rt_heap_unbind (RT_HEAP *heap)


Function Documentation

int rt_heap_alloc ( RT_HEAP *  heap,
size_t  size,
RTIME  timeout,
void **  blockp 
)

Allocate a block or return the single segment base.

This service allocates a block from the heap's internal pool, or returns the address of the single memory segment in the caller's address space. Tasks may wait for some requested amount of memory to become available from local heaps.

Parameters:
heap The descriptor address of the heap to allocate a block from.
size The requested size in bytes of the block. If the heap is managed as a single-block area (H_SINGLE), this value can be either zero, or the same value given to rt_heap_create(). In that case, the same block covering the entire heap space will always be returned to all callers of this service.
timeout The number of clock ticks to wait for a block of sufficient size to be available from a local heap (see note). Passing TM_INFINITE causes the caller to block indefinitely until some block is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no block is available on entry. This parameter has no influence if the heap is managed as a single-block area since the entire heap space is always available.
blockp A pointer to a memory location which will be written upon success with the address of the allocated block, or the start address of the single memory segment. In the former case, the block should be freed using rt_heap_free().
Returns:
0 is returned upon success. Otherwise:

Environments:

This service can be called from:

Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation. Operations on single-block heaps never start the rescheduling procedure.

Note:
The timeout value will be interpreted as jiffies if the native skin is bound to a periodic time base (see CONFIG_XENO_OPT_NATIVE_PERIOD), or nanoseconds otherwise.

int rt_heap_bind ( RT_HEAP *  heap,
const char *  name,
RTIME  timeout 
)

Bind to a mappable heap.

This user-space only service retrieves the uniform descriptor of a given mappable Xenomai heap identified by its symbolic name. If the heap does not exist on entry, this service blocks the caller until a heap of the given name is created.

Parameters:
name A valid NULL-terminated name which identifies the heap to bind to.
heap The address of a heap descriptor retrieved by the operation. Contents of this memory is undefined upon failure.
timeout The number of clock ticks to wait for the registration to occur (see note). Passing TM_INFINITE causes the caller to block indefinitely until the object is registered. Passing TM_NONBLOCK causes the service to return immediately without waiting if the object is not registered on entry.
Returns:
0 is returned upon success. Otherwise:

This service can be called from:

Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.

Note:
The timeout value will be interpreted as jiffies if the native skin is bound to a periodic time base (see CONFIG_XENO_OPT_NATIVE_PERIOD), or nanoseconds otherwise.
Examples:
shared_mem.c.

int rt_heap_create ( RT_HEAP *  heap,
const char *  name,
size_t  heapsize,
int  mode 
)

Create a memory heap or a shared memory segment.

Initializes a memory heap suitable for time-bounded allocation requests of dynamic memory. Memory heaps can be local to the kernel address space, or mapped to user-space.

In their simplest form, heaps are only accessible from kernel space, and are merely usable as regular memory allocators.

Heaps existing in kernel space can be mapped by user-space processes to their own address space provided H_MAPPABLE has been passed into the mode parameter.

By default, heaps support allocation of multiple blocks of memory in an arbitrary order. However, it is possible to ask for single-block management by passing the H_SINGLE flag into the mode parameter, in which case the entire memory space managed by the heap is made available as a unique block. In this mode, all allocation requests made through rt_heap_alloc() will then return the same block address, pointing at the beginning of the heap memory.

H_SHARED is a shorthand for creating shared memory segments transparently accessible from kernel and user-space contexts, which are basically single-block, mappable heaps. By proper use of a common name, all tasks can bind themselves to the same heap and thus share the same memory space, which start address should be subsequently retrieved by a call to rt_heap_alloc().

Parameters:
heap The address of a heap descriptor Xenomai will use to store the heap-related data. This descriptor must always be valid while the heap is active therefore it must be allocated in permanent memory.
name An ASCII string standing for the symbolic name of the heap. When non-NULL and non-empty, this string is copied to a safe place into the descriptor, and passed to the registry package if enabled for indexing the created heap. Mappable heaps must be given a valid name.
heapsize The size (in bytes) of the block pool which is going to be pre-allocated to the heap. Memory blocks will be claimed and released to this pool. The block pool is not extensible, so this value must be compatible with the highest memory pressure that could be expected. A minimum of 2 * PAGE_SIZE will be enforced for mappable heaps, 2 * XNCORE_PAGE_SIZE otherwise.
mode The heap creation mode. The following flags can be OR'ed into this bitmask, each of them affecting the new heap:

Returns:
0 is returned upon success. Otherwise:

Environments:

This service can be called from:

Rescheduling: possible.

int rt_heap_delete ( RT_HEAP *  heap  ) 

Delete a real-time heap.

Destroy a heap and release all the tasks currently pending on it. A heap exists in the system since rt_heap_create() has been called to create it, so this service must be called in order to destroy it afterwards.

Parameters:
heap The descriptor address of the affected heap.
Returns:
0 is returned upon success. Otherwise:

Environments:

This service can be called from:

Rescheduling: possible.

int rt_heap_free ( RT_HEAP *  heap,
void *  block 
)

Free a block.

This service releases a block to the heap's internal pool. If some task is currently waiting for a block so that it's pending request could be satisfied as a result of the release, it is immediately resumed.

If the heap is defined as a single-block area (i.e. H_SINGLE mode), this service leads to a null-effect and always returns successfully.

Parameters:
heap The address of the heap descriptor to which the block block belong.
block The address of the block to free.
Returns:
0 is returned upon success, or -EINVAL if block is not a valid block previously allocated by the rt_heap_alloc() service.
Environments:

This service can be called from:

Rescheduling: possible.

int rt_heap_inquire ( RT_HEAP *  heap,
RT_HEAP_INFO *  info 
)

Inquire about a heap.

Return various information about the status of a given heap.

Parameters:
heap The descriptor address of the inquired heap.
info The address of a structure the heap information will be written to.
Returns:
0 is returned and status information is written to the structure pointed at by info upon success. Otherwise:

Environments:

This service can be called from:

Rescheduling: never.

int rt_heap_unbind ( RT_HEAP *  heap  ) 

Unbind from a mappable heap.

This user-space only service unbinds the calling task from the heap object previously retrieved by a call to rt_heap_bind().

Unbinding from a heap when it is no longer needed is especially important in order to properly release the mapping resources used to attach the heap memory to the caller's address space.

Parameters:
heap The address of a heap descriptor to unbind from.
Returns:
0 is always returned.
This service can be called from:

Rescheduling: never.

Examples:
shared_mem.c.


Generated on Mon Mar 24 18:02:42 2008 for Xenomai API by  doxygen 1.5.3