Skip to content

preempt_rt_kernel

Dan Zimmerman edited this page Oct 16, 2024 · 14 revisions

Building The PREEMPT_RT Realtime Kernel

Attempt 1: Bookworm - Raspberry Pi OS Official Instructions

Following cross-compile instructions here:

https://www.raspberrypi.com/documentation/computers/linux_kernel.html#cross-compile-the-kernel

Doing this on WSL 2, Ubuntu Noble 24.04.1 LTS

  1. Clone the Raspberry Pi OS kernel sources
git clone --depth=1 https://github.com/raspberrypi/linux
  1. Prepare for cross-compilation

Install some tools:

sudo apt update
sudo apt install bc bison flex libssl-dev make libc6-dev libncurses5-dev

And get cross-build for ARM64:

sudo apt install crossbuild-essential-arm64
  1. Patch the kernel

https://www.raspberrypi.com/documentation/computers/linux_kernel.html#patch-the-kernel

See also:

https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/real_time.rst

Check the kernel version:

dan@karman:~/linux$ head Makefile -n 4
# SPDX-License-Identifier: GPL-2.0
VERSION = 6
PATCHLEVEL = 6
SUBLEVEL = 56

We actually want 6.6.53 after 4ad9fa5c30edc19acf05b2960dd686c29cbe75a2

💡 The Raspberry Pi forums don't seem to require an exact match between the kernel version and the RT patch version. Let's try it.

In the cloned linux folder:

wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.6/patch-6.6.53-rt44.patch.gz
gunzip patch-6.6.53-rt44.patch.gz
cat patch-6.6.53-rt44.patch | patch -p1

This seemed fine, see below.

⚠️ However, there's no "Fully Preemptible Kernel Option

Patch Output Details

Patch output
patching file arch/arm/Kconfig
patching file arch/arm/mm/fault.c
patching file arch/arm/vfp/vfpmodule.c
Hunk #2 succeeded at 271 (offset 3 lines).
Hunk #3 succeeded at 279 (offset 3 lines).
Hunk #4 succeeded at 307 (offset 3 lines).
Hunk #5 succeeded at 353 (offset 3 lines).
Hunk #6 succeeded at 400 (offset 3 lines).
Hunk #7 succeeded at 425 (offset 3 lines).
Hunk #8 succeeded at 444 (offset 3 lines).
Hunk #9 succeeded at 552 (offset 6 lines).
Hunk #10 succeeded at 566 (offset 7 lines).
Hunk #11 succeeded at 726 (offset 12 lines).
Hunk #12 succeeded at 791 (offset 12 lines).
Hunk #13 succeeded at 806 (offset 12 lines).
Hunk #14 succeeded at 863 (offset 12 lines).
Hunk #15 succeeded at 895 (offset 13 lines).
patching file arch/arm64/Kconfig
patching file arch/powerpc/Kconfig
patching file arch/powerpc/include/asm/stackprotector.h
patching file arch/powerpc/kernel/traps.c
patching file arch/powerpc/kvm/Kconfig
patching file arch/powerpc/platforms/pseries/Kconfig
patching file arch/powerpc/platforms/pseries/iommu.c
patching file arch/riscv/Kconfig
patching file arch/riscv/include/asm/cpufeature.h
patching file arch/riscv/include/asm/thread_info.h
Hunk #1 succeeded at 87 (offset 5 lines).
Hunk #2 succeeded at 102 (offset 5 lines).
patching file arch/riscv/kernel/cpufeature.c
patching file arch/riscv/kernel/smpboot.c
patching file arch/x86/Kconfig
patching file arch/x86/include/asm/thread_info.h
patching file drivers/acpi/processor_idle.c
patching file drivers/block/zram/zram_drv.c
patching file drivers/block/zram/zram_drv.h
patching file drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c
patching file drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c
patching file drivers/gpu/drm/amd/display/dc/dcn21/dcn21_resource.c
patching file drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c
patching file drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.h
patching file drivers/gpu/drm/i915/Kconfig
patching file drivers/gpu/drm/i915/display/intel_crtc.c
patching file drivers/gpu/drm/i915/display/intel_vblank.c
patching file drivers/gpu/drm/i915/gt/intel_breadcrumbs.c
patching file drivers/gpu/drm/i915/gt/intel_execlists_submission.c
patching file drivers/gpu/drm/i915/gt/intel_reset.c
patching file drivers/gpu/drm/i915/gt/uc/intel_guc.h
patching file drivers/gpu/drm/i915/i915_request.c
patching file drivers/gpu/drm/i915/i915_trace.h
patching file drivers/gpu/drm/i915/i915_utils.h
patching file drivers/tty/serial/21285.c
patching file drivers/tty/serial/8250/8250_aspeed_vuart.c
patching file drivers/tty/serial/8250/8250_bcm7271.c
patching file drivers/tty/serial/8250/8250_core.c
Hunk #1 succeeded at 271 (offset 12 lines).
Hunk #2 succeeded at 304 (offset 12 lines).
Hunk #3 succeeded at 607 (offset 15 lines).
Hunk #4 succeeded at 615 (offset 15 lines).
Hunk #5 succeeded at 745 (offset 15 lines).
Hunk #6 succeeded at 1047 (offset 15 lines).
Hunk #7 succeeded at 1249 (offset 15 lines).
patching file drivers/tty/serial/8250/8250_dma.c
patching file drivers/tty/serial/8250/8250_dw.c
patching file drivers/tty/serial/8250/8250_exar.c
patching file drivers/tty/serial/8250/8250_fsl.c
patching file drivers/tty/serial/8250/8250_mtk.c
patching file drivers/tty/serial/8250/8250_omap.c
patching file drivers/tty/serial/8250/8250_pci1xxxx.c
patching file drivers/tty/serial/8250/8250_port.c
Hunk #16 succeeded at 1644 (offset 3 lines).
Hunk #17 succeeded at 1938 (offset 9 lines).
Hunk #18 succeeded at 2008 (offset 9 lines).
Hunk #19 succeeded at 2025 (offset 9 lines).
Hunk #20 succeeded at 2090 (offset 9 lines).
Hunk #21 succeeded at 2231 (offset 9 lines).
Hunk #22 succeeded at 2241 (offset 9 lines).
Hunk #23 succeeded at 2250 (offset 9 lines).
Hunk #24 succeeded at 2367 (offset 9 lines).
Hunk #25 succeeded at 2379 (offset 9 lines).
Hunk #26 succeeded at 2402 (offset 9 lines).
Hunk #27 succeeded at 2448 (offset 9 lines).
Hunk #28 succeeded at 2519 (offset 9 lines).
Hunk #29 succeeded at 2538 (offset 9 lines).
Hunk #30 succeeded at 2774 (offset 9 lines).
Hunk #31 succeeded at 2818 (offset 9 lines).
Hunk #32 succeeded at 2921 (offset 9 lines).
Hunk #33 succeeded at 2944 (offset 9 lines).
Hunk #34 succeeded at 3348 (offset 9 lines).
Hunk #35 succeeded at 3381 (offset 9 lines).
Hunk #36 succeeded at 3432 (offset 9 lines).
Hunk #37 succeeded at 3504 (offset 9 lines).
Hunk #38 succeeded at 3653 (offset 9 lines).
Hunk #39 succeeded at 3663 (offset 9 lines).
patching file drivers/tty/serial/altera_jtaguart.c
patching file drivers/tty/serial/altera_uart.c
patching file drivers/tty/serial/amba-pl010.c
patching file drivers/tty/serial/amba-pl011.c
Hunk #1 succeeded at 361 (offset 14 lines).
Hunk #2 succeeded at 564 (offset 20 lines).
Hunk #3 succeeded at 585 (offset 20 lines).
Hunk #4 succeeded at 596 (offset 20 lines).
Hunk #5 succeeded at 1024 (offset 20 lines).
Hunk #6 succeeded at 1040 (offset 20 lines).
Hunk #7 succeeded at 1106 (offset 20 lines).
Hunk #8 succeeded at 1206 (offset 20 lines).
Hunk #9 succeeded at 1420 (offset 20 lines).
Hunk #10 succeeded at 1440 (offset 20 lines).
Hunk #11 succeeded at 1465 (offset 20 lines).
Hunk #12 succeeded at 1576 (offset 25 lines).
Hunk #13 succeeded at 1606 (offset 25 lines).
Hunk #14 succeeded at 1678 (offset 25 lines).
Hunk #15 succeeded at 1824 (offset 25 lines).
Hunk #16 succeeded at 1846 (offset 25 lines).
Hunk #17 succeeded at 1854 (offset 25 lines).
Hunk #18 succeeded at 1862 (offset 25 lines).
Hunk #19 succeeded at 1882 (offset 25 lines).
Hunk #20 succeeded at 1893 (offset 25 lines).
Hunk #21 succeeded at 1954 (offset 25 lines).
Hunk #22 succeeded at 1971 (offset 25 lines).
Hunk #23 succeeded at 2123 (offset 25 lines).
Hunk #24 succeeded at 2197 (offset 25 lines).
Hunk #25 succeeded at 2215 (offset 25 lines).
Hunk #26 succeeded at 2353 (offset 25 lines).
Hunk #27 succeeded at 2382 (offset 25 lines).
patching file drivers/tty/serial/apbuart.c
patching file drivers/tty/serial/ar933x_uart.c
patching file drivers/tty/serial/arc_uart.c
patching file drivers/tty/serial/atmel_serial.c
patching file drivers/tty/serial/bcm63xx_uart.c
patching file drivers/tty/serial/cpm_uart.c
patching file drivers/tty/serial/digicolor-usart.c
patching file drivers/tty/serial/dz.c
patching file drivers/tty/serial/fsl_linflexuart.c
patching file drivers/tty/serial/fsl_lpuart.c
patching file drivers/tty/serial/icom.c
patching file drivers/tty/serial/imx.c
patching file drivers/tty/serial/ip22zilog.c
patching file drivers/tty/serial/jsm/jsm_neo.c
patching file drivers/tty/serial/jsm/jsm_tty.c
patching file drivers/tty/serial/liteuart.c
patching file drivers/tty/serial/lpc32xx_hs.c
patching file drivers/tty/serial/ma35d1_serial.c
patching file drivers/tty/serial/mcf.c
patching file drivers/tty/serial/men_z135_uart.c
patching file drivers/tty/serial/meson_uart.c
patching file drivers/tty/serial/milbeaut_usio.c
patching file drivers/tty/serial/mpc52xx_uart.c
patching file drivers/tty/serial/mps2-uart.c
patching file drivers/tty/serial/msm_serial.c
patching file drivers/tty/serial/mvebu-uart.c
patching file drivers/tty/serial/omap-serial.c
patching file drivers/tty/serial/owl-uart.c
patching file drivers/tty/serial/pch_uart.c
patching file drivers/tty/serial/pic32_uart.c
patching file drivers/tty/serial/pmac_zilog.c
patching file drivers/tty/serial/pxa.c
patching file drivers/tty/serial/qcom_geni_serial.c
Hunk #1 succeeded at 473 (offset -9 lines).
Hunk #2 succeeded at 511 (offset -9 lines).
Hunk #3 succeeded at 963 (offset -9 lines).
patching file drivers/tty/serial/rda-uart.c
patching file drivers/tty/serial/rp2.c
patching file drivers/tty/serial/sa1100.c
patching file drivers/tty/serial/samsung_tty.c
patching file drivers/tty/serial/sb1250-duart.c
patching file drivers/tty/serial/sc16is7xx.c
Hunk #1 succeeded at 819 (offset 2 lines).
Hunk #2 succeeded at 828 (offset 2 lines).
patching file drivers/tty/serial/serial-tegra.c
patching file drivers/tty/serial/serial_core.c
patching file drivers/tty/serial/serial_mctrl_gpio.c
patching file drivers/tty/serial/serial_port.c
patching file drivers/tty/serial/serial_txx9.c
patching file drivers/tty/serial/sh-sci.c
patching file drivers/tty/serial/sifive.c
patching file drivers/tty/serial/sprd_serial.c
patching file drivers/tty/serial/st-asc.c
patching file drivers/tty/serial/stm32-usart.c
patching file drivers/tty/serial/sunhv.c
patching file drivers/tty/serial/sunplus-uart.c
patching file drivers/tty/serial/sunsab.c
patching file drivers/tty/serial/sunsu.c
patching file drivers/tty/serial/sunzilog.c
patching file drivers/tty/serial/timbuart.c
patching file drivers/tty/serial/uartlite.c
patching file drivers/tty/serial/ucc_uart.c
patching file drivers/tty/serial/vt8500_serial.c
patching file drivers/tty/serial/xilinx_uartps.c
patching file drivers/tty/tty_io.c
patching file fs/proc/consoles.c
patching file include/linux/bottom_half.h
patching file include/linux/console.h
patching file include/linux/entry-common.h
patching file include/linux/entry-kvm.h
patching file include/linux/interrupt.h
patching file include/linux/netdevice.h
patching file include/linux/printk.h
patching file include/linux/sched.h
patching file include/linux/sched/idle.h
patching file include/linux/sched/rt.h
patching file include/linux/serial_8250.h
patching file include/linux/serial_core.h
patching file include/linux/thread_info.h
patching file include/linux/trace_events.h
patching file kernel/Kconfig.preempt
patching file kernel/entry/common.c
patching file kernel/entry/kvm.c
patching file kernel/futex/pi.c
patching file kernel/futex/requeue.c
patching file kernel/ksysfs.c
patching file kernel/locking/lockdep.c
patching file kernel/locking/rtmutex.c
patching file kernel/locking/rwbase_rt.c
patching file kernel/locking/rwsem.c
patching file kernel/locking/spinlock_rt.c
patching file kernel/locking/ww_rt_mutex.c
patching file kernel/panic.c
patching file kernel/printk/Makefile
patching file kernel/printk/internal.h
patching file kernel/printk/nbcon.c
patching file kernel/printk/printk.c
patching file kernel/printk/printk_ringbuffer.c
patching file kernel/printk/printk_ringbuffer.h
patching file kernel/printk/printk_safe.c
patching file kernel/rcu/rcutorture.c
patching file kernel/rcu/tree_stall.h
patching file kernel/sched/core.c
patching file kernel/sched/debug.c
patching file kernel/sched/fair.c
Hunk #6 succeeded at 5495 (offset 76 lines).
Hunk #7 succeeded at 5509 (offset 76 lines).
Hunk #8 succeeded at 5655 (offset 76 lines).
Hunk #9 succeeded at 5915 (offset 76 lines).
Hunk #10 succeeded at 6620 (offset 76 lines).
Hunk #11 succeeded at 8298 with fuzz 1 (offset 76 lines).
Hunk #12 succeeded at 8336 (offset 72 lines).
Hunk #13 succeeded at 12482 (offset 72 lines).
Hunk #14 succeeded at 12647 (offset 72 lines).
patching file kernel/sched/features.h
patching file kernel/sched/idle.c
patching file kernel/sched/rt.c
patching file kernel/sched/sched.h
patching file kernel/signal.c
patching file kernel/softirq.c
patching file kernel/time/hrtimer.c
patching file kernel/time/tick-sched.c
patching file kernel/time/timer.c
patching file kernel/trace/trace.c
patching file kernel/trace/trace_output.c
patching file localversion-rt
patching file net/core/dev.c
Hunk #1 succeeded at 4709 (offset 4 lines).
Hunk #2 succeeded at 6677 (offset 4 lines).
Hunk #3 succeeded at 11640 (offset 4 lines).
patching file net/core/skbuff.c

Attempt 2

https://github.com/by/RT-Kernel

In the resulting linux folder run

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2712_defconfig

Then

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

General->Preemption Model->Fully Preemptible

CPU Frequency Scaling -> Default CPUFreq governor (performance)

Then exit out.

From UR Client Library

scripts/config --disable SYSTEM_TRUSTED_KEYS
scripts/config --disable SYSTEM_REVOCATION_KEYS

Then finally:

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j `getconf _NPROCESSORS_ONLN` deb-pkg

Needed also, based on build error:

sudo apt install debhelper-compat cpio libelf-dev
Clone this wiki locally