[Nexus S Android Development] :
This is the location of the file on my github that I've been meddling with:

https://github.com/bedalus/bedalusKERNEL/blob/performance_DI/kernel/power/earlysuspend.c

Here is the original cyanogenmod version:

https://github.com/CyanogenMod/android_kernel_samsung_crespo/blob/ics/kernel/power/earlysuspend.c

And here is the actual commit where Kalim added his code:

https://github.com/CyanogenMod/andr...mmit/8619dc1984ebfde99d06ec8276e024d47313b128 (the lines he added are highlighted in green: github is good!)

In case you don't want to navigate out, here's the added code:

#ifdef CONFIG_CPU_DIDLE
/* Increases the CPU min speed if we have deepidle enabled and we go into
suspend mode. This is fully independent of the governor, so we can add
or remove our favourite governor */
struct cpufreq_policy *policy;

if (deepidle_is_enabled()) {
policy = cpufreq_cpu_get(0);
if ((new_state == PM_SUSPEND_MEM) && (uIsSuspended == 0)) {
lMinOldFreq = policy->max;
lPolicyMinOldFreq = policy->user_policy.max;
policy->user_policy.max = 800000;
policy->max = 800000;
cpufreq_cpu_put(policy);
uIsSuspended = 1;
} else {
if (lMinOldFreq < 100000) {
lMinOldFreq = policy->max;
lPolicyMinOldFreq = policy->user_policy.max;
uIsSuspended = 0;
}
policy->max = lMinOldFreq;
policy->user_policy.max = lPolicyMinOldFreq;
cpufreq_cpu_put(policy);
uIsSuspended = 0;
}
}
#endif

The variable policy is actually something called a struct (short for structure). It's really a neat way to hold a collection of different variables, like the name of the governor you're using, and what your minimum and maximum frequency settings are, and also contains extra variables so you can temporarily store values if you want to change your min or max.

As you can see in the note kalim wrote above the code, he wants to increase the minimum frequency before suspending. He even wrote this "Add 800Mhz as maxXPU Speed for DEEPIdle Stability," as the commit message. It's pretty clear what his intention was.

However, the code tells a different story. Look at these lines:

lMinOldFreq = policy->max;
lPolicyMinOldFreq = policy->user_policy.max;

Kalim has created these new variables, lMinOldFreq and lPolicyMinOldFreq to store what the current minimum settings are. That makes sense. We need to remember what we had if we're going to go back to it when we come out of suspend. However, where it appears he went wrong is that he makes his new variables = max. No prizes for guessing what that is. It's the current maximum frequency. For a long time, I wondered if he'd done this deliberately, but after spending many many many hours looking at this code, I think it was just a mistake.

What does he do next?

policy->user_policy.max = 800000;
policy->max = 800000;

He's setting the

maximum

frequency to 800000. But he said he wanted to raise the minimum, right? Again, I think this must have been a mistake. This code will reduce your CPU maximum from 1GHz to 0.8GHz (800Mhz). This means while the UI is suspended, the phone will continue to operate as normal, trying to decide what frequency to jump to next based on load. All that's changed is that instead of the available frequencies being 100 200 400 800 and 1000Mhz, you only have 100 to 800.

Okay, so I fixed that with what seemed at the time to be completely obvious:

policy->user_policy.min = 800000;
policy->min = 800000;

...and of course store the old values for retrieval later.

Then I got greedy and wanted 400MHz for maximum power saving. We all know that led nowhere. However, the code was still a bit clumsy. Here's my current up-to-date code:

if (deepidle_is_enabled())
{
policy = cpufreq_cpu_get(0);
if (davebool)
{
old_gov = *policy->user_policy.governor;
old_gov_ptr = &old_gov;
lPolicyMaxOldFreq = policy->user_policy.max;
davebool = 0; // i.e. don't return to this scope until == 1;
}
if ((new_state == PM_SUSPEND_MEM) && (uIsSuspended == 0))
{
policy->user_policy.governor = gov; // gov means performance governor
policy->user_policy.max = 800000; // the most efficient DI state
uIsSuspended = 1;
davebool = 0;
}
else
{
policy->user_policy.governor = old_gov_ptr;
policy->user_policy.max = lPolicyMaxOldFreq;
uIsSuspended = 0;
davebool = 1;
}
cpufreq_cpu_put(policy);
printk("* * *");
printk("* * * DAVE: kernel/power/earlysuspend.c");
}

Now the two lines of particular interest are:

policy->user_policy.governor = gov; // gov means performance governor

policy->user_policy.max = 800000; // the most efficient DI state

...the first line changes user_policy.governor to gov. This 'gov' is just a label I have given to the performance governor for short.

What does the performance governor do? It keeps the frequency at the maximum. I want my maximum at 800 MHz. Check the second line, user_policy.max gets set to 800 MHz.

thalamus, you just made me feel publicly humiliated again, so I'm just defending the hundreds of hours I put into learning how to do this. If you want to help, I'll happily accept remarks like "You've ****ed this commit because... <insert specific reason here>"