Battery life on Lenoxo X1 Carbon Gen 11

I got a new laptop, a Lenovo X1 Carbon Gen 11 but battery life is miserable.

Hibernations works with a swapfile, I’ve added

boot.kernelParams = ["resume_offset=____"];
boot.resumeDevice = "/dev/disk/by-uuid/_____";

but memory suspend is not. only s2idle is announced, and I cannot find any other setting in BIOS (updated to last version)

~ cat /sys/power/mem_sleep
[s2idle]

TLP is enabled

services.tlp.enable = true;

I’ve installed s0ix-selftest-tool and this is the result:

s0ix-selftest-tool -s

---Check S2idle path S0ix Residency---:

The system OS Kernel version is:
Linux alamut 6.1.62 #1-NixOS SMP PREEMPT_DYNAMIC Wed Nov  8 13:11:05 UTC 2023 x86_64 GNU/Linux

---Check whether your system supports S0ix or not---:

Low Power S0 Idle is:1
Your system supports low power S0 idle capability.



---Check whether intel_pmc_core sysfs files exit---:

The pmc_core debug sysfs files are OK on your system.



---Judge PC10, S0ix residency available status---:

Test system supports S0ix.y substate

S0ix substate before S2idle:
  S0i2.0 S0i3.0

S0ix substate residency before S2idle:
  0 0

Turbostat output:
15.491378 sec
CPU%c1  CPU%c6  CPU%c7  GFX%rc6 Pkg%pc2 Pkg%pc3 Pkg%pc6 Pkg%pc7 Pkg%pc8 Pkg%pc9 Pk%pc10 SYS%LPI
0.48    79.34   19.47   20804.32        1.28    94.27   0.00    0.00    0.00    0.00    0.00    0.00
1.03    0.33    96.93   20804.19        1.28    94.27   0.00    0.00    0.00    0.00    0.00    0.00
1.63
0.76    0.26    97.76
1.50
0.17    98.92   0.00
0.00    99.12   0.00
0.07    98.99   0.00
0.00    99.38   0.00
0.15    99.16   0.00
0.15    99.06   0.00
0.27    99.04   0.00
0.02    99.13   0.00

CPU Core C7 residency after S2idle is: 19.47
GFX RC6 residency after S2idle is: 20804.32
CPU Package C-state 2 residency after S2idle is: 1.28
CPU Package C-state 3 residency after S2idle is: 94.27
CPU Package C-state 8 residency after S2idle is: 0.00
CPU Package C-state 9 residency after S2idle is: 0.00
CPU Package C-state 10 residency after S2idle is: 0.00
S0ix residency after S2idle is: 0.00

Your system achieved PC3 residency: 94.27, but no PC8 residency during S2idle: 0.00

---Debug no PC8 residency scenario---:
modprobe cpufreq_stats failed
Loaded 1 prior measurements
Cannot load from file /var/cache/powertop/saved_parameters.powertop
File will be loaded after taking minimum number of measurement(s) with battery only
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask d
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask d
Devfreq not enabled
glob returned GLOB_ABORTED
Cannot load from file /var/cache/powertop/saved_parameters.powertop
File will be loaded after taking minimum number of measurement(s) with battery only
To show power estimates do 590 measurement(s) connected to battery only
Leaving PowerTOP

Turbostat output:

15.201897 sec
CPU%c1  CPU%c6  CPU%c7  GFX%rc6 Pkg%pc2 Pkg%pc3 Pkg%pc6 Pkg%pc7 Pkg%pc8 Pkg%pc9 Pk%pc10 SYS%LPI
0.38    79.66   19.37   21341.32        1.46    94.32   0.00    0.00    0.00    0.00    0.00    0.00
0.62    0.50    97.27   21340.87        1.46    94.32   0.00    0.00    0.00    0.00    0.00    0.00
1.23
0.66    1.56    96.46
1.55
0.03    99.24   0.00
0.06    99.22   0.00
0.10    99.39   0.00
0.00    99.34   0.00
0.13    99.30   0.00
0.12    99.39   0.00
0.03    99.41   0.00
0.04    99.28   0.00

Your CPU Core C7 residency is available: 19.37

Your system Intel graphics RC6 residency is available:21341.32

Checking PCIe Device D state and Bridge Link state:

Available bridge device: 0000:00:06.0 0000:00:07.0 0000:00:07.2

The PCIe bridge link power management state is:
0000:00:06.0 Link is in L0

The link power management state of PCIe bridge: 0000:00:06.0 is not expected.
which is expected to be L1.1 or L1.2, or user would run this script again.


The L1SubCap of the failed 0000:00:06.0 is:
                L1SubCap: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+ L1_PM_Substates+

The L1SubCtl1 of the failed 0000:00:06.0 is:
                L1SubCtl1: PCI-PM_L1.2- PCI-PM_L1.1- ASPM_L1.2- ASPM_L1.1-


Checking PCI Devices tree diagram:
-[0000:00]-+-00.0  Intel Corporation Device a708
           +-02.0  Intel Corporation Raptor Lake-P [Iris Xe Graphics]
           +-04.0  Intel Corporation Device a71d
           +-06.0-[04]----00.0  Kingston Technology Company, Inc. Device 5017
           +-07.0-[20-49]--
           +-07.2-[50-79]--
           +-08.0  Intel Corporation GNA Scoring Accelerator module
           +-0a.0  Intel Corporation Device a77d
           +-0d.0  Intel Corporation Device a71e
           +-0d.2  Intel Corporation Device a73e
           +-0d.3  Intel Corporation Device a76d
           +-14.0  Intel Corporation Alder Lake PCH USB 3.2 xHCI Host Controller
           +-14.2  Intel Corporation Alder Lake PCH Shared SRAM
           +-14.3  Intel Corporation Device 51f1
           +-15.0  Intel Corporation Alder Lake PCH Serial IO I2C Controller #0
           +-16.0  Intel Corporation Alder Lake PCH HECI Controller
           +-19.0  Intel Corporation Alder Lake-P Serial IO I2C Controller #0
           +-1f.0  Intel Corporation Device 519d
           +-1f.3  Intel Corporation Device 51ca
           +-1f.4  Intel Corporation Alder Lake PCH-P SMBus Host Controller
           \-1f.5  Intel Corporation Alder Lake-P PCH SPI Controller


Checking PCI Devices D3 States:
[20032.602350] sof-audio-pci-intel-tgl 0000:00:1f.3: PCI PM: Suspend power state: D3hot
[20032.604896] xhci_hcd 0000:00:0d.0: PCI PM: Suspend power state: D3cold
[20032.621184] i801_smbus 0000:00:1f.4: PCI PM: Suspend power state: D0
[20032.621203] i801_smbus 0000:00:1f.4: PCI PM: Skipped
[20032.621667] i915 0000:00:02.0: PCI PM: Suspend power state: D3hot
[20032.632604] nvme 0000:04:00.0: PCI PM: Suspend power state: D3hot
[20032.632867] pcieport 0000:00:06.0: PCI PM: Suspend power state: D0
[20032.632875] pcieport 0000:00:06.0: PCI PM: Skipped
[20032.635519] mei_me 0000:00:16.0: PCI PM: Suspend power state: D3hot
[20032.637217] proc_thermal_pci 0000:00:04.0: PCI PM: Suspend power state: D3hot
[20032.638027] intel-lpss 0000:00:15.0: PCI PM: Suspend power state: D3hot
[20032.638938] xhci_hcd 0000:00:14.0: PCI PM: Suspend power state: D3hot
[20032.641738] thunderbolt 0000:00:0d.2: PCI PM: Suspend power state: D3cold
[20032.641936] thunderbolt 0000:00:0d.3: PCI PM: Suspend power state: D3cold
[20032.642012] iwlwifi 0000:00:14.3: PCI PM: Suspend power state: D3hot


Checking PCI Devices tree diagram:
-[0000:00]-+-00.0  Intel Corporation Device a708
           +-02.0  Intel Corporation Raptor Lake-P [Iris Xe Graphics]
           +-04.0  Intel Corporation Device a71d
           +-06.0-[04]----00.0  Kingston Technology Company, Inc. Device 5017
           +-07.0-[20-49]--
           +-07.2-[50-79]--
           +-08.0  Intel Corporation GNA Scoring Accelerator module
           +-0a.0  Intel Corporation Device a77d
           +-0d.0  Intel Corporation Device a71e
           +-0d.2  Intel Corporation Device a73e
           +-0d.3  Intel Corporation Device a76d
           +-14.0  Intel Corporation Alder Lake PCH USB 3.2 xHCI Host Controller
           +-14.2  Intel Corporation Alder Lake PCH Shared SRAM
           +-14.3  Intel Corporation Device 51f1
           +-15.0  Intel Corporation Alder Lake PCH Serial IO I2C Controller #0
           +-16.0  Intel Corporation Alder Lake PCH HECI Controller
           +-19.0  Intel Corporation Alder Lake-P Serial IO I2C Controller #0
           +-1f.0  Intel Corporation Device 519d
           +-1f.3  Intel Corporation Device 51ca
           +-1f.4  Intel Corporation Alder Lake PCH-P SMBus Host Controller
           \-1f.5  Intel Corporation Alder Lake-P PCH SPI Controller

The pcieport 0000:00:06.0 ASPM enable status:


Pcieport is not in D3cold:
0000:00:06.0


The pcieroot port 0000:00:06.0 ASPM setting is Disabled, and its D state and Link PM are not expected,
please enable 0000:00:06.0 ASPM setting to double check or report a bug.

What other things should I try? If i close the lid the battery drains in 7~8 hours.

Hey welcome to NixOS!

What is the exact nature of your problem? Battery life when running or battery life on stand by / suspend?

We very recently had a battery life issue with another X1 Carbon user here: NixOS Drains my Laptop Battery in 10 min

Would be interesting to see if there is a commonality.

Hi! Sorry if my question was unclear/uncomplete.

Battery life during normal usage is acceptable, mainly similar to a previous old Thinkpad X1 where I was running Debian.

My problem is with sleep (suspend to ram): the battery drains. I read several people suggesting to look in the laptop BIOS to change the suspend configuration, but my BIOS (updated to last version) has nothing to change it. Then I read about s0ix and the output was attached above
Wondering if someone else has the same laptop and what kernel tweaking is adopting. Thanks

Yeah I understand now that it is a different problem.

I also have an Intel based laptop, albeit a little older (8th gen Core i7 by Xiaomi). And I noticed a difference that might actually make a difference.

When doing a cat /sys/power/mem_sleep I get s2idle [deep]. According to kernel documentation here System Sleep States — The Linux Kernel documentation, s2idle has two modes. So it indeed might be the case, as you suggested, that your laptop doesn’t go into suspend-to-ram mode but stays on standby.

I added this piece of systemd related config for my system. I mainly did this because I had problems with hibernation I believe. But maybe it helps for getting your laptop to suspend?

  systemd.sleep.extraConfig = ''
    AllowSuspend=yes
    AllowHibernation=no
  '';

As far as I can tell this just adds the two line string to /etc/systemd/sleep.conf

you might also try sudo journalctl | grep "PM: suspend" | tail -2 to see what actually happend when your laptop went into suspend the last time. For my machine I get this (it slept during the night):

Nov 24 22:47:34 minotebook kernel: PM: suspend entry (deep)
Nov 25 11:13:20 minotebook kernel: PM: suspend exit

Another suggestion might be to add the mem_sleep_default=deep to your list of kernel parameters. This should go into the boot.kernelParams list on NixOS. Notice this is a list of strings, separated with spaces and inside double quotes. So it should be

boot.kernelParams = [ "mem_sleep_default=deep" ];

I’ve tried both kernelParams and systemd.sleep.extraConfig

But still suspend never goes into deep

nov 25 14:21:24 alamut kernel: PM: suspend entry (s2idle)
nov 25 14:21:29 alamut kernel: PM: suspend exit

so basically my problem is here:

~ cat /sys/power/mem_sleep
[s2idle]

Yes, your issue appears to be that the laptop doesn’t really get to suspend-to-ram. The big question is just why.

Here it would be helpful if we had someone else with a Lenovo X1 Carbon 11th Gen.

Try

udev.extraRules = lib.mkMerge [     
      ''ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"''                  # autosuspend USB devices      
      ''ACTION=="add", SUBSYSTEM=="pci", TEST=="power/control", ATTR{power/control}="auto"''                  # autosuspend PCI devices      
      ''ACTION=="add", SUBSYSTEM=="net", NAME=="enp*", RUN+="${pkgs.ethtool}/sbin/ethtool -s $name wol d"''   # disable Ethernet Wake-on-LAN
    ];

Or help your self to my guthub
https://github.com/tolgaerok/nixos-kde/blob/61155c6b23133109889b1a3f81a11374465ed93c/core/gpu/intel/intel-laptop/HP-Folio-9470M/Eilite-Folio-9470M-HD-Intel-4000.nix#L68

I’ve read many complaining in the Lenovo forum, pointing to solution like this:

I’m a bit disappointed, but not NixOS fault.
Next time I’m gonna choose carefully before buy, I trusted the X1.

I would trust Lenovo too, usually. But researching this problem in advance is hard, you need to look for it specifically. But looking at this, you might still be able to work around it.

What does sudo dmesg | grep 'ACPI.*supports S' give you?

I get this: [ 0.303949] ACPI: PM: (supports S0 S3 S4 S5)

Edit: What is strange is that supposedly Lenovo has fixed this issue in the past already. Look at this blog post speaking of a specific BIOS setting that was added for an older generation of X1 Carbon:

I’ve tried several settings with no luck. I’ve also read on the Lenovo support forum that s0ix is the only sleep supported,

And in the end I see there is a Kernel ticket still opened
https://bugzilla.kernel.org/show_bug.cgi?id=215832

Yes, but S0ix appears to have several states. Your laptop doesn’t get deep enough. That’s why I wanted to get dmesg output.

Looking at it quickly, kernel ticket appears to indicate two potential causes: wifi module or nvme drive. You could test both of those.

here the dmesg: debian Pastezone

okay I must have missed the response. Sorry, but the output is gone already. You can just paste it here in discourse. But the important line was which S-states are supported.

(sorry for the external paste)

here the output:

dmesg | grep 'ACPI.*supports S'
[    0.369003] ACPI: PM: (supports S0 S4 S5)

Yesterday I upgraded to NixOS 23.11, things are slighy better, probably new kernel.
(unrelated: this the first NixOS “dist-upgrade” for me, works like a charm compared to other distro, full love)

Yes, so as we can see, it doesn’t “support” S3. Which it should. And which it does on my Intel laptop. And which is probably the main issue for your energy problem.

(Yes, that is why I started and kept using NixOS at the beginning. It is a better third option to the dichotomy of rolling-release Arch vs. Debian-style dist-upgrade.)

Oh dear, although good to hear that it went all good for you, just to let you know, ive been upgrading my fedora kde from 37 - 39 without a glitch - including the nvidia + wayland upgrades.

All distro’s have there strengths, nixos is a brilliant sandbox distro where as fedora workstation is a brilliant desktop and daily platform / distro …

I’ve been daily driving NixOS for a while now. While Fedora is always my preferred Sandbox distro :smile:

But Fedora is indeed a really good distro. If it wasn’t for NixOS I would surely look at it as a potential daily driver for me.