Friday, 1 January 2010

Configuring OnDemand CPU frequency scaling

From here http://linux.digitalsp.com/2009/08/improving-stuttering-during-flash-video.html

Problem:

You have a CPU that supports dynamic frequency scaling and you experience dropping frames or sound stuttering during flash video playback. By default the CPU governor in Ubuntu is set to 'ondemand'. It appears that the ondemand governor does not always scale up as needed.

What is ondemand ?

Ondemand is a dynamic in-kernel CPU frequency governor that can change CPU frequency depending on CPU utilization. It was first introduced in the linux-2.6.9 kernel. Not all hardware support this feature. For Intel CPUs is referred to as SpeedStep and for AMD CPUs it is referred to as Cool'n'Quiet or PowerNow!

Solution:

Add the following lines to your /etc/init.d/ondemand configuration file. You can type “sudo gedit /etc/init.d/ondemand” in the terminal to access this file. I changed my file using the root mode of Krusader.
for CPU_THRESHOLD in /sys/devices/system/cpu/cpu*/cpufreq /ondemand/up_threshold
do
[ -f $CPU_THRESHOLD ] || continue
echo -n 40 > $CPU_THRESHOLD
done
This is what my ondemand file looks like after the change:
photo of ondemand configuration file
This will scale your CPU when the processing utilization reaches 40%. You can experiment with different values here. Reboot after making these changes and you can verify that your CPU supports this feature by checking the output from the command line with the dmesgcommand. You should NOT see the following message:
ondemand governor failed, too long transition latency of HW, fallback to performance governor

This should provide an improvement for all applications (not just Firefox, Opera) that needs that extra kick to work smoothly.

No comments: