Lecture 9
Lecture 9
Lecture 9:
Scheduling and feasibility
Burns/Wellings ch. 13 (except 13.12)
1
Recap:
• A typical real-time OS like QNX offers
- Threads for concurrent execution
- “Parking” operations like MsgReceive(),
MsgReceivePulse(), sigwait(), ...
- Static priorities for controlling relative
importance of threads
• A system specification might contain
- A set of events to handle
- Specified reactions for each event
- A deadline for each reaction
• How map a specification onto an implementation?
REALTIME SYSTEMS – SMD138
2
Specific problem:
3
Priority assignment
4
Initial restricted model
• All threads follow the event-loop pattern:
initialization();
while (1) {
parking_op();
non_blocking_code()
}
• Every parking op waits for a timer tick
• The timers are periodic with fixed period lengths
• The non-blocking code really means non-blocking;
not even mutex calls are allowed
• That is: a set of strictly periodic independent threads
5
Notation
For each thread i we know
- its period Ti (given by control algorithm)
- its execution time Ci (measured, or analyzed)
- its relative deadline Di (equal to Ti for now)
Ti ( = Di )
Ci
We want to determine each thread priority Pi
6
Basic rule
• Under the given assumtions, there exists an
optimal priority assignment rule that is really
simple:
Let Pi < Pj if Tj < Ti
i.e., the shorter the period, the higher the priority
• This rule is called Rate Monotonic Priority
Assignment, or RM for short
• RM is optimal, meaning that if an RM assignment
results is missed deadlines, every other priority
assignment does so too
7
Example
• Given a set of periodic threads with periods
T1 = 150 ms
T2 = 120 ms
T3 = 200 ms
T4 = 75 ms
• An RM priority assignment might be
P1 = 10
P2 = 12
P3 = 9
P4 = 13
8
Optimality & schedulability
9
Utilization-based analysis
Given as set of simple periodic threads, scheduling with
priorities according to RM will succeed if
!
N
Ci
U≡ ≤ N (21/N − 1)
i=1
Ti
where N is the number of threads
That is, the sum of all CPU utilizations must be less than
a certain bound that depends on N
10
Utilization bounds
N Utlilization bound
1 100.0 %
2 82.8 %
3 78.0 %
4 75.7 %
5 74.3 %
10 71.8 %
11
Example A
12
Time-line for example A
Missed
deadline
0 10 20 30 40 50 60
13
Example B
14
Time-line for example B
0 16 32 48 64 80 96
15
Example C
16
Time-line for example C
0 10 20 30 40 50 60 70 80
17
Characterisics
18
Response time analysis
• A more elaborate test that is both sufficient and
necessary
• Idea: compute the response time for each thread, and
compare with deadline
• For highest priority thread, response time equals
execution time
• For second but highest, response time is execution
time + interference by highest priority thread
• Repeat recursively
• Interference depends on period ratio
19
Response time analysis
• For each thread i, calculate its response time Ri:
! " Ri #
Ri = Ci + Cj
Tj
j∈hp(i)
20
Execution times
21
Example
• Assume the following code:
for (i = 1; i <= 10; i++) {
if (cond)
// basic block that costs 100 ms
else
// basic block that costs 10 ms
}
• A conservative approximation says each turn takes
100 ms; i.e., 10*100 ms = 1000 ms in total
• But now assume cond is actually i < 4. Since it can
only be true at most 3 turns, the worst case is 3*100 +
7*10 = 370 ms, which is much less than 1000 ms
REALTIME SYSTEMS – SMD138
22
Hard vs. soft real-time
23
Loosening the restrictions
• Let deadlines be less than periods; i.e., Di ≤ Ti
- Use Deadline Monotonic priority assignment (DM)
• In addition to periodic threads, let some threads be
sporadic, with some minimum inter-arrival time Ti
- Treat these as periodic threads with period Ti, as
long as Di ≤ Ti
• Let threads block for access to common resources
- Extend Response-time analysis with Blocking
time analysis (requires Priority Inheritance)
24
Aperiodic tasks
• An aperiodic task is not periodic, and lacks a
minimum inter-arrival time
• Such a task might easily consume the whole CPU
under bad circumstances (dense arrivals)
- This suggests giving aperiodic tasks the lowest
priorities
• However, under better circumstances, the relative
importance of an aperiodic task might suggest a
higher priority...
• The solution is to associate an “account” of cpu
cycles with a thread – as long as there are cycles on
the account, priority is high, otherwise it drops
• This is the meaning of a Sporadic Server in POSIX
REALTIME SYSTEMS – SMD138
25
Deadline scheduling
For comparison, there actually exists an alternative
scheduling algorithm that
- does not apply to periodic processes only
- can handle sporadic processes via interrupts
- does not need an intermediate priority
assignment step
- has a simple utilization-based test that is
necessary and sufficient, and extremely simple:
N
∑
i =1
Ci
Ti
≤1
!
N
Ci
U≡ ≤1
i=1
Ti
This algorithm is called Earliest Deadline First (EDF)
REALTIME SYSTEMS – SMD138
26
EDF
• EDF is a dynamic scheduling algorithm, since it
prioritizes threads according to their absolut$
deadline at run-time
- The absolute deadline of an event is the time of
the event + its relative deadline
• Like RM and fixed priorities, EDF is an optimal
scheduling algorithm
• EDF constitutes a promising alternative to RM/
DM because of its
- close relation to the terminology of real-time
specifications
- superior resource utilization
- ease of handling in the sporadic/aperiodic cases
REALTIME SYSTEMS – SMD138
27
Drawbacks of EDF
28
Summary
• Fixed priority scheduling applies primary to periodic
processes (sporadic ≈ periodic in the worst case)
• Aperiodic processes can be handled by the dynamic
technique of sporadic servers
• Priorities are assigned according to period (RM) or
deadline (DM) [note: RM is a special case of DM]
• Utilization-based test requires CPU utilization to be
less than 69% in the general case
• Response-time analysis is more refined, and can
handle blocking for resources
• Deadline-based scheduling (EDF) is a theoretically
appealing alternative to fixed priorities
REALTIME SYSTEMS – SMD138
29