Skip to content

Latest commit

 

History

History
113 lines (66 loc) · 6.15 KB

power.md

File metadata and controls

113 lines (66 loc) · 6.15 KB

Linux Power / Energy Savings Management

Background

The Linux Kernel can manage power consumption of the hardware it controls through various knobs.

There are a few popular tools which configure the Kernel appropriately to save power e.g. on a laptop running on battery.

This article is about power when running, there is another one about suspend.

Measure Power Consumption

Like any such thing, it's much easier (and fun) to optimize something you can actually measure.

One way to do this is using GNOME's Power Statistics GUI. You can install it using e.g. sudo dnf install gnome-power-manager (source). Clicking e.g. on Laptop battery on the left will show you the current Rate. The Energy when full -VS- Energy (design) will show you how your "new" battery still is (they degrade over time). (upower --dump can show some similar information on the CLI.) On the History tab,the Graph type: Time to empty (for a given Data length: N hours) lets you see the predicted battery time remaining; this graph view over time gives a better view than the single "snapshot in time" remaining duration shown on the Power section in the GNOME Setings.

batstat is a similar tool for the CLI, and powerstat, which can be easily installed on Fedora using Snap is another such tool. (It focuses on measuring power consumption while a laptop is on battery; when plugged in it will refuse to start, saying: "Device is not discharging, cannot measure power usage. Perhaps re-run with -z (ignore zero power) or -R (RAPL)". Run it WITHOUT sudo, as with it it failed with _socket failed: errno=1 (Operation not permitted)`, for me.)

power-profile-switcher

To automatically switch Power Settings from Performance to Balanced or Power Saver when on Battery, install the GNOME power-profile-switcher extension (see GitHub, and a related article).

auto-cpufreq

TODO To automate CPU speed & power further than performance/balanced/safer, consider using https://github.com/AdnanHodzic/auto-cpufreq?

Recommended: TLP - Optimize Linux Laptop Battery Life

TODO, clarify: I used to use this on a Laptop, but ended up removing it, and going back to power-profiles-daemon because it seemed to prevent max. CPU frequency even when plugged in and under heavy load?

TLP is easy to install on many Linux distros:

dnf install tlp
dnf remove power-profiles-daemon
sudo systemctl enable --now tlp.service

I've decided not to install / use the Radio Device Wizard (tlp-rdw) and keep that manual.

TLPUI can be installed via Flatpack to make tweaks later.

CPU

sudo cpupower frequency-info
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
sudo cpupower frequency-set --governor performance
sudo cpupower frequency-set --governor powersave

Graphics GPUs

Intel:

sudo dnf install igt-gpu-tools
sudo intel_gpu_top

NVIDIA:

sudo dnf install nvtop
nvtop

Battery Care / re-charging thresholds

Other Tools (Not Recommended / Required)

Power Profiles

The Power Saver / Balanced / Performance that is available e.g. in GNOME out-of-the-box e.g. since Fedora 35 from the menu in the upper right hand corner of the screen and in GNOME Settings > Power uses the power-profiles-daemon (over D-Bus) to set these. It's also available on the CLI as powerprofilesctl.

These are relatively "coarse grained" profiles - and require a user to remember to manually change them when going on and off charging - which is not ideal. (It would, of course, be possible to script automate this with home made scripts.) They interfere with TLP, and we've disabled them during the installation of TLP above.

Powertop

powertop shows which processes and Kernel events consume power. (The total Watts is also shown on the Device Info tab.) sudo powertop --html=report.html produces a HTML report which can be easily shared.

After sudo powertop --calibrate, or just running for a while, Power Estimates in Watt will start to show up.

It has a Tunables section which recommendations for PCIe devices. Changes made there do not persist over a reboot, but it's possible to launch powertop --auto-tune at every system boot, e.g. with systemd. Powertop is not aware of if the laptop runs on battery or not.

TLP fixes Powertop's Tunables recommendations (ignore the VM writeback timeout).

fatrace

fatrace comes with power-usage-report which provides similar information to powertop but as CSV.

Laptop Mode Tools

The https://github.com/rickysarraf/laptop-mode-tools, also documented e.g. on https://wiki.archlinux.org/title/Laptop_Mode_Tools, are an alternative to TLP.

It's older than TLP, has less Stars on GitHub, and no Fedora package.

thermald? throttled?

Probably not required / useful anymore with the intel_pstate driver.

konkor/cpufreq

https://github.com/konkor/cpufreq looks neat - but it's manual; automation with power-profile-switcher and auto-cpufreq is better!

Further Resources