15 October, 2006

Linux, the real-time kernel

As of 2.6.18, the mainline Linux kernel has gained real-time features. But there are some confusion about the benefits and drawbacks of having real-time capabilities.

What's all the fuss about?


Real-time isn't about high throughput or low latencies. Real-time is about having predictability and consistency. The kernel must make good predictions about how long an operation will take, and meet those predictions under any circumstances. Even even if a certain application decides to eat up all memory and introduce massive swapping, or a device starts sending millions of hardware interrupts in every second. A real-time kernel must handle and schedule those events in a fashion so it can meet the promised execution times.

Ok, that sounds nice. Where are the drawbacks?


There's no such thing as free lunch. The price of these strict conditions is reduced speed. Most operations (like disk I/O) have the highest throughput if they are sustained without any interruptions, and the constant preemption and task switching interferes with this. Preemption has overhead. The scheduler, which decides what task should be taken care of has overhead.

So, do I need real-time kernel?


There are two categories of real-time. Hard real-time means strict schedule: a task finished late as bad as a task not done. Hard real-time is necessary in critical environments, like nuclear plants, or medical equipment. Take an X-ray machine, designed to fire 50ms pulses of Roentgen-radiation. It would be unacceptable to have 2-3 second long pulses because the kernel was busy processing the insane amount of interrupts sent by a malfunctioning component or stuck button. With soft real-time, occasionally violating the time constraints is allowed. For a TV station, the occasional loss of a single frame is acceptable if otherwise the video stream is fluid.
But for common desktop or server use, real-time capabilities are not necessary. Soft real-time can be useful for some video/audio professionals, but has no use for DVD-ripping/transcoding and makes it longer.

Conclusion


Having official support for real-time facilities in the Linux kernel is a great thing. It can reach now niche markets like some embedded systems where real-time is a must. And what about the rest of us, running our desktops and servers on Linux? All of us will benefit of the SMP/locking bugs found and fixed during the development of the rt patchset, without ever turning on the CONFIG_PREEMPT_RT option.