Slashdot Mirror


Preemptible Kernel Patch Accepted

An Anonymous Coward writes: "The preemptible Linux kernel patch that was originally introduced by MontaVista Software and more recently championed by Robert Love has been merged by Linus Torvalds into the main linux development-kernel tree, beginning version v2.5.4-pre6. This adds a far greater degree of real-time responsiveness to the standard Linux kernel, by reducing interrupt latencies while kernel functions are executing. The story at LinuxDevices.com includes comments by Robert Love, and there is also a recent interview with Robert Love about the preemptable kernel here and a whitepaper about the technology by MontaVista here."

27 of 352 comments (clear)

  1. Wow. by 1010011010 · · Score: 5, Insightful

    I thought that the preempt patch was quite a way from being part of the linus tree. On the other hand, early in a development kernel is probably the right place to integrate it, so that all those device drivers with problems with the preempt stuff (like NE2000, I think) can get fixed.

    --
    Napster-to-go says "Fill and refill your compatible MP3 player", which is a lie. It's not MP3. It's WMA with DRM.
  2. Nice work by ekrout · · Score: 5, Informative

    But many folks may have no idea what effect preemptability actually has upon a user who uses GNU/Linux. Here's the good news:

    [] Smoother video
    [] Smoother user interface
    [] A seemingly more responsive computer
    [] Overall smoothness in operation
    (reply to this if you'd like to add to my list)

    Congrats to Linus for getting this ready so soon, and to those who helped develop it.

    EricKrout.com :: A Weblog On Crack

    --

    If you celebrate Xmas, befriend me (538
    1. Re:Nice work by jsse · · Score: 5, Informative

      Aye, it's sure a great news for *cough* gamers. In the past when we'd like to have a smoother 'mouse' we must change the HZ value in include/asm/param.h from 100 to a higher value(progressive increase the value and recompile kernel until it breaks. ^_^)

      Other archs like alpha use values higher than 100 e.g.

      include/asm-alpha/param.h:# define HZ 1024

      include/asm-ia64/param.h:# define HZ 1024

      You may try it if you aren't going to go to 2.5.x in the near future, but hell, if you don't mind twisting and breaking the kernel by altering the HZ value, why not 2.5.x! :D

      Note: I notice that whenever I talk about changing kernel values the post will be modded redundant. I know a lot of you guys know about kernel insdide out so this might bore you - but come on! I'm sure so many other would be interested in it.

    2. Re:Nice work by rhekman · · Score: 5, Informative
      Just to avoid confusion... a few notes about this approach.

      First, for those that didn't get it from the parent post, HZ is a system wide timing value. It has nothing directly to do with the mouse.

      What it does deal with is how many times a second the system's interrupt timer fires. The problem with increasing the interrupt timer frequency is that you waste more time servicing interrupts than doing real work. It may improve interactive "feel" because the timer interrupt will trigger higher priority tasks to be rescheduled more often, but at the price of higher system time and lower "throughput".

      Compared to the preemptible kernel patch, increasing HZ is actually harder on throughput, especially on slower systems. Much work has been done on finding and killing long held locks not covered by the preempt patch (thanks to Andrew Morton and RML), an approach which has been shown to be quite effective. Increasing timer interrupt frequency means you're creating more pointless interrupt load, which goes against the approach and advances of the other low-latency patches.

      There is an interesting discussion of the HZ value and how it effects Linux in a VM at Linux Weekly News and for more arcana check out the high resolution timers project.

      Regards

      --
      I like teamwork. It's easier to assign blame that way.
  3. Tradeoffs? by chuckw · · Score: 4, Interesting

    You don't get anything for free. What is the tradeoff that occurs when you integrate this patch?

    --
    *Condense fact from the vapor of nuance*
    1. Re:Tradeoffs? by megabeck42 · · Score: 5, Informative

      With this patch the kernel becomes preemptible - meaning, other kernel tasks can stop the current one from executing, execute, finish, and allow the stopped tasks to finish.

      Net effect - expensive operations can be suspended for user interactiveness. Can this impact performance, Yes. Noticeably? No.

      If you're running a big-ass server, it's probably head-less, anyways - and you won't have any large, interactive processes preempting the kernel for smoothness.

      If you're running a workstation, this means that X won't bog down as much when you're running those huge simulations, compiles, etc.

      If you're on an embedded device, you can use this to try and get real-time responsiveness. (perhaps not ideal, but, in an embedded situation you have enough control that if you need a better real-time guarantee, you have other options (e.g. rtlinux).)

      If you're on a modest, consumer PC - X won't suck as much.

      All in all, this is a good idea. In theory, you lose some efficiency making several thousand context switches/second, but that's the price you pay for multi-tasking. Yeah, certain kernel operations may take longer, but, you get a better responsiveness, which - for most people, is a good thing. Most interactive individuals are seldomly pegging their processor at 100% utilization for any worthwhile period of time. (Games are an exception.)

      This is good stuff.

      --
      fnord.
    2. Re:Tradeoffs? by sydb · · Score: 5, Insightful

      Aside from the technicalities of this particular patch, your assumption that you're going to lose something when you apply a beneficial patch because 'you don't get anything for free' is, despite appearing mature and clueful, way off mark.

      The cost doesn't have to be borne by the end user. The cost can be developer time / clues. In the Free Software world, you do get that for free.

      --
      Yours Sincerely, Michael.
    3. Re:Tradeoffs? by psamuels · · Score: 5, Insightful
      You don't get anything for free.

      Not quite true - some Linux patches give unilateral improvement. But I do see your point.

      What is the tradeoff that occurs when you integrate this patch?

      None of the other responses to this thread (that I've noticed) addressed one tradeoff: complexity and bugs. Ever since Linux started to support SMP systems, SMP kernels have been somewhat buggier than UP kernels. This is because there are a lot of potential mistakes to be made - getting and releasing spinlocks and semaphores at the right places is not trivial stuff. Of course bugs have been fixed over the past several years, and SMP is now considered a standard Linux feature (in 2.0 it was "experimental"), but there are still no doubt lots of SMP bugs in some of the more obscure device drivers.

      The problem with the preempt patch is that it introduces all these potential bugs into a standard non-SMP kernel, since preempt uses much the same basic mechanism as SMP. Most people only have one CPU, but now these people will be exposed to the same "increased level of risk" as SMP systems.

      In a way, that could be considered a benefit - this may serve to flush out some of those last remaining SMP bugs. The SMP code paths will be exercised by a lot of people now.

      --
      "How can you claim that you are anti-crack, while still writing a window manager?" — Metacity README
    4. Re:Tradeoffs? by Ami+Ganguli · · Score: 5, Informative
      If you're running a big-ass server, it's probably head-less, anyways - and you won't have any large, interactive processes preempting the kernel for smoothness.

      But you will have IO-bound processes coming alive faster once their data is available, often improving throughput. There have been benchmarks floating around that indicate that a lot of typical server workloads benefit from this patch too.

      It appears that this is generally a good thing. The only downside is the added complexity.

      --
      It is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail. - Abraham Maslow
  4. Scalability of a pre-emptible kernal? by Maddog_Delphi97 · · Score: 4, Interesting

    What effect would a pre-emptible kernal have on the scalability of Linux?

    As far as I can tell, a particularly responsive kernal wouldn't scale very well, since there wouldn't any guarantees as how much "time" as being spent on a thread/process by the CPU.

    Think of a large, multi-user environment based on Linux. Do you really want any user to pre-empt the processing in the kernal by CPU to the detriment of other users? A more logical answer to this is to have set guarantees as how much processing time is given to each user. It shouldn't matter if it's one user or 2,000 users, the speed of applications for each user should stay the same as much as possible.

    Maybe I'm describing Solaris, or some other operating system like this.

    1. Re:Scalability of a pre-emptible kernal? by restive · · Score: 4, Insightful

      If you don't like it, treat it the same way as SMP...turn it off!

      The fact that this is built into the kernel means that we don't always have to go out and download patches to change this. I would assume that vendors using the Linux kernel would make decisions on how to compile the kernel to suit their environment.

      There are lots of people that are frustrated by the current need to go and get patches to change this. Incorporating it into the main kernel should be very positive, IMHO.

    2. Re:Scalability of a pre-emptible kernal? by Fjord · · Score: 5, Insightful

      "Do you really want any user to pre-empt the processing in the kernal by CPU to the detriment of other users? A more logical answer to this is to have set guarantees as how much processing time is given to each user."

      Actually, I would think it would be the opposite. Being able to preempt within the kernel can pretect you against a DOS attack where a process repeatedly makes long running kernel calls. That would give that process more than it's fair share of time, and other processes couldn't respond to interrupts as well. Without a fully preemptable kernel, you can't guarantee how long a process can run, because it is impossible to preempt them while they are in a kernel call.

      --
      -no broken link
    3. Re:Scalability of a pre-emptible kernal? by iabervon · · Score: 5, Insightful

      Consider, however, the case where the reason a task is preempted in the kernel is that it has used all of its timeslice. Without the preemptable kernel patch, the task cannot be interrupted to schedule another task. In order to make guarantees about how much time will be given to each process, it needs to be possible to stop a process when its time is up essentially no matter what the process is doing.

      The issues you raise are a matter of scheduling policy, not of whether the kernel is preemptible. Furthermore, for most interactive tasks, the correct behavior is to react quickly, because those tasks haven't used up their timeslices, since they blocked waiting for input. In this case, interactive processes give up the CPU to wait for input, and then get their time back as soon as they have a use for it.

      Of course, this all also applies to tasks which "interact" with the network or the hard drives, which is any task when you have swap space. Processes which are waiting on input want to run as soon as their input is ready, and don't care about time before that. Processes which are not waiting on input want to run as much as possible, and don't care exactly when. Having the scheduler's instructions followed as closely as possible benefits both kinds.

  5. This and O(1) scheduling by Ingo Molnar _rock_ by sydb · · Score: 5, Informative

    Quake 3 has never been smoother on my machine. 2.4.18-pre7 with Robert Love's Pre-emptible Kernel patch and Ingo's O(1) patch. Get it.

    --
    Yours Sincerely, Michael.
    1. Re:This and O(1) scheduling by Ingo Molnar _rock_ by doug363 · · Score: 4, Informative

      The fact that the scheduler is O(1) is largely irrelevant, although that's how it was announced on the Kernel mailing list so that's what it's called. The patch includes rewrites for other critical scheduler functions which improve performance under common conditions, especially interactive performance. In particular, it gives priority boosts for processes that have low average load requirements when they need the CPU.

  6. Re:Doesn't everyone else already do this? by Max+Threshold · · Score: 5, Informative

    Linux user-space processes have always been preemptible. The kernel itself was not. WinNT/2K is fully preemptible (kernel and user); other flavors of Windows are not. Preemptive multi-tasking means that a process can be forced to give up its control of the CPU. This is opposed to cooperative multi-tasking, which means each process must voluntarily give up control before others can proceed. In general, preemptive multi-tasking is a good thing because it means one process cannot hog the CPU.

  7. Other arches? by saintlupus · · Score: 4, Interesting

    Has anyone tried this patch on non-x86 hardware?

    I've got a Powermac 7200 I'm playing with YDL on right now...

    (Note: I am not a programmer. Should this be something patently obvious to anyone with the most casual knowledge of OS programming, I still don't know. So don't flame me.)

    --saint

    1. Re:Other arches? by hysterion · · Score: 5, Informative

      I wondered too (I also have a 7200), and found this answer in the changelog:

      <rml@tech9.net>:
      [PATCH] Re: [PATCH] Preemptible Kernel for 2.5

      On Sat, 2002-02-09...<snip>

      Again, this is a minimal i386-only patch. I have other arches, documentation, etc. Patch against 2.5.4-pre5. Enjoy,

      Robert Love

  8. Can you say "Re-inventing the wheel?" by Mr+Z · · Score: 5, Interesting

    Writing pixels directly to a frame-buffer is slow. You lose all of the acceleration features of your video card. Keeping as much of the protocol at a high level as possible is good. The only things that benefit from direct frame-buffer access are programs that do all their own rendering. (Think video decoders.)

    Still, if you think about it, the basic gist of your idea is to get rid of the network channel from the communication protocol, and instead have the app talk directly to the X server, say, in shared memory. If so, then how does your idea compare to MITSHM and Shared-Memory Transport? Or the Direct Rendering Interface for that matter? And for 2-D stuff, let's not forget the Direct Graphics Architecture extension. Nothing stops GTK, Qt and friends from using any one of these technologies if they'd improve performance and latency.

    --Joe
    1. Re:Can you say "Re-inventing the wheel?" by Junta · · Score: 5, Informative

      Pretty good response, though I would note that even for video decoders writing to a raw framebuffer isn't desired... Writing directly to an allocated overlay in a colorspace natural to the decoding is better (that way, X provides a surface to write to that takes care of both colorspace conversion and scaling in hardware, two *Very* expensive video rendering tasks.). There are very few applications in which direct, unmediated framebuffer access is that beneficial... For example some apps support all sorts of targets from standard Xlib, to XShm, to DGA, to GL. The DGA is probably the closes to direct access, and, no surprise, it isn't that impressive....
      Of course, I think the poster didn't really mean direct framebuffer access, but rather trimming Xlib where possible to not do things that increase latency locally, which, as many have pointed out Xshm does that very thing..

      --
      XML is like violence. If it doesn't solve the problem, use more.
  9. Now for the entropy pool. by augustz · · Score: 5, Informative

    Robert Love has another patch that I'm hoping to see make it into the kernel. For systems in headless situations with large entropy reqs, this is pretty much make or break.

    http://www.kernel.org/pub/linux/kernel/people/rml/ netdev-random/README-netdev-random

    describes what it is all about

  10. [PATCH] To fix compile error on UP systems by worldwideweber · · Score: 5, Informative

    Folks:

    It should be noted that this will lead to a compile error if you enable preemption but disable SMP. To make this build, you need to add this patch:

    diff -urN linux-2.5.4-pre6/include/asm-i386/smplock.h linux/include/asm-i386/smplock.h
    --- linux-2.5.4-pre6/include/asm-i386/smplock.h Sun Feb 10 15:35:55 2002
    +++ linux/include/asm-i386/smplock.h Sun Feb 10 18:15:55 2002
    @@ -15,6 +15,7 @@
    #else
    #ifdef CONFIG_PREEMPT
    #define kernel_locked() preempt_get_count()
    +#define global_irq_holder 0
    #else
    #define kernel_locked() 1
    #endif

    --
    w o r l d w i d e w e b e r
  11. Re:Doesn't everyone else already do this? by Fjord · · Score: 5, Informative

    You are probably thinking of preemtive multitasking. Most modern operating systems use preemtive multitasking, where the kernel enforces when a process gets on the CPU, instead of cooperative multitasking, where a process (in a cooperative way) tells the kernel that it's okay to interrupt it (directly or indirectly) and then kernel makes a decision to give another process the CPU. Cooperative multitasking is bad because a process can decide not to cooperate and effectively take over the system.

    This is a refinement on preemptive multitasking, which linux had before. Before having a preemptive kernel, the kernel could only preempt the process if it wasn't in a kernel call (okay, there are some kernel calls like writes to disk that it can preempt but most it can't). So, if an interrupt happens while my process is in the middle of a kernel call, the process that handles the interrupt will just have to wait until the call is completed.

    With this patch, my process will be preempted for the handling process, allowing it to respond in a very timely fashion. Thus, this is considered to be a prerequisite for real time operating systems.

    According to this Windows NT does have a preemptive kernel, but I doubt 9x/ME do. I'm not even sure that page is right, since I couldn't find any primary sources for this and other pages imply it doesn't (by listing a fully preemptive kernel as a feature under one operative system, but not listing it under windows NT).

    Windows CE definitly has a fully preemptive kernel.

    --
    -no broken link
  12. Maybe you could call it Direct Rendering Interface by lkaos · · Score: 5, Informative

    Oh wait, that name's already taken as it's been a part of XFree86 by default since the 4.0 release!

    Man, people piss me off sometimes... I wish people would actually read something about X before bitching about it on /.

    I don't know why people think X is so horrible. X just destroys Windows as a windowing system. The only plus Windows has it that it has better hardware support. Other than that, X blows Windows away.

    And this got mod'd up to 4... Sheeesh

    --
    int func(int a);
    func((b += 3, b));
  13. Technical Overview by lkaos · · Score: 5, Informative

    Four keys terms to know:

    1) Pre-emptive
    The operating system can interrupt the currently running process to allow another process to run

    2) Co-operative multi-tasking
    A task gives control back to the operating system in order to let more programs run.

    3) User Mode
    On most platforms, an execution state with limited hardware and memory access.

    4) Kernel Mode
    On most platforms, an execution state with direct access to all system resources including page tables and hardware.

    Win3.1 runs entirely in Kernel Mode and uses co-operative multi-tasking.

    Win9x runs entirely in Kernel Mode and uses pre-emptive multi-tasking.

    WinNT based systems (including Win2k) uses pre-emptive multi-tasking and supports both user mode and kernel mode.

    Linux uses pre-emptive multi-tasking and supports both user mode and kernel mode.

    Now, a system that has pre-emptive multi-tasking can either only allow pre-emption to occur in user mode, or in both user mode and kernel mode.

    Theoritically, something should not be in kernel mode for a very long period of time and what's being done in kernel mode tends to be very important.

    So, Linus never really was very concerned about kernel mode pre-emptiveness because it's not terribly useful unless you have a horribly inefficent kernel or you require absolute real-time operations. Instead, he wanted to focus on making sure the kernel was as efficent as possible.

    This patch allows one to enable kernel pre-emption, but be forewarned, that it will only increase the total time spent in kernel mode (doing the necessary checks) and it will not have a noticable effect unless you are running very real-time applications. That is why it's disabled by default.

    It's a good thing to have for a kernel, but it's not very useful for the average user. That's why it's a configuration option. The big performance increase people are referring to is because of the new scheduler... That's a different thread though.

    The fact that WinNT has a pre-emptive kernel is not necessarily a good thing. They are undoubtly taking a performance hit for it and since one can't disable it, there is no way to not have it if one doesn't need it.

    I think Linus made a good decision about letting it into the kernel mainline, but I think he also made a good decision about keeping it as a configuration option and not integrating by default.

    --
    int func(int a);
    func((b += 3, b));
  14. Re:And what about 2.4? by evil_one · · Score: 4, Informative

    On one hand, the preempt patch makes heavy use of SMP spinlocks, and the stability of preempt in parts of the kernel that arn't SMP capable (which are few and far between at this point) and on SMP systems is questionable.
    On the other hand, an awful lot of users have been testing and reporting back to lkml, and Robert Love has been persuing the bugs with the dedication of a first love. I'm sure that scores points with the power(s) that be on LK.

    --
    Desperation is a stinky cologne
  15. Re:Ingo? by mikera · · Score: 4, Informative

    You can have O(f(n)) where f(n) is pretty much any function of n.

    Classifying algorithms this way is *extremely* useful for working out what will give good real-world performance.

    In general, you want to stick to O(1) or O(log n) to have performance that scales in a reasonably effective way.

    Quite a lot of algorithms are O(n) which is OK for small values of n but can get nasty when n becomes large. Inserting a value into a linked list is a typical O(n) algorithm - OK for small lists, bad for long ones as you have to run down the list to find the correct insertion point. (Tchnically you only have to go halfway down the list on average, which would make it O(0.5n), but by convention and for practicality purposes the notation drops and constant factors).

    A large proportion of processor bottlenecks are due to getting stuck in O(n^2) or O(n.log n) tasks. Sorting algorithms tend to fall into this category, which explains why they are often slow and/or processor hungry.

    Higher polynomial orders such as O(n^4) etc are possible, but generally less common. Sometimes writing a sort algorithm really badly will get you into this territory however :-)

    Then there are the *really evil* algorithms that behave like O(2^n) or O(n!). These rapidly become intractable as n grows. Good examples would be the exhastive search of soloutions for the travelling salesman problem, or an exhaustive search of the tree of moves for a game like chess. When faced with this kind of problem, you are basically forced to either limit yourself to small values of n or choose an "approximate" algorithm, such as accepting the best solution found after a timeout period.