LJ Archive

Listing 1. Linux Schedule Function

/* Code from sched.c, heavily edited for clarity
   and simplicity */
static inline int goodness(struct task_struct * p,
struct task_struct * prev, int this_cpu)
 {
 int weight;
 weight = p->counter;
 /* Code to adjust weight */
 return weight;
 }
 asmlinkage void schedule(void)
 {
 prev = current;
 c = -1000;
 next = idle_task;
 /* The Search Loop */
 while (p != &init_task) {
 int weight = goodness(p, prev, this_cpu);
 if (weight > c)
 c = weight, next = p;
 p = p->next_run;
 }
 /* The Recalc Loop */
 /* if all runnable processes have "counter == 0",
    re-calculate counters */
 if (!c) {
 for_each_task(p)
 p->counter = (p->counter >> 1) + p->priority;
 }
 }
LJ Archive