Skip to content

Instantly share code, notes, and snippets.

@krezreb
Last active June 23, 2024 17:47
Show Gist options
  • Save krezreb/b1dbb790e04016f521360600edd747c6 to your computer and use it in GitHub Desktop.
Save krezreb/b1dbb790e04016f521360600edd747c6 to your computer and use it in GitHub Desktop.
linux power management notes

notes for setting up power management under ubuntu 22.04 (kernel 5.15) on a dell xps

I am a developer and system admin. I have a LOT of browser tabs, lots of terminals open, as well as vscode and MS Teams. YMMV but as far as I can tell, the "best" balance of power savings (long battery life) vs maching usability is using tlp and tlpui. This gives approx 5 - 6 hours of battery life on my workload.

I am running an INTEL processor, the below does not apply to AMD

TL;DR

Default, out of the box power management in linux is still not mature. Use tlp for power management when using intel processors (scroll to bottom for instructions)

what I have tried

gnome power saving

As of this writing, gnome power management doesn't have a separate setting for AC power and battery. So if you set it to power saving, then plug it in, you'll have to manually change the setting in the menu to performance or balanced, which kind of goes against the whole point of the damned thing.

auto-cpufreq / acpid

acpi is the scaling driver available before intel pstates was published (and the default driver for AMD silicon). I allows fine grained control of your cpus' max and min frequencies. However, it is not as good as the intel driver at scaling up and down. I tried it out, told the cpu to scale way down to stay cool and save battery, but the system became jittery and practically unusable. To my surprise, this slowness and jitteryness did NOT translate to better battery life. I believe this to be due to the traffic jams caused by the various processes fighting for the limited cpu power, thus taking longer to run, thus burning watts nonetheless.

takeaways

Use the default intel pstate driver when running intel silicon gives the best results. This driver has multiple levels of ways to save power while still allowing the system to be usable, and it's kinda complicated. It's clearly explained here if you have 5 hours to spare.

In a nutshell, intel pstate:

  • has fewer governors, but you really only need to use powersave (even when plugged in)
  • does not allow you to cap the cpu frequency
  • allows you to cap the cpu percentage via CPU_PERF
  • allows you to set and energy policy via CPU_ENERGY_PERF_POLICY, and this parameter is key to saving power when running battery

setting up tlp

disable default gnome power saving to avoid conflict with tlp

systemctl disable power-profiles-daemon 
systemctl mask power-profiles-daemon

disable thermald

systemctl disable thermald
systemctl mask thermald

these instructrions were graciously stolen

From here and here

install tlp

add-apt-repository ppa:linrunner/tlp
apt update
apt install tlp tlp-rdw

install the tlp gui

add-apt-repository -y ppa:linuxuprising/apps
apt update
apt install tlpui

setup

Run tlp gui as root

tlpui

  • CPU_SCALING_GOVERNOR = powersave for both AC and BAT (to avoid the fans from spinning up as soon as I plug it in
  • CPU_SCALING_FREQ, ignore
  • CPU_ENERGY_PERF_POLICY = power for both AC and BAT
  • CPU_MIN_PERF_ON_AC = 0
  • CPU_MAX_PERF_ON_AC = 100
  • CPU_MIN_PERF_ON_BAT = 0
  • CPU_MAX_PERF_ON_BAT = 30
  • PLATFORM_PROFILE_ON_AC = balanced # this allows the machine to run fast and smooth, and silently on ac
  • PLATFORM_PROFILE_ON_BAT = low-power

You can also enable power saving for usb and pci.

nvidia graphics

The cpu is the top energy consumer on a laptop, but the graphics card(s) are a close second. On an nvidia card, you can reduce power consumption by running prime-select on-demand or even prime-select intel to only use the built in intel card

YMMV & things change

The above setup took many long hours to figure out. I've used linux for years, but until 2019 I hadn't spent time figuring out battery life on laptops (was mostly using servers, and always pluggin my laptop into the socket).

Kernel v5.19 has just been announced with lots of power management improvements, which may render the above settings useless. I am also still wondering why thermald needs to be disabled when running tlp. Perhaps tweaking thermald settings can reach better results than tlp can. I have spent enough time on the subject for time being, and I remain disappointed that Ubuntu doesn't offer good power mangement settings that truly work, out of the box.

@ipeacocks
Copy link

@krezreb
Copy link
Author

krezreb commented May 30, 2022

Have you tried https://extensions.gnome.org/extension/945/cpu-power-manager/ ?

Tried it just now, screenshots look pretty good. However, it's not yet updated for gnome 42/ubuntu 22.04 so couldn't get it working. This has been my experience with gnome extensions in general, when they work they can be great (I use the bluetooth and sound selection extensions) but they tend to break easily, either because of a change in gnome or because the extension author wrote buggy code.

@ipeacocks
Copy link

ipeacocks commented May 30, 2022

I know that it's a bit complicated but try code from master https://github.com/deinstapel/cpupower#installing-for-another-admin-user

@d3vilguard
Copy link

Gave auto-cpufreq a try, gave your guide a try. In both instances the system just becomes slow. Painfully slow. tlp being a bit better than auto-cpufreq. That's on a dell latitude 3301 with an i5 auto-cpufreq. At this point I think that the default "powersave" of intel_pstate is good enough. One can just manually stop turbo via terminal on battery if doing very light work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment