Search code examples
androidlinuxperformancecpufrequency

Can‘t Lock Android MTK 8050 CPU frequency


Recently, I've been trying to lock the CPU core frequency for performance testing on MTK 8050. However, after modifying the CPU frequency, the value remains unchanged. The phone already has root access.Here are some details

TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # ls -l
total 0
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 affected_cpus
-r-------- 1 root   root   4096 2023-09-21 12:49 cpuinfo_cur_freq
-r--r--r-- 1 root   root   4096 2023-09-21 12:45 cpuinfo_max_freq
-r--r--r-- 1 root   root   4096 2023-09-21 12:45 cpuinfo_min_freq
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 cpuinfo_transition_latency
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 related_cpus
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 scaling_available_frequencies
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 scaling_available_governors
-r--r--r-- 1 root   root   4096 2023-09-21 12:45 scaling_cur_freq
-r--r--r-- 1 root   root   4096 2023-09-21 12:49 scaling_driver
-rw-rw---- 1 system system 4096 2023-09-21 12:02 scaling_governor
-rw-rw-r-- 1 system system 4096 2023-09-20 21:15 scaling_max_freq
-rw-rw-r-- 1 system system 4096 2023-09-21 12:24 scaling_min_freq
-rw-r--r-- 1 root   root   4096 2023-09-21 12:51 scaling_setspeed
drwxr-xr-x 2 root   root      0 2023-09-21 12:45 stats
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # whoami
root
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # cat scaling_governor
userspace
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # cat scaling_available_frequencies
2600000 2507000 2354000 2200000 1985000 1855000 1740000 1624000 1537000 1451000 1335000 1162000 1046000 902000 700000 437000
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # echo 2600000 > scaling_setspeed
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 # cat scaling_setspeed
700000
TECNO-CK9n:/sys/devices/system/cpu/cpufreq/policy4 #



Solution

  • For Old Kernel (4.19 and lower)

    Mediatek completely nuke user ability to change CPU frequency using scaling_frequency. You must use procfs called "Performance and Power Management" or PPM to order change the Frequencies.

    It's important to enable PPM and policy "hard_userlimit" first.

    # cluster: Specify target cluster (big.LITTLE thing), started from 0
    # target_freq: Frequency target
    
    # Enable PPM
    echo 1 >/proc/ppm/enabled
    
    # Max frequency
    echo ${cluster} ${target_freq} >/proc/ppm/policy/hard_userlimit_max_cpu_freq
    
    # Min frequency
    echo ${cluster} ${target_freq} >/proc/ppm/policy/hard_userlimit_min_cpu_freq
    

    For Newer Kernel

    You could use scaling_frequency normally, but it will throttled by thermal service, however you could bypass it like this:

    cpu_num="cpu0 "# Bypass thermal throttle on this core
    max_freq="1700000" # Maximum freq for this core
    echo "$cpu_num $max_freq" >/sys/devices/virtual/thermal/thermal_message/cpu_limits