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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Aug 28 11:11:48 2013 +0200

copperplate: drop __THREAD_S_NOPREEMPT bit

This flag is redundant, since we already have the scheduler lock
nesting count available. Therefore threadobj_get_lockdepth() > 0
implies __THREAD_S_NOPREEMPT is set.

---

 include/copperplate/threadobj.h   |   21 ++++++++++++---------
 lib/copperplate/regd/fs-common.c  |    1 +
 lib/copperplate/regd/fs-mercury.c |    2 +-
 lib/copperplate/regd/sysregfs.h   |    1 +
 lib/copperplate/threadobj.c       |   14 ++++++--------
 lib/vxworks/taskLib.c             |    4 ++--
 6 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 97985ff..b7af004 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -43,6 +43,8 @@ struct threadobj_corespec {
 struct threadobj_stat {
        /** Current CPU for thread. */
        int cpu;
+       /** Scheduler lock nesting count. */
+       int schedlock;
        /** Cobalt thread status bits. */
        unsigned long status;
        /** Execution time in primary mode (ns). */
@@ -91,6 +93,8 @@ struct threadobj_corespec {
 struct threadobj_stat {
        /** Current CPU for thread. */
        int cpu;
+       /** Scheduler lock nesting count. */
+       int schedlock;
        /** Mercury thread status bits. */
        unsigned long status;
        /** Current timeout value (ns). */
@@ -112,15 +116,14 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 /*
  * threadobj->status, updated with ->lock held.
  */
-#define __THREAD_S_NOPREEMPT   (1 << 0)        /* Holds the scheduler lock. */
-#define __THREAD_S_RR          (1 << 1)        /* Undergoes round-robin. */
-#define __THREAD_S_STARTED     (1 << 2)        /* threadobj_start() called. */
-#define __THREAD_S_WARMUP      (1 << 3)        /* threadobj_prologue() not 
called yet. */
-#define __THREAD_S_ABORTED     (1 << 4)        /* Cancelled before start. */
-#define __THREAD_S_LOCKED      (1 << 5)        /* threadobj_lock() granted 
(debug only). */
-#define __THREAD_S_ACTIVE      (1 << 6)        /* Running user code. */
-#define __THREAD_S_SUSPENDED   (1 << 7)        /* Suspended via 
threadobj_suspend(). */
-#define __THREAD_S_SAFE                (1 << 8)        /* TCB release 
deferred. */
+#define __THREAD_S_RR          (1 << 0)        /* Undergoes round-robin. */
+#define __THREAD_S_STARTED     (1 << 1)        /* threadobj_start() called. */
+#define __THREAD_S_WARMUP      (1 << 2)        /* threadobj_prologue() not 
called yet. */
+#define __THREAD_S_ABORTED     (1 << 3)        /* Cancelled before start. */
+#define __THREAD_S_LOCKED      (1 << 4)        /* threadobj_lock() granted 
(debug only). */
+#define __THREAD_S_ACTIVE      (1 << 5)        /* Running user code. */
+#define __THREAD_S_SUSPENDED   (1 << 6)        /* Suspended via 
threadobj_suspend(). */
+#define __THREAD_S_SAFE                (1 << 7)        /* TCB release 
deferred. */
 #define __THREAD_S_DEBUG       (1 << 31)       /* Debug mode enabled. */
 /*
  * threadobj->run_state, locklessly updated by "current", merged
diff --git a/lib/copperplate/regd/fs-common.c b/lib/copperplate/regd/fs-common.c
index 270199e..d4e2b78 100644
--- a/lib/copperplate/regd/fs-common.c
+++ b/lib/copperplate/regd/fs-common.c
@@ -121,6 +121,7 @@ ssize_t read_threads(struct fsobj *fsobj, char *buf,
                p->status = statbuf.status;
                p->cpu = statbuf.cpu;
                p->timeout = statbuf.timeout;
+               p->schedlock = statbuf.schedlock;
                p++;
        }
 
diff --git a/lib/copperplate/regd/fs-mercury.c 
b/lib/copperplate/regd/fs-mercury.c
index d53254c..a6a95a5 100644
--- a/lib/copperplate/regd/fs-mercury.c
+++ b/lib/copperplate/regd/fs-mercury.c
@@ -72,7 +72,7 @@ char *format_thread_status(const struct thread_data *p, char 
*buf, size_t len)
        else
                *wp++ = 'U';
 
-       if (p->status & __THREAD_S_NOPREEMPT)
+       if (p->schedlock > 0)
                *wp++ = 'l';
 
        if (p->status & __THREAD_S_RR)
diff --git a/lib/copperplate/regd/sysregfs.h b/lib/copperplate/regd/sysregfs.h
index 2a780ee..13f7e61 100644
--- a/lib/copperplate/regd/sysregfs.h
+++ b/lib/copperplate/regd/sysregfs.h
@@ -39,6 +39,7 @@ struct thread_data {
        int priority;
        int policy;
        int cpu;
+       int schedlock;
        ticks_t timeout;
        unsigned long status;
 };
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 8761571..64eb138 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -183,7 +183,6 @@ int threadobj_lock_sched(void) /* current->lock held */
        if (current->schedlock_depth++ > 0)
                return 0;
 
-       current->status |= __THREAD_S_NOPREEMPT;
        /*
         * In essence, we can't be scheduled out as a result of
         * locking the scheduler, so no need to drop the thread lock
@@ -210,8 +209,6 @@ int threadobj_unlock_sched(void) /* current->lock held */
        if (--current->schedlock_depth > 0)
                return 0;
 
-       current->status &= ~__THREAD_S_NOPREEMPT;
-
        return __bt(-pthread_set_mode_np(PTHREAD_LOCK_SCHED, 0, NULL));
 }
 
@@ -331,6 +328,7 @@ int threadobj_stat(struct threadobj *thobj, struct 
threadobj_stat *p) /* thobj->
        p->xsc = stat.xsc;
        p->pf = stat.pf;
        p->timeout = stat.timeout;
+       p->schedlock = thobj->schedlock_depth;
 
        return 0;
 }
@@ -501,7 +499,6 @@ int threadobj_lock_sched(void) /* current->lock held */
 
        current->core.prio_unlocked = current->priority;
        current->core.policy_unlocked = current->policy;
-       current->status |= __THREAD_S_NOPREEMPT;
        current->priority = threadobj_lock_prio;
        current->policy = SCHED_RT;
        param.sched_priority = threadobj_lock_prio;
@@ -524,7 +521,6 @@ int threadobj_unlock_sched(void) /* current->lock held */
        if (--current->schedlock_depth > 0)
                return 0;
 
-       current->status &= ~__THREAD_S_NOPREEMPT;
        current->priority = current->core.prio_unlocked;
        param.sched_priority = current->core.prio_unlocked;
        policy = current->core.policy_unlocked;
@@ -548,7 +544,7 @@ int threadobj_set_priority(struct threadobj *thobj, int 
prio) /* thobj->lock hel
         * the target thread holds the scheduler lock, but only record
         * the level to set when unlocking.
         */
-       if (thobj->status & __THREAD_S_NOPREEMPT) {
+       if (thobj->schedlock_depth > 0) {
                thobj->core.prio_unlocked = prio;
                thobj->core.policy_unlocked = prio ? SCHED_RT : SCHED_OTHER;
                threadobj_unlock(thobj);
@@ -581,7 +577,7 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current->lock h
 
        __threadobj_check_locked(current);
 
-       if (current->status & __THREAD_S_NOPREEMPT)
+       if (current->schedlock_depth > 0)
                old |= __THREAD_M_LOCK;
 
        if (setmask & __THREAD_M_LOCK) {
@@ -734,6 +730,8 @@ int threadobj_stat(struct threadobj *thobj,
        } else
                stat->timeout = 0;
 
+       stat->schedlock = thobj->schedlock_depth;
+
        return 0;
 }
 
@@ -1188,7 +1186,7 @@ int threadobj_set_rr(struct threadobj *thobj, struct 
timespec *quantum)
         * logic simpler in the Mercury case with respect to tracking
         * the current scheduling parameters.
         */
-       if (thobj->status & __THREAD_S_NOPREEMPT)
+       if (thobj->schedlock_depth > 0)
                return -EINVAL;
 
        return __bt(set_rr(thobj, quantum));
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index 5f2514d..b3244b4 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -168,9 +168,9 @@ static inline char *task_decode_status(struct wind_task 
*task, char *buf)
        int status;
 
        *buf = '\0';
-       status = threadobj_get_status(&task->thobj);
-       if (status & __THREAD_S_NOPREEMPT)
+       if (threadobj_get_lockdepth(&task->thobj) > 0)
                strcat(buf, "+sched_lock");
+       status = threadobj_get_status(&task->thobj);
        if (status & __THREAD_S_RR)
                strcat(buf, "+sched_rr");
        if (status & __THREAD_S_SUSPENDED)


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

Reply via email to