Tuesday 3 February 2015

How to change CPU frequency

you can change the CPU frequency on your android device regardless of what your CPU governor is. You will be actually changing the governor to one that only takes userspace input in determining frequency.

The first step is to make sure you have the userspace governor available on your device..
root@:/ # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
interactive ondemand userspace powersave performance

we have the userspace governor on my Nexus 4, you should see it on any other Android device as well since it’s an old and simple governor.

Next we will set our governor to be userspace.
root@:/ # echo userspace >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
root@:/ # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
usersapce

It is set now. If the governor isn’t set then scaling_governor will return something else.

Now it’s just a matter of determining what frequencies are available and setting them.
root@:/ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
384000 486000 594000 702000 810000 918000 1026000 1134000 1242000 1350000 1458000 1512000

For Locking CPU Frequecy at a particular level:
By using below mentioned ADB Command we can lock CPU Frequency

adb shell "echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
adb shell "echo userspace > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq"
adb shell "echo userspace > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq"
adb shell "echo userspace > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
adb shell "echo 1600000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq"

adb shell "echo 1600000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq"

If you are interested in how long your system spent in what state, check out the file
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
To have frequency on Android, just read these special files 
in /sys directory
#cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"

5 comments:

  1. Replies
    1. Interested in this questions as well as rooting a device itself can change performance characteristics and invalidate results

      Delete