Help! My GPU is eating my battery!
As an attempt to reignite my love for programming, I started taking my linux laptop (XPS 9570) with me and code in cosy places that inspire me.
To my surprise, that was an extremely short novel since my battery died after two hours!
After throwing out a bunch of WTFs it was time to dig in.
It's an old laptop so the first suspect was the battery. I ran upower and indeed, the battery lost some of its capacity:
upower -i /org/freedesktop/UPower/devices/battery_BAT0
native-path: BAT0
...
energy-full: 69.9276 Wh
energy-full-design: 97.0026 Wh
...~70% of the original capacity but it should be enough for ~6 hours of random terminal usage and browsing.
The same command had some other disturbing number:
upower -i /org/freedesktop/UPower/devices/battery_BAT0
...
energy-rate: 32.1204 W
...The laptop is doing absolutely nothing.. why does it need 32W/Hour?!?!
I ran powertop and saw that the Nvidia GPU is on - even though I wasn't running anything that requires an actual GPU and the internal (efficient) Intel integrated GPU could handle the GPU tasks just fine.
One google search later, I found the command that toggles the GPU on or off ("prime-select") and shut down the Nvidia GPU completely when running on battery power.
upower -i /org/freedesktop/UPower/devices/battery_BAT0
...
energy-rate: 14.2418 W
...That's half the depletion rate and it means ~4.5 Hours of on the road coding!
But since I already entered this rabbit hole, why not go all the way. I found another app that helps optimizing the laptop settings for lower battery usage:
https://github.com/Slimbook-Team/slimbookbattery.
upower -i /org/freedesktop/UPower/devices/battery_BAT0
...
energy-rate: 9.7120 W
...7 Hours of laptop usage! (we started with two hours)
But there was a hidden cost - when my laptop went to sleep, it wouldn't come back from sleep - manageable but annoying :\
Good thing that the good folks of Arch linux tackled the same issue already and found out that my laptop has some weird default battery configuration (the "modern" sleepmode is actually pretty bad and can cause random behavior)
After changing the suspend method as instructed by this guide, the side-effects were gone and my laptop was back!
Let's sum this up:
Laptop battery usage went up from ~2.5 Hours to ~7 Hours.
Time spent in process - ~5 Hours.
Fun gauge - over 9000!
Bonus - I'm a little happier every time I'm on the go and open my laptop 😎