Kernel Preemption
The mainline Linux kernel currently has three preemption settings available: server, desktop, and low-latency desktop. With the introduction of the PREEMPT_RT patch, a fourth real-time option becomes available. By using these options, it is possible to trade throughput for latency determinism. These options are described in the following list ordered from worst to best in terms of real-time performance.
- Server is the traditional preemption model. With this selection, the kernel code is executed with preemption disabled for the maximum throughput.
- Desktop preemption model adds explicit preemption points to the kernel code. This option provides better responsiveness at the cost of slightly lower throughput.
- Low-Latency Desktop reduces the latencies by making all normal kernel code preemptible. This setting allows better reaction times to interactive events.
- Real-Time option practically makes the whole kernel preemptible, including the most critical sections. This option is available only when the PREEMPT_RT patch is applied.
As the preemption option names suggest, each one of these settings has an appropriate use case. The server preemption can be used in server installations where throughput is the single most important figure. On the other hand, real-time preemption should be used in embedded systems where the absolute throughput is not critical but rather the maximum experienced latency is. Therefore, different preemption levels in Linux allow for great flexibility to be utilized in varying environments, i.e., the same operating system can be used in servers and embedded systems. Overall, this synergy is very beneficial for the whole ecosystem as improvements or fixes implemented for server systems can be also automatically applied for small embedded devices.
Even if some of the preemption settings claim to have reduced latency, in practice, the real-time setting is the only viable option for any real-time system. In this configuration, the majority of spinlocks are converted to normal sleeping locks, interrupt handlers are threaded, and high-resolution timers are used for precise timing. Additionally, there are some other more insignificant changes introduced. With these improvements, practically the whole kernel is completely preemptible. Only things like very low-level event handling are executed in a non-preemptible context. Altogether, the real-time preemption model significantly improves the system responsiveness but decreases the overall performance as every introduced change causes some additional overhead.