spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
|
Memory management routines for SARK. More...
#include <sark.h>
Macros | |
#define | FREE_MASK 0xe0ff |
Mask used to pick out whether a block is allocated and allocated to a particular application instance. | |
Functions | |
void * | sark_xalloc (heap_t *heap, uint size, uint tag, uint flag) |
Allocate a memory block from the specified heap. | |
void * | sark_alloc (uint count, uint size) |
Allocate a block of memory of count × size bytes from the DTCM heap. Returns either a pointer to the block on success, or NULL on failure. | |
void | sark_xfree (heap_t *heap, void *ptr, uint flag) |
Free a memory block in the specified heap. | |
void | sark_free (void *ptr) |
Frees a block of memory which was previously allocated by sark_alloc() (i.e., from the DTCM heap). | |
uint | sark_xfree_id (heap_t *heap, uint app_id, uint lock) |
Free all allocated blocks in the specified heap which are tagged with the given "app_id". | |
uint | sark_heap_max (heap_t *heap, uint flag) |
Search the supplied heap and return the size of the largest free block (in bytes). | |
heap_t * | sark_heap_init (uint *base, uint *top) |
Initialise an area of memory as a heap. | |
uint | rtr_alloc_id (uint size, uint app_id) |
Allocate a block of entries in the router multicast table (and associate the supplied app_id with this block). | |
uint | rtr_alloc (uint size) |
Allocate a block of entries in the router multicast table (and associate the caller's app_id with this block). | |
void | rtr_free (uint entry, uint clear) |
Free a block of MC table entries which starts with the supplied entry. The relevant router registers can be optionally re-initialised. | |
uint | rtr_free_id (uint app_id, uint clear) |
Free all allocated blocks in the router which are tagged with the given "app_id". | |
uint | rtr_alloc_max (void) |
Return the size of the largest free block in the router multicast table (or zero if table is full). | |
void * | sark_tag_ptr (uint tag, uint app_id) |
Get a pointer to a tagged allocation. | |
Memory management routines for SARK.
Allocate a memory block from the specified heap.
The block will be tagged with the supplied "tag" which must be <= 255. Returns NULL on failure (not enough memory, bad tag or tag in use).
The flag parameter contains two flags in the bottom two bits. If bit 0 is set (ALLOC_LOCK), the heap manipulation is done behind a lock with interrupts disabled. If bit 1 is set (ALLOC_ID), the block is tagged with the AppID provided in bits 15:8 of the flag, otherwise the AppID of the current application is used.
The 8-bit tag
is combined with the AppID and stored in the "free" field while the block is allocated. If the tag
is non-zero, the block is only allocated if the tag is not in use. The tag (and AppID) is stored in the "alloc_tag" table while the block is allocated.
If this command is used to allocate for an app-id which isn't the caller's, the user should set sv->app_data[app_id].clean
to 0 for the application concerned. This ensures that the memory will be cleaned up by a stop signal.
[in] | heap | the heap from which the block should be allocated |
[in] | size | the size of the block in bytes |
[in] | tag | 8-bit tag |
[in] | flag | flags to control locking and AppID |
Allocate a block of memory of count
× size
bytes from the DTCM heap. Returns either a pointer to the block on success, or NULL on failure.
The total amount of memory available for allocation is around 62KB less all of the static variables used by the application.
[in] | count | number of sub-blocks to allocate |
[in] | size | size of each sub-block |
Free a memory block in the specified heap.
If the lock bit in the flag
parameter is set, the manipulation of the heap is done behind a lock. This will turn interrupts off for some time while the heap is searched. If a NULL pointer (ptr
) is passed in, a runtime error will occur. If there is an "alloc_tag" entry associated with the block it is set to NULL.
[in] | heap | the heap to which the free block should be returned |
[in] | ptr | a pointer to the memory block to be freed |
[in] | flag | bit 0 set if the heap should be locked during free |
void sark_free | ( | void * | ptr | ) |
Frees a block of memory which was previously allocated by sark_alloc() (i.e., from the DTCM heap).
[in] | ptr | pointer to memory block |
Free all allocated blocks in the specified heap which are tagged with the given "app_id".
The flag
parameter specifies if locking is needed in the sark_xfree() call. Returns the number of blocks freed.
[in] | heap | the heap from which blocks should be freed |
[in] | app_id | the AppID whose block should be freed |
[in] | flag | controls locking of heap transactions |
Search the supplied heap and return the size of the largest free block (in bytes).
The flag
parameter allows the heap to be locked while the search takes place.
[in] | heap | the heap to be searched |
[in] | flag | controls locking of heap transactions |
Initialise an area of memory as a heap.
Arguments are (uint) pointers to base and top of the area. Returns a pointer to the heap (same address as the base). Assumes the area is large enough to hold a minimal heap (a zero size heap needs 28 bytes).
[in] | base | pointer to bottom of heap memory |
[in] | top | pointer to top of heap memory |
Allocate a block of entries in the router multicast table (and associate the supplied app_id with this block).
If this command is used to allocate for an app-id which isn't the caller's, the user should set sv->app_data[app_id].clean to 0 for the application concerned. This ensures that the memory will be cleaned up by a stop signal.
[in] | size | number of entries to allocate |
[in] | app_id | AppID associated with block |
Allocate a block of entries in the router multicast table (and associate the caller's app_id with this block).
[in] | size | number of entries to allocate |
Free a block of MC table entries which starts with the supplied entry. The relevant router registers can be optionally re-initialised.
[in] | entry | first entry in the block (as returned by rtr_alloc) |
[in] | clear | non-zero to cause router registers to be re-initialised |
Free all allocated blocks in the router which are tagged with the given "app_id".
The relevant router registers can be optionally re-initialised. Returns number of blocks freed.
[in] | app_id | AppID whose entries are to be freed |
[in] | clear | non-zero to cause router registers to be re-initialised |
uint rtr_alloc_max | ( | void | ) |
Return the size of the largest free block in the router multicast table (or zero if table is full).
Get a pointer to a tagged allocation.
[in] | tag | The tag of the allocation to get a pointer to |
[in] | app_id | AppID whose tagged allocation to read (or 0 to use the current core's app ID) |