[5/5] sched/fair: narrow the sched_use_asym_prio checking scenario

Message ID 20240117085715.2614671-5-alexs@kernel.org
State New
Headers
Series [1/5] sched/fair: add SD_CLUSTER in comments |

Commit Message

alexs@kernel.org Jan. 17, 2024, 8:57 a.m. UTC
  From: Alex Shi <alexs@kernel.org>

Current function doesn't match it's comments, in fact, core_idle
checking is only meaningful with non-SMT.
So make the function right.

Signed-off-by: Alex Shi <alexs@kernel.org>
To: Valentin Schneider <vschneid@redhat.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
To: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@redhat.com>
---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Shrikanth Hegde Jan. 23, 2024, 8:47 a.m. UTC | #1
On 1/17/24 2:27 PM, alexs@kernel.org wrote:
> From: Alex Shi <alexs@kernel.org>
> 
> Current function doesn't match it's comments, in fact, core_idle
> checking is only meaningful with non-SMT.
> So make the function right.
> 
> Signed-off-by: Alex Shi <alexs@kernel.org>
> To: Valentin Schneider <vschneid@redhat.com>
> To: Vincent Guittot <vincent.guittot@linaro.org>
> To: Peter Zijlstra <peterz@infradead.org>
> To: Ingo Molnar <mingo@redhat.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 96163ab69ae0..0a321f639c79 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -9741,8 +9741,8 @@ group_type group_classify(unsigned int imbalance_pct,
>   */
>  static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
>  {
> -	return (!sched_smt_active()) ||
> -		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
> +	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
> +		(!sched_smt_active() && is_core_idle(cpu));
>  }

This seems wrong. This would always return false for higher than SMT domains 
if smt is active. 

Was this meant to be sched_smt_active() && is_core_idle(cpu)? 

>  
>  static inline bool _sched_asym(struct sched_domain *sd,
  
kuiliang Shi Jan. 25, 2024, 9:35 a.m. UTC | #2
On 1/23/24 4:47 PM, Shrikanth Hegde wrote:
> 
> 
> On 1/17/24 2:27 PM, alexs@kernel.org wrote:
>> From: Alex Shi <alexs@kernel.org>
>>
>> Current function doesn't match it's comments, in fact, core_idle
>> checking is only meaningful with non-SMT.
>> So make the function right.
>>
>> Signed-off-by: Alex Shi <alexs@kernel.org>
>> To: Valentin Schneider <vschneid@redhat.com>
>> To: Vincent Guittot <vincent.guittot@linaro.org>
>> To: Peter Zijlstra <peterz@infradead.org>
>> To: Ingo Molnar <mingo@redhat.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 96163ab69ae0..0a321f639c79 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -9741,8 +9741,8 @@ group_type group_classify(unsigned int imbalance_pct,
>>   */
>>  static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
>>  {
>> -	return (!sched_smt_active()) ||
>> -		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
>> +	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
>> +		(!sched_smt_active() && is_core_idle(cpu));
>>  }
> 
> This seems wrong. This would always return false for higher than SMT domains 
> if smt is active. 
> 

yes, thanks for point out.

> Was this meant to be sched_smt_active() && is_core_idle(cpu)? 

In theory, yes, it should like this. But I have no ASYM device to test. :(

Thanks!
Alex

> 
>>  
>>  static inline bool _sched_asym(struct sched_domain *sd,
  
Ricardo Neri Jan. 26, 2024, 12:04 a.m. UTC | #3
On Tue, Jan 23, 2024 at 02:17:00PM +0530, Shrikanth Hegde wrote:
> 
> 
> On 1/17/24 2:27 PM, alexs@kernel.org wrote:
> > From: Alex Shi <alexs@kernel.org>
> > 
> > Current function doesn't match it's comments, in fact, core_idle
> > checking is only meaningful with non-SMT.

For SMT cores, we _do_ need to check for a whole core to be idle when
deciding to use asym_packing priorities when balancing between cores, but
not in SMT domains. This is what the function's documentation states.

> > So make the function right.
> > 
> > Signed-off-by: Alex Shi <alexs@kernel.org>
> > To: Valentin Schneider <vschneid@redhat.com>
> > To: Vincent Guittot <vincent.guittot@linaro.org>
> > To: Peter Zijlstra <peterz@infradead.org>
> > To: Ingo Molnar <mingo@redhat.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 96163ab69ae0..0a321f639c79 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -9741,8 +9741,8 @@ group_type group_classify(unsigned int imbalance_pct,
> >   */
> >  static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
> >  {
> > -	return (!sched_smt_active()) ||
> > -		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
> > +	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
> > +		(!sched_smt_active() && is_core_idle(cpu));
> >  }
> 
> This seems wrong. This would always return false for higher than SMT domains 
> if smt is active. 

Agreed.

> 
> Was this meant to be sched_smt_active() && is_core_idle(cpu)? 

But this would not work if SMT is inactive, in such case checking
for a whole idle core is pointless.
  
Ricardo Neri Jan. 26, 2024, 12:06 a.m. UTC | #4
On Thu, Jan 25, 2024 at 05:35:32PM +0800, kuiliang Shi wrote:
> 
> 
> On 1/23/24 4:47 PM, Shrikanth Hegde wrote:
> > 
> > 
> > On 1/17/24 2:27 PM, alexs@kernel.org wrote:
> >> From: Alex Shi <alexs@kernel.org>
> >>
> >> Current function doesn't match it's comments, in fact, core_idle
> >> checking is only meaningful with non-SMT.
> >> So make the function right.
> >>
> >> Signed-off-by: Alex Shi <alexs@kernel.org>
> >> To: Valentin Schneider <vschneid@redhat.com>
> >> To: Vincent Guittot <vincent.guittot@linaro.org>
> >> To: Peter Zijlstra <peterz@infradead.org>
> >> To: Ingo Molnar <mingo@redhat.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 96163ab69ae0..0a321f639c79 100644
> >> --- a/kernel/sched/fair.c
> >> +++ b/kernel/sched/fair.c
> >> @@ -9741,8 +9741,8 @@ group_type group_classify(unsigned int imbalance_pct,
> >>   */
> >>  static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
> >>  {
> >> -	return (!sched_smt_active()) ||
> >> -		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
> >> +	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
> >> +		(!sched_smt_active() && is_core_idle(cpu));
> >>  }
> > 
> > This seems wrong. This would always return false for higher than SMT domains 
> > if smt is active. 
> > 
> 
> yes, thanks for point out.
> 
> > Was this meant to be sched_smt_active() && is_core_idle(cpu)? 
> 
> In theory, yes, it should like this. But I have no ASYM device to test. :(

This would not work with !SMT and asym_packing.

I can test your patches on asym_packing + SMT systems if you post a new
version.
  
kuiliang Shi Jan. 30, 2024, 1:18 p.m. UTC | #5
On 1/26/24 8:06 AM, Ricardo Neri wrote:
> On Thu, Jan 25, 2024 at 05:35:32PM +0800, kuiliang Shi wrote:
>>
>>
>> On 1/23/24 4:47 PM, Shrikanth Hegde wrote:
>>>
>>>
>>> On 1/17/24 2:27 PM, alexs@kernel.org wrote:
>>>> From: Alex Shi <alexs@kernel.org>
>>>>
>>>> Current function doesn't match it's comments, in fact, core_idle
>>>> checking is only meaningful with non-SMT.
>>>> So make the function right.
>>>>
>>>> Signed-off-by: Alex Shi <alexs@kernel.org>
>>>> To: Valentin Schneider <vschneid@redhat.com>
>>>> To: Vincent Guittot <vincent.guittot@linaro.org>
>>>> To: Peter Zijlstra <peterz@infradead.org>
>>>> To: Ingo Molnar <mingo@redhat.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 96163ab69ae0..0a321f639c79 100644
>>>> --- a/kernel/sched/fair.c
>>>> +++ b/kernel/sched/fair.c
>>>> @@ -9741,8 +9741,8 @@ group_type group_classify(unsigned int imbalance_pct,
>>>>   */
>>>>  static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
>>>>  {
>>>> -	return (!sched_smt_active()) ||
>>>> -		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
>>>> +	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
>>>> +		(!sched_smt_active() && is_core_idle(cpu));
>>>>  }
>>>
>>> This seems wrong. This would always return false for higher than SMT domains 
>>> if smt is active. 
>>>
>>
>> yes, thanks for point out.
>>
>>> Was this meant to be sched_smt_active() && is_core_idle(cpu)? 
>>
>> In theory, yes, it should like this. But I have no ASYM device to test. :(
> 
> This would not work with !SMT and asym_packing.
> 
> I can test your patches on asym_packing + SMT systems if you post a new
> version.
> 

Hi Neri,

Thanks a lot for generous offer! I don't know if my understanding right, but I try my best to have a best guessing in V2 patch for you. :)

Many thanks for the help!

Best regards
Alex
  

Patch

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 96163ab69ae0..0a321f639c79 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9741,8 +9741,8 @@  group_type group_classify(unsigned int imbalance_pct,
  */
 static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 {
-	return (!sched_smt_active()) ||
-		(sd->flags & SD_SHARE_CPUCAPACITY) || is_core_idle(cpu);
+	return	(sd->flags & SD_SHARE_CPUCAPACITY) ||
+		(!sched_smt_active() && is_core_idle(cpu));
 }
 
 static inline bool _sched_asym(struct sched_domain *sd,