Sunday, April 17, 2011

CPU Frequency scaling in FreeBSD

I've already posted about how easy this is to set up in Ubuntu using indicator-cpufreq.
The principal, if not the only, benefit from this is reduced power consumption which is useful when running on battery power. A further benefit is reduced processor temperature which "may" prolong processor life.
I learned about this first when I saw this tutorial, this one and this too.
Both of these are, however, very curtailed and lacking in detail so I still had to do quite a bit of investigation. In this, some further documents helped me including the powerd man page and this PCBSD forum thread which provides some useful examples.
Right now, I've got it working, but still not optimized, in FreeBSD 8.2 on my DEll E520 which is, of course, a Desktop rather than a laptop to which this technology is more appropriate.
Here, I just want to run through the most useful commands that helped me get this far.

1. cpufreq.ko is included in the 8.2-release kernel so you don't need to run /sbin/kldload cpufreq.ko as suggested here.

2. Useful sysctl commands using cpufreq and the outputs I get are shown below:

i) $ sysctl dev.cpu.0.freq
dev.cpu.0.freq: 1600 ##frequency in MHz of CPU 0 (total)

ii) $ sysctl dev.cpu.0.freq_levels
dev.cpu.0.freq_levels: 1867/89000 1633/77875 1600/63000 1400/55125 1200/47250 1000/39375 800/31500 600/23625 400/15750 200/7875 ## allowed frequencies for CPU (first is in MHz, not sure yet about the second of the pair)

iii) # sysctl dev.cpu.0.freq=1200
Use this (as root) to set CPU frequency to any of the allowed frequencies shown above. Note that this command doesn't work if powerd is enabled.

iv) I put these two lines in /etc/rc.conf to enable powerd at boot

powerd_flags="-a adaptive"

The -a flag refers to AC power, which is all I have on my Desktop. Options here besides adaptive (IOW, frequency varies with load),are hiadaptive (same as adaptive but keeps frequencies towards the higher end. For me, even at idle, it didn't vary from maximum over about 15 minutes.), maximum and minimum.
See the man page for details.

Just to mention, that my processor temperatures, at maximum frequency, run at 60-64ºC. But, when I set it to 1200 MHz, the temperatures dropped over about an hour to mid forties.
Next, I want to investigate the value of the various powerd_flag options to get a tighter control on how my CPU frequency varies.
Some other useful posts on this topic are this wiki article on powerd, this also from the wiki on more general laptop power consumption tuning and, finally, this which deals with the topic in general but from a Linux viewpoint.

No comments:

Post a Comment