2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
1998-03-28 11:51:01 +00:00
|
|
|
* Copyright (c) 1996, 1997, 1998
|
|
|
|
* HD Associates, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by HD Associates, Inc
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* p1003_1b: Real Time common code.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:34:30 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-11-15 22:55:06 +00:00
|
|
|
#include "opt_posix.h"
|
|
|
|
|
1998-03-28 11:51:01 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/mutex.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
1998-03-28 11:51:01 +00:00
|
|
|
#include <sys/proc.h>
|
2006-11-11 16:19:12 +00:00
|
|
|
#include <sys/posix4.h>
|
2005-03-31 22:54:48 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysent.h>
|
1998-03-28 11:51:01 +00:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
|
|
|
|
|
2007-03-05 13:10:58 +00:00
|
|
|
/* The system calls return ENOSYS if an entry is called that is not run-time
|
|
|
|
* supported. I am also logging since some programs start to use this when
|
|
|
|
* they shouldn't. That will be removed if annoying.
|
1998-05-18 12:53:45 +00:00
|
|
|
*/
|
1998-03-28 11:51:01 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
|
2007-11-14 06:21:24 +00:00
|
|
|
td->td_name, td->td_proc->p_pid, s);
|
1998-05-18 12:53:45 +00:00
|
|
|
|
|
|
|
/* a " return nosys(p, uap); " here causes a core dump.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return ENOSYS;
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(_KPOSIX_PRIORITY_SCHEDULING)
|
|
|
|
|
1999-04-17 08:36:07 +00:00
|
|
|
/* Not configured but loadable via a module:
|
1998-03-28 11:51:01 +00:00
|
|
|
*/
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
static int
|
|
|
|
sched_attach(void)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_setparam)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_getparam)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_yield)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
|
|
|
|
SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Configured in kernel version:
|
|
|
|
*/
|
|
|
|
static struct ksched *ksched;
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
static int
|
|
|
|
sched_attach(void)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
int ret = ksched_attach(&ksched);
|
|
|
|
|
|
|
|
if (ret == 0)
|
2010-11-19 17:56:16 +00:00
|
|
|
p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 200112L);
|
1998-03-28 11:51:01 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_setparam(struct thread *td, struct sched_setparam_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *targettd;
|
2001-06-30 03:13:36 +00:00
|
|
|
struct proc *targetp;
|
1998-03-28 11:51:01 +00:00
|
|
|
int e;
|
1998-05-19 21:11:53 +00:00
|
|
|
struct sched_param sched_param;
|
2001-08-31 22:34:40 +00:00
|
|
|
|
2001-06-28 22:53:42 +00:00
|
|
|
e = copyin(uap->param, &sched_param, sizeof(sched_param));
|
|
|
|
if (e)
|
|
|
|
return (e);
|
1998-05-19 21:11:53 +00:00
|
|
|
|
2001-06-30 07:55:19 +00:00
|
|
|
if (uap->pid == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
targetp = td->td_proc;
|
|
|
|
targettd = td;
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_LOCK(targetp);
|
2006-07-13 06:41:26 +00:00
|
|
|
} else {
|
2001-06-30 07:55:19 +00:00
|
|
|
targetp = pfind(uap->pid);
|
2006-07-11 06:11:34 +00:00
|
|
|
if (targetp == NULL)
|
|
|
|
return (ESRCH);
|
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
e = p_cansched(td, targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0) {
|
2006-07-11 06:11:34 +00:00
|
|
|
e = ksched_setparam(ksched, targettd,
|
2001-08-31 22:34:40 +00:00
|
|
|
(const struct sched_param *)&sched_param);
|
|
|
|
}
|
2006-04-10 04:55:59 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_getparam(struct thread *td, struct sched_getparam_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
int e;
|
1998-05-19 21:11:53 +00:00
|
|
|
struct sched_param sched_param;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *targettd;
|
2001-06-30 03:13:36 +00:00
|
|
|
struct proc *targetp;
|
1998-03-28 11:51:01 +00:00
|
|
|
|
2001-06-30 07:55:19 +00:00
|
|
|
if (uap->pid == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
targetp = td->td_proc;
|
|
|
|
targettd = td;
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_LOCK(targetp);
|
2006-07-13 06:41:26 +00:00
|
|
|
} else {
|
2001-06-30 07:55:19 +00:00
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
2006-07-11 06:11:34 +00:00
|
|
|
return (ESRCH);
|
2001-08-31 22:34:40 +00:00
|
|
|
}
|
2008-03-12 10:12:01 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
e = p_cansee(td, targetp);
|
2006-04-10 04:55:59 +00:00
|
|
|
if (e == 0) {
|
2006-07-11 06:11:34 +00:00
|
|
|
e = ksched_getparam(ksched, targettd, &sched_param);
|
2006-04-10 04:55:59 +00:00
|
|
|
}
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0)
|
|
|
|
e = copyout(&sched_param, uap->param, sizeof(sched_param));
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
int e;
|
1998-05-19 21:11:53 +00:00
|
|
|
struct sched_param sched_param;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *targettd;
|
2001-06-30 03:13:36 +00:00
|
|
|
struct proc *targetp;
|
|
|
|
|
2006-11-06 13:42:10 +00:00
|
|
|
/* Don't allow non root user to set a scheduler policy. */
|
|
|
|
e = priv_check(td, PRIV_SCHED_SET);
|
|
|
|
if (e)
|
|
|
|
return (e);
|
2006-05-21 00:40:38 +00:00
|
|
|
|
2001-06-28 22:53:42 +00:00
|
|
|
e = copyin(uap->param, &sched_param, sizeof(sched_param));
|
|
|
|
if (e)
|
|
|
|
return (e);
|
1998-05-19 21:11:53 +00:00
|
|
|
|
2001-06-30 07:55:19 +00:00
|
|
|
if (uap->pid == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
targetp = td->td_proc;
|
|
|
|
targettd = td;
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_LOCK(targetp);
|
2006-07-13 06:41:26 +00:00
|
|
|
} else {
|
2001-06-30 07:55:19 +00:00
|
|
|
targetp = pfind(uap->pid);
|
2006-07-11 06:11:34 +00:00
|
|
|
if (targetp == NULL)
|
|
|
|
return (ESRCH);
|
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
e = p_cansched(td, targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0) {
|
2006-07-11 06:11:34 +00:00
|
|
|
e = ksched_setscheduler(ksched, targettd,
|
2001-09-12 08:38:13 +00:00
|
|
|
uap->policy, (const struct sched_param *)&sched_param);
|
2001-08-31 22:34:40 +00:00
|
|
|
}
|
2006-04-10 04:55:59 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
2006-07-11 06:11:34 +00:00
|
|
|
int e, policy;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *targettd;
|
2001-06-30 03:13:36 +00:00
|
|
|
struct proc *targetp;
|
1998-03-28 11:51:01 +00:00
|
|
|
|
2001-06-30 07:55:19 +00:00
|
|
|
if (uap->pid == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
targetp = td->td_proc;
|
|
|
|
targettd = td;
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_LOCK(targetp);
|
2006-07-13 06:41:26 +00:00
|
|
|
} else {
|
2001-06-30 07:55:19 +00:00
|
|
|
targetp = pfind(uap->pid);
|
2010-09-29 07:31:05 +00:00
|
|
|
if (targetp == NULL)
|
|
|
|
return (ESRCH);
|
2008-03-12 10:12:01 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
e = p_cansee(td, targetp);
|
2006-07-11 06:11:34 +00:00
|
|
|
if (e == 0) {
|
|
|
|
e = ksched_getscheduler(ksched, targettd, &policy);
|
|
|
|
td->td_retval[0] = policy;
|
|
|
|
}
|
2006-04-10 04:55:59 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-06-28 23:02:09 +00:00
|
|
|
|
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_yield(struct thread *td, struct sched_yield_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
2001-08-31 22:34:40 +00:00
|
|
|
|
2007-10-08 23:45:24 +00:00
|
|
|
sched_relinquish(curthread);
|
|
|
|
return 0;
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_get_priority_max(struct thread *td,
|
|
|
|
struct sched_get_priority_max_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
2006-07-11 06:11:34 +00:00
|
|
|
int error, prio;
|
2001-08-31 22:34:40 +00:00
|
|
|
|
2006-07-11 06:11:34 +00:00
|
|
|
error = ksched_get_priority_max(ksched, uap->policy, &prio);
|
|
|
|
td->td_retval[0] = prio;
|
2001-08-31 22:34:40 +00:00
|
|
|
return (error);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_get_priority_min(struct thread *td,
|
|
|
|
struct sched_get_priority_min_args *uap)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
2006-07-11 06:11:34 +00:00
|
|
|
int error, prio;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-07-11 06:11:34 +00:00
|
|
|
error = ksched_get_priority_min(ksched, uap->policy, &prio);
|
|
|
|
td->td_retval[0] = prio;
|
2001-08-31 22:34:40 +00:00
|
|
|
return (error);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
sched_rr_get_interval(struct thread *td,
|
|
|
|
struct sched_rr_get_interval_args *uap)
|
2005-03-31 22:54:48 +00:00
|
|
|
{
|
|
|
|
struct timespec timespec;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = kern_sched_rr_get_interval(td, uap->pid, ×pec);
|
|
|
|
if (error == 0)
|
|
|
|
error = copyout(×pec, uap->interval, sizeof(timespec));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
int
|
|
|
|
kern_sched_rr_get_interval(struct thread *td, pid_t pid,
|
2005-03-31 22:54:48 +00:00
|
|
|
struct timespec *ts)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
int e;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *targettd;
|
2001-06-30 03:13:36 +00:00
|
|
|
struct proc *targetp;
|
1998-03-28 11:51:01 +00:00
|
|
|
|
2005-03-31 22:54:48 +00:00
|
|
|
if (pid == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
targettd = td;
|
|
|
|
targetp = td->td_proc;
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_LOCK(targetp);
|
2006-07-11 06:11:34 +00:00
|
|
|
} else {
|
2010-09-29 07:31:05 +00:00
|
|
|
targetp = pfind(pid);
|
|
|
|
if (targetp == NULL)
|
2006-07-11 06:11:34 +00:00
|
|
|
return (ESRCH);
|
2010-09-29 07:31:05 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
e = p_cansee(td, targetp);
|
2005-03-31 22:54:48 +00:00
|
|
|
if (e == 0)
|
2006-07-11 06:11:34 +00:00
|
|
|
e = ksched_rr_get_interval(ksched, targettd, ts);
|
2005-03-31 22:54:48 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-05-19 06:37:24 +00:00
|
|
|
static void
|
|
|
|
p31binit(void *notused)
|
1998-03-28 11:51:01 +00:00
|
|
|
{
|
|
|
|
(void) sched_attach();
|
1998-06-01 21:54:43 +00:00
|
|
|
p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);
|