初试:优化高通cpu在MIUI上的配置

前言

当前手机硬件日新月异,在某种程度上手机硬件性能已经过剩,手机的性能反而在于软件上的优化。比如小米4搭载的高通801这款cpu四核2.5GHZ,性能已经不错,但是由于MIUI对cpu进行无脑的限频,均衡模式下,关闭两个核心,其他两个核心频率限制在1036MHz,1036MHz!这样无异于杀鸡用牛刀,而且用的是刀柄,连鸡都搞不定。估计把性能压得如此底,厂商也有自己的考虑吧。

正题

下面介绍要修改的cpu配置文件的含义
主要文件有
1、thermal-engine-8974.conf(system/etc目录下 )
2、changepowermode.sh(system/bin目录下)

####1、thermal-engine-8974.conf
用于设定cpu在指定条件下触发的动作的算法
初试:优化高通cpu在MIUI上的配置_第1张图片
其中各个属性含义:
sampling:取样时间
[CPU_MONITOR]:算法实例标签
algo_type:算法类型,共有4种: monitor, pid, ss, virtual
sensor:传感器
thresholds: 觉阈值(触发条件)
thresholds_clr:清除觉阈值(取消触发的动作的条件)
actions:动作
action_info:动作值

###changepowermode.sh
顾名思义,这个文件就是MIUI切换均衡模式和性能模式的命令文件。

target=`getprop ro.product.model`
powermode=`getprop persist.sys.aries.power_profile`
dev_governor=`ls /sys/class/devfreq/qcom,cpubw*/governor`
case "$target" in
    "MI 3W" | "MI 3C")
        case "$powermode" in
            "high")
                 echo 2265600                              > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
                 echo 20000                                > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                 echo 60                                   > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
                 echo 1190400                              > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
                 echo 70                                   > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                 echo 40000                                > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
                 echo 20                                   > /sys/module/cpu_boost/parameters/boost_ms
                 echo 1728000                              > /sys/module/cpu_boost/parameters/sync_threshold
                 echo 1497600                              > /sys/module/cpu_boost/parameters/input_boost_freq
                 echo 40                                   > /sys/module/cpu_boost/parameters/input_boost_ms
                 echo 255                                  > /sys/class/leds/lcd-backlight/max_brightness
                 echo 578000000                            > /sys/class/kgsl/kgsl-3d0/max_gpuclk
                 echo "msm_cpufreq"                        > $dev_governor
              ;;
            "middle")
                 echo 2265600                              > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
                 echo 2265600                              > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
                 echo "20000 1400000:40000 1700000:20000"  > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                 echo 90                                   > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
                 echo 1190400                              > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
                 echo "85 1500000:90 1800000:70"           > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                 echo 40000                                > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
                 echo 20                                   > /sys/module/cpu_boost/parameters/boost_ms
                 echo 1728000                              > /sys/module/cpu_boost/parameters/sync_threshold
                 echo 1190400                              > /sys/module/cpu_boost/parameters/input_boost_freq
                 echo 40                                   > /sys/module/cpu_boost/parameters/input_boost_ms
                 echo 255                                  > /sys/class/leds/lcd-backlight/max_brightness
                 echo 578000000                            > /sys/class/kgsl/kgsl-3d0/max_gpuclk
                 echo "cpubw_hwmon"                        > $dev_governor
             ;;
             "low")
                 echo 1036800                              > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
                 echo 1036800                              > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
                 echo 1036800                              > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
                 echo 1036800                              > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
                 echo "40000"                              > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                 echo 90                                   > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
                 echo 960000                               > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
                 echo "85 960000:70"                       > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                 echo 40000                                > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
                 echo 0                                    > /sys/module/cpu_boost/parameters/boost_ms
                 echo 960000                               > /sys/module/cpu_boost/parameters/sync_threshold
                 echo 960000                               > /sys/module/cpu_boost/parameters/input_boost_freq
                 echo 40                                   > /sys/module/cpu_boost/parameters/input_boost_ms
                 echo 100                                  > /sys/class/leds/lcd-backlight/max_brightness
                 echo 330000000                            > /sys/class/kgsl/kgsl-3d0/max_gpuclk
                 echo "cpubw_hwmon"                        > $dev_governor
              ;;
        esac
        ;;

    "LEO "* | "MI 4"* | "MI NOTE"* | "VIRGO"*)
        case "$powermode" in
            "high")
                 stop mpdecision
                 sleep 1
                 echo 1                                    > /sys/devices/system/cpu/cpu1/online
                 echo 1                                    > /sys/devices/system/cpu/cpu2/online
                 echo 1                                    > /sys/devices/system/cpu/cpu3/online
                 echo 1                                    > /sys/devices/system/cpu/cpu1/online
                 echo 1                                    > /sys/devices/system/cpu/cpu2/online
                 echo 1                                    > /sys/devices/system/cpu/cpu3/online
                 echo 2457600                              > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
                 echo performance                          > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                 echo performance                          > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
                 echo performance                          > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
                 echo performance                          > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
                 echo 20                                   > /sys/module/cpu_boost/parameters/boost_ms
                 echo 1728000                              > /sys/module/cpu_boost/parameters/sync_threshold
                 echo 1497600                              > /sys/module/cpu_boost/parameters/input_boost_freq
                 echo 40                                   > /sys/module/cpu_boost/parameters/input_boost_ms
                 echo 255                                  > /sys/class/leds/lcd-backlight/max_brightness
                 echo 578000000                            > /sys/class/kgsl/kgsl-3d0/max_gpuclk
                 echo performance                          > /sys/class/kgsl/kgsl-3d0/devfreq/governor
                 echo "msm_cpufreq"                        > $dev_governor
              ;;
            "middle")
                 echo interactive                          > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                 echo interactive                          > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
                 echo interactive                          > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
                 echo interactive                          > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
                 echo 2457600                              > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
                 echo 2457600                              > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq
                 echo "20000 1400000:40000 1700000:20000"  > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                 echo 90                                   > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
                 echo 1190400                              > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
                 echo "85 1500000:99"                      > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                 echo 40000                                > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
                 echo 20                                   > /sys/module/cpu_boost/parameters/boost_ms
                 echo 1497600                              > /sys/module/cpu_boost/parameters/sync_threshold
                 echo 1190400                              > /sys/module/cpu_boost/parameters/input_boost_freq
                 echo 40                                   > /sys/module/cpu_boost/parameters/input_boost_ms
                 echo 255                                  > /sys/class/leds/lcd-backlight/max_brightness
                 echo 578000000                            > /sys/class/kgsl/kgsl-3d0/max_gpuclk
                 echo msm-adreno-tz                        > /sys/class/kgsl/kgsl-3d0/devfreq/governor
                 echo "cpubw_hwmon"                        > $dev_governor
                 start mpdecision
             ;;
        esac
        ;;
esac

可以看到 "LEO "* | “MI 4”* | “MI NOTE”* | “VIRGO”*)
case “$powermode” in
“high”)
的部分,这是性能模式下的调节文件。
“middle”,是均衡模式的部分。

####根据changepowermode的内容,可知里面各个文件的主要功能:
1、/sys/devices/system/cpu/cpuX/cpufreq/scaling_governor
用于控制cpu0的运行模式
运行模式有6种:interactive,conservative,ondemand,userspace,powersave,performance

2、/sys/devices/system/cpu/cpuX/cpufreq/scaling_max_freq
用于控制cpu的最大频率,频率从300000~2457600(此为801的范围,其他型号各异)。系统就是通过这个文件来限频,修改此文件可以修改cpu最高频率。

3、/sys/devices/system/cpu/cpufreq/interactive/ 下的文件
above_hispeed_delay:跳到高频要花的时间(微妙)
go_hispeed_load:是高频阈值。当系统的负载超过该值,升频,否则降频。具体如何升频、如何降频,后面介绍。
hispeed_freq:高速状态的频率
target_loads:CPU的负载达到设定百分比时进入预设的频率
min_sample_time:下调频率的最小时间. 该值设置的越高, CPU降频越慢. 单位uS, 例如80000=80ms
target_loads: 一般情况下, 调速器根据target_loads参数调整频率, 负载超过设定值时提高频率, 反之则下降频率. 该值设置的越低, CPU越容易提升频率. 单位:%, 频率单位:KHz
above_hispeed_delay:当核心保持hispeed_freq超过一定时间(above_hispeed_delay), 且负载依然很高, CPU频率才会继续上升.
4、 /sys/module/cpu_boost/parameters/
boost_ms:加速时间
sync_threshold:同步阈值
input_boost_freq:检测到输入时加速的频率
input_boost_ms:检测到输入时的加速时间

5、除了以上文件,我还发现了对防止被系统反复修改为限频的两个很重要的文件,分别是/sys/devices/system/cpu/cpuX/cpufreq/sys_cap_freq和/sys/devices/system/cpu/cpu0/cpufreq/thermal_capp_freq。
sys_cap_freq:意为系统覆盖频率,调了一下里面的参数,发现如果从性能模式返回均衡模式,限频的就是这个参数
thermal_capp_freq:这个是性能模式的参数,同理。

###注意:修改文件需要使用RE管理器和获取root。
通过修改上面的参数,解除限频。经过测试,为了避免参数被系统修改,需要关闭MIUI的神隐模式。
以下是我自用的修改后的截图,较为激进,当然,保守的也可以自行修改。
thermal-engine-8974.conf

sampling         5000

[CPU0_MONITOR]
algo_type        monitor
sensor           cpu0
sampling         1000
thresholds       55000 60000 65000 70000 85000 105000 115000
thresholds_clr   50000 55000 60000 66000 80000 90000 110000
actions          cpu cpu cpu cpu cpu cpu shutdown
action_info      2457600 2457600 2457600 2457600 1728000 1036800 0

[CPU1_MONITOR]
algo_type        monitor
sensor           cpu1
sampling         65
thresholds       115000
thresholds_clr   110000
actions          shutdown
action_info      0

[CPU2_MONITOR]
algo_type        monitor
sensor           cpu2
sampling         65
thresholds       115000
thresholds_clr   110000
actions          shutdown
action_info      0

[CPU3_MONITOR]
algo_type        monitor
sensor           cpu3
sampling         65
thresholds       115000
thresholds_clr   110000
actions          shutdown
action_info      0

[BATTERY_MONITOR]
algo_type        monitor
sensor           batt_temp
sampling         1000
thresholds       380 395 500 550
thresholds_clr   370 385 450 500
actions          cpu cpu cpu cpu
action_info      2457600  2457600 2457600 2457600

/sys/devices/system/cpu/cpuX/cpufreq/scaling_max_freq

2457600

/sys/devices/system/cpu/cpuX/cpufreq/sys_cap_freq

2457600

其他文件的保持不变。
性能监视器下截图:初试:优化高通cpu在MIUI上的配置_第2张图片

完毕。

你可能感兴趣的:(初试:优化高通cpu在MIUI上的配置)