[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release
Module: xenomai-jki Branch: for-forge Commit: 3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a Author: Jan KiszkaDate: Mon May 9 21:19:04 2016 +0200 cobalt/kernel: Return need_resched flag from xnsynch_release We currently return the next owner, but no caller of xnsynch_release evaluates this beyond != NULL and calls xnsched_run in that case. Simplify the API by returning a need_resched flag directly. This will also help with fixing the missing reschedule after PP deboost. Signed-off-by: Jan Kiszka --- include/cobalt/kernel/synch.h |3 +-- kernel/cobalt/posix/mutex.c |2 +- kernel/cobalt/rtdm/drvlib.c |2 +- kernel/cobalt/synch.c | 23 +++ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h index 04d7f10..1e99c18 100644 --- a/include/cobalt/kernel/synch.h +++ b/include/cobalt/kernel/synch.h @@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch, int xnsynch_try_acquire(struct xnsynch *synch); -struct xnthread *xnsynch_release(struct xnsynch *synch, -struct xnthread *thread); +bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread); struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch); diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c index c6020ff..f99874b 100644 --- a/kernel/cobalt/posix/mutex.c +++ b/kernel/cobalt/posix/mutex.c @@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr, cobalt_cond_deferred_signals(cond); } } - need_resched |= xnsynch_release(>synchbase, curr) != NULL; + need_resched |= xnsynch_release(>synchbase, curr); return need_resched; } diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c index ae55a4b..1973c37 100644 --- a/kernel/cobalt/rtdm/drvlib.c +++ b/kernel/cobalt/rtdm/drvlib.c @@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex) trace_cobalt_driver_mutex_release(mutex); if (unlikely(xnsynch_release(>synch_base, -xnsched_current_thread()) != NULL)) +xnsched_current_thread( xnsched_run(); } EXPORT_SYMBOL_GPL(rtdm_mutex_unlock); diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c index 976261d..0130844 100644 --- a/kernel/cobalt/synch.c +++ b/kernel/cobalt/synch.c @@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch, drop_booster(synch, owner); } -static struct xnthread *transfer_ownership(struct xnsynch *synch, - struct xnthread *lastowner) +static bool transfer_ownership(struct xnsynch *synch, + struct xnthread *lastowner) { /* nklock held, irqs off */ struct xnthread *nextowner; xnhandle_t nextownerh; @@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, if (list_empty(>pendq)) { synch->owner = NULL; atomic_set(lockp, XN_NO_HANDLE); - return NULL; + return false; } nextowner = list_first_entry(>pendq, struct xnthread, plink); @@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, atomic_set(lockp, nextownerh); - return nextowner; + return true; } /** - * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread *curr) + * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr) * @brief Release a resource and pass it to the next waiting thread. * * This service releases the ownership of the given synchronization @@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, * @param curr The descriptor address of the current thread, which * must own the object at the time of calling. * - * @return The descriptor address of the unblocked thread. + * @return True if a reschedule is required. * * @sideeffect * @@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, * * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release(struct xnsynch *synch, -struct xnthread *curr) +bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr) { - struct xnthread *nextowner = NULL; + bool need_resched = false; xnhandle_t currh, h; atomic_t *lockp; spl_t s; @@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, trace_cobalt_synch_release(synch); if (xnthread_put_resource(curr)) - return NULL; + return 0;
[Xenomai-git] Jan Kiszka : cobalt/kernel: Trigger missing reschedule after PP deboost
Module: xenomai-jki Branch: for-forge Commit: 2f2f4c76b7a79c772d7224ca7591a23136b131f3 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=2f2f4c76b7a79c772d7224ca7591a23136b131f3 Author: Jan KiszkaDate: Mon May 9 21:22:23 2016 +0200 cobalt/kernel: Trigger missing reschedule after PP deboost xnsynch_release also needs to tell the caller about the potential need for a reschedule after deboosting for prio-protection. Signed-off-by: Jan Kiszka --- kernel/cobalt/synch.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c index 0130844..ee52dbd 100644 --- a/kernel/cobalt/synch.c +++ b/kernel/cobalt/synch.c @@ -949,8 +949,10 @@ bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr) else if (h != currh)/* FLCEIL set, FLCLAIM clear. */ atomic_set(lockp, XN_NO_HANDLE); - if (synch->status & XNSYNCH_PP) + if (synch->status & XNSYNCH_PP) { clear_pp_boost(synch, curr); + need_resched = true; + } xnlock_put_irqrestore(, s); ___ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Jan Kiszka : cobalt/kernel: Null-terminate cobalt_print_sched_params output
Module: xenomai-jki Branch: for-forge Commit: 459f0de2357214e9ac13411dbe5c22e467cfc5ec URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=459f0de2357214e9ac13411dbe5c22e467cfc5ec Author: Jan KiszkaDate: Fri May 6 10:42:27 2016 +0200 cobalt/kernel: Null-terminate cobalt_print_sched_params output Using trace_seq_printf requires to terminate the generated string with 0, or we print additional garbage. Signed-off-by: Jan Kiszka --- kernel/cobalt/trace/cobalt-posix.h |1 + 1 file changed, 1 insertion(+) diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h index 75673d7..cc0eb05 100644 --- a/kernel/cobalt/trace/cobalt-posix.h +++ b/kernel/cobalt/trace/cobalt-posix.h @@ -130,6 +130,7 @@ DECLARE_EVENT_CLASS(syscall_exit, (__p_ex)->sched_priority); \ break; \ } \ + trace_seq_putc(p, '\0');\ __ret; \ }) ___ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Jan Kiszka : cobalt/kernel: Return need_resched flag from xnsynch_release
Module: xenomai-jki Branch: for-forge Commit: dd2df9a8bfbb7e45e1c262b52050cc1c3f75b3bd URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=dd2df9a8bfbb7e45e1c262b52050cc1c3f75b3bd Author: Jan KiszkaDate: Mon May 9 21:19:04 2016 +0200 cobalt/kernel: Return need_resched flag from xnsynch_release We currently return the next owner, but no caller of xnsynch_release evaluates this beyond != NULL and calls xnsched_run in that case. Simplify the API by returning a need_resched flag directly. This will also help with fixing the missing reschedule after PP deboost. Signed-off-by: Jan Kiszka --- include/cobalt/kernel/synch.h |3 +-- kernel/cobalt/posix/mutex.c |2 +- kernel/cobalt/rtdm/drvlib.c |2 +- kernel/cobalt/synch.c | 22 ++ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h index 04d7f10..83b82c4 100644 --- a/include/cobalt/kernel/synch.h +++ b/include/cobalt/kernel/synch.h @@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch, int xnsynch_try_acquire(struct xnsynch *synch); -struct xnthread *xnsynch_release(struct xnsynch *synch, -struct xnthread *thread); +int xnsynch_release(struct xnsynch *synch, struct xnthread *thread); struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch); diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c index c6020ff..f99874b 100644 --- a/kernel/cobalt/posix/mutex.c +++ b/kernel/cobalt/posix/mutex.c @@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr, cobalt_cond_deferred_signals(cond); } } - need_resched |= xnsynch_release(>synchbase, curr) != NULL; + need_resched |= xnsynch_release(>synchbase, curr); return need_resched; } diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c index ae55a4b..1973c37 100644 --- a/kernel/cobalt/rtdm/drvlib.c +++ b/kernel/cobalt/rtdm/drvlib.c @@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex) trace_cobalt_driver_mutex_release(mutex); if (unlikely(xnsynch_release(>synch_base, -xnsched_current_thread()) != NULL)) +xnsched_current_thread( xnsched_run(); } EXPORT_SYMBOL_GPL(rtdm_mutex_unlock); diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c index 976261d..d9fb5a2 100644 --- a/kernel/cobalt/synch.c +++ b/kernel/cobalt/synch.c @@ -843,8 +843,7 @@ static inline void clear_pp_boost(struct xnsynch *synch, drop_booster(synch, owner); } -static struct xnthread *transfer_ownership(struct xnsynch *synch, - struct xnthread *lastowner) +static int transfer_ownership(struct xnsynch *synch, struct xnthread *lastowner) { /* nklock held, irqs off */ struct xnthread *nextowner; xnhandle_t nextownerh; @@ -859,7 +858,7 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, if (list_empty(>pendq)) { synch->owner = NULL; atomic_set(lockp, XN_NO_HANDLE); - return NULL; + return 0; } nextowner = list_first_entry(>pendq, struct xnthread, plink); @@ -879,11 +878,11 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, atomic_set(lockp, nextownerh); - return nextowner; + return 1; } /** - * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread *curr) + * @fn int xnsynch_release(struct xnsynch *synch, struct xnthread *curr) * @brief Release a resource and pass it to the next waiting thread. * * This service releases the ownership of the given synchronization @@ -900,7 +899,7 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, * @param curr The descriptor address of the current thread, which * must own the object at the time of calling. * - * @return The descriptor address of the unblocked thread. + * @return Non-zero if a reschedule is required. * * @sideeffect * @@ -913,10 +912,9 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, * * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release(struct xnsynch *synch, -struct xnthread *curr) +int xnsynch_release(struct xnsynch *synch, struct xnthread *curr) { - struct xnthread *nextowner = NULL; + int need_resched = 0; xnhandle_t currh, h; atomic_t *lockp; spl_t s; @@ -926,7 +924,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, trace_cobalt_synch_release(synch); if (xnthread_put_resource(curr)) - return NULL; + return 0; lockp = xnsynch_fastlock(synch);
[Xenomai-git] Jan Kiszka : cobalt/kernel: Introduce __SCHED_CURRENT policy to setschedparam_ex
Module: xenomai-jki Branch: for-forge Commit: 110b97a4770affa6f0888355fc5a7c57e12b4ab9 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=110b97a4770affa6f0888355fc5a7c57e12b4ab9 Author: Jan KiszkaDate: 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 --- 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_CURRENT44 + #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 = >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 == _class_rt && +xnthread_test_state(base_thread, XNRRB)) + policy = SCHED_RR; + } + tslice = thread->threadbase.rrperiod; sched_class = cobalt_sched_policy_param(, policy, param_ex, ); diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h index 92f7245..75673d7 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, ""}) #define cobalt_print_sched_params(__policy, __p_ex)\ ({ \ ___ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git