spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
Macros | Functions
sark_alloc.c File Reference

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_tsark_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.
 

Detailed Description

Memory management routines for SARK.

Author
Steve Temple, APT Group, School of Computer Science

Function Documentation

◆ sark_xalloc()

void * sark_xalloc ( heap_t heap,
uint  size,
uint  tag,
uint  flag 
)

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.

Parameters
[in]heapthe heap from which the block should be allocated
[in]sizethe size of the block in bytes
[in]tag8-bit tag
[in]flagflags to control locking and AppID
Returns
pointer to allocated block or NULL on failure

◆ sark_alloc()

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.

The total amount of memory available for allocation is around 62KB less all of the static variables used by the application.

Parameters
[in]countnumber of sub-blocks to allocate
[in]sizesize of each sub-block
Returns
pointer to block or NULL

◆ sark_xfree()

void sark_xfree ( heap_t heap,
void *  ptr,
uint  flag 
)

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.

Parameters
[in]heapthe heap to which the free block should be returned
[in]ptra pointer to the memory block to be freed
[in]flagbit 0 set if the heap should be locked during free

◆ sark_free()

void sark_free ( void *  ptr)

Frees a block of memory which was previously allocated by sark_alloc() (i.e., from the DTCM heap).

Parameters
[in]ptrpointer to memory block

◆ sark_xfree_id()

uint sark_xfree_id ( heap_t heap,
uint  app_id,
uint  flag 
)

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.

Parameters
[in]heapthe heap from which blocks should be freed
[in]app_idthe AppID whose block should be freed
[in]flagcontrols locking of heap transactions
Returns
number of blocks freed

◆ sark_heap_max()

uint sark_heap_max ( heap_t heap,
uint  flag 
)

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.

Parameters
[in]heapthe heap to be searched
[in]flagcontrols locking of heap transactions
Returns
size of largest block

◆ sark_heap_init()

heap_t * sark_heap_init ( uint base,
uint top 
)

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).

Parameters
[in]basepointer to bottom of heap memory
[in]toppointer to top of heap memory
Returns
pointer to heap

◆ rtr_alloc_id()

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).

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.

Parameters
[in]sizenumber of entries to allocate
[in]app_idAppID associated with block
Returns
index of first entry in block on success, zero on failure.

◆ rtr_alloc()

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).

Parameters
[in]sizenumber of entries to allocate
Returns
index of first entry in block on success, zero on failure.

◆ rtr_free()

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.

Parameters
[in]entryfirst entry in the block (as returned by rtr_alloc)
[in]clearnon-zero to cause router registers to be re-initialised

◆ rtr_free_id()

uint rtr_free_id ( uint  app_id,
uint  clear 
)

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.

Parameters
[in]app_idAppID whose entries are to be freed
[in]clearnon-zero to cause router registers to be re-initialised
Returns
number of blocks freed

◆ rtr_alloc_max()

uint rtr_alloc_max ( void  )

Return the size of the largest free block in the router multicast table (or zero if table is full).

Returns
number of entries in largest block

◆ sark_tag_ptr()

void * sark_tag_ptr ( uint  tag,
uint  app_id 
)

Get a pointer to a tagged allocation.

Parameters
[in]tagThe tag of the allocation to get a pointer to
[in]app_idAppID whose tagged allocation to read (or 0 to use the current core's app ID)
Returns
A pointer to the first allocation found with the given tag, or NULL if no such allocation exists.