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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jul  7 18:31:50 2014 +0200

lib/cobalt: restrict sched_get_priority_min/max() range for SCHED_FIFO/RR

Increasing the values returned by the sched_get_priority_max() wrapper
above the glibc limit breaks the basic assumption that such value
could be used with pthread_create(), which is wrong.

When an overlap exist for some scheduling policies (i.e. SCHED_FIFO,
RR) between Cobalt and glibc interface, we must differentiate calls
for obtaining the static range complying with the glibc, from those
for dealing specifically with those policies if Cobalt extends them.

This translates to:

sched_get_priority_max(SCHED_FIFO/RR) => 99
sched_get_priority_max_ex(SCHED_FIFO/RR) => 256

---

 include/cobalt/sched.h      |    4 ++
 lib/cobalt/thread.c         |  110 ++++++++++++++++++++++++++++++++++++-------
 lib/copperplate/threadobj.c |    6 +--
 lib/psos/task.c             |    2 +-
 lib/vxworks/taskLib.c       |    2 +-
 5 files changed, 103 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/sched.h b/include/cobalt/sched.h
index 943cb35..776272b 100644
--- a/include/cobalt/sched.h
+++ b/include/cobalt/sched.h
@@ -47,6 +47,10 @@ void __sched_cpufill(size_t __setsize, cpu_set_t *__setp);
 extern "C" {
 #endif
 
+int sched_get_priority_min_ex(int policy);
+
+int sched_get_priority_max_ex(int policy);
+
 int sched_setconfig_np(int cpu, int policy,
                       const union sched_config *config, size_t len);
 
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 547bef9..6c45337 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -781,8 +781,7 @@ COBALT_IMPL(int, sched_yield, (void))
  * This service returns the minimum priority of the scheduling policy @a
  * policy.
  *
- * @param policy scheduling policy, one of SCHED_FIFO, SCHED_RR,
- * SCHED_SPORADIC, SCHED_TP or SCHED_OTHER.
+ * @param policy scheduling policy.
  *
  * @retval 0 on success;
  * @retval -1 with @a errno set if:
@@ -797,15 +796,55 @@ COBALT_IMPL(int, sched_get_priority_min, (int policy))
 {
        int ret;
 
-       ret = XENOMAI_SKINCALL1(__cobalt_muxid, sc_cobalt_sched_minprio, 
policy);
-       if (ret < 0) {
-               if (ret == -ENOSYS)
-                       return __STD(sched_get_priority_min(policy));
+       switch (policy) {
+       case SCHED_FIFO:
+       case SCHED_RR:
+               break;
+       default:
+               ret = XENOMAI_SKINCALL1(__cobalt_muxid,
+                                       sc_cobalt_sched_minprio, policy);
+               if (ret >= 0)
+                       return ret;
+               if (ret != -EINVAL) {
+                       errno = -ret;
+                       return -1;
+               }
+       }
+
+       return __STD(sched_get_priority_min(policy));
+}
+
+/**
+ * Get extended minimum priority of the specified scheduling policy.
+ *
+ * This service returns the minimum priority of the scheduling policy
+ * @a policy, reflecting any Cobalt extension to the standard classes.
+ *
+ * @param policy scheduling policy.
+ *
+ * @retval 0 on success;
+ * @retval -1 with @a errno set if:
+ * - EINVAL, @a policy is invalid.
+ *
+ * @see
+ * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/sched_get_priority_min.html";>
+ * Specification.</a>
+ *
+ */
+int sched_get_priority_min_ex(int policy)
+{
+       int ret;
+
+       ret = XENOMAI_SKINCALL1(__cobalt_muxid,
+                               sc_cobalt_sched_minprio, policy);
+       if (ret >= 0)
+               return ret;
+       if (ret != -EINVAL) {
                errno = -ret;
-               ret = -1;
+               return -1;
        }
 
-       return ret;
+       return __STD(sched_get_priority_min(policy));
 }
 
 /**
@@ -814,8 +853,7 @@ COBALT_IMPL(int, sched_get_priority_min, (int policy))
  * This service returns the maximum priority of the scheduling policy @a
  * policy.
  *
- * @param policy scheduling policy, one of SCHED_FIFO, SCHED_RR,
- * SCHED_SPORADIC, SCHED_TP or SCHED_OTHER.
+ * @param policy scheduling policy.
  *
  * @retval 0 on success;
  * @retval -1 with @a errno set if:
@@ -830,15 +868,55 @@ COBALT_IMPL(int, sched_get_priority_max, (int policy))
 {
        int ret;
 
-       ret = XENOMAI_SKINCALL1(__cobalt_muxid, sc_cobalt_sched_maxprio, 
policy);
-       if (ret < 0) {
-               if (ret == -ENOSYS)
-                       return __STD(sched_get_priority_max(policy));
+       switch (policy) {
+       case SCHED_FIFO:
+       case SCHED_RR:
+               break;
+       default:
+               ret = XENOMAI_SKINCALL1(__cobalt_muxid,
+                                       sc_cobalt_sched_maxprio, policy);
+               if (ret >= 0)
+                       return ret;
+               if (ret != -EINVAL) {
+                       errno = -ret;
+                       return -1;
+               }
+       }
+
+       return __STD(sched_get_priority_max(policy));
+}
+
+/**
+ * Get extended maximum priority of the specified scheduling policy.
+ *
+ * This service returns the maximum priority of the scheduling policy
+ * @a policy, reflecting any Cobalt extension to standard classes.
+ *
+ * @param policy scheduling policy.
+ *
+ * @retval 0 on success;
+ * @retval -1 with @a errno set if:
+ * - EINVAL, @a policy is invalid.
+ *
+ * @see
+ * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/sched_get_priority_max.html";>
+ * Specification.</a>
+ *
+ */
+int sched_get_priority_max_ex(int policy)
+{
+       int ret;
+
+       ret = XENOMAI_SKINCALL1(__cobalt_muxid,
+                               sc_cobalt_sched_maxprio, policy);
+       if (ret >= 0)
+               return ret;
+       if (ret != -EINVAL) {
                errno = -ret;
-               ret = -1;
+               return -1;
        }
 
-       return ret;
+       return __STD(sched_get_priority_max(policy));
 }
 
 /**
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index b5ce3d1..05bb6cb 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -242,8 +242,8 @@ static inline void threadobj_set_agent(struct threadobj 
*thobj)
 
 static inline void pkg_init_corespec(void)
 {
-       threadobj_irq_prio = __RT(sched_get_priority_max(SCHED_CORE));
-       threadobj_high_prio = __RT(sched_get_priority_max(SCHED_FIFO));
+       threadobj_irq_prio = sched_get_priority_max_ex(SCHED_CORE);
+       threadobj_high_prio = sched_get_priority_max_ex(SCHED_FIFO);
 }
 
 static inline int threadobj_init_corespec(struct threadobj *thobj)
@@ -546,7 +546,7 @@ static inline void pkg_init_corespec(void)
         * holding the scheduler lock, unless the latter has to block
         * for some reason, defeating the purpose of such lock anyway.
         */
-       threadobj_irq_prio = __RT(sched_get_priority_max(SCHED_FIFO));
+       threadobj_irq_prio = sched_get_priority_max(SCHED_FIFO);
        threadobj_lock_prio = threadobj_irq_prio - 1;
        threadobj_high_prio = threadobj_irq_prio - 2;
 
diff --git a/lib/psos/task.c b/lib/psos/task.c
index 26db2b9..89ba917 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -225,7 +225,7 @@ static void *task_trampoline(void *arg)
  * The application code may override the routine doing the priority
  * mapping from pSOS to SCHED_FIFO (normalize). Normalized priorities
  * returned by this routine must be in the range [ 1
- * .. sched_get_priority_max(SCHED_FIFO) - 1 ] inclusive.
+ * .. threadobj_high_prio] inclusive.
  */
 __weak int psos_task_normalize_priority(unsigned long psos_prio)
 {
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index fa6b4f5..34faedc 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -294,7 +294,7 @@ static void *task_trampoline(void *arg)
  * The application code may override the routine doing the priority
  * mapping from VxWorks to SCHED_FIFO (normalize). Normalized
  * priorities returned by this routine must be in the range [ 1
- * .. sched_get_priority_max(SCHED_FIFO) - 1 ] inclusive.
+ * .. threadobj_high_prio ] inclusive.
  */
 __weak int wind_task_normalize_priority(int wind_prio)
 {


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

Reply via email to