governor - switch Linux cpufreq governor

(Note: The source code is now part of the embutils repository)

I run this trivial program at boot-time. Here is a 32-bit x86 binary, and here is a 64-bit AMD64 binary.

This code works on my Athlon 64 desktop and on my Core 2 Duo notebook. On my Athlon 64, I use this .config, and on my Core 2 Duo, I use this one.

It checks the ACPI kernel info to see if the computer is running on AC power or on battery, and sets the cpufreq governor to "ondemand" for AC and to "powersave" for battery.

The program can also set the governor unconditionally. If you run it as "fast", it will set the governor to "performance" (CPU at max all the time). If you run it as "auto", it will do the above ACPI based auto detection ("ondemand" runs the CPU at min, but switches to full speed if you run something demanding; it's the best setting). If you run it as "slow", it will run the CPU at min all the time.

You could usually get by with telling the kernel to always use ondemand (but the kernel only allows for "performance" and "userspace"... !?) and not even compile the other options in, but if you want to do some benchmarks, you need a way to switch the CPU freq to some well defined position, and I use "fast" for that.

To see what frequency I'm currently running with, I use

alias freq="cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq"

(zsh syntax)

The "userspace" governor is obsolete crap. I don't even compile it in the kernel or as a module.