|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
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 [email protected]
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>
69: #include <kern/lock.h>
70: #include <kern/time_out.h> /*** ??? temp - remove me soon ***/
71: #include <kern/cpu_data.h>
72: #include <kern/wait_queue.h>
73:
74: #ifdef MACH_KERNEL_PRIVATE
75:
76: #include <mach_ldebug.h>
77: /*
78: * Exported interface to sched_prim.c.
79: * A few of these functions are actually defined in
80: * ipc_sched.c, for historical reasons.
81: */
82:
83: /* Initialize scheduler module */
84: extern void sched_init(void);
85:
86: /* Called when timeout expires */
87: extern void thread_timer_expire(
88: thread_t thread);
89:
90: /*
91: * Set up thread timeout element when thread is created.
92: */
93: extern void thread_timer_setup(
94: thread_t thread);
95:
96: #define thread_bind_locked(thread, processor) \
97: (thread)->bound_processor = (processor)
98:
99: /*
100: * Prevent a thread from restarting after it blocks interruptibly
101: */
102: extern boolean_t thread_stop(
103: thread_t thread);
104:
105: /*
106: * wait for a thread to stop
107: */
108: extern boolean_t thread_wait(
109: thread_t thread);
110:
111: /* Select a thread to run on a particular processor */
112: extern thread_t thread_select(
113: processor_t myprocessor);
114:
115: extern void thread_go_locked(
116: thread_t thread,
117: int result);
118:
119: /* Stop old thread and run new thread */
120: extern boolean_t thread_invoke(
121: thread_t old_thread,
122: thread_t new_thread,
123: int reason,
124: void (*continuation)(void));
125:
126: /* Called when current thread is given new stack */
127: extern void thread_continue(
128: thread_t old_thread);
129:
130:
131: /* Switch directly to a particular thread */
132: extern void thread_run(
133: void (*continuation)(void),
134: thread_t new_thread);
135:
136: /* Dispatch a thread not on a run queue */
137: extern void thread_dispatch(
138: thread_t thread);
139:
140: /* Invoke continuation */
141: extern void call_continuation(
142: void (*continuation)(void));
143:
144: /* Compute effective priority of the specified thread */
145: extern void compute_priority(
146: thread_t thread,
147: int resched);
148:
149: /* Version of compute_priority for current thread or
150: * thread being manipuldated by scheduler.
151: */
152: extern void compute_my_priority(
153: thread_t thread);
154:
155: /* Recompute priorities of all threads (done periodically) */
156: extern void recompute_priorities(void);
157:
158: /* Update priority of thread that has been sleeping or suspended.
159: * Used to "catch up" with the system.
160: */
161: extern void update_priority(
162: thread_t thread);
163:
164: /* Idle thread loop */
165: extern void idle_thread(void);
166:
167: /* Scheduling thread loop */
168: extern void sched_thread(void);
169:
170: /*
171: * thread_sleep_interlock:
172: *
173: * Cause the current thread to wait until the specified event
174: * occurs. The specified HW interlock is unlocked before releasing
175: * the cpu. (This is a convenient way to sleep without manually
176: * calling assert_wait).
177: */
178:
179: #define thread_sleep_interlock(event, lock, interruptible) \
180: MACRO_BEGIN \
181: assert_wait(event, interruptible); \
182: interlock_unlock(lock); \
183: thread_block((void (*)(void)) 0); \
184: MACRO_END
185:
186: /*
187: * Machine-dependent code must define these functions.
188: */
189:
190: /* Start thread running */
191: extern void thread_bootstrap_return(void);
192:
193: /* Return from exception */
194: extern void thread_exception_return(void);
195:
196: extern thread_t switch_context(
197: thread_t old_thread,
198: void (*continuation)(void),
199: thread_t new_thread);
200:
201: /* Attach stack to thread */
202: extern void machine_kernel_stack_init(
203: thread_t thread,
204: void (*continuation)(void));
205:
206: extern void load_context(
207: thread_t thread);
208:
209: extern thread_act_t switch_act(
210: thread_act_t act);
211:
212: extern void machine_switch_act(
213: thread_t thread,
214: thread_act_t old,
215: thread_act_t new,
216: int cpu);
217:
218: /*
219: * These functions are either defined in kern/thread.c
220: * or are defined directly by machine-dependent code.
221: */
222:
223: /* Allocate an activation stack */
224: extern vm_offset_t stack_alloc(thread_t thread, void (*continuation)(void));
225:
226: /* Free an activation stack */
227: extern void stack_free(thread_t thread);
228:
229: /* Collect excess kernel stacks */
230: extern void stack_collect(void);
231:
232: /*
233: * Temporary definitions needed for MK SP work-in-progress
234: */
235: extern void set_pri(
236: thread_t thread,
237: int pri,
238: boolean_t resched);
239:
240: extern thread_t sched_thread_id;
241:
242:
243: /* Block current thread, indicating reason (Block or Quantum expiration) */
244: extern int thread_block_reason(
245: void (*continuation)(void),
246: int reason);
247:
248: /* Make thread runnable */
249: extern void thread_setrun(
250: thread_t thread,
251: boolean_t may_preempt,
252: boolean_t tail);
253: /*
254: * Flags for thread_setrun()
255: */
256:
257: #define HEAD_Q 0 /* FALSE */
258: #define TAIL_Q 1 /* TRUE */
259:
260: #endif /* MACH_KERNEL_PRIVATE */
261:
262: /*
263: ****************** Only exported until BSD stops using ********************
264: */
265:
266: /*
267: * Cancel a stop and continue the thread if necessary.
268: */
269: extern void thread_unstop(
270: thread_t thread);
271:
272: /* Wake up thread directly, passing result */
273: extern void clear_wait(
274: thread_t thread,
275: int result,
276: boolean_t interruptible);
277:
278: /* Bind thread to a particular processor */
279: extern void thread_bind(
280: thread_t thread,
281: processor_t processor);
282:
283:
284: /*
285: * ********************* PUBLIC APIs ************************************
286: */
287:
288: /* Set timer for current thread */
289: extern void thread_set_timer(
290: natural_t interval,
291: natural_t scale_factor);
292:
293: extern void thread_set_timer_deadline(
294: AbsoluteTime deadline);
295:
296: extern void thread_cancel_timer(void);
297:
298: /*
299: * thread_stop a thread then wait for it to stop (both of the above)
300: */
301: extern boolean_t thread_stop_wait(
302: thread_t thread);
303:
304: /* Declare thread will wait on a particular event */
305: extern void assert_wait(
306: event_t event,
307: int interruptflag);
308:
309: /* Assert that the thread intends to wait for a timeout */
310: extern void assert_wait_timeout(
311: natural_t msecs,
312: int interruptflags);
313:
314: /* Wake up thread (or threads) waiting on a particular event */
315: extern void thread_wakeup_prim(
316: event_t event,
317: boolean_t one_thread,
318: int result);
319:
320: /* Block current thread (Block reason) */
321: extern int thread_block(
322: void (*continuation)(void));
323:
324:
325: /*
326: * Routines defined as macros
327: */
328:
329: #define thread_wakeup(x) \
330: thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
331: #define thread_wakeup_with_result(x, z) \
332: thread_wakeup_prim((x), FALSE, (z))
333: #define thread_wakeup_one(x) \
334: thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
335:
336: /*
337: * thread_sleep_mutex:
338: *
339: * Cause the current thread to wait until the specified event
340: * occurs. The specified mutex is unlocked before releasing
341: * the cpu. (This is a convenient way to sleep without manually
342: * calling assert_wait).
343: */
344:
345: #define thread_sleep_mutex(event, lock, interruptible) \
346: MACRO_BEGIN \
347: assert_wait(event, interruptible); \
348: mutex_unlock(lock); \
349: thread_block((void (*)(void)) 0); \
350: MACRO_END
351:
352: /*
353: * thread_sleep_simple_lock:
354: *
355: * Cause the current thread to wait until the specified event
356: * occurs. The specified simple_lock is unlocked before releasing
357: * the cpu. (This is a convenient way to sleep without manually
358: * calling assert_wait).
359: */
360:
361: #define thread_sleep_simple_lock(event, lock, interruptible) \
362: MACRO_BEGIN \
363: assert_wait(event, interruptible); \
364: simple_unlock(lock); \
365: thread_block((void (*)(void)) 0); \
366: MACRO_END
367:
368:
369: #endif /* _KERN_SCHED_PRIM_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.