# preempt?

## Aries-Belgium

What is PREEMPT? And what does it do?

----------

## i92guboj

Preemptivity, from the kernel menuconfig help:

```

  │ This option reduces the latency of the kernel by making                 │  

  │ all kernel code (that is not executing in a critical section)           │  

  │ preemptible.  This allows reaction to interactive events by             │  

  │ permitting a low priority process to be preempted involuntarily         │  

  │ even if it is in kernel mode executing a system call and would          │  

  │ otherwise not be about to reach a natural preemption point.             │  

  │ This allows applications to run more 'smoothly' even when the           │  

  │ system is under load, at the cost of slighly lower throughput           │  

  │ and a slight runtime overhead to kernel code.   

```

Translated, means that preemptivity makes possible that any uses task interrupts a kernel process when it needs so. This is what make a desktop feels more interactive, by avoidid choppy mouse movements, instantly displaying menus, etc, even if there is a system task that needs to be run and is considered more important.

If you dont use preemptivity then the kernel threads take precedence over any user task. So, if there is something more important to do that to move the mouse pointer, it will be done first, and you will get the choppy mouse effect. Generally, if you are configuring a desktop preemptivity is a good thing, while if you are configuring a critical tasks machine (aka server, for example) then it makes more sense that the trully important tasks take precedence over the rest of the stuff.

----------

## Aries-Belgium

Okay thanks for the explanation.

But I enabled preemt in the kernel and I still have choppy mouse movements when I load OpenOffice for instance. I do have a slow system (550Mhz). So is it possible that preempt already needs a faster system to work on?

----------

## i92guboj

Preemptivity helps a bit, but it is not a miracle. OOo is a huge and monolithical application that sucks up resources as hell, so, the interactivity level of your machine while starting it will depend in some other things as well as in the capability of the kernel to preempt its code. I think that your main problem could be ram memory and hd reads. If the hard disk is not so fast or you havent set on the dma mode for your drive, the huge loads from hd (like the oo one) will suck a lot of cpu resources.

OpenOffice is massive. Usually, when preemptivity is enabled you will notice a smoother performance in general terms, but when the time comes to load such a huge thing there is nothing that can make it smoother, unless you spend some money on ram and cpu or use a lighter office suitte.

----------

## Aries-Belgium

Thanks for the reply.

I'm planning to buy a new computer in a few months, because this slow pc is not suitable for the things I do.

But anyway, now I know what preempting is ... Thanks.

[EDIT]

I still have another question, but it's related to preempt (I think):

When I do:

```
uname -a
```

I get:

```
Linux aries 2.6.14-gentoo #2 PREEMPT Thu Nov 24 03:04:34 CET 2005 i686 AMD-K7(tm) Processor AuthenticAMD GNU/Linux
```

What is the #2 after the kernel version?

----------

## PaulBredbury

 *Aries-Belgium wrote:*   

> But I enabled preemt in the kernel and I still have choppy mouse movements when I load OpenOffice for instance.

 

Got an nvidia geforce video card? These options helped for me in /etc/X11/xorg.conf

```
Section "Module"

#   Load   "xrender"   # For the transparency effects. Disable - nvidia already does it in hardware, to stop mouse flicker.

EndSection

Section "Device"

   Identifier   "Geforce"

   Option       "HWCursor"      "True"

   Option       "CursorShadow"  "True"

EndSection

Section "Extensions"

#   Option       "RENDER"       "True"   # Disable - nvidia already does it in hardware, to stop mouse flicker.

EndSection
```

----------

## Aries-Belgium

 *PaulBredbury wrote:*   

>  *Aries-Belgium wrote:*   But I enabled preemt in the kernel and I still have choppy mouse movements when I load OpenOffice for instance. 
> 
> Got an nvidia geforce video card? These options helped for me in /etc/X11/xorg.conf
> 
> ```
> ...

 

Unfortionally I've got a ATI card. And my mouse cursor doesn't really flicker, it has with chocky movements when loading some applications. But anyway, I think it's time to buy a new system.

Thanks for the tip. I'm going to buy a Nvidea card, so your tip could come in handy ...

----------

## i92guboj

 *Aries-Belgium wrote:*   

> 
> 
> I still have another question, but it's related to preempt (I think):
> 
> When I do:
> ...

 

```

6thpink xarchive-0.2.2-3 # LC_ALL="C" uname -v

#2 PREEMPT Fri Nov 18 02:24:10 CET 2005

6thpink xarchive-0.2.2-3 # LC_ALL="C" uname --help

Usage: uname [OPTION]...

Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order:

  -s, --kernel-name        print the kernel name

  -n, --nodename           print the network node hostname

  -r, --kernel-release     print the kernel release

  -v, --kernel-version     print the kernel version

  -m, --machine            print the machine hardware name

  -p, --processor          print the processor type

  -i, --hardware-platform  print the hardware platform

  -o, --operating-system   print the operating system

      --help     display this help and exit

      --version  output version information and exit

Report bugs to <bug-coreutils@gnu.org>.

```

As you see the #2 is part of the info given by -v. I never looked into that, but I assume that is mean that we are using v2 series of the linux kernel (2.x). So, if im right, this number will be the same for quite some years  :Smile: 

----------

## pv

 *Quote:*   

> I never looked into that, but I assume that is mean that we are using v2 series of the linux kernel (2.x).

 

Sorry, you are wrong. It means the kernel was compiled 2 times after the last 

```
make mrproper
```

 or the last untarring. For example, I have the 2.6.13.4 kernel and #1 because I make mrproper before any compilation of my kernel. I think this deletes dirty files.

----------

## Aries-Belgium

 *pv wrote:*   

>  *Quote:*   I never looked into that, but I assume that is mean that we are using v2 series of the linux kernel (2.x). 
> 
> Sorry, you are wrong. It means the kernel was compiled 2 times after the last 
> 
> ```
> ...

 

Isn't that the same as:

```
make clean
```

?

[EDIT]

WTH!!! The "make mrproper" command deletes your .config file too and you have to reconfigure the kernel again! I don't think it's really safe to do that ...

----------

## pv

 *Quote:*   

> WTH!!! The "make mrproper" command deletes your .config file too and you have to reconfigure the kernel again! I don't think it's really safe to do that ...

 

For my part, after each kernel building I copy bzImage to /boot/vmlinuz-<VERSION> and .config to /boot/config-<VERSION> so it's safe for me to do make mrproper. In the case of .config deletion error I always can restore the last kernel configuration from /boot.

----------

## thomasvk

Sorry to kind of reopen this old thread, but I have a preempt related question. I kind of understand what it is a little bit by now, but I'm still unsure. It's obvious that a preemptible kernel would be best for a desktop and not for a server. But I'm not working on a good config for a fileserver, but it's not only going to sit around serving files. Sometimes I would want to ssh into it and unrar a file or something like that. Would it be best to go with a preemptible kernel because I would run other processes which otherwise might be too slow, or no preemptible kernel because it would just server files most of the time?

I hope this makes sense and anyone can answer it.

----------

## dsd

you are confusing kernel preemption and task preemption.

task preemption is where the kernel can pause a user program and switch to running a different program. this is why you can still be reading your email while unrarring a huge archive. task preemption is always on, you cannot configure this.

kernel preemption is where the *kernel* threads can preempt each other. kernel threads usually perform specialised tasks, its hard to say how useful this is now that a lot of latency reduction work has been completed over the kernel code base. some people claim kernel preemption helps, some people claim it doesnt.

----------

## Sachankara

 *t0maz wrote:*   

> Sorry to kind of reopen this old thread, but I have a preempt related question. I kind of understand what it is a little bit by now, but I'm still unsure. It's obvious that a preemptible kernel would be best for a desktop and not for a server. But I'm not working on a good config for a fileserver, but it's not only going to sit around serving files. Sometimes I would want to ssh into it and unrar a file or something like that. Would it be best to go with a preemptible kernel because I would run other processes which otherwise might be too slow, or no preemptible kernel because it would just server files most of the time?
> 
> I hope this makes sense and anyone can answer it.

 Nope, you only need preempt for X and for example video playback. Set the thread time (or whatever it was called) to 250 Hz for reasonable responsive multipurpose server.

To the thread creator: I suggest you do as I wrote above too. Loading OO on my slower 333 MHz AMD K6-2 doesn't cause the system to lag. You probably have to look over your settings.

----------

## Dominique_71

 *dsd wrote:*   

> you are confusing kernel preemption and task preemption.
> 
> task preemption is where the kernel can pause a user program and switch to running a different program. this is why you can still be reading your email while unrarring a huge archive. task preemption is always on, you cannot configure this.
> 
> kernel preemption is where the *kernel* threads can preempt each other. kernel threads usually perform specialised tasks, its hard to say how useful this is now that a lot of latency reduction work has been completed over the kernel code base. some people claim kernel preemption helps, some people claim it doesnt.

 

It depend of what you are doing. For big application as Ooo, it is only one thing to do: wait until it have finish to load. In general, RAM memory have more impact as premption on the speed of the desktop.

Now, if you are doing work where you have one or more programs that use a lot of processor work, as with sound synthesys or video rendering, it can help a lot to have a so called realtime preemption or full premption. For that, you must use a kernel with Ingo Molnar's realtime parch, or a PAM enabled kernel. Even here, for that to work, you have to define the priorities of your hardaware and software. As exemple, for an audio pro workstation, you would put the system clock at the higher hardware prioriy, followed in decreasing order by the sond cards one by one, the usb, the keyboard, and the other stuff. And you will grant the users in the audio group a realtime prioritiy, so at their softwares will have an higher priority as the other softwares.

The problem with it, is at you must accept, at even with a very fast machine, it can append sometime, when a sound application is loading the proceesor with a very heavy load, at even if the sound is OK (it is what you want), the system can be or can not be responsive. In such cases, you can have a very strange behaviour with the desktop freesing a few seconds, but at the same time, the sound applications are working without problem and we get no xruns in jack (jack is THE linux professional sound server).

Now, for a desktop use and in comparaison with a "standard" kernel, it is not so easy to respond if preemption help or not. With gentoo, it doesn't do a big difference, because we compile the kernel at the first installation and we can optimize it for the hardware in the box. We get, with a modern kernel and without a realtime pacth or a pam kernel, already very good performances.

But if I take a Suse kernel, that is optimized for server work and the network, the desktop become much more responsive with a self compiled kernel, especialy with a good preemption. Suse is the worst system I know for professional audio work, but with a realtime kernel, the difference in performances between suse and gentoo on the same box is so little, at I can say at it is no difference. In the case of suse, the difference is outstanding, even for the desktop. But with gentoo, the difference is only when doing audio work. (At least with my box, a P4 1.8 GHz and 1.5 Gb RAM)

Last but not least: The preemption in a vanilla kernel is good enough for desktop use and I would not recommand to install a such realtime kernel for a general desktop use, because it can hang the system if not correctly installed, and it is hardware issues with it and buggy hardwares as some SIS chipsets.

EDIT: When i wrote PAM kernel, you must read realtime kernel with PAM-RLIMiTS system and without the realtime-lsm module. PAM have nothing to do with realtime, you must have a PAM-Rlimits for that to work. Look here: [portage overlay] pro audio production applicationsLast edited by Dominique_71 on Sat May 20, 2006 11:45 am; edited 2 times in total

----------

## widremann

 *dsd wrote:*   

> you are confusing kernel preemption and task preemption.
> 
> task preemption is where the kernel can pause a user program and switch to running a different program. this is why you can still be reading your email while unrarring a huge archive. task preemption is always on, you cannot configure this.
> 
> kernel preemption is where the *kernel* threads can preempt each other. kernel threads usually perform specialised tasks, its hard to say how useful this is now that a lot of latency reduction work has been completed over the kernel code base. some people claim kernel preemption helps, some people claim it doesnt.

 

This is wrong.  It has nothing to do with kernel threads.  They are just processes like everybody else with the exception that they run entirely in kernel mode and don't have their own memory context (they use the memory context of the last running user process).  What preemptive kernel really means is that when a process is executing in kernel mode (any process, not just kernel threads), it can be preempted by another process.  Under the old model, once a process entered kernel mode, for whatever reason (system call, hardware interrupt), a task switch wouldn't occur until either the process manually yielded the CPU or until a return to user mode was about to occur.  The problem with this was that if an interrupt occured indicating, for example, that an I/O operation had completed for another process, then the target process would just have to wait until the currently running process was finished in kernel mode, adding some bit of latency in the kernel when responding to events.

----------

