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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Aug  1 16:54:56 2013 +0200

cobalt/debug: introduce canned checks for calling context/domain

---

 include/cobalt/kernel/assert.h |    7 +++++++
 kernel/cobalt/Kconfig          |   17 +++++++++++------
 kernel/cobalt/clock.c          |    4 ++++
 kernel/cobalt/heap.c           |    3 +++
 kernel/cobalt/intr.c           |   14 +++++++++-----
 kernel/cobalt/registry.c       |    2 --
 kernel/cobalt/shadow.c         |    3 +--
 kernel/cobalt/thread.c         |    9 +++------
 8 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index dbca076..4d4cf9f 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -47,6 +47,10 @@
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif
 
+#ifndef CONFIG_XENO_OPT_DEBUG_CONTEXT
+#define CONFIG_XENO_OPT_DEBUG_CONTEXT 0
+#endif
+
 #ifndef CONFIG_XENO_OPT_DEBUG_XNLOCK
 #define CONFIG_XENO_OPT_DEBUG_XNLOCK 0
 #endif
@@ -67,6 +71,9 @@
 #define CONFIG_XENO_OPT_DEBUG_COBALT 0
 #endif
 
+#define primary_mode_only()    XENO_BUGON(CONTEXT, ipipe_root_p)
+#define secondary_mode_only()  XENO_BUGON(CONTEXT, !ipipe_root_p)
+
 void __xnsys_assert_failed(const char *file, int line, const char *msg);
 
 void __xnsys_fatal(const char *format, ...);
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 0b1d53b..fb13b8f 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -325,14 +325,19 @@ menuconfig XENO_OPT_DEBUG
 if XENO_OPT_DEBUG
 
 config XENO_OPT_DEBUG_NUCLEUS
-       bool "Nucleus runtime checks"
+       bool "Nucleus runtime assertions"
        help
 
-       This option activates various debugging checks inside the core
-       system. Doing so adds a significant runtime overhead,
-       worsening the latency figures especially on SMP kernels.  Do
-       not switch this option on unless you really know what you are
-       doing.
+       This option activates various assertions inside the core
+       system. This option has limited overhead.
+
+config XENO_OPT_DEBUG_CONTEXT
+       bool "Check for calling context"
+       help
+
+       This option enables checks for the calling context in the
+       Xenomai code, aimed at detecting when regular linux code is
+       entered from a real-time context, and conversely.
 
 config XENO_OPT_DEBUG_XNLOCK
        bool "Spinlock latency measurement"
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 15aad23..bd06a96 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -489,6 +489,8 @@ int xnclock_register(struct xnclock *clock)
        struct xntimerdata *tmd;
        int cpu;
 
+       secondary_mode_only();
+
        trace_mark(xn_nucleus, clock_register, "clock %s", clock->name);
 
        /* Allocate the percpu timer queue slot. */
@@ -536,6 +538,8 @@ void xnclock_deregister(struct xnclock *clock)
        struct xntimerdata *tmd;
        int cpu;
 
+       secondary_mode_only();
+
        trace_mark(xn_nucleus, clock_deregister, "clock %s", clock->name);
 
        cleanup_clock_proc(clock);
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 3db83be..af2d6c7 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -1283,6 +1283,8 @@ int xnheap_init_mapped(struct xnheap *heap, unsigned long 
heapsize, int memflags
        void *heapbase;
        int err;
 
+       secondary_mode_only();
+
        /* Caller must have accounted for internal overhead. */
        heapsize = xnheap_align(heapsize, PAGE_SIZE);
 
@@ -1317,6 +1319,7 @@ void xnheap_destroy_mapped(struct xnheap *heap,
        unsigned long len;
        spl_t s;
 
+       secondary_mode_only();
        /*
         * Trying to unmap user memory without providing a release
         * handler for deferred cleanup is a bug.
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 36bf647..d315b25 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -624,7 +624,7 @@ int xnintr_init(xnintr_t *intr, const char *name,
                unsigned int irq, xnisr_t isr, xniack_t iack,
                int flags)
 {
-       XENO_BUGON(NUCLEUS, !ipipe_root_p);
+       secondary_mode_only();
 
        if (irq >= IPIPE_NR_IRQS)
                return -EINVAL;
@@ -669,7 +669,7 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  */
 void xnintr_destroy(xnintr_t *intr)
 {
-       XENO_BUGON(NUCLEUS, !ipipe_root_p);
+       secondary_mode_only();
        xnintr_detach(intr);
        free_percpu(intr->stats);
 }
@@ -713,12 +713,13 @@ EXPORT_SYMBOL_GPL(xnintr_destroy);
  * @note Attaching an interrupt resets the tracked number of receipts
  * to zero.
  */
-
 int xnintr_attach(xnintr_t *intr, void *cookie)
 {
        int ret;
        spl_t s;
 
+       secondary_mode_only();
+
        trace_mark(xn_nucleus, irq_attach, "irq %u name %s",
                   intr->irq, intr->name);
 
@@ -778,6 +779,8 @@ void xnintr_detach(xnintr_t *intr)
 {
        spl_t s;
 
+       secondary_mode_only();
+
        trace_mark(xn_nucleus, irq_detach, "irq %u", intr->irq);
 
        xnlock_get_irqsave(&intrlock, s);
@@ -816,8 +819,8 @@ EXPORT_SYMBOL_GPL(xnintr_detach);
 
 void xnintr_enable(xnintr_t *intr)
 {
+       secondary_mode_only();
        trace_mark(xn_nucleus, irq_enable, "irq %u", intr->irq);
-
        ipipe_enable_irq(intr->irq);
 }
 EXPORT_SYMBOL_GPL(xnintr_enable);
@@ -845,8 +848,8 @@ EXPORT_SYMBOL_GPL(xnintr_enable);
 
 void xnintr_disable(xnintr_t *intr)
 {
+       secondary_mode_only();
        trace_mark(xn_nucleus, irq_disable, "irq %u", intr->irq);
-
        ipipe_disable_irq(intr->irq);
 }
 EXPORT_SYMBOL_GPL(xnintr_disable);
@@ -869,6 +872,7 @@ EXPORT_SYMBOL_GPL(xnintr_disable);
 
 void xnintr_affinity(xnintr_t *intr, cpumask_t cpumask)
 {
+       secondary_mode_only();
        trace_mark(xn_nucleus, irq_affinity, "irq %u %lu",
                   intr->irq, *(unsigned long *)&cpumask);
 
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 5f2deb6..cebd5f0 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -631,7 +631,6 @@ static inline int registry_wakeup_sleepers(const char *key)
  *
  * Rescheduling: possible.
  */
-
 int xnregistry_enter(const char *key, void *objaddr,
                     xnhandle_t *phandle, struct xnpnode *pnode)
 {
@@ -756,7 +755,6 @@ EXPORT_SYMBOL_GPL(xnregistry_enter);
  * Rescheduling: always unless the request is immediately satisfied or
  * @a timeout specifies a non-blocking operation.
  */
-
 int xnregistry_bind(const char *key, xnticks_t timeout, int timeout_mode,
                    xnhandle_t *phandle)
 {
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 6f9fcb8..8f0d93d 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -2111,8 +2111,7 @@ static int handle_taskexit_event(struct task_struct *p) 
/* p == current */
         * We are called for both kernel and user shadows over the
         * root thread.
         */
-       XENO_BUGON(NUCLEUS, !xnsched_root_p());
-
+       secondary_mode_only();
        thread = xnshadow_current();
        XENO_BUGON(NUCLEUS, thread == NULL);
        personality = thread->personality;
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 0890171..d41da62 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -486,7 +486,7 @@ void __xnthread_cleanup(struct xnthread *curr)
 {
        spl_t s;
 
-       XENO_BUGON(NUCLEUS, !ipipe_root_p);
+       secondary_mode_only();
 
        trace_mark(xn_nucleus, thread_cleanup, "thread %p thread_name %s",
                   curr, xnthread_name(curr));
@@ -1735,10 +1735,7 @@ EXPORT_SYMBOL_GPL(xnthread_migrate);
  *
  * This service can be called from:
  *
- * - Kernel module initialization/cleanup code
- * - Interrupt service routine
- * - Kernel-based task
- * - User-space task
+ * - Primary mode only.
  *
  * Rescheduling: never.
  *
@@ -1754,7 +1751,7 @@ int xnthread_set_schedparam(struct xnthread *thread,
        int old_wprio, new_wprio, ret;
        spl_t s;
 
-       XENO_BUGON(NUCLEUS, xnsched_root_p());
+       primary_mode_only();
 
        xnlock_get_irqsave(&nklock, s);
 


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

Reply via email to