Chapter 5: CPU Scheduling (Cont) : Modified From Silberschatz, Galvin and Gagne ©2009
Chapter 5: CPU Scheduling (Cont) : Modified From Silberschatz, Galvin and Gagne ©2009
SHORT-TERM
LONG-TERM MID-TERM
cooperative scheduling
let a process run until it blocks on I/O, terminates or voluntarily releases the CPU
(system call)
Runnin
Ready
g
Blocke
d
preemptive scheduling
follow clock interrupts (ex: 50Hz) to forcibly switch processes (demote the “Running”
to “Ready”)
Runnin
Ready
g
Blocke
d
Nonpreemtive
Convoy effect short process behind long process
A
Arrival times B
C
D
E
A B C D E Mean
A
Arrival times B
C
D
E
Shortest Job
First (SJF)
A B C D E Mean
SJF
=1
n+1 = tn
Only the actual last CPU burst counts
Since both and (1 - ) are less than or equal to 1, each successive term
has less weight than its predecessor
A
Arrival times B
C
D
E
A B C D E Mean
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
Problem Starvation
low priority processes may never execute
Solution Aging
as time progresses increase the priority of the process
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 q must be large with respect to context switch, otherwise
overhead is too high
A B C D E Mean
A B C D E Mean
Scheduling
A new job enters queue Q0 which is served FCFS.
When it gains CPU, job receives 8 milliseconds.
If it does not finish in 8 milliseconds, job is moved to queue Q1.
Pthread Scheduling
API allows specifying either PCS or SCS during thread creation
Asymmetric multiprocessing
only one processor accesses the system data structures,
alleviates the need for data sharing
Load balancing
Push migration
Pull migration
Solaris scheduling
Windows XP scheduling
Linux scheduling
Dispatch Table
Average wait = 28
SJF
Average wait = 13
RR
Average wait = 23
CS 446 Principles of Computer Operating Systems 32
Algorithm Evaluation
Queuing models
Distribution of CPU and I/O bursts
Distribution of arrival times
Little’s formula: n = x W
In steady-state, number of departures must be equal to the number
of arrivals