socketcan and j1939 - elinux · 10/21/2019 · multiple processes with userspace stack (j1939...
TRANSCRIPT
![Page 1: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/1.jpg)
https://www.pengutronix.de
SocketCan and J1939
Oleksij Rempel – [email protected] Kleine-Budde – [email protected]
![Page 2: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/2.jpg)
2/28
My assumption about you
What is J1939 and do I actually need it? I use this protocol as user space stack in some product and it
works for me. Why should I care about kernel stack? Just skip 1. and 2., and tell me how can I use the kernel
stack?!
![Page 3: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/3.jpg)
3/28
… spend some words on CAN
something different than Ethernet 2 wire cable speed up to 1 Mbit (only) 8 bytes per frame
![Page 4: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/4.jpg)
4/28
CAN: every thing is a broadcast
11 bit or 29 bit address (CAN-ID)
priorisation of CAN frames by CAN-ID
CSMCA (Carrier Sense Multiple Collision Avoidance)
CAN frames are broadcasted
![Page 5: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/5.jpg)
5/28
State of CAN infrastructure before 2013
Kernel
Different kernel and user-space drivers
No compatibility No unified tooling Bad testing coverage
![Page 6: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/6.jpg)
6/28
SocketCAN now
Kernel
Protocol
Hardware abstraction layer One socket interface for all
applications SoC vendors do mainline
linux CAN drivers
![Page 7: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/7.jpg)
7/28
SocketCAN isn‘t Rocket Science!
Linux Socket Layer
PF_CAN
routing and packet scheduler
eth0 can0 can1
CAN App 2
RX dispatcher/CAN core
CAN App 1
RAW ...
...
PF
_IN
ET
![Page 8: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/8.jpg)
8/28
SocketCAN: infrastructure
CAN-utils CAN-tests Wireshark …?
![Page 9: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/9.jpg)
9/28
CAN: 0...8 bytes per CAN frame (only)
A spoon of bytes!!!
![Page 10: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/10.jpg)
10/28
Main motivation for J1939
CAN bus is slow and packages are very small.
![Page 11: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/11.jpg)
11/28
For example IP Header is 20 Bytes...
![Page 12: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/12.jpg)
12/28
For example IP Header is 20 Bytes…
![Page 13: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/13.jpg)
13/28
What is SAE J1939?
Recommendation for: Physical Layer Defines PGNs (Parameter
Group Number) PGN identifies a message's
function and meaning of associated data
![Page 14: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/14.jpg)
14/28
What is SAE J1939?
Transport Protocol / Extended Transport Protocol
Reliable send/receive large amounts of data
Transport Protocol = 1792 bytes, Extended Transport Protocol ~ 112 MiB
![Page 15: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/15.jpg)
15/28
J1939 TP is like TCP (20 Byte header !!!)
![Page 16: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/16.jpg)
16/28
How about UDP?! (8 byte header)
![Page 17: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/17.jpg)
17/28
SocketCAN with J1939 stack
Same situation as with Linux CAN
before SocketCAN Different user space and
kernel implementations
![Page 18: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/18.jpg)
18/28
Why kernel stack: CPU load and timings
busy CAN bus about 2000 pps (or more?)
(Spoons) per second * socket relative relaxed timing
requirements in general ...but not on a loaded single
core 400 MHz ARMv5 (imx28)
![Page 19: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/19.jpg)
19/28
Different user space implementations
1. Multiple processes with userspace stack (J1939 daemon)
2. One library used by different applications 3. All in one. One application with J1939 stack and
many threads. 4. Different J1939 stack variants per developer
![Page 20: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/20.jpg)
20/28
1. Multiple processes with userspace stack
one J1939 process running to parse J1939 traffic and communicate with multiple applications
long round trip times: [Kernel - CAN_RAW socket] J1939 stack pipes/unix → →
domain sockets/tcp application→
![Page 21: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/21.jpg)
21/28
2. One library used by different applications
the load on the CAN bus will be increased as well. For example: more Address Claiming requests.
Increased memory usage. For example: same TP or ETP should be reconstructed separately multiple times on same system.
![Page 22: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/22.jpg)
22/28
3. All in one
no isolation of processes malfunction/security problem in one thread will affect
other applications/threads
![Page 23: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/23.jpg)
23/28
4. Different J1939 variants per developer
Many end devices are made by chain of different suppliers.
Each chain part is using own software and great, special version of J1939 stack.
![Page 24: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/24.jpg)
24/28
SAE J1939 Linux Kernel Implementation
Should be able to cover: SAE J1939 IsoBUS NMEA2000 MilCAN A
![Page 25: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/25.jpg)
25/28
SAE J1939 Linux Kernel Implementation
Simple programming model Well known socket interface.
Better performance Kernel don't cares about
data or PGN except of: AC and (E)TP
Kernel J1939
Transport
AC
![Page 26: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/26.jpg)
26/28
How to use kernel SAE J1939 stack?
Jacd and jcat: https://github.com/linux-can/can-utils Kernel: Documentation/networking/j1939.rst
![Page 27: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/27.jpg)
27/28
Challanges
MTU: ~112 MiB (solved) Proper way to export
address claiming cache to the userspace
Quirky buses. Test automation (follow
osmocom testing experience?)
![Page 28: SocketCan and J1939 - eLinux · 10/21/2019 · Multiple processes with userspace stack (J1939 daemon) 2. One library used by different applications 3. All in one. One application](https://reader036.vdocuments.pub/reader036/viewer/2022071114/5feb741b52341708350a4a9d/html5/thumbnails/28.jpg)
https://www.pengutronix.de
Thank you!
Questions?