Title: School of Computing and Technology
1School of Computing and Technology
SYSTEMS SOFTWARE
2OPERATING SYSTEMS LECTURE 7 The DISPATCHER
(Low Level Scheduler) FUNCTION OF THE
DISPATCHER
- It allocates the CPU to processes in the
system - It is called whenever a process cannot
continue, i.e. after an external interrupt
(changes process status), after an extra code
(wait or signal) -gt makes process unable to
continue. after an error trap, which stops the
process while the error is dealt
with. - Dispatcher is entered after ALL
interrupts -gt thus uniform treatment of all
interrupts is assured.
3(No Transcript)
4(No Transcript)
5(No Transcript)
6(No Transcript)
7SUMMARY of dispatcher operations
1. is current process 1st run-able? If so
resume it if not 2. save current process
volatile environment, 3. retrieve 1st run-able
process volatile environment, 4. run this
process.
8MULTIPLE QUEUES
- Process doing I/O needs rapid service, but
have low processor computations. - Processor
bound jobs need longer (but would have to be less
frequent) processor attention. - Need at least
2 separate processor queues one for fast but
short processes, the other for slow and long
jobs.
9Example DEC10 has 3 queues - 20 millisec,
250 millisec, and 2 sec PRE-EMPTION time i.e.
Time a process is allowed to continue before
processor is switched to other processes of
higher priority. - Short pre-emption time queue
has higher priority than long P-E Q. - As
processor has little idea how long a process is
going to take before it is actually executed ..
-gt need dynamic re-allocation between
Qs. i. Place process in 20 ms Q. If it runs
for whole 20ms, relegate to 250ms
Q. ii. Continue running it in the 250ms Q. If
it is still running after 250ms, relegate it to
2s Q. 7-8
10(No Transcript)
11(No Transcript)
12IMPLEMENTATION OF WAIT SIGNAL Why are WAIT
SIGNAL part of systems nucleus? 1. Must be
available to all processes -- -gt must be
implemented at a low level. 2. WAIT may result
in a process being blocked --gt Dispatcher is
entered to re-allocate the processor. Wait opn
must have fast access to Dispatcher. 3. SIGNAL
is done by interrupt rtn to allow process in 2
above to continue. SIGNAL opn must be
accessable to interrupt rtns. Remember Wait(s
) when s gt 0 do decrement s. Signal(s)
increment s To develop the implementation we
consider 7-11
131. Blocking and Unblocking 2. Queuing and
De-queuing 3. Processor Allocation 4. Indivisi
bility 1. BLOCKING AND UNBLOCKING Blocking
happens when s0 (Wait). Unblocking frees a
process by a signal opn which makes
s1. Semaphore Queue when a process tries to
do a Wait but cannot (because s0), that process
is added to a queue associated with that
semaphore, and the process made
un-run-able. When a Signal is done on the
semaphore some process can be removed from the
Queue and made run-able. 7-12
14Wait(s) IF s gt0 THEN ss-1 ELSE add process
to semaphore Q and make un-run-able. Signal(s)
IF Q empty THEN ss1 ELSE remove some
process from Q and make run-able. In Signal, s
is incremented only if Q is empty otherwise the
freed process would immediately have to decrement
s again in completing its Wait opn. 2. QUEUING
AND DEQUEUING i. Where about in the Q do we put
an unsuccessful Wait process? ii. Which process
do we remove from the Q after Signal?.
15(No Transcript)
163. PROCESSOR ALLOCATION In general, Wait
makes a process Un-run-able Signal makes a
process Run-able ? Must enter Dispatcher at
Wait Signal to decide which process to run
next. ? Dispatcher resumes current process if
Wait was successful, or Signal on a semaphore
with empty Q. In this case return from Signal
or Wait can be directly to current process
(rather than via Dispatcher), ? this makes
Signal/Wait programs a little longer have to
detect this condition rather than enter
Dispatcher directly let it decide. 7-15
174. INDIVISIBILITY Wait Signal must be
indivisible, i.e. only one process can be allowed
to execute them at any one time. ? Must LOCK at
start UNLOCK at end of their algorithms. Disab
le Interrupt to lock, and re-enable to
unlock. Processor H/W Requirements A.
Single instruction TEST SET cannot be
interrupted. Other processes cannot access
location which is used as Flag (gate) Flag
tested by any process wanting to do
Signal/Wait Can only go ahead if Flag 1. If
Flag 1, instn TestSet sets it to 0, lets
the process go in. If Flag 0, process wanting
to do Signal/Wait loops back to TestSet instrn
. . until flag changes to 1 by the process
inside Signal/Wait unlocking on exit.
18(No Transcript)
19B. MEMORY SWAP Alternative to TestSet is to
have a SWAP instn (indivisible) Lock swap
zero and Flag, Flag location is now zero. Other
processes Swap Test if it is zero, ? cannot
go, loop back until A process finding Flag
1, goes ahead with Wait/Signal. A swap is done
on exit to unlock the process. Wait/signal
progs must be kept to a min size to reduce
waiting time by other processes locked in their
test loops. Lock/Unlock must not be used
instead of Wait/Signal Lock is not acceptable
for the long time periods associated with Wait.
20(No Transcript)
21(No Transcript)