Professional Documents
Culture Documents
Stefan M. Petters
Lecture Content
NICTA 2007/2008
No: 2
Definition
NICTA 2007/2008
No: 3
Real-Time Systems
NICTA 2007/2008
No: 4
Real-Time Systems
NICTA 2007/2008
No: 5
Real-Time Systems
NICTA 2007/2008
No: 6
Real-Time Systems
NICTA 2007/2008
No: 7
Real-Time Systems
Is there a pattern?
Hard real-time systems
Soft real-time systems
Firm teal-time systems
Weakly hard real-time
A deadline is a given time after a triggering event, by
which a response has to be completed.
Therac 25 example
NICTA 2007/2008
No: 8
Small size?
should be small anyway
Multitasking?
often used, but not necessarily
No: 9
Deadline
Triggering
Event
Time
NICTA 2007/2008
No: 10
Soft Real-Time
Cost
Example Cost
Function
Triggering
Event
Time
NICTA 2007/2008
No: 11
Deadline
Example Gain
Function
Triggering
Event
NICTA 2007/2008
No: 12
NICTA 2007/2008
No: 13
No: 14
NICTA 2007/2008
No: 15
NICTA 2007/2008
No: 16
NICTA 2007/2008
No: 17
Overview
NICTA 2007/2008
No: 18
Requirements
Cyclic
Mixed
Anything in between
NICTA 2007/2008
No: 19
Specification
Cyclic
feedback control loop
NICTA 2007/2008
No: 20
10
Task Model
Periodic tasks
Time-driven. Characteristics are known a priori
Task i is characterized by (Ti, Ci)
E.g.: Task monitoring temperature of a patient in an ICU.
Aperiodic tasks
Event-driven. Characteristics are not known a priori
Task i is characterized by (Ci, Di) and some probabilistic profile
for arrival patterns (e.g. Poisson model)
E.g.: Task activated upon detecting change in patients condition.
Sporadic Tasks
Aperiodic tasks with known minimum inter-arrival time (Ti, Ci)
NICTA 2007/2008
No: 21
Task Model
No: 22
11
Task Constraints
Deadline constraint
Resource constraints
Shared access (read-read), Exclusive access (write-x)
Energy
Precedence constraints
1 2: Task 2 can start executing only after 1
finishes its execution
Fault-tolerant requirements
To achieve higher reliability for task execution
Redundancy in execution
NICTA 2007/2008
No: 23
Preemption
No: 24
12
Preemption
Cooperative preemption?
Applications allow preemption at given points
Reduction of preemptions
Increase of latency for high priority tasks
NICTA 2007/2008
No: 25
NICTA 2007/2008
No: 26
13
Scheduler picks from all ready tasks the one with the highest priority
to be dispatched.
Benefits:
Simple to implement
Not much overhead
Minimal latency for high priority tasks
Drawbacks
Inflexible
Suboptimal (from analysis point of view)
NICTA 2007/2008
No: 27
Task 1
Task 2
Task 3
NICTA 2007/2008
Priority
1
2
3
C
5
8
15
T
20
30
50
D
20
20
50
No: 28
14
Drawbacks:
Deteriorates badly under overload
Needs smarter scheduler
Scheduling is more expensive
NICTA 2007/2008
No: 29
Task 1
Task 2
Task 3
NICTA 2007/2008
No: 30
15
Task 1
Priority
1
C
5
T
20
D
20
Task 2
30
20
Task 3
15
40
40
NICTA 2007/2008
No: 31
Task 1
Task 2
Task 3
NICTA 2007/2008
No: 32
16
No: 33
Disadvantages:
Big latency if event rate does not match base rate
Inflexible
Potentially big base rate (many scheduling decisions) or
hyperperiod
1
Hyperperiod
NICTA 2007/2008
BMW example
No: 34
17
1
3
NICTA 2007/2008
No: 35
Overload Situations
NICTA 2007/2008
No: 36
18
Old
Task 1
Task 2
Task 3
NICTA 2007/2008
Priority
1
2
3
C
5
12
15
T
20
20
50
D
20
20
50
No: 37
Task 1
Task 2
Task 3
NICTA 2007/2008
No: 38
19
Task 1
Task 2
Task 3
NICTA 2007/2008
No: 39
Task 1
Task 3
Task 2
Task 3
NICTA 2007/2008
No: 40
20
Priority Inversion
NICTA 2007/2008
No: 41
2 shared resources
One shared by 3 (nested by one)
One shared by 2
NICTA 2007/2008
No: 42
21
BAD
Tasks blocked even when no contention exists.
NICTA 2007/2008
No: 43
Priority Inheritance
Task 1
Task 2
Task 3
Task 4
Task 5
No: 44
22
Priority Inheritance
When lower priority job blocks, it inherits priority of
blocked job.
GOOD
No unbounded priority inversion
Simple
No prior knowledge required
Works with fixed and dynamic priorities.
BAD
Possible Deadlock.
Blocking of jobs not in resource contention.
Blocking time could be better
Indirection a pain in the neck
NICTA 2007/2008
No: 45
Task 1
Task 2
Task 3
Task 4
Task 5
NICTA 2007/2008
No: 46
23
BAD
Task may be denied resource even when available.
Need a priori knowledge of use of resources.
K
Bi = usage ( k , i )C ( k )
Bi = max usage ( k , i )C ( k )
k =1
k =1
Priority Inheritance
No: 47
Task 1
Task 2
Task 3
Task 4
Task 5
NICTA 2007/2008
No: 48
24
Simple.
Shared run-time stack.
Reduced Context-Switching
No deadlock.
No unbounded priority inversion.
BAD
Task may be denied resource even when available
Task may be affected by blocking effect without using any
resources
Need a priori knowledge of use of resources.
No self suspension while holding a resource
NICTA 2007/2008
No: 49
Implementation Comparison
Non-preemptable critical sections
Easy to implement. Either blocking interrupts or syscall to have that
implemented on behalf of task
Priority Inheritance
Fairly straightforward, however requires various references (e.g.
which thread is holding a resource)
Basic Priority Ceiling
Requires application designer to explicitly identify which resources
will be requested later (when first resource request of nested
requests is made) on top of references
Immediate priority ceiling
Very easy to implement: Only requires ceilings associated with each
resource mutex (thats something which may be automated if all tasks
known
Alternatively server task encapsulating the critical section
NICTA 2007/2008
No: 50
25
Reflective/Feedback-based Scheduling
Adaptive systems
By definition soft real time
Adjusts scheduling based on information
about change
Capable of better coping with the
unknown
Connects quite well with adaptive
applications
NICTA 2007/2008
No: 51
NICTA 2007/2008
No: 52
26
Schedulability Analysis
NICTA 2007/2008
No: 53
Critical Instant
No: 54
27
NICTA 2007/2008
No: 55
Task 1
Task 2
Task 3
Priority
1
2
3
C
5
8
15
T
20
30
50
D
20
20
50
Task 11
Task 22
Task 33
NICTA 2007/2008
No: 56
28
Formal RTA
wi = Ci
n +1
i
NICTA 2007/2008
win
= Ci + * C j
j < i T j
No: 57
Blocking time
Jitter
Pre-emption delay
w
n +1
i
NICTA 2007/2008
J j + w in
= C i + Bi +
* (C j + i , j )
T
j<i
No: 58
29
NICTA 2007/2008
No: 59
1
Ci
n
n * ( 2 1)
i
T
i
NICTA 2007/2008
No: 60
30
Computation
Request
Time
Task 1
Task 2
Events
Deadlines
NICTA 2007/2008
Task 3
No: 61
Computation
Request
Time
Task 1
Task 2
Events
Deadlines
NICTA 2007/2008
Task 3
No: 62
31
NICTA 2007/2008
No: 63
Problem Definition
WCET profile
"Real" Worst-case
Average
Maximum Observed
Best-case
Safe upper
bound
Safe
upper bound
execution time
NICTA 2007/2008
No: 64
32
"Real" Worst-case
Maximum Observed
Safe upper bound
execution time
execution time
NICTA 2007/2008
No: 65
Is it a Problem?
NICTA 2007/2008
No: 66
33
Is it a Problem? contd
No: 67
Program
NICTA 2007/2008
Structural
Analysis
Low-Level
Analysis
Constraint/Flow
Analysis
Computation
WCET
No: 68
34
Structural Analysis
NICTA 2007/2008
No: 69
Object Code
Pros:
All compiler optimisations are done
This is what really is running, no trouble with
macros, preprocessors
Cons:
Needs to second guess what all the variables
meant
A lot of the original information is lost
NICTA 2007/2008
35
Assembly Code
Pros:
All compiler optimisations done
Cons:
Same as Object Code +
Potentially still some macros
NICTA 2007/2008
No: 71
Source Code
Pros:
All information the user has put there is there
Structure in pure form (e.g. multiple loop
continue conditions, object member functions,
indirect calls)
Cons:
Trouble with macros, preprocessors etc.
Needs to second guess what the compiler will
do
NICTA 2007/2008
No: 72
36
Func()
}
first
second
Func();
}
}
NICTA 2007/2008
No: 73
Flow information
NICTA 2007/2008
No: 74
37
A
B
Example program
Structurally possible
flows (infinite)
max = 20
Basic finiteness
samepath(D,G)
samepath(D,G)
D
C
I
max = 10
Statically allowed
Actual feasible
paths
E
G
F
H
J
Basic block graph
NICTA 2007/2008
No: 75
Constraints Generated
Foo()
Constraints:
XfooA
Xfoo=1
Xend =1
XA
XAB=XA
XBC+XBD=XB
XAB
XC
Loop bounds
Other flow
information
XA<=100
XB
XBD
XDE
XCE
E
XE=XCE+XDE
XBC
XA=XfooA+XGA
XGA
XEG
XEF
XD
XE
F
XFG
XF
XG
XC+XF<=XA
end
NICTA 2007/2008
No: 76
38
Hardware
NICTA 2007/2008
No: 77
Static Analysis
NICTA 2007/2008
No: 78
39
No: 79
NICTA 2007/2008
No: 80
40
NICTA 2007/2008
No: 81
Tree Representation
Sequence
1
2
3
Alt
Loop
4
5
Void
Sequence
Void
7
Alt
8
9
NICTA 2007/2008
No: 82
41
IPET Calculation
WCET=
Foo()
NICTA 2007/2008
XA
Xfoo=1 XA=XfooA+XGA
XAB=XA
XBC+XBD=XB
XE=XCE+XDE
XfooA
tA=7
XAB
XBC
tC=12
XC
XC+XF=100
tB=5
XB
XBD
tD=2
D
X
XDE D
XE
XCE
XEG
XEF
tE=4
tF=8
XFG
G
XA<=100
XGA
XF
tG=20
XG
end
No: 83
Calculation methods
Foo() Xfoo=1
Solution methods:
XA=100 A
Solution:
XB=100
WCET=4800
D
E
XE=100
F
XD=0
XF=0
XG=100
Xend=1 end
NICTA 2007/2008
No: 84
42
Multiprocessor/Multithreaded Real-Time
Systems
NICTA 2007/2008
No: 85
WHY
Performance
Responsiveness in the presence of many
external events
Throughput
Managing continuous load
Fault tolerance
Managing bugs, HW faults
Reliability
Ensuring uptime, HW/SW upgrades
NICTA 2007/2008
No: 86
43
Hardware
Asymmetric Multiprocessor
Specialised units, coherency
Distributed System
Latency in communication, loosely coupled
NICTA 2007/2008
No: 87
SMT
Almost an SMT:
Image taken from http://www.tommesani.com/images/P3Architecture.jpg
NICTA 2007/2008
No: 88
44
SMP
No: 89
Distributed System
CPU
CPU
Caches
Caches
Memory
Memory
NIC
NIC
Network
CPU
CPU
Caches
Caches
Memory
Memory
NIC
NIC
NICTA 2007/2008
No: 90
45
Issues
Resource contention
Execution units
Caches
Memory
Network
NICTA 2007/2008
No: 91
Solutions??
Partitioning
Resource contention still there!
Assignment using heuristics
Non partitioning
mostly theoretical so far
Assumptions:
No: 92
46
Solutions??
Testing is easier??
Reduce need for blocking
But!
NICTA 2007/2008
No: 93
Non-Preemptive
But!!!
Less efficient processor use
Anomalies: response time can increase with
No: 94
47
And now?
No global solution.
Partitioning and reducing it to single CPU problem
good, but still contention of resources.
Next step: After figuring out how to do the
scheduling, what about preemption delay?
Industry works with SMP/SMT, but most often on
a very ad hoc basis.
Active and unsolved research area
Why does it work on non-RT?
Running the wrong task is not critical.
NICTA 2007/2008
No: 95
NICTA 2007/2008
No: 96
48
No: 97
Why?
We want both flexible general-purpose processing and robust realtime processing
Multimedia is ubiquitous in general-purpose systems
Real-time systems are growing in size and complexity
No: 98
49
How?
We need integrated solutions for each type of resource
CPU, storage, memory, network,
No: 99
Continuous processing
requirements
NICTA 2007/2008
Undefined timeliness
requirements
Hierarchical scheduling is a
partial solution
Allows apps with a variety of
timeliness requirements, BUT
Static, inflexible hierarchies
No: 100
50
NICTA 2007/2008
CPUBound
Soft
RealTime
ed
Resource
Allocation
SRT
s
Ba
e-
Dispatching
at
R
Resource Allocation
Resource allocation
Hard
RealTime
Missed
Deadline
SRT
unconstrained
Observation: Scheduling
consists of two distinct
questions:
constrained
Best
Effort I/OBound
unconstrained
constrained
Dispatching
No: 101
Per
i
WC od
ET
Rate-Based
Packets/sec
Soft
Real-Time
Frames/sec
ACET
Scheduling
Policy
Resource
Allocation
Scheduling
Parameters
Feedback
Scheduling
Mechanism
Scheduler
Dispatching
When?
rity
Prio
Best-Effort
NICTA 2007/2008
How
much?
P0
Runtime System
No: 102
51
Basic Idea
EDF provides hard guarantees
Varying rates and periods provide
flexibility
Programmable timer interrupts
guarantee isolation between
processes
RBED policy
Resource allocation: Target rateof-progress for each process (S
100%)
Dispatching: Period based on
process timeliness needs
RBED mechanism
Rate
Period
How
Scheduling
much
Mechanism
?
Period,
EDF
WCET
Dispatch, w/timers
block, etc.
When?
P0
Runtime System
Scheduling
Policy
rate = utilization
WCET = rate*period
No: 103
BE
Process 1
Time
NICTA 2007/2008
No: 104
52
BE
Process 1
BE
Process 2
Time
NICTA 2007/2008
No: 105
EDF
Period and WCET are
specified per task
RBED
Period and WCET are
specified per job
NICTA 2007/2008
No: 106
53
Two Observations
deadline
time
job release
NICTA 2007/2008
No: 107
Now
time
NICTA 2007/2008
No: 108
54
Now
time
NICTA 2007/2008
No: 109
Now
A task can
never be in
this region
if resources
are available!
time
NICTA 2007/2008
No: 110
55
Now
time
NICTA 2007/2008
No: 111
Corollary: A new task may enter at any time, within available resources
Theorem 2: The rate of any task can be increased at any time, within
available resources
Theorem 4: The rate of any task can be lowered at any time, down to
what it has already used in the current period
Theorem 5: The period of any task can be reduced at any time, down
to the time corresponding to the current periods resource usage
Corollary: The period of any task can be increased at any time (without
changing WCET)
Corollary: The period of a job which is ahead of its target allocation can
be reduced at any time, down to the time corresponding to its current
resource usage (without changing WCET) as long as the resources are
available for the rate change
NICTA 2007/2008
No: 112
56
NICTA 2007/2008
No: 113
NICTA 2007/2008
No: 114
57
Task
Reservation
Period
T1
1.5
6.0
T2
4.0
8.0
T3
2.5
10
Solution
Answer: Allocate
slack as early as
possible
NICTA 2007/2008
No: 115
Task
Reservation
Period
T1
1.5
6.0
T2
4.0
8.0
T3
2.5
10
Solution
Answer: Allocate
slack to the task
with the earliest
deadline
NICTA 2007/2008
No: 116
58
Task
Reservation
Period
T1
1.5
3.0
T2
1.0
8.0
T3
Solution
Answer: Borrow
resources (potential
slack) from the next
job to meet the
current deadline
NICTA 2007/2008
No: 117
Task
Reservation
Period
T1
1.5
3.0
T2
1.0
8.0
T3
Solution
NICTA 2007/2008
No: 118
59
Principles
1.
2.
3.
SLAD
4.
SRAND
SLASH
NICTA 2007/2008
BACK
SLASH
No: 119
BACKSLASH Conclusions
NICTA 2007/2008
No: 120
60
"Real" Worst-case
Maximum Observed
Safe upper bound
Best-case
start of
job
execution
time
Task model
deadline
reserved budget
release
timek execution time k
NICTA 2007/2008
release
timek+1
No: 121
X
release time
NICTA 2007/2008
deadline
deadline
No: 122
61
Modelling Time
performance
performance
fCPU
fCPU
T=
Ccpu
f cpu
Cmem Cbus
+
+ ...
f mem f bus
NICTA 2007/2008
Modelling Energy
energy
energy
fCPU
f=f
opt min
f < f
min
+ mem f mem t
Edyn fV 2 t cyclesV 2
NICTA 2007/2008
fCPU
opt
No: 124
62
Integration of DVFS
Dynamic slack donation
t
wasted cycles
Job stretching
t
NICTA 2007/2008
No: 125
or
NICTA 2007/2008
No: 126
63
Algorithm
No: 127
f
t
f2
t
Real World
f1
t
f2
NICTA 2007/2008
No: 128
64
reserved budget
release
timek
t switch
execution time
k
dynamic slack
t switch
release t
time k+1
release time
NICTA 2007/2008
deadline
No: 129
http://ebook.ieeelab.com/Embedded/RTSbook.pdf
Dale A. Mackall: Development and flight test experiences with
a flight-crucial digital control system. NASA Technical Paper
2857, NASA Ames Research Center, Dryden Flight
Research Facility, Edwards, CA, 1988.
NICTA 2007/2008
No: 130
65
NICTA 2007/2008
No: 131
No: 132
66