Re: [PATCH v5 2/4] sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop()

From: Peter Zijlstra
Date: Thu Jun 15 2023 - 08:40:30 EST


On Tue, Jun 13, 2023 at 04:20:10PM +0800, Hao Jia wrote:
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index a8be5415daba..1eca36299d8b 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2398,7 +2398,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;
> @@ -2456,10 +2455,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

So now you've got update_rq_clock() in both callers, why not remove it
from __balance_push_cpu_stop() ?

Afaict nothing actually needs it before __migrate_task().

---
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9435,8 +9435,6 @@ static int __balance_push_cpu_stop(void
raw_spin_lock_irq(&p->pi_lock);
rq_lock(rq, &rf);

- update_rq_clock(rq);
-
if (task_rq(p) == rq && task_on_rq_queued(p)) {
cpu = select_fallback_rq(rq->cpu, p);
rq = __migrate_task(rq, &rf, p, cpu);