Timing Analysis of Linux-Based CAN-to-CAN Gateway Michal Sojka - - PowerPoint PPT Presentation

timing analysis of linux based can to can gateway
SMART_READER_LITE
LIVE PREVIEW

Timing Analysis of Linux-Based CAN-to-CAN Gateway Michal Sojka - - PowerPoint PPT Presentation

Timing Analysis of Linux-Based CAN-to-CAN Gateway Michal Sojka Czech Technical University in Prague Faculty of Electrical Engineering sojkam1@fel.cvut.cz February 3, 2011 Center for Applied Cybernetics Embedded Systems Colloquium Michal


slide-1
SLIDE 1

Timing Analysis of Linux-Based CAN-to-CAN Gateway

Michal Sojka

Czech Technical University in Prague Faculty of Electrical Engineering sojkam1@fel.cvut.cz

February 3, 2011 Center for Applied Cybernetics Embedded Systems Colloquium

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 1 / 21

slide-2
SLIDE 2

Outline

Introduction Testbed Description Results Conclusion

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 2 / 21

slide-3
SLIDE 3

Introduction

SocketCAN

◮ Open-source project, official CAN-bus support for Linux

kernel

◮ Initiated by Volkswagen research – first open source

project where Volkswagen participates

◮ Core developers also from a few other companies ◮ Contributors from many other people ◮ In mainline Linux since 2.6.25 ◮ Based on standard Linux networking infrastructure ◮ http://socketcan.berlios.de

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 3 / 21

slide-4
SLIDE 4

Introduction

SocketCAN-based Gateway

◮ Routes CAN frames between multiple CAN buses. ◮ Frames can be modified (ID, length, data) ◮ Modifications: SET, AND, OR, XOR, CRC ◮ Can filter frames based on ID/mask pairs. ◮ Implemented as Linux kernel module ◮ Easy to use

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 4 / 21

slide-5
SLIDE 5

Introduction

The Goal of our Work

◮ Timing analysis of the gateway ◮ How are the routed frames delayed by the gateway? ◮ What influences the delays (latencies)?

◮ Traffic patterns, ◮ additional load, ◮ gateway configuration, ◮ Linux kernel version.

◮ Volkswagen uses the gateway for fast prototyping. It works

well for them and they wanted to know where are the limits.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 5 / 21

slide-6
SLIDE 6

Testbed Description

Testbed Setup

◮ Gateway – PowerPC MPC5200 ◮ PC – Pentium 4, Kvaser PCI quad-CAN SJA1000-based

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 6 / 21

slide-7
SLIDE 7

Testbed Description

Measurement Methodology

◮ Bus bit-rate 1 Mbps ◮ Frames are sent from can0 ◮ Received on can1 and can2 ◮ Receive timestamps are taken by the driver at interrupt

time – SO_TIMESTAMPNS socket option

◮ Timestamps with nanosecond precision (TSC) ◮ Same clock for both timestamps – no problems with time

synchronization between computers

CAN bus 0 CAN bus 1 time msg 1 msg 1' message latency Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 7 / 21

slide-8
SLIDE 8

Testbed Description

Measurement Measurement II.

◮ Traffic patterns:

◮ one message at a time, ◮ 50% bus load, ◮ flood (almost 100% bus load)

◮ Additional loads:

◮ CPU load – hackbench ◮ Ethernet load – ping -f -s 6000

◮ Versions:

◮ Latest SocketCAN from SVN (rev 1199 + fixes) ◮ Kernel: 2.6.33, 2.6.33-rt, 2.6.36 Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 8 / 21

slide-9
SLIDE 9

Results

Precision and Presentation of Results

1 10 100 1000 10000 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 Latency profile [messages] Time [ms] No GW, two interfaces in PC

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic 50, Load none)

2 byte messages 4 byte messages 6 byte messages 8 byte messages

◮ Two points (t1, m1) and (t2, m2): t1 < t2 ⇒ m1 − m2 frames

had the latency in the range [t1, t2).

◮ The right most point (tw, mw): mw frames with the latency

  • f tw.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 9 / 21

slide-10
SLIDE 10

Results

Simple Gateway

1 10 100 1000 10000 0.1 0.15 0.2 0.25 0.3 0.35 0.4 Latency profile [messages] Time [ms] Single GW job for all messages, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

2 byte messages 4 byte messages 6 byte messages 8 byte messages 0.1 0.15 0.2 0.25 0.3 1 2 3 4 5 6 7 Latency [ms] Time [s] Single GW job for all messages, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

2 byte messages 4 byte messages 6 byte messages 8 byte messages

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 10 / 21

slide-11
SLIDE 11

Results

Frame Filtering

1 10 100 1000 10000 0.05 0.1 0.15 0.2 0.25 0.3 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask C00007FF), no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047 1 10 100 1000 10000 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047

Two types of filters

◮ SFF frames (11 bit ID),

single ID

◮ Implemented as lookup

table (by ID)

◮ Fast ◮ Top figure

◮ EFF frames (29 bit ID) or

filters matching multiple frames (mask)

◮ Implemented as linear

list

◮ Latency depends on ID ◮ Bottom figure Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 11 / 21

slide-12
SLIDE 12

Results

Frame Filtering under Heavy Traffic

1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047 0.1 1 10 100 2 4 6 8 10 12 14 16 18 20 Latency [ms] Time [s] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047

◮ Packet processing takes

longer time ⇒ packet losses

◮ The effect of hardware

buffers (bottom figure)

◮ MPC5200 has 4 hardware

buffers

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 12 / 21

slide-13
SLIDE 13

Results

Frame Modification

1 10 100 1000 10000 140 150 160 170 180 190 200 Latency profile [messages] Time [µs] Single GW job for all messages with modifications, 8 byte messages

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

No modifications T wo modifications Four modifications Four modifications and XOR checksum Four modifications and CRC8 checksum

◮ Perpetum mobile – the more work to do, the less time it

takes.

◮ Wrong branch prediction? No. Difference under 1 µs.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 13 / 21

slide-14
SLIDE 14

Results

Multi-Hop Routing with Virtual Interfaces

can0 GW0 nop GW(n+1) nop can1 GW2 id⇒id+1

id id id+1 id+1 id+n id+2

GWn id⇒id+1

i d + n

  • 1

id+n

MPC5200

id id+n

vcan0 GW1 id⇒id+1

Figure: Multi-Hop gateway with a single virtual CAN interface (vcan0).

can0 GW0 id⇒id+1

id+1

MPC5200

id

GW2 id⇒id+1 can1

id+2 id+3

vcan0 GW1 id⇒id+1

id+2 id+1

vcan1

Figure: Multi-Hop gateway with several virtual CAN interfaces.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 14 / 21

slide-15
SLIDE 15

Results

Multi-Hop Routing with Virtual Interfaces

1 10 100 1000 10000 0.1 0.15 0.2 0.25 0.3 0.35 0.4 Latency profile [messages] Time [ms] Chained GW jobs on a single VCAN interface

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

2 GW jobs, 1 vcan 4 GW jobs, 1 vcan 6 GW jobs, 1 vcan 8 GW jobs, 1 vcan 10 GW jobs, 1 vcan 12 GW jobs, 1 vcan 1 10 100 1000 10000 0.1 0.15 0.2 0.25 0.3 0.35 0.4 Latency profile [messages] Time [ms] Chained GW jobs on multiple VCAN interfaces

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

1 GW jobs, 0 vcans 2 GW jobs, 1 vcans 4 GW jobs, 3 vcans 6 GW jobs, 5 vcans 8 GW jobs, 7 vcans 10 GW jobs, 9 vcans

◮ Goal: evaluate the internals of the gateway and

SocketCAN infrastructure.

◮ Result: nothing unexpected – the more hops, the more

time.

◮ Every additional hop adds approximately 11 µs.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 15 / 21

slide-16
SLIDE 16

Results

Kernel-Space vs. User-Space routing – Non-rt Kernel

1 10 100 1000 10000 0.1 1 10 100 1000 Latency profile [messages] Time [ms] Kernel vs. userspace GW, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load none)

Userspace GW, 2 byte messages Userspace GW, 8 byte messages Kernel GW, 2 byte messages Kernel GW, 8 byte messages 1 10 100 1000 10000 0.1 1 10 100 1000 Latency profile [messages] Time [ms] Kernel vs. userspace GW, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

Userspace GW, 2 byte messages Userspace GW, 8 byte messages Kernel GW, 2 byte messages Kernel GW, 8 byte messages

◮ Kernel-space has much lower overhead. ◮ Kernel-space handles even flood traffic without problems.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 16 / 21

slide-17
SLIDE 17

Results

Additional Load

1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] Single GW job for all messages, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic 50, Load none)

2 byte messages 4 byte messages 6 byte messages 8 byte messages 1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] Single GW job for all messages, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic 50, Load cpu)

2 byte messages 4 byte messages 6 byte messages 8 byte messages 1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] Single GW job for all messages, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic 50, Load eth)

2 byte messages 4 byte messages 6 byte messages 8 byte messages

◮ User-space CPU load – no

problem.

◮ Ethernet load – shared

queues for Ethernet and CAN frames

◮ Significant influence on

latency.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 17 / 21

slide-18
SLIDE 18

Results

Differences Between Kernels

1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic oneatatime, Load cpu)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047 1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.33.7-rt29-00004-g92487e4, Traffic oneatatime, Load cpu)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047 1 10 100 1000 10000 0.1 1 10 100 Latency profile [messages] Time [ms] 2048 GW jobs (one per id, mask 0x7FF), no modifications

(GW kernel 2.6.36.2-00015-g4f1bc4e, Traffic oneatatime, Load cpu)

Message id 0 Message id 255 Message id 511 Message id 767 Message id 1023 Message id 1279 Message id 1535 Message id 1791 Message id 2047

◮ 2.6.36 has approximately

10 µs higher latency when compared to 2.6.33.

◮ There is some bug in

2.6.33-rt29!

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 18 / 21

slide-19
SLIDE 19

Results

User-Space Gateway under rt and non-rt Kernel

1 10 100 1000 10000 0.1 1 10 100 1000 Latency profile [messages] Time [ms] Kernel vs. userspace GW, no modifications

(GW kernel 2.6.33.7-rt29-00004-g92487e4, Traffic flood, Load none)

Userspace GW, 2 byte messages Userspace GW, 8 byte messages Kernel GW, 2 byte messages Kernel GW, 8 byte messages 1 10 100 1000 10000 0.1 1 10 100 1000 Latency profile [messages] Time [ms] Kernel vs. userspace GW, no modifications

(GW kernel 2.6.33.7-00007-g9c0ff90, Traffic flood, Load none)

Userspace GW, 2 byte messages Userspace GW, 8 byte messages Kernel GW, 2 byte messages Kernel GW, 8 byte messages

◮ rt kernel brings kernel capabilities to user-space (with

  • verhead)

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 19 / 21

slide-20
SLIDE 20

Results

Results processing

◮ More than 600 experiments ◮ HTML-based navigation on results ◮ file:///home/wsh/projects/can-benchmark/

gw-tests/results/index.html

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 20 / 21

slide-21
SLIDE 21

Conclusion

Conclusion

◮ SocketCAN-based gateway is a reliable solution for CAN

bus routing.

◮ Kernel-space solution performs better the a user-space

  • ne.

◮ There are things to avoid:

◮ Combining CAN traffic with Ethernet traffic. ◮ Use of big number filters.

◮ A paper sent to IEEE Transactions on Industrial

Informatics.

Michal Sojka Timing Analysis of Linux-Based CAN-to-CAN Gateway February 3, 2011 21 / 21