# T i - Homepages

```3.2 Rate Monotonic Analysis

Assumptions
–
–
–
–
–
1
A1. No nonpreemptible parts in a task, and
negligible preemption cost
A2. Resource constraint on CPU time only
A3. No precedence constraints among tasks
Spring 2002
Real-Time Systems (Shin)
Rate-Monotonic Scheduling(RMS)

Overview
–
rate monotonic priority

–
–
the higher rate, the higher priority
schedulability guaranteed if utilization rate is
below a certain limit
for feasible schedules
 fi

2
= 1/Ti : frequency (=rate)
ci or Ci : execution time
n
c
i 1
i
fi 1
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,
n
c f
i i


–
 n(2  1)  U (n)
i 1
U(1) = 1.0, U(2) = 0.828, U(3) = 0.779, U(∞) = ln2
only sufficient condition
priority inversion problem

3
1
n
if a more critical task has a longer period
Spring 2002
Real-Time Systems (Shin)
Rate Monotonic Analysis(RMA)

Introduction
–
Rate monotonic analysis(RMA)






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



–



5
priority inversion
preemption
execution
blocking
Spring 2002
Real-Time Systems (Shin)
A Sample Problem
Periodics
Servers
Aperiodics
Emergency
100 msec
50 msec
1
20 msec
Data Server
5 msec
2 msec
150 msec
20 msec
after arrival
2
40 msec
Comm Server
350 msec
10 msec
10 msec
3
Routine
40 msec
2 msec
100 msec
Desired response
4 msec average
2’s deadline is 20 msec before the end of each period
6
Spring 2002
Real-Time Systems (Shin)

–
–

task’s CPU utilization Ui = Ci/Ti
total CPU utilization U = Ui + U2 + … + 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
1
Cn
C1 C2

 ...
 U (n)  n(2 n  1)
T1 T2
Tn
–
7
for harmonic task sets, the utilization bound is U(n) = 1.00
for all n.
Spring 2002
Real-Time Systems (Shin)

Sample Problem: Applying UB Test
C T
U
–
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
1
2
3
Scheduling Points
9
(scheduling point: a point in time when new work arrives
Spring 2002
Real-Time Systems (Shin)

10
Exercise: Applying the UB Test
Given:
C
T
1
4
τ 1
2
6
τ 2
1
10
τ 3
U
a. What is utilization for each task?
b. Is the task set schedulable?
c. Draw the timeline.
d. What is the total
if C3=2?
Springutilization
2002
Real-Time Systems (Shin)

Extension of UB test
–
UB test has three possible outcomes.



–
–
11
0 ≤ U ≤ U(n)  success
U(n) < U ≤ 1.00  inconclusive
UB test is conservative
A more precise test can be applied.
Spring 2002
Real-Time Systems (Shin)

Schedulability: CT Test
–
Theorem

–
For a set of independent, periodic tasks, if each task meets its
always be met.
Completion Time Test
Let Wi = completion time
of taski. Wi may be computed by the

W
i (n)
following
iterative
formula:
W (n  1)  C 
C where W (0)  0

i
12

i

j i
 Tj


j
i
Task i is schedulable if its completion time is before its
Spring 2002
Real-Time Systems (Shin)
deadline. That is, Wi ≤ Ti

Example: Applying CT Test
–
–
Taking the sample problem, we increase the
compute time of T1 from 20 to 40. Is the task set
still schedulable?
Utilization of first two tasks: 0.667 < U(2) = 0.828

–
Utilization of all three tasks: 0.953 > U(3) = 0.779


13
first two tasks are schedulable by utilization bound test
utilization bound test is inconclusive
need to apply completion time test
Spring 2002
Real-Time Systems (Shin)
–
14
(continued)
0
W3 (1CT
) test
C3 todetermine
 100
Use
3 meets its first
j 3  T j 
100
W3 (2)  C3   
C j
j 3  T j 
100
100
 100 
(40)  
(40)  180


100
150
180
180
W3 (3)  100 
(40)  
(40)  260


100
150
Spring 2002
Real-Time Systems (Shin)
W3 (3)  260
 260
 260
(continued)
W3 (4)  100 
(
40
)

(
40
)

300



100
150




 300
 300
W3 (4)  100 
(40)  
(40)  300  Done!


 100
 150
W3  300  T3  350
Task 3 is schedulable using CT test.
15
Spring 2002
Real-Time Systems (Shin)
Example : Using Schedulability Points
0
100
200
300
400
1
2
3
Scheduling Points
16
Spring 2002
Real-Time Systems (Shin)

Exercise: Applying CT Test
17
T1 = 4
T2 = 4
T3 = 4
a. Apply UB test.
b. Draw timeline.
c. Apply CT test.
Spring 2002
Real-Time Systems (Shin)

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.







18
all tasks run on a single processor
deadlines always at the end of the period
no interrupts
rate monotonic priorities assigned
Spring 2002
Real-Time Systems (Shin)
Rate Monotonic Analysis(RMA)
Extensions to basic theory

Extending the schedulability tests
–
–
–

–
19
priority inversion (blocking)
synchronization(mutual exclusion) is required
Spring 2002
Real-Time Systems (Shin)

–
Task switching time can be modeled as execution
time

–
Preperiod deadline can be modeled as “dormant
time”

20
for task switching time S, Ui = (Ci+2S)/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)

–
1
21
applying
(C the2SUB
) Test to the sample problem
1
T1
 U (1)
2
(C1  2S ) (C2  2S  D2 )

 U (2)
T1
T2
3
(C1  2S ) (C2  2S ) (C3  2S )


 U (3)
T1
T2
T3
Spring 2002
Real-Time Systems (Shin)

Schedulability with interrupts
–
Interrupt processing can be inconsistent with rate monotonic
priority assignment


–
Effects of interrupt processing must be taken into account in
schedulability model.

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)

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)

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)

Accounting for priority inversion
–
Recall that task schedulability is affected by:



–
25
preemption: potentially many times 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.
Spring 2002
Real-Time Systems (Shin)
Adding blocking time to schedulability test
0
1
100
For 1
I
0
100
200
1
For 2
2
I
0
100
200
300
400
1
2
Interrupt
I
I
For 4
4
26
Spring 2002
Real-Time Systems (Shin)

UB test with blocking
–
Cn
C1 C2priority inversion,
Before considering
we simply tested the


...


U
( n)
total utilization
for
n
T T
T
1
–
–
n
Now we must test each task for schedulability.
k 1general schedulability test is:
The
C C
B
T
i 1
27
2
i
i

k
Tk

k
Tk
Spring 2002
 U (n) , k  1, 2, ..., n
Real-Time Systems (Shin)

CT test with blocking
–
–
A set of periodic tasks, scheduled according to the rate
monotonic policy, is schedulable if each task meets its first
That is, if completion time of each task, Wi, is less than or
Wi (k ) 
Wi (k  1)  Bi  Ci   
Cj
j i  T j

blocking execution preemption
28
Spring 2002
Real-Time Systems (Shin)

Exercise: Schedulability with priority
inversion
T
D
U
B
Given: (where
1 τ3 is4 nonpreemptive
0.250)
τ
τ
τ
29
1
2
3
2
1
6
10
1
0.334
0.100
a. fill in column B
b. construct a schedulability model
schedulable?
Spring
2002
Real-Time Systems (Shin)

Synchronization problem
–
–
analyze the effects of task interactions on
schedulability
in this discussion

30
synchronization = mutual exclusion
Spring 2002
Real-Time Systems (Shin)
Sample Problem : Synchronization
Periodics
Servers
100 msec
Aperiodics
Emergency
50 msec
1
20 msec
Data Server
5 msec
2 msec
150 msec
2
20 msec
40 msec
Comm Server
350 msec
10 msec
10 msec
3
after arrival
Routine
40 msec
2 msec
100 msec
Desired response
4 msec average
2’s deadline is 20 msec before the end of each period.
31
Spring 2002
Real-Time Systems (Shin)
Synchronization Model
Legend
Critical section
Executing
1:{…P(S)…V(S)…}
3:{…P(S)…V(S)…}
attempts to lock S (blocked)
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
1:{…P(S1)…V(S1)…}
3:{…P(S1)…V(S1)…}
Executing
S1 locked
attempts to lock S1 (blocked)
τ1(H)
τ2(M)
S1 locked
S1 unlocked
Blocked
B
S1 locked
S1 unlocked
τ3(L)
33
Time
Spring 2002
Real-Time Systems (Shin)
B

Synchronization protocols
–
–
–
–

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
2:{…P(S1)…V(S1)…}
4:{…P(S1)…V(S1)…}
S1 locked
Executing
Blocked
B
τ1(H)
τ2
τ3
S1 locked
S1 unlocked
τ4(L)
Time
35
Spring 2002
Real-Time Systems (Shin)
B
Highest Locker’s Priority Protocol
2:{…P(S1)…V(S1)…}
4:{…P(S1)…V(S1)…}
Legend
S1 locked
Executing
Blocked
τ1(H)
τ2
B
B
τ3
S1 locked
S1 unlocked
τ4(L)
Time
36
Spring 2002
Real-Time Systems (Shin)
B
Basic Inheritance Protocol (BIP)
2:{…P(S1)…V(S1)…}
4:{…P(S1)…V(S1)…}
Legend
S1 locked
Executing
Blocked
τ1(H)
Attempts to lock S1
S1 locked
S1 unlocked
B
τ2
τ3
S1 locked
S1 unlocked
τ4(L)
Time
37
Spring 2002
Real-Time Systems (Shin)
B
Priority Ceiling Protocol (PCP)
2:{…P(S1)…V(S1)…}
4:{…P(S1)…V(S1)…}
Legend
S1 locked
Executing
Blocked
τ1(H)
Attempts to lock S1
S1 locked
S1 unlocked
B
τ2
τ3
S1 locked
S1 unlocked
τ4(L)
Time
38
Spring 2002
Real-Time Systems (Shin)
B

Priority ceiling
–
priority ceiling of a semaphore S


–
simply the priority of the highest priority task that may lock
semaphore S
“system” ceiling: the maximum ceiling of all semaphores
the idea behind PCP
τ (high)
 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)

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
[When there is only one semaphore, PCP works just like
BIP.]
40
Spring 2002
Real-Time Systems (Shin)

PCP rules - revisited
–
1. when T wants to enter the c. s.


–
2. while running inside the c. s.

–
can preempt a lower priority task
4. when T completes execution normally

41
always inherits highest priority among the blocked
3. When T does not want to enter the c. s.

–
its priority must be higher than system ceiling
when exiting, wake up the highest priority task among the
blocked
Spring 2002
Real-Time Systems (Shin)
PCP
Example
J0 = { …, P(S0), …, V(S0), … }
J1 = { …, P(S1), …, P(S2), …, V(S2), …, V(S1), … }
J2 = { …, P(S2), …, P(S1), …, V(S1), …, V(S2), … }
Critical section guarded by
S0
S0 locked
S1
S2
S0 unlocked
J0
S1 locked
Blocked by J2
S2 locked S2 unlocked
S1 unlocked
(attempt to
lock S1)
J1
S1 unlocked
S1 locked
S2 unlocked
S2 locked
J2
t0
42
t1
t2
t3
t4
t5
t6
Spring 2002
t7
t8
t9
t10 t11 t12 t13
time
Real-Time Systems (Shin)
PCP
Example
J0 = { …, P(S0), …, V(S0), …, P(S1), …, V(S1), ... }
J1 = { …, P(S2), …, V(S2), … }
J2 = { …, P(S2), …, P(S1), …, V(S1), …, V(S2), … }
Critical section guarded by
S0
S1
S2
S0 unlocked S1 locked
S1 unlocked
S0 locked
J0
blocked by J2
(attempt to lock S1)
(attempt to lock S0)
blocked by J2
S2 locked
S2 unlocked
J1
S2 locked
S1 locked
S1 unlocked
S2 unlocked
J2
t0
43
t1
t2
t3
t4
t5
t6
Spring 2002
t7
t8
t9
t10 t11 t12 t13 t14
time
Real-Time Systems (Shin)
Example Of Chained Blocking (BIP)
1:{…P(S1)…P(S2)…V(S2)...V(S1)…}
2:{…P(S1)…V(S1)…}
3:{…P(S2)…V(S2)…}
Legend
S1 locked
S2 locked
Blocked
Attempts to lock S1 (blocked)
τ1(H)
τ2(M)
B
B
S1 locked
B
Attempts to lock S2 (blocked)
B
S1 unlocked
S2 locked
S2 unlocked
τ3(L)
Time
44
Spring 2002
Real-Time Systems (Shin)
Blocked At Most Once (PCP)
1:{…P(S1)…P(S2)…V(S2)...V(S1)…}
2:{…P(S1)…V(S1)…}
3:{…P(S2)…V(S2)…}
Legend
S1 locked
S2 locked
S1 locked S2 unlocked
S1 locked
Ceiling
S1 unlocked
Attempts to lock S1 (blocked)
τ1(H)
Attempts to lock S1 (blocked)
S1 locked
S1 unlocked
τ2(M)
S2 locked
S2 unlocked
τ3(L)
Time
45
Spring 2002
Real-Time Systems (Shin)
Legend
1:{…P(S1)…P(S2)…V(S2)...V(S1)…}
2:{…P(S2)…P(S1)…V(S1)...V(S2)…}
S1 locked
S2 locked
Blocked
B
attempts to lock S2 (blocked)
locks S1
τ1(H)
B
S2 locked
Attempts to lock S1 (blocked)
τ2(M)
Time
46
Spring 2002
Real-Time Systems (Shin)
1:{…P(S1)…P(S2)…V(S2)...V(S1)…}
2:{…P(S2)…P(S1)…V(S1)...V(S2)…}
Legend
S1 locked
S2 locked
Ceiling
B
locks S2
attempts to lock S1 (blocked)
locks S1
τ1(H)
locks S2
locks S1
unlocks S1 unlocks S2
τ2(M)
Time
47
Spring 2002
Real-Time Systems (Shin)

Summary of synchronization protocols
–
No preemption

–
Highest locker’s priority

–
when a lower priority task blocks the execution of a higher
Priority ceiling

48
execute critical sections with the priority of the highest priority
task that may lock the semaphore
Priority inheritance

–
do not allow preemption during execution of critical sections
priority inheritance plus priority ceiling rule for locking
semaphores
Spring 2002
Real-Time Systems (Shin)
Bounded
(continued)
priority
 Summary
most once aviodance
Protocol of synchronization protocols
inversion
Nonpremptible
Yes1
Yes1
Yes
critical sections
Highest locker’s
Yes1
Yes1
Yes
priority
No
No
Yes
Basic inheritance
Yes
Yes2
Yes
Priority ceiling
1 Only if tasks do not suspend within critical sections
2 PCP is not affected if tasks suspend within critical sections.
49
Spring 2002
Real-Time Systems (Shin)

C
T
D
B
Sample Problem: Using BIP
T1
20 100
30
T2
40
150
T3
100
350
20
10
50
Spring 2002
Real-Time Systems (Shin)
Schedulability model using BIP
C1

T1
C1

T1
C1

T1
51


B1

T1


100
C2  D2

T2
C2
20
U (1)

C3
B2

T2
 
 

T
T
2

U (2)
3

100

0.50  1.0
 20

20
  

100
Spring 2002
30
10
   

20
100
U (3)

40
150
0.667  0.828
150
40
100
150
350
0.753  0.779
Real-Time Systems (Shin)
```
Computer science

25 Cards

ARM architecture

23 Cards

MSN

28 Cards