Lecture5 - CPU Scheduling
Lecture5 - CPU Scheduling
The Dispatcher is the module that gives control of the CPU to the
process selected by the short-term scheduler; this involves:
Dispatch latency ; the time it takes for the dispatcher to stop one
process and start another running
Scheduling Criteria
CPU utilization – keep the CPU as busy as possible.
Throughput – # of processes that complete their execution per time unit(10
processes/second)
Turnaround time – amount of time to execute a particular process(the
interval from the time of submission of a process to the time of completion,
waiting to get into memory, waiting in the ready queue, exciting on the CPU,
doing I/O).
Waiting time – the amount of times 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)
Scheduling Algorithm Optimization Criteria
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect as short processes go behind long process lower
CPU and device utilization.
Shortest-Job-First (SJF) Scheduling
P4 P1 P3 P2
0 3 9 16 24
P1 P3 P2 P4
0 2 4 5 7 8 12 16
P1‘s wating time = 0
P1(7)
P2(4) P2‘s wating time = 6
P3‘s wating time = 3
P3(1)
P4‘s wating time = 7
P4(4)
Shortest-Job-First (SJF) Scheduling
Example3:
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
Preemptive SJF(SRTF) Average waiting time = (9 + 1 + 0 +2)/4 = 3
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
P1(5) P1‘s wating time = 9
P1(7)
P2(4) P2(2) P2‘s wating time = 1
P3‘s wating time = 0
P3(1)
P4‘s wating time = 2
P4(4)
Shortest-Job-First (SJF) Scheduling
P2 P5 P1 P3 P4
0 1 6 16 18 19
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
AWT(6(10-4)+4+7)/3 = 5.66
Round Robin (RR)
Example2:
Time quantum = 20
Process Burst Time Wait Time
P1 53 57 +24 = 81
P2 17 20
P3 68 37 + 40 + 17= 94
P4 24 57 + 40 = 97
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
P1(53) 57
P1(33) 24P1(13)
P2(17) 20
37
P3(48)
40 P3(28) P3(8)
P3(68) 17
P4(24) 57 40 P4(4)
Three queues:
Q0 – RR with time quantum 8
milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
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
At Q1 job is again served FCFS and
receives 16 additional milliseconds
If it still does not complete, it is
preempted and moved to queue Q2
Multilevel Feedback Queue