linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong
@ 2022-10-08  2:27 Lin Shengwang
  2022-10-10  1:14 ` Aubrey Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lin Shengwang @ 2022-10-08  2:27 UTC (permalink / raw)
  To: peterz, mingo, juri.lelli, vincent.guittot, aubrey.li
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, cj.chengjian

In commit 97886d9dcd86 ("sched: Migration changes for core scheduling"),
sched_group_cookie_match() was added to help finding cookie matched
group, but was inconsistent with the actual purpose.

Using cpu_rq(cpu) instead of rq to fix the bug.

Fixes: 97886d9dcd86 ("sched: Migration changes for core scheduling")
Signed-off-by: Lin Shengwang <linshengwang1@huawei.com>
---
 kernel/sched/sched.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 23c6f9f42ba1..1ba602139840 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1182,6 +1182,14 @@ static inline bool is_migration_disabled(struct task_struct *p)
 #endif
 }
 
+DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
+
+#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
+#define this_rq()		this_cpu_ptr(&runqueues)
+#define task_rq(p)		cpu_rq(task_cpu(p))
+#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
+#define raw_rq()		raw_cpu_ptr(&runqueues)
+
 struct sched_group;
 #ifdef CONFIG_SCHED_CORE
 static inline struct cpumask *sched_group_span(struct sched_group *sg);
@@ -1269,7 +1277,7 @@ static inline bool sched_group_cookie_match(struct rq *rq,
 		return true;
 
 	for_each_cpu_and(cpu, sched_group_span(group), p->cpus_ptr) {
-		if (sched_core_cookie_match(rq, p))
+		if (sched_core_cookie_match(cpu_rq(cpu), p))
 			return true;
 	}
 	return false;
@@ -1384,14 +1392,6 @@ static inline void update_idle_core(struct rq *rq)
 static inline void update_idle_core(struct rq *rq) { }
 #endif
 
-DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
-
-#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
-#define this_rq()		this_cpu_ptr(&runqueues)
-#define task_rq(p)		cpu_rq(task_cpu(p))
-#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
-#define raw_rq()		raw_cpu_ptr(&runqueues)
-
 #ifdef CONFIG_FAIR_GROUP_SCHED
 static inline struct task_struct *task_of(struct sched_entity *se)
 {
-- 
2.17.1


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

* Re: [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong
  2022-10-08  2:27 [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong Lin Shengwang
@ 2022-10-10  1:14 ` Aubrey Li
  2022-10-10  7:37 ` Peter Zijlstra
  2022-10-17 14:45 ` [tip: sched/urgent] sched/core: Fix comparison in sched_group_cookie_match() tip-bot2 for Lin Shengwang
  2 siblings, 0 replies; 4+ messages in thread
From: Aubrey Li @ 2022-10-10  1:14 UTC (permalink / raw)
  To: Lin Shengwang, peterz, mingo, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
	linux-kernel, cj.chengjian

On 10/8/22 10:27, Lin Shengwang wrote:
> In commit 97886d9dcd86 ("sched: Migration changes for core scheduling"),
> sched_group_cookie_match() was added to help finding cookie matched
> group, but was inconsistent with the actual purpose.
> 
> Using cpu_rq(cpu) instead of rq to fix the bug.
> 
> Fixes: 97886d9dcd86 ("sched: Migration changes for core scheduling")
> Signed-off-by: Lin Shengwang <linshengwang1@huawei.com>
> ---
>  kernel/sched/sched.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 23c6f9f42ba1..1ba602139840 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -1182,6 +1182,14 @@ static inline bool is_migration_disabled(struct task_struct *p)
>  #endif
>  }
>  
> +DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
> +
> +#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
> +#define this_rq()		this_cpu_ptr(&runqueues)
> +#define task_rq(p)		cpu_rq(task_cpu(p))
> +#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
> +#define raw_rq()		raw_cpu_ptr(&runqueues)
> +
>  struct sched_group;
>  #ifdef CONFIG_SCHED_CORE
>  static inline struct cpumask *sched_group_span(struct sched_group *sg);
> @@ -1269,7 +1277,7 @@ static inline bool sched_group_cookie_match(struct rq *rq,
>  		return true;
>  
>  	for_each_cpu_and(cpu, sched_group_span(group), p->cpus_ptr) {
> -		if (sched_core_cookie_match(rq, p))
> +		if (sched_core_cookie_match(cpu_rq(cpu), p))>  			return true;
>  	}
>  	return false;
This looks a proper fix to me. Thanks!

-Aubrey

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

* Re: [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong
  2022-10-08  2:27 [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong Lin Shengwang
  2022-10-10  1:14 ` Aubrey Li
@ 2022-10-10  7:37 ` Peter Zijlstra
  2022-10-17 14:45 ` [tip: sched/urgent] sched/core: Fix comparison in sched_group_cookie_match() tip-bot2 for Lin Shengwang
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2022-10-10  7:37 UTC (permalink / raw)
  To: Lin Shengwang
  Cc: mingo, juri.lelli, vincent.guittot, aubrey.li, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel,
	cj.chengjian

On Sat, Oct 08, 2022 at 10:27:09AM +0800, Lin Shengwang wrote:
> In commit 97886d9dcd86 ("sched: Migration changes for core scheduling"),
> sched_group_cookie_match() was added to help finding cookie matched
> group, but was inconsistent with the actual purpose.
> 
> Using cpu_rq(cpu) instead of rq to fix the bug.
> 
> Fixes: 97886d9dcd86 ("sched: Migration changes for core scheduling")
> Signed-off-by: Lin Shengwang <linshengwang1@huawei.com>
> ---
>  kernel/sched/sched.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 23c6f9f42ba1..1ba602139840 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h

> @@ -1269,7 +1277,7 @@ static inline bool sched_group_cookie_match(struct rq *rq,
>  		return true;
>  
>  	for_each_cpu_and(cpu, sched_group_span(group), p->cpus_ptr) {
> -		if (sched_core_cookie_match(rq, p))
> +		if (sched_core_cookie_match(cpu_rq(cpu), p))
>  			return true;

Urgh.. Thanks!

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

* [tip: sched/urgent] sched/core: Fix comparison in sched_group_cookie_match()
  2022-10-08  2:27 [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong Lin Shengwang
  2022-10-10  1:14 ` Aubrey Li
  2022-10-10  7:37 ` Peter Zijlstra
@ 2022-10-17 14:45 ` tip-bot2 for Lin Shengwang
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Lin Shengwang @ 2022-10-17 14:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Lin Shengwang, Peter Zijlstra (Intel), x86, linux-kernel

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

Commit-ID:     e705968dd687574b6ca3ebe772683d5642759132
Gitweb:        https://git.kernel.org/tip/e705968dd687574b6ca3ebe772683d5642759132
Author:        Lin Shengwang <linshengwang1@huawei.com>
AuthorDate:    Sat, 08 Oct 2022 10:27:09 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 17 Oct 2022 16:41:24 +02:00

sched/core: Fix comparison in sched_group_cookie_match()

In commit 97886d9dcd86 ("sched: Migration changes for core scheduling"),
sched_group_cookie_match() was added to help determine if a cookie
matches the core state.

However, while it iterates the SMT group, it fails to actually use the
RQ for each of the CPUs iterated, use cpu_rq(cpu) instead of rq to fix
things.

Fixes: 97886d9dcd86 ("sched: Migration changes for core scheduling")
Signed-off-by: Lin Shengwang <linshengwang1@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20221008022709.642-1-linshengwang1@huawei.com
---
 kernel/sched/sched.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 1644242..0d08511 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1182,6 +1182,14 @@ static inline bool is_migration_disabled(struct task_struct *p)
 #endif
 }
 
+DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
+
+#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
+#define this_rq()		this_cpu_ptr(&runqueues)
+#define task_rq(p)		cpu_rq(task_cpu(p))
+#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
+#define raw_rq()		raw_cpu_ptr(&runqueues)
+
 struct sched_group;
 #ifdef CONFIG_SCHED_CORE
 static inline struct cpumask *sched_group_span(struct sched_group *sg);
@@ -1269,7 +1277,7 @@ static inline bool sched_group_cookie_match(struct rq *rq,
 		return true;
 
 	for_each_cpu_and(cpu, sched_group_span(group), p->cpus_ptr) {
-		if (sched_core_cookie_match(rq, p))
+		if (sched_core_cookie_match(cpu_rq(cpu), p))
 			return true;
 	}
 	return false;
@@ -1384,14 +1392,6 @@ static inline void update_idle_core(struct rq *rq)
 static inline void update_idle_core(struct rq *rq) { }
 #endif
 
-DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
-
-#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
-#define this_rq()		this_cpu_ptr(&runqueues)
-#define task_rq(p)		cpu_rq(task_cpu(p))
-#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
-#define raw_rq()		raw_cpu_ptr(&runqueues)
-
 #ifdef CONFIG_FAIR_GROUP_SCHED
 static inline struct task_struct *task_of(struct sched_entity *se)
 {

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

end of thread, other threads:[~2022-10-17 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-08  2:27 [PATCH -next] sched/core: Fix the bug that traversal in sched_group_cookie_match is wrong Lin Shengwang
2022-10-10  1:14 ` Aubrey Li
2022-10-10  7:37 ` Peter Zijlstra
2022-10-17 14:45 ` [tip: sched/urgent] sched/core: Fix comparison in sched_group_cookie_match() tip-bot2 for Lin Shengwang

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).