Presentation is loading. Please wait.

Presentation is loading. Please wait.

Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems.

Similar presentations


Presentation on theme: "Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems."— Presentation transcript:

1 Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems Laboratory Department of Computer and Information Science Linköping university 36 pages Autumn 2009

2 Undergraduate course on Real-time Systems Linköping University 2 of 36 Autumn 2009 Practical announcements Registration at webreg for TDDD07 Follow instructions on the web!

3 Undergraduate course on Real-time Systems Linköping University 3 of 36 Autumn 2009 Cyclic scheduling: What is the deadline for each process? How does one know that processes meet their deadlines? What happens if they don’t? From last lecture

4 Undergraduate course on Real-time Systems Linköping University 4 of 36 Autumn 2009 Better methods needed For: Processes with long WCET Sporadic events Processes with long period but short deadline Process dependence –sharing resources –overruns

5 Undergraduate course on Real-time Systems Linköping University 5 of 36 Autumn 2009 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!”

6 Undergraduate course on Real-time Systems Linköping University 6 of 36 Autumn 2009 RMS Rate Monotonic Scheduling: On-line Preemptive Priority-based with fixed (static) priorities

7 Undergraduate course on Real-time Systems Linköping University 7 of 36 Autumn 2009 Priorities Each process has a period T i that is the shortest interval between its release times Processes are assigned priorities dependent on length of T i – The shorter T i the higher the priority

8 Undergraduate course on Real-time Systems Linköping University 8 of 36 Autumn 2009 Example (4) P1 P2 P3 Period (Ti) 20 50 30 WCET (Ci)10 10 5 Priority high low medium

9 Undergraduate course on Real-time Systems Linköping University 9 of 36 Autumn 2009 Consider following scenario: arrival timeprocess 0P1, P2, P3 20 P1 30 P3 40P1 50P2 60P1, P3 0 10 20 30 40 50 60 80 90... preemption time

10 Undergraduate course on Real-time Systems Linköping University 10 of 36 Autumn 2009 Schedulability test Theorem: (sufficient condition) For n processes, RMS will guarantee their schedulability if the total utilisation U = C 1 /T 1 +... + C n /T n does not exceed the guarantee level G = n (2 1/n -1)

11 Undergraduate course on Real-time Systems Linköping University 11 of 36 Autumn 2009 U = 10/20+10/50+5/30 = 0,87 n = 3  G = 3(2 1/3 -1) = 0,78 Schedulability is not guaranteed! (but processes may still meet their deadlines...) For this example

12 Undergraduate course on Real-time Systems Linköping University 12 of 36 Autumn 2009 When the test fails Try with 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

13 Undergraduate course on Real-time Systems Linköping University 13 of 36 Autumn 2009 For example 4 scenario: arrival timeprocess 0P1, P2, P3 20 P1 30 P3 40P1 50P2 60P1, P3 0 10 20 30 40 50 60 80 90... preemption time

14 Undergraduate course on Real-time Systems Linköping University 14 of 36 Autumn 2009 Exact analysis Mathematical equations for computing worst case response times R i for each process Process set schedulable if R i ≤ T i for all processes Assumptions?

15 Undergraduate course on Real-time Systems Linköping University 15 of 36 Autumn 2009 Response time analysis Response time: the time between the release and the completion time Tasks suffer interference from higher priority tasks Iterative formula for calculating response time

16 Undergraduate course on Real-time Systems Linköping University 16 of 36 Autumn 2009 Not schedulabe task set When response time analysis gives a “no” answer: Change U by reducing C i (code optimisation, faster processor,...) or Increase T i for some process (can one do this?)

17 Undergraduate course on Real-time Systems Linköping University 17 of 36 Autumn 2009 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]

18 Undergraduate course on Real-time Systems Linköping University 18 of 36 Autumn 2009 What does the test mean? Utilisation based test: G = n ( 2 1/n - 1) For a given n, the highest ceiling under which we only find schedulable task sets (irrespective of release times, with all possible C i, T i )

19 Undergraduate course on Real-time Systems Linköping University 19 of 36 Autumn 2009 P 1 P 2 P 3 Period (T i ) 20 50 30 WCET (C i ) 7 10 5 U = 7/20 + 10/50 + 5/30 = 0,72 >0,69 but... < G = 0,78 The schedulability of this task set is guaranteed! Example (2)

20 Undergraduate course on Real-time Systems Linköping University 20 of 36 Autumn 2009 Dynamic priorities Allow –processes with long T i and short deadline –Process dependencies: when processes share resources and must be synchronised Next scheduling algorithm: change priorities dynamically

21 Undergraduate course on Real-time Systems Linköping University 21 of 36 Autumn 2009 Earliest deadline first (EDF) Online Preemptive Dynamic priorities Policy: Always run the process that is closest to its deadline

22 Undergraduate course on Real-time Systems Linköping University 22 of 36 Autumn 2009 Event that leads to release of process P i appears with minimum inter-arrival interval T i P i has a max computation time C i The process must be finished before its deadline D i  T i Processes are independent (do not share resources) EDF: The process with nearest absolute deadline (d i ) will run first Process sets

23 Undergraduate course on Real-time Systems Linköping University 23 of 36 Autumn 2009 Consider following processes: P 1 P 2 WCET (C i ) 510 Deadline (D i = T i ) 2012 Arrival times (r i )0, 20,... 0, 12,... 01015...? time 2025 Example (3)

24 Undergraduate course on Real-time Systems Linköping University 24 of 36 Autumn 2009 For same task set:P 1 P 2 WCET (C i )510 Deadline (D i = T i ) 2012 Arrival times (r i ) 0, 20,... 0, 12,... 01015 time 2025...? Preemption Compare to RMS

25 Undergraduate course on Real-time Systems Linköping University 25 of 36 Autumn 2009 Theorem A set of periodic tasks P 1,...,P n for which D i = T i is schedulable with EDF iff U= C 1 /T 1 +...+C n /T n  For Example 3: C 1 /T 1 + C 2 /T 2 = 5/20 + 10/12 = 1,08!

26 Undergraduate course on Real-time Systems Linköping University 26 of 36 Autumn 2009 Consider following task set:P 1 P 2 WCET (C i )24 Deadline (D i = T i )57 Is it schedulable? U = 2/5 + 4/7 = 0,97 Yes! Example (4)

27 Undergraduate course on Real-time Systems Linköping University 27 of 36 Autumn 2009 EDF vs. RMS EDF gives higher processor utilisation (Example 4 not schedulable with RMS!) EDF has simpler exact analysis for the mentioned type of task sets RMS can be implemented to run faster at run-time (if we ignore the time for context switching)

28 Undergraduate course on Real-time Systems Linköping University 28 of 36 Autumn 2009 Sharing resources Assume that processes synchronise using semaphores We schedule the processes with fixed priorities but relax the independence requirement

29 Undergraduate course on Real-time Systems Linköping University 29 of 36 Autumn 2009 Priority Inversion A low priority process (P 1 ) locks the resource A high priority process (P 2 ) has to wait on the semaphore (blocked state) A medium priority process (P 3 ) preempts P 1 and runs to completion before P 2 !

30 Undergraduate course on Real-time Systems Linköping University 30 of 36 Autumn 2009 How to avoid it? When P 2 is blocked by P 1 one raises the priority of P 1 to the same level as P 2 temporarily Afterwards, when the semaphore is released by P 1, it goes back to its prior priority level P 3 can not interrupt P 1 any more!

31 Undergraduate course on Real-time Systems Linköping University 31 of 36 Autumn 2009 Priority inheritance Is transitive Guarantees upper bound for blocking time, since high priority process P 2 is blocked only under the time that P 1 uses the resource But... Does not avoid deadlock!

32 Undergraduate course on Real-time Systems Linköping University 32 of 36 Autumn 2009 Example P1 P2 0 time S1 S2S1? Preemption Blocked S2? Blocked Inheritance Si Here denotes the process locks semaphore Si. Let P1 have lower priority than P2.

33 Undergraduate course on Real-time Systems Linköping University 33 of 36 Autumn 2009 Note that: blocked – when waiting for a resource (other than CPU) not dispatched or preempted - when waiting for CPU Terminology

34 Undergraduate course on Real-time Systems Linköping University 34 of 36 Autumn 2009 Ceiling Protocols e.g. Immediate priority Ceiling Protocol (ICP): A process that obtains its first resource inherits the resource’s ceiling priority - the highest priority among all processes that can possibly claim that resource Dynamic priority for a process is the max of own (fixed) priority and the ceiling values of all resources it has locked When a resource is released, the process priority returns to the normal level (or to another engaged resource’s ceiling)

35 Undergraduate course on Real-time Systems Linköping University 35 of 36 Autumn 2009 Properties A process is blocked max once by another process with lower priority The blocking delay is a function of the length of the critical section Do not even need to use semaphores!

36 Undergraduate course on Real-time Systems Linköping University 36 of 36 Autumn 2009 ICP & Deadlock The ICP prevents deadlocks (How?) Moreover, it prevents starvation (How?)


Download ppt "Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems."

Similar presentations


Ads by Google