Open Minded Brain Open source, open mind, open future

26Oct/1032

Undervolting in Ubuntu 10.10 (Maverick)

This is a guide to Undervolting your Intel CPU under Ubuntu 10.10. For the ones that do not know, Undervolting means taking some of the voltage from the CPU which in return gives a longer battery life and lower temperature during intensive use of the CPU.

Note: this is an copy/update of my old post about undervolting in Ubuntu 10.04 found over here. Be sure to check it out, especially because of the comments, some could be helpful and address possible questions/difficulties you may have.

And what are the negative aspects of Undervolting? Well actually taking some voltage from the CPU could bring in computational problems, basically when taking too much of it the CPU could start mixing 1's and 0's which can crash the entire system (reset needed) or bring in data loss/corruption. Not so good eh? So how is that people manage to do it without causing those side effects?

It depends on every CPU. Because it is not possible to create two CPU's 100% alike in the factory, tests are made to ensure all CPU's sold can work with the voltages specified under all circumstances. The fact is that some of the CPU's can work with voltages many times inferior than others that came from same factory/same box. The trick is to discover the limits of your CPU and set the voltage just a little above this limit and you are good to go.

WARNING because of the negative aspects shown above, by following the steps given below, I am not under any circumstances responsible for any data loss or corruption, damage to the CPU/PC. Those next steps were proven to work for many people around the world, but no guarantee is given that it would work for you without possible side effects. Just make sure that at least you have an updated backup of the data before continuing.


Ok, so now that you accept full responsibilities for the steps below, let's get going. I actually did this several years ago under other version of Ubuntu (using a single core Pentium M CPU back then) and it worked alright, but many things changed since then, we've got multi core CPU's everywhere and the way the undervolting issue is handled in Linux is very different also.

So what do we need? A single or multi core Intel Mobile/Laptop CPU and Ubuntu 10.10 installed on it and some time because it will take a little before having everything configured. Here are the complete steps that worked for me:

  1. As we are going to use a custom kernel, we need to add the linux-phc PPA repository, so just open a terminal and execute:
    $ sudo add-apt-repository ppa:linux-phc/ppa
    $ sudo apt-get update
    
    Basically they provide the same kernel as the Ubuntu one but with the patch that is capable for Undervolting.
  2. Next we need to install the phc kernel, with headers:
    $ sudo apt-get install linux-generic-phc linux-headers-generic-phc
    
    Ok, now we need to restart and use the installed phc kernel when booting. After restarting, you can check if you are using the phc kernel by using
    $ uname -r
    2.6.35-22-generic-phc
    
    If no "phc" appears, then you have to configure grub2 to allow you to chose boot options and select the phc kernel at boot time. This can be done many ways one would be:
    sudo update-grub
    
    and count the number of lines that says "Found linux image" (first one is 0) and, when you found the phc one, do:
    sudo gedit /etc/default/grub
    
    then just change the "GRUB_DEFAULT=0" to the number of the entry you found that has phc. Save the file and do a update-grub command again like in the first step. Now you can reboot into the phc kernel.
  3. Great, we are using a phc kernel, now we need to add the actual undervolt module, as the kernel comes only with support for it, not the actual module. First we need to download phc-intel offtree module from here. Right now they do not have a compatible version for the 2.6.35 kernel, but give the link a try, maybe by the time you read this post there is already a module that can be used in 2.6.35 kernels. Meanwhile there was a kind user on linux-phc forum that managed to create a module for the 2.6.35 and 2.6.36 kernels. Topic about it here. Direct link to the tar.gz file he kindly shared to the rest of us here. So download and unpack the files anywhere and point the terminal to the directory where you extracted the files and do:
    $ make prepare
    $ make
    $ sudo make install
    
    Right now you should have the module installed, check if everything worked by typing:
    $ cat /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids 
    40 34 31 27 23 15
    
    If everything worked, you should see some numbers (the ones above are the default ones for my CPU). If not, you may try to restart and check back to see if it works.
  4. So right now we are set, the only thing we have to do is... undervolt the CPU.
    Now we have to discover the limits of the CPU by lowering it's current voltage one step at a time and set the voltage 4 steps above the critical limit (where the cpu starts to give wrong calculations or the PC simply crashes).

    Why four? Well the recommendation was 2 steps above, but with this limit the PC crashed in the same day hours later, so I made it 3 steps, then some days after it crashed again. So I think 4 steps should actually do it. If not, you may increase this value until it suits you.

    Ok great now how to find the actual critical limit? There exists a script, created by the community, but it's old and it does not work for multi core CPU's and also in my particular case it sets the voltage directly below this critical limit so the PC crashes instantly.

    I updated this script and made it work on multi core CPU's (hopefully it will work for you too), so you just have to download the script, then give it execution permissions and execute it and follow on-screen indications:
    $ chmod +x intel-phc-undervolt.bash
    $ ./intel-phc-undervolt.bash
    
    Oh and make sure you close as many applications as possible when executing the script as the system may actually turn instable (it is intended actually) just to prevent any data loss. The script treats all CPU's cores with the same voltages, so if one of them is weaker than the other (does not support such a aggressive undervolting) is this the critical value that the script uses for all of the others, even if they could possibly use a even lower value.
  5. After you finished with the script, now you should have a "phc_tweaked_vids" file, containing the acceptable steps for your CPU. Now you only have to make changes permanent (load them at every boot of the pc) by editing /etc/rc.local file:
    $ sudo gedit /etc/rc.local
    
    and adding one entry for every core you have, something like:
    echo "23 20 4 4 4 4" > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids
    echo "23 20 4 4 4 4" > /sys/devices/system/cpu/cpu1/cpufreq/phc_vids
      .
      .
      .
    echo "23 20 4 4 4 4" > /sys/devices/system/cpu/cpu8/cpufreq/phc_vids
    
    just before the "exit 0". Note that "23 20 4 4 4 4" are my values, you have to replace the above with your values, that came from the "phc_tweaked_vids" file. So that's about it. Not too easy, not too complicated.

So... is it worth it? I have done some tests to see if the above actually works as said, so first I tested to see if on battery using powertop application and the CPU temperature I could see any differences. None actually, if the CPU is in idle state, there is no actual gain using undervolting, be it battery or temperature.

But when I've done the test under full load (using 2 burnMMX instances, one for every core) and with the CPU set at it's maximum 2.4Ghz I could see a very very noticeable difference.

First let's see the power drain of the battery in Watts, as indicated by powertop application (with the PC disconnected from the charger, of course):

It seems that Undervolting can spare you 10 Watt of power under full CPU load (Actual values from 38.4Watt to 28.7Watt). Now let's see how this translates actually to CPU temperature:

So those 10 Watt of power actually translates into having the CPU 7°C cooler (from 59°C to 52°C) while doing the same tasks under full load.

Just to clarify a little about the results of the CPU undervolt script. If the result of the script goes down to 0, that means is a fake value and that the CPU is locked and actually can't go below the lowest value (in my example the last values that have "4" value are faked by the CPU because he is actually running at it's lowest hardware allowed value, that would be 15). What this means is that at idle for example (when on 800Mhz in my case) I don't benefit anything by undervolting, but at higer frequencies (especially the 2.4Ghz one) I benefit a lot from it (see the charts abobe).

So that's about it. Hope you enjoyed the reading and that the steps were easy and clear to follow. Any questions/suggestions you can add them below, in the comments.

Comments (32) Trackbacks (0)
  1. Really nice guide!

  2. Hey Dan. I’m running a ThinkPad x200 with the P8600 processor (2.4 Ghz), which has four p-states – “Turbo”, 2400, 1600, and 800. I am trying to figure out whether the Super LFM at the 800 p-state is in fact unlocked on my processor, as this is documented in many forum discussions. Is there any way to know for sure? So far my VIDs are 26, 21, 13, 13.

    Your instructions have been superb, however I experimented with your script only after I had found satisfactory VIDs myself through trial and error, and the script did not seem to crash the system when it should have. The script was running VIDs through the ground, and it was only when I closed the script myself in progress, that the PC actually crashed?

    Thanks so much,
    Matthew

  3. Hi,

    Great thread. Lot of good work and people seem to be getting a lot out of it. I’m new to all this linux stuff and have a few problems. I’m fine up to step 4 but then it won’t make and install the module into the kernel. Just says can’t find the make file and when I drop the file directly into the terminal it can’t find the directory of the kernel. Any thoughts?

    I’m using ubuntu 10.10 by the way.

    Best,

    Rob.

  4. Hi,
    thankx for porting the tutorial.. My problem is just, that I did all the steps without problems, but the undervolting doesn’t start automatically after startup… If I start PHCTool I can change the values and check with “cat /sys/devices/system/cpu/cpu0/cpufreq/phc_controls” but still after every reboot I get the default values… Do You have an idea? I’m using a single core (Centrino) and it worked just fine in Karmic!

    Greetz, Peter

  5. Peter: You have to add the command to a script which gets automatically executed after boot. A good place is in /etc/rc.local

    Add the line “echo ‘blah blah’ > …/phc_vids” before the line “exit 0;” in /etc/rc.local and reboot, you are done!

  6. Sorry, seems like I haven’t been clear enough… I already added that line to my /etc/rc.local file, but still nothing happens…

    This is how the file looks like now (without the commented introduction):
    # WLAN Stromsparen bei intel2200 (z.B. T43)
    iwpriv eth1 set_power 5

    # Laptop Mode aktivieren
    echo 5 > /proc/sys/vm/laptop_mode

    # Bluetooth abschalten
    hciconfig hci0 down ; rmmod hci_usb

    echo “24 19 14 8 2″ > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids
    exit 0

    Thanks and greetings, Peter

  7. Hi, I agree that the guide is very well written, I have no problem following it. Thanks for the work put into it. Sadly, I don’t manage to get things working, and I get stuck after compiling and installing the module. When I try to write

    cat /sys/device/system/cpu/cpu0/cpufreq/phc_default_vids

    I can’t find the “cpufreq” direcotory in “cpu0″, and thus I can’t proceed. Why is this, I think I’ve done all the other steps correctly. Any ideas would be much appreciated!

    /E

  8. @Erik
    I think it shouldn’t be the problem, but maybe… You wrote “sys/device/system/… but it has to be /sys/devices/system/…
    Otherwise, do You maybe have the “cpufreq” directory in the /sys/devices/system/cpu directory?

    Lykke til ;-)
    Peter

  9. Great post!!
    A small thing: you have to say the script requires aptitude, or to use apt-get, otherwise the script won’t work. (i thought aptitude was by default in ubuntu, but in the 10.10 not..)

    PS: what’s the problem here?
    I don’t trust the CPU can work with the first VID at 0.
    I’m ignoring it and replace it with the default VID.

    i’m sure that it worked with this vid at 0.. can I set 4?
    Now i try again;)

  10. Thanks a lot for your guide! But I have a problem:

    $ uname -r
    2.6.35-22-generic-phc
    :~/…/phc-intel-0.3.2-12-1_2.6.36$ make prepare

    Makefile detected your kernel version as 2.6.35
    ***FOUND AVAILABLE PATCHSET. PREPARING.***
    ./prepare.sh: line 12: patch: command not found

    In line 12 of prepare.sh I can read: # for 2.6.35 to compile an aditional mperf.h is needed, this copies it (maybe also needed for later kernels)
    What is mperf.h ? I don’t understand what I should do…
    My cpu is an Intel pentium M 1600mhz
    I hope you can help me!
    Dome

  11. I have the same problem as you Peter,
    it seems like in maverick you need more than sudo to change the values.
    If I do the “echo…” manually using sudo it gives:
    “bash: /sys/devices/system/cpu/cpu1/cpufreq/phc_vids: Permission denied”

    I’m tryings different settings, will let you know if I find out anything

  12. Hello, I’ve found a solution, check this: http://o0arthur0o.wordpress.com/2010/06/17/undervolting-your-cpu-on-debian-squeeze/

    Beginning with “Applying chosen VIDs at boot time”
    Careful because “‘s don’t copy&paste very well, they had to be corrected after I pasted them.

    Cheers

  13. hi people, i have a massive problem at stage 3, right at the end part. I type:
    ___
    cat /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids
    40 34 31 27 23 15
    ___

    into the terminal, but it says that that directory doesn’t exist. I am really new to ubuntu, so please be patient to my idiotic questions.

    Any help would be appreciated. Thanks.

  14. Nice! We got a solution (thankx to Pedro) and now suddenly there is a new problem… For a couple of days it’s not possible anymore to use the PHC functionality :-(

    Using the intel-phc-undervolt script just stops with the following message:
    > ERROR: No CPU core capable of undervolting found.

    Before it worked fine. Seems like there’s something wrong with the latest PHC-Kernel… Anyone else experiencing the same story or even havong a solution?

    Greetings, Peter

  15. Hi people, at stage 4, where i have to run the script. The termal tells me that the processor is not capable of undervolting :S:
    Do you want to continue? [Y/n/?] Yes
    > ERROR: No CPU core capable of undervolting found.

    What is going on? I am really really really new to ubuntu, and would love some support.

    THanks in advance, Mike.

  16. Great article!

    Im using 34 23 16 11 5 0 on a Thinkpad X31 1.7Mhz if someone is curious or lazy ;)

  17. Hi to everyone! If someone have a problem like published by Ildom or Mike (Makefile detected your kernel version as 2.6.35
    ***FOUND AVAILABLE PATCHSET. PREPARING.***
    ./prepare.sh: line 12: patch: command not found) or Do you want to continue? [Y/n/?] Yes
    > ERROR: No CPU core capable of undervolting found.) I may give you a solution. The problem appears to be at the stage of patching – look at prepare.sh (“patch -p1 phc-intel.c inc/$1/linux-phc-0.3.2.patch”). I tried to run it in terminal – the problem revealed itself – no command “patch” has been installed (as I never used it before ever) – the system advised me to install it with a proprietary command (I don’t remember it exactly – something like apt-get patch). After that “make prepare” worked perfectly, make install-reboot – an everythig worked – Just try it…)))

  18. No way, it never worked for me, either on 10.04 or 10.10…. and in worked when I used windows….. make prepare ok, make ok, make install ok, but the folder cpufreq does not exist

    thank you anyway

  19. By the way, if anyone gets the error about “device or resource busy” when trying to load the module just after installation (I got it using both modprobe or insmod), reboot and try again. Worked for me.

  20. jama@jokonon:~/Downloads/phc-intel-0.3.2-12-1_2.6.36$ make prepare

    Makefile detected your kernel version as 2.6.35
    ***FOUND AVAILABLE PATCHSET. PREPARING.***
    patching file phc-intel.c

    jama@jokonon:~/Downloads/phc-intel-0.3.2-12-1_2.6.36$ sudo make install
    make -C /lib/modules/`uname -r`/build SUBDIRS= modules
    make[1]: Betrete Verzeichnis ‘/usr/src/linux-headers-2.6.35-24-generic-phc’
    CHK include/linux/version.h
    CHK include/generated/utsrelease.h
    make[2]: *** Keine Regel vorhanden, um das Target »kernel/bounds.c«,
    benötigt von »kernel/bounds.s«, zu erstellen. Schluss.
    make[1]: *** [prepare0] Fehler 2
    make[1]: Verlasse Verzeichnis ‘/usr/src/linux-headers-2.6.35-24-generic-phc’
    make: *** [phc-intel.ko] Fehler 2

    tried to download header and source again but nothing changed…

    finaly the

    cat /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids

    won’t find anything.

    Anyone a hint ?

    Thx so far!

  21. The command andrew used was

    sudo apt-get install patch

    this worked for me to get rid of the “line 12: patch: command not found” in step three using the “make prepare” command

    so run

    sudo apt-get install patch

    then

    make prepare

    and continue on. I hope this helps.

  22. sorry for the double post….this fixed the problem of using

    cat /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids

    where there was nothing found or no such directory.

  23. thx 4 help so far, but as u may see in my previose post. patch is sucessfully installed and working properly.
    make prepare works well finally sudo make install is not able to run properly because of

    make[2]: *** Keine Regel vorhanden, um das Target »kernel/bounds.c«,
    benötigt von »kernel/bounds.s«, zu erstellen. Schluss.
    make[1]: *** [prepare0] Fehler 2
    make[1]: Verlasse Verzeichnis ‘/usr/src/linux-headers-2.6.35-24-generic-phc’
    make: *** [phc-intel.ko] Fehler 2

  24. hallo – thanks for the wonderful guide.
    managed to undervolt my X31 Thinkpad to “24 18 10 5 1″ (absolute hardlimit).
    but i am curious how to get the rc.local configuration to work.
    i injected the necessary lines – but it wont start.
    are the rc.local files executed with user permissions?

  25. Are the patch links given in step 3 still good? The links show they’re tarball files but they download as php files which don’t extract (for me). They give:
    Could not open input file: file.php

    Any ideas?

  26. @jacko: execute as superuser by doing

    sudo su
    make prepare

  27. Woow, this guide is by far one of the best guides i followed in my 2 years with ubuntu ..
    Thank you :) ..
    My cpu is about 8degrees cooler at idle and 7 on full load! :) ..

  28. Thank you for that nice script to automatically find out the lowest values.

    But I encounter one small problem. When I run the script, I get the message that the governor is set to “userspace” with a beginning frequency of 2001000.

    Switch to ‘userspace’ scaling governor.
    [sudo] password for robert:
    > Success!
    Set frequency to 2001000.
    > Success!

    But when I check my current frequency there is not the same used. For any reason the settings were not adapted. First I thought there may be running something in the background but I don’t have any clue what it might be as I disabled the most suspicous candidates.

    Every 1,0s: cat /sys/devices/system/cpu/cpu0/cpufre… Fri Apr 1 22:45:35 2011

    2000000

    Could you help me out?

    Thank you in advance.

  29. Great tutorial. But is there a way to make the changes apply independently of PHC (ie change the default values so that it works when I boot in another OS?)

    I run dual-boot with windows and would like to enjoy the same undervolting but RMClock have not been updated for a long time, meaning undervolting is dead for windows users with current CPUs.

    Thanks for anything.

  30. Any news on Natty?

  31. Hi, anyone tried to use PHC on ubuntu 11.04?

    For me it worked somehow just fine, with the help of this page: http://www.linux-phc.org/forum/viewtopic.php?f=7&t=267
    but then, when trying to apply the new values I get the “Permission denied”-error from above again, but this time the solution by Pedro won’t help… Any other ideas?

    Greetz, Peter

  32. Hello! Great post and still useful in 2012 with phc 0.4 and linux kernel version 3.2:) However, I’ve found a problem while running your script.

    I don’t know the direct cause of this behavior but something overwrites CPU frequency settings that tweaking script tries to put in /sys/devices/system/cpu/cpuX/cpufreq/scaling_setspeed. As a result only the highest frequency is being tested.

    Instead of investigating power management software installed that is most suspected, my workaround for this is to change line 359 from:

    printf “${freq[$cur_pos]}” | sudo tee $i/scaling_setspeed > /dev/null

    to:

    printf “${freq[$cur_pos]}” | sudo tee $i/scaling_max_freq > /dev/null


Leave a comment

No trackbacks yet.