]>
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 | ||
64 | #include <cpus.h> | |
65 | #include <simple_clock.h> | |
66 | #include <stat_time.h> | |
67 | ||
68 | #include <mach/policy.h> | |
69 | #include <kern/kern_types.h> | |
70 | #include <kern/queue.h> | |
71 | #include <kern/lock.h> | |
72 | #include <kern/macro_help.h> | |
73 | ||
74 | #if STAT_TIME | |
75 | ||
76 | /* | |
77 | * Statistical timing uses microseconds as timer units. 16 bit shift | |
78 | * yields priorities. PRI_SHIFT_2 isn't needed. | |
79 | */ | |
80 | #define PRI_SHIFT (16 - SCHED_TICK_SHIFT) | |
81 | ||
82 | #else /* STAT_TIME */ | |
83 | ||
84 | /* | |
85 | * Otherwise machine provides shift(s) based on time units it uses. | |
86 | */ | |
87 | #include <machine/sched_param.h> | |
88 | ||
89 | #endif /* STAT_TIME */ | |
90 | ||
91 | #define NRQS 128 /* 128 run queues per cpu */ | |
92 | #define NRQBM (NRQS / 32) /* number of run queue bit maps */ | |
93 | ||
94 | #define MAXPRI (NRQS-1) | |
95 | #define MINPRI IDLEPRI /* lowest legal priority schedulable */ | |
96 | #define IDLEPRI 0 /* idle thread priority */ | |
97 | #define DEPRESSPRI MINPRI /* depress priority */ | |
98 | ||
99 | /* | |
100 | * High-level priority assignments | |
101 | * | |
102 | ************************************************************************* | |
103 | * 127 Reserved (real-time) | |
104 | * A | |
105 | * + | |
106 | * (32 levels) | |
107 | * + | |
108 | * V | |
109 | * 96 Reserved (real-time) | |
110 | * 95 Kernel mode only | |
111 | * A | |
112 | * + | |
113 | * (16 levels) | |
114 | * + | |
115 | * V | |
116 | * 80 Kernel mode only | |
117 | * 79 High priority | |
118 | * A | |
119 | * + | |
120 | * (16 levels) | |
121 | * + | |
122 | * V | |
123 | * 64 High priority | |
124 | * 63 Elevated priorities | |
125 | * A | |
126 | * + | |
127 | * (12 levels) | |
128 | * + | |
129 | * V | |
130 | * 52 Elevated priorities | |
131 | * 51 Elevated priorities (incl. BSD +nice) | |
132 | * A | |
133 | * + | |
134 | * (20 levels) | |
135 | * + | |
136 | * V | |
137 | * 32 Elevated priorities (incl. BSD +nice) | |
138 | * 31 Default (default base for threads) | |
139 | * 30 Lowered priorities (incl. BSD -nice) | |
140 | * A | |
141 | * + | |
142 | * (20 levels) | |
143 | * + | |
144 | * V | |
145 | * 11 Lowered priorities (incl. BSD -nice) | |
146 | * 10 Lowered priorities (aged pri's) | |
147 | * A | |
148 | * + | |
149 | * (11 levels) | |
150 | * + | |
151 | * V | |
152 | * 0 Lowered priorities (aged pri's / idle) | |
153 | ************************************************************************* | |
154 | */ | |
155 | ||
156 | #define BASEPRI_REALTIME (MAXPRI - (NRQS / 4) + 1) /* 96 */ | |
157 | ||
158 | #define MAXPRI_STANDARD (BASEPRI_REALTIME - 1) /* 95 */ | |
159 | ||
160 | #define MAXPRI_KERNBAND MAXPRI_STANDARD /* 95 */ | |
161 | #define MINPRI_KERNBAND (MAXPRI_KERNBAND - (NRQS / 8) + 1) /* 80 */ | |
162 | ||
163 | #define MAXPRI_HIGHBAND (MINPRI_KERNBAND - 1) /* 79 */ | |
164 | #define MINPRI_HIGHBAND (MAXPRI_HIGHBAND - (NRQS / 8) + 1) /* 64 */ | |
165 | ||
166 | #define MAXPRI_MAINBAND (MINPRI_HIGHBAND - 1) /* 63 */ | |
167 | #define BASEPRI_DEFAULT (MAXPRI_MAINBAND - (NRQS / 4)) /* 31 */ | |
168 | #define MINPRI_MAINBAND MINPRI /* 0 */ | |
169 | ||
170 | #define MINPRI_STANDARD MINPRI_MAINBAND /* 0 */ | |
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 | ||
188 | #define csw_needed(thread, processor) ( \ | |
189 | ((thread)->state & TH_SUSP) || \ | |
190 | ((processor)->first_quantum? \ | |
191 | ((processor)->runq.highq > (thread)->sched_pri || \ | |
192 | (processor)->processor_set->runq.highq > (thread)->sched_pri) : \ | |
193 | ((processor)->runq.highq >= (thread)->sched_pri || \ | |
194 | (processor)->processor_set->runq.highq >= (thread)->sched_pri)) ) | |
195 | ||
196 | /* | |
197 | * Scheduler routines. | |
198 | */ | |
199 | ||
200 | /* Remove thread from its run queue */ | |
201 | extern run_queue_t rem_runq( | |
202 | thread_t thread); | |
203 | ||
204 | /* Mach factor computation (in mach_factor.c) */ | |
205 | extern void compute_mach_factor(void); | |
206 | ||
207 | /* Update threads quantum (in priority.c) */ | |
208 | extern void thread_quantum_update( | |
209 | int mycpu, | |
210 | thread_t thread, | |
211 | int nticks, | |
212 | int state); | |
213 | ||
214 | extern int min_quantum; /* defines max context switch rate */ | |
215 | ||
216 | /* | |
217 | * Shift structures for holding update shifts. Actual computation | |
218 | * is usage = (usage >> shift1) +/- (usage >> abs(shift2)) where the | |
219 | * +/- is determined by the sign of shift 2. | |
220 | */ | |
221 | struct shift { | |
222 | int shift1; | |
223 | int shift2; | |
224 | }; | |
225 | ||
226 | typedef struct shift *shift_t, shift_data_t; | |
227 | ||
228 | /* | |
229 | * Age usage (1 << SCHED_TICK_SHIFT) times per second. | |
230 | */ | |
231 | ||
232 | extern unsigned sched_tick; | |
233 | ||
234 | #define SCHED_TICK_SHIFT 3 | |
235 | ||
236 | #define SCHED_SCALE 128 | |
237 | #define SCHED_SHIFT 7 | |
238 | ||
239 | /* | |
240 | * thread_timer_delta macro takes care of both thread timers. | |
241 | */ | |
242 | ||
243 | #define thread_timer_delta(thread) \ | |
244 | MACRO_BEGIN \ | |
245 | register unsigned delta; \ | |
246 | \ | |
247 | delta = 0; \ | |
248 | TIMER_DELTA((thread)->system_timer, \ | |
249 | (thread)->system_timer_save, delta); \ | |
250 | TIMER_DELTA((thread)->user_timer, \ | |
251 | (thread)->user_timer_save, delta); \ | |
252 | (thread)->cpu_delta += delta; \ | |
253 | (thread)->sched_delta += (delta * \ | |
254 | (thread)->processor_set->sched_load); \ | |
255 | MACRO_END | |
256 | ||
257 | #if SIMPLE_CLOCK | |
258 | /* | |
259 | * sched_usec is an exponential average of number of microseconds | |
260 | * in a second for clock drift compensation. | |
261 | */ | |
262 | ||
263 | extern int sched_usec; | |
264 | #endif /* SIMPLE_CLOCK */ | |
265 | ||
266 | #endif /* _KERN_SCHED_H_ */ |