Android中adb设置cpu频率

cpu频率设定

一般情况,我们在做效能测试的时候,希望得到的结果稳定,而效能测试的一个关键因素就是CPU的频率,当我们期望CPU频率保持在最大或者某一个值的时候,可以通过adb来设置
下边脚本,可以直接运行和设置

设置CPU频率脚本

#!/bin/bash

echo "cpu 0 freq"
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
adb shell "echo "2100000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

echo "cpu 1 freq"  
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
adb shell "echo "1600000" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_setspeed"

echo "cpu 2 freq"  
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
adb shell "echo "1600000" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_setspeed"

echo "cpu 3 freq"  
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
adb shell "echo "2100000" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_setspeed"

echo "cpu 4 freq"  
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor"
adb shell "echo "2100000" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_setspeed"

echo "cpu 5 freq"  
adb shell "echo "userspace" > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor"
adb shell "echo "2100000" > /sys/devices/system/cpu/cpu5/cpufreq/scaling_setspeed"

check cpu频率脚本

#!/bin/bash


for ((i=0;i<3000000;i++));
do
        echo "\n\n========test cnt ${i}======="
        echo "cpu 0 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"

	echo "cpu 1 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq"

	echo "cpu 2 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq"

	echo "cpu 3 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq"

	echo "cpu 4 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq"

	echo "cpu 5 freq"  
	adb shell "cat /sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_cur_freq"
done

此处我们需要多次check,保证我们设置确实成功了。

cpufreq中参数说明

scaling_setspeed–设置cpu运行的频率
cpuinfo_cur_freq–CPU当前运行的频率
cpuinfo_max_freq—CPU可以运行的最大频率
cpuinfo_min_freq—CPU最小运行频率
scaling_governor—控制CPU频率的调整方式

你可能感兴趣的:(Android&TEE,android,adb)