# Kernel frequency

## TBKDan

I am running a few gameservers on gentoo 2005.1, and I have the kernel frequency set to 1000hz.  I would like to increase this value to get better server reaction time, but in meuconfig the max is 1000.  Is there any way to increase this to greater than 1000, or is it not supposed to go that high..?  I want to make my system as responsive as possible.

----------

## alistair

there are only 3 options 100Hz, 250Hz and 1000Hz

100Hz:  Servers.  Higher throughput. Processes run for long and get more done

250Hz:  Server/Desktop.  A compromise between the other 2

1000Hz: Desktop.  Higher responsiveness. Processes dont run as long, more timer interrupts.

If linux had the ability to have really high Hz then ppl would be dumb and set their frequency really high and the computer would then be continuely handling interupts and never any userspace programs

[edit]

I would personally lower the value not raise it.

----------

## TBKDan

Well the higher the frequency, the higher the framerate on the server.  The higher the framerate, the smoother it runs and better hit registration it gets.  That is why I want to get a higher frequency.  I'm almost considering going back to Windows on this box just so that I can get a higher framerate :'(

----------

## feld

framerate? what are you smoking? There's no such thing as framerate for a server. You're not rendering anything.

-Feld

----------

## alistair

 *TBKDan wrote:*   

> Well the higher the frequency, the higher the framerate on the server.  The higher the framerate, the smoother it runs and better hit registration it gets.  That is why I want to get a higher frequency.  I'm almost considering going back to Windows on this box just so that I can get a higher framerate :'(

 

So this isnt just for a dedicated gameserver?  Just to let you know windows Hz is set to 100 (

----------

## lbrtuk

Higher frequency != faster.

Higher frequency does mean that kernel code gets executed more times per second and thus increases the kernel's overhead. Sometimes as a result of this though, if you're creating / deleting / running a lot of processes and continually having to switch between them or doing a lot of realtime i/o (audio/video), you might get better percieved performance.

----------

## curtis119

Be very very careful with the frequency settings. MS Windows is timed at 100 and *a lot* of hardware manufacturers only use parts that are rated at 100 because they only care about Windows users and it's cheaper. If you bump the frequency above that you can actually fry your motherboard.

----------

## G2k

if I'm not mistaken, ck-sources in 2.6.15 defaults to 1000Hz. There's a problem in kernels above 2.6.12 with hyperthreading and I can't get a non-lagging system without setting the frequency to 1000Hz...I still haven't been able to solve this, I've been using 2.6.12 for the longest time  :Sad: 

----------

## TBKDan

This is a CS:S game server.  Framerate as in FPS, how many ticks the server will process per second.  If the server misses a tick that was sent by the client, it could result in a bullet that was fired by the client but never received by the server, therefore a miss when it should have been a hit, and therefore unhappy players.  With 100hz, the server framerate stays about 50 FPS.  With 250hz, it stays about 166FPS, and with 1000hz, it stays around 333FPS.  Now do you see my logic in wanting to increase the framerate?  On windows I can easily hold about 500FPS, and on one motherboard configuration I actually achieved 1000FPS, but it was something special about that chipset that I have not been able to recreate.  I hope that is a bit more clear of my intentions  :Smile: 

EDIT:  Most clients send 100 updates per second, and expect 100 back.  If the server FPS ever falls below 100, then they experience issues in gameplay that are not wanted at all.

EDIT2:  When running Windows Media Player or a separate utility (one created just for this purpose), you can raise the hz for windows (although I am not sure what it gets raised to).

----------

## bollucks

Wow that sounds like such broken software. The HZ should not be limiting frame rate in that way. Servers are usually non-timer interrupt driven and they can usually service more interrupts when they're running at lower HZ. That game server software sounds pretty much broken by design.

----------

## widan

 *curtis119 wrote:*   

> Be very very careful with the frequency settings. MS Windows is timed at 100 and *a lot* of hardware manufacturers only use parts that are rated at 100 because they only care about Windows users and it's cheaper. If you bump the frequency above that you can actually fry your motherboard.

 

The HZ value is not related to hardware at all. It's just the frequency of timer interrupts, and all motherboards can handle 1000 timer interrupts per second. It won't fry anything, it's not like overclocking hardware. The worst that can happen is to have so many interrupts that the machine is spending all its time processing them.

 *bollucks wrote:*   

> Servers are usually non-timer interrupt driven

 

This is true, but the kernel scheduling uses the timer interrupt, so increasing HZ increases scheduling frequency, and so will result in a more responsive system (less latency) at the price of higher overhead (you need to handle all those interrupts). Depending on the processes running, this can have a positive or negative effect.

 *TBKDan wrote:*   

> Is there any way to increase this to greater than 1000, or is it not supposed to go that high..?

 

No supported way. You can try to modify kernel/Kconfig.hz and add/modify things there (that file defines the options you're seeing in dmesg, and the actual values that are associated to them), but you do so at your own risk.

Also, if you want low latency, make sure you have kernel preemption enabled (it will allow threads to be preempted even if they are currently running in kernel mode).

----------

## TBKDan

Well, it is made by Valve  :Very Happy:   So I wouldn't be surprised, but the kernel hz DOES have an impact on the performance of the server.

----------

## curtis119

 *widan wrote:*   

>  *curtis119 wrote:*   Be very very careful with the frequency settings. MS Windows is timed at 100 and *a lot* of hardware manufacturers only use parts that are rated at 100 because they only care about Windows users and it's cheaper. If you bump the frequency above that you can actually fry your motherboard. 
> 
> The HZ value is not related to hardware at all. It's just the frequency of timer interrupts, and all motherboards can handle 1000 timer interrupts per second. It won't fry anything, it's not like overclocking hardware. The worst that can happen is to have so many interrupts that the machine is spending all its time processing them.
> 
> 

 

Nope, you are incorrect. A high frequency *can* cause capacitors on your motherboard to burn out. Search for it if you don't believe me.

----------

## alistair

 *TBKDan wrote:*   

> This is a CS:S game server.  Framerate as in FPS, how many ticks the server will process per second.  If the server misses a tick that was sent by the client, it could result in a bullet that was fired by the client but never received by the server, therefore a miss when it should have been a hit, and therefore unhappy players.  With 100hz, the server framerate stays about 50 FPS.  With 250hz, it stays about 166FPS, and with 1000hz, it stays around 333FPS.  Now do you see my logic in wanting to increase the framerate?  On windows I can easily hold about 500FPS, and on one motherboard configuration I actually achieved 1000FPS, but it was something special about that chipset that I have not been able to recreate.  I hope that is a bit more clear of my intentions 
> 
> EDIT:  Most clients send 100 updates per second, and expect 100 back.  If the server FPS ever falls below 100, then they experience issues in gameplay that are not wanted at all.
> 
> EDIT2:  When running Windows Media Player or a separate utility (one created just for this purpose), you can raise the hz for windows (although I am not sure what it gets raised to).

 

Wow your computers/motherboards are wierd.  As has been said above (1)Windows timer frequency is set to 100Hz, (2) increasing the Hz shouldnt make a server run "better" and (3) FPS doesnt/shouldnt/wouldnt effect the amount of actually server work done.

The only thing I could imagine is that there is some ... conflict ... between the Hz and your IO schedulars and that some IO schedulars are more effective at different timer frequencies.  Yet im still stretching my imagination to figure out why?

----------

## erikm

TBKDan: Which preemption option are you using?

----------

## TBKDan

alistair: The FPS results are pretty much common across the board for anybody who runs srcds on any linux distro, with a few exceptions to that rule.

ErikM: The lowest latency one (desktop).  I can't remember the actual name but I know that's it  :Razz: 

----------

## erikm

 *TBKDan wrote:*   

> alistair: The FPS results are pretty much common across the board for anybody who runs srcds on any linux distro, with a few exceptions to that rule.
> 
> ErikM: The lowest latency one (desktop).  I can't remember the actual name but I know that's it 

 

I run Gentoo on my desktop machine at work. As a computational scientist, I use some very resource heavy codes, and to be able to test my jobs before I submit them to our MPP cluster, I also installed the software on my desktop. That is, my poor machine typically has to multitask and run high-throughput stuff, simultaneously.

I used the lowest latency preemption model in my last kernel, and after switching to 'voluntary' the machine feels a lot less congested. 

I'd say play with the preemption models and the IO schedulers, rather than messing with the frequency. As others have pointed out, more ticks per time will improve latency, and the responsiveness for some applications, but will also decrease throughput, i.e. performance in other applications.

----------

## XenoTerraCide

curtis119 could you point me to where you have found that the high frequencies can cause hardware damage? I did some quick googles but saw nothing. I can't attest one way or another who is right but I would like the fact's. the only thing I've found so far is this

"According to Alan Cox, HZ==1000 is also harmful on some laptops

(presumably due to long SMI windows)"

do you have anymore information on this?

----------

## widan

I have some doubts too about capacitor damage... The big caps on a motherboard are filtering caps for the DC/DC converters that generate the various voltages for the CPU, chipset, ... and those run at much higher frequencies than 1000 Hz. There was a bad batch of caps a few years ago, and those had a tendency to fail, but it's completely unrelated to timer frequency.

 *XenoTerraCide wrote:*   

>  *Quote:*   "According to Alan Cox, HZ==1000 is also harmful on some laptops (presumably due to long SMI windows)" 
> 
> do you have anymore information on this?

 

Laptops use SMM (System Management Mode, a special execution mode of the x86 CPUs) for many things (especially power management). This is completely transparent to the OS, but if the SMM code takes more than 1/1000th of a second to run, you will lose a timer interrupt if they are configured to occur at 1000 Hz (two interrupts will have occured during the time the SMM handler was running, but the OS will only see one). And losing interrupts is bad.

----------

## XenoTerraCide

I see you said x86 what about athlon64 laptops? that what I have so although other people need to know about x86 laptops I'm not concerned as much. 

my basic understanding of this option is that a higher hz reduces latency at the cost of throughput. 

I am also doing a linux kernel presentation for the local LUG in a week and I was planning on going over kernel modules and option's including this one. so the more I know the better.

----------

## widan

 *XenoTerraCide wrote:*   

> I see you said x86 what about athlon64 laptops? that what I have so although other people need to know about x86 laptops I'm not concerned as much.

 

SMM works on amd64 too. And there are quite a few laptops with broken BIOSes that hold the CPU in SMM for way too long. An (old) example of SMM-related lost ticks is here. Unfortunately, there are still broken BIOSes (example here, and a Google search for "lost ticks" and SMM should turn up more).

In any case, if you see messages about lost ticks when running with high HZ, you should try to reduce it, as it means the kernel is losing timer interrupts) It's not necessarily a good idea from a power management point of view too (the CPU is idle for less time between interrupts, so it will use more power).

SMM is mostly used for power management (mostly laptops) and USB keyboard emulation (running DOS with a USB keyboard). Those uses should not cause problems (if properly written - which, unfortunately, is not always the case  :Evil or Very Mad: ). A lot worse is the VSA stuff of Geode processors:

 *Quote:*   

> The GXLV processor also incorporates Virtual System Architecture® (VSA) technology. VSA technology enables the XpressGRAPHICS and XpressAUDIO subsystems. Software handlers are available that provide full compatibility for industry standard VGA and 16-bit audio functions that are transparent at the operating system level.

 

Yes, that really means they are emulating a VGA card and a sound card through SMM. Here the SMM handlers can cause significant latencies in some cases, but fortunately that kind of CPU is mostly used for embedded work.

----------

## XenoTerraCide

I had losing ticks and then I turned off amd powernow in the kernel. I don't have that problem now. also I had to do a flash of my bios do to motherboard unstable timesource issue's but I haven't had any problems recently like that. (recently defined as since I fixed it)

----------

## curtis119

 *XenoTerraCide wrote:*   

> curtis119 could you point me to where you have found that the high frequencies can cause hardware damage? I did some quick googles but saw nothing. I can't attest one way or another who is right but I would like the fact's. the only thing I've found so far is this
> 
> "According to Alan Cox, HZ==1000 is also harmful on some laptops
> 
> (presumably due to long SMI windows)"
> ...

 

I couldn't actually find it but I'm 99% sure that I am correct. Setting the timer interrupt to a higher value can cause *some* cheaply made capacitors to burn out faster than they should. I remember reading that it was two specific brands of capacitors used in desktops.

I could be misremembering this but I'm pretty sure. Does anyone else know WTF I'm talking about?

----------

## widan

There was a bad batch of caps (made with the wrong electrolyte I think) that tended to fail prematurely (after only one or two years of service). When they failed, the top was "rounded" (because of gas production inside) instead of flat, and the cap frequently leaked. It looked like that (on the left picture, two of the top three caps).

But the large caps that had problems were low-ESR caps used for filtering in the CPU (or chipset, RAM or others, but usually the ones for the CPU failed faster because of the higher current draw) voltage regulation circuit, and that circuit is not affected by interrupt frequency (it just provides power to the CPU, so interrupts or timers don't matter).

Many Windows machines had caps fail too (so it's not related to Linux). The caps could be replaced, but it was not worth the time it took for cheap boards (also, finding small quantities of low-ESR caps was not simple, and they weren't cheap).

----------

## lunarg

Maybe a bit OT:

So for a standard desktop system (office work, internet and email, chatting, watching a dvd or so, ...) it's best not to use the 1000hz option? Or am I wrong here?

Out of curiosity: what was the default before you could change it in 'make menuconfig' ?

Grts

----------

## curtis119

 *lunarg wrote:*   

> Maybe a bit OT:
> 
> So for a standard desktop system (office work, internet and email, chatting, watching a dvd or so, ...) it's best not to use the 1000hz option? Or am I wrong here?
> 
> Out of curiosity: what was the default before you could change it in 'make menuconfig' ?
> ...

 

Linus and the other kernel devs suggest 1000 for a desktop. The default is 250.

----------

## curtis119

I found the thing about the capacitors. It turns out I was partially correct. If the timer frequency is turned up too high cheap capacitors will produce an analog radio signal that can be picked up by your sound card if it isn't shielded correctly. It's called "singing capacitors" and it doesn't damage the MoBo. It's just really annoying.

----------

