BUG: Ubuntu 9.04 – OnDemand Doesn’t Scale CPU Speed

Ubuntu Logo

Along another one of those long, strung-out searches, I came across a problem I didn’t know I had. Or to be more precise, peculiarities I couldn’t put a finger on. Before Ubuntu 9.04, I had no problem running a bunch of gee-whiz compiz effects on my desktop. Before Ubuntu 9.04, Flash overdoses and crashes caused my CPU fan to spin up instead of slowing down my desktop. Before Ubuntu 9.04, I could see my CPU frequencies bouncing around.

That’s because Ubuntu 8.10 didn’t set the CPU usage threshold to 95% before bumping up the CPU frequency with the ondemand governor.

I’d honestly like to sit down with a dev and have them explain to me why they thought 95% was a good number. I’m not going to claim God-like knowledge of CPU frequency scaling, but it would seem to me that applications would have to chug for a bit at a processor’s lowest frequency scale before the CPU would bump itself up. Aren’t there applications out there that will throttle themselves, inhibiting a CPU speed increase? Doesn’t this mean that a 5% decrease in CPU usage will bump the processor right back down to a lower speed? Maybe this works better on processors that have a more fine-grained speed stepping in their CPUs. But for processors with only two or three speed steps, this completely blows.

Indeed, a quick look at my servers still running 8.04 LTS, the old threshold was 60%. Now we have people completely over-reacting in the opposite direction, suggesting you go as low as 20%. Great. Fucking. Job.

Good job to these guy for figuring things out.

Edit /etc/init.d/ondemand

Add this block of code directly after the for CPUFREQ in block and before the double-semicolons.

	for CPU_THRESHOLD in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/up_threshold
	do
		[ -f $CPU_THRESHOLD ] || continue
		echo -n 60 > $CPU_THRESHOLD
	done

You can change the number 60 if you want. I’ve actually found 40 to be a good compromise for a performance desktop. It’ll keep the CPU clock low during mundane tasks and keep it from decreasing during moderate usage. If 60 holds the CPU back from ramping up a bit too much, play around with it for a bit.