Scheduling Periodic
Scheduling Periodic
1 2
time time
T:period
T:period
D: deadline D: deadline
R: release time R: release time
3 4
5 6
1
CPU utilization Scheduling periodic tasks
C/T is the CPU utilization of a task Assume a set of independent periodic tasks: (Ci,Ti)
U=Σ Ci/Ti is the CPU utilization of a task set Schedulability analysis:
Note that the CPU utilization is a measure on how busy the
is it possible to meet all deadlines in all periods?
processor could be during the shortest repeating cycle:
T1*T2*...*Tn A task set is schedulable/feasible if it can be scheduled so
that all instances of all tasks meet deadlines
U>1 (overload): some task will fail to meet its deadline no matter
what algorithms you use! If yes,
U<=1: it will depend on the scheduling algorithms how to schedule all task instances to meet all deadlines?
If U=1 and the CPU is kept busy (non idle algorithms e.g. EDF), all
deadlines will be met
Optimal scheduling algorithms?
7 8
9 10
Example: the Car Controller The car controller: static cyclic scheduling
Activities of a car control system. Let The cycle = 80ms
C= worst case execution time
The tasks within the cycle:
1.
2. T= (sampling) period
3. D= deadline
Speed measurment: C=4ms, T=20ms, D=20ms 0 20 40 60 80
ABS control: C=10ms,T=40ms, D=40ms Speed Speed Speed Speed
ABS ABS
Fuel injection: C=40ms,T=80ms, D=80ms
Fuel
Other software with soft deadlines e.g audio, air condition etc
11 12
2
The car controller: time table Static cyclic scheduling: + and –
80 0
4 Deterministic: predictable (+)
76 Soft RT tasks speed 14 Easy to implement (+)
ABS
Inflexible (-)
FUEL-4 Difficult to modify, e.g adding another task
FUEL-1 20 Difficult to handle external events
64
speed The table can be huge (-)
speed A feasible Schedule!
Huge memory-usage
24
Difficult to construct the time table
FUEL-3
60 Fuel-2
ABS
speed
54 40
44 13 14
15 16
Task set: {(2,5),(4,7)} Note that this is just the simple EDF algorithm; it works for all
types of tasks: periodic or non periodic
U = 2/5 + 4/7= 34/35 ~ 0.97 (schedulable!) It is simple and works nicely in theory (+)
Simple schedulability test: U <= 1 (+)
Optimal (+)
Best CPU utilization (+)
Difficult to implement in practice. It is not very often adopted
0 5 10 15 35 due to the dynamic priority-assignment (expensive to sort the
ready queue on-line), which has nothing to do with the periods
of tasks. Note that Any task could get the highest priority (-)
Non stable: if any task instance fails to meet its deadline, the
0 7 14 35 system is not predictable, any instance of any task may fail (-)
3
Rate Monotonic Scheduling: task model RMS: fixed/static-priority scheduling
19 20
Example Example
{(20,100),(40,150),(100,350)} Pr(T1)=1, Pr(T2)=2, Pr(T3)=3
Task set: T1=(2,5), T2=(4,7)
T1 20 20 20 20 U = 2/5 + 4/7= 34/35 ~ 0.97 (schedulable?)
0 100 200 300 RMS priority assignment: Pr(T1)=1, Pr(T2)=2
T2 40 40 40 0 2 5 10 15 35
0 150 300 Missing the deadline!
T3 40 30 10 20 0 2 5 7 14 35
0 350
21 22
23 24
4
UB test is only sufficient, not necessay! Example: Utilization bounds
25 26
40 30 10 20
0 350
27 28
0 10 20
29 30
5
How to deal with tasks with the same period RMS: Summary
31 32
33 34
6
Worst case response time calculation: example Calculation of worst case response times
[Mathai Joseph and Paritosh Pandya, 1986]
Response times?
{(1,3),(1,5),(1,6),(2,10)} Worst case? First period? Let Ri stand for the response time for task i. Then
Why? Ri= Ci + ∑j I(i,j)
WCR=1 Ci is the computing time
0 3 6 9 12 15 18 I(i,j) is the so-called interference of task j to i
I(i,j) = 0 if task i has higher priority than j
WCR=2
0 5 10 15 20 I(i,j) = Ri/Tj*Cj if task i has lower priority than j
You don’t have to
Check this area! x denotes the least integer larger than x
WCR=3 E.g 3.2 = 4, 3 =3, 1.9 =2
0 6 12 18
Ri= Ci + ∑j ∈ HP(i) Ri/Tj*Cj
WCR=9
0 10 20
39 40
Assume a task set: {(1,3),(1,5),(1,6),(2,10)} Calculate R3 and R4 for the above example
Question: is the task set schedulable? Construct the run-time RMS schedule and check if
Answer: YES your calculation is correct
Because
R11 = R10 = C1=1 (done)
R20 = C2 + C1=2,
R21 = C2 + R20/T1*C1=1+ 2/3*1=2 (done)
41 42
7
Example (combine UB test and precise test) Combine UB and Precise tests
Consider the task set: {(1,3),(1,5),(1,6),(3,10)} Order tasks according to their priorities (periods)
(this is not the previous example!)
CPU utilization U= 1/3+1/5+1/6+3/10=0.899> B(4)= 0.756 Use UB test as far as you can until you find the first
Fail the UB test! non-schedulable task
But U(3)= 1/3+1/5+1/6=0.699<B(3)=0.779 Calculate response time for the task and all tasks
This means that the first 3 tasks are schedulable with lower priority
Thus we do not need to calculate for R1, R2, R3!
Question: is task 4 set schedulable?
R40 = C1+C2+C3+C4= 6
R41 = C4+R40/T1*C1+R40/T2*C2+R40/T3*C3
= 3 + 6/3*1+6/5*1+6/6*1=8
R42 = C4+R41/T1*C1+R41/T2*C2+R41/T3*C3
= 3 + 8/3*1+8/5*1+8/6*1
= 3+4+2+2
= 11 (task 4 is non schedulable!) 43 44
45 46
Could we calculate the response times by the same How to handle precedence constraints?
equation for different priority assignment? We can always try the ’old’ method: static cyclic scheduling!
47 48
8
Summary: Three ways to check schedulability Summary: UB and precise test
49 50
51 52
Task 4 1 11 10
6 12
FACTS:
DMS is optimal 11
RMS is a special case of DMS R1=1
DMS is often refered as Rate Monotonic Scheduling
for historical reasons and they are so similar
R2=4
R3=3
R4=10
☺
53 54
9
DMS: Schedulability analysis DMS: Schedulability analysis
UB test (sufficient): Assume that all tasks (or their first instances) arrive at time 0:
critical instant
Σ Ci/Di <= n*(21/n-1) implies schedulable by DMS
Construct a schedule for the first periods: draw the diagram!
Prescise test (exactly the same as for RMS):
Response time calculation: Ri= Ci + ∑j ∈ HP(i) Ri/Tj*Cj If all tasks meet their deadlines within the first periods,
Ri0 = Ci + ∑j ∈ HP(i) Cj = C1+C2+...+Ci (the first guess) schedulable, otherwise not!
Rik+1 = Ci + ∑j ∈ HP(i) Rik/Tj*Cj (the (k+1)th guess)
The iteration stops when either
Rim+1>Di or non schedulable
Rim<Di and Rim+1 = Rim schedulable
55 56
Summary: 3 ways for DMS schedulability check EDF for tasks with D <= T
UB test (sufficient, inconclusive) You can always use EDF and it is always optimal to
Response time calculation schedule tasks with deadlines
We have a precise UB test for EDF for tasks with Di=Ti:
Draw the schedule for the first periods
U<=1 iff task set is schedulable
Unfortunately, for tasks with Di<=Ti, schedulability analysis
is more complicated (out of scope of the course, further
reading [Giorgio Buttazzo’s book])
We can always check the whole LCM
57 58
10
Handling context switch overheads ? Handling context switch
Thus, the real computing time for a task should be Ri= Ci+ 2Ccs + ∑j ∈ HP(i) Ri/Tj*(Cj + 2Ccs)
Ci*= Ci+Cl+Cs This is wrong!
61 62
Task 0
Whenever possible: move code from the interrupt
0 200
Task 0 is the interrupt handler
60 100 handler to a special application task with the same
with highest priority rate as the interrupt handler to make the interrupt
Released here Missing deadline = 50
C T=D Response time = 70
handler (with high priority) as shorter as possible
IH, task 0 60 200 Interrupt processing can be inconsistent with RM
Task 1 10 50
Task 1
0 50 60 priority assignment, and therefore can effect
Task 2 40 250 schedulability of task set (previous example)
Interrupt handler runs with high priority despites its period
Task 2 Interrupt processing may delay tasks with shorter periods
(deadlines)
how to calculate the worst case response time ?
63 64
65 66
11
Handling non preemptive sections: Handling non-preemtive sections:
Problem and Example Response time calculation
Task 3 is an interrupt handler with highest priority
Task 4 has a non preemptive section of 20 sec The equation for response time calculation:
C T=D blocking blocked Ri= Bi + Ci + ∑j ∈ HP(i) Ri/Tj*Cj
Task 1 20 100 0 20 Where Bi is the longest time that task i can be
Task 2 40 150 0 20
blocked by lower-priority tasks with non preemptive
Task 3 60 200 0 20
Missing deadline 150 section
Task 4 40 350 20 0
Bi = max{Cbj | task j has lower priority than task i}
IH Task 3 60 60 Note that a task preempts only one task with lower priority
100 200 within each period
Task 1
Task 2
150
Task 4 20 20
69 70
L released
T3 is activated by T2 when it finishes within each period
Note that because the response time for T2 is not a constant,
the period between two instances of T3 is not a constant: 170, 130 12
missing deadline at 27
71 72
12
Jitter: Definition Jitter: Example
{(20,100),(40,150),(20, T3)} Pr(T1)=1, Pr(T2)=2, Pr(T3)=3
J(biggest)=maximal delay from period-start
J(smallest)=minimal delay from period-start T1 20 20 20 20
Jitter= J(biggest)-J(smallest) 0 100 200 300
T2 40 40 40
If J(biggest)=J(smallest), then no influence on the 0 150 300
130 170
other tasks with lower priorities
T3 20
0 150 300
73 74
Task L will be preempted at least 2 times if Rlow > Thigh -Jhigh Task L will be preempted at least 3 times if Rlow > 2Thigh -Jhigh
Rlow Rlow
One release One release
Task L Task L
0 0
Tlow Tlow
Jhigh One more release due to the jitter
Jhigh One more release due to the jitter
Task H Which preempts L, one more time Task H Which preempts L, one more time
0 Thigh 0 Thigh 2Thigh
77 78
13
The number of preemptions/blocking
when jitters occur Handling Jitters in schedulability analysis
Task L will be preempted at least 2 times if Rlow > Thigh -Jhigh Ri= Ci + ∑j ∈ HP(i) ”number of preemptions” *Cj
Task L will be preempted at least 3 times if Rlow > 2 *Thigh -Jhigh Ri* = Ri + Ji(biggest)
...
Task L will be preempted at least n times if
Rlow > (n-1)* Thigh –Jhigh
if Ri* < Di, task i is schedulable otherwise no
Thus (Rlow +Jhigh)/Tj > n-1
the largest n satisfying the condition is given by
n= (Rlow + Jhigh)/ Thigh
79 80
81 82
Summary: + and -
Static Cyclic Scheduling (SCS)
Simple, and reliable, may be difficult to construct the time
table and difficult to modify and (inflexible)
Earliest Deadline First (EDF)
Simple in theory, but difficult to implement, non-stable
no precise analysis for tasks D<T
Rate Monotonic Scheduling (RMS)
Simple in theory and practice, and easy to implement
Deadline Monotonic Scheduling (DMS)
Similar to RMS
Handling overheads, blocking
83
14