2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
56 * Scheduling primitive definitions file
60 #ifndef _KERN_SCHED_PRIM_H_
61 #define _KERN_SCHED_PRIM_H_
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>
71 #ifdef MACH_KERNEL_PRIVATE
74 extern void sched_init(void);
76 extern void sched_startup(void);
78 extern void sched_timebase_init(void);
80 /* Force a preemption point for a thread and wait for it to stop running */
81 extern boolean_t
thread_stop(
84 /* Release a previous stop request */
85 extern void thread_unstop(
88 /* Wait for a thread to stop running */
89 extern void thread_wait(
92 /* Select a thread to run */
93 extern thread_t
thread_select(
94 processor_t myprocessor
);
96 /* Unblock thread on wake up */
97 extern boolean_t
thread_unblock(
99 wait_result_t wresult
);
101 /* Unblock and dispatch thread */
102 extern kern_return_t
thread_go(
104 wait_result_t wresult
);
106 /* Context switch primitive */
107 extern boolean_t
thread_invoke(
112 /* Perform calculations for thread finishing execution */
113 extern void thread_done(
116 processor_t processor
);
118 /* Set up for thread beginning execution */
119 extern void thread_begin(
121 processor_t processor
);
123 /* Handle previous thread at context switch */
124 extern void thread_dispatch(
127 /* Switch directly to a particular thread */
128 extern int thread_run(
130 thread_continue_t continuation
,
132 thread_t new_thread
);
134 /* Resume thread with new stack */
135 extern void thread_continue(
136 thread_t old_thread
);
138 /* Invoke continuation */
139 extern void call_continuation(
140 thread_continue_t continuation
,
142 wait_result_t wresult
);
144 /* Set the current scheduled priority */
145 extern void set_sched_pri(
149 /* Set base priority of the specified thread */
150 extern void set_priority(
154 /* Reset scheduled priority of thread */
155 extern void compute_priority(
157 boolean_t override_depress
);
159 /* Adjust scheduled priority of thread during execution */
160 extern void compute_my_priority(
163 /* Periodic scheduler activity */
164 extern void sched_tick_thread(void);
166 /* Perform sched_tick housekeeping activities */
167 extern void update_priority(
170 /* Idle processor thread */
171 extern void idle_thread(void);
173 extern kern_return_t
idle_thread_create(
174 processor_t processor
);
176 /* Start thread running */
177 extern void thread_bootstrap_return(void);
179 /* Continuation return from syscall */
180 extern void thread_syscall_return(
184 extern wait_result_t
thread_block_reason(
185 thread_continue_t continuation
,
189 /* Reschedule thread for execution */
190 extern void thread_setrun(
194 #define SCHED_TAILQ 0
195 #define SCHED_HEADQ 1
196 #define SCHED_PREEMPT 2
198 /* Bind thread to a particular processor */
199 extern processor_t
thread_bind(
201 processor_t processor
);
203 extern void thread_timer_expire(
207 /* Set the maximum interrupt level for the thread */
208 __private_extern__ wait_interrupt_t
thread_interrupt_level(
209 wait_interrupt_t interruptible
);
211 __private_extern__ wait_result_t
thread_mark_wait_locked(
213 wait_interrupt_t interruptible
);
215 /* Wake up locked thread directly, passing result */
216 __private_extern__ kern_return_t
clear_wait_internal(
218 wait_result_t result
);
220 #endif /* MACH_KERNEL_PRIVATE */
224 #ifdef XNU_KERNEL_PRIVATE
226 extern boolean_t
assert_wait_possible(void);
229 ****************** Only exported until BSD stops using ********************
232 /* Wake up thread directly, passing result */
233 extern kern_return_t
clear_wait(
235 wait_result_t result
);
237 /* Return from exception (BSD-visible interface) */
238 extern void thread_exception_return(void);
240 #endif /* XNU_KERNEL_PRIVATE */
243 extern wait_result_t
thread_block(
244 thread_continue_t continuation
);
246 extern wait_result_t
thread_block_parameter(
247 thread_continue_t continuation
,
250 /* Declare thread will wait on a particular event */
251 extern wait_result_t
assert_wait(
253 wait_interrupt_t interruptible
);
255 /* Assert that the thread intends to wait with a timeout */
256 extern wait_result_t
assert_wait_timeout(
258 wait_interrupt_t interruptible
,
260 uint32_t scale_factor
);
262 extern wait_result_t
assert_wait_deadline(
264 wait_interrupt_t interruptible
,
267 /* Wake up thread (or threads) waiting on a particular event */
268 extern kern_return_t
thread_wakeup_prim(
270 boolean_t one_thread
,
271 wait_result_t result
);
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)
280 extern boolean_t
preemption_enabled(void);
282 #ifdef KERNEL_PRIVATE
285 * Obsolete interfaces.
288 extern void thread_set_timer(
290 uint32_t scale_factor
);
292 extern void thread_set_timer_deadline(
295 extern void thread_cancel_timer(void);
297 #ifndef MACH_KERNEL_PRIVATE
299 #ifndef ABSOLUTETIME_SCALAR_TYPE
301 #define thread_set_timer_deadline(a) \
302 thread_set_timer_deadline(__OSAbsoluteTime(a))
304 #endif /* ABSOLUTETIME_SCALAR_TYPE */
306 #endif /* MACH_KERNEL_PRIVATE */
308 #endif /* KERNEL_PRIVATE */
312 #endif /* _KERN_SCHED_PRIM_H_ */