diff options
author | PA4WDH | 2023-05-20 14:11:46 +0200 |
---|---|---|
committer | PA4WDH | 2023-05-20 14:11:46 +0200 |
commit | 5ae6c94265a112badb6ef1d7793d367eedb9a41c (patch) | |
tree | 9c1be9256d3af515fd78215ea022a8decc88f67f /poc | |
download | cputemp2maxfreq-5ae6c94265a112badb6ef1d7793d367eedb9a41c.tar.gz cputemp2maxfreq-5ae6c94265a112badb6ef1d7793d367eedb9a41c.tar.bz2 cputemp2maxfreq-5ae6c94265a112badb6ef1d7793d367eedb9a41c.zip |
Initial commit, POC shell script
Diffstat (limited to 'poc')
-rwxr-xr-x | poc/cputemp2maxfreq.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/poc/cputemp2maxfreq.sh b/poc/cputemp2maxfreq.sh new file mode 100755 index 0000000..f2da851 --- /dev/null +++ b/poc/cputemp2maxfreq.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +TEMP_INPUT=/sys/devices/virtual/thermal/thermal_zone0/temp +TEMP_MAX=70000 +FREQ_STEP=100000 + +read CPU_MIN < /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq +read CPU_MAX < /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq +read GOV_MAX < /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq + +CPUS=`find /sys/devices/system/cpu -name "cpufreq" -type l` + +set_max_freq() +{ + local NEWFREQ=$1 + + for CPU in $CPUS + do + echo "$NEWFREQ" > "$CPU/scaling_max_freq" + done + + sleep 0.1 + read GOV_MAX < /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq +} + +while true +do + read TEMP < /sys/devices/virtual/thermal/thermal_zone0/temp + read CPU_CUR < /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq + printf "$TEMP $TEMP_MAX $CPU_MAX $GOV_MAX $CPU_CUR" + if [ "$TEMP" -lt "$TEMP_MAX" -a "$GOV_MAX" -lt "$CPU_MAX" ] + then + DIFF=$(((TEMP_MAX-TEMP)/1000)) + NEWFREQ=$((GOV_MAX+(FREQ_STEP*DIFF))) + if [ "$NEWFREQ" -gt "$CPU_MAX" ] + then + NEWFREQ=$CPU_MAX + fi + printf " Increase GOV_MAX to $NEWFREQ" + set_max_freq $NEWFREQ + fi + if [ "$TEMP" -gt "$TEMP_MAX" -a "$GOV_MAX" -gt "$CPU_MIN" ] + then + DIFF=$(((TEMP-TEMP_MAX)/1000)) + NEWFREQ=$((GOV_MAX-(FREQ_STEP*DIFF))) + if [ "$NEWFREQ" -lt "$CPU_MIN" ] + then + NEWFREQ=$CPU_MIN + fi + printf " Decrease GOV_MAX to $NEWFREQ" + set_max_freq $NEWFREQ + fi + echo "" + sleep 10 +done |