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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jul 12 16:42:23 2015 +0200

cobalt/kernel: improve handling of user debug options

This changeset introduces individual switches for enabling/disabling
particular user debug features. At this chance, the related
documentation has been updated.

Notification upon secondary mode switches is still considered
regardless of the debug settings, as production setups may depend on
it for basic sanity testing.

---

 include/cobalt/kernel/synch.h  |    6 +-
 include/cobalt/kernel/thread.h |    2 +-
 include/cobalt/uapi/corectl.h  |   16 ++--
 include/cobalt/uapi/signal.h   |    2 +-
 kernel/cobalt/Kconfig          |  168 +++++++++++++++++++++-------------------
 kernel/cobalt/debug.c          |    2 +-
 kernel/cobalt/posix/cond.c     |    5 +-
 kernel/cobalt/posix/mutex.c    |   22 +++---
 kernel/cobalt/posix/sem.c      |   10 +--
 kernel/cobalt/posix/syscall.c  |   10 ++-
 kernel/cobalt/rtdm/core.c      |    2 +-
 kernel/cobalt/rtdm/fd.c        |    5 +-
 kernel/cobalt/synch.c          |    8 +-
 kernel/cobalt/thread.c         |   26 ++++---
 kernel/drivers/Kconfig         |    3 +-
 lib/cobalt/internal.c          |    4 +-
 lib/cobalt/thread.c            |   29 +++++--
 17 files changed, 176 insertions(+), 144 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index f53cd5e..ffb884a 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -101,14 +101,14 @@ static inline struct xnthread *xnsynch_owner(struct 
xnsynch *synch)
 #define xnsynch_owner_check(synch, thread) \
        xnsynch_fast_owner_check((synch)->fastlock, thread->handle)
 
-#if XENO_DEBUG(USER)
+#if XENO_DEBUG(MUTEX_RELAXED)
 
 void xnsynch_detect_relaxed_owner(struct xnsynch *synch,
                                  struct xnthread *sleeper);
 
 void xnsynch_detect_claimed_relax(struct xnthread *owner);
 
-#else /* !XENO_DEBUG(USER) */
+#else /* !XENO_DEBUG(MUTEX_RELAXED) */
 
 static inline void xnsynch_detect_relaxed_owner(struct xnsynch *synch,
                                  struct xnthread *sleeper)
@@ -119,7 +119,7 @@ static inline void xnsynch_detect_claimed_relax(struct 
xnthread *owner)
 {
 }
 
-#endif /* !XENO_DEBUG(USER) */
+#endif /* !XENO_DEBUG(MUTEX_RELAXED) */
 
 void xnsynch_init(struct xnsynch *synch, int flags,
                  atomic_t *fastlock);
diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 8a9236a..1ba0c1b 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -503,7 +503,7 @@ static inline void xnthread_get_resource(struct xnthread 
*thread)
 static inline int xnthread_put_resource(struct xnthread *thread)
 {
        if (xnthread_test_state(thread, XNWEAK) ||
-           IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER)) {
+           IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP)) {
                if (unlikely(thread->res_count == 0)) {
                        if (xnthread_test_state(thread, XNWARN))
                                xnthread_signal(thread, SIGDEBUG,
diff --git a/include/cobalt/uapi/corectl.h b/include/cobalt/uapi/corectl.h
index d2544b3..9466743 100644
--- a/include/cobalt/uapi/corectl.h
+++ b/include/cobalt/uapi/corectl.h
@@ -22,12 +22,16 @@
 #define _CC_COBALT_GET_NR_PIPES                1
 #define _CC_COBALT_GET_NR_TIMERS       2
 
-#define _CC_COBALT_GET_DEBUG           3
-#   define _CC_COBALT_DEBUG_ASSERT     1
-#   define _CC_COBALT_DEBUG_CONTEXT    2
-#   define _CC_COBALT_DEBUG_LOCKING    4
-#   define _CC_COBALT_DEBUG_USER       8
-#   define _CC_COBALT_DEBUG_RELAX      16
+#define _CC_COBALT_GET_DEBUG                   3
+#   define _CC_COBALT_DEBUG_ASSERT             1
+#   define _CC_COBALT_DEBUG_CONTEXT            2
+#   define _CC_COBALT_DEBUG_LOCKING            4
+#   define _CC_COBALT_DEBUG_USER               8
+#   define _CC_COBALT_DEBUG_MUTEX_RELAXED      16
+#   define _CC_COBALT_DEBUG_MUTEX_SLEEP                32
+#   define _CC_COBALT_DEBUG_POSIX_SYNCHRO      64
+#   define _CC_COBALT_DEBUG_LEGACY             128
+#   define _CC_COBALT_DEBUG_TRACE_RELAX                256
 
 #define _CC_COBALT_GET_POLICIES                4
 #   define _CC_COBALT_SCHED_FIFO       1
diff --git a/include/cobalt/uapi/signal.h b/include/cobalt/uapi/signal.h
index 53e46ba..b5483d7 100644
--- a/include/cobalt/uapi/signal.h
+++ b/include/cobalt/uapi/signal.h
@@ -66,7 +66,7 @@
 #define SIGDEBUG_WATCHDOG              6
 #define SIGDEBUG_RESCNT_IMBALANCE      7
 #define SIGDEBUG_LOCK_BREAK            8
-#define SIGDEBUG_RESCNT_SLEEP          9
+#define SIGDEBUG_MUTEX_SLEEP           9
 
 #define COBALT_DELAYMAX                        2147483647U
 
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 27b4a4a..afa62d2 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -4,7 +4,6 @@ config XENO_OPT_SCHED_CLASSES
        bool "Extra scheduling classes"
        default n
        help
-
        The Cobalt kernel implements a set of scheduling classes.
        Each scheduling class defines its own set of rules for
        determining when and how to select a new thread to run.
@@ -22,7 +21,6 @@ config XENO_OPT_SCHED_WEAK
        default n
        depends on XENO_OPT_SCHED_CLASSES
        help
-
        This option creates a Cobalt scheduling class for mapping
        members of the regular POSIX SCHED_FIFO/RR policies to a low
        priority class of the Cobalt kernel, providing no real-time
@@ -50,7 +48,6 @@ config XENO_OPT_SCHED_TP
        default n
        depends on XENO_OPT_SCHED_CLASSES
        help
-
        This option enables support for temporal partitioning.
 
        If in doubt, say N.
@@ -61,7 +58,6 @@ config XENO_OPT_SCHED_TP_NRPART
        range 1 1024
        depends on XENO_OPT_SCHED_TP
        help
-
        Define here the maximum number of temporal partitions the TP
        scheduler may have to handle.
 
@@ -70,7 +66,6 @@ config XENO_OPT_SCHED_SPORADIC
        default n
        depends on XENO_OPT_SCHED_CLASSES
        help
-
        This option enables support for the sporadic scheduling policy
        in the Cobalt kernel (SCHED_SPORADIC), also known as POSIX
        sporadic server.
@@ -86,7 +81,6 @@ config XENO_OPT_SCHED_SPORADIC_MAXREPL
        range 4 16
        depends on XENO_OPT_SCHED_SPORADIC
        help
-
        For performance reason, the budget replenishment information
        is statically stored on a per-thread basis. This parameter
        defines the maximum number of replenishment requests that can
@@ -98,7 +92,6 @@ config XENO_OPT_SCHED_QUOTA
        default n
        depends on XENO_OPT_SCHED_CLASSES
        help
-
        This option enables the SCHED_QUOTA scheduling policy in the
        Cobalt kernel.
 
@@ -122,7 +115,6 @@ config XENO_OPT_SCHED_QUOTA_PERIOD
        range 100 1000000000
        depends on XENO_OPT_SCHED_QUOTA
        help
-
        The global period thread groups can get a share of.
 
 config XENO_OPT_SCHED_QUOTA_NR_GROUPS
@@ -131,7 +123,6 @@ config XENO_OPT_SCHED_QUOTA_NR_GROUPS
        range 1 1024
        depends on XENO_OPT_SCHED_QUOTA
        help
-
        The overall number of thread groups which may be defined
        across all CPUs.
 
@@ -140,7 +131,6 @@ config XENO_OPT_STATS
        depends on XENO_OPT_VFILE
        default y
        help
-
        This option causes the Cobalt kernel to collect various
        per-thread runtime statistics, which are accessible through
        the /proc/xenomai/sched/stat interface.
@@ -148,7 +138,6 @@ config XENO_OPT_STATS
 config XENO_OPT_SHIRQ
        bool "Shared interrupts"
        help
-
        Enables support for both level- and edge-triggered shared
        interrupts, so that multiple real-time interrupt handlers
        are allowed to control dedicated hardware devices which are
@@ -158,7 +147,6 @@ config XENO_OPT_RR_QUANTUM
        int "Round-robin quantum (us)"
        default 1000
        help
-
        This parameter defines the duration of the default round-robin
        time quantum expressed as a count of micro-seconds. This value
        may be overriden internally by Cobalt services which do
@@ -176,7 +164,6 @@ config XENO_OPT_AUTOTUNE
 config XENO_OPT_SCALABLE_SCHED
        bool "O(1) scheduler"
        help
-
        This option causes a multi-level priority queue to be used in
        the real-time scheduler, so that it operates in constant-time
        regardless of the number of _concurrently runnable_ threads
@@ -192,7 +179,6 @@ choice
        prompt "Timer indexing method"
        default XENO_OPT_TIMER_LIST
        help
-
        This option allows to select the underlying data structure
        which is going to be used for ordering the outstanding
        software timers managed by the Cobalt kernel.
@@ -200,7 +186,6 @@ choice
 config XENO_OPT_TIMER_LIST
        bool "Linear"
        help
-
        Use a linked list. Albeit O(N), this simple data structure is
        particularly efficient when only a few timers (< 10) may be
        concurrently outstanding at any point in time.
@@ -208,7 +193,6 @@ config XENO_OPT_TIMER_LIST
 config XENO_OPT_TIMER_HEAP
        bool "Tree"
        help
-
        Use a binary heap. This data structure is efficient when a
        high number of software timers may be concurrently
        outstanding at any point in time.
@@ -220,7 +204,6 @@ config XENO_OPT_TIMER_HEAP_CAPACITY
        depends on XENO_OPT_TIMER_HEAP
        default 256
        help
-
        Set the maximum number of timers the binary heap can index.
 
 config XENO_OPT_HOSTRT
@@ -253,7 +236,6 @@ config XENO_OPT_PIPE_NRDEV
        depends on XENO_OPT_PIPE
        default 32
        help
-
        Message pipes are bi-directional FIFO communication channels
        allowing data exchange between Cobalt threads and regular
        POSIX threads. Pipes natively preserve message boundaries, but
@@ -268,7 +250,6 @@ config XENO_OPT_REGISTRY_NRSLOTS
        int "Number of registry slots"
        default 512
        help
-
        The registry is used by the Cobalt kernel to export named
        resources to user-space programs via the /proc interface.
        Each named resource occupies a registry slot. This option sets
@@ -278,7 +259,6 @@ config XENO_OPT_SYS_HEAPSZ
        int "Size of system heap (Kb)"
        default 256
        help
-
        The system heap is used for various internal allocations by
        the Cobalt kernel. The size is expressed in Kilobytes.
 
@@ -286,7 +266,6 @@ config XENO_OPT_PRIVATE_HEAPSZ
        int "Size of private heap (Kb)"
        default 64
        help
-
        The Cobalt kernel implements fast IPC mechanisms within the
        scope of a process which require a private kernel memory heap
        to be mapped in the address space of each Xenomai application
@@ -299,7 +278,6 @@ config XENO_OPT_SHARED_HEAPSZ
        int "Size of shared heap (Kb)"
        default 64
        help
-
        The Cobalt kernel implements fast IPC mechanisms between
        processes which require a shared kernel memory heap to be
        mapped in the address space of all Xenomai application
@@ -312,7 +290,6 @@ config XENO_OPT_NRTIMERS
        int "Maximum number of POSIX timers per process"
        default 128
        help
-
        This tunable controls how many POSIX timers can exist at any
        given time for each Cobalt process (a timer is created by a
        call to the timer_create() service of the Cobalt/POSIX API).
@@ -322,7 +299,6 @@ config XENO_OPT_DEBUG_TRACE_LOGSZ
        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.
@@ -367,7 +343,6 @@ config XENO_OPT_TIMING_IRQLAT
        int "Interrupt latency (ns)"
        default 0
        help
-
        The interrupt latency is the time between the occurrence of an
        IRQ and the first instruction of the interrupt handler which
        will service it. A default value of 0 (recommended) will cause
@@ -382,92 +357,128 @@ menuconfig XENO_OPT_DEBUG
        depends on XENO_OPT_VFILE
        bool "Debug support"
        help
-
-       When enabled, various debugging features can be switched
-       on. They can help to find problems in applications, drivers,
-       and the Cobalt kernel. XENO_OPT_DEBUG by itself does not have
-       any impact on the generated code.
+         When enabled, various debugging features can be switched
+         on. They can help to find problems in applications, drivers,
+         and the Cobalt kernel. XENO_OPT_DEBUG by itself does not have
+         any impact on the generated code.
 
 if XENO_OPT_DEBUG
 
 config XENO_OPT_DEBUG_COBALT
        bool "Cobalt runtime assertions"
        help
-
-       This option activates various assertions inside the Cobalt
-       kernel. This option has limited overhead.
+         This option activates various assertions inside the Cobalt
+         kernel. 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
-       Cobalt kernel, aimed at detecting when regular Linux routines
-       are entered from a real-time context, and conversely.
+         This option enables checks for the calling context in the
+         Cobalt kernel, aimed at detecting when regular Linux routines
+         are entered from a real-time context, and conversely.
 
 config XENO_OPT_DEBUG_LOCKING
        bool "Spinlock debugging support"
        default y if SMP
        help
+         This option activates runtime assertions, and measurements
+         of spinlocks spinning time and duration in the Cobalt
+         kernel. It helps finding latency spots due to interrupt
+         masked sections. Statistics about the longest masked section
+         can be found in /proc/xenomai/debug/lock.
 
-       This option activates runtime assertions, and measurements of
-       spinlocks spinning time and duration in the Cobalt kernel. It
-       helps finding latency spots due to interrupt masked
-       sections. Statistics about the longest masked section can be
-       found in /proc/xenomai/lock.
-
-       This option may induce a measurable overhead on low end
-       machines.
+         This option may induce a measurable overhead on low end
+         machines.
 
 config XENO_OPT_DEBUG_USER
        bool "User consistency checks"
        help
+         This option enables a set of consistency checks for
+         detecting wrong runtime behavior in user applications.
 
-       This option enables a set of consistency checks for detecting
-       wrong runtime behavior in user applications.
+         With some of the debug categories, threads can ask for
+         notification when a problem is detected, by turning on the
+         PTHREAD_WARNSW mode bit with pthread_setmode_np().  Cobalt
+         sends the Linux-originated SIGDEBUG signal for notifying
+         threads, along with a reason code passed into the associated
+         siginfo data (see pthread_setmode_np()).
+       
+         Some of these runtime checks may induce overhead, enable
+         them for debugging purposes only.
 
-       For instance, this feature detects when a Cobalt thread
-       attempts to sleep on a Cobalt mutex, which is owned by another
-       thread currently running in secondary mode (i.e. plain Linux
-       execution mode). If the WARNSW flag is enabled for the sleeper
-       when this situation arises, it immediately receives the
-       SIGDEBUG signal (see pthread_setmode_np(), rt_task_set_mode()
-       depending on your API). This particular situation is a
-       possible source of unwanted latency, since the current mutex
-       owner may be unexpectedly delayed as a result of using
-       non-deterministic Linux services, thus deferring the release
-       of the Cobalt mutex after an undefined amount of time.
+if XENO_OPT_DEBUG_USER
 
-       This option may introduce some overhead (e.g. with highly
-       contended mutexes). Use this feature for debugging purposes
-       only.
+config XENO_OPT_DEBUG_MUTEX_RELAXED
+       bool "Detect relaxed mutex owner"
+       default y
+       help
+         A thread which attempts to acquire a mutex currently owned by
+         another thread running in secondary/relaxed mode thread will
+         suffer unwanted latencies, due to a priority inversion.
+         debug notifications are enabled for such thread, it receives
+         a SIGDEBUG signal.
+
+        This option has some overhead in real-time mode over
+        contented mutexes.
+ 
+config XENO_OPT_DEBUG_MUTEX_SLEEP
+       bool "Detect sleeping with mutex"
+       default y
+       help
+         A thread which goes sleeping while holding a mutex is prone
+         to cause unwanted latencies to other threads serialized by
+         the same lock. If debug notifications are enabled for such
+         thread, it receives a SIGDEBUG signal right before entering
+        sleep.
+
+        This option has noticeable overhead in real-time mode as it
+        disables the normal fast mutex operations from user-space,
+        causing a system call for each mutex acquisition/release.
+
+config XENO_OPT_DEBUG_POSIX_SYNCHRO
+        bool "Detect POSIX synchronization issues"
+       default n
+       help
+         When this debug category is enabled, calls to the thread
+         synchronization services are checked for consistency, beyond
+         the requirements of the POSIX standard. In most cases, a
+         faulty call results in error EPERM when detected.
+
+         This option has negligible overhead.
+ 
+config XENO_OPT_DEBUG_LEGACY
+        bool "Detect usage of legacy constructs/features"
+       default n
+       help
+           Turns on detection of legacy API usage.
+
+endif # XENO_OPT_DEBUG_USER
 
 config XENO_OPT_DEBUG_TRACE_RELAX
        bool "Trace relax requests"
+       default n
        help
-
-       This option enables recording of unwanted relax requests from
-       user-space applications leaving the real-time domain, logging
-       the thread information and code location involved. All records
-       are readable from /proc/xenomai/debug/relax, and can be
-       decoded using the "slackspot" utility.
+         This option enables recording of unwanted relax requests from
+         user-space applications leaving the real-time domain, logging
+         the thread information and code location involved. All records
+         are readable from /proc/xenomai/debug/relax, and can be
+         decoded using the "slackspot" utility.
 
 config XENO_OPT_WATCHDOG
        bool "Watchdog support"
        default y
        help
+         This option activates a watchdog aimed at detecting runaway
+         Cobalt threads. If enabled, the watchdog triggers after a
+         given period of uninterrupted real-time activity has elapsed
+         without Linux interaction in the meantime.
 
-       This option activates a watchdog aimed at detecting runaway
-       Cobalt threads. If enabled, the watchdog triggers after a
-       given period of uninterrupted real-time activity has elapsed
-       without Linux interaction in the meantime.
+         In such an event, the current thread is moved out the
+         real-time domain, receiving a SIGDEBUG signal from the Linux
+         kernel immediately after.
 
-       In such an event, the current thread is moved out the
-       real-time domain, receiving a SIGDEBUG signal from the Linux
-       kernel immediately after.
-
-       The timeout value of the watchdog can be set using the
-       XENO_OPT_WATCHDOG_TIMEOUT parameter.
+         The timeout value of the watchdog can be set using the
+         XENO_OPT_WATCHDOG_TIMEOUT parameter.
 
 config XENO_OPT_WATCHDOG_TIMEOUT
        depends on XENO_OPT_WATCHDOG
@@ -475,7 +486,6 @@ config XENO_OPT_WATCHDOG_TIMEOUT
        default 4
        range 1 60
        help
-
-       Watchdog timeout value (in seconds).
+         Watchdog timeout value (in seconds).
 
 endif # XENO_OPT_DEBUG
diff --git a/kernel/cobalt/debug.c b/kernel/cobalt/debug.c
index 6324ab7..312f43a 100644
--- a/kernel/cobalt/debug.c
+++ b/kernel/cobalt/debug.c
@@ -410,7 +410,7 @@ static const char *reason_str[] = {
     [SIGDEBUG_NOMLOCK] = "mlock-check",
     [SIGDEBUG_WATCHDOG] = "runaway-break",
     [SIGDEBUG_RESCNT_IMBALANCE] = "resource-count-imbalance",
-    [SIGDEBUG_RESCNT_SLEEP] = "sleep-holding-resource",
+    [SIGDEBUG_MUTEX_SLEEP] = "sleep-holding-mutex",
     [SIGDEBUG_LOCK_BREAK] = "scheduler-lock-break",
 };
 
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index 758444b..502df5d 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -137,13 +137,12 @@ static inline int cobalt_cond_timedwait_prologue(struct 
xnthread *cur,
                goto unlock_and_return;
        }
 
-#if XENO_DEBUG(USER)
-       if (cond->resnode.scope !=
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
+           cond->resnode.scope !=
            cobalt_current_resources(cond->attr.pshared)) {
                err = -EPERM;
                goto unlock_and_return;
        }
-#endif
 
        if (mutex->attr.pshared != cond->attr.pshared) {
                err = -EINVAL;
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index 3d31fa2..d9ebdfb 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -95,11 +95,11 @@ int cobalt_mutex_release(struct xnthread *cur,
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, struct cobalt_mutex))
                 return -EINVAL;
 
-#if XENO_DEBUG(USER)
-       if (mutex->resnode.scope !=
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
+           mutex->resnode.scope !=
            cobalt_current_resources(mutex->attr.pshared))
                return -EPERM;
-#endif
+
        state = container_of(mutex->synchbase.fastlock, struct 
cobalt_mutex_state, owner);
        flags = state->flags;
        need_resched = 0;
@@ -142,13 +142,14 @@ redo:
                ret = -EINVAL;
                goto out;
        }
-#if XENO_DEBUG(USER)
-       if (mutex->resnode.scope !=
+
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
+           mutex->resnode.scope !=
            cobalt_current_resources(mutex->attr.pshared)) {
                ret = -EPERM;
                goto out;
        }
-#endif
+
        if (xnsynch_owner_check(&mutex->synchbase, curr)) {
                if (fetch_timeout) {
                        xnlock_put_irqrestore(&nklock, s);
@@ -171,11 +172,10 @@ redo:
        switch(mutex->attr.type) {
        case PTHREAD_MUTEX_NORMAL:
                /* Attempting to relock a normal mutex, deadlock. */
-#if XENO_DEBUG(USER)
-               printk(XENO_WARNING
-                      "thread %s deadlocks on non-recursive mutex\n",
-                      curr->name);
-#endif
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO))
+                       printk(XENO_WARNING
+                              "thread %s deadlocks on non-recursive mutex\n",
+                              curr->name);
                /* Make the caller hang. */
                __cobalt_mutex_acquire_unchecked(curr, mutex, NULL);
                break;
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index e63967f..08c4cc3 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -209,10 +209,9 @@ static inline int sem_trywait_inner(struct cobalt_sem *sem)
        if (sem == NULL || sem->magic != COBALT_SEM_MAGIC)
                return -EINVAL;
 
-#if XENO_DEBUG(USER)
-       if (sem->resnode.scope != sem_kqueue(sem))
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
+           sem->resnode.scope != sem_kqueue(sem))
                return -EPERM;
-#endif
 
        if (atomic_sub_return(1, &sem->state->value) < 0)
                return -EAGAIN;
@@ -237,10 +236,9 @@ static int sem_post_inner(struct cobalt_sem *sem, int 
bcast)
        if (sem == NULL || sem->magic != COBALT_SEM_MAGIC)
                return -EINVAL;
 
-#if XENO_DEBUG(USER)
-       if (sem->resnode.scope && sem->resnode.scope != sem_kqueue(sem))
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
+           sem->resnode.scope && sem->resnode.scope != sem_kqueue(sem))
                return -EPERM;
-#endif
 
        if (atomic_read(&sem->state->value) == SEM_VALUE_MAX)
                return -EINVAL;
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index cf93f07..759e423 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -395,8 +395,16 @@ static int get_conf_option(int option, void __user *u_buf, 
size_t u_bufsz)
                        val |= _CC_COBALT_DEBUG_LOCKING;
                if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER))
                        val |= _CC_COBALT_DEBUG_USER;
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_RELAXED))
+                       val |= _CC_COBALT_DEBUG_MUTEX_RELAXED;
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP))
+                       val |= _CC_COBALT_DEBUG_MUTEX_SLEEP;
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO))
+                       val |= _CC_COBALT_DEBUG_POSIX_SYNCHRO;
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_LEGACY))
+                       val |= _CC_COBALT_DEBUG_LEGACY;
                if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_TRACE_RELAX))
-                       val |= _CC_COBALT_DEBUG_RELAX;
+                       val |= _CC_COBALT_DEBUG_TRACE_RELAX;
                break;
        case _CC_COBALT_GET_WATCHDOG:
 #ifdef CONFIG_XENO_OPT_WATCHDOG
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index fda3dab..6de8e85 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -104,7 +104,7 @@ open_devnode(struct rtdm_device *dev, const char *path, int 
oflag)
        struct file *filp;
        char *filename;
 
-       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER) &&
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_LEGACY) &&
            strncmp(path, "/dev/rtdm/", 10))
                printk(XENO_WARNING
                       "%s[%d] opens obsolete device path: %s\n",
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 7f35ea3..4d1e597 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -732,10 +732,9 @@ void rtdm_fd_init(void)
 
 static inline void warn_user(const char *name)
 {
-#ifdef CONFIG_XENO_OPT_DEBUG_USER
-       printk(XENO_WARNING "%s[%d] called regular %s() with RTDM 
file/socket\n",
+       printk(XENO_WARNING
+              "%s[%d] called regular %s() with RTDM file/socket\n",
               current->comm, current->pid, name + 5);
-#endif
 }
 
 static ssize_t dumb_read(struct file *file, char  __user *buf,
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index f3c9d31..7142fd2 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -171,10 +171,10 @@ int xnsynch_sleep_on(struct xnsynch *synch, xnticks_t 
timeout,
 
        thread = xnthread_current();
 
-       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER) &&
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP) &&
            thread->res_count > 0 &&
            xnthread_test_state(thread, XNWARN))
-               xnthread_signal(thread, SIGDEBUG, SIGDEBUG_RESCNT_SLEEP);
+               xnthread_signal(thread, SIGDEBUG, SIGDEBUG_MUTEX_SLEEP);
        
        xnlock_get_irqsave(&nklock, s);
 
@@ -903,7 +903,7 @@ void xnsynch_release_all_ownerships(struct xnthread *thread)
 }
 EXPORT_SYMBOL_GPL(xnsynch_release_all_ownerships);
 
-#if XENO_DEBUG(USER)
+#if XENO_DEBUG(MUTEX_RELAXED)
 
 /*
  * Detect when a thread is about to sleep on a synchronization
@@ -945,6 +945,6 @@ void xnsynch_detect_claimed_relax(struct xnthread *owner)
        }
 }
 
-#endif /* XENO_DEBUG(USER) */
+#endif /* XENO_DEBUG(MUTEX_RELAXED) */
 
 /** @} */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index acaf1a3..4cec6e7 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -171,7 +171,7 @@ int __xnthread_init(struct xnthread *thread,
         * state, to speed up branch taking in lib/cobalt wherever
         * this needs to be tested.
         */
-       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER))
+       if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP))
                flags |= XNDEBUG;
 
        thread->personality = attr->personality;
@@ -718,20 +718,22 @@ EXPORT_SYMBOL_GPL(xnthread_start);
  * SIGDEBUG (Linux-originated) signal is sent when the following
  * atypical or abnormal behavior is detected:
  *
- * - the current thread switches to secondary mode. Such notification
- * comes in handy for detecting spurious relaxes.
+ *    - the current thread switches to secondary mode. Such notification
+ *      comes in handy for detecting spurious relaxes.
  *
- * - the current thread is about to sleep on a Cobalt mutex currently
- * owned by a thread running in secondary mode, which reveals a
- * priority inversion.
+ *    - CONFIG_XENO_OPT_DEBUG_MUTEX_RELAXED is enabled in the kernel
+ *      configuration, and the current thread is sleeping on a Cobalt
+ *      mutex currently owned by a thread running in secondary mode,
+ *      which reveals a priority inversion.
  *
- * - the current thread is about to sleep while holding a Cobalt
- * mutex, and CONFIG_XENO_OPT_DEBUG_USER is enabled in the kernel
- * configuration. Blocking for acquiring a mutex does not trigger such
- * signal though.
+ *    - the current thread is about to sleep while holding a Cobalt
+ *      mutex, and CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP is enabled in the
+ *      kernel configuration. Blocking for acquiring a mutex does not
+ *      trigger such a signal though.
  *
- * - the current thread has both XNTRAPLB and XNLOCK set, and attempts
- * to block on a Cobalt service, which would cause a lock break.
+ *    - the current thread has both XNTRAPLB and XNLOCK set, and
+ *      attempts to block on a Cobalt service, which would cause a
+ *      lock break.
  *
  * - XNTRAPLB disallows breaking the scheduler lock. In the default
  * case, a thread which holds the scheduler lock is allowed to drop it
diff --git a/kernel/drivers/Kconfig b/kernel/drivers/Kconfig
index b0101ae..a8b4c26 100644
--- a/kernel/drivers/Kconfig
+++ b/kernel/drivers/Kconfig
@@ -4,7 +4,6 @@ config XENO_OPT_RTDM_COMPAT_DEVNODE
        bool "Enable legacy pathnames for named RTDM devices"
        default y
        help
-
        This compatibility option allows applications to open named
        RTDM devices using the legacy naming scheme, i.e.
 
@@ -13,7 +12,7 @@ config XENO_OPT_RTDM_COMPAT_DEVNODE
        fd = open("/dev/devname", ...);
 
        When such a request is received by RTDM, a warning message is
-       issued to the kernel log whenever XENO_OPT_DEBUG_USER is
+       issued to the kernel log whenever XENO_OPT_DEBUG_LEGACY is
        also enabled in the kernel configuration.
 
        Applications should open named devices via their actual device
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 5b0b0d6..09cce81 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -403,8 +403,8 @@ void cobalt_sigdebug_handler(int sig, siginfo_t *si, void 
*context)
        case SIGDEBUG_RESCNT_IMBALANCE:
                raw_write_out("resource locking imbalance");
                break;
-       case SIGDEBUG_RESCNT_SLEEP:
-               raw_write_out("sleeping while holding resource");
+       case SIGDEBUG_MUTEX_SLEEP:
+               raw_write_out("sleeping while holding mutex");
                break;
        case SIGDEBUG_WATCHDOG:
                raw_write_out("watchdog triggered");
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 2d0023f..140033d 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -351,20 +351,33 @@ COBALT_IMPL(int, pthread_create, (pthread_t *ptid_r,
  *   the following atypical or abnormal behavior is detected:
  *
  *   - the current thread switches to secondary mode. Such
- *     notification comes in handy for detecting spurious relaxes.
+ *     notification comes in handy for detecting spurious relaxes,
+ *     with one of the following reason codes:
  *
- *   - the current thread is about to sleep on a Cobalt mutex
- *     currently owned by a thread running in secondary mode, which
- *     reveals a priority inversion.
+ *     - SIGDEBUG_MIGRATE_SYSCALL, if the thread issued a regular
+ *       Linux system call.
+ *
+ *     - SIGDEBUG_MIGRATE_SIGNAL, if the thread had to leave real-time
+ *       mode for handling a Linux signal.
+ *
+ *     - SIGDEBUG_MIGRATE_FAULT, if the thread had to leave real-time
+ *       mode for handling a processor fault/exception.
+ *
+ *   - the current thread is sleeping on a Cobalt mutex currently
+ *     owned by a thread running in secondary mode, which reveals a
+ *     priority inversion. In such an event, the reason code passed to
+ *     the signal handler will be SIGDEBUG_MIGRATE_PRIOINV.
  *
  *   - the current thread is about to sleep while holding a Cobalt
- *     mutex, and CONFIG_XENO_OPT_DEBUG_USER is enabled in the kernel
- *     configuration. Blocking for acquiring a mutex does not trigger
- *     such signal though.
+ *     mutex, and CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP is enabled in the
+ *     kernel configuration.  In such an event, the reason code passed
+ *     to the signal handler will be SIGDEBUG_MUTEX_SLEEP.  Blocking
+ *     for acquiring a mutex does not trigger such signal though.
  *
  *   - the current thread has enabled PTHREAD_DISABLE_LOCKBREAK and
  *     PTHREAD_LOCK_SCHED, then attempts to block on a Cobalt service,
- *     which would cause a lock break.
+ *     which would cause a lock break. In such an event, the reason
+ *     code passed to the signal handler will be SIGDEBUG_LOCK_BREAK.
  *
  * - PTHREAD_DISABLE_LOCKBREAK disallows breaking the scheduler
  *   lock. Normally, the scheduler lock is dropped implicitly when the


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

Reply via email to