Carnegie Mellon University Software Engineering Institute Guaranteeing Real-Time Performance Using Rate Monotonic Analysis
Embedded Systems Conference September 20-23, 1994
Presented by Ray Obenza Software Engineering Institute Carnegie Mellon University Pittsburgh PA 15213 Sponsored by the U.S. Department of Defense Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis Introduction Periodic tasks Extending basic theory Synchronization and priority inversion Aperiodic servers Case study: BSY-1 Trainer
1 Introduction
Carnegie Mellon University Software Engineering Institute Purpose of Tutorial
Introduce rate monotonic analysis Explain how to perform the analysis Give some examples of usage Convince you it is useful
2 Introduction
Carnegie Mellon University Software Engineering Institute Tutorial Format
Lecture Group exercises Case study Questions welcome anytime
3 Introduction
Carnegie Mellon University Software Engineering Institute RMARTS Project
Originally called Real-Time Scheduling in Ada Project (RTSIA). ¥ focused on rate monotonic scheduling theory ¥ recognized strength of theory was in analysis Rate Monotonic Analysis for Real-Time Systems (RMARTS) ¥ focused on analysis supported by (RMS) theory ¥ analysis of designs regardless of language or scheduling approach used Project focused initially on uniprocessor systems. Work continues in distributed processing systems.
4 Introduction
Carnegie Mellon University Software Engineering Institute Real-Time Systems
Timing requirements ¥ meeting deadlines Periodic and aperiodic tasks Shared resources Interrupts
5 Introduction
Carnegie Mellon University Software Engineering Institute What’s Important in Real-Time
Criteria for real-time systems differ from that for time- sharing systems. Time-Sharing Real-Time Systems Systems Capacity High throughput Schedulability Responsiveness Fast average Ensured worst- response case latency Overload Fairness Stability
¥ schedulability is the ability of tasks to meet all hard deadlines ¥ latency is the worst-case system response time to events ¥ stability in overload means the system meets critical deadlines even if all deadlines cannot be met
6 Introduction
Carnegie Mellon University Software Engineering Institute Scheduling Policies
CPU scheduling policy: a rule to select task to run next ¥ cyclic executive ¥ rate monotonic/deadline monotonic ¥ earliest deadline first ¥ least laxity first Assume preemptive, priority scheduling of tasks ¥ analyze effects of non-preemption later
7 Introduction
Carnegie Mellon University Software Engineering Institute Rate Monotonic Scheduling (RMS)
Priorities of periodic tasks are based on their rates: highest rate gets highest priority. Theoretical basis ¥ optimal fixed scheduling policy (when deadlines are at end of period) ¥ analytic formulas to check schedulability Must distinguish between scheduling and analysis ¥ rate monotonic scheduling forms the basis for rate monotonic analysis ¥ however, we consider later how to analyze systems in which rate monotonic scheduling is not used ¥ any scheduling approach may be used, but all real-
8 time systems should be analyzed for timing Introduction
Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis (RMA)
Rate monotonic analysis is a method for analyzing sets of real-time tasks. Basic theory applies only to independent, periodic tasks, but has been extended to address ¥ priority inversion ¥ task interactions ¥ aperiodic tasks Focus is on RMA, not RMS.
9 Introduction
Carnegie Mellon University Software Engineering Institute Why Are Deadlines Missed?
For a given task, consider ¥ preemption: time waiting for higher priority tasks ¥ execution: time to do its own work ¥ blocking: time delayed by lower priority tasks The task is schedulable if the sum of its preemption, execution, and blocking is less than its deadline. Focus: identify the biggest hits among the three and reduce, as needed, to achieve schedulability
10 Introduction
Carnegie Mellon University Software Engineering Institute Rate Monotonic Theory - Experience
IBM Systems Integration Division delivered a “schedulable” real-time network. Theory used successfully to improve performance of IBM BSY-1 Trainer. Incorporated into IEEE FutureBus+ standard Adopted by NASA Space Station Program European Space Agency requires as baseline theory. Supported in part by Ada vendors
11 Introduction
Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis - Products
Journal articles (e.g., IEEE Computer, Hot Topics) Videotape from SEI Courses from Telos and Tri-Pacific A Practitioner’s Handbook for Real-Time Analysis: Guide to Rate Monotonic Analysis for Real-Time Systems from Kluwer CASE tools from Introspect and Tri-Pacific Operating systems and runtimes from Alsys, DDC-I, Lynx, Sun, Verdix and Wind River Standards: Futurebus+, POSIX, Ada 9X
12 Introduction
Carnegie Mellon University Software Engineering Institute Summary
Real-time goals are: fast response, guaranteed deadlines, and stability in overload. Any scheduling approach may be used, but all real-time systems should be analyzed for timing. Rate monotonic analysis ¥ 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 13 Introduction
Carnegie Mellon University Software Engineering Institute Plan for Tutorial
Present basic theory for periodic task sets Extend basic theory to include ¥ context switch overhead ¥ preperiod deadlines ¥ interrupts Consider task interactions: ¥ priority inversion ¥ synchronization protocols (time allowing) Extend theory to aperiodic tasks: ¥ sporadic servers (time allowing) Present BSY-1 Trainer case study
14 Introduction
Carnegie Mellon University Software Engineering Institute A Sample Problem
PeriodicsServers Aperiodics
100 msec Emergency 50 msec !1 20 msec Data Server 5 msec
2 msec Deadline 6 msec 20 msec after arrival 150 msec
!2 40 msec Comm Server Routine 40 msec 10 msec 350 msec 10 msec 2 msec !3 100 msec Desired response 20 msec average
!2’s deadline is 20 msec before the end of each period
15 Introduction Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis
Introduction Periodic tasks Extending basic theory Synchronization and priority inversion Aperiodic servers Case Study: BSY-1 Trainer
1 Periodic Tasks Carnegie Mellon University Software Engineering Institute A Sample Problem - Periodics
PeriodicsServers Aperiodics
100 msec Emergency 50 msec !1 20 msec Data Server 5 msec
2 msec Deadline 6 msec 20 msec after arrival 150 msec
!2 40 msec Comm Server Routine 40 msec 10 msec 350 msec 10 msec 2 msec !3 100 msec Desired response 20 msec average
!2’s deadline is 20 msec before the end of each period.
2 Periodic Tasks Carnegie Mellon University Software Engineering Institute Concepts and Definitions - Periodics
Periodic task ¥ initiated at fixed intervals ¥ must finish before start of next cycle
C i Task’s CPU utilization: U = ----- i T i
¥ Ci = compute time (execution time) for task !i ¥ Ti = period of task !i CPU utilization for a set of tasks: UU= +++U U 1 2 " n
3 Periodic Tasks Carnegie Mellon University Software Engineering Institute Example of Priority Assignment Semantic-Based Priority Assignment
1 VIP: IP: UIP = 10 = 0.10 02511 VIP: UVIP = 25 = 0.44 misses deadline IP: 0102030
Policy-Based Priority Assignment IP: 0102030
VIP: 0 25
4 Periodic Tasks Carnegie Mellon University Software Engineering Institute Schedulability: UB Test
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 C C 1 n ------++... ------# Un()= n $%21/n Ð 1 T T 1 n
U(1) = 1.0 U(4) = 0.756 U(7) = 0.728 U(2) = 0.828 U(5) = 0.743 U(8) = 0.724 U(3) = 0.779 U(6) = 0.734 U(9) = 0.720 For harmonic task sets, the utilization bound is U(n)=1.00 for all n.
5 Note: UB test = Techniques 1 and 2 in handbook. Periodic Tasks Carnegie Mellon University Software Engineering Institute Sample Problem: Applying UB Test
CTU
Task !1: 20 100 0.200 Task !2: 40 150 0.267 Task&!3: 100 350 0.286 Total utilization is .200 + .267 + .286 = .753 < U(3) = .779 The periodic tasks in the sample problem are schedulable according to the UB test.
6 Periodic Tasks Carnegie Mellon University Software Engineering Institute Timeline for Sample Problem
0 100 200 300 400
!1
!2
!3
Scheduling Points
7 Periodic Tasks Carnegie Mellon University Software Engineering Institute Exercise: Applying the UB Test
Given: Task CTU 14 !' !2 26 110 !(
a. What is total utilization? b. Is the task set schedulable? c. Draw the timeline.
d. What is the total utilization if C3 = 2? 8 Periodic Tasks Carnegie Mellon University Software Engineering Institute Toward a More Precise Test
UB test has three possible outcomes:
0 ##UUn$%) Success Un$%* U # 1.00 ) Inconclusive 1.00 * U) Overload
UB test is conservative. A more precise test can be applied.
10 Periodic Tasks Carnegie Mellon University Software Engineering Institute Schedulability: RT Test
Theorem: 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.
Response time (RT) test: let an = response time of task i. an may be computed by the following iterative formula: i Ð 1 a i n a = C + + ------C where a &= + C n + 1 i T j 0 j j = 1 j j = 1
Test terminates when an+1 = an. Task i is schedulable if its response time is before its deadline: an < Ti
11 Periodic Tasks Carnegie Mellon University Software Engineering Institute Example: Applying RT Test -1
Taking the sample problem, we increase the compute time of !1 from 20 to 40; is the task set still schedulable? Utilization of first two tasks: 0.667 < U(2) = 0.828 ¥ first two tasks are schedulable by UB test Utilization of all three tasks: 0.953 > U(3) = 0.779 ¥ UB test is inconclusive ¥ need to apply RT test
&
12 Periodic Tasks Carnegie Mellon University Software Engineering Institute Example: Applying RT Test -2
Use RT test to determine if !3 meets its first deadline: i = 3 3 a ==C C +C +C = 40+ 40 + 100 = 180 0 + j 1 2 3 j = 1 i Ð 1 a 2 a 0 0 ==C + + ------C C + + ------C 1 i T j 3 T j j = 1 j j = 1 j
180 180 & &=== & 100 + &------$% 40& +& ------$%40 100+ 80 + 80 260 100 150
13 Periodic Tasks &
Carnegie Mellon University Software Engineering Institute Example: Applying the RT Test -3
2 a 1 260 260 ==C ++ ------C 100 ++------$%40 ------$%40 = 30 3 T j 100 150 j = 1 j 2 a 2 300 300 ==C ++ ------C 100 ++------$%40 ------$%40 = 30 3 T j 100 150 j = 1 j
a ==a 300 Done! 3 2
Task !3 is schedulable using RT test. a = 300 T = 350 3 *
14 Periodic Tasks
Carnegie Mellon University Software Engineering Institute Timeline for Example 0 100 200 300
!1
!2
!3
!3 completes its work at t = 300
15 Periodic Tasks & & &
Carnegie Mellon University Software Engineering Institute Exercise: Applying RT Test
Task !1: C1 = 1 T1 = 4
Task !2: C2 = 2 T2 = 6
Task !3: C3 = 2 T3 = 10 a) Apply UB test b) Draw timeline c) Apply RT Test
16 Periodic Tasks
Carnegie Mellon University Software Engineering Institute Exercise: Worksheet
0 5 10 15 20
Task_____
0 5 10 15 20
Task_____
0 5 10 15 20
Task_____
17 Periodic Tasks
Carnegie Mellon University Software Engineering Institute Summary
UB test is simple but conservative. RT test is more exact but also more complicated. To this point, UB and RT tests share the same limitations: ¥ all tasks run on a single processor ¥ all tasks are periodic and noninteracting ¥ deadlines are always at the end of the period ¥ there are no interrupts ¥ rate monotonic priorities are assigned ¥ there is zero context switch overhead ¥ tasks do not suspend themselves
19 Periodic Tasks Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis
Introduction
Periodic tasks
Extending basic theory
Synchronization and priority inversion
Aperiodic servers
Case study: BSY-1 Trainer
1 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Extensions to Basic Theory
This section extends the schedulability tests to address ¥ nonzero task switching times ¥ preperiod deadlines ¥ interrupts and non-rate-monotonic priorities
2 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Modeling Task Switching as Execution Time
Ci + 2S Ui = Ti
100 200 C1 0
' ! C1 C1 C1 C2
!, C2 C2
SSSC1 C2 SS !(
40 40 time
T1 T2 2T1 Two scheduling actions per task (start of period and end of period)
3 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Modeling Preperiod Deadlines
Suppose task !, with compute time C and period T, has a preperiod deadline D (i.e. D < T ).
Compare total utilization to modified bound:
C1 Cn Utotal = ------++ ... ------ & Un& (). -i T1 Tn
where -i is the ratio of Di to Ti . 341 n $%$%2- 1/n Ð 1 + 1 Ð - . --&- *& - # 1.0 12i i 2 i Un(). -i = 12 121 - . &- # --- & /0i i 2 4 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Schedulability with Interrupts
Interrupt processing can be inconsistent with rate monotonic priority assignment. ¥ interrupt handler executes with high priority despite its period ¥ interrupt processing may delay execution of tasks with shorter periods
Effects of interrupt processing must be taken into account in schedulability model.
Question is: how to do that?
5 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Example: Determining Schedulability with Interrupts CTU
Task !1: 20 100 0.200 Task !2: 40 150 0.267 Task&!3: 60 200 0.300 Task&!4: 40 350 0.115
!3 is an interrupt handler
6 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Example: Execution with Rate Monotonic Priorities
6 '66 ,66 (66 566
!'
!,
!(
!5
7 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Example: Execution with an Interrupt Priority
6 '66 ,66 (66 566
!'
!,
Interrupt
!5
8 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Resulting Table for Example
Task Period Execution Priority Deadline (i) (T) Time (P) (D) (C)
!3 200 60 HW 200 !1 100 20 High 100 !2 150 40 Medium 150 !4 350 40 Low 350
9 Extending Basic Theory Carnegie Mellon University Software Engineering Institute UB Test with Interrupt Priority
Test is applied to each task.
Determine effective utilization (f ) of each task i using i C C 1 f = -----j ++-----i ---- C i + T T T + k jHn7 j i ikH7 1
Preemption Execution Preemption from tasks that can of task under test from tasks that can hit more than once hit only once (with period less than Di) (with period greater than Di)
Compare effective utilization against bound, U(n). ¥ n = num(Hn) + 1
10 ¥ num(Hn) = the number of tasks in the set Hn Extending Basic Theory Carnegie Mellon University Software Engineering Institute
UB Test with Interrupt Priority: !3
For !3, no tasks have a higher priority: H = Hn = H1 = { }.
C3
f 3 = 0 ++ ------0 # &U $%1 & & T3
Note that utilization bound is U(1): num(Hn) = 0.
Plugging in numbers:
C3 60 f 3 ==------= 0.3* 1.0 T3 200
11 Extending Basic Theory Carnegie Mellon University Software Engineering Institute
UB Test with Interrupt Priority: !1
To !1, !3 has higher priority: H = {!3}; Hn = { }; H1 = {!3}.
C1 1 f = 0 +------+----- C U 1 1 + k #& $% T1 T1k = 3
Note that utilization bound is U(1): num(Hn) = 0.
Plugging in the numbers:
C1 C3 20 60 f 1 ==------+ ------+------= 0.800* 1.0 & & & & T1 T1 100 100
12 Extending Basic Theory Carnegie Mellon University Software Engineering Institute
UB Test with Interrupt Priority: !2
To !2: H = {!1.!3}; Hn = {!1}; H1 = {!3}.
C j C2 1 f = ----- ++------C U 2 2 + + k #& & $% j = 1 T j T2 T2k = 3
Note that utilization bound is U(2): num(Hn) = 1.
Plugging in the numbers:
C1 C2 C3 20 40 60 f 2 ==------++------+------+------= 0.867 8& 0.828 T1 T2 T2 100 150 150
13 Extending Basic Theory & & & && && & && && &
Carnegie Mellon University Software Engineering Institute
UB Test with Interrupt Priority: !4
To !2: H = {!1.!2.!3}; Hn = {!1.!2.!3}; H1 = {&}. C C f = -----j ++-----4- 0 #& U $%4 4 + T T j = 123.. j 4
Note that utilization bound is U(4): num(Hn) = 3.
Plugging in the numbers:
C1 C2 C3 C4 f 4 = ------+++------T1 T2 T3 T4 20 40 60 40 = ------+------+------+------= 0.882 &8 0.756 100 150 200 350
14 Extending Basic Theory & & &
Carnegie Mellon University Software Engineering Institute Exercise: Schedulability with Interrupts
Given the following tasks: Task Period Execution Priority Deadline (i) (T) Time (P) (D) (C)
!int 6 2 HW 6 !1 4 1 High 3 !2 10 1 Low 10
Use the UB test to determine which tasks are schedulable.
15 Extending Basic Theory
Carnegie Mellon University Software Engineering Institute Solution: Schedulability with Interrupts
Cint ------# U $%1 0.334* 1.0 Tint {H1} C C -----1- + ------int- # U $%1. .75 0.250+ 0.500 == 0.750 U $%1. .75 T1 T1
{Hn} C C C ------int- ++-----1------2- # U $%3 Tint T1 T2 0.334+ 0.250 + 0.100 = 0.684* 0.779
16 Extending Basic Theory &
Carnegie Mellon University Software Engineering Institute Basic Theory: Where Are We?
We have shown how to handle ¥ task context switching time: include 2S within C
¥ preperiod deadlines: change bound to U(n, -i) ¥ non-rate-montonic priority assignments
We still must address ¥ task interactions ¥ aperiodic tasks
We still assume ¥ single processor ¥ priority-based scheduling ¥ tasks do not suspend themselves 17 Extending Basic Theory
Carnegie Mellon University Software Engineering Institute Other Important Issues
Mode change
Multiprocessor systems
Priority granularity
Overload
Spare capacity assessment
Distributed systems
Post-period deadlines
18 Extending Basic Theory Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis Introduction Periodic tasks Extending basic theory
Synchronization and priority inversion Aperiodic servers Case study: BSY-1 Trainer
1 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Sample Problem: Synchronization
PeriodicsServers Aperiodics
100 msec Emergency 50 msec !1 20 msec Data Server 5 msec
2 msec Deadline 6 msec 20 msec after arrival 150 msec
!2 40 msec Comm Server Routine 40 msec 10 msec 350 msec 10 msec 2 msec !3 100 msec Desired response 20 msec average
!2’s deadline is 20 msec before the end of each period.
2 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Priority Inversion in Synchronization
Legend :{...P(S1)...V(S1)...} !' Critical section (S1 locked) !(:{...P(S1)...V(S1)...} Executing attempts to lock S1 (blocked) S1 locked S1 unlocked
Blocked B B !'(H)
!,(M) S1 locked S1 unlocked
!((L)
Time
3 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Priority Inversion
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 and evaluating the effect of sources of priority inversion is important in schedulability analysis.
4 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Sources of Priority Inversion
Synchronization and mutual exclusion
Non-preemptable regions of code
FIFO (first-in-first-out) queues
5 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Accounting for Priority Inversion
Recall that task schedulability is affected by ¥ preemption: two types of preemption - can occur several times per period - can only occur once per period ¥ execution: once per period ¥ blocking: at most once per period for each source
The schedulability formulas are modified to add a “blocking” or “priority inversion” term to account for inversion effects.
6 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute UB Test with Blocking
Include blocking while calculating effective utilization for each tasks:
C C B 1 f = ------j ++-----i -----i + ----- C i + T T T T + k jHn7 j i i ikH7 1
Hn Preemption && H1 Preemption && (can hit n times) Execution Blocking (can hit once)
7 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute RT Test with Blocking
Blocking is also included in the RT test: i Ð 1 a a = B + C + -----n C n + 1 i i + T j j = 1 j i
where a = B + C 0 & i + j j = 1
Perform test as before, including blocking effect.
8 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Example: Considering Blocking
Consider the following example:
Periodics tasks 100 msec
!1 25 msec Data Structure
200 msec 10 msec 30 msec !2 50 msec
300 msec
!3 100 msec
What is the worst-case blocking effect (priority inversion) experienced by each task?
9 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Example: Adding Blocking
Task !2 does not use the data structure. Task !2 experiences no priority inversion.
Task !1 shares the data structure with !3. Task !1 could have to wait for !3 to complete its critical section. But worse, if !2 preempts while !1 is waiting for the data structure.&!1 could have to wait for !2’s entire computation. This is the resulting table: Task Period Execution Priority Blocking Deadline Time Delays
!1 100 25 High 30+50 100 !2 200 50 Medium 0 200 !3 300 100 Low 0 300
10 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute UB Test for Example
Recall UB test with blocking:
C C B 1 f = ------j ++-----i -----i + ----- C i + T T T T + k jHn7 j i i ikH7 1
C1 B1 25 80 Not schedulable f 1 ==------+ ------+------= 1.058 1.00 T1 T1 100 100
C1 C2 25 50 f 2 ==------+ ------+------= 0.50 * U $%2 T1 T2 100 200
C1 C2 C3 25 50 100 f 3 ==------++------+------+------= 0.84 8 U $%3 T1 T2 T3 100 200 300 RT test shows !3 is schedulable 11 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Synchronization Protocols
No preemption Basic priority inheritance Highest locker’s priority Priority ceiling
Each protocol prevents unbounded priority inversion.
12 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Nonpreemption Protocol ! :{...P(S1)...V(S1)...} , Legend Ready ! :{...P(S1)...V(S1)...} 5 S1 locked
9 Executing !'(H) Blocked B
Ready
!,
Ready
!( S1 locked S1 unlocked
!5(L)
Time 13 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Basic Inheritance Protocol (BIP) :{...P(S1)...V(S1)...} !, Legend :{...P(S1)...V(S1)...} !5 S1 locked
Executing !'(H) Blocked B Attempts to lock S1 S1 locked S1 unlocked
Ready 9 !,
Ready
!( S1 locked S1 unlocked
!5(L)
Time
14 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Highest Locker’s Priority Protocol :{...P(S1)...V(S1)...} !, Legend :{...P(S1)...V(S1)...} !5 S1 locked
Executing !'(H) Blocked B Ready
9 9 !,
Ready
!( S1 locked S1 unlocked
!5(L)
Time
15 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Priority Ceiling Protocol (PCP)
!,:{...P(S1)...V(S1)...} Legend !5:{...P(S1)...V(S1)...} S1 locked
Executing !'(H) Attempts to lock S1 S1 locked S1 unlocked Blocked B
Ready 9 !,
Ready
!( S1 locked S1 unlocked
!5(L)
Time
16 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Example Of Chained Blocking (BIP)
!1:{...P(S1)...P(S2)...V(S2)...V(S1)...} Legend :{...P(S1)...V(S1)...} !, S1 locked
!(:{...P(S2)...V(S2)...} S2 locked
Attempts to lock S1 (blocked) Attempts to lock S2 (blocked) Blocked B
9 9 !'(H)
S1 locked S1 unlocked
!,(M)
S2 locked S2 unlocked
!((L)
012345678910111213 Time
17 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Blocked At Most Once (PCP)
!1:{...P(S1)...P(S2)...V(S2)...V(S1)...} Legend
!,:{...P(S1)...V(S1)...} S1 locked
!(:{...P(S2)...V(S2)...} S2 locked S2 locked S2 unlocked Ceiling C S1 locked S1 unlocked
Attempts to lock S1 (blocked)
C !'(H)
Attempts to lock S1 (blocked) S1 locked S1 unlocked
!,(M)
S2 locked S2 unlocked
!((L)
012345678910111213
18 Time Synchronization & Priority Inversion
Carnegie Mellon University Software Engineering Institute Deadlock: Using BIP
!1:{...P(S1)...P(S2)...V(S2)...V(S1)...} Legend
!,:{...P(S2)...P(S1)...V(S1)...V(S2)...} S1 locked
S2 locked
attempts to lock S2 (blocked) Blocked B locks S1
!'(H) B
S2 locked Attempts to lock S1 (blocked)
!,(M)
012345678910111213 Time
19 Synchronization & Priority Inversion
Carnegie Mellon University Software Engineering Institute Deadlock Avoidance: Using PCP
Legend !1:{...P(S1)...P(S2)...V(S2)...V(S1)...} S1 locked !,:{...P(S2)...P(S1)...V(S1)...V(S2)...} S2 locked
Ceiling C locks S2
attempts to lock S1 (blocked) locks S1
!'(H) C
locks S2 locks S1 unlocks S1 unlocks S2
!,(M)
012345678910111213 Time
20 Synchronization & Priority Inversion
Carnegie Mellon University Software Engineering Institute Summary of Synchronization Protocols
Bounded Blocked at Deadlock Protocol Priority Most Once Avoidance Inversion Nonpreemptible Yes Yes1 Yes1 critical sections Highest locker’s Yes Yes1 Yes1 priority Basic inheritance Yes No No Priority ceiling Yes Yes2 Yes
1 Only if tasks do not suspend within critical sections
2 PCP is not affected if tasks suspend within critical sections
21 Synchronization & Priority Inversion & & &
Carnegie Mellon University Software Engineering Institute Sample Problem with Synchronization
When basic priority inheritance protocol is used: Task Period Execution Priority Blocking Deadline Time Delays
!1 100 20 High 20+10 100 !2 150 40 Medium 10 130 !3 350 100 Low 0 350
22 Synchronization & Priority Inversion
Carnegie Mellon University Software Engineering Institute UB Test for Sample Problem
This format is sometimes called a schedulability model for the task set:
C1 B1 20 30 f 1 ==------+ ------+------= 0.500 * U $%1 T1 T1 100 100
C1 C2 B2 20 40 10 f 2 ==------++------+------+------= 0.534* 0.729 T1 T2 T2 100 150 150 U $%2. .80 = 0.729
C1 C2 C3 20 40 100 f 3 ==------++------+------+------= 0.753 * U $%3 T1 T2 T3 100 150 350
23 Synchronization & Priority Inversion Carnegie Mellon University Software Engineering Institute Rate Monotonic Analysis Introduction Periodic tasks Extending basic theory Synchronization and priority inversion
Aperiodic servers Case study: BSY-1 Trainer
1 Aperiodic Servers Carnegie Mellon University Software Engineering Institute Sample Problem: Aperiodics
PeriodicsServers Aperiodics
100 msec Emergency 50 msec !1 20 msec Data Server 5 msec
2 msec Deadline 6 msec 20 msec after arrival 150 msec
!2 40 msec Comm Server Routine 40 msec 10 msec 350 msec 10 msec 2 msec !3 100 msec Desired response 20 msec average
!2’s deadline is 20 msec before the end of each period.
2 Aperiodic Servers Carnegie Mellon University Software Engineering Institute Concepts and Definitions
Aperiodic task: runs at unpredictable intervals
Aperiodic deadline: ¥ hard, minimum interarrival time ¥ soft, best average response time
3 Aperiodic Servers Carnegie Mellon University Software Engineering Institute Scheduling Aperiodic Tasks Polling 0 100