Ignore machine-check MSRs
[freebsd-src/fkvm-freebsd.git] / sys / kern / p1003_1b.c
blob6d05972f4155e186efa0bf5e81ca1b8c04e2a095
1 /*-
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
7 * are met:
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
30 * SUCH DAMAGE.
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>
44 #include <sys/lock.h>
45 #include <sys/module.h>
46 #include <sys/mutex.h>
47 #include <sys/priv.h>
48 #include <sys/proc.h>
49 #include <sys/posix4.h>
50 #include <sys/syscallsubr.h>
51 #include <sys/sysctl.h>
52 #include <sys/sysent.h>
53 #include <sys/syslog.h>
54 #include <sys/sysproto.h>
56 MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
58 /* The system calls return ENOSYS if an entry is called that is not run-time
59 * supported. I am also logging since some programs start to use this when
60 * they shouldn't. That will be removed if annoying.
62 int
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_name, td->td_proc->p_pid, s);
68 /* a " return nosys(p, uap); " here causes a core dump.
71 return ENOSYS;
74 #if !defined(_KPOSIX_PRIORITY_SCHEDULING)
76 /* Not configured but loadable via a module:
79 static int
80 sched_attach(void)
82 return 0;
85 SYSCALL_NOT_PRESENT_GEN(sched_setparam)
86 SYSCALL_NOT_PRESENT_GEN(sched_getparam)
87 SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
88 SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
89 SYSCALL_NOT_PRESENT_GEN(sched_yield)
90 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
91 SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
92 SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
93 #else
95 /* Configured in kernel version:
97 static struct ksched *ksched;
99 static int
100 sched_attach(void)
102 int ret = ksched_attach(&ksched);
104 if (ret == 0)
105 p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
107 return ret;
111 sched_setparam(struct thread *td, struct sched_setparam_args *uap)
113 struct thread *targettd;
114 struct proc *targetp;
115 int e;
116 struct sched_param sched_param;
118 e = copyin(uap->param, &sched_param, sizeof(sched_param));
119 if (e)
120 return (e);
122 if (uap->pid == 0) {
123 targetp = td->td_proc;
124 targettd = td;
125 PROC_LOCK(targetp);
126 } else {
127 targetp = pfind(uap->pid);
128 if (targetp == NULL)
129 return (ESRCH);
130 targettd = FIRST_THREAD_IN_PROC(targetp);
133 e = p_cansched(td, targetp);
134 if (e == 0) {
135 e = ksched_setparam(ksched, targettd,
136 (const struct sched_param *)&sched_param);
138 PROC_UNLOCK(targetp);
139 return (e);
143 sched_getparam(struct thread *td, struct sched_getparam_args *uap)
145 int e;
146 struct sched_param sched_param;
147 struct thread *targettd;
148 struct proc *targetp;
150 if (uap->pid == 0) {
151 targetp = td->td_proc;
152 targettd = td;
153 PROC_LOCK(targetp);
154 } else {
155 targetp = pfind(uap->pid);
156 if (targetp == NULL) {
157 return (ESRCH);
159 targettd = FIRST_THREAD_IN_PROC(targetp);
162 e = p_cansee(td, targetp);
163 if (e == 0) {
164 e = ksched_getparam(ksched, targettd, &sched_param);
166 PROC_UNLOCK(targetp);
167 if (e == 0)
168 e = copyout(&sched_param, uap->param, sizeof(sched_param));
169 return (e);
173 sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
175 int e;
176 struct sched_param sched_param;
177 struct thread *targettd;
178 struct proc *targetp;
180 /* Don't allow non root user to set a scheduler policy. */
181 e = priv_check(td, PRIV_SCHED_SET);
182 if (e)
183 return (e);
185 e = copyin(uap->param, &sched_param, sizeof(sched_param));
186 if (e)
187 return (e);
189 if (uap->pid == 0) {
190 targetp = td->td_proc;
191 targettd = td;
192 PROC_LOCK(targetp);
193 } else {
194 targetp = pfind(uap->pid);
195 if (targetp == NULL)
196 return (ESRCH);
197 targettd = FIRST_THREAD_IN_PROC(targetp);
200 e = p_cansched(td, targetp);
201 if (e == 0) {
202 e = ksched_setscheduler(ksched, targettd,
203 uap->policy, (const struct sched_param *)&sched_param);
205 PROC_UNLOCK(targetp);
206 return (e);
210 sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
212 int e, policy;
213 struct thread *targettd;
214 struct proc *targetp;
216 if (uap->pid == 0) {
217 targetp = td->td_proc;
218 targettd = td;
219 PROC_LOCK(targetp);
220 } else {
221 targetp = pfind(uap->pid);
222 if (targetp == NULL) {
223 e = ESRCH;
224 goto done2;
226 targettd = FIRST_THREAD_IN_PROC(targetp);
229 e = p_cansee(td, targetp);
230 if (e == 0) {
231 e = ksched_getscheduler(ksched, targettd, &policy);
232 td->td_retval[0] = policy;
234 PROC_UNLOCK(targetp);
236 done2:
237 return (e);
241 sched_yield(struct thread *td, struct sched_yield_args *uap)
244 sched_relinquish(curthread);
245 return 0;
249 sched_get_priority_max(struct thread *td,
250 struct sched_get_priority_max_args *uap)
252 int error, prio;
254 error = ksched_get_priority_max(ksched, uap->policy, &prio);
255 td->td_retval[0] = prio;
256 return (error);
260 sched_get_priority_min(struct thread *td,
261 struct sched_get_priority_min_args *uap)
263 int error, prio;
265 error = ksched_get_priority_min(ksched, uap->policy, &prio);
266 td->td_retval[0] = prio;
267 return (error);
271 sched_rr_get_interval(struct thread *td,
272 struct sched_rr_get_interval_args *uap)
274 struct timespec timespec;
275 int error;
277 error = kern_sched_rr_get_interval(td, uap->pid, &timespec);
278 if (error == 0)
279 error = copyout(&timespec, uap->interval, sizeof(timespec));
280 return (error);
284 kern_sched_rr_get_interval(struct thread *td, pid_t pid,
285 struct timespec *ts)
287 int e;
288 struct thread *targettd;
289 struct proc *targetp;
291 if (pid == 0) {
292 targettd = td;
293 targetp = td->td_proc;
294 PROC_LOCK(targetp);
295 } else {
296 targetp = td->td_proc;
297 PROC_LOCK(targetp);
298 targettd = thread_find(targetp, pid);
299 if (targettd == NULL) {
300 PROC_UNLOCK(targetp);
301 return (ESRCH);
305 e = p_cansee(td, targetp);
306 if (e == 0)
307 e = ksched_rr_get_interval(ksched, targettd, ts);
308 PROC_UNLOCK(targetp);
309 return (e);
312 #endif
314 static void
315 p31binit(void *notused)
317 (void) sched_attach();
318 p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
321 SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);