]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/sched_prim.h
xnu-792.13.8.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_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58 /*
59 */
60 /*
61 * File: sched_prim.h
62 * Author: David Golub
63 *
64 * Scheduling primitive definitions file
65 *
66 */
67
68 #ifndef _KERN_SCHED_PRIM_H_
69 #define _KERN_SCHED_PRIM_H_
70
71 #include <mach/boolean.h>
72 #include <mach/machine/vm_types.h>
73 #include <mach/kern_return.h>
74 #include <kern/clock.h>
75 #include <kern/kern_types.h>
76 #include <kern/thread.h>
77 #include <sys/cdefs.h>
78
79 #ifdef MACH_KERNEL_PRIVATE
80
81 /* Initialization */
82 extern void sched_init(void);
83
84 extern void sched_startup(void);
85
86 extern void sched_timebase_init(void);
87
88 /* Force a preemption point for a thread and wait for it to stop running */
89 extern boolean_t thread_stop(
90 thread_t thread);
91
92 /* Release a previous stop request */
93 extern void thread_unstop(
94 thread_t thread);
95
96 /* Wait for a thread to stop running */
97 extern void thread_wait(
98 thread_t thread);
99
100 /* Select a thread to run */
101 extern thread_t thread_select(
102 processor_t myprocessor);
103
104 /* Unblock thread on wake up */
105 extern boolean_t thread_unblock(
106 thread_t thread,
107 wait_result_t wresult);
108
109 /* Unblock and dispatch thread */
110 extern kern_return_t thread_go(
111 thread_t thread,
112 wait_result_t wresult);
113
114 /* Context switch primitive */
115 extern boolean_t thread_invoke(
116 thread_t old_thread,
117 thread_t new_thread,
118 ast_t reason);
119
120 /* Perform calculations for thread finishing execution */
121 extern void thread_done(
122 thread_t old_thread,
123 thread_t new_thread,
124 processor_t processor);
125
126 /* Set up for thread beginning execution */
127 extern void thread_begin(
128 thread_t thread,
129 processor_t processor);
130
131 /* Handle previous thread at context switch */
132 extern void thread_dispatch(
133 thread_t thread);
134
135 /* Switch directly to a particular thread */
136 extern int thread_run(
137 thread_t self,
138 thread_continue_t continuation,
139 void *parameter,
140 thread_t new_thread);
141
142 /* Resume thread with new stack */
143 extern void thread_continue(
144 thread_t old_thread);
145
146 /* Invoke continuation */
147 extern void call_continuation(
148 thread_continue_t continuation,
149 void *parameter,
150 wait_result_t wresult);
151
152 /* Set the current scheduled priority */
153 extern void set_sched_pri(
154 thread_t thread,
155 int priority);
156
157 /* Set base priority of the specified thread */
158 extern void set_priority(
159 thread_t thread,
160 int priority);
161
162 /* Reset scheduled priority of thread */
163 extern void compute_priority(
164 thread_t thread,
165 boolean_t override_depress);
166
167 /* Adjust scheduled priority of thread during execution */
168 extern void compute_my_priority(
169 thread_t thread);
170
171 /* Periodic scheduler activity */
172 extern void sched_tick_thread(void);
173
174 /* Perform sched_tick housekeeping activities */
175 extern void update_priority(
176 thread_t thread);
177
178 /* Idle processor thread */
179 extern void idle_thread(void);
180
181 extern kern_return_t idle_thread_create(
182 processor_t processor);
183
184 /* Start thread running */
185 extern void thread_bootstrap_return(void);
186
187 /* Continuation return from syscall */
188 extern void thread_syscall_return(
189 kern_return_t ret);
190
191 /* Context switch */
192 extern wait_result_t thread_block_reason(
193 thread_continue_t continuation,
194 void *parameter,
195 ast_t reason);
196
197 /* Reschedule thread for execution */
198 extern void thread_setrun(
199 thread_t thread,
200 integer_t options);
201
202 #define SCHED_TAILQ 0
203 #define SCHED_HEADQ 1
204 #define SCHED_PREEMPT 2
205
206 /* Bind thread to a particular processor */
207 extern processor_t thread_bind(
208 thread_t thread,
209 processor_t processor);
210
211 extern void thread_timer_expire(
212 void *thread,
213 void *p1);
214
215 /* Set the maximum interrupt level for the thread */
216 __private_extern__ wait_interrupt_t thread_interrupt_level(
217 wait_interrupt_t interruptible);
218
219 __private_extern__ wait_result_t thread_mark_wait_locked(
220 thread_t thread,
221 wait_interrupt_t interruptible);
222
223 /* Wake up locked thread directly, passing result */
224 __private_extern__ kern_return_t clear_wait_internal(
225 thread_t thread,
226 wait_result_t result);
227
228 #endif /* MACH_KERNEL_PRIVATE */
229
230 __BEGIN_DECLS
231
232 #ifdef XNU_KERNEL_PRIVATE
233
234 extern boolean_t assert_wait_possible(void);
235
236 /*
237 ****************** Only exported until BSD stops using ********************
238 */
239
240 /* Wake up thread directly, passing result */
241 extern kern_return_t clear_wait(
242 thread_t thread,
243 wait_result_t result);
244
245 /* Return from exception (BSD-visible interface) */
246 extern void thread_exception_return(void);
247
248 #endif /* XNU_KERNEL_PRIVATE */
249
250 /* Context switch */
251 extern wait_result_t thread_block(
252 thread_continue_t continuation);
253
254 extern wait_result_t thread_block_parameter(
255 thread_continue_t continuation,
256 void *parameter);
257
258 /* Declare thread will wait on a particular event */
259 extern wait_result_t assert_wait(
260 event_t event,
261 wait_interrupt_t interruptible);
262
263 /* Assert that the thread intends to wait with a timeout */
264 extern wait_result_t assert_wait_timeout(
265 event_t event,
266 wait_interrupt_t interruptible,
267 uint32_t interval,
268 uint32_t scale_factor);
269
270 extern wait_result_t assert_wait_deadline(
271 event_t event,
272 wait_interrupt_t interruptible,
273 uint64_t deadline);
274
275 /* Wake up thread (or threads) waiting on a particular event */
276 extern kern_return_t thread_wakeup_prim(
277 event_t event,
278 boolean_t one_thread,
279 wait_result_t result);
280
281 #define thread_wakeup(x) \
282 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
283 #define thread_wakeup_with_result(x, z) \
284 thread_wakeup_prim((x), FALSE, (z))
285 #define thread_wakeup_one(x) \
286 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
287
288 extern boolean_t preemption_enabled(void);
289
290 #ifdef KERNEL_PRIVATE
291
292 /*
293 * Obsolete interfaces.
294 */
295
296 extern void thread_set_timer(
297 uint32_t interval,
298 uint32_t scale_factor);
299
300 extern void thread_set_timer_deadline(
301 uint64_t deadline);
302
303 extern void thread_cancel_timer(void);
304
305 #ifndef MACH_KERNEL_PRIVATE
306
307 #ifndef ABSOLUTETIME_SCALAR_TYPE
308
309 #define thread_set_timer_deadline(a) \
310 thread_set_timer_deadline(__OSAbsoluteTime(a))
311
312 #endif /* ABSOLUTETIME_SCALAR_TYPE */
313
314 #endif /* MACH_KERNEL_PRIVATE */
315
316 #endif /* KERNEL_PRIVATE */
317
318 __END_DECLS
319
320 #endif /* _KERN_SCHED_PRIM_H_ */