ThinkPad x220t power saving in Fedora 16/17/19

A script to enable laptop power saving features for Fedora.

We are going to take advantage of a pm-utils feature: any script placed in /etc/pm/power.d/ will automatically run when the AC power is connected or disconnected.

To install the script you only have to copy it to /etc/pm/power.d/:

[chris@thinkpad Downloads]$ sudo mv thinkpad-powersave.sh /etc/pm/power.d/

At the moment I get around 5 hours (update: 8 hours) battery live when reading a PDF and making notes with Xournal on my Lenovo ThinkPad X220T.

[chris@thinkpad ~]$ uname -r
3.9.0-301.fc19.x86_64

The battery reports a discharge rate of 11.8 W and all tunables are marked as good in powertop.

To start / stop it run:

[chris@thinkpad ~]$ sudo sh thinkpad-powersave.sh true
[chris@thinkpad ~]$ sudo sh thinkpad-powersave.sh false

You may also try to run:

[chris@thinkpad ~]$ sudo pm-powersave false
[chris@thinkpad ~]$ sudo pm-powersave true

to see if t works.

To check that the script is running, and to see any errors run:

[chris@thinkpad ~]$ cat /var/log/pm-powersave.log

The script

#!/bin/sh
# List of modules to unload, space seperated. Edit depending on your hardware and preferences.
# In modlist you can put a list of modules to automatically load and unload. The uvcvideo entry will disable most webcams.
# Remove this if you want to use your webcam on battery without having to sudo modprobe uvcvideo first.
# e1000e belongs to my wired network adapter
modlist="uvcvideo videodev media e1000e"

# Bus list for runtime pm. Probably shouldn't touch this.
buslist="pci i2c"

# spindown time for HD (man hdparm for valid values)
# I prefer 2 hours for acad and 2 min for batt
ACAD_HD=244
BATT_HD=24

# Power management level
# 255 (off) on AC
# 128 (medium) on batt
ACAD_PM=255
BATT_PM=96

case "$1" in
    true)
      logger "Start powersave"
      # Enable some power saving settings while on battery
      # Enable laptop mode
      echo 5 > /proc/sys/vm/laptop_mode
      # Less VM disk activity. Suggested by powertop
      echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
      # Intel Audio power saving
      # maybe you have to mute some channels, or stop multimedia apps that your audio controller can turn itself off
      echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
      echo 1 > /sys/module/snd_hda_intel/parameters/power_save
      # Set backlight brightness to 50%
      # find /sys -iname brightness
      # echo 5 > /sys/devices/virtual/backlight/acpi_video0/brightness
      echo 2 > /sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness
      # Disable NMI wathcdog. Suggested by powertop http://www.mjmwired.net/kernel/Documentation/nmi_watchdog.txt
      echo 0 > /proc/sys/kernel/nmi_watchdog
      #echo disable > /proc/acpi/ibm/bluetooth
      #echo disable > /proc/acpi/ibm/wan
      echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
      echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
      ethtool -s em1 wol d

      # enable wlan0 power saving
      #iwconfig wlan0 power on

      # rfkill - tool for enabling and disabling wireless devices
      # run "rfkill list" to list the current state of all available rfkill-using devices
      # run "man rfkill" for more info
      # block index|type : Disable the device corresponding to the given index. type is one of "all", "wifi", "wlan", "bluetooth", "wwan", ...
      # rfkill block bluetooth
      #rfkill block all
      rfkill block wifi
      rfkill block wlan
      rfkill block bluetooth

      logger "Setting HD spindown for BATT mode with hdparm -S $BATT_HD /dev/sda."
      hdparm -S $BATT_HD /dev/sda > /dev/null 2>&1
      logger "Setting HD powersaving for BATT mode with hdparm -B $BATT_PM /dev/sda."
      hdparm -B $BATT_PM /dev/sda > /dev/null 2>&1

      cpupower frequency-set -g powersave
      # USB powersaving
        for i in /sys/bus/usb/devices/*/power/autosuspend; do
            echo 1 > $i
        done
        for i in /sys/bus/usb/devices/*/power/level; do echo auto > $i; done
      # SATA power saving
        for i in /sys/class/scsi_host/host*/link_power_management_policy; do
            echo min_power > $i
        done
      # Disable hardware modules to save power
        for mod in $modlist; do
            grep $mod /proc/modules >/dev/null || continue
            modprobe -r $mod 2>/dev/null
        done
      # Enable runtime power management. Suggested by powertop.
        for bus in $buslist; do
            for i in /sys/bus/$bus/devices/*/power/control; do
                echo auto > $i
            done
        done
    ;;
    false)
      logger "Stop powersave"
      # Return settings to default on AC power
        echo 0 > /proc/sys/vm/laptop_mode
        echo 500 > /proc/sys/vm/dirty_writeback_centisecs
        echo N > /sys/module/snd_hda_intel/parameters/power_save_controller
        echo 0 > /sys/module/snd_hda_intel/parameters/power_save
        # echo 10 > /sys/devices/virtual/backlight/acpi_video0/brightness
        echo 15 > /sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness
        echo 1 > /proc/sys/kernel/nmi_watchdog
        #echo enable > /proc/acpi/ibm/bluetooth
        #echo enable > /proc/acpi/ibm/wan

        # rfkill unblock bluetooth
        rfkill unblock all

        logger "Setting HD spindown for AC mode with hdparm -S $ACAD_HD /dev/sda."
        hdparm -S $ACAD_HD /dev/sda > /dev/null 2>&1
        logger "Setting HD powersaving for AC mode with hdparm -B $ACAD_PM /dev/sda."
        hdparm -B $ACAD_PM /dev/sda > /dev/null 2>&1

        # use sudo cpupower frequency-info for available cpufreq governors
        cpupower frequency-set -g performance
        #iwconfig wlan0 power off
        for i in /sys/bus/usb/devices/*/power/autosuspend; do
            echo 2 > $i
        done
        for i in /sys/class/scsi_host/host*/link_power_management_policy
            do echo max_performance > $i
        done
        for mod in $modlist; do
            if ! lsmod | grep $mod; then
                modprobe $mod 2>/dev/null
            fi
        done
        for bus in $buslist; do
            for i in /sys/bus/$bus/devices/*/power/control; do
                echo on > $i
            done
        done
    ;;
esac

exit 0

Download the script: thinkpad-powersave.sh

Some tips

Other useful programs: powertop, thinkfan, hdapsd.

I’ve experimented a little bit with my thinkfan‘s configuration and now I think I have a good balance between fan noise, power usage and cpu temperature, my /etc/thinkfan.conf looks like this:

sensor /sys/class/hwmon/hwmon0/temp1_input
(0,     0,      55)
(1,     50,     61)
(2,     52,     63)
(3,     56,     65)
(4,     59,     66)
(5,     63,     70)
(7,     65,     32767)

For more information about thinkfan have a look at its README-file inside the source tarball and visit http://www.thinkwiki.org/wiki/How_to_control_fan_speed.

And some more tips from lesswatts.org/tips/disks.php:

Use the - option in /etc/syslog.conf or /etc/rsyslog.conf

Add a - in front of this line:

*.info;mail.none;authpriv.none;cron.none  /var/log/messages

like this:

*.info;mail.none;authpriv.none;cron.none   -/var/log/messages

Update

As seen here:

Edit /etc/default/grub and add i915.i915_enable_rc6=1 pcie_aspm=force:

sudo vim /etc/default/grub

GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 rd.luks.uuid=luks-2b38bb0c-9787-4ef3-8803-7af548660aac $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :) vconsole.keymap=de rhgb quiet i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1 pcie_aspm=force slub_debug=-"
GRUB_DISABLE_RECOVERY="true"
GRUB_THEME="/boot/grub2/themes/system/theme.txt"

And then run sudo grub2-mkconfig -o /boot/grub2/grub.cfg to update your grub.conf

My battery monitor reports now nearly 8 hours remaining:

KDE battery monitor

And powertop says: “The battery reports a discharge rate of 8.40 W”, “System baseline power is estimated at 6.57 W”.

pwertop

An alternative: http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html

I don’t have the time to write complete HOWTO’s so feel free to ask questions and make comments ...