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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 20 18:21:55 2014 +0200

cobalt/sched: increase the visible priority range of real-time classes

There is no point in limiting the available priority range to 99 for
all classes but SCHED_COBALT, although we support up to 258 distinct
levels internally.

POSIX explicitly states that such limit is implementation-dependent,
and provides for sched_get_priority_max() for retrieving it
dynamically. Applications wary of portability between the Cobalt and
Mercury cores should probe for such limit.

All real-time classes exposed to userland now support up to 256 levels
[0..255], except SCHED_COBALT which gives access to the widest range
[0..257] available internally.

---

 doc/asciidoc/MIGRATION.adoc            |   16 +++++++++++++---
 include/cobalt/kernel/rtdm/driver.h    |    2 +-
 include/cobalt/kernel/sched-quota.h    |    5 +++++
 include/cobalt/kernel/sched-rt.h       |   11 ++++++-----
 include/cobalt/kernel/sched-sporadic.h |    5 ++++-
 include/cobalt/kernel/sched-tp.h       |    5 +++++
 include/cobalt/kernel/sched-weak.h     |    3 ++-
 kernel/cobalt/sched-quota.c            |    4 ++--
 kernel/cobalt/sched-sporadic.c         |   12 +++++++-----
 kernel/cobalt/sched-tp.c               |    4 ++--
 kernel/cobalt/sched-weak.c             |   12 +++++++++++-
 lib/cobalt/thread.c                    |   27 ++++++++++++++-------------
 12 files changed, 72 insertions(+), 34 deletions(-)

diff --git a/doc/asciidoc/MIGRATION.adoc b/doc/asciidoc/MIGRATION.adoc
index cd2a1a4..650a6f4 100644
--- a/doc/asciidoc/MIGRATION.adoc
+++ b/doc/asciidoc/MIGRATION.adoc
@@ -381,9 +381,19 @@ using the Cobalt core.
 
 .Scheduling
 
-- Calling +pthread_setschedparam()+ may cause a secondary mode switch
-  for the caller, but does not cause any mode switch for the target
-  thread unlike with Xenomai 2.x.
+- +sched_get_priority_max()+ returns a larger value for all real-time
+  policies over Cobalt, compared to their Mercury counterpart, which
+  are directly mapped over the native Linux scheduling policies
+  instead (e.g. 255 vs 99 for SCHED_FIFO/RR). Applications wary of
+  portability between the Cobalt and Mercury cores should probe for
+  such limit.
+
+- The +SCHED_SPORADIC+ and +SCHED_TP classes now support up to 255
+  priority levels, instead of 99 as previously with Xenomai 2.x.
+
+- +pthread_setschedparam()+ may cause a secondary mode switch for the
+  caller, but will not cause any mode switch for the target thread
+  unlike with Xenomai 2.x.
 
 [normal]
   This is a requirement for maintaining both the *glibc* and the
diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 6c805d8..b07f68f 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -1357,7 +1357,7 @@ typedef void (*rtdm_task_proc_t)(void *arg);
  * Maximum and minimum task priorities
  * @{ */
 #define RTDM_TASK_LOWEST_PRIORITY      0
-#define RTDM_TASK_HIGHEST_PRIORITY     XNSCHED_FIFO_MAX_PRIO
+#define RTDM_TASK_HIGHEST_PRIORITY     99
 /** @} Task Priority Range */
 
 /**
diff --git a/include/cobalt/kernel/sched-quota.h 
b/include/cobalt/kernel/sched-quota.h
index d5e4bdd..381f8cb 100644
--- a/include/cobalt/kernel/sched-quota.h
+++ b/include/cobalt/kernel/sched-quota.h
@@ -26,6 +26,11 @@
 
 #ifdef CONFIG_XENO_OPT_SCHED_QUOTA
 
+#define XNSCHED_QUOTA_MIN_PRIO 1
+#define XNSCHED_QUOTA_MAX_PRIO 255
+#define XNSCHED_QUOTA_NR_PRIO  \
+       (XNSCHED_QUOTA_MAX_PRIO - XNSCHED_QUOTA_MIN_PRIO + 1)
+
 extern struct xnsched_class xnsched_class_quota;
 
 struct xnsched_quota_group {
diff --git a/include/cobalt/kernel/sched-rt.h b/include/cobalt/kernel/sched-rt.h
index 4655ac9..7e34850 100644
--- a/include/cobalt/kernel/sched-rt.h
+++ b/include/cobalt/kernel/sched-rt.h
@@ -28,24 +28,25 @@
 #endif
 
 /*
- * Global priority scale for Xenomai's RT scheduling class, available
- * to SCHED_COBALT members.
+ * Global priority scale for Xenomai's core scheduling class,
+ * available to SCHED_COBALT members.
  */
 #define XNSCHED_RT_MIN_PRIO    0
 #define XNSCHED_RT_MAX_PRIO    257
-#define XNSCHED_RT_NR_PRIO     (XNSCHED_RT_MAX_PRIO - XNSCHED_RT_MIN_PRIO + 1)
+#define XNSCHED_RT_NR_PRIO     \
+       (XNSCHED_RT_MAX_PRIO - XNSCHED_RT_MIN_PRIO + 1)
 
 /*
  * Common POSIX priority range for SCHED_FIFO, and all other classes
  * except SCHED_COBALT.
  */
 #define XNSCHED_FIFO_MIN_PRIO  1
-#define XNSCHED_FIFO_MAX_PRIO  99
+#define XNSCHED_FIFO_MAX_PRIO  255
 
 #if XNSCHED_RT_NR_PRIO > XNSCHED_CLASS_WEIGHT_FACTOR ||        \
   (defined(CONFIG_XENO_OPT_SCALABLE_SCHED) &&          \
    XNSCHED_RT_NR_PRIO > XNSCHED_MLQ_LEVELS)
-#error "RT class has too many priority levels"
+#error "SCHED_COBALT has too many priority levels"
 #endif
 
 extern struct xnsched_class xnsched_class_rt;
diff --git a/include/cobalt/kernel/sched-sporadic.h 
b/include/cobalt/kernel/sched-sporadic.h
index a319333..002d88c 100644
--- a/include/cobalt/kernel/sched-sporadic.h
+++ b/include/cobalt/kernel/sched-sporadic.h
@@ -29,7 +29,10 @@
 
 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
 
-#include <cobalt/kernel/heap.h>
+#define XNSCHED_SPORADIC_MIN_PRIO      1
+#define XNSCHED_SPORADIC_MAX_PRIO      255
+#define XNSCHED_SPORADIC_NR_PRIO       \
+       (XNSCHED_SPORADIC_MAX_PRIO - XNSCHED_SPORADIC_MIN_PRIO + 1)
 
 extern struct xnsched_class xnsched_class_sporadic;
 
diff --git a/include/cobalt/kernel/sched-tp.h b/include/cobalt/kernel/sched-tp.h
index dad2f6d..c828aa0 100644
--- a/include/cobalt/kernel/sched-tp.h
+++ b/include/cobalt/kernel/sched-tp.h
@@ -26,6 +26,11 @@
 
 #ifdef CONFIG_XENO_OPT_SCHED_TP
 
+#define XNSCHED_TP_MIN_PRIO    1
+#define XNSCHED_TP_MAX_PRIO    255
+#define XNSCHED_TP_NR_PRIO     \
+       (XNSCHED_TP_MAX_PRIO - XNSCHED_TP_MIN_PRIO + 1)
+
 extern struct xnsched_class xnsched_class_tp;
 
 struct xnsched_tp_window {
diff --git a/include/cobalt/kernel/sched-weak.h 
b/include/cobalt/kernel/sched-weak.h
index 132c293..9f725ea 100644
--- a/include/cobalt/kernel/sched-weak.h
+++ b/include/cobalt/kernel/sched-weak.h
@@ -27,7 +27,8 @@
 
 #define XNSCHED_WEAK_MIN_PRIO  0
 #define XNSCHED_WEAK_MAX_PRIO  99
-#define XNSCHED_WEAK_NR_PRIO   (XNSCHED_WEAK_MAX_PRIO - XNSCHED_WEAK_MIN_PRIO 
+ 1)
+#define XNSCHED_WEAK_NR_PRIO   \
+       (XNSCHED_WEAK_MAX_PRIO - XNSCHED_WEAK_MIN_PRIO + 1)
 
 #if XNSCHED_WEAK_NR_PRIO > XNSCHED_CLASS_WEIGHT_FACTOR ||      \
        (defined(CONFIG_XENO_OPT_SCALABLE_SCHED) &&             \
diff --git a/kernel/cobalt/sched-quota.c b/kernel/cobalt/sched-quota.c
index 5cddd67..5b1c659 100644
--- a/kernel/cobalt/sched-quota.c
+++ b/kernel/cobalt/sched-quota.c
@@ -299,8 +299,8 @@ static int xnsched_quota_declare(struct xnthread *thread,
        struct xnsched_quota *qs;
        int tgid;
 
-       if (p->quota.prio < XNSCHED_RT_MIN_PRIO ||
-           p->quota.prio > XNSCHED_RT_MAX_PRIO)
+       if (p->quota.prio < XNSCHED_QUOTA_MIN_PRIO ||
+           p->quota.prio > XNSCHED_QUOTA_MAX_PRIO)
                return -EINVAL;
 
        tgid = p->quota.tgid;
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index cae950e..9ec3b0d 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -17,6 +17,7 @@
  * 02111-1307, USA.
  */
 #include <cobalt/kernel/sched.h>
+#include <cobalt/kernel/heap.h>
 
 #define MAX_REPLENISH CONFIG_XENO_OPT_SCHED_SPORADIC_MAXREPL
 
@@ -285,12 +286,13 @@ static int xnsched_sporadic_declare(struct xnthread 
*thread,
 {
        struct xnsched_sporadic_data *pss;
 
-       if (p->pss.low_prio < -1 ||
-           p->pss.low_prio > XNSCHED_RT_MAX_PRIO)
+       if (p->pss.low_prio != -1 &&
+           (p->pss.low_prio < XNSCHED_SPORADIC_MIN_PRIO ||
+            p->pss.low_prio > XNSCHED_SPORADIC_MAX_PRIO))
                return -EINVAL;
 
-       if (p->pss.normal_prio < XNSCHED_RT_MIN_PRIO ||
-           p->pss.normal_prio > XNSCHED_RT_MAX_PRIO)
+       if (p->pss.normal_prio < XNSCHED_SPORADIC_MIN_PRIO ||
+           p->pss.normal_prio > XNSCHED_SPORADIC_MAX_PRIO)
                return -EINVAL;
 
        if (p->pss.init_budget == 0)
@@ -308,7 +310,7 @@ static int xnsched_sporadic_declare(struct xnthread *thread,
        if (p->pss.max_repl < 1 || p->pss.max_repl > MAX_REPLENISH)
                return -EINVAL;
 
-       pss = xnmalloc(sizeof(struct xnsched_sporadic_data));
+       pss = xnmalloc(sizeof(*pss));
        if (pss == NULL)
                return -ENOMEM;
 
diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 13c4416..880d2b3 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -165,8 +165,8 @@ static int xnsched_tp_declare(struct xnthread *thread,
 {
        struct xnsched *sched = thread->sched;
 
-       if (p->tp.prio < XNSCHED_RT_MIN_PRIO ||
-           p->tp.prio > XNSCHED_RT_MAX_PRIO)
+       if (p->tp.prio < XNSCHED_TP_MIN_PRIO ||
+           p->tp.prio > XNSCHED_TP_MAX_PRIO)
                return -EINVAL;
 
        list_add_tail(&thread->tp_link, &sched->tp.threads);
diff --git a/kernel/cobalt/sched-weak.c b/kernel/cobalt/sched-weak.c
index 687789f..5ab6374 100644
--- a/kernel/cobalt/sched-weak.c
+++ b/kernel/cobalt/sched-weak.c
@@ -66,6 +66,16 @@ void xnsched_weak_trackprio(struct xnthread *thread,
                thread->cprio = thread->bprio;
 }
 
+static int xnsched_weak_declare(struct xnthread *thread,
+                               const union xnsched_policy_param *p)
+{
+       if (p->weak.prio < XNSCHED_WEAK_MIN_PRIO ||
+           p->weak.prio > XNSCHED_WEAK_MAX_PRIO)
+               return -EINVAL;
+
+       return 0;
+}
+
 #ifdef CONFIG_XENO_OPT_VFILE
 
 struct xnvfile_directory sched_weak_vfroot;
@@ -188,7 +198,7 @@ struct xnsched_class xnsched_class_weak = {
        .sched_rotate           =       NULL,
        .sched_forget           =       NULL,
        .sched_kick             =       NULL,
-       .sched_declare          =       NULL,
+       .sched_declare          =       xnsched_weak_declare,
        .sched_setparam         =       xnsched_weak_setparam,
        .sched_trackprio        =       xnsched_weak_trackprio,
        .sched_getparam         =       xnsched_weak_getparam,
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index 0d7d7c8..b461058 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -45,32 +45,33 @@ static void prefault_stack(void)
 }
 
 static int libc_setschedparam(pthread_t thread,
-                             int policy_ex, const struct sched_param_ex 
*param_ex)
+                             int policy, const struct sched_param_ex *param_ex)
 {
        struct sched_param param;
-       int policy, priority;
+       int priority;
 
        priority = param_ex->sched_priority;
 
-       switch (policy_ex) {
+       switch (policy) {
        case SCHED_WEAK:
                policy = priority ? SCHED_FIFO : SCHED_OTHER;
                break;
-       case SCHED_COBALT:
-       case SCHED_TP:
-       case SCHED_SPORADIC:
-       case SCHED_QUOTA:
+       default:
                policy = SCHED_FIFO;
+               /* falldown wanted. */
+       case SCHED_OTHER:
+       case SCHED_FIFO:
+       case SCHED_RR:
                /*
-                * Our priority range is larger than the regular
-                * kernel's, limit the priority value accordingly.
+                * The Cobalt priority range is larger than those of
+                * the native SCHED_FIFO/RR classes, so we have to cap
+                * the priority value accordingly.  We also remap
+                * "weak" (negative) priorities - which are only
+                * meaningful for the Cobalt core - to regular values.
                 */
                if (priority > std_maxpri)
                        priority = std_maxpri;
-               break;
-       default:
-               policy = policy_ex;
-               if (priority < 0)
+               else if (priority < 0)
                        priority = -priority;
        }
 


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

Reply via email to