Bug 493093 - cpu plugin causes hang/crash when starting plasma-ksystemstats daemon
Summary: cpu plugin causes hang/crash when starting plasma-ksystemstats daemon
Status: RESOLVED FIXED
Alias: None
Product: ksystemstats
Classification: Frameworks and Libraries
Component: General (show other bugs)
Version: 6.1.90
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2024-09-14 03:31 UTC by Jonathan L Hanmann
Modified: 2024-10-02 14:19 UTC (History)
2 users (show)

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


Attachments
Patch to ksystemstats/plugins/cpu/linuxcpuplugin.cpp (867 bytes, patch)
2024-09-14 14:32 UTC, Jonathan L Hanmann
Details
Improved Patch to ksystemstats/plugins/cpu/linuxcpuplugin.cpp (808 bytes, patch)
2024-09-14 15:07 UTC, Jonathan L Hanmann
Details
/proc/cpuinfo for Rock-5b/RK3588 (1.88 KB, text/plain)
2024-09-14 15:08 UTC, Jonathan L Hanmann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan L Hanmann 2024-09-14 03:31:46 UTC
SUMMARY

The ksystemstats daemon will not start on my Rock-5b system. It is running the Armbian vendor kernel version 6.1.75. The very latest version. I am running Qt 6.7.2 with the latest build of the Plasma 6 tips.

By process of elimination I determined that if I prevent loading of the cpu plugin (by renaming it to .no instead of .so) the daemon will load and operate correctly albeit without cpu stats present. There is no output message in either the systemd journal or the system log (dmesg) so I can't currently offer more information on what may be going wrong. I'm going to try to look at the plugin code to see if I can spot anything.

Of course if I can provide any more information you need only request it.

STEPS TO REPRODUCE
1. Build ksystemstats
2. Try to start with systemctl --user start plasma-ksystemstats
3. Timeout after a few minutes but no messages other than the timeout indication.

OBSERVED RESULT

× plasma-ksystemstats.service - Track hardware statistics
     Loaded: loaded (/usr/lib/systemd/user/plasma-ksystemstats.service; static)
     Active: failed (Result: timeout) since Fri 2024-09-13 19:39:10 PDT; 24s ago
    Process: 203993 ExecStart=/usr/bin/ksystemstats (code=killed, signal=TERM)
   Main PID: 203993 (code=killed, signal=TERM)
        CPU: 1min 29.889s

Sep 13 19:37:40 rock-5b-3 systemd[2189]: Starting plasma-ksystemstats.service - Track hardware statistics...
Sep 13 19:37:40 rock-5b-3 ksystemstats[203993]: Loaded plugin "ksystemstats_plugin_osinfo" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_osin>
Sep 13 19:37:40 rock-5b-3 ksystemstats[203993]: Loaded plugin "ksystemstats_plugin_network" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_net>
Sep 13 19:37:40 rock-5b-3 ksystemstats[203993]: Loaded plugin "ksystemstats_plugin_power" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_power>
Sep 13 19:37:40 rock-5b-3 ksystemstats[203993]: Loaded plugin "ksystemstats_plugin_disk" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_disk.s>
Sep 13 19:39:10 rock-5b-3 systemd[2189]: plasma-ksystemstats.service: start operation timed out. Terminating.
Sep 13 19:39:10 rock-5b-3 systemd[2189]: plasma-ksystemstats.service: Failed with result 'timeout'.
Sep 13 19:39:10 rock-5b-3 systemd[2189]: Failed to start plasma-ksystemstats.service - Track hardware statistics.

EXPECTED RESULT

● plasma-ksystemstats.service - Track hardware statistics
     Loaded: loaded (/usr/lib/systemd/user/plasma-ksystemstats.service; static)
     Active: active (running) since Fri 2024-09-13 20:01:15 PDT; 28min ago
   Main PID: 205716 (ksystemstats)
      Tasks: 2 (limit: 18826)
     Memory: 5.8M (peak: 6.6M)
        CPU: 4.578s
     CGroup: /user.slice/user-1000.slice/user@1000.service/background.slice/plasma-ksystemstats.service
             └─205716 /usr/bin/ksystemstats

Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_memory" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_memo>
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_disk" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_disk.s>
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_lmsensors" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_l>
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Found unsupported GPU: /sys/devices/platform/display-subsystem/drm/card0
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Found unsupported GPU: /sys/devices/platform/fb000000.gpu-panthor/drm/card2
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Found unsupported GPU: /sys/devices/platform/fdab0000.npu/drm/card1
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_gpu" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_gpu.so"
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_power" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_power>
Sep 13 20:01:15 rock-5b-3 ksystemstats[205716]: Loaded plugin "ksystemstats_plugin_pressure" from file "/usr/lib/aarch64-linux-gnu/qt6/plugins/ksystemstats/ksystemstats_plugin_pr>
Sep 13 20:01:15 rock-5b-3 systemd[2189]: Started plasma-ksystemstats.service - Track hardware statistics.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma:  Kernel 6.1.75
KDE Plasma Version:  6.2 Beta
KDE Frameworks Version:  6.7.0
Qt Version: 6.7.2

ADDITIONAL INFORMATION
Comment 1 Jonathan L Hanmann 2024-09-14 14:31:34 UTC
I have attached a patch to fix this problem. The ksystemstats runs ok with this patch now. The CPU count (on my system anyways) is off by one. It reflects cores 0-8 when it should be 0-7. Oddly the core 0 appears to be the invalid one. I am going to look into this further also and see if I can identify and fix this issue as well. For now this patch at least prevents the hang/timeout and enables ksystemstats and the System Monitor app to work ok.
Comment 2 Jonathan L Hanmann 2024-09-14 14:32:57 UTC
Created attachment 173659 [details]
Patch to ksystemstats/plugins/cpu/linuxcpuplugin.cpp

Fix for hang/timeout when loading ksystemstats cpu plugin on Rock-5b (RK3588).
Comment 3 Jonathan L Hanmann 2024-09-14 15:01:01 UTC
Comment on attachment 173659 [details]
Patch to ksystemstats/plugins/cpu/linuxcpuplugin.cpp

diff --git a/plugins/cpu/linuxcpuplugin.cpp b/plugins/cpu/linuxcpuplugin.cpp
index 6c01e40..ba1b385 100644
--- a/plugins/cpu/linuxcpuplugin.cpp
+++ b/plugins/cpu/linuxcpuplugin.cpp
@@ -90,10 +90,17 @@ LinuxCpuPluginPrivate::LinuxCpuPluginPrivate(CpuPlugin *q)
                 info.frequency = value.toDouble();
             } else if (field == "siblings") {
                 info.siblings = value.toInt();
-            }
+            } else if (field == "Serial")
+                break;
         }

-        cpus.push_back(info);
+        if((info.id != -1) ||
+           (info.cpu != -1) ||
+           (info.core != -1) ||
+           (info.frequency != 0) ||
+           (info.siblings != -1)) {
+            cpus.push_back(info);
+        }
         cpuCount = std::max(cpuCount, info.cpu);
     }
Comment 4 Jonathan L Hanmann 2024-09-14 15:07:09 UTC
Created attachment 173660 [details]
Improved Patch to ksystemstats/plugins/cpu/linuxcpuplugin.cpp

This fixes both the hang/timeout and the extraneous core 0 problem. The core 0 problem was caused by my prior patch. While I am not happy about the conditional on the cpus.push_back(info) I had to add it works. You will likely know a better means of addressing the issue it is addressing.

That issue is that the /proc/cpuinfo for the RK3588 includes a line for the Serial at the end of the cpu info. That is messing up your algorithm and it is being counted as an extra cpu core albeit with no real information. I added the detection of the "Serial" field with a break from the inner for loop and the conditional on the push_back.

There is now no hang and only 8 cores listed. I will attach my /proc/cpuinfo also so you may see the input file causing this difficulty.
Comment 5 Jonathan L Hanmann 2024-09-14 15:08:32 UTC
Created attachment 173661 [details]
/proc/cpuinfo for Rock-5b/RK3588

This is the offending /proc/cpuinfo input file causing such difficulties for ksystemstats cpu plugin.
Comment 6 Bug Janitor Service 2024-09-30 09:18:36 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/ksystemstats/-/merge_requests/88
Comment 7 Bug Janitor Service 2024-10-02 11:46:21 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/ksystemstats/-/merge_requests/89
Comment 8 Arjen Hiemstra 2024-10-02 11:48:06 UTC
Git commit 478e766d19b333a7cc2316ed11e002928673ba2c by Arjen Hiemstra.
Committed on 02/10/2024 at 11:45.
Pushed by ahiemstra into branch 'Plasma/6.2'.

plugins/cpu: Ignore invalid CPU info when reading /proc/cpuinfo

On some systems, /proc/cpuinfo contains non-core related data. When that
happens, we would end up creating an invalid CpuInfo object that would
later on crash ksystemstats. Instead, ignore said CpuInfo object
properly so we don't crash.

Patch based on Jonathan L Hanmann's suggestion from the bug report.


(cherry picked from commit c5bc0067b31f6c2bdee127702c6cc4717c770808)

Co-authored-by: Arjen Hiemstra <ahiemstra@heimr.nl>

M  +10   -3    plugins/cpu/linuxcpuplugin.cpp

https://invent.kde.org/plasma/ksystemstats/-/commit/478e766d19b333a7cc2316ed11e002928673ba2c
Comment 9 Arjen Hiemstra 2024-10-02 11:54:22 UTC
Git commit c5bc0067b31f6c2bdee127702c6cc4717c770808 by Arjen Hiemstra.
Committed on 30/09/2024 at 09:18.
Pushed by ahiemstra into branch 'master'.

plugins/cpu: Ignore invalid CPU info when reading /proc/cpuinfo

On some systems, /proc/cpuinfo contains non-core related data. When that
happens, we would end up creating an invalid CpuInfo object that would
later on crash ksystemstats. Instead, ignore said CpuInfo object
properly so we don't crash.

Patch based on Jonathan L Hanmann's suggestion from the bug report.

M  +10   -3    plugins/cpu/linuxcpuplugin.cpp

https://invent.kde.org/plasma/ksystemstats/-/commit/c5bc0067b31f6c2bdee127702c6cc4717c770808