linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
@ 2023-06-17  8:19 Miaohe Lin
  2023-06-18 16:32 ` Chen Yu
  2023-06-20 14:11 ` Peter Zijlstra
  0 siblings, 2 replies; 8+ messages in thread
From: Miaohe Lin @ 2023-06-17  8:19 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, linmiaohe

When sg != sd->groups, the do while loop would cause deadloop here. But
that won't occur because sg is always equal to sd->groups now. Remove
this unneeded do while loop.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 kernel/sched/topology.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index ca4472281c28..9010c93c3fdb 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -750,10 +750,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
 			 * domain for convenience. Clear such flags since
 			 * the child is being destroyed.
 			 */
-			do {
-				sg->flags = 0;
-			} while (sg != sd->groups);
-
+			sg->flags = 0;
 			sd->child = NULL;
 		}
 	}
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-17  8:19 [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain() Miaohe Lin
@ 2023-06-18 16:32 ` Chen Yu
  2023-06-20 14:11 ` Peter Zijlstra
  1 sibling, 0 replies; 8+ messages in thread
From: Chen Yu @ 2023-06-18 16:32 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel,
	tim.c.chen, ricardo.neri, yangyicong

On 2023-06-17 at 16:19:26 +0800, Miaohe Lin wrote:
> When sg != sd->groups, the do while loop would cause deadloop here. But
> that won't occur because sg is always equal to sd->groups now. Remove
> this unneeded do while loop.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  kernel/sched/topology.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index ca4472281c28..9010c93c3fdb 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -750,10 +750,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
>  			 * domain for convenience. Clear such flags since
>  			 * the child is being destroyed.
>  			 */
> -			do {
> -				sg->flags = 0;
I guess we don't need to clear the flag of remote groups for now.
> -			} while (sg != sd->groups);
> -
> +			sg->flags = 0;
>  			sd->child = NULL;
>  		}
>  	}
> -- 
> 2.27.0
>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>

thanks,
Chenyu 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-17  8:19 [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain() Miaohe Lin
  2023-06-18 16:32 ` Chen Yu
@ 2023-06-20 14:11 ` Peter Zijlstra
  2023-06-21  2:53   ` Miaohe Lin
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2023-06-20 14:11 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel

On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
> When sg != sd->groups, the do while loop would cause deadloop here. But
> that won't occur because sg is always equal to sd->groups now. Remove
> this unneeded do while loop.

This Changelog makes no sense to me.. Yes, as is the do {} while loop is
dead code, but it *should* have read like:

	do {
		sg->flags = 0;
		sg = sg->next;
	} while (sg != sd->groups);

as I noted here:

  https://lore.kernel.org/all/20230523105935.GN83892@hirez.programming.kicks-ass.net/T/#u

So what this changelog should argue is how there cannot be multiple
groups here -- or if there can be, add the missing iteration.

> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  kernel/sched/topology.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index ca4472281c28..9010c93c3fdb 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -750,10 +750,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
>  			 * domain for convenience. Clear such flags since
>  			 * the child is being destroyed.
>  			 */
> -			do {
> -				sg->flags = 0;
> -			} while (sg != sd->groups);
> -
> +			sg->flags = 0;
>  			sd->child = NULL;
>  		}
>  	}
> -- 
> 2.27.0
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-20 14:11 ` Peter Zijlstra
@ 2023-06-21  2:53   ` Miaohe Lin
  2023-06-21 13:11     ` Ricardo Neri
  0 siblings, 1 reply; 8+ messages in thread
From: Miaohe Lin @ 2023-06-21  2:53 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel

On 2023/6/20 22:11, Peter Zijlstra wrote:
> On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
>> When sg != sd->groups, the do while loop would cause deadloop here. But
>> that won't occur because sg is always equal to sd->groups now. Remove
>> this unneeded do while loop.
> 
> This Changelog makes no sense to me.. Yes, as is the do {} while loop is
> dead code, but it *should* have read like:
> 
> 	do {
> 		sg->flags = 0;
> 		sg = sg->next;
> 	} while (sg != sd->groups);
> 
> as I noted here:
> 
>   https://lore.kernel.org/all/20230523105935.GN83892@hirez.programming.kicks-ass.net/T/#u

[1]

> 
> So what this changelog should argue is how there cannot be multiple
> groups here -- or if there can be, add the missing iteration.

[1] said:
"
Yes, I missed that.

That being said, the only reason for sd to be degenerate is that there
is only 1 group. Otherwise we will keep it and degenerate parents
instead
"

IOW, "sg = sg->next;" is missed intentionally in the do while{} loop to show that
there's only 1 sched group. This looks weird to me but no persist on change the code.

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-21  2:53   ` Miaohe Lin
@ 2023-06-21 13:11     ` Ricardo Neri
  2023-06-21 18:57       ` Ricardo Neri
  0 siblings, 1 reply; 8+ messages in thread
From: Ricardo Neri @ 2023-06-21 13:11 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: Peter Zijlstra, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, yu.c.chen, tim.c.chen

On Wed, Jun 21, 2023 at 10:53:57AM +0800, Miaohe Lin wrote:
> On 2023/6/20 22:11, Peter Zijlstra wrote:
> > On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
> >> When sg != sd->groups, the do while loop would cause deadloop here. But
> >> that won't occur because sg is always equal to sd->groups now. Remove
> >> this unneeded do while loop.
> > 
> > This Changelog makes no sense to me.. Yes, as is the do {} while loop is
> > dead code, but it *should* have read like:
> > 
> > 	do {
> > 		sg->flags = 0;
> > 		sg = sg->next;
> > 	} while (sg != sd->groups);

Yes, I agree that this is the correct solution.

> > 
> > as I noted here:
> > 
> >   https://lore.kernel.org/all/20230523105935.GN83892@hirez.programming.kicks-ass.net/T/#u

I apologize. I missed this e-mail.

> 
> [1]
> 
> > 
> > So what this changelog should argue is how there cannot be multiple
> > groups here -- or if there can be, add the missing iteration.
> 
> [1] said:
> "
> Yes, I missed that.
> 
> That being said, the only reason for sd to be degenerate is that there
> is only 1 group. Otherwise we will keep it and degenerate parents
> instead
> "

In the section of the code in question ,`sd` now points to the parent of the
sched group being degenerated. Thus, it may have more than one group, and we should
iterate over them to clear the flags.

> 
> IOW, "sg = sg->next;" is missed intentionally in the do while{} loop to show that
> there's only 1 sched group. This looks weird to me but no persist on change the code.

Not having `sg = sg->next;` is a bug, IMO.

Thanks and BR,
Ricardo 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-21 13:11     ` Ricardo Neri
@ 2023-06-21 18:57       ` Ricardo Neri
  2023-06-25  1:59         ` Miaohe Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Ricardo Neri @ 2023-06-21 18:57 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: Peter Zijlstra, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, yu.c.chen, tim.c.chen

On Wed, Jun 21, 2023 at 06:11:59AM -0700, Ricardo Neri wrote:
> On Wed, Jun 21, 2023 at 10:53:57AM +0800, Miaohe Lin wrote:
> > On 2023/6/20 22:11, Peter Zijlstra wrote:
> > > On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
> > >> When sg != sd->groups, the do while loop would cause deadloop here. But
> > >> that won't occur because sg is always equal to sd->groups now. Remove
> > >> this unneeded do while loop.
> > > 
> > > This Changelog makes no sense to me.. Yes, as is the do {} while loop is
> > > dead code, but it *should* have read like:
> > > 
> > > 	do {
> > > 		sg->flags = 0;
> > > 		sg = sg->next;
> > > 	} while (sg != sd->groups);
> 
> Yes, I agree that this is the correct solution.

I take this back. I think we should do this:

@@ -758,19 +758,14 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
 		sd = sd->parent;
 		destroy_sched_domain(tmp);
 		if (sd) {
-			struct sched_group *sg = sd->groups;
-
 			/*
 			 * sched groups hold the flags of the child sched
 			 * domain for convenience. Clear such flags since
 			 * the child is being destroyed.
 			 */
-			do {
-				sg->flags = 0;
-			} while (sg != sd->groups);
+			sd->groups->flags = 0;
 
 			sd->child = NULL;
-		}
 	}
 
 	sched_domain_debug(sd, cpu);

A comment from Chenyu made got me thinking that we should only clear the
flags of the local group as viewed from the parent domain. This is because
the domain being degenerated defines the flags of such group only.

The current code does the right thing, but in a fortuitous and ugly manner.

Thanks and BR,
Ricardo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-21 18:57       ` Ricardo Neri
@ 2023-06-25  1:59         ` Miaohe Lin
  2023-07-12 18:33           ` Ricardo Neri
  0 siblings, 1 reply; 8+ messages in thread
From: Miaohe Lin @ 2023-06-25  1:59 UTC (permalink / raw)
  To: Ricardo Neri
  Cc: Peter Zijlstra, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, yu.c.chen, tim.c.chen

On 2023/6/22 2:57, Ricardo Neri wrote:
> On Wed, Jun 21, 2023 at 06:11:59AM -0700, Ricardo Neri wrote:
>> On Wed, Jun 21, 2023 at 10:53:57AM +0800, Miaohe Lin wrote:
>>> On 2023/6/20 22:11, Peter Zijlstra wrote:
>>>> On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
>>>>> When sg != sd->groups, the do while loop would cause deadloop here. But
>>>>> that won't occur because sg is always equal to sd->groups now. Remove
>>>>> this unneeded do while loop.
>>>>
>>>> This Changelog makes no sense to me.. Yes, as is the do {} while loop is
>>>> dead code, but it *should* have read like:
>>>>
>>>> 	do {
>>>> 		sg->flags = 0;
>>>> 		sg = sg->next;
>>>> 	} while (sg != sd->groups);
>>
>> Yes, I agree that this is the correct solution.
> 
> I take this back. I think we should do this:
> 
> @@ -758,19 +758,14 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
>  		sd = sd->parent;
>  		destroy_sched_domain(tmp);
>  		if (sd) {
> -			struct sched_group *sg = sd->groups;
> -
>  			/*
>  			 * sched groups hold the flags of the child sched
>  			 * domain for convenience. Clear such flags since
>  			 * the child is being destroyed.
>  			 */
> -			do {
> -				sg->flags = 0;
> -			} while (sg != sd->groups);
> +			sd->groups->flags = 0;
>  
>  			sd->child = NULL;
> -		}
>  	}
>  
>  	sched_domain_debug(sd, cpu);
> 
> A comment from Chenyu made got me thinking that we should only clear the
> flags of the local group as viewed from the parent domain. This is because
> the domain being degenerated defines the flags of such group only.

This looks better to my patch. Thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()
  2023-06-25  1:59         ` Miaohe Lin
@ 2023-07-12 18:33           ` Ricardo Neri
  0 siblings, 0 replies; 8+ messages in thread
From: Ricardo Neri @ 2023-07-12 18:33 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: Peter Zijlstra, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, yu.c.chen, tim.c.chen

On Sun, Jun 25, 2023 at 09:59:36AM +0800, Miaohe Lin wrote:
> On 2023/6/22 2:57, Ricardo Neri wrote:
> > On Wed, Jun 21, 2023 at 06:11:59AM -0700, Ricardo Neri wrote:
> >> On Wed, Jun 21, 2023 at 10:53:57AM +0800, Miaohe Lin wrote:
> >>> On 2023/6/20 22:11, Peter Zijlstra wrote:
> >>>> On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
> >>>>> When sg != sd->groups, the do while loop would cause deadloop here. But
> >>>>> that won't occur because sg is always equal to sd->groups now. Remove
> >>>>> this unneeded do while loop.
> >>>>
> >>>> This Changelog makes no sense to me.. Yes, as is the do {} while loop is
> >>>> dead code, but it *should* have read like:
> >>>>
> >>>> 	do {
> >>>> 		sg->flags = 0;
> >>>> 		sg = sg->next;
> >>>> 	} while (sg != sd->groups);
> >>
> >> Yes, I agree that this is the correct solution.
> > 
> > I take this back. I think we should do this:
> > 
> > @@ -758,19 +758,14 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
> >  		sd = sd->parent;
> >  		destroy_sched_domain(tmp);
> >  		if (sd) {
> > -			struct sched_group *sg = sd->groups;
> > -
> >  			/*
> >  			 * sched groups hold the flags of the child sched
> >  			 * domain for convenience. Clear such flags since
> >  			 * the child is being destroyed.
> >  			 */
> > -			do {
> > -				sg->flags = 0;
> > -			} while (sg != sd->groups);
> > +			sd->groups->flags = 0;
> >  
> >  			sd->child = NULL;
> > -		}
> >  	}
> >  
> >  	sched_domain_debug(sd, cpu);
> > 
> > A comment from Chenyu made got me thinking that we should only clear the
> > flags of the local group as viewed from the parent domain. This is because
> > the domain being degenerated defines the flags of such group only.
> 
> This looks better to my patch. Thanks.

Are you planning on posting a v2? Maybe I missed it.
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-12 18:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17  8:19 [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain() Miaohe Lin
2023-06-18 16:32 ` Chen Yu
2023-06-20 14:11 ` Peter Zijlstra
2023-06-21  2:53   ` Miaohe Lin
2023-06-21 13:11     ` Ricardo Neri
2023-06-21 18:57       ` Ricardo Neri
2023-06-25  1:59         ` Miaohe Lin
2023-07-12 18:33           ` Ricardo Neri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).