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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Oct 10 19:40:32 2010 +0200

native: fix semantics of broken T_PRIMARY with T_CONFORMING

T_PRIMARY was often misused, leading to applications forcing their
execution domain for no reason most of the time (typically because
Xenomai syscalls do migrate the caller to the proper domain when
needed). As a matter of fact, the only meaningful usage of such
feature is to force a real-time shadow back to primary mode, before
entering a syscall-less loop.

Additionally, now that auto-relax is enabled for non real-time shadow
threads upon syscall exit, forcing T_PRIMARY on such threads would
make no sense at all anymore.

Therefore, to reduce the odds of misinterpreting what the feature
brings, this patch removes the T_PRIMARY bit, and replaces it by
T_CONFORMING, to request that the caller be moved to its preferred
execution domain if it is not yet current.

This results in the following changes API-wise:

 - rt_task_set_mode(clrmask, setmask=T_PRIMARY, &oldmode)
   becomes:
   rt_task_set_mode(clrmask, setmask=T_CONFORMING, &oldmode), forcing
   primary mode for SCHED_FIFO Xenomai threads only. Nop otherwise
   (i.e. a non real-time shadow remains in relaxed mode after the
   syscall has returned, since this is its conforming execution mode).

 - rt_task_set_mode(clrmask=T_CONFORMING, setmask, &oldmode)
   always begets -EINVAL.

---

 include/native/task.h         |    6 ++++--
 ksrc/skins/native/API.CHANGES |   23 +++++++++++++++++++++++
 ksrc/skins/native/syscall.c   |   23 +++++++++++++----------
 ksrc/skins/native/task.c      |   11 ++++++-----
 4 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/include/native/task.h b/include/native/task.h
index 95187f1..bcba49b 100644
--- a/include/native/task.h
+++ b/include/native/task.h
@@ -49,8 +49,10 @@
 #define T_NOSIG    XNASDI     /**< See #XNASDI    */ 
 #define T_WARNSW   XNTRAPSW   /**< See #XNTRAPSW  */ 
 #define T_RPIOFF   XNRPIOFF   /**< See #XNRPIOFF  */ 
-#define T_PRIMARY  0x00000200  /* Recycle internal bits status which */
-#define T_JOINABLE 0x00000400  /* won't be passed to the nucleus.  */
+
+/* Pseudo-status bits (no conflict with other T_* bits) */
+#define T_CONFORMING  0x00000200
+#define T_JOINABLE    0x00000400
 /*! @} */ /* Ends doxygen-group native_task_status */
 
 /* Task hook types. */
diff --git a/ksrc/skins/native/API.CHANGES b/ksrc/skins/native/API.CHANGES
index b9ee04e..9f76338 100644
--- a/ksrc/skins/native/API.CHANGES
+++ b/ksrc/skins/native/API.CHANGES
@@ -288,3 +288,26 @@ 
___________________________________________________________________
 
        * New rt_task_same() call. Returns true whenever two task
          descriptors refer to the same task, false otherwise.
+
+___________________________________________________________________
+
+
+2.5.5 -> 2.6.0
+
+       * rt_task_set_mode() does not support the T_PRIMARY bit
+         anymore; the latter has been replaced by T_CONFORMING, which
+         is allowed in the setmask only, and only effective for
+         real-time shadows.
+
+        In other words,
+
+        - rt_task_set_mode(clrmask, setmask=T_PRIMARY, &oldmode)
+          becomes:
+          rt_task_set_mode(clrmask, setmask=T_CONFORMING, &oldmode),
+          forcing primary mode only for SCHED_FIFO Xenomai threads
+          only. Nop otherwise (i.e. a non real-time shadow remains
+          in relaxed mode after the syscall has returned, since this
+          is its conforming runtime mode).
+
+        - rt_task_set_mode(clrmask=T_CONFORMING, setmask, &oldmode)
+        always begets -EINVAL.
diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index c4d0357..b0f3766 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -589,19 +589,22 @@ static int __rt_task_set_mode(struct pt_regs *regs)
        int err, setmask, clrmask, mode_r;
 
        clrmask = __xn_reg_arg1(regs);
-       setmask = __xn_reg_arg2(regs);
-
-       err =
-           rt_task_set_mode(clrmask & ~T_PRIMARY, setmask & ~T_PRIMARY,
-                            &mode_r);
+       if (clrmask & T_CONFORMING)
+               return -EINVAL;
 
+       /*
+        * This call already required a primary mode switch, so if
+        * T_CONFORMING was specified for a real-time shadow, we are
+        * fine. If it was given from a non real-time shadow, well
+        * this is silly, and we'll be relaxed soon due to the
+        * auto-relax feature, leading to a nop.
+        */
+       setmask = __xn_reg_arg2(regs) & ~T_CONFORMING;
+       err = rt_task_set_mode(clrmask, setmask, &mode_r);
        if (err)
                return err;
 
-       if ((clrmask & T_PRIMARY) != 0)
-               xnshadow_relax(0, 0);
-       else
-               mode_r |= T_PRIMARY;
+       mode_r |= T_CONFORMING;
 
        if (__xn_reg_arg3(regs) &&
            __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
diff --git a/ksrc/skins/native/task.c b/ksrc/skins/native/task.c
index 31c700f..f87ccb1 100644
--- a/ksrc/skins/native/task.c
+++ b/ksrc/skins/native/task.c
@@ -1433,10 +1433,10 @@ int rt_task_notify(RT_TASK *task, rt_sigset_t signals)
  * inheriting the priority of the running shadow Xenomai thread. Use
  * CONFIG_XENO_OPT_RPIOFF to globally disable priority coupling.
  *
- * - T_PRIMARY can be passed to switch the current user-space task to
- * primary mode (setmask |= T_PRIMARY), or secondary mode (clrmask |=
- * T_PRIMARY). Upon return from rt_task_set_mode(), the user-space
- * task will run into the specified domain.
+ * - T_CONFORMING can be passed in @a setmask to switch the current
+ * user-space task to its preferred runtime mode. The only meaningful
+ * use of this switch is to force a real-time shadow back to primary
+ * mode. Any other use either cause to a nop, or an error.
  *
  * Normally, this service can only be called on behalf of a regular
  * real-time task, either running in kernel or user-space. However, as
@@ -1461,7 +1461,8 @@ int rt_task_notify(RT_TASK *task, rt_sigset_t signals)
  * @return 0 is returned upon success, or:
  *
  * - -EINVAL if either @a setmask or @a clrmask specifies invalid
- * bits. T_PRIMARY is invalid for kernel-based tasks.
+ * bits. T_CONFORMING is always invalid in @a clrmask, or when applied
+ * in @a setmask to kernel-based tasks.
  *
  * - -EPERM is returned if this service was not called from a
  * real-time task context.


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

Reply via email to