summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-04-27 08:18:23 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-04-27 08:18:23 +0000
commit66d0fee031ed44d54ee9e1a183fbe75c37a6e158 (patch)
treedaa71c55e66d8720e95d00de6f5673a23b90bfa8 /lib/libthr
parente4cefd49df59b5e0ac6b8c1791cf554240bae189 (diff)
downloadFreeBSD-src-66d0fee031ed44d54ee9e1a183fbe75c37a6e158.zip
FreeBSD-src-66d0fee031ed44d54ee9e1a183fbe75c37a6e158.tar.gz
- Use same priority range returned by kernel's sched_get_priority_min()
and sched_get_priority_max() syscalls. - Remove unused fields from structure pthread_attr.
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_attr.c30
-rw-r--r--lib/libthr/thread/thr_getschedparam.c6
-rw-r--r--lib/libthr/thread/thr_init.c18
-rw-r--r--lib/libthr/thread/thr_mutexattr.c2
-rw-r--r--lib/libthr/thread/thr_private.h49
-rw-r--r--lib/libthr/thread/thr_setschedparam.c7
6 files changed, 57 insertions, 55 deletions
diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c
index 906f45c..24dd064 100644
--- a/lib/libthr/thread/thr_attr.c
+++ b/lib/libthr/thread/thr_attr.c
@@ -424,20 +424,23 @@ __weak_reference(_pthread_attr_setschedparam, pthread_attr_setschedparam);
int
_pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
{
- int ret = 0;
+ int policy;
if ((attr == NULL) || (*attr == NULL))
- ret = EINVAL;
- else if (param == NULL) {
- ret = ENOTSUP;
- } else if ((param->sched_priority < THR_MIN_PRIORITY) ||
- (param->sched_priority > THR_MAX_PRIORITY)) {
- /* Return an unsupported value error. */
- ret = ENOTSUP;
- } else
- (*attr)->prio = param->sched_priority;
+ return (EINVAL);
- return(ret);
+ if (param == NULL)
+ return (ENOTSUP);
+
+ policy = (*attr)->sched_policy;
+
+ if (param->sched_priority < _thr_priorities[policy-1].pri_min ||
+ param->sched_priority > _thr_priorities[policy-1].pri_max)
+ return (ENOTSUP);
+
+ (*attr)->prio = param->sched_priority;
+
+ return (0);
}
__weak_reference(_pthread_attr_setschedpolicy, pthread_attr_setschedpolicy);
@@ -451,9 +454,10 @@ _pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
ret = EINVAL;
else if ((policy < SCHED_FIFO) || (policy > SCHED_RR)) {
ret = ENOTSUP;
- } else
+ } else {
(*attr)->sched_policy = policy;
-
+ (*attr)->prio = _thr_priorities[policy-1].pri_default;
+ }
return(ret);
}
diff --git a/lib/libthr/thread/thr_getschedparam.c b/lib/libthr/thread/thr_getschedparam.c
index 88d8524..31b3268 100644
--- a/lib/libthr/thread/thr_getschedparam.c
+++ b/lib/libthr/thread/thr_getschedparam.c
@@ -57,8 +57,7 @@ _pthread_getschedparam(pthread_t pthread, int *policy,
* thread.
*/
THR_THREAD_LOCK(curthread, curthread);
- param->sched_priority =
- THR_BASE_PRIORITY(pthread->base_priority);
+ param->sched_priority = pthread->base_priority;
tmp = pthread->attr.sched_policy;
THR_THREAD_UNLOCK(curthread, curthread);
*policy = tmp;
@@ -68,8 +67,7 @@ _pthread_getschedparam(pthread_t pthread, int *policy,
else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
== 0) {
THR_THREAD_LOCK(curthread, pthread);
- param->sched_priority =
- THR_BASE_PRIORITY(pthread->base_priority);
+ param->sched_priority = pthread->base_priority;
tmp = pthread->attr.sched_policy;
THR_THREAD_UNLOCK(curthread, pthread);
_thr_ref_delete(curthread, pthread);
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 05006dc..40365a0 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -67,14 +67,22 @@ int _thread_active_threads = 1;
atfork_head _thr_atfork_list = TAILQ_HEAD_INITIALIZER(_thr_atfork_list);
umtx_t _thr_atfork_lock;
+/*
+ * XXX these values should be updated from kernel at startup,
+ * but current they are same.
+ */
+struct pthread_prio _thr_priorities[3] = {
+ {0, 31, 0}, /* FIF0 */
+ {-20, 20, 0}, /* OTHER */
+ {0, 31, 0} /* RR */
+};
+
struct pthread_attr _pthread_attr_default = {
.sched_policy = SCHED_OTHER,
.sched_inherit = 0,
- .sched_interval = TIMESLICE_USEC,
- .prio = THR_DEFAULT_PRIORITY,
+ .prio = 0,
.suspend = THR_CREATE_RUNNING,
.flags = PTHREAD_SCOPE_SYSTEM,
- .arg_attr = NULL,
.stackaddr_attr = NULL,
.stacksize_attr = THR_STACK_DEFAULT,
.guardsize_attr = 0
@@ -400,8 +408,8 @@ init_main_thread(struct pthread *thread)
thr_set_name(thread->tid, "initial thread");
/* Default the priority of the initial thread: */
- thread->base_priority = THR_DEFAULT_PRIORITY;
- thread->active_priority = THR_DEFAULT_PRIORITY;
+ thread->base_priority = THR_DEF_PRIORITY;
+ thread->active_priority = THR_DEF_PRIORITY;
thread->inherited_priority = 0;
/* Initialize the mutex queue: */
diff --git a/lib/libthr/thread/thr_mutexattr.c b/lib/libthr/thread/thr_mutexattr.c
index c77d946..7244c58 100644
--- a/lib/libthr/thread/thr_mutexattr.c
+++ b/lib/libthr/thread/thr_mutexattr.c
@@ -225,7 +225,7 @@ _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
ret = EINVAL;
else {
(*mattr)->m_protocol = protocol;
- (*mattr)->m_ceiling = THR_MAX_PRIORITY;
+ (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY;
}
return(ret);
}
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index bc91b94..9863a3b 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -232,12 +232,10 @@ struct pthread_atfork {
struct pthread_attr {
int sched_policy;
int sched_inherit;
- int sched_interval;
int prio;
int suspend;
#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
int flags;
- void *arg_attr;
void *stackaddr_attr;
size_t stacksize_attr;
size_t guardsize_attr;
@@ -262,33 +260,26 @@ struct pthread_attr {
#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
/*
- * Define the different priority ranges. All applications have thread
- * priorities constrained within 0-31. The threads library raises the
- * priority when delivering signals in order to ensure that signal
- * delivery happens (from the POSIX spec) "as soon as possible".
- * In the future, the threads library will also be able to map specific
- * threads into real-time (cooperating) processes or kernel threads.
- * The RT and SIGNAL priorities will be used internally and added to
- * thread base priorities so that the scheduling queue can handle both
- * normal and RT priority threads with and without signal handling.
- *
- * The approach taken is that, within each class, signal delivery
- * always has priority over thread execution.
- */
-#define THR_DEFAULT_PRIORITY 15
-#define THR_MIN_PRIORITY 0
-#define THR_MAX_PRIORITY 31 /* 0x1F */
-#define THR_SIGNAL_PRIORITY 32 /* 0x20 */
-#define THR_RT_PRIORITY 64 /* 0x40 */
-#define THR_FIRST_PRIORITY THR_MIN_PRIORITY
-#define THR_LAST_PRIORITY \
- (THR_MAX_PRIORITY + THR_SIGNAL_PRIORITY + THR_RT_PRIORITY)
-#define THR_BASE_PRIORITY(prio) ((prio) & THR_MAX_PRIORITY)
-
-/*
- * Time slice period in microseconds.
+ * Define priorities returned by kernel.
*/
-#define TIMESLICE_USEC 20000
+#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
+#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
+#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
+
+#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
+#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
+#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
+
+/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
+#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
+#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_min)
+#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
+
+struct pthread_prio {
+ int pri_min;
+ int pri_max;
+ int pri_default;
+};
struct pthread_rwlockattr {
int pshared;
@@ -622,6 +613,8 @@ extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
/* Default condition variable attributes: */
extern struct pthread_cond_attr _pthread_condattr_default __hidden;
+extern struct pthread_prio _thr_priorities[] __hidden;
+
extern pid_t _thr_pid __hidden;
extern size_t _thr_guard_default __hidden;
extern size_t _thr_stack_default __hidden;
diff --git a/lib/libthr/thread/thr_setschedparam.c b/lib/libthr/thread/thr_setschedparam.c
index 9cbebbf..eba5017 100644
--- a/lib/libthr/thread/thr_setschedparam.c
+++ b/lib/libthr/thread/thr_setschedparam.c
@@ -55,8 +55,8 @@ _pthread_setschedparam(pthread_t pthread, int policy,
if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) {
ret = EINVAL;
- } else if ((param->sched_priority < THR_MIN_PRIORITY) ||
- (param->sched_priority > THR_MAX_PRIORITY)) {
+ } else if (param->sched_priority < _thr_priorities[policy-1].pri_min ||
+ param->sched_priority > _thr_priorities[policy-1].pri_max) {
ret = ENOTSUP;
} else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
== 0) {
@@ -74,8 +74,7 @@ _pthread_setschedparam(pthread_t pthread, int policy,
/* Set the scheduling policy: */
pthread->attr.sched_policy = policy;
- if (param->sched_priority ==
- THR_BASE_PRIORITY(pthread->base_priority))
+ if (param->sched_priority == pthread->base_priority)
/*
* There is nothing to do; unlock the threads
* scheduling queue.
OpenPOWER on IntegriCloud