7

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?

8

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).

  • Thanks, that was my exact problem.(I use i3 and i3status and from time to time I have to change the cpu temperature path) That's when I decided to write a small program to do just this. – yaku Nov 11 '14 at 8:02
7

First, /sys/class is a convenient way to find things in /sys. You'll find everything inside is actually a symlink; I'm pretty sure your first stanza is symlink'd to your third stanza.

The 2nd stanza is the kernel reading the temperature directly from the CPU/chipset. The 3rd stanza is the kernel getting the value from the BIOS via ACPI. While on your system they may give the same answer, they need not (for example, the BIOS could be using a different sensors, averaging a few together, or applying some board-specific adjustment).

Finally, each stanza has two different readings because there are likely two thermometers. Or at least, the hardware's API allows for it.

  • Thanks for your reply. This makes things clearer. Yet on a different laptop with two cores the paths could be different right? (Could it be /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp0_input /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp3_input for example?) . – yaku Nov 10 '14 at 22:50
  • @yaku Yes, the paths could vary. E.g., a laptop could have a cooling zone for (e.g.,) the hard disk, or the northbridge, or whatever. – derobert Nov 10 '14 at 22:58
1

Have a look at the *_label files to see what is being reported - here's my i5:

$ grep "" /sys/devices/platform/coretemp.?/hwmon/hwmon?/temp?_label
/sys/devices/platform/coretemp.0/hwmon/hwmon1/temp1_label:Physical id 0
/sys/devices/platform/coretemp.0/hwmon/hwmon1/temp2_label:Core 0
/sys/devices/platform/coretemp.0/hwmon/hwmon1/temp3_label:Core 1

(grep "" is just used as "cat with filenames")

So here is a total temperature of the CPU, plus a temperature per core.

On a bigger, multi-CPU system you may see dozens of entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.