1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
* Mach Operating System
* Copyright (c) 1992,1991,1990,1989,1988,1987 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* File: sched_prim.h
* Author: David Golub
*
* Scheduling primitive definitions file
*
*/
#ifndef _KERN_SCHED_PRIM_H_
#define _KERN_SCHED_PRIM_H_
#include <mach/boolean.h>
#include <mach/message.h> /* for mach_msg_timeout_t */
#include <kern/lock.h>
#include <kern/kern_types.h> /* for thread_t */
/*
* Possible results of assert_wait - returned in
* current_thread()->wait_result.
*/
#define THREAD_AWAKENED 0 /* normal wakeup */
#define THREAD_TIMED_OUT 1 /* timeout expired */
#define THREAD_INTERRUPTED 2 /* interrupted by clear_wait */
#define THREAD_RESTART 3 /* restart operation entirely */
typedef void *event_t; /* wait event */
typedef void (*continuation_t)(void); /* continuation */
/*
* Exported interface to sched_prim.c.
*/
extern void sched_init(void);
extern void assert_wait(
event_t event,
boolean_t interruptible);
extern void clear_wait(
thread_t thread,
int result,
boolean_t interrupt_only);
extern void thread_sleep(
event_t event,
simple_lock_t lock,
boolean_t interruptible);
extern void thread_wakeup(void); /* for function pointers */
extern void thread_wakeup_prim(
event_t event,
boolean_t one_thread,
int result);
extern boolean_t thread_invoke(
thread_t old_thread,
continuation_t continuation,
thread_t new_thread);
extern void thread_block(
continuation_t continuation);
extern void thread_run(
continuation_t continuation,
thread_t new_thread);
extern void thread_set_timeout(
int t);
extern void thread_setrun(
thread_t thread,
boolean_t may_preempt);
extern void thread_dispatch(
thread_t thread);
extern void thread_continue(
thread_t old_thread);
extern void thread_go(
thread_t thread);
extern void thread_will_wait(
thread_t thread);
extern void thread_will_wait_with_timeout(
thread_t thread,
mach_msg_timeout_t msecs);
extern boolean_t thread_handoff(
thread_t old_thread,
continuation_t continuation,
thread_t new_thread);
extern void recompute_priorities(void *param);
extern void update_priority(
thread_t thread);
extern void compute_my_priority(
thread_t thread);
extern void thread_bind(
thread_t thread,
processor_t processor);
extern void compute_priority(
thread_t thread,
boolean_t resched);
extern void thread_timeout_setup(
thread_t thread);
/*
* Routines defined as macros
*/
#define thread_wakeup(x) \
thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
#define thread_wakeup_with_result(x, z) \
thread_wakeup_prim((x), FALSE, (z))
#define thread_wakeup_one(x) \
thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
/*
* Machine-dependent code must define these functions.
*/
extern void thread_bootstrap_return(void) __attribute__((noreturn));
extern void thread_exception_return(void) __attribute__((noreturn));
extern void __attribute__((__noreturn__)) thread_syscall_return(kern_return_t);
extern thread_t switch_context(
thread_t old_thread,
continuation_t continuation,
thread_t new_thread);
extern void stack_handoff(
thread_t old_thread,
thread_t new_thread);
/*
* These functions are either defined in kern/thread.c
* via machine-dependent stack_attach and stack_detach functions,
* or are defined directly by machine-dependent code.
*/
extern void stack_alloc(
thread_t thread,
void (*resume)(thread_t));
extern boolean_t stack_alloc_try(
thread_t thread,
void (*resume)(thread_t));
extern void stack_free(
thread_t thread);
/*
* Convert a timeout in milliseconds (mach_msg_timeout_t)
* to a timeout in ticks (for use by set_timeout).
* This conversion rounds UP so that small timeouts
* at least wait for one tick instead of not waiting at all.
*/
#define convert_ipc_timeout_to_ticks(millis) \
(((millis) * hz + 999) / 1000)
void set_pri(thread_t th, int pri, boolean_t resched);
void do_thread_scan(void);
thread_t choose_pset_thread(processor_t myprocessor, processor_set_t pset);
#if DEBUG
void checkrq(run_queue_t rq, char *msg);
void thread_check(thread_t th, run_queue_t rq);
#endif /* DEBUG */
extern void idle_thread(void) __attribute__((noreturn));
extern void sched_thread(void);
#endif /* _KERN_SCHED_PRIM_H_ */
|