diff options
| author | rmind <rmind@NetBSD.org> | 2008-01-26 17:55:29 +0000 |
|---|---|---|
| committer | rmind <rmind@NetBSD.org> | 2008-01-26 17:55:29 +0000 |
| commit | b5e9addd22eabcce2e017947a3b5e8569ca6500a (patch) | |
| tree | 3dd6e6289a1458aafa08984cba5c0c1f18ae4180 /lib | |
| parent | ef515ac1dc49cc036e4437a2a8dbf89d538707fe (diff) | |
sched_setparam: fix the case when incorrect (according to the class)
in-kernel priority is used. Reported by <drochner>.
Minor fixes for scheduling calls to conform the POSIX:
- If pid is equal to zero, use the calling process;
- In case of permission problem, return EPERM instead of EACESS;
- sched_setscheduler() should return previously used policy;
- pthread_* calls should return the error code or zero;
Should fix the namespace problems (and builds of some packages):
- Move cpuset_t defintion from pset.h to sched.h;
- Remove the #include of pset.h in pthread.h;
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libc/gen/sysconf.c | 6 | ||||
| -rw-r--r-- | lib/libpthread/pthread.h | 10 | ||||
| -rw-r--r-- | lib/libpthread/pthread_misc.c | 34 | ||||
| -rw-r--r-- | lib/librt/sched.c | 48 |
4 files changed, 67 insertions, 31 deletions
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 4f8e1459a26..b9180b20a5a 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysconf.c,v 1.26 2008/01/15 03:37:14 rmind Exp $ */ +/* $NetBSD: sysconf.c,v 1.27 2008/01/26 17:55:30 rmind Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; #else -__RCSID("$NetBSD: sysconf.c,v 1.26 2008/01/15 03:37:14 rmind Exp $"); +__RCSID("$NetBSD: sysconf.c,v 1.27 2008/01/26 17:55:30 rmind Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -357,7 +357,7 @@ yesno: if (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1) /* Native */ case _SC_SCHED_RT_TS: - if (sysctlgetmibinfo("kern.sched.rt_ts", &mib[0], &mib_len, + if (sysctlgetmibinfo("kern.sched.rtts", &mib[0], &mib_len, NULL, NULL, NULL, SYSCTL_VERSION)) return -1; break; diff --git a/lib/libpthread/pthread.h b/lib/libpthread/pthread.h index 05e07f1e4e8..4ad7360dde7 100644 --- a/lib/libpthread/pthread.h +++ b/lib/libpthread/pthread.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.h,v 1.27 2008/01/19 16:05:34 christos Exp $ */ +/* $NetBSD: pthread.h,v 1.28 2008/01/26 17:55:30 rmind Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -44,9 +44,6 @@ #include <time.h> /* For timespec */ #include <sched.h> #include <sys/featuretest.h> -#ifdef _NETBSD_SOURCE -#include <sys/pset.h> -#endif #include <pthread_types.h> @@ -190,13 +187,14 @@ int pthread_barrierattr_destroy(pthread_barrierattr_t *); int pthread_getschedparam(pthread_t, int * __restrict, struct sched_param * __restrict); int pthread_setschedparam(pthread_t, int, const struct sched_param *); -int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *); -int pthread_setaffinity_np(pthread_t, size_t, cpuset_t *); int pthread_setschedprio(pthread_t, int); int *pthread__errno(void); #if defined(_NETBSD_SOURCE) +int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *); +int pthread_setaffinity_np(pthread_t, size_t, cpuset_t *); + int pthread_mutex_held_np(pthread_mutex_t *); pthread_t pthread_mutex_owner_np(pthread_mutex_t *); diff --git a/lib/libpthread/pthread_misc.c b/lib/libpthread/pthread_misc.c index 42e77eae4a6..2c161b655f2 100644 --- a/lib/libpthread/pthread_misc.c +++ b/lib/libpthread/pthread_misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_misc.c,v 1.4 2008/01/15 03:37:14 rmind Exp $ */ +/* $NetBSD: pthread_misc.c,v 1.5 2008/01/26 17:55:30 rmind Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_misc.c,v 1.4 2008/01/15 03:37:14 rmind Exp $"); +__RCSID("$NetBSD: pthread_misc.c,v 1.5 2008/01/26 17:55:30 rmind Exp $"); #include <errno.h> #include <string.h> @@ -68,15 +68,15 @@ __strong_alias(__libc_thr_yield,pthread__sched_yield) int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param) { - int error; if (pthread__find(thread) != 0) return ESRCH; - error = _sched_getparam(getpid(), thread->pt_lid, param); - if (error == 0) - *policy = param->sched_class; - return error; + if (_sched_getparam(getpid(), thread->pt_lid, param) < 0) + return errno; + + *policy = param->sched_class; + return 0; } int @@ -90,7 +90,10 @@ pthread_setschedparam(pthread_t thread, int policy, memcpy(&sp, param, sizeof(struct sched_param)); sp.sched_class = policy; - return _sched_setparam(getpid(), thread->pt_lid, &sp); + if (_sched_setparam(getpid(), thread->pt_lid, &sp) < 0) + return errno; + + return 0; } int @@ -100,7 +103,10 @@ pthread_getaffinity_np(pthread_t thread, size_t size, cpuset_t *cpuset) if (pthread__find(thread) != 0) return ESRCH; - return _sched_getaffinity(getpid(), thread->pt_lid, size, cpuset); + if (_sched_getaffinity(getpid(), thread->pt_lid, size, cpuset) < 0) + return errno; + + return 0; } int @@ -110,7 +116,10 @@ pthread_setaffinity_np(pthread_t thread, size_t size, cpuset_t *cpuset) if (pthread__find(thread) != 0) return ESRCH; - return _sched_setaffinity(getpid(), thread->pt_lid, size, cpuset); + if (_sched_setaffinity(getpid(), thread->pt_lid, size, cpuset) < 0) + return errno; + + return 0; } int @@ -123,7 +132,10 @@ pthread_setschedprio(pthread_t thread, int prio) sp.sched_class = SCHED_NONE; sp.sched_priority = prio; - return _sched_setparam(getpid(), thread->pt_lid, &sp); + if (_sched_setparam(getpid(), thread->pt_lid, &sp) < 0) + return errno; + + return 0; } int diff --git a/lib/librt/sched.c b/lib/librt/sched.c index 263bebf3a3a..e2e14bdf6f7 100644 --- a/lib/librt/sched.c +++ b/lib/librt/sched.c @@ -1,4 +1,4 @@ -/* $NetBSD: sched.c,v 1.1 2008/01/15 03:37:15 rmind Exp $ */ +/* $NetBSD: sched.c,v 1.2 2008/01/26 17:55:30 rmind Exp $ */ /* * Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: sched.c,v 1.1 2008/01/15 03:37:15 rmind Exp $"); +__RCSID("$NetBSD: sched.c,v 1.2 2008/01/26 17:55:30 rmind Exp $"); #include <string.h> #include <unistd.h> @@ -37,6 +37,9 @@ __RCSID("$NetBSD: sched.c,v 1.1 2008/01/15 03:37:15 rmind Exp $"); #include <sys/pset.h> #include <sys/types.h> +/* All LWPs in the process */ +#define P_ALL_LWPS 0 + /* * Scheduling parameters. */ @@ -44,36 +47,51 @@ __RCSID("$NetBSD: sched.c,v 1.1 2008/01/15 03:37:15 rmind Exp $"); int sched_setparam(pid_t pid, const struct sched_param *param) { + struct sched_param sp; - return _sched_setparam(pid, 0, param); + memset(&sp, 0, sizeof(struct sched_param)); + sp.sched_priority = param->sched_priority; + sp.sched_class = SCHED_NONE; + return _sched_setparam(pid, P_ALL_LWPS, &sp); } int sched_getparam(pid_t pid, struct sched_param *param) { - return _sched_getparam(pid, 0, param); + return _sched_getparam(pid, P_ALL_LWPS, param); } int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param) { struct sched_param sp; + int ret, old_policy; - memcpy(&sp, param, sizeof(struct sched_param)); + ret = _sched_getparam(pid, P_ALL_LWPS, &sp); + if (ret < 0) + return ret; + old_policy = sp.sched_class; + + memset(&sp, 0, sizeof(struct sched_param)); + sp.sched_priority = param->sched_priority; sp.sched_class = policy; - return _sched_setparam(pid, 0, &sp); + ret = _sched_setparam(pid, P_ALL_LWPS, &sp); + if (ret < 0) + return ret; + + return old_policy; } int sched_getscheduler(pid_t pid) { struct sched_param sp; - int error; + int ret; - error = _sched_getparam(pid, 0, &sp); - if (error) - return error; + ret = _sched_getparam(pid, P_ALL_LWPS, &sp); + if (ret < 0) + return ret; return sp.sched_class; } @@ -86,6 +104,10 @@ int sched_get_priority_max(int policy) { + if (policy < SCHED_OTHER || policy > SCHED_RR) { + errno = EINVAL; + return -1; + } return sysconf(_SC_SCHED_PRI_MAX); } @@ -93,6 +115,10 @@ int sched_get_priority_min(int policy) { + if (policy < SCHED_OTHER || policy > SCHED_RR) { + errno = EINVAL; + return -1; + } return sysconf(_SC_SCHED_PRI_MIN); } @@ -113,5 +139,5 @@ int pset_bind(psetid_t psid, idtype_t idtype, id_t id, psetid_t *opsid) { - return _pset_bind(idtype, id, 0, psid, opsid); + return _pset_bind(idtype, id, P_ALL_LWPS, psid, opsid); } |
