diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-09-21 04:21:30 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-09-21 04:21:30 +0000 |
commit | d2c57b7fad5ce91e8b900f315b41d142831b90f1 (patch) | |
tree | f7b8debfd8a0b2054c46d867116922ddcfad5995 /lib/libthr | |
parent | 92bd1e76b1d6d685331ec54d7b5703a34d37f84e (diff) | |
download | FreeBSD-src-d2c57b7fad5ce91e8b900f315b41d142831b90f1.zip FreeBSD-src-d2c57b7fad5ce91e8b900f315b41d142831b90f1.tar.gz |
use rtprio_thread system call to get or set thread priority.
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/thread/thr_create.c | 14 | ||||
-rw-r--r-- | lib/libthr/thread/thr_getschedparam.c | 2 | ||||
-rw-r--r-- | lib/libthr/thread/thr_init.c | 4 | ||||
-rw-r--r-- | lib/libthr/thread/thr_kern.c | 66 | ||||
-rw-r--r-- | lib/libthr/thread/thr_private.h | 6 | ||||
-rw-r--r-- | lib/libthr/thread/thr_setprio.c | 8 | ||||
-rw-r--r-- | lib/libthr/thread/thr_setschedparam.c | 6 |
7 files changed, 90 insertions, 16 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index dc22fe3..99e3d0c 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -29,6 +29,7 @@ #include "namespace.h" #include <sys/types.h> +#include <sys/rtprio.h> #include <sys/signalvar.h> #include <errno.h> #include <stdlib.h> @@ -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 c3233cd..b36d724 100644 --- a/lib/libthr/thread/thr_getschedparam.c +++ b/lib/libthr/thread/thr_getschedparam.c @@ -33,6 +33,8 @@ */ #include "namespace.h" +#include <sys/types.h> +#include <sys/rtprio.h> #include <errno.h> #include <pthread.h> #include "un-namespace.h" diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index f0da5f6..3624cf8 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 aa7dce6..649a973 100644 --- a/lib/libthr/thread/thr_kern.c +++ b/lib/libthr/thread/thr_kern.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <sys/signalvar.h> +#include <sys/rtprio.h> #include <pthread.h> #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 eb9c25c..0099a94 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 cca4771..21bb1a4 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 5ed6a49..59d62dc 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 { |