Distributed Embedded Real-time Systems
Transcript of Distributed Embedded Real-time Systems
-
8/12/2019 Distributed Embedded Real-time Systems
1/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
1
Distributed Embedded
Real-time Systems
Zhonghai Lu
KTH Royal Institute of Technology
Agenda
Real-time networking
Real-time communication and analysis: CAN
End-to-End WCRT analysis for CAN
Real-time communication: TTP
Application to automobile communicationnetworks
March 1, 2014 2
-
8/12/2019 Distributed Embedded Real-time Systems
2/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
2
Realtime systems
Correct systemoperations mean notonly results correctbut also completion ingood time.
Timeliness
Soft deadline Firm deadline
Hard deadline
March 1, 2014 3
Embedded Realtime systems
Uniprocessor system Multiple tasks on one CPU with focus on scheduling policies and
schedulability analysis
Multiprocessor system Multiple tasks multiple CPUs, assuming task communication in
shared variables and synchronization via lock, semaphore etc.
Distributed system Tasks communicate via message passing (not shared variable)
on a bus or network shared communication media Interaction between computation and communication tasks
March 1, 2014 4
-
8/12/2019 Distributed Embedded Real-time Systems
3/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
3
Disturbed embedded systems
March 1, 2014 5
Computation
Communication
Control
System architecture
March 1, 2014 6
H. Kopetz. A Comparison of CAN and TTP. Annual Reviews in Control, 24:177188, 2000.
A distributed vehicle control system
-
8/12/2019 Distributed Embedded Real-time Systems
4/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
4
Real-time networking
The end-to-end communication delay must be bounded! All services at all layers must be time-bounded
Requires appropriate time-bounded protocols
Distributed systems Node distribution
For embedded systems Not like open networking systems, embedded systems are closed
systems with good knowledge of application requirements Reliability and cost-efficiency
Centralized arbitration vs. Distributed arbitration
March 1, 2014 7
Protocol stack
The 7 OSI layers impose aconsiderable overhead forembedded implementations.
Many real-time networks are dedicated to a well-defined
application (no need forpresentation)
use single network domain (noneed for routing)
use short messages (no needto fragment/reassemble)
March 1, 2014 8
-
8/12/2019 Distributed Embedded Real-time Systems
5/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
5
Collapsed OSI model
Application accesses the Data Link directly
Other layers may be present but are not fullystacked
In industrial automation these networks arecalled field buses
March 1, 2014 9
Data Link Layer
Addressing
Logical Link Control (LLC) Transmission error control
Medium Access Control (MAC) for sharedmedia
March 1, 2014 10
-
8/12/2019 Distributed Embedded Real-time Systems
6/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
6
Data link layer: Addressing
Direct addressing The sender and receiver(s) are explicitly identified in every
transaction, using physical address (MAC addresses inEthernet)
Indirect (source) addressing The message contents are explicitly identified (e.g. temperature
of sensor X).
Receivers that need the message retrieve it from the network
(as in CAN) Indirect (time-based) addressing
The message is identified by the time instant at which it istransmitted (as in TTP Time Triggered Protocol)
March 1, 2014 11
Data link layer: LLC
Upper sub-layer of the data link layer, dealing with thereliable information transfer at this level
Typical services Data transfer schemes
Send with immediate acknowledge: Sender waits for acknowledge from receiver Send without acknowledge: No synchronization between data and receiver
Connection-oriented services: A connection must be established before anycommunication may take place
Specify error detection and action upon this. Typical actions are Forward error correction (FEC): Error correcting codes (more related to the
physical layer)
Automatic Repeat reQuest (ARQ): The receiver triggers a repeat request uponerror
Positive Acknowledgement and Retry (PAR): The sender resends if ACK is notreceived
March 1, 2014 12
-
8/12/2019 Distributed Embedded Real-time Systems
7/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
7
Data link layer: MAC
Medium Access Control (MAC) Lower sub-layer of the data link layer Determines the order of the network access by
contending nodes and, thus the network accessdelay
Crucial for the real-time behavior of networks
that use a shared medium
March 1, 2014 13
MAC protocols
Master-slave
TDMA
Token circulation
CSMA CSMA-CD CSMA-CR
March 1, 2014 14
-
8/12/2019 Distributed Embedded Real-time Systems
8/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
8
MAC: Master-Slave
Access is granted by the Master node Nodes synchronized with the master Requires one control message per data message
Example: LIN, Bluetooth (within piconets)
March 1, 2014 15
What if multiple masters?Master
Slave Slave Slave
1
2
LIN: Local Interconnect
Network
LIN is a broadcast serial network protocol used forcommunication between components in vehicles. Itaims for cost-efficiency to complement CAN. It comprises one master and typically up to 16 slaves.
All messages are initiated by the master with at most one slave replying toa given message identifier. The master node can also act as a slave byreplying to its own messages.
Because all communications are initiated by the master it is not necessaryto implement a collision detection.
The master is typically a microcontroller, whereas the slavesare implemented as ASICs.
March 1, 2014 16
-
8/12/2019 Distributed Embedded Real-time Systems
9/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
9
MAC: TDMA
Time-Division Multiple Access Access granted in a dedicated time-slot
Time slots are pre-defined in a cyclic framework
Requires global clock synchronization
High data efficiency
Typically uses static table-based scheduling
Example: TTP/C, TT-CAN, PROFINET
March 1, 2014 17PROFINET is a standard for industrial automation using a computer network
Node A Node B Node C Node C
MAC: Token circulation
Access is granted by the possession of a token
Order of access enforced by token circulation
Real-time operation requires bounded token
holding time Example: FDDI, PROFIBUS
March 1, 2014 18
PROFIBUS (Process Field Bus) is a standard forfieldbus communication in automation technology.
Fiber Distributed Data Interface (FDDI) is a data-transmission standard for in a LAN:
Node AT
Node B Node C
Node D Node E
Token
circulation
-
8/12/2019 Distributed Embedded Real-time Systems
10/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
10
MAC: CSMA
Carrier-Sense Multiple Access
Set of protocols based on sensing businactivity before transmitting (asynchronousbus access)
Collisions may occur.
Upon collision, nodes back off and retry later,according to some specific rule (this ruledetermines to a large extent the real-timefeatures of the protocols)
March 1, 2014 19
CSMA - CD
Carrier-Sense Multiple Access with Collision Detection Used in shared Ethernet (hub instead of switch)
Collisions are destructive and are detected within collision window
Upon collision, the retry interval is random and the randomization
window is doubled for each retry until 1024 slots Non-deterministic (e.g., chained collisions)
Not suitable for a real-time network. However,
The physical Ethernet layer is often used in real-time networks.
It is possible to get real-time performance on an Ethernet network,if the access to the medium is scheduled in some way, i.e.,collisions are avoided
March 1, 2014 20
-
8/12/2019 Distributed Embedded Real-time Systems
11/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
11
CSMA - CR
Carrier-Sense Multiple Access with Bit-Wise Arbitration,also called CSMA/CR (Collision Resolution)
Bit-wise arbitration with non-destructive collisions
Upon collision, highest priority node is unaffected. Nodeswith lower priorities retry right after
Deterministic in priority arbitration
Example: CAN
March 1, 2014 21
Communication alternatives
Event-Triggered (ET) communication Communication activities are driven by occurrences of events
More flexible
Time-Triggered (TT) communication Communication activities are driven by the progress of time Dependability is much easier to ensure using a time-triggered bus
Hybrid ET+TT communication
Examples in the automobile industry Event-triggered: LIN, CAN* Time-triggered: TTP/A, TTP/C Hybrid: TT-CAN, FlexRay
March 1, 2014 22
-
8/12/2019 Distributed Embedded Real-time Systems
12/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
12
Summary
MAC is crucial for real-time performance Master-slave
Token passing
TDMA
CSMA CSMA-CD
CSMA-CR
ET vs. TT architectures Examples in the automobile industry Event-triggered: LIN, CAN*
Time-triggered: TTP/A, TTP/C
Hybrid: TT-CAN, FlexRayMarch 1, 2014 23
Real-time Communication:
The CAN bus
Zhonghai Lu, Yang Chen
KTH Royal Institute of Technology
-
8/12/2019 Distributed Embedded Real-time Systems
13/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
13
Automobile Communication
Network
March 1, 2014 25Renesas Electronics Corp. Introduction to CAN.
AutomobileCommunication Network
March 1, 2014 26
-
8/12/2019 Distributed Embedded Real-time Systems
14/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
14
Control ler Area Network
Birth of CAN Developed originally by BOSCH in 1983,
standardrised in 1993 (ISO 11898)
Purpose Find a bus protocol with good real-time
performance and which can be analysed to showworst case timing behaviour
March 1, 2014 27
History
Developed by BOSCH Starting in 1983 presented at SAE in 1986
Standardized by ISO in 1993 (11898)
First CAN controller chips Intel (82526), Philips (82C200) in 1987
First production car using CAN 1991 Mercedes-Benz S-class (W140)
Milestone of success 1995 Volvo S80 (P23) (with hard real-time guarantee)
March 1, 2014 28
-
8/12/2019 Distributed Embedded Real-time Systems
15/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
15
Nowadays
Today almost everynew car sold in Europeuses CAN bus
Sales ofmicroprocessors withon chip CAN capability
increased from under50 million in 1999 toover 750 million in 2010
March 1, 2014 29
Advantages
Token Ring the previous solution Pass the token among processors. The processor
holding the token has the right to transmit
Urgent messages have to wait for the token, whichcauses low real-time performance
Short intervals cause large protocol overhead
Advantages of CAN Associate a priority with each message and use
priority based arbitration mechanism to ensure thatthe higher priority message has shorter delay
March 1, 2014 30
-
8/12/2019 Distributed Embedded Real-time Systems
16/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
16
CAN Bus
CAN is a multi-master CSMA/CR serial bus 1 Mbit/sec with the length no longer than 50m 500Kbit/sec with the length no longer than 100m Arbitrary number of CAN stations can be connected
March 1, 2014 31
Host
Processor
CAN
Controller
CAN BUS
ECU
Host
Processor
CAN
Controller
ECU
ECU:Execution Control Unit
CAN bus features
Priority-based Messages have a unique (pre-defined) global identifiers.
Report error if two messages are found with the sameidentifier.
Each node can send many messages Non-preemptive
Message being transmitted can not be preempted byhigher priority messages
March 1, 2014 32
-
8/12/2019 Distributed Embedded Real-time Systems
17/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
17
Distributed priority arbitration
CAN physical layer sends a bit stream, with each bitsupports two states: 0dominant, 1recessive
Transmit ID from the most significant ones. Collisions among identifier bits are resolved by the
logical AND semantics, and each node reads thebus state while it transmits
Node reads its identifier bits on the medium without
any change, it realizes it is the winner
March 1, 2014 33
Transmission
Transmission steps CAN nodes wait for bus idle before starting
transmission
Synchronise on the SOF bit (0) Each node starts to transmit the ID for arbitration Node transmitting highest priority message wins
arbitration, which then completes the transmission
March 1, 2014 34
-
8/12/2019 Distributed Embedded Real-time Systems
18/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
18
Example of Bus Arbitration
March 1, 2014 35
Standard11-bit identifier
Smaller Id value, higher priority.
CAN Frames
Messages are transmitted in frames. Frame Types:
Data: data information
Remote: request transmission of a Data frame
Error: transmitted whenever a node detects an error
Overload: for flow control to request an additionaltime delay
March 1, 2014 36
-
8/12/2019 Distributed Embedded Real-time Systems
19/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
19
CAN Frame Format
Arbitration field: ID with 11 bit (standard) or 29 bit (extended)
ID associates priority A message with smaller ID has higher priority
March 1, 2014 37
Bit Stuffing
If 5 consecutive bits with the same levelappear, one bit of inverted data is added 000000 and 111111 are used to signal errors
March 1, 2014 38
How many stuffing bits are needed?
'5
ll
l ' l1
4
21 bits
26 bits
-
8/12/2019 Distributed Embedded Real-time Systems
20/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
20
Message
maximum transmission time
Worst case bit stuffing
l is the size of bits that are related to bit stuffing
Maximum transmission time si is message size in byte g is the sum size of
arbitration, control andCRC field
tbit is the time to transmitone bit
March 1, 2014 39
l ' l1
4
Ci g 8si 1
4
g 8si 13
tbit
Standard 11-bit identifier
What is the maximum size of a frame?
Summary
Messages are transmitted in bit-stream frames,which are prioritized globally. An identifier is transmitted along with data
Bit stuffing to accommodate special-purpose codes Use CSMA-CR as MAC for the serial bus
Natural AND to determine the winner upon collision
Higher priority wins over lower priority frames.
Deterministic maximum messagecommunication time (no bus contention) Non-preemptive transmission
March 1, 2014 40
-
8/12/2019 Distributed Embedded Real-time Systems
21/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
21
Real-time Communication
Analysis on CAN
Zhonghai Lu, Yang ChenKTH Royal Institute of Technology
Real-time analysis for CAN
A common misconception in the early 1990s Good at transmitting the highest priority message with low
latency, but not possible to guarantee low priority messages
Real-time analysis for CAN Tindell and Burns (York University, 1994) showed how
research into fixed priority pre-emptive scheduling forsingle processor systems could be adapted and appliedto the scheduling of messages on CAN
In 1995 it was recognized by Volvo Car Corporation andused in the development of the Volvo S80 (P23)
Due to Tindells work, CAN has been widely recognized since1995
March 1, 2014 42
-
8/12/2019 Distributed Embedded Real-time Systems
22/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
22
Message modeling
Periodic messages
Each message has Unique priority Pi
smaller i, higher priority
Period Ti Maximum transmission time Ci Queuing jitter Ji Deadline D
i(D
i T
i)
Worst-case Response time(WCRT)Ri
March 1, 2014 43
Queuing Jitter
Queuing jitter The maximum difference between the reference
arrival and the actual arrival of a message
Reason causing queuing jitter Task queuing the message may be finished very
soon (BCRT) or finished with WCRT of the task. E.g., Task j queues message i, Ji (queuing jitter) is
equal to Rj (WCRT BCRT of task j)
March 1, 2014 44
-
8/12/2019 Distributed Embedded Real-time Systems
23/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
23
WCRT analysis
Two steps Determine the worst case Calculate WCRT from the worst case
To determine the worst case, need to consider Starting of tasks are asynchronously Different combinations of the starting cause
messages experiencing different response time
March 1, 2014 45
Crit ical Instant
Critical Instant ofMi Mi with maximum queuing jitter is queued with all higher
priority message simultaneously, then each of these higherpriority messages is subsequently queued again after theshortest possible time interval
A lower priority message with maximum execution starts to betransmitted just before the instant, so called priority inversion
March 1, 2014 46
C1 2
C2 1
C3 2
-
8/12/2019 Distributed Embedded Real-time Systems
24/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
24
Priori ty Inversion
Blocking time due to priority inversion A message may suffer from blocking that is the delay
caused by transmission of a lower priority message
Maximum blocking timeBi
Upper-bounded by Example:
Mk is the lower priority message with largest size
Mi is queued just after the SOF bit ofMkhas been sent
March 1, 2014 47
Bi maxklp(i )
(Ck ) 135tbit
135 bitt
WCRT Calculation
Wi: waiting and communication time Hp(i): higher priority messages than i Bi: blocking time caused by lower priority message
March 1, 2014 48
Ri Ji wi
win1 Ci Bi
Jkwin
Tk
khp(i )
Ck
-
8/12/2019 Distributed Embedded Real-time Systems
25/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
25
Example of WCRT Analysis
49
0
2
12 2 2 1
2
2 2 2 1
3
2 2 2 1
0
5
2 7
2 7
w
w C B C
w C B C
w C B C
RiJi wi
win1 Ci Bi
Jk win
Tk
khp(i ) Ck
March 1, 2014
C1 2
C2 1
C3 2
1
2
3
1
1
1
J
J
J
T1 5
T2 20
T3 100
2 3 2B C
2 2 2 7 1 8R J w
Compute WCRT of message MA2
Summary
Message modeling Queuing jitter
Priority inversion
WCRT analysis of CAN message Identify the critical instant (higher priority
messages and a lower priority message) WCRT calculation for the critical instant scenario
using the formulas
March 1, 2014 50
-
8/12/2019 Distributed Embedded Real-time Systems
26/26
IL2226 Embedded SystemsDesign: Lecture 7
3/1/2014
Acknowledgements
Karl-Erik rzen , Lecture slides on Realtime systems, LundUniversity.
Ken Tindell and Hans Hansson. Real Time Systems by FixedPriority Scheduling, Uppsala University, October 1997
H. Kopetz. GNTHER BAUER. The Time-Triggered Architecture.PROCEEDINGS OF THE IEEE, VOL. 91, NO. 1, JANUARY 2003.
H. Kopetz. A Comparison of CAN and TTP. Annual Reviews inControl, 24:177188, 2000.
Safety-related architectures and time-triggered networkshttp://www.ttagroup.org/ FlexRay: Automotive Communication Bus Overview. National
Instrument, Aug 21, 2009
March 1, 2014 51
Acknowledgements
Marco Di Natale, Haibo Zeng, Paolo Giusto, Arkadeb Ghosal,Understanding and Using the Controller Area NetworkCommunication Protocol Theory and Practice
Roman ObermaisserTime-Triggered Communication (EmbeddedSystems)Nov. 2011
R.I.Davis, A. Burns, R.J. Bril, and J.J. Lukkien. Controller AreaNetwork (CAN) Schedulability Analysis: Refuted, Revisited andRevised. Real-Time Systems, Volume 35, Number 3, pp. 239-272,April 2007.
March 1, 2014 52