Processes – an abstract view

Process Scheduling
Schedulers and Scheduling Methods
Processes and CPU utilization



Processes often need to be suspended
Reason for suspension may include
Lack of resources
Waiting for signals I/O operations
Kernel operations
Page Fault (later more)
Whatever the reason, the OS must suspend the
process and allow another to utilize the CPU
The framework

Two strategies:
•
•

Preemptive Scheduling
Non-Preemptive Scheduling
Scheduling decisions must be made in any of the
following situation:




Process switches from running to waiting state;
Process switches from running to ready state
Process switches from waiting to ready state
When a process terminates
CPU Burst Time



Time, Tb that a process could run without needing
to be put into a waiting queue.
We can think of program as a series of CPUBursts and I/O Bursts, interspersed.
Alternatively, CPU Burst is the time that a
process could stay in the CPU before the next
interrupt IF we were running a non-preemptive
scheduler
Priority Scheduling


All schedulers use some sort of
process priority level to decide
which process will execute next.
Priority P of process pi can be
viewed as a function P = prio(pi),
where the function prio() may by as
simple as retrieving the process’
user assigned priority or as complex
as necessary to take runtime
conditions of the system into
consideration.




In general, priority can be
•
•
static  no change during the runtime
of the process;
dynamic  it may change do to the
dynamic nature of the system of
processes in the system;

In case of dynamic priority, the
scheduler may re-calculate the
priority of each process
whenever it executes.
Regardless of how the priorities
are computed, they divide the
set of processes into multiple
priority levels (or classes)
These levels are manifested in a
data structure called Ready List
(RL).
We may think of a priority list
(queues), i.e., a list of list such
that the priority of processes
on list RL[i] have precedence of
processes on list RL[j] if j < i.
Priority Functions
The decision which process will be
allowed to execute is generally
based on some measure of priority p.
External priorities may be assigned to
processes to indicate an initial
difference among processes.
System measures that may determine
the priority level of a process
include:
A function that combines external
(statically assigned) priorities with
dynamic priority measures will
determine the outcome of a scheduling
decision
•
•
•
•
•
•
•
attained service time
real-time in the system
total service time
deadline
periodicity
external priority
memory requirements
Many of these parameters are dynamic
in nature and will cause the priority
of a process to change over time.
Arbitration becomes necessary when
two processes with equal priority are to
be scheduled. This is the function of
the arbitration rule!
In a quantum-based system, the
arbitration rule may be “round-robin”.
In most other systems (e.g.,FIFO),
chronological ordering is used.
Scheduling Methods
We can categorize the various
scheduling methods by:
•
•
•
•
•
•
•
PF  Priority Function
DM Decision Mode
AR  Arbitration Rule
FIFO
SJF
SRT
RR
First In / First Out (FIFO):
Processes that arrive earlier have
higher priority.
PF  P = r, where r is the amount
of real-time that the process
has spent in the system.
DM  Non-Preemtive
AR  random choice among
processes arriving at exactly
the same time
… methods cont’d
Shortest Job First (SJF):
Example:
Processes with lower total service
time have priority!
Consider the following set of
processes
PF  P = -t, where t is the total
service time
Process
P1
P2
P3
P4
DM  Non-Preemptive
AR  either chronological or random
among processes with same
service time.
SJF is provably optimal, in that it
results in the minimum average
waiting time for a given set of
processes!!
Burst Time
6
8
7
3
Calculate the average waiting time when
FIFO is used ( 1-2-3-4 order) and
compare with the avg. waiting time for
SJF.
SJF optimality …
The average waiting time for FIFO
scheduling is computed as:
(P1 (0) + P2 (6) + P3 (14) + P4 (21)) / 4
= 10.25 time units.
The average waiting time for SJF is
computed as:
(P4 (0) + P1 (3) + P3 (9) + P2 (16)) / 4
= 7 time units.
We need to prove that this is true
in general. How do we do that?
Hint: Consider how we calculate the
average waiting time of a sequence
of processes <p1, p2, …, pn> with
corresponding burst time tbi.
awt = 1/n Σi=1 (n-i) x tbi
We clearly would like the largest
burst time to occur in the sum as
the nth element  with weight 0.
…methods cont’d
SJF is Non-Preemptive!
We can show optimality of SJF on a
static set of processes.
However, if we consider arbitrary
arrival times of processes, we must
re-define SJF to allow for the
preemption of already executing
processes.
This yields a new version of SJF,
sometimes referred to as Shortest
Remaining Time First (SRT).
Shortest Remaining Time (SRT):
A preemptive and dynamic version of
SJF giving processes with the least
amount of remaining time to complete
the highest priority.
PF  P = (t – a), where t-a is the
remaining time;
DM  preemptive;
AR  Same as SJF – chronological or
random among processes with the
same time to completion.
More Scheduling Methods
Round Robin (RR):
Round Robin imposes a fixed time
quantum (time slice) on the amount of
continuous CPU time that can be used by
a process.
When the time slice expires, the
process is preempted and place on the
ready-list.
PF  P = 0; all processes have the same
priority;
DM  preemptive quantum oriented
AR  cyclic;
Multilevel Priority (ML):
Uses a fixed set of priorities 1 (lowest)
thru n (highest).
Each process is assigned an external
priority e upon creation. This priority can
only be changed by authorized kernel calls.
PF  P = e;
DM  preemptive if newly arriving process
has a higher priority. Within each priority
queue, scheduling may be preemptive RR
or non-preemptive FIFO.
AR  cyclic if RR, random/chronological if
FIFO.
Example of RR with Time Quantum
= 20
Process
Burst Time

P1
P2
P3
P4
The Gantt chart is:
P1
0

P2
20
37
P3
53
17
68
24
P4
57
P1
77
P3
97 117
P4
P1
P3
P3
121 134 154 162
Typically, higher average turnaround than SJF, but
better response
The Relationship Between Priorities and Timeslice length
Summary of Scheduling Methods
Algorithm
Decision Mode
Priority Function
Arbitration
Rule
FIFO
nonpreemptive
r
random
SJF
nonpreemptive
-t
chronological or
random
SRT
preemptive
- (t-a)
chronological or
random
RR
preemptive
O
cyclic
RM
preemptive
-d
chronological or
random
EDF
preemptive
- (d-r%d)
chronological or
random
a = attained
service
time
r = real time
in system
t = total
service
time
d = period
e = external
priority