sched/cpufreq: Fix capacity calc in shared policy update
Subsystems (2)
PATCH 1/1 sched/cpufreq: Fix capacity calc in shared policy update
In sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
--- kernel/sched/cpufreq_schedutil.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/sched/cpufreq_schedutil.c +4 -4
@@ -492,15 +492,15 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) {struct sugov_policy *sg_policy = sg_cpu->sg_policy;struct cpufreq_policy *policy = sg_policy->policy; -unsigned long util =0 , max_cap; +unsigned long util =0 , max_cap =0 ;unsigned int j; - max_cap =arch_scale_cpu_capacity (sg_cpu->cpu); -for_each_cpu (j, policy->cpus) {struct sugov_cpu *j_sg_cpu = &per_cpu (sugov_cpu, j); -unsigned long boost; +unsigned long boost, j_max_cap; + j_max_cap =arch_scale_cpu_capacity (j); + max_cap =max (max_cap, j_max_cap); boost =sugov_iowait_apply (j_sg_cpu, time, max_cap);sugov_get_util (j_sg_cpu, boost);
Signature · 1 line
2.34.1
Quoted 6 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
Then this needs a fixes tag?
Maybe even the intel_pstate setup changes? I think the policy <=> capacity assumption made here was true before that?
Quoted 3 lines
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
s/all CPUs/all policy CPUs/ maybe?
Quoted 16 lines
Signed-off-by Kaushlendra Kumar <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/sched/cpufreq_schedutil.c +1
-1@@ -492,15 +492,15 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) {struct sugov_policy *sg_policy = sg_cpu->sg_policy;struct cpufreq_policy *policy = sg_policy->policy; -unsigned long util =0 , max_cap; +unsigned long util =0 , max_cap =0 ;
kernel/sched/cpufreq_schedutil.c static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) · line 502
Quoted 10 lines
kernel/sched/cpufreq_schedutil.c +2
-3unsigned int j; - max_cap =arch_scale_cpu_capacity (sg_cpu->cpu); -for_each_cpu (j, policy->cpus) {struct sugov_cpu *j_sg_cpu = &per_cpu (sugov_cpu, j); -unsigned long boost; +unsigned long boost, j_max_cap; + j_max_cap =arch_scale_cpu_capacity (j);
nit: j_max_cap is only used once...
kernel/sched/cpufreq_schedutil.c static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) · line 504
Quoted 2 lines
kernel/sched/cpufreq_schedutil.c +1
-0+ max_cap =max (max_cap, j_max_cap); boost =sugov_iowait_apply (j_sg_cpu, time, max_cap);
I find this a bit strange, you might as well argue that this sets the wrong frequency with your patch (boost being determined by the highest frequency seen in this loop so far?)
My understanding was that this "different capacity, same cluster" was just a technicality and because the capacities are still really close (1-2%?) we essentially don't care about the difference. Why do we care here/now?
Quoted 2 lines
kernel/sched/cpufreq_schedutil.c +0
-0sugov_get_util (j_sg_cpu, boost);
Hi Dietmar,
Quoted 10 lines · Dietmar Eggemann
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.Then this needs a fixes tag?
Maybe even theintel_pstatesetup changes? I think the policy <=> capacity assumption made here was true before that?
You're right, I'll add a Fixes tag.
Quoted 6 lines
Quoted 4 lines
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
s/all CPUs/all policy CPUs/ maybe?
Agreed.
Quoted 27 lines
Quoted 27 lines
Signed-off-by Kaushlendra Kumar <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/sched/cpufreq_schedutil.c +2
-4@@ -492,15 +492,15 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) {struct sugov_policy *sg_policy = sg_cpu->sg_policy;struct cpufreq_policy *policy = sg_policy->policy; -unsigned long util =0 , max_cap; +unsigned long util =0 , max_cap =0 ;unsigned int j; - max_cap =arch_scale_cpu_capacity (sg_cpu->cpu); -for_each_cpu (j, policy->cpus) {struct sugov_cpu *j_sg_cpu = &per_cpu (sugov_cpu, j); -unsigned long boost; +unsigned long boost, j_max_cap;
Quoted 3 lines
kernel/sched/cpufreq_schedutil.c static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) · line 502
Quoted 1 line
kernel/sched/cpufreq_schedutil.c +1
-0+ j_max_cap =arch_scale_cpu_capacity (j);nit:
j_max_capis only used once...
Will inline it: max_cap = max(max_cap, arch_scale_cpu_capacity(j));
Quoted 10 lines
kernel/sched/cpufreq_schedutil.c static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) · line 504
Quoted 3 lines
kernel/sched/cpufreq_schedutil.c +1
-0+ max_cap =max (max_cap, j_max_cap); boost =sugov_iowait_apply (j_sg_cpu, time, max_cap);I find this a bit strange, you might as well argue that this sets the wrong frequency with your patch (boost being determined by the highest frequency seen in this loop so far?) My understanding was that this "different capacity, same cluster" was just a technicality and because the capacities are still really close (1-2%?) we essentially don't care about the difference. Why do we care here/now?
Good point about the boost calculation using intermediate max_cap values.
If the capacity differences are indeed only 1-2%, perhaps this needs further investigation. Let me investigate the actual capacity deltas.
Thanks for the review.
Regards,
Kaushlendra
Hi Kaushlendra,
Quoted 6 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?
I would like to hear Rafael's view on such platform configuration.
It looks like a hack and the next needed step would be a similar hack to calm down EAS and EM in the energy estimation code...
Do we really want to support such configuration in the generic code?
Quoted 3 lines
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
I've changed that loop to speed-up the hot code path triggered from the scheduler. For most platforms (till now) it's fine to get the cpu capacity once for all cpus in the policy. A lot of code is based on this assumption.
Quoted 20 lines
Signed-off-by Kaushlendra Kumar <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/sched/cpufreq_schedutil.c +1
-3@@ -492,15 +492,15 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) {struct sugov_policy *sg_policy = sg_cpu->sg_policy;struct cpufreq_policy *policy = sg_policy->policy; -unsigned long util =0 , max_cap; +unsigned long util =0 , max_cap =0 ;unsigned int j; - max_cap =arch_scale_cpu_capacity (sg_cpu->cpu); -
kernel/sched/cpufreq_schedutil.c static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) · line 506
Quoted 10 lines
kernel/sched/cpufreq_schedutil.c +3
-1for_each_cpu (j, policy->cpus) {struct sugov_cpu *j_sg_cpu = &per_cpu (sugov_cpu, j); -unsigned long boost; +unsigned long boost, j_max_cap; + j_max_cap =arch_scale_cpu_capacity (j); + max_cap =max (max_cap, j_max_cap); boost =sugov_iowait_apply (j_sg_cpu, time, max_cap);sugov_get_util (j_sg_cpu, boost);
My gut feeling tells me that it won't be the last needed code change if we go that path...
Regards,
Lukasz
Hi Lukasz,
Quoted 11 lines · Lukasz Luba
Hi Kaushlendra,
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?
This is with respect to intel platforms which has E-cores and P-cores.
Quoted 7 lines
I would like to hear Rafael's view on such platform configuration.
It looks like a hack and the next needed step would be a similar hack to calm down EAS and EM in the energy estimation code...
Do we really want to support such configuration in the generic code?
I understand the concern about maintaining the optimization in the hot path. Lets hear Rafael.
Quoted 8 lines
Quoted 3 lines
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
I've changed that loop to speed-up the hot code path triggered from the scheduler. For most platforms (till now) it's fine to get the cpu capacity once for all cpus in the policy.
A lot of code is based on this assumption.
Agreed, the hot path performance is critical.
Quoted 3 lines
My gut feeling tells me that it won't be the last needed code change if we go that path...
You're right to be cautious. Let's investigate the EAS/EM implications and have more complete assessment of this change.
Thanks for the feedback.
Regards,
Kaushlendra
Vincent Guittot
maintainerQuoted 13 lines · Kaushlendra
Hi Lukasz,
Quoted 9 lines · Lukasz Luba
Hi Kaushlendra,
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
Quoted 4 lines
Quoted 2 lines
How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?This is with respect to intel platforms which has E-cores and P-cores.
Do you mean that they share the same frequency domains ?
Quoted 34 lines
Quoted 8 lines
I would like to hear Rafael's view on such platform configuration.
It looks like a hack and the next needed step would be a similar hack to calm down EAS and EM in the energy estimation code...
Do we really want to support such configuration in the generic code?
I understand the concern about maintaining the optimization in the hot path. Lets hear Rafael.
Quoted 8 lines
Quoted 3 lines
Calculate per-CPU capacity in the loop and track maximum across all CPUs for proper frequency calculation.
I've changed that loop to speed-up the hot code path triggered from the scheduler. For most platforms (till now) it's fine to get the cpu capacity once for all cpus in the policy.
A lot of code is based on this assumption.Agreed, the hot path performance is critical.
Quoted 3 lines
My gut feeling tells me that it won't be the last needed code change if we go that path...
You're right to be cautious. Let's investigate the EAS/EM implications and have more complete assessment of this change.
Thanks for the feedback.
Regards,
Kaushlendra
Quoted 15 lines · Vincent Guittot
Quoted 13 lines · Kaushlendra
Hi Lukasz,
Quoted 9 lines · Lukasz Luba
Hi Kaushlendra,
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?This is with respect to intel platforms which has E-cores and P-cores.
Do you mean that they share the same frequency domains ?
Just to get everybody on the same page:
Intel has what's called "favored cores", P-cores that allow for slightly higher frequencies than the other (same uArch) P-cores.
Rafael's EAS series decided that it wouldn't be worth the effort make EAS always iterate over an extra cluster (overhead on every wakeup hot-path) for CPUs where in the bigger picture the difference is negligible.
https://lore.kernel.org/lkml/[email protected]/
(capacities are 623, 1009 and 1024 here, 1009 and 1024 are lumped into one cluster.)
I think this isn't unreasonable, as long as this technicality lives inside of intel_pstate setup code and doesn't escape, like proposed here. Obviously EAS heavily relies on "1 cluster => 1 capacity" assumption as mentioned before, even just for max-spare-cap in feec().
Breaking this assumption would require a huge rework, which AFAIU specifically wasn't was Rafael intended, but I'm sure he'll chime in himself. So if you really have issues with the different capacities within a cluster trick that Rafael went with, please just reconsider that instead of trying to patch things up outside of intel_pstate.
Vincent Guittot
maintainerQuoted 20 lines · Christian Loehle
Quoted 18 lines · Vincent Guittot
Quoted 16 lines · Kaushlendra
Hi Lukasz,
Quoted 11 lines · Lukasz Luba
Hi Kaushlendra,
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
This is with respect to intel platforms which has E-cores and P-cores.
Do you mean that they share the same frequency domains ?
Just to get everybody on the same page:
Intel has what's called "favored cores", P-cores that allow for slightly higher frequencies than the other (same uArch) P-cores.
Okay so it's not E-core and P-core in the same domain but P-cores and favored P-cores
Quoted 8 lines
Rafael's EAS series decided that it wouldn't be worth the effort make EAS always iterate over an extra cluster (overhead on every wakeup hot-path) for CPUs where in the bigger picture the difference is negligible.
https://lore.kernel.org/lkml/[email protected]/
(capacities are 623, 1009 and 1024 here, 1009 and 1024 are lumped into one cluster.)
I think this isn't unreasonable, as long as this technicality lives inside ofintel_pstatesetup code and doesn't escape, like proposed here.
I agree
Quoted 7 lines
Obviously EAS heavily relies on "1 cluster => 1 capacity" assumption as mentioned before, even just for max-spare-cap in
feec().
Breaking this assumption would require a huge rework, which AFAIU specifically wasn't was Rafael intended, but I'm sure he'll chime in himself. So if you really have issues with the different capacities within a cluster trick that Rafael went with, please just reconsider that instead of trying to patch things up outside ofintel_pstate.
Rafael J. Wysocki
maintainerQuoted 17 lines · Christian Loehle
Quoted 15 lines · Vincent Guittot
Quoted 13 lines · Kaushlendra
Hi Lukasz,
Quoted 9 lines · Lukasz Luba
Hi Kaushlendra,
Quoted 5 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
How is this possible?
Is it old or new Intel SoC (a chip name would be also welcome)?This is with respect to intel platforms which has E-cores and P-cores.
So this is all misguided.
P-cores and E-cores don't even share frequency, so why would they be there in the same domain?
On P-cores, frequency can be controlled independently per-core.
E-cores technically go in modules of 4 and the frequency is shared within a module, but the interface to control it (HWP or CPPC if you will) is per-CPU and intel_pstate treans them as independent.
For this reason, sugov_next_freq_shared() should never be used on Intel hardware.
Quoted 6 lines
Quoted 2 lines
Do you mean that they share the same frequency domains ?
Just to get everybody on the same page:
Intel has what's called "favored cores", P-cores that allow for slightly higher frequencies than the other (same uArch) P-cores.
Yes, but they don't share the frequency level with any other cores.
Quoted 6 lines
Rafael's EAS series decided that it wouldn't be worth the effort make EAS always iterate over an extra cluster (overhead on every wakeup hot-path) for CPUs where in the bigger picture the difference is negligible.
https://lore.kernel.org/lkml/[email protected]/
(capacities are 623, 1009 and 1024 here, 1009 and 1024 are lumped into one cluster.)
Frequency control is still per-CPU though and from the schedutil perspective it is always the single CPU case.
Quoted 6 lines
I think this isn't unreasonable, as long as this technicality lives inside of
intel_pstatesetup code and doesn't escape, like proposed here. Obviously EAS heavily relies on "1 cluster => 1 capacity" assumption as mentioned before, even just for max-spare-cap infeec().
Breaking this assumption would require a huge rework, which AFAIU specifically wasn't was Rafael intended, but I'm sure he'll chime in himself.
The EAS considerations are kind of a separate thing and they have never changed the intel_pstate's assumptions regarding the performance control granularity.
Quoted 3 lines
So if you really have issues with the different capacities within a cluster trick that Rafael went with, please just reconsider that instead of trying to patch things up outside of
intel_pstate.
Honestly, I think that trying to patch things at all without sufficient understanding is antisocial and wrong.
Hi Rafael,
Quoted 14 lines · Rafael J. Wysocki
Quoted 6 lines · Christian Loehle
Quoted 4 lines · Vincent Guittot
Quoted 2 lines · Kaushlendra
This is with respect to intel platforms which has E-cores and P-cores.
So this is all misguided.
P-cores and E-cores don't even share frequency, so why would they be there in the same domain?
Quoted 8 lines
On P-cores, frequency can be controlled independently per-core.
E-cores technically go in modules of 4 and the frequency is shared within a module, but the interface to control it (HWP or CPPC if you will) is per-CPU and
intel_pstatetreans them as independent.For this reason,
sugov_next_freq_shared()should never be used on Intel hardware.
Thank you for the clarification.
BR,
Kaushlendra
Rafael J. Wysocki
maintainerQuoted 7 lines · Kaushlendra Kumar
In
sugov_next_freq_shared(), the CPU capacity is retrieved only for the CPU that triggered the update (sg_cpu->cpu) and then incorrectly applied to all CPUs in the shared frequency domain during the loop.On heterogeneous systems with CPUs of different capacities sharing a frequency domain, this causes incorrect frequency selection.
No, this is not what happens. sugov_next_freq_shared() is for the cases when the frequency *needs* to be set for all CPUs in the domain in one go.
Your patch is invalid, please be more careful.