All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity
@ 2019-12-04 18:21 Vincent Guittot
  2019-12-04 23:22 ` Valentin Schneider
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vincent Guittot @ 2019-12-04 18:21 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, dietmar.eggemann, rostedt, bsegall,
	mgorman, linux-kernel
  Cc: john.stultz, valentin.schneider, qais.yousef, Vincent Guittot

Because of CPU affinity, the local group can be skipped which breaks the
assumption that statistics are always collected for local group. With
uninitialized local_sgs, the comparison is meaningless and the behavior
unpredictable. This can even end up to use local pointer which is to
NULL in this case.

If the local group has been skipped because of CPU affinity, we return
the idlest group.

Fixes: 57abff067a08 ("sched/fair: Rework find_idlest_group()")
Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Tested-by: John Stultz <john.stultz@linaro.org>
---
 kernel/sched/fair.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 08a233e..146b6c8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8417,6 +8417,10 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
 	if (!idlest)
 		return NULL;
 
+	/* The local group has been skipped because of CPU affinity */
+	if (!local)
+		return idlest;
+
 	/*
 	 * If the local group is idler than the selected idlest group
 	 * don't try and push the task.
-- 
2.7.4


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

* Re: [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity
  2019-12-04 18:21 [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity Vincent Guittot
@ 2019-12-04 23:22 ` Valentin Schneider
  2019-12-10 10:36 ` Qais Yousef
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Valentin Schneider @ 2019-12-04 23:22 UTC (permalink / raw)
  To: Vincent Guittot, mingo, peterz, juri.lelli, dietmar.eggemann,
	rostedt, bsegall, mgorman, linux-kernel
  Cc: john.stultz, qais.yousef

On 04/12/2019 18:21, Vincent Guittot wrote:
> Because of CPU affinity, the local group can be skipped which breaks the
> assumption that statistics are always collected for local group. With
> uninitialized local_sgs, the comparison is meaningless and the behavior
> unpredictable. This can even end up to use local pointer which is to
> NULL in this case.
> 
> If the local group has been skipped because of CPU affinity, we return
> the idlest group.
> 

I stared at find_idlest_group() before the rework out of curiosity and
AFAICT the "never visit local group" thing was there already. However, we
would only use the load and spare capacity of that group, and the relevant
variables where initialized to ULONG_MAX and 0 respectively. This would lead
us to return 'idlest' (or 'most_spare_sg', but it's the same as 'idlest' now).

So IMO this is just restoring the previous behaviour, which is what we want
methinks.

Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>

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

* Re: [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity
  2019-12-04 18:21 [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity Vincent Guittot
  2019-12-04 23:22 ` Valentin Schneider
@ 2019-12-10 10:36 ` Qais Yousef
  2019-12-17  1:08 ` John Stultz
  2019-12-17 12:39 ` [tip: sched/urgent] sched/fair: Fix " tip-bot2 for Vincent Guittot
  3 siblings, 0 replies; 5+ messages in thread
From: Qais Yousef @ 2019-12-10 10:36 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: mingo, peterz, juri.lelli, dietmar.eggemann, rostedt, bsegall,
	mgorman, linux-kernel, john.stultz, valentin.schneider

On 12/04/19 19:21, Vincent Guittot wrote:
> Because of CPU affinity, the local group can be skipped which breaks the
> assumption that statistics are always collected for local group. With
> uninitialized local_sgs, the comparison is meaningless and the behavior
> unpredictable. This can even end up to use local pointer which is to
> NULL in this case.

For the record; I think this is safe and I can't see how the local_sgs can be
used uninitialized, but experience shows that if this happened once it's likely
to happen again when things change. So I think it'd be safer to always
initialize local_sgs to something sensible and avoid future trouble. I don't
see any cost to initializing it.

My 2p :-) The change is good for me as-is otherwise.

Cheers

--
Qais Yousef

> 
> If the local group has been skipped because of CPU affinity, we return
> the idlest group.
> 
> Fixes: 57abff067a08 ("sched/fair: Rework find_idlest_group()")
> Reported-by: John Stultz <john.stultz@linaro.org>
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> Tested-by: John Stultz <john.stultz@linaro.org>
> ---
>  kernel/sched/fair.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 08a233e..146b6c8 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8417,6 +8417,10 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
>  	if (!idlest)
>  		return NULL;
>  
> +	/* The local group has been skipped because of CPU affinity */
> +	if (!local)
> +		return idlest;
> +
>  	/*
>  	 * If the local group is idler than the selected idlest group
>  	 * don't try and push the task.
> -- 
> 2.7.4
> 

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

* Re: [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity
  2019-12-04 18:21 [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity Vincent Guittot
  2019-12-04 23:22 ` Valentin Schneider
  2019-12-10 10:36 ` Qais Yousef
@ 2019-12-17  1:08 ` John Stultz
  2019-12-17 12:39 ` [tip: sched/urgent] sched/fair: Fix " tip-bot2 for Vincent Guittot
  3 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2019-12-17  1:08 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, bsegall, mgorman, lkml, Valentin Schneider,
	Qais Yousef

On Wed, Dec 4, 2019 at 10:21 AM Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> Because of CPU affinity, the local group can be skipped which breaks the
> assumption that statistics are always collected for local group. With
> uninitialized local_sgs, the comparison is meaningless and the behavior
> unpredictable. This can even end up to use local pointer which is to
> NULL in this case.
>
> If the local group has been skipped because of CPU affinity, we return
> the idlest group.
>
> Fixes: 57abff067a08 ("sched/fair: Rework find_idlest_group()")
> Reported-by: John Stultz <john.stultz@linaro.org>
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> Tested-by: John Stultz <john.stultz@linaro.org>

Just wanted to follow up on this, as its seemed to have missed -rc2?

thanks
-john

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

* [tip: sched/urgent] sched/fair: Fix find_idlest_group() to handle CPU affinity
  2019-12-04 18:21 [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity Vincent Guittot
                   ` (2 preceding siblings ...)
  2019-12-17  1:08 ` John Stultz
@ 2019-12-17 12:39 ` tip-bot2 for Vincent Guittot
  3 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Vincent Guittot @ 2019-12-17 12:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: John Stultz, Vincent Guittot, Peter Zijlstra (Intel),
	Valentin Schneider, rostedt, mingo, mgorman, juri.lelli,
	dietmar.eggemann, bsegall, qais.yousef, x86, LKML

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     7ed735c33104f3c6194fbc67e3a8b6e64ae84ad1
Gitweb:        https://git.kernel.org/tip/7ed735c33104f3c6194fbc67e3a8b6e64ae84ad1
Author:        Vincent Guittot <vincent.guittot@linaro.org>
AuthorDate:    Wed, 04 Dec 2019 19:21:40 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 17 Dec 2019 13:32:48 +01:00

sched/fair: Fix find_idlest_group() to handle CPU affinity

Because of CPU affinity, the local group can be skipped which breaks the
assumption that statistics are always collected for local group. With
uninitialized local_sgs, the comparison is meaningless and the behavior
unpredictable. This can even end up to use local pointer which is to
NULL in this case.

If the local group has been skipped because of CPU affinity, we return
the idlest group.

Fixes: 57abff067a08 ("sched/fair: Rework find_idlest_group()")
Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Cc: rostedt@goodmis.org
Cc: valentin.schneider@arm.com
Cc: mingo@redhat.com
Cc: mgorman@suse.de
Cc: juri.lelli@redhat.com
Cc: dietmar.eggemann@arm.com
Cc: bsegall@google.com
Cc: qais.yousef@arm.com
Link: https://lkml.kernel.org/r/1575483700-22153-1-git-send-email-vincent.guittot@linaro.org
---
 kernel/sched/fair.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 08a233e..146b6c8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8417,6 +8417,10 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
 	if (!idlest)
 		return NULL;
 
+	/* The local group has been skipped because of CPU affinity */
+	if (!local)
+		return idlest;
+
 	/*
 	 * If the local group is idler than the selected idlest group
 	 * don't try and push the task.

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

end of thread, other threads:[~2019-12-17 12:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 18:21 [PATCH] sched/fair: fix find_idlest_group() to handle CPU affinity Vincent Guittot
2019-12-04 23:22 ` Valentin Schneider
2019-12-10 10:36 ` Qais Yousef
2019-12-17  1:08 ` John Stultz
2019-12-17 12:39 ` [tip: sched/urgent] sched/fair: Fix " tip-bot2 for Vincent Guittot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.