[TRACKING] Linux battery life tuning

Yes, that’s from Powertop, and it did look like at least 90% of the total at the time, so it must just be an artifact. Thanks!

For y’all that aren’t reaching C9/C10 and have PSR enabled:

  • Check that CPU usage is around ~0% and no process is consuming excess in something like top
  • important: ensure the screen can be static, meaning nothing is moving, changing, flashing, etc. on the display. How PSR works is if nothing needs to be updated on the display, no new info needs to be sent to the display. So, the display engine in the CPU can be turned off, allowing C9/C10.

As an example: I had a low battery alert styling in Waybar. At 15%, the color of a small rectangle in my tray would constantly transition linearly between red and white. That simple action constantly updated the display, preventing the CPU from reaching C9/C10 and causing increased idle power consumption.

Here’s some interesting info from Intel, for 11th Gen. Under 11th Generation Intel® Core™ Processor Family (for U-series, not Desktop) > Documents > Datasheet, Volume 1

image

Table 3-5: Some criteria to reach C9/C10:
ksnip_20210914-115958

Table 3-6: With up to a resolution of 5210x3200@60Hz, and PSR enabled, the CPU can reach C10.
Table 3-7: Seems like the USB4 controller plays a part in reaching C10 as well, so maybe check your USB devices. I can confirm my laptop reaches C10 with the HDMI Expansion Card plugged in, as well as in performance governor.
ksnip_20210914-120232


This has happened to me a few times :joy:

Er, 5.14 is needed on Fedora to fix the PSR micro-stutter issue. PSR can still be enabled in the recent earlier kernels which allow reaching C9/C10 (can personally confirm).

Echoing this as well – ~2.6%/hr seems to be about what I’m getting on Fedora 34 which is much higher than it could be. I plan on using suspend-then-hibernate (similar to Windows) for better standby life. Some Linux hibernation info here, and the ongoing Windows discussion here, for comparison. Will report back once I dive into this!

From what I’ve gathered:

If this is S0 suspend (s2idle in /sys/power/mem_sleep), which should be S0ix on 11th Gen, being able to reach C10 plays a role in better standby battery life, so ensure that’s happening.

If this is S3 suspend (deep in /sys/power/mem_sleep), well, according to this System76 engineer:

It was discovered, deep in one of the Intel documents, that TigerLake-U no longer officially supported S3 suspend.

so maybe that’s why S3 suspend seems subpar, FWIW.

7 Likes

@TJ1 I’m also seeing the same draw with the microsd card :frowning:

It prevents the system from reaching PC 9 or 10 and costs over a full watt

1 Like

I’m getting pretty subpar 8w performance on Manjaro +KDE

I can get it down to 5 watts if I unplug the microsd card, disable WiFi and Bluetooth, and log in to the virtual console (not plasma)

I’ve tried setting everything mentioned here and I’m not sure where the extra power draw is going. The CPU is spending most of its time in C9-10 and the GPU is idling.

Plasma has …something wrong with it as the CPU usage is always 1-2%. But even in the console mode it looks like I’m several watts higher than the expected base draw

Silly question - brightness set to minimum and keyboard backlight off? When I was first testing, the keyboard backlight got me. The fact it’s C9-C10 means all the power settings should be there, but maybe do powertop --auto-tune one more time with 2.14? Did you use rfkill to disable the wifi? And what’s your kernel version?

I’m hitting pc10 on Manjaro Gnome 21.1.2 but if I disable PSR (to fix the stuttering issue Periodic stuttering on fresh gnome.40 wayland install on Arch Linux - #6 by William_Light) the lowest I can get is pc8.

I can confirm default Manjaro Gnome installation gets pc10 for me as well (and better battery life than Windows with all its background processes). I thought I was going crazy due to the random stuttering, but I think I can live with it for a while until a battery-friendly fix is available.

Another item I have noticed… pcie aspm is supported:
[ 1.010937] acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI EDR HPX-Type3]

But never changes from default normally:

cat /sys/module/pcie_aspm/parameters/policy
[default] performance powersave powersupersave

I’m not sure if thats because it’s adjusting, but not updating that or what… but if I set that to powersupersave it seems to allow cpu to get to lower states (C10, etc) here.
Unclear if it helps battery life yet.

Been messing with the power settings on my Framework for the past week and I figured I should post my own findings for others here. I’m running Fedora 34’s KDE/Plasma spin on it’s latest 5.13.15 kernel. I have messed with tuned, tlp, powertop and the power-profiles-daemon and ran with many of the configurations suggested on the various threads where it has been discussed.

Running with tuned or tlp alongside powertop I was definitely seeing an increase in battery-life, the cpu was routinely getting put into C7 states, but it wasn’t really enough. Usage typically wouldn’t fall below 6 watts. I was looking at anywhere from 5-7 hours of battery on a light workload (A few tabs of Firefox, Discord in the background, LibreOffice Writer.)

By far the best setup I have found is the power-profiles-daemon running alongside powertop. The power-saver profile gets the cpu into C10 states better than the other tools and I’m now looking at 4-6 hours for a heavy workload and anywhere from 8-12 on a lighter workload. At full idle, I have seen the laptop dip down to 3.2 watts of usage thanks to PSR.

Additional tips & tricks:

  • Automation: I like to switch between power profiles when I am plugged in to AC so I can do heavier workloads and some light gaming on the laptop when the situation calls for it. With powertop installed, I have set up some udev triggers to change the power-profiles-daemon’s active profile depending on whether or not I am running on battery or AC. I made the /etc/udev/rules.d/10-power.rules file below.
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/bin/at -M -f /lib/udev/power-profiles/power-saver now"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/bin/at -M -f /lib/udev/power-profiles/performance now"

The triggers run the shell scripts I made at /lib/udev/power-profiles. These shell scripts just run the “powerprofilesctl set” command for the profiles I want running in each power state. Running these comands through /usr/bin/at isn’t 100% necessary, but udev runs it’s triggers before a lot of modules are loaded at boot. Running your commands through at is a quick way to make sure your triggers are processed after more kernel modules are loaded.
TL:DR of this is that running these udev triggers through at allows this to work on system boot in addition to changing profiles whenever the system is plugged in or put on battery. I have the system set to performance on AC and power-saver on battery.

  • Be mindful of peripherals
    Simple one, but some applications like Discord will try to connect to the camera if it sees it. the camera draws quite a bit of power on it’s own (a couple watts, even at idle form my observations,) so just be mindful about turning it off when not in use on battery power. Same goes with the microhpone and any expansion cards you may have installed. From reading other threads, it seems the HDMI and MicroSD modules have some idle power draw as well.
7 Likes

Thanks for the detail and udev triggers @IPGentlemann! To add on, initially I ran and saw good results with power-profiles-daemon. I then experimented with TLP and simply haven’t bothered to revert (though I wanted to because power-profiles-daemon is much simpler + Fedora 35 includes it by default, etc.). With your findings, I’m going to switch back. But since power-profiles-daemon doesn’t apply many of the tweaks that TLP does, I’m curious @IPGentlemann:

  1. Are you setting some/all of the recommended tweaks/tunables from powertop? If so,
  2. Which have you set/are using?
  3. How are you applying them? e.g. powertop --auto-tune at boot, via udev rules, etc.

For those using Waybar + power-profiles-daemon, here’s the custom module I run. It displays the current power profile (refreshes every 60 seconds), and a left/middle/right click on the area sets the respective power profile. This functionality already exists in Gnome control center Settings → Power (and from a quick search, I believe KDE/Plasma now has support as well).

Click Action
Left (one finger tap or physical left click) set power-saver profile
Middle (three finger tap) set balanced profile
Right (two finger tap or physical right click) set performance profile
"custom/power_profile": {
    "exec": "powerprofilesctl get",
    "interval": 60,
    "on-click": "powerprofilesctl set power-saver",
    "on-click-right": "powerprofilesctl set balanced",
    "on-click-middle": "powerprofilesctl set performance"
}
1 Like

@Michael_Wu I am using Powertop’s tweaks. Powertop comes with a .service file that you can enable with systemctl.

sudo systemctl enable powertop

This service will run at boot, apply Powertop’s tweaks and then shut itself off once it is finished. No custom bootup scripts or udev triggers required.

3 Likes

While I added the grub line for it, I haven’t actually suspended since I received my framework. It cold boots quick enough I always do a complete shutdown.

1 Like

Just tested with my i7-1165G7 model this afternoon on Gnome Manjaro (kernel 5.13.15-1-MANJARO) and I saw 24% battery drain in 6 hours and 44 minutes. So about 3.56%/hr suspended with lid closed the whole time starting at 97%.

I haven’t done any tweaking of power settings yet, but like @malachid, I’ve just been shutting down completely when I’m not using my laptop. The 19s cold boot time blows any other computer I’ve used regularly out of the water.

2 Likes

I have been running into so many issues with battery/performance. I have no idea what is going on as everything runs smoothly on my Dell Latitude 7480. I am running on NixOS with flakes so the entire system is quite literally the exact setup (from reproducibility).

I am using TLP to set up AC/Battery settings. Idle on 50% brightness with powertop open has a discharge rate of ~3.5w. That is all good, my latitude has a discharge rate of about ~3.9w. But that’s where the expected behavior ends.

On battery, this is how everything is running. Omitted some lines for clarity:

/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver    = intel_pstate
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor  = powersave

/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference = power [HWP.EPP]

/sys/devices/system/cpu/intel_pstate/status            = active
/sys/devices/system/cpu/intel_pstate/min_perf_pct      =   9 [%]
/sys/devices/system/cpu/intel_pstate/max_perf_pct      =  50 [%]
/sys/devices/system/cpu/intel_pstate/no_turbo          =   0
/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost =   0
/sys/devices/system/cpu/intel_pstate/turbo_pct         =  47 [%]
/sys/devices/system/cpu/intel_pstate/num_pstates       =  39

Doing simple activities on Firefox (aka writing this post) I immediately hit 13-15w discharge. Videos are atrocious and send me up to 20-25w discharge with fans running. On my dell latitude it is limited to 10-12w discharge even during videos. This makes no sense as my settings are all firmly in the power saving camp. Its as if the settings aren’t being listened to.

I’d also note that supposedly my cores during heavy video usage are at ~55-60c with ~40% usage all cores and the computer is burning hot (fans are running full blast). When at idle the bottom of the computer/power button is warm to the touch ~40c. And the computer is overall warm at normal web usage at ~45c. The computer is always warm even when not doing anything.

If you read through all of that I am curious your thoughts/experience. I feel I am missing something extremely obvious. Note that these issues also occur outside of firefox with other programs.

tldr: power, temperature, and CPU usage all make no sense.

1 Like

I don’t think you’ve enabled powersave on battery? Check the following lines.

/etc/tlp.conf L0019: PCIE_ASPM_ON_AC="performance"
/etc/tlp.conf L0020: PCIE_ASPM_ON_BAT="powersupersave"

Also, have you enabled hardware acceleration on firefox?

1 Like

I had PCIE_ASPM_ON_** set to default. Tried setting it to powersupersave on battery and no luck. Still same issues.

I spent a bit of time looking into hardware acceleration and also no dice there. I confirmed that VA-API is working and xserver is doing direct rendering. I enabled Guc/Huc and framebuffer compression from the archwiki. Firefox hardware acceleration is broken with intel-media-driver. I get the sandbox violation errors. See this active bug thread: 1619585 - VAAPI video playback leads to sandbox violations (Temporary solution: Uninstall iHD driver (intel-media-driver) and install i965 driver (i965-va-driver == intel-vaapi-driver)). However from my understanding can’t use intel-vaapi-driver with iris xe so out of luck :frowning: . I did get it working with MPV for testing consumption and still was hitting 20+ watt discharge.

Is there anything I might be missing? I am not sure what to do as the laptop is basically unusable. Zoom calls means less than two hours of battery life and fans at full speed. Normal web browsing is three-four hours of battery life. Even pure terminal usage gets me only up to 7-8 hours.

edit: I would also like to add that general performance has been pretty bad. Any GUI program such as Firefox, LibreOffice, and Zoom has noticeable lag and frequently freezes for a few seconds. I am so suprised because everything works great with the same NixOS configuration (with separate drivers of course) on my dell latitude 7480 that has an old dual core i7-7600u with whatever nonexistent integrated graphics.

1 Like

This is super-weird. I’m using Guix and I think the most I’ve seen is 9W while watching videos - with 1W taken by the ethernet adapter, etc.

What kernel version? I’m on:

Linux guixframework 5.13.15-gnu1 #1 SMP 1 x86_64 GNU/Linux

Another thing to do is to wipe and start with ubuntu which has pretty reasonable default battery life of 6-10 hours iirc. If you can’t get it with ubuntu, there’s something weird going on.

You have tested with no adapters, right?

edit: Ubuntu with TLP and powertop --auto-tune had pretty good battery life. Don’t recall if they were installed by default.

What do you mean by no adapters?

It is really weird. I really am lost at what is wrong. Luckily it will be easy to get NixOS setup. Reproducibility really coming in handy (guix + nixos ftw!). Installing ubuntu fresh might be the next step to make sure this isn’t a hardware problem.

Running the latest kernel. And these are the hardware specific things that NixOS auto-generates on setup.

kernelPackage = pkgs.linuxPackages_latest;  # 5.14.5
initrd = [ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod" ];
kernelMods = [ "kvm-intel" ];

With none of the expansion cards plugged in. The HDMI and microsd adapters each take 1W when idle right now it looks like.

Ah, I am only running usb-a/usb-c expansion cards. I took them out and it seems to have lowered usage just a little. Still sitting at ~8-9w discharge writing this post with a few tabs open and powertop (and basic system services).