Thursday, February 11, 2010

Saving battery on your Android

I was pretty much concerned about the battery drain on my HTC Dream/G1/Android phone, so I did some research and came up with the below. These settings should help reduce battery drain and even make your phone a bit faster.

Usually you would have been stuck, but with an open source phone, you have an answer ;)

Researched various settings to save battery life on a linux kernel and finally compiled the below settings.

There changes are to be done to /system/bin/user.conf

This file by default is read-only to modify do the following

$ su
# mount -o remount,rw /dev/block/mtdblock3 /system
# vi /system/bin/user.conf

once you have vi you can edit the file and save it.

The changed parts are given below.

VM

laptop_mode = 5
dirty_writeback_centisecs = 1500
———-
compcache — disabled
———–
linux_swap_en = 1
——–
CPU

scaling_min_freq=192000
scaling_max_freq=524000
sampling_rate=4000000
powersave_bias=100
up_threshold=25


The VM Changes
1. laptop_mode: When laptop mode is enabled, the kernel will try to be smart about when to do IO, to give the disk and the SATA links as much time as possible in a low power state. Laptop mode works by submitting all future pending disk IO (such as pending VM cache writebacks, as described in the VM writeback time tip, above) at once, when the kernel has to do an IO to the disk for any reason. By submitting future planned IO right away, when the disk is powered up anyway, the assumption is that this IO will no longer need to happen, so the disk can remain in a low power mode longer.

2. dirty_writeback_centisecs: The VM subsystem, in the Linux kernel, buffers writes to files that applications perform for a period of time. This caching allows the kernel to group consecutive writes into one big write, and to generally optimize the disk IO to be the most efficient. The kernel, by default, will start writing out data to disk after 5 seconds, so, if a power failure or kernel crash happens, at most, 5 seconds of data would be lost. Since we run on battery, we can, hopefully, set this to a longer time of 15 seconds.

3. compcache is enabled by default on this ROM of size 32MB. If you have a third partition disable this and enable that partition which would be of the file system type linux-swap by default, thereby avoiding the need to process two layers of filesystem logic of 1 from linux-swap to ext2/fat32 and then 2nd from fat32/ext2 to disk.

4. sampling_rate: this is how often you want the kernel to look at the CPU usage and to make decisions on what to do about the frequency. This is by default set to 200000, which I think is a bit too sensitive for a phone, hence I have doubled this amount to 4000000 as an experiment. Not sure till how much we can increase this, but it would be worth the test i guess. You will understand more why when we talk about up_threshold.

5. powersave_bias: set to 0, which pretty much doesnt really use this feature. in a range from 1 to 1000, if you set the powersave bias to say 100(or 10%) the cpu runs at 100-10% of the required scaled frequency and if this is enough then it is set at that. Hence as an experiment set it to 100 (or 10%).

6. up_threshold: This plays together with the sampling_rate. This is an additional check for the kernel to scale the cpu frequency if the load of the cpu goes beyond a certain percentage as specified by the up_threshold in between the sampling rates.

Hope this was helpful.

No comments:

Post a Comment