150 |
int policy_index; |
int policy_index; |
151 |
}; |
}; |
152 |
|
|
153 |
|
|
154 |
|
/* Migrating threads. |
155 |
|
|
156 |
/* ??? comment here. */ |
To support migrating threads we split the concept of (static) threads |
157 |
|
into two parts; threads and activations. |
158 |
|
|
159 |
|
The thread holds scheduling information and a stack of activations. |
160 |
|
On top of the stack is the current executing activation. |
161 |
|
|
162 |
|
An activation is the executing part of a thread. An activation can |
163 |
|
belong to any thread in the system, but it never leaves the task that |
164 |
|
it is created within. |
165 |
|
|
166 |
|
Since a thread is no longer bound to a task, we can migrate threads |
167 |
|
to other tasks. This is done by pushing an activation on the threads |
168 |
|
activation stack. */ |
169 |
|
|
170 |
|
struct activation |
171 |
|
{ |
172 |
|
/* Pointer to next activation in pool or on stack. */ |
173 |
|
|
174 |
|
struct activation *next; |
175 |
|
|
176 |
|
/* Task that this activation belongs to. Activation can not migrate |
177 |
|
to another task. */ |
178 |
|
|
179 |
|
struct task *task; |
180 |
|
|
181 |
|
/* Thread that this activation currently belongs to. */ |
182 |
|
|
183 |
|
struct thread *thread; |
184 |
|
|
185 |
|
/* Control block for the activation. Holds both user- and kernel-mode |
186 |
|
states. */ |
187 |
|
|
188 |
|
struct pcb pcb; |
189 |
|
}; |
190 |
|
|
191 |
|
|
192 |
|
/* Thread. |
193 |
|
|
194 |
|
Holds scheduling, timer and IPC space for thread. It also contains |
195 |
|
the activation stack. */ |
196 |
|
|
197 |
struct thread |
struct thread |
198 |
{ |
{ |
208 |
int wait_event; |
int wait_event; |
209 |
int wait_result; |
int wait_result; |
210 |
|
|
211 |
struct task *task; /* Task that this thread belongs to. */ |
/* Task that this thread belongs to (i.e., was created in). */ |
212 |
int ref_cnt; /* Reference counter. */ |
|
213 |
|
struct task *task; |
214 |
|
|
215 |
|
/* Reference counter. */ |
216 |
|
|
217 |
|
int ref_cnt; |
218 |
|
|
219 |
/* Target dependent members: */ |
/* Target dependent members: */ |
220 |
struct pcb pcb; /* Thread control block. */ |
struct pcb pcb; /* Thread control block. */ |
221 |
vm_offset_t kernel_stack; /* Kernel stack. */ |
|
222 |
|
/* Kernel stack for thread. We only maintain one kernel stack |
223 |
|
for all activations. */ |
224 |
|
|
225 |
|
vm_offset_t kernel_stack; |
226 |
|
|
227 |
|
/* Swap in function, called when thread is given a new stack. */ |
228 |
|
|
229 |
void (*swap_fn) (void); |
void (*swap_fn) (void); |
230 |
|
|
231 |
/* Timer informations: */ |
/* Timer statistics; execution time in user and kernel mode |
232 |
struct timer timer_user; /* User timer. */ |
respectively. */ |
233 |
struct timer timer_system; /* System timer. */ |
|
234 |
|
struct timer timer_user; |
235 |
|
struct timer timer_system; |
236 |
|
|
237 |
/* IPC information: */ |
/* IPC information: */ |
238 |
struct ipc_kmsg *ipc_kmsg; /* kernel message. */ |
struct ipc_kmsg *ipc_kmsg; /* kernel message. */ |
240 |
ipc_return_t ipc_result; /* result. */ |
ipc_return_t ipc_result; /* result. */ |
241 |
|
|
242 |
/* Scheduling information: */ |
/* Scheduling information: */ |
|
#if 0 |
|
|
int sched_priority; /* Priority. */ |
|
|
int sched_policy; /* Scheduling policy. */ |
|
|
#endif |
|
243 |
int sched_credits; /* Credits. */ |
int sched_credits; /* Credits. */ |
244 |
|
|
245 |
int sched_state; /* State of thread. */ |
int sched_state; /* State of thread. */ |
248 |
#define THREAD_STATE_IDLE 0x04 /* Thread is idle thread. */ |
#define THREAD_STATE_IDLE 0x04 /* Thread is idle thread. */ |
249 |
#define THREAD_STATE_SUSPEND 0x08 /* Thread is suspended. */ |
#define THREAD_STATE_SUSPEND 0x08 /* Thread is suspended. */ |
250 |
#define THREAD_STATE_SWAPPED 0x10 /* Thread is swapped. */ |
#define THREAD_STATE_SWAPPED 0x10 /* Thread is swapped. */ |
251 |
|
#define THREAD_STATE_INTR 0x20 /* Thread is interrupt thread. */ |
252 |
|
|
253 |
#define THREAD_SCHED_STATE \ |
#define THREAD_SCHED_STATE (THREAD_STATE_RUN | \ |
254 |
(THREAD_STATE_RUN | THREAD_STATE_WAIT | THREAD_STATE_SUSPEND) |
THREAD_STATE_WAIT | \ |
255 |
|
THREAD_STATE_SUSPEND | \ |
256 |
|
THREAD_STATE_INTR) |
257 |
|
|
258 |
int runq_p; |
int runq_p; |
259 |
|
|
261 |
|
|
262 |
int suspend_cnt; /* Suspend counter. */ |
int suspend_cnt; /* Suspend counter. */ |
263 |
|
|
264 |
/* Processor that this thread is bound to run on. */ |
/* Processor that this thread is bound to run on (if any), |
265 |
|
and processor that this thread last ran on. */ |
266 |
|
|
267 |
struct processor *bound_processor; |
struct processor *bound_processor; |
|
|
|
|
/* Last processor this thread run on. */ |
|
|
|
|
268 |
struct processor *last_processor; |
struct processor *last_processor; |
269 |
|
|
270 |
/* Scheduling policy, priority and pre-multiplied priority. */ |
/* Scheduling policy, priority and pre-multiplied priority. */ |
301 |
|
|
302 |
struct thread_lock *blocked_lock; |
struct thread_lock *blocked_lock; |
303 |
|
|
|
/* Lended priority (from other higher-priority thread). |
|
|
Used with BLOCKED_LOCK to prevent priority inversion. */ |
|
|
|
|
|
int lended_priority; |
|
|
|
|
304 |
/* True if we have inherited priority from another thread. */ |
/* True if we have inherited priority from another thread. */ |
305 |
|
|
306 |
bool inherited_priority_p: 1; |
bool inherited_priority_p: 1; |
307 |
|
|
308 |
|
/* Activation stack. ACT_STACK_UPPER holds pointer to current |
309 |
|
activation. ACT_STACK_LOWER is the initial activation. */ |
310 |
|
|
311 |
|
struct activation *act_stack_upper; |
312 |
|
struct activation *act_stack_lower; |
313 |
}; |
}; |
314 |
|
|
315 |
/* Convenience macros. */ |
/* Convenience macros. */ |
434 |
|
|
435 |
extern void thread_bootstrap_return (void); |
extern void thread_bootstrap_return (void); |
436 |
|
|
437 |
|
/* Select next thread to be run ??? on PROCESSOR. This function should be |
438 |
|
called with interrupts disabled. */ |
439 |
|
|
440 |
|
extern struct thread *thread_select (struct processor *processor); |
441 |
|
|
442 |
#endif /* thread.h */ |
#endif /* thread.h */ |