]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/sched_prim.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / osfmk / kern / sched_prim.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53/*
54 */
55/*
56 * File: sched_prim.h
57 * Author: David Golub
58 *
59 * Scheduling primitive definitions file
60 *
61 */
62
63#ifndef _KERN_SCHED_PRIM_H_
64#define _KERN_SCHED_PRIM_H_
65
66#include <mach/boolean.h>
67#include <mach/machine/vm_types.h>
68#include <mach/kern_return.h>
69#include <kern/clock.h>
70#include <kern/kern_types.h>
71#include <kern/thread.h>
72#include <kern/lock.h>
73#include <kern/time_out.h> /*** ??? temp - remove me soon ***/
74#include <kern/cpu_data.h>
1c79356b 75
9bccf70c
A
76#include <sys/appleapiopts.h>
77
78#ifdef __APPLE_API_PRIVATE
79
80#ifdef MACH_KERNEL_PRIVATE
1c79356b
A
81
82#include <mach_ldebug.h>
83/*
84 * Exported interface to sched_prim.c.
85 * A few of these functions are actually defined in
86 * ipc_sched.c, for historical reasons.
87 */
88
89/* Initialize scheduler module */
90extern void sched_init(void);
91
55e303ae
A
92extern void sched_timebase_init(void);
93
1c79356b
A
94/*
95 * Set up thread timeout element(s) when thread is created.
96 */
97extern void thread_timer_setup(
98 thread_t thread);
99
100extern void thread_timer_terminate(void);
101
1c79356b 102/*
9bccf70c 103 * Stop a thread and wait for it to stop running.
1c79356b
A
104 */
105extern boolean_t thread_stop(
106 thread_t thread);
107
108/*
9bccf70c 109 * Wait for a thread to stop running.
1c79356b
A
110 */
111extern boolean_t thread_wait(
112 thread_t thread);
113
114/* Select a thread to run on a particular processor */
115extern thread_t thread_select(
116 processor_t myprocessor);
117
9bccf70c
A
118extern kern_return_t thread_go_locked(
119 thread_t thread,
120 wait_result_t result);
1c79356b
A
121
122/* Stop old thread and run new thread */
123extern boolean_t thread_invoke(
9bccf70c
A
124 thread_t old_thread,
125 thread_t new_thread,
126 int reason,
127 thread_continue_t continuation);
1c79356b
A
128
129/* Called when current thread is given new stack */
130extern void thread_continue(
9bccf70c 131 thread_t old_thread);
1c79356b
A
132
133/* Switch directly to a particular thread */
134extern int thread_run(
9bccf70c
A
135 thread_t old_thread,
136 thread_continue_t continuation,
137 thread_t new_thread);
1c79356b
A
138
139/* Dispatch a thread not on a run queue */
140extern void thread_dispatch(
9bccf70c 141 thread_t thread);
1c79356b
A
142
143/* Invoke continuation */
144extern void call_continuation(
9bccf70c
A
145 thread_continue_t continuation);
146
147/* Set the current scheduled priority */
148extern void set_sched_pri(
149 thread_t thread,
150 int priority);
1c79356b 151
9bccf70c
A
152/* Set base priority of the specified thread */
153extern void set_priority(
154 thread_t thread,
155 int priority);
156
157/* Reset scheduled priority of thread */
1c79356b 158extern void compute_priority(
9bccf70c
A
159 thread_t thread,
160 boolean_t override_depress);
1c79356b 161
9bccf70c 162/* Adjust scheduled priority of thread during execution */
1c79356b 163extern void compute_my_priority(
9bccf70c 164 thread_t thread);
1c79356b
A
165
166/* Periodic scheduler activity */
0b4e3aa0 167extern void sched_tick_init(void);
1c79356b 168
9bccf70c
A
169/*
170 * Update thread to the current scheduler tick.
1c79356b
A
171 */
172extern void update_priority(
9bccf70c 173 thread_t thread);
1c79356b
A
174
175/* Idle thread loop */
176extern void idle_thread(void);
177
1c79356b
A
178/*
179 * Machine-dependent code must define these functions.
180 */
181
182/* Start thread running */
183extern void thread_bootstrap_return(void);
184
185/* Return from exception */
186extern void thread_exception_return(void);
187
188/* Continuation return from syscall */
189extern void thread_syscall_return(
190 kern_return_t ret);
191
1c79356b
A
192/*
193 * These functions are either defined in kern/thread.c
194 * or are defined directly by machine-dependent code.
195 */
196
9bccf70c
A
197/* Block current thread, indicating reason */
198extern wait_result_t thread_block_reason(
199 thread_continue_t continuation,
200 ast_t reason);
1c79356b 201
9bccf70c 202/* Dispatch a thread for execution */
1c79356b 203extern void thread_setrun(
9bccf70c 204 thread_t thread,
55e303ae 205 integer_t options);
1c79356b 206
55e303ae
A
207#define SCHED_TAILQ 0
208#define SCHED_HEADQ 1
209#define SCHED_PREEMPT 2
1c79356b
A
210
211/* Bind thread to a particular processor */
55e303ae
A
212extern processor_t thread_bind(
213 thread_t thread,
214 processor_t processor);
1c79356b 215
9bccf70c
A
216/* Set the maximum interrupt level for the thread */
217__private_extern__ wait_interrupt_t thread_interrupt_level(
218 wait_interrupt_t interruptible);
219
220__private_extern__ wait_result_t thread_mark_wait_locked(
221 thread_t thread,
222 wait_interrupt_t interruptible);
223
224/* Sleep, unlocking and then relocking a usimple_lock in the process */
225__private_extern__ wait_result_t thread_sleep_fast_usimple_lock(
226 event_t event,
227 simple_lock_t lock,
228 wait_interrupt_t interruptible);
229
230/* Wake up locked thread directly, passing result */
231__private_extern__ kern_return_t clear_wait_internal(
232 thread_t thread,
233 wait_result_t result);
1c79356b 234
55e303ae
A
235__private_extern__
236 wait_queue_t wait_event_wait_queue(
237 event_t event);
238
1c79356b
A
239#endif /* MACH_KERNEL_PRIVATE */
240
55e303ae
A
241extern wait_result_t assert_wait_prim(
242 event_t event,
243 thread_roust_t roust_hint,
244 uint64_t deadline,
245 wait_interrupt_t interruptible);
246
1c79356b
A
247/*
248 ****************** Only exported until BSD stops using ********************
249 */
250
251/*
9bccf70c 252 * Cancel a stop and unblock the thread if already stopped.
1c79356b
A
253 */
254extern void thread_unstop(
9bccf70c 255 thread_t thread);
1c79356b
A
256
257/* Wake up thread directly, passing result */
9bccf70c
A
258extern kern_return_t clear_wait(
259 thread_t thread,
260 wait_result_t result);
1c79356b 261
9bccf70c 262#endif /* __APPLE_API_PRIVATE */
1c79356b
A
263
264/*
265 * ********************* PUBLIC APIs ************************************
266 */
267
268/* Set timer for current thread */
269extern void thread_set_timer(
0b4e3aa0
A
270 uint32_t interval,
271 uint32_t scale_factor);
1c79356b
A
272
273extern void thread_set_timer_deadline(
0b4e3aa0 274 uint64_t deadline);
1c79356b
A
275
276extern void thread_cancel_timer(void);
277
1c79356b 278/* Declare thread will wait on a particular event */
9bccf70c
A
279extern wait_result_t assert_wait(
280 event_t event,
281 wait_interrupt_t interruptflag);
1c79356b
A
282
283/* Assert that the thread intends to wait for a timeout */
9bccf70c
A
284extern wait_result_t assert_wait_timeout(
285 natural_t msecs,
286 wait_interrupt_t interruptflags);
287
288/* Sleep, unlocking and then relocking a usimple_lock in the process */
289extern wait_result_t thread_sleep_usimple_lock(
290 event_t event,
291 usimple_lock_t lock,
292 wait_interrupt_t interruptible);
293
294/* Sleep, unlocking and then relocking a mutex in the process */
295extern wait_result_t thread_sleep_mutex(
296 event_t event,
297 mutex_t *mutex,
298 wait_interrupt_t interruptible);
299
300/* Sleep with a deadline, unlocking and then relocking a mutex in the process */
301extern wait_result_t thread_sleep_mutex_deadline(
302 event_t event,
303 mutex_t *mutex,
304 uint64_t deadline,
305 wait_interrupt_t interruptible);
306
307/* Sleep, unlocking and then relocking a write lock in the process */
308extern wait_result_t thread_sleep_lock_write(
309 event_t event,
310 lock_t *lock,
311 wait_interrupt_t interruptible);
312
313/* Sleep, hinting that a thread funnel may be involved in the process */
314extern wait_result_t thread_sleep_funnel(
315 event_t event,
316 wait_interrupt_t interruptible);
1c79356b
A
317
318/* Wake up thread (or threads) waiting on a particular event */
9bccf70c
A
319extern kern_return_t thread_wakeup_prim(
320 event_t event,
321 boolean_t one_thread,
322 wait_result_t result);
323
324#ifdef __APPLE_API_UNSTABLE
1c79356b
A
325
326/* Block current thread (Block reason) */
9bccf70c
A
327extern wait_result_t thread_block(
328 thread_continue_t continuation);
1c79356b 329
9bccf70c 330#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
331
332/*
333 * Routines defined as macros
334 */
335
336#define thread_wakeup(x) \
337 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
338#define thread_wakeup_with_result(x, z) \
339 thread_wakeup_prim((x), FALSE, (z))
340#define thread_wakeup_one(x) \
341 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
342
0b4e3aa0
A
343#if !defined(MACH_KERNEL_PRIVATE) && !defined(ABSOLUTETIME_SCALAR_TYPE)
344
345#include <libkern/OSBase.h>
346
347#define thread_set_timer_deadline(a) \
348 thread_set_timer_deadline(__OSAbsoluteTime(a))
349
350#endif
1c79356b
A
351
352#endif /* _KERN_SCHED_PRIM_H_ */