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."
Cool! I really hope this'll make it into the official kernel, hopefully even 2.4 (though I doubt so not that 2.5 has been started).
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.
Nope. Decent sound-on-sound recording uses pretty large buffers to get around that sort of problem.
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?
Does anyone think that this will ever make it into the kernel? It seems that Linus does not like this because it cures the symptons of latency in the kernel instead of the real problems.
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.
Look at BeOS for an example of why this sort of processing can't possibly fit into a normal-use system. BeOS was constructed especially for the handling of low-latency media such as audio, but as anyone who tried to program it can tell you, it was exceptionally difficult to program anything other than media apps with it! 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. This is why BeOS ultimately flopped: it was too hard to program for.
But, of course, this is an area where Linux could shine. Due to its open-source nature, a special media-processing fork of the kernel could be made for those who need to deal with real-time audio, while the general-purpose kernel remains general-purpose. In fact, DeMuDi Linux is already striving for this goal.
Loneliness is a power that we possess to give or take away forever
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"
Mac OS-X is fully pre-empt already, making it a greatly stable system.
I can only see a fully pre-empted Linux increasing it's already solid stability.
Now if only we could remove co-operative threading from windows....
The One Rule Of Chess You'll Ever Need: Don't play someone who carries a kit in their bookbag.
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)
Is it a Worm, is it a Virus, does it use Outlook?
I couldn't disagree more. BeOS is far from hard to program for. The API's are relatively simple, in fact BeOS is one of the only O/Ses you can read people calling a joy to code for. How much do you even know about it?
That's the idea...
No sig is worth reading.
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 */
OK... I'm confused... this is extrmeley off-topic and I've never touched BeOS (besides failing to install it) so I don't know what I'm talking about.
Are you saying that in a multi-threaded program BeOS was so finely preemptible w/ small time slices that you couldn't be sloppy with resource contention like you can get away with on most UP platforms? I can't see any other way a scheduler would effect a user application.
Or maybe the application framework you used for BeOS applications allowed events to be handled in parallel? Or...?
Brian Macy
Its a Virus.
This is about making the kernel preemptible, which means that a process can be preempted if it's in kernel space (i.e. making a system call) as well as when it's executing normal user code.
Without a preemptible kernel, a process can remain on the cpu during the several milliseconds that a system call can potentially take to return or sleep, even if a higher priority process becomes runnable during that time.
After the MS anthrax attack, I saw Linux geeks dancing and celebrating in the streets on CNN. Fucking assholes. We should bomb them.
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.
http://www.uow.edu.au/~andrewm/linux/schedlat.html
The last time I looked, the Linux process time slice HZ constant was an anemic 100. When will it finally be defaulted to a respectable 1000 so that programs that act on events are more responsive? You can't even make a smooth scrolling ticker on Linux without chewing up all the CPU if the HZ constant is 100 - too slow. I realize that more time will be spect in context switching - so be it - the time is miniscule.
The lower the latencies the smoother your game is likely to be since it's being run at more predictable intervals
>> Really? That's the first time I hear about that.
Well consider yourself informed.
And yes, I do know what the hell I'm talking about. Save the tutorial for someone that will be impressed.
RTLinux is for specialised apps that need guarunteed sub millisecond responce times and is therefore more anal about preemption.
AFIK the preemption patch doesn't come close to RT in guarunteed latency but on the other hand it doesn't incur the speed hit either.
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...
I would just like to add that I'm using an RME Hammerfall on Windows 2000 with 3ms latency. Works fine.
I downloaded linux 2.4.12, unzipped it to make /usr/src/linux, downloaded preempt-kernel-rml-2.4.12-1 and did "patch -p0 preempt-kernel-rml-2.4.12-1.patch" and got tons of errors and warnings from patch along the lines of:
Hunk #1 FAILED at xx.
What am I doing wrong here?
Geoffeg
Except that then there's latencies in the Mach kernel to worry about.
Agreed, a microkernel _should_ have a lot less latency due to its organisation (though I have heard differently about Mach). I really should take a better look at the internal architecture.
/Janne
Trust the Computer. The Computer is your friend.
Also, and this is key, the audio in my test game (Loki's Tribes 2 port) DEFINATELY syncs up better with on-screen action, making me think that this type of patch is an incredible boon for us Linux gamers.
Please Rate my comment (and help support Fre
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?
Don't let the loser bother you. Consider: a person who has nothing better to do with his time than sit on slashdot randomly telling strangers to "get a life" seriously needs to get a life himself. I can't even imagine how sad and pathetic someone's existence must be for that to be the high point of their day. Nobody who really had a life would be doing that, it doesn't make sense. I'm not claiming I have a life, but I haven't sunk that low yet :)
Does anyone who's installed this thing know if you can switch kernel preemption on and off on the fly (through /proc or something)? And if not, how difficult would that be to achieve? Sorry, I'm not a kernel hacker so I have no clue how to find this out from the source.
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...
Mostly correct but Windows 9x/Me had fully pre-emptive multitasking for all Win32 apps.
Where it suffered was memory protection which had to be partially sacrificed to fully support Win16 apps.
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
Excellent work on this. It's a wonder that the a fully preemptive kernel wasn't introduced a long time ago, but I guess it depends on what your view of the purpose of Linux is.
1. Is it a server OS, built to handle a large amount of processing and get it done as fast as possible
or
2. Is it a workstation OS, built with from a user's perspective, with responsiveness and ease of frustration as the most important elements.
If you look at it this way, I guess it is easy to see why the preemptive kernel wasn't brought in before now, because up until only recently, Linux really was thought of as a server OS. But now that it's trying to become more user friendly to the general populace to more easily spread its love, #2 starts eclipsing #1 for attention.
It is a good thing that they are making it a sysem option, because then you can choose which mode is more important for YOU.
+1 Insightful, -1 Troll. What can I say, I'm an Insightful Troll.
He didn't even answer the guy's question.
And anyway, threading never caused a BSOD in Win9x. He's on crack.
___
The ends are ape-chosen, only the means are man's. -- Aldous Huxley
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.
Response from one of the head developers:
/home/brennan Shell: /usr/local/bin/tcsh
/.
[simm0@mercury ~]$ finger brennan@nullsoft.com
[nullsoft.com]
Login: brennan Name: Brennan Underwood
Directory:
On since Sun Oct 14 18:17 (PDT) on ttyp0, idle 1:05, from 64.105.36.233
New mail received Sun Oct 14 19:20 2001 (PDT)
Unread since Sun Oct 14 19:05 2001 (PDT)
Project:
Why, none other than architect and head such-and-such for Winamp 3.0.
Codename Wasabi. Why this fails to get me all the chicks I'll never know.
Plan:
14-Oct-2001
Dear
We ported it to Linux because we *like* Linux. Calm down.
Sincerely,
Brennan
Actually, I would think that this would be overall beneficial to servers. Yah, raw server throughput is important; but so is response time, particularly when a server is heavily loaded. I would think that a pre-emptible kernel would servers to handle more simultaneous users in heavy load cases.... you'd effectively be sacrificing some I/O throughput in light load situations for a guaranteed I/O throughput and responsiveness under heavy loads.
"Great men are not always wise: neither do the aged understand judgement." Job 32:9
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
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
Yeah, this puts the kernel right up there with the Emmys!
Will Joan Rivers be there for the 2.5 rollout?
Kill, Tux, kill!
As shown by the chart from the Real-Time Benchmark Result - available at [ http://kpreempt.sourceforge.net/ ] - we can see that the spinlock problem is preventing the pre-emptive kernel to achieve its true potential.
Therefore, is there ANYONE out there doing anything to solve the spinlock problem?
Muchas Gracias, Señor Edward Snowden !
True reduction of latency will NOT happen as long as the Spinlock problem is still plaguing Linux.
As shown by the chart from the Real-Time Benchmark Result - available at [ http://kpreempt.sourceforge.net/ ] - we can see that the spinlock problem is preventing the pre-emptive kernel to achieve its true potential.
Therefore, is there ANYONE out there doing anything to solve the spinlock problem?
Muchas Gracias, Señor Edward Snowden !
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
...but since on Win9x the GDI is a Win16 DLL you don't get any advantage because you keep running out of resources & anything which crashes GDI brings the whole system down.
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
Using a kernel with this patch to run vmware, I experience long halts in both systems (linux and windows98/vmware). They both freeze for several seconds each, waiting for something. This happens a couple of times every minute. Anybody know what's up?
sig sig sputnik
According to Tanenbaum, the Windows 2000 has a fully pre-emptible kernel.
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.
Uh, so why add it to Linux? Cause Linux is also used in embedded systems? Guess what, SO IS NT! You should also tell Sun how crap pre-emptible kernels are so they fix Solaris.
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.
Considering that BeOS has no pthreads library, I'm not surprised that you weren't impressed with its pthreads compatibility.
And the "littany of devices you had to lock to access memory"... uh, ok. Sure. malloc() and friends must have slipped your mind.
Unless you were working on specialized low-level stuff (you don't say), you're totally blowing smoke and FUD. Doing POSIX programming... no need to worry about threads or locking or anything (well, maybe you'd worry about sockets not being file descriptors). Doing GUI programming, you lock your window when you access it and unlock it when you're done... not a big deal, and not a totally alien concept.
BeOS was by no means perfect, but it certainly wasn't pure hell to program.
*shrug*
- chrish
OS X has been mentioned once -but no one pointed out the following link: http://developer.apple.com/technotes/tn/tn2028.htm l#MacOSXThreading
You have to scroll down to reach the section about kernel threading.