]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: sched.h | |
54 | * Author: Avadis Tevanian, Jr. | |
55 | * Date: 1985 | |
56 | * | |
57 | * Header file for scheduler. | |
58 | * | |
59 | */ | |
60 | ||
61 | #ifndef _KERN_SCHED_H_ | |
62 | #define _KERN_SCHED_H_ | |
63 | ||
1c79356b A |
64 | #include <simple_clock.h> |
65 | #include <stat_time.h> | |
66 | ||
67 | #include <mach/policy.h> | |
68 | #include <kern/kern_types.h> | |
69 | #include <kern/queue.h> | |
70 | #include <kern/lock.h> | |
71 | #include <kern/macro_help.h> | |
0b4e3aa0 | 72 | #include <kern/timer_call.h> |
1c79356b A |
73 | |
74 | #if STAT_TIME | |
75 | ||
76 | /* | |
0b4e3aa0 | 77 | * Statistical timing uses microseconds as timer units. |
1c79356b A |
78 | */ |
79 | #define PRI_SHIFT (16 - SCHED_TICK_SHIFT) | |
80 | ||
81 | #else /* STAT_TIME */ | |
82 | ||
83 | /* | |
84 | * Otherwise machine provides shift(s) based on time units it uses. | |
85 | */ | |
86 | #include <machine/sched_param.h> | |
87 | ||
88 | #endif /* STAT_TIME */ | |
89 | ||
90 | #define NRQS 128 /* 128 run queues per cpu */ | |
91 | #define NRQBM (NRQS / 32) /* number of run queue bit maps */ | |
92 | ||
93 | #define MAXPRI (NRQS-1) | |
94 | #define MINPRI IDLEPRI /* lowest legal priority schedulable */ | |
95 | #define IDLEPRI 0 /* idle thread priority */ | |
96 | #define DEPRESSPRI MINPRI /* depress priority */ | |
97 | ||
98 | /* | |
99 | * High-level priority assignments | |
100 | * | |
101 | ************************************************************************* | |
102 | * 127 Reserved (real-time) | |
103 | * A | |
104 | * + | |
105 | * (32 levels) | |
106 | * + | |
107 | * V | |
108 | * 96 Reserved (real-time) | |
109 | * 95 Kernel mode only | |
110 | * A | |
111 | * + | |
112 | * (16 levels) | |
113 | * + | |
114 | * V | |
115 | * 80 Kernel mode only | |
0b4e3aa0 | 116 | * 79 System high priority |
1c79356b A |
117 | * A |
118 | * + | |
119 | * (16 levels) | |
120 | * + | |
121 | * V | |
0b4e3aa0 | 122 | * 64 System high priority |
1c79356b A |
123 | * 63 Elevated priorities |
124 | * A | |
125 | * + | |
126 | * (12 levels) | |
127 | * + | |
128 | * V | |
129 | * 52 Elevated priorities | |
130 | * 51 Elevated priorities (incl. BSD +nice) | |
131 | * A | |
132 | * + | |
133 | * (20 levels) | |
134 | * + | |
135 | * V | |
136 | * 32 Elevated priorities (incl. BSD +nice) | |
137 | * 31 Default (default base for threads) | |
138 | * 30 Lowered priorities (incl. BSD -nice) | |
139 | * A | |
140 | * + | |
141 | * (20 levels) | |
142 | * + | |
143 | * V | |
144 | * 11 Lowered priorities (incl. BSD -nice) | |
145 | * 10 Lowered priorities (aged pri's) | |
146 | * A | |
147 | * + | |
148 | * (11 levels) | |
149 | * + | |
150 | * V | |
151 | * 0 Lowered priorities (aged pri's / idle) | |
152 | ************************************************************************* | |
153 | */ | |
154 | ||
155 | #define BASEPRI_REALTIME (MAXPRI - (NRQS / 4) + 1) /* 96 */ | |
156 | ||
157 | #define MAXPRI_STANDARD (BASEPRI_REALTIME - 1) /* 95 */ | |
158 | ||
0b4e3aa0 A |
159 | #define MAXPRI_KERNEL MAXPRI_STANDARD /* 95 */ |
160 | #define BASEPRI_PREEMPT (MAXPRI_KERNEL - 2) /* 93 */ | |
161 | #define MINPRI_KERNEL (MAXPRI_KERNEL - (NRQS / 8) + 1) /* 80 */ | |
1c79356b | 162 | |
0b4e3aa0 A |
163 | #define MAXPRI_SYSTEM (MINPRI_KERNEL - 1) /* 79 */ |
164 | #define MINPRI_SYSTEM (MAXPRI_SYSTEM - (NRQS / 8) + 1) /* 64 */ | |
1c79356b | 165 | |
0b4e3aa0 A |
166 | #define MAXPRI_USER (MINPRI_SYSTEM - 1) /* 63 */ |
167 | #define BASEPRI_DEFAULT (MAXPRI_USER - (NRQS / 4)) /* 31 */ | |
168 | #define MINPRI_USER MINPRI /* 0 */ | |
1c79356b | 169 | |
0b4e3aa0 | 170 | #define MINPRI_STANDARD MINPRI_USER /* 0 */ |
1c79356b A |
171 | |
172 | /* | |
173 | * Macro to check for invalid priorities. | |
174 | */ | |
175 | #define invalid_pri(pri) ((pri) < MINPRI || (pri) > MAXPRI) | |
176 | ||
177 | struct run_queue { | |
178 | queue_head_t queues[NRQS]; /* one for each priority */ | |
179 | decl_simple_lock_data(,lock) /* one lock for all queues */ | |
180 | int bitmap[NRQBM]; /* run queue bitmap array */ | |
181 | int highq; /* highest runnable queue */ | |
182 | int count; /* # of runnable threads */ | |
183 | }; | |
184 | ||
185 | typedef struct run_queue *run_queue_t; | |
186 | #define RUN_QUEUE_NULL ((run_queue_t) 0) | |
187 | ||
0b4e3aa0 A |
188 | #define first_quantum(processor) ((processor)->slice_quanta > 0) |
189 | ||
1c79356b A |
190 | #define csw_needed(thread, processor) ( \ |
191 | ((thread)->state & TH_SUSP) || \ | |
0b4e3aa0 | 192 | (first_quantum(processor)? \ |
1c79356b A |
193 | ((processor)->runq.highq > (thread)->sched_pri || \ |
194 | (processor)->processor_set->runq.highq > (thread)->sched_pri) : \ | |
195 | ((processor)->runq.highq >= (thread)->sched_pri || \ | |
196 | (processor)->processor_set->runq.highq >= (thread)->sched_pri)) ) | |
197 | ||
198 | /* | |
199 | * Scheduler routines. | |
200 | */ | |
201 | ||
202 | /* Remove thread from its run queue */ | |
203 | extern run_queue_t rem_runq( | |
0b4e3aa0 | 204 | thread_t thread); |
1c79356b | 205 | |
0b4e3aa0 | 206 | /* Periodic computation of load factors */ |
1c79356b A |
207 | extern void compute_mach_factor(void); |
208 | ||
0b4e3aa0 A |
209 | /* Handle quantum expiration for an executing thread */ |
210 | extern void thread_quantum_expire( | |
211 | timer_call_param_t processor, | |
212 | timer_call_param_t thread); | |
213 | ||
214 | extern uint32_t std_quantum, min_std_quantum; | |
215 | extern uint32_t std_quantum_us; | |
1c79356b | 216 | |
0b4e3aa0 | 217 | extern uint32_t max_rt_quantum, min_rt_quantum; |
1c79356b A |
218 | |
219 | /* | |
220 | * Shift structures for holding update shifts. Actual computation | |
221 | * is usage = (usage >> shift1) +/- (usage >> abs(shift2)) where the | |
222 | * +/- is determined by the sign of shift 2. | |
223 | */ | |
224 | struct shift { | |
225 | int shift1; | |
226 | int shift2; | |
227 | }; | |
228 | ||
229 | typedef struct shift *shift_t, shift_data_t; | |
230 | ||
231 | /* | |
232 | * Age usage (1 << SCHED_TICK_SHIFT) times per second. | |
233 | */ | |
234 | ||
235 | extern unsigned sched_tick; | |
236 | ||
237 | #define SCHED_TICK_SHIFT 3 | |
238 | ||
239 | #define SCHED_SCALE 128 | |
240 | #define SCHED_SHIFT 7 | |
241 | ||
242 | /* | |
243 | * thread_timer_delta macro takes care of both thread timers. | |
244 | */ | |
245 | ||
246 | #define thread_timer_delta(thread) \ | |
247 | MACRO_BEGIN \ | |
248 | register unsigned delta; \ | |
249 | \ | |
250 | delta = 0; \ | |
251 | TIMER_DELTA((thread)->system_timer, \ | |
252 | (thread)->system_timer_save, delta); \ | |
253 | TIMER_DELTA((thread)->user_timer, \ | |
254 | (thread)->user_timer_save, delta); \ | |
255 | (thread)->cpu_delta += delta; \ | |
256 | (thread)->sched_delta += (delta * \ | |
257 | (thread)->processor_set->sched_load); \ | |
258 | MACRO_END | |
259 | ||
260 | #if SIMPLE_CLOCK | |
261 | /* | |
262 | * sched_usec is an exponential average of number of microseconds | |
263 | * in a second for clock drift compensation. | |
264 | */ | |
265 | ||
266 | extern int sched_usec; | |
267 | #endif /* SIMPLE_CLOCK */ | |
268 | ||
269 | #endif /* _KERN_SCHED_H_ */ |