Preemptible Linux Kernel: Interviews and Info
An anonymous submitter sends: "MontaVista and Robert Love are developing a patch for the Linux kernel to make it fully preemptible. Lots of users are involved, and tests show huge reductions in latency. Robert's kernel patches are here. Finally, an interview with Robert, on preemption and more."
The reductions in latency -- would that include the type of latency that plagues real-time audio applications like sound-on-sound recording?
We're sorry, but tonight's "Linux" will not be aired. Normally you would find 2.4.12 or 2.4.13-pre2 on Sunday nights, but not this evening. Now that Linux is fully preemptible, NBC will be airing a four-hour music-and-ice-skating tribute to Bill Gates.
We apologize for any inconvenience, and for the reduced uptime. Enjoy the show.
You'd think this would have been one of the first few 'features' of the Linux core. If the latency were high, it would screw programs and things that rely on low latencies to compute. Better late than never.
Job? I don't have time to get a job! Who will sit around and bitch about being broke and unemployed then?
I'm wondering about this paragraph:
Can anyone give a nice layman's description of what he's talking about here?
"You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
JA: What tips and inspiration can you offer aspiring kernel hackers?
Robert Love: Read the source, play with the source, and bathe regularly.
All computer science labs should have available eye-wash style emergency showers.
Troll Like a Champion Today
Can someone fill me in... Hasn't Microsoft been claiming windows has been preemptive since win95??? Is this some other form of 'preemptiveness'?
What is this 'preemptive' thing refering to? Task scheduling?
---
Programming is like sex... Make one mistake and support it the rest of your life.
I think this is a good short-term solution for the latency problems but I personally wouldn't include it in the main kernel releases. I believe that it *might* be a good idea to fork the kernel releases (temorarily) in two groups: One for servers and one for workstations until the problems have been solved. ;-)). We still need a larger user base...
I think that (for now) using this patch on workstations is a pretty good idea. And I think that there should be a better solution for the problem witch should THEN be something along the lines of kernel 3.0
I am not a kernel developer or anything, but I am currently reading up on the source and the mailing lists.
Basically all I am trying to say is: Make it work NOW and solve the real problem later. Just make sure that is WILL be solved... (no microsoft coding ways here
Fighting for peace is like fucking for virginity
So long as the console driver and the keyboard driver are alive, root should always be able to open a new shell and kill an offending process that is hanging the rest of the system. Right now, this is too frequently a non-option.
I am not a lawyer. Do not take my words as legal advice. If you need legal advice, consult an attorney.
I thought giving the Kernel the ability to preemt other programs was important. If you give programs the ability to preempt the kernel, doesn't that just change the system back to cooperative multi-tasking? I could just see programmers abusing the ability to preempt the kernel to squeeze a little more speed out of their app.
If you're wondering what the heck a preemptive kernel entails, then here's some background.
Also, if you don't like Robert Love's implementation, then Andrew Morton maintains a patch with a similar low-latency goal.
- Linux Devices Article detailed, very nice, on this issue from Sept 6
- Kernel Hacking How-to Page on this again, very detailed.
- The Kernel SpinLock metering FAQ
All around useful stuff, enough to get you started destro^H^H^H^H^H^H hacking your own kernel"It is a greater offense to steal men's labor, than their clothes"
I don't want to sound like I'm contradicting you, but did you happen to read this link from the article? It's specifically about realtime audio. Key paragraph:
*EXCITING* NEWS: things getting almost perfect ! Ingo's lowlatency-2.2.10-N6 patch with the shm.c part backed out and a modification of filemap.c (thanks to Roger Larsson) performs _REALLY_ well, using my usual latencytest parameters (4.3ms buffer), I got NO DROP-OUTS anymore, with sporadic maximum peaks of ONLY 2.9ms This is really exciting because it opens the doors to a whole new class of Realtime applications for Linux, simply using userspace processes scheduled SCHED_FIFO. I heard of comparable low-latencies only from BEOS, Windows can't simply guarantee these kind of latencies, not even using DirectX. Using a soft-synth on Win98 on my BOX I must use 15-20ms audio buffers to get _SOMEWHAT_ reliable audio. This is actually about more than 3-4times the buffer I used for testing under Linux ( 4.35ms).
I don't know much about the field, but the page seems to speak to several of the audio-related concerns mentioned above.
Kill, Tux, kill!
The left hand (processor 0) needs to know what the right hand (processor 1) is doing.
:)
Reverse if necessary.
Ambidexterous people...just HUSH!
Heh, how about that, computers do have a real life (tm) frame of referrence.
Moose.
Have you read the moderator guidelines? Well, have you, PUNK? (and I want a Karma: Gnarly option)
Linux is fully preemptible, and has always been. This is about being preemptible while executing in the kernel. I have no idea if OSX allows this or not - it's BSD based, so probably no, but then Mach is involved someway or other, so maybe. It would be interesting to know.
/Janne
Trust the Computer. The Computer is your friend.
Ummm,
Sorry, just want to note that mutex and semaphore programming is not all that difficult if you do it much. True windows have a few kinks, but the concept is pretty basic. Basically I would have to disagree that mutex and thread programming makes programming hard. It's just programming once you understand it, it's pretty straight forward.
As for the windows problem use startthreadx instead of startthread (Yeah probably not the real api functions, but close enough haven't worked on windows for a while.)
Lando
/* TODO: Spawn child process, interest child in technology, have child write a new sig */
I hope that Linus will look at whether these patches hurt the normal case. "normal" means things like kernel compilation, not just an arbitrary latency measure and dbench (one of the least realistic benchmarks possible!)
there are good reasons to be skeptical of all-out premptiveness: it will unavoidably lower throughput in easy-to-define cases. any intro OS text will talk about optimal scheduling, where 'optimal' requires a definition of throughput or some other metric. preemptive kernels will context switch more, and will probably interfere with the natural 'batching' that happens when a big job runs for a while. think about caches: you never want to switch unless you must. this is not an argument against low-latency! it's an arguement against lowest latency as an absolute; we need to set a target (5ms would be fine imo) and meet it. going beyond such a goal will hurt the normal case.
Whether this patch is added or not is surely just a question of whether it is stable enough or not.
As it says in the interview, the enablement of the patch is an option in the config... For those that want it (i.e. most desktop users I would expect) it's there. For those that don't, it can be disabled.
It seems that the patch works, as scientifically explored by his benchmarks. If there is a fault in the patch, I'm sure that half of slashdot will email the chap.
In summary, it works, is probably stable and can be enabled/disabled in config if needed. It already does, and probably can, benefit lots of people.
Put it in!
(At worst it can be removed and a new kernel released the day after... hehe)
-- Mike
http://www.linuxdevices.com/articles/AT4185744181. html
Goofed that up.
Nice discussion, from Sept 6, with related links
[sigh]
"It is a greater offense to steal men's labor, than their clothes"
Really? That's the first time I hear about that.
;-)
There is a difference between pre-emptive multitasking and pre-emptible kernel.
Pre-emptive multitasking means that the kernel can interrupt any thread and give control to another thread, so that a thread cannot hog the CPU resources. This is what all modern operating systems do, except Windows 3.1/9x/Me and MacOS (pre- X), though it could be argued that Windows 3.1/9x/Me is not an operating system much less a modern one
Pre-emptible kernel is a different beast. It means that the kernel can interrupt itself (i.e. a thread running in the kernel mode) and give control to another thread running in the kernel mode. This is used in real-time operating systems where you need to have a guaranteed maximum response time (i.e. a thread must not wait longer than a certain amount of time before it gets control). However, this is not all that useful for general-purpose OSes and may even be detrimental to servers, where throughput matter more than response time. So it's good to know that this will be a compile-time option.
___
If you think big enough, you'll never have to do it.
Linus himself said, that they should rather fix the CAUSE of those latencies instead of the symptoms.
Isn't that like saying that you'd rather fix all buggy applications instead of providing a protected memory environment?
BeOS programming really isn't that hard. You just have to get used to the idea of locking every single thing that could possibly be shared.
A deep unwavering belief is a sure sign you're missing something...
The extremely high-resolution threading of the operating system made even the simplest programming tasks near impossible, as mutex locks and thread conditionals needed to be spread throughout the code to ensure proper execution.
Right on! I ran BeOs under VmWare to try developing for it, and the pthreads compatibility was... well let's just be polite and say "extremely non-optimal". The spin locks in the kernel were so tightly placed that any possible race condition you could think of would occur if you didn't mutex lock the hell out of it, and the littany of devices you had to lock to access memory was just unbelievable. I pretty much had to read through the video driver code to get anything done as the documentation got as far as "Hello World" before wishing you luck.
Anyway, DeMuDi looks to be a step in the right direction - maybe if a Linux distro starts shipping with 2 kernels, a standard kernel and a multi-media enhanced kernel, we'll finally have a workable solution.
"Professional audio processing requires an extremely special form of real-time processing that is pretty much only good for handling audio, and which actually can cause problems with any other types of software."
Special in what way? I'm not really familiar with audio software but I have a hard time picturing what you mean by "special" real-time.
You say that in Windows software handles it's own scheduling and bypasses the kernel. What exactly does that buy you that you couldn't get more elegantly in Linux by creating a kernel patch (A premptable kernel patch for example). The windows way strikes me as not very stable, flexible or good.
Linux let's your program hog the cpu already by setting nice levels. With preemption even if it gives the cpu to a different process it can take it back right away.
The Linux way seems better exactly because it's not a special purpose hack. Why is hogging the cpu for audio processing any different than hogging the cpu for video processing?
True, also, you can always chicken out and use big global locks if you need something quick.
A deep unwavering belief is a sure sign you're missing something...
Tried this patch before... it works great adds a nice option in the kernel config. But the problem is pcmcia-cs doesn't work with it. Says in the changelog it will be fixed on the next release of pcmcia-cs but I want it now!
It does work nicely... everything is a lot more responsive.
Great work!
After messing with it on several machines, here is what I have found.
* it doesn't work well on a shell server or anything which might have alot of disk activity. The changes seem to do everything at the expense of disk IO and network IO. I do see better speed on interactive stuff though. Its not worth the hit in IO.
* there is no option to turn it off while in operation. Means you have to run different kernels if you want to do some things with the preempt, and other stuff without.
Brielle
No, I thinks its more like Linux is saying he would rather make Linux faster, than make it feel faster.
This is why BeOS ultimately flopped: it was too hard to program for.
True, but in a very different way. The lack of decent developer support, for a platform running on hardware most people use windows on, aimed at the market that people buy macs for, compatible with less actual hardware than either, with no software from vendors anyone had ever heard of, is why it flopped.
I liked BeOS too. I ultimately wiped it off my system because I just didn't have a use for it.
I've finally had it: until slashdot gets article moderation, I am not coming back.
yeah the one I tried was with 2.4.10 didn't work. my card's driver isn't included with the kernel so I have to compile the pcmcia driver that comes with the pcmcia-cs package (why IS there 2 different drivers?). I checked the changelog on the pre-emptive kernel page and it mentions that they are pressing the maintainers to fix the code for pcmcia-cs for the next release which I hope is soon.
Anywhere that BeOS highlighted your race condition by causing unwanted behaviour is somewhere that you'd get "random" crash bugs from in another OS if you didn't fix the code.
Other OSes don't guarantee much about how long your timeslice is, or how often you'll get time, it's sort of haphazard. That randomness means that while those race conditions don't manifest as much, they're still there to bite you.
Think of it like memory leaks and dangling pointers. Ninety-nine times you can use an element of a linked list after delinking it, one time it will have already been written over. But you don't want to somehow make the bug come up one in a thousand times... you want it to come up EVERY time so that you fix the problem before release.
It might be a bit of a pain to put locks around everything, but after a while it becomes quick and natural and you still have the power of a fast kernel with a very small timeslice for when you need it.
Those locks you're leaving out of your non-BeOS code might make it easier to code, but they mean it'll crash at random years later when some odd combination of load variables causes your program to be yanked out of a critical area before completion and lets the next thread enter too soon. But you'll have run it for months, seen no problems, and shipped it.
You *need* to lock everything that might ever be an issue, even if it's the tiniest operation. That's why there's a "Test & Set" operation in ASM. It might be the tiniest thing, but you need to guarantee it's atomic.
I wish more OSes were hard in the way you describe - if race conditions were more easily shaken out they wouldn't plague "release caliber" software.
And as to BeOS being hard to program for... What?!? It might have enforced better style which could be a pain at first, but it was (is still, I guess) a wonderful OS for programmers.
The desktop end-user *is* a real-time application
I can't speak to whether or not OS X is kernel preemptible either, but I assume when Apple talks of "fully preemptible" they are just drawing a contrast with the cooperative multitasking that MacOS has had since day one.
- jon
Ganymede, a GPL'ed metadirectory for UNIX
The pre-emptible kernel patches radically rework the way the kernel functions. So people are being cautious.
I was surprised he said this. This isn't a big scary kludge that inserts a bunch of hacks all over the place in the kernel; this is a relatively small patch that simply leverages all the SMP work. It won't make the kernel uglier or harder to maintain, so IMHO it is very worth adding.
I am confident that Linus will get that prodding from the real world he is waiting for, because my own experiences with this patch are overwhelmingly positive. I'm using kernel 2.4.10 with the preemption patch on my desktop Linux boxes, and I love the snappy feel it gives my system. Playing back MP3 music never skips now, and my K6-III/450 system pops up web pages in Galeon so fast it feels like an Athlon system.
Kudos to Robert Love and anyone else who worked on this patch.
steveha
lf(1): it's like ls(1) but sorts filenames by extension, tersely
Win 9x/ME *does* have pre-emptive multitasking. However, it doesn't have very effective memory protection which is why it's rather prone to being crashed by errant programs. I believe this was to ensure compatibility with 16bit apps left over from Win 3.1
And are you a Linux user? If so PLEASE go and get demudi up and running on that box and see what latencies you get there for comparable tasks and then come back and tell us! Demudi is spawned from the Hammerfall's ability to offer (Semi-)Professional audio capabilities to Linux. I have a Hammerfall about 5 metres from me at the moment, but it's not mine and I would be beaten severly if I touched it :-(
Never underestimate the dark side of the Source
I don't know how this might manifest itself, but I could see how some existing, highly tuned programs could have problems with such a patch. If software is developed with the current mainstream kernel in mind, it may make certain internal assumptions about not being preempted during certain operations, and some timing getting messed up because of that. One poster mentioned a potential VMware problem, which could be an effect of something like this.
I would like to see this patch in there, but I could see some reasons to be hesitant about putting it in now. I would love to see latency on the level of QNX, that seems very responsev..
XML is like violence. If it doesn't solve the problem, use more.
HZ is already 1024 on architectures such as Alpha and IA64. You have the source. Change it before you build; it's only a 2 byte change.