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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jan  4 18:41:39 2012 +0100

cobalt: introduce user visible state window

We can't reuse the common thread state flags to hold the monitor grant
condition (former XNGRANT), since the u_mode area should be altered by
the owner thread only, unless all accesses are changed to atomic ops,
which would be overkill.

To fix this, we replace the former u_mode data by a more generic user
visible structure shared between the nucleus and the Cobalt libraries,
in which the copy of the kernel thread state bits is stored separately
from the monitor grant flag.

---

 include/asm-generic/bits/current.h |   22 ++++----
 include/cobalt/nucleus/shadow.h    |    3 +-
 include/cobalt/nucleus/thread.h    |   41 +++++++++++-----
 include/copperplate/threadobj.h    |    4 +-
 kernel/cobalt/monitor.c            |   12 ++--
 kernel/cobalt/nucleus/shadow.c     |   67 ++++++++++++--------------
 kernel/cobalt/thread.c             |   92 ++++++++++++++++++------------------
 kernel/cobalt/thread.h             |    8 ++--
 lib/cobalt/current.c               |   15 +++---
 lib/cobalt/internal.c              |   16 ++++---
 lib/cobalt/internal.h              |   11 ++--
 lib/cobalt/thread.c                |    6 +-
 lib/copperplate/syncobj.c          |    2 +-
 lib/copperplate/threadobj.c        |    2 +-
 14 files changed, 159 insertions(+), 142 deletions(-)

diff --git a/include/asm-generic/bits/current.h 
b/include/asm-generic/bits/current.h
index 7b70794..2f7f1a9 100644
--- a/include/asm-generic/bits/current.h
+++ b/include/asm-generic/bits/current.h
@@ -4,7 +4,7 @@
 #include <pthread.h>
 #include <nucleus/thread.h>
 
-extern pthread_key_t xeno_current_mode_key;
+extern pthread_key_t xeno_current_window_key;
 
 xnhandle_t xeno_slow_get_current(void);
 
@@ -12,7 +12,7 @@ xnhandle_t xeno_slow_get_current(void);
 extern __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
 xnhandle_t xeno_current;
 extern __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
-unsigned long *xeno_current_mode;
+struct xnthread_user_window *xeno_current_window;
 
 static inline xnhandle_t xeno_get_current(void)
 {
@@ -23,12 +23,12 @@ static inline xnhandle_t xeno_get_current(void)
 
 static inline unsigned long xeno_get_current_mode(void)
 {
-       return xeno_current_mode ? *xeno_current_mode : XNRELAX;
+       return xeno_current_window ? xeno_current_window->state : XNRELAX;
 }
 
-static inline unsigned long *xeno_get_current_mode_ptr(void)
+static inline struct xnthread_user_window *xeno_get_current_window(void)
 {
-       return xeno_current ? xeno_current_mode : NULL;
+       return xeno_current ? xeno_current_window : NULL;
 }
 
 #else /* ! HAVE_TLS */
@@ -53,16 +53,16 @@ static inline xnhandle_t xeno_get_current_fast(void)
 
 static inline unsigned long xeno_get_current_mode(void)
 {
-       unsigned long *mode;
+       struct xnthread_user_window *window;
 
-       mode = pthread_getspecific(xeno_current_mode_key);
+       window = pthread_getspecific(xeno_current_window_key);
 
-       return mode ? *mode : XNRELAX;
+       return window ? window->state : XNRELAX;
 }
 
-static inline unsigned long *xeno_get_current_mode_ptr(void)
+static inline struct xnthread_user_window *xeno_get_current_window(void)
 {
-       return pthread_getspecific(xeno_current_mode_key);
+       return pthread_getspecific(xeno_current_window_key);
 }
 
 #endif /* ! HAVE_TLS */
@@ -71,6 +71,6 @@ void xeno_init_current_keys(void);
 
 void xeno_set_current(void);
 
-void xeno_set_current_mode(unsigned long offset);
+void xeno_set_current_window(unsigned long offset);
 
 #endif /* _XENO_ASM_GENERIC_CURRENT_H */
diff --git a/include/cobalt/nucleus/shadow.h b/include/cobalt/nucleus/shadow.h
index 7088d5a..db44228 100644
--- a/include/cobalt/nucleus/shadow.h
+++ b/include/cobalt/nucleus/shadow.h
@@ -30,6 +30,7 @@
 #define XNSHADOW_CLIENT_DETACH  1
 
 struct xnthread;
+struct xnthread_user_window;
 struct xnmutex;
 struct pt_regs;
 struct timespec;
@@ -79,7 +80,7 @@ void xnshadow_release_events(void);
 
 int xnshadow_map(struct xnthread *thread,
                 xncompletion_t __user *u_completion,
-                unsigned long __user *u_mode_offset);
+                unsigned long __user *u_window_offset);
 
 void xnshadow_unmap(struct xnthread *thread);
 
diff --git a/include/cobalt/nucleus/thread.h b/include/cobalt/nucleus/thread.h
index 1eeee8e..598a14f 100644
--- a/include/cobalt/nucleus/thread.h
+++ b/include/cobalt/nucleus/thread.h
@@ -50,18 +50,11 @@
 #define XNRRB     0x00008000 /**< Undergoes a round-robin scheduling */
 #define XNASDI    0x00010000 /**< ASR are disabled */
 #define XNDEFCAN  0x00020000 /**< Deferred cancelability mode (self-set only) 
*/
-#define XNGRANT   0x00040000 /**< Granted monitor-protected resource */
-
-/*
- * Some skins may depend on the following fields to live in the high
- * 16-bit word, in order to be combined with the emulated RTOS flags
- * which use the low one, so don't change them carelessly.
- */
-#define XNTRAPSW  0x00080000 /**< Trap execution mode switches */
-#define XNFPU     0x00100000 /**< Thread uses FPU */
-#define XNSHADOW  0x00200000 /**< Shadow thread */
-#define XNROOT    0x00400000 /**< Root thread (that is, Linux/IDLE) */
-#define XNOTHER   0x00800000 /**< Non real-time shadow (prio=0) */
+#define XNTRAPSW  0x00040000 /**< Trap execution mode switches */
+#define XNFPU     0x00080000 /**< Thread uses FPU */
+#define XNSHADOW  0x00100000 /**< Shadow thread */
+#define XNROOT    0x00200000 /**< Root thread (that is, Linux/IDLE) */
+#define XNOTHER   0x00400000 /**< Non real-time shadow (prio=0) */
 
 /*! @} */ /* Ends doxygen comment group: nucleus_state_flags */
 
@@ -149,6 +142,11 @@ typedef struct xnthread_info {
 
 } xnthread_info_t;
 
+struct xnthread_user_window {
+       unsigned long state;
+       unsigned int granted : 1;
+};
+
 #ifdef __KERNEL__
 
 #include <nucleus/stat.h>
@@ -293,7 +291,7 @@ typedef struct xnthread {
        void *cookie;           /* Cookie to pass to the entry routine */
 
        struct pt_regs *regs;           /* Current register frame */
-       unsigned long __user *u_mode;   /* Thread mode variable in userland. */
+       struct xnthread_user_window *u_window;  /* Data visible from userland. 
*/
 #ifdef CONFIG_XENO_OPT_DEBUG
        const char *exe_path;   /* Executable path */
        u32 proghash;           /* Hash value for exe_path */
@@ -378,6 +376,23 @@ struct xnthread *xnthread_lookup(xnhandle_t threadh)
        return (thread && xnthread_handle(thread) == threadh) ? thread : NULL;
 }
 
+static inline void xnthread_sync_window(struct xnthread *thread)
+{
+       thread->u_window->state = thread->state;
+}
+
+static inline
+void xnthread_clear_sync_window(struct xnthread *thread, int bits)
+{
+       thread->u_window->state = thread->state & ~bits;
+}
+
+static inline
+void xnthread_set_sync_window(struct xnthread *thread, int bits)
+{
+       thread->u_window->state = thread->state | bits;
+}
+
 /*
  * XXX: Mutual dependency issue with synch.h, we have to define
  * xnsynch_release() here.
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 1e77e2e..d086dcb 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -30,9 +30,11 @@
 
 #ifdef CONFIG_XENO_COBALT
 
+struct xnthread_user_window;
+
 struct threadobj_corespec {
        xnhandle_t handle;
-       unsigned long *u_mode;
+       struct xnthread_user_window *u_window;
 };
 
 struct threadobj_stat {
diff --git a/kernel/cobalt/monitor.c b/kernel/cobalt/monitor.c
index 1416398..da51a39 100644
--- a/kernel/cobalt/monitor.c
+++ b/kernel/cobalt/monitor.c
@@ -192,13 +192,13 @@ static void cobalt_monitor_wakeup(struct cobalt_monitor 
*mon)
                h = nextq(&mon->waiters, h);
                p = &tid->threadbase;
                /*
-                * A thread might receive XNGRANT albeit it does not
-                * wait on a monitor, or it might have timed out
-                * before we got there, so we really have to check
+                * A thread might receive a grant signal albeit it
+                * does not wait on a monitor, or it might have timed
+                * out before we got there, so we really have to check
                 * that ->wchan does match our sleep queue.
                 */
-               if (bcast || ((*p->u_mode & XNGRANT) &&
-                             p->wchan == &tid->monitor_synch)) {
+               if (bcast ||
+                   (p->u_window->granted && p->wchan == &tid->monitor_synch)) {
                        xnsynch_wakeup_this_sleeper(&tid->monitor_synch,
                                                    &p->plink);
                        removeq(&mon->waiters, &tid->monitor_link);
@@ -272,7 +272,7 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_monsh,
        if (event & COBALT_MONITOR_WAITDRAIN)
                synch = &mon->drain;
        else {
-               *cur->threadbase.u_mode &= ~XNGRANT;
+               cur->threadbase.u_window->granted = 0;
                appendq(&mon->waiters, &cur->monitor_link);
                cur->monitor_queued = 1;
        }
diff --git a/kernel/cobalt/nucleus/shadow.c b/kernel/cobalt/nucleus/shadow.c
index 0f4cd3f..9ebec62 100644
--- a/kernel/cobalt/nucleus/shadow.c
+++ b/kernel/cobalt/nucleus/shadow.c
@@ -400,8 +400,7 @@ redo:
                goto redo;
        }
 
-       if (thread->u_mode)
-               *(thread->u_mode) = thread->state & ~XNRELAX;
+       xnthread_clear_sync_window(thread, XNRELAX);
 
        /*
         * Set up the request to move "current" from the Linux domain
@@ -533,12 +532,11 @@ int xnshadow_harden(void)
                   "thread %p name %s comm %s",
                   thread, xnthread_name(thread), p->comm);
 
-       if (thread->u_mode)
-               *(thread->u_mode) = thread->state & ~XNRELAX;
+       xnthread_clear_sync_window(thread, XNRELAX);
 
        ret = __ipipe_migrate_head();
        if (ret) {
-               *(thread->u_mode) = thread->state | XNRELAX;
+               xnthread_set_sync_window(thread, XNRELAX);
                return ret;
        }
 
@@ -678,22 +676,24 @@ void xnshadow_relax(int notify, int reason)
        }
 
 #ifdef CONFIG_SMP
-       /* If the shadow thread changed its CPU affinity while in
-          primary mode, reset the CPU affinity of its Linux
-          counter-part when returning to secondary mode. [Actually,
-          there is no service changing the CPU affinity from primary
-          mode available from the nucleus --rpm]. */
+       /*
+        * If the shadow thread changed its CPU affinity while in
+        * primary mode, reset the CPU affinity of its Linux
+        * counter-part when returning to secondary mode. [Actually,
+        * there is no service changing the CPU affinity from primary
+        * mode available from the nucleus --rpm].
+        */
        if (xnthread_test_info(thread, XNAFFSET)) {
                xnthread_clear_info(thread, XNAFFSET);
                set_cpus_allowed(p, xnthread_affinity(thread));
        }
 #endif /* CONFIG_SMP */
 
-       /* "current" is now running into the Linux domain on behalf of the
-          root thread. */
-
-       if (thread->u_mode)
-               *(thread->u_mode) = thread->state;
+       /*
+        * "current" is now running into the Linux domain on behalf of
+        * the root thread.
+        */
+       xnthread_sync_window(thread);
 
        trace_mark(xn_nucleus, shadow_relaxed,
                  "thread %p thread_name %s comm %s",
@@ -832,7 +832,7 @@ static inline void destroy_threadinfo(void)
 }
 
 /**
- * @fn int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion, unsigned long __user *u_mode_offset)
+ * @fn int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion, unsigned long __user *u_window_offset)
  * @internal
  * @brief Create a shadow thread context.
  *
@@ -856,12 +856,10 @@ static inline void destroy_threadinfo(void)
  * immediately started and "current" immediately resumes in the Xenomai
  * domain from this service.
  *
- * @param u_mode_offset is the address of a user space address where
- * we will store the offset of the "u_mode" thread variable in the
- * process shared heap. This thread variable reflects the current
- * thread mode (primary or secondary). The nucleus will try to update
- * the variable before switching to secondary  or after switching from
- * primary mode.
+ * @param u_window_offset will receive the offset of the per-thread
+ * "u_window" structure in the process shared heap associated to @a
+ * thread. This structure reflects thread state information visible
+ * from userland through a shared memory window.
  *
  * @return 0 is returned on success. Otherwise:
  *
@@ -892,12 +890,12 @@ static inline void destroy_threadinfo(void)
  */
 
 int xnshadow_map(xnthread_t *thread, xncompletion_t __user *u_completion,
-                unsigned long __user *u_mode_offset)
+                unsigned long __user *u_window_offset)
 {
+       struct xnthread_user_window *u_window;
        struct xnthread_start_attr attr;
        xnarch_cpumask_t affinity;
        struct xnsys_ppd *sys_ppd;
-       unsigned long *u_mode;
        xnheap_t *sem_heap;
        spl_t s;
        int ret;
@@ -908,7 +906,7 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion,
        if (xnshadow_current() || xnthread_test_state(thread, XNMAPPED))
                return -EBUSY;
 
-       if (!access_wok(u_mode_offset, sizeof(*u_mode_offset)))
+       if (!access_wok(u_window_offset, sizeof(*u_window_offset)))
                return -EFAULT;
 
 #ifdef CONFIG_MMU
@@ -930,8 +928,8 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion,
        xnlock_put_irqrestore(&nklock, s);
 
        sem_heap = &sys_ppd->sem_heap;
-       u_mode = xnheap_alloc(sem_heap, sizeof(*u_mode));
-       if (!u_mode)
+       u_window = xnheap_alloc(sem_heap, sizeof(*u_window));
+       if (u_window == NULL)
                return -ENOMEM;
 
        /* Restrict affinity to a single CPU of nkaffinity & current set. */
@@ -947,8 +945,8 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion,
        xnarch_init_shadow_tcb(xnthread_archtcb(thread), thread,
                               xnthread_name(thread));
 
-       thread->u_mode = u_mode;
-       __xn_put_user(xnheap_mapped_offset(sem_heap, u_mode), u_mode_offset);
+       thread->u_window = u_window;
+       __xn_put_user(xnheap_mapped_offset(sem_heap, u_window), 
u_window_offset);
 
        xnthread_set_state(thread, XNMAPPED);
        xnpod_suspend_thread(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
@@ -990,8 +988,7 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t __user 
*u_completion,
        if (ret)
                return ret;
 
-       if (thread->u_mode)
-               *(thread->u_mode) = thread->state;
+       xnthread_sync_window(thread);
 
        ret = xnshadow_harden();
 
@@ -1021,8 +1018,8 @@ void xnshadow_unmap(xnthread_t *thread)
        xnthread_clear_state(thread, XNMAPPED);
 
        sys_ppd = xnsys_ppd_get(0);
-       xnheap_free(&sys_ppd->sem_heap, thread->u_mode);
-       thread->u_mode = NULL;
+       xnheap_free(&sys_ppd->sem_heap, thread->u_window);
+       thread->u_window = NULL;
 
        xnarch_atomic_dec(&sys_ppd->refcnt);
 
@@ -2115,7 +2112,7 @@ restart:
        /* Update the stats and userland-visible state. */
        if (thread) {
                xnstat_counter_inc(&thread->stat.xsc);
-               *thread->u_mode = thread->state;
+               xnthread_sync_window(thread);
        }
 
        trace_mark(xn_nucleus, syscall_histage_exit,
@@ -2290,7 +2287,7 @@ restart:
        /* Update the stats and userland-visible state. */
        if (thread) {
                xnstat_counter_inc(&thread->stat.xsc);
-               *thread->u_mode = thread->state;
+               xnthread_sync_window(thread);
        }
 
        trace_mark(xn_nucleus, syscall_lostage_exit,
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 99e7d26..d3fbb86 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -511,7 +511,7 @@ static inline int pthread_make_periodic_np(pthread_t thread,
 {
 
        xnticks_t start, period;
-       int err;
+       int ret;
        spl_t s;
 
        if (clock_id != CLOCK_MONOTONIC &&
@@ -522,20 +522,20 @@ static inline int pthread_make_periodic_np(pthread_t 
thread,
        xnlock_get_irqsave(&nklock, s);
 
        if (!cobalt_obj_active(thread, COBALT_THREAD_MAGIC, struct 
cobalt_thread)) {
-               err = -ESRCH;
+               ret = -ESRCH;
                goto unlock_and_exit;
        }
 
        start = ts2ns(starttp);
        period = ts2ns(periodtp);
-       err = xnpod_set_thread_periodic(&thread->threadbase, start,
+       ret = xnpod_set_thread_periodic(&thread->threadbase, start,
                                        clock_flag(TIMER_ABSTIME, clock_id),
                                        period);
       unlock_and_exit:
 
        xnlock_put_irqrestore(&nklock, s);
 
-       return err;
+       return ret;
 }
 
 /**
@@ -848,12 +848,12 @@ static inline int pthread_setschedparam_ex(pthread_t tid, 
int pol,
 int cobalt_thread_setschedparam(unsigned long tid,
                                int policy,
                                struct sched_param __user *u_param,
-                               unsigned long __user *u_mode_offset,
+                               unsigned long __user *u_window_offset,
                                int __user *u_promoted)
 {
        struct sched_param param;
        struct cobalt_hkey hkey;
-       int err, promoted = 0;
+       int ret, promoted = 0;
        pthread_t k_tid;
 
        if (__xn_safe_copy_from_user(&param, u_param, sizeof(param)))
@@ -863,43 +863,43 @@ int cobalt_thread_setschedparam(unsigned long tid,
        hkey.mm = current->mm;
        k_tid = cobalt_thread_find(&hkey);
 
-       if (!k_tid && u_mode_offset) {
+       if (k_tid == NULL && u_window_offset) {
                /*
                 * If the syscall applies to "current", and the latter
                 * is not a Xenomai thread already, then shadow it.
                 */
-               k_tid = cobalt_thread_shadow(current, &hkey, u_mode_offset);
+               k_tid = cobalt_thread_shadow(current, &hkey, u_window_offset);
                if (IS_ERR(k_tid))
                        return PTR_ERR(k_tid);
 
                promoted = 1;
        }
        if (k_tid)
-               err = pthread_setschedparam(k_tid, policy, &param);
+               ret = pthread_setschedparam(k_tid, policy, &param);
        else
                /*
                 * target thread is not a real-time thread, and is not current,
                 * so can not be promoted, try again with the real
                 * pthread_setschedparam service.
                 */
-               err = -EPERM;
+               ret = -EPERM;
 
-       if (err == 0 &&
+       if (ret == 0 &&
            __xn_safe_copy_to_user(u_promoted, &promoted, sizeof(promoted)))
-               err = -EFAULT;
+               ret = -EFAULT;
 
-       return err;
+       return ret;
 }
 
 int cobalt_thread_setschedparam_ex(unsigned long tid,
                                   int policy,
                                   struct sched_param __user *u_param,
-                                  unsigned long __user *u_mode_offset,
+                                  unsigned long __user *u_window_offset,
                                   int __user *u_promoted)
 {
        struct sched_param_ex param;
        struct cobalt_hkey hkey;
-       int err, promoted = 0;
+       int ret, promoted = 0;
        pthread_t k_tid;
 
        if (__xn_safe_copy_from_user(&param, u_param, sizeof(param)))
@@ -909,23 +909,23 @@ int cobalt_thread_setschedparam_ex(unsigned long tid,
        hkey.mm = current->mm;
        k_tid = cobalt_thread_find(&hkey);
 
-       if (!k_tid && u_mode_offset) {
-               k_tid = cobalt_thread_shadow(current, &hkey, u_mode_offset);
+       if (k_tid == NULL && u_window_offset) {
+               k_tid = cobalt_thread_shadow(current, &hkey, u_window_offset);
                if (IS_ERR(k_tid))
                        return PTR_ERR(k_tid);
 
                promoted = 1;
        }
        if (k_tid)
-               err = pthread_setschedparam_ex(k_tid, policy, &param);
+               ret = pthread_setschedparam_ex(k_tid, policy, &param);
        else
-               err = -EPERM;
+               ret = -EPERM;
 
-       if (err == 0 &&
+       if (ret == 0 &&
            __xn_safe_copy_to_user(u_promoted, &promoted, sizeof(promoted)))
-               err = -EFAULT;
+               ret = -EFAULT;
 
-       return err;
+       return ret;
 }
 
 
@@ -949,7 +949,7 @@ int cobalt_thread_setschedparam_ex(unsigned long tid,
 
 int cobalt_thread_create(unsigned long tid, int policy,
                         struct sched_param_ex __user *u_param,
-                        unsigned long __user *u_mode)
+                        unsigned long __user *u_window_offset)
 {
        struct task_struct *p = current;
        struct sched_param_ex param;
@@ -986,7 +986,7 @@ int cobalt_thread_create(unsigned long tid, int policy,
                return ret;
 
        h_tid = task_pid_vnr(p);
-       ret = xnshadow_map(&k_tid->threadbase, NULL, u_mode);
+       ret = xnshadow_map(&k_tid->threadbase, NULL, u_window_offset);
        if (ret)
                goto fail;
 
@@ -1007,38 +1007,38 @@ fail:
 
 pthread_t cobalt_thread_shadow(struct task_struct *p,
                               struct cobalt_hkey *hkey,
-                              unsigned long __user *u_mode_offset)
+                              unsigned long __user *u_window_offset)
 {
        pthread_attr_t attr;
        pthread_t k_tid;
        pid_t h_tid;
-       int err;
+       int ret;
 
        attr = default_thread_attr;
        attr.detachstate = PTHREAD_CREATE_DETACHED;
        attr.name = p->comm;
 
-       err = pthread_create(&k_tid, &attr);
+       ret = pthread_create(&k_tid, &attr);
 
-       if (err)
-               return ERR_PTR(-err);
+       if (ret)
+               return ERR_PTR(-ret);
 
        h_tid = task_pid_vnr(p);
-       err = xnshadow_map(&k_tid->threadbase, NULL, u_mode_offset);
+       ret = xnshadow_map(&k_tid->threadbase, NULL, u_window_offset);
        /*
         * From now on, we run in primary mode, so we refrain from
         * calling regular kernel services (e.g. like
         * task_pid_vnr()).
         */
-       if (err == 0 && !cobalt_thread_hash(hkey, k_tid, h_tid))
-               err = -EAGAIN;
+       if (ret == 0 && !cobalt_thread_hash(hkey, k_tid, h_tid))
+               ret = -EAGAIN;
 
-       if (err)
+       if (ret)
                xnpod_delete_thread(&k_tid->threadbase);
        else
                k_tid->hkey = *hkey;
 
-       return err ? ERR_PTR(err) : k_tid;
+       return ret ? ERR_PTR(ret) : k_tid;
 }
 
 int cobalt_thread_make_periodic_np(unsigned long tid,
@@ -1066,14 +1066,14 @@ int cobalt_thread_make_periodic_np(unsigned long tid,
 int cobalt_thread_wait_np(unsigned long __user *u_overruns)
 {
        unsigned long overruns;
-       int err;
+       int ret;
 
-       err = xnpod_wait_thread_period(&overruns);
+       ret = xnpod_wait_thread_period(&overruns);
 
-       if (u_overruns && (err == 0 || err == -ETIMEDOUT))
+       if (u_overruns && (ret == 0 || ret == -ETIMEDOUT))
                __xn_put_user(overruns, u_overruns);
 
-       return err;
+       return ret;
 }
 
 int cobalt_thread_set_mode_np(int clrmask, int setmask, int __user *u_mode_r)
@@ -1248,7 +1248,7 @@ int cobalt_thread_getschedparam(unsigned long tid,
        struct sched_param param;
        struct cobalt_hkey hkey;
        pthread_t k_tid;
-       int policy, err;
+       int policy, ret;
 
        hkey.u_tid = tid;
        hkey.mm = current->mm;
@@ -1257,9 +1257,9 @@ int cobalt_thread_getschedparam(unsigned long tid,
        if (!k_tid)
                return -ESRCH;
 
-       err = pthread_getschedparam(k_tid, &policy, &param);
-       if (err)
-               return err;
+       ret = pthread_getschedparam(k_tid, &policy, &param);
+       if (ret)
+               return ret;
 
        if (__xn_safe_copy_to_user(u_policy, &policy, sizeof(int)))
                return -EFAULT;
@@ -1274,7 +1274,7 @@ int cobalt_thread_getschedparam_ex(unsigned long tid,
        struct sched_param_ex param;
        struct cobalt_hkey hkey;
        pthread_t k_tid;
-       int policy, err;
+       int policy, ret;
 
        hkey.u_tid = tid;
        hkey.mm = current->mm;
@@ -1283,9 +1283,9 @@ int cobalt_thread_getschedparam_ex(unsigned long tid,
        if (!k_tid)
                return -ESRCH;
 
-       err = pthread_getschedparam_ex(k_tid, &policy, &param);
-       if (err)
-               return err;
+       ret = pthread_getschedparam_ex(k_tid, &policy, &param);
+       if (ret)
+               return ret;
 
        if (__xn_safe_copy_to_user(u_policy, &policy, sizeof(int)))
                return -EFAULT;
diff --git a/kernel/cobalt/thread.h b/kernel/cobalt/thread.h
index 49c4b35..81db737 100644
--- a/kernel/cobalt/thread.h
+++ b/kernel/cobalt/thread.h
@@ -87,11 +87,11 @@ pthread_t cobalt_thread_find(const struct cobalt_hkey 
*hkey);
 
 int cobalt_thread_create(unsigned long tid, int policy,
                         struct sched_param_ex __user *u_param,
-                        unsigned long __user *u_mode);
+                        unsigned long __user *u_window_offset);
 
 pthread_t cobalt_thread_shadow(struct task_struct *p,
                               struct cobalt_hkey *hkey,
-                              unsigned long __user *u_mode_offset);
+                              unsigned long __user *u_window_offset);
 
 int cobalt_thread_make_periodic_np(unsigned long tid,
                                   clockid_t clk_id,
@@ -114,13 +114,13 @@ int cobalt_thread_stat(unsigned long tid,
 int cobalt_thread_setschedparam(unsigned long tid,
                                int policy,
                                struct sched_param __user *u_param,
-                               unsigned long __user *u_mode_offset,
+                               unsigned long __user *u_window_offset,
                                int __user *u_promoted);
 
 int cobalt_thread_setschedparam_ex(unsigned long tid,
                                   int policy,
                                   struct sched_param __user *u_param,
-                                  unsigned long __user *u_mode_offset,
+                                  unsigned long __user *u_window_offset,
                                   int __user *u_promoted);
 
 int cobalt_thread_getschedparam(unsigned long tid,
diff --git a/lib/cobalt/current.c b/lib/cobalt/current.c
index 8ccb0b3..6ea49f4 100644
--- a/lib/cobalt/current.c
+++ b/lib/cobalt/current.c
@@ -15,7 +15,7 @@ extern unsigned long xeno_sem_heap[2];
 __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
 xnhandle_t xeno_current = XN_NO_HANDLE;
 __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
-unsigned long *xeno_current_mode;
+struct xnthread_user_window *xeno_current_window;
 
 static inline void __xeno_set_current(xnhandle_t current)
 {
@@ -26,13 +26,14 @@ void xeno_init_current_keys(void)
 {
 }
 
-void xeno_set_current_mode(unsigned long offset)
+void xeno_set_current_window(unsigned long offset)
 {
-       xeno_current_mode = (unsigned long *)(xeno_sem_heap[0] + offset);
+       xeno_current_window = (struct xnthread_user_window *)
+               (xeno_sem_heap[0] + offset);
 }
 #else /* !HAVE_TLS */
 
-pthread_key_t xeno_current_mode_key;
+pthread_key_t xeno_current_window_key;
 pthread_key_t xeno_current_key;
 
 static inline void __xeno_set_current(xnhandle_t current)
@@ -55,7 +56,7 @@ static void init_current_keys(void)
 
        pthread_atfork(NULL, NULL, &xeno_current_fork_handler);
 
-       err = pthread_key_create(&xeno_current_mode_key, NULL);
+       err = pthread_key_create(&xeno_current_window_key, NULL);
        if (err) {
          error_exit:
                fprintf(stderr, "Xenomai: error creating TSD key: %s\n",
@@ -70,9 +71,9 @@ void xeno_init_current_keys(void)
        pthread_once(&xeno_init_current_keys_once, init_current_keys);
 }
 
-void xeno_set_current_mode(unsigned long offset)
+void xeno_set_current_window(unsigned long offset)
 {
-       pthread_setspecific(xeno_current_mode_key,
+       pthread_setspecific(xeno_current_window_key,
                            (void *)(xeno_sem_heap[0] + offset));
 }
 #endif /* !HAVE_TLS */
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 0a6faeb..fb68be3 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -168,20 +168,22 @@ int cobalt_monitor_wait(cobalt_monitor_t *mon, int event,
        return ret ?: opret;
 }
 
-void cobalt_monitor_grant(cobalt_monitor_t *mon, unsigned long *u_mode)
+void cobalt_monitor_grant(cobalt_monitor_t *mon,
+                         struct xnthread_user_window *u_window)
 {
        struct cobalt_monitor_data *datp = get_monitor_data(mon);
 
        datp->flags |= COBALT_MONITOR_GRANTED;
-       *u_mode |= XNGRANT;
+       u_window->granted = 1;
 }
 
-int cobalt_monitor_grant_sync(cobalt_monitor_t *mon, unsigned long *u_mode)
+int cobalt_monitor_grant_sync(cobalt_monitor_t *mon,
+                         struct xnthread_user_window *u_window)
 {
        struct cobalt_monitor_data *datp = get_monitor_data(mon);
        int ret, oldtype;
 
-       cobalt_monitor_grant(mon, u_mode);
+       cobalt_monitor_grant(mon, u_window);
 
        if ((datp->flags & COBALT_MONITOR_PENDED) == 0)
                return 0;
@@ -200,19 +202,19 @@ int cobalt_monitor_grant_sync(cobalt_monitor_t *mon, 
unsigned long *u_mode)
        return ret;
 }
 
-void cobalt_monitor_grant_all(cobalt_monitor_t *mon, unsigned long *u_mode)
+void cobalt_monitor_grant_all(cobalt_monitor_t *mon)
 {
        struct cobalt_monitor_data *datp = get_monitor_data(mon);
 
        datp->flags |= COBALT_MONITOR_GRANTED|COBALT_MONITOR_BROADCAST;
 }
 
-int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon, unsigned long *u_mode)
+int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon)
 {
        struct cobalt_monitor_data *datp = get_monitor_data(mon);
        int ret, oldtype;
 
-       cobalt_monitor_grant_all(mon, u_mode);
+       cobalt_monitor_grant_all(mon);
 
        if ((datp->flags & COBALT_MONITOR_PENDED) == 0)
                return 0;
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index cf497cd..d4a1785 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -8,6 +8,7 @@ void xeno_sigshadow_install_once(void);
 
 extern int __cobalt_muxid;
 
+struct xnthread_user_window;
 struct cobalt_threadstat;
 struct cobalt_monitor_shadow;
 
@@ -28,16 +29,14 @@ int cobalt_monitor_wait(cobalt_monitor_t *mon, int event,
                        const struct timespec *ts);
 
 void cobalt_monitor_grant(cobalt_monitor_t *mon,
-                         unsigned long *u_mode);
+                         struct xnthread_user_window *u_window);
 
 int cobalt_monitor_grant_sync(cobalt_monitor_t *mon,
-                             unsigned long *u_mode);
+                             struct xnthread_user_window *u_window);
 
-void cobalt_monitor_grant_all(cobalt_monitor_t *mon,
-                             unsigned long *u_mode);
+void cobalt_monitor_grant_all(cobalt_monitor_t *mon);
 
-int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon,
-                                 unsigned long *u_mode);
+int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon);
 
 void cobalt_monitor_drain(cobalt_monitor_t *mon);
 
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 568ab0a..045243a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -55,7 +55,7 @@ int __wrap_pthread_setschedparam(pthread_t thread,
        if (ret == 0 && promoted) {
                xeno_sigshadow_install_once();
                xeno_set_current();
-               xeno_set_current_mode(mode_offset);
+               xeno_set_current_window(mode_offset);
                if (policy != SCHED_OTHER)
                        XENOMAI_SYSCALL1(sc_nucleus_migrate, 
XENOMAI_XENO_DOMAIN);
        }
@@ -86,7 +86,7 @@ int pthread_setschedparam_ex(pthread_t thread,
        if (ret == 0 && promoted) {
                xeno_sigshadow_install_once();
                xeno_set_current();
-               xeno_set_current_mode(mode_offset);
+               xeno_set_current_window(mode_offset);
                if (policy != SCHED_OTHER)
                        XENOMAI_SYSCALL1(sc_nucleus_migrate, 
XENOMAI_XENO_DOMAIN);
        }
@@ -214,7 +214,7 @@ static void *__pthread_trampoline(void *p)
                                policy, &param_ex, &mode_offset);
        if (ret == 0) {
                xeno_set_current();
-               xeno_set_current_mode(mode_offset);
+               xeno_set_current_window(mode_offset);
        }
 
        /*
diff --git a/lib/copperplate/syncobj.c b/lib/copperplate/syncobj.c
index 24770f3..3563e61 100644
--- a/lib/copperplate/syncobj.c
+++ b/lib/copperplate/syncobj.c
@@ -94,7 +94,7 @@ int monitor_wait_drain(struct syncobj *sobj, const struct 
timespec *timeout)
 static inline
 void monitor_grant(struct syncobj *sobj, struct threadobj *thobj)
 {
-       cobalt_monitor_grant(&sobj->core.monitor, thobj->core.u_mode);
+       cobalt_monitor_grant(&sobj->core.monitor, thobj->core.u_window);
 }
 
 static inline
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 49d3dfe..789d635 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -106,7 +106,7 @@ static inline void threadobj_setup_corespec(struct 
threadobj *thobj)
 {
        pthread_set_name_np(pthread_self(), thobj->name);
        thobj->core.handle = xeno_get_current();
-       thobj->core.u_mode = xeno_get_current_mode_ptr();
+       thobj->core.u_window = xeno_get_current_window();
 }
 
 static inline void threadobj_cleanup_corespec(struct threadobj *thobj)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to