How to set which GPU is the one connected to the display

Hi Everyone,
I have a laptop with 2 graphic cards, integrated and dedicated GPUs, AMD and Nvidia. I suspected that Wayland ran on the dedicated card, causing the laptop to drain the battery faster. Also the fans are running non stop.

After some research it was confirmed that the Wayland, I use KDE Kwin compositor, indeed runs on Nvidia. See details in:

According to this KWin compositor commit, KWin picks the GPU which has a display connected to. See details here: backends/drm: be smarter about picking the primary GPU (51338427) · Commits · Plasma / KWin · GitLab - backends/drm: make a smarter default choice about the primary GPU. Quoting: By default, we want the primary GPU to be one that displays are connected to, and if we’re on a laptop, one that the internal display is connected to.

This kind of makes sense. Other compositors are probably doing something similar.

How to make the display connect to the integrated GPU?
I cannot do that in BIOS.
It must happen before Wayland starts to I guess during kernel boot.
I suspect it must be done through the kernel and during boot. What kernel parameters? DRM/KMS/modesetting or ACPI?

Can you set KWIN_DRM_DEVICES to suit perhaps?

Something like as outlined here…

https://wiki.archlinux.org/title/Environment_variables

Just a comment, that all depends on what the dGPU is, VGA will work, if Display or 3D Controller it’s only meant to be an offload device…

1 Like

I found a working solution!
Add to kernel boot parameters in Grub (Grub2) this parameter: nvidia-drm.modeset=0

Yes, I’m setting there 0, not 1 as most online posts advised. 0 did the trick.

Now it looks like NVidia is finally switched off and Wayland is running on AMD. Reportedly the battery now would last 6-9 hours instead of 2 - 3 reported before.

Nvidia is reported as switched off:

espinosa@espinosa-asus:~> cat /sys/class/drm/card*/device/power_state
D3cold
D0

And I can still use Nvidia for for specific tasks, for offloading, with switcheroo:

switcherooctl launch -g 0 glxgears
…
espinosa@espinosa-asus:~> cat /sys/class/drm/card*/device/power_state
D0
D0

When I stop the glxgears, after few seconds, Nvidia is switched off again:

espinosa@espinosa-asus:~> cat /sys/class/drm/card*/device/power_state
D3cold
D0

FYI, this is my current full boot kernel parameter printout:

espinosa@espinosa-asus:~> cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.13.2-1-default root=UUID=60138d9f-ea26-4f20-95f6-98767950ee42 splash=silent quiet security=apparmor modprobe.blacklist=nouveau rd.driver.blacklist=nouveau nvidia-drm.modeset=0 mitigations=auto

You may have noticed, I also added modprobe.blacklist=nouveau rd.driver.blacklist=nouveau to the kernel boot parameters.
It doesn’t seem to have any effect but it cannot hurt either.

How did nvidia-drm.modeset=0 make Wayland running on AMD? Here is my layman explanation:

  • Modesetting (aka KMS, kernel mode setting) is these days by default on for all cards in the system
  • By switching modesetting (KMS) to off for one GPU, the other one will be the one doing the modesetting and that one ends with display output set to it (to be the Display/VGA Controller?)
  • Do not set the general nomodeset, it would degrade the system. For example Wayland won’t be able to run, X11 probably still yes.

Here is some reading what the Nvidia modesetting does when it is activated:

Quoting:
Setting nvidia-drm.modeset=1 … All it really does is enable the DRIVER_MODESET capability flag in the nvidia-drm devices so that DRM clients can use the various modesetting APIs. In addition to allowing clients that talk to the low-level DRM interface to work, it’s also necessary for some PRIME-related interoperability features.
… loading nvidia-drm with modeset=1 causes it to configure and initialize all GPUs immediately rather than waiting for a client to open the /dev/nvidia device files. …*

That’s exactly the opposite of what I want. So I thought, switching it off may help. And it did.

Oddly, all online posts I found related to this topic recommended to set there 1.

Oddly, the fans are still on. I’ll open another issue for that.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.