Real-Time & Kernel9 min readLinux 6.12 LTS

PREEMPT_RT latency tuning on Linux 6.12: rtla timerlat, threaded IRQs & CPU isolation

Separate throughput folklore from worst-case latency engineering: sleeping spinlocks, priority inheritance, CPU isolation, firmware SMI traps, and tracing microsecond tail spikes with rtla.

1. Throughput tuning breaks real-time bounds

General-purpose server tuning optimises mean throughput: batching interrupts, coalescing network rings, migrating tasks across sockets, and parking idle cores in deep C-states. Deterministic control loops care only about the right tail — the single worst wakeup across a hundred million timer periods. A system with a 3 µs average wakeup and one 420 µs spike misses a 250 µs motor-control deadline just as surely as a broken driver.

With CONFIG_PREEMPT_RT merged across mainline architectures in Linux 6.12 LTS, most in-kernel critical sections become preemptible without out-of-tree patchsets. Enabling the Kconfig symbol is only step one; bounding worst-case latency requires aligning four layers simultaneously: kernel locking semantics, interrupt threading, scheduler housekeeping isolation, and platform firmware power states.

2. What CONFIG_PREEMPT_RT actually changes in the kernel

On a standard voluntary or preemptible kernel, spinlock_t disables preemption and — in spin_lock_irqsave() — masks local CPU interrupts. Any high-priority SCHED_FIFO task waking on that CPU stalls until the lock holder finishes.

Under PREEMPT_RT, kernel primitives split into two explicit contracts:

  • spinlock_t & rwlock_t become sleeping locks backed by rt_mutex with priority inheritance (PI). Preemption and hardware interrupts remain enabled; if a priority-90 control thread blocks on a lock held by a priority-20 worker, the holder inherits priority 90 until release.
  • raw_spinlock_t stays a true spinning lock that disables preemption and interrupts. It is reserved strictly for the scheduler core, RCU internals, GIC/APIC irqchip controllers, and low-level timer hardware. Any driver holding a raw_spinlock_t across MMIO polling or variable-length loops directly inflates worst-case IRQ latency.
  • Hardware interrupt handlers run as scheduled kernel threads (irq/<N>-<name> at SCHED_FIFO priority 50 by default) unless registered with IRQF_NO_THREAD. Softirqs move into per-CPU ktimers and ksoftirqd context rather than hijacking arbitrary task returns.

3. Kernel boot parameters and housekeeping CPU split

Never run deterministic real-time threads on CPU 0. Boot housekeeping, timekeeping duties, and non-affinitised platform work gravitate there. Partition your cores into housekeeping CPUs (for SSH, logging, storage, and non-RT network traffic) and isolated RT CPUs:

# Example 4-core industrial SoC: CPUs 0-1 housekeeping, CPUs 2-3 isolated RT
isolcpus=managed_irq,domain,2-3
irqaffinity=0-1
nohz_full=2-3
rcu_nocbs=2-3
rcutree.kthread_prio=2
processor.max_cstate=1 idle=poll

Verify the active isolation masks immediately after boot rather than assuming the bootloader passed the command line intact:

cat /sys/devices/system/cpu/isolated
# expected: 2-3
cat /sys/devices/system/cpu/nohz_full
# expected: 2-3
ps -eo pid,psr,cls,rtprio,comm | awk '$3=="FF" {print}'

Note the trade-off on idle=poll versus /dev/cpu_dma_latency: holding a file descriptor open on /dev/cpu_dma_latency with a 32-bit integer value of 0 written to it prevents deep package C-state transitions dynamically while your real-time application runs, without burning thermal headroom when the machine is disarmed.

4. Ranking IRQ priorities above ksoftirqd, below the control loop

Leaving every threaded interrupt at the default SCHED_FIFO priority 50 means an Ethernet burst or MMC block completion preempts or contends with your fieldbus or sensor interrupt. Establish an explicit priority hierarchy:

LayerPolicy & priorityCPU mask
Hard safety / servo loopSCHED_FIFO 90 (mlockall(MCL_CURRENT|MCL_FUTURE))Isolated (2–3)
Deterministic bus IRQ (EtherCAT / CAN / SPI ADC)SCHED_FIFO 80Isolated core matching consumer
ktimers/* on RT coresSCHED_FIFO 75Per-CPU
Non-RT peripheral IRQs (NVMe, USB, management NIC)SCHED_FIFO 50 (default)Housekeeping (0–1)
rcuc/*, rcuog/*, rcuop/*SCHED_FIFO 2–5Housekeeping (0–1)

5. Hunting tail spikes with rtla timerlat and osnoise

cyclictest tells you that a 190 µs spike occurred; it does not tell you who disabled interrupts or held preemption before your thread ran. Mainline Linux ships rtla on top of the kernel timerlat and osnoise tracers specifically to close that gap without flooding ring buffers during normal cycles.

# Stress housekeeping & memory buses while watching isolated cores 2-3
stress-ng --cpu 2 --taskset 0-1 --io 2 --vm 1 --vm-bytes 256M --timeout 300s &

# Trigger an ftrace snapshot automatically if thread latency exceeds 40 us
rtla timerlat top -q -c 2-3 -p 1000 -P f:90 -i 25 -T 40 --aa-only 5

Read the two latency columns separately:

  • IRQ Timer Latency measures hardware timer interrupt delay. A spike here points below the scheduler: a driver holding a raw_spinlock_t, local_irq_disable(), cache/interconnect stall, UEFI runtime service, or x86/ARM firmware SMM/EL3 trap.
  • Thread Timer Latency measures the gap from timer IRQ exit to the real-time thread executing. When IRQ latency stays at 2 µs while Thread latency jumps to 85 µs, inspect the auto-analysis output from rtla: it names the exact blocking kernel thread, preemption-disabled section, or page fault.

6. Three userspace mistakes that ruin a tuned RT kernel

  1. Lazy page faults and stack growth: Always call mlockall(MCL_CURRENT | MCL_FUTURE) and pre-touch the worst-case thread stack plus heap arenas before entering the cyclic loop. One minor fault under memory pressure costs tens of microseconds.
  2. Standard pthread_mutex_t without PI: Initialise shared locks with pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) so the kernel backs them with FUTEX_LOCK_PI instead of plain wait queues subject to unbounded priority inversion.
  3. Synchronous logging on the RT thread: Calling fprintf(), syslog(), or allocating sockets inside the control loop hands your deterministic thread directly to VFS writeback or journal locks. Push fixed-size records into a lock-free SPSC ring buffer drained by a housekeeping thread on CPU 0.

Questions engineers ask

Is PREEMPT_RT mainline in Linux 6.12 LTS?

Yes. Linux 6.12 LTS completed mainline integration of PREEMPT_RT across x86_64, ARM64, and RISC-V, allowing real-time kernels to be built directly from upstream kernel.org releases without external patch queues.

Why use rtla timerlat instead of cyclictest?

cyclictest measures wakeup timestamps from userspace after the delay has already ended. rtla timerlat instruments both the hardware timer IRQ and thread wakeup inside ftrace and freezes the trace buffer at the exact microsecond a threshold is crossed, naming the offending function or lock.

What latency bound is realistic on PREEMPT_RT?

On properly isolated ARM64 or x86_64 hardware without firmware SMI interference, worst-case thread wakeup latency under heavy system load typically lands between 15 us and 50 us. Sub-microsecond hard deadlines with zero jitter belong in bare-metal Cortex-R/M firmware or an FPGA.

Hands-on courses covering this stack

More technical articles

Want a practitioner to look at your trace or board?

Book a free 60-minute technical session for your engineering team, or scope a private cohort adapted to your kernel tree and hardware.

Free technical session