mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zicheng Qu <quzicheng315@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: arighi@nvidia.com, brho@google.com, bsegall@google.com,
	changwoo@igalia.com, dietmar.eggemann@arm.com, haoluo@google.com,
	joshdon@google.com, juri.lelli@redhat.co, kprateek.nayak@amd.com,
	linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com,
	quzicheng@huawei.com, rostedt@goodmis.org,
	sched-ext@lists.linux.dev, tanghui20@huawei.com, tj@kernel.org,
	vincent.guittot@linaro.org, void@manifault.com,
	vschneid@redhat.com, zhangqiao22@huawei.com,
	quzicheng315@gmail.com
Subject: Re: [PATCH v2] sched_ext: Rebuild fair weight on ext to fair switches
Date: Thu, 28 May 2026 10:53:54 +0800	[thread overview]
Message-ID: <3c258a36-2b28-4221-b2b6-776a0b1693ab@gmail.com> (raw)
In-Reply-To: <20260527112624.GT3126523@noisy.programming.kicks-ass.net>

On Wed, May 27, 2026 at 07:26PM +0800, Peter Zijlstra wrote:

> This is truly horrible. We have 4 class methods involved with switching
> classes and you stick in a random call in a place that is called when no
> class is changed.
>
> Would not something like this work?
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 62a2dcb0d03e..a2eb43bd73b9 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -14957,6 +14957,11 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p)
>   	detach_task_cfs_rq(p);
>   }
>   
> +static void switching_to_fair(struct rq *rq, struct task_struct *p)
> +{
> +	set_load_weight(p, false);
> +}
> +
>   static void switched_to_fair(struct rq *rq, struct task_struct *p)
>   {
>   	WARN_ON_ONCE(p->se.sched_delayed);
> @@ -15351,6 +15356,7 @@ DEFINE_SCHED_CLASS(fair) = {
>   	.prio_changed		= prio_changed_fair,
>   	.switching_from		= switching_from_fair,
>   	.switched_from		= switched_from_fair,
> +	.switching_to		= switching_to_fair,
>   	.switched_to		= switched_to_fair,
>   
>   	.get_rr_interval	= get_rr_interval_fair,
Yes, from the class switch point of view, `switching_to_fair()` is a better
fit.

Before v2, I was weighing three possible places for the fix:

1. Updating `p->se.load` from `reweight_task_scx()`. This would keep the 
fair
weight in sync while the task is on sched_ext, so switching back to fair 
would
not need any extra fixup. However, it would also make sched_ext maintain 
fair
class state even when fair is not using it, which does not seem like the 
right
ownership model.

2. Rebuilding `p->se.load` from fair's `switching_to` hook. This is the most
natural place semantically, since the task is entering fair and fair 
prepares
its own state before enqueue. My only concern was that, for non-ext -> fair
paths, `__setscheduler_params()` may have already updated `p->se.load` 
through
`set_load_weight(p, true)`, so calling `set_load_weight(p, false)`
unconditionally here can be redundant logically. Functionally, though, it is
harmless.

3. Rebuilding in `sched_change_end()` based on the old/new classes. That was
the v2 choice because both classes are available there, the task has not 
been
enqueued yet, and it covers both `scx_root_disable()` and the partial-mode
`sched_setscheduler()` path. In hindsight, though, this makes the generic
sched_change path handle a scx & fair-specific fixup. That is more awkward
than letting fair prepare its own state in `switching_to_fair()`.

I'll respin v3 as you suggested.


Thanks,

Zicheng


  reply	other threads:[~2026-05-28  2:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 13:52 [PATCH] sched_ext: Rebuild fair weight when disabling BPF scheduler Zicheng Qu
2026-05-26 17:20 ` Andrea Righi
2026-05-27  9:40   ` [PATCH v2] sched_ext: Rebuild fair weight on ext to fair switches quzicheng315
2026-05-27 11:26     ` Peter Zijlstra
2026-05-28  2:53       ` Zicheng Qu [this message]
2026-05-28  9:25         ` Peter Zijlstra
2026-05-28 13:12           ` [PATCH v3] sched/fair: Rebuild load weight when switching to fair quzicheng315
2026-05-28 14:27             ` Tejun Heo

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=3c258a36-2b28-4221-b2b6-776a0b1693ab@gmail.com \
    --to=quzicheng315@gmail.com \
    --cc=arighi@nvidia.com \
    --cc=brho@google.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=haoluo@google.com \
    --cc=joshdon@google.com \
    --cc=juri.lelli@redhat.co \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=quzicheng@huawei.com \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tanghui20@huawei.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.com \
    --cc=zhangqiao22@huawei.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®