Low latency for audio applications
The idea of merging the realtime module appears to have been dropped for now; the opposition was too strong. There are a couple of other approaches which are being worked on, however, to meet the audio developers' needs. In particular, Con Kolivas and Ingo Molnar have been creating patches, and audio hacker Jack O'Quin has been tirelessly testing them out. Two approaches which look like they could solve the problem have emerged from this work.
The approach taken by Con Kolivas is the isochronous scheduler patch. This patch, in its current form, creates two new scheduling classes: SCHED_ISO_RR and SCHED_ISO_FIFO. These classes function much like the realtime scheduling classes in that they provide a higher scheduling priority than any SCHED_NORMAL process enjoys. They differ from the true realtime classes, however, in a couple of ways. No privilege is required to enter one of the isochronous classes, so audio applications need not run as root. The scheduler will also automatically select an isochronous class if an unprivileged application attempts to enter a true realtime class, with the result that many audio applications can use the new classes without modification.
The isochronous classes give high-priority access to the CPU, but only to a point. If isochronous processes use more than an administrator-defined percentage of the processor (70% by default), they get dropped back to the SCHED_NORMAL class for a while. This feature prevents high-priority, unprivileged tasks from taking over the system entirely. This is an important feature - the lack of any such protection was the reason for many of the objections to the realtime security module.
Ingo Molnar's approach, instead, is the creation of a new resource limit (initially called RLIMIT_RT_CPU_RATIO, later changed to RLIMIT_RT_CPU). This limit controls what percentage of the processor's time may be taken by all unprivileged realtime processes. If the limit is in effect, the patch also allows any process to enter the realtime scheduling classes. So the end result is similar to that obtained with Con's patch: unprivileged tasks can get realtime access to the processor, but they are prevented from taking over entirely. The difference is that Ingo's patch is somewhat smaller and simpler, and does not require the introduction of new scheduling classes.
The rlimit-based patch is also interesting in that it allows each process to have a different maximum CPU utilization limit. Imagine a system running a set of audio applications where some have their limit set at 60%, and others at 80%. If 70% of the available processor time is actually being used by realtime tasks, processes with the 60% limit will lose their realtime access, but the 80% processes will not. This scheme, thus, allows a smart supervisor (such as the jack server) to arrange for a (relatively) graceful degradation as contention for the CPU increases.
Jack O'Quin's benchmarking suggests that either patch, in their most recent
forms, has the potential to solve the problem (though the realtime
preemption work may also be required for a complete solution). He appears
to favor Ingo's version, however, and its relative simplicity could well
argue for taking that path. It does not seem that any decisions have been
made, however; it may be that nothing is merged until the 2.6.12 process
starts. It does appear, however, that life is about to get a little easier
for Linux audio users, which is a good thing. It can be worthwhile to be
noisy about your needs, especially if you are willing to put time into
helping in the development of the solution.
Index entries for this article | |
---|---|
Kernel | Latency |
Kernel | Realtime |
Kernel | Scheduler/Latency |
Posted Jan 27, 2005 7:12 UTC (Thu)
by xorbe (guest, #3165)
[Link] (3 responses)
Posted Jan 27, 2005 8:48 UTC (Thu)
by alonso (guest, #2828)
[Link]
Posted Jan 27, 2005 9:54 UTC (Thu)
by gnb (subscriber, #5132)
[Link]
Posted Jan 27, 2005 10:55 UTC (Thu)
by farnz (subscriber, #17727)
[Link]
As a simple example of when this helps; a soft synth is normally a realtime application (MIDI in -> Waveform out). When running, a soft synth doesn't take that much CPU; if it did, it wouldn't work. If your algorithm fails, and causes the synth to run away in an endless loop (bad validation of input MIDI data, for example), you're doomed if it can take 100% CPU. If all your RT tasks are limited to 95% CPU between them, you can fire up "top", notice that the soft synth has gone from around 5% CPU to around 90% CPU, and kill it.
Posted Jan 27, 2005 17:29 UTC (Thu)
by mwalls (guest, #6268)
[Link]
Posted Feb 3, 2005 17:10 UTC (Thu)
by acristianb (guest, #1702)
[Link] (1 responses)
Posted Feb 3, 2005 17:52 UTC (Thu)
by farnz (subscriber, #17727)
[Link]
No matter what the kernel does, if you want more CPU power than is available, you're doomed; all the isosynchronous patches do is limit the available CPU power to less than flat-out, allowing an admin to recover if a realtime process runs away. The solution is the same as in any other realtime system; get a faster processor.
Except that, a musician is not going to be happy when hisLow latency for audio applications
app exceeds "80%" and gets dropped back into the normal
realm of scheduling. How come these people can't just be
fed a kernel that does what they want? It's not rocket
science.
Set the limit at 100%... and be happyLow latency for audio applications
Because you need to say what it is you want. If there isn't enough CPU Low latency for audio applications
to meet all requirements, someone needs to decide on a trade-off and
not all users will want the same things: should the RT apps remain
RT even if this makes all the non-RT ones completely unuseable? Surely
the user should make that decision rather than the kernel? Or, as other
people have more concisely put it, the kernel provides mechanism, not
policy.
It is rocket science; if his app exceeds 100% CPU usage, he's not getting what he wants, and there's nothing a better kernel can do about it. As exceeding 100% CPU is going to lock up his machine, the patch allows a musician to set a limit, and then if his realtime applications are going to lock his machine up, the kernel drops their realtimeness, thus giving a musician a chance of recovering. Without this mechanism, the machine can lock hard, and there's no way to discover why, or to recover.
Low latency for audio applications
Another group that really cares about these patches are the video people (mythtv and relatives). Same problem even greater CPU load issues.Low latency for audio applications
Real time apps need realtime processing. They do not care if that takes 50% or 70% of the CPU. I think the isoschmiso classes are just teasing the apps in that they are promising them CPU bandwith but not realy guaranteeing that. I think a better approach would be to measure what are the needs of a realtime application and compute at application start time if a CPU bandwidth can be guaranteed for it and if not to exit right there with an error message or start NORMAL and notify the user of this.Low latency for audio applications
There is no way for the kernel to accurately gauge the needs of a real-time application. Given a simple enough case, the developers of the application can determine what it needs, and require that users set the cap high enough, but in the general case, this is not possible.
Low latency for audio applications