如何锁定Android系统CPU的频率

接触到了Android系统的Performance测试,所以有锁定CPU的需求:

由于要首先读取到此系统所支持的CPU频率,之后再所支持的频率中选取你想要的频率,之后进行锁定。

这个过程,手动也是可以的,直接:

1.查看所支持的CPU频率:

adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

返回的结果是:416000 728000 900000 1040000

2.从上边的结果中选取一个416000 ,之后进行设定:

echo 416000  > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 416000  > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

之后运行adb shell环境,输入

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

查看设置是否有效,假如一直是416000,则证明设置生效。

由于每次都要输入以上代码查看之后设置,所以考虑用自动化实现,代码如下:

setFrequence.bat文件:

@adb shell setprop persist.service.thermal 0
@adb wait-for-device

@adb root
@adb wait-for-device
@adb remount

@for /f "tokens=*" %%i in ('adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies') do @set var=%%i 

@echo All cpufreqs are: %var%

@set /p last=please input your freq:

::@echo My cpufreq is: %last%

@adb push .run.sh /system/bin/

@adb shell chmod -R 777 /system/bin

@adb shell /system/bin/run.sh --Cpufreq=%last%

run.sh文件:

#!system//bin/sh

while [ $# -gt 0 ]; do
    case $1 in
      --Cpufreq=*)
        cpufreq=${1#--Cpufreq=}
        ;;
    esac
    shift
  done

#echo cpufreq=`echo $cpufreq`
echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq  

echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq  

echo scaling_min_freq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`
echo scaling_max_freq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`


echo scaling_cur_freq=
i=10
while [[ $i -gt 1 ]];
do
 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq;
 sleep 5;
 ((i--));
done

把上边两个文件放到一个folder下边,双击执行setFrequence.bat文件,输入你想要的频率即可。

原文地址:https://www.cnblogs.com/yajing-zh/p/5055047.html