Optimizing KDE’s energy profiles

In my last posting, I mentioned that my notebook eats by far more battery when running Linux / KDE than running Windows 7. Even though I identified (and fixed) that this was due to the switchable graphics (both cards were running and sucking power), I was eager to optimize the power consumption. After some research, I came up with the following solution.

I put several energy-savign tweaks into a script, saved it to /usr/local/sbin/powersave.sh and added an entry in sudoers for it because it requires root privileges. I can run the script now with sudo but without having to enter the root password thus allowing the KDE energy manager Powerdevil to run the script automatically. Therefore, I added the following custom call to the Powersave profile in Powerdevil‘s settings:

sudo /usr/local/sbin/powersave.sh

This makes KDE call the optimizations automatically as soon as the notebook switches to the Powersave profile.

I adapted the optimizations to a max_performance.sh script that reverts all changes done by the powersave script. This script needs an entry in sudoers, too, and should be added to the Performance energy profile.

You find my scripts below. Please note, that you will most probably need to change some things in the scripts to make them fit your notebook, especially if you do not have a hybrid ATI graphics adapter or a CPU with 4 cores.

[UPDATE] Scripts re-uploaded because Pastebin.com lost them [/UPDATE]


 
 
 

23 Responses to “Optimizing KDE’s energy profiles”


  1. rakhmad
    21. July 2010 um 12:28

    after using those scripts, how does linux perform compare to windows 7? and which process consume most power?

  2. Andreas Demmer
    21. July 2010 um 12:36

    Now Linux consumes about 15W with low display brightness, deactivated display effects and enabled wireless. Windows 7 consumes about 13W with display effects. But this is pretty close, now.

    Most wakeups are caused by the i915 (graphics) and the wl (wireless) drivers. I read that the i915 has a bug in wakeups that can be worked around by deactivating DRI in xorg.conf. This should save some more watts. BUT it disables desktop effects permanently what makes me not doing this.

  3. Thorsten
    21. July 2010 um 14:51

    Thank you for the scripts, Andreas. Though I wonder why powerdevil doesn’t do all these things… :-(

  4. Ryan
    21. July 2010 um 15:52

    You should separate this into a series of script in /etc/pm/power.d/. That way, these settings would not depend on you having powerdevil running at the time. So they would work even if you’re not logged in, or logged in at the console for some reason.

    For example, /etc/pm/power.d/cpu-frequency-scaling:

    #!/bin/sh

    if [ "$1" = true ]; then
    GOVERNOR=”powersave”
    else
    GOVERNOR=”ondemand”
    fi

    for x in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
    echo “$GOVERNOR” > “$x”
    done

  5. Fri13
    21. July 2010 um 17:17

    Very nice post about powermanagement. Even the sudoers file editing is not needed (the top post), it was nice trick (perhaps even a hack?) to get wanted thing. Hopefully more people would know what to do with the sudo (even it is not so good for security, it makes things easier).

  6. drf
    21. July 2010 um 20:12

    @Thorsten: well, it actually does all of these things: that’s why I put the script feature in the first place. No other powermanager allows you to do such a thing.

    Btw, if you meant “by default”, the answer is: it will never do. These are quite hard powersaving settings which surely fit a lot of use cases, but IMHO are not suitable for a good default.

    Although, I might consider to install those scripts along with PowerDevil – that is surely possible.

    @Andreas: nice stuff, I’ll have to try them :)

  7. Freddie
    21. July 2010 um 20:21

    Why two separate scripts? Why not one script with a case or if statement at the top? Or even mixed into the body? Seems like a waste to have two separate scripts that do the same thing, just in reverse.

    Then you just pass in a parameter (fast/slow; or powersave/ondemand) on the command-line.

  8. Obi-Wahn
    21. July 2010 um 21:01

    Danke für das Skript. Ich habe seit ein paar Monaten einen Asus UL50VT, der schon sehnsüchtig auf ein Linux wartet. Ich wollte in den nächsten paar Tagen openSUSE 11.3 installieren und dann mal gucken, ob ich dein Skript bei mir anpassen kann. Es gibt für mich aber auch noch andere Möglichkeiten: https://launchpad.net/~asus-ul30

  9. michael
    22. July 2010 um 09:47

    hello, noob question here. What exactly do I need to put in sudoers to let the scripts work?

    I have a script of mine which i’d like to run, but if i put it in powerdevil it dooesn’t start and I need to start it manually every time.

    Now I understand why it doesn’t work, but could someone please tell me what I need to add to sudoers?

    Ty.

  10. Andreas Demmer
    22. July 2010 um 09:53

    First make your script executable. Then add it to sudoers with visudo (to not mess it up and break your installation). Add this line for each script:
    your_username ALL = NOPASSWD: /path/to/your/script.sh

    After this, you are able to excute “sudo /path/to/your/script.sh” without having to enter the root password.

    Be sure that this script is only writable for you and root to avoid security holes!

  11. michael
    22. July 2010 um 10:38

    many many thanks :)

  12. warnec
    22. July 2010 um 13:31

    For noobs, it’s best to try something like EDITOR=nano visudo so that they don’t get lost with vi ;)

    PS How is the energy draw with compositing on?

  13. warnec
    22. July 2010 um 13:33

    PPS are these tricks:

    powersave:

    #
    #
    # put HDDs to min_power mode
    #
    echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
    #
    echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
    #

    #
    # advice HDD to sleep after 5min idle
    #
    /sbin/hdparm -B 1 -S 60 /dev/sda
    #

    #
    # increase write cache time to 15s
    #
    echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

    max perf.:
    #
    #
    # put HDDs to max_performance mode
    #
    echo max_performance > /sys/class/scsi_host/host0/link_power_management_policy
    #
    echo max_performance > /sys/class/scsi_host/host1/link_power_management_policy
    #

    #
    # advice HDD to sleep after 60min
    #
    /sbin/hdparm -B 254 -S 242 /dev/sda
    #

    #
    # decrease write cache time
    #
    echo 500 > /proc/sys/vm/dirty_writeback_centisecs

    of any use for SSD?

  14. Andreas Demmer
    26. July 2010 um 09:18

    WARNING: I forgot to enable the DVD-drive polling when plugged again, resulting in the DVD drive not recognizing media automatically. To fix this, add the following call to the max_performance script:
    hal-disable-polling –enable-polling –device /dev/cdrom

  15. Elaina Zelenka
    29. July 2010 um 22:25

    Hey there’s one bug with the site on OPera the sidebar is weird :/

  16. Marci
    10. September 2010 um 19:12

    would you post again your script?
    I can’t visit the pastebin page.
    thanks

  17. Marco
    10. September 2010 um 19:31

    I’m usable view the scripts, there’s a problem with pastebin.
    please share them again?
    thanks

  18. Andreas Demmer
    17. September 2010 um 13:39

    Since it seems that Pastebin.com has lost my scripts, I uploaded them to my own server again.
    Powersave
    Performance

  19. Björn
    16. October 2010 um 13:02

    Hallo Andreas!
    Ich habe ein Acer-Notebook mit ähnlicher Ausstattung und versuche gerade den Stromverbrauch unter KDE zu verringern, dabei bin ich auf Deine Seite gestoßen und habe so einige Informationen davon verwenden können. :) Was mich mal interessieren würde, was ist bei Dir die Ausgabe von
    “cat /proc/acpi/processor/CPU0/throttling”? Bei mir steht immer folgendes, egal ob ich den powersafe-Governor aktiviere oder nicht:

    state count: 8
    active state: T0
    state available: T0 to T7
    states:
    *T0: 100%
    T1: 87%
    T2: 75%
    T3: 62%
    T4: 50%
    T5: 37%
    T6: 25%
    T7: 12%

    Das würde doch heißen, dass der Prozessor immer noch auf 100% Geschwindigkeit läuft oder? Wie sieht das bei Dir aus?

    Grüße,
    Björn

  20. Andreas Demmer
    17. October 2010 um 11:30

    Tatsächlich entspricht meine Ausgabe im Stromsparmodus Deiner Ausgabe. Allerdings bestätigt mir powertop, dass die CPU im gedrosselten Modus läuft:

    P-states (frequencies)
    C0 (cpu running)        ( 0.0%)       Turbo Mode     0.0%
    C0               10.9ms ( 0.4%)         2.40 Ghz     0.0%
    C1 mwait          1.5ms (13.1%)         2.27 Ghz     0.0%
    C3 mwait          3.3ms (107.7%)        2.14 Ghz     0.0%
                                            1199 Mhz   100.0%
    
  21. Cyrus
    28. December 2010 um 07:39

    Just wanted to chip in here that with my setup I had to start my own scripts with a brief pause (sleep 5) for my power saving script parameters to go into effect. I suspect Power Devil was making its own adjustments to the same items I was making adjustments. Vice versa (From Battery to AC Adapter) it worked just fine, no need for a pause.

  22. John
    13. March 2011 um 02:27

    Hi,

    What exectly is in /usr/local/sbin/switch_ati_off.sh?

    John

  23. Andreas Demmer
    15. March 2011 um 15:56

    This script turns the discrete ATI card off and works only with hybrid graphics.

Leave a Reply