Process Scheduling Algorithm-1
Process Scheduling Algorithm-1
Priority Scheduling
Process CPU Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
Average waiting time
Gantt Graph = (6+0+16+18+1)/5 = 8.2
P2 P5 P1 P3 P4
0 1 6 16 18 19
Priority Scheduling
Priority Assignment
Internally defined – use some
measurable quantity, such as the #
of open files, Average CPU Burst
Average I/O Burst
Priority Scheduling
Preemptive or Non-Preemptive?
Preemptive scheduling – CPU
scheduling is invoked whenever a
process arrives at the ready queue,
or the running process relinquishes
the CPU.
Non-preemptive scheduling – CPU
scheduling is invoked only when the
running process relinquishes the
CPU.
Priority Scheduling
Major Problem
Indefinite Blocking (/Starvation)
Low-priority processes could starve
to death!
A Solution: Aging
A technique that increases the
priority of processes waiting in the
system for a long time.
ready running
Interrupt at every time quantum (time slice)
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 0 10 20 30
0 10
P2
10 20 0 10 20 30
P3
20 30 0 10 20 30
Average Turnaround Time ATT = (28+29+30)/3 = 29
= (10+20+30)/3 = 20
=> 80% CPU Burst < time slice
System Processes
Interactive Processes
…
Batch Processes
Multilevel Queue Scheduling
Intra-queue scheduling
Independent choice of scheduling
algorithms.
Inter-queue scheduling
a. Fixed-priority preemptive scheduling
a. e.g., foreground queues always have absolute
priority over the background queues.
b. Time slice between queues
a. e.g., 80% CPU is given to foreground processes,
and 20% CPU to background processes.
c. More??
Multilevel Feedback
Queue Scheduling
Different from Multilevel Queue
Scheduling by Allowing Processes to
Migrate Among Queues.
Configurable Parameters:
a. # of queues
b. The scheduling algorithm for each queue
c. The method to determine when to upgrade a
process to a higher priority queue.
d. The method to determine when to demote a
process to a lower priority queue.
e. The method to determine which queue a newly
ready process will enter.
*Inter-queue scheduling: Fixed-priority preemptive?!
Multilevel Feedback
Queue Scheduling
Example
quantum = 8
quantum = 16
FCFS
*Idea: Separate processes with different CPU-burst
characteristics!
Multiple-Processor Scheduling
CPU scheduling in a system with
multiple CPUs
A Homogeneous System
Processes are identical in terms of their
functionality.
Can processes run on any processor?
A Heterogeneous System
Programs must be compiled for
instructions on proper processors.
Multiple-Processor Scheduling
Load Sharing – Load Balancing!!
A queue for each processor
Self-Scheduling – Symmetric
Multiprocessing
A common ready queue for all processors.
Self-Scheduling
Need synchronization to access common
data structure, e.g., queues.
Master-Slave – Asymmetric Multiprocessing
One processor accesses the system
structures no need for data sharing.
Multiple-Processor Scheduling
Load Balancing
Push migration: A specific task periodically
checks for imbalance and migrate tasks
Pull migration: An idle processor pulls a
waiting task from a busy processor
Linux and FreeBSD do both!
Processor Affinity
The system might avoid process migration
because of the cost in invalidating or re-
populating caches
Soft or hard affinity
Multiple-Processor Scheduling
Multiple-Processor Scheduling –
SMT Superscalar SMT
U t ilizat io n++
time T hr o ghput ++
u
Pe rf ormance++