CS211 Lec 13
CS211 Lec 13
Lecture # 13
1
Agenda for Today
Round-Robin scheduling
Multi-level queues scheduling
Multi-level feedback queues scheduling
UNIX System V scheduling
Algorithm evaluation
2
Round Robin (RR)
The round-robin (RR) scheduling algorithm is similar to FCFS
scheduling, but preemption is added to enable the system to switch
between processes.
A small unit of time, called a time quantum or time slice, is defined. A
time quantum is generally from 10 to 100 milliseconds in length.
The ready queue is treated as a circular queue.
The CPU scheduler goes around the ready queue, allocating the CPU
to each process for a time interval of up to 1 time quantum.
In the RR scheduling algorithm, no process is allocated the CPU for
more than 1 time quantum in a row. If a process’s CPU burst exceeds 1
time quantum, that process is preempted and is put back in the ready
queue.
The RR scheduling algorithm is thus preemptive.
3
Round Robin (RR)
If there are n processes in the ready queue and the time
quantum is q, then each process gets 1/n of the CPU time in
chunks of at most q time units.
Each process must wait no longer than (n − 1) × q time units
until its next time quantum.
For example, with five processes and a time quantum of 20
milliseconds, each process will get up to 20 milliseconds every
100 milliseconds.
The performance of the RR algorithm depends heavily on the
size of the time quantum.
At one extreme, if the time quantum is extremely large, the RR
policy is the same as the FCFS policy. In contrast, if the time
quantum is extremely small (say, 1 millisecond), the RR
approach can result in a large number of context switches.
4
Round Robin (RR)
Performance
q large FCFS
q small q must be large with
respect to context
switch, otherwise
overhead is too high.
5
Round Robin Example
Process Burst Time
P1 53 — 33 — 13
P2 17
P3 68 — 48 — 28 — 8
P4 24 — 4
The Gantt chart with quantum 20 is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
6
Round Robin Example
Process Turnaround Time Waiting Time
P1 134 134 – 53 = 81
P2 37 37 – 17 = 20
P3 162 162 – 68 = 94
P4 121 121 – 24 = 97
Average waiting time = 73
Average waiting time for SJF = 38
Typically, higher average turnaround
than SJF, but better response.
7
Quantum vs Context Switch
8
Turnaround Time vs Quantum
Turnaround time also depends on the size of
the time quantum.
As in Figure 5.6, the average turnaround time
of a set of processes does not necessarily
improve as the time-quantum size increases.
In general, the average turnaround time can
be improved if most processes finish their
next CPU burst in a single time quantum.
For example, given three processes of 10
time units each and a quantum of 1 time
unit, the average turnaround time is 29. If
the time quantum is 10, however, the
average turnaround time drops to 20.
If context-switch time is added in, the
average turnaround time increases even
more for a smaller time quantum, since more
context switches are required.
9
Priority Scheduling
A priority number (integer) is
associated with each process
The CPU is allocated to the process
with the highest priority (smallest
integer highest priority).
Preemptive
Non-preemptive
10
Priority Scheduling
11
Priority Scheduling
SJF is a priority scheduling where priority is the predicted next
CPU burst time.
A major problem with priority scheduling algorithms is
indefinite blocking, or starvation. A process that is ready to run
but waiting for the CPU can be considered blocked. A priority
scheduling algorithm can leave some low priority processes
waiting indefinitely. In a heavily loaded computer system, a
steady stream of higher-priority processes can prevent a low-
priority process from ever getting the CPU.
A solution to the problem of indefinite blockage of low-priority
processes is aging. Aging involves gradually increasing the
priority of processes that wait in the system for a long time.
12
Multilevel Queue Scheduling
With both priority and round-robin scheduling, all
processes may be placed in a single queue, and the
scheduler then selects the process with the highest
priority to run.
Depending on how the queues are managed, an O(n)
search may be necessary to determine the highest-
priority process.
In practice, it is often easier to have separate queues
for each distinct priority, and priority scheduling
simply schedules the process in the highest-priority
queue. 13
Multilevel Queues
This approach—known as multilevel queue—
also works well when priority scheduling is
combined with round-robin: if there are
multiple processes in the highest-priority
queue, they are executed in round-robin order.
In the most generalized form of this approach,
a priority is assigned statically to each process,
and a process remains in the same queue for
the duration of its runtime.
14
Multilevel Queues
A multilevel queue scheduling algorithm can also be
used to partition processes into several separate queues
based on the process type
For example, a common division is made between
foreground (interactive) processes and background
(batch) processes.
These two types of processes have different response-
time requirements and so may have different scheduling
needs.
In addition, foreground processes may have priority over
background processes.
Separate queues might be used for foreground and
background processes, and each queue might have its
own scheduling algorithm. 15
Multilevel Queues
16
Multilevel Feedback Queues
A process can move between the various
queues; aging can be implemented this way.
Multilevel-feedback-queue scheduler defined by
the following parameters:
Number of queues
Scheduling algorithms for each queue
17
Multilevel Feedback Queues
19
UNIX System V Scheduling Algorithm
Multilevel feedback priority queues with
round robin within each queue
Quantum = 1 second
Priorities are divided into two
groups/bands:
Kernel Group
User Group
20
UNIX System V Scheduling Algorithm
21
UNIX System V Scheduling Algorithm
22
UNIX System V Scheduling Algorithm
24
UNIX System V Scheduling Algorithm
Every second, the priority number of all those processes
that are in the main memory and ready to run is updated
by using the following formula:
25
Algorithm Evaluation
Analytic Evaluation: The algorithm and some system
workload are used to produce a formula or number which
gives the performance of the algorithm for that workload.
Deterministic modeling: it is one type of analytic
evaluation. This method takes a particular predetermined
workload and defines the performance of each algorithm
for that workload.
Queuing models
Simulation
Implementation
26
Deterministic Modeling
Predetermined workload and
performance of each algorithm for that
workload. Use of Gantt charts.
Simple and fast
Exact numbers for comparison
Requires exact input
Performance figures may not be true in
general
27
Deterministic Modeling
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
Gantt chart
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
32
Simulation
Programming model for the
computer system
Workload generated by
assuming some distribution and
a random number generator, or
by collecting data from the
actual system.
33
Simulation
Characteristics
Expensive: hours of
programming and execution
time
May be erroneous because of
the assumptions about
distributions
34
Implementation
Best
Most expensive
Good option due to Open Source
kernels such as Linux
35
End of
Lecture # 13
36