CPU Scheduling
CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Algorithm Evaluation
Multiple-Processor Scheduling
Real-Time Scheduling
Basic Concepts - Scheduling
What is scheduling ?
Assignment of various jobs to the CPU to get the optimal use by
reducing CPU idling time
Fundamental Observation:
Maximize
CPU utilization
Throughput
Minimize
Turnaround time
Waiting time
Response time
Ensure fairness
Scheduling Algorithms - General
(0 + 24 + 27)/3 = 17
P1 P2 P3
P1 , P2 , P3
0 24 27 30
P2 , P3 , P1 P2 P3 P1 (6 + 0 + 3)/3 = 3
0 3 6 30
Scheduling Algorithms 2. Shortest-Job-
First (SJF)
P1 P3 P2 P4
0 3 7 8 12 16
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
Scheduling Algorithms 2. Shortest Job
First (SJF) - Estimating CPU Burst
Prioritized processes
Highest priority first
Preemptive / nonpreemptive
Determining Criteria
Internal e.g. I/O : CPU time
External e.g. fee charged, organizational rank
SJF is a priority scheduling
Criteria : Inverse of the CPU burst
Problem: Starvation low priorities may never be
executed.
Solution: Aging time variant priority
Example
Scheduling Algorithms 4. Round Robin
(RR)
P1 P2 P3 P4
53 17 68 24
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Optimal: 80%
of CPU bursts
must be
shorter than
time quantum
Scheduling Algorithms 5. Multilevel
Queue Scheduling
Disadvantage : Starvation
Scheduling Algorithms 6. Multilevel
Feedback Queue
Example:
Q0 time quantum 8 ms
Q1 time quantum 16 ms
Q2 FCFS
Scheduling
A new job enters Q0 (FCFS), gets 8 ms; if
the work is not completed (CPU burst > 8
ms), preempted & moved to queue Q1.
In Q1 (FCFS), it gets 16 ms more. If the
work still incomplete, preempted and moved
to queue Q2 (FCFS).
Algorithm Evaluation
Deterministic modeling
Take a particular predetermined workload and compare the
performances of different algorithms
Problem estimating actual times; good for repeated
processes
Queuing models
Model the system statistically; based on the statistical data
calculate different parameters
Ex. n = x W (Littles formula : =avg. arrival rate, W= avg.
wait time, n=no. of processes entering the queue in W time)
Algorithm Evaluation
Simulations
Programming a model of the computer system
Data for the model can be generated by random number
generator that generates random CPU burst, I/O bursts, arrival
times etc. according to a probability distribution
Such an estimate may not be accurate since the real systems
have a order of occurrence
To correct this problem we use an observed sequence
More costly
Implementation
The ideal method
Most expensive not only technical cost but the cost involved
in getting user feedback
Multiple-Processor Scheduling