350 likes | 455 Views
RTOS Scheduling 3. Cyclic scheduling, EDF. Tasks with precedence, Scheduling impact of DMA, cache, interrupts & context switch overhead, Aperiodic. Georgio Butazzo, “Predictable scheduling Algorithms and applications”, 3 rd edition. Scheduling Approaches Summary.
E N D
RTOS Scheduling 3 Cyclic scheduling, EDF. Tasks with precedence, Scheduling impact of DMA, cache, interrupts & context switch overhead, Aperiodic Georgio Butazzo, “Predictable scheduling Algorithms and applications”, 3rd edition
Scheduling Approaches Summary • Off-line scheduling / analysis(static analysis - static scheduling) • All tasks, times, priorities given • Time-driven; schedule hardcoded, does not use kernel sched. • E.g., Cyclic Executives • Inflexible – reliable used Military, space • Fixed priority scheduling (static analysis + dynamic scheduling) • All tasks, times and priorities given • Priority-driven, dynamic scheduling run time scheduling • Used hard / safety critical systems • E.g., RMA/RMS • Dynamic priority scheduling ( dynamic priorities) • Tasks times may not be known • priorities based on current system - dynamic • For hard / best effort systems • E.g., Earliest Deadline, First (EDF),
Offline, static: Cyclic (a.k.a. Time Line ) Scheduling defence – military – traffic control • Time divided into slices. Greatest Common Divisor of Periods time slice: 25ms for example – minor cycle, min. cycle of repetition =major cycle Example: TA = 25ms, TB = 50ms, TC = 100ms Task A executed every time slot, Task B every two slots, Task C every 4 slots Simple off-line Algorithm
2nd Cyclic Executive example:fyi • Car controller • Speed measurement C= 4ms, P = 20ms, D = 20ms • ABS control C= 10ms, P = 40ms, D = 40ms • Fuel injection C= 40ms, P = 80ms, D = 80ms • Other • Shortest repeat cycle = 80 ms 4 14 20 24 40 44 54 60 64 76 80 speed ABS fuel1 speed fuel2 speed ABS fuel3 speed fuel4 other
Cyclic Executive pros & cons • Pros: Simple to implement, does not use kernel scheduler, timer interrupt every minor cycle – main calls tasks; No switching OH • Pros: Predictable, Good for safety critical app. • Con: waste CPU time • Con: difficult to modify - add task eg increase task time may exceed minor cycle • Con: poor fragile overload handling– eg task does not terminate (Aborted ?) ..domino effect • Con: non optimal response time
RM vs. EDF • Rate Monotonic fixed priority / Dynamic scheduling • Simpler implementation • Predictability for highest priority tasks • EDF dynamic priority • Full processor utilization • Misbehavior during overload conditions
5 10 15 5 10 15 EDF (Earliest Deadline First) dynamic priorityscheduling I no precedence • task with shorter deadline has higher priority • Executes job with earliest deadline Example T1 (4,1) T2 (5,2) T3 (7,2)
5 10 15 5 10 15 EDF • Optimal algorithm - if there is a schedule, EDF can schedule it. T1 (4,1) T2 (5,2) T3 (7,2)
Scheduling tasks with precedence relations Conventional task set Scheduler {T1, T2} Tasks with precedence constraints T1 T2
Scheduling Tasks with Precedence – use DAG - fyi 4 • directed acyclic graph – (DAG) indicates which tasks must complete before other tasks start. 2 DAG : task 1 must complete before tasks 2 and 3 start, etc. 1 5 3 6
Example: EDF Scheduling of Tasks with precedence II C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 Determine schedule feasibility 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
EDF not optimal under precedence constraints – but minimizes latencies C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 • task 3 chosen at time 1 ; has earlier deadline. • Result: task 4 misses its deadline EDF Schedule 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6 2 4 6
Solution: modify EDF task parameters release time & deadlines Tasks with precedence constraints T1 T2 Schedule queue Modify task parameters to respect precedence constraints Scheduler
Task release time & deadlineschanged EDF Using EDF scheduler, task – release time & deadline modified to respect precedence constraints • Rj* ≥ Max (Rj, (Ri* + Ci)) new release time • Di* ≥ Min (Di, (Dj* – Cj)) new deadline Ti Tj
Modifying Release times for EDF Example R1 = 0 R2 = 5 T1 1 T2 2 R4’ = max(R1+C1, R2+C2,R4) R3’ = max(R1 + C1, R3) Initial Task Parameters R3 = 0 R3’ = 1 R4 = 0 T3 2 T4 1 R4’ = 7 T5 3 R5 = 0 R5’ = 8 R5’ = max(R3’+C3, R4’+C4,R5)
Modifying release times for EDF R1 = 0 R2 = 5 T1 1 T2 2 Modified Task Parameters R3’ = 1 T3 2 T4 1 R4’ = 7 T5 3 R5’ = 8
Modifying Deadlines for EDF D2’ = Min( (D4’ – C4),(D3’ – C3), D1) D1 = 5 D2 = 7 D1’ = 3 D2’ = 7 T1 1 T2 2 D2’ = Min( (D4’ – C4), D2) Modified Task Parameters D3 = 5 T3 2 D3’ = 5 T4 1 D4 = 10 D4’ = 9 T5 3 D5 = 12 D3’ = Min( (D5 – C5), D3) D4’ = Min( (D5 – C5), D4)
ModifiedDeadlines & release times for EDF D1’ = 3 D2’ = 7 T1 1 T2 2 Modified Task Parameters T3 2 D3’ = 5 T4 1 D4’ = 9 T5 3 D5 = 12
Real time systems Predictability Problems _ DMA • Direct Memory Access • transfer data between device ,main memory • Problem: I/O device and CPU share same bus • good for performance, but –ve bad for predictability solutions: • Cycle stealing • DMA steals CPU memory cycle for its data transfer • CPU waits until DMA transfer complete • Source of non-determinism! • Time-slice method • memory cycle split in two adjacent time slots • One for the CPU • One for the DMA • More costly, but more predictable!
Predictability Problems: Cache To obtain high predictability, better to have processors without cache ; sacrifice some performance Source of non-determinism • cache miss vs. cache hit miss penalty • writing vs. reading; needs write through memory
Predictability Problems: Interrupts One of biggest problem for predictability • Typical device driver <enable device interrupt> <wait for interrupt> <transfer data> • In OS • Interrupts service routine • interrupts served with fixed static priority • interrupts have higher priorities than processes, but • processes may be higher importance than I/0 operation! • delay introduced by interrupts, # interrupts occur during a task? unpredicatble
Predictability Problems: Interrupts Solutions – approaches • Disable interrupts, except timer • I/O handled by application, polling • -vesacrificeefficienc, busy – wait, cumbersome • Interrupts disabled, same as 1; but periodic Kernel routine(s) manages I/O • +ve limit bound on service; hides I/O details • -ve still has busy-wait, OH due to app kernel communication • Enable Interrupts; strip down service to activate a task • +ve task scheduled with rest – under kernel control, priorities managed • +ve eliminate busy – wait • -ve still has some driver unbounded delys
Handling Interrupts – exampleT0- interrupt handler; Highest priority C T T0 (int.) 60 200 T1 10 50 T240 250 T0 Missed deadline 60 100 200 T1 50 60 T2
Handling Interrupts – examplesolution:interrupt handler IH & T3move some code from handler toanother task T3 with same rateIH highest priority, may conflictwith RM IH 100 150 200 T1 50 60 T2 T3
Handling Context Switch Overhead • Assume Cl = time required to load new task • Cs = time required to save current task context (Cl = Cs) • Task1 • Task 2 • Task 3 OH subtracted from budget every period
Handling Aperiodic Tasks • Solutions • Immediate service • Background scheduling • Aperiodic servers
Aperiodic: Immediate Service • Aperiodic request served as soon as they arrive in system • Minimum response times for aperiodic requests • But Weak guarantees for periodic tasks • Example
Aperiodic: Background Scheduling • Handle soft aperiodic tasks in background behind periodic tasks – in processor free time - after scheduling all periodic tasks • Aperiodic tasks lower priority than periodic tasks • Organization:
Latest Deadline First (LDF) 1973 FYIbuild schedule backwards. example C4 = 1 d4 = 3 EDF Schedule C2 = 1 d2 = 5 4 • LDF scheduling strategy: build schedule backwards. Given a DAG, choose leaf node with latest deadline to be scheduled last, work backwards. 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6 LDF Schedule
Latest Deadline First (LDF)example C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 • Build schedule backwards. Given DAG, choose leaf node with latest deadline (6) to be scheduled last - work backwards. Look at 3, 4, 5 next 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
Latest Deadline First (LDF) C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 • 5 is next. , look at 3,4 next 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
Latest Deadline First (LDF) C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 • 3 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
Latest Deadline First (LDF) C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
Latest Deadline First (LDF) C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6
Latest Deadline First (LDF)optimal under precedence constraints C4 = 1 d4 = 3 C2 = 1 d2 = 5 4 • The LDF schedule - respects all precedence and meets all deadlines. 2 C5 = 1 d5 = 5 1 5 C1 = 1 d1 = 2 3 C3 = 1 d3 = 4 6 C6 = 1 d6 = 6