Created
June 20, 2019 13:51
-
-
Save superna9999/d4de964dbc0f84b7d527e1df2ddea25f to your computer and use it in GitHub Desktop.
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/sh | |
if [ "$#" -gt 0 ] ; then | |
if [ "$1" == "1" ] ; then | |
CPU="cpu0" | |
MSR="sys_cpu_div16" | |
devmem 0xFF63C15C 32 0x15002A2 | |
elif [ "$1" == "2" ] ; then | |
CPU="cpu2" | |
MSR="sys_cpub_div16" | |
devmem 0xFF63C200 32 0x15002A2 | |
else | |
echo "Invalid CPU cluster" | |
exit 1 | |
fi | |
else | |
echo "Usage: $0 <cpu cluster, 1 or 2> [debug]" | |
exit 1 | |
fi | |
DEBUG="$2" | |
# mount debugfs if not mounted yet | |
[ -d /sys/kernel/debug/meson-clk-msr ] || mount -t debugfs none /sys/kernel/debug | |
FREQS=`cat /sys/bus/cpu/devices/$CPU/cpufreq/scaling_available_frequencies` | |
echo 1 > /sys/bus/cpu/devices/$CPU/cpufreq/stats/reset | |
while true ; do | |
clear | |
cat /sys/bus/cpu/devices/$CPU/cpufreq/stats/trans_table | |
for f in $FREQS ; do | |
TARGET=`expr $f \* 1000` | |
[ $DEBUG ] && echo "=> $TARGET" | |
echo $f > /sys/bus/cpu/devices/$CPU/cpufreq/scaling_setspeed ; | |
MIN=`expr $TARGET \* 99 / 100` | |
MAX=`expr $TARGET \* 101 / 100` | |
CUR=`cat /sys/kernel/debug/meson-clk-msr/clks/$MSR | cut -f 1` | |
CURRENT=`expr $CUR \* 16` | |
[ $DEBUG ] && echo "<= $CURRENT" | |
if [ $CURRENT -gt $MAX -o $CURRENT -lt $MIN ] ; then | |
echo invalid $CURRENT != $TARGET | |
exit 1 | |
fi | |
[ $DEBUG ] && echo $TARGET == $CURRENT | |
for g in $FREQS ; do | |
TARGET=`expr $g \* 1000` | |
[ $DEBUG ] && echo "=> $TARGET" | |
echo $g > /sys/bus/cpu/devices/$CPU/cpufreq/scaling_setspeed ; | |
MIN=`expr $TARGET \* 99 / 100` | |
MAX=`expr $TARGET \* 101 / 100` | |
CUR=`cat /sys/kernel/debug/meson-clk-msr/clks/$MSR | cut -f 1` | |
CURRENT=`expr $CUR \* 16` | |
[ $DEBUG ] && echo "<= $CURRENT" | |
[ $DEBUG ] && echo $TARGET == $CURRENT | |
if [ $CURRENT -gt $MAX -o $CURRENT -lt $MIN ] ; then | |
echo invalid $CURRENT != $TARGET | |
exit 1 | |
fi | |
TARGET=`expr $f \* 1000` | |
[ $DEBUG ] && echo "=> $TARGET" | |
echo $f > /sys/bus/cpu/devices/$CPU/cpufreq/scaling_setspeed ; | |
MIN=`expr $TARGET \* 99 / 100` | |
MAX=`expr $TARGET \* 101 / 100` | |
CUR=`cat /sys/kernel/debug/meson-clk-msr/clks/$MSR | cut -f 1` | |
CURRENT=`expr $CUR \* 16` | |
[ $DEBUG ] && echo "<= $CURRENT" | |
[ $DEBUG ] && echo $TARGET == $CURRENT | |
if [ $CURRENT -gt $MAX -o $CURRENT -lt $MIN ] ; then | |
echo invalid $CURRENT != $TARGET | |
exit 1 | |
fi | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment