CPU cores, frequency and policy control of Android system

1, / sys/devices/system/cpu directory

Z91:/sys/devices/system/cpu # ls -all
ls -all
total 0
drwxr-xr-x 13 root root    0 2018-01-09 11:17 .
drwxr-xr-x  6 root root    0 2018-01-09 11:17 ..
drwxr-xr-x  5 root root    0 2018-01-09 11:17 cpu0 [See CPU Number of cores, frequency, strategy, frequency gear]
drwxr-xr-x  5 root root    0 2018-01-10 14:23 cpu1
drwxr-xr-x  5 root root    0 2018-01-10 14:23 cpu2
drwxr-xr-x  5 root root    0 2018-01-10 14:23 cpu3
drwxr-xr-x  3 root root    0 2018-01-09 11:17 cpufreq
drwxr-xr-x  2 root root    0 2018-01-09 11:17 cpuidle
drwxr-xr-x  2 root root    0 2018-01-09 11:17 cputopo
drwxr-xr-x  2 root root    0 2018-01-09 11:17 eas
-r--r--r--  1 root root 4096 2018-01-09 11:17 isolated
-r--r--r--  1 root root 4096 2018-01-09 11:17 kernel_max
-r--r--r--  1 root root 4096 2018-01-09 11:17 modalias
-r--r--r--  1 root root 4096 2018-01-09 11:17 offline
-r--r--r--  1 root root 4096 2018-01-09 11:17 online [See CPU Current open core]
-r--r--r--  1 root root 4096 2018-01-09 11:17 possible
drwxr-xr-x  2 root root    0 2018-01-09 11:17 power
-r--r--r--  1 root root 4096 2018-01-09 11:17 present [See CPU Kernel number]
drwxr-xr-x  2 root root    0 2018-01-09 11:17 rq-stats
drwxr-xr-x  2 root root    0 2018-01-09 11:17 sched
-rw-r--r--  1 root root 4096 2018-01-09 11:17 uevent

2, View CPU cores, frequency, and policy

2.1 view CPU cores

adb shell cat /sys/devices/system/cpu/present

Z91:/sys/devices/system/cpu # cat present
cat present
0-3

2.2 view the current number of open cores of CPU

adb shell cat /sys/devices/system/cpu/online

Z91:/sys/devices/system/cpu # cat online
cat online
0-3

2.3 check the frequency modulation gear of CPU

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequencies
cat scaling_available_frequencies

1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702
000 624000 546000 416000 338000 299000

2.4 view the current frequency of CPU

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_cur_freq
cat cpuinfo_cur_freq
299000

2.5 view CPU support strategy

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

D:\AndroidStudioProject\CpuRun>adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
ondemand userspace powersave interactive performance sched

2.6 view CPU operation strategy

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

D:\AndroidStudioProject\CpuRun>adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
sched

3, Set CPU cores, frequency and policy

3.1 control CPU cores

3.1.1 opening order

adb shell "echo 1 > /sys/devices/system/cpu/cpu[index]/online"

adb shell "echo 1 > /sys/devices/system/cpu/cpu1/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu2/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu3/online"

3.1.2 shutdown order

adb shell "echo 0 > /sys/devices/system/cpu/cpu[index]/online"

adb shell "echo 0 > /sys/devices/system/cpu/cpu1/online"
adb shell "echo 0 > /sys/devices/system/cpu/cpu2/online"
adb shell "echo 0 > /sys/devices/system/cpu/cpu3/online"

3.1.3 query command

adb shell cat /sys/devices/system/cpu/cpu[index]/online

View individual
adb shell cat /sys/devices/system/cpu/cpu1/online
adb shell cat /sys/devices/system/cpu/cpu2/online
adb shell cat /sys/devices/system/cpu/cpu3/online

//View all
adb shell cat /sys/devices/system/cpu/present

3.2 control CPU strategy

You need to review the supported policy types in advance

adb shell "echo [governor strategy] > / sys / devices / system / CPU / CPU [index] / cpufreq / scaling [governor"

adb shell "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
adb shell "echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
adb shell "echo sched > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
adb shell "echo interactive > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"

//Check whether the modification is successful
adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

3.2 control CPU frequency

Limit the threshold value of the highest frequency or scaling_setspeed, but the actual setting may not be set, but it is also normal. Because CPU frequency modulation is related to the scene, for example, the click to open application and the sliding desktop will be fully open without frequency control, so the CPU scene frequency modulation mode is adopted here

adb shell "echo [frequency] > / sys / devices / system / CPU / CPU [index] / cpufreq/scaling_setspeed"

adb shell "echo [frequency] >

1.Querying supported gears
adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702
000 624000 546000 416000 338000 299000

2.View current maximum frequency threshold
adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"


3.Set the maximum current maximum frequency threshold scaling_setspeed
adb shell "echo 845000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
adb shell "echo 845000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
adb shell "echo 1274000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"

4.View current frequency and verify results
adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq

Tags: shell

Posted on Sun, 03 May 2020 17:46:04 -0700 by quark76