Ubuntu Laptop Battery Life
I have a Lenovo Thinkpad X1 Carbon 5th gen (2017). Its battery seemed to totally crap out this year, so I ordered a replacement battery, but right after clicking “buy,” I started poking around the power utilities on Ubuntu. I started to get the feeling that the battery wasn’t actually that much worse than when I first got it – utilities showed that the charge could reach 80% of what it used to. That made me wonder if there was some software-based issue that was killing my battery.1
Battery life on Linux-based laptops has always been garbage: from the day I got the laptop, it would last 8+ hours when I booted Windows, but only a few hours on Ubuntu. To make matters worse, for the longest time my laptop would not sleep correctly. It still only does so intermittently; every so often I close the laptop lid and come back to find my laptop battery drained. I haven’t diagnosed what situations result in this, but you can imagine this is quite annoying and I have to keep everything saved and just expect that my laptop could be dead if I put it to sleep.
Anyway you might say “just use windows” but tbh it’s gonna be a nah from me dawg.2 So here I am in 2021 still debugging the effing linux desktop.
Here’s what I learned:
sudo snap install auto-cpufreq
TL;DR install this package, thensudo auto-cpufreq --install
to install its daemon. Basically someone noticed that bare-minimum power optimizations were not being made, and wrote software to do simple things like turn off intel’s TurboBoost which chews through your battery. You can then runsudo auto-cpufreq --stats
for a monitor that tells you nice things like what energy profile is being used (e.gbalance_power
) and what power driver is being used (e.gintel_pstate
). This package alone improved my batterylife dramatically: I did a load test and even under load my battery life is back up to ~4 hours, up from 30min-1 hour prior to installing this package.- TLP is a super cool package you can use to optimize power on Ubuntu. TLP stacks with
auto-cpufreq
. sudo apt install powertop
« this package is liketop
, but shows which processes are waking up the CPU/GPU, what the battery discharge rate is, and what the total power consumed is.
The other thought I had was: maybe these tools will help me reduce my desktop’s energy footprint as well. I might update here with findings. My desktop tends to be doing some computionally intensive thing, whether it’s transcoding videos or processing Dark Forest zk-SNARKs.
-
I ended up swapping the battery after realizing the software-based battery life gains. X1 Carbon Gen5 battery swap is super easy: a total of 9 screws! If only modern hardware were this easy to repair. ↩
-
Yeah, I’m gonna upgrade to a MBP next year. Four years ago I thought “surely Linux laptops are usable now” – I don’t know what I was expecting. ↩