[tip:,sched/core] sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop()

Message ID 168717269089.404.10438864985621759181.tip-bot2@tip-bot2
State New
Headers
Series [tip:,sched/core] sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop() |

Commit Message

tip-bot2 for Thomas Gleixner June 19, 2023, 11:04 a.m. UTC
  The following commit has been merged into the sched/core branch of tip:

Commit-ID:     96500560f0c73c71bca1b27536c6254fa0e8ce37
Gitweb:        https://git.kernel.org/tip/96500560f0c73c71bca1b27536c6254fa0e8ce37
Author:        Hao Jia <jiahao.os@bytedance.com>
AuthorDate:    Tue, 13 Jun 2023 16:20:10 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 16 Jun 2023 22:08:12 +02:00

sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop()

There is a double update_rq_clock() invocation:

  __balance_push_cpu_stop()
    update_rq_clock()
    __migrate_task()
      update_rq_clock()

Sadly select_fallback_rq() also needs update_rq_clock() for
__do_set_cpus_allowed(), it is not possible to remove the update from
__balance_push_cpu_stop(). So remove it from __migrate_task() and
ensure all callers of this function call update_rq_clock() prior to
calling it.

Signed-off-by: Hao Jia <jiahao.os@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lkml.kernel.org/r/20230613082012.49615-3-jiahao.os@bytedance.com
---
 kernel/sched/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Hao Jia June 19, 2023, 12:18 p.m. UTC | #1
On 2023/6/19 tip-bot2 for Hao Jia wrote:
> The following commit has been merged into the sched/core branch of tip:
> 
> Commit-ID:     96500560f0c73c71bca1b27536c6254fa0e8ce37
> Gitweb:        https://git.kernel.org/tip/96500560f0c73c71bca1b27536c6254fa0e8ce37
> Author:        Hao Jia <jiahao.os@bytedance.com>
> AuthorDate:    Tue, 13 Jun 2023 16:20:10 +08:00
> Committer:     Peter Zijlstra <peterz@infradead.org>
> CommitterDate: Fri, 16 Jun 2023 22:08:12 +02:00
> 
> sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop()
> 
> There is a double update_rq_clock() invocation:
> 
>    __balance_push_cpu_stop()
>      update_rq_clock()
>      __migrate_task()
>        update_rq_clock()
> 
> Sadly select_fallback_rq() also needs update_rq_clock() for
> __do_set_cpus_allowed(), it is not possible to remove the update from
> __balance_push_cpu_stop(). So remove it from __migrate_task() and
> ensure all callers of this function call update_rq_clock() prior to
> calling it.
> 
Hi Peter,

Thank you very much for refactoring these commit messages to make it 
clearer and more concise.

Thanks,
Hao

> Signed-off-by: Hao Jia <jiahao.os@bytedance.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Link: https://lkml.kernel.org/r/20230613082012.49615-3-jiahao.os@bytedance.com
> ---
>   kernel/sched/core.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 442efe5..c7db597 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2546,7 +2546,6 @@ static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
>   	if (!is_cpu_allowed(p, dest_cpu))
>   		return rq;
>   
> -	update_rq_clock(rq);
>   	rq = move_queued_task(rq, rf, p, dest_cpu);
>   
>   	return rq;
> @@ -2604,10 +2603,12 @@ static int migration_cpu_stop(void *data)
>   				goto out;
>   		}
>   
> -		if (task_on_rq_queued(p))
> +		if (task_on_rq_queued(p)) {
> +			update_rq_clock(rq);
>   			rq = __migrate_task(rq, &rf, p, arg->dest_cpu);
> -		else
> +		} else {
>   			p->wake_cpu = arg->dest_cpu;
> +		}
>   
>   		/*
>   		 * XXX __migrate_task() can fail, at which point we might end
  

Patch

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 442efe5..c7db597 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2546,7 +2546,6 @@  static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
 	if (!is_cpu_allowed(p, dest_cpu))
 		return rq;
 
-	update_rq_clock(rq);
 	rq = move_queued_task(rq, rf, p, dest_cpu);
 
 	return rq;
@@ -2604,10 +2603,12 @@  static int migration_cpu_stop(void *data)
 				goto out;
 		}
 
-		if (task_on_rq_queued(p))
+		if (task_on_rq_queued(p)) {
+			update_rq_clock(rq);
 			rq = __migrate_task(rq, &rf, p, arg->dest_cpu);
-		else
+		} else {
 			p->wake_cpu = arg->dest_cpu;
+		}
 
 		/*
 		 * XXX __migrate_task() can fail, at which point we might end