All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	linux-kernel@vger.kernel.org, pierre.gondois@arm.com,
	kprateek.nayak@amd.com, qyousef@layalina.io,
	hongyan.xia2@arm.com, christian.loehle@arm.com,
	luis.machado@arm.com
Subject: Re: [PATCH 4/6 v8] sched/fair: Add push task mechanism for fair
Date: Fri, 5 Dec 2025 14:26:53 +0100	[thread overview]
Message-ID: <aTLdncXYqNyF9Bqq@vingu-cube> (raw)
In-Reply-To: <20251205085912.GQ2528459@noisy.programming.kicks-ass.net>

Le vendredi 05 déc. 2025 à 09:59:12 (+0100), Peter Zijlstra a écrit :
> On Thu, Dec 04, 2025 at 03:34:15PM +0100, Vincent Guittot wrote:
> > On Thu, 4 Dec 2025 at 12:29, Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Tue, Dec 02, 2025 at 07:12:40PM +0100, Vincent Guittot wrote:
> > > > +/*
> > > > + * See if the non running fair tasks on this rq can be sent on other CPUs
> > > > + * that fits better with their profile.
> > > > + */
> > > > +static bool push_fair_task(struct rq *rq)
> > > > +{
> > > > +     struct task_struct *next_task;
> > > > +     int prev_cpu, new_cpu;
> > > > +     struct rq *new_rq;
> > > > +
> > > > +     next_task = pick_next_pushable_fair_task(rq);
> > > > +     if (!next_task)
> > > > +             return false;
> > > > +
> > > > +     if (is_migration_disabled(next_task))
> > > > +             return true;
> > > > +
> > > > +     /* We might release rq lock */
> > > > +     get_task_struct(next_task);
> > > > +
> > > > +     prev_cpu = rq->cpu;
> > > > +
> > > > +     new_cpu = select_task_rq_fair(next_task, prev_cpu, 0);
> > > > +
> > > > +     if (new_cpu == prev_cpu)
> > > > +             goto out;
> > > > +
> > > > +     new_rq = cpu_rq(new_cpu);
> > > > +
> > > > +     if (double_lock_balance(rq, new_rq)) {
> > > > +             /* The task has already migrated in between */
> > > > +             if (task_cpu(next_task) != rq->cpu) {
> > > > +                     double_unlock_balance(rq, new_rq);
> > > > +                     goto out;
> > > > +             }
> > > > +
> > > > +             deactivate_task(rq, next_task, 0);
> > > > +             set_task_cpu(next_task, new_cpu);
> > > > +             activate_task(new_rq, next_task, 0);
> > > > +
> > > > +             resched_curr(new_rq);
> > > > +
> > > > +             double_unlock_balance(rq, new_rq);
> > > > +     }
> > >
> > > Why not use move_queued_task() ?
> > 
> > double_lock_balance() can fail and prevent being blocked waiting for
> > new rq whereas move_queued_task() will wait, won't it ?
> > 
> > Do you think move_queued_task() would be better ?
> 
> No, double_lock_balance() never fails, the return value indicates if the
> currently held rq-lock, (the first argument) was unlocked while
> attaining both -- this is required when the first rq is a higher address
> than the second.
> 
> double_lock_balance() also puts the wait-time and hold time of the
> second inside the hold time of the first, which gets you a quadric term
> in the rq hold times IIRC. Something that's best avoided.

yeah, I misread the return and my current code need to be fixed like:

---
 kernel/sched/fair.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fbbe325dc633..35c7c968ddd2 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8629,19 +8629,18 @@ static bool push_fair_task(struct rq *rq)
 
 	if (double_lock_balance(rq, new_rq)) {
 		/* The task has already migrated in between */
-		if (task_cpu(next_task) != rq->cpu) {
-			double_unlock_balance(rq, new_rq);
-			goto out;
-		}
+		if (task_cpu(next_task) != rq->cpu)
+			goto unlock;
+	}
 
-		deactivate_task(rq, next_task, 0);
-		set_task_cpu(next_task, new_cpu);
-		activate_task(new_rq, next_task, 0);
+	deactivate_task(rq, next_task, DEQUEUE_NOCLOCK);
+	set_task_cpu(next_task, new_cpu);
+	activate_task(new_rq, next_task, 0);
 
-		resched_curr(new_rq);
+	wakeup_preempt(new_rq, next_task, 0);
 
-		double_unlock_balance(rq, new_rq);
-	}
+unlock:
+	double_unlock_balance(rq, new_rq);
 
 out:
 	put_task_struct(next_task);
-- 
2.43.0



> 
> move_queued_task() OTOH takes the task off the runqueue you already hold
> locked, drops this lock, acquires the second, puts the task there, and
> returns with the dst rq locked.

I supposed it's doable even if we don't have rq_flags
But we need the re-lock the current rq and release the new one to let the balance_callback
loop in the same state

> 
> > In case of migrate_disable, push_fair_task() returns true and we
> > continue with the next task (It should not have much anyway). If the
> > task is migrate_disabled when we try to push it, we remove it from the
> > list anyway. At now, we try to not have more than 1 task in the list
> > to cap the overhead on sched_switch
> 
> Right, clearly I needed more wake-up juice, I thought it returned false
> and would stick around.

  parent reply	other threads:[~2025-12-05 13:26 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 18:12 [PATCH 0/6 v8] sched/fair: Add push task mechanism and handle more EAS cases Vincent Guittot
2025-12-02 18:12 ` [PATCH 1/6 v8] sched/fair: Filter false overloaded_group case for EAS Vincent Guittot
2025-12-02 18:12 ` [PATCH 2/6 v8] sched/fair: Update overutilized detection Vincent Guittot
2026-02-06 17:42   ` Qais Yousef
2025-12-02 18:12 ` [PATCH 3/6 v8] sched/fair: Prepare select_task_rq_fair() to be called for new cases Vincent Guittot
2025-12-07 13:23   ` Shrikanth Hegde
2026-02-09 13:21     ` Vincent Guittot
2026-02-06 18:03   ` Qais Yousef
2026-02-09 13:21     ` Vincent Guittot
2025-12-02 18:12 ` [PATCH 4/6 v8] sched/fair: Add push task mechanism for fair Vincent Guittot
2025-12-04 10:46   ` Peter Zijlstra
2025-12-04 14:32     ` Vincent Guittot
2025-12-04 11:29   ` Peter Zijlstra
2025-12-04 14:34     ` Vincent Guittot
2025-12-05  8:59       ` Peter Zijlstra
2025-12-05 12:49         ` K Prateek Nayak
2025-12-05 12:56           ` Peter Zijlstra
2025-12-05 13:05             ` K Prateek Nayak
2025-12-05 13:36           ` Vincent Guittot
2025-12-06  3:08             ` K Prateek Nayak
2025-12-05 13:26         ` Vincent Guittot [this message]
2025-12-07 12:13   ` Shrikanth Hegde
2026-02-09 13:17     ` Vincent Guittot
2025-12-10 14:01   ` Dietmar Eggemann
2026-02-09 13:17     ` Vincent Guittot
2026-02-06 18:21   ` Qais Yousef
2026-02-09 13:18     ` Vincent Guittot
2025-12-02 18:12 ` [RFC PATCH 5/6 v8] sched/fair: Enable idle core tracking for !SMT Vincent Guittot
2025-12-05 15:52   ` Christian Loehle
2025-12-06  2:11     ` Chen, Yu C
2025-12-06 10:18       ` Vincent Guittot
2025-12-06 10:09     ` Vincent Guittot
2025-12-08 18:43   ` Christian Loehle
2025-12-02 18:12 ` [RFC PATCH 6/6 v8] sched/fair: Add EAS and idle cpu push trigger Vincent Guittot
2026-02-06 18:30   ` Qais Yousef
2026-02-09 13:20     ` Vincent Guittot
2026-02-11  0:59       ` Qais Yousef
2025-12-03 14:06 ` [PATCH 0/6 v8] sched/fair: Add push task mechanism and handle more EAS cases Christian Loehle
2025-12-10 13:30 ` Dietmar Eggemann
2026-02-06 18:32 ` Qais Yousef
2026-02-09 13:20   ` Vincent Guittot
2026-02-26 17:34 ` Pierre Gondois
2026-03-10  4:16   ` Qais Yousef
2026-03-10 10:27     ` Pierre Gondois
2026-03-10 15:11       ` Qais Yousef
2026-03-10 16:59         ` Pierre Gondois
2026-03-12  8:19           ` Vincent Guittot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aTLdncXYqNyF9Bqq@vingu-cube \
    --to=vincent.guittot@linaro.org \
    --cc=bsegall@google.com \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hongyan.xia2@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luis.machado@arm.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pierre.gondois@arm.com \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.