This project is about understanding how your computer measures temperature. We'll learn how the system checks how hot your CPU (the main brain of your computer) is getting!
Your computer has a special tool called a sensor that watches the temperature of your CPU. Think of it like a thermometer, but for your computer's brain!
On Linux systems using XFCE desktop, the temperature display is usually shown in the taskbar (the bar at the bottom or top of your screen).
If you want to see your CPU temperature on your taskbar, follow these simple steps:
Run this command in your terminal:
xfce4-panel --preferences- Right-click on the taskbar
- Click "Add new items" (you'll see this option when you hover over the panel)
- A window will pop up - select "Sensor Plugin"
Once you follow these steps, your computer is using this program to measure temperature:
xfce4-sensors-plugin
This is just a tool that reads and displays the temperature - it's not actually measuring it directly. It just shows you the number!
The real temperature measurement happens deep inside your computer. Let's trace where:
The program doing the actual work is called xfce4-sensors-plugin, which is part of the XFCE project:
📎 Source Code: https://gitlab.xfce.org/panel-plugins/xfce4-sensors-plugin
You can use a helpful trick to read the code more easily:
- Go to the GitHub link
- Replace
github.comwithgithub.devin the URL - This opens the code in a special viewer inside your web browser - much easier to explore!
You can also use this helpful project: GitNexus (https://github.com/abhigyanpatwari/GitNexus) - it helps you understand code better.
After digging deep into the code, we found something important:
The plugin is just a reader - it reads information that's already been measured by something else. It gets the temperature data from:
/sys/class/hwmon/- a special folder in Linuxlibsensors- a library that reads sensorslm-sensors- Linux monitoring tools
All of these ultimately come from something called the kernel driver named coretemp.
Your CPU Hardware → Kernel Driver (coretemp) → Linux System Files → XFCE Plugin → Your Screen
To check which sensor driver your computer uses, run this command:
for hw in /sys/class/hwmon/hwmon*; do
echo "=== $hw ==="
cat $hw/name
donecoretemp- If you have an Intel processork10temp- If you have an AMD processor
A kernel driver is a special program that talks directly to your hardware. It's the real sensor that's actually measuring temperature!
After you know which sensor you have (like coretemp), you can find where its code is stored.
readlink -f /sys/class/hwmon/hwmon0/deviceThis command finds the actual physical location of your sensor. It might show something like:
/sys/devices/platform/coretemp.0
What does this mean?
coretemp= your temperature sensor driverhwmon= short for "Hardware Monitor"
Use this command to get information about the driver:
modinfo coretempThis will show you where the kernel driver file is stored. On some systems, it might be at:
/lib/modules/6.18.12+kali-amd64/kernel/drivers/hwmon/coretemp.ko.xz
Your CPU has special registers (tiny memory areas) that store information. Your computer:
- Reads the current temperature data from these registers
- Does some math to turn the raw data into degrees Celsius
- Saves the result so programs like XFCE can read it
- Displays it on your screen
Here's the journey of temperature measurement:
Hardware (MSR 0x19C Register)
↓ Raw temperature data is read (DTS bits)
↓ Maximum safe temperature is read (TjMax from MSR 0x1A2)
↓ Math formula is used: Temp = TjMax − DTS
↓ coretemp kernel driver saves this to /sys files
↓ xfce4-sensors-plugin reads /sys files
↓ Temperature appears on your taskbar!
Here's how your computer calculates the actual temperature:
The CPU's temperature sensor (DTS - Digital Thermal Sensor) reads the raw data from a special location called MSR 0x19C.
The system reads the maximum allowed temperature (TjMax) from another location called MSR 0x1A2. This is different for each CPU type!
Temperature = TjMax − DTS_value
For example, if TjMax is 95°C and DTS is 20, then:
Temperature = 95 − 20 = 75°C
The kernel driver saves this number to the Linux file system, and XFCE reads it and shows it on your screen!
These are the special memory areas your CPU uses:
| Register | Purpose |
|---|---|
| 0x1A2 | Stores the maximum safe temperature (TjMax) |
| 0xEE | Backup location if 0x1A2 doesn't work |
| 0x17 | Third backup location |
| 0x19C | Stores the actual temperature reading (DTS) |
While the temperature sensor does a good job, it has some limitations:
Each temperature reading is independent. If your CPU gets a quick spike of heat, you might see a big jump in temperature (10°C in one second!). It doesn't smooth out quick changes.
The maximum safe temperature (TjMax) is read once when your computer starts up. If your BIOS (computer settings) tells it the wrong number, all readings will be wrong forever.
The temperature is stored as whole numbers only. So if the real temperature is 63.7°C, you'll only see 63 or 64°C on your screen.
Real silicon (the material of your CPU) has something called "thermal mass" - it takes time to heat up and cool down. The sensor doesn't account for this physics.
The temperature sensor doesn't talk to your cooling fan. The sensor and fan system are completely separate - they don't share information.
If you want to check if your temperature is being measured correctly, you can run this script:
#!/usr/bin/env bash
sudo modprobe msr >/dev/null 2>&1
# Read the maximum safe temperature for each core
RAW_TJ0=$(sudo rdmsr -p 0 0x1A2 2>/dev/null)
RAW_TJ1=$(sudo rdmsr -p 1 0x1A2 2>/dev/null)
TJ0=$(( (0x$RAW_TJ0 >> 16) & 0xFF ))
TJ1=$(( (0x$RAW_TJ1 >> 16) & 0xFF ))
[ "$TJ0" -eq 0 ] || [ "$TJ0" -gt 125 ] && TJ0=95
[ "$TJ1" -eq 0 ] || [ "$TJ1" -gt 125 ] && TJ1=95
echo "Per-core Maximum Temperature → Core 0: ${TJ0}°C Core 1: ${TJ1}°C"
echo ""
while true; do
# Get the timestamp
T_READ=$(date '+%H:%M:%S.%N')
# Read the normal system files
SYS2=$(cat /sys/class/hwmon/hwmon0/temp2_input 2>/dev/null || echo 0)
SYS3=$(cat /sys/class/hwmon/hwmon0/temp3_input 2>/dev/null || echo 0)
# Read the raw hardware data
RAW0=$(sudo rdmsr -p 0 0x19C 2>/dev/null)
RAW1=$(sudo rdmsr -p 1 0x19C 2>/dev/null)
T_MSR=$(date '+%H:%M:%S.%N')
# Do the math to calculate temperature
F0=$(( 0x$RAW0 )); F1=$(( 0x$RAW1 ))
VALID0=$(( (F0 >> 31) & 1 ))
VALID1=$(( (F1 >> 31) & 1 ))
DTS0=$(( (F0 >> 16) & 0x7F ))
DTS1=$(( (F1 >> 16) & 0x7F ))
MSR0=$(( TJ0 - DTS0 ))
MSR1=$(( TJ1 - DTS1 ))
S0=$(( SYS2 / 1000 ))
S1=$(( SYS3 / 1000 ))
DIFF0=$(( MSR0 - S0 ))
DIFF1=$(( MSR1 - S1 ))
# Check if CPU is being throttled (slowed down due to heat)
THR0=$(( F0 & 1 ))
THR1=$(( F1 & 1 ))
# Find the highest temperature of both cores
PKG_MSR=$(( MSR0 > MSR1 ? MSR0 : MSR1 ))
PKG_SYS=$(( S0 > S1 ? S0 : S1 ))
# Display the results nicely
clear
printf "%-22s %10s %10s\n" "" "Core 0" "Core 1"
printf "%-22s %9s°C %9s°C\n" "Max Temp" "$TJ0" "$TJ1"
printf "%-22s %10s %10s\n" "Raw Data" "$DTS0" "$DTS1"
printf "%-22s %9s°C %9s°C\n" "Calculated" "$MSR0" "$MSR1"
printf "%-22s %9s°C %9s°C\n" "System Read" "$S0" "$S1"
printf "%-22s %9s°C %9s°C\n" "Difference" "$DIFF0" "$DIFF1"
printf "%-22s %10s %10s\n" "Valid Data" "$VALID0" "$VALID1"
printf "%-22s %10s %10s\n" "Throttling" \
"$([ $THR0 -eq 1 ] && echo YES || echo No)" \
"$([ $THR1 -eq 1 ] && echo YES || echo No)"
echo ""
echo "Package (Highest of Both Cores)"
printf " Calculated: %d°C System: %d°C Difference: %d°C\n" \
"$PKG_MSR" "$PKG_SYS" "$(( PKG_MSR - PKG_SYS ))"
echo ""
echo "Read time : $T_READ"
echo "Data time : $T_MSR"
sleep 1
done- Compares the temperature calculated from raw hardware data
- With the temperature shown by the normal system
- Shows if they match (they should be very close!)
If the difference is only 1°C or less, your temperature measurement is working correctly! ✅
Here's the complete flow from your CPU to your screen:
Your CPU Hardware
↓ (reads MSR 0x19C register)
Kernel Driver (coretemp.ko)
↓ (applies math formula)
System Files (/sys/class/hwmon/)
↓ (caches every ~250 milliseconds)
Linux Software
↓ (reads the files)
XFCE Sensors Plugin
↓ (shows the number)
Your Taskbar Display
- Hardware - Actually measures the temperature using the Digital Thermal Sensor
- Kernel Driver - Does the math: Temperature = TjMax - DTS
- System Files - Makes temperature available for any program to read
- XFCE Plugin - Reads the temperature and displays it
- Your Screen - Shows you the number!
Your computer's temperature measurement system works by:
- Reading raw sensor data from special CPU registers
- Doing math to convert that data to degrees
- Saving it to files that programs can read
- Displaying it on your screen
The amazing part? It all happens automatically, hundreds of times per second! 🚀
Now you understand how your computer checks its own temperature! 🎉