Archive for the 'Linux' Category

CPU Frequency Scaling

Friday, November 19th, 2010

I compiled my own kernel for the first time since high school last night. And it felt good. And now, I have CPU Frequency Scaling working. I probably could have made it work before because it looked like everything was built as modules, but I never got around to figuring out what I needed to load. So, I just built in what I knew I needed. The kernel compile took 3:18 (3 minutes) on the stock kernel, and running the build again using the new kernel was slightly slower at 3:48. If I get time, I’d like to see if I can get that down… although I would need to save the specific configuration to have a meaningful comparison. However, as long as the build time is going down I should be approaching faster, because if it’s due to less things being compiled the kernel will be leaner. A leaner kernel leaves more precious CPU cache for the processes. Of course, modules break this theory in that removing the compilation of unneeded modules speeds up the compile without speeding things up at all.

Anyway, back to frequency scaling. My CPU supports 4 frequencies, 800 MHz, 2.2, 2.7, 3.4 GHz. And each core can me set independently. Sweet. It turns out that when all 4 cores are at 800 MHz, I get an audible buzz that is rather annoying. Shame on you AMD. Setting any one of the processors to the next higher frequency eliminates the problem, but I want to use the ondemand governor. What ondemand does is increase the frequency when the CPU load is high. I think it can even skip for example from 800 MHz to straight to 3.4 if it detects the load rising quickly enough. Well, it turns out that I can set a minimum frequency per core. So, by running

sudo su -c ‘echo 2200000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq’

I set the minimum frequency to 2.2 GHz on the fourth CPU. So now I’ve got 3 at 800 MHz and one at 2.2 GHz. No whiny processors, and much power savings over 4 cores blasting noops at 3.4*10^9 times per second. Not the ideal of replacing 4.25 noops with 1, because of AMD’s failure to thoroughly test the acoustic consequences of their design, but still we are reducing 2.96 to 1 at idle.