Module: xenomai-forge Branch: next Commit: ddc1e9d4453fae71c58d14a04c14626f9a0dce74 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ddc1e9d4453fae71c58d14a04c14626f9a0dce74
Author: Philippe Gerum <r...@xenomai.org> Date: Tue May 20 11:39:57 2014 +0200 copperplate/threadobj: unify scheduling parameter settings for both cores --- include/cobalt/boilerplate/Makefile.am | 1 + include/cobalt/boilerplate/sched.h | 23 ++++++++++++ include/copperplate/threadobj.h | 2 +- include/mercury/boilerplate/Makefile.am | 1 + include/mercury/boilerplate/sched.h | 37 +++++++++++++++++++ lib/alchemy/task.c | 14 +++---- lib/copperplate/internal.c | 19 ++++++---- lib/copperplate/internal.h | 18 +++------ lib/copperplate/threadobj.c | 61 ++++++++++++++++--------------- lib/copperplate/timerobj.c | 4 +- lib/psos/task.c | 4 +- lib/vxworks/taskLib.c | 4 +- 12 files changed, 125 insertions(+), 63 deletions(-) diff --git a/include/cobalt/boilerplate/Makefile.am b/include/cobalt/boilerplate/Makefile.am index cbf76d1..ec3c2fe 100644 --- a/include/cobalt/boilerplate/Makefile.am +++ b/include/cobalt/boilerplate/Makefile.am @@ -1,6 +1,7 @@ includesubdir = $(includedir)/cobalt/boilerplate includesub_HEADERS = \ + sched.h \ limits.h \ signal.h \ trace.h \ diff --git a/include/cobalt/boilerplate/sched.h b/include/cobalt/boilerplate/sched.h new file mode 100644 index 0000000..d23a8da --- /dev/null +++ b/include/cobalt/boilerplate/sched.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef _COBALT_BOILERPLATE_SCHED_H +#define _COBALT_BOILERPLATE_SCHED_H + +#include <cobalt/sched.h> + +#endif /* _COBALT_BOILERPLATE_SCHED_H */ diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h index 8603534..1746517 100644 --- a/include/copperplate/threadobj.h +++ b/include/copperplate/threadobj.h @@ -20,12 +20,12 @@ #define _COPPERPLATE_THREADOBJ_H #include <time.h> -#include <sched.h> #include <semaphore.h> #include <signal.h> #include <pthread.h> #include <boilerplate/list.h> #include <boilerplate/lock.h> +#include <boilerplate/sched.h> #include <copperplate/clockobj.h> #include <copperplate/heapobj.h> #include <copperplate/debug.h> diff --git a/include/mercury/boilerplate/Makefile.am b/include/mercury/boilerplate/Makefile.am index e285a69..63cf2f6 100644 --- a/include/mercury/boilerplate/Makefile.am +++ b/include/mercury/boilerplate/Makefile.am @@ -1,6 +1,7 @@ includesubdir = $(includedir)/mercury/boilerplate includesub_HEADERS = \ + sched.h \ limits.h \ signal.h \ trace.h \ diff --git a/include/mercury/boilerplate/sched.h b/include/mercury/boilerplate/sched.h new file mode 100644 index 0000000..30dde60 --- /dev/null +++ b/include/mercury/boilerplate/sched.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef _MERCURY_BOILERPLATE_SCHED_H +#define _MERCURY_BOILERPLATE_SCHED_H + +#include <time.h> +#include <sched.h> + +struct __sched_rr_param { + struct timespec __sched_rr_quantum; +}; + +struct sched_param_ex { + int sched_priority; + union { + struct __sched_rr_param rr; + } sched_u; +}; + +#define sched_rr_quantum sched_u.rr.__sched_rr_quantum + +#endif /* _MERCURY_BOILERPLATE_SCHED_H */ diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index 380e265..fb5cae8 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -416,8 +416,8 @@ int rt_task_create(RT_TASK *task, const char *name, cta.detachstate = mode & T_JOINABLE ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED; - cta.sched.policy = prio ? SCHED_RT : SCHED_OTHER; - cta.sched.param.sched_priority = prio; + cta.policy = prio ? SCHED_RT : SCHED_OTHER; + cta.param_ex.sched_priority = prio; cta.prologue = task_prologue_1; cta.run = task_entry; cta.arg = tcb; @@ -716,11 +716,11 @@ out: int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode) { struct threadobj *current = threadobj_current(); - struct coresched_attributes csa; + struct sched_param_ex param_ex; struct alchemy_task *tcb; struct service svc; + int policy, ret; pthread_t self; - int ret; if (mode & ~(T_LOCK | T_WARNSW)) return -EINVAL; @@ -754,9 +754,9 @@ int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode) if (task) task->thread = self; - csa.policy = prio ? SCHED_RT : SCHED_OTHER; - csa.param.sched_priority = prio; - ret = __bt(copperplate_renice_local_thread(self, &csa)); + policy = prio ? SCHED_RT : SCHED_OTHER; + param_ex.sched_priority = prio; + ret = __bt(copperplate_renice_local_thread(self, policy, ¶m_ex)); out: CANCEL_RESTORE(svc); diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c index 89957a8..b57b529 100644 --- a/lib/copperplate/internal.c +++ b/lib/copperplate/internal.c @@ -79,10 +79,10 @@ int copperplate_create_thread(struct corethread_attributes *cta, return __bt(thread_spawn_epilogue(cta)); } -int copperplate_renice_local_thread(pthread_t tid, - const struct coresched_attributes *csa) +int copperplate_renice_local_thread(pthread_t tid, int policy, + const struct sched_param_ex *param_ex) { - return __bt(-pthread_setschedparam_ex(tid, csa->policy, &csa->param)); + return __bt(-pthread_setschedparam_ex(tid, policy, param_ex)); } static inline void prepare_wait_corespec(void) @@ -137,10 +137,14 @@ int copperplate_create_thread(struct corethread_attributes *cta, return __bt(thread_spawn_epilogue(cta)); } -int copperplate_renice_local_thread(pthread_t tid, - const struct coresched_attributes *csa) +int copperplate_renice_local_thread(pthread_t tid, int policy, + const struct sched_param_ex *param_ex) { - return __bt(-__RT(pthread_setschedparam(tid, csa->policy, &csa->param))); + struct sched_param param = { + .sched_priority = param_ex->sched_priority, + }; + + return __bt(-__RT(pthread_setschedparam(tid, policy, ¶m))); } static inline void prepare_wait_corespec(void) @@ -212,7 +216,8 @@ static void *thread_trampoline(void *arg) __RT(sem_post(&cta->__reserved.warm)); thread_spawn_wait(&released); __RT(sem_destroy(&released)); - ret = __bt(copperplate_renice_local_thread(pthread_self(), &_cta.sched)); + ret = __bt(copperplate_renice_local_thread(pthread_self(), + _cta.policy, &_cta.param_ex)); if (ret) warning("cannot renice core thread, %s", symerror(ret)); diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h index 6a45732..034be93 100644 --- a/lib/copperplate/internal.h +++ b/lib/copperplate/internal.h @@ -23,11 +23,11 @@ #include <time.h> #include <pthread.h> #include <semaphore.h> -#include <sched.h> #include <xeno_config.h> #include <boilerplate/list.h> #include <boilerplate/ancillaries.h> #include <boilerplate/limits.h> +#include <boilerplate/sched.h> #include <copperplate/heapobj.h> #define HOBJ_MINLOG2 3 @@ -55,19 +55,11 @@ struct shared_heap { } buckets[HOBJ_NBUCKETS]; }; -struct coresched_attributes { - int policy; -#ifdef CONFIG_XENO_COBALT - struct sched_param_ex param; -#else - struct sched_param param; -#endif -}; - struct corethread_attributes { size_t stacksize; int detachstate; - struct coresched_attributes sched; + int policy; + struct sched_param_ex param_ex; int (*prologue)(void *arg); void *(*run)(void *arg); void *arg; @@ -91,8 +83,8 @@ int copperplate_kill_tid(pid_t tid, int sig); int copperplate_create_thread(struct corethread_attributes *cta, pthread_t *tid); -int copperplate_renice_local_thread(pthread_t tid, - const struct coresched_attributes *csa); +int copperplate_renice_local_thread(pthread_t tid, int policy, + const struct sched_param_ex *param_ex); void copperplate_bootstrap_minimal(const char *arg0, char *mountpt); diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c index e6b3992..f010450 100644 --- a/lib/copperplate/threadobj.c +++ b/lib/copperplate/threadobj.c @@ -48,8 +48,8 @@ union copperplate_wait_union { static void finalize_thread(void *p); -static int request_setschedparam(struct threadobj *thobj, - const struct coresched_attributes *csa); +static int request_setschedparam(struct threadobj *thobj, int policy, + const struct sched_param_ex *param_ex); static int request_cancel(struct threadobj *thobj); @@ -89,7 +89,8 @@ struct remote_cancel { struct remote_setsched { pthread_t tid; - struct coresched_attributes attr; + int policy; + struct sched_param_ex param_ex; }; struct remote_request { @@ -147,7 +148,8 @@ static void *agent_loop(void *arg) switch (rq->req) { case RMT_SETSCHED: ret = copperplate_renice_local_thread(rq->u.setsched.tid, - &rq->u.setsched.attr); + rq->u.setsched.policy, + &rq->u.setsched.param_ex); break; case RMT_CANCEL: ret = pthread_cancel(rq->u.cancel.tid); @@ -197,8 +199,8 @@ static void start_agent(void) sigaddset(&set, SIGAGENT); pthread_sigmask(SIG_BLOCK, &set, NULL); - cta.sched.policy = SCHED_RT; - cta.sched.param.sched_priority = threadobj_agent_prio; + cta.policy = SCHED_RT; + cta.param_ex.sched_priority = threadobj_agent_prio; cta.prologue = agent_prologue; cta.run = agent_loop; cta.arg = NULL; @@ -402,33 +404,33 @@ void __threadobj_set_scheduler(struct threadobj *thobj, int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock held, dropped */ { - struct coresched_attributes csa; - int ret; + struct sched_param_ex param_ex; + int policy, ret; __threadobj_check_locked(thobj); - csa.policy = SCHED_RT; + policy = SCHED_RT; if (prio == 0) { thobj->status &= ~__THREAD_S_RR; - csa.policy = SCHED_OTHER; + policy = SCHED_OTHER; } else if (thobj->status & __THREAD_S_RR) { - csa.param.sched_rr_quantum = thobj->tslice; - csa.policy = SCHED_RR; + param_ex.sched_rr_quantum = thobj->tslice; + policy = SCHED_RR; } /* * As a side effect, resetting SCHED_RR will refill the time * credit for the target thread with the last quantum set. */ - csa.param.sched_priority = prio; + param_ex.sched_priority = prio; thobj->priority = prio; - thobj->policy = csa.policy; + thobj->policy = policy; if (thobj == threadobj_current()) { threadobj_unlock(thobj); - ret = request_setschedparam(thobj, &csa); + ret = request_setschedparam(thobj, policy, ¶m_ex); } else { - ret = request_setschedparam(thobj, &csa); + ret = request_setschedparam(thobj, policy, ¶m_ex); threadobj_unlock(thobj); } @@ -842,8 +844,8 @@ void __threadobj_set_scheduler(struct threadobj *thobj, int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock held, dropped */ { - struct coresched_attributes csa; - int ret; + struct sched_param_ex param_ex; + int policy, ret; __threadobj_check_locked(thobj); @@ -859,22 +861,22 @@ int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock hel return 0; } - csa.policy = SCHED_RT; + policy = SCHED_RT; if (prio == 0) { thobj->status &= ~__THREAD_S_RR; - csa.policy = SCHED_OTHER; + policy = SCHED_OTHER; } else if (thobj->status & __THREAD_S_RR) - csa.policy = SCHED_RR; + policy = SCHED_RR; - csa.param.sched_priority = prio; + param_ex.sched_priority = prio; thobj->priority = prio; - thobj->policy = csa.policy; + thobj->policy = policy; if (thobj == threadobj_current()) { threadobj_unlock(thobj); - ret = request_setschedparam(thobj, &csa); + ret = request_setschedparam(thobj, policy, ¶m_ex); } else { - ret = request_setschedparam(thobj, &csa); + ret = request_setschedparam(thobj, policy, ¶m_ex); threadobj_unlock(thobj); } @@ -1051,8 +1053,8 @@ int threadobj_stat(struct threadobj *thobj, #endif /* CONFIG_XENO_MERCURY */ -static int request_setschedparam(struct threadobj *thobj, - const struct coresched_attributes *csa) +static int request_setschedparam(struct threadobj *thobj, int policy, + const struct sched_param_ex *param_ex) { #ifdef CONFIG_XENO_PSHARED struct remote_request *rq; @@ -1065,7 +1067,8 @@ static int request_setschedparam(struct threadobj *thobj, rq->req = RMT_SETSCHED; rq->u.setsched.tid = thobj->tid; - rq->u.setsched.attr = *csa; + rq->u.setsched.policy = policy; + rq->u.setsched.param_ex = *param_ex; ret = __bt(send_agent(thobj, rq)); if (ret) @@ -1073,7 +1076,7 @@ static int request_setschedparam(struct threadobj *thobj, return ret; } #endif - return __bt(copperplate_renice_local_thread(thobj->tid, csa)); + return __bt(copperplate_renice_local_thread(thobj->tid, policy, param_ex)); } static int request_cancel(struct threadobj *thobj) /* thobj->lock held, dropped. */ diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c index d69e346..f9938f1 100644 --- a/lib/copperplate/timerobj.c +++ b/lib/copperplate/timerobj.c @@ -157,8 +157,8 @@ static int timerobj_spawn_server(void) if (svthread) goto out; - cta.sched.policy = SCHED_RT; - cta.sched.param.sched_priority = threadobj_irq_prio; + cta.policy = SCHED_RT; + cta.param_ex.sched_priority = threadobj_irq_prio; cta.prologue = server_prologue; cta.run = timerobj_server; cta.arg = NULL; diff --git a/lib/psos/task.c b/lib/psos/task.c index 18d8c0b..5f92367 100644 --- a/lib/psos/task.c +++ b/lib/psos/task.c @@ -346,8 +346,8 @@ u_long t_create(const char *name, u_long prio, goto fail_register; } - cta.sched.policy = SCHED_RT; - cta.sched.param.sched_priority = cprio; + cta.policy = SCHED_RT; + cta.param_ex.sched_priority = cprio; cta.prologue = task_prologue; cta.run = task_trampoline; cta.arg = task; diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c index f574157..ad64679 100644 --- a/lib/vxworks/taskLib.c +++ b/lib/vxworks/taskLib.c @@ -377,8 +377,8 @@ static STATUS __taskInit(struct wind_task *task, registry_init_file(&task->fsobj, ®istry_ops, 0); - cta.sched.policy = SCHED_RT; - cta.sched.param.sched_priority = cprio; + cta.policy = SCHED_RT; + cta.param_ex.sched_priority = cprio; cta.prologue = task_prologue; cta.run = task_trampoline; cta.arg = task; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git