User Tools

Site Tools


Technical details of the real-time preemption

The main aim of the real-time preemption is to minimize the amount of kernel code that is non-preemptible 1). Therefore different mechanisms are implemented. Those mechanisms are partially available in mainline Linux. The PREEMPT_RT patch has been partially merged into the mainline Linux kernel, starting from version 5.15 2) and enabled with CONFIG_PREEMPT_RT

High resolution timers

The high resolution timers allows precise timed scheduling and removes the dependency of timers on the periodic scheduler tick (jiffies).

Threaded interrupt handler

The PREEMPT_RT patch forces the mechanism of threaded interrupt handlers. Due to this all interrupt handlers run in a threaded context except they are marked with the IRQF_NO_THREAD flag. This mechanism can be forced also in Linux mainline kernel without PREEMPT_RT patch by the kernel command line option threadirqs. But there is a small difference in the resulted behavior.


RCU mechanisms in mainline Linux are only preemptible if CONFIG_PREEMPT is set (Preemption model: “Low-Latency Desktop”). The PREEMPT_RT preemption models both use preemptible RCU mechanisms. Additionally the PREEMPT_RT patch eliminates RCU handling from all intermediate states and processes it only in its own thread.


Mutexes are implemented with rt mutexes. A rt_mutex implements priority inheritance (see rt_mutex_adjust_prio_chain) to avoid priority inversion. This also applies to sleeping spinlocks and rwlocks. However, the holder of a semaphore can be preempted but does not participate in priority inheritance.

Sleeping spinlocks

In a non-PREEMPT-RT preemption model spinlocks are mapped onto raw spinlocks. A task waiting for a spinlock held by another task spins until the task holding the spinlock releases it. Preemption is disabled in raw spinlock context. In PREEMPT_RT spinlocks are mapped onto rt_mutex_base and became “sleeping spinlocks”, and raw spinlocks retain their behavior. A task waiting for a sleeping spinlock goes to sleep and is woken up when the spinlock is released. In the sleeping spinlock context preemption is not disabled.


local_lock maps to a per CPU spinlock, which protects the critical section while staying preemptible. See local_lock_internal.h

Paul McKenney, A realtime preemption overview
Realtime preemption locking core merged
realtime/documentation/technical_details/start.txt · Last modified: 2023/10/03 08:37 by costa.shul