Real-Time Extensions
Like any GPOS, the Linux kernel is mainly optimized for throughput, as that is the most important design goal for such systems. This means that by default, unmodified Linux systems will regularly experience significant unbounded latencies that cannot be accepted in a real-time system. However, it is possible to add the missing real-time capabilities to the Linux kernel. This way, the operating system can provide the best of both worlds by offering a wide range of system services and acceptable real-time performance. Generally, there are two different ways of implementing the real-time capabilities, either by implementing a co-kernel-based system or by patching the mainline kernel, as presented in Different Architectures of Real-Time Linux Systems. In the first option, the Linux kernel is run as a normal process under a separate real-time scheduler. When this same scheduler also handles real-time tasks and system events, the real-time portion can be quite easily separated from the rest of the system. The second option is to leave the underlying kernel architecture untouched and instead introduce a set of changes to the kernel itself. In this configuration, the Linux kernel is responsible for simultaneously scheduling both normal and real-time tasks executing within the system.
In co-kernel systems, the Linux kernel is isolated from real-time tasks in some way.
(a) Co-kernel (Xenomai) (b) Patch (PREEMPT_RT) |
One quite popular example of such a system is the Xenomai project, utilizing an intermediate layer between the hardware and Linux kernel, which effectively acts as an interrupt dispatcher and scheduler. Basically, it handles the system events so that processing is always prioritized for the highest priority real-time tasks to guarantee the specified timing requirements. Another viable alternative is a PREEMPT_RT patched Linux, i.e., Real-Time Linux kernel. In this approach, underlying architecture remains exactly the same before. Previously, the PREEMPT_RT introduced a very significant number of changes to the kernel, but today many of these features have already been merged into the mainline kernel. This work is still ongoing, but eventually the whole PREEMPT_RT patch should be included in the mainline kernel.
Choosing between these two architectures is very much application-dependent. Typically, approaches utilizing co-kernel can achieve slightly lower latencies. But on the other hand, the system complexity is increased, and real-time tasks need to be specially crafted for the used real-time kernel. That is the opposite of the PREEMPT_RT patched Linux kernel as the architecture is simpler, and the real-time tasks can be written almost like any other regular application. Also, the overall performance of patched Linux is on average better than what the co-kernel counter parts can achieve.