All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	John Stultz <jstultz@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Christian Loehle <christian.loehle@arm.com>,
	David Dai <david.dai@linux.dev>, Koba Ko <kobak@nvidia.com>,
	Aiqun Yu <aiqun.yu@oss.qualcomm.com>,
	Shuah Khan <shuah@kernel.org>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 02/16] sched/core: Dequeue waking proxy donors before reset
Date: Tue, 22 Sep 2026 18:51:41 +0200	[thread overview]
Message-ID: <20260922165445.943315-3-arighi@nvidia.com> (raw)
In-Reply-To: <20260922165445.943315-1-arighi@nvidia.com>

proxy_needs_return() resets an active donor while holding blocked_lock.
proxy_reset_donor() invokes scheduling-class callbacks, adding an
unnecessary raw-spinlock nesting.

For an EXT donor, resetting rq->donor first calls put_prev_task_scx()
while SCX_TASK_QUEUED and is_blocked are still set. That path reenqueues
the retained donor through scx_do_enqueue_task(), only for the following
block_task() to dequeue it again.

Split block_task() so the waking donor is first dequeued from its
scheduling class while it is still rq->donor. This lets
dequeue_task_scx() end the donor's running session and clear
SCX_TASK_QUEUED before proxy_reset_donor() invokes put_prev_task_scx().
Keep the generic on_rq state set until donor references are replaced,
then complete the runqueue removal.

This follows the normal sleep ordering, avoids transiently re-enqueuing
the waking donor, and moves the scheduling-class callbacks outside
blocked_lock.

This is a preparatory change to support proxy execution with sched_ext.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/core.c | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3026d01fd7aef..83b220e3a232a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2253,7 +2253,8 @@ void deactivate_task(struct rq *rq, struct task_struct *p, int flags)
 	dequeue_task(rq, p, flags);
 }
 
-static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state)
+static bool dequeue_block_task(struct rq *rq, struct task_struct *p,
+			       unsigned long task_state)
 {
 	int flags = DEQUEUE_NOCLOCK;
 
@@ -2274,9 +2275,15 @@ static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_
 	 *
 	 * Where __schedule() and ttwu() have matching control dependencies.
 	 *
-	 * After this, schedule() must not care about p->state any more.
+	 * Once the caller invokes __block_task(), schedule() must not care about
+	 * p->state any more.
 	 */
-	if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags))
+	return dequeue_task(rq, p, DEQUEUE_SLEEP | flags);
+}
+
+static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state)
+{
+	if (dequeue_block_task(rq, p, task_state))
 		__block_task(rq, p);
 }
 
@@ -3775,6 +3782,8 @@ static inline void proxy_reset_donor(struct rq *rq)
  */
 static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p)
 {
+	bool dequeued;
+
 	/*
 	 * Typically per __set_task_cpu(), task_cpu(p) == p->wake_cpu.
 	 *
@@ -3797,12 +3806,23 @@ static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p)
 		/* If already current, don't need to return migrate */
 		if (task_current(rq, p))
 			return false;
-
-		/* If we're return migrating the rq->donor, switch it out for idle */
-		if (task_current_donor(rq, p))
-			proxy_reset_donor(rq);
 	}
-	block_task(rq, p, TASK_WAKING);
+
+	dequeued = dequeue_block_task(rq, p, TASK_WAKING);
+
+	/*
+	 * Dequeue @p from its scheduling class before resetting rq->donor.
+	 * In particular, sched_ext needs to end the donor's running session
+	 * and clear SCX_TASK_QUEUED before put_prev_task_scx() is called by
+	 * proxy_reset_donor(); otherwise it would reenqueue the blocked donor.
+	 *
+	 * Keep on_rq set until all donor references have been replaced.
+	 */
+	if (task_current_donor(rq, p))
+		proxy_reset_donor(rq);
+
+	if (dequeued)
+		__block_task(rq, p);
 	return true;
 }
 #else /* !CONFIG_SCHED_PROXY_EXEC */
-- 
2.55.0


  parent reply	other threads:[~2026-09-22 16:55 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 16:51 [PATCHSET v14 sched_ext/for-7.4] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-09-22 16:51 ` [PATCH 01/16] sched/core: Drop mutex locks before proxy rescheduling Andrea Righi
2026-09-22 16:51 ` Andrea Righi [this message]
2026-09-22 16:51 ` [PATCH 03/16] sched/core: Mark wakeups completed through ttwu_runnable() Andrea Righi
2026-09-22 16:51 ` [PATCH 04/16] sched: Add helper to block retained proxy donors Andrea Righi
2026-09-22 16:51 ` [PATCH 05/16] sched: Add sched_ext hooks for proxy execution Andrea Righi
2026-09-24  7:51   ` Peter Zijlstra
2026-09-25  8:23     ` Andrea Righi
2026-09-22 16:51 ` [PATCH 06/16] sched_ext: Block proxy donors before taking control Andrea Righi
2026-09-22 16:51 ` [PATCH 07/16] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-09-22 16:51 ` [PATCH 08/16] sched_ext: Move reject DSQ draining into core Andrea Righi
2026-09-22 16:51 ` [PATCH 09/16] sched_ext: Generalize the reject DSQ reenqueue path Andrea Righi
2026-09-22 16:51 ` [PATCH 10/16] sched_ext: Handle proxy-exec races in remote DSQ transfers Andrea Righi
2026-09-22 16:51 ` [PATCH 11/16] sched_ext: Split curr|donor references properly Andrea Righi
2026-09-22 16:51 ` [PATCH 12/16] sched_ext: Track proxy execution for NOHZ_FULL Andrea Righi
2026-09-22 16:51 ` [PATCH 13/16] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-09-22 16:51 ` [PATCH 14/16] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-09-22 16:51 ` [PATCH 15/16] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-09-22 16:51 ` [PATCH 16/16] sched: Allow enabling proxy exec with sched_ext Andrea Righi
2026-09-24  7:52 ` [PATCHSET v14 sched_ext/for-7.4] sched: Make proxy execution compatible " Peter Zijlstra
2026-09-24  7:59   ` Peter Zijlstra
2026-09-24  8:10     ` K Prateek Nayak
2026-09-24  9:09       ` Peter Zijlstra
2026-09-25  7:46   ` Andrea Righi
2026-09-25  7:56     ` Peter Zijlstra
2026-09-26 19:17       ` Tejun Heo
2026-09-28 19:53 ` Tejun Heo
2026-09-28 20:47   ` Andrea Righi

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=20260922165445.943315-3-arighi@nvidia.com \
    --to=arighi@nvidia.com \
    --cc=aiqun.yu@oss.qualcomm.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=christian.loehle@arm.com \
    --cc=david.dai@linux.dev \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kobak@nvidia.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --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.