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

            Bug ID: 526594
           Summary: Sensor stays subscribed when one client subscribes to
                    it twice and then unsubscribes twice
    Classification: Frameworks and Libraries
           Product: ksystemstats
      Version First 6.7.5
       Reported In:
          Platform: NixOS
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: General
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

Created attachment 196792
  --> https://bugs.kde.org/attachment.cgi?id=196792&action=edit
QML reproducer: two Sensors for gpu/gpu0/usage in one process, destroyed after
5 s

DESCRIPTION
When one client subscribes to the same sensor twice and later unsubscribes
twice, ksystemstats keeps the sensor subscribed until the client disconnects.
On an NVIDIA laptop this keeps `nvidia-smi dmon` running and the dGPU never
runtime-suspends.

STEPS TO REPRODUCE
1. On a system with an NVIDIA GPU, make sure nothing else uses gpu/gpu0 sensors
(no nvidia-smi process running).
2. Run the attached ksystemstats-duplicate-subscribe.qml with `qml`. It creates
two Sensor objects for gpu/gpu0/usage in one process and destroys both after 5
seconds.
3. Watch for the `nvidia-smi dmon` process started by ksystemstats.

OBSERVED RESULT
nvidia-smi dmon starts when the sensors are created and keeps running after
both Sensor objects are destroyed. It stops only when the qml process exits.

EXPECTED RESULT
nvidia-smi dmon stops once no Sensor uses gpu/gpu0/usage anymore.

SOFTWARE/OS VERSIONS
Operating System: NixOS 26.11
KDE Plasma Version: 6.7.5
KDE Frameworks Version: 6.30.0
Qt Version: 6.11.2
Kernel Version: 7.2.8 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 260 w/ Radeon 780M Graphics
Memory: 24 GiB of RAM (22.8 GiB usable)
Graphics Processor 1: AMD Radeon 780M Graphics
Graphics Processor 2: NVIDIA GeForce RTX 5050 Laptop GPU
libksysguard / ksystemstats: 6.7.5
NVIDIA driver: 615.71.09 (open kernel module), PRIME offload with runtime D3
power management

ADDITIONAL INFORMATION
libksysguard sends a separate subscribe call for every Sensor object, so a
single client (for example plasmashell with two widgets showing the same
sensor) can subscribe the same path twice.

In src/client.cpp, Client::subscribeSensors() calls sensor->subscribe() every
time, so SensorProperty's subscriber count goes up by two. m_subscribedSensors
is a QHash with one entry per path though. The first unsubscribeSensors() call
takes that entry and calls sensor->unsubscribe() once; the second call finds
nothing. The count stays at 1 until the client disconnects. The code is the
same on master.

On NVIDIA laptops this keeps nvidia-smi running, which keeps the dGPU out of
D3cold. On my machine that is about 7 W extra on battery. Related: bug 497024.

Tracking the number of subscriptions per path in Client and only calling
sensor->unsubscribe() when it reaches zero fixes it for me.

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

Reply via email to