mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Peter Zijlstra <peterz@infradead.org>, Tejun Heo <tj@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	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>,
	John Stultz <jstultz@google.com>,
	David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>, Tao Cui <cuitao@kylinos.cn>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] sched_ext: Make SCX_OPS_ENQ_BLOCKED a hierarchy-wide setting
Date: Thu, 26 Nov 2026 12:13:58 +0100	[thread overview]
Message-ID: <20261126111649.208476-3-arighi@nvidia.com> (raw)
In-Reply-To: <20261126111649.208476-1-arighi@nvidia.com>

Moving a task between BPF schedulers (sub-sched enable, rehome and punt)
doesn't change its sched_class, so switching_to() doesn't run and can't
keep a scheduler that doesn't admit blocked donors from inheriting one.
scx_prepare_task_sched_change() works around this by blocking a retained
donor before every ownership change, even when both schedulers admit
blocked donors.

Mixing proxy donor admission within a hierarchy has no real use, so
don't allow it: a sub-scheduler must match the root scheduler's
SCX_OPS_ENQ_BLOCKED setting or it fails to load. Ownership changes then
can't affect donor admission: if the hierarchy doesn't admit blocked
donors, no EXT task is a retained donor; if it does, the incoming
scheduler accepts the donor just like on class entry.

Drop scx_prepare_task_sched_change() and the DEQUEUE_NOCLOCK it required
from the sub-sched paths. With that, sched_ext never blocks a donor that
it still owns, so scx_block_proxy_donor() and the SCX_RQ_PROXY_BLOCKING
special case in put_prev_task_scx() go away too.

Update the scx_qmap -X help text and drop SCX_RQ_PROXY_BLOCKING from the
generated enum headers.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext/ext.c                        | 44 ++++++-------------
 kernel/sched/ext/internal.h                   |  4 +-
 kernel/sched/ext/sub.c                        | 12 ++---
 kernel/sched/sched.h                          |  1 -
 .../sched_ext/include/scx/enum_defs.autogen.h |  1 -
 .../sched_ext/include/scx/enums_abi.autogen.h |  1 -
 tools/sched_ext/scx_qmap.c                    |  2 +-
 7 files changed, 20 insertions(+), 45 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 99038c2f6f4b0..ecec827ad986b 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -24,17 +24,6 @@
 
 DEFINE_RAW_SPINLOCK(scx_sched_lock);
 
-/*
- * Block a retained proxy donor, telling put_prev_task_scx() that the donor is
- * about to be dequeued and must not be reenqueued.
- */
-static void scx_block_proxy_donor(struct rq *rq, struct task_struct *p)
-{
-	rq->scx.flags |= SCX_RQ_PROXY_BLOCKING;
-	sched_proxy_block_task(rq, p);
-	rq->scx.flags &= ~SCX_RQ_PROXY_BLOCKING;
-}
-
 bool __scx_allow_proxy_exec(const struct task_struct *p)
 {
 	struct scx_sched *sch;
@@ -46,21 +35,6 @@ bool __scx_allow_proxy_exec(const struct task_struct *p)
 	return !sch || (sch->ops.flags & SCX_OPS_ENQ_BLOCKED);
 }
 
-/*
- * End retained proxy execution before changing @p's BPF scheduler ownership.
- * Called with @p's pi and rq locks held immediately before
- * sched_change_begin(). The caller must pass DEQUEUE_NOCLOCK so the rq clock
- * is updated only once.
- */
-void scx_prepare_task_sched_change(struct task_struct *p)
-{
-	lockdep_assert_held(&p->pi_lock);
-	lockdep_assert_rq_held(task_rq(p));
-
-	update_rq_clock(task_rq(p));
-	scx_block_proxy_donor(task_rq(p), p);
-}
-
 /*
  * NOTE: sched_ext is in the process of growing multiple scheduler support and
  * scx_root usage is in a transitional state. Naked dereferences are safe if the
@@ -3596,7 +3570,6 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 	struct scx_sched *sch = scx_task_sched(p);
 	bool proxy_put = p->is_blocked && next == rq->idle &&
 			 (rq->scx.flags & SCX_RQ_PROXY_PENDING);
-	bool proxy_block = rq->scx.flags & SCX_RQ_PROXY_BLOCKING;
 	bool rescue_keep = false;
 
 	rq->scx.flags &= ~SCX_RQ_PROXY_PENDING;
@@ -3624,15 +3597,12 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 	if (next != p && (p->scx.flags & SCX_TASK_QUEUED) &&
 	    (p->scx.flags & SCX_TASK_RUN_TRACKED)) {
 		if (SCX_HAS_OP(sch, stopping))
-			SCX_CALL_OP_TASK(sch, stopping, rq, p, !proxy_block);
+			SCX_CALL_OP_TASK(sch, stopping, rq, p, true);
 
 		p->scx.flags &= ~SCX_TASK_RUN_TRACKED;
 	}
 
 	if (p->scx.flags & SCX_TASK_QUEUED) {
-		if (proxy_block)
-			goto switch_class;
-
 		set_task_runnable(rq, p);
 
 		/*
@@ -8246,6 +8216,18 @@ int scx_validate_ops(struct scx_sched *sch, const struct sched_ext_ops *ops)
 		return -EINVAL;
 	}
 
+	/*
+	 * Proxy donor admission is a property of the whole hierarchy, so that
+	 * moving a task between schedulers never changes whether a retained
+	 * donor is admitted. Sub-scheds must follow the root scheduler.
+	 */
+	if (scx_parent(sch) &&
+	    (ops->flags & SCX_OPS_ENQ_BLOCKED) !=
+	    (sch->ancestors[0]->ops.flags & SCX_OPS_ENQ_BLOCKED)) {
+		scx_error(sch, "SCX_OPS_ENQ_BLOCKED must match the root scheduler");
+		return -EINVAL;
+	}
+
 	/*
 	 * SCX_OPS_TID_TO_TASK is enabled by the root scheduler. A sub-sched
 	 * may set it to declare a dependency; reject if the root hasn't
diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
index c20326d6eed84..726cf4cee2c2a 100644
--- a/kernel/sched/ext/internal.h
+++ b/kernel/sched/ext/internal.h
@@ -240,6 +240,9 @@ enum scx_ops_flags {
 	 *
 	 * For blocked donors, this flag takes precedence over
 	 * %SCX_OPS_ENQ_EXITING and %SCX_OPS_ENQ_MIGRATION_DISABLED.
+	 *
+	 * The root scheduler decides for the whole hierarchy. A sub-scheduler
+	 * must match the root's setting or it fails to load.
 	 */
 	SCX_OPS_ENQ_BLOCKED		= 1LLU << 10,
 
@@ -2296,7 +2299,6 @@ struct task_struct *scx_task_iter_next_locked(struct scx_task_iter *iter);
 bool scx_set_task_slice(struct task_struct *p, u64 slice);
 void scx_task_slice_ended(struct rq *rq, struct task_struct *p);
 void scx_task_unlink_from_dsq(struct task_struct *p, struct scx_dispatch_q *dsq);
-void scx_prepare_task_sched_change(struct task_struct *p);
 void scx_dispatch_dequeue(struct rq *rq, struct task_struct *p);
 void scx_do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags,
 			 int sticky_cpu);
diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index 9732809c09f89..e5b5098fa1e3d 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -1623,9 +1623,7 @@ static void scx_rehome_task(struct scx_sched *to, struct task_struct *p)
 	lockdep_assert_held(&p->pi_lock);
 	lockdep_assert_rq_held(task_rq(p));
 
-	scx_prepare_task_sched_change(p);
-	scoped_guard (sched_change, p,
-		      DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK) {
+	scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE) {
 		scx_disable_and_exit_task(scx_task_sched(p), p);
 		scx_set_task_state(p, SCX_TASK_INIT_BEGIN);
 		scx_set_task_state(p, SCX_TASK_INIT);
@@ -1655,9 +1653,7 @@ static void scx_punt_task(struct scx_sched *to, struct task_struct *p)
 	lockdep_assert_rq_held(task_rq(p));
 	WARN_ON_ONCE(!READ_ONCE(to->bypass_depth));
 
-	scx_prepare_task_sched_change(p);
-	scoped_guard (sched_change, p,
-		      DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK) {
+	scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE) {
 		scx_disable_and_exit_task(scx_task_sched(p), p);
 		scx_set_task_sched(p, to);
 	}
@@ -2434,9 +2430,7 @@ void scx_sub_enable_workfn(struct kthread_work *work)
 		if (!(p->scx.flags & SCX_TASK_SUB_INIT))
 			continue;
 
-		scx_prepare_task_sched_change(p);
-		scoped_guard (sched_change, p,
-			      DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK) {
+		scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE) {
 			/*
 			 * $p must be either READY or ENABLED. If ENABLED,
 			 * __scx_disabled_and_exit_task() first disables and
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 11d38b2e18f05..b34709723d861 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -803,7 +803,6 @@ enum scx_rq_flags {
 	SCX_RQ_PROXY_RETRY	= 1 << 9, /* proxy-rejected tasks need retry */
 	SCX_RQ_PROXY_TICK	= 1 << 10, /* proxy execution requires the tick */
 	SCX_RQ_PROXY_PENDING	= 1 << 11, /* blocked donor awaits proxy resolution */
-	SCX_RQ_PROXY_BLOCKING	= 1 << 12, /* donor is being removed for sched change */
 
 	SCX_RQ_IN_WAKEUP	= 1 << 16,
 	SCX_RQ_IN_DISPATCH	= 1 << 17,
diff --git a/tools/sched_ext/include/scx/enum_defs.autogen.h b/tools/sched_ext/include/scx/enum_defs.autogen.h
index 27b45040c88ad..67aff283798af 100644
--- a/tools/sched_ext/include/scx/enum_defs.autogen.h
+++ b/tools/sched_ext/include/scx/enum_defs.autogen.h
@@ -208,7 +208,6 @@
 #define HAVE_SCX_RQ_PROXY_RETRY
 #define HAVE_SCX_RQ_PROXY_TICK
 #define HAVE_SCX_RQ_PROXY_PENDING
-#define HAVE_SCX_RQ_PROXY_BLOCKING
 #define HAVE_SCX_RQ_IN_WAKEUP
 #define HAVE_SCX_RQ_IN_DISPATCH
 #define HAVE_SCX_SCHED_PCPU_BYPASSING
diff --git a/tools/sched_ext/include/scx/enums_abi.autogen.h b/tools/sched_ext/include/scx/enums_abi.autogen.h
index 5cf54dcf5ffe1..18d69aa45538a 100644
--- a/tools/sched_ext/include/scx/enums_abi.autogen.h
+++ b/tools/sched_ext/include/scx/enums_abi.autogen.h
@@ -220,7 +220,6 @@ static const struct __scx_enum_abi_val __scx_enum_abi_vals[]
 	{ "scx_rq_flags", "SCX_RQ_PROXY_RETRY", 0x200LLU },
 	{ "scx_rq_flags", "SCX_RQ_PROXY_TICK", 0x400LLU },
 	{ "scx_rq_flags", "SCX_RQ_PROXY_PENDING", 0x800LLU },
-	{ "scx_rq_flags", "SCX_RQ_PROXY_BLOCKING", 0x1000LLU },
 	{ "scx_rq_flags", "SCX_RQ_IN_WAKEUP", 0x10000LLU },
 	{ "scx_rq_flags", "SCX_RQ_IN_DISPATCH", 0x20000LLU },
 	{ "scx_sched_pcpu_flags", "SCX_SCHED_PCPU_BYPASSING", 0x1LLU },
diff --git a/tools/sched_ext/scx_qmap.c b/tools/sched_ext/scx_qmap.c
index 414afb817e0a6..48cedf635d77f 100644
--- a/tools/sched_ext/scx_qmap.c
+++ b/tools/sched_ext/scx_qmap.c
@@ -65,7 +65,7 @@ const char help_fmt[] =
 "  -S            Suppress qmap-specific debug dump\n"
 "  -p            Switch only tasks on SCHED_EXT policy instead of all\n"
 "  -I            Turn on SCX_OPS_ALWAYS_ENQ_IMMED\n"
-"  -X            Turn on SCX_OPS_ENQ_BLOCKED\n"
+"  -X            Turn on SCX_OPS_ENQ_BLOCKED, sub-schedulers must match the root\n"
 "  -F COUNT      IMMED stress: force every COUNT'th enqueue to a busy local DSQ (use with -I)\n"
 "  -C MODE       cid-override test (shuffle|bad-dup|bad-range|bad-mono)\n"
 "  -i SEC        Stats interval, seconds (default 5)\n"
-- 
2.56.1


  parent reply	other threads:[~2026-11-26 11:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 11:13 [PATCHSET sched_ext/for-7.5] sched/proxy: Handle retained donors on scheduling class transitions Andrea Righi
2026-11-26 11:13 ` [PATCH 1/4] sched: Let switching_to() decide whether to keep a retained proxy donor Andrea Righi
2026-11-26 16:01   ` Peter Zijlstra
2026-11-26 11:13 ` Andrea Righi [this message]
2026-11-26 11:13 ` [PATCH 3/4] sched: Remove sched_proxy_block_task() Andrea Righi
2026-11-26 11:14 ` [PATCH 4/4] selftests/sched_ext: Check that blocked donors are never enqueued unadmitted 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=20261126111649.208476-3-arighi@nvidia.com \
    --to=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=cuitao@kylinos.cn \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®