🛠 Surveillance thermique et bridage : le sprint-marathon
Objectives
Instrument the specific thermal management of the 3B+: the default soft limit at 60 °C (temp_soft_limit, capped at 70 °C) which drops the CPU from 1.4 GHz to 1.2 GHz, followed by hard throttling between 80 and 85 °C. You will learn how to read temperature, frequency, and the throttling mask via vcgencmd, generate a test load, and log everything using systemd.
Hardware
- Raspberry Pi 3 Model B+ board (ideally with a heatsink or small ventilated case)
- 5.1 V / 2.5 A power supply (the undervoltage bit skews measurements)
sudo apt install -y sysbenchfor the test load
Complete code
#!/usr/bin/env bash
# thermal-watch.sh — journalise temperature, frequence ARM et masque de bridage.
# vcgencmd parle au GPU : c'est la source exacte selon la doc officielle.
LOG=/var/log/thermal.csv
[ -f "$LOG" ] || echo "horodatage,temp_c,arm_mhz,throttled" > "$LOG"
while true; do
temp=$(vcgencmd measure_temp | cut -d= -f2 | tr -d "'C")
clk=$(( $(vcgencmd measure_clock arm | cut -d= -f2) / 1000000 ))
# Masque : bit 0 sous-tension ; bit 3 (valeur 8) frequence bridsee ;
# bit 5 (32) sous-tension subie ; bit 6 (64) limite douce ; bit 8 (256) limite dure.
thr=$(vcgencmd get_throttled | cut -d= -f2)
echo "$(date -Is),${temp},${clk},${thr}" >> "$LOG"
printf "temp=%s C arm=%s MHz throttled=%s\r" "$temp" "$clk" "$thr"
sleep 1
done
# Lancer la surveillance et la charge en parallele
sudo ./thermal-watch.sh &
sysbench cpu --cpu-max-prime=20000 --time=600 run # 10 min de charge quad-core
# Attendu : 1400 MHz sous 60 C, puis 1200 MHz au-dessus (limite douce),
# puis bridage progressif 80-85 C. temp_soft_limit se regle dans config.txt.
Expected verification
Under load, the CSV shows the step: frequency stays at 1400 MHz as long as the sensor remains below 60 °C, then drops to 1200 MHz with the soft limit bit lighting up in get_throttled. At idle, everything returns to normal. An undervoltage bit (bit 0/5) lighting up indicates a power supply issue, not heat.
Common errors
- Confusing thermal throttling and undervoltage: the
get_throttledmask distinguishes the two — read each bit. - Raising
temp_soft_limitabove 60: possible only up to 70 °C, and "may cause instability" according to the documentation;force_turbo=1+over_voltage_*burns the overclock bit into the SoC. - Measuring with
cat /sys/class/thermal/...and comparing to the GPU: the official reference remainsvcgencmd measure_temp. - Closed case without airflow: thermal mass is a resource that is exhausted within a few minutes of quad-core load.
- Forgetting to stop the background script:
sudo pkill -f thermal-watch.sh; otherwise the CSV grows indefinitely — consider using logrotate. - Using a 1 A phone charger: permanent false throttling events that pollute measurements.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython