SHARE
TWEET

watch-your-pi-0.3.sh

a guest Apr 7th, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # Watch your Pi! RPi foundation knows that Micro USB for DC-IN
  4. # is sh*t but also don't give a sh*t. Voltage drops caused by
  5. # average USB cables cause all sorts of instabilities and also
  6. # data corruption but instead of fixing the problem they masked
  7. # it in their 'firmware'. The main CPU on the Raspberry monitors
  8. # voltage drops and then acts on accordingly. If heavy voltage
  9. # drops directly after startup are monitored the firmware lowers
  10. # the core voltage available to CPU cores and also caps CPU
  11. # clockspeed. If voltage drops aren't that severe a more flexible
  12. # approach is used and at least you gain performance back after
  13. # periods of heavy load.
  14. #
  15. # The monitoring script prints SoC temperature, sysfs clockspeed
  16. # (and real clockspeed if differing -- this can happen on RPi 3),
  17. # 'vcgencmd get_throttled' bits and core voltage. To interpret
  18. # the 'get_throttled' bits please refer to this:
  19. #
  20. # 0: under-voltage
  21. # 1: arm frequency capped
  22. # 2: currently throttled
  23. # 16: under-voltage has occurred
  24. # 17: arm frequency capped has occurred
  25. # 18: throttling has occurred
  26. #
  27. # Background info: http://preview.tinyurl.com/mmwjfwy and
  28. # http://tech.scargill.net/a-question-of-lifespan/
  29. #
  30. # With a crappy PSU and/or Micro USB cable output looks like this
  31. # on a RPi 3:
  32. #
  33. # 44.0'C  600 MHz 1010000000000000000 1.2V
  34. # 44.5'C  600 MHz 1010000000000000000 1.2V
  35. # 44.0'C  600 MHz 1010000000000000101 1.2V
  36. # 44.0'C  600 MHz 1010000000000000101 1.2V
  37. # 44.0'C  600 MHz 1010000000000000101 1.2V
  38. # 44.5'C  600 MHz 1010000000000000000 1.2V
  39. # 45.1'C  600 MHz 1010000000000000101 1.2V
  40. #
  41. # With an ok-ish cable it looks like this (when running cpuburn-a53):
  42. #
  43. # 48.3'C 1200 MHz 0000000000000000000 1.3312V
  44. # 48.3'C 1200 MHz 0000000000000000000 1.3312V
  45. # 48.3'C 1200 MHz 0000000000000000000 1.3312V
  46. # 48.3'C 1200 MHz 0000000000000000000 1.3312V
  47. # 50.5'C 1200 MHz 0000000000000000000 1.3312V
  48. # 56.4'C  600 MHz 0000000000000000000 1.2V
  49. # 54.8'C  600 MHz 1010000000000000101 1.2V
  50. # 55.3'C  600 MHz 1010000000000000101 1.2V
  51. # 55.8'C  600 MHz 1010000000000000101 1.3312V
  52. # 53.7'C  600 MHz 1010000000000000101 1.2V
  53. # 51.5'C  600 MHz 1010000000000000101 1.2V
  54. # 51.0'C  600 MHz 1010000000000000101 1.2V
  55. #
  56. # And only by bypassing the crappy connector you can enjoy RPi 3
  57. # performing as it should (please note, there's a heatsink on the SoC
  58. # -- without throttling would start and then reported clockspeed
  59. # numbers start to get funny):
  60. #
  61. # 75.2'C 1200 MHz 1010000000000000000 1.3250V
  62. # 75.8'C 1200 MHz 1010000000000000000 1.3250V
  63. # 75.8'C 1200 MHz 1010000000000000000 1.3250V
  64. # 76.3'C 1200 MHz 1010000000000000000 1.3250V
  65. # 76.3'C 1200 MHz 1010000000000000000 1.3250V
  66. # 73.6'C 1200 MHz 1010000000000000000 1.3250V
  67. # 72.0'C 1200 MHz 1010000000000000000 1.3250V
  68. # 70.4'C 1200 MHz 1010000000000000000 1.3250V
  69. #
  70. # Now with a pillow on top for some throttling:
  71. #
  72. # 82.2'C 1200/ 947 MHz 1110000000000000010 1.3250V
  73. # 82.7'C 1200/ 933 MHz 1110000000000000010 1.3250V
  74. # 82.7'C 1200/ 931 MHz 1110000000000000010 1.3250V
  75. # 82.7'C 1200/ 918 MHz 1110000000000000010 1.3250V
  76. # 82.2'C 1200/ 935 MHz 1110000000000000010 1.3250V
  77. # 79.9'C 1200/1163 MHz 1110000000000000000 1.3250V
  78. # 75.8'C 1200 MHz 1110000000000000000 1.3250V
  79. #
  80. # And here on RPi 2 with crappy USB cable and some load
  81. #
  82. # 50.8'C  900 MHz 1010000000000000000 1.3125V
  83. # 49.8'C  900 MHz 1010000000000000000 1.3125V
  84. # 49.8'C  900/ 600 MHz 1010000000000000101 1.2V
  85. # 49.8'C  900/ 600 MHz 1010000000000000101 1.2V
  86. # 48.7'C  900/ 600 MHz 1010000000000000101 1.2V
  87. # 49.2'C  900/ 600 MHz 1010000000000000101 1.2V
  88. # 48.7'C  900 MHz 1010000000000000000 1.3125V
  89. # 46.5'C  900 MHz 1010000000000000000 1.3125V
  90. #
  91. # The funny thing is that while the kernel thinks it's running
  92. # with 900 MHz (performance governor) in reality the 'firmware'
  93. # throttles down to 600 MHz but no one knows :)
  94.  
  95. echo -e "To stop simply press [ctrl]-[c]\n"
  96. Maxfreq=$(( $(awk '{printf ("%0.0f",$1/1000); }'  </sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) -15 ))
  97. while true ; do
  98.     Health=$(perl -e "printf \"%19b\n\", $(vcgencmd get_throttled | cut -f2 -d=)")
  99.     Temp=$(vcgencmd measure_temp | cut -f2 -d=)
  100.     RealClockspeed=$(vcgencmd measure_clock arm | awk -F"=" '{printf ("%0.0f",$2/1000000); }' )
  101.     SysFSClockspeed=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
  102.     CoreVoltage=$(vcgencmd measure_volts | cut -f2 -d= | sed 's/000//')
  103.     if [ ${RealClockspeed} -ge ${Maxfreq} ]; then
  104.         echo -e "${Temp}$(printf "%5s" ${SysFSClockspeed}) MHz $(printf "%019d" ${Health}) ${CoreVoltage}"
  105.     else
  106.         echo -e "${Temp}$(printf "%5s" ${SysFSClockspeed})/$(printf "%4s" ${RealClockspeed}) MHz $(printf "%019d" ${Health}) ${CoreVoltage}"
  107.     fi
  108.     sleep 5
  109. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top