Break up nucleus heap
PATCH 1/2 Break up nucleus heap
By splitting up the nucleus heap layer in generic part and an allocator implementation, this patch allows to install different heap allocation schemes. For now the patch only moves the BSD-specific parts into separate files and pushes BSD-specific fields in xnheap_t into a private sub-block. Also a "Heap allocator" config option is added, but it only offers BSD.
Todo: Comments in ksrc/nucleus/heap.c need to be updated or moved to bsdalloc.c.
--- include/nucleus/bsdalloc.h | 58 +++++ include/nucleus/heap.h | 37 +-- ksrc/nucleus/Config.in | 10 ksrc/nucleus/Kconfig | 9 ksrc/nucleus/Makefile | 3 ksrc/nucleus/bsdalloc.c | 485 +++++++++++++++++++++++++++++++++++++++++++++ ksrc/nucleus/heap.c | 474 ------------------------------------------- 7 files changed, 575 insertions(+), 501 deletions(-)
nucleus/heap.h renamed from nucleus/heap.h.orig +11 -26
@@ -20,8 +20,6 @@#ifndef _XENO_NUCLEUS_HEAP_H#define _XENO_NUCLEUS_HEAP_H -#include <nucleus/queue.h> -/* * CONSTRAINTS: *
@@ -44,16 +42,11 @@ #if defined(__KERNEL__) || defined(__XENO_SIM__) -#define XNHEAP_MINLOG2 3 -#define XNHEAP_MAXLOG2 22 -#define XNHEAP_MINALLOCSZ (1 << XNHEAP_MINLOG2) -#define XNHEAP_MINALIGNSZ (1 << 4) /* i.e. 16 bytes */ -#define XNHEAP_NBUCKETS (XNHEAP_MAXLOG2 - XNHEAP_MINLOG2 + 2) -#define XNHEAP_MAXEXTSZ (1 << 31) /* i.e. 2Gb */ - -#define XNHEAP_PFREE 0 -#define XNHEAP_PCONT 1 -#define XNHEAP_PLIST 2 +#include <nucleus/queue.h> + +#if defined(CONFIG_XENO_OPT_ALLOC_BSD) +#include <nucleus/bsdalloc.h> +#endif /* allocator selection */ typedef struct xnextent {
@@ -63,10 +56,9 @@ typedef struct xnextent { ((xnextent_t *)(((char *)laddr) - (int)(&((xnextent_t *)0)->link)))caddr_t membase,/* Base address of the page array */ - memlim,/* Memory limit of page array */ - freelist;/* Head of the free page list */ + memlim;/* Memory limit of page array */ -u_char pagemap[1 ];/* Beginning of page map */ +xnextend_priv_t priv; } xnextent_t;
@@ -78,12 +70,10 @@ typedef struct xnheap { ((xnheap_t *)(((char *)laddr) - (int)(&((xnheap_t *)0)->link)))u_long extentsize, - pagesize, - pageshift, + pagesize, hdrsize, - npages,/* Number of pages per extent */ ubytes, - maxcont; + maxcont;xnqueue_t extents;
@@ -91,7 +81,7 @@ typedef struct xnheap {xnlock_t lock;#endif /* CONFIG_SMP */ -caddr_t buckets[XNHEAP_NBUCKETS ]; +xnheap_priv_t priv;xnholder_t *idleq;
@@ -105,14 +95,9 @@ extern xnheap_t kheap;#define xnheap_size (heap) ((heap)->extentsize)#define xnheap_page_size (heap) ((heap)->pagesize) -#define xnheap_page_count (heap) ((heap)->npages)#define xnheap_used_mem (heap) ((heap)->ubytes)#define xnheap_max_contiguous (heap) ((heap)->maxcont) -#define xnheap_overhead (hsize,psize) \ -((sizeof(xnextent_t) + (((hsize) - sizeof(xnextent_t)) / (psize)) + \ - XNHEAP_MINALIGNSZ - 1) & ~(XNHEAP_MINALIGNSZ - 1)) -/* The alignment value must be a power of 2 */ -#define xnheap_align (size,al) (((size)+(al)-1)&(~((al)-1))) +#define xnheap_align (size,al) (((size)+(al)-1)&(~((al)-1)))#define xnmalloc (size) xnheap_alloc(&kheap,size)#define xnfree (ptr) xnheap_free(&kheap,ptr)
nucleus/bsdalloc.h new file +58 -0
58 lines not on this page · raw message
nucleus/Kconfig renamed from nucleus/Kconfig.orig +9 -0
@@ -127,6 +127,15 @@ config XENO_OPT_REGISTRY_NRSLOTS registry can handle. All skins using the registry share this storage. +choice + prompt "Heap allocator" + default XENO_OPT_ALLOC_BSD + +config XENO_OPT_ALLOC_BSD + bool "BSD" + +endchoice + config XENO_OPT_SYS_HEAPSZ int "Size of the system heap (Kb)" default 128
nucleus/heap.c renamed from nucleus/heap.c.orig +3 -471
519 lines not on this page · raw message
nucleus/bsdalloc.c new file +485 -0
485 lines not on this page · raw message
nucleus/Config.in renamed from nucleus/Config.in.orig +6 -4
@@ -26,6 +26,8 @@ if [ "$CONFIG_XENO_OPT_NUCLEUS" != "n" ] if [ "$CONFIG_XENO_OPT_REGISTRY" != "n" ]; then int 'Number of registry slots' CONFIG_XENO_OPT_REGISTRY_NRSLOTS 512 fi + choice 'Heap allocator' \ + "BSD CONFIG_XENO_OPT_ALLOC_BSD BSD int 'Size of the system heap (Kb)' CONFIG_XENO_OPT_SYS_HEAPSZ 128 bool 'Interrupt shield support' CONFIG_XENO_OPT_ISHIELD bool 'Optimize as pipeline head' CONFIG_XENO_OPT_PIPELINE_HEAD
@@ -49,10 +51,10 @@ if [ "$CONFIG_XENO_OPT_NUCLEUS" != "n" ] mainmenu_option next_comment comment 'Scalability options' bool 'O(1) scheduler' CONFIG_XENO_OPT_SCALABLE_SCHED - choice 'Timer indexing method' \ - "Linear CONFIG_XENO_OPT_TIMER_LIST \ - Tree CONFIG_XENO_OPT_TIMER_HEAP \ - Hash CONFIG_XENO_OPT_TIMER_WHEEL" Linear + choice 'Timer indexing method' \ + "Linear CONFIG_XENO_OPT_TIMER_LIST \ + Tree CONFIG_XENO_OPT_TIMER_HEAP \ + Hash CONFIG_XENO_OPT_TIMER_WHEEL" Linear if [ "$CONFIG_XENO_OPT_TIMER_HEAP" = "y" ]; then int 'Max. number of timers' CONFIG_XENO_OPT_TIMER_HEAP_CAPACITY 256 fi
nucleus/Makefile renamed from nucleus/Makefile.orig +3 -0
@@ -12,6 +12,8 @@ xeno_nucleus-$(CONFIG_XENO_OPT_PIPE) += xeno_nucleus-$(CONFIG_XENO_OPT_REGISTRY) += registry.o +xeno_nucleus-$(CONFIG_XENO_OPT_ALLOC_BSD) += bsdalloc.o + xeno_nucleus-$(CONFIG_LTT) += ltt.o EXTRA_CFLAGS += -D__IN_XENOMAI__ -Iinclude/xenomai
@@ -32,6 +34,7 @@ opt_objs-y := opt_objs-$(CONFIG_XENO_OPT_PERVASIVE) += shadow.o core.o opt_objs-$(CONFIG_XENO_OPT_PIPE) += pipe.o opt_objs-$(CONFIG_XENO_OPT_REGISTRY) += registry.o +opt_objs-$(CONFIG_XENO_OPT_ALLOC_BSD) += bsdalloc.o opt_objs-$(CONFIG_LTT) += ltt.o xeno_nucleus-objs += $(opt_objs-y)