Mastere Ems Lecture
Mastere Ems Lecture
modelling languages
Claire Pagetti
[email protected]
1
Course Objectives
1. Introduction to real-time
– What is a real-time system?
– Definition of classical notions and terms for real-time
– WCET computation
i
2
Course organisation
• Lecture 1 : introduction
• Lecture 2 & practical sessions 3, 4: Lustre
François-Xavier
• Lectures 5, 8 & practical sessions 6, 9: SCADE Dormoy (Esterel Tech)
• Lectures 7, 12 & 13: scheduling
• Lecture 10 & practical session 11: SDL
• Practical session 14: scheduling analyses
Evaluation:
– Commented code of practical sessions 3 & 4
– Code and report (max 2 pages) of practical session 11
3
Outline
4
Outline - Part I What is a real-time system?
1. First definitions
1. Definitions
2. A real example
2. General architecture
3. WCET computation
4. Real-time problems
5
1.1 Introduction
6
1.1 First definitions
machine-tools
measures sensors
wagon
events in
orders computation
time
continuous
actuators
command
7
History – early 60s
• The first notable embedded real-time system was the Apollo Guidance Computer,
onboard computation for guidance, navigation, and control of the spacecraft of the
Apollo program. It has been developed by Charles Stark Draper of Massachusetts
Institute of Technology.
• First computer to use integrated circuits
• Used in real-time by the astronauts to collect and provide flight data, and to
automatically control the navigation functions of the spacecraft.
• 16-bit wordlength memory : composed of 64 ko (32 000 words) ROM containing all the
programs and of 4 ko (2 042 words) RAM for the computations. The processor weights
around 35 kg.
Source: http://fr.wikipedia.org/wiki/Apollo_Guidance_Computer
8
Embedded system market
“Over 4 billion embedded processors were sold last year and the global
market is worth €60 billion with annual growth rates of 14%. Forecasts
predict more than 16 billion embedded devices by 2010 and over 40
billion by 2020.
Embedded computing and electronics add substantial value to products.
Within the next five years, the share of embedded systems are expected
to increase substantially in markets such as automotive (36%), industrial
automation (22%), telecommunications (37%), consumer electronics
(41%) and health/medical equipment (33%). The value added to the
final product by embedded software is much higher than the cost of the
embedded device itself. For example, in the case of a modern car, by
2010 over 35% of its value will be due to embedded electronics. ”
9
Some examples
10
Example: sample control loop
distance
u(t)
time
d (distance)
u(t) d(t) speed: v=
process dt
hold sampler
uk dk
D-A computer A-D
d k − d k −1
dk
vk =
uk
Discrete time
12
Example : control-command system
inputs outputs
Equations of state
process
u y dx = f(x,u)
state y = h(x)
computer
command
event
level detector
14
Real-time System
15
What time is it?
Two entities: the plant (or physical process) to control and the real-time
computer system
⇒ Two times: the time of the environment and the time of the real-time system
• Environment time = chronometric time (the real time)
• Computer system time = chronological time, composed by the sequence of
events or instructions of the system (steps of the real time seen by the system)
⇒ The computer system must put its actions in phase with the chronometric time
of the process
⇒ the actions of the system will be tasks and messages. Use of techniques of
scheduling of tasks and communications
16
Real-time ≠ go quick
– Need of a short reaction (1 ms) for the control of an military aircraft
– Need of a slower reaction (10 ms) for the control of a civil aircraft
– Need of a slower reaction (1s) for an HCI (human-computer interaction)
– Need of a slower reaction (1mn) for the control of a production line
– Need of a slower reaction (1h) for the control of chemical reaction
– …
– Need of a reaction of several hours to make a meteorological prediction
– Need of a reaction of several days for computation of the pay of the
employees…
17
Hard and soft real-time
Consequences…
=> In the case of hard real-time systems, conceivers want to be predictable,
deterministic and reliable
=> Use of mathematical techniques (scheduling, worst case evaluation…)
=> In the case of soft real-time systems, conceivers want to minimise the
probability to miss a deadline several times
18
1.2 Example of hard real-time: aircraft flight
control
From physics to a computer-aided navigation …
Vertical CG
North
Z
Y
X East 19
Aircraft attitude
pitch
roll
roll
pitch
yaw
yaw
20
Flight control system
The aircraft primary flight control system is the set of elements between
the stick and the surfaces which aim at controlling the attitude, the
trajectory and the speed of the aircraft.
21
Fly-by-wire flight control system
22
(Some) Aircraft sensors
– GPS
– altimeter: measures the altitude of an object above a fixed level
– inertial measurement unit is an electronic device that measures and reports on a craft's
velocity, orientation, and gravitational forces, using a combination of accelerometers
and gyroscopes.
A pitot tube is a pressure measurement instrument used to measure fluid flow velocity
23
A320 flight controls systems
Fly-by-wire system
– 9 calculators
• Functions allocation :
– 2 redundant calculators for the slats and the flaps (SFCC1-2)
– 2 redundant calculators for the rudder (FAC1-2)
– 3 redundant calculators the spoilers, the elevators and the trim (SEC1-2-3)
– 2 redundant calculators for the ailerons, the elevators and the trim (ELAC1-
2), replaced in case of failure by the SEC1-2-3
• Safety requirements
– each calculator must be "fail-silent"
– each calculator must have a failure rate less than 10-3 per flight hour
– ...
24
A320 flight controls systems architecture
25
Reconfiguration policies
SEC 1
ELAC 1 SEC 2
ELAC 2 SEC 3
GND-SPL GND-SPL
Trimmable Horizontal
Stabilizer Actuator
26
Outline - Part I What is a real-time system?
1. First definitions
2. General architecture
1. Material architecture
2. Functional behaviour
3. Executive support
3. WCET computation
4. Real-time problems
27
2.1 Embedded real-time architectures
data
Environment
Computer measures
System events
May be realised by
commands
• a programmable automaton
• an integrated circuit (ASIC)
• a calculator (monoprocessor)
• a multiprocessor system with a shared memory
• a distributed system
• ...
28
Multiprocessor architecture
memory
memory
Acquisition, alarm, Command
emission
Architecture master-slayer
operator
29
P2
Solution
P
Solution
Distributed architecture
Communication
network
30
2.2 Functioning
While TRUE do
Inputs acquisition(measures…)
Computation of orders to send to the process
Orders emission
End while
31
Cyclic run
But :
– system not much "reactive" if the environment produces information at
different frequencies
=> need to foresee all possible reactions of the system in the loop
=> bad performance
=> or interleaving of loops at different frequencies
=> difficulties for realisation, code readability, evolution
32
Chronogram of cyclical implementation
fill
empty
cool
warm
events C L W H
time
33
Event run
34
Chronogram of event driven implementation
Regulation of the level and the temperature of liquid
• Events: H (for high), L (for low), C (for cold) and W (warm)
• Priorities: 2, 2, 1, 1
fill
empty
cool ….…
warm ….…
events C L W H
time
35
Shared resources
empty
cool ….…
events W H
when interrupted, the task cool was acceding to a shared resource (for instance
memory). Conflict problem.
=> A solution: interdiction to preempt a task when using a shared memory.
empty
cool ….…
events W H W H
36
Example: Sojourner
Priority inversion:
“Even though NASA knew the problem, [http://en.wikipedia.org/wiki/Sojourner_%28rover%29]
because it already occurred on all the tests
that had been performed. But NASA thought
it won't be a problem because on earth the
situation didn't occur very often, NASA only
underestimated the number of situations the
problem appeared.”
Tasks
Library
Kernel
38
Solution with an executive component
Application
measures commands
Task Task Task Task
Services calls
clock
Time Events Tasks
events handler handler handler
from the
process
Scheduler
Executive
39
Real-time OS
40
Market for the real-time OS
41
Example: APEX Arinc 653
42
A653 functioning
APEX
OPERATING SYSTEM
Hardware
Operating system :
– Schedule the module partitions
– Schedule the processes of each partition
– Ensure segregation (partitioning) spatially and temporally
43
Sharing of resources
Spatial segregation:
Memory zone predetermined for each partition
• All the objects (ports, processes …) are created during the initialisation phase
45
Processes handling
Standard
• 2 types of processes: periodic and aperiodic
• No segregation between processes of a same partition
• The processes of a partition are not visible by other partitions
• A unique process is running at a time
• Several scheduling are proposed for the processes
46
Example: Paparazzi project
http://paparazzi.enac.fr/wiki/Main_Page
47
Paparazzi project
48
Hardware architecture
49
Functional architecture
50
Code
51
Outline - Part I What is a real-time system?
1. First definitions
2. General architecture
3. WCET computation
4. Real-time problems
52
The WCET Problem
Given
the code for a software task
the platform (OS + hardware) that it will run on
Determine the WCET of the task.
53
Methods
Measuring:
Compile, link and download onto target CPU
Hook up logic analyzer or oscilloscope or use built in registers
Run the code with test inputs, and record execution times
Take the maximum as WCET
No guarantee to hit the worst case!
Simulation:
Various levels of precision possible (cycle accurate, instruction accurate);
difficulty to simulate behavior of environment.
Analysis:
Compute estimate of run time, based on program analysis and model of target
hardware
54
Overview of the methods results
55
Influence of input size
Control flow (while, for loops) can run for variable number of
iterations
Parameters:
• A positive integer, n.
Returns: The sum of the integers from 1 to n.
{ sum := 0;
for i := 1 upto n
{ sum := sum + i;}
return sum;}
56
WCET computation by static analysis
source code
N = input
even = 0;
odd = 0; 1100101 A
for (i=0 ; i<N ; i++) {
binary code CFG
if (i%2 == 0) compiler
extraction
B
even++;
else
odd++; C D
E
flow analysis
Linear program
analysis xA = 1 xA = xAB
xB = xAB + xEB xB = xBC + xBD
xC = xBC xC = xCE
xD = xBD xD = xDE
xE = xCE + xDE xE = 1 + xEB
cA = …; cB = …; cC = …; cD = …; cE = …;
[Rochange2012]
57
Control flow graph (CFG)
• Nodes represent basic blocks. A Basic Block (BB) is piece of code with a single
entry point and a single exit point, with no branching in-between.
• Edges represent flow of control (jumps, branches, calls,...)
Example
test.c
int ex(int n) {
BB1
int i, s=0;
for(i=0; i< n; i++){
s+=i;
}
return s;
} BB3
terminal BB2
>gcc –c –g –lrm test.c Deassemble the code
>dissy test.o
BB4
58
CFG - example
test.c
int ex(int n) {
int i, s=0;
for(i=0; i< n; i++){
s+=i;
}
return s;
}
Generated CFG
CFG idea
B1:
0x000005e
B1: …
int i, s=0; 0x00000079
i=0;
B2:
0x0000085
B2: …
i<n 0x0000008b
B3: B3:
B4: B4: 0x000007b
return s; s+=i;
0x000008d …
i++;
… 0x00000081
0x00000091
59
Identification of the longest path in a CFG
CFG can have loops, how to infer loop bounds?
– unroll loops, resulting in directed acyclic graph (DAG)
– construct system of equations
Example
xi → # times Bi is executed d01
60
Computation of basic blocks WCET
61
Example - micro architectural analysis
i0: load A r0
i1: add r0 r1 r0
i2: mul r3 r2 r3
fetch
decode
issue
IU1
IU2
LSU
complete
scenario 1 scenario 1
A in the L1D A not in L1 and not in L2
62
Outline - Part I What is a real-time system?
1. First definitions
2. General architecture
3. WCET computation
4. Real-time problems
63
Choices for the conceiver
64
Characteristics
“Classical” program:
1. (1) ends; (2) returns a result and (3) handles complex data structure with
quite simple control structure.
2. For such programs, properties to be fulfilled are often “when the
function is called and the pre-condition is satisfied, then the function
ends and the post-condition is satisfied”.
Typical examples of classical program : compiler, sort algorithm.
65
Temporal properties
The properties are very different from those of standard programs. Typically, we
are interested of event interleaving all along infinite executions. For instance:
- If a process requests infinitely often to execute, then the OS will execute it at
some point;
- it is always possible during the execution to return to the initial state;
- whenever a failure is detected, an alarm is raised;
- whenever an alarm is raised, a failure has been detected.
[Bar08]
66
Bibliography
67
Future courses
68
Outline
69
Outline - Part II – High level programming
language
1. Lustre
2. SDL
70
Outline – II.1 - Presentation of Lustre
2. Lustre overview
71
Difficulties
Typical example:
In a world where actions like communication or computation take a
variable amount of time, how to interpret the absence of an information?
– The absence may be due to:
• A delay
• A real absence
– A misunderstanding of the situation
– …
72
Asynchronous vs. Synchronous programming
Asynchronous programming:
– Processes are independent with each other and with the environment
– No global time
– Actions have a non-deterministic duration
– Needs for synchronisation mechanisms (rendez-vous…)
Advantage:
– Close to the real world
Problem:
– Concurrence is not deterministic
– Example:
product X(0); [product X(1);product X(2);] || product Y(X+1);
The result can be either Y(1), Y(2) or Y(3)
=> product X(1);product X(2); not equiv to product X(2)
No code compaction!
73
Asynchronous vs. Synchronous programming
Advantage:
– Determinism
– Simpler programs
But:
– Need to verify that the implementation respects the hypothesis
74
Development process of control command systems
physicist
Simulink
discrete
models
computer scientist
Lustre/SCADE
programs Constraints:
-OS
ACG Mathworks -hardware
ACGLustre
Embedded
executable
C code
75
Panorama of synchronous languages
Main applicative domains
- control-command
- Circuits
2. Lustre overview
1. Introduction
2. Syntax
3. Examples
4. Over sampling and sub sampling
77
Presentation
Motivation:
Allow a natural programming
– of control command systems
– of circuits …
for the safe programming (of critical and reactive systems)
Mean:
Classical techniques of programming close to traditional methods used in
industries by engineers
– block diagrams and data-flow
– sampled systems
LUSTRE:
– Formal language defined in 1985 by P. Caspi and N. Halbwachs in Grenoble
Verimag.
– Commercial distribution SCADE - Esterel Technology
– Industrial use: Airbus, Schneider electric
78
Examples
Logic gate
X
Z
Y
For all n, Zn = Xn or Yn
Relay Z
V
U
W
For all n, Un = if Zn then Vn else Wn
Filter
O0 = aU0
U a+bz-1+cz-2 O O1 = aU1 + bU0
∀n≥2, On = aUn + bUn-1 + cUn-2
79
Examples
Generalisation:
– Description of a system by a sequence of sampled values: the data-flow
– A system = a set of operators applied on the data-flow
Example
X Z
Y
V U
a+bz-1+cz-2 O
W
Z = X or Y;
U = if Z then V else W;
O = a.U + B. pre(U) + c.pre(pre(U));
80
Approach
Data-flow:
– X is a sequence of values Xn with n ≥0
– Xn is the value of X at the instant n (nth top)
Basic clock: all the flows are assumed to be cadenced at the same clock
– Xn and Yn are the values of X and Y at the same instant
Definition of flows:
– A flow is defined by an equation O=F(X,Y,..) which computes On depending
on Xn and Yn (at the same instant)
A program Lustre:
– set of equations
– at each top, the variables are evaluated depending on the values of the inputs
81
Approach
Working hypothesis
– We program as if the communications and the reactions take no time.
– We focus on the relation between inputs and outputs
82
General syntax
[declaration of types and external functions]
node name (declaration of input flows)
returns (declaration of output flows)
[var declaration of local flows]
let
[assertions]
system of equations defining once each local flow
and output depending on them and the inputs
tel.
[other nodes]
Types :
– basic types: int, bool, real
– tabular : int^3, real^5^2…
83
Equations
84
Operators
Classical operators:
Arithmetical :
Binary : +, -, *, div, mod, /, **
Unary : -
Logical :
Binary : or, xor, and, =>
Unary : not
Comparison :
=, <>, <, >, <=, >=
Control :
if . then . else
Temporal operators :
pre (precedent) : operator which allows to work on the past of a flow
-> (followed by) : operator which allows to initiate a flow
85
Operator pre
Let
X be the flow (X0, X1, … , Xn, …)
then
pre(X) is the flow (nil, X0, X1, … , Xn, …)
86
Operator ->
Initialisation of a flow.
Let
X be the flow (X0, X1, … , Xn, …) and Y the flow (Y0, Y1, … , Yn, …)
then
Y->X is the flow (Y0, X1, … , Xn, …)
87
Example
pre
→ Y
X Horloge
Y
88
Example
Flip-flop
Let set and reset be two input Boolean flows, let level be an output
Boolean flow
P1
reset
false
→ level
true
pre true
set
89
Exercises
tel
tel
90
Exercise
A resetable counter
– Input: reset reset the counter (Boolean flow)
– Output: counter value of the counter (Integer flow)
tel
91
Exercise
A timer:
– Input: set activation of the timer (Boolean flow)
– Output: level state of the timer (Boolean flow)
– Constante: delay duration of the timer in number of tops
tel
92
Assertion
Example
assert (not (X and Y))
imposes that the Boolean flows X and Y are never true simultaneously
93
Example: Lulu, the wolf, the goat and the cabbage
Lulu needs to bring a wolf, a goat, and a cabbage across the river.
– The boat is tiny and can only carry one passenger at a time.
– If he leaves the wolf and the goat alone together, the wolf will eat the goat.
– If he leaves the goat and the cabbage alone together, the goat will eat the
cabbage.
– How can he bring all three safely across the river?
94
Example: Lulu, the wolf, the goat and the cabbage
95
Example: Lulu, the wolf, the goat and the cabbage
Program
node river(m, mw, mg, mc : bool) returns (L, W, G, C : int)
assert (m or mw or mg or mc);
assert( not (m and mw));
assert( not (m and mg));
assert( not (m and mc));
assert( not (mw and mg));
assert( not (mw and mc));
assert( not (mg and mc));
assert( true -> not (mw and not (pre(L)=pre(W))));
assert( true -> not (mg and not (pre(L)=pre(G))));
assert( true -> not (mc and not (pre(L)=pre(C))));
let
L = 0 -> 1 - pre(L);
W = 0 -> if mw then 1 - pre(W) else pre(W);
G = 0 -> if pre(G) = 2 then pre(G)
else if mg then 1 - pre(G)
else if (pre(G)=pre(W) and not mw) then 2
else pre(G);
C = 0 -> if pre(C) = 2 then pre(C)
else if mc then 1 - pre(C)
else if (pre(C)=pre(G) and not mg) then 2
else pre(C);
tel.
96
Example: Lulu, the wolf, the goat and the cabbage
97
First conclusion
98
Outline– II.1 - Presentation of Lustre
2. Lustre overview
99
Clock-based semantics
Clock:
– a clock is a Boolean flow
Basic clock:
– is the flow true
Semantics of a flow:
– is the sequence of pairs (vi,ci) where vi is the value and ci is the clock
associated to the flow
Equation:
– must be homogenous in term of clock
• X + Y has a sense iff X and Y have the same clock
100
Operator when
101
Operator current
102
Sampling
X 4 1 -3 0 2 7 8
C false false false true true false true
current(X when C) nil nil nil 0 2 2 8
104
Exercise
106
Exercise
107
Exercise: 3 bits adder
Write a node
• node Add3b(cin, x, y : bool) returns (cout, s : bool);
• Which computes cin, x and y
i.e. for all t cint + xt + yt = 2 * coutt + st
108
Exercise: serial adder
109
References
110
Outline - Part II – High level programming
language
1. Lustre
2. SDL
111
Outline – II.2 SDL
2. Introduction of SDL
3. Syntax of SDL
112
Development process
Specification,
definition
Conception,
global architecture
Detailed conception,
high level programming
Implementation
113
Development process
UML-RT SDL
Specification, => Use cases
definition sequence diagram
Conception,
global architecture
Detailed conception,
high level programming
Implementation
114
Development process
y
(ti e g al v is bilit
Specification,
c h io u o f
)
UML-RT
…
SDL
el av n
ly la
od h tio
definition
ec r
Fo ana edu
ng
m l b e ic a
ki
=> System structure
h
s
Sc
e d a r if
m lo b e
(class diagram)
Conception, => Description of tasks, processes
th r m
global architecture => Description of components
Detailed conception,
high level programming
Implementation
115
Development process
Specification,
definition
sk
Conception,
ta
ch
global architecture SDL
ur n
ea
io tio
of
a v ic a
ESTEREL
e h r if
e b ve
Detailed conception, SCADE/LUSTRE
th a l
of rm
high level programming => Task description
Fo
Low level programming
Implementation
116
Development process
Specification,
definition
Conception,
global architecture
Detailed conception,
f
to
ce
high level programming
w
C, C++
of
sk on
Ada
ta ta ti
ch u
⇒task
ea mp
Low level programming
Co
coding
Implementation
117
Development process
Specification,
definition
Simple sched
Conception,
(RMA, EDF…)
global architecture
Simple sched under
energy constraint
Detailed conception,
high level programming Real-time sched
(m,k)-firm
an of
Low level programming
s…
r m io n
ce
rfo at
p e a lu
Ev
=> choice of scheduling
Implementation => choice of real-time OS
=> choice of network and of protocols
118
Outline – II.2 SDL
2. Introduction of SDL
3. Syntax of SDL
119
Generalities
General features:
– the specification of a system is the description of the expected behaviour
– the description of a system is the description of the real behaviour
– the specifications and the descriptions made in SDL must be formal in the
sense that it could be possible to analyse and interpret them without ambiguity
– SDL is easy to learn and use (several formal methods should be applied)
=> Graphical language
120
Brief historical
121
Advantages in the development process
122
Industrial example: ATC (Air Traffic Control)
[wikipedia]
123
Embedded ATC
ON board data (position, altitude, speed, weather) are collected,
transmitted regularly to on ground equipments. Electronic dialogue
between pilot and controllers.
– ADS (Automatic Dependant Surveillance) : surveillance technology for
tracking aircraft. If an aircraft deviates from its flight profile, it reaches a specific
monitored mode to quickly correct its position. Future generation: ADS-B
(Broadcast), delays are improved
– CPDLC (Controller-Pilot Data Link Communications) : method by which air
traffic controllers can communicate with pilots over a datalink system. Formatted
electronic dialogue (no ambiguity): set of clearance/information/request message
elements which correspond to voice phraseology employed by Air Traffic Control
procedures (eg clearance to climb or descend to a given flight altitude)
– CAP (Controller Access Parameters). On board systems compute and
automatically send surveillance data (such as magnetic heading, indicated
airspeed, vertical rate…). This allows a tighter surveillance of the traffic for the
ATC and reduce the overload on human
[wikipedia]
124
Embedded ATC
125
Outline – II.2 SDL
2. Introduction of SDL
126
Structure of an SDL system
An SDL system is a structured set of processes which execute in
parallel and communicate by exchanging messages
environment
interface
system
127
Structure of an SDL system
3 levels of structuring:
1. System = block + communication channel
2. Block = processes + signal route
3. Process = an automaton
environment
interface
system
block block
block
128
Structure of an SDL system
channel
block
129
Example: simple reactive system
system reactive_system
input output
reactive_block_1
[ order ] [ result ]
130
Example: simple reactive system
Block reactive_block_1
input1 output1
input reactive_process_1 output
[ order ] [ result ]
131
Example: simple reactive system
process reactive_process_1
wait
order
result
wait
132
Lexical rules
Comments:
– between /* …*/
– after keywords COMMENT
– special graphical symbol for the graphical version a comment
Identifier: [a-z_+#@]*
No shared variable
133
Declarations
Elementary types:
– Boolean: true, false
– Character: ‘A’,’1’, …
– Integer: Z
– Natural: N
– Real
– Charstring
– Pid: identifier of process (2 operators =, /=)
– Time
134
Example 2
system FTP_minimal
FTP_connection
FTP_server FTP_client
[ command ] [ data ]
[ command ] [ command ]
process_client FTP_connection FTP_connection process_server
[ data ] link link
[ data ]
135
Definition of the behaviour in the process
136
Example: process of the client
process FTP_client
receive
command data
receive receive
137
Example: process of the server
process FTP_server
idle
idle command
data
138
Semantics of a process
139
Example
140
Communication semantics
1
P1 P2
m
m 2 m
m
3
141
Communication semantics
process P1 m p process P1 p
s1 s1
input(m)
m m
s2 s2
control point
of the process
142
Communication semantics
control point
of the process
r
m r
p m r
s2 s2
s2
143
Signal handling
144
Variables declaration
In a block text.
DCL a Character;
DCL b Character, i integer;
DCL c,d Character, n,m Natural ;
145
Declarations
idle s(val)
s(val+1)
idle
146
Decision
expr
Examples
n n<5
147
Tasks
( n<5 ) ( else )
ok n := 0
n := n+1
sending
148
Loops
s
l
( n<5 ) ( else )
ok n := 0
n := n+1
sending
l
149
Timers
reset
reset
set overrun
inactive active expired
set
150
Example: process of the client
wait
command
data T
set(NOW+10,T)
command
wait
set(NOW+10,T)
wait
151
Outline – II.2 SDL
2. Introduction of SDL
152
Tools
Command T Command
Data Data
T
Command
Data
Version 1 Version 2
153
Exercise
Model this system in SDL. This will be useful for the next practical
session.
154
References
156
Outline - Part III - Scheduling
1. First definitions
157
Definitions
158
How to model a task?
A model should be :
– accurate and precise enough to express the features of the application;
– exploitable for validation.
159
Model of a task
can be activated
start
waiting suspend
• Ready: the task is ready to
execute and waits for the resource
activate
wake up ready to start. The scheduler chooses
among the ready tasks which one
will start next.
• Waiting: the task is blocked and
is waiting for an event
160
Execution time
+
….…
time
161
Release time
Oi
….…
t0 ri time
Synchronous tasks
– If ri = t0
162
Deadline
Relative deadline:
– Maximal delay for the execution of a task, denoted by Di.
Oi Di
….…
t0 ri di
163
Start and end of an execution
Start time:
– Instant when the execution starts, denoted by si
Oi Di
….…
t0 ri s i fi d i
164
Response time
Response time:
– Delay between the activation and the end of an execution, denoted by
Ri
Ri = fi − ri
Oi Ri
….…
t0 ri s i fi d i
165
Repetitive task
Repetitive task:
– Task which executes several times
….…
t0 ri s i 1 fi 1 d i 1 ri 2 fi 2 d i2
s i2
166
Periodic task
Periodic task:
– Time interval between 2 activations is constant, of period Ti
ri1= ri
rik = ri1+ (k-1) Ti
Ti Ti
….…
t0 ri s i 1 fi 1 d i 1 ri 2 fi 2 d i2
s i2
167
Non-periodic task
Sporadic task:
– Time interval between 2 activations is more than a value, named inter arrival
time denoted by Ti
rik - rik-1≥ Ti
Ti Ti
….…
t0 ri s i 1 fi 1 d i 1 ri 2 fi 2 d i2
Aperiodic task:
– No constraint on the activation times
168
Real-time constraints
(m,k)-firm task:
– At least m instances among k consecutive instances (m<k) must respect their
deadlines
Examples :
– ABS control system: hard real-time
– Emission of multimedia stream on internet: contrainte (m, k )-firm
– Air conditioning control system: soft real-time
169
Outline - Part II - Scheduling
1. First definitions
170
Outline – III.2 – Uniprocessor scheduling
1. Recalls
2. Real-time Scheduling
3. Priority-based Scheduling
171
Definitions
Predictability:
–The application performances must be defined in the worst case for any possible
behaviour in order to ensure the respect of timed constraints
Determinism:
–There is non uncertainty on the behaviour: this behaviour is always the same in
a given context
Reliability:
–ability of a system to perform and maintain its functions in normal
circumstances. For real-time, reliability refers to the timed constraints respect.
We may also want the system to remain reliable even when some failures occur:
we then speak of fault tolerant system.
172
Periodic sequencing
For a set of periodic tasks T = {τ1, τ2, …τn} which are sequenced off line. The
sequence is made over a feasibility interval (or a meta period) H.
Case: for all i ri = 0
H = lcm (Ti) Task r C
0 D T
1 0 2 6 6
2 0 1 8 8
3 0 2 10 12
S S
6 8 12 16 18 24
General case:
H = max (ri) + 2 * lcm (Ti)
Task r0 C D T
1 0 2 6 6
2 2 1 8 8
3 0 2 10 12
Processor utilisation
– For a task Ui = Ci/Ti
– In general: fraction of processor time spent in the execution of the task set
n
U = ∑ Ci / Ti
i =1
Example
Task r0 C D T
1 0 2 6 6
2 2 1 8 8
3 0 2 10 12
– Ui =
174
Dynamic parameters
D
Cmax L(t)
t
r d
t C(t)
D(t)
175
Scheduling overview
Scheduling policy:
– Algorithm by which tasks are given access to system resources (e.g. processor
time, communications bandwidth).
Valid scheduling:
– The scheduling of a set of tasks is said to be valid if and only if no task
instance misses its absolute deadline.
Schedulability:
– A set of tasks is said to be feasible with respect to a given class of schedulers
(we consider 4 classes preemptive/non-preemptive, fixed/dynamic priority) if
and only if there exists at least one valid schedule for this class.
Activities:
– For a given system, there are 2 main activities: choice of the scheduling policy
and validation of this policy on the set of tasks.
176
Outline - III.2 – Uniprocessor scheduling
1. Recalls
2. Real-time scheduling
3. Priority-based Scheduling
177
Scheduler internal structure
Scheduler:
– the kernel module which applies the scheduling algorithm and handles the tables
Dispatcher:
– the kernel module which realises the effective activation and the context change
t2:ready scheduler
t3:suspend
t4:waiting
Active
task
execution dispatcher
178
Criteria associated to a scheduling
Efficiency:
– the processor must spend the maximum time in executing the application
(minimisation of the overhead)
Predictability:
– guaranty of the delays, capacity of predicting the behaviour
Flexibility:
– ability to dynamically reallocate units of resource, fault tolerance …
179
4 classes of scheduling
Preemptive policy:
– Tasks can be interrupted at any time and the processor allocated to an other task
– Better response time
– Mechanism for shared resources
– Context handling
180
Exercises
Some sets of tasks can be scheduled for a preemptive policy but not
for a non preemptive one. Give an example?
181
General purpose vs real-time scheduling
Real-time scheduling:
– Guaranty the respect of deadlines
– Even in the worst case
182
Classical scheduling policies
Best effort
– Preemptive
183
Round Robin strategy
Circular scheduling list
Waiting and
Suspended tasks
τ5 τ2 τ4 τ3 τ1 τ6
Running Arriving of
task Ready tasks
ready tasks
Configuration
Tasks τ1 τ2 τ3 τ4
Execution time 10 ms 20 ms 30 ms 40 ms
τ1 τ2 τ3 τ4 τ2 τ3 τ4 τ3 τ4 τ4
t
10 20 30 40 50 60 70 80 90 100
184
Round Robin with several queues
M queues will execute in a circular manner with each other. Usually the quantum
are 4xT0, 2xT0, T0. The sequence is then F1 F2 F3 F1 F2 F3…
τ3 τ8 τ5
Quantum
T1
Running
F2
task
τ4 Quantum
T2
F3
τ2 τ10 τ1 Quantum
T3
185
Example of circular scheduling
Configuration
Tasks τ1 τ2 τ3 τ4 τ5
Execution time 10 ms 20 ms 30 ms 40 ms 50 ms
Scheduling
186
Outline - III.2 – Uniprocessor scheduling
1. Recalls
2. Real-time scheduling
3. Priority-based Scheduling
187
Priority-based scheduling
188
Priority-based scheduling: example
SIGNAL_EVT(evt2)
task τ1 t
task τ2 t
Background task t
189
Classical algorithms for choosing the priority
Constant priority:
1. Rate monotonic (RM)
2. Deadline monotonic (or inverse deadline, DM)
3. Audsley algorithm
4. …
Dynamic priority:
1. Earliest deadline first (EDF)
2. Least laxity (LL)
3. …
190
Optimality
Corollary :
– Any application A in T schedulable by an algorithm in C, is also schedulable
by P.
191
Rate monotonic (Liu & Layland 1973)
Hypothesis:
Periodic independent tasks with simultaneous start (for all i ri = 0)
Priority:
given to the smallest period
Example:
(r=0, C=3, T=20)
(r=0, C=2, T=5)
(r=0, C=2, T=10)
U=?
Scheduling?
192
Exercise 1 on RM
τ2 0 40 150 150
τ1 t
100 200 300
τ2 t
100 200 300
τ3 t
100 200 300
τback t
100 200 300
193
Exercise 2 on RM
T ri Ci Di Ti Prioi
τ1 0 1 2 3
τ2 0 3 5 6
τ1 t
3 6
τ2 t
3 6
194
Results for RM
Optimality:
RM is optimal for the family of independent periodic tasks with r=0,
P=D and static priority:
if any static priority preemptive scheduling algorithm can meet all the
deadlines, then the rate monotonic algorithm can too
195
Feasibility tests for RM
196
Schedulablity for RM: processor utilisation
0
1 2 3 nombre
numberde of
tâches
tasks
Reference: Liu&Layland 73
197
Critical zone theorem for RM
The theorem of the critical zone is less restrictive than the processor utilisation condition.
If all the tasks respect their first deadline then they will respect all their deadlines.
Let τ1,...,τn be n tasks (Ti,0,Ci,Di) such that Ti ≤ Ti+k, the tasks are schedulable if and only
if
i Cj
∀i, 1 ≤ i ≤ n min ∑ t T j ≤ 1
0 ≤t ≤ Di t
j =1
Ri0 = C i
Rin
R i
n +1
= C i + ∑ C j
j∈hp ( i ) T j
References:
-M. Joseph and P. Pandya, Finding response times in a real-time system, The Computer Journal
29 (5) (1986), pp. 390–395.
-J P Lehoczky, Fixed priority scheduling of periodic task sets with arbitrary deadlines (1990), In
Proc. of the 11th IEEE Real-Time Systems Symposium
199
Computation of the response time for RM
T ri Ci Ti
τ1 0 2 7
τ2 0 1 4
τ3 0 6 14
200
Deadline monotonic (Leung & Whitehead, 1980)
T ri Ci Di Ti Prioi
τ1 0 1 2 2
τ2 0 1 1 3
τ1 t
3 6
τ2 t
3 6
201
Results for DM
Optimality:
RM is optimal for the family of independent periodic tasks with r=0,
T>=D and static priority
∑ i i
C /
i =1
D ≤ n ( 21/ n
− 1)
202
Critical zone for DM
Let τ1,...,τn be n tasks (Ti,0,Ci,Di) such that Ti ≤ Ti+k, the tasks are schedulable if and
only if
i− 1
∀i, 1 ≤ i ≤ n C i + ∑ Cj Di T j ≤ Di
j= 1
203
Optimality of DM
Optimality of DM:
– In the class of static priority preemptive scheduling, for independent periodic
tasks with T ≤ D, the politicy DM is optimal.
∀i, Di ≤ Pi ∧ ∀(i, j ), Ci ≤ C j ⇒ Di ≤ D j
204
RM and DM example
T ri Ci Di Ti PrioRM PrioDM
τ1 0 1 3 3
τ2 0 1 4 4
τ3 0 2 5 5
τ1 t
4 8 12 16 20 24
τ2 t
4 8 12 16 20 24
τ3 t
4 8 12 16 20 24
τfond t
4 8 12 16 20 24
205
Audsley priority assignment (Audsley 1991)
Context:
– For independent periodic tasks with T≤D and r non necessarily null.
Algorithm:
– The response time only depends (for static priority) on the higher priority tasks
and is independent from the combination of lower priorities. The idea is then
to search among the set of tasks a candidate to have the lowest priority. The
task accepts if the feasibility test is fine. Re do the same for the rest of tasks.
Feasibility test:
– The schedulability is ensured by construction
Optimality
206
Audsley priority assignment
T ri Ci Di Ti Prio
τ1 0 1 3 3
τ2 1 4 9 9
τ3 3 2 5 7
5
4
2
…
1
1 2 3 4 5 6 7 8 9
Optimality:
– In the class of dynamic priority preemptive scheduling, for independent periodic tasks,
the policy EDF is optimal.
– For non preemptive scheduling, EDF is not anymore optimal
208
EDF: example
T ri Ci Di Ti
τ1 0 1 3 3
τ2 0 1 4 4
τ3 0 2 5 5
Di(t)
τ1 t
4 8 12 16 20 24
Di(t)
τ2 t
4 8 12 16 20 24
Di(t)
τ3 t
4 8 12 16 20 24
209
Least laxity first (LLF)
Optimality:
– In the class of dynamic priority preemptive scheduling, for independent
periodic tasks, the policy LLF is optimal.
210
LLF: example
Li(t)
τ1 t
T ri Ci Di Ti
4 8 12
τ1 0 1 3 3 Li(t)
τ2 t
τ2 0 1 4 4 4 8 12
Li(t)
τ3 0 2 3 6 τ3 t
4 8 12
LLF t
EDF t
RM t
DM t
211
Outline - III.2 – Uniprocessor scheduling
1. Recalls
2. Real-time scheduling
3. Priority-based Scheduling
212
Scheduling with shared resources
Problems encountered:
- Blocking
- Priority inversion phenomenon
- Scheduling anomaly
213
Anomaly of scheduling
τ1 t shared resource
4 8 12
τ2 t
4 8 12
τ3 t C3=4, simu OK
4 8 12
τ1 t
4 8 12
τ2 t
4 8 12
214
Priority inversion
τ1 t shared resource
4 8 12
τ1> τ2> τ3
τ2 t
4 8 12 Request for the
resource
τ3 t
4 8 12
Priority inversion
215
A solution: PIP Priority inheritance protocol
Context:
– Static priority algorithms
Principle:
– When a task is blocked when accessing a resource, the task which is locking
the resource inherits during the critical section of the priority of the requesting
task.
Result:
– Suppression of priority inversion
– Other tasks may be blocked
Reference:
- L. Sha, R. Rajkumar and J. P. Lehoczky, Priority inheritance protocols : an
approach to real-time synchronisation, IEEE Transactions on Computer, vol. 39
(1990), pp. 1175–1185.
216
PIP example
τ1 t shared resource
4 8 12
τ2 t τ1> τ2> τ3
4 8 12
Request for the
τ3 t resource
4 8 12
τ1 t
4 8 12
τ2 t
4 8 12
τ3 t
4 8 12
217
References
218
Outline - Part III - Scheduling
1. First definitions
219
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
220
General principles
We consider:
– a set of n tasks S= {ττ1, τ2,…, τn }
– a parallel architecture composed of m processors P={p1, p2,…,pm}
(applies for multicore)
Objective:
– schedule the tasks on the platform.
• Resolution of two problems: allocation (on which processor) and priority
Constraints:
– A processor executes at most a task at a time
– A task executes at most on one processor at an instant
221
Taxonomy of the multiprocessor platform
• Identical: all the processors are assumed to be identical, with the same
computing capacity.
222
Taxonomy of the multiprocessor scheduling (I)
a new period
Task execution on the processors:
p1
• No migration: each task is allocated on a unique
p2
processor and never changes
a new period
• Task-level migration: the jobs may execute on
p1
different processors, but a job is allocated on a
p2
unique processor and never changes
a new period
• Job-level migration (or full migration): a job can
migrate p1
p2
priority
Priorities:
• Fixed task priority: each task has a fixed priority time
forever
• Fixed job priority: the jobs may have several priority
priorities, but each job has a fixed priority (e.g.
EDF) time
• Dynamic priority: the priority of a job may evolve priority
(e.g. LLF)
time
223
Taxonomy of the multiprocessor scheduling (II)
224
Comparison of scheduling policies
– Dominance
P2
P1 ⊂ P2 P1
– Equivalence
P2
P1 = P2 P1
– Incomparable
P1 P2
P1 ⊗ P2
[Park 2007]
225
Current state of the art
226
Optimality (non) results
“In 1988, Hong and Leung proved that there is no optimal online
scheduling algorithm for the case of an arbitrary collection of jobs that
have more than one distinct deadline, and are scheduled on more than
oneprocessor. Hong and Leung showed that such an algorithm would
require knowledge of future arrivals and execution times to avoid making
decisions that lead to deadline misses; hence optimality in this case
Is impossible without clairvoyance. In 1989, this result was extended by
Dertouzos and Mok who showed that knowledge of arrival times is
necessary for optimality, even if execution times are known.”
[Davis&Burns09]
NB: A scheduling algorithm is said to be clairvoyant if it makes use of
information about future events, such as the precise arrival times of sporadic
tasks, or actual execution times, which are not generally known until they
happen.
227
Families of algorithms
CPU1
τ1 τ5 τ4 τ1 CPU1 τ1
τ5 τ4 τ3 τ2 τ1 CPU2
τ2 τ3 τ2 CPU2 τ2
CPU3
τ3 CPU3
228
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
229
Partitioning
• Correspondence
– objects = tasks
– The size of the boxes depends on the policy
230
Heuristic for partitioning
231
Ordering policies
233
Allocation algorithm
1. First fit: place the item in the first bin that can accommodate it
• Example with IP and RM
τ1=(4,1,4,0)
τ2=(8,2,8,0) P1 P2
τ3=(20,10,20,0)
P1 t
2 4 6 8 10 12 14 16
P2 t
2. Best fit: place the item in a bin that can accommodate it and with the
smallest available size
3. Next fit: place the item in the next bin that can accommodate it (it starts
from the previous bin which have been used)
4. Worst fit: place the item in a bin that can accommodate it and with the
largest available size
Exercise: apply for all the algorithms on the example
234
Heuristic for partitioning
235
Exercises
T ri Ci Ti
τ1 0 3 7
τ2 0 2 4 Number of processors = 2
Apply the following heuristics:
τ3 0 6 14 1. FFDU-EDF
2. WFDE-LLF
τ4 0 7 20
236
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
1. Policies
2. Schedulability tests
3. PFair
4. LLREF
237
Multiprocessor scheduling policies
238
Example of global DM scheduling
T ri Ci Di Ti
τ1 0 1 4 4
τ2 0 2 8 8
τ3 0 3 16 16
P1 t
2 4 6 8 10 12 14 16
P2 t
239
gEDF and gLLF
T Ci Ti
τ1 2 3
This task set is gLLF schedulable but not gEDF
τ2 2 3 Prove it.
τ3 2 3
T ri Ci Di Ti
τ1 0 1 5 10
τ2 0 1 5 10
This task set is gEDF schedulable but not gLLF
τ3 0 3 6 10 Prove it.
τ4 1 3 9 10 [Kal00]
τ5 4 5 9 10
τ6 4 5 9 10
240
Comparison between 9 classes
3: full migration (1,3)-scheduling (2,3) (3,3)
2: task level migration (1,2) (2,2) (3,2)
P2
1 2 3 4 5 6 7 8 9 10 11 12 13 241
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
1. Policies
2. Schedulability tests
3. PFair
4. LLREF
242
Not applicable
T ri Ci Ti P1
2 4 5 OK
τ1 0 5 5
P2
gRM
τ2 0 2 5
P1
KO
τ3 0 2 5 2 4 5
P2
T Di Ci Ti P1 1 3
τ1 2 2 8 2 6 8 12 16
τ2 2 2 10 P2 2 4
τ3 6 4 8 gDM
τ4 7 4 8 R41=6 R41=8
243
Contre-intuitive observations (1)
T ri Ci Di Ti
1
τ1 0 1 1 2
3
2 3
τ2 0 1 1 3
τ3 0 5 6 6
The processor demand decreases but the task set become unschedulable
244
Contre-intuitive observations (2)
T ri Ci Di Ti T ri Ci Di Ti
τ1 0 4 4 100 τ1 0 4 4 100
τ2 0 2 2 100 τ2 0 2 2 100
τ3 0 2 6 100 τ3 0 2 6 100
τ4 0 4 8 100 τ4 0 4 8 100
τ5 5 2 2 100 τ5 6 2 2 100
τ6 5 1 1 100 τ6 6 1 1 100
τ7 6 1 2 100 τ7 6 1 2 100
1 3 5
P1 1 3 5 P1
2 5 6 8 2 5 6 8
P2 2 3 4 6 7 4 P2 2 4 6 7
3 and 4 have each their turn the priority 4 has a higher priority
245
Schedulability test
246
Utilisation bounds
Theorem
1. For (3,3), synchronous task set with implicit deadline, Umax=m
2. For (x,y) with x,y ≠ 3, Umax≤(m+1)/2
Proof:
1. Cf PFair or LLREF
2. Consider a task set
t1 = (1+ε, 2)
m
t2 = (1+ε, 2)
U = ∑ (1 + ε ) / 2 = (m + 1)(1 + ε ) / 2 →ε →0 (m + 1) / 2
…
i =1
tm+1 = (1+ε, 2)
[Park 2007]
247
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
1. Policies
2. Schedulability tests
3. PFair
4. LLREF
248
PFair (Proportionate Fair) [Baruah et al 1996]
Basic Ideas:
–PFair tries to track the ideal scheduling
–For task (C,T), the ideal scheduling is WT(t)=t*C/T
Example: τ = (2,5)
3
2 Sched(t)
WT(t)
1
0
0 1 2 3 4 5 6
The tracking is formalised using the function
–lag(t) = WT(t) – sched(t)
–A schedule is PFair if lag (t ) ∈ [ −1,1]
Allocation 2
[Park 2007]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
249
PFair scheduling
Ideas:
–Processor time is allocated in multiples of some basic quantum.
–Break tasks into subtasks of length 1.
–Assign deadlines and release times to subtasks.
• deadline and release time of subtask i are
i i − 1
di = ri =
U U
window of the
window of the second subtask
first subtask
0 1 2
time
quantum 0
T= 11
[Park 2007]
250
PFair scheduling
time
Exercise: Find a PFair scheduling for (4,9)
251
PFair scheduling algorithm
τ1k+1
2- d(τ1k) = d(τ2k’) and b(τ1k) > b(τ2k’) τ1k
with b(τ1k) =d(τ1k) - r(τ1k+1) τ2k’+1
τ2k’
(number of slots by which τi’s window overlaps τi+1’s window)
{( ) (
D (τ k ) = min t t = d (τ k + p ) ∧ b(τ k + p ) = 0 ∨ t = d (τ k + p ) − 1 ∧ W (τ k + p ) = 3 )}
252
Exercise
τ1 2 3
τ2 4 6
τ3 6 12
253
PFair results
254
Outline – III.3 – multiprocessor scheduling
1. Generalities
2. Partitioned scheduling
3. Global scheduling
1. Policies
2. Schedulability tests
3. PFair
4. LLREF
255
LLREF (Least Local Remaining Execution First)[Cho et al 2006]
Tasks are splitted not at time quantum, but at scheduling events (at release
instants)
Two parameters
ND (t ) − t
1. Local remaining execution time lτ (t ) = Cτ (t ) ×
Tτ − t
2. Local laxity Lτ (t ) = ND (t ) − lτ (t )
Priority
1. Highest priorities for the tasks with Lτ=0
2. τ1 has a higher priority than τ2 if lt1 > lt2
Quantum
1. If τ1,.., τΜ have the highest priority at time t, they keep the CPUs until t’=min{lτ}
256
References
257