Re: [PATCHSET v14 sched_ext/for-7.4] sched: Make proxy execution compatible with sched_ext

From: Peter Zijlstra

Date: Thu Sep 24 2026 - 04:05:05 EST


On Thu, Sep 24, 2026 at 09:52:38AM +0200, Peter Zijlstra wrote:
> On Tue, Sep 22, 2026 at 06:51:39PM +0200, Andrea Righi wrote:
>
> > Andrea Righi (16):
> > sched/core: Drop mutex locks before proxy rescheduling
> > sched/core: Dequeue waking proxy donors before reset
> > sched/core: Mark wakeups completed through ttwu_runnable()
> > sched: Add helper to block retained proxy donors
> > sched: Add sched_ext hooks for proxy execution
>
> Right, so these add:
>
> WF_TTWU_RQ:
>
> Used like ENQUEUE_DELAYED; could be fixed by generalizing that to cover all
> of p->is_blocked.
>
> scx_allow_proxy_exec():
>
> Hook to kill proxy exec for scx
>
> scx_proxy_reenqueue_retry():
>
> Like put_prev_task(), but for current. Ensures current gets put back on a DSQ
> once its done running.
>
> scx_proxy_donor_start():
>
> Delayed set_next_task(), confirms donor will be used.
>
> sched_proxy_block_task():
>
> Almost like switching_to_scx(), except it needs to change ctx->queued in case
> of p->is_blocked. Hence a new callback ran before sched_change_begin().

And I wonder, would something like so work?

---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index adcc9264c0c6..3e7691d24930 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11215,8 +11215,13 @@ void sched_change_end(struct sched_change_ctx *ctx)
*/
WARN_ON_ONCE(p->sched_class != ctx->class && !(ctx->flags & ENQUEUE_CLASS));

- if ((ctx->flags & ENQUEUE_CLASS) && p->sched_class->switching_to)
- p->sched_class->switching_to(rq, p);
+ if ((ctx->flags & ENQUEUE_CLASS) && p->sched_class->switching_to) {
+ bool block = p->sched_class->switching_to(rq, p);
+ if (block && p->is_blocked) {
+ block_task(rq, p, READ_ONCE(p->__state));
+ ctx->queued = false;
+ }
+ }

if (ctx->queued)
enqueue_task(rq, p, ctx->flags);
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 9c1f10cf3c24..e706fb899834 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -4288,12 +4288,12 @@ static void prio_changed_scx(struct rq *rq, struct task_struct *p, u64 oldprio)
{
}

-static void switching_to_scx(struct rq *rq, struct task_struct *p)
+static bool switching_to_scx(struct rq *rq, struct task_struct *p)
{
struct scx_sched *sch = scx_task_sched(p);

if (task_dead_and_done(p))
- return;
+ return false;

scx_enable_task(sch, p);

@@ -4303,6 +4303,8 @@ static void switching_to_scx(struct rq *rq, struct task_struct *p)
*/
if (SCX_HAS_OP(sch, set_cpumask))
scx_call_op_set_cpumask(sch, rq, p, (struct cpumask *)p->cpus_ptr);
+
+ return !scx_allow_proxy_exec(p);
}

static void switched_from_scx(struct rq *rq, struct task_struct *p)
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 76f3c84ca684..23217b91db03 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -543,7 +543,7 @@ static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
update_curr_idle(rq);
}

-static void switching_to_idle(struct rq *rq, struct task_struct *p)
+static bool switching_to_idle(struct rq *rq, struct task_struct *p)
{
BUG();
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e06b34984e48..ba4c55d0a601 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2759,7 +2759,7 @@ struct sched_class {
*/
void (*switching_from)(struct rq *this_rq, struct task_struct *task);
void (*switched_from) (struct rq *this_rq, struct task_struct *task);
- void (*switching_to) (struct rq *this_rq, struct task_struct *task);
+ bool (*switching_to) (struct rq *this_rq, struct task_struct *task);
void (*switched_to) (struct rq *this_rq, struct task_struct *task);
u64 (*get_prio) (struct rq *this_rq, struct task_struct *task);
void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c
index 1e0109ec36b3..b7541bb7b593 100644
--- a/kernel/sched/stop_task.c
+++ b/kernel/sched/stop_task.c
@@ -78,7 +78,7 @@ static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued)
{
}

-static void switching_to_stop(struct rq *rq, struct task_struct *p)
+static bool switching_to_stop(struct rq *rq, struct task_struct *p)
{
BUG(); /* its impossible to change to this class */
}