0% found this document useful (0 votes)
18 views29 pages

Lecture 9

Uploaded by

en.lennart.berg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views29 pages

Lecture 9

Uploaded by

en.lennart.berg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Realtime Systems – SMD138

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:

How do we pick thread priorities for the purpose of meeting


deadlines?
• No generally applicable method exists...
• ... we must concentrate on programs of a rather
restricted form
• Outline:
- Start out with very restricted programs
- Reintroduce some of the complicating factors
- Discuss remaining limitations

REALTIME SYSTEMS – SMD138

3
Priority assignment

• Under some given assumptions, there might be


several ways of assigning priorities so that deadlines
are met
• We’d like to find an optimal method, that fails only
if every other method also fails
• Two separate issues:
- Applying an optimal priority assignment method
- Determining if meeting deadlines is at all possible

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

8
Optimality & schedulability

• RM will produce a priority assignment that meets


deadlines, if such an assignment exists
• [ Note that for some given set of periods, there
might be other priority assignments that also give
good results ]
• However, RM doesn’t really say that the resulting
set of threads wi" meet their deadlines!
• [ This is like knowing where the shortest path from
A to B lies, but still not knowing if that path is
short enough so that B can be reached in time ]

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

10
Utilization bounds
N Utlilization bound
1 100.0 %
2 82.8 %
3 78.0 %
4 75.7 %
5 74.3 %
10 71.8 %

Approaches 69.3% asymptotically

REALTIME SYSTEMS – SMD138

11
Example A

Thread Period Execution time Priority Utilization


i Ti Ci Pi Ui
1 50 12 10 24%
2 40 10 11 25%
3 30 10 12 33%

The combined utilization is 82%, which is above the


bound for 3 threads (78%)
The thread set fails the utilization test

REALTIME SYSTEMS – SMD138

12
Time-line for example A

Missed
deadline

0 10 20 30 40 50 60

REALTIME SYSTEMS – SMD138

13
Example B

Thread Period Execution time Priority Utilization


i Ti Ci Pi Ui
1 80 32 10 40%
2 40 5 11 12.5%
3 16 4 12 25%

The combined utilization is 77.5%, which is below than


the bound for 3 threads (78%)
Hence the thread set will meet all its deadlines

REALTIME SYSTEMS – SMD138

14
Time-line for example B

0 16 32 48 64 80 96

REALTIME SYSTEMS – SMD138

15
Example C

Thread Period Execution time Priority Utilization


i Ti Ci Pi Ui
1 80 40 10 50%
2 40 10 11 25%
3 20 5 12 25%

The combined utilization is 100%, which is well above


the bound for 3 threads (78%)
However, the thread set still meets all its deadlines!

REALTIME SYSTEMS – SMD138

16
Time-line for example C

0 10 20 30 40 50 60 70 80

REALTIME SYSTEMS – SMD138

17
Characterisics

• The utilization-based test is


- sufficient (pass the test, and you’re ok)
- not necessary (fail, and you’ve still got a chance)
• Why bother with such a test?
- Because it’s so simple!

REALTIME SYSTEMS – SMD138

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

REALTIME SYSTEMS – SMD138

19
Response time analysis
• For each thread i, calculate its response time Ri:
! " Ri #
Ri = Ci + Cj
Tj
j∈hp(i)

where hp(i) is the set of threads with priority higher


than i, and !x" means the least integer ≥ x
• Then check if each Ri is less than the corresponding
period (=deadline) Ti
• But how calculate an Ri that depends on itself?
• Answer: start by assuming Ri = Ci , then repeat
calculation based on previous value intil it stabilizes
ProcPr – ISI217

20
Execution times

• How can we obtain worst-case execution times?


- By measurement (but how do we know that we
are measuring the worst case?)
- By analysis (but how do we accurately model
pipelines, caches, etc?)
• How do we deal with data dependencies?
- Conservative approximations
- Use semantic information

REALTIME SYSTEMS – SMD138

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

• A hard task must always meet its deadline


- Use worst-case execution time in analysis
• A soft task must be fast enough over some period
of time
- Use mean execution time in analysis
• Note: with modern architectures, the mean case
might differ from the worst case with a huge factor
(in the 1000 range)

REALTIME SYSTEMS – SMD138

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)

REALTIME SYSTEMS – SMD138

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

• EDF still lacks wide-spread use because


- It exhibits random behavior under overload
- Utilization-based test becomes much more
elaborate when Di ≤ Ti
- Operating systems generally don’t support it
- Few languages allow for natural deadline
constraints
• Still, EDF continues to be intensively studied
because of its theoretical properties

REALTIME SYSTEMS – SMD138

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

You might also like