]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
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. | |
8f6c56a5 | 11 | * |
6601e61a A |
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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
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. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
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> | |
91447636 | 69 | #include <sys/cdefs.h> |
9bccf70c A |
70 | |
71 | #ifdef MACH_KERNEL_PRIVATE | |
1c79356b | 72 | |
91447636 | 73 | /* Initialization */ |
1c79356b A |
74 | extern void sched_init(void); |
75 | ||
91447636 | 76 | extern void sched_startup(void); |
1c79356b | 77 | |
91447636 | 78 | extern void sched_timebase_init(void); |
1c79356b | 79 | |
91447636 | 80 | /* Force a preemption point for a thread and wait for it to stop running */ |
1c79356b A |
81 | extern boolean_t thread_stop( |
82 | thread_t thread); | |
83 | ||
91447636 A |
84 | /* Release a previous stop request */ |
85 | extern void thread_unstop( | |
1c79356b A |
86 | thread_t thread); |
87 | ||
91447636 A |
88 | /* Wait for a thread to stop running */ |
89 | extern void thread_wait( | |
90 | thread_t thread); | |
1c79356b | 91 | |
91447636 A |
92 | /* Select a thread to run */ |
93 | extern thread_t thread_select( | |
94 | processor_t myprocessor); | |
1c79356b | 95 | |
91447636 A |
96 | /* Unblock thread on wake up */ |
97 | extern boolean_t thread_unblock( | |
98 | thread_t thread, | |
99 | wait_result_t wresult); | |
1c79356b | 100 | |
91447636 A |
101 | /* Unblock and dispatch thread */ |
102 | extern kern_return_t thread_go( | |
103 | thread_t thread, | |
104 | wait_result_t wresult); | |
1c79356b | 105 | |
91447636 A |
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( | |
9bccf70c | 114 | thread_t old_thread, |
91447636 A |
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); | |
1c79356b | 122 | |
91447636 A |
123 | /* Handle previous thread at context switch */ |
124 | extern void thread_dispatch( | |
9bccf70c | 125 | thread_t thread); |
1c79356b | 126 | |
91447636 A |
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 | ||
1c79356b A |
138 | /* Invoke continuation */ |
139 | extern void call_continuation( | |
91447636 A |
140 | thread_continue_t continuation, |
141 | void *parameter, | |
142 | wait_result_t wresult); | |
9bccf70c A |
143 | |
144 | /* Set the current scheduled priority */ | |
145 | extern void set_sched_pri( | |
146 | thread_t thread, | |
147 | int priority); | |
1c79356b | 148 | |
9bccf70c A |
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 */ | |
1c79356b | 155 | extern void compute_priority( |
9bccf70c A |
156 | thread_t thread, |
157 | boolean_t override_depress); | |
1c79356b | 158 | |
9bccf70c | 159 | /* Adjust scheduled priority of thread during execution */ |
1c79356b | 160 | extern void compute_my_priority( |
9bccf70c | 161 | thread_t thread); |
1c79356b A |
162 | |
163 | /* Periodic scheduler activity */ | |
91447636 | 164 | extern void sched_tick_thread(void); |
1c79356b | 165 | |
91447636 | 166 | /* Perform sched_tick housekeeping activities */ |
1c79356b | 167 | extern void update_priority( |
9bccf70c | 168 | thread_t thread); |
1c79356b | 169 | |
91447636 | 170 | /* Idle processor thread */ |
1c79356b A |
171 | extern void idle_thread(void); |
172 | ||
91447636 A |
173 | extern kern_return_t idle_thread_create( |
174 | processor_t processor); | |
1c79356b A |
175 | |
176 | /* Start thread running */ | |
177 | extern void thread_bootstrap_return(void); | |
178 | ||
1c79356b A |
179 | /* Continuation return from syscall */ |
180 | extern void thread_syscall_return( | |
181 | kern_return_t ret); | |
182 | ||
91447636 | 183 | /* Context switch */ |
9bccf70c A |
184 | extern wait_result_t thread_block_reason( |
185 | thread_continue_t continuation, | |
91447636 | 186 | void *parameter, |
9bccf70c | 187 | ast_t reason); |
1c79356b | 188 | |
91447636 | 189 | /* Reschedule thread for execution */ |
1c79356b | 190 | extern void thread_setrun( |
9bccf70c | 191 | thread_t thread, |
55e303ae | 192 | integer_t options); |
1c79356b | 193 | |
55e303ae A |
194 | #define SCHED_TAILQ 0 |
195 | #define SCHED_HEADQ 1 | |
196 | #define SCHED_PREEMPT 2 | |
1c79356b A |
197 | |
198 | /* Bind thread to a particular processor */ | |
55e303ae A |
199 | extern processor_t thread_bind( |
200 | thread_t thread, | |
201 | processor_t processor); | |
1c79356b | 202 | |
91447636 A |
203 | extern void thread_timer_expire( |
204 | void *thread, | |
205 | void *p1); | |
206 | ||
9bccf70c A |
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 | ||
9bccf70c A |
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); | |
1c79356b A |
219 | |
220 | #endif /* MACH_KERNEL_PRIVATE */ | |
221 | ||
91447636 | 222 | __BEGIN_DECLS |
55e303ae | 223 | |
91447636 A |
224 | #ifdef XNU_KERNEL_PRIVATE |
225 | ||
226 | extern boolean_t assert_wait_possible(void); | |
1c79356b A |
227 | |
228 | /* | |
91447636 | 229 | ****************** Only exported until BSD stops using ******************** |
1c79356b | 230 | */ |
1c79356b A |
231 | |
232 | /* Wake up thread directly, passing result */ | |
9bccf70c A |
233 | extern kern_return_t clear_wait( |
234 | thread_t thread, | |
235 | wait_result_t result); | |
1c79356b | 236 | |
91447636 A |
237 | /* Return from exception (BSD-visible interface) */ |
238 | extern void thread_exception_return(void); | |
1c79356b | 239 | |
91447636 | 240 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 241 | |
91447636 A |
242 | /* Context switch */ |
243 | extern wait_result_t thread_block( | |
244 | thread_continue_t continuation); | |
1c79356b | 245 | |
91447636 A |
246 | extern wait_result_t thread_block_parameter( |
247 | thread_continue_t continuation, | |
248 | void *parameter); | |
1c79356b | 249 | |
1c79356b | 250 | /* Declare thread will wait on a particular event */ |
91447636 A |
251 | extern wait_result_t assert_wait( |
252 | event_t event, | |
253 | wait_interrupt_t interruptible); | |
1c79356b | 254 | |
91447636 A |
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); | |
1c79356b | 261 | |
91447636 A |
262 | extern wait_result_t assert_wait_deadline( |
263 | event_t event, | |
264 | wait_interrupt_t interruptible, | |
265 | uint64_t deadline); | |
1c79356b | 266 | |
91447636 A |
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); | |
1c79356b A |
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 | ||
91447636 A |
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); | |
0b4e3aa0 | 294 | |
91447636 A |
295 | extern void thread_cancel_timer(void); |
296 | ||
297 | #ifndef MACH_KERNEL_PRIVATE | |
298 | ||
299 | #ifndef ABSOLUTETIME_SCALAR_TYPE | |
0b4e3aa0 A |
300 | |
301 | #define thread_set_timer_deadline(a) \ | |
302 | thread_set_timer_deadline(__OSAbsoluteTime(a)) | |
303 | ||
91447636 A |
304 | #endif /* ABSOLUTETIME_SCALAR_TYPE */ |
305 | ||
306 | #endif /* MACH_KERNEL_PRIVATE */ | |
307 | ||
308 | #endif /* KERNEL_PRIVATE */ | |
309 | ||
310 | __END_DECLS | |
1c79356b A |
311 | |
312 | #endif /* _KERN_SCHED_PRIM_H_ */ |