Lecture 6 (Theory)
Lecture 6 (Theory)
1. Basic Concepts
2. Scheduling Criteria
3. Scheduling Algorithms
Basic Concepts
Maximum CPU utilization obtained with
multiprogramming
CPU–I/O Burst Cycle – Process execution
consists of a cycle of CPU execution and I/O
wait
CPU burst followed by I/O burst
Max throughput
P1 24
P2 3
P3 3
FCFS Scheduling (cont’d)
P2 , P3 , P1
P2 P3 P1
0 3 6 30
Associate with each process the length of its next CPU burst
Use these lengths to schedule the process with the shortest time
SJF is optimal – gives minimum average waiting time for a given
set of processes
The difficulty is knowing the length of the next CPU request
Could ask the user
Example of SJF
ProcessArriva l Time Burst Time
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
SJF scheduling chart
P4 P1 P3 P2
0 3 9 16 24
Can only estimate the length – should be similar to the previous one
Then pick process with shortest predicted next CPU burst
Can be done by using the length of previous CPU bursts, using exponential
averaging th
1. t n actual length of n CPU burst
2. n 1 predicted value for the next CPU burst
3. , 0 1 n 1 t n 1 n .
4. Define :
Commonly, α set to ½
Preemptive version called shortest-remaining-time-first
Prediction of the Length of the Next CPU
Burst
Examples of Exponential Averaging
=0
n+1 = n
Recent history does not count
=1
n+1 = tn
Only the actual last CPU burst counts
If we expand the formula, we get:
n+1 = tn+(1 - ) tn -1 + …
+(1 - )j tn -j + …
+(1 - )n +1 0
Since both and (1 - ) are less than or equal to 1, each successive term has less
weight than its predecessor
Example of Shortest-remaining-
time-first
Now we add the concepts of varying arrival times and preemption to the analysis
ProcessA arri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26
Performance
q large FIFO
q small q must be large with respect to context switch, otherwise overhead is
too high
Example of RR with Time Quantum = 4
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time