[Desire HD General] Roberto_Lim:
Understanding max and min cpu load

In the previous part of this guide we learned who to set the ideal wake and sleep levels.

Lets move on to another pair of important tunables:

max_cpu_load

min_cpu_load

max/min cpu load is set at a % figure.

For if example max_cpu_load is set at "55", than when the average processor usage is over 55% for a given period of time the processor will speed up. min_cpu_load is the figure that governs when the processor will slow down.

Before talking about how to do this, lets do that math since these two figures have to be set in a mathematically correct way.

A lot of popular ROM's these days have very few choices in terms of clock speeds:

These are the clock speeds on the Blackout ICS ROM and other ROM's based on the Virtuous Kernel. You can find the available clock speeds for a ROM by looking at the sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies. In that file you will see clockspeeds in Hertz rather than MHz so 122000 = 122 mHz.

The Blackoyr ROM also sets:

Ramp up and ramp down steps are also important to how this all works, and can be adjusted, but lets leave that to the next part of this guide.

Slowing down

Using the setting in the Blackout ROM, this is how min_cpu_load works

Okay, all this is a bit confusing (or at least I am having a hard time writing it) but let me see if I can explain it by example. Lets says you just completed a heavy task and the phone is running at full speed (1024 MHz be default). The phone will continue to run at this speed, until the average processor use is below min_cpu_load:

So the processor goes down from 1024 MHz by 300 MHz (the ramp down speed) to 768 MHz. If processor use goes to below 256 MHz, the processor will ramp down to 768 MHz.

One at 768 MHz, the governor will compute again:

If the average processor speed is less than 192 MHz, is will continue to slow down. If greater than 192 MHz it will stay at 768 MHz.

Speeding up

With the phone now running 768 MHz, if the load goes higher the max_cpu_load than the processor will speed up. At 768 MHz the max_cpu_load is 422 MHz:

Logical values

When setting this two figures, it is important that:

Lets say we set:

Using the the new figures, we just completed another heavy task and the phone is again running at full speed (1024 MHz be default). The phone will continue to run at this speed, until the average processor use is below min_cpu_load:

Lets say the average processor speed is at 450 MHz, so the processor scales down to 768 MHz.

If processor use remain continues at 450 MHz, the governor will compute again:

Since 400 MHz is higher than 345 MHz. The processor stays at 768MHz and the governor stops ramping down. But the governor is also checking if it should speed up:

Since average speed is over 422 MHz, the processor speeds up back to 1024 MHz. And when there, it will ramps down again.

In sum:

max_cpu_load = 55

min_cpu_load = 45

Are not good values when use with a ROM where the available frequencies are far apart like the ones on the Blackout ROM. The min_cpu_load it too close to max_cpu_load.

Before we set the max_cpu_load and min_cpu_load in our current project, we should also discuss ramp_up and ramp_down steps.