summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_kern.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-09-21 04:21:30 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-09-21 04:21:30 +0000
commitd2c57b7fad5ce91e8b900f315b41d142831b90f1 (patch)
treef7b8debfd8a0b2054c46d867116922ddcfad5995 /lib/libthr/thread/thr_kern.c
parent92bd1e76b1d6d685331ec54d7b5703a34d37f84e (diff)
downloadFreeBSD-src-d2c57b7fad5ce91e8b900f315b41d142831b90f1.zip
FreeBSD-src-d2c57b7fad5ce91e8b900f315b41d142831b90f1.tar.gz
use rtprio_thread system call to get or set thread priority.
Diffstat (limited to 'lib/libthr/thread/thr_kern.c')
-rw-r--r--lib/libthr/thread/thr_kern.c66
1 files changed, 66 insertions, 0 deletions
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));
+}
OpenPOWER on IntegriCloud