Rev 99 | Rev 109 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 99 | Rev 107 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | */ |
54 | */ |
55 | 55 | ||
56 | spinlock_t nrdylock; |
56 | spinlock_t nrdylock; |
57 | volatile int nrdy; |
57 | volatile int nrdy; |
58 | 58 | ||
- | 59 | ||
- | 60 | /** Initialize context switching |
|
- | 61 | * |
|
- | 62 | * Initialize context switching and lazy FPU |
|
- | 63 | * context switching. |
|
- | 64 | * |
|
- | 65 | */ |
|
59 | void before_thread_runs(void) |
66 | void before_thread_runs(void) |
60 | { |
67 | { |
61 | before_thread_runs_arch(); |
68 | before_thread_runs_arch(); |
62 | fpu_context_restore(&(THREAD->saved_fpu_context)); |
69 | fpu_context_restore(&(THREAD->saved_fpu_context)); |
63 | } |
70 | } |
64 | 71 | ||
65 | 72 | ||
- | 73 | /** Initialize scheduler |
|
- | 74 | * |
|
- | 75 | * Initialize kernel scheduler. |
|
- | 76 | * |
|
- | 77 | */ |
|
66 | void scheduler_init(void) |
78 | void scheduler_init(void) |
67 | { |
79 | { |
68 | spinlock_initialize(&nrdylock); |
80 | spinlock_initialize(&nrdylock); |
69 | } |
81 | } |
70 | 82 | ||
- | 83 | ||
71 | /* cpu_priority_high()'d */ |
84 | /** Get thread to be scheduled |
- | 85 | * |
|
- | 86 | * Get the optimal thread to be scheduled |
|
- | 87 | * according thread accounting and scheduler |
|
- | 88 | * policy. |
|
- | 89 | * |
|
- | 90 | * @return Thread to be scheduled. |
|
- | 91 | * |
|
- | 92 | */ |
|
72 | struct thread *find_best_thread(void) |
93 | struct thread *find_best_thread(void) |
73 | { |
94 | { |
74 | thread_t *t; |
95 | thread_t *t; |
75 | runq_t *r; |
96 | runq_t *r; |
76 | int i, n; |
97 | int i, n; |
Line 153... | Line 174... | ||
153 | } |
174 | } |
154 | goto loop; |
175 | goto loop; |
155 | 176 | ||
156 | } |
177 | } |
157 | 178 | ||
- | 179 | ||
- | 180 | /** Prevent rq starvation |
|
158 | /* |
181 | * |
159 | * This function prevents low priority threads from starving in rq's. |
182 | * Prevent low priority threads from starving in rq's. |
- | 183 | * |
|
160 | * When it decides to relink rq's, it reconnects respective pointers |
184 | * When the function decides to relink rq's, it reconnects |
161 | * so that in result threads with 'pri' greater or equal 'start' are |
185 | * respective pointers so that in result threads with 'pri' |
162 | * moved to a higher-priority queue. |
186 | * greater or equal 'start' are moved to a higher-priority queue. |
- | 187 | * |
|
- | 188 | * @param start Threshold priority. |
|
- | 189 | * |
|
163 | */ |
190 | */ |
164 | void relink_rq(int start) |
191 | void relink_rq(int start) |
165 | { |
192 | { |
166 | link_t head; |
193 | link_t head; |
167 | runq_t *r; |
194 | runq_t *r; |
Line 190... | Line 217... | ||
190 | } |
217 | } |
191 | spinlock_unlock(&CPU->lock); |
218 | spinlock_unlock(&CPU->lock); |
192 | 219 | ||
193 | } |
220 | } |
194 | 221 | ||
195 | /* |
222 | |
196 | * The scheduler. |
223 | /** The scheduler |
- | 224 | * |
|
- | 225 | * The thread scheduling procedure. |
|
- | 226 | * |
|
197 | */ |
227 | */ |
198 | void scheduler(void) |
228 | void scheduler(void) |
199 | { |
229 | { |
200 | volatile pri_t pri; |
230 | volatile pri_t pri; |
201 | 231 | ||
Line 235... | Line 265... | ||
235 | context_set(&CPU->saved_context, FADDR(scheduler_separated_stack), CPU->stack, CPU_STACK_SIZE); |
265 | context_set(&CPU->saved_context, FADDR(scheduler_separated_stack), CPU->stack, CPU_STACK_SIZE); |
236 | context_restore(&CPU->saved_context); |
266 | context_restore(&CPU->saved_context); |
237 | /* not reached */ |
267 | /* not reached */ |
238 | } |
268 | } |
239 | 269 | ||
- | 270 | ||
- | 271 | /** Scheduler stack switch wrapper |
|
- | 272 | * |
|
- | 273 | * Second part of the scheduler() function |
|
- | 274 | * using new stack. Handling the actual context |
|
- | 275 | * switch to a new thread. |
|
- | 276 | * |
|
- | 277 | */ |
|
240 | void scheduler_separated_stack(void) |
278 | void scheduler_separated_stack(void) |
241 | { |
279 | { |
242 | int priority; |
280 | int priority; |
243 | 281 | ||
244 | if (THREAD) { |
282 | if (THREAD) { |
Line 363... | Line 401... | ||
363 | 401 | ||
364 | context_restore(&THREAD->saved_context); |
402 | context_restore(&THREAD->saved_context); |
365 | /* not reached */ |
403 | /* not reached */ |
366 | } |
404 | } |
367 | 405 | ||
- | 406 | ||
368 | #ifdef __SMP__ |
407 | #ifdef __SMP__ |
- | 408 | /** Load balancing thread |
|
369 | /* |
409 | * |
370 | * This is the load balancing thread. |
410 | * SMP load balancing thread, supervising thread supplies |
371 | * It supervises thread supplies for the CPU it's wired to. |
411 | * for the CPU it's wired to. |
- | 412 | * |
|
- | 413 | * @param arg Generic thread argument (unused). |
|
- | 414 | * |
|
372 | */ |
415 | */ |
373 | void kcpulb(void *arg) |
416 | void kcpulb(void *arg) |
374 | { |
417 | { |
375 | thread_t *t; |
418 | thread_t *t; |
376 | int count, i, j, k = 0; |
419 | int count, i, j, k = 0; |