My per-core CPU values were wrong because Conky was ignoring half the data in /proc/stat.
In Linux, Conky supports short and long /proc/stat formats. The type is auto-detected by determine_longstat_file(). However, this function is only called if the user's config uses a ${top *} var. If the user doesn't use this widget, the CPU values are calculated wrong because 4 of the 8 stat values are ignored.
In my case, I discovered it because conky showed one of my CPU cores pegged at 100% all the time no matter what. But htop + btop showed under 5% for that core. So I did some digging, and found it was happening because that core was stuck in iowait due to a hung NFS mount.
Conky normally handles iowait correctly, but only if it detected the long stat format. I didn't have any ${top *} vars, so conky wasn't trying to detect the stat format, defaulting to short stat which ignores half the data, and this made it think the CPU was always at 100%.
Suggested fix: Detect stat format the first time it's accessed, regardless of which widgets the user config contains.
Version
git head 2023-09-29 53973402b4fda399267c225b9fc7395ed862bde9
Which OS/distro are you seeing the problem on?
Debian
Conky config
-- This config is sufficient to see wrong CPU values in Linux Conky.
-- If a CPU core is stuck in iowait, it'll show up as 100%.
conky.config = {
alignment = 'top_right',
own_window = true,
}
conky.text = [[
CPUs ${alignr}${cpu}%
${cpubar}
${alignr}${cpugraph 30,84}
${alignr}${cpu cpu1} ${cpugraph cpu1 10,64}
${alignr}${cpu cpu2} ${cpugraph cpu2 10,64}
${alignr}${cpu cpu3} ${cpugraph cpu3 10,64}
${alignr}${cpu cpu4} ${cpugraph cpu4 10,64}
]]
-- However, this config shows the correct CPU core usage values.
conky.config = {
alignment = 'top_right',
own_window = true,
}
conky.text = [[
CPUs ${alignr}${cpu}%
${cpubar}
${alignr}${cpugraph 30,84}
${alignr}${cpu cpu1} ${cpugraph cpu1 10,64}
${alignr}${cpu cpu2} ${cpugraph cpu2 10,64}
${alignr}${cpu cpu3} ${cpugraph cpu3 10,64}
${alignr}${cpu cpu4} ${cpugraph cpu4 10,64}
${top cpu 1}
]]
1632 is a slightly different version of your patch, it makes the logic a bit simpler imo, but otherwise the effect is the same. It would be nice if you could test it.
1632 works for me. There's a bunch of unrelated formatting changes in that patch, but I can confirm the relevant portions of the patch fix the issue for me.
Here's my thin little sidebar running with that patch. With 2 cores stuck in iowait, it no longer shows them as pegged... which is good.
What happened?
My per-core CPU values were wrong because Conky was ignoring half the data in
/proc/stat
.In Linux, Conky supports short and long
/proc/stat
formats. The type is auto-detected bydetermine_longstat_file()
. However, this function is only called if the user's config uses a${top *}
var. If the user doesn't use this widget, the CPU values are calculated wrong because 4 of the 8 stat values are ignored.In my case, I discovered it because conky showed one of my CPU cores pegged at 100% all the time no matter what. But htop + btop showed under 5% for that core. So I did some digging, and found it was happening because that core was stuck in iowait due to a hung NFS mount.
Conky normally handles iowait correctly, but only if it detected the long stat format. I didn't have any
${top *}
vars, so conky wasn't trying to detect the stat format, defaulting to short stat which ignores half the data, and this made it think the CPU was always at 100%.Suggested fix: Detect stat format the first time it's accessed, regardless of which widgets the user config contains.
Version
git head 2023-09-29 53973402b4fda399267c225b9fc7395ed862bde9
Which OS/distro are you seeing the problem on?
Debian
Conky config
Stack trace
No response
Relevant log output
No response