]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/sched_prim.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / kern / sched_prim.h
1 /*
2 * Copyright (c) 2000-2005 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_prim.h
54 * Author: David Golub
55 *
56 * Scheduling primitive definitions file
57 *
58 */
59
60 #ifndef _KERN_SCHED_PRIM_H_
61 #define _KERN_SCHED_PRIM_H_
62
63 #include <mach/boolean.h>
64 #include <mach/machine/vm_types.h>
65 #include <mach/kern_return.h>
66 #include <kern/clock.h>
67 #include <kern/kern_types.h>
68 #include <kern/thread.h>
69 #include <sys/cdefs.h>
70
71 #ifdef MACH_KERNEL_PRIVATE
72
73 /* Initialization */
74 extern void sched_init(void);
75
76 extern void sched_startup(void);
77
78 extern void sched_timebase_init(void);
79
80 /* Force a preemption point for a thread and wait for it to stop running */
81 extern boolean_t thread_stop(
82 thread_t thread);
83
84 /* Release a previous stop request */
85 extern void thread_unstop(
86 thread_t thread);
87
88 /* Wait for a thread to stop running */
89 extern void thread_wait(
90 thread_t thread);
91
92 /* Select a thread to run */
93 extern thread_t thread_select(
94 processor_t myprocessor);
95
96 /* Unblock thread on wake up */
97 extern boolean_t thread_unblock(
98 thread_t thread,
99 wait_result_t wresult);
100
101 /* Unblock and dispatch thread */
102 extern kern_return_t thread_go(
103 thread_t thread,
104 wait_result_t wresult);
105
106 /* Context switch primitive */
107 extern boolean_t thread_invoke(
108 thread_t old_thread,
109 thread_t new_thread,
110 ast_t reason);
111
112 /* Perform calculations for thread finishing execution */
113 extern void thread_done(
114 thread_t old_thread,
115 thread_t new_thread,
116 processor_t processor);
117
118 /* Set up for thread beginning execution */
119 extern void thread_begin(
120 thread_t thread,
121 processor_t processor);
122
123 /* Handle previous thread at context switch */
124 extern void thread_dispatch(
125 thread_t thread);
126
127 /* Switch directly to a particular thread */
128 extern int thread_run(
129 thread_t self,
130 thread_continue_t continuation,
131 void *parameter,
132 thread_t new_thread);
133
134 /* Resume thread with new stack */
135 extern void thread_continue(
136 thread_t old_thread);
137
138 /* Invoke continuation */
139 extern void call_continuation(
140 thread_continue_t continuation,
141 void *parameter,
142 wait_result_t wresult);
143
144 /* Set the current scheduled priority */
145 extern void set_sched_pri(
146 thread_t thread,
147 int priority);
148
149 /* Set base priority of the specified thread */
150 extern void set_priority(
151 thread_t thread,
152 int priority);
153
154 /* Reset scheduled priority of thread */
155 extern void compute_priority(
156 thread_t thread,
157 boolean_t override_depress);
158
159 /* Adjust scheduled priority of thread during execution */
160 extern void compute_my_priority(
161 thread_t thread);
162
163 /* Periodic scheduler activity */
164 extern void sched_tick_thread(void);
165
166 /* Perform sched_tick housekeeping activities */
167 extern void update_priority(
168 thread_t thread);
169
170 /* Idle processor thread */
171 extern void idle_thread(void);
172
173 extern kern_return_t idle_thread_create(
174 processor_t processor);
175
176 /* Start thread running */
177 extern void thread_bootstrap_return(void);
178
179 /* Continuation return from syscall */
180 extern void thread_syscall_return(
181 kern_return_t ret);
182
183 /* Context switch */
184 extern wait_result_t thread_block_reason(
185 thread_continue_t continuation,
186 void *parameter,
187 ast_t reason);
188
189 /* Reschedule thread for execution */
190 extern void thread_setrun(
191 thread_t thread,
192 integer_t options);
193
194 #define SCHED_TAILQ 0
195 #define SCHED_HEADQ 1
196 #define SCHED_PREEMPT 2
197
198 /* Bind thread to a particular processor */
199 extern processor_t thread_bind(
200 thread_t thread,
201 processor_t processor);
202
203 extern void thread_timer_expire(
204 void *thread,
205 void *p1);
206
207 /* Set the maximum interrupt level for the thread */
208 __private_extern__ wait_interrupt_t thread_interrupt_level(
209 wait_interrupt_t interruptible);
210
211 __private_extern__ wait_result_t thread_mark_wait_locked(
212 thread_t thread,
213 wait_interrupt_t interruptible);
214
215 /* Wake up locked thread directly, passing result */
216 __private_extern__ kern_return_t clear_wait_internal(
217 thread_t thread,
218 wait_result_t result);
219
220 #endif /* MACH_KERNEL_PRIVATE */
221
222 __BEGIN_DECLS
223
224 #ifdef XNU_KERNEL_PRIVATE
225
226 extern boolean_t assert_wait_possible(void);
227
228 /*
229 ****************** Only exported until BSD stops using ********************
230 */
231
232 /* Wake up thread directly, passing result */
233 extern kern_return_t clear_wait(
234 thread_t thread,
235 wait_result_t result);
236
237 /* Return from exception (BSD-visible interface) */
238 extern void thread_exception_return(void);
239
240 #endif /* XNU_KERNEL_PRIVATE */
241
242 /* Context switch */
243 extern wait_result_t thread_block(
244 thread_continue_t continuation);
245
246 extern wait_result_t thread_block_parameter(
247 thread_continue_t continuation,
248 void *parameter);
249
250 /* Declare thread will wait on a particular event */
251 extern wait_result_t assert_wait(
252 event_t event,
253 wait_interrupt_t interruptible);
254
255 /* Assert that the thread intends to wait with a timeout */
256 extern wait_result_t assert_wait_timeout(
257 event_t event,
258 wait_interrupt_t interruptible,
259 uint32_t interval,
260 uint32_t scale_factor);
261
262 extern wait_result_t assert_wait_deadline(
263 event_t event,
264 wait_interrupt_t interruptible,
265 uint64_t deadline);
266
267 /* Wake up thread (or threads) waiting on a particular event */
268 extern kern_return_t thread_wakeup_prim(
269 event_t event,
270 boolean_t one_thread,
271 wait_result_t result);
272
273 #define thread_wakeup(x) \
274 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
275 #define thread_wakeup_with_result(x, z) \
276 thread_wakeup_prim((x), FALSE, (z))
277 #define thread_wakeup_one(x) \
278 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
279
280 extern boolean_t preemption_enabled(void);
281
282 #ifdef KERNEL_PRIVATE
283
284 /*
285 * Obsolete interfaces.
286 */
287
288 extern void thread_set_timer(
289 uint32_t interval,
290 uint32_t scale_factor);
291
292 extern void thread_set_timer_deadline(
293 uint64_t deadline);
294
295 extern void thread_cancel_timer(void);
296
297 #ifndef MACH_KERNEL_PRIVATE
298
299 #ifndef ABSOLUTETIME_SCALAR_TYPE
300
301 #define thread_set_timer_deadline(a) \
302 thread_set_timer_deadline(__OSAbsoluteTime(a))
303
304 #endif /* ABSOLUTETIME_SCALAR_TYPE */
305
306 #endif /* MACH_KERNEL_PRIVATE */
307
308 #endif /* KERNEL_PRIVATE */
309
310 __END_DECLS
311
312 #endif /* _KERN_SCHED_PRIM_H_ */