ThinkPad P1 (maybe X1?) Gen 4 configuration + reducing CPU usage

Hello everyone,

For the interest of the community, I managed to get my new P1 to a working state. Issues:
- can't fully disable NVIDIA (options are hybrid or dedicated, no Intel-only option)
- extreme number of interrupts eating constantly 10% of CPU time.

Investigation:
drm interrupt errors in dmesg
iichid driver also generating lots of interruptions
issues starting X

Solutions so far:

For the GPU, X configuration:
Section "Device"
Identifier "Card0"
Option "DPMS"
Code:
Driver "intel" (or "modesetting" - both work)
BusID "PCI:0@0:2:0"
EndSection

Clearing drm interrupt warnings in dmesg (information from Arch linux forums):
In /boot/loader.conf:
hw.i915kms.enable_dc=0
compat.linuxkpi.i915_enable_dc=0

Unfortunately, I couldn't get iichid to calm down (maybe need to tweak pooling times, but this is a project for later me), so I just killed iichid:
module_blacklist="iichid"
I am ok with the trackpoint only, so the trackpad is dead weight for now.

Now the fans are off in normal use and estimated battery life is now at 3h30 (my W530 gets 5h on a 10 years old battery).
To check:
- review hpstate configuration when on battery.
- confirm the nvidia is really off, maybe possible via ACPI commands.

Any suggestions, please share.
 
This seems to kill the NVIDIA GPU (I have the A2000):
acpi_call -p "\_SB.PC00.PEG1.PEGP._OFF"

Now my estimated battery life is 300 minutes. =)
 
I'm on P1 Gen 2 with NVIDIA as well. Would you mind sharing your loader.conf/rc.conf/sysctl.conf, of course, P1 focused parts only? I'm interested.
 
I am back to zero on this. Something else is going on. I think it was false alarm.

The system is fresh and absolutely nothing is installed except clean openbox. I did a quick install of prusa-slicer just to see how the GPU behaves and confirm I am getting acceleration.

I applied all power saving shenanigans on both system level and on the Intel driver. I am aware of and I boot at 5W idle on powermon.
When I use acpi_call to kill the NVIDIA, I am idling at ~2W. (X not loaded)

However, at the moment I load i915kms, I start having these spikes in CPU power. Interrupts are normal, top is at 0.1%.
The CPU goes to 5W (powermon) then every 3-4 seconds it has these spikes of 30W. (X not loaded)

So I installed the NVIDIA drivers (nvidia-modeset) and I get the same behavior. A few seconds of 5W and then spikes. Of course, if I load X and start prusa slicer, it is much faster with the nvidia.

Most of the time, I will be using the computer connected to power and since CPU utilization is not high, I suppose I am not going to lose performance by the spikes? Otherwise, I might for a while run this installation through virtualbox under windows (my soul hurts) and see if the push for freebsd laptop support bears fruit. Then I can go back to a physical boot.

The only thing missing for me to revalidate is the Linux S3 sleep mode in the BIOS.

In comparison, my W530 on FreeBSD and configured as per Vermaden's tutorials lasts for 4-5h on a 10 years old battery on normal tasks (aggressive CPU throttling) and 1:30-2h on the NVIDIA. The CPU idles at 4-5W (powermon) regardless of nvidia or i915kms. Meh, if the W530 had ECC, I'd stay with it.

will get back
 
It seems that the culprit is the Intel driver. The spikes are less frequent and the system rest at quite low levels with using modesetting.

With all optimizations applied, I got 4:30h of battery life during my usual daily routine: some coding, building a few things from ports, many browser tabs, Geany, 3-4 terminal windows, under Openbox. The computer was quite warm.
I get 5 hours on the W530 and its prehistorical battery. =)

Then I tried the same workload under VirtualBox (I assigned the physical partitions to the VM, RAIDZ on both nvmes working ok) and I got 6 hours. I expect, once FreeBSD drivers are as optimized as they are for the old W530, that we could easily get 9-10 hours. A very light workload gives me 8h under Windows on this laptop.
Another advantage is that the laptop runs much cooler and sometimes the fans even go off.

So, for now, I will settle with virtualization. I tested that I can easily reboot bare metal and I will be periodically trying to see the state of things. Maybe I will boot bare metal when docked, will see. =)

The settings I used for best battery life (they may be a bit extreme or even inadequate - I am not so experienced):

/etc/rc.conf:
powerd_enable="YES" (powerdxx did not work)
powerd_flags="-n adaptive -a adaptive -b adaptive" (keeps heat lower)
performance_cx_lowest="Cmax" (also to keep heat and noise lower - not good for performance if connected to power ofc)
economy_cx_lowest="Cmax"
devmatch_blacklist="iichid" (the touchpad driver goes crazy on the interruptions as of now)

/etc/sysctl.conf:
dev.hwpstate_intel.0.epp=100
dev.hwpstate_intel.1.epp=100
(repeat for all threads)

/boot/loader.conf:
hw.pci.do_power_nodriver=3
machdep.hwpstate_pkg_ctrl=0
hw.acpi.cpu.cppc_notify=0
net.bluetooth.usb_isoc_enable=0 (also reduced interrupts)
hw.psm.synaptics_support=0 (probably redundant since I blacklisted the driver)
module_blacklist="iicihd"
vfs.zfs.prefetch_disable=1
hw.i915kms.enable_dc=0
compat.linuxkpi.i915_enable_dc=0
(not sure if I need to use both settings pairs)
hw.i915kms.enable_fbc=1
compat.linuxkpi.i915_enable_fbc=1
kw.i915kms.fastboot=1
compat.linuxkpi.i915_fastboot=1
hw.i915kms.enable_psr=1
compat.linuxkpi.i915_enable_psr=1

X config for modesetting:
Section "Device"
Identifier "Card0"
Option "DPMS"
Driver "modesetting"
BusID "PCI:0@0:2:0"
EndSection
(you can get the bus ID via pciconf)

X config for the NVIDIA (with Intel disabled - I have not driven a display in hybrid mode - secondary driver pooped on me when I tried blender)
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
EndSection

Section "Monitor"
Identifier "Monitor0"
Option "DPMS"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
EndSection

arandr seems to work fine after X is already loaded.
 
vermaden no problem - I thank you. Your guides assisted me on migrating to freebsd. =)
Anything else I could have missed, in terms of settings?

I will periodically boot bare metal and report back in case of improvements. In any case , virtualization is here to save the day. I won't deny credit where credit is due: Windows makes a very good platform for a hypervisor, at least when it comes to power consumption, both on hyper-v and virtualbox (the ones I've tried).
 
Updating:

I've moved today to 14.2. Some good news!

- CPU power is reduced (checking via powermon).
I still get around 5.5W at idle but loading the nvidia kernel module OR killing the nvidia GPU via acpi_call -p "\_SB.PC00.PEG1.PEGP._OFF" gets it down to 3.5W. It is still higher than my ThinkPad W530 (quad core) at 1.8-3W, but yeay!

- X CPU utilization is lower in general when idle in openbox as well.

- onboard audio now works.

- No need to use powerd. But I will need to write some scripts to change the speedstep (or however it is called now) behavior when on battery.

The annoying bits:
- I still didn't manage to keep it set to "Hybrid Graphics" in the BIOS and have the internal display driven by the Intel GPU and the external driven by the NVIDIA. So if I am going away and won't be using the external monitor, I need to go to the setup, change to Hybrid, and then use X via modesetting. If I am docked, I need to switch to nvidia-only. The setup is very lean, as I only load the kernel module I need.
- It looks like the touchpad driver is still eating all the CPU of the universe. But I need to reconfirm that.

Still to test (news, anyone?):
- Deep sleep S3 shenanigans.

Meanwhile, my usual setup of:
- boot FreeBSD, run Windows in the VM for work
- boot Windows when working with photos (printer, scanner), and boot FreeBSD in virtualbox
is still working fine.

edit: clarity

So yeay, progress!!!
 
From iichid manual page:
BUGS
The iichid does not support GPIO interrupts yet. In that case iichid
enables sampling mode with periodic polling of hardware by driver means.
See dev.iichid.*.sampling_* sysctl(8) variables for tuning of sampling
parameters.

sysctl dev.iichid.0.sampling_rate_slow affect battery usage in my setup (I haven't this problem) I not tested other sysctls.
 
From iichid manual page:


sysctl dev.iichid.0.sampling_rate_slow affect battery usage in my setup (I haven't this problem) I not tested other sysctls.
Very good information.

I am ok with the trackpoint, so it is not a big deal. The only thing I (rarely) miss is pinch-to-zoom.
 
Reporting back from the land of 14.2 and happy to report that I can switch back to FreeBSD bare metal, Windows VM instead of Windows metal, FreeBSD VM, with a lot of new answers and a new configuration. The best new thing is that I can leave the BIOS set to hybrid graphics now (finally figured out X configuration).

Battery use or single monitor:
  • i915kms, nvidia-modeset or modesetting work
  • i915kms:
    • Sometimes idles at 5W (using Vermaden's epic setup), sometimes at 3W. (checked via powermon). I don't know why it happens.
      • On the ThinkPad W530, CPU idles at 2.5W-3W. I found out that this is related to screen resolution causing higher base CPU usage. My P1 Gen 4 has a 3840x2400 screen whereas the W530 has a 1920x1080 screen.
      • In any case, the battery life is 6 hours doing usual non-Internet-bloat stuff. Windows gets 8-9, so I am ok with it.
      • Must stop nvidia GPU otherwise CPU power consumption is super high, palm rest is super warm and fans will be annoyinng ! acpi_call -p "\_SB.PC00.PEG1.PEGP._OFF" -o i
        • Command should print 1.
    • Big issue: whenever I load i915kms or i915_tgl_dmc_ver2_112_bin modules, sysctl -a crashes so badly I need to restart via ctrl-alt-del.
  • nvidia-modeset:
    • For now, to run single monitor and nvidia, I need to switch BIOS to dedicated graphics. I could probably figure it out via proper x config, but unfortunately the day only has 24 hours.
    • Battery life is very low - 2 hours doing light stuff. But this is expected.
    • Issue: can't set backlight, even after loading acpi_ibm or acpi_video.
  • modesetting:
    • Works ok. Not much difference in the power consumption or performance to be honest.
  • Configuration: everything works out of the box. You can tweak X config as you wish and it works ok. With nvidia-modeset, arandr
Dual monitor:
  • nvidia-modeset + plain modesetting: not tested
  • nvidia-modeset + i915kms:
    • load nvidia-modeset and i915kms.
    • Every few seconds, CPU power consumption spikes to 20W. It doesn't bother me because I never run 2 monitors on battery.
    • Background CPU utilization of X is quite high: 5-7%. Driving 2x 4K screens is the reason.
    • Intel GPU drives internal display (backlight setting works). NVIDIA drives external display.
    • All audio outputs work well: internal speakers, HDMI and headphone jack.
    • Fan at minimum speed doing normal desktop stuff. I can't hear it from a sitting distance.
    • Possible issue: I think OpenGL acceleration is disabled for the internal display. Need to confirm.
    • Issue: arandr does not start.
    • Requires manual X configuration.
  • nvidia-modeset only (BIOS set to dedicated graphics only):
    • Works out of the box. No X config required.
    • arandr works.
    • High power consumption. No chance on battery. Fans are not bad, but audible from a sitting distance. Laptop is warmer.
    • Same higher background CPU usage.
    • Issue: can't adjust backlight.
X Configuration for dual displays (i915kms + nvidia):

Code:
Section "ServerLayout"
    Identifier     "Layout0"
    Screen        0    "IntelScreen" 0 0
    Screen        1    "NvidiaScreen" RightOf "IntelScreen"
    Option            "Xinerama" "1"
EndSection

Section "Device"
    Identifier    "IntelGPU"
    Driver        "intel"
    Option        "TearFree" "true"
    Option        "DRI" "true"
    BusID        "PCI:0:2:0"
EndSection

Section "Screen"
    Identifier    "IntelScreen"
    Device        "IntelGPU"
EndSection

Section "Device"
    Identifier    "NvidiaGPU"
    Driver        "nvidia"
    BusID        "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier    "NvidiaScreen"
    Device        "NvidiaGPU"
EndSection

This will set both internal and external screens to maximum possible resolution. For other resolutions, rotation, other options, you must add manually.

rc.conf: My setup is not final and, for now, I am loading modules and copying x settings into place as required. I will wrap everything up in a script eventually. Otherwise, the important stuff added:

Code:
#do not load touchpad
devmatch_blacklist="iichid"
#powerd seems not to be needed in newer intels
powerd_enable="NO"

/boot/loader.conf: A tweak could fix some of the issues I am facing. Suggestions welcome. I am quite confused about the linux compat lines. =( I've added the following:

Code:
cpufreq_load="YES"
hw.pci.do_power_nodriver=3
machdep.hwpstate_pkg_ctrl=0
hw.acpi.cpu.cppc_notify=0
#do not load nasty touchpad driver
hw.psm.synaptics_support=0
hw.acpi.cpu.cx_lowest=C8
#really do not load nasty touchpad driver
module_blacklist="iichid"
hw.i915kms.enable_dc=0
compat.linuxkpi.i915_enable_dc=0
hw.i915kms.enable_fbc=1
compat.linuxkpi.i915_enable_fbc=1
hw.i915kms.fastboot=1
compat.linuxkpi.i915_fastboot=1
hw.i915kms.enable_psr=1
compat.linuxkpi.i915_enable_psr=1

WiFi: still sucks, but works.
Touchpad driver: still eats all CPU of the universe (check posts above).

Big issue: loading i915kms, i915_tgl_dmc_ver2_12_bin or acpi_video result in such unresponsive system when running sysctl -a that I need to restart the computer via Ctrl-Alt-Del.

Suggestions accepted: X config for modesetting + nvidia? Any other suggestions? Are the new sleep states supported? I've disabled them in BIOS for the moment.

Not having to daily drive Windows: priceless.

edit: clarity and comment.
 
I cant help you but im a simple man - i always disabling touchpad on ThinkPad`s ( bios or physically disconnecting cable ) ... i see no reason why i need them :) so maybe if you disable it - drivers wont get installed / loaded or its not a case ?
 
Same touchpad issue on P14s, had to disable iichid.

By the way, can you try the following for the NVIDIA card and see if it helps with power consumption on your end? Definitely does on mine.

Code:
# Set persistence mode to on and power limit to 1W for Nvidia GPU
# Adjust clocks to minimum
sudo kldload nvidia
sudo killall -9 nvidia-smi
sudo nvidia-smi daemon
sudo nvidia-smi -pl=1
sudo nvidia-smi -ac=405,300
sudo nvidia-smi -lgc=300,300
 
blackhaz I am happy to try, but could you be more specific on the context of your proposal?

If I have iGPU+nvidia enabled in the BIOS, then I don't think the test makes much sense. How would loading the nvidia module and setting power consumption to 1W use less power than just killing the nvidia via ACPI?

If I have nvidia-only enabled in the BIOS, then is it realistic that we can set the power limit to 1W and retain a functional system?
 
I cant help you but im a simple man - i always disabling touchpad on ThinkPad`s ( bios or physically disconnecting cable ) ... i see no reason why i need them :) so maybe if you disable it - drivers wont get installed / loaded or its not a case ?
I don't EVER use the touchpad -
except pinch-to-zoom. I really miss it.
(but not enough to daily drive anything else)
 
Back
Top