2 * Copyright (c) 1996, 1997, 1998
3 * HD Associates, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by HD Associates, Inc
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 /* p1003_1b: Real Time common code.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include "opt_posix.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
45 #include <sys/module.h>
46 #include <sys/mutex.h>
48 #include <sys/syscallsubr.h>
49 #include <sys/sysctl.h>
50 #include <sys/sysent.h>
51 #include <sys/syslog.h>
52 #include <sys/sysproto.h>
54 #include <posix4/posix4.h>
56 MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
58 /* The system calls return ENOSYS if an entry is called that is
59 * not run-time supported. I am also logging since some programs
60 * start to use this when they shouldn't. That will be removed if annoying.
63 syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
65 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
66 td->td_proc->p_comm, td->td_proc->p_pid, s);
68 /* a " return nosys(p, uap); " here causes a core dump.
74 #if !defined(_KPOSIX_PRIORITY_SCHEDULING)
76 /* Not configured but loadable via a module:
79 static int sched_attach(void)
84 SYSCALL_NOT_PRESENT_GEN(sched_setparam)
85 SYSCALL_NOT_PRESENT_GEN(sched_getparam)
86 SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
87 SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
88 SYSCALL_NOT_PRESENT_GEN(sched_yield)
89 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
90 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
91 SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
95 /* Configured in kernel version:
97 static struct ksched *ksched;
99 static int sched_attach(void)
101 int ret = ksched_attach(&ksched);
104 p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
112 int sched_setparam(struct thread *td,
113 struct sched_setparam_args *uap)
115 struct thread *targettd;
116 struct proc *targetp;
118 struct sched_param sched_param;
120 e = copyin(uap->param, &sched_param, sizeof(sched_param));
126 targetp = td->td_proc;
130 targetp = pfind(uap->pid);
131 if (targetp == NULL) {
135 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
138 e = p_cansched(td, targetp);
139 PROC_UNLOCK(targetp);
141 e = ksched_setparam(&td->td_retval[0], ksched, targettd,
142 (const struct sched_param *)&sched_param);
152 int sched_getparam(struct thread *td,
153 struct sched_getparam_args *uap)
156 struct sched_param sched_param;
157 struct thread *targettd;
158 struct proc *targetp;
162 targetp = td->td_proc;
166 targetp = pfind(uap->pid);
167 if (targetp == NULL) {
171 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
174 e = p_cansee(td, targetp);
175 PROC_UNLOCK(targetp);
179 e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
181 e = copyout(&sched_param, uap->param, sizeof(sched_param));
190 int sched_setscheduler(struct thread *td,
191 struct sched_setscheduler_args *uap)
194 struct sched_param sched_param;
195 struct thread *targettd;
196 struct proc *targetp;
198 e = copyin(uap->param, &sched_param, sizeof(sched_param));
204 targetp = td->td_proc;
208 targetp = pfind(uap->pid);
209 if (targetp == NULL) {
213 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
216 e = p_cansched(td, targetp);
217 PROC_UNLOCK(targetp);
219 e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
220 uap->policy, (const struct sched_param *)&sched_param);
230 int sched_getscheduler(struct thread *td,
231 struct sched_getscheduler_args *uap)
234 struct thread *targettd;
235 struct proc *targetp;
239 targetp = td->td_proc;
243 targetp = pfind(uap->pid);
244 if (targetp == NULL) {
248 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
251 e = p_cansee(td, targetp);
252 PROC_UNLOCK(targetp);
254 e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
264 int sched_yield(struct thread *td,
265 struct sched_yield_args *uap)
270 error = ksched_yield(&td->td_retval[0], ksched);
278 int sched_get_priority_max(struct thread *td,
279 struct sched_get_priority_max_args *uap)
284 error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
292 int sched_get_priority_min(struct thread *td,
293 struct sched_get_priority_min_args *uap)
298 error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
306 int sched_rr_get_interval(struct thread *td,
307 struct sched_rr_get_interval_args *uap)
309 struct timespec timespec;
312 error = kern_sched_rr_get_interval(td, uap->pid, ×pec);
314 error = copyout(×pec, uap->interval, sizeof(timespec));
318 int kern_sched_rr_get_interval(struct thread *td, pid_t pid,
322 struct thread *targettd;
323 struct proc *targetp;
328 targetp = td->td_proc;
331 targetp = pfind(pid);
332 if (targetp == NULL) {
336 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
339 e = p_cansee(td, targetp);
341 e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
343 PROC_UNLOCK(targetp);
350 static void p31binit(void *notused)
352 (void) sched_attach();
353 p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
356 SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);