Deleted Added
full compact
p1003_1b.c (108896) p1003_1b.c (116192)
1/*
2 * Copyright (c) 1996, 1997, 1998
3 * HD Associates, Inc. All rights reserved.
4 *
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.
19 *
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.
1/*
2 * Copyright (c) 1996, 1997, 1998
3 * HD Associates, Inc. All rights reserved.
4 *
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.
19 *
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.
31 *
32 * $FreeBSD: head/sys/kern/p1003_1b.c 108896 2003-01-07 20:10:04Z alfred $
33 */
34
35/* p1003_1b: Real Time common code.
36 */
37
31 */
32
33/* p1003_1b: Real Time common code.
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/kern/p1003_1b.c 116192 2003-06-11 06:34:30Z obrien $");
38
38#include "opt_posix.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/module.h>
45#include <sys/mutex.h>
46#include <sys/proc.h>
47#include <sys/sysctl.h>
48#include <sys/sysent.h>
49#include <sys/syslog.h>
50#include <sys/sysproto.h>
51
52#include <posix4/posix4.h>
53
54MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
55
56/* The system calls return ENOSYS if an entry is called that is
57 * not run-time supported. I am also logging since some programs
58 * start to use this when they shouldn't. That will be removed if annoying.
59 */
60int
61syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
62{
63 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
64 td->td_proc->p_comm, td->td_proc->p_pid, s);
65
66 /* a " return nosys(p, uap); " here causes a core dump.
67 */
68
69 return ENOSYS;
70}
71
72#if !defined(_KPOSIX_PRIORITY_SCHEDULING)
73
74/* Not configured but loadable via a module:
75 */
76
77static int sched_attach(void)
78{
79 return 0;
80}
81
82SYSCALL_NOT_PRESENT_GEN(sched_setparam)
83SYSCALL_NOT_PRESENT_GEN(sched_getparam)
84SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
85SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
86SYSCALL_NOT_PRESENT_GEN(sched_yield)
87SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
88SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
89SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
90
91#else
92
93/* Configured in kernel version:
94 */
95static struct ksched *ksched;
96
97static int sched_attach(void)
98{
99 int ret = ksched_attach(&ksched);
100
101 if (ret == 0)
102 p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
103
104 return ret;
105}
106
107/*
108 * MPSAFE
109 */
110int sched_setparam(struct thread *td,
111 struct sched_setparam_args *uap)
112{
113 struct thread *targettd;
114 struct proc *targetp;
115 int e;
116 struct sched_param sched_param;
117
118 e = copyin(uap->param, &sched_param, sizeof(sched_param));
119 if (e)
120 return (e);
121
122 mtx_lock(&Giant);
123 if (uap->pid == 0) {
124 targetp = td->td_proc;
125 targettd = td;
126 PROC_LOCK(targetp);
127 } else {
128 targetp = pfind(uap->pid);
129 if (targetp == NULL) {
130 e = ESRCH;
131 goto done2;
132 }
133 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
134 }
135
136 e = p_cansched(td, targetp);
137 PROC_UNLOCK(targetp);
138 if (e == 0) {
139 e = ksched_setparam(&td->td_retval[0], ksched, targettd,
140 (const struct sched_param *)&sched_param);
141 }
142done2:
143 mtx_unlock(&Giant);
144 return (e);
145}
146
147/*
148 * MPSAFE
149 */
150int sched_getparam(struct thread *td,
151 struct sched_getparam_args *uap)
152{
153 int e;
154 struct sched_param sched_param;
155 struct thread *targettd;
156 struct proc *targetp;
157
158 mtx_lock(&Giant);
159 if (uap->pid == 0) {
160 targetp = td->td_proc;
161 targettd = td;
162 PROC_LOCK(targetp);
163 } else {
164 targetp = pfind(uap->pid);
165 if (targetp == NULL) {
166 e = ESRCH;
167 goto done2;
168 }
169 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
170 }
171
172 e = p_cansee(td, targetp);
173 PROC_UNLOCK(targetp);
174 if (e)
175 goto done2;
176
177 e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
178 if (e == 0)
179 e = copyout(&sched_param, uap->param, sizeof(sched_param));
180done2:
181 mtx_unlock(&Giant);
182 return (e);
183}
184
185/*
186 * MPSAFE
187 */
188int sched_setscheduler(struct thread *td,
189 struct sched_setscheduler_args *uap)
190{
191 int e;
192 struct sched_param sched_param;
193 struct thread *targettd;
194 struct proc *targetp;
195
196 e = copyin(uap->param, &sched_param, sizeof(sched_param));
197 if (e)
198 return (e);
199
200 mtx_lock(&Giant);
201 if (uap->pid == 0) {
202 targetp = td->td_proc;
203 targettd = td;
204 PROC_LOCK(targetp);
205 } else {
206 targetp = pfind(uap->pid);
207 if (targetp == NULL) {
208 e = ESRCH;
209 goto done2;
210 }
211 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
212 }
213
214 e = p_cansched(td, targetp);
215 PROC_UNLOCK(targetp);
216 if (e == 0) {
217 e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
218 uap->policy, (const struct sched_param *)&sched_param);
219 }
220done2:
221 mtx_unlock(&Giant);
222 return (e);
223}
224
225/*
226 * MPSAFE
227 */
228int sched_getscheduler(struct thread *td,
229 struct sched_getscheduler_args *uap)
230{
231 int e;
232 struct thread *targettd;
233 struct proc *targetp;
234
235 mtx_lock(&Giant);
236 if (uap->pid == 0) {
237 targetp = td->td_proc;
238 targettd = td;
239 PROC_LOCK(targetp);
240 } else {
241 targetp = pfind(uap->pid);
242 if (targetp == NULL) {
243 e = ESRCH;
244 goto done2;
245 }
246 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
247 }
248
249 e = p_cansee(td, targetp);
250 PROC_UNLOCK(targetp);
251 if (e == 0)
252 e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
253
254done2:
255 mtx_unlock(&Giant);
256 return (e);
257}
258
259/*
260 * MPSAFE
261 */
262int sched_yield(struct thread *td,
263 struct sched_yield_args *uap)
264{
265 int error;
266
267 mtx_lock(&Giant);
268 error = ksched_yield(&td->td_retval[0], ksched);
269 mtx_unlock(&Giant);
270 return (error);
271}
272
273/*
274 * MPSAFE
275 */
276int sched_get_priority_max(struct thread *td,
277 struct sched_get_priority_max_args *uap)
278{
279 int error;
280
281 mtx_lock(&Giant);
282 error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
283 mtx_unlock(&Giant);
284 return (error);
285}
286
287/*
288 * MPSAFE
289 */
290int sched_get_priority_min(struct thread *td,
291 struct sched_get_priority_min_args *uap)
292{
293 int error;
294
295 mtx_lock(&Giant);
296 error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
297 mtx_unlock(&Giant);
298 return (error);
299}
300
301/*
302 * MPSAFE
303 */
304int sched_rr_get_interval(struct thread *td,
305 struct sched_rr_get_interval_args *uap)
306{
307 int e;
308 struct thread *targettd;
309 struct timespec timespec;
310 struct proc *targetp;
311
312 mtx_lock(&Giant);
313 if (uap->pid == 0) {
314 targettd = td;
315 targetp = td->td_proc;
316 PROC_LOCK(targetp);
317 } else {
318 targetp = pfind(uap->pid);
319 if (targetp == NULL) {
320 e = ESRCH;
321 goto done2;
322 }
323 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
324 }
325
326 e = p_cansee(td, targetp);
327 PROC_UNLOCK(targetp);
328 if (e == 0) {
329 e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
330 &timespec);
331 if (e == 0)
332 e = copyout(&timespec, uap->interval,
333 sizeof(timespec));
334 }
335done2:
336 mtx_unlock(&Giant);
337 return (e);
338}
339
340#endif
341
342static void p31binit(void *notused)
343{
344 (void) sched_attach();
345 p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
346}
347
348SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);
39#include "opt_posix.h"
40
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/proc.h>
48#include <sys/sysctl.h>
49#include <sys/sysent.h>
50#include <sys/syslog.h>
51#include <sys/sysproto.h>
52
53#include <posix4/posix4.h>
54
55MALLOC_DEFINE(M_P31B, "p1003.1b", "Posix 1003.1B");
56
57/* The system calls return ENOSYS if an entry is called that is
58 * not run-time supported. I am also logging since some programs
59 * start to use this when they shouldn't. That will be removed if annoying.
60 */
61int
62syscall_not_present(struct thread *td, const char *s, struct nosys_args *uap)
63{
64 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
65 td->td_proc->p_comm, td->td_proc->p_pid, s);
66
67 /* a " return nosys(p, uap); " here causes a core dump.
68 */
69
70 return ENOSYS;
71}
72
73#if !defined(_KPOSIX_PRIORITY_SCHEDULING)
74
75/* Not configured but loadable via a module:
76 */
77
78static int sched_attach(void)
79{
80 return 0;
81}
82
83SYSCALL_NOT_PRESENT_GEN(sched_setparam)
84SYSCALL_NOT_PRESENT_GEN(sched_getparam)
85SYSCALL_NOT_PRESENT_GEN(sched_setscheduler)
86SYSCALL_NOT_PRESENT_GEN(sched_getscheduler)
87SYSCALL_NOT_PRESENT_GEN(sched_yield)
88SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
89SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
90SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
91
92#else
93
94/* Configured in kernel version:
95 */
96static struct ksched *ksched;
97
98static int sched_attach(void)
99{
100 int ret = ksched_attach(&ksched);
101
102 if (ret == 0)
103 p31b_setcfg(CTL_P1003_1B_PRIORITY_SCHEDULING, 1);
104
105 return ret;
106}
107
108/*
109 * MPSAFE
110 */
111int sched_setparam(struct thread *td,
112 struct sched_setparam_args *uap)
113{
114 struct thread *targettd;
115 struct proc *targetp;
116 int e;
117 struct sched_param sched_param;
118
119 e = copyin(uap->param, &sched_param, sizeof(sched_param));
120 if (e)
121 return (e);
122
123 mtx_lock(&Giant);
124 if (uap->pid == 0) {
125 targetp = td->td_proc;
126 targettd = td;
127 PROC_LOCK(targetp);
128 } else {
129 targetp = pfind(uap->pid);
130 if (targetp == NULL) {
131 e = ESRCH;
132 goto done2;
133 }
134 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
135 }
136
137 e = p_cansched(td, targetp);
138 PROC_UNLOCK(targetp);
139 if (e == 0) {
140 e = ksched_setparam(&td->td_retval[0], ksched, targettd,
141 (const struct sched_param *)&sched_param);
142 }
143done2:
144 mtx_unlock(&Giant);
145 return (e);
146}
147
148/*
149 * MPSAFE
150 */
151int sched_getparam(struct thread *td,
152 struct sched_getparam_args *uap)
153{
154 int e;
155 struct sched_param sched_param;
156 struct thread *targettd;
157 struct proc *targetp;
158
159 mtx_lock(&Giant);
160 if (uap->pid == 0) {
161 targetp = td->td_proc;
162 targettd = td;
163 PROC_LOCK(targetp);
164 } else {
165 targetp = pfind(uap->pid);
166 if (targetp == NULL) {
167 e = ESRCH;
168 goto done2;
169 }
170 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
171 }
172
173 e = p_cansee(td, targetp);
174 PROC_UNLOCK(targetp);
175 if (e)
176 goto done2;
177
178 e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param);
179 if (e == 0)
180 e = copyout(&sched_param, uap->param, sizeof(sched_param));
181done2:
182 mtx_unlock(&Giant);
183 return (e);
184}
185
186/*
187 * MPSAFE
188 */
189int sched_setscheduler(struct thread *td,
190 struct sched_setscheduler_args *uap)
191{
192 int e;
193 struct sched_param sched_param;
194 struct thread *targettd;
195 struct proc *targetp;
196
197 e = copyin(uap->param, &sched_param, sizeof(sched_param));
198 if (e)
199 return (e);
200
201 mtx_lock(&Giant);
202 if (uap->pid == 0) {
203 targetp = td->td_proc;
204 targettd = td;
205 PROC_LOCK(targetp);
206 } else {
207 targetp = pfind(uap->pid);
208 if (targetp == NULL) {
209 e = ESRCH;
210 goto done2;
211 }
212 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
213 }
214
215 e = p_cansched(td, targetp);
216 PROC_UNLOCK(targetp);
217 if (e == 0) {
218 e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
219 uap->policy, (const struct sched_param *)&sched_param);
220 }
221done2:
222 mtx_unlock(&Giant);
223 return (e);
224}
225
226/*
227 * MPSAFE
228 */
229int sched_getscheduler(struct thread *td,
230 struct sched_getscheduler_args *uap)
231{
232 int e;
233 struct thread *targettd;
234 struct proc *targetp;
235
236 mtx_lock(&Giant);
237 if (uap->pid == 0) {
238 targetp = td->td_proc;
239 targettd = td;
240 PROC_LOCK(targetp);
241 } else {
242 targetp = pfind(uap->pid);
243 if (targetp == NULL) {
244 e = ESRCH;
245 goto done2;
246 }
247 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
248 }
249
250 e = p_cansee(td, targetp);
251 PROC_UNLOCK(targetp);
252 if (e == 0)
253 e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
254
255done2:
256 mtx_unlock(&Giant);
257 return (e);
258}
259
260/*
261 * MPSAFE
262 */
263int sched_yield(struct thread *td,
264 struct sched_yield_args *uap)
265{
266 int error;
267
268 mtx_lock(&Giant);
269 error = ksched_yield(&td->td_retval[0], ksched);
270 mtx_unlock(&Giant);
271 return (error);
272}
273
274/*
275 * MPSAFE
276 */
277int sched_get_priority_max(struct thread *td,
278 struct sched_get_priority_max_args *uap)
279{
280 int error;
281
282 mtx_lock(&Giant);
283 error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
284 mtx_unlock(&Giant);
285 return (error);
286}
287
288/*
289 * MPSAFE
290 */
291int sched_get_priority_min(struct thread *td,
292 struct sched_get_priority_min_args *uap)
293{
294 int error;
295
296 mtx_lock(&Giant);
297 error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
298 mtx_unlock(&Giant);
299 return (error);
300}
301
302/*
303 * MPSAFE
304 */
305int sched_rr_get_interval(struct thread *td,
306 struct sched_rr_get_interval_args *uap)
307{
308 int e;
309 struct thread *targettd;
310 struct timespec timespec;
311 struct proc *targetp;
312
313 mtx_lock(&Giant);
314 if (uap->pid == 0) {
315 targettd = td;
316 targetp = td->td_proc;
317 PROC_LOCK(targetp);
318 } else {
319 targetp = pfind(uap->pid);
320 if (targetp == NULL) {
321 e = ESRCH;
322 goto done2;
323 }
324 targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
325 }
326
327 e = p_cansee(td, targetp);
328 PROC_UNLOCK(targetp);
329 if (e == 0) {
330 e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
331 &timespec);
332 if (e == 0)
333 e = copyout(&timespec, uap->interval,
334 sizeof(timespec));
335 }
336done2:
337 mtx_unlock(&Giant);
338 return (e);
339}
340
341#endif
342
343static void p31binit(void *notused)
344{
345 (void) sched_attach();
346 p31b_setcfg(CTL_P1003_1B_PAGESIZE, PAGE_SIZE);
347}
348
349SYSINIT(p31b, SI_SUB_P1003_1B, SI_ORDER_FIRST, p31binit, NULL);