1 /* $OpenBSD: sched.h,v 1.4 2003/06/02 23:28:21 millert Exp $ */
2 /* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
3
4 /*-
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Ross Harvey.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*-
41 * Copyright (c) 1982, 1986, 1991, 1993
42 * The Regents of the University of California. All rights reserved.
43 * (c) UNIX System Laboratories, Inc.
44 * All or some portions of this file are derived from material licensed
45 * to the University of California by American Telephone and Telegraph
46 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
47 * the permission of UNIX System Laboratories, Inc.
48 *
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 * notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 * notice, this list of conditions and the following disclaimer in the
56 * documentation and/or other materials provided with the distribution.
57 * 3. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
72 *
73 * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
74 */
75
76 #ifndef _SYS_SCHED_H_
77 #define _SYS_SCHED_H_
78
79 /*
80 * Posix defines a <sched.h> which may want to include <sys/sched.h>
81 */
82
83 #ifdef _KERNEL
84
85 #define PPQ (128 / NQS) /* priorities per queue */
86 #define NICE_WEIGHT 2 /* priorities per nice level */
87 #define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - PPQ)
88
89 extern int schedhz; /* ideally: 16 */
90
91 #ifdef _SYS_PROC_H_
92 void schedclock(struct proc *p);
93 static __inline void scheduler_fork_hook(
94 struct proc *parent, struct proc *child);
95 static __inline void scheduler_wait_hook(
96 struct proc *parent, struct proc *child);
97
98 /* Inherit the parent's scheduler history */
99
100 static __inline void
scheduler_fork_hook(parent,child)101 scheduler_fork_hook(parent, child)
102 struct proc *parent, *child;
103 {
104 child->p_estcpu = parent->p_estcpu;
105 }
106
107 /* Chargeback parents for the sins of their children. */
108
109 static __inline void
scheduler_wait_hook(parent,child)110 scheduler_wait_hook(parent, child)
111 struct proc *parent, *child;
112 {
113 /* XXX just return if parent == init?? */
114
115 parent->p_estcpu = ESTCPULIM(parent->p_estcpu + child->p_estcpu);
116 }
117 #endif /* _SYS_PROC_H_ */
118
119 #if !defined(__HAVE_CPUINFO) && !defined(splsched)
120 #define splsched() splhigh()
121 #endif
122 #ifndef IPL_SCHED
123 #define IPL_SCHED IPL_HIGH
124 #endif
125
126 #define SCHED_ASSERT_LOCKED() splassert(IPL_SCHED);
127 #define SCHED_ASSERT_UNLOCKED() /* nothing */
128
129 #define SCHED_LOCK(s) s = splsched()
130 #define SCHED_UNLOCK(s) splx(s)
131
132 #endif /* _KERNEL */
133 #endif /* _SYS_SCHED_H_ */
134