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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Aug 30 19:58:21 2014 +0200

cobalt/kernel: group user-oriented debug checks

Consistency checks which monitor how applications behave (and not how
the Cobalt kernel behaves) are better grouped under a single switch,
i.e. CONFIG_XENO_OPT_DEBUG_USER.

---

 include/cobalt/kernel/assert.h |   10 +++++-----
 include/cobalt/kernel/synch.h  |    6 +++---
 include/cobalt/uapi/sysconf.h  |    4 ++--
 kernel/cobalt/Kconfig          |   37 +++++++++++++++++++------------------
 kernel/cobalt/posix/cond.c     |    2 +-
 kernel/cobalt/posix/mutex.c    |   13 ++++++-------
 kernel/cobalt/posix/process.c  |    4 ++--
 kernel/cobalt/posix/sem.c      |    8 ++++----
 kernel/cobalt/posix/syscall.c  |    6 +++---
 kernel/cobalt/synch.c          |    4 ++--
 10 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 3510a8c..2318410 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -54,19 +54,19 @@
        } while (0)
 
 #ifndef CONFIG_XENO_OPT_DEBUG_COBALT
-#define CONFIG_XENO_OPT_DEBUG_COBALT 0
+#define CONFIG_XENO_OPT_DEBUG_COBALT   0
 #endif
 
 #ifndef CONFIG_XENO_OPT_DEBUG_CONTEXT
-#define CONFIG_XENO_OPT_DEBUG_CONTEXT 0
+#define CONFIG_XENO_OPT_DEBUG_CONTEXT  0
 #endif
 
 #ifndef CONFIG_XENO_OPT_DEBUG_LOCKING
-#define CONFIG_XENO_OPT_DEBUG_LOCKING 0
+#define CONFIG_XENO_OPT_DEBUG_LOCKING  0
 #endif
 
-#ifndef CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX
-#define CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX 0
+#ifndef CONFIG_XENO_OPT_DEBUG_USER
+#define CONFIG_XENO_OPT_DEBUG_USER     0
 #endif
 
 #define primary_mode_only()    XENO_BUGON(CONTEXT, ipipe_root_p)
diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index b6f6380..1900dc2 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -109,14 +109,14 @@ static inline struct xnthread *xnsynch_owner(struct 
xnsynch *synch)
        (((fastlock) & ~XNSYNCH_FLCLAIM) | ((enable) ? XNSYNCH_FLCLAIM : 0))
 #define xnsynch_fast_mask_claimed(fastlock) ((fastlock & ~XNSYNCH_FLCLAIM))
 
-#if XENO_DEBUG(SYNCH_RELAX)
+#if XENO_DEBUG(USER)
 
 void xnsynch_detect_relaxed_owner(struct xnsynch *synch,
                                  struct xnthread *sleeper);
 
 void xnsynch_detect_claimed_relax(struct xnthread *owner);
 
-#else /* !XENO_DEBUG(SYNCH_RELAX) */
+#else /* !XENO_DEBUG(USER) */
 
 static inline void xnsynch_detect_relaxed_owner(struct xnsynch *synch,
                                  struct xnthread *sleeper)
@@ -127,7 +127,7 @@ static inline void xnsynch_detect_claimed_relax(struct 
xnthread *owner)
 {
 }
 
-#endif /* !XENO_DEBUG(SYNCH_RELAX) */
+#endif /* !XENO_DEBUG(USER) */
 
 void xnsynch_init(struct xnsynch *synch, int flags,
                  atomic_long_t *fastlock);
diff --git a/include/cobalt/uapi/sysconf.h b/include/cobalt/uapi/sysconf.h
index f753116..b3fc407 100644
--- a/include/cobalt/uapi/sysconf.h
+++ b/include/cobalt/uapi/sysconf.h
@@ -25,8 +25,8 @@
 #   define _SC_COBALT_DEBUG_ASSERT     1
 #   define _SC_COBALT_DEBUG_CONTEXT    2
 #   define _SC_COBALT_DEBUG_LOCKING    4
-#   define _SC_COBALT_DEBUG_SYNCREL    8
-#   define _SC_COBALT_DEBUG_TRACEREL   16
+#   define _SC_COBALT_DEBUG_USER       8
+#   define _SC_COBALT_DEBUG_RELAX      16
 #define _SC_COBALT_POLICIES    4
 #   define _SC_COBALT_SCHED_FIFO       1
 #   define _SC_COBALT_SCHED_RR         2
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 2d61b7e..aeb621a 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -389,26 +389,27 @@ config XENO_OPT_DEBUG_LOCKING
        This option may induce a measurable overhead on low end
        machines.
 
-config XENO_OPT_DEBUG_SYNCH_RELAX
-       bool "Detect mutexes held in relaxed sections"
-       default y
+config XENO_OPT_DEBUG_USER
+       bool "User consistency checks"
        help
 
-       This option 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 for too long.
-
-       This option may introduce some overhead in case mutexes are
-       highly contended. Use this feature for debugging purposes
+       This option enables a set of consistency checks for detecting
+       wrong runtime behavior in user applications.
+
+       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.
+
+       This option may introduce some overhead (e.g. with highly
+       contended mutexes). Use this feature for debugging purposes
        only.
 
 config XENO_OPT_DEBUG_TRACE_RELAX
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index c0c4353..1777a6f 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -185,7 +185,7 @@ static inline int cobalt_cond_timedwait_prologue(struct 
xnthread *cur,
                goto unlock_and_return;
        }
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
        if (cond->owningq != cobalt_kqueues(cond->attr.pshared)) {
                err = -EPERM;
                goto unlock_and_return;
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index 8c77d87..e000202 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -102,10 +102,10 @@ static inline int cobalt_mutex_acquire(struct xnthread 
*cur,
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, struct cobalt_mutex))
                return -EINVAL;
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
        if (mutex->owningq != cobalt_kqueues(mutex->attr.pshared))
                return -EPERM;
-#endif /* XENO_DEBUG(COBALT) */
+#endif
 
        if (xnsynch_owner_check(&mutex->synchbase, cur) == 0)
                return -EBUSY;
@@ -154,11 +154,10 @@ int cobalt_mutex_release(struct xnthread *cur,
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, struct cobalt_mutex))
                 return -EINVAL;
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
        if (mutex->owningq != cobalt_kqueues(mutex->attr.pshared))
                return -EPERM;
-#endif /* XENO_DEBUG(COBALT) */
-
+#endif
        datp = container_of(mutex->synchbase.fastlock, struct mutex_dat, owner);
        flags = datp->flags;
        need_resched = 0;
@@ -193,11 +192,11 @@ int cobalt_mutex_timedlock_break(struct cobalt_mutex 
*mutex,
        switch(mutex->attr.type) {
        case PTHREAD_MUTEX_NORMAL:
                /* Attempting to relock a normal mutex, deadlock. */
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
                printk(XENO_WARN
                       "thread %s deadlocks on non-recursive mutex\n",
                       curr->name);
-#endif /* XENO_DEBUG(COBALT) */
+#endif
                cobalt_mutex_acquire_unchecked(curr, mutex, timed, u_ts);
                break;
 
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index ac0b96c..c71d1ce 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -745,7 +745,7 @@ static inline int handle_exception(struct ipipe_trap_data 
*d)
         */
        thread->regs = xnarch_fault_regs(d);
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(COBALT) || XENO_DEBUG(USER)
        if (!user_mode(d->regs)) {
                xntrace_panic_freeze();
                printk(XENO_WARN
@@ -762,7 +762,7 @@ static inline int handle_exception(struct ipipe_trap_data 
*d)
                       xnarch_fault_trap(d),
                       xnarch_fault_pc(d),
                       xnthread_host_pid(thread));
-#endif /* XENO_DEBUG(COBALT) */
+#endif
 
        if (xnarch_fault_pf_p(d))
                /*
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 93d5ea1..bba8f48 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -220,10 +220,10 @@ static inline int sem_trywait_inner(struct cobalt_sem 
*sem)
        if (sem == NULL || sem->magic != COBALT_SEM_MAGIC)
                return -EINVAL;
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
        if (sem->owningq != sem_kqueue(sem))
                return -EPERM;
-#endif /* XENO_DEBUG(COBALT) */
+#endif
 
        if (atomic_long_sub_return(1, &sem->datp->value) < 0)
                return -EAGAIN;
@@ -327,10 +327,10 @@ int sem_post_inner(struct cobalt_sem *sem, struct 
cobalt_kqueues *ownq, int bcas
        if (sem == NULL || sem->magic != COBALT_SEM_MAGIC)
                return -EINVAL;
 
-#if XENO_DEBUG(COBALT)
+#if XENO_DEBUG(USER)
        if (ownq && ownq != sem_kqueue(sem))
                return -EPERM;
-#endif /* XENO_DEBUG(COBALT) */
+#endif
 
        if (atomic_long_read(&sem->datp->value) == SEM_VALUE_MAX)
                return -EINVAL;
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index ae8c52f..0f09e5d 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -693,10 +693,10 @@ static int cobalt_sysconf(int option, void __user *u_buf, 
size_t u_bufsz)
                        val |= _SC_COBALT_DEBUG_CONTEXT;
                if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_LOCKING))
                        val |= _SC_COBALT_DEBUG_LOCKING;
-               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX))
-                       val |= _SC_COBALT_DEBUG_SYNCREL;
+               if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_USER))
+                       val |= _SC_COBALT_DEBUG_USER;
                if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_TRACE_RELAX))
-                       val |= _SC_COBALT_DEBUG_TRACEREL;
+                       val |= _SC_COBALT_DEBUG_RELAX;
                break;
        case _SC_COBALT_WATCHDOG:
 #if IS_ENABLED(CONFIG_XENO_OPT_WATCHDOG)
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 7d4130f..b6cf84e 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -819,7 +819,7 @@ void xnsynch_release_all_ownerships(struct xnthread *thread)
 }
 EXPORT_SYMBOL_GPL(xnsynch_release_all_ownerships);
 
-#if XENO_DEBUG(SYNCH_RELAX)
+#if XENO_DEBUG(USER)
 
 /*
  * Detect when a thread is about to sleep on a synchronization
@@ -861,6 +861,6 @@ void xnsynch_detect_claimed_relax(struct xnthread *owner)
        }
 }
 
-#endif /* XENO_DEBUG(SYNCH_RELAX) */
+#endif /* XENO_DEBUG(USER) */
 
 /** @} */


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

Reply via email to