# Automating low-latency setting in kernel

## Mr. Ust

I'm wondering if there's a simple way to automatically manage the low-latency and pre-emptible patches using sysctl.

Basically, what I want is a simple form of management.  If I'm actively working in X, low-latency is very important.  I need responsiveness.  However, if I'm not in X, or away for an extended period of time, I would prefer to have high throughput, especially if there is a lot of background work going on.

So here's my proposal, and see if you can poke holes in it:

Apparently there is a way to manage the low-latency patch using sysctl.  I'm not sure if there is an equivalent for the pre-emptible kernel patch.

I'm not yet familiar with the runlevels gentoo uses.. Assuming runlevel 5 is multiuser and runlevel 6 is X, I'd edit the appropriate files and have the patches turn off or on as I enter and exit X.

The other thing I would like is to have the low-latency/pre-emptible kernel patches turn off if I'm afk for more than 10 minutes.  Basically, instead of a screensaver, the PC would switch to high throughput mode, and then back again.  Is there some screen-saver functionality in X that I could tie this to?

So here are my concerns:

What are the downsides of switching back and forth?  Is there a risk of data corruption, crashes, etc... with the scheme I've outlined?

How do I actually go about doing this?  Is there a handy rc-update command I can issue?  I haven't mucked about with the runlevels manually just yet.

And finally, why isn't everyone doing this?  :Wink: 

----------

## delta407

 *Quote:*   

> If I'm actively working in X, low-latency is very important. I need responsiveness. However, if I'm not in X, or away for an extended period of time, I would prefer to have high throughput, especially if there is a lot of background work going on. 

 

Can you explain, exactly, how having faster response times decreases throughput? Do you have any data that the low latency or pre-emptible kernel patches reduce performance?

----------

## delta407

As far as runlevels go, there's boot, single-user, nonetwork, default, default, default, and reboot, though those aren't entirely useful under Gentoo. It kinda depends on how you start X; modifying your startup script to echo "1" > /proc/sys/LOWLATENCYTHINGY before X is started and echo "0" after X terminates might do the trick.

But... again, I ask, why do you want to do this?

----------

## Mr. Ust

 *delta407 wrote:*   

> Can you explain, exactly, how having faster response times decreases throughput? Do you have any data that the low latency or pre-emptible kernel patches reduce performance?

 

First, I don't have any data to back this up (now that that's out of the way, I can proceed to make a fool of myself).

Low-latency/throughput is a classic trade-off.  With low-latency, there is more overhead for the scheduler as processes are switched in and out of context more often.  This results in less real work being done (though the system is more responsive).  This is true theoretically.

Now for some anecdotal evidence (nearly meaningless):

And in fact, I believe it to be true in my case.  I originally installed the XFS kernel sources since the install guide incorrectly states that the gentoo-sources don't include XFS support).  I was doing some compiles in the background and just from watching gkrellm, I could tell my system was getting throttled.  Mouse movements were slowing down and desktop performance was unacceptable.  So I switched to the gentoo-sources kernel and everything runs smoother, but looking at gkrellm, the system isn't being throttled as before.

----------

## Mr. Ust

 *delta407 wrote:*   

> As far as runlevels go, there's boot, single-user, nonetwork, default, default, default, and reboot, though those aren't entirely useful under Gentoo. It kinda depends on how you start X; modifying your startup script to echo "1" > /proc/sys/LOWLATENCYTHINGY before X is started and echo "0" after X terminates might do the trick.
> 
> But... again, I ask, why do you want to do this?

 

Thanks for the startup script advice.  I guess I'd put it in .xinitrc ?

Not sure if that would help on the exit.  (Can't give you any more details at the moment as I'm booted into windows atm.  I wish DivX 5.0 Pro was available under Linux)

As for why I want to do this - It's a quick optimization hack.  Eventually, I'd fine-tune it depending on how I was using my system.  Reading some of the other forums, I've learned there are advantages and disadvantages to using the patches depending on how you use the system.

My real concern was about unexpected consequences, and that's why I posted to the forum.

----------

