This presentation reports the results of thorough analysis of timing properties of CAN-to-CAN gateway built with Linux kernel CAN subsystem. The latencies induced by this gateway are evaluated under many combinations of conditions, such as when traffic filtering is used, when the gateway is configured to modify the routed frames, when various types of load are imposed on the gateway or when the gateway is run on different kernels (both rt-preempt and vanilla are included). From the detailed results, we derive the general characteristics of the gateway. Some of the results apply not only for the special case of CAN-to-CAN routing, but also for the whole Linux networking subsystem because many mechanisms in the Linux networking stack are shared by all protocols.
Towards the Performance Analysis of IEEE 802.11 in Multi-hop Ad-Hoc Networks
Timing Analysis of a Linux-Based CAN-to-CAN Gateway
1. Timing Analysis of a Linux-Based
CAN-to-CAN Gateway
Michal Sojka1 , Pavel Píša1 , Ondˇej Špinka1 ,
r
Oliver Hartkopp2 , Zdenek Hanzálek1
ˇ
1 Czech Technical University in Prague
Faculty of Electrical Engineering
2 Volkswagen Group Research
13th Real-Time Linux Workshop
October 22, Prague
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 1 / 26
3. Motivation
CAN Bus
Intended to interconnect microcontrollers for short
distances.
Network with deterministic medium access ⇒ real-time
applications.
Heavily used in automotive industry.
Bit rates up to 1 Mbit/s.
Every frame can carry up to 8 bytes of data.
Frames are identified by frame IDs (11 or 29 bits).
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 3 / 26
4. Motivation
Rapid prototyping with CAN
Goal: Quickly interconnect devices/subsystems from
multiple vendors.
Frame ID clashes cause problems – devices cannot be
connected together.
A need for CAN-to-CAN gateways to route (and modify)
messages between multiple buses.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 4 / 26
5. Motivation
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 CAN-to-CAN Gateway Timing Analysis RTLWS13 5 / 26
6. Motivation
SocketCAN-based Gateway
Routes CAN frames between multiple CAN buses.
Frames can be modified (ID, length, data)
Modifications: SET, AND, OR, XOR, CRC
Frames can be filtered based on ID/mask pairs.
Implemented as a Linux kernel module
Easy to use:
cangw -A -s can0 -d can1
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 6 / 26
7. Motivation
Motivation of our Work
Adding gateways to real-time network can violate real-time
requirements (deadlines).
How are the routed frames delayed by the gateway?
What influences the delays (latencies)?
Traffic patterns,
Additional load,
Gateway configuration,
Linux kernel version.
Where are the limits of the SocketCAN-based gateway?
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 7 / 26
8. Motivation
Motivation of our Work
Adding gateways to real-time network can violate real-time
requirements (deadlines).
How are the routed frames delayed by the gateway?
What influences the delays (latencies)?
Traffic patterns,
Additional load,
Gateway configuration,
Linux kernel version.
Where are the limits of the SocketCAN-based gateway?
Nice way to measure temporal properties of the Linux
kernel.
Some of our results apply not only for CAN, but also for
Linux networking subsystem in general.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 7 / 26
11. Testbed Description
Measured Latencies
CAN bus 0 msg 1
CAN gateway
(Linux)
CAN bus 1 msg 1'
time
GW latency Duration
Total latency
RX timestamp 1 RX timestamp 2
Same clock for both
timestamps
SO_TIMESTAMPNS
socket option
Clock source = TSC
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 9 / 26
12. Testbed Description
Tested Scenarios
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:
Kernel: 2.6.33, 2.6.33-rt29, 2.6.36, 3.0.4, 3.0.4-rt14
Latest SocketCAN from SVN (rev 1199 + fixes)
All combinations of the above.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 10 / 26
13. Analysis Results
The Simplest GW Configuration
Experiment:
Frames with payload of 2 bytes
Message transmission time: 60 µs
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 11 / 26
22. Analysis Results
Measurement Precision
Influence of Ethernet load generator on measurement precision. No GW involved!
10000
No load
Ethernet load
Latency profile
1000
[frames]
100
10
1
0 31 50 100 150 200 250 300
TX+RX overhead [µs]
i.e. tkernel RX - tbefore send - tTX duration
TX+RX overhead (interfaces can0 and can1 on the PC)
Desired result: vertical lines at the same position
The error is much smaller than latencies observed for the
gateway.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 15 / 26
23. Analysis Results
Batched Processing of Frames
10000
One frame at a time
Flood
1000
Latency profile
[frames]
100
10
1
0 20 40 60 80 100 120 140
GW latency [µs]
Soft-IRQ processes packets in batches (if possible).
Decreases average latency.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 16 / 26
24. Analysis Results
Effect of Loading the Gateway – CPU
10000
No load
CPU load
1000
Latency profile
[frames]
100
10
1
0 50 100 150 200 250 300
GW latency [µs]
Hackbench
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 17 / 26
26. Analysis Results
Frame Filtering
Different number of filters, only the last one matches
10000
List length 1
List length 128
Latency profile
1000 List length 256
List length 384
[frames]
100 List length 512
List length 768
List length 1024
10 List length 1536
List length 2048 Two filter implementations:
1
0 200 400 600 800 1000
list traversal, array indexing
2048 SFF filters, different frame IDs More than 80 list entries ⇒
10000
Frame ID 1 Frame ID 1536
the delay increases faster
Frame ID 256 Frame ID 2048
Latency profile
1000
Frame ID 512 (cache trashing)
[frames]
Frame ID 768
100 Frame ID 1024
10
1
0 200 400 600 800 1000
GW latency [µs]
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 19 / 26
34. Analysis Results
Results processing
More than 600 experiments
HTML-based navigation on results
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 25 / 26
35. Analysis Results
Results processing
More than 600 experiments
HTML-based navigation on results
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 25 / 26
36. Conclusions
Conclusion
SocketCAN-based gateway is a reliable solution for CAN
bus routing.
Kernel-space solution performs better than a user-space
one.
There are things to avoid:
Combining CAN traffic with Ethernet traffic.
Use of too many filters.
The gateway will be merged in 3.2 kernel.
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 26 / 26
37. Conclusions
Conclusion
SocketCAN-based gateway is a reliable solution for CAN
bus routing.
Kernel-space solution performs better than a user-space
one.
There are things to avoid:
Combining CAN traffic with Ethernet traffic.
Use of too many filters.
The gateway will be merged in 3.2 kernel.
Nice way of measuring Linux kernel temporal properties
from outside.
https://rtime.felk.cvut.cz/can/benchmark/2.1/
https://rtime.felk.cvut.cz/gitweb/can-benchmark.git
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 26 / 26
38. Conclusions
Conclusion
SocketCAN-based gateway is a reliable solution for CAN
bus routing.
Kernel-space solution performs better than a user-space
one.
There are things to avoid:
Combining CAN traffic with Ethernet traffic.
Use of too many filters.
The gateway will be merged in 3.2 kernel.
Nice way of measuring Linux kernel temporal properties
from outside.
https://rtime.felk.cvut.cz/can/benchmark/2.1/
https://rtime.felk.cvut.cz/gitweb/can-benchmark.git
Questions?
Michal Sojka CAN-to-CAN Gateway Timing Analysis RTLWS13 26 / 26