CPU Scheduling
Heechul Yun
1
CPU Scheduling Heechul Yun 1 Agenda Introduction to CPU - - PowerPoint PPT Presentation
CPU Scheduling Heechul Yun 1 Agenda Introduction to CPU scheduling Classical CPU scheduling algorithms 2 CPU Scheduling CPU scheduling is a policy to decide Which thread to run next? When to schedule the next thread? How
1
2
3
4
5
6
7
8
A B C A B C A C A C Time
+ + wait time response time
9
A B C A B C A C A C Time
+ wait time response time
10
A B C A B C A C A C Time
+ + + wait time response time
11
12
13
A B C A B C A C A C Time
+ + + wait time response time
14
Process Arrival Time Burst Time P1 8 P2 1 4 P3 1 10 P4 6 2
P1 P2 P3 P4
8 12 22 24
15
16
17
18
Process Arrival Time Burst Time P1 24 P2 3 P3 3 P1 P2 P3 24 27 30
19
Process Arrival Time Burst Time P1 24 P2 3 P3 3 P1 P3 P2 6 3 30
20
21
Process Arrival Time Burst Time P1 6 P2 8 P3 7 P4 3 P4 P3 P1 3 16 9 P2 24
22
23
Process Arrival Time Burst Time P1 8 P2 1 4 P3 2 9 P4 3 5
P2 P4 P1 P3
8 12 17 26
24
Process Arrival Time Burst Time P1 8 P2 1 4 P3 2 9 P4 3 5
P
1
P2 P4 P1 P3
1 5 10 17 26
25
Process Arrival Time Burst Time P1 8 P2 1 4 P3 2 9 P4 3 5
P
1
P2 P4 P1 P3
1 5 10 17 26
P1 P2 P3 P4
26
27
28
29
Process Burst Times P1 24 P2 3 P3 3 P1 P2 P3 P1 P1 P1 P1 P1 4 7 10 14 18 22 26 30
30
31
Process Burst Times P1 24 P2 3 P3 3 P1 P2 P3 P1 P2 P1 P1 P3 P1 2 4 6 8 9 12 14 10 30
32
33
Compute I/O I/O
34
I/O
…
I/O
I/O
…
I/O
I/O
– Run to completion in order of arrival – Pros: simple, low overhead, good for batch jobs – Cons: short jobs can stuck behind the long ones
– FCFS with preemption. Cycle after a fixed time quantum – Pros: better interactivity (low average scheduling latency) – Cons: performance is dependent on the quantum size
– Shorted job (or shortest remaining job) first – Pros: optimal average waiting time – Cons: you need to know the future, long jobs can be starved by short jobs
35
36
Process Arrival Time Burst Time P1 8 P2 1 4 P3 1 10 P4 6 2
P1 P2 P3 P4
8 12 22 24
– Run to completion in order of arrival – Pros: simple, low overhead, good for batch jobs – Cons: short jobs can stuck behind the long ones
– FCFS with preemption. Cycle after a fixed time quantum – Pros: better interactivity (low average scheduling latency) – Cons: performance is dependent on the quantum size
– Shorted job (or shortest remaining job) first – Pros: optimal average waiting time – Cons: you need to know the future, long jobs can be starved by short jobs
37
38
39
40
41
42
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 0 Time
A B C
2 5 9
43
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 1 Time
A B C
3 7
A
1
44
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 2 Time
A B C
4 3
A
1
B
45
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 3 Time
A B C
6 3
A
1
B C
46
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 3 Time
A B C
6 3
A
1
B C
Suppose A is blocked on I/O
47
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 3 Time
B C
5 2
A B C
Suppose A is blocked on I/O
48
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 5 Time
A B C
3
A
1
B C
A is returned from I/O
49
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 6 Time
A B C
3
A B C
50
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 8 Time
A B C
3
A B C
2
C
51
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 9 Time
A B C A B C C
52
53
54
5 6 8 10
55
9 6 8 10
56 Figure source: M. Tim Jones, “Inside the Linux 2.6 Completely Fair Scheduler”, IBM developerWorks
57
58
59