Remove All Ads from XDA

[MOD][KERNEL] Deep Idle

715 posts
Thanks Meter: 1,726
By Ezekeel, Retired Recognized Developer on 10th October 2011, 10:46 PM
Post Reply Email Thread
I recently had a discussion with someone regarding the benefits of screen-off profiles/daemons that put a limit on the CPU frequency while the screen is switched off for the sake of reducing the power consumption and thus prolonging the battery runtime. My argument was that putting a hard limit on the CPU frequency would rather have a detrimental effect of the battery runtime since this would hinder the CPU from racing-to-idle. I also argued that due to this race-to-idle effect, in general restricting the CPU frequency is not beneficial to the battery runtime and in contrast to intuition overclocking should reduce the average battery drain (as long as no disproportionate increase in voltage is necessary).

Since this is just theory and Morfic noted that his experience seems to indicate otherwise and that limiting the CPU frequency does actually decrease the battery drain, I put this theory to the test and logged the battery charge over 10h of FLAC playback in Airplane mode with the screen switched off.

As one can see, limiting the frequency to a maximum of 880MHz does indeed reduce the power consumption.

Thus it seems that race-to-idle does not properly work on this device. But why? The answer is that, while the technical manual showed that the hardware supports six different power states: NORMAL, IDLE, DEEP-IDLE, STOP, DEEP-STOP and SLEEP, a quick look into the source code revealed that (besides SLEEP) only the most rudimentary power saving state IDLE is actually implemented in the kernel. And for this IDLE state no parts of the hardware are powered down; the only thing that essentially happens is that the CPU clock is set to zero.

For the real power savings to kick in, one would have to power down parts of the hardware (at least the CPU) and that is exactly what the DEEP-IDLE state is supposed to do. Unfortunately this was not implemented. So, following the technical manual I tried to implement this DEEP-IDLE state on my own... and failed miserably. Well, not that miserably... at least I had an idea where the problem was. However I had no idea how to fix it since I did not know enough about the hardware details, had no experience working that close to the CPU and also the manual was far from instructive.

So I googled to maybe find someone smarter than me who had figured out a solution and found out that "some guys" already tried to implement this DEEP-IDLE state for the Galaxy S, however that did not work for some reason. I located the source code in some older version of sixstringsg's Glitch kernel, made some modification, put it into my reference kernel and everything is running fine for more than two days now.

I have repeated the above test runs on a kernel including the deep-idle state.

The battery drain is reduced to 17-18% compared to the 41%/46% (880MHz/1320MHz) obtained without deep-idle support. Thus the battery consumption is reduced by more than 55%. Also we see that with the kernel including deep-idle both 880MHz and 1320MHz yield almost the same average battery drain, showing that race-to-idle actually does work as long as the power saving features are properly supported. So, once these modifications are implemented in your favorite kernel, there should be no need for limiting the frequency anymore and you should be able to blast away without wasting a thought about the battery drain. Also, there is no reason anymore not to overclock your device, except of course the thermal limit of the device auto-incinerating in your hand.

Changes to the source code:


1. While the screen is on, only the normal IDLE state is used.
2. Removed DEEP IDLE state with TOP=ON.
3. For the DEEP IDLE state with TOP=OFF, all external interrupt
wakeup sources except XEINT[30] (key input) are disabled and
all internal wakeup sources are disabled.



1. The reserved values of S5P_WAKEUP_MASK are not touched.
2. Only XEINT[22] = GPH2[6] = GPIO_nPOWER = GPIO_N_POWER and
and XEINT[29] = GPH3[5] = GPIO_OK_KEY are enabled as external
wakeup sources.
3. Only RTC TICK and I2S are enabled as wakeup sources.



For DEEP IDLE the same wakeup interrupt sources are used as for the
sleep state plus at least XEINT[22] = GPH2[6] = GPIO_nPOWER =



Implemented a sysfs interface (/sys/class/misc/deepidle) for enabling/disabling the use of the DEEP IDLE state.



Fixed the BT problem and made sure the DEEP IDLE state is not used when the device is going to/waking from suspend (SLEEP).



1. Mimicking the procedure for the SLEEP state, when entering/returning
from the DEEP IDLE state, a notification is send to kernel modules
using 'pm_notifier_call_chain'. This will cause CPUfreq to statically
set the frequency to SLEEP_FREQ and prevent further frequency changes
until the system returns from DEEP IDLE.
2. The APLL lock is not modified.



Fixed GPS problems.



The DEEP IDLE with TOP=ON is used while GPS or BT are running.


Notifications using 'pm_notifier_call_chain' when entering/leaving DEEP IDLE have been removed.


Test kernel:
For each of the different idle states, the number of idle calls and the total amount of time spend in each state are saved. These stats can be shown using 'idle_stats' in the sysfs interface and resetted with 'reset_stats'.



1. Changed stats variables to 'unsigned long long' to defer overflow and keep the idle times in us for increased accuracy.
2. In case of an overflow of one of the stats variables, all stats are resetted.
3. Put in a mutex to prevent simultanous access to the stats variables.



Notifications using 'pm_notifier_call_chain' when entering/leaving DEEP IDLE have been removed.



Removed RTC TICK as wakeup source and added RTC ALARM.



Added ST as wakeup source.



Added KEY as wakeup source.


No further patches will be published here. I have set up a git repo for all my tweaks. Each mod has its own branch to keep the tweaks cleanly separated and one can simply pull the latest patches from the corresponding branch.

As I said above, this code is almost entirely written by "some other guys". I just made some improvements and extensions to it. Unfortunately I have no idea who these great people are, so I cannot give any credit (yet). However I asked sixstringsg and he told me he would ask around.

CAM bug

There is a bug in the Google Talk app with video-chat which causes the CAM submodule to be activated on boot. As a consequence the DEEP IDLE state will not be used. Opening the camera app once and then closing it, shuts down the CAM module so after that the DEEP IDLE state will be used properly. The Talk version without video-chat does not have this issue. Unfortunately both version are shown as Version 1.3 in the application info, however the app size differs (740KB with video-chat, 500KB without video-chat) as well as the permissions (with video-chat additionally has the permission 'Hardware controls').

without video-chat:

with video-chat:

A big thank you to FloHimself for tracking down the problem!
The Following 131 Users Say Thank You to Ezekeel For This Useful Post: [ View ] Gift Ezekeel Ad-Free
10th October 2011, 10:54 PM |#2  
simms22's Avatar
Recognized Contributor - R.I.P
Thanks Meter: 26,426
10th October 2011, 10:54 PM |#3  
superfloup's Avatar
Senior Member
Flag Ivry-la-Bataille
Thanks Meter: 21
Donate to Me
Woow !! Sounds good !!
10th October 2011, 11:13 PM |#4  
Junior Member
Thanks Meter: 0
Awesome! Can't wait... J
10th October 2011, 11:14 PM |#5  
Senior Member
Thanks Meter: 86
Wow, really looking forward to this

Sent from my Nexus S using Tapatalk
10th October 2011, 11:26 PM |#6  
qubz's Avatar
Inactive Recognized Developer
Flag A parallel dimension
Thanks Meter: 71
Donate to Me
Holy crap. Awesome.
11th October 2011, 12:07 AM |#7  
Serious_Beans's Avatar
Senior Member
Thanks Meter: 342
Originally Posted by qubit76

Holy crap. Awesome.

This with morfics TEUV will give me days of battery life, can't wait! Great stuff!
11th October 2011, 12:26 AM |#8  
arianR10's Avatar
Senior Member
Thanks Meter: 5
11th October 2011, 12:53 AM |#9  
franciscofranco's Avatar
Recognized Developer
Flag Carcavelos
Thanks Meter: 136,088
Donate to Me
**** that looks ****ing awesome. Can't wait to see the code to check what you did.
The Following User Says Thank You to franciscofranco For This Useful Post: [ View ]
11th October 2011, 01:21 AM |#10  
Thanks Meter: 5
Ezekeel - are you a google employee, how the heck do you come out with these brilliant ideas and code implementations week to week? I think we're all for longer battery life. For some myself included have weighed the decision of that 3000mah whale of a battery (opt cover) or tweak the heck out of phones to extract as much as we can from it.

I'm all for the tweaks.

I'm waiting for the next [MOD] [KERNEL] - walk my dog lol
11th October 2011, 02:11 AM |#11  
caleb1783's Avatar
Senior Member
Flag Bangkok
Thanks Meter: 19
Donate to Me

looks promising.

keep up the great work!
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes