Module: xenomai-forge
Branch: next
Commit: 9e0dce83f29bfb1540ffee9fb38ac3d16445ef1e
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=9e0dce83f29bfb1540ffee9fb38ac3d16445ef1e

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep  9 09:40:31 2014 +0200

cobalt/debug: use separate memory pool for tracing relax requests

Pulling memory from the system heap for logging such debug data has
two adverse effects:

- it might gradually deplete the core heap due to a constantly
  misbehaving application,

- it may leave the user under the (wrong) impression that a memory
  leak is ongoing in the core heap, when a sane application is
  restarted multiple times, which invariably causes a few relax spots
  to be logged during the init phase.

We fix this by assigning a private memory pool for this debug
feature. Traces will simply stop being logged when the pool is full,
until /proc/xenomai/debug/relax is written to for flushing it.

---

 kernel/cobalt/Kconfig |   12 ++++++++++++
 kernel/cobalt/debug.c |   36 ++++++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index c957ec2..6301437 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -350,6 +350,18 @@ config XENO_OPT_RTDM_FILDES
        descriptor is created by each successful call to the open()
        service of the Cobalt/POSIX API).
 
+config XENO_OPT_DEBUG_TRACE_LOGSZ
+       int "Trace log size"
+       depends on XENO_OPT_DEBUG_TRACE_RELAX
+       default 16
+       help
+       
+       The size (kilobytes) of the trace log of relax requests. Once
+       this limit is reached, subsequent traces will be silently
+       discarded.
+
+       Writing to /proc/xenomai/debug/relax empties the trace log.
+
 endmenu
 
 menuconfig XENO_OPT_DEBUG
diff --git a/kernel/cobalt/debug.c b/kernel/cobalt/debug.c
index b33ccb9..8a5a8b5 100644
--- a/kernel/cobalt/debug.c
+++ b/kernel/cobalt/debug.c
@@ -22,6 +22,7 @@
 #include <linux/jhash.h>
 #include <linux/mm.h>
 #include <linux/signal.h>
+#include <linux/vmalloc.h>
 #include <cobalt/kernel/sched.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/clock.h>
@@ -50,6 +51,8 @@ struct hashed_symbol {
 
 static struct hashed_symbol *symbol_jhash[SYMBOL_HSLOTS];
 
+static struct xnheap memory_pool;
+
 /*
  * This is a permanent storage for ASCII strings which comes handy to
  * get a unique and constant reference to a symbol while preserving
@@ -80,7 +83,7 @@ static const char *hash_symbol(const char *symbol)
        if (p)
                goto done;
 
-       p = xnmalloc(sizeof(*p) + len + 1);
+       p = xnheap_alloc(&memory_pool, sizeof(*p) + len + 1);
        if (p == NULL) {
                s = NULL;
                goto out;
@@ -328,7 +331,7 @@ void xndebug_trace_relax(int nr, unsigned long __user 
*u_backtrace,
         * allocation while probing and updating the hash table in a
         * single move.
         */
-       p = xnmalloc(sizeof(*p));
+       p = xnheap_alloc(&memory_pool, sizeof(*p));
        if (p == NULL)
                goto out;      /* Something is about to go wrong... */
 
@@ -479,7 +482,7 @@ static ssize_t relax_vfile_store(struct xnvfile_input 
*input)
 
        while (p) {
                np = p->r_next;
-               xnfree(p);
+               xnheap_free(&memory_pool, p);
                p = np;
        }
 
@@ -501,12 +504,37 @@ static struct xnvfile_regular relax_vfile = {
 
 static inline int init_trace_relax(void)
 {
-       return xnvfile_init_regular("relax", &relax_vfile, &debug_vfroot);
+       u32 size = CONFIG_XENO_OPT_DEBUG_TRACE_LOGSZ * 1024;
+       void *p;
+       int ret;
+
+       p = vmalloc(size);
+       if (p == NULL)
+               return -ENOMEM;
+
+       ret = xnheap_init(&memory_pool, p, size);
+       if (ret)
+               return ret;
+
+       xnheap_set_name(&memory_pool, "debug log");
+
+       ret = xnvfile_init_regular("relax", &relax_vfile, &debug_vfroot);
+       if (ret) {
+               xnheap_destroy(&memory_pool);
+               vfree(p);
+       }
+
+       return ret;
 }
 
 static inline void cleanup_trace_relax(void)
 {
+       void *p;
+
        xnvfile_destroy_regular(&relax_vfile);
+       p = xnheap_get_membase(&memory_pool);
+       xnheap_destroy(&memory_pool);
+       vfree(p);
 }
 
 #else /* !CONFIG_XENO_OPT_DEBUG_TRACE_RELAX */


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to