]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/sched_prim.h
xnu-344.49.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
92/*
93 * Set up thread timeout element(s) when thread is created.
94 */
95extern void thread_timer_setup(
96 thread_t thread);
97
98extern void thread_timer_terminate(void);
99
100#define thread_bind_locked(thread, processor) \
101 (thread)->bound_processor = (processor)
102
103/*
9bccf70c 104 * Stop a thread and wait for it to stop running.
1c79356b
A
105 */
106extern boolean_t thread_stop(
107 thread_t thread);
108
109/*
9bccf70c 110 * Wait for a thread to stop running.
1c79356b
A
111 */
112extern boolean_t thread_wait(
113 thread_t thread);
114
115/* Select a thread to run on a particular processor */
116extern thread_t thread_select(
117 processor_t myprocessor);
118
9bccf70c
A
119extern kern_return_t thread_go_locked(
120 thread_t thread,
121 wait_result_t result);
1c79356b
A
122
123/* Stop old thread and run new thread */
124extern boolean_t thread_invoke(
9bccf70c
A
125 thread_t old_thread,
126 thread_t new_thread,
127 int reason,
128 thread_continue_t continuation);
1c79356b
A
129
130/* Called when current thread is given new stack */
131extern void thread_continue(
9bccf70c 132 thread_t old_thread);
1c79356b
A
133
134/* Switch directly to a particular thread */
135extern int thread_run(
9bccf70c
A
136 thread_t old_thread,
137 thread_continue_t continuation,
138 thread_t new_thread);
1c79356b
A
139
140/* Dispatch a thread not on a run queue */
141extern void thread_dispatch(
9bccf70c 142 thread_t thread);
1c79356b
A
143
144/* Invoke continuation */
145extern void call_continuation(
9bccf70c
A
146 thread_continue_t continuation);
147
148/* Set the current scheduled priority */
149extern void set_sched_pri(
150 thread_t thread,
151 int priority);
1c79356b 152
9bccf70c
A
153/* Set base priority of the specified thread */
154extern void set_priority(
155 thread_t thread,
156 int priority);
157
158/* Reset scheduled priority of thread */
1c79356b 159extern void compute_priority(
9bccf70c
A
160 thread_t thread,
161 boolean_t override_depress);
1c79356b 162
9bccf70c 163/* Adjust scheduled priority of thread during execution */
1c79356b 164extern void compute_my_priority(
9bccf70c 165 thread_t thread);
1c79356b
A
166
167/* Periodic scheduler activity */
0b4e3aa0 168extern void sched_tick_init(void);
1c79356b 169
9bccf70c
A
170/*
171 * Update thread to the current scheduler tick.
1c79356b
A
172 */
173extern void update_priority(
9bccf70c 174 thread_t thread);
1c79356b
A
175
176/* Idle thread loop */
177extern void idle_thread(void);
178
1c79356b
A
179/*
180 * Machine-dependent code must define these functions.
181 */
182
183/* Start thread running */
184extern void thread_bootstrap_return(void);
185
186/* Return from exception */
187extern void thread_exception_return(void);
188
189/* Continuation return from syscall */
190extern void thread_syscall_return(
191 kern_return_t ret);
192
193extern thread_t switch_context(
194 thread_t old_thread,
9bccf70c 195 thread_continue_t continuation,
1c79356b
A
196 thread_t new_thread);
197
198/* Attach stack to thread */
199extern void machine_kernel_stack_init(
200 thread_t thread,
201 void (*start_pos)(thread_t));
202
203extern void load_context(
204 thread_t thread);
205
206extern thread_act_t switch_act(
207 thread_act_t act);
208
209extern void machine_switch_act(
210 thread_t thread,
211 thread_act_t old,
212 thread_act_t new,
213 int cpu);
214
215/*
216 * These functions are either defined in kern/thread.c
217 * or are defined directly by machine-dependent code.
218 */
219
220/* Allocate an activation stack */
221extern vm_offset_t stack_alloc(thread_t thread, void (*start_pos)(thread_t));
222
223/* Free an activation stack */
224extern void stack_free(thread_t thread);
225
226/* Collect excess kernel stacks */
227extern void stack_collect(void);
228
9bccf70c
A
229/* Block current thread, indicating reason */
230extern wait_result_t thread_block_reason(
231 thread_continue_t continuation,
232 ast_t reason);
1c79356b 233
9bccf70c 234/* Dispatch a thread for execution */
1c79356b 235extern void thread_setrun(
9bccf70c
A
236 thread_t thread,
237 boolean_t tail);
1c79356b
A
238
239#define HEAD_Q 0 /* FALSE */
240#define TAIL_Q 1 /* TRUE */
241
242/* Bind thread to a particular processor */
243extern void thread_bind(
9bccf70c
A
244 thread_t thread,
245 processor_t processor);
1c79356b 246
9bccf70c
A
247/* Set the maximum interrupt level for the thread */
248__private_extern__ wait_interrupt_t thread_interrupt_level(
249 wait_interrupt_t interruptible);
250
251__private_extern__ wait_result_t thread_mark_wait_locked(
252 thread_t thread,
253 wait_interrupt_t interruptible);
254
255/* Sleep, unlocking and then relocking a usimple_lock in the process */
256__private_extern__ wait_result_t thread_sleep_fast_usimple_lock(
257 event_t event,
258 simple_lock_t lock,
259 wait_interrupt_t interruptible);
260
261/* Wake up locked thread directly, passing result */
262__private_extern__ kern_return_t clear_wait_internal(
263 thread_t thread,
264 wait_result_t result);
1c79356b
A
265
266#endif /* MACH_KERNEL_PRIVATE */
267
268/*
269 ****************** Only exported until BSD stops using ********************
270 */
271
272/*
9bccf70c 273 * Cancel a stop and unblock the thread if already stopped.
1c79356b
A
274 */
275extern void thread_unstop(
9bccf70c 276 thread_t thread);
1c79356b
A
277
278/* Wake up thread directly, passing result */
9bccf70c
A
279extern kern_return_t clear_wait(
280 thread_t thread,
281 wait_result_t result);
1c79356b 282
9bccf70c 283#endif /* __APPLE_API_PRIVATE */
1c79356b
A
284
285/*
286 * ********************* PUBLIC APIs ************************************
287 */
288
289/* Set timer for current thread */
290extern void thread_set_timer(
0b4e3aa0
A
291 uint32_t interval,
292 uint32_t scale_factor);
1c79356b
A
293
294extern void thread_set_timer_deadline(
0b4e3aa0 295 uint64_t deadline);
1c79356b
A
296
297extern void thread_cancel_timer(void);
298
1c79356b 299/* Declare thread will wait on a particular event */
9bccf70c
A
300extern wait_result_t assert_wait(
301 event_t event,
302 wait_interrupt_t interruptflag);
1c79356b
A
303
304/* Assert that the thread intends to wait for a timeout */
9bccf70c
A
305extern wait_result_t assert_wait_timeout(
306 natural_t msecs,
307 wait_interrupt_t interruptflags);
308
309/* Sleep, unlocking and then relocking a usimple_lock in the process */
310extern wait_result_t thread_sleep_usimple_lock(
311 event_t event,
312 usimple_lock_t lock,
313 wait_interrupt_t interruptible);
314
315/* Sleep, unlocking and then relocking a mutex in the process */
316extern wait_result_t thread_sleep_mutex(
317 event_t event,
318 mutex_t *mutex,
319 wait_interrupt_t interruptible);
320
321/* Sleep with a deadline, unlocking and then relocking a mutex in the process */
322extern wait_result_t thread_sleep_mutex_deadline(
323 event_t event,
324 mutex_t *mutex,
325 uint64_t deadline,
326 wait_interrupt_t interruptible);
327
328/* Sleep, unlocking and then relocking a write lock in the process */
329extern wait_result_t thread_sleep_lock_write(
330 event_t event,
331 lock_t *lock,
332 wait_interrupt_t interruptible);
333
334/* Sleep, hinting that a thread funnel may be involved in the process */
335extern wait_result_t thread_sleep_funnel(
336 event_t event,
337 wait_interrupt_t interruptible);
1c79356b
A
338
339/* Wake up thread (or threads) waiting on a particular event */
9bccf70c
A
340extern kern_return_t thread_wakeup_prim(
341 event_t event,
342 boolean_t one_thread,
343 wait_result_t result);
344
345#ifdef __APPLE_API_UNSTABLE
1c79356b
A
346
347/* Block current thread (Block reason) */
9bccf70c
A
348extern wait_result_t thread_block(
349 thread_continue_t continuation);
1c79356b 350
9bccf70c 351#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
352
353/*
354 * Routines defined as macros
355 */
356
357#define thread_wakeup(x) \
358 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
359#define thread_wakeup_with_result(x, z) \
360 thread_wakeup_prim((x), FALSE, (z))
361#define thread_wakeup_one(x) \
362 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
363
0b4e3aa0
A
364#if !defined(MACH_KERNEL_PRIVATE) && !defined(ABSOLUTETIME_SCALAR_TYPE)
365
366#include <libkern/OSBase.h>
367
368#define thread_set_timer_deadline(a) \
369 thread_set_timer_deadline(__OSAbsoluteTime(a))
370
371#endif
1c79356b
A
372
373#endif /* _KERN_SCHED_PRIM_H_ */