2X the Battery Life for Your Linux Laptop

January 27, 2020

Introduction

Recently I my old laptop decided it didn't want to charge anymore so I replaced my old laptop with an XPS 15. Because linux doesn't have as good a built in battery optimization solution as windows, installing a linux OS on a laptop often decreases its battery life by a significant amount, especially if your laptop has a dedicated GPU. So here I will show a few tips that helped double my XPS 15's battery life.

Battery Life Optimization

TLP

For those who don’t know what TLP is:

TLP brings you the benefits of advanced power management for Linux without the need to understand every technical detail. TLP comes with a default configuration already optimized for battery life, so you may just install and forget it. Nevertheless TLP is highly customizable to fulfil your specific requirements.

All you need to do is install:

  1. tlp
  2. tlpui

You can tweak some settings in tlpui, but the default settings work nicely for me.

Powertop

Why do I need powertop?

Although TLP is pretty nice, if your laptop has a dedicated GPU, you definitely need powertop, as it has this functionality:

Runtime PM for PCI Device NVIDIA Corporation Device

Basically what is does is it turns off the GPU when it's idling. This feature alone reduces the power consumption of my laptop from around 20 W to less than 10 W, bringing the battery life from 5 hours to over 10 hours. MASSIVE improvement.

How to set it up

First, install powertop

In powertop, you can enable/disable its battery optimization functionalities, but they don’t last through reboots, so you have to turn them on every time you restart your laptop. Fortunately, you can use systemctl to enable a service to do the trick automatically for you. Here’s how you can do it:

As root, create and edit a file like /usr/lib/systemd/user/powertop.service.

The contents should be:

[Unit] 
Description=Powertop tunings

[Service] 
Type=oneshot 
ExecStart=/usr/bin/powertop --auto-tune

[Install] 
WantedBy=multi-user.target

(May be /usr/sbin/powertop in some distros, run which powertop to see which.) Then enable it with

sudo systemctl enable /usr/lib/systemd/user/powertop.service

Reboot, and you should see the NVIDIA card optimized in Powertop. (Some optimizations may stay in ‘bad’ state but that’s not really an issue).

Undervolting CPU

Why you should unvervolt your CPU

Undervolting both increases battery life and lowers your CPU temperature, reducing CPU throttling and increasing performance. Yes, as counterintuitive as it sounds, undervolting actually increases performance. So the real question is, why not?

Is undervolting dangerous

No. Undervolting will not damage your CPU. You might experience a few blue screens if you go too far on undervolting, but that won’t damage your CPU, and once you find the right amount of undervolting your cpu can handle, you computer will run normally.

How to

  1. Install intel-undervolt
  2. Edit /etc/intel-undervolt.conf (Each CPU can take a different amount of undervolting, so experiment and find the right offset)
    For example, I unvervolted my CPU and CPU cache by 140mV
undervolt 0 'CPU' -140
undervolt 1 'GPU' 0
undervolt 2 'CPU Cache' -140
undervolt 3 'System Agent' 0
undervolt 4 'Analog I/O' 0
  1. run intel-undervolt apply
  2. Once you’ve found the sweetspot(the maximal amount of undervolting your CPU can handle while staying stable), you can enable the undervolting settings so it automatically applies on every startupsystemctl enable --now intel-undervolt.service

Subscribe to my email list

© 2024 ALL RIGHTS RESERVED