1 /* $NetBSD: freebsd_sched.c,v 1.18 2008/02/29 08:41:51 dogcow Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center; by Matthias Scheler.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * FreeBSD compatibility module. Try to deal with scheduler related syscalls.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: freebsd_sched.c,v 1.18 2008/02/29 08:41:51 dogcow Exp $");
40 #include <sys/param.h>
41 #include <sys/mount.h>
43 #include <sys/systm.h>
44 #include <sys/syscallargs.h>
45 #include <sys/kauth.h>
49 #include <compat/freebsd/freebsd_syscallargs.h>
50 #include <compat/freebsd/freebsd_sched.h>
53 freebsd_sys_yield(struct lwp
*l
, const void *v
, register_t
*retval
)
61 * XXX: Needs adjustment to do a proper conversion.
64 sched_freebsd2native(int freebsd_policy
,
65 struct freebsd_sched_param
*freebsd_params
, int *native_policy
,
66 struct sched_param
*native_params
)
72 switch (freebsd_policy
) {
73 case FREEBSD_SCHED_OTHER
:
74 *native_policy
= SCHED_OTHER
;
77 case FREEBSD_SCHED_FIFO
:
78 *native_policy
= SCHED_FIFO
;
81 case FREEBSD_SCHED_RR
:
82 *native_policy
= SCHED_RR
;
90 if (freebsd_params
!= NULL
&& native_params
!= NULL
&& !error
) {
91 native_params
= (struct sched_param
*)freebsd_params
;
98 * XXX: Needs adjustment to do a proper conversion.
101 sched_native2freebsd(int native_policy
, struct sched_param
*native_params
,
102 int *freebsd_policy
, struct freebsd_sched_param
*freebsd_params
)
108 switch (native_policy
) {
110 *freebsd_policy
= FREEBSD_SCHED_OTHER
;
114 *freebsd_policy
= FREEBSD_SCHED_FIFO
;
118 *freebsd_policy
= FREEBSD_SCHED_RR
;
126 if (native_params
!= NULL
&& freebsd_params
!= NULL
&& !error
) {
127 freebsd_params
= (struct freebsd_sched_param
*)native_params
;
134 freebsd_sys_sched_setparam(struct lwp
*l
, const struct freebsd_sys_sched_setparam_args
*uap
, register_t
*retval
)
137 syscallarg(pid_t) pid;
138 syscallarg(const struct freebsd_sched_param *) sp;
141 struct freebsd_sched_param lp
;
142 struct sched_param sp
;
144 if (SCARG(uap
, pid
) < 0 || SCARG(uap
, sp
) == NULL
) {
149 error
= copyin(SCARG(uap
, sp
), &lp
, sizeof(lp
));
153 /* We need the current policy in FreeBSD terms. */
154 error
= do_sched_getparam(SCARG(uap
, pid
), 0, &policy
, NULL
);
157 error
= sched_native2freebsd(policy
, NULL
, &policy
, NULL
);
161 error
= sched_freebsd2native(policy
, &lp
, &policy
, &sp
);
165 error
= do_sched_setparam(SCARG(uap
, pid
), 0, policy
, &sp
);
174 freebsd_sys_sched_getparam(struct lwp
*l
, const struct freebsd_sys_sched_getparam_args
*uap
, register_t
*retval
)
177 syscallarg(pid_t) pid;
178 syscallarg(struct freebsd_sched_param *) sp;
180 struct freebsd_sched_param lp
;
181 struct sched_param sp
;
184 if (SCARG(uap
, pid
) < 0 || SCARG(uap
, sp
) == NULL
) {
189 error
= do_sched_getparam(SCARG(uap
, pid
), 0, NULL
, &sp
);
193 error
= sched_native2freebsd(0, &sp
, NULL
, &lp
);
197 error
= copyout(&lp
, SCARG(uap
, sp
), sizeof(lp
));
206 freebsd_sys_sched_setscheduler(struct lwp
*l
, const struct freebsd_sys_sched_setscheduler_args
*uap
, register_t
*retval
)
209 syscallarg(pid_t) pid;
210 syscallarg(int) policy;
211 syscallarg(cont struct freebsd_sched_scheduler *) sp;
214 struct freebsd_sched_param lp
;
215 struct sched_param sp
;
217 if (SCARG(uap
, pid
) < 0 || SCARG(uap
, sp
) == NULL
) {
222 error
= copyin(SCARG(uap
, sp
), &lp
, sizeof(lp
));
226 error
= sched_freebsd2native(SCARG(uap
, policy
), &lp
, &policy
, &sp
);
230 error
= do_sched_setparam(SCARG(uap
, pid
), 0, policy
, &sp
);
239 freebsd_sys_sched_getscheduler(struct lwp
*l
, const struct freebsd_sys_sched_getscheduler_args
*uap
, register_t
*retval
)
242 syscallarg(pid_t) pid;
248 error
= do_sched_getparam(SCARG(uap
, pid
), 0, &policy
, NULL
);
252 error
= sched_native2freebsd(policy
, NULL
, &policy
, NULL
);
263 freebsd_sys_sched_yield(struct lwp
*l
, const void *v
, register_t
*retval
)
271 freebsd_sys_sched_get_priority_max(struct lwp
*l
, const struct freebsd_sys_sched_get_priority_max_args
*uap
, register_t
*retval
)
274 syscallarg(int) policy;
278 * We can't emulate anything put the default scheduling policy.
280 if (SCARG(uap
, policy
) != FREEBSD_SCHED_OTHER
) {
290 freebsd_sys_sched_get_priority_min(struct lwp
*l
, const struct freebsd_sys_sched_get_priority_min_args
*uap
, register_t
*retval
)
293 syscallarg(int) policy;
297 * We can't emulate anything put the default scheduling policy.
299 if (SCARG(uap
, policy
) != FREEBSD_SCHED_OTHER
) {