diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index dc22fe34fc59..99e3d0cd227c 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -29,6 +29,7 @@ #include "namespace.h" #include +#include #include #include #include @@ -50,7 +51,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, { struct pthread *curthread, *new_thread; struct thr_param param; - struct thr_sched_param sched_param; + struct sched_param sched_param; + struct rtprio rtp; int ret = 0, locked, create_suspended; sigset_t set, oset; @@ -144,12 +146,12 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, if (new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) param.flags |= THR_SYSTEM_SCOPE; if (new_thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED) - param.sched_param = NULL; + param.rtp = NULL; else { - param.sched_param = &sched_param; - param.sched_param_size = sizeof(sched_param); - sched_param.policy = new_thread->attr.sched_policy; - sched_param.param.sched_priority = new_thread->attr.prio; + sched_param.sched_priority = new_thread->attr.prio; + _schedparam_to_rtp(new_thread->attr.sched_policy, + &sched_param, &rtp); + param.rtp = &rtp; } /* Schedule the new thread. */ diff --git a/lib/libthr/thread/thr_getschedparam.c b/lib/libthr/thread/thr_getschedparam.c index c3233cd28334..b36d7241bd9c 100644 --- a/lib/libthr/thread/thr_getschedparam.c +++ b/lib/libthr/thread/thr_getschedparam.c @@ -33,6 +33,8 @@ */ #include "namespace.h" +#include +#include #include #include #include "un-namespace.h" diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index f0da5f6c04d9..3624cf815e7a 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -411,8 +411,8 @@ init_main_thread(struct pthread *thread) thread->state = PS_RUNNING; - thr_getscheduler(thread->tid, &thread->attr.sched_policy, - &sched_param, sizeof(sched_param)); + _thr_getscheduler(thread->tid, &thread->attr.sched_policy, + &sched_param); thread->attr.prio = sched_param.sched_priority; /* Others cleared to zero by thr_alloc() */ diff --git a/lib/libthr/thread/thr_kern.c b/lib/libthr/thread/thr_kern.c index aa7dce69f793..649a973aabdc 100644 --- a/lib/libthr/thread/thr_kern.c +++ b/lib/libthr/thread/thr_kern.c @@ -29,6 +29,7 @@ #include #include +#include #include #include "thr_private.h" @@ -96,3 +97,68 @@ _thr_assert_lock_level() { PANIC("locklevel <= 0"); } + +int +_rtp_to_schedparam(const struct rtprio *rtp, int *policy, + struct sched_param *param) +{ + switch(rtp->type) { + case RTP_PRIO_REALTIME: + *policy = SCHED_RR; + param->sched_priority = RTP_PRIO_MAX - rtp->prio; + break; + case RTP_PRIO_FIFO: + *policy = SCHED_FIFO; + param->sched_priority = RTP_PRIO_MAX - rtp->prio; + break; + default: + *policy = SCHED_OTHER; + param->sched_priority = 0; + break; + } + return (0); +} + +int +_schedparam_to_rtp(int policy, const struct sched_param *param, + struct rtprio *rtp) +{ + switch(policy) { + case SCHED_RR: + rtp->type = RTP_PRIO_REALTIME; + rtp->prio = RTP_PRIO_MAX - param->sched_priority; + break; + case SCHED_FIFO: + rtp->type = RTP_PRIO_FIFO; + rtp->prio = RTP_PRIO_MAX - param->sched_priority; + break; + case SCHED_OTHER: + default: + rtp->type = RTP_PRIO_NORMAL; + rtp->prio = 0; + break; + } + return (0); +} + +int +_thr_getscheduler(lwpid_t lwpid, int *policy, struct sched_param *param) +{ + struct rtprio rtp; + int ret; + + ret = rtprio_thread(RTP_LOOKUP, lwpid, &rtp); + if (ret == -1) + return (ret); + _rtp_to_schedparam(&rtp, policy, param); + return (0); +} + +int +_thr_setscheduler(lwpid_t lwpid, int policy, const struct sched_param *param) +{ + struct rtprio rtp; + + _schedparam_to_rtp(policy, param, &rtp); + return (rtprio_thread(RTP_SET, lwpid, &rtp)); +} diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index eb9c25c9caa2..0099a94a7f75 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -640,6 +640,12 @@ void _thr_once_init(void) __hidden; void _thr_report_creation(struct pthread *curthread, struct pthread *newthread) __hidden; void _thr_report_death(struct pthread *curthread) __hidden; +int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden; +int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden; +int _rtp_to_schedparam(const struct rtprio *rtp, int *policy, + struct sched_param *param) __hidden; +int _schedparam_to_rtp(int policy, const struct sched_param *param, + struct rtprio *rtp) __hidden; void _thread_bp_create(void); void _thread_bp_death(void); diff --git a/lib/libthr/thread/thr_setprio.c b/lib/libthr/thread/thr_setprio.c index cca47719845c..21bb1a48edad 100644 --- a/lib/libthr/thread/thr_setprio.c +++ b/lib/libthr/thread/thr_setprio.c @@ -55,8 +55,8 @@ _pthread_setprio(pthread_t pthread, int prio) curthread->attr.prio = prio; ret = 0; } else { - ret = thr_setschedparam(curthread->tid, - ¶m, sizeof(struct sched_param)); + ret = _thr_setscheduler(curthread->tid, + curthread->attr.sched_policy, ¶m); if (ret == -1) ret = errno; else @@ -71,8 +71,8 @@ _pthread_setprio(pthread_t pthread, int prio) pthread->attr.prio = prio; ret = 0; } else { - ret = thr_setschedparam(pthread->tid, ¶m, - sizeof(struct sched_param)); + ret = _thr_setscheduler(pthread->tid, + curthread->attr.sched_policy, ¶m); if (ret == -1) ret = errno; else diff --git a/lib/libthr/thread/thr_setschedparam.c b/lib/libthr/thread/thr_setschedparam.c index 5ed6a4957990..59d62dcda1ef 100644 --- a/lib/libthr/thread/thr_setschedparam.c +++ b/lib/libthr/thread/thr_setschedparam.c @@ -62,8 +62,7 @@ _pthread_setschedparam(pthread_t pthread, int policy, THR_UNLOCK(curthread); return (0); } - ret = thr_setscheduler(curthread->tid, policy, param, - sizeof(struct sched_param)); + ret = _thr_setscheduler(curthread->tid, policy, param); if (ret == -1) ret = errno; else { @@ -81,8 +80,7 @@ _pthread_setschedparam(pthread_t pthread, int policy, THR_THREAD_UNLOCK(curthread, pthread); return (0); } - ret = thr_setscheduler(pthread->tid, policy, param, - sizeof(struct sched_param)); + ret = _thr_setscheduler(pthread->tid, policy, param); if (ret == -1) ret = errno; else {