/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.
I use ondemand on my laptop, and it works wonderfully; it instantly maxes my CPU speed when needed, and drops it back down the moment it isn't.
Based on the error message you're getting, a few suggestions: * Is the ondemand governor built for your kernel? * If ondemand is a module, is the module loaded? * Have you tried using cpufrequtils? * In particular, have you tried just setting the governor in /etc/defaults/cpufrequtils? * What does "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors" say? * How about "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"?
The files in /sys can be very picky; have you tried 'echo -n' instead of plain echo?
(FWIF Ubuntu installed powernowd on my laptop; and I can see that the CPU speed drops to 600 Mhz when the machine is idle, and goes back up to 1.6 GHz after a couple of seconds of 100% CPU activity.)
You actually need to manually load these cpufreq_* modules for those governors to work (again, they work for me, even though I don't currently use them).
You might want to load one of the speedstep-* modules, too. I know, it's a mess!
/Mikael
For what I know, "ondemand" simply doesn't want to work with PPC laptops..
See http://www.linuxfromscratch.org/hints/downloads/files/cpufreq.txt, here is a snippet: " It would seem that the 'ondemand' driver makes powernowd redundant, but some CPUs (like the ppc 7447) apparently have a very high transition latency which causes the ondemand governor to decline to manage them - on my 7447A the powersave and performance drivers ('governors') work, but trying to install 'ondemand' fails. Equally, on a laptop powernowd will probably be a little quicker at dropping the speed, and can therefore give a little more battery life."
I think it's really funny that you've gone about to write your own power deamon, but if you think it works, I guess it's okay.
You should probably use powernowd, at the sine setting it's very sensible to me.