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