Xenomai 4 or PREEMPT_RT?

Since Linux 6.12, the mainline kernel can be built with native preemption (PREEMPT_RT), which turns the whole kernel into a fully preemptible one. Xenomai 4 follows another path. Both can serve real-time applications, but they do not make the same trade-offs. This page should help you pick the one which fits your project.

Two ways to get real-time behavior

Native preemption makes the whole kernel preemptible: interrupt handlers run in threads, most spinlocks become sleeping locks, and a high-priority task may preempt nearly any kernel activity. Real-time tasks share the same kernel with every other task. Their response time depends on how the whole system behaves: every driver, lock and subsystem they may run into, and every other real-time task competing for the CPU.

Xenomai 4 keeps the real-time path small and separate. The Dovetail interface gives the kernel a second, out-of-band execution stage, which runs ahead of the rest of Linux. Time-critical work runs on that stage, served by the compact EVL core (about 20 KLOC). The rest of the system, including the regular kernel, runs in-band. Its activity has little effect on the out-of-band stage, which preempts it at any time.

Why Xenomai 4 shows less jitter

On the same hardware, the response time of Xenomai 4 usually varies less than with PREEMPT_RT, as the benchmarks show. The reasons all come from the small and separate real-time path:

  • In-band code cannot delay the out-of-band stage. With the interrupt pipeline, the in-band kernel only disables interrupts virtually: the CPU still takes them, and passes them on to the out-of-band stage at once. With PREEMPT_RT, some kernel code still runs with preemption or interrupts disabled, such as the scheduler, the timer code, or code holding a raw spinlock. The longest of these sections, anywhere in the kernel, adds to the worst case.

  • Fewer steps from an interrupt to the task. An out-of-band interrupt handler runs right away, and can wake up an EVL thread directly. With PREEMPT_RT, most interrupt handlers run in kernel threads: the interrupt first wakes up the handler thread, which then wakes up the real-time task. This means one more wakeup and one more context switch on the way.

  • No lock shared with the rest of the system. Out-of-band code never waits for a lock held by in-band code. With PREEMPT_RT, a real-time task may wait for a sleeping lock held by any other task. Priority inheritance bounds this wait, but its length still depends on what the owner does while it holds the lock.

  • A small code footprint. The EVL core is about 20 KLOC, and its scheduler only deals with out-of-band threads. The code which runs from an interrupt to the task is short, so it needs few cache lines and TLB entries. Cache misses are a common source of jitter: in-band activity evicts the real-time code from the caches, and the less code there is to fetch back, the less the response time varies. With PREEMPT_RT, the same path goes through the common scheduler, the regular system call entry and exit work, and the general locking code.

The introduction to Dovetail explains this design further.

At a glance

PREEMPT_RT Xenomai 4
Kernel Mainline, built with CONFIG_PREEMPT_RT Patched with Dovetail and EVL, for the tip, LTS and SLTS kernel series
Real-time path The whole kernel The EVL core and out-of-band drivers
What the worst case depends on Every part of the kernel the real-time tasks run into, plus the other real-time tasks Mainly the out-of-band code path and the hardware
Device drivers Any Linux driver, with threaded interrupt handlers Any Linux driver in-band; out-of-band drivers for real-time I/O (GPIO, SPI, DMA, network)
Programming interface Standard POSIX and Linux calls The native API, the POSIX API, or Rust
System tuning Whole-system tuning, checked driver by driver Few runtime settings, see the caveats
Low-end hardware Works best with CPUs set aside for real-time Designed to guarantee small and bounded jitter down to single-core systems
Multi-core hardware CPUs set aside for real-time, with CPU isolation Use all CPUs for the real-time workload, or set some aside for this with evl.oobcpus, with CPU isolation

When PREEMPT_RT fits

  • You want to use a stock kernel, and keep using every driver as is.
  • Your application uses the standard POSIX and Linux calls, and you do not want to change how it is written.
  • Your timing budget leaves enough margin for the latency peaks of the whole system, which you can measure on your own setup.
  • You can set CPUs aside for the real-time work, and tune the rest of the system around it.

When Xenomai 4 fits

  • The worst-case response time must stay small and bounded, whatever the general-purpose side of the system is doing.
  • Timing accuracy matters: the out-of-band path shows less jitter, so periodic work runs closer to its due dates.
  • The hardware is modest, possibly a single core, and cannot spare CPUs for the real-time work alone.
  • The hardware has many CPUs: you can set a subset of them aside for the real-time work with the evl.oobcpus kernel parameter, along with CPU isolation, as PREEMPT_RT requires. Or you can use all or part of them in mixed-mode, shared between in-band and out-of-band tasks, trading more jitter on the real-time side - mainly due to cache eviction - for more CPU bandwidth available to the in-band workload when the real-time side is quiet.
  • You want a clear split between time-critical code and the rest of the application. Out-of-band calls are explicit in the code, which makes the real-time path easy to identify and review.
  • You need real-time I/O on devices for which an out-of-band driver is readily available, or you are ready to add out-of-band support to a driver.

Measure on your own hardware

Latency figures depend on the hardware, the kernel configuration and the load. The benchmarks page compares both approaches under the same stress load, and explains how to run the same tests on your own machine with the latmus program.