Sched_ext development
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Tejun Heo <tj@kernel.org>, 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: Re: [PATCH 1/4] sched: Let switching_to() decide whether to keep a retained proxy donor
Date: Sat, 28 Nov 2026 17:42:02 +0100	[thread overview]
Message-ID: <awsEWrroU0QGiyjD@gpd4> (raw)
In-Reply-To: <20261126160128.GL49833@noisy.programming.kicks-ass.net>

Hi Peter,

On Thu, Nov 26, 2026 at 05:01:28PM +0100, Peter Zijlstra wrote:
> On Thu, Nov 26, 2026 at 12:13:57PM +0100, Andrea Righi wrote:
> > @@ -11200,6 +11213,58 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned int
> >  	return ctx;
> >  }
> >  
> > +/*
> > + * Block a mutex-blocked task retained on the rq for proxy execution, because
> > + * the class it is switching to does not accept blocked tasks.
> > + *
> > + * sched_change_begin() already dequeued @p from its old class and put it if
> > + * it was the donor, so finish the job a sleeping dequeue would have done
> > + * without going through a class again.
> > + *
> > + * The caller holds p->pi_lock, so @p cannot wake and migrate once
> > + * __block_task() clears p->on_rq.
> > + */
> > +static void sched_change_block_task(struct rq *rq, struct sched_change_ctx *ctx)
> > +{
> > +	struct task_struct *p = ctx->p;
> > +	unsigned long state = READ_ONCE(p->__state);
> > +
> > +	lockdep_assert_held(&p->pi_lock);
> > +
> > +	if (WARN_ON_ONCE(state == TASK_RUNNING))
> > +		return;
> > +
> > +	/*
> > +	 * Hand the donor role back to the execution context before clearing
> > +	 * p->on_rq. This is proxy_reset_donor() without put_prev_task(), which
> > +	 * sched_change_begin() already did, and without zapping the balance
> > +	 * callbacks: nothing redoes them here, and they include the pull that
> > +	 * switched_from_rt() or switched_from_dl() may have queued.
> > +	 *
> > +	 * If @p is rq->curr, __schedule() retained it and dropped the rq lock
> > +	 * while picking. Block it like any prev that blocks in __schedule():
> > +	 * keep it set, and let the pending pick put it.
> > +	 */
> > +	if (ctx->running && rq->curr != p) {
> > +		struct task_struct *curr = rq->curr;
> > +
> > +		__put_prev_set_next_dl_server(rq, p, curr);
> > +		curr->sched_class->set_next_task(rq, curr, SNT_PICK);
> > +		proxy_set_curr_donor(rq);
> > +		ctx->running = false;
> > +	}
> > +
> > +	p->sched_contributes_to_load = task_state_contributes_to_load(state);
> > +
> > +	/* The DEQUEUE_SAVE in sched_change_begin() skipped these. */
> > +	sched_info_dequeue(rq, p);
> > +	psi_dequeue(p, DEQUEUE_SLEEP);
> 
> Should we assert DEQUEUE_SAVE was set? I mean, it should be, but afaict
> nothing screams if someone forgets? And with these changes on, it will
> go a bit funny.

Ah, good point. All the current callers that change class pass
DEQUEUE_SAVE, but nothing enforces it, and without it
sched_info_dequeue() and psi_dequeue() would run twice. I'll add a:

  WARN_ON_ONCE(!(ctx->flags & DEQUEUE_SAVE));

at the top of sched_change_block_task().

> 
> > +	__block_task(rq, p);
> > +
> > +	ctx->queued = false;
> > +}
> 
> Other than that, this looks good. Let me go read the next patches.

Thanks,
-Andrea

  reply	other threads:[~2026-11-28 16:42 UTC|newest]

Thread overview: 10+ 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-28 16:42     ` Andrea Righi [this message]
2026-11-26 11:13 ` [PATCH 2/4] sched_ext: Make SCX_OPS_ENQ_BLOCKED a hierarchy-wide setting Andrea Righi
2026-11-27 20:29   ` Tejun Heo
2026-11-28 16:39     ` Andrea Righi
2026-11-28 16:53       ` Andrea Righi
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=awsEWrroU0QGiyjD@gpd4 \
    --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