0% found this document useful (0 votes)
23 views36 pages

CS211 Lec 13

The document discusses scheduling algorithms including round robin, priority scheduling, multilevel queue scheduling, multilevel feedback queues scheduling, and UNIX System V scheduling. It provides details on how each algorithm works and considerations for evaluating scheduling algorithms.

Uploaded by

Muhammad Rafay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views36 pages

CS211 Lec 13

The document discusses scheduling algorithms including round robin, priority scheduling, multilevel queue scheduling, multilevel feedback queues scheduling, and UNIX System V scheduling. It provides details on how each algorithm works and considerations for evaluating scheduling algorithms.

Uploaded by

Muhammad Rafay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Operating Systems

Course Code: CS211


Instructor: Dr. Sarah Iqbal

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

0 20 37 57 77 97 117 121 134 154 162

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

 Method used to determine when to


upgrade a process
 Method used to determine when to
demote a process
 Method used to determine which
queue a process will enter when
that process needs service
18
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

Priorities in the Kernel Group are


assigned in a manner to minimize
bottlenecks: processes waiting in a lower-
level routine get higher priorities than
those waiting at relatively higher-level
routines.

21
UNIX System V Scheduling Algorithm

In decreasing order of priority, the bands


are:
Swapper
Block I/O device control processes
File manipulation
Character I/O device control processes
User processes

22
UNIX System V Scheduling Algorithm

Priorities of processes in the Kernel


Group remain fixed.
Priorities of processes in the User Group
are recalculated every second.
Inside the User Group, the CPU-bound
processes are penalized at the expense
of I/O-bound processes
23
UNIX System V Scheduling Algorithm

The CPU usage of each process is updated every


clock tick by the clock ISR.
Every second, a decay function is applied to the
CPU usage of each process in the ready queue:
Decay (CPU Usage)=(CPU Usage)/2
Priority number of each process is recomputed
every second

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:

Priority# = (Recent CPU Usage)/2 + Threshold Priority+ nice

 Threshold priority and nice values are always positive to


prevent a user from migrating out of its assigned group

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

 Average waiting time = (9 + 1 + 0 +2)/4 = 3


28
Queuing Modeling
Computer system viewed as a network
of queues and servers: ready queue, I/O
queue, event queues, CPUs, I/O device
controllers, etc.
Input: Arrival and service rates
Output: CPU utilization, average
queue length, average
waiting time, …
29
Queuing Modeling
Little’s Formula:
n = λ* W
where
n = average queue length
λ = average arrival rate
W = average waiting time in a
queue
This equation, known as Little’s formula, is particularly useful because it is
valid for any scheduling algorithm and arrival distribution.
30
Queuing Modeling
Let the average job arrival rate be 0.5
Algorithm Average Wait Average Queue
Time Length(n)
W=tw
FCFS 4.6 2.3
SJF 3.6 1.8
SRTF 3.2 1.6
RR (q=1) 7.0 3.5
RR (q=4) 6.0 3.0
31
Queuing Modeling
Complicated mathematics
Distributions (Poisson, uniform,
exponential, etc) for the arrival and
departure rates can be difficult to work
with
Assumptions may not be accurate
Approximation of the real system

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

You might also like