Module: xenomai-3
Branch: wip/heapmem
Commit: d516ee9ef8661d9dc65372ecfff0c6a2415ce323
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d516ee9ef8661d9dc65372ecfff0c6a2415ce323
Author: Philippe Gerum
Date: Sun Apr 22 19:50:57 2018 +0200
copperplate/heapobj: enable heapmem for private memory
Make HEAPMEM the default private memory allocator for real-time
configurations (cobalt || (mercury && non-debug)).
This setting can be reverted by passing --with-localmem=tlsf.
---
configure.ac | 51 ++---
include/copperplate/heapobj.h | 68 ++-
lib/boilerplate/Makefile.am |7 ++-
lib/copperplate/Makefile.am |4 ++
lib/copperplate/heapobj-heapmem.c | 91 +
5 files changed, 209 insertions(+), 12 deletions(-)
diff --git a/configure.ac b/configure.ac
index 61ebcbe..2caa4f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,6 +327,26 @@ if test x$use_pshared = xy; then
fi
AM_CONDITIONAL(XENO_PSHARED,[test x$use_pshared = xy])
+dnl Allocator selection
+
+localmem_allocator=heapmem
+AC_MSG_CHECKING([for process-local memory allocator])
+AC_ARG_WITH(localmem,
+AS_HELP_STRING([--with-localmem=],[Select process-local
memory allocator]),
+[
+ case "$withval" in
+ "" | y | ye | yes | n | no)
+ AC_MSG_ERROR([You must supply an argument to --with-localmem])
+ ;;
+ heapmem|tlsf)
+ localmem_allocator=$withval
+ ;;
+ *)
+ AC_MSG_ERROR([--localmem-allocator=])
+ esac
+])
+AC_MSG_RESULT($localmem_allocator)
+
dnl Registry support in user-space (FUSE-based, default: off)
use_registry=
@@ -610,12 +630,31 @@ AM_CONDITIONAL(CONFIG_XENO_SHARED,[test "$enable_shared"
= 'yes'])
# Default sampling period (ns) used in various tests
AC_DEFINE_UNQUOTED(CONFIG_XENO_DEFAULT_PERIOD,$CONFIG_XENO_DEFAULT_PERIOD,[config])
-dnl Allocator for Copperplate
-dnl Note: in dual kernel mode, we don't want malloc, no matter what.
-dnl We switch to malloc only over the Mercury core in debug mode, to ease
-dnl debugging with valgrind, instrumented glibc etc.
-AM_CONDITIONAL(XENO_TLSF,[test $rtcore_type = cobalt -o x$debug_mode = x])
-test $rtcore_type = cobalt -o x$debug_mode = x &&
AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+dnl Allocator for Copperplate. Note: in dual kernel mode, we don't
+dnl want malloc, no matter what: pick either heapmem or tlsf, defaults
+dnl to heapmem. Force switch to malloc over the Mercury core in debug
+dnl mode, to ease debugging with valgrind, instrumented glibc etc.
+
+if test $rtcore_type = cobalt -o x$debug_mode = x; then
+ case $localmem_allocator in
+ heapmem)
+ AC_DEFINE(CONFIG_XENO_HEAPMEM,1,[config])
+ use_heapmem=y
+ use_tlsf=
+ ;;
+ tlsf)
+ AC_DEFINE(CONFIG_XENO_TLSF,1,[config])
+ use_tlsf=y
+ use_heapmem=
+ ;;
+ esac
+else
+ use_heapmem=
+ use_tlsf=
+AC_MSG_WARN([using malloc() for private memory in debug mode])
+fi
+AM_CONDITIONAL(XENO_TLSF,[test x$use_tlsf = xy])
+AM_CONDITIONAL(XENO_HEAPMEM,[test x$use_heapmem = xy])
dnl Check for atomic builtins. For now we only check for the legacy
dnl interface, i.e. __sync_*.
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index dc2a45d..c8a7773 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -139,7 +139,71 @@ static inline char *pvstrdup(const char *ptr)
return strcpy(str, ptr);
}
-#else /* !CONFIG_XENO_TLSF, i.e. malloc */
+#elif defined(CONFIG_XENO_HEAPMEM)
+
+#include
+
+extern struct heap_memory heapmem_main;
+
+static inline
+void pvheapobj_destroy(struct heapobj *hobj)
+{
+ heapmem_destroy(hobj->pool);
+}
+
+static inline
+int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
+{
+ return heapmem_extend(hobj->pool, mem, size);
+}
+
+static inline
+void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
+{
+ return heapmem_alloc(hobj->pool, size);
+}
+
+static inline
+void pvheapobj_free(struct heapobj *hobj, void *ptr)
+{
+ heapmem_free(hobj->pool, ptr);
+}
+
+static inline
+size_t pvheapobj_validate(struct heapobj *hobj, void *ptr)
+{
+ ssize_t size = heapmem_check(hobj->pool, ptr);
+ return size < 0 ? 0 : size;
+}
+
+static inline
+size_t pvheapobj_inquire(struct heapobj *hobj)
+{
+ return heapmem_used_size(hobj->pool);
+}
+
+static inline void *pvmalloc(size_t size)
+{
+ return heapmem_alloc(&heapmem_main, size);
+}
+
+static inline void pvfree(void *ptr)
+{
+ heapmem_free(&heapmem_main, ptr);
+}
+
+static inline char *pvstrdup(const char *ptr)
+{
+ char *str;
+
+ str = (char *)pvmalloc(strlen(ptr) + 1);
+ if (str == NULL)
+ return NULL;
+
+ return strcpy(str, ptr);
+}
+
+#else /* !CONFIG_XENO_HEAPMEM, i.e. malloc */
#include
@@ -17