Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Measure Raspberry Pi CPU / GPU / Core / SD clock speeds and check whether you are undervolted
#!/bin/bash
# This bash script outputs the status of your Pi and checks whether you are being throttled for undervoltage and gives you your temperature
# Article and discussion at https://jamesachambers.com/measure-raspberry-pi-undervoltage-true-clock-speeds/
# Author James A Chambers 6-6-17
# updated throttle reason codes by tmuka 2021-10
# Output current configuration
vcgencmd get_config int | egrep "(arm|core|gpu|sdram)_freq|over_volt"
# Measure clock speeds
# for src in arm core h264 isp v3d; do echo -e "$src:\t$(vcgencmd measure_clock $src)"; done
# output human readable cpu speeds in GHz if you want raw data, use the previous line instead.
for src in arm core h264 isp v3d; do echo -e "$src:\t$(vcgencmd measure_clock $src | awk ' BEGIN { FS="=" } ; { printf("%.1fGHz\n", $2 / 1000000000) } ')"; done
# Measure Volts
for id in core sdram_c sdram_i sdram_p ; do echo -e "$id:\t$(vcgencmd measure_volts $id)"; done
# Measure Temperature
vcgencmd measure_temp
# See if we are being throttled
throttled="$(vcgencmd get_throttled)"
echo -e "$throttled"
if [[ $throttled != "throttled=0" ]]; then
# echo "WARNING: You are/have been throttled."
# updated warnings details based on https://raspberrypi.stackexchange.com/a/91433
# https://forum.libreelec.tv/thread/17860-how-to-interpret-rpi-vcgencmd-get-throttled/
# NOTE: The script is slightly out of date as bits 3 and 19 have now been added since the page was published. So
# 0x0 means nothing wrong
# 0x50000 means throttled has occurred since the last reboot.
# 0x50005 means you are currently under-voltage and throttled.
#
# Bit Hex value Meaning
# 0 1 Under-voltage detected
# 1 2 Arm frequency capped
# 2 4 Currently throttled
# 3 8 Soft temperature limit active
# 16 10000 Under-voltage has occurred
# 17 20000 Arm frequency capping has occurred
# 18 40000 Throttling has occurred
# 19 80000 Soft temperature limit has occurred
case $throttled in
"throttled=0x0")
echo "0x0 nothing wrong"
;;
"throttled=0x50000")
echo "0x50000 throttling occurred since last reboot"
;;
"throttled=0x50005")
echo "0x50005 currently under voltage and throttled."
;;
"throttled=0x1")
echo "0 1 Under-voltage detected"
;;
"throttled=0x2")
echo "1 2 Arm frequency capped"
;;
"throttled=0x4")
echo "2 4 Currently throttled"
;;
"throttled=0x8")
echo "3 8 Soft temperature limit active";
;;
"throttled=0x10000")
echo "16 10000 Under-voltage has occurred"
;;
"throttled=0x20000")
echo "17 20000 Arm frequency capping has occurred"
;;
"throttled=0x40000")
echo "18 40000 Throttling has occurred"
;;
"throttled=0x80000")
echo "19 80000 Soft temperature limit has occurred"
;;
esac
fi
@tmuka
Copy link
Author

tmuka commented Oct 26, 2021

Thanks for the useful script! I noticed it's reporting potential undervoltage for me, but I found some updated information about my throttling being due to temperature limits reached. I've updated your script with more reason codes. Feel free to incorporate them or use them however you like!

Thanks!

@tmuka
Copy link
Author

tmuka commented Oct 26, 2021

oh- i see there is more room for improvement as more than one of these bits may coexist. eg. i just saw "throttled=0x80008" which should report both present and past "soft temperature limit has occurred".

@tmuka
Copy link
Author

tmuka commented Nov 4, 2021

updated so the script outputs human readable clock speeds in GHz instead of raw Hz.

@tmuka
Copy link
Author

tmuka commented Nov 4, 2021

@Benik3
Copy link

Benik3 commented Feb 15, 2022

Hello.
Nice script, but I got error on line 24, because there are double brackets. After change to single bracket it's OK.

Also shouldn't be the result determined by bit mask, not only by comparison?

@tmuka
Copy link
Author

tmuka commented Feb 15, 2022

Hi @Benik3 the double brackets worked okay for me in Bash, maybe you're running a different shell? Yes, a bitmask would be better to detect when more than one of the conditions has occurred. I'd welcome your input on how to achieve that.

@Benik3
Copy link

Benik3 commented Feb 15, 2022

I'm running RPi Zero 2 W with latest Raspbian lite. I was connected with putty and run the bash simply by sh measurepi.sh
Maybe I will look on the bit mask, I'm new in RPi and bash, so I'm learning it just now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment