yashsingh1/xdaforums huggingface dataset:
[Nexus 4 Original Android Development] franciscofranco:
It kinda works exactly like he explained. When it detects its over 25 it onlines one cpu. For at least 4 seconds the second core stays up. After those 4s if the load is below 50% it offlines it.
[Nexus 4 Original Android Development] smarki:
So ehat if the load is below 25? The phone works with no cpus online, and yet processing on going stuff? Sound weird to me
[Nexus 4 Original Android Development] ck2009:
There is always at least one core online at all times, if the load is above 25% one extra core is onlined for four seconds, if after the four seconds have elapsed the load is less than 50% the extra core is offlined - returning to a single online core again.
[Nexus 4 Original Android Development] abaaaabbbb63:
That is the most groundbreaking sentence I have seen in my life.
[Nexus 4 Original Android Development] ck2009:
You must have a very exciting life :eek:
[Nexus 4 Original Android Development] mrgwap:
Dang. Yeah typo I meant to type cpu..
[Nexus 4 Original Android Development] zando2712:
After the second core kicks in, when does the third go online?

I understand with 90, 25, 50 all cores go online at 90 load.
[Nexus 4 Original Android Development] Net.silb:
I think I understand, but just to be sure, tell me what happens in this scenario:

One core is online, load is 0.

Hotplug driver decides: no change.

Reason: load is not bigger than 90, not bigger than 25 and is lower than 50.

Next

One core is online, load is 60.

Hotplug driver decides: online one more core.

Reason: load is not bigger than 90 and is bigger than 25.

Next

Two cores are online, load is 30. (4 seconds have past)

Hotplug driver decides: ?

Reason: ?

So, what happens now and why?
[Nexus 4 Original Android Development] Alex240188:
It does not check each entry.

Think of it like this

1core

Load at 60%

Is load > 90 = false

Is load > 25 = true

Bring online 2nd core

Wait 4 second

Now load is only at 40%

Is load > 90 = false

Is load > 25 = true

Bring online 3rd core

Wait 4 seconds

Now load is only at 20%

Is load > 90 = false

Is load > 25 = false

Is load < 50 = true

Offline all cores*

Wait 4 seconds

*All cores means back to single core

Note not all calculations are necessarily done every cycle. Only until one is true

So it is looking for high load. Then medium then low.

If any are true it acts accordingly and ignores the lower ones.

Hope this explains it a bit better
[Nexus 4 Original Android Development] thucoisao:
Sorry, i was tried my best to make it empty but too tired and sleepy. Well done man. :thumbup:

Sent from my Nexus 4.
[Nexus 4 Original Android Development] combatdeity:
Excuse my ignorance, but why does it offline all cores instead of shutting them down one by one?

Couldn't that leave the load such that its going to have to online a core again straight away?
[Nexus 4 Original Android Development] Dan53:
If this is the logic, which I'm not sure it is, then its flawed. Say you are doing one task one core at 66%. It onlines another core then they are both at 33%, it onlines another core. Now the three are at 22%, so all cores offline. But now one core is at 66% again so it needs to online them all again? Doesn't make sense to me

Sent from my Nexus 4
[Nexus 4 Original Android Development] Net.silb:
Same thought here, if it turns off all cores when the load is 20%, the load will increase immediately and more cores will be onlined again, sorry but this doesn't make a lot of sense...

It would make more sense if it was like this

high load - 90

medium load - 50

low load 25

because then as long as the load is over 50 it will online more cores, then if the load is between 25-50 it would stay with the same amount of cores and only if the load dropped below 25 it would only keep one core.
[Nexus 4 Original Android Development] aimcr7:
Low load is 50 because if it below 50 and 2 cores is online for 4 seconds and still on that state it will be back to one core.

Med load is 25 to maintain smoothness, if load is above 25 cpu1 will be activated (which is dual core mode), if load doesn't go above 50 cpu1 will be offline.
[Nexus 4 Original Android Development] Net.silb:
Why does the amount of cores online need to change constantly?

If it works the way you describe it, every four seconds the hotplug driver will either turn on all cores, turn on one more core or turn off all cores. Why can't there be just two cores or three cores online without that changing every four seconds?
[Nexus 4 Original Android Development] nexusmaniac:
What's the brightness set to?

N7/N4 - CM10.1 Nightly, Franco Kernel
[Nexus 4 Original Android Development] Redneck Trash:
Hotplugging doesn't occur every four seconds. If I understand right a check of CPU load occurs at four second intervals.
[Nexus 4 Original Android Development] santeana:
Holy **** [MENTION=3292224]franciscofranco[/MENTION] I dunno what you did when you say performance improvements but my Antutu score just shot up from 16,900 to 21,300. Only change being flashing from 133 to 134 lol. If that's you, then nice work! =D
[Nexus 4 Original Android Development] yokuyuki:
Agreed because it seems like you could end up with a condition in which you're just constantly offlining and onlining cores as it bounces between medium load and low load and constantly hotplugging isn't exactly great for battery.

---------- Post added at 10:15 AM ---------- Previous post was at 10:09 AM ----------

And the check of the CPU load triggers hotplugging... hotplugging doesn't exactly take that long so it essentially is every 4 seconds if you're bouncing between loads.
[Nexus 4 Original Android Development] aimcr7:
practically when you play with UI, swipe at app drawer it uses 2 cores, when you load web pages it will use 2 cores or even more it depends on how complex that page, then you read it, so 2 cores it's not needed here, so it will wait for four seconds before set cpu1 to offline.

This setup is to maintain smoothness as well as battery life.

And, franco never force you to use his default settings, you can change it in hotplug settings to fit your usage. :)

Me myself prefer default hotplug parameters, never suffers any lag and I got a good battery life either. Usually more than 4 hours of screen on, in 3g all the time. :cool:
[Nexus 4 Original Android Development] cool.darshak:
turning cores on-off eats battery too..correct me if m wrong...how about introducing the time and frequency factor also...

...just psuedo code...m sure there might be problems in below code...may be franco can work on it...

freqhigh = 1350 Mhz

freqmed = 1242 Mhz

freqlow = 1024 Mhz

highload = 90

lowload = 60

mediumload = 25

timehigh = 10 secs

timemed = 5 secs

loop

if load <= mediumload and flag = 0 then

only one core online

scale core = freqlow

else if load < lowload and flag = 0 then

one more core online

flag = 1

scale online cores = freqmed

else if load < lowload and flag = 1 then

one more core online

flag = 0

scale online cores = freqhigh

else if load > highload then

all core online

scale all cores = freqhigh

else

flag = 0

end if

loop

if x > timehigh secs

flag = 1

online core = freqlow

else if x < timemed secs

flag = 0

online core = freqhigh

else

flag = 0

online core = freqmed

end if

end loop

end loop
[Nexus 4 Original Android Development] spicediablo:
This is the latest that touch control supports .:beer:

Sent from Mako⁴
[Nexus 4 Original Android Development] drawde40599:
One of my N4 's i didn't feel a difference at 1.7 the other i did (dont no y) so drop it to 1620 or the other1600 slot along with setting in gov control. See if u notice it then . Use it for a day then go back to stock settings ull notice the difference :D
[Nexus 4 Original Android Development] Net.silb:
Here is the hotplug driver code that I believe we are discussing:

[COLOR="DimGray"]static void hotplug_decision_work_fn(struct work_struct *work)
{
static unsigned int total = 0;
unsigned int disable_load, enable_load, available_cpus;
unsigned int online_cpus;
int avg_running, i;

[COLOR="Black"][B]online_cpus = num_online_cpus();
available_cpus = num_possible_cpus();
disable_load = disable_load_threshold * online_cpus;
enable_load = enable_load_threshold * online_cpus;[/B][/COLOR]

if (foo++ == SAMPLES)
foo = 0;

[COLOR="Green"]/*
* This is a custom function from Codeaurora to calculate the average of the runnable threads
* and it doesn't seem to be very expensive so its worth a try. sched_get_nr_running_avg running
* on this kernel is modified from original code, the iowait calculations were removed because
* for the purpose of this driver we don't use that value and may cause extra overhead.
*
* This function call has a 0ms to 1ms cost, roughly 200k nanoseconds - measured with ktime_get()
*/[/COLOR]

sched_get_nr_running_avg(&avg_running);
timer_history[foo] = avg_running;

for (i = 0; i < ARRAY_SIZE(timer_history); i++)
total += timer_history[i];

total = total/SAMPLES;
[COLOR="Green"]//pr_info("hotplug_ decision: total: %d\n", total);[/COLOR]

[COLOR="Black"][B]if (!_lock_hotplug) {
if ((total > enable_all_load_threshold) && (online_cpus < available_cpus)) {

schedule_work(&hotplug_online_all_work);

return;
} else if ((total >= enable_load) && (online_cpus < available_cpus)) {

schedule_work(&hotplug_online_single_work);

return;
} else if ((total < disable_load) && (online_cpus > 2)) {
[COLOR="Green"]//if (boostpulse_active) {
//	boostpulse_active = false;
//} else if (online_cpus > 2) {

/*
* This count serves to filter any spurious lower load as we don't want the driver
* to offline a core during a intense task if for some reason it reports a low
* load in one sample time. This can be called a sampling rate.
*/ [/COLOR]
schedule_work(&hotplug_offline_all_work);
[COLOR="Green"]//}[/COLOR]
}[/B][/COLOR]
}

schedule_delayed_work(&hotplug_decision_work, msecs_to_jiffies(sampling_timer));
}[/COLOR]

Basically, I believe that the parameters are the following:

enable_all_load_threshold - High load threshold

enable_load_threshold - Medium load threshold

disable_load_threshold - Low load threshold
[Nexus 4 Original Android Development] Alex240188:
look at the code yourselves

https://github.com/franciscofranco/mako/blob/nightlies/arch/arm/kernel/auto_hotplug.c

line 88-148

if ((total > enable_all_load_threshold) && (online_cpus < available_cpus)) {

schedule_work(&hotplug_online_all_work);

return;
} else if ((total >= enable_load) && (online_cpus < available_cpus)) {

schedule_work(&hotplug_online_single_work);

return;
} else if ((total < disable_load) && (online_cpus > 2)) {
//if (boostpulse_active) {
// boostpulse_active = false;
//} else if (online_cpus > 2) {

/*
* This count serves to filter any spurious lower load as we don't want the driver
* to offline a core during a intense task if for some reason it reports a low
* load in one sample time. This can be called a sampling rate.
*/
schedule_work(&hotplug_offline_all_work);
//}
}

Broken Down

if (("CPU_Load" > "High Load Threshold") && ("Number of online Cores" < 4)) {

schedule_work("Online All Cores");

} else if (("CPU_Load" >= "Medium Load Threshold") && ("Number of online Cores" < 4)) {

schedule_work("Online One More Core");

} else if (("CPU_Load" < "Low Load Threshold") && ("Number of online Cores" > 2)) {

schedule_work("Offline All Cores");

Broken Down even further

if ("CPU Load" is more than 75) & (less than 4 cores online)

bring all cores online

else if ("CPU Load" is 25 or higher) & (less than 4 cores online)

bring another core online

else if ("CPU Load" is less than 50) & (more than 2 cores online)

drop back to single core

now after looking at this i dont understand how it goes from 2x cores to 1 core,

that is obviously handled elsewhere but this is the basic formula that franco has used.

sorry to say basic franco ** I know its not basic, its a simple yet genious solution

the explanation that I gave previously was my best guess and after looking at franco's source, it appears I was right on the money
[Nexus 4 Original Android Development] igalmarino:
Why the cores go online one by one but go offline all at the same time ? Sorry my ignorance im just trying to understand !

Sent from my Nexus 4
[Nexus 4 Original Android Development] Net.silb:
I was thinking the same thing regarding 2 cores.

How does the CPU go down from 2 to one cores?

shouldn't it be

else if (("CPU_Load" < "Low Load Threshold") && ("Number of online Cores" >= 2)) {
schedule_work("Offline All Cores");

?
[Nexus 4 Original Android Development] Alex240188:
No because the phone does go from 2 cores to one core by itself. So that is obviously handled elsewhere in the source
[Nexus 4 Original Android Development] Dan53:
https://github.com/franciscofranco/mako/blob/nightlies/arch/arm/kernel/mako_hotplug.c

Take a look at that instead
[Nexus 4 Original Android Development] Alex240188:
whoops, looks like i was looking at an old file, let me have a look over this one
[Nexus 4 Original Android Development] jabbeboy:
What do you mean? :cowboy:
[Nexus 4 Original Android Development] lorolouis:
Wow

Wow ... 5 hours :good:

How is possible people to feedback so early after an update is published, is that one full battery cycle?

I'd like rather my battery to stay longer than 2 days as a total time, than to see 5h SOT ..

What you've been doing with your phone man ... during the test time, or you just leave the screen ON at lowest contrast and toggle something to keep it on for next 5 hours ... or you are too good with the PhotoShop :cool: ?
[Nexus 4 Original Android Development] scottx .:
I get great battery life too.

Just now as I type this it dropped to 99. Love this kernel.

Also its nice to see CPU over-clocking implemented.
[Nexus 4 Original Android Development] fakudolan:
I just used my phone to check facebook, flipboard, no games, some music here and there, light usage
[Nexus 4 Original Android Development] Alex240188:
mako_hotplug.c is still following the same procedure. it just does it much more effectively (& with governer changes)

I'll still stand by this description

High

If Load > 80

Online All cores

wait 4 seconds

Mid

else if load > 25

Online +1 core

wait 4 seconds

Low

else if load < 50

offline all extra cores

wait 4 seconds

if High = true then Mid & Low will not be checked

If High = false, Mid = true, then low will not be checked

the only way cores will be offlined is if High/Mid are not met or you are already running on 4 cores when they are met

there are many other controls and factors in the source however that is the basic principle of it
[Nexus 4 Original Android Development] Net.silb:
Ok guys,

I analyzed the hotplug driver being used, it can be found here: https://github.com/franciscofranco/mako/blob/nightlies/arch/arm/kernel/mako_hotplug.c

Here is the simplified algorithm it uses for core management:

1 - If, load >= High load threshold (80 is default), then:

1.1 - If, online cores = 4, then:

1.1.1 - Do nothing.

1.2 - Otherwise, if, online cores = 2 || 2 or more seconds have past since the last hotplugging, then:

1.2.1 - Online all remaining cores.

1.2.2 - Scale interactive tunables accordingly.

2 - Otherwise, If, load >= Medium load threshold (25 is default), then:

2.1 - If, online cores = 4, then:

2.1.1 - Do nothing.

2.2 - Otherwise, if, online cores < 2 || 4 or more seconds have past since the last hotplugging, then:

2.2.1 - Online 1 more core.

2.2.2 - Scale interactive tunables accordingly.

3 - Otherwise, If, load <= Low load threshold (50 is default), then:

3.1 - If, online cores = 1, then:

1.1.1 - Do nothing.

1.2 - Otherwise, if, 2 or more seconds have past since the last hotplugging, then:

1.2.1 - Offline all cores except for 1.

1.2.2 - Scale interactive tunables accordingly.
[Nexus 4 Original Android Development] rdxhd:
My default was also row. I have changed to deadline. However, I have been noticing less battery life with this setting. It may be placebo but I wanted to understand what is the difference between the two i/o. Thanks!
[Nexus 4 Original Android Development] andyli1985:
Sorry for the OT, but what theme are you using? I really like it. :good:
[Nexus 4 Original Android Development] Alex240188:
That was the conclusion I came to. Is it possible to have 3 cores with this setup because the conditions are.

For high load you have to have 2 cores online.

For medium load you have to have 1 core.

The only pattern of cores I can see with this are

1 > medium > 2 > High > 4 > low > 1

Or

1 > medium > 2 > low > 1
[Nexus 4 Original Android Development] Net.silb:
Basically, I'm still not happy with the default parameters because they cause the following possible scenario:

Online cores = 1

Load = 10

0 seconds later:

Hotplug - Do nothing.

Online cores = 1

Load = 50

0 seconds later:

Hotplug - Online 1 more core.

Online cores = 2

Load = 30

4 seconds later:

Hotplug - Online 1 more core.

Online cores = 3

Load = 20

2 seconds later:

Hotplug - Offline all cores except for 1.

Online cores = 1

Load = 50

0 seconds later:

Hotplug - Online 1 more core.

Online cores = 2

Load = 30

4 seconds later:

Hotplug - Online 1 more core.

Online cores = 3

Load = 20

2 seconds later:

Hotplug - Offline all cores except for 1.

Online cores = 1

And so on and so on, leading to the cores constantly turning on and off until the task the user is doing is complete...
[Nexus 4 Original Android Development] Alex240188:
but how likely are you to have a load that doesnt change over that many seconds that isnt a high load

please forgive me if i am being stupid

would you never get to 3 cores because of this in second level work check

if (stats.online_cpus < 2 || (now - stats.time_stamp) >= temp_diff)

meaning that you can only +1 core if you are currently only running on 1 core

shouldnt this be "if (stats.online_cpus < available_cpus || (now - stats.time_stamp) >= temp_diff)"

or if (stats.online_cpus < 4 || (now - stats.time_stamp) >= temp_diff)
[Nexus 4 Original Android Development] Net.silb:
I suggest the following parameters:

High load threshold - 80

Medium load threshold - 40 (Or anything higher than the Low load threshold)

Low load threshold - 25 (Or anything lower than the Medium load threshold)

That way the scenario would play out like this:

Online cores = 1

Load = 10

0 seconds later:

Hotplug - Do nothing.

Online cores = 1

Load = 50

0 seconds later:

Hotplug - Online 1 more core.

Online cores = 2

Load = 45

4 seconds later:

Hotplug - Online 1 more core.

Online cores = 3

Load = 30

For the next X seconds, as the load stays 30:

Hotplug - Do nothing.

Online cores = 3

Load = 20

0 seconds later:

Hotplug - Offline all cores except for 1.

Online cores = 1

That seems like a much better combination of parameters than the default ones...

[MENTION=3292224]franciscofranco[/MENTION] We need your say in the matter! (please...)

.
[Nexus 4 Original Android Development] Bobtehblob:
I thought Franco explained this all fairly well when he first implemented his hotplug?
[Nexus 4 Original Android Development] pkelly517:
He did.

Quick startup when load bumps up.

Keep adding cores until task done.

Shut them off when task is done.
[Nexus 4 Original Android Development] Alex240188:
but this is what i'm trying to say

it wont keep adding cores

because of

if (stats.online_cpus < 2 || (now - stats.time_stamp) >= temp_diff)

in second level work check

it will only +1 core up to 2 cores then that is it

I will upload some screenies to show you what i mean

1st image

ddms using 16% CPU - only 1 core online

2nd image

interact with phone, cpu usage jumps to 51%

meets 2nd level and +1 core, 2 cores online

3rd image

continued interaction, cpu usage still 50%

does not meet 2nd level because online cpu is not < 2

3rd core does not come online
[Nexus 4 Original Android Development] lorolouis:
Amazing!

Even I have "faster" binned CPU (the best) I would not lower -125 under-voltage, probably just a little -75 all to be on the safer side.

I've been using r127 for a while, no issues all good. Skipping some r-s in between, including the M2 and jumping to r134.

Are there any other fine custom tweaks, different than default ones you can suggest?

Thank you.
[Nexus 4 Original Android Development] Net.silb:
1 - If, load >= High load threshold (80 is default), then:

1.1 - If, online cores = 4, then:

1.1.1 - Do nothing.

1.2 - Otherwise, if, online cores = 2 || 2 or more seconds have past since the last hotplugging, then:

1.2.1 - Online all remaining cores.

1.2.2 - Scale interactive tunables accordingly.

2 - Otherwise, If, load >= Medium load threshold (25 is default), then:

2.1 - If, online cores = 4, then:

2.1.1 - Do nothing.

2.2 - Otherwise, if, online cores < 2 || 4 or more seconds have past since the last hotplugging, then:

2.2.1 - Online 1 more core.

2.2.2 - Scale interactive tunables accordingly.

3 - Otherwise, If, load <= Low load threshold (50 is default), then:

3.1 - If, online cores = 1, then:

1.1.1 - Do nothing.

1.2 - Otherwise, if, 2 or more seconds have past since the last hotplugging, then:

1.2.1 - Offline all cores except for 1.

1.2.2 - Scale interactive tunables accordingly.

You're wrong. Check line 2.2, '||' means OR and '&&' means AND. Only one of the two conditions need to exist in a case of '||'.
[Nexus 4 Original Android Development] :
We had similar settings to the ones you're suggesting (r125 or earlier release around that time) and the performance was ok the current settings give the best performance, I'm guessing cause the cores online faster to respond to load increase
[Nexus 4 Original Android Development] Alex240188:
oh my gosh, i feel very stupid now

it's been about 7 years sinse i last did anything with C or any other programming language to be fair.

i looked at || and it didnt even register in my head

ignore me as i'm been a complete dumba$$
[Nexus 4 Original Android Development] fakudolan:
Well, i have turned off both log settings in kernel tweaks section, fsync off and stock deadline settings too. Hot plug high load changed to 80, rest unchanged.

I guess all i can say is, battery life varies on your personal usage.
[Nexus 4 Original Android Development] Net.silb:
I'm gonna use the following hotplug settings and report my conclusions:

High load - 90

Medium load - 50

Low load - 30
[Nexus 4 Original Android Development] Dan53:
You know that means if load four cores are active for something, and load goes down to 30%, they will all stay active? Better efficiency would come from two/three cores. Which is what franco's option will achieve. It has it's pros and cons
[Nexus 4 Original Android Development] Net.silb:
Hmm, I guess you're right...

Why have two ways with pros and cons if you can make a new way with no pros and cons?

Basically, I'm saying that I'm in the process of developing a new, better hotplugging algorithm and I hope Franco will consider using it when I suggest it to him.
[Nexus 4 Original Android Development] Dan53:
Yeah. we've (hopefully) located a problem, see what we can do to fix it.

EDIT: One thing I see is that the thresholds are NOT equal to the default levels. We've missed lines 163-169

stats.online_cpus = num_online_cpus();

/* the load thresholds scale with the number of online cpus */
first_level = stats.default_first_level * stats.online_cpus;
second_level = stats.default_second_level * stats.online_cpus;
third_level = stats.default_third_level * stats.online_cpus;

Means the second level will go up. Problem solved?

Only when the load on quad core is less than 100% will the cores offline

Only when the load on three cores is less than 75% will the cores offline

Only when the load on two cores is less than 50% will the cores offline
[Nexus 4 Original Android Development] Net.silb:
Don't think so...

I believe that each core has a load from 0-100 but the value of the load in the kernel is the total load 0-400.

The thresholds we input in the app are per core, so that piece of code just coverts our thresholds to ones that can be compared to the load value coming from the kernel...
[Nexus 4 Original Android Development] franciscofranco:
Thats not the code, its mako_hotplug.c
[Nexus 4 Original Android Development] Net.silb:
Ya, I know now, check a few posts later...