AMD processor temperature under Ubuntu 24.04
I often like to check my laptop’s temperature when I am doing something that requires a lot of power. I found knowing temperature really helps with understanding where the limits lie. However, my old scripts that worked on Intel systems doesn’t work on AMD. So I went to research it a bit.
After a bit of snooping around, all the data can be found under /sys/class/hwmon/
. It’s there where we can find multiple _label
files which describe a temperature source. The one we’re after is Tctl
. Once we look over all of these, THERMAL_SOURCES
variable should contain the file path (or more of them) for the temperature expressed in thousands of ℃.
for THERMAL_LABEL_FILE in `find /sys/class/hwmon/hwmon?/ -type f -name "temp*_label" -print`; do
THERMAL_LABEL=`cat "$THERMAL_LABEL_FILE"`
if [ "$THERMAL_LABEL" = "Tctl" ]; then
THERMAL_SOURCES="`echo $THERMAL_LABEL_FILE | sed 's/_label$/_input/g'`"
fi
done
Knowing which file contains a temperature is only the first part. What I like to do next is to fold all temperatures (if multiple sources exist) into a single figure by selecting the maximum value. Then, it’s just a matter of moving the decimal point around to get a while number reading.
TEMP_ALL="$(cat $THERMAL_SOURCES | awk '{print $1}' | sort -n)"
TEMP_MAX="$(echo "$TEMP_ALL" | tail -n 1 | awk '{print int(($1 + 500) / 1000) }')"