How do I find the temperatures without 3rd party software?
It sounds like what you want is /sys/class/hwmon
and /sys/class/thermal
.
Both of these provide simple shell based access to the data you want (the hwmon directory will also include other sensor types). Each has one directory for each sensor interface in your system (which may have more than one sensor).
Three other things to note though:
- Unless you have a really bad system, running the
sensors
command even once a second shouldn't have any percievable effect. In fact, regularly reading the files in the above mentioned directories may have more of an effect. - Graphs are your friend here. I would suggest getting something like netdata or collectd running so you have realtime (or near realtime) data to look at.
- Check your voltages too. What your describing could also be due to having a power supply that can't keep up with your system's power requirements. This will be indicated by voltages dropping significantly when the system is under high load.
This answer is about one way to monitor processor temperature manually for some Intel processors via accessing the Machine Specific Registers (MSR) directly.
The first thing to note is, in this case, what is read out of the MSR is relative to the Tcc, the limit temperature, so an additional calculation is required to determine the actual temperature.
Refer to the Intel® 64 and IA-32 Architectures Software Developer’s Manual, or in your case the AMD equivalent.
In my case, I want bits 22-16 of the MSR at 0x1B1, aka IA32_PACKAGE_THERM_STATUS. The Tcc for my older i7-2600K is 98 degrees.
Here is a simple script to monitor the temperature (and CPU frequency) manually:
#! /bin/dash
#
# temp_mon3 Smythies 2016.10.05
# a simplified version of temp_mon2,
# for monitoring temp.
# Note: it is on purpose that -a is not used.
# Also CPU0 frequency (1 is good enough, when all
# are loaded).
#
# temp_mon2 Smythies 2016.09.29
# Monitor Package temperatures.
# Use clock modulation to control temps.
# i.e. simulate the second to last level
# of defense.
# Use simple primatives.
# run as sudo
# hardcoded for my tcc of 98 degrees.
#
echo ... begin package temperature monitoring ...
#
# In case I forgot (which I often do)
modprobe msr
#
# first let the drastic effect of the sudo command decay
# Done later in temp_mon3.
#
# some stuff
COMMAND="rdmsr --bitfield 22:16 -u 0x1B1"
COMMAND2="cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq"
#
# then get on with it
while [ 1 ];do
sleep 4
TEMP_RAW=$(eval $COMMAND)
CPU0_FREQ=$(eval $COMMAND2)
TEMP_ACT=$((98-TEMP_RAW))
echo "$TEMP_ACT $CPU0_FREQ"
done
And here is some sample output, where I add some CPU load after awhile (temp goes from 31 to 73 degrees):
$ sudo ./temp_mon3
[sudo] password for doug:
... begin package temperature monitoring ...
31 1605275
31 1605154
32 1605164
30 1605148
31 1605176
51 3511279
54 3511278
55 3511279
57 3511283
58 3511279
60 3511278
61 3511284
63 3511279
64 3511280
64 3511280
66 3511280
67 3511278
68 3511280
68 3511281
69 3511278
71 3511280
70 3511281
71 3511281
71 3511280
72 3511276
72 3511277
73 3511283
73 3511279
^C
The lm-sensors project (and therefore the sensors
command) makes use of the libsensor library; the libraries and package are:
Ubuntu 18.04: libsensors4, version 3.4.0-4
sudo apt install libsensors4
Ubuntu 20.04: libsensors5, version 3.6.0.
sudo apt install libsensors5
I also recommend to install the developer package (includes man pages), which is the same for LTS 18.04 and LTS 20.04:
sudo apt install libsensors4-dev
Some background information can no be found on:
man libsensors
man sensors.conf
BTW this is the same library which reads the temperature as seen in the sys
directory.
To sum it up, sensors is a good choice. Watching the temperature from command-line can be easily done by
watch -n 1 sensors
If you intend to write a program, take a look at the libsensors manual man libsensors
or make use of your /usr/share/doc/
documentation. In a C-program you have to include #include <sensors/sensors.h>
headers. It will use the sensors.conf
files /etc/sensors3.conf and/or /etc/sensors.conf. Further (users) configuration can be found in /etc/sensors.d/
, if you make use of this option.
If you think that you are missing some sensors take a look at the /sys/class/thermal
or the linked /sys/devices/virtual/thermal
directory.
To get the temperatures of the all thermal zones use the command
$ cat /sys/devices/virtual/thermal/thermal_zone?/temp
77000
66000
67000
The temperature is measured in miliCelcius (mC), in the case above, the temperature measured in celsius are: 77.0, 66.0, 67.0 °C.
To watch the temperatures continuously use
watch -n 1 cat /sys/devices/virtual/thermal/thermal_zone?/temp
In this directory you can also find information about your cooling (fan) devices, and how the PID regulators are programmed.
Further some over-temperature protection is coded firmware/hardware based (this is a good idea), and its set-up data is placed in your bios.
If you prefer to display the temperature in °C instead of °mC use the bash computation $((value / 1000 ))
or awk to make this conversion:
cat /sys/devices/virtual/thermal/thermal_zone?/temp | awk '{printf " %5.2f °C\n" , $1/1000}'