Performance evaluation of Linux CAN-related system calls Michal - - PowerPoint PPT Presentation

performance evaluation of linux can related system calls
SMART_READER_LITE
LIVE PREVIEW

Performance evaluation of Linux CAN-related system calls Michal - - PowerPoint PPT Presentation

Performance evaluation of Linux CAN-related system calls Michal Sojka , Pavel P sa, Zden ek Hanz alek Czech Technical University in Prague, Faculty of Electrical Engineering Email: { sojkam1,pisa,hanzalek } @fel.cvut.cz SESAMO


slide-1
SLIDE 1

Performance evaluation of Linux CAN-related system calls

Michal Sojka, Pavel P´ ıˇ sa, Zdenˇ ek Hanz´ alek

Czech Technical University in Prague, Faculty of Electrical Engineering Email: {sojkam1,pisa,hanzalek}@fel.cvut.cz SESAMO

Security and Safety Modelling

Workshop on Factory Communication Systems (WFCS) May 7, 2014 – Toulouse, France

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 1 / 15

slide-2
SLIDE 2

Introduction

Motivation

Security of on-board networks

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-3
SLIDE 3

Introduction

Motivation

Security of on-board networks

I D S

Intrusion detection system

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-4
SLIDE 4

Introduction

Motivation

Security of on-board networks

I D S

Intrusion detection system Needs to be "tuned" to avoid false positives

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-5
SLIDE 5

Introduction

Motivation

Security of on-board networks

I D S

Intrusion detection system Needs to be "tuned" to avoid false positives Data from outdoor experiments

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-6
SLIDE 6

Introduction

Motivation

Security of on-board networks

I D S

Intrusion detection system Needs to be "tuned" to avoid false positives Data from outdoor experiments Logging

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-7
SLIDE 7

Introduction

Motivation

Security of on-board networks

I D S

Intrusion detection system Needs to be "tuned" to avoid false positives Data from outdoor experiments Logging

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 2 / 15

slide-8
SLIDE 8

Introduction

Requirements

◮ All CAN traffic from a car has to be logged in real-time. ◮ Up to 20 CAN buses needs to be logged simultaneously. ◮ Logs are analyzed off-line.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 3 / 15

slide-9
SLIDE 9

Introduction

Outline

CAN support in Linux Virtual CAN interface method Gateway-based method Low-latency sockets Conclusion

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 4 / 15

slide-10
SLIDE 10

CAN support in Linux

Linux networking subsystem

RX/TX path overheads:

◮ Interrupt ◮ Socket, protocol,

Qdisc

◮ System call ◮ We are interested in

the interface between applications and the kernel.

CAN controller (HW) Queuing discipline Protocol layer (af_can.c) Socket layer (can/raw.c) Device driver ISR Poll Application (user space) Kernel

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 5 / 15

slide-11
SLIDE 11

CAN support in Linux

Linux networking subsystem

RX/TX path overheads:

◮ Interrupt ◮ Socket, protocol,

Qdisc

◮ System call ◮ We are interested in

the interface between applications and the kernel.

CAN controller (HW) Queuing discipline Protocol layer (af_can.c) Socket layer (can/raw.c) Device driver ISR Poll Application (user space) Kernel

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 5 / 15

slide-12
SLIDE 12

CAN support in Linux

Linux networking API

Sockets:

◮ Raw CAN sockets – most common ◮ Memory mapped socket (PF PACKET) ◮ Non-blocking I/O (O NONBLOCK) ◮ New “Low-latency” sockets (Linux 3.11 – 9/2013)

Operations on sockets:

◮ read/write (send/recv) ◮ sendmmsg/recvmmsg

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 6 / 15

slide-13
SLIDE 13

CAN support in Linux

Memory-mapped sockets

PF PACKET

Reception

◮ no system call ◮ wait: poll()

Transmission

◮ Notify the kernel

about ready messages. CAN controller (HW) Queuing discipline Protocol & socket layer (af_packet.c) Device driver ISR Poll Application (user space) Kernel

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 7 / 15

slide-14
SLIDE 14

Virtual CAN interface method

Single/multiple messages per system call

◮ Comparison of recv() and recvmmsg() system calls ◮ Use of virtual CAN interface (vcan) Application Kernel RX socket RX queue TX socket vcan af_can.c, raw.c write/send read/recv

Experiment

  • 1. Send X messages – kernel queues them in an RX queue
  • 2. Receive X messages from the RX queue
  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 8 / 15

slide-15
SLIDE 15

Virtual CAN interface method

With or without mmsg – results

PC

2 4 6 8 10 12 14 16 0 5 10 15 20 25 30 35 40 45 50 5 10 15 20 25 30 35 40 Time [ms] Frames [×1000] read recvmmsg write sendmmsg

◮ recvmmsg 7% faster ◮ sendmmsg 12% faster

Embedded system (MPC5200B)

50 100 150 200 250 300 350 400 450 0 5 10 15 20 25 30 35 40 45 50 500 1000 1500 2000 2500 3000 Time [ms] Frames [×1000] read recvmmsg write sendmmsg

◮ recvmmsg 19% faster ◮ sendmmsg 35% faster

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 9 / 15

slide-16
SLIDE 16

Gateway-based method

Embedded system used for experiments

◮ PowerPC ◮ Freescale MPC5200B ◮ 400 Mhz ◮ 128 MB RAM ◮ on-chip CAN controller ◮ Linux 3.12.3

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 10 / 15

slide-17
SLIDE 17

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

ff

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-18
SLIDE 18

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

ff

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-19
SLIDE 19

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

ff

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-20
SLIDE 20

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

ff

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-21
SLIDE 21

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

ff

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-22
SLIDE 22

Gateway-based method

Gateway-based experiments

CAN bus 0 CAN bus 1 time msg 1 Duration msg 1' CAN gateway (Linux) GW latency

RX timestamp 1 RX timestamp 2

T

  • tal latency

Different implemntations

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 11 / 15

slide-23
SLIDE 23

Gateway-based method

Results – one message at a time

50 100 150 200 250 read-write mmap-write mmap-mmap mmsg-mmsg GW latency [µs]

◮ Blocking system

calls

◮ Non-blocking/busy

waiting

◮ Linux kernel &

RTEMS (no Linux)

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 12 / 15

slide-24
SLIDE 24

Gateway-based method

Results – one message at a time

50 100 150 200 250 read-write mmap-write mmap-mmap mmsg-mmsg GW latency [µs] mmapbusy-mmap mmapbusy-write readnb-write readbusy-write readbusynoirq-write readnb-mmap

◮ Blocking system

calls

◮ Non-blocking/busy

waiting

◮ Linux kernel &

RTEMS (no Linux)

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 12 / 15

slide-25
SLIDE 25

Gateway-based method

Results – one message at a time

50 100 150 200 250 read-write mmap-write mmap-mmap mmsg-mmsg GW latency [µs] mmapbusy-mmap mmapbusy-write readnb-write readbusy-write readbusynoirq-write readnb-mmap rtems kernel

◮ Blocking system

calls

◮ Non-blocking/busy

waiting

◮ Linux kernel &

RTEMS (no Linux)

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 12 / 15

slide-26
SLIDE 26

Gateway-based method

Results – periodic messages

Bitrate: 1 Mbps, Payload: 2 bytes Median of 3200 frames

20 50 100 200 500 1000 2000 5000 10000 20000 120 125 130 135 140 145 150 155 160 GW latency [µs] ± packet loss Frame period [µs] 8-byte frame length read-write

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 13 / 15

70 µs 70 µs period

slide-27
SLIDE 27

Gateway-based method

Results – periodic messages

Bitrate: 1 Mbps, Payload: 2 bytes Median of 3200 frames

20 50 100 200 500 1000 2000 5000 10000 20000 120 125 130 135 140 145 150 155 160 GW latency [µs] ± packet loss Frame period [µs] 8-byte frame length read-write mmap-write

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 13 / 15

70 µs 70 µs period

slide-28
SLIDE 28

Gateway-based method

Results – periodic messages

Bitrate: 1 Mbps, Payload: 2 bytes Median of 3200 frames

20 50 100 200 500 1000 2000 5000 10000 20000 120 125 130 135 140 145 150 155 160 GW latency [µs] ± packet loss Frame period [µs] 8-byte frame length read-write mmap-write mmsg-mmsg mmap-mmap

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 13 / 15

70 µs 70 µs period

slide-29
SLIDE 29

Gateway-based method

Results – periodic messages

Bitrate: 1 Mbps, Payload: 2 bytes Median of 3200 frames

20 50 100 200 500 1000 2000 5000 10000 20000 120 125 130 135 140 145 150 155 160 GW latency [µs] ± packet loss Frame period [µs] 8-byte frame length read-write mmap-write mmsg-mmsg mmap-mmap kernel

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 13 / 15

70 µs 70 µs period

slide-30
SLIDE 30

Gateway-based method

Results – periodic messages

Bitrate: 1 Mbps, Payload: 2 bytes Median of 3200 frames

20 50 100 200 500 1000 2000 5000 10000 20000 120 125 130 135 140 145 150 155 160 GW latency [µs] ± packet loss Frame period [µs] 8-byte frame length

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 13 / 15

70 µs 70 µs period

slide-31
SLIDE 31

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ CPU read()

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-32
SLIDE 32

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ CPU read() read()

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-33
SLIDE 33

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ IRQ minimum inter-IRQ time (≈100 µs) CPU read() read()

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-34
SLIDE 34

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ IRQ minimum inter-IRQ time (≈100 µs) CPU read() read() busy waiting

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-35
SLIDE 35

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ IRQ minimum inter-IRQ time (≈100 µs) CPU read() read() read() busy waiting read() timeout

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-36
SLIDE 36

Low-latency sockets

Low-latency sockets

aka Busy polling sockets

Network frame frame frame frame frame IRQ IRQ minimum inter-IRQ time (≈100 µs) CPU read() read() busy waiting read() timeout

◮ Not many CAN controllers offer interrupt coalescing. ◮ Avoiding IRQ overhead brings only negligible benefits. ◮ Busy polling is not useful for CAN.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 14 / 15

slide-37
SLIDE 37

Conclusion

Conclusion

◮ Experimental performance analysis of Linux network-related

user space APIs in the context of CAN bus.

◮ Interfaces that can handle multiple messages per system call

(recvmmsg(), memory-mapped sockets) are superior to single-message system calls (read()).

◮ recvmmsg() is simpler to use than memory-mapped sockets.

◮ New Low-latency sockets are not useful for CAN applications. ◮ Task wake-up latency.

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 15 / 15

slide-38
SLIDE 38

Conclusion

Conclusion

◮ Experimental performance analysis of Linux network-related

user space APIs in the context of CAN bus.

◮ Interfaces that can handle multiple messages per system call

(recvmmsg(), memory-mapped sockets) are superior to single-message system calls (read()).

◮ recvmmsg() is simpler to use than memory-mapped sockets.

◮ New Low-latency sockets are not useful for CAN applications. ◮ Task wake-up latency.

Thank you!

  • M. Sojka, et al.

Linux CAN-related system calls WFCS2014 15 / 15