Real Time Systems | 2 min | 3704
Today I patched the kernel of a Raspberry Pi Zero W with Preempt-RT. I used the repo TiejunChina.
Update 18.03.2018: The official Preempt-RT patched Rasbian repo is here.
##~/rpi-kernel$ git clone https://github.com/TiejunChina/linux.git # update 18.03.2018: old repository## ~/rpi-kernel$ git clone https://github.com/raspberrypi/linux.git # update 18.03.2018: new repository ~/rpi-kernel$ cd linux ~/rpi-kernel/linux$ git checkout rpi-4.14.y-rt # today the kernel version is 4.14.22 # with rt17 resulting in 4.14.22-rt17+
You can find a complete tutorial for patching a Raspbian kernel 4.14.y here.
Check the options for Raspberry Model A(+), B(+), Zero W, especially these ones:
~/rpi-kernel/linux$ export KERNEL=kernel ~/rpi-kernel/linux$ make bcmrpi_defconfig
For the Zero, you also need the options:
~$ sudo nano /boot/cmdline.txt # Add the following options: dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0
if you are using the USB port, otherwise the Raspberry Zero freezes immediately as soon as you connect something to the port (USB drive, Wi-Fi dongle etc.)
Here are the results for the latency:
Fig. 1: Latency using Kernel Patched with Preempt-RT
If you are interesting in the results for the Raspberry Pi 3 Model B, check this link!
Performance & Errors
In this case, I thought that the Raspberry Pi Zero didn't have the problem with the performance because of the
irq/33-dwc_otg(read here), which was on the list of
top, but it didn't use too much CPU. BUT! The Raspberry Zero doesn't have any LAN over USB connection, and that was the difference. I connected an USB drive and copied a file to it, and guest what! Check Fig. 2: Yes, the
irq/33-dwc_otgtook 16,7% CPU. The problem is still there! If you don't need to use the USB, the Preempt-RT Kernel is a good option!
Fig. 2: Performance problems with Preempt-RT patched kernel
dmesgand I got the following errors very often! (Fig. 3)
raspberrypi-firmware soc:firmware: Request 0x00030046 returned status 0x80000001
Fig. 3: dmesg reporting an error
I don't known, if the request ID is related with this commit. I have to check a little more. If you have an idea, write a comment!
The latency is reduced. If you are not using the USB port of the Raspberry Pi Zero and latency is important to you, e.g. sampling a sensor using SPI, or something related, the Preempt-RT patched kernel is a good option for you. If you are using the USB port, you will be losing about 16% of CPU with this kernel, because of the USB irq. Then, you need to evaluate if latency is more important than performance.