Recap from last lecture TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems Laboratory Department of Computer and Information Science Linköping University Undergraduate course on Real-time Systems Linköping University • Real-time systems have well-defined timing requirements • Many systems have a soft real-time character • But first we look at the extreme case • Computational processes that need to meet every deadline for each instance of each process • Most commonly used: Cyclic scheduling with Major/Minor cycle Undergraduate course on Real-time Systems Linköping University 38 pages Autumn 2015 When is the schedule correct? 2 of 38 Autumn 2015 Harmonic processes • All processes should be run at least as often as every (original) Ti Easy to find minor/major cycle Recall example 2: • All processes fit in the minor cycles they are placed in process period A 20 B 40 C 60 • We started with harmonic processes … If sum of WCETs fits in... ... 0 Undergraduate course on Real-time Systems Linköping University 3 of 38 Autumn 2015 20 120 Undergraduate course on Real-time Systems Linköping University 4 of 38 Autumn 2015 Next try... • In either case we need to What if periods are not harmonic? Or the WCET sum does not fit? – change the task set parameters – recall that all processes should be run at least as often as every (original) Ti • Place the processes in new minor cycle and major cycle until repetition appears Undergraduate course on Real-time Systems Linköping University 5 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 6 of 38 Autumn 2015 1 Example (3.1) process period A 75 Jitter control B 100 • Many applications need to minimise jitter in reading data from sensors or producing output to actuators Alternative 1: Choose minor cycle as greatest common divisor, and move processes backwards in time when they clash. Drawbacks? ... 0 25 100 time 150 Undergraduate course on Real-time Systems Linköping University Undergraduate course on Real-time Systems Linköping University 7 of 38 Autumn 2015 8 of 38 Autumn 2015 Example (3.2) process period A 75 B 100 0 Drawbacks? ... 75 time Undergraduate course on Real-time Systems Linköping University process period A 75 B 100 Alternative 3: A mix of the last two Alternative 2: Run process B more often than necessary, e.g. once every 75 time units. minor cycle Example (3.3) 9 of 38 Autumn 2015 Drawbacks? minor cycle 0 50 Undergraduate course on Real-time Systems Linköping University If they don’t fit? ... time 10 of 38 Autumn 2015 Note: No preemption! • Break some process that does not fit into two or more processes and run the different parts in different minor cycles Creates new processes out of the old one! Undergraduate course on Real-time Systems Linköping University Drawbacks? 11 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 12 of 38 Autumn 2015 2 Now let’s check! You should be able to answer how the typical scheduling questions are answered in a cyclic schedule context … During run-time: • What is the de facto “deadline” for each process? • How does one know that processes meet their deadlines? • What happens if they don’t? Undergraduate course on Real-time Systems Linköping University 13 of 38 Autumn 2015 What if dependent? • So far we assumed all processes are independent • Dependence can be due to sharing resources or computation precedence requirements – Computation precedence automatically taken care of as each instance of a process reads the inputs at the beginning of a minor cycle (produced by another process at the end of some prior minor cycle) – Mutual access to resources does not take place as each process is running alone with no interruptions Undergraduate course on Real-time Systems Linköping University Summary 14 of 38 Autumn 2015 But... • Simple at run-time • No overheads for context switching • Processes can exchange data without the need for explicit (dynamic) synchronisation • Cycles can be hard to determine and can become looong ... • Long WCET can create problems • Sporadic processes are run periodically – Can lead to high processor utilisation • Very inflexible! Undergraduate course on Real-time Systems Linköping University 15 of 38 Autumn 2015 Better methods needed For: • Processes with long WCET • Sporadic events • Processes with long period but short deadline • Run-time process dependence – specially in terms of overruns Undergraduate course on Real-time Systems Linköping University Undergraduate course on Real-time Systems Linköping University 16 of 38 Autumn 2015 Priority-based scheduling • A preemptive method where the priority of the process determines whether it continues to run or it is disrupted ”Most important process first!” 17 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 18 of 38 Autumn 2015 3 RMS Priorities • Each process has a period Ti that is the shortest interval between its release times Rate Monotonic Scheduling: • On-line • Preemptive • Priority-based with fixed (static) priorities Undergraduate course on Real-time Systems Linköping University • Processes are assigned priorities dependent on length of Ti – The shorter Ti the higher the priority Undergraduate course on Real-time Systems Linköping University 19 of 38 Autumn 2015 Consider following scenario: Example (4) Period (Ti) WCET (Ci) Priority P1 P2 20 10 high 50 30 10 5 low medium arrival time 0 20 30 40 50 60 P3 preemption 0 Undergraduate course on Real-time Systems Linköping University 21 of 38 Autumn 2015 20 of 38 Autumn 2015 10 20 30 40 process P1, P2, P3 P1 P3 P1 P2 P1, P3 ... 50 60 80 90 Undergraduate course on Real-time Systems Linköping University Schedulability Tests time 22 of 38 Autumn 2015 RMS Schedulability • Sufficient – if test is passed, then tasks are definitely schedulable – if test is not passed, we don’t know Theorem: • Necessary – if test is not passed, tasks are definitely not schedulable – if test is passed, we don’t know • Exact test: (sufficient condition) For n processes, RMS will guarantee their schedulability if the total utilisation U = C1/T1 + ... + Cn/Tn does not exceed the guarantee level G = n (2 1/n -1) – sufficient & necessary at the same time Undergraduate course on Real-time Systems Linköping University 23 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 24 of 38 Autumn 2015 4 For this example When the test fails U = 10/20+10/50+5/30 = 0,87 n=3 G = 3(2 1/3 • Try testing the critical instant: Assume that all processes are released simultaneously at time 0, and then arrive according to their periods • Check whether each process meets its deadline for all releases before the first deadline for the process with lowest priority -1) = 0,78 Schedulability is not guaranteed! (but processes may still meet their deadlines...) Undergraduate course on Real-time Systems Linköping University Undergraduate course on Real-time Systems Linköping University 25 of 38 Autumn 2015 For example 4 scenario: Example (4) Period (Ti) WCET (Ci) Priority P1 P2 20 10 high 50 30 10 5 low medium arrival time 0 20 30 40 50 60 P3 27 of 38 Autumn 2015 10 20 30 40 ... 50 60 time Response time analysis • Tasks suffer interference from higher priority tasks Ri Ci I i Ri Ci jhp ( i ) Ri Cj Tj • Iterative formula for calculating response time • Assumptions? 29 of 38 Autumn 2015 90 28 of 38 Autumn 2015 win 1 Ci Undergraduate course on Real-time Systems Linköping University 80 Undergraduate course on Real-time Systems Linköping University Exact schedulability test • Mathematical equations for computing worst case response times Ri for each process • Response time: the time between the release and the completion time • Process set schedulable if Ri ≤ Ti for all processes process P1, P2, P3 P1 P3 P1 P2 P1, P3 preemption 0 Undergraduate course on Real-time Systems Linköping University 26 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University jhp ( i ) win Cj Tj 30 of 38 Autumn 2015 5 Not schedulabe task set When response time analysis gives a “no” answer: • Change U by reducing Ci (code optimisation, faster processor, ...) or • Increase Ti for some process (can one do this?) Theorems • Optimality: RMS is optimal among methods with fixed priority (in what sense?) • Lowest upper bound: For arbitrarily large n, it suffices that processor utilisation is < 0.69 [Nice proofs in Buttazzo book] $B 2 Bonus points! Undergraduate course on Real-time Systems Linköping University 31 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 32 of 38 Autumn 2015 What does the test mean? Utilisation based test: G = n ( 2 1/n - 1) Example (5) Period (Ti) WCET (Ci) For a given n, the highest ceiling under which we only find schedulable task sets P1 P2 P3 20 7 50 10 30 5 U = 7/20 + 10/50 + 5/30 = 0,72 >0,69 but... < G = 0,78 (irrespective of release times, with all possible Ci, Ti) The schedulability of this task set is guaranteed! Undergraduate course on Real-time Systems Linköping University 33 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University Better methods needed For: • Processes with long WCET • Sporadic events • Processes with long period but short deadline • Run-time process dependence – specially in terms of overruns Did we fix these? 34 of 38 Autumn 2015 Summarising RMS • Processes with long WCET – RMS does not require splitting the code • Sporadic events – RMS only runs them when they arrive • Processes with long period but short deadline – Can allocate fixed priorities based on deadlines for the cases Di Ti - Deadline monotonic scheduling • Run-time process dependence – Overruns: highest priority task not affected! How about mutual access? Undergraduate course on Real-time Systems Linköping University 35 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 36 of 38 Autumn 2015 6 Dynamic priorities Earliest deadline first (EDF) • Online decision • Preemptive • Dynamic priorities • Next: We look at regimes that change priorities dynamically Policy: Always run the process that is closest to its deadline Undergraduate course on Real-time Systems Linköping University 37 of 38 Autumn 2015 Undergraduate course on Real-time Systems Linköping University 38 of 38 Autumn 2015 7