Linux Kernel – Why Does Linux Store CPU Temperatures in So Many Files?

linux-kernel

I have a laptop(thinkpad) with 2 cpus. Currently I can read the cpu temperatures
from the files below with cat(1):

cat /sys/class/thermal/thermal_zone0/temp
cat /sys/class/thermal/thermal_zone1/temp

cat /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp2_input
cat /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp3_input

cat /sys/devices/LNXSYSTM:00/LNXCPU:00/thermal_cooling/subsystem/thermal_zone1/temp
cat /sys/devices/LNXSYSTM:00/LNXCPU:01/thermal_cooling/subsystem/thermal_zone0/temp

My question is why the kernel stores this information on so many different places and which one is the "standard" file to read a cpu's temperature?

Is this happening due to systemd(I'm using Arch Linux) or non-systemd Linux distros like Slackware have a different approach?

Best Answer

Actually, the temperature is not stored anywhere. /sys is an in-memory filesystem, and reading from files in /sys invokes code in the kernel that computes values on the fly.

The different directories correspond to different ways that the hardware can report temperatures. The temp*_input files have an associated temp*_label that identifies which component's temperature is reported.

Locations under /sys tend to vary from kernel version to kernel version (not from distribution to distribution). That's a difficulty that authors of programs that read data in /sys have to live with (example).

Related Question