CPU Scheduling
Heechul Yun
1
CPU Scheduling Heechul Yun 1 Administrative Midterm Mar. 15, - - PowerPoint PPT Presentation
CPU Scheduling Heechul Yun 1 Administrative Midterm Mar. 15, 2016 Closed book, in-class Review class: Mar. 13, 2016 2 Agenda Introduction to CPU scheduling Classical CPU scheduling algorithms 3 CPU Scheduling CPU
1
2
3
4
5
6
7
8
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
A B C A B C A C A C Time
+ + + wait time response time
12
Process Arrival Time Burst Time P1 8 P2 1 4 P3 1 10 P4 6 2
P1 P2 P3 P4
8 12 22 24
13
14
15
Process Arrival Time Burst Time P1 24 P2 3 P3 3 P1 P2 P3 24 27 30
16
Process Arrival Time Burst Time P1 24 P2 3 P3 3 P1 P3 P2 6 3 30
17
18
19
Process Arrival Time Burst Time P1 6 P2 8 P3 7 P4 3 P4 P3 P1 3 16 9 P2 24
20
21
Process Arrival Time Burst Time P1 8 P2 1 4 P3 2 9 P4 3 5
P2 P4 P1 P3
8 12 17 26
22
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
23
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
24
25
26
27
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
28
29
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
30
31
Compute I/O I/O
32
…
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
33
34
35
36
37
38
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 0 Time
A B C
2 5 9
39
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
40
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
41
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
42
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
43
Priority 0 (time slice = 1): Priority 1 (time slice = 2): Priority 2 (time slice = 4):
time = 3 Time
A B C
5 2
A
1
B C
Suppose A is blocked on I/O
44
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
Suppose A is returned from I/O
45
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
46
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
47
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
48
49
50
51
52
53
5 6 8 10
54
9 6 8 10
55 Figure source: M. Tim Jones, “Inside the Linux 2.6 Completely Fair Scheduler”, IBM developerWorks
56
57
58
59
ECE493T9
60
User interface Computer simulation Internet video, audio Tele communication Flight control
Soft RT Hard RT No RT
61 [*] Robert Leibinger, “Software Architectures for Advanced Driver Assistance Systems (ADAS)”, OSPERT’15 keynote
62
63
64
65
Task t1: 20 100 0.200 Task t2: 40 150 0.267 Task t3: 100 350 0.286
66
t1 t2 t3 t1 t2 t3 t1 t2 t3
(20, 100) RM (40, 150) (100, 350) (40, 100) RM (40, 150) (110, 350) (40, 100) EDF (40, 150) (110, 350)
67
t1 t2 t3 t1 t2 t3 t1 t2 t3
(20, 100) RM (40, 150) (100, 350) (40, 100) RM (40, 150) (110, 350) (40, 100) EDF (40, 150) (110, 350)
deadline miss!
CFS (sched/fair.c) Real-time (sched/rt.c)
68
CFS (sched/fair.c) Real-time (sched/rt.c)
SCHED_OTHER SCHED_BATCH SCHED_RR SCHED_FIFO
SCHED_DEADLINE
70
71
Core1 Core2 Core3 Core4 DRAM
72
CPU1 CPU2 CPU3 CPU4 HW OS RunQueue tasks
73
CPU1 CPU2 CPU3 CPU4 HW OS
RunQueue
tasks
RunQueue
tasks
RunQueue
tasks
RunQueue
tasks
74
75
Core1 Core2 Core3 Core4 LLC LLC
76
– Migration overhead – Shared hardware resources (cache, dram, etc) – Core architecture heterogeneity (big cores vs. small cores) – …
77
– 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
78
79