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"
Very Useful ADB coomand for Debugging System and Android Application:

To show information about the currently running processes:
> adb shell ps


To display top CPU processes:
> adb shell top –m [num] –s [cpu | vss | rss | thr] –t –d [num]
-m [num]: Maximum number of processes to display
-s [cpu,vss,rss,thr]: column to sort by <cpu,vss,rss,thr>
-t: Show threads instead of processes
-d: Time interval for information update


To show memory usage:
> adb shell cat /proc/meminfo

*cat: To concatenate files and print on the standard
       output


To show a quick summary of process memory utilization. By default it shows Vss, Rss, Pss and Uss, and by sorts by Vss:
> adb shell procrank -p


To show a quick summary of process memory utilization. By default it shows Vss, Rss, Pss and Uss, and by sorts by Vss:
> adb shell procmem –p [PID]


To show memory information in details for the selected process
> adb shell dumpsys meminfo [PID]



logcat: Collect and view system debug output

      > adb shell logcat
      > adb logcat (ex. adb logcat –v time)

bugreport: Print dumpsys, dumpstate, and logcat data to the screen for the purposes of bug reporting. Same as log information by *#9900#

      > adb bugreport

pm: Package Manager. To perform actions and queries on application packages installed on the device.

      - List permission / instrumentation (all test packages) / feature (all features of the system)
      - Install / Remove package
      > adb shell pm <command> (ex. adb shell pm uninstall com.example.MyApp)

am: Activity Manager. To perform various system actions such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more.

      > adb shell am <command> (ex. adb shell am start -a android.intent.action.VIEW)

monkey: A program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.


      > adb shell monkey [options] <event-count>
        (ex. adb shell monkey -p your.package.name –v 500)


To dump traffic on a network
> adb shell tcpdump

USB Charge Mode off
echo 1 > sys/class/power_supply/battery/batt_slate_mode