









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Goal
What characterizes a “fair internal policy?” Which process is given
the CPU next? This is the province of schedulers.
Schedulers
Three kinds:
for processing
example: in a batch system, often more jobs are submitted than can
be done at once, so some are spooled out to a mass storage device;
the long-term scheduler selects the next one to be loaded into
memory. So it controls the degree of multiprogramming, i.e., the
number of processes in memory.
ready queue) goes next
the system temporarily; that is, too many jobs may be competing for
memory. The removed process will be restarted where it left off later;
called swapping. This scheduler decides who gets swapped out and in.
The long term scheduler is invoked relatively infrequently, but the
short term one is invoked often — whenever any process returns control
to the operating system. Hence the short-term scheduler must be very
fast. (Context switching also must be very fast; typically, 10μs to 100μs.
Many machines have special-purpose instructions, like the VAX LDCTX, for
just this reason.)
The system should try to balance CPU-bound and I/O-bound jobs.
Characterizati on of Scheduling Algorithms
decision mode
This is non-preemptive if a process runs until it blocks or completes; at
no time during its run will the operating system replace it with another
job. It is preemptive if the operating system can interrupt the currently
running process to start another one.
priority function
This is a mathematical function which assigns a priority to the process;
the process with the highest (numerical) priority goes next. The function
usually involves the service time so far a, the real time spent in the
system so far r, and the total required service time t.
arbitration rule
If two processes have the same priority, this rule states how one of
them is selected to run.
The Scheduling Algorithms
First Come, First Served (FCFS)
decision mode: non-preemptive
priority function: p(a, r, t) = r
arbitration rule: random
service
time
arrival
time
start finish T W R
mean 38.2 26 5.
A potential problem is when a short job follows a long one:
service
time
arrival
time
start finish T W R
Gantt Chart:
Basically, long processes love FCFS, but short ones seem to be much
slower.
change over a period of time; that is, a process might be CPU-bound
for a time, then I/O-bound, then CPU-bound, etc.
average of previous CPU-bursts of the process. Let tn be the length of
the n-th CPU burst, and tn+1 the expected length of the next burst;
then
tn+1 = atn + (1-a)tn
where a is a parameter indicating how much to count past history
(usually chosen around
1 2 )
a = 1 the estimate is simply the length of the last CPU burst
a = 0 the estimate is the initial estimate holds
burst
length
actual
estimated
t 6 4 6 4 13 13 13 13 i t i
Comparing exponential estimation with actual values: = a1/
SPN is better than FCFS for short jobs, but long jobs may have to wait for
some time for service.
The long-term scheduler can simply use the job's time limit as
specified by the user; this motivates users to be realistic in their limits,
as:
Shortest Remaining Time (SRT), Preemptive Shortest Process Next (PSPN)
This is like SPN, but preemptive.
decision mode: preemptive (at arrival)
priority function: p(a, r, t) = a–t
arbitration rule: chronological or random
service
time
arrival
time
start finish T W R
mean 24 11.8 1.
Miscellaneous:
current job.
Round Robin (RR) with Quantum q
This is especially designed for time sharing; the quantum is typically
1
60
≤ q ≤ 1 seconds.
decision mode: preemptive (at quantum)
priority function: p(a, r, t) = c
arbitration rule: cyclic
In this example the quantum is 5:
service
time
arrival
time
start finish T W R
mean 34.8 22.6 3.
Why? Here is what things look like:
time 0 5 10 13 18 23 28 33 35 40 45 47 52 57 61
proc. A B C D E A B D E B E B B B
rem 5 24 0 2 7 0 19 0 2 14 0 9 4 0
(here, “proc” is the process starting at the indicated time, and “rem” the
remaining time after the quantum is complete.)
processor that is slower in proportion to the number of competing
processes; this is called processor sharing. This scheme is used in
hardware in CDC6600 to implement 10 peripheral processors with one
set of hardware ( i.e., processor) and 10 sets of registers; the
processor does 1 instruction for one set of registers, then goes on to
the next set. (This turns out to be not much slower than a real
processor.)
Variants:
example: after every process switch, the quantum becomes q/n,
where n is the number of processes in the ready list
minimizing process switches.
processes a shot at the CPU over a fixed period of time, at the
price of more process switching
fairly soon, and hence may finish sooner.
new process arrives
This reduces process switching in proportion to the number of
processes arriving.
External Pri ority Methods
These adjust priority based on some external factors, and are quite
common when users pay based upon their computer use.
Examples:
based on the external priority of process ( i.e., the more you pay, the
bigger the quantum.)
function” (based on how long the process had to wait, how many
times it has been preempted, how much the user is paying, and/or the
amount of time and resources used). The process with the greatest
suffering gets the next quantum.
takes into account the difference between the guaranteed response
ratio and the actual response ratio at the moment.
and by what real time it must be finished. The algorithm tries not to
run jobs that cannot meet their deadline.
of processes, usually by splitting user processes into groups; within
each group, use a standard schedule, but allocate the CPU
proportionately to each group
example: All processes are infinite loops; 1 process in group 1, 2 in
group 2, 3 in group 3, and 4 in group 4
regular scheduler: each process gets 10%
fair share scheduler: each group gets 25%; processes in sgroup share
equally
example: This uses UNIX internal, not external, priorities. Here, 3
processes: process A in one group; processes B and C in another
group. The internal priority function is:
priority =
recent CPU usage
2
group CPU usage
2
(with the threshold being 60 for user processes). A decay function
decrements the current CPU usage of processes not run; this has the
effect of raising their priority. The function is:
decay of CPU usage =
CPU usage
2
example of the UNIX Fair Share Scheduler: Here, the quantum is 1
second. Note that the higher the priority, the lower the integer
representing that priority.
A runs for 1 second
decay applied to CPU and group CPU usage; A's new priority is 60 +
30
2
= 90. As B and C now have higher priority, one of them
(say, B) goes next.
B runs for 1 second
decay applied to CPU and group CPU usage; A's new priority is 60 +
15
2
= 74, B's new priority is 60 +
= 90, and C's
new priority is 60 +
= 75; A has the highest priority, so it
runs next.
A runs for 1 second.
decay applied to CPU and group CPU usage; A's new priority is 60 +
37
2
= 96, B's new priority is 60 +
= 74, and C's
new priority is 60 +
= 67; C has the highest priority, so it
runs next.
C runs for 1 second.
decay applied to CPU and group CPU usage; A's new priority is 60 +
18
2
= 96, B's new priority is 60 +
= 81, and C's
new priority is 60 +
= 93; A has the highest priority, so
it runs next.
Hence the order of running is A B A C A B A C …, with A getting 50%
of the CPU and B and C together getting 50%.
example: VAX/VMS scheduler
This scheduler has 32 priority levels: levels 31 to 16 are for real-time
processes, and levels 15 to 0 for regular processes. Real-time processes
have fixed priority throughout their lifetime; but the priority of regular
processes is dynamic:
minimum priority
each of which has an associated increment, i.e., terminal read
increment > terminal write increment > disk I/O
When awakened due to a system event, the appropriate
increment is added to the current priority value; on preemption due
to quantum expiration, the current priority drops by 1.