Najważniejsze zmienne stosowane przez schedule():
Algorytm:
if (in_interrupt()) {
printk("Scheduling in interrupt\n");
BUG();
return;;
}
if (prev->policy == SCHED_RR) {
if (!prev->counter) {
prev->counter = NICE_TO_TICKS(prev->nice)
move_last_runqueue(prev);
}
}
switch (prev->state) {
case TASK_INTERRUPTIBLE:
if (signal_pending(prev)) {
prev->state = TASK_RUNNING;
break;
}
default:
del_from_runqueue(prev);
case TASK_RUNNING:;
}
prev->need_resched = 0;
next = idle_task(this_cpu); c = -1000;
if (prev->state == TASK_RUNNING) {
c = goodness(prev, this_cpu, prev->active_mm);
next = prev;
}
list_for_each(tmp, &runqueue_head) {
p = list_entry(tmp, struct task_struct, run_list);
int weight = goodness(p, this_cpu, prev->active_mm);
if (weight > c)
c = weight, next = p;
}
if (!c)
{
struct task_struct *p;
for_each_task(p)
p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice);
<powrot do punktu 4>
}
Makro NICE_TO_TICKS jest zdefiniowane następująco:
#define TICK_SCALE(x) ((x) >> 2) /* dla procesorow i386 (gdy HZ = 100)*/ #define NICE_TO_TICKS(nice) (TICK_SCALE(20-(nice))+1)A więc może przyjąź wartości od 1 do 11.
if (prev == next) {
prev->policy &= ~SCHED_YIELD;
return;
}
To zagadnienie jest szerzej omówione w osobnym referacie.