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

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Mar  8 14:41:28 2016 +0100

cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex

Define the internal scheduling policy "current": it shall refer to the
target thread's current scheduling policy. This will allow to model
pthread_setschedprio on top of pthread_setschedparam_ex with only a
single syscall.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/cobalt/uapi/sched.h        |    3 +++
 kernel/cobalt/posix/thread.c       |   10 ++++++++++
 kernel/cobalt/trace/cobalt-posix.h |    3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index b672095..2a1df44 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -21,6 +21,9 @@
 #define SCHED_COBALT           42
 #define SCHED_WEAK             43
 
+/* for internal use */
+#define __SCHED_CURRENT                44
+
 #ifndef SCHED_SPORADIC
 #define SCHED_SPORADIC         10
 #define sched_ss_low_priority  sched_u.ss.__sched_low_priority
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index d87edb1..217b81b 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -242,6 +242,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct 
xnthread *zombie)
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
                                     const struct sched_param_ex *param_ex)
 {
+       struct xnthread *base_thread = &thread->threadbase;
        struct xnsched_class *sched_class;
        union xnsched_policy_param param;
        xnticks_t tslice;
@@ -256,6 +257,15 @@ int __cobalt_thread_setschedparam_ex(struct cobalt_thread 
*thread, int policy,
                goto out;
        }
 
+       if (policy == __SCHED_CURRENT) {
+               policy = base_thread->base_class->policy;
+               if (xnthread_base_priority(base_thread) == 0)
+                       policy = SCHED_NORMAL;
+               else if (base_thread->base_class == &xnsched_class_rt &&
+                        xnthread_test_state(base_thread, XNRRB))
+                       policy = SCHED_RR;
+       }
+
        tslice = thread->threadbase.rrperiod;
        sched_class = cobalt_sched_policy_param(&param, policy,
                                                param_ex, &tslice);
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index 3d0e20c..cc0eb05 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -90,7 +90,8 @@ DECLARE_EVENT_CLASS(syscall_exit,
                         {SCHED_QUOTA, "quota"},                \
                         {SCHED_SPORADIC, "sporadic"},          \
                         {SCHED_COBALT, "cobalt"},              \
-                        {SCHED_WEAK, "weak"})
+                        {SCHED_WEAK, "weak"},                  \
+                        {__SCHED_CURRENT, "<current>"})
 
 #define cobalt_print_sched_params(__policy, __p_ex)                    \
 ({                                                                     \


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

Reply via email to