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.
|
|
|
|
*
|
2000-05-01 20:32:07 +00:00
|
|
|
* $FreeBSD$
|
1998-03-28 11:51:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* p1003_1b: Real Time common code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
1998-03-28 11:51:01 +00:00
|
|
|
#include <sys/proc.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>
|
|
|
|
|
|
|
|
#include <posix4/posix4.h>
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
|
|
|
|
|
1998-05-18 12:53:45 +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-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",
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_proc->p_comm, 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
|
|
|
*/
|
|
|
|
|
|
|
|
static int sched_attach(void)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
static int sched_attach(void)
|
|
|
|
{
|
|
|
|
int ret = ksched_attach(&ksched);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_setparam(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_setparam_args *uap)
|
|
|
|
{
|
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-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
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);
|
|
|
|
} else {
|
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
|
|
|
e = ESRCH;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-02-07 20:58:47 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = p_cansched(td->td_proc, targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
e = ksched_setparam(&td->td_retval[0], ksched, targettd,
|
2001-08-31 22:34:40 +00:00
|
|
|
(const struct sched_param *)&sched_param);
|
|
|
|
}
|
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_getparam(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_getparam_args *uap)
|
|
|
|
{
|
|
|
|
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-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
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);
|
|
|
|
} else {
|
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
|
|
|
e = ESRCH;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-02-07 20:58:47 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = p_cansee(td->td_proc, targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-06-28 23:02:09 +00:00
|
|
|
if (e)
|
2001-08-31 22:34:40 +00:00
|
|
|
goto done2;
|
2001-06-30 07:55:19 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0)
|
|
|
|
e = copyout(&sched_param, uap->param, sizeof(sched_param));
|
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
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
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_setscheduler(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_setscheduler_args *uap)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
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-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
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);
|
|
|
|
} else {
|
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
|
|
|
e = ESRCH;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-02-07 20:58:47 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = p_cansched(td->td_proc, targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
|
|
|
|
uap->policy, (const struct sched_param *)&sched_param);
|
2001-08-31 22:34:40 +00:00
|
|
|
}
|
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
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
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_getscheduler(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_getscheduler_args *uap)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
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);
|
|
|
|
} else {
|
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
|
|
|
e = ESRCH;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-02-07 20:58:47 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = p_cansee(td->td_proc, targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0)
|
2001-09-12 08:38:13 +00:00
|
|
|
e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
|
2001-06-28 23:02:09 +00:00
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
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
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_yield(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_yield_args *uap)
|
|
|
|
{
|
2001-08-31 22:34:40 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ksched_yield(&td->td_retval[0], ksched);
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_get_priority_max(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_get_priority_max_args *uap)
|
|
|
|
{
|
2001-08-31 22:34:40 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_get_priority_min(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_get_priority_min_args *uap)
|
|
|
|
{
|
2001-08-31 22:34:40 +00:00
|
|
|
int error;
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
int sched_rr_get_interval(struct thread *td,
|
1998-03-28 11:51:01 +00:00
|
|
|
struct sched_rr_get_interval_args *uap)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2001-08-31 22:34:40 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-06-30 07:55:19 +00:00
|
|
|
if (uap->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);
|
|
|
|
} else {
|
|
|
|
targetp = pfind(uap->pid);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (targetp == NULL) {
|
|
|
|
e = ESRCH;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-02-07 20:58:47 +00:00
|
|
|
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
2001-06-30 07:55:19 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
e = p_cansee(td->td_proc, targetp);
|
2001-06-30 07:55:19 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-08-31 22:34:40 +00:00
|
|
|
if (e == 0) {
|
2001-09-12 08:38:13 +00:00
|
|
|
e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
|
2001-08-31 22:34:40 +00:00
|
|
|
uap->interval);
|
|
|
|
}
|
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
2001-06-28 23:02:09 +00:00
|
|
|
return (e);
|
1998-03-28 11:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void p31binit(void *notused)
|
|
|
|
{
|
|
|
|
(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);
|