sched/core: use correct cpu_capacity in wake_affine_weight()

Message ID 20221116091027.78906-1-wanghonglei@didiglobal.com
State New
Headers
Series sched/core: use correct cpu_capacity in wake_affine_weight() |

Commit Message

Honglei Wang Nov. 16, 2022, 9:10 a.m. UTC
  It seems make more sense to do the load weight calculation with
respective cpu_capacity.

Signed-off-by: Honglei Wang <wanghonglei@didiglobal.com>
---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Vincent Guittot Nov. 16, 2022, 11 a.m. UTC | #1
On Wed, 16 Nov 2022 at 10:12, Honglei Wang <wanghonglei@didiglobal.com> wrote:
>
> It seems make more sense to do the load weight calculation with
> respective cpu_capacity.
>
> Signed-off-by: Honglei Wang <wanghonglei@didiglobal.com>
> ---
>  kernel/sched/fair.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index e4a0b8bd941c..a9f75040969b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6262,13 +6262,13 @@ wake_affine_weight(struct sched_domain *sd, struct task_struct *p,
>         this_eff_load += task_load;
>         if (sched_feat(WA_BIAS))
>                 this_eff_load *= 100;
> -       this_eff_load *= capacity_of(prev_cpu);
> +       this_eff_load *= capacity_of(this_cpu);
>
>         prev_eff_load = cpu_load(cpu_rq(prev_cpu));
>         prev_eff_load -= task_load;
>         if (sched_feat(WA_BIAS))
>                 prev_eff_load *= 100 + (sd->imbalance_pct - 100) / 2;
> -       prev_eff_load *= capacity_of(this_cpu);
> +       prev_eff_load *= capacity_of(prev_cpu);

we want to test :
    (cpu_load(this_rq) + task_h_load(p) ) / capacity_of(this_cpu)  <
cpu_load(prev_rq) / capacity_of(prev_cpu)

but instead of doing expensive division, we do the below which gives
the same result
    (cpu_load(this_rq) + task_h_load(p) ) * capacity_of(prev_cpu)  <
cpu_load(prev_rq) * capacity_of(this_cpu)


>
>         /*
>          * If sync, adjust the weight of prev_eff_load such that if
> --
> 2.14.1
>
  
Honglei Wang Nov. 16, 2022, 11:17 a.m. UTC | #2
On 2022/11/16 19:00, Vincent Guittot wrote:
> On Wed, 16 Nov 2022 at 10:12, Honglei Wang <wanghonglei@didiglobal.com> wrote:
>>
>> It seems make more sense to do the load weight calculation with
>> respective cpu_capacity.
>>
>> Signed-off-by: Honglei Wang <wanghonglei@didiglobal.com>
>> ---
>>   kernel/sched/fair.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index e4a0b8bd941c..a9f75040969b 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -6262,13 +6262,13 @@ wake_affine_weight(struct sched_domain *sd, struct task_struct *p,
>>          this_eff_load += task_load;
>>          if (sched_feat(WA_BIAS))
>>                  this_eff_load *= 100;
>> -       this_eff_load *= capacity_of(prev_cpu);
>> +       this_eff_load *= capacity_of(this_cpu);
>>
>>          prev_eff_load = cpu_load(cpu_rq(prev_cpu));
>>          prev_eff_load -= task_load;
>>          if (sched_feat(WA_BIAS))
>>                  prev_eff_load *= 100 + (sd->imbalance_pct - 100) / 2;
>> -       prev_eff_load *= capacity_of(this_cpu);
>> +       prev_eff_load *= capacity_of(prev_cpu);
> 
> we want to test :
>      (cpu_load(this_rq) + task_h_load(p) ) / capacity_of(this_cpu)  <
> cpu_load(prev_rq) / capacity_of(prev_cpu)
> 
> but instead of doing expensive division, we do the below which gives
> the same result
>      (cpu_load(this_rq) + task_h_load(p) ) * capacity_of(prev_cpu)  <
> cpu_load(prev_rq) * capacity_of(this_cpu)
> 
> 

ha, I misunderstand the strategy, thanks for coaching, Vincent.

>>
>>          /*
>>           * If sync, adjust the weight of prev_eff_load such that if
>> --
>> 2.14.1
>>
  

Patch

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e4a0b8bd941c..a9f75040969b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6262,13 +6262,13 @@  wake_affine_weight(struct sched_domain *sd, struct task_struct *p,
 	this_eff_load += task_load;
 	if (sched_feat(WA_BIAS))
 		this_eff_load *= 100;
-	this_eff_load *= capacity_of(prev_cpu);
+	this_eff_load *= capacity_of(this_cpu);
 
 	prev_eff_load = cpu_load(cpu_rq(prev_cpu));
 	prev_eff_load -= task_load;
 	if (sched_feat(WA_BIAS))
 		prev_eff_load *= 100 + (sd->imbalance_pct - 100) / 2;
-	prev_eff_load *= capacity_of(this_cpu);
+	prev_eff_load *= capacity_of(prev_cpu);
 
 	/*
 	 * If sync, adjust the weight of prev_eff_load such that if