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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Aug  1 15:36:17 2013 +0200

cobalt/assert: move failed assertion handler out of line

In the same move, the former "action" argument disappears from
XENO_ASSERT(), which now returns the boolean result for the asserted
condition.

formerly:
        XENO_ASSERT(subsystem, condition, action);

should now be written:
        if (!XENO_ASSERT(subsystem, condition))
                action;

---

 include/cobalt/kernel/assert.h |   39 ++++++++-------
 include/cobalt/kernel/heap.h   |    1 -
 include/cobalt/kernel/misc.h   |   27 ----------
 include/cobalt/kernel/sched.h  |   26 ++++++----
 include/rtdm/rtdm_driver.h     |   20 +++++---
 kernel/cobalt/Makefile         |    1 +
 kernel/cobalt/assert.c         |  105 ++++++++++++++++++++++++++++++++++++++++
 kernel/cobalt/heap.c           |   16 ++----
 kernel/cobalt/intr.c           |    2 +-
 kernel/cobalt/rtdm/core.c      |   23 ++++-----
 kernel/cobalt/rtdm/device.c    |   32 +++++++-----
 kernel/cobalt/rtdm/drvlib.c    |   38 ++++++++++-----
 kernel/cobalt/sched.c          |   18 ++-----
 kernel/cobalt/sys.c            |   89 +++-------------------------------
 kernel/cobalt/thread.c         |   18 ++-----
 15 files changed, 234 insertions(+), 221 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 4cf421c..cad72d0 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -16,38 +16,43 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
  */
-
 #ifndef _COBALT_KERNEL_ASSERT_H
 #define _COBALT_KERNEL_ASSERT_H
 
 #include <cobalt/kernel/trace.h>
 
-#define XENO_DEBUG(subsystem)                  \
-       (CONFIG_XENO_OPT_DEBUG_##subsystem > 0)
+#define XENO_INFO KERN_INFO    "[Xenomai] "
+#define XENO_WARN KERN_WARNING "[Xenomai] "
+#define XENO_ERR  KERN_ERR     "[Xenomai] "
+
+#define XENO_DEBUG(__subsys)   \
+       (CONFIG_XENO_OPT_DEBUG_##__subsys > 0)
 
-#define XENO_ASSERT(subsystem,cond,action)  do {                       \
-               if (unlikely(XENO_DEBUG(subsystem) && !(cond))) {       \
-                       xntrace_panic_freeze();                         \
-                       printk(XENO_ERR "assertion failed at %s:%d (%s)\n",     
\
-                                __FILE__, __LINE__, (#cond));          \
-                       xntrace_panic_dump();                   \
-                       action;                                         \
-               }                                                       \
-       } while(0)
+#define XENO_ASSERT(__subsys, __cond)                                          
\
+       ({                                                                      
\
+               int __ret = !XENO_DEBUG(__subsys) || (__cond);                  
\
+               if (unlikely(!__ret))                                           
\
+                       __xnsys_assert_failed(__FILE__, __LINE__, (#__cond));   
\
+               __ret;                                                          
\
+       })
 
-#define XENO_BUGON(subsystem,cond)                                     \
+#define XENO_BUGON(__subsys, __cond)                                   \
        do {                                                            \
-               if (unlikely(XENO_DEBUG(subsystem) && (cond)))          \
+               if (unlikely(XENO_DEBUG(__subsys) && (__cond)))         \
                        xnsys_fatal("bug at %s:%d (%s)",                \
-                                   __FILE__, __LINE__, (#cond));       \
-       } while(0)
+                                   __FILE__, __LINE__, (#__cond));     \
+       } while (0)
 
 #ifndef CONFIG_XENO_OPT_DEBUG_NUCLEUS
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif /* CONFIG_XENO_OPT_DEBUG_NUCLEUS */
 
-extern void (*nkpanic)(const char *format, ...);
+void __xnsys_assert_failed(const char *file, int line, const char *msg);
+
+void __xnsys_fatal(const char *format, ...);
 
 #define xnsys_fatal(__fmt, __args...) nkpanic(__fmt, ##__args)
 
+extern void (*nkpanic)(const char *format, ...);
+
 #endif /* !_COBALT_KERNEL_ASSERT_H */
diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index 263dd6a..83874ff 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -26,7 +26,6 @@
 #include <cobalt/kernel/lock.h>
 #include <cobalt/kernel/list.h>
 #include <cobalt/kernel/trace.h>
-#include <cobalt/kernel/misc.h>
 #include <cobalt/uapi/kernel/types.h>
 #include <cobalt/uapi/kernel/heap.h>
 
diff --git a/include/cobalt/kernel/misc.h b/include/cobalt/kernel/misc.h
deleted file mode 100644
index a2c723a..0000000
--- a/include/cobalt/kernel/misc.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2013 Philippe Gerum <r...@xenomai.org>.
- *
- * Xenomai is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef _COBALT_KERNEL_MISC_H
-#define _COBALT_KERNEL_MISC_H
-
-#define XENO_INFO KERN_INFO    "[Xenomai] "
-#define XENO_WARN KERN_WARNING "[Xenomai] "
-#define XENO_ERR  KERN_ERR     "[Xenomai] "
-
-#endif /* !_COBALT_KERNEL_MISC_H */
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index 6aa2c06..e6751c4 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -35,6 +35,7 @@
 #include <cobalt/kernel/sched-weak.h>
 #include <cobalt/kernel/sched-sporadic.h>
 #include <cobalt/kernel/vfile.h>
+#include <cobalt/kernel/assert.h>
 
 /* Sched status flags */
 #define XNRESCHED      0x10000000      /* Needs rescheduling */
@@ -158,9 +159,15 @@ struct xnsched_class {
 #define XNSCHED_RUNPRIO   0x80000000
 
 #ifdef CONFIG_SMP
-#define xnsched_cpu(__sched__) ((__sched__)->cpu)
+static inline int xnsched_cpu(struct xnsched *sched)
+{
+       return sched->cpu;
+}
 #else /* !CONFIG_SMP */
-#define xnsched_cpu(__sched__) ({ (void)(__sched__); 0; })
+static inline int xnsched_cpu(struct xnsched *sched)
+{
+       return 0;
+}
 #endif /* CONFIG_SMP */
 
 static inline struct xnsched *xnsched_struct(int cpu)
@@ -341,15 +348,12 @@ int xnsched_maybe_resched_after_unlocked_switch(struct 
xnsched *sched)
 
 #else /* !CONFIG_XENO_HW_UNLOCKED_SWITCH */
 
-#ifdef CONFIG_SMP
-#define xnsched_finish_unlocked_switch(__sched__)      \
-       ({ XENO_BUGON(NUCLEUS, !hard_irqs_disabled());  \
-               xnsched_current(); })
-#else /* !CONFIG_SMP */
-#define xnsched_finish_unlocked_switch(__sched__)      \
-       ({ XENO_BUGON(NUCLEUS, !hard_irqs_disabled());  \
-               (__sched__); })
-#endif /* !CONFIG_SMP */
+static inline struct xnsched *
+xnsched_finish_unlocked_switch(struct xnsched *sched)
+{
+       XENO_BUGON(NUCLEUS, !hard_irqs_disabled());
+       return xnsched_current();
+}
 
 static inline void xnsched_resched_after_unlocked_switch(void) { }
 
diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index 801dbdd..f8acc9c 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -579,8 +579,8 @@ struct rtdm_dev_context *rtdm_context_get(int fd);
 
 static inline void rtdm_context_lock(struct rtdm_dev_context *context)
 {
-       XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context),
-                   /* just warn if context was a dangling pointer */);
+       /* just warn if context was a dangling pointer */
+       XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context));
        atomic_inc(&context->close_lock_count);
 }
 
@@ -588,8 +588,8 @@ extern int rtdm_apc;
 
 static inline void rtdm_context_unlock(struct rtdm_dev_context *context)
 {
-       XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context),
-                   /* just warn if context was a dangling pointer */);
+       /* just warn if context was a dangling pointer */
+       XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context));
        smp_mb__before_atomic_dec();
        if (unlikely(atomic_dec_and_test(&context->close_lock_count)))
                xnapc_schedule(rtdm_apc);
@@ -923,7 +923,8 @@ int rtdm_irq_request(rtdm_irq_t *irq_handle, unsigned int 
irq_no,
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
 static inline int rtdm_irq_free(rtdm_irq_t *irq_handle)
 {
-       XENO_ASSERT(RTDM, xnsched_root_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, xnsched_root_p()))
+               return -EPERM;
        xnintr_detach(irq_handle);
        return 0;
 }
@@ -1132,7 +1133,8 @@ static inline rtdm_task_t *rtdm_task_current(void)
 
 static inline int rtdm_task_wait_period(void)
 {
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, !xnsched_unblockable_p()))
+               return -EPERM;
        return xnthread_wait_period(NULL);
 }
 
@@ -1238,7 +1240,8 @@ int rtdm_mutex_timedlock(rtdm_mutex_t *mutex, 
nanosecs_rel_t timeout,
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
 static inline void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
 {
-       XENO_ASSERT(RTDM, !xnsched_interrupt_p(), return;);
+       if (!XENO_ASSERT(RTDM, !xnsched_interrupt_p()))
+               return;
 
        trace_mark(xn_rtdm, mutex_unlock, "mutex %p", mutex);
 
@@ -1366,7 +1369,8 @@ static inline int rtdm_strncpy_from_user(rtdm_user_info_t 
*user_info,
 
 static inline int rtdm_rt_capable(rtdm_user_info_t *user_info)
 {
-       XENO_ASSERT(RTDM, !xnsched_interrupt_p(), return 0;);
+       if (!XENO_ASSERT(RTDM, !xnsched_interrupt_p()))
+               return 0;
 
        return (user_info ? xnshadow_thread(user_info) != NULL
                          : !xnsched_root_p());
diff --git a/kernel/cobalt/Makefile b/kernel/cobalt/Makefile
index 3e77206..dc053ee 100644
--- a/kernel/cobalt/Makefile
+++ b/kernel/cobalt/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_XENOMAI) += xenomai.o rtdm/ posix/
 
 xenomai-y :=   apc.o           \
                arith.o         \
+               assert.o        \
                bufd.o          \
                clock.o         \
                heap.o          \
diff --git a/kernel/cobalt/assert.c b/kernel/cobalt/assert.c
new file mode 100644
index 0000000..8032c02
--- /dev/null
+++ b/kernel/cobalt/assert.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2013 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#include <stdarg.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <cobalt/kernel/sched.h>
+#include <cobalt/kernel/assert.h>
+#include <cobalt/kernel/clock.h>
+
+void (*nkpanic)(const char *format, ...) = panic;
+EXPORT_SYMBOL_GPL(nkpanic);
+
+void __xnsys_fatal(const char *format, ...)
+{
+       static char msg_buf[1024];
+       struct xnthread *thread;
+       struct xnsched *sched;
+       static int oopsed;
+       char pbuf[16];
+       xnticks_t now;
+       unsigned cpu;
+       va_list ap;
+       int cprio;
+       spl_t s;
+
+       xntrace_panic_freeze();
+       ipipe_prepare_panic();
+
+       xnlock_get_irqsave(&nklock, s);
+
+       if (oopsed)
+               goto out;
+
+       oopsed = 1;
+       va_start(ap, format);
+       vsnprintf(msg_buf, sizeof(msg_buf), format, ap);
+       printk(XENO_ERR "%s", msg_buf);
+       va_end(ap);
+
+       now = xnclock_read_monotonic(&nkclock);
+
+       printk(KERN_ERR "\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
+              "CPU", "PID", "PRI", "TIMEOUT", "STAT", "NAME");
+
+       /*
+        * NOTE: &nkthreadq can't be empty, we have the root thread(s)
+        * linked there at least.
+        */
+       for_each_online_cpu(cpu) {
+               sched = xnsched_struct(cpu);
+               list_for_each_entry(thread, &nkthreadq, glink) {
+                       if (thread->sched != sched)
+                               continue;
+                       cprio = xnthread_current_priority(thread);
+                       snprintf(pbuf, sizeof(pbuf), "%3d", cprio);
+                       printk(KERN_ERR "%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
+                              thread == sched->curr ? '>' : ' ',
+                              cpu,
+                              xnthread_host_pid(thread),
+                              pbuf,
+                              xnthread_get_timeout(thread, now),
+                              xnthread_state_flags(thread),
+                              xnthread_name(thread));
+               }
+       }
+
+       printk(KERN_ERR "Master time base: clock=%Lu\n",
+              xnclock_read_raw(&nkclock));
+#ifdef CONFIG_SMP
+       printk(KERN_ERR "Current CPU: #%d\n", ipipe_processor_id());
+#endif
+out:
+       xnlock_put_irqrestore(&nklock, s);
+
+       show_stack(NULL,NULL);
+       xntrace_panic_dump();
+       for (;;)
+               cpu_relax();
+}
+EXPORT_SYMBOL_GPL(__xnsys_fatal);
+
+void __xnsys_assert_failed(const char *file, int line, const char *msg)
+{
+       xntrace_panic_freeze();
+       printk(XENO_ERR "assertion failed at %s:%d (%s)\n",
+              file, line, msg);
+       xntrace_panic_dump();
+}
+EXPORT_SYMBOL_GPL(__xnsys_assert_failed);
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 61f572b..3db83be 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -629,18 +629,15 @@ void *xnheap_alloc(struct xnheap *heap, unsigned long 
size)
                } else {
                        if (bsize <= heap->pagesize)
                                --heap->buckets[ilog].fcount;
-                       if (list_empty(&heap->extents))
+                       if (!XENO_ASSERT(NUCLEUS, !list_empty(&heap->extents)))
                                goto oops;
                        list_for_each_entry(extent, &heap->extents, link) {
                                if ((caddr_t) block >= extent->membase &&
                                    (caddr_t) block < extent->memlim)
                                        goto found;
                        }
+                       XENO_ASSERT(NUCLEUS, 0);
                oops:
-                       XENO_ASSERT(NUCLEUS, 0,
-                                   xnsys_fatal("cannot determine source extent 
for block %p (heap %p)?!",
-                                               block, heap);
-                               );
                        block = NULL;
                        goto release_and_exit;
                found:
@@ -842,11 +839,8 @@ found:
                nextpage = freepage + heap->pagesize;
                nblocks = heap->pagesize >> log2size;
                heap->buckets[ilog].fcount -= (nblocks - 1);
+               XENO_BUGON(NUCLEUS, heap->buckets[ilog].fcount < 0);
 
-               XENO_ASSERT(NUCLEUS, heap->buckets[ilog].fcount >= 0,
-                           xnsys_fatal("free block count became negative (heap 
%p, log2=%d, fcount=%d)?!",
-                                       heap, log2size, 
heap->buckets[ilog].fcount);
-                       );
                /*
                 * Easy case: all free blocks are laid on a single
                 * page we are now releasing. Just clear the bucket
@@ -1327,7 +1321,7 @@ void xnheap_destroy_mapped(struct xnheap *heap,
         * Trying to unmap user memory without providing a release
         * handler for deferred cleanup is a bug.
         */
-       XENO_ASSERT(NUCLEUS, mapaddr == NULL || release, /* nop */);
+       XENO_ASSERT(NUCLEUS, mapaddr == NULL || release);
 
        if (XENO_DEBUG(NUCLEUS) && heap->ubytes != 0)
                printk(XENO_ERR "destroying shared heap '%s' "
@@ -1367,7 +1361,7 @@ void xnheap_destroy_mapped(struct xnheap *heap,
                /* The release handler is supposed to clean up the rest. */
                heap->release = release;
                spin_unlock(&kheapq_lock);
-               XENO_ASSERT(NUCLEUS, release != NULL, /* nop */);
+               XENO_ASSERT(NUCLEUS, release != NULL);
                return;
        }
 
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 6973a46..cb5761b 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -27,7 +27,7 @@
 #include <cobalt/kernel/intr.h>
 #include <cobalt/kernel/stat.h>
 #include <cobalt/kernel/clock.h>
-#include <cobalt/kernel/misc.h>
+#include <cobalt/kernel/assert.h>
 
 #define XNINTR_MAX_UNHANDLED   1000
 
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 52000d2..6750946 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -287,8 +287,8 @@ int __rt_dev_open(rtdm_user_info_t *user_info, const char 
*path, int oflag)
                ret = device->open_rt(context, user_info, oflag);
        }
 
-       XENO_ASSERT(RTDM, !spltest(),
-                   splnone(););
+       if (!XENO_ASSERT(RTDM, !spltest()))
+               splnone();
 
        if (unlikely(ret < 0))
                goto cleanup_out;
@@ -339,8 +339,8 @@ int __rt_dev_socket(rtdm_user_info_t *user_info, int 
protocol_family,
                ret = device->socket_rt(context, user_info, protocol);
        }
 
-       XENO_ASSERT(RTDM, !spltest(),
-                   splnone(););
+       if (!XENO_ASSERT(RTDM, !spltest()))
+               splnone();
 
        if (unlikely(ret < 0))
                goto cleanup_out;
@@ -405,8 +405,8 @@ int __rt_dev_close(rtdm_user_info_t *user_info, int fd)
        else
                ret = context->ops->close_rt(context, user_info);
 
-       XENO_ASSERT(RTDM, !spltest(),
-                   splnone(););
+       if (!XENO_ASSERT(RTDM, !spltest()))
+               splnone();
 
        xnlock_get_irqsave(&rt_fildes_lock, s);
 
@@ -464,8 +464,7 @@ void cleanup_process_files(struct rtdm_process *owner)
                                       fd);
 
                        ret = __rt_dev_close(NULL, fd);
-                       XENO_ASSERT(RTDM, ret == 0 || ret == -EBADF,
-                                   /* only warn here */;);
+                       XENO_ASSERT(RTDM, ret == 0 || ret == -EBADF);
                }
        }
 }
@@ -488,8 +487,8 @@ do {                                                        
                \
        else                                                            \
                ret = ops->operation##_nrt(context, user_info, args);   \
                                                                        \
-       XENO_ASSERT(RTDM, !spltest(),                   \
-                   splnone();)
+       if (!XENO_ASSERT(RTDM, !spltest()))                             \
+                   splnone();
 
 #define MAJOR_FUNCTION_WRAPPER_BH()                                    \
        rtdm_context_unlock(context);                                   \
@@ -631,8 +630,8 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector,
 
        ret = ops->select_bind(context, selector, type, fd_index);
 
-       XENO_ASSERT(RTDM, !spltest(),
-                   splnone(););
+       if (!XENO_ASSERT(RTDM, !spltest()))
+                   splnone();
 
        rtdm_context_unlock(context);
 
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 5362f70..1aa2542 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -204,23 +204,26 @@ int rtdm_dev_register(struct rtdm_device *device)
                return -ENOSYS;
 
        /* Sanity check: structure version */
-       XENO_ASSERT(RTDM, device->struct_version == RTDM_DEVICE_STRUCT_VER,
-                   printk(XENO_ERR "invalid rtdm_device version (%d, "
-                          "required %d)\n", device->struct_version,
-                          RTDM_DEVICE_STRUCT_VER);
-                   return -EINVAL;);
+       if (!XENO_ASSERT(RTDM, device->struct_version == 
RTDM_DEVICE_STRUCT_VER)) {
+               printk(XENO_ERR "invalid rtdm_device version (%d, "
+                      "required %d)\n", device->struct_version,
+                      RTDM_DEVICE_STRUCT_VER);
+               return -EINVAL;
+       }
 
        /* Sanity check: proc_name specified? */
-       XENO_ASSERT(RTDM, device->proc_name,
-                   printk(XENO_ERR "no vfile (/proc) name specified for RTDM 
device\n");
-                   return -EINVAL;);
+       if (!XENO_ASSERT(RTDM, device->proc_name)) {
+               printk(XENO_ERR "no vfile (/proc) name specified for RTDM 
device\n");
+               return -EINVAL;
+       }
 
        switch (device->device_flags & RTDM_DEVICE_TYPE_MASK) {
        case RTDM_NAMED_DEVICE:
                /* Sanity check: any open handler? */
-               XENO_ASSERT(RTDM, ANY_HANDLER(*device, open),
-                           printk(XENO_ERR "missing open handler for RTDM 
device\n");
-                           return -EINVAL;);
+               if (!XENO_ASSERT(RTDM, ANY_HANDLER(*device, open))) {
+                       printk(XENO_ERR "missing open handler for RTDM 
device\n");
+                       return -EINVAL;
+               }
                if (device->open_rt &&
                    device->socket_rt != (void *)rtdm_no_support)
                        printk(XENO_ERR "RT open handler is deprecated, "
@@ -231,9 +234,10 @@ int rtdm_dev_register(struct rtdm_device *device)
 
        case RTDM_PROTOCOL_DEVICE:
                /* Sanity check: any socket handler? */
-               XENO_ASSERT(RTDM, ANY_HANDLER(*device, socket),
-                           printk(XENO_ERR "missing socket handler for RTDM 
device\n");
-                           return -EINVAL;);
+               if (!XENO_ASSERT(RTDM, ANY_HANDLER(*device, socket))) {
+                       printk(XENO_ERR "missing socket handler for RTDM 
device\n");
+                       return -EINVAL;
+               }
                if (device->socket_rt &&
                    device->socket_rt != (void *)rtdm_no_support)
                        printk(XENO_ERR "RT socket creation handler is "
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 44dc79b..15ec39b 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -381,7 +381,8 @@ int __rtdm_task_sleep(xnticks_t timeout, xntmode_t mode)
 {
        xnthread_t *thread = xnsched_current_thread();
 
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, !xnsched_unblockable_p()))
+               return -EPERM;
 
        xnthread_suspend(thread, XNDELAY, timeout, mode, NULL);
 
@@ -416,7 +417,8 @@ EXPORT_SYMBOL_GPL(__rtdm_task_sleep);
  */
 void rtdm_task_join_nrt(rtdm_task_t *task, unsigned int poll_delay)
 {
-       XENO_ASSERT(RTDM, xnsched_root_p(), return;);
+       if (!XENO_ASSERT(RTDM, xnsched_root_p()))
+               return;
 
        trace_mark(xn_rtdm, task_joinnrt, "thread %p poll_delay %u",
                   task, poll_delay);
@@ -713,7 +715,7 @@ int device_service_routine(...)
  */
 void rtdm_toseq_init(rtdm_toseq_t *timeout_seq, nanosecs_rel_t timeout)
 {
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), /* only warn here */;);
+       XENO_ASSERT(RTDM, !xnsched_unblockable_p()); /* only warn here */
 
        *timeout_seq = xnclock_read_monotonic(&nkclock) + timeout;
 }
@@ -925,7 +927,8 @@ int rtdm_event_timedwait(rtdm_event_t *event, 
nanosecs_rel_t timeout,
        spl_t s;
        int err = 0;
 
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, !xnsched_unblockable_p()))
+               return -EPERM;
 
        trace_mark(xn_rtdm, event_timedwait,
                   "event %p timeout %Lu timeout_seq %p timeout_seq_value %Lu",
@@ -1203,7 +1206,8 @@ int rtdm_sem_timeddown(rtdm_sem_t *sem, nanosecs_rel_t 
timeout,
        spl_t s;
        int err = 0;
 
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, !xnsched_unblockable_p()))
+               return -EPERM;
 
        trace_mark(xn_rtdm, sem_timedwait,
                   "sem %p timeout %Lu timeout_seq %p timeout_seq_value %Lu",
@@ -1495,7 +1499,8 @@ int rtdm_mutex_timedlock(rtdm_mutex_t *mutex, 
nanosecs_rel_t timeout,
                   "mutex %p timeout %Lu timeout_seq %p timeout_seq_value %Lu",
                   mutex, (long long)timeout, timeout_seq, (long 
long)(timeout_seq ? *timeout_seq : 0));
 
-       XENO_ASSERT(RTDM, !xnsched_unblockable_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, !xnsched_unblockable_p()))
+               return -EPERM;
 
        xnlock_get_irqsave(&nklock, s);
 
@@ -1506,8 +1511,10 @@ int rtdm_mutex_timedlock(rtdm_mutex_t *mutex, 
nanosecs_rel_t timeout,
        else {
                /* Redefinition to clarify XENO_ASSERT output */
                #define mutex_owner xnsynch_owner(&mutex->synch_base)
-               XENO_ASSERT(RTDM, mutex_owner != curr_thread,
-                           err = -EDEADLK; goto unlock_out;);
+               if (!XENO_ASSERT(RTDM, mutex_owner != curr_thread)) {
+                       err = -EDEADLK;
+                       goto unlock_out;
+               }
 
                /* non-blocking mode */
                if (timeout < 0) {
@@ -1586,7 +1593,8 @@ int rtdm_irq_request(rtdm_irq_t *irq_handle, unsigned int 
irq_no,
 {
        int err;
 
-       XENO_ASSERT(RTDM, xnsched_root_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, xnsched_root_p()))
+               return -EPERM;
 
        xnintr_init(irq_handle, device_name, irq_no, handler, NULL, flags);
 
@@ -1797,8 +1805,10 @@ static int rtdm_mmap_buffer(struct file *filp, struct 
vm_area_struct *vma)
        if ((vaddr >= VMALLOC_START) && (vaddr < VMALLOC_END)) {
                unsigned long mapped_size = 0;
 
-               XENO_ASSERT(RTDM, vaddr == PAGE_ALIGN(vaddr), return -EINVAL);
-               XENO_ASSERT(RTDM, (size % PAGE_SIZE) == 0, return -EINVAL);
+               if (!XENO_ASSERT(RTDM, vaddr == PAGE_ALIGN(vaddr)))
+                       return -EINVAL;
+               if (!XENO_ASSERT(RTDM, (size % PAGE_SIZE) == 0))
+                       return -EINVAL;
 
                while (mapped_size < size) {
                        if (xnheap_remap_vm_page(vma, maddr, vaddr))
@@ -1861,7 +1871,8 @@ static int rtdm_do_mmap(rtdm_user_info_t *user_info,
        void *old_priv_data;
        struct file *filp;
 
-       XENO_ASSERT(RTDM, xnsched_root_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, xnsched_root_p()))
+               return -EPERM;
 
        filp = filp_open(XNHEAP_DEV_NAME, O_RDWR, 0);
        if (IS_ERR(filp))
@@ -2057,7 +2068,8 @@ int rtdm_munmap(rtdm_user_info_t *user_info, void *ptr, 
size_t len)
 {
        int err;
 
-       XENO_ASSERT(RTDM, xnsched_root_p(), return -EPERM;);
+       if (!XENO_ASSERT(RTDM, xnsched_root_p()))
+               return -EPERM;
 
        down_write(&user_info->mm->mmap_sem);
        err = do_munmap(user_info->mm, (unsigned long)ptr, len);
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 803cbc0..8db8e2a 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -290,9 +290,9 @@ EXPORT_SYMBOL_GPL(___xnsched_lock);
 void ___xnsched_unlock(struct xnsched *sched)
 {
        struct xnthread *curr = sched->curr;
-       XENO_ASSERT(NUCLEUS, xnthread_lock_count(curr) > 0,
-                   xnsys_fatal("Unbalanced lock/unlock");
-                   );
+
+       if (!XENO_ASSERT(NUCLEUS, xnthread_lock_count(curr) > 0))
+               return;
 
        if (--xnthread_lock_count(curr) == 0) {
                xnthread_clear_state(curr, XNLOCK);
@@ -460,6 +460,8 @@ void sched_initq(struct xnsched_mlq *q, int loprio, int 
hiprio)
 {
        int prio;
 
+       XENO_BUGON(NUCLEUS, hiprio - loprio + 1 >= XNSCHED_MLQ_LEVELS);
+
        q->elems = 0;
        q->loprio = loprio;
        q->hiprio = hiprio;
@@ -468,19 +470,11 @@ void sched_initq(struct xnsched_mlq *q, int loprio, int 
hiprio)
 
        for (prio = 0; prio < XNSCHED_MLQ_LEVELS; prio++)
                INIT_LIST_HEAD(q->heads + prio);
-
-       XENO_ASSERT(NUCLEUS,
-                   hiprio - loprio + 1 < XNSCHED_MLQ_LEVELS,
-                   xnsys_fatal("priority range [%d..%d] is beyond multi-level "
-                               "queue indexing capabilities",
-                               loprio, hiprio));
 }
 
 static inline int indexmlq(struct xnsched_mlq *q, int prio)
 {
-       XENO_ASSERT(NUCLEUS,
-                   prio >= q->loprio && prio <= q->hiprio,
-                   xnsys_fatal("priority level %d is out of range ", prio));
+       XENO_BUGON(NUCLEUS, prio < q->loprio || prio > q->hiprio);
        /*
         * BIG FAT WARNING: We need to rescale the priority level to a
         * 0-based range. We use ffnz() to scan the bitmap which MUST
diff --git a/kernel/cobalt/sys.c b/kernel/cobalt/sys.c
index 4744de2..9329a83 100644
--- a/kernel/cobalt/sys.c
+++ b/kernel/cobalt/sys.c
@@ -20,10 +20,6 @@
  * @defgroup nucleus Xenomai core services.
  * @{
  */
-#include <stdarg.h>
-#include <linux/ptrace.h>
-#include <linux/sched.h>
-#include <linux/kernel.h>
 #include <cobalt/kernel/sched.h>
 #include <cobalt/kernel/timer.h>
 #include <cobalt/kernel/intr.h>
@@ -38,83 +34,6 @@
 
 cpumask_t nkaffinity = CPU_MASK_ALL;
 
-void (*nkpanic)(const char *format, ...) = panic;
-EXPORT_SYMBOL_GPL(nkpanic);
-
-static void fatal(const char *format, ...)
-{
-       static char msg_buf[1024];
-       struct xnthread *thread;
-       struct xnsched *sched;
-       static int oopsed;
-       char pbuf[16];
-       xnticks_t now;
-       unsigned cpu;
-       va_list ap;
-       int cprio;
-       spl_t s;
-
-       xntrace_panic_freeze();
-       ipipe_prepare_panic();
-
-       xnlock_get_irqsave(&nklock, s);
-
-       if (oopsed)
-               goto out;
-
-       oopsed = 1;
-       va_start(ap, format);
-       vsnprintf(msg_buf, sizeof(msg_buf), format, ap);
-       printk(XENO_ERR "%s", msg_buf);
-       va_end(ap);
-
-       now = xnclock_read_monotonic(&nkclock);
-
-       printk(KERN_ERR "\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
-              "CPU", "PID", "PRI", "TIMEOUT", "STAT", "NAME");
-
-       /*
-        * NOTE: &nkthreadq can't be empty, we have the root thread(s)
-        * linked there at least.
-        */
-       for_each_online_cpu(cpu) {
-               sched = xnsched_struct(cpu);
-               list_for_each_entry(thread, &nkthreadq, glink) {
-                       if (thread->sched != sched)
-                               continue;
-                       cprio = xnthread_current_priority(thread);
-                       snprintf(pbuf, sizeof(pbuf), "%3d", cprio);
-                       printk(KERN_ERR "%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
-                              thread == sched->curr ? '>' : ' ',
-                              cpu,
-                              xnthread_host_pid(thread),
-                              pbuf,
-                              xnthread_get_timeout(thread, now),
-                              xnthread_state_flags(thread),
-                              xnthread_name(thread));
-               }
-       }
-
-       printk(KERN_ERR "Master time base: clock=%Lu\n",
-              xnclock_read_raw(&nkclock));
-#ifdef CONFIG_SMP
-       printk(KERN_ERR "Current CPU: #%d\n", ipipe_processor_id());
-#endif
-out:
-       xnlock_put_irqrestore(&nklock, s);
-
-       show_stack(NULL,NULL);
-       xntrace_panic_dump();
-       for (;;)
-               cpu_relax();
-}
-
-static void flush_heap(struct xnheap *heap,
-                      void *extaddr, unsigned long extsize, void *cookie)
-{
-       free_pages_exact(extaddr, extsize);
-}
-
 static int enable_timesource(void)
 {
        struct xnsched *sched;
@@ -244,7 +163,7 @@ int xnsys_init(void)
 
        xnregistry_init();
 
-       nkpanic = fatal;
+       nkpanic = __xnsys_fatal;
        smp_wmb();
        xnshadow_grab_events();
 
@@ -274,6 +193,12 @@ static void disable_timesource(void)
 #endif /* CONFIG_XENO_OPT_STATS */
 }
 
+static void flush_heap(struct xnheap *heap,
+                      void *extaddr, unsigned long extsize, void *cookie)
+{
+       free_pages_exact(extaddr, extsize);
+}
+
 /**
  * @fn void xnsys_shutdown(void)
  * @brief Shutdown the Xenomai system.
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 78f9b11..0890171 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -857,15 +857,10 @@ void xnthread_suspend(xnthread_t *thread, int mask,
        struct xnsched *sched;
        spl_t s;
 
-       XENO_ASSERT(NUCLEUS, !xnthread_test_state(thread, XNROOT),
-                   xnsys_fatal("attempt to suspend root thread %s",
-                               thread->name);
-               );
-
-       XENO_ASSERT(NUCLEUS, wchan == NULL || thread->wchan == NULL,
-                   xnsys_fatal("thread %s attempts a conjunctive wait",
-                               thread->name);
-               );
+       /* No, you certainly do not want to suspend the root thread. */
+       XENO_BUGON(NUCLEUS, xnthread_test_state(thread, XNROOT));
+       /* No built-in support for conjunctive wait. */
+       XENO_BUGON(NUCLEUS, wchan && thread->wchan);
 
        xnlock_get_irqsave(&nklock, s);
 
@@ -1540,9 +1535,8 @@ void xnthread_cancel(struct xnthread *thread)
 {
        spl_t s;
 
-       XENO_ASSERT(NUCLEUS, !xnthread_test_state(thread, XNROOT),
-                   xnsys_fatal("attempt to cancel the root thread");
-               );
+       /* Right, so you want to kill the kernel?! */
+       XENO_BUGON(NUCLEUS, xnthread_test_state(thread, XNROOT));
 
        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