Lecture 5 Uniprocessor Scheduling
Lecture 5 Uniprocessor Scheduling
Uniprocessor Scheduling
Operating System
1
Contents
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Uniprocessor scheduling – multilevel
queue scheduling
2
Basic Concepts
Scheduling is concerned with the decision of assigning
processor (or processors) to processes in such a way so as to
optimize a number of performance criteria. These performance
criteria can be user-oriented or system-oriented.
Types of Scheduling
Long-term scheduling – the decision to add to the pool of
processes to be executed.
Medium-term scheduling – The decision to add to the number of
processes that are partially or full in main memory.
Short-term scheduling – The decision as to which available process
will be executed by the processor.
I/O scheduling – The decision as to which process’ pending I/O
request shall be handled by the available I/O device.
4
Long-Term Scheduling (cont.)
1. For decision 1. the decision is driven by the desired
degree of multiprogramming. The degree of
multiprogramming is dictated by the available
resources (e.g. enough memory.
2. For decision 2, the decision can be on a FCFS
policy, or certain criteria based on priority,
expected execution time, or I/O requirements. For
example, the scheduler may attempt to keep a mix
of processor-bound and I/O-bound processes. The
scheduler may attempt to keep a good mix of short
jobs (student jobs) and long jobs (research
projects)
5
Medium-term scheduling
Medium-term scheduling is part of the swap-out
function. Typically, blocked processes are the ones to
swap-out. It is a function of the desired degree of
multiprogramming as well as the cost of swapping.
6
Short-term scheduling
(dispatcher)
The short-term scheduler is invoked
whenever an event occurs that may lead to
the suspension of the current process or that
may provide an opportunity to preempt a
currently running process in favor of another.
Examples of such events include the
following:
Clock interrupts
I/O interrupts
OS calls
Signals
7
Dispatcher
Dispatcher module gives control of the CPU
to the process selected by the short-term
scheduler; this involves:
switching context
switching to user mode
jumping to the proper location in the user
program to restart that program
Dispatch latency – time it takes for the
dispatcher to stop one process and start
another running
8
Short-term Scheduling Criteria
System-Oriented Criteria
CPU utilization – percentage time that the processor is busy, keep
the CPU as busy as possible (maximize processor utilization)
Throughput – # of processes that complete their execution per time
unit (maximize throughput)
User-Oriented Criteria
Turnaround time – interval of time between submission of a job and
its completion, i.e., the total time that the process spends in the
system (waiting time plus service time). Appropriate measure for
batch job.
Waiting time – amount of time a process has been waiting in the
ready queue
Response time – amount of time it takes from when a request was
submitted until the first response is produced, not output (for time-
sharing environment)
Deadline – The ability to meet hard deadline. Appropriate for real-
time jobs
9
Short-term Scheduling
CPU Scheduler
Selects from among the processes in memory that
are ready to execute, and allocates the CPU to one of
them
Scheduling Discipline:
Nonpreemptive – Once a process is in the Running State, it
continues to execute until
(a) it terminates
(b) blocks itself to wait for I/O or to request some OS services
Preemptive – The currently running process may be
interrupted and moved to the Ready State by the OS
(a) Switches from running to ready state
(b) Switches from waiting to ready state
Preemptive more overhead than nonpreemptive, but
may provide better service
10
Optimization Criteria
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
11
Scheduling Algorithm
Turnaround Time(TAT) is the total time
that the process spends in the system
(waiting time + service time).
Normalized Turnaround Time is the
ratio of Turnaround Time to Service
Time
12
First-Come, First-Served (FCFS)
Scheduling
Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
The Gantt Chart for the schedule is:
A B C D E
0 3
Turnaround 9 A: 13
Time(TAT) 3; B: 7; C: 9; 18
D: 12;20
E: 12
Normalized Turnaround Time: A: 3/3=1.0; B: 7/6; C: 9/4=2.25; D:
12/5=2.4; E: 12/2=6.0
13
Round Robin (RR)
Used in interactive time-sharing system.
Each process gets a small unit of CPU time (time quantum),
usually 10-100 milliseconds. After this time has elapsed, the
process is preempted and added to the end of the ready
queue.
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 at once. No process waits
more than (n-1)q time units.
Performance
q large FIFO
q small processor sharing
q must be large with respect to context switch, otherwise
overhead is too high
Best choice q for will be slightly greater than the time required
for a typical interaction.
14
Example of RR with Time
Quantum = 1
Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
The Gantt chart is:
A A A B B C B C D B C E D B C E D B D D
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
15
Time Quantum and Context Switch Time
16
Shortest- Process-Next (SPN)
Scheduling
This is a nonpreemptive scheduling discipline in which the shortest expected
processing time is selected next.
A B E C D
0 3 9 11 15 20
Turnaround Time(TAT) A: 3; B: 7; E: 3; C: 11; D: 14
Normalized Turnaround Time: A: 3/3=1; B: 7/6; E: 3/2; C: 11/4; D: 14/5
Needs user to provide an estimate of processing time.
17
Determining Length of Next CPU
Burst (not required)
For interactive processes, the OS may keep a running average of each “burst” for each
process and estimate the processing time requirement
n
of the next burst by
1
S n 1
n
T
i 1
i
Ti= processor execution time for the ith instance of this process
Si= predicted value for the ith instance
S1=predicted value for the 1st instance, not calculated, assumed to be 0.
The equation can be rewritten as
1 n 1
S n 1 Tn Sn
n n
The above formular gives equal weight to each instance. If we want to give greater weight
to more recent instances, then we can use an exponential averaging
S n 1 Tn (1 ) S n
where α is a constant and 0< α <1,
A B C E B D
0 3 4 8 10 15 20
Turnaround Time(TAT) A: 3; B: 13; C: 4; D: 14; E: 2
Normalized Turnaround Time: A: 3/3=1; B: 13/6; C: 4/4=1; D: 14/5=2.8; E:
2/2=1
19
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
nonpreemptive
SJF is a priority scheduling where priority is the predicted next
CPU burst time
FCFS is a priority scheduling where priority is the arrival time of
the process.
Problem Starvation – low priority processes may never
execute
Solution Aging – as time progresses increase the priority of
the process
20
Highest Response Ratio Next
w= time spent waiting for the processor
s= expected service time
R=(w+s)/s
When a process is free for assignment, choose the process with the greatest value of R.
Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
The Gantt chart is:
A B C E D
0 3 9 13 15 20
Calculate R:
at time 9: C: ((9-4)+4)/4=9/4; D: ((9-6)+5)/5=8/5; E: ((9-8)+2)/2=3/2, choose C
At time 13: D: ((13-6)+5)/5=2.4; E: ((13-8)+2)/2=3.5; choose E.
21
End of lecture 5
Thank you!
22