Re: Preemptive scheduling under Linux?

Rik van Riel (H.H.vanRiel@phys.uu.nl)
Wed, 17 Jun 1998 21:34:15 +0200 (CEST)


On Wed, 17 Jun 1998, Marc Bechler wrote:

> This morning I was really worried about the scheduling: I thought the
> Linux-scheduling is preemptive; but I have not found a periodic timer that
> preempts the tasks (after 20 ticks) ... or does a task voluntarily preempt
> hisself???

On all architectures, the clock chip generates an
interrupt 100 times a second (except Alpha, where
the frequency is 1024Hz). On an interrupt, the
system enters the kernel.

The kernel sees that it's an interrupt, and updates
the statistics.
The function you're looking for is update_process_times()
in kernel/sched.c (line 1035 for v2.1.101). There you'll
see:
p->counter -= ticks;
if (p->counter < 0) {
p->counter = 0;
need_resched = 1;
}

The actual function that calls schedule() on an interrupt,
is located in arch/<arch>/kernel/entry.S. For x86 CPUs the
fragment is located on line 167 and goes as follows:

ret_with_reschedule:
cmp $0,SYMBOL_NAME(need_resched)
jne reschedule
...

So, if need_resched != 0, the following is executed:

reschedule:
pushl $ret_from_sys_call
jmp SYMBOL_NAME(schedule) # test

And the function schedule() in kernel/sched.c is called...

Rik.

PS. Anyone know a good book on assembler? I hardly know
assembler, but after just parsing the structure and the
mnemonics for their english 'translations', I already
begin to enjoy it :-)
+-------------------------------------------------------------------+
| Linux memory management tour guide. H.H.vanRiel@phys.uu.nl |
| Scouting Vries cubscout leader. http://www.phys.uu.nl/~riel/ |
+-------------------------------------------------------------------+

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu