Created
May 10, 2022 13:26
-
-
Save stanislavvv/82a9b35c745c7ea7571dbd683e08a806 to your computer and use it in GitHub Desktop.
thermald replacement for arm singleboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# get temperature and on thresholds change system frequencies to lower or higher | |
# tested only on Orange Pi 3 LTS | |
TEMPPATH="/sys/devices/virtual/thermal/thermal_zone*" | |
TEMPFILENAME="temp" | |
TEMP_MAX=84000 | |
TEMP_MIN=77000 | |
AVAIL_FREQ=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies | |
CURR_FREQ=/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq | |
get_temp() { | |
cat $TEMPPATH/$TEMPFILENAME | sort -n -r | head -1 | |
} | |
get_lower_freq() { | |
CFREQ=$(cat $CURR_FREQ) | |
RET=$(cat $AVAIL_FREQ | cut -f1 -d' ') | |
for i in $(cat $AVAIL_FREQ); do | |
if [[ $CFREQ -gt $i ]]; then | |
RET=$i | |
fi | |
done | |
echo $RET | |
} | |
get_higher_freq() { | |
CFREQ=$(cat $CURR_FREQ) | |
RET=$(cat $AVAIL_FREQ | awk '{ print $(NF) }') | |
for i in $(cat $AVAIL_FREQ | awk '{ for (i=NF; i>=1; i--) printf("%s ",$i);}'); do | |
if [[ $CFREQ -lt $i ]]; then | |
RET=$i | |
fi | |
done | |
echo $RET | |
} | |
new_freq() { | |
RET=$(cat $CURR_FREQ) | |
TEMP=$(get_temp) | |
if [[ $TEMP -gt $TEMP_MAX ]]; then | |
RET=$(get_lower_freq) | |
elif [[ $TEMP -lt $TEMP_MIN ]]; then | |
RET=$(get_higher_freq) | |
fi | |
echo $RET | |
} | |
main() { | |
CFREQ=$(cat $CURR_FREQ) | |
NFREQ=$(new_freq) | |
if [[ $CFREQ -ne $NFREQ ]]; then | |
echo "temperature: $(get_temp), setting frequency to $NFREQ" | |
cpufreq-set -u $NFREQ | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment