Non-Deathmatch: Preempt v. Low-Latency Patch 178
LiquidPC writes: "In this whitepaper on Linux Scheduler Latency, Clark Williams of Red Hat compares the performance of two popular ways to improve kernel Linux preemption latency -- the preemption patch pioneered by MontaVista and the low-latency patch pioneered by Ingo Molnar -- and discovers that the best approach might be a combination of both."
co-op! (Score:2, Funny)
Re:co-op! (Score:1)
Uhh, that was either a joke or a troll. Either way you got caught!
.
Re:co-op! (Score:2, Insightful)
Re:co-op! (Score:1)
The diffference between preemption/coop is very much like the difference between using threads and blocking I/O (i.e. On a general purpose system, the cost of preemption is masked by a) the high speeds of today's processors, and b) the fact that although preemption is locally suboptimal, it yields better results globally. Still, for precisely circumscribed domains, coop will deliver better performance.
Re:co-op! (Score:1)
Re:co-op! (Score:2)
The list goes on...
Actually co-op is useful in porting... (Score:1)
<karma hoard>
This is quite a good thing when doing ports, e.g. Wux applications from Unix to Windows PDF here [dmst.aueb.gr]. Particularly insightful is "Chapter 3.2.2 Operating Systems Differences". This document can also serve as Unix to Windows porting 101. I wonder if the Win 3.1 stuff they are talking about is still valid in the non-MSDOS WinME,NT,2000,XP ?
</karma hoard>
The Linux kernel preemption project (Score:5, Informative)
comprehensive guide to Linux Latency.
Re:The Linux kernel preemption project (Score:1, Interesting)
Pretty shameful for
Re:The Right Reasons (Score:2)
However, it's debatable if this is a good thing. Providing transactions is good, but why write an SQL interface for the whole file system? And then have to massage files into specific data types, or a whole bunch of BLOBs which you can't perform any complex operations on...
If MS does come out with this filesystem, they won't make it a default. It'd rock for some uses and suck for others. Much like NTFS.
Re:The Right Reasons (Score:1)
THis have however been done b4 as already stated, with various results. BeOS used to have it but they dumped it in order for a more normal fs...
Mind you, if one is attracted to buzzwords this is probably the way to go.
Re:The Right Reasons (Score:1)
(Even with the "trial" version of Beos r5 you can still setup and install it onto a native partition, btw.)
Re:Wow!, what an insightful conclusion. (Score:2, Informative)
Clark Williams did a lot of work to prove that the assumptions you would have when looking at combining the two patches hold.
Re:Wow!, what an insightful conclusion. (Score:2, Informative)
Alan has suggested I include both patches into the next 2.5 release (though there is quite a lot going on there so it may not make it in until the next one after that) and it will be fun to see the effects on latency and throughput, especially with the new I/O subsystem, in widespread use on various architectures; Clark Williams only compared the patches on single processor machines for example, where we have to pay special attention to the various SMP archtectures out there.
But remember! Linux is not a RTOS and I have no intention of making it one, although there are forked kernels that do exactly that.
More serious player in the shadows (Score:3, Interesting)
Oooooh (Score:4, Funny)
Re:Oooooh (Score:1)
Nah. I'll just wait for Taco to post the definitive answer once the debate is over..
.
Re:Oooooh (Score:1)
Re:Oooooh (Score:3, Funny)
Works very well here (Score:1)
I've found SMP on Linux to work very well. There are definitely no delays on my dual cpu workstation and dual cpu server. I've even done some extensive bvenchmarks which show that Linux scales very well. At least compared to NT4/W2K where the results were dreadful.
I'm sorry that I can't offer any help but I hope you find where the problem is.
O(1) already integrated... (Score:2, Informative)
Ingo Molnar's O(1) scheduler was integrated
into the development tree back around Linux 2.5.4
So it's already in there.
Preemption was integrated about the same time.
Re:SMP Scheduling Latency... (Score:1)
2.5 merged it around 2.5.4 (IIRC)
One good way to reduce kernel latency.. (Score:5, Interesting)
One thing not mentioned so far is that one of THE largest scheduler latency problems comes from the driver for a PS/2 mouse, a very common item to be found plugged into servers which have no need for it. By removing the PS/2 mouse (and driver..) a significant latency improvement can be gained!
It's a pity that most USB mice don't seem to provide quite the quality of use as the PS/2 items (although this is probably also a driver issue)
Loy latency can be an advantage, but it is important that the cost of the lower latency is not an increase in total load, as in reality the lower latency does not provide a large gain in performance for most desktop or server roles, but rather is a measure more often used in real time systems, which it can make the difference between a system working or not.
An example of this is in an ignition ECU for a V12 engine at 6000 RPM, a (pair of) plug is firing every 1/600th of a sceond (1.66ms), but the accuracy of the firing even must be in the order of 10us, which is not yet reachable be any 'standard' unix kernel, but quite easy to get on a much simpler ECU (I use an SH-2 at 24 MHz) than you would notmally find using a true real-time kernel.
With some developments is may be possibly for a form of linux to reach this level, which would be fantastic, as a LOT of time is spent in embedded development providing 'operating system' level functionality around the actual application code, and with embedded processors getting faster, and memory getting cheap, embedding *nix has become much more of a possibility.
Re:One good way to reduce kernel latency.. (Score:4, Funny)
Honestly, I'm not trying to troll you here, but why would you WANT to run a *nix kernel on hardware that's responsible for engine timing? Especially when you apparently already have tech that works. Is the idea just to make vehicles that much harder for people to maintain? The day my mechanic keeps a sysadmin on duty so he patch my buggy Linux 4.5.3 ECU is the day I put a gun to my head and pull the trigger.
Aside from that. Way to inform the masses.
Re:One good way to reduce kernel latency.. (Score:2, Funny)
Re:One good way to reduce kernel latency.. (Score:2)
Do you really think that companies doing their own proprietary kernels come up with something more reliable? For the most part, they don't -- but once a deeply embedded system is out the door, the rule is that it'll Just Work the way it did in the lab, because for that embedded system nothing (the hardware, the software, the input, the output, whatever) ever changes from what it was designed and tested on -- or if it does, you've got bigger problems.
That's less true for less deeply embedded systems... but those are where something like Linux is even more appropriate.
Re:One good way to reduce kernel latency.. (Score:2, Funny)
If you use an early development kernel in a production engine, you deserve what you get.
Re:One good way to reduce kernel latency.. (Score:2)
Of course, you'd presumably get a higher load, since you're doing your task in less time, which means that the processor is busy more of the time.
Additionally, latency is important for interactive tasks on desktop machines, because it determines how responsive the system feels under load. The user's experience is determined more by how quickly the system responds to simple requests (moving the mouse cursor, drawing menus, etc) than by the milliseconds place on more complex tasks. Furthermore, the user will instantly notice if sound or video is not handled on time.
Re:One good way to reduce kernel latency.. (Score:2)
I personally haven't been able to tell between the pre-empt kernel and traditional, they both give the same 'feel' on the desktop level.
Re:One good way to reduce kernel latency.. (Score:2)
Under high loads, when playing audio, the difference can be quite remarkable.
I'd be curious to know under what kinds of loads the tests documented here were run.
Re:One good way to reduce kernel latency.. (Score:2)
In any event, low latency is good, and my entire point is irrelevant except as a nitpick.
Re:One good way to reduce kernel latency.. (Score:1)
If your target is professional video, the customer will scream loudly if even a single frame is dropped (and they will check), or if any fields are reversed, etc.
Though for these applications, you really need guaranteed real-time performance anyway, for which a RTOS or (possibly) Real-Time Linux is more appropriate. It could also possibly be done with a kernel thread...
Re:One good way to reduce kernel latency.. (Score:2)
I'm not sure exactly how many frame updates you can miss without people noticing, but it's got to be a lot fewer than frames you can blank without anyone noticing, especially if it's not consistent.
Re:One good way to reduce kernel latency.. (Score:2)
Re:One good way to reduce kernel latency.. (Score:2)
Re:One good way to reduce kernel latency.. (Score:1)
Interrupt priorities (Score:4, Funny)
Clearly, most RTOS designers have their priorities backwards.
Mmmm, donuts.
What's up with the degrading performance? (Score:2, Informative)
So after only 12, the low-latency patch degraded by an ungodly amount (1.3 -> 215.2 ms)!! and even the combined patch had a 25% degraded performance(1.2 -> 1.5 ms)!
Embedded systems must have a very high uptime, it's not acceptable to reboot the machine every day to maintain performance. Many embedded systems require a downtime of less than 5 minutes per year. That doesn't give you much time to reboot the machine just for performance issues.
Re:What's up with the degrading performance? (Score:3, Insightful)
The event which caused the 215ms even probably only happens once or twice per day. Perhaps it was some weird code path that the LL patch didn't touch, or some unlikely combination of events occuring "simultaneously"
Re: What's up with the degrading performance? (Score:1)
Re:What's up with the degrading performance? (Score:4, Interesting)
It's called a bug - they'll figure it out.
it's not acceptable to reboot the machine every day to maintain performance
Hey, it worked for NT4 admins, why not for embedded developers? *rimshot*
Sorry. But seriously, anyone looking for hardcore low latency in Linux right now for systems that need that buzzword compliant "five 9's" should probably wait on using Linux until it's READY. Make no mistake, with as much interest and developer hours as are going into it, Linux WILL make it into this market, and it will succeed; it's merely a matter of time. (and hell, at this rate, it may not be long...)
Re:What's up with the degrading performance? (Score:4, Informative)
You're misinterpreting the figures. After a short benchmarking, the worst figure recorded was 1.3ms. After the machine had been left up for 12 hours (thereby allowing there to be much more time for something odd to crop up), the worst figure recorded was 215.2ms. That doesn't mean that the performance had degraded - it means that over the course of those 12 hours, something happened that caused latency to peak at 215.2ms. It might be something that happens once every 12 hours, for instance.
Re:What's up with the degrading performance? (Score:1)
Re:What's up with the degrading performance? (Score:4, Informative)
If you'd actually read the article you'd know that this can't happen with the preempt patch + low-latency, not unless a spinlock gets jammed, then you have much worse problems. The preempt patch takes care of scheduling events that occur during normal kernel execution (and it does this much more reliably than the low latency patch) but since preemption isn't allowed while spinlocks are held, it can't do anything about latency due to spinlocks. This explains the apparently worse performance of the preempt patch - you're just seeing the spinlock latency there.
The low latency patch breaks up the spinlocks with explicit scheduling points, which is pretty much the only approach possible without really major kernel surgery. That's why the combination works so well. In fact, the parts of the low latency patch that aren't connected with breaking up spinlocks aren't doing anything useful and should be omitted. The worst-case performance won't change.
Re:What's up with the degrading performance? (Score:1)
Re:What's up with the degrading performance? (Score:5, Insightful)
Embedded systems must have a very high uptime, it's not acceptable to reboot the machine every day to maintain performance.
True that. Which is why the author of that article made the point that combining the two patches is the best way to go, since he ran the torture test for 15 hours and it didn't go over 1.5 msec even once.
Note that for many purposes, a worst-case latency of 1.5 msec is ample. I don't think there is any version of Windows that goes that low; I don't even think BeOS (legendary for low latency) goes that low. As the author noted, if you are driving a chemical processing factory or something like that, you need hard realtime and you should use something other than Linux kernel 2.4.x!
steveha
Re:What's up with the degrading performance? (Score:1)
On the contrary, testing for embedded systems needs just that, if that's what it takes to find the outliers. We're trying to find the worst case here you know.
Sort of works most of the time, if you don't run any cron jobs, or a similar load, doesn't quite cut it in semi hard real time systems.
Measuring latencies? (Score:3, Interesting)
Re:Measuring latencies? (Score:1)
Custom Redhat RPM's (Score:2)
I'm just lazy.
la... (Score:2, Funny)
A good paper, but... (Score:2)
Re:A good paper, but... (Score:1)
Re:A good paper, but... (Score:1)
The differences between the unpatched kernel and the patched versions than would give an estimate how the patches influence the overall system behaviour.
The CPU-intensive tests are then an indication what influences the patches have on pure OS overhead, while the IO-intensive tests show the (hopefully positive) effects of latency reduction.
A rough and unscientific measurement method, but easy to implement (e.g. just counting the number of times each particular test was run during the test-period). Of course all the tests would influence each other, but that's not in opposition to the heuristic/stochastic test-setup and well in tune with the goal to improve the real-time behavour without changing the overall effiency of linux negatively.
Just a dummies way to measure immeasurable things.
NGPT in 2.4.19-pre3. (Score:1)
So many very good things happen to Linux kernel! I am impressed.
Re:NGPT in 2.4.19-pre3. (Score:1)
This must really piss off the folk who have worked hard on LinuxThreads (the thread support in glibc) over the years! A number of LinuxThreads shortcomings are due to kernel support not being forth coming...
Interesting times ahead...
QNX vs. Linux (Score:1, Informative)
Anyway IMHO to make a real assesment for any 'hard' realtime tasks is much too much effort for most of the readers here. =)
But here are more white papers than you can shake a stick at....
http://www.ece.umd.edu/serts/bib/index.shtml
Re:QNX vs. Linux (Score:2, Interesting)
All times given below are in microseconds (sec).
Processor_______Context____Interrupt Latency
Pentium/133_____1.95_______4.3
Pentium/
486DX4__________6.75______
386/33__________22.6_______15
With nested interrupts, these interrupt latencies represent the worst-case latency for the highest priority interrupt. Interrupt priority is user-definable and the interrupt latency for lower-priority interrupt sources is defined by the user's application-specific interrupt handlers. "
Re:QNX vs. Linux (Score:1)
Thorough evaluations of several RTOS's can be found here [dedicated-systems.com]. Free registration required.
For those that choose not to read the report, the worst-case scheduling latency for QNX is about an order of magnitude better than a preemtive Linux kernel (actually Windows CE 3.0 appears to be considerably more deterministic than Linux too).
More importantly the latency in QNX is deterministic, while the scheduling latency under Linux (IIRC) grows linearly with the number of threads in the system.
Interrupt latency in Windows CE 3.0 (Score:2, Informative)
Re:Interrupt latency in Windows CE 3.0 (Score:1)
There was a fight? (Score:2)
I never realized there was competition between the two. I did hear the low-latency crowd claim that it was lower risk due to its less invasive nature. However, that hardly says anything about the performance of either approach - or that they should be mutually exclusive.
Two wrongs doesn't make a right, and vice-versa (but two Wrights make an airplane).
Re:There was a fight? (Score:1)
In particular Alan Cox (perhaps not coincidentally also the author of the document referenced above) has been hammering on the fact that preemption can break code that needs to consider the timing requirements of the hardware itself; simply put, you do not want code that is busy interfacing with a device to be preempted for possibly long periods of time because the device might not have that kind of patience. So any kind of preemption patch would need to address these issues, and you end up touching lots of files just like the low-latency patch does.
Low-latency and Preemptible on my Notebook (Score:3, Funny)
Re:Low-latency and Preemptible on my Notebook (Score:2)
<plug>
AlsaPlayer comes with a --realtime switch that enabled SCHED_FIFO scheduling for the audio thread, this eliminates skipping for most people, but requires the binary to be run as root (or be suid root)
</plug>
-adnans
(*) scheduling something at a higher prio usually requires running the program suid root, or calling renice(8) as root with the programs pid. A better method is to sudo the nice command for the given user so he/she can nice the app at the start
Re:Low-latency and Preemptible on my Notebook (Score:1)
Re:Low-latency and Preemptible on my Notebook (Score:2)
Re:Low-latency and Preemptible on my Notebook (Score:1)
Your problem likely has little to do with the way the kernel handles CPU scheduling, but rather the interrupts from your hdd controller and soundcard. You might be able to test this to a degree by putting the mp3s into a ramdisk and trying the same operations.
I had exactly the same kind of mp3 skipping problems on my desktop machine for a long time, until a friend introduced me to hdparm, which allows you to set your IDE controller to DMA mode. Try it. The difference is breathtaking. Combine that with 2.4.19-pre2 and preempt and you have a smoooth desktop system :)
I just put the following in a startup script, and everything's highly froody.
hdparm -d 1 -W 1 -u 1 /dev/hda
I don't want to patch kernels arbitrarily anymore! (Score:1)
When I tried a kernel patched by some arbitrary person (i.e., not -ac or -aa, but rather someone appearing just several times a month on lkml) so that it contains all kinds of new things like the new scheduler (which DOES help) and preempt, I found that the system was very stable after two days of desktop use. Then I decided to try `nice -n 30 make -j' PRBoom, and the system is still as responsive as ever. I was happy and posted on Slashdot about how slick it is just after the compilation ended successfully. Wanting to verify my results, I `make clean' and retried. Guess what? Solid lockup without any logs. I hit the reset button and tried the compilation again in console mode with only `top' running. 2 out of 3 times the system locked up solid, Alt-Sysrq just shows messages without doing real things.
I then rebooted and ran the kernel for another two days with constant fear that it may mysterically lock up at any minute. Luckily it didn't, and I then replaced the kernel with a -aa one, without most of the new features, but at least it is rock solid, hasn't crashed since. I think I will add the preempt (or ll) patches only after Marcelo or A.C. or A.A. incorporate it, or when I decide to do some kernel hacking.
So my advice is that try arbitrarily patched (I mean putting patches together by yourself or by someone else who did not test it extensively) kernels only in deep-kernel-hack-mode, just like when you try a kernel in which you modified several lines by yourself. After all, many of us has been spoilt by Linux's stability, and our nerves are not quite prepared for a lock-up when facing a screen with WindowMaker (rather than Win98) on it.
Weighted mid points (Score:1)
Re:Weighted mid points (Score:1)
Worst of both worlds (Score:1, Funny)
Good article, good contribution (Score:4, Informative)
I always think that tests and write-ups like this are a great way that people can contribute to Linux development without having to hack the kernel directly. There's no substitute for a thorough testing to help you improve your designs and theories.
Nice job!
No argument here, move along. (Score:4, Insightful)
Er... while some misinformed folks have in fact been arguing over "which approach is better," both Robert Love [iu.edu] (preemption) and Andrew Morton [iu.edu] (low latency), the authors of the patches, have agreed since before November that a hybrid approach is probably correct, and it seems to me (though I don't speak for them) that they're faintly embarassed [iu.edu] at the number of True Believers who have stepped up to champion one or the other's side in this nondeathmatch. They're attacking different sections of the same problem.
Re:No argument here, move along. (Score:3, Funny)
They are both wrong. The correct solution is to remodulate the preemption and vent the latency through the Bussard collectors.
-
Another article (Score:2, Informative)
applications under Linux, you can read it here if interested:
http://linux.oreillynet.com/pub/a/linux/2000/11
It's more of a hands-on article, tells you how
to do it yourself with Andrew Morton's patches.
My take on the results and the future (Score:5, Informative)
It is not a surprise the low-latency patches scored better, or that the ideal scenario was using both. The preemptive kernel patch is not capable of fixing most of the worst-case latencies. This is because, since we can not preempt while holding a lock, any long durations where locks are held now become our worst-case latencies. We have a tool, preempt-stats [kernel.org], that helps us find these. With the preempt-kernel, however, average case latency is incredibly low. Often measured around 0.5-1.5 ms. Worst-case depends on your workload, and varies under both patches.
Now, the results don't mention average case (which is fine), but keep in mind with preempt-kernel it is much lower. The good thing about these results are that it does indeed show that certain areas have long-held locks and the preempt-kernel does nothing about them. Thus a combination of both gives an excellent average latency while tackling some of the long-held locks. Note it is actually best to use my lock-break [kernel.org] patch in lieu of low-latency in combination of with preempt-kernel, as they are designed and optimal for each other (lock-break is based on Andrew's low-latency).
So what is the future? preempt-kernel is now in 2.5 and, as has been mentioned, Andrew and I are working on the worst-case latencies that still exist. Despite what has been mentioned here, however, we are not going to adopt a low-latency/lock-break explicit schedule and lock-breaking approach. We are going to rewrite algorithms, improve lock semantics, etc. to lower lock-held times. That is the ease and cleanliness of the preemptive kernel approach: no more hackery and such to lower latency in problem areas. Now we can cleanly fix them and voila: preemption takes over and gives us perfect response. I did some lseek cleanup in 2.5 (removed the BKL from generic_file_llseek and pushed the responsibility for locking into the other lseek methods) and this reduced latency during lseek operations -- a good example.
So that is the plan
Re:My take on the results and the future (Score:1)
Re:My take on the results and the future (Score:2, Informative)
The results do mention the average latency. For the vanilla kernel it is 88.3 microseconds. For the low-latency patch it is 54.3 microseconds. For the preemption patch it is 52.9 microseconds. Is 52.9 much lower than 54.3?
How much difference? (Score:2)
Will Ethernet devices, TCP/IP stacks and the lot become more responsive? Will MySQL/PostgreSQL/SapDB/Oracle/DB2/Interbase be able to execute a small query even faster? How much?
Actually, I hope to measure this sometime not too far into the future!
Re:How much difference? (Score:1)
I think the much bigger question is... (Score:2)
I don't think anyone doubts that this is a good approach. But, both patches are still being worked on right now. And while the preempt patch has already been merged with the 2.5 kernel, the low-latency patch is still nowhere to be seen.
I certainly think that this would indeed have a great impact on Linux Multimedia, but not until a company like RedHat or SUSE is willing to include it at least as an optional kernel. The reason is, a vendor doesn't have to support patches until they include it in one of their pre-compiled kernels.
This might not mean much to home users, but a company will not rely on an unsupported feature.
Like it or not, business still drives the industry.
Re:I did better (Score:3, Funny)
Re:Non-deathmatch, eh? (Score:1)
(used to run voodoo3, now I run nvidia geforce)
Re:Non-deathmatch, eh? (Score:1)
Re:Non-deathmatch, eh? (Score:1)
Re:Non-deathmatch, eh? (Score:1)
Re:Non-deathmatch, eh? (Score:2)