https://bugs.kde.org/show_bug.cgi?id=526347

            Bug ID: 526347
           Summary: On distributions that use eudev instead of
                    systemd-udev (e.g. Void Linux, Gentoo/Alpine setups
                    with eudev), the GPU plugin finds no GPUs, so Plasma
                    System Monitor shows missing GPU sensors ("gpu" group
                    exists but has no gpu0/...).
    Classification: Frameworks and Libraries
           Product: ksystemstats
      Version First unspecified
       Reported In:
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: General
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

Created attachment 196626
  --> https://bugs.kde.org/attachment.cgi?id=196626&action=edit
Patch file

SUMMARY
On distributions that use eudev instead of systemd-udev (e.g. Void Linux,
Gentoo/Alpine setups with eudev), the GPU plugin finds no GPUs, so Plasma
System Monitor shows missing GPU sensors ("gpu" group exists but has no
gpu0/...).

CAUSE
plugins/gpu/LinuxBackend.cpp calls udev_enumerate_add_match_sysattr(enumerate,
"class", ...) three times (VGA 0x030000, 3D 0x030200, Display 0x038000).
systemd's libudev ORs multiple values for the same attribute, but eudev's
libudev ANDs every sysattr match, so no PCI device can match and the
enumeration is empty.

STEPS TO REPRODUCE
1. Void Linux (eudev-libudev 3.2.14), Plasma 6.7.5, AMD Radeon 890M (PCI class
0x038000, driver amdgpu).
2. Run `kstatsviewer --list | grep ^gpu` -> only "gpu GPU", no gpu0 sensors.
Minimal proof with eudev's libudev: enumerate subsystem "pci" + class 0x038000
-> 1 device; add all three class matches (as the plugin does) -> 0 devices.

EXPECTED
GPUs are detected regardless of libudev implementation.

FIX
Enumerate the "pci" subsystem only and filter by the "class" sysattr in the
loop (patch below). Tested on Void: gpu0 appears with usage, temperature,
core/memory frequency, PPT, vddgfx and VRAM sensors.

```diff
--- a/plugins/gpu/LinuxBackend.cpp
+++ b/plugins/gpu/LinuxBackend.cpp
@@ -40,9 +40,8 @@
     auto enumerate = udev_enumerate_new(m_udev);

     udev_enumerate_add_match_subsystem(enumerate, "pci");
-    udev_enumerate_add_match_sysattr(enumerate, "class", VGAController);
-    udev_enumerate_add_match_sysattr(enumerate, "class", threeDController);
-    udev_enumerate_add_match_sysattr(enumerate, "class", displayController);
+    // Filter by class below: repeated sysattr matches are OR'ed by systemd's
libudev
+    // but AND'ed by eudev, which would match no device at all.
     udev_enumerate_scan_devices(enumerate);

     auto devices = udev_enumerate_get_list_entry(enumerate);
@@ -50,6 +49,11 @@
     for (auto entry = devices; entry; entry = udev_list_entry_get_next(entry))
{
         auto path = udev_list_entry_get_name(entry);
         auto pciDevice = udev_device_new_from_syspath(m_udev, path);
+        const QByteArray pciClass(udev_device_get_sysattr_value(pciDevice,
"class"));
+        if (pciClass != VGAController && pciClass != threeDController &&
pciClass != displayController) {
+            udev_device_unref(pciDevice);
+            continue;
+        }

         auto vendor = QByteArray(udev_device_get_sysattr_value(pciDevice,
"vendor"));
         auto gpuId = QStringLiteral("gpu%1").arg(gpuNumber);
```

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to