Disadvantages of cyclic TDDB47 Real Time Systems • “Manual” scheduler construction Lecture 2: RM & EDF • Cannot deal with any runtime changes – What happens if we add a task to the set? • Denies the advantages of concurrent programming Mikael Asplund Real-Time Systems Laboratory Department of Computer and Information Science Linköping University, Sweden – Which? The lecture notes are partly based on lecture notes by Calin Curescu, Simin NadjmTehrani, Jörgen Hansson, Anders Törne. They also loosely follow Burns’ and Welling book “Real-Time Systems and Programming Languages”. These lecture notes should only be used for internal teaching purposes at Linköping University. Lecture 2: RM & EDF Mikael Asplund 29 pages Lecture 2: RM & EDF Mikael Asplund States of a process 2 of 29 Priority-based scheduling • Every task has an associated priority • Run task with the highest priority – At every scheduling decision moment • Examples – Rate Monotonic (RM) • Static priority assignment – Earliest Deadline First (EDF) • Dynamic priority assignment – And many others … Lecture 2: RM & EDF Mikael Asplund 3 of 29 Lecture 2: RM & EDF Mikael Asplund 4 of 29 Schedulability Test • Test to determine whether a feasible schedule exists • Sufficient + if test is passed, then tasks are definitely schedulable - if test is not passed, we don’t know • Necessary + if test is passed, we don’t know - if test is not passed, tasks are definitely not schedulable • Exact • sufficient & necessary at the same time Lecture 2: RM & EDF Mikael Asplund Rate Monotonic (RM) 5 of 29 Lecture 2: RM & EDF Mikael Asplund 6 of 29 Assumption Rate Monotonic • Each process is assigned a (unique) priority based on its period; the shorter the period, the higher the priority • All tasks have their initial release at time 0 • Assumes the “Simple task model” • Fixed priority scheduling • Preemptive – Unless stated otherwise Lecture 2: RM & EDF Mikael Asplund 7 of 29 Lecture 2: RM & EDF Mikael Asplund 8 of 29 Example 1 • Assume we have the following task set • OBS: not scheduled yet … Lecture 2: RM & EDF Mikael Asplund Example 1 (cont’d) • Scheduled with RM 9 of 29 Lecture 2: RM & EDF Mikael Asplund 10 of 29 Schedulability test for RM • Sufficient, but not necessary: N ∑ i= 1 Ci Ti Example 2 • Taskset • Period (Ti) • WCET (Ci) ≤N 21 / N −1 P1 20 7 P2 50 10 P3 30 5 • Necessary, but not sufficient: N ∑ i= 1 Lecture 2: RM & EDF Mikael Asplund Ci Ti ≤1 11 of 29 Lecture 2: RM & EDF Mikael Asplund 12 of 29 Harmonic periods Example 3 • Taskset: • Exact schedulability test for RM if periods are harmonic: N ∑ i= 1 C ≤1 T • Gantt chart: i i Lecture 2: RM & EDF Mikael Asplund 13 of 29 Lecture 2: RM & EDF Mikael Asplund 14 of 29 Exact schedulability test The first time is the hardest • The scedulability of a given taskset for RM can be decided by: • Theorem – If all tasks meet their first deadline, then they will meet all future ones. – Drawing a schedule – Proof: paper by Liu and Layland, 1973 – Doing a response time analysis • Why? • Complexity: Pseudo-polynomial time Lecture 2: RM & EDF Mikael Asplund 15 of 29 Response time analysis Lecture 2: RM & EDF Mikael Asplund 16 of 29 Optimality of scheduling algorithms • Tasks suffer interference from higher priority tasks • “A scheduler is optimal if it always finds a schedule when a schedulability test indicates there is one.” • Response time: the time that passes since the task is released and until it finishes R i =C i +I i R i =Ci ∑ j∈hp i Ri Tj – Burns, 1991 • “An optimal scheduling algorithm is one that may fail to meet a deadline if no other scheduling algorithm can meet it.” Cj – Stankovic et al., 1995 • “An optimal scheduling algorithm is guaranteed to always find a feasible schedule, given that a feasible schedule does exist.” • Iterative formula for calculating response time 1 w n+ =Ci i Lecture 2: RM & EDF Mikael Asplund ∑ j∈hp i w ni Tj – Hansson, 1998 Cj 17 of 29 Lecture 2: RM & EDF Mikael Asplund 18 of 29 Optimality of RM What to do if not schedulable • Change the task set utilitsation – by reducing Ci • Rate Monotonic is optimal among fixed priority schedulers • code optimisation • faster processor – If we assume the “Simple Process Model” for the tasks • Increase Ti for some process – If your program and environment allows it Lecture 2: RM & EDF Mikael Asplund 19 of 29 Lecture 2: RM & EDF Mikael Asplund 20 of 29 RM characteristics • Easy to implement. • Drawback: – May not give a feasible schedule even if processor is idle at some points. Lecture 2: RM & EDF Mikael Asplund Earliest Deadline First (EDF) 21 of 29 Lecture 2: RM & EDF Mikael Asplund 22 of 29 Earliest Deadline First (EDF) • Always runs the process that is closest to its deadline. • Dynamic priority scheduling – Evaluated at run-time – What are the events that should trigger a priority reevaluation? Schedulability test for EDF • Utilitsation test – Necessary and sufficient • Or “exact” test N ∑ • Assumes the “Simple task model” – Actually more relaxed: Di < Ti i= 1 Ci Ti ≤1 • Preemptive – Unless stated otherwise Lecture 2: RM & EDF Mikael Asplund 23 of 29 Lecture 2: RM & EDF Mikael Asplund 24 of 29 Optimality of EDF Example 4 • Consider following task set: • WCET (Ci) • EDF is optimal among dynamic priority schedulers P1 P2 2 4 • Deadline (Di = Ti) – If we assume the “Simple Process Model” for the tasks • Or a more relaxed one where Di < Ti 5 7 • Is it schedulable with EDF? • Is it schedulable with RM? Lecture 2: RM & EDF Mikael Asplund 25 of 29 Lecture 2: RM & EDF Mikael Asplund 26 of 29 Domino Effect EDF vs. RM • EDF can handle tasksets with higher processor utilisation. – Example 4 not schedulable with RMS! • EDF has simpler exact analysis • RMS can be implemented to run faster at run-time – Depends on the OS – But they usually like fixed priorities more Lecture 2: RM & EDF Mikael Asplund 27 of 29 Lecture 2: RM & EDF Mikael Asplund Reading material 28 of 29 Dynamic Scheduling • Chapter 13 in Burns & Wellings • Chapter 4 in Butazzo – for the proofs of sufficient condition and optimality Lecture 2: RM & EDF Mikael Asplund 29 of 29 Lecture 2: RM & EDF Mikael Asplund 30 of 29