PREEMPT_RT Explained: How to Check If Your Linux Kernel Is Real-Time
What PREEMPT_RT changes in the Linux kernel, and how to check a running system's kernel configuration for CONFIG_PREEMPT_RT with a short script.
Contents
PREEMPT_RT is a kernel configuration that makes Linux react to higher-priority work sooner by shrinking the code paths that cannot be interrupted. A kernel is only real-time capable if it was built with CONFIG_PREEMPT_RT, and you can check that on a running system by reading its build configuration.
What PREEMPT_RT changes
The kernel documentation describes two main ideas: sleeping locks and forced-threaded interrupts. Both aim at the same goal, which is to let the scheduler preempt the current context and switch to a higher-priority task sooner.
Sleeping spin locks. On a normal kernel, taking a spinlock_t disables preemption and spins until the lock is free. With PREEMPT_RT, spinlock_t is built on an rtmutex. A task that hits a contended lock donates its priority to the owner and sleeps instead of spinning. Preemption stays enabled, and the task is kept on its CPU by disabling migration.
Priority inheritance. Locks built on rtmutex, such as spinlock_t and mutex, pass the waiter’s scheduling parameters to the lock owner. If a SCHED_FIFO task waits on a lock held by a SCHED_OTHER task, the owner temporarily runs with the waiter’s priority, releases the lock, and then reverts.
Threaded interrupts. Interrupt handlers are forced into threads. A small primary handler runs in interrupt context and only wakes the threaded handler, which runs in process context under scheduler control. By default that thread uses SCHED_FIFO at priority 50.
Some things also move. Soft interrupts run in preemptible thread context, and hrtimers run in softirq context unless marked as hard. Raw spinlocks (raw_spinlock_t) keep the traditional behavior and are used by core parts such as the scheduler and interrupt handling.
Why the scheduling policy still matters
PREEMPT_RT does not make every program fast or real-time by itself. The default SCHED_OTHER policy gives no guarantee that a newly runnable task preempts the current one right away. Real-time policies such as SCHED_FIFO do: a newly runnable higher-priority task is chosen immediately and runs until it blocks or yields. Latency-sensitive tasks need such a policy.
Check the kernel configuration
The option to look for is CONFIG_PREEMPT_RT. The kernel documentation says it must be enabled or the kernel will not be fully preemptible and real-time capable. This script looks for the build configuration in /proc/config.gz (when the kernel provides it) and in /boot/config-<release>. It prints what it finds and does not fail if neither exists.
cfg=""
if [ -r /proc/config.gz ]; then
cfg="zcat /proc/config.gz"
elif [ -r "/boot/config-$(uname -r)" ]; then
cfg="cat /boot/config-$(uname -r)"
fi
if [ -z "$cfg" ]; then
echo "No kernel config found for $(uname -r); cannot tell from here."
elif $cfg | grep -q '^CONFIG_PREEMPT_RT=y'; then
echo "CONFIG_PREEMPT_RT is enabled: this is a real-time kernel build."
else
echo "CONFIG_PREEMPT_RT is not enabled in this kernel's configuration."
fiIf the script reports that the option is not enabled, the kernel was not built as a PREEMPT_RT kernel. If it finds no config file, check your distribution’s kernel package documentation.
Other settings that affect latency
The real-time configuration guide lists more options beyond CONFIG_PREEMPT_RT. It recommends, for example, a fixed CPU frequency through the performance governor, and avoiding the lockup detector (CONFIG_LOCKUP_DETECTOR), CONFIG_PROVE_LOCKING and the irqsoff and preempt tracers in production. It also advises caution with tickless modes and deep CPU idle states. Treat those as tuning steps after you confirm the kernel itself is a PREEMPT_RT build.
Where to read more
The kernel.org documentation also covers hardware considerations (memory, buses, virtualization, networking, firmware) and how to port an architecture to PREEMPT_RT. For running a minimal kernel of your own, see Buildroot: Build a Minimal Linux Image and Boot It in QEMU. To read kernel messages after boot, see journalctl: Read and Filter systemd Logs on Linux.
Sources
This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.