Lecture 24: Process Scheduling Examples and for Real-time Systems
Review: Categories of Process Scheduling Batch Systems (Compute Servers) Many processes, not interactive, throughput is important Interactive Systems PC Real Time Systems Guaranteed response times, meet deadlines
Scheduling Algorithm Goals All Systems Fairness – giving each process a fair share of the CPU Policy enforcement – seeing that stated policy is carried out Balance – keeping all parts of the system busy
Review: Scheduling Algorithms for Batch Systems First come first serve Shortest job first Shortest remaining time next
Review: Scheduling Algorithms for Interactive Systems Round-Robin scheduling Priority scheduling Multiple queues Lottery scheduling
FCFS Arrival time CPU burst P1: 4 36 8 112 1 13 I/O burst 16 13 16 20 P1: 4 36 8 112 1 I/O burst P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1
FCFS 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next? P1 idle P2 P3 P4 0 4 13 36 40 42
FCFS Time next ready 40 76 60 192 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next? P1 idle P2 P3 P4 0 4 13 36 40 42
FCFS Time next ready 40 76 60 192 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 P1 idle P2 P3 P4 P1 idle P3 0 4 13 36 40 42 50 60 172
FCFS 162 76 212 192 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 P1 idle P2 P3 P4 P1 idle P3 P2 P1 idle P4 0 4 13 36 40 42 50 60 172 174 175 192
RR, Q = 10 Arrival time CPU burst P1: 4 36 8 112 1 13 I/O burst 16 13 16 20 P1: 4 36 8 112 1 I/O burst P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart
RR, Q = 10 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next, and when? Gantt chart P1 idle P2 P3 P4 0 4 13 23 27 29
RR, Q = 10 40 82 47 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 0 4 13 23 27 29 42
RR, Q = 10 162 End Run 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 P1 P3 P2 P3 0 4 13 23 27 29 42 50 90 92
RR, Q = 10 End 205 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 P1 P3 P2 P3 P1 P3 idle 0 4 13 23 27 29 42 50 90 92 162 163 165
MLFQ: Q0 = 8, Q1 = 16, Q2 = 40 q1 45 177 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 15 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart 1 idle 2 3 4 2 0 4 13 21 25 27
MLFQ: Q0 = 8, Q1 = 16, Q2 = 160 q1 177 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 2 P3: 4 20 112 40 2 40 2 40 1 104 P4: 2 150 3 10 1 Gantt chart 1 idle 2 3 4 2 1 3 0 4 13 21 25 27 40 48 56
MLFQ: Q0 = 8, Q1 = 16, Q2 = 160 98 q2 177 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 64 P4: 2 150 3 10 1 Gantt chart 1 idle 2 3 4 2 1 3 2 3 0 4 13 21 25 27 40 48 56 58 98
MLFQ: Q0 = 8, Q1 = 16, Q2 = end q2 190 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 4 P4: 2 150 3 10 1 Gantt chart 1 idle 2 3 4 2 1 3 2 3 2 3 1 3 idle 0 4 13 21 25 27 40 48 56 58 98 100 160 161 165
Real-time Scheduling Definition Performance measure Key property Systems whose correctness depends on their temporal aspects as well as their functional aspects Performance measure Timeliness on timing constraints (deadlines) Speed/average case performance are less significant. Key property Predictability on timing constraints
Real-time Scheduling Absolute deadline Released Execution time Relative deadline
Deadlines: Hard vs. Soft Hard deadline Disastrous or very serious consequences may occur if the deadline is missed Validation is essential : can all the deadlines be met, even under worst-case scenario? Deterministic guarantees Soft deadline Ideally, the deadline should be met for maximum performance. The performance degrades in case of deadline misses. Best effort approaches / statistical guarantees
RM (Rate Monotonic) Optimal static-priority scheduling It assigns priority according to period A task with a shorter period has a higher priority Executes a job with the shortest period T1 (4,1) T2 (5,2) 5 10 15 T3 (7,2)
EDF (Earliest Deadline First) Optimal dynamic priority scheduling A task with a shorter deadline has a higher priority Executes a job with the earliest deadline T1 (4,1) T2 (5,2) 5 10 15 T3 (7,2)