Linux Laptop Power Tuning with Powertop and Friends

TuxOxygen480-status-battery-charging-060.svgThere’s an easy way to reduce power usage on Linux laptops using Intel’s Powertop utility.  Powertop polls your existing power usage and recommends tunings for your hardware.  I’ll show you how to quickly make the most of your battery life using this tool as well as tuned and cpufreq.

Install Powertop
I’m using Fedora for these examples, but most distributions will have this available – adjust as needed.

dnf install powertop -y

Note Normal Pre-tune Power Usage
Run powertop to see normal power usage, make sure you are not connected to a power source.



Poll Usage and Record
Next you’ll want to run powertop with the –calibrate and –html flag while not connected to a power source.  Note that –calibrate will disconnect you from wifi temporarily and you might see some screen flickering.

powertop --calibrate
powertop --html

You’ll see some output like below, when it’s completed you’ll have a powertop.html file wherever you ran the program.

Loaded 750 prior measurements
 RAPL device for cpu 0
 RAPL Using PowerCap Sysfs : Domain Mask f
 RAPL device for cpu 0
 RAPL Using PowerCap Sysfs : Domain Mask f
 RAPL device for cpu 0
 RAPL Using PowerCap Sysfs : Domain Mask f
 Devfreq not enabled
 Preparing to take measurements
 unknown op '{'
 Taking 1 measurement(s) for a duration of 20 second(s) each.
 PowerTOP outputing using base filename powertop.html

Output and Recommendations
Point a browser to the powertop.html file and you’ll see things like status, power usage, processes using the most power and lastly tuning.  The tuning tab is what we’ll focus on.



Apply Tuning Recommendations
There’s several options you can pursue here.  You can either manually copy/paste the tuning recommendations from the generated HTML tunings above or you can use lynx and a bit of sed to spit them out and apply them all.  Lastly, you can just set powertop to use the –auto-tune feature (though you’ll need to run it at boot everytime).  It’s best to review them all prior.

Note: you might want to forgo any USB suspend options if you use an external keyboard or mouse as USB is always slow to resume and this causes issues for some people.

Option #1 – Apply Tuning Recommendations Permanently

In this example I’ll show all tunings in an easy, copy/paste fashion to make the most of your time.

Convert HTML to TXT

lynx -dump -width 200 powertop.html > powertop.txt

Strip out Recommended Power Tunings

cat powertop.txt | sed 's/^.*echo/echo/' | \
sed 's/^.*ethtool/ethtool/' | egrep -B3 "echo|ethtool|hdparm" \
| egrep -v "Software|Description|Script" > /tmp/tuning.txt

Now review what’s been captured, you can paste these them all to apply them or choose individually as you prefer.

cat /tmp/tuning.txt | less

Note the tuning recommendations..

echo '1500' > '/proc/sys/vm/dirty_writeback_centisecs';
echo '1' > '/sys/module/snd_hda_intel/parameters/power_save';
echo '0' > '/proc/sys/kernel/nmi_watchdog';
echo 'auto' > '/sys/bus/i2c/devices/i2c-3/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-4/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-1/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-2/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';
echo 'auto' > '/sys/bus/usb/devices/8-1/power/control';
echo 'auto' > '/sys/bus/usb/devices/3-2/power/control';
-- snip --

Review the tunings.
If you like how this looks, you can also make a script to apply it all instead of pasting it.

echo '#!/bin/bash' > /tmp/
cat powertop.txt | sed 's/^.*echo/echo/' | sed \
's/^.*ethtool/ethtool/' | egrep -B3 "echo|ethtool|hdparm" \
| egrep -v "Software|Description|Script" >> /tmp/

Run the Script

chmod +x /tmp/
sh /tmp/

Option #2 – Auto Tune
Powertop provides the option to simply apply all the recommended settings for you, but they will be lost on boot.

powertop --auto-tune

Persist after boot
You can use the following systemd unit file to simply make powertop a systemd-controlled service

cat > /etc/systemd/system/powertop.service << EOF
Description=Powertop tunings

ExecStart=/usr/sbin/powertop --auto-tune

systemctl enable powertop

Running Powertop
You can run powertop manually at any time to get a feeling for your battery usage.  It might be a good idea to see before/after improvement.  For comparison I get an average of 6 to 8W of power usage under a normal workload on my Lenovo x240 running Fedora 22 on Kernel 4.2.7.  I believe I average around 6-9W, down from 10-12W with no tuning – quite an improvement!  I see larger gains on the more recent Intel chipsets, due in part to some power-savings improvements both in the CPU as well as the Linux kernel.


Tuned: Further Savings
You can also use a tuned profile to provide additional power management savings.

Install tuned and Profiles

dnf install tuned-profiles-compat tuned -y

Enable Tuned and Set Profile

systemctl enable tuned.service
systemctl start tuned.service
tuned-adm profile laptop-battery-powersave

You can list other profiles available and see what works best, just “powersave” is good too.

tuned-adm list

Alternative to tuned profiles
There is also a command called powertop2tuned that will generate a tuned profile based directly on your powertop –html output, you can specify an existing html file or run it without options and it will create one.  I just use the laptop-battery-powersave tuned profile instead.  Below is an example where powertop-settings is the new tuned profile you’d want to use.

powertop2tuned powertop-settings
Running PowerTOP, please wait...
Generating shell script /etc/tuned/powertop-settings/
Generating Tuned config file /etc/tuned/powertop-settings/tuned.conf

Now apply the tuned profile based on powertop settings, you’d use what you named it above.
More info can be found here.

tuned-adm profile powertop-settings

Cpufreq – Further Tuning
Lastly, you will want to enable cpufreq so you can have CPU frequency scale up and down based on demand – this will save a noticable amount of power basd on the powersave profile.

Install cpufreq-utils

dnf install cpufreq-utils -y

Use Powersave Options

cpupower frequency-set -g powersave

Check your settings

cpupower frequency-info
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency set by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 800 MHz - 3.30 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 3.30 GHz.
                  The governor "powersave" may decide speed to use
                  within this range.
  current CPU frequency is 800 MHz (asserted by call to hardware).
  boost state support:
    Supported: yes
    Active: yes

Note: in later versions of the Linux Kernel this is built in via the cpupower command.

cpupower frequency-set --governor powersave

That’s it, no system service as it’s built into the kernel.

cpupower frequency-info
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 10.0 us
hardware limits: 1.60 GHz - 2.26 GHz
available frequency steps: 2.26 GHz, 2.26 GHz, 2.13 GHz, 2.00 GHz, 1.86 GHz, 1.73 GHz, 1.60 GHz
available cpufreq governors: conservative userspace powersave ondemand performance schedutil
current policy: frequency should be within 1.60 GHz and 2.26 GHz.
The governor "powersave" may decide which speed to use
within this range.
current CPU frequency: 1.60 GHz (asserted by call to hardware)
boost state support:
Supported: yes
Active: yes
2400 MHz max turbo 4 active cores
2400 MHz max turbo 3 active cores
2533 MHz max turbo 2 active cores
2533 MHz max turbo 1 active cores

Kernel GPU Savings Options (NOTE i915 chipset only)
I also use the following kernel options for my laptop, a Lenovo x240 using the Intel i915 chipset.  These settings won’t work for everyone so research them before applying.  If you’re not sure skip over this part.

  • file: /etc/default/grub
  • Note: this is a snippet, so make sure to append this only to your existing grub settings.
--snip append to your grub entry --
GRUB_CMDLINE_LINUX="drm.debug=0 drm.vblankoffdelay=1 
i915.semaphores=1 i915.modeset=1 i915.use_mmio_flip=1 
i915.powersave=1 i915.enable_ips=1 i915.disable_power_well=1 
i915.enable_hangcheck=1 i915.enable_cmd_parser=1 i915.fastboot=0 
i915.enable_ppgtt=1 i915.reset=0 i915.lvds_use_ssc=0 
i915.enable_psr=0 vblank_mode=0 i915.i915_enable_rc6=1"
--snip append to your grub entry --

Like usual, to apply grub changes run the following command and reboot:

grub2-mkconfig -o /boot/grub2/grub.cfg

Additional i915 Only Tunings (Lenovo x240 or similiar)
You can also pre-blacklist some modules not really needed often and force some power savings i915 kernel module options like below.  These seem to further help power savings for the GPU.  Note some of these are duplicated in the above kernel boot options, but we’ll force them anyways for modprobe as well for good measure.

cat > /etc/modprobe.d/x240-i915.conf << EOF
options i915 i915_enable_rc6=1 i915_enable_fbc=1 lvds_downclock=1
options iwl_wifi power_save=1 power_level=3 bt_coex_active=0 11ndisable=1

blacklist sierra_net
blacklist cdc_mbim
blacklist cdc_ncm
blacklist btusb

Update: 2018-04: I cannot validate that these settings will work for you and I don’t currently need them on my 7th gen i5-7300U Kabylake (Lenovo x270) but I’m leaving them here for posterity.

Further Power Savings Tips
In general the following tips apply to conserving battery:

  • Don’t use max brightness, this seems to usurp a lot of battery power.
  • Unplug your laptop when it’s fully charged, in general this prolongs the battery lifetime.
  • Use a blank screensaver.
  • Disable your ethernet kernel module if you don’t use it often, I do this via rc.local:
touch /etc/rc.d/rc.local
echo '#!/bin/bash' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
echo 'rmmod e1000e' >> /etc/rc.local
systemctl enable rc-local.service

Some readers over at the r/linux subreddit have pointed out that TLP is a good alternative tool to, or to be used in conjunction with powertop.  I’ve not tried it yet, being happy with my power savings from the above approach but please post in comments if you have any suggestions and I’m happy to merge them here.  Both TLP and powertop will make the same settings, but I prefer to use the powertop approach as it’s usually best to understand/review everything you’re changing before making any changes to the system.

Current Savings: 2018
It’s been a few years since I wrote this guide but I’m still using the same settings on my Lenovo x270 running Fedora 27 (as of typing this).

Before tuning I got around 10-12 hours of battery life with the extended battery for normal usage with no tuning, now I’m getting around 16-18hrs out of the same battery.

Things like video conferencing (Bluejeans, Skype, Hangouts, Viber) will drain your battery but for normal everyday usage I’m averaging around 6-10W of power.

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , , , , , . Bookmark the permalink.

7 Responses to Linux Laptop Power Tuning with Powertop and Friends

  1. Unbelievable. As dirty as it made me feel, I kept thinking to myself “maybe I should just get a mac” for the sole reason of power consumption and battery life. Until I implemented the changes you’ve outlined here, on my Fedora 23 installation on Lenovo T430s running xfce+kwin I was running at about 186F / 85C, and a powertop reported battery discharge rate of 25W. I’ve since cut that in half to between 12-14W, and a much cooler running temprature of 125F / 52C.

    Liked by 1 person

  2. JJ says:

    I can’t run the dnf command in Ubuntu, as I understand, that is only for Fedora. Is there an alternative command for Ubuntu? Sorry, I am a complete Linux noob.


    • Will Foster says:

      I can’t run the dnf command in Ubuntu, as I understand, that is only for Fedora. Is there an alternative command for Ubuntu? Sorry, I am a complete Linux noob.

      Hey JJ – not to worry, apt-get install should work instead.


  3. pooppoop123 says:

    I’m averaging around 6-10W of power.I’m getting around 16-18hrs
    16 x 10w = 160Wh battery. 18*6 = 108Wh battery
    Powertop is pretty magical.


  4. jonzi says:

    I’m trying to build the auto-tune script in Option 1, but the first call to grep “grep -B3 “echo|ethtool|hdparm” ” doesnt return anything, and as a result tuning.txt is empty. Incidentally, “grep -v “Software|Description|Script” ” returns whatever was piped to it, as if I didn’t have that command there.

    Using Linux Mint 19. Any pointers?


  5. Karkan says:

    Could you please make a detailed video on this? I am not running fedora. I am running an ubuntu based Distro. I have followed all the steps and got it working just fine, but I am still consuming 17-30 w. The early steps are very confusing where you start converting to HTML all the way to installing the tuned files (I have managed to install the tuned-GUI and got it working). I got lost there. I got the cpupower and and cpuutils all setup. I hope I didn’t confuse you, but a video would be much much much appreciated. Thank you


    • Will Foster says:

      Hey @Karkan, I wouldn’t worry about the nailing the commands at the beginning of the guide, running powertop with the autotune option is going to do this for you, I’d just set this to start on boot.

      See the area “Option #2 – Auto Tune”

      This should set you straight on powertop if the munging of HTML output into values is troublesome – no need for a video I think yet.


Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.