43
Undergraduate course on Real-time Systems Linköping TDDD07 Real-time Systems Lecture 5: Real-time Communication Simin Nadjm-Tehrani Real-time Systems Laboratory Department of Computer and Information Science Linköping university 36 pages Autumn 2009

TDDC47: Real-time and Concurrent Programming Lecture 8: Real-time communication

  • Upload
    syshe

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

TDDC47: Real-time and Concurrent Programming Lecture 8: Real-time communication. Simin Nadjm-Tehrani Real-time Systems Laboratory Department of Computer and Information Science Linköping university. Reading material. TDDD07: H. Kopetz 2003 article (see course web) - PowerPoint PPT Presentation

Citation preview

Page 1: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

TDDD07 Real-time Systems

Lecture 5: Real-time Communication

Simin Nadjm-Tehrani

Real-time Systems Laboratory

Department of Computer and Information ScienceLinköping university

36 pagesAutumn 2009

Page 2: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

2 of 36 Autumn 2009

TDDC47: Real-time and

Concurrent Programming

Lecture 8: Real-time communication

Simin Nadjm-Tehrani

Real-time Systems Laboratory

Department of Computer and Information ScienceLinköping university

Page 3: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

3 of 36 Autumn 2009

Reading material

TDDD07:• H. Kopetz 2003 article (see course web)• Davis et al 2007 article (- ” -)

TDDC47:• Course compendium• Davis et al 2007 article (see course web)

Page 4: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

4 of 36 Autumn 2009

From last lectures

• In two scheduling lectures we looked at – Single processor hard real-time

scheduling

– TDDD07: • Distributed case with dynamic load• Time and clocks in distributed systems

...

Page 5: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

5 of 36 Autumn 2009

Real-time communication

• This lecture: How can the communication network and protocols support real-time?

• RT communication is about scheduling the communication medium – NOT the CPU

...

Page 6: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

6 of 36 Autumn 2009

Distributed applications

• Assume that tasks are run on different nodes according to some local scheduling

• Nodes need to exchange data • messages need to reach destination

before their deadline

...

Page 7: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

7 of 36 Autumn 2009

Real-time constraints

• When message transmissions must have a well-defined time bound for the system to meet it deadlines– So called end-to-end deadlines

• Example: shortly after each braking, brake light must know it in order to turn on!

Page 8: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

8 of 36 Autumn 2009

New resource

Single Node Distributed

Resource CPU Bandwidth

Scheduled element

Task/process Message

Demand on resource

WCET & interarrival

Message size & frequency

Performancemetric

Deadlines metUtilisation

Message delayThroughput

Page 9: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

9 of 36 Autumn 2009

Two approaches

• We will look at two dominant methods for bus scheduling– Time triggered (TTP)– Event triggered (CAN)

• Used extensively in automotive and aerospace applications

Page 10: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

10 of 36 Autumn 2009

Time-triggered protocol (TTP)

• Origin in research projects in Vienna in early 90´s [Kopetz et.al]

• Time division multiple access (TDMA)

Node 1 Node n… Node n-1

Page 11: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

11 of 36 Autumn 2009

Communication protocol

• Message Description List: allocates a pre-defined slot within which each node can send its (pre-defined) message

A TDMA round

Node 1 Node n… Node n-1

Page 12: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

12 of 36 Autumn 2009

Message scheduling

• TDMA round implemented through the MEDL (message description list)

• MEDL has a static schedule for each message

• No constraints on (local) node CPU scheduling

Page 13: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

13 of 36 Autumn 2009

Temporal firewall

…CC

Host

CC

HostCNI

• CNI provides temporally accurate state information (via clock synchronisation)

• When the data is temporally not valid, it can no longer be exchanged

Node n

Page 14: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

14 of 36 Autumn 2009

Replication & failure detection

BG: Buss Guardian (stops babbling idiots)

BGBG BG

CC

Host

BGBGBG BG

CC

Host

BGBG

CNI

Page 15: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

15 of 36 Autumn 2009

• The major success of the TTP bus is due to the possibility of detecting arbitrary (Byzantine) failures

• We will come back to this later…

Page 16: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

16 of 36 Autumn 2009

Two approaches

• We will look at two dominant methods for bus scheduling– Time triggered (TTP)– Event triggered (CAN)

• Used extensively in automotive and aerospace applications

Page 17: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

17 of 36 Autumn 2009

The CAN bus

Amount of wires…

• Controller area network that exists in all cars built in Europe today

• Compulsory for the on-board diagnostics in USA car models from 2008

• Why?– Imagine: 2500 signals, 32 ECUs on

one bus

Page 18: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

18 of 36 Autumn 2009

Predecessor to CAN (1976)

Ethernet:• Current versions give high bandwidth

but time-wise nondeterministic• CSMA/CD

– Sense before sending on the medium (Carrier Sense: CS)– All nodes broadcast to all (Multiple

Access: MA)– If collision, back off and resend

(Collision Detection: CD)

Page 19: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

19 of 36 Autumn 2009

Collisions

• Ethernet has high throughput but temporally nondeterministic

Node 1 sends

Node 3 waits for sending

Node 2 waits for sending

Node 2 & 3 start to send

Collision

Page 20: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

20 of 36 Autumn 2009

Backoff

• The period for waiting after a collision• Each node waits up to two “slot times”

after a collision (random wait)• If a new collision, the max. backoff

interval is doubled• After 10 attempts the node stops

doubling• After 16 attempts declares an error

Page 21: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

21 of 36 Autumn 2009

Treating non-determinism

• Model the network throughput and compute probabilistic guarantees that collisions will not be too often

• Theoretical study:With 100Mbps, sending 1000 messages of 128 bytes per second, there is a 99% probability that there will be a 1 ms delay over ~1140 years

[www.rti.com Ethernet study]

• Make collision resolution deterministic!

How often?

Page 22: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

22 of 36 Autumn 2009

CAN protocol

• Developed by Bosch and Intel (1986)• ISO Standard 1993• Highest bandwidth 1Mbps, ~40-50m• CSMA/CR: broadcast to all nodes• CR: Collision resolution by bit-wise

arbitration plus fixed priorities (deterministic)

• Bus value is bitwise AND of the sent messages

Page 23: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

23 of 36 Autumn 2009

Message priority

• The ID of the frame is located at the beginning– initial bits that are inserted into the

bus are the ID-bits– ID also determines the priority of a

frame– priority of the frame increases as the

ID decreases

Page 24: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

24 of 36 Autumn 2009

Bitwise arbitration

Node 1 sends: 010………sends rest of packetNode 2 sends: 100……detects collision firstNode 3 sends: 011……detects collision next

• This is how ID for a message (frame) works as its priority

Page 25: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

25 of 36 Autumn 2009

Note

• Two roles for message ID:– Arbitration and priority– Every node upon receiving a message,

uses the ID to work out whether that message is any use to it or not

Page 26: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

26 of 36 Autumn 2009

Response time analysis

• Fixed priorities means RMS-like worst case analysis

• Messages are sent non-preemptively!• Blocking is only possible before the first

bit

• Scheduling analysis: Is every message delivered before its deadline?

Page 27: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

27 of 36 Autumn 2009

Worst Case Response

According to Tindell & Burns 94:Message response time =Ji: Jitter (from event to placement in queue)+

wi: Queuing time (response time of first bit)+

Ci: Transmission time

Ri = Ji +wi + Ci – tbit

wi = tbit + Bi + IiBi + Ii : Blocking and Interference time (as RMS)

Page 28: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

28 of 36 Autumn 2009

Interference and blocking

• Ii: waiting due to higher priority processes, bounded if messages are sent periodically

• Bi: waiting due to lower priority messages, only one can start before i

• Ji: jitter, has to be assumed bounded (by assumptions on the node scheduling policy!)

Page 29: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

29 of 36 Autumn 2009

• Blocking is fixed: max Cj of all lower priority messages

• wi = Bi + khp(i) ( wi + Jk + tbit )/ Tk Ck

• w0i = Bi

• wn+1i = Bi + khp(i) ( wi

n + Jk + tbit )/ Tk Ck

• After fixed point is reached: Bi + wn+1i + Ci Di ?

Solving recurrent equations

Page 30: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

30 of 36 Autumn 2009

Example

• From [Davis etal 2007]:– To show how a w-term for each message

was computed based on original method from 1994

– Assume ji= 0

Message priority period deadline TX time

A 1 2.5ms 2.5ms 1ms

B 2 3.5ms 3.25ms 1ms

C 3 3.5ms 3.25ms 1ms

Page 31: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

31 of 36 Autumn 2009

Exercise

• Compute response times for the three messages

Page 32: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

32 of 36 Autumn 2009

• Blocking is fixed: max Cj of all lower priority messages

• wi = Bi + khp(i) ( wi + Jk + tbit )/ Tk Ck

• w0i = Bi

• wn+1i = Bi + khp(i) ( wi

n + Jk + tbit )/ Tk Ck

• After fixed point is reached: Bi + wn+1i + Ci Di ?

Solving recurrent equations

Page 33: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

33 of 36 Autumn 2009

The original analysis

• From 1994• … was Optimistic!• There can be a case where analysis

shows schedulability but in fact deadlines can be missed!

[Davis, Burns, Bril, Lukkien 2007]

Page 34: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

34 of 36 Autumn 2009

The correct analysis

• Takes account of the fact that different instances of a message may appear in a busy period

and• All such instances should be shown to

meet their deadlines!

[Reading: Sec. 3.1 & 3.2, Davis et al.07]

Page 35: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

35 of 36 Autumn 2009

Revised computation

• Rm(q)= Jm + wm(q) – qTm + cm

• q=i, w(q) computes busy period for ith

instance of message m

• To know range of q, i.e. how many instances of message m are relevant, we need to find the longest busy period for m denoted tm

Page 36: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

36 of 36 Autumn 2009

Example revisited

• Now with the new formula where busy period term is according to [Davis etal 2007]:

Message priority period deadline TX time

A 1 2.5ms 2.5ms 1ms

B 2 3.5ms 3.25ms 1ms

C 3 3.5ms 3.25ms 1ms

Page 37: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

37 of 36 Autumn 2009

Exercise

• Redo the old exercise with the Davis et al. variant of the busy period

Wn+1m (q) =

Bm +

khp(m) ( wnm + Jk + tbit )/ Tk Ck

Page 38: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

38 of 36 Autumn 2009

Solution

• To know how many instances of message m are relevant we need to find the longest busy period for m denoted tm

• t03 = C3= 1

• t13 = t0

3/T3 C3 + t03/T2 C2+ t0

3/T1 C1 = 1+1+1= 3

• t23 = t1

3/T3 C3 + t13/T2 C2+ t1

3/T1 C1 = 1+1+2= 4

• t33 = t2

3/T3 C3 + t23/T2 C2+ t2

3/T1 C1 = 2+2+2= 6

• t43 = t3

3/T3 C3 + t33/T2 C2+ t3

3/T1 C1 = 2+2+3= 7

• t53 = t4

3/T3 C3 + t43/T2 C2+ t4

3/T1 C1 = 2+2+3= 7

• Which means 3 instances of message C are relevant! Q=2 and q:0.. Q-1

Page 39: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

39 of 36 Autumn 2009

Computing the queuing time

• w03 (0) = B3+0.C3= 0

• w13 (0) = (w0

3(0)+ tbit)/T2 C2 + (w03 (0)+ tbit) /T1 C1 = 1+1 =2

• w23 (0) = 1+1= 2

w3 (0) = 2 R3 (0) = w3 (0) – qT3 + C3 = 3

• w03 (1) = w3 (0) + C3 = 2+1= 3

• w13 (1) = C3 + (w0

3 (1)+ tbit)/T2 C2 + (w03 (1)+ tbit)/T1 C1 = 1+1+2 =

4• w2

3 (1) = C3 + (w13 (1)+ tbit)/T2 C2 + (w1

3 (1)+ tbit)/T1 C1 = 1+2+2=5

• w33 (1) = C3 + (w2

3 (1)+ tbit)/T2 C2 + (w23 (1)+ tbit)/T1 C1 = 1+2+3 =

6• w4

3 (1) = C3 + (w33(1) + tbit )/T2 C2 + (w3

3 (1)+ tbit) /T1 C1 = 1+2+3 = 6

w3 (1) = 6 R3 (1) = w3 (1) – qT3+ C3 = 3.5

Page 40: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

40 of 36 Autumn 2009

Now for the 3rd instance

• w03 (2) = w3 (1) + C3 = 6+1=7

• w13 (2) = C3 + (w0

3(2) + tbit )/T2 C2 + (w03

(2)+ tbit )/T1 C1 = 1+3+3 = 7

w3 (2) = 7

R3 (2) = w3 (2) – qT3+ C3 = 1

Not adding to the response time

Rm =max{q:0..qm-1} Rm(q) = 3.5

That’s why message C missed its deadline!

Page 41: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

41 of 36 Autumn 2009

Error detection

• If a node sends a message that is corrupted in transmission the Cyclic Redundancy Check (CRC) field will be wrong

• The first node that notes this sends 000000

• This works as long as the node is not erroneous – Babbling idiot!

Page 42: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

42 of 36 Autumn 2009

Recent developments

• Formal verification of clock synchronisation and fault tolerance mechanisms

• X-by-wire applications seem to adopt TTP solutions for higher reliability and fault tolerance

• New solutions to combine event-triggered and time-triggered messages are needed:– Simulating CAN over TTP, or TT-CAN?– FlexRay

Page 43: TDDC47: Real-time and  Concurrent Programming Lecture  8:  Real-time communication

Undergraduate course on Real-time SystemsLinköping

43 of 36 Autumn 2009

Summary

• CAN: Event-triggered

vs

• TTP: Time-triggered

Both have pros and cons in hard real-time applications...