Bug 449106 - Discrete graphics card not detected for dual-DPU setup with no /sys/kernel/debug/vgaswitcheroo/switch file on disk
Summary: Discrete graphics card not detected for dual-DPU setup with no /sys/kernel/de...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.86.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: David Edmundson
URL:
Keywords:
: 464423 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-01-24 22:06 UTC by yuri6037
Modified: 2023-07-21 21:25 UTC (History)
10 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.109
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yuri6037 2022-01-24 22:06:40 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***
I've recently switched to KDE 5.22.5 which is available through normal Pop OS packages. I did that switch to avoid the repetitive crashes with GNOME/VLC and recover the good old global menu I'm missing from Unity 7 era.

STEPS TO REPRODUCE
1. Right click app in start menu.
2. Go to "Properties" then "Application" then open advanced settings.
3. Enjoy the GPU section missing.

OBSERVED RESULT
The GPU section is missing.

EXPECTED RESULT
The GPU section should appear.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Pop!_OS 21.10
(available in About System)
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
My hardware is a dual GPU system Intel UHD + NVIDIA RTX 3060. This is a laptop.

The GPU works properly in hybrid mode as modifying apps in "Application" menu by adding the "env __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia" prefix does indeed launch apps on the RTX 3060 (verified through nvidia-smi). Using these env vars in terminal also works as expected. CUDA apps also works. This is only a plasma issue where plasma is unable to detect that the system is configured as switchable hybrid graphics.

The driver in use is NVIDIA proprietary with NVIDIA prime. Driver version is 470.86.
Comment 1 Nate Graham 2023-04-27 21:51:58 UTC
Looks like the code in KIO does a Solid DBus call to determine the presence or absence of a discrete GPU. Can you run `qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement hasDualGpu` in a terminal window and paste the output?

If it says, "false", then the issue is either in Solid, or deeper down the stack. If it says true, the issue in KIO.
Comment 2 Bug Janitor Service 2023-05-12 03:46:03 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 3 yuri6037 2023-05-12 05:16:37 UTC
Hello,

Sorry for the really late answer, I didn't see your message before. I still have the computer however I no longer use PopOS 21.10 but instead I use Kubuntu.

I'll check if Kubuntu have the exact same issue and I'll try checking this qdbus command this weekend as I currently have no access to the proper hardware.

Thanks in advance
Comment 4 yuri6037 2023-05-13 12:52:56 UTC
Hi,

I have just tried again on the same hardware but with Kubuntu and I still have the same problem the GPU options are still missing from "Edit Application">Application>"Advanced Options".

The new OS configuration is as follows:
Operating System: Kubuntu 22.04
KDE Plasma Version: 5.24.7
KDE Frameworks Version: 5.92.0
Qt Version: 5.15.3
Kernel Version: 6.2.6-76060206-generic (64-bit)
Graphics Platform: X11

Output of qdbus:
yuri@yuri-oryp7:~$ qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement hasDualGpu
false

Output of nvidia-smi:
yuri@yuri-oryp7:~$ nvidia-smi
Sat May 13 14:51:10 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.105.17   Driver Version: 525.105.17   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   36C    P3    N/A /  55W |      5MiB /  6144MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1527      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+
Comment 5 yuri6037 2023-05-13 13:21:15 UTC
Update:

If this file: https://invent.kde.org/plasma/powerdevil/-/blob/master/daemon/backends/upower/discretegpuhelper.cpp is still up to date and used in the current version of KDE then it's normal it can't work because there is no vgaswitcheroo on my system, what this software should do instead is lspci, "lsmod | grep nvidia_modeset" or check the existance of "nvidia-smi" and if nvidia_modeset is present it should run apps on the dGPU by setting 2 environment variables before running the target software: "__NV_PRIME_RENDER_OFFLOAD=1" and "__GLX_VENDOR_LIBRARY_NAME=nvidia"
Comment 6 Nate Graham 2023-05-14 17:06:09 UTC
Nice find!

It sounds like we should be checking multiple conditions here; not only should we look for /sys/kernel/debug/vgaswitcheroo/switch, but also something else, maybe what you said.
Comment 7 Nate Graham 2023-06-06 15:59:53 UTC
*** Bug 464423 has been marked as a duplicate of this bug. ***
Comment 8 Dave Vasilevsky 2023-06-07 07:36:58 UTC
It looks like gnome checks this by asking switcheroo-control over dbus[0], and switcheroo-control reads the cards from udev[1]. Then for launching with the selected GPU, it uses environment variables chosen by switcheroo-control[2], rather than just setting DRI_PRIME like KDE does.

[0] https://github.com/GNOME/gnome-shell/blob/dec26b7da2ee61641eac8909d0fc2a9f8985216d/js/ui/appMenu.js#L163  
[1] https://gitlab.freedesktop.org/hadess/switcheroo-control/-/blob/master/src/switcheroo-control.c
[2] https://github.com/GNOME/gnome-shell/blob/dec26b7da2ee61641eac8909d0fc2a9f8985216d/src/shell-app.c#L1342

On my Intel/Nvidia box I can see that switcheroo-control's dbus service can indeed see my GPUs, as well as how to select each one:

$ gdbus call --system --dest net.hadess.SwitcherooControl --object-path /net/hadess/SwitcherooControl --method org.freedesktop.DBus.Properties.Get net.hadess.SwitcherooControl HasDualGpu
(<true>,)
$ gdbus call --system --dest net.hadess.SwitcherooControl --object-path /net/hadess/SwitcherooControl --method org.freedesktop.DBus.Properties.Get net.hadess.SwitcherooControl GPUs
(<[{'Name': <'NVIDIA Corporation TU117M [GeForce GTX 1650 Mobile / Max-Q]'>, 'Environment': <['__GLX_VENDOR_LIBRARY_NAME', 'nvidia', '__NV_PRIME_RENDER_OFFLOAD', '1']>, 'Default': <false>}, {'Name': <'Intel® UHD Graphics 630'>, 'Environment': <['DRI_PRIME', 'pci-0000_00_02_0']>, 'Default': <true>}]>,)
Comment 9 Bug Janitor Service 2023-06-22 01:08:24 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/195
Comment 10 Bug Janitor Service 2023-06-22 01:41:38 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1330
Comment 11 Dave Vasilevsky 2023-06-22 02:17:50 UTC
Nate Graham do you think you could help me find someone to review?
Comment 12 Nate Graham 2023-06-22 05:48:38 UTC
Thank you very much for that. I will do so today. Let's follow up in the merge request's comments section.
Comment 13 Bug Janitor Service 2023-06-23 01:39:31 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1332
Comment 14 Nicolas Fella 2023-07-12 00:33:40 UTC
Git commit c13421078014035d290650c4db850fad83a819ba by Nicolas Fella, on behalf of Dave Vasilevsky.
Committed on 12/07/2023 at 00:12.
Pushed by nicolasfella into branch 'master'.

Use switcheroo-control to find discrete GPUs

Previously, we only asked powerdevil, and it did not work on Nvidia GPUs.

M  +7    -0    CMakeLists.txt
A  +13   -0    cmake/FindSwitcherooControl.cmake
M  +1    -0    src/gui/CMakeLists.txt
A  +119  -0    src/gui/gpudetection.cpp     [License: LGPL(v3.0) LGPL(v2.0)]
A  +28   -0    src/gui/gpudetection_p.h     [License: LGPL(v3.0) LGPL(v2.0)]
M  +13   -22   src/gui/kprocessrunner.cpp
M  +5    -27   src/widgets/kpropertiesdialog.cpp

https://invent.kde.org/frameworks/kio/-/commit/c13421078014035d290650c4db850fad83a819ba
Comment 15 Nicolas Fella 2023-07-12 00:43:48 UTC
Git commit d270ba449fd59d374637a64a4ba4bf11d8ac9b10 by Nicolas Fella, on behalf of Dave Vasilevsky.
Committed on 12/07/2023 at 00:40.
Pushed by nicolasfella into branch 'kf5'.

Use switcheroo-control to find discrete GPUs

Previously, we only asked powerdevil, and it did not work on Nvidia GPUs.
(cherry picked from commit c13421078014035d290650c4db850fad83a819ba)

M  +7    -0    CMakeLists.txt
A  +13   -0    cmake/FindSwitcherooControl.cmake
M  +1    -0    src/gui/CMakeLists.txt
A  +119  -0    src/gui/gpudetection.cpp     [License: LGPL(v3.0) LGPL(v2.0)]
A  +28   -0    src/gui/gpudetection_p.h     [License: LGPL(v3.0) LGPL(v2.0)]
M  +13   -22   src/gui/kprocessrunner.cpp
M  +5    -27   src/widgets/kpropertiesdialog.cpp

https://invent.kde.org/frameworks/kio/-/commit/d270ba449fd59d374637a64a4ba4bf11d8ac9b10