The beginning of the realtime preemption debate
The realtime preemption patches attempt to provide a guaranteed maximum response time for high-priority user-space processes - just like a "real" realtime operating system would. This goal is achieved by making everything in the kernel preemptible. No matter what the kernel is doing on a given processor, if a higher-priority process becomes runnable, it will be scheduled immediately. Many changes are required to make the whole kernel preemptible; the core parts are:
- New locking primitives. The spinlocks used by the kernel can cause
any number of processors to stall while waiting for a lock to become
free. Code which holds a spinlock cannot be preempted, or a
deadlocked kernel could result. The realtime preemption patches
introduce a new mutual exclusion type (the rt_mutex) which does not
spin, and, thus, will not stall a processor. The spinlocks and
semaphores currently used in the kernel are all converted over to the
new rt_mutex type, and all code which runs with spinlocks held becomes
preemptible. The rt_mutex type also implements priority inheritance,
so that a low-priority process will not block a higher-priority
process (for long, at least) by losing the processor while holding an
important lock.
- Threaded interrupt handlers. Interrupt handlers can create latencies
by monopolizing the processor for long periods of time. The realtime
preemption patch moves interrupt handling into kernel threads, which
contend for the processor with all other processes in the system. If
a certain realtime task is more important than interrupt handling, its
priority can be set accordingly.
- Various other mutual exclusion mechanisms, including read-copy-update, per-CPU variables, and seqlocks, require that preemption be disabled. All of these mechanisms are changed for the realtime preemption mode, usually by making them look more like regular spinlocks.
The realtime preemption patch set (at version -RT-2.6.12-rc5-V0.7.47-10 as of this writing) is clearly large and intrusive - it would be hard to make fundamental changes like those listed above any other way. It should be noted that Ingo has gone out of his way to minimize this intrusiveness, however: the patch is written to minimize code changes, and the kernel functions as always if realtime preemption is not selected at configuration time. The merging of this patch set would not force the new preemption model on users.
According to Lee Revell, the realtime preemption patches are already seeing some serious use:
Certainly the discussions that inevitably follow the release of a new version of the patch set indicate that there is an active user community out there. Some members of the community are starting to wonder why the realtime preemption patches have not been merged, and when (if ever) that might change. The biggest reason is that Ingo has not yet requested that the patches be included - though many small pieces and fixes from the realtime patch set have found their way into the mainline. If and when Ingo does push for inclusion, however, there will be some opposition.
To some developers, the realtime patch seems like a set of questionable and widespread changes aimed at the needs of a very small user community. Changing spinlocks into mutexes and moving interrupt handlers into threads are fundamental changes to how the kernel does things with the potential for the creation of subtle bugs and performance problems. Reworking things and adding complexity at that level is not a task that should be undertaken without a strong need - and many developers do not see a sufficiently strong need.
There are some concerns about the performance impact of these changes. Acquiring an uncontended spinlock is a very fast operation; the rt_mutex type, with its wait queues and priority inheritance mechanisms, is bound to be slower. There is some anecdotal evidence that there is a performance hit to realtime preemption, but little in the way of real benchmarking has been done. In any case, the performance penalty should only affect users who have actually enabled the realtime preemption mode.
Finally, not everybody is convinced that the realtime preemption approach can solve the real problem: providing an ironclad guarantee that a realtime process will be scheduled within a given maximum latency. Ingo believes that this guarantee can be made by eliminating all code within the kernel which can delay a reschedule; others feel that, to make a guarantee that can truly be trusted, the entire kernel must be audited and verified. They have a point: how strong a guarantee would you want before running realtime Linux in your car's braking system?
Those who want true realtime guarantees, along with developers who simply do not want to clutter the kernel with realtime mechanisms, argue that a different approach should be taken. The most commonly suggested alternative is RTAI-Fusion, which works (at its core) by interposing a "nanokernel" between Linux and the bare hardware. The nanokernel guarantees latency by taking the lowest-level scheduling decisions out of the Linux kernel's hands; it is kept small and easy to verify. Another project taking a similar approach is Iguana, which is based on the L4 microkernel.
Since the realtime preemption patch is not being proposed for merging at this time, no decisions are likely to result from the current, lengthy discussion. If Ingo has his way, there may never be one big decision; instead, pieces of the patch will be merged if and when it makes sense.
There may be some interesting realtime-related sessions at next month's
Kernel Summit in Ottawa, however. Meanwhile, should anybody wish to plow
through the entire thread on linux-kernel, here is the starting point.
Index entries for this article | |
---|---|
Kernel | Latency |
Kernel | Preemption |
Kernel | Realtime |
Posted Jun 2, 2005 3:30 UTC (Thu)
by bronson (subscriber, #4806)
[Link] (1 responses)
Posted Jun 2, 2005 7:16 UTC (Thu)
by xoddam (subscriber, #2322)
[Link]
Posted Jun 2, 2005 6:46 UTC (Thu)
by aleXXX (subscriber, #2742)
[Link] (1 responses)
Posted Jun 2, 2005 9:32 UTC (Thu)
by simlo (guest, #10866)
[Link]
Some day, someone will hopefully post a comparison between PREEMPT_RT and RTAI, wrt. how well it works wrt. latencies and performance, and how much work you need to put in to actually use it on _real_ projects.
Posted Jun 2, 2005 15:45 UTC (Thu)
by wa1hco (subscriber, #3628)
[Link]
The nanokernel debate reminds me of the old RISC vs CISC debate. RISC attempted to use simplification to enable faster execution, but then the CISC people (Intel, et al) proved that with some effort, CISC can run as fast or faster than RISC. RISC really only offered a way to do fast _low budget_ cpu's
Nanokernel advocates seem to make a similar argument. They have a low budget (less complex) way to get real time. If the analogy holds, Ingo's patch will, with some extra effort, provide a way to address realtime requirements with as good or better performance.
Posted Jun 3, 2005 6:58 UTC (Fri)
by jwb (guest, #15467)
[Link] (1 responses)
I wish the audio people would solve the problem differently. They should be able to pin their
Now I'm not suggesting that the majority should rule, but Linux has normally been able to
Posted Jun 3, 2005 7:43 UTC (Fri)
by set (guest, #4788)
[Link]
Actually, the issue I would rather have seen presented here would be about
And no one even mentioned the patent fud;)
Posted Jun 10, 2005 0:59 UTC (Fri)
by huaz (guest, #10168)
[Link] (1 responses)
Posted Jul 21, 2005 10:22 UTC (Thu)
by mingo (guest, #31122)
[Link]
No Git news this week? Git Traffic appears to have died the day it was created.Whatabout Git?
Git was born small and almost perfectly formed. Current development is a It's just sugar...
matter of "sweeten to taste".
I really think RTAI (or the L4 stuff) are a better alternative, or at The beginning of the realtime preemption debate
least they can provide a way to provide "real" realtime together with
linux. What's actually the current state of RTAI with kernel 2.6 ? Which
architectures are supported ?
Alex
Oh no! Don't start that discussion here as well! It is really long and heated on lkml already! I will dear to add that I disagree, but I will refer to lkml for the arguments. The beginning of the realtime preemption debate
Realtime discussions devolve into endless debates _because_ each party defines their interests differently: Soft realtime, Hard realtime, Provable realtime, desktop use, audio use, braking use, aircraft use, etc. etc. For a more productive conversation, we need to develop consistent terminology and recognize the value of other applications.Talking past each other...
What's with the car brakes argument? I could probably implement a braking system in 100 lines on The beginning of the realtime preemption debate
an AVR. I'm not sure why I'd use a microprocessor and millions of lines of kernel code.
processes exclusively on one or more CPUs, leaving the rest of the lower-priority tasks fighting over
the remaining CPU or CPUs. This might even be possible with the scheduling domains patch. I'm
worried that the people who want XMMS to not skip when they mkfs a 2TB device while playing
Quake are going to screw up the kernel for other users. Linux has a history of making basic
operations like syscall, i/o, schedule, and fork cheaper with each release. The RT work tends to
make basic operations more expensive, which isn't going to put a smile on the face of your local
mail server sysadmin. I'm going to go way out on a limb and guess that there are at least 1000
network server instances for every instance of Linux in audio performance roles.
accomodate weird use cases without compromising the mainstream. And that's what I'm hoping
shakes out of the RT debate.
The 'audio people' are not driven by xmms playback issues, although theThe beginning of the realtime preemption debate
general userbase would benifit from their concerns. They want to be able
to record live sessions and do live performances without drop outs or
clicks, which are show stoppers. This extends to live effects processing
and multimedia capture of all sorts. And the RT patch is completely
optional. It should have zero effect if you dont config it. The debate
is not about how this patch would affect the majority, but if it is the
best solution for a broad range of problems, which, if you read the
ungodly long thread on lkml, seems to have goosed a number of parties,
armchair and otherwise.
the argument about what exactly 'real time' means. For example, some backers of the RT patch are saying it is better than RTOS's they are using
in their industry, and that it is potentially earthshaking. The adjective
'hard' when combined with 'real time' seems to be where the semantics
get difficult.
Kernel preemption itself is not a guarantee of hard real time. What about priority inheritance? Is is addressed in the RT patches?The beginning of the realtime preemption debate
yes, priority inheritance is part of the PREEMPT_RT patchset.The beginning of the realtime preemption debate