Disadvantages of cyclic TDDB47 Real Time Systems Lecture 2: RM & EDF

advertisement
Disadvantages of cyclic
TDDB47 Real Time Systems
•
“Manual” scheduler construction
•
Cannot deal with any runtime changes
– What happens if we add a task to the set?
•
Denies the advantages of concurrent programming
– Which?
Lecture 2: RM & EDF
Calin Curescu
Real-Time Systems Laboratory
Department of Computer and Information Science
Linköping University, Sweden
The lecture notes are partly based on lecture notes by Simin Nadjm-Tehrani, Jörgen Hansson, Anders Törne.
They also loosely follow Burns’ and Welling book “Real-Time Systems and Programming Languages”. These
lecture notes should only be used for internal teaching purposes at Linköping University.
Lecture 2: RM & EDF
Calin Curescu
Lecture 2: RM & EDF
Calin Curescu
35 pages
States of a process
Lecture 2: RM & EDF
Calin Curescu
2 of 35
Priority-based scheduling
•
Every task has an associated priority
•
Run task with the highest priority
– At every scheduling decision moment
•
Examples
– Rate Monotonic (RM)
• Static priority assignment
– Earliest Deadline First (EDF)
• Dynamic priority assignment
– And many others …
Lecture 2: RM & EDF
Calin Curescu
3 of 35
Schedulability Test
•
Test to determine whether a feasible schedule exists
•
Sufficient
+ if test is passed, then tasks are definitely schedulable
- if test is not passed, we don’t know
Necessary
+ if test is passed, we don’t know
- if test is not passed, tasks are definitely not schedulable
Exact
• sufficient & necessary at the same time
•
•
Lecture 2: RM & EDF
Calin Curescu
4 of 35
Rate Monotonic
• Each process is assigned a (unique) priority based
on its period; the shorter the period, the higher the
priority
5 of 35
•
Assumes the “Simple task model”
•
Fixed priority scheduling
•
Preemptive
– Unless stated otherwise
Lecture 2: RM & EDF
Calin Curescu
6 of 35
Example 1
•
Assume we have the following task set
• OBS: not scheduled yet …
Lecture 2: RM & EDF
Calin Curescu
Example 1 (cont’d)
•
7 of 35
Scheduled with RM
Lecture 2: RM & EDF
Calin Curescu
8 of 35
Schedulability test for RM
•
Sufficient, but not necessary:
⎛ Ci ⎞
⎟⎟ ≤ N (21/ N − 1)
i =1 ⎝ i ⎠
N
∑ ⎜⎜ T
•
Example 2
•
•
•
Taskset
Period (Ti)
WCET (Ci)
P1
20
7
P2
50
10
P3
30
5
•
U = 7/20 + 10/50 + 5/30 = 0,72 < 0,78
•
The schedulability of this task set is guaranteed!
Necessary, but not sufficient:
N
⎛ Ci ⎞
⎟⎟ ≤ 1
⎝ i⎠
∑ ⎜⎜ T
i =1
Lecture 2: RM & EDF
Calin Curescu
9 of 35
Lecture 2: RM & EDF
Calin Curescu
Example 3
•
10 of 35
Exact schedulability test
Taskset:
•
Theorem
– If all tasks meet their first deadline, then they will meet all
future ones.
– Proof: paper by Liu and Layland, 1973
•
Gant chart:
•
How de we show this?
– Assume worst case: critical instant
– I.e. all tasks are released at moment 0
– Draw Gant-Charts for testing the schedulability.
or
– Perform response time analysis for the first period for all
the tasks.
Lecture 2: RM & EDF
Calin Curescu
11 of 35
Lecture 2: RM & EDF
Calin Curescu
12 of 35
Response time analysis
•
Tasks suffer interference from higher priority tasks
•
Response time: the time that passes since the task is
released and until it finishes
Ri = Ci + I i
•
Ri = Ci +
∑
j∈hp ( i )
Optimality of scheduling algorithms
∑
j∈hp ( i )
“A scheduler is optimal if it always finds a schedule when a
schedulability test indicates there is one.”
•
“An optimal scheduling algorithm is one that may fail to
meet a deadline if no other scheduling algorithm can meet
it.”
•
“An optimal scheduling algorithm is guaranteed to always
find a feasible schedule, given that a feasible schedule does
exist.”
– Burns, 1991
⎡ Ri ⎤
⎢ ⎥Cj
⎢Tj ⎥
– Stankovic et al., 1995
Iterative formula for calculating response time
win +1 = Ci +
•
⎡ win ⎤
⎢ ⎥Cj
⎢ Tj ⎥
Lecture 2: RM & EDF
Calin Curescu
– Hansson, 1998
Lecture 2: RM & EDF
Calin Curescu
13 of 35
Optimality of RM
•
14 of 35
What to do if not schedulable
•
Change the task set utilitsation
– by reducing Ci
• code optimisation
• faster processor
•
Increase Ti for some process
– If your program and environment allows it
Rate Monotonic is optimal among fixed priority schedulers
– If we assume the “Simple Process Model” for the tasks
Lecture 2: RM & EDF
Calin Curescu
Lecture 2: RM & EDF
Calin Curescu
15 of 35
RM characteristics
16 of 35
Earliest Deadline First (EDF)
•
Easy to implement.
• Always runs the process that is closest to its deadline.
•
Drawback:
– May not give a feasible schedule even if processor is
idle at some points.
•
Dynamic priority scheduling
– Evaluated at run-time
– What are the events that should trigger a priority reevaluation?
•
Assumes the “Simple task model”
– Actually more relaxed: Di < Ti
•
Preemptive
– Unless stated otherwise
Lecture 2: RM & EDF
Calin Curescu
17 of 35
Lecture 2: RM & EDF
Calin Curescu
18 of 35
Schedulability test for EDF
•
Optimality of EDF
Necessary and sufficient
– Or “exact”
•
⎛ Ci ⎞
⎜⎜ ⎟⎟ ≤ 1
∑
i =1 ⎝ Ti ⎠
EDF is optimal among dynamic priority schedulers
N
– If we assume the “Simple Process Model” for the tasks
• Or a more relaxed one where Di < Ti
Lecture 2: RM & EDF
Calin Curescu
19 of 35
Lecture 2: RM & EDF
Calin Curescu
Example 4
•
•
•
Consider following task set:
WCET (Ci)
Deadline (Di = Ti)
•
Is it schedulable with EDF?
•
Is it schedulable with RM?
P1
2
5
P2
4
7
Lecture 2: RM & EDF
Calin Curescu
21 of 35
EDF vs. RM
•
EDF can handle tasksets with higher processor utilisation.
– Example 4 not schedulable with RMS!
•
EDF has simpler exact analysis
•
RMS can be implemented to run faster at run-time
– Depends on the OS
– But they usually like fixed priorities more
Lecture 2: RM & EDF
Calin Curescu
Reading material
•
Chapter 13 in Burns & Wellings
•
Chapter 4 in Butazzo
– for the proofs of sufficient condition and optimality
Lecture 2: RM & EDF
Calin Curescu
23 of 35
20 of 35
22 of 35
Domino Effect
Lecture 2: RM & EDF
Calin Curescu
24 of 35
Dynamic Scheduling
Lecture 2: RM & EDF
Calin Curescu
25 of 35
Download