2008-04-24 22:39:20 +04:00
|
|
|
/* $NetBSD: sys_sched.c,v 1.21 2008/04/24 18:39:24 ad Exp $ */
|
2007-01-16 08:28:45 +03:00
|
|
|
|
2008-01-15 06:37:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
|
2007-01-16 08:28:45 +03:00
|
|
|
* All rights reserved.
|
2008-01-15 06:37:10 +03:00
|
|
|
*
|
2007-01-16 08:28:45 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2008-02-23 01:32:49 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2007-01-16 08:28:45 +03:00
|
|
|
*/
|
|
|
|
|
2008-01-15 06:37:10 +03:00
|
|
|
/*
|
2008-02-23 02:10:12 +03:00
|
|
|
* System calls relating to the scheduler.
|
|
|
|
*
|
2008-01-15 06:37:10 +03:00
|
|
|
* TODO:
|
|
|
|
* - Handle pthread_setschedprio() as defined by POSIX;
|
|
|
|
* - Handle sched_yield() case for SCHED_FIFO as defined by POSIX;
|
|
|
|
*/
|
|
|
|
|
2007-01-16 08:28:45 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-04-24 22:39:20 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.21 2008/04/24 18:39:24 ad Exp $");
|
2007-01-16 08:28:45 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/kauth.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/lwp.h>
|
|
|
|
#include <sys/mutex.h>
|
2007-01-16 08:28:45 +03:00
|
|
|
#include <sys/proc.h>
|
2008-01-15 06:37:10 +03:00
|
|
|
#include <sys/pset.h>
|
|
|
|
#include <sys/sched.h>
|
2007-01-16 08:28:45 +03:00
|
|
|
#include <sys/syscallargs.h>
|
2008-01-15 06:37:10 +03:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
|
2008-01-26 20:55:29 +03:00
|
|
|
/*
|
|
|
|
* Convert user priority or the in-kernel priority or convert the current
|
|
|
|
* priority to the appropriate range according to the policy change.
|
|
|
|
*/
|
|
|
|
static pri_t
|
|
|
|
convert_pri(lwp_t *l, int policy, pri_t pri)
|
|
|
|
{
|
|
|
|
int delta = 0;
|
|
|
|
|
|
|
|
switch (policy) {
|
|
|
|
case SCHED_OTHER:
|
|
|
|
delta = PRI_USER;
|
|
|
|
break;
|
|
|
|
case SCHED_FIFO:
|
|
|
|
case SCHED_RR:
|
|
|
|
delta = PRI_USER_RT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("upri_to_kpri");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pri != PRI_NONE) {
|
|
|
|
/* Convert user priority to the in-kernel */
|
|
|
|
KASSERT(pri >= SCHED_PRI_MIN && pri <= SCHED_PRI_MAX);
|
|
|
|
return pri + delta;
|
|
|
|
}
|
|
|
|
if (l->l_class == policy)
|
|
|
|
return l->l_priority;
|
|
|
|
|
|
|
|
/* Change the current priority to the appropriate range */
|
|
|
|
if (l->l_class == SCHED_OTHER) {
|
|
|
|
KASSERT(policy == SCHED_FIFO || policy == SCHED_RR);
|
|
|
|
return l->l_priority + delta;
|
|
|
|
}
|
|
|
|
if (policy == SCHED_OTHER) {
|
|
|
|
KASSERT(l->l_class == SCHED_FIFO || l->l_class == SCHED_RR);
|
|
|
|
return l->l_priority - delta;
|
|
|
|
}
|
|
|
|
KASSERT(l->l_class != SCHED_OTHER && policy != SCHED_OTHER);
|
|
|
|
return l->l_class;
|
|
|
|
}
|
|
|
|
|
2008-01-15 06:37:10 +03:00
|
|
|
int
|
2008-02-28 19:09:18 +03:00
|
|
|
do_sched_setparam(pid_t pid, lwpid_t lid, int policy,
|
|
|
|
const struct sched_param *params)
|
2008-01-15 06:37:10 +03:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
struct lwp *t;
|
|
|
|
pri_t pri;
|
2008-02-28 19:09:18 +03:00
|
|
|
u_int lcnt;
|
2008-01-15 06:37:10 +03:00
|
|
|
int error;
|
|
|
|
|
2008-02-28 19:09:18 +03:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
pri = params->sched_priority;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
2008-01-26 20:55:29 +03:00
|
|
|
/* If no parameters specified, just return (this should not happen) */
|
|
|
|
if (pri == PRI_NONE && policy == SCHED_NONE)
|
|
|
|
return 0;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
2008-01-26 20:55:29 +03:00
|
|
|
/* Validate scheduling class */
|
|
|
|
if (policy != SCHED_NONE && (policy < SCHED_OTHER || policy > SCHED_RR))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Validate priority */
|
|
|
|
if (pri != PRI_NONE && (pri < SCHED_PRI_MIN || pri > SCHED_PRI_MAX))
|
|
|
|
return EINVAL;
|
|
|
|
|
2008-02-28 19:09:18 +03:00
|
|
|
if (pid != 0) {
|
2008-01-26 20:55:29 +03:00
|
|
|
/* Find the process */
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
|
|
|
p = p_find(pid, PFIND_LOCKED);
|
|
|
|
if (p == NULL) {
|
|
|
|
mutex_exit(proc_lock);
|
2008-01-26 20:55:29 +03:00
|
|
|
return ESRCH;
|
2008-04-24 19:35:27 +04:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-01-26 20:55:29 +03:00
|
|
|
/* Disallow modification of system processes */
|
2008-02-23 02:10:12 +03:00
|
|
|
if ((p->p_flag & PK_SYSTEM) != 0) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-01-26 20:55:29 +03:00
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Use the calling process */
|
2008-02-28 19:09:18 +03:00
|
|
|
p = curlwp->l_proc;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2008-01-15 06:37:10 +03:00
|
|
|
}
|
2007-01-16 08:28:45 +03:00
|
|
|
|
2008-01-15 06:37:10 +03:00
|
|
|
/* Find the LWP(s) */
|
|
|
|
lcnt = 0;
|
|
|
|
LIST_FOREACH(t, &p->p_lwps, l_sibling) {
|
2008-01-26 20:55:29 +03:00
|
|
|
pri_t kpri;
|
2008-02-17 22:22:35 +03:00
|
|
|
int lpolicy;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
if (lid && lid != t->l_lid)
|
|
|
|
continue;
|
2008-02-19 22:38:18 +03:00
|
|
|
lcnt++;
|
2008-01-26 20:55:29 +03:00
|
|
|
KASSERT(pri != PRI_NONE || policy != SCHED_NONE);
|
|
|
|
lwp_lock(t);
|
|
|
|
|
2008-02-17 22:22:35 +03:00
|
|
|
if (policy == SCHED_NONE)
|
2008-02-18 05:00:08 +03:00
|
|
|
lpolicy = t->l_class;
|
2008-02-17 22:22:35 +03:00
|
|
|
else
|
|
|
|
lpolicy = policy;
|
|
|
|
|
2008-01-26 20:55:29 +03:00
|
|
|
/*
|
|
|
|
* Note that, priority may need to be changed to get into
|
|
|
|
* the correct priority range of the new scheduling class.
|
|
|
|
*/
|
2008-02-17 22:22:35 +03:00
|
|
|
kpri = convert_pri(t, lpolicy, pri);
|
|
|
|
|
|
|
|
/* Check the permission */
|
2008-02-28 19:09:18 +03:00
|
|
|
error = kauth_authorize_process(kauth_cred_get(),
|
2008-02-17 22:22:35 +03:00
|
|
|
KAUTH_PROCESS_SCHEDULER_SETPARAM, p, t, KAUTH_ARG(lpolicy),
|
|
|
|
KAUTH_ARG(kpri));
|
2008-02-19 12:44:26 +03:00
|
|
|
if (error) {
|
|
|
|
lwp_unlock(t);
|
2008-02-17 22:22:35 +03:00
|
|
|
break;
|
2008-02-19 12:44:26 +03:00
|
|
|
}
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
/* Set the scheduling class */
|
2008-01-26 20:55:29 +03:00
|
|
|
if (policy != SCHED_NONE)
|
|
|
|
t->l_class = policy;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
/* Change the priority */
|
2008-01-26 20:55:29 +03:00
|
|
|
if (t->l_priority != kpri)
|
|
|
|
lwp_changepri(t, kpri);
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
lwp_unlock(t);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-01-26 20:55:29 +03:00
|
|
|
return (lcnt == 0) ? ESRCH : error;
|
2008-01-15 06:37:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-28 19:09:18 +03:00
|
|
|
* Set scheduling parameters.
|
2008-01-15 06:37:10 +03:00
|
|
|
*/
|
|
|
|
int
|
2008-02-28 19:09:18 +03:00
|
|
|
sys__sched_setparam(struct lwp *l, const struct sys__sched_setparam_args *uap,
|
2008-01-15 06:37:10 +03:00
|
|
|
register_t *retval)
|
|
|
|
{
|
|
|
|
/* {
|
|
|
|
syscallarg(pid_t) pid;
|
|
|
|
syscallarg(lwpid_t) lid;
|
2008-02-28 19:09:18 +03:00
|
|
|
syscallarg(int) policy;
|
|
|
|
syscallarg(const struct sched_param *) params;
|
2008-01-15 06:37:10 +03:00
|
|
|
} */
|
2008-02-28 19:09:18 +03:00
|
|
|
struct sched_param params;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Get the parameters from the user-space */
|
|
|
|
error = copyin(SCARG(uap, params), ¶ms, sizeof(params));
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = do_sched_setparam(SCARG(uap, pid), SCARG(uap, lid),
|
|
|
|
SCARG(uap, policy), ¶ms);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
do_sched_getparam(pid_t pid, lwpid_t lid, int *policy,
|
|
|
|
struct sched_param *params)
|
|
|
|
{
|
|
|
|
struct sched_param lparams;
|
2008-01-15 06:37:10 +03:00
|
|
|
struct lwp *t;
|
2008-02-28 19:09:18 +03:00
|
|
|
int error, lpolicy;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
2008-02-23 01:32:49 +03:00
|
|
|
/* Locks the LWP */
|
2008-02-28 19:09:18 +03:00
|
|
|
t = lwp_find2(pid, lid);
|
2008-04-24 22:39:20 +04:00
|
|
|
if (t == NULL)
|
|
|
|
return ESRCH;
|
2008-02-09 19:58:01 +03:00
|
|
|
|
|
|
|
/* Check the permission */
|
2008-02-28 19:09:18 +03:00
|
|
|
error = kauth_authorize_process(kauth_cred_get(),
|
2008-02-16 19:39:34 +03:00
|
|
|
KAUTH_PROCESS_SCHEDULER_GETPARAM, t->l_proc, NULL, NULL, NULL);
|
2008-02-09 19:58:01 +03:00
|
|
|
if (error != 0) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->l_proc->p_lock);
|
|
|
|
return error;
|
2008-02-09 19:58:01 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
lwp_lock(t);
|
2008-02-28 19:09:18 +03:00
|
|
|
lparams.sched_priority = t->l_priority;
|
|
|
|
lpolicy = t->l_class;
|
2008-01-15 06:37:10 +03:00
|
|
|
|
2008-02-28 19:09:18 +03:00
|
|
|
switch (lpolicy) {
|
2008-01-15 06:37:10 +03:00
|
|
|
case SCHED_OTHER:
|
2008-02-28 19:09:18 +03:00
|
|
|
lparams.sched_priority -= PRI_USER;
|
2008-01-15 06:37:10 +03:00
|
|
|
break;
|
|
|
|
case SCHED_RR:
|
|
|
|
case SCHED_FIFO:
|
2008-02-28 19:09:18 +03:00
|
|
|
lparams.sched_priority -= PRI_USER_RT;
|
2008-01-15 06:37:10 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-02-28 19:09:18 +03:00
|
|
|
|
|
|
|
if (policy != NULL)
|
|
|
|
*policy = lpolicy;
|
|
|
|
|
|
|
|
if (params != NULL)
|
|
|
|
*params = lparams;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
lwp_unlock(t);
|
|
|
|
mutex_exit(t->l_proc->p_lock);
|
2008-02-28 19:09:18 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get scheduling parameters.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sys__sched_getparam(struct lwp *l, const struct sys__sched_getparam_args *uap,
|
|
|
|
register_t *retval)
|
|
|
|
{
|
|
|
|
/* {
|
|
|
|
syscallarg(pid_t) pid;
|
|
|
|
syscallarg(lwpid_t) lid;
|
|
|
|
syscallarg(int *) policy;
|
|
|
|
syscallarg(struct sched_param *) params;
|
|
|
|
} */
|
|
|
|
struct sched_param params;
|
|
|
|
int error, policy;
|
|
|
|
|
|
|
|
error = do_sched_getparam(SCARG(uap, pid), SCARG(uap, lid), &policy,
|
|
|
|
¶ms);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = copyout(¶ms, SCARG(uap, params), sizeof(params));
|
2008-02-09 19:58:01 +03:00
|
|
|
if (error == 0 && SCARG(uap, policy) != NULL)
|
|
|
|
error = copyout(&policy, SCARG(uap, policy), sizeof(int));
|
2008-02-28 19:09:18 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
return (error);
|
2008-01-15 06:37:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set affinity.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sys__sched_setaffinity(struct lwp *l,
|
|
|
|
const struct sys__sched_setaffinity_args *uap, register_t *retval)
|
|
|
|
{
|
|
|
|
/* {
|
|
|
|
syscallarg(pid_t) pid;
|
|
|
|
syscallarg(lwpid_t) lid;
|
|
|
|
syscallarg(size_t) size;
|
|
|
|
syscallarg(void *) cpuset;
|
|
|
|
} */
|
|
|
|
cpuset_t *cpuset;
|
|
|
|
struct cpu_info *ci = NULL;
|
|
|
|
struct proc *p;
|
|
|
|
struct lwp *t;
|
|
|
|
CPU_INFO_ITERATOR cii;
|
|
|
|
lwpid_t lid;
|
|
|
|
u_int lcnt;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Allocate the CPU set, and get it from userspace */
|
|
|
|
cpuset = kmem_zalloc(sizeof(cpuset_t), KM_SLEEP);
|
|
|
|
error = copyin(SCARG(uap, cpuset), cpuset,
|
|
|
|
min(SCARG(uap, size), sizeof(cpuset_t)));
|
|
|
|
if (error)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Look for a CPU in the set */
|
|
|
|
for (CPU_INFO_FOREACH(cii, ci))
|
|
|
|
if (CPU_ISSET(cpu_index(ci), cpuset))
|
|
|
|
break;
|
|
|
|
if (ci == NULL) {
|
|
|
|
/* Empty set */
|
|
|
|
kmem_free(cpuset, sizeof(cpuset_t));
|
|
|
|
cpuset = NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-26 20:55:29 +03:00
|
|
|
if (SCARG(uap, pid) != 0) {
|
|
|
|
/* Find the process */
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
|
|
|
p = p_find(SCARG(uap, pid), PFIND_LOCKED);
|
2008-01-26 20:55:29 +03:00
|
|
|
if (p == NULL) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-01-26 20:55:29 +03:00
|
|
|
error = ESRCH;
|
|
|
|
goto error;
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-02-23 02:10:12 +03:00
|
|
|
/* Disallow modification of system processes. */
|
|
|
|
if ((p->p_flag & PK_SYSTEM) != 0) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-02-23 02:10:12 +03:00
|
|
|
error = EPERM;
|
|
|
|
goto error;
|
|
|
|
}
|
2008-01-26 20:55:29 +03:00
|
|
|
} else {
|
|
|
|
/* Use the calling process */
|
|
|
|
p = l->l_proc;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2008-01-15 06:37:10 +03:00
|
|
|
}
|
|
|
|
|
2008-02-09 19:58:01 +03:00
|
|
|
/*
|
|
|
|
* Check the permission.
|
|
|
|
*/
|
2008-02-16 19:39:34 +03:00
|
|
|
error = kauth_authorize_process(l->l_cred,
|
|
|
|
KAUTH_PROCESS_SCHEDULER_SETAFFINITY, p, NULL, NULL, NULL);
|
2008-02-09 19:58:01 +03:00
|
|
|
if (error != 0) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-02-09 19:58:01 +03:00
|
|
|
goto error;
|
|
|
|
}
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
/* Find the LWP(s) */
|
|
|
|
lcnt = 0;
|
|
|
|
lid = SCARG(uap, lid);
|
|
|
|
LIST_FOREACH(t, &p->p_lwps, l_sibling) {
|
|
|
|
if (lid && lid != t->l_lid)
|
|
|
|
continue;
|
|
|
|
lwp_lock(t);
|
|
|
|
if (cpuset) {
|
|
|
|
/* Set the affinity flag and new CPU set */
|
|
|
|
t->l_flag |= LW_AFFINITY;
|
|
|
|
memcpy(&t->l_affinity, cpuset, sizeof(cpuset_t));
|
|
|
|
/* Migrate to another CPU, unlocks LWP */
|
|
|
|
lwp_migrate(t, ci);
|
|
|
|
} else {
|
|
|
|
/* Unset the affinity flag */
|
|
|
|
t->l_flag &= ~LW_AFFINITY;
|
|
|
|
lwp_unlock(t);
|
|
|
|
}
|
|
|
|
lcnt++;
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-01-15 06:37:10 +03:00
|
|
|
if (lcnt == 0)
|
|
|
|
error = ESRCH;
|
|
|
|
error:
|
|
|
|
if (cpuset != NULL)
|
|
|
|
kmem_free(cpuset, sizeof(cpuset_t));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get affinity.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sys__sched_getaffinity(struct lwp *l,
|
|
|
|
const struct sys__sched_getaffinity_args *uap, register_t *retval)
|
|
|
|
{
|
|
|
|
/* {
|
|
|
|
syscallarg(pid_t) pid;
|
|
|
|
syscallarg(lwpid_t) lid;
|
|
|
|
syscallarg(size_t) size;
|
|
|
|
syscallarg(void *) cpuset;
|
|
|
|
} */
|
|
|
|
struct lwp *t;
|
|
|
|
void *cpuset;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, size) <= 0)
|
|
|
|
return EINVAL;
|
|
|
|
cpuset = kmem_zalloc(sizeof(cpuset_t), KM_SLEEP);
|
|
|
|
|
2008-02-23 01:32:49 +03:00
|
|
|
/* Locks the LWP */
|
|
|
|
t = lwp_find2(SCARG(uap, pid), SCARG(uap, lid));
|
2008-01-15 06:37:10 +03:00
|
|
|
if (t == NULL) {
|
|
|
|
kmem_free(cpuset, sizeof(cpuset_t));
|
|
|
|
return ESRCH;
|
|
|
|
}
|
2008-02-09 19:58:01 +03:00
|
|
|
/* Check the permission */
|
2008-02-16 19:39:34 +03:00
|
|
|
if (kauth_authorize_process(l->l_cred,
|
|
|
|
KAUTH_PROCESS_SCHEDULER_GETAFFINITY, t->l_proc, NULL, NULL, NULL)) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->l_proc->p_lock);
|
2008-02-09 19:58:01 +03:00
|
|
|
kmem_free(cpuset, sizeof(cpuset_t));
|
|
|
|
return EPERM;
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
lwp_lock(t);
|
2008-01-15 06:37:10 +03:00
|
|
|
if (t->l_flag & LW_AFFINITY)
|
|
|
|
memcpy(cpuset, &t->l_affinity, sizeof(cpuset_t));
|
|
|
|
lwp_unlock(t);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(t->l_proc->p_lock);
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
error = copyout(cpuset, SCARG(uap, cpuset),
|
|
|
|
min(SCARG(uap, size), sizeof(cpuset_t)));
|
|
|
|
|
|
|
|
kmem_free(cpuset, sizeof(cpuset_t));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yield.
|
|
|
|
*/
|
2007-01-16 08:28:45 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys_sched_yield(struct lwp *l, const void *v, register_t *retval)
|
2007-01-16 08:28:45 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
yield();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-15 06:37:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sysctl nodes and initialization.
|
|
|
|
*/
|
|
|
|
SYSCTL_SETUP(sysctl_sched_setup, "sysctl sched setup")
|
|
|
|
{
|
|
|
|
const struct sysctlnode *node = NULL;
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "kern", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_KERN, CTL_EOL);
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
|
|
|
|
CTLTYPE_INT, "posix_sched",
|
|
|
|
SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
|
|
|
|
"Process Scheduling option to which the "
|
|
|
|
"system attempts to conform"),
|
|
|
|
NULL, _POSIX_PRIORITY_SCHEDULING, NULL, 0,
|
|
|
|
CTL_KERN, CTL_CREATE, CTL_EOL);
|
|
|
|
sysctl_createv(clog, 0, NULL, &node,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "sched",
|
|
|
|
SYSCTL_DESCR("Scheduler options"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_KERN, CTL_CREATE, CTL_EOL);
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, &node, NULL,
|
|
|
|
CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
|
|
|
|
CTLTYPE_INT, "pri_min",
|
|
|
|
SYSCTL_DESCR("Minimal POSIX real-time priority"),
|
|
|
|
NULL, SCHED_PRI_MIN, NULL, 0,
|
|
|
|
CTL_CREATE, CTL_EOL);
|
|
|
|
sysctl_createv(clog, 0, &node, NULL,
|
|
|
|
CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
|
|
|
|
CTLTYPE_INT, "pri_max",
|
2008-03-05 15:47:13 +03:00
|
|
|
SYSCTL_DESCR("Maximal POSIX real-time priority"),
|
2008-01-15 06:37:10 +03:00
|
|
|
NULL, SCHED_PRI_MAX, NULL, 0,
|
|
|
|
CTL_CREATE, CTL_EOL);
|
|
|
|
}
|