systemstat icon indicating copy to clipboard operation
systemstat copied to clipboard

cpu_temp in Linux

Open darkforcesjedi opened this issue 9 months ago • 2 comments

In linux.rs, the cpu_temp function (https://github.com/valpackett/systemstat/blob/f884080af45215d01be62b621674896aa8ed4e6a/src/platform/linux.rs#L723-L734) assumes that the CPU temperature is at /sys/class/thermal/thermal_zone0/temp or /sys/class/hwmon/hwmon0/temp1_input. The order of devices in /sys/class/hwmon is determined by how modules are loaded at boot time and can change from one boot to the next.

A better approach is to scan through the hwmon hierarchy to find a temperature provided by a kernel module associated with a CPU. This is what CPU-X does: https://github.com/TheTumultuousUnicornOfDarkness/CPU-X/blob/84f2da456e57898e5f6655794b2ff0712f41b8c9/src/util.cpp#L507-574

darkforcesjedi avatar Apr 07 '25 02:04 darkforcesjedi

Definitely!

Feel free to submit a PR implementing this :) I might get around to this myself but I'm really busy with (and interested in) other stuff these days.

valpackett avatar Apr 07 '25 04:04 valpackett

I unfortunately don't know any rust. I might try it myself but whatever I come up with probably won't be the greatest solution.

darkforcesjedi avatar Apr 07 '25 04:04 darkforcesjedi