Something pretty historic (at least for geeks like us), happened this week of 16 September 2024; the Linux realtime effort, christened PREEMPT_RT and then Real-Time Linux (RTL), has finally – finally! – been fully merged into the kernel.
The intense, and often earlier unrewarded, work of making Linux RT capable – to use as an RTOS – began back in 2004 with Thomas Gleixner, the late Doug Niehaus, and Ingo Molnar. Soon enough Steven Rostedt (he of Ftrace fame), and several others became major contributors to the effort. It took ‘just’ 20 years; and soon the shiny new 6.12 6.11 Linux kernel will have all the RTL code in-tree. (Update: 6.11 has been released on 23 Sept 2024.)
Until now, developers had to apply an out-of-tree patch to get the code in; here’s the recent 6.9 RT patch(es).
The ‘Merge’
The final barrier falls – the ‘last’ patch (PR) from Petr Mladek, dated 13 Sept 2024, that gets the stubborn printk issues resolved and merged into the (soon-to-be) 6.11 kernel.
Here’s a pic of Thomas Gleixner presenting the last printk-related PR – the one that completes the full inclusion of RTL – to Linus Torvalds at the Open Source Summit Europe in Vienna on 19 Sept 2024. The pull request was presented to Linus in hard-copy gold paper, tied with a ribbon! (That’s Thomas on the left, Linus on the right.)
Pic credit: https://lwn.net/Articles/990985/, Jon Corbet.
See a short video clip of this historic event here (credit: Alexander Kanavin. In it, you can also see a background pic of late Doug Niehaus and Daniel Bristot de Oliveira; as one person commented on LinkedIn: ‘The RT folks are classy.’).
Linus acts on the patch! Here’s the commit (# baeb9a7d8b60b021d907127509c44507539c15e5).
Trying it out
Here’s a simple ‘try’ of the brand new fully-merged RTL kernel; the steps to fetch the git tree, configure and build it, and see it run are shown here… (I did this trivially on an x86_64 Ubuntu 22.04 LTS VM).
Steps
- Get the bleeding-edge linux-next kernel tree
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git - Look up the Makefile and git log, see the last RTL patch:
$ cd linux-next
$ head Makefile
# SPDX-License-Identifier: GPL-2.0
VERSION = 6
PATCHLEVEL = 11
SUBLEVEL = 0
EXTRAVERSION =[ ... ]
$ git logMerge: 2004cef11ea0 2638e4e6b182Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Fri Sep 20 06:04:27 2024 +0200
Merge tag 'sched-rt-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tipPull RT enablement from Thomas Gleixner:
"Enable PREEMPT_RT on supported architectures:After twenty years of development we finally reached the point to enable PREEMPT_RT support in the mainline kernel.All prerequisites are merged, so enable it on the supported architectures ARM64, RISCV and X86(32/64-bit)"* tag 'sched-rt-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
riscv: Allow to enable PREEMPT_RT.
arm64: Allow to enable PREEMPT_RT.
x86: Allow to enable PREEMPT_RT.commit 2004cef11ea072838f99bd95cefa5c8e45df0847
Merge: 509d2cd12a10 bc9057da1a22
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Thu Sep 19 15:55:58 2024 +0200
Merge tag 'sched-core-2024-09-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[ ... ] - Configure the kernel, turn on PREEMPT_RT – no patching required!
(as a simplification, I use the ‘localmodconfig’ config target to have the kernel config be a reasonable size, based on that of the build host):lsmod > mylsmod
make LSMOD=./mylsmod localmodconfig
make menuconfig
[ ... ]

Figure: navigate to ‘General Setup / Preemption Model’ and turn RTL on!
Save and exit.
FYI, here’s the ‘Kconfig’ fragment: kernel/Kconfig.preempt
config PREEMPT_RT
bool "Fully Preemptible Kernel (Real-Time)"
depends on EXPERT && ARCH_SUPPORTS_RT
select PREEMPTION
help
This option turns the kernel into a real-time kernel by replacing various locking primitives (spinlocks, rwlocks, etc.) with preemptible priority-inheritance aware variants, enforcing interrupt threading and introducing mechanisms to break up long non-preemptible sections. This makes the kernel, except for very low level and critical code paths (entry code, scheduler, low level interrupt handling) fully preemptible and brings most execution contexts under scheduler control.
Select this if you are building a kernel for systems which require real-time guarantees.
[ … ]$ grep PREEMPT_RT .config
CONFIG_PREEMPT_RT=y
4. Build it:
$ time make -j12
[ ... ]
BUILD arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready (#1)
$ sudo make modules_install && sudo make install
5. Ok, let’s reboot and see…
sudo reboot]
[ ... select the new RTL kernel from the bootloader ...
$ cat /proc/version
Linux version 6.11.0-rtl+ (kaiwan@vbox-22) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #1 SMP PREEMPT_RT Fri Sep 20 19:11:35 IST 2024
Nice! (Not that one can ‘feel’ anything very different on a PC/laptop; to realize it’s value, run a real-time app – audio (via JACK, PulseAudio, etc) is typically a very good fit.)
The history of PREEMPT_RT / RTL
If interested, you can find (a lot!) of the history, as well as the reasons to use RTL, from the following:
- This excellent article ‘In the trenches with Thomas Gleixner, real-time Linux kernel patch set’, by Jason Perlow, Linux.com (April 2020), is a superb interview with Thomas Gleixner; they talk about the history, the challenges faced along the way, where it’s going (for example, the LF ELISA projects’ attempting to ultimately be able to certify Linux as a safety-critical (RT)OS)
- Technical articles on Linux Realtime on lwn.net; they span from Oct 2004 to May 2020.
I do hope you enjoyed reading this; do leave your comments and share, thanks.
