<#1705#> [This is still pretty weak, but I think that I have removed most
or all of the inaccuracies that were in previous versions. Jim Wisner
appears to have dropped from the face of the Net, so I have not been
able to get his help at making this chapter more meaningful. If
anyone has a copy of the paper he wrote on the scheduler, please get
in touch with me, as he promised me a copy, and I'd at least like to
see what he had to say about the scheduler.]<#1705#>
<#1706#> [I'm not going to spend any further time on this until the new
scheduler is added to Linux. The current one doesn't handle lots
of tasks at once very well, and some day a new one will be put in.]<#1706#>
The scheduler is a function, <#1707#> schedule()<#1707#>, which is called at
various times to determine whether or not to switch tasks, and if so,
which task to switch to. The scheduler works in concert with the
function <#1708#> do_timer()<#1708#>, which is called 100 times per second (on
), on each system timer interrupt, and with the system call
handler part <#1709#> ret_from_sys_call()<#1709#> which is called on the
return from system calls.
When a system call completes, or when a ``slow'' interrupt completes,
<#1710#> ret_from_sys_call()<#1710#> is called. It does a bit of work, but
all we care about are two lines:
#screen1711#
These lines check the <#1713#> need_resched<#1713#> flag, and if it is set,
<#1714#> schedule()<#1714#> is called, choosing a new process, and then after
<#1715#> schedule()<#1715#> has chosen the new process, a little more magic in
<#1716#> ret_from_sys_call()<#1716#> restores the environment for the chosen
process (which may well be, and usually is, the process which is
already running), and returns to user space. Returning to user space
causes the new process which has been selected to run to be returned
to.
In <#1717#> sched_init()<#1717#> in kernel/sched.c, <#1718#> request_irq()<#1718#> is used
to get the timer interrupt. <#1719#> request_irq()<#1719#> sets up housekeeping
before and after interrupts are serviced, as seen in <#1720#>
;SPM_lt;asm/irq.h;SPM_gt;<#1720#>. However, interrupts that are serviced often and that must be
serviced quickly, such as serial interrupts, do <#1721#> not<#1721#> call <#1722#>
ret_from_sys_call()<#1722#> when done and do as little as possible, to
keep the overhead down. In particular, they only save the registers
that C would clobber, and assume that if the handler is going to use
any others, the handler will deal with that. These ``fast'' interrupt
handlers must be installed with the <#1723#> irqaction()<#1723#> function
described in section~#secdevfuncs#1724>.
The \ scheduler is significantly different from the schedulers
in other unices, especially in its treatment of `nice level'
priorities. Instead of scheduling processes with higher priority
first, \ does round-robin scheduling, but lets higher priority
processes run both sooner and longer. The standard \ scheduler
instead uses queues of processes. Most implementations use two
priority queues; a standard queue and a ``real time'' queue.
Essentially, all processes on the ``real time'' queue get executed
before processes on the standard queue, if they are not blocked, and
within each queue, higher nice-level processes run before lower ones.
The \ scheduler gives much better interactive performance at the
expense of some ``throughput.''