#!/bin/bash # You can change these values to suit. TEMPERATURE_MAX=90 THROTTLED_CLOCK=1000000 # You can limit the top speed to less than the default maximum by setting # MAX_CLOCK to the clock speed in KHz. MAX_CLOCK=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies | sed -e 's/.* \([0-9]* $\)/\1/'` # We set the speed to MAX_CLOCK, just in case it is lower than the actual # maximum echo $MAX_CLOCK > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo $MAX_CLOCK > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq while [ 1 ]; do current_max_clock=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq` temperature=`sensors | grep temp2 | sed -e 's/temp2: *+//' -e 's/°.*//' -e 's/\.[0-9]//'` # Uncomment the following two lines for extra debug verbosity # echo "Current temperature: $temperature" # echo "Current maximum clock: $current_max_clock" # if temperature exceeds the throttling threshold... if [ $temperature -gt $TEMPERATURE_MAX ]; then # ... and if we aren't already throttled ... if [ $current_max_clock -gt $THROTTLED_CLOCK ]; then # ... reduce scaling_max_freq to $THROTTLED_CLOCK echo "CPU temperature exceeds $TEMPERATURE_MAX C. Reducing speed to $THROTTLED_CLOCK KHz" echo $THROTTLED_CLOCK > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo $THROTTLED_CLOCK > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq sleep 2 fi # if temperature is below the throttling threshold ... else # ... and if we aren't at $MAX_CLOCK already ... if [ $current_max_clock -lt $MAX_CLOCK ]; then # Unthrottle echo "CPU temperature below $TEMPERATURE_MAX C. Boosting speed to $MAX_CLOCK KHz" echo $MAX_CLOCK > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo $MAX_CLOCK > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq fi fi sleep 1 done