Skip to content

Instantly share code, notes, and snippets.

@superna9999
Created June 20, 2019 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save superna9999/d4de964dbc0f84b7d527e1df2ddea25f to your computer and use it in GitHub Desktop.
Save superna9999/d4de964dbc0f84b7d527e1df2ddea25f to your computer and use it in GitHub Desktop.
#!/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