3 2 Rate Monotonic Analysis l Assumptions 1



















































- Slides: 51
3. 2 Rate Monotonic Analysis l Assumptions – – – 1 A 1. No nonpreemptible parts in a task, and negligible preemption cost A 2. Resource constraint on CPU time only A 3. No precedence constraints among tasks A 4. All tasks periodic A 5. Relative deadline = period Spring 2002 Real-Time Systems (Shin)
Rate-Monotonic Scheduling(RMS) l Overview – rate monotonic priority l – – the higher rate, the higher priority schedulability guaranteed if utilization rate is below a certain limit for feasible schedules l fi l 2 = 1/Ti : frequency (=rate) ci or Ci : execution time Spring 2002 Real-Time Systems (Shin)
(continued) – If the total utilization rate has least upper bound n(21/n - 1) where n = #tasks, there exists a feasible rate monotonic schedule. That is, l l – priority inversion problem l 3 U(1) = 1. 0, U(2) = 0. 828, U(3) = 0. 779, U(∞) = ln 2 only sufficient condition if a more critical task has a longer period Spring 2002 Real-Time Systems (Shin)
Rate Monotonic Analysis(RMA) Basic theory with periodic tasks l Introduction – Rate monotonic analysis(RMA) l l l 4 a method for analyzing sets of real-time tasks based on rate monotonic scheduling theory analytic formulas to determine schedulability framework for reasoning about system timing behavior separation of timing and functional concerns provides an engineering basis for designing real-time systems Spring 2002 Real-Time Systems (Shin)
(continued) – Basic theory applies only to independent, periodic tasks, but has been extended to address: l l l – Why are deadline missed? l l l 5 priority inversion task interactions aperiodic tasks preemption execution blocking Spring 2002 Real-Time Systems (Shin)
A Sample Problem Periodics Servers Aperiodics Emergency 100 msec 50 msec t 1 20 msec Data Server 5 msec 2 msec 150 msec 20 msec Deadline 6 msec after arrival t 2 40 msec Comm Server 350 msec 10 msec t 3 Routine 40 msec 2 msec 100 msec Desired response 4 msec average t 2’s 6 deadline is 20 msec before the end of each period Spring 2002 Real-Time Systems (Shin)
l Periodic tasks – – l 7 task’s CPU utilization Ui = Ci/Ti total CPU utilization U = Ui + U 2 + … + Un Utilization Bound(UB) Test – A set of n independent periodic tasks scheduled by the rate monotonic algorithm will always meet its deadlines, for all task phasings, if – for harmonic task sets, the utilization bound is U(n) = 1. 00 for all n. Spring 2002 Real-Time Systems (Shin)
l Sample Problem: Applying UB Test – Total utilization: 0. 200 + 0. 267 + 0. 286 = 0. 753 < U(3) = 0. 779 – 8 The periodic tasks in the sample problem are schedulable according to the UB test. Spring 2002 Real-Time Systems (Shin)
Timeline for Sample Problem 0 100 200 300 400 t 1 t 2 t 3 Scheduling Points 9 (scheduling point: a point in time when new work arrives worst-case phasing: all tasks are ready to execute at t=0) Spring 2002 Real-Time Systems (Shin)
l Exercise: Applying the UB Test Given: 10 a. What is utilization for each task? b. Is the task set schedulable? c. Draw the timeline. d. What is the total if C 3=2? Springutilization 2002 Real-Time Systems (Shin)
l Extension of UB test – UB test has three possible outcomes. l l l – – 11 0 ≤ U(n) success U(n) < U ≤ 1. 00 inconclusive 1. 00 < U overloaded UB test is conservative A more precise test can be applied. Spring 2002 Real-Time Systems (Shin)
l Schedulability: CT Test – Theorem l – 12 For a set of independent, periodic tasks, if each task meets its first deadline, with worst-case task phasing, the deadline will always be met. Completion Time Test l Let Wi = completion time of task i. Wi may be computed by the following iterative formula: l Task i is schedulable if its completion time is before its Spring 2002 Real-Time Systems (Shin) deadline. That is, Wi ≤ Ti
l Example: Applying CT Test – – Taking the sample problem, we increase the compute time of T 1 from 20 to 40. Is the task set still schedulable? Utilization of first two tasks: 0. 667 < U(2) = 0. 828 l – Utilization of all three tasks: 0. 953 > U(3) = 0. 779 l l 13 first two tasks are schedulable by utilization bound test is inconclusive need to apply completion time test Spring 2002 Real-Time Systems (Shin)
(continued) – 14 Use CT test to determine if task 3 meets its first deadline Spring 2002 Real-Time Systems (Shin)
(continued) Task 3 is schedulable using CT test. 15 Spring 2002 Real-Time Systems (Shin)
Example : Using Schedulability Points 0 100 200 300 400 t 1 t 2 t 3 Scheduling Points 16 Spring 2002 Real-Time Systems (Shin)
l Exercise: Applying CT Test Task τ1: C 1 = 1 Task τ2: C 2 = 1 Task τ3: C 3 = 1 17 T 1 = 4 T 2 = 4 T 3 = 4 a. Apply UB test. b. Draw timeline. c. Apply CT test. Spring 2002 Real-Time Systems (Shin)
l Summary – – – Utilization bound test is simple but conservative Completion time test is more exact but also more complicated To this point, UB and CT tests share the same limitations. l l l l 18 all tasks run on a single processor all tasks periodic and noninteracting deadlines always at the end of the period no interrupts rate monotonic priorities assigned zero context switch overhead tasks do not suspend themselves Spring 2002 Real-Time Systems (Shin)
Rate Monotonic Analysis(RMA) Extensions to basic theory l Extending the schedulability tests – – – l Task interactions – 19 nonzero task switching times preperiod deadlines priority inversion (blocking) synchronization(mutual exclusion) is required Spring 2002 Real-Time Systems (Shin)
l Integrating task switching times and preperiod deadlines – Task switching time can be modeled as execution time l – Preperiod deadline can be modeled as “dormant time” l 20 for task switching time S, Ui = (Ci+2 S)/Ti instead of Ui = Ci/Ti for preperiod deadline D, Ui = (Ci+D)/Ti applied for schedulability test on τi only C D T T Spring 2002 time Real-Time Systems (Shin)
l Example for task switching and preperiod deadline – 21 applying the UB Test to the sample problem Spring 2002 Real-Time Systems (Shin)
l Schedulability with interrupts – Interrupt processing can be inconsistent with rate monotonic priority assignment l l – Effects of interrupt processing must be taken into account in schedulability model. l 22 interrupt handler executes with high priority despite its period interrupt processing may delay execution of tasks with higher rate monotonic priority (shorter periods) higher priority tasks regard the interrupt as blocking factor. (source of priority inversion) Spring 2002 Real-Time Systems (Shin)
l Priority inversion – – – 23 Delay to a task’s execution caused by interference from lower-priority tasks is known as priority inversion. Priority inversion is modeled by blocking time. Identifying, modeling and reducing sources of priority inversion is central to schedulability analysis. Spring 2002 Real-Time Systems (Shin)
l Sources of priority inversion non-preemptable regions of code – interrupts – non-unique priorities for some tasks (if there are not enough priority levels) – non-rate-monotonic assignment of task priorities – FIFO queues – synchronization and mutual exclusion – 24 Spring 2002 Real-Time Systems (Shin)
l Accounting for priority inversion – Recall that task schedulability is affected by: l l l – 25 preemption: potentially many times period execution: once period blocking: at most once period for each source The schedulability formulas are modified to add a “blocking” or “priority inversion” term to account for inversion effects. Spring 2002 Real-Time Systems (Shin)
Adding blocking time to schedulability test 0 t 1 100 I 0 100 t 1 For t 2 For t 4 200 t 1 t 2 For I 0 100 200 300 400 t 1 t 2 Interrupt I I t 4 26 Spring 2002 Real-Time Systems (Shin)
l UB test with blocking – Before considering priority inversion, we simply tested the total utilization for n tasks: – Now we must test each task for schedulability. The general schedulability test is: – 27 Spring 2002 Real-Time Systems (Shin)
l CT test with blocking – – A set of periodic tasks, scheduled according to the rate monotonic policy, is schedulable if each task meets its first deadline. That is, if completion time of each task, Wi, is less than or equal to its deadline. blocking execution 28 Spring 2002 preemption Real-Time Systems (Shin)
l Exercise: Schedulability with priority inversion Given: (where τ3 is nonpreemptive ) a. fill in column B b. construct a schedulability model c. which tasks are schedulable? 29 Spring 2002 Real-Time Systems (Shin)
l Synchronization problem – – analyze the effects of task interactions on schedulability in this discussion l 30 synchronization = mutual exclusion Spring 2002 Real-Time Systems (Shin)
Sample Problem : Synchronization Periodics Servers 100 msec 20 msec t 1 Data Server Aperiodics Emergency 50 msec 5 msec 2 msec 150 msec 20 msec Deadline 6 msec after arrival 40 msec t 2 Comm Server 350 msec 10 msec t 3 Routine 40 msec 2 msec 100 msec Desired response 4 msec average t 2’s 31 deadline is 20 msec before the end of each period. Spring 2002 Real-Time Systems (Shin)
Synchronization Model Legend Critical section Executing t 1: {…P(S)…V(S)…} Blocked t 3: {…P(S)…V(S)…} attempts to lock S (blocked) S locked B S unlocked τ1(H) τ2(M) S locked S unlocked τ3(L) 32 Time Spring 2002 Real-Time Systems (Shin)
Priority Inversion in Synchronization Legend t 1: {…P(S 1)…V(S 1)…} S 1 locked t 3: {…P(S 1)…V(S 1)…} Executing attempts to lock S 1 (blocked) S 1 unlocked B τ1(H) τ2(M) S 1 locked S 1 unlocked τ3(L) 33 Time Spring 2002 Real-Time Systems (Shin) B
l Synchronization protocols – – v 34 no preemption highest locker’s priority basic priority inheritance priority ceiling Each protocol prevents unbounded priority inversion Spring 2002 Real-Time Systems (Shin)
Nonpreemption Protocol Legend t 2: {…P(S 1)…V(S 1)…} S 1 locked t 4: {…P(S 1)…V(S 1)…} Ready Executing Blocked B τ1(H) Ready τ2 Ready τ3 S 1 locked S 1 unlocked τ4(L) Time 35 Spring 2002 Real-Time Systems (Shin) B
Highest Locker’s Priority Protocol Legend t 2: {…P(S 1)…V(S 1)…} t 4: {…P(S 1)…V(S 1)…} S 1 locked Executing Blocked τ1(H) Ready τ2 B B Ready τ3 S 1 locked S 1 unlocked τ4(L) Time 36 Spring 2002 Real-Time Systems (Shin) B
Basic Inheritance Protocol (BIP) Legend t 2: {…P(S 1)…V(S 1)…} t 4: {…P(S 1)…V(S 1)…} S 1 locked Executing Blocked τ1(H) Attempts to lock S 1 locked S 1 unlocked Ready B τ2 Ready τ3 S 1 locked S 1 unlocked τ4(L) Time 37 Spring 2002 Real-Time Systems (Shin) B
Priority Ceiling Protocol (PCP) Legend t 2: {…P(S 1)…V(S 1)…} t 4: {…P(S 1)…V(S 1)…} S 1 locked Executing Blocked τ1(H) Attempts to lock S 1 locked S 1 unlocked Ready B τ2 Ready τ3 S 1 locked S 1 unlocked τ4(L) Time 38 Spring 2002 Real-Time Systems (Shin) B
l Priority ceiling – priority ceiling of a semaphore S l l – simply the priority of the highest priority task that may lock semaphore S “system” ceiling: the maximum ceiling of all semaphores currently locked by other tasks the idea behind PCP τ (high) l to create a total priority ordering of executing and suspended critical sections τ (low) S priority ceiling of semaphore S is the priority of τ (high) 39 Spring 2002 Real-Time Systems (Shin)
l Priority ceililng protocol(PCP) rules – – – Preemption: A task with a higher execution priority always preempts tasks with lower execution priorities. Ceiling: A task cannot enter its critical section unless its priority is higher than the system ceiling. Inheritance: A lower priority task that blocks a higher priority task Th inherits the priority of task T h. [When there is only one semaphore, PCP works just like BIP. ] 40 Spring 2002 Real-Time Systems (Shin)
l PCP rules - revisited – 1. when T wants to enter the c. s. l l – 2. while running inside the c. s. l – can preempt a lower priority task 4. when T completes execution normally l 41 always inherits highest priority among the blocked 3. When T does not want to enter the c. s. l – its priority must be higher than system ceiling when exiting, wake up the highest priority task among the blocked if there are many tasks of same priority ready for execution, schedule the task blocking other tasks Spring 2002 Real-Time Systems (Shin)
PCP Example J 0 = { …, P(S 0), …, V(S 0), … } J 1 = { …, P(S 1), …, P(S 2), …, V(S 1), … } J 2 = { …, P(S 2), …, P(S 1), …, V(S 2), … } Critical section guarded by S 0 locked S 1 S 2 S 0 unlocked J 0 S 1 locked Blocked by J 2 S 2 locked S 2 unlocked S 1 unlocked (attempt to lock S 1) J 1 S 1 unlocked S 1 locked S 2 unlocked S 2 locked J 2 time t 0 42 t 1 t 2 t 3 t 4 t 5 t 6 Spring 2002 t 7 t 8 t 9 t 10 t 11 t 12 t 13 Real-Time Systems (Shin)
PCP Example J 0 = { …, P(S 0), …, V(S 0), …, P(S 1), …, V(S 1), . . . } J 1 = { …, P(S 2), …, V(S 2), … } J 2 = { …, P(S 2), …, P(S 1), …, V(S 2), … } Critical section guarded by S 0 S 1 S 2 S 0 unlocked S 1 unlocked S 0 locked J 0 blocked by J 2 (attempt to lock S 1) (attempt to lock S 0) blocked by J 2 J 1 S 2 locked S 1 locked S 2 locked S 1 unlocked S 2 unlocked J 2 time t 0 43 t 1 t 2 t 3 t 4 t 5 t 6 Spring 2002 t 7 t 8 t 9 t 10 t 11 t 12 t 13 t 14 Real-Time Systems (Shin)
Example Of Chained Blocking (BIP) t 1: {…P(S 1)…P(S 2)…V(S 2). . . V(S 1)…} Legend t 2: {…P(S 1)…V(S 1)…} S 1 locked t 3: {…P(S 2)…V(S 2)…} S 2 locked Blocked Attempts to lock S 1 (blocked) τ1(H) τ2(M) B B S 1 locked B Attempts to lock S 2 (blocked) B S 1 unlocked S 2 unlocked τ3(L) Time 44 Spring 2002 Real-Time Systems (Shin)
Blocked At Most Once (PCP) t 1: {…P(S 1)…P(S 2)…V(S 2). . . V(S 1)…} Legend t 2: {…P(S 1)…V(S 1)…} S 1 locked t 3: {…P(S 2)…V(S 2)…} S 2 locked S 1 locked S 2 unlocked S 1 locked Ceiling S 1 unlocked Attempts to lock S 1 (blocked) τ1(H) Attempts to lock S 1 (blocked) S 1 locked S 1 unlocked τ2(M) S 2 locked S 2 unlocked τ3(L) Time 45 Spring 2002 Real-Time Systems (Shin)
Deadlock: Using BIP Legend t 1: {…P(S 1)…P(S 2)…V(S 2). . . V(S 1)…} S 1 locked t 2: {…P(S 2)…P(S 1)…V(S 1). . . V(S 2)…} S 2 locked B attempts to lock S 2 (blocked) locks S 1 τ1(H) B S 2 locked Attempts to lock S 1 (blocked) τ2(M) Time 46 Spring 2002 Real-Time Systems (Shin)
Deadlock Avoidance: Using PCP t 1: {…P(S 1)…P(S 2)…V(S 2). . . V(S 1)…} Legend t 2: {…P(S 2)…P(S 1)…V(S 1). . . V(S 2)…} S 1 locked S 2 locked Ceiling locks S 2 attempts to lock S 1 (blocked) B locks S 1 τ1(H) locks S 2 locks S 1 unlocks S 2 τ2(M) Time 47 Spring 2002 Real-Time Systems (Shin)
l Summary of synchronization protocols – No preemption l – Highest locker’s priority l – when a lower priority task blocks the execution of a higher priority task, it inherits the priority of the task it blocks Priority ceiling l 48 execute critical sections with the priority of the highest priority task that may lock the semaphore Priority inheritance l – do not allow preemption during execution of critical sections priority inheritance plus priority ceiling rule for locking semaphores Spring 2002 Real-Time Systems (Shin)
(continued) l 49 Summary of synchronization protocols 1 Only if tasks do not suspend within critical sections 2 PCP is not affected if tasks suspend within critical sections. Spring 2002 Real-Time Systems (Shin)
l Sample Problem: Using BIP D: preperiod deadline 50 Spring 2002 Real-Time Systems (Shin)
Schedulability model using BIP C 1 T 1 51 B 1 T 20 100 U (1) 1 D 2 C 2 T 2 C 2 T U (2) 2 C 3 T T 2 B 2 U (3) 3 Spring 2002 20 100 30 100 40 0. 50 1. 0 20 10 150 40 100 150 350 0. 667 0. 828 0. 753 0. 779 Real-Time Systems (Shin)



















































