/usr/local/sbin/mycpufreqd

#!/bin/bash

modprobe cpufreq_userspace
echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
while true
do
	if expr $(uptime|cut -d',' -f3|cut -d':' -f2) '>' 0.75 > /dev/null
	then
		echo 1333333 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
	else
		if expr $(uptime | cut -d',' -f4) '<' 0.75 > /dev/null
		then
			echo 666666 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
		fi
	fi
	sleep 10
done

I tried using some of the standard cpufreq stuff that's in the archive, but none of them seem to work for me; they all make my laptop work at full speed, all the time. Which is silly.

Also, the kernel ondemand and conservative governors don't seem to work—when I write "ondemand" to /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor, it comes back with write error: invalid argument, or some such.

So, I hacked up the above script. It sets the speed at full (1.3Ghz powerpc here) when the load rises above 0.75 for the last minute, and sets it at the low speed again when the load drops below 0.75 for both one and five minutes.

Using the system load average as a metric to decide what speed you run your processor at isn't terribly state of the art, but it Works For Me(tm); my processor isn't put to full speed when some short cpu-intensive job comes up for three seconds, but if something decides to use it for a bit longer, it does turn it up after approximately 30 seconds. Once it reaches that, it stays there until (on average) a few minutes after the cpu-intensive job has finished.

I like it that way.

Update: I received no less than four replies to this post that I need to make sure that cpufreq_ondemand is loaded, which I can check by reading /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors. Yes, I know. I did that. It's there. Yet, it still doesn't work, not even with echo -n.

Which is why I'm so confused. It's probably just a kernel bug, though.