Unfortunately the Raspberry Pi OS does not support a precompiled PREEMPT_RT patched kernel for armhf in their repositories. It is described here roughly how to do the task.
Short description of cross-building a PREEMPT_RT patched kernel for the Raspberry Pi. A SD-card with a preinstalled Raspberry Pi OS is needed with following partitions mounted to the host:
/media/debian/rootfs
/media/debian/boot
Clone the latest kernel sources and check version:
debian@pc:~/$ git clone --depth=1 --branch=rpi-5.15.y https://github.com/raspberrypi/linux.git linux
debian@pc:~/$ cd linux
debian@pc:~/linux$ make kernelversion
Setup a shell script setup.sh
within linux directory for setting build variables:
#!/bin/sh
export KERNEL=kernel7
export ARCH=arm
export CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-
export CONCURRENCY_LEVEL=4
export INSTALL_MOD_PATH=/media/debian/rootfs
Make it executable with chmod u+x setup.sh
.
Execute shell script and generate default kernel config for Rpi3:
debian@pc:~/linux$ source setup.sh
debian@pc:~/linux$ make bcm2709_defconfig
debian@pc:~/linux$ cd ..
Load and apply realtime patch:
debian@pc:~/$ wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/5.15/patch-5.15.21-rt30.patch.xz
debian@pc:~/$ cd linux
debian@pc:~/linux$ xzcat ../patch-5.15.21-rt30.patch.xz | patch -p1
Modify kernel to be fully preemptible:
debian@pc:~/linux$ make menuconfig
Save to default (.config) and exit. Build the kernel:
debian@pc:~/linux$ make clean
debian@pc:~/linux$ make -j4 zImage modules dtbs
Install kernel modules to SD-card:
debian@pc:~/linux$ sudo bash -c "source ./setup.sh; make modules_install"
Install kernel to boot partition:
debian@pc:~/linux$ sudo cp arch/arm/boot/zImage /media/debian/boot/kernel7_rt.img
debian@pc:~/linux$ sudo cp arch/arm/boot/dts/*.dtb /media/debian/boot/
debian@pc:~/linux$ sudo cp arch/arm/boot/dts/overlays/*.dtb* /media/debian/boot/overlays/
Modify /media/debian/boot/config.txt
for booting the realtime kernel:
kernel=kernel7_rt.img
enable_uart=1
force_turbo=1
Modify /media/debian/boot/cmdline.txt
for disabling FIQ, because leads to freeze of kernel:
dwc_otg.fiq_fsm_enable=0 dwc_otg.fiq_enable=0 dwc_otg.nak_holdoff=0
Sync and unmount SD-card:
debian@pc:~/$ sudo sync
debian@pc:~/$ sudo umount /media/debian/boot/
debian@pc:~/$ sudo umount /media/debian/rootfs/
Insert SD-card into Raspberry-Pi3 and boot. Check if kernel reports PREEMPT_RT in uname -r
.
The Linux-Foundation offers a tool set for testing the realtime performance on a PREEMPT_RT patched kernel. Additionally the OSADL has a script which automates the test and creates a nice histogram showing the statistics. The test should run under heavy load conditions with the tool sysbench.