If you use Linux on a Laptop, chances are high that you can dramatically improve the responsiveness of all your GUI applications. This tip will work for you if you:
- Use a frequency scaling application like powernowd (Ubuntu does this by default), cpudynd, or cpufreqd.
- Have Kernel 2.6.9 or better.
In short, the trick is to disable powernowd and use the ondemand governor instead. How to do this in Ubuntu comes later, let me first show you what this change gets you. In short, you get maximum performance and a longer battery life.
I have a laptop with a Pentium-M that allows frequencies between 600MHz and 1500MHz. Running on 600MHz gives a long battery lifetime and a quiet notebook, on 1500MHz I get good performance. The trick is to switch between the frequencies so that you can have the best of both sides.
This are the rendering times of the CNN site, with different CPU frequency scaling settings. Each measurement was performed 4 times, and the average is show.
Here is an explanation for the graphs:
powersave (600MHz): Since kernel 2.6.9 there are CPU governor in the kernel that allow different frequency scaling behaviour. In the first benchmark the CPU was set to “powersave” which means that only the lowest possible frequency is used. With 600MHz it takes 9.38 seconds processor time to render CNN.com.
performance (1500MHz): The governor “performance” always keeps the CPU at the maximum setting, 3.82 seconds render time is the fastest I can possibly get from of my machine.
powernowd -q -m 3: This one is interesting, here the governor “userspace” was used which means the frequency can be controlled by a userspace application, which in this case was powernowd. The load time is somewhere inbetween the previous two benchmarks, which means that powernowd correctly recognizes that there is a high CPU demand, and switches to the highest frequency. This detection takes quite a bit of time so precious 1.73 seconds are lost compared to what is truly possible with this computer! This is very bad.
ondemand: Finally the glorious “ondemand” governor. This governor switches to the highest frequency if processor usage goes above 80%, and switches back to the lowest frequency where the CPU has less than 80% utilization as soon as possible.
This is not much different from powernowd, except that it can sample the CPU utilization 25 times per seconds which means it can react in mere milliseconds on a change. Since the governors are kernel modules this does not have the high overhead that a userspace tools like powernowd would have with such a sampling rate. The result speaks for itself, the ondemand governor provides almost exactly the same performance as with constantly running at maximum speed. Not only does it have almost no performance difference to the maximum settings, it is also very good for the battery because it is equaly fast when switching back to lower frequencies.
For more background information about the algorithm behind the ondemand governor have a look at the paper The Ondemand Governor.
How To Benchmark For Yourself
You do not need anything special for this benchmark, this is how I have done it:
- Install the Fasterfox extension, this has a page load timer
- Browse to any website (I used CNN since it is a quite complicated site that takes a while to render).
- Save the website (File > Save As).
- Now enter the name of your saved file into the address bar (e.g.
/home/martinus/CNN.htmlfor me). It is important to use the saved file, so that the load measurement contains the raw rendering performance and not how fast you can download
- Wait about 5 seconds, so that you can be sure whatever you use for frequency scaling has switched to the lowest MHz setting.
- Press Enter.
- Have a look at the timer (lower right corner of firefox) when the page has finished loading.
How To Use Ondemand Governor In Ubuntu Dapper
This is quite simple. See this For a longer description.
- Uninstall powernowd
sudo apt-get remove powernowd
- Enable speed stepping (I have a centrino, you might need a different module)
sudo modprobe speedstep-centrino
- Enable the “ondemand” governor
sudo modprobe cpufreq-ondemand
- Switch to the ondemand governor (default is performance). As someone in the comments has pointed out sudo does not work here, so use this:
sudo bash echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor exit
For permanent settings:
/etc/modulesand add the following lines (if you do not have a centrino chipset you need to exchange speedstep-centrio with something else)
- Install sysfsutils with
sudo apt-get install sysfsutils
/etc/sysfs.confand add the line