Real-Time Networks and Distributed Systems
Real-Time Networks and Distributed Systems
1 2
C
A
C D
5 6
1
10/13/2008
Time triggered:
SAFEbus - airplanes, eg. Boeing
TTA - cars, eg. Audi, Volkswagen
FlexRay - cars, eg. BMW, DaimlerChrysler
Time triggered Event triggered Event triggered
TDMA CSMA/CR (Collision Resolution) CAN - cars, eg. Volvo, Saab, VW, Ford, GM
(Time Division Multiple Access,e.g. GSM ) (Carrier Sense Multiple Access / Collision Resolution) Byteflight - cars, BMW
Pre-Scheduled Priority driven LIN – a cheaper and simple bus protocol
Predictable Dynamic Scheduling
Testable Flexible Mixtures
Static e.g. CAN Time-Triggered CAN (TTCAN)
Pri: A>B>C>D
e.g. TTP TTA extended with events
0 T time 0 time
Response time for C
7 8
9 10
Message based with payload size 0-8 bytes CAN bus can have an arbitrary number of nodes
Not for bulk data transfer! Nodes do not have proper addresses
But perfect for many embedded control applications Rather, each message has an 11-bit “field identifier”
In extended mode, identifiers are 29 bits
Everyone interested in a message type listens for it
CAN interfaces are usually pretty smart Works like this: “I’m sending a temperature sensor reading”
Interrupt only after an entire message is received Not like this: “I’m sending a message to node 8”
Filter out unwanted messages in HW – zero CPU load
Designer should allocate the message identifiers to the
stations (different nodes send different messages!)
11 12
2
10/13/2008
Remote frame:
Frame requesting the transmission of a specific identifier
Error frame:
Frame transmitted by any node detecting an error
3.5 V
CAN_H
Node
2
Node
3
Node
n A frame is tagged by an identifier
120 R 120 R
indicates contents of frame D
also used for arbitration as ”priority” B
Bit-wise arbitration A C
15 16
Send theresten
Skicka rest of
av ramen
the frame
17 18
3
10/13/2008
Schemes for protecting against this have been When error is detected by node it sends an
developed but are not commonly deployed error frame
Most likely this happens very rarely
starting with 6 dominant bits (000000) in a row
CAN bus is usually managed by hardware
tells other nodes that error occurred
other nodes then also send error frames
Arbitration restarts when bus is idle
CAN has a mechanism to protect against broken After the priority transmitted (the arbitration is finished), the
rest of the message is transmitted
hardware: error counters
A message contains: 0-8 bytes for data and 47bits OH
The CAN controller in a node counts failed frames and Priority/identity: 11bits
successful frames Data field: 0-8 bytes long
When errors exceed a threshold, the controller gets disconnected CRC field (checksum, parity bits etc: checking the message has
ERROR-counter EC not been corrupted, and other ”housekeeping” bits)
EC:= EC+1 when an error is signalled Out of the 47, 34 bits are bitstuffed
EC:= EC-1 when a frame is correctly received 000000 and 111111 are reserved as ”marker” to signal all
EC > K the node shuts-off itself (is fail-silent) stations on the bus
So ”bitstuffing” is needed: whenever 00000 or 11111 appears in a
bitstream, an extra bit of the opposite sign should be added
E.g. 1111 1000 0111 1000 0111 1 should be
1111 1000 0011 1110 0000 1111 10
21 22
The total number before bitstuffing: 8n+47 Network scheduling is usually non-preemptive
Non-preemptive scheduling means high-priority sender must wait while
After bitstuffing: 8n+47+(34+8n-1)/4
low-priority sends
Short message length keeps this delay small
Max: 64+47+24=135 bits
E.g. 1Mbit/sec, 1 bit needs 1 micro seconds
The max transmission time for one message= 135
micro sec
23 24
4
10/13/2008
Transmission Delay
A
A C
Mj = < Tj, Cj > (Mj M )
Tj = period (time betw een queuing)
Cj = transmission time
Bj = blocking time (waiting for low priority message, bus non-preemptive)
The whole bus + CAN
controllers can be
abstracted as one queue
A
Worst-case waiting/queuing time (before transmission ):
qi = Bi +S j hp(i) qi/Tj Cj
B
Removed after
C transmission time
hp(i) = frames with priority higher than Pi
Frame in
D Priority queue
transmission Worst-case Response time (delay before delivered) :
Bi = MAX
A C
k lp(i) (Ci) <= time to transmit 135 bits
Unfortunately not!
Worst case: Bi = Ci= 135 micro sec Non-periodic queuing times causes jitter
(for 1MB/sec CAN) No global time reference
Transmission errors (recovery + retransmission)
27 28
D
B
C
A New equation for worst-case Transmission Delay:
task_1 RTOS
Task_3 on node A executes with certain
task_2 period
task_3
task_4 Message mAtoB gets same period as R i = J i +q i + C i
task_3() { task_3 qi = Bi +S j hp(i) (qi+Jj)/TjCj
Shortest time before send:
while(1) {
read_sensor();
if(...)
// do some work
BCET = C3 min for task_3
else
// do some other work
Longest time before send: task_3’s worst
send_CAN(m AtoB, prio); case response time = R3
// some more work
sleep_until_next_period(); R3 - C3 min= jitter for message mAtoB
}
29 30
5
10/13/2008
Analysis of Distr.
Transmission Errors
Systems
Max number of errors must be bounded
D
B
C
Fault hypothesis
A
Error function E(t) = max time required for error Detect obstacle Initial Send msg Calculate Send msg Inflate
signalling and recovery in any time interval of length t (read sensor) processing on bus action on bus airbag
time
31 32
When tasks on a node can both send and receive Tasks on CPUs are exchanging msgs over CAN
messages we have a holistic scheduling problem
Tasks are queuing messages
The equations giving the worst case time for
Completion times will vary =>
tasks depends on messages arriving at the node
Jitter (variations in release times) will be inherited
We cannot apply the processor
scheduling analysis before we send(i)
0 CPU
dest(i)
Message m(i), queued by a task send(i):
act(i)
get values from the bus Jm(i)= Rsend(i) – Csend(i)
scheduling analysis m sg(i)
33 34
Distributed Systems
0
send(i) dest(i)
CPU
Example: m sg(i)
35 36
6
10/13/2008
Event Driven
Peak Load Deadline for
message 9 Other Solutions:
e.g.TTP - the Time Triggered Protocol
Network Message Queue
9 9 9 9
9 8 9
9 9 2 5 8 9
3 6 1 2 5 8 9 Intended for X-by-wire applications
3 6 1 2 5 8 9
CAN
BUS Example: Break-by-wire in car
Time A lot of features built in into the bus protocol
Message Ready
9
(which must be added on top of the CAN bus)
Conceptually similar to
3 6 2 1 5 8
netw ork
8
3 6
All nodes
has identical
message tables Transmission
Column 0 1 2 3 0 1 2 3 0
TDMA round TDMA round
41 42