All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	sched-ext@lists.linux.dev, Tejun Heo <tj@kernel.org>,
	David Vernet <void@manifault.com>,
	Andrea Righi <arighi@nvidia.com>,
	Changwoo Min <changwoo@igalia.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: Re: [RANT][PATCH] sched_ext: Fix stale fair load weight after renice under SCX
Date: Sun, 6 Dec 2026 16:25:25 +0900	[thread overview]
Message-ID: <20261206072525.GA1047183@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20261204093507.424049cf@gandalf.local.home>

On Fri, Dec 04, 2026 at 09:35:07AM -0500, Steven Rostedt wrote:
> From: Steven Rostedt (LLM) <rostedt@goodmis.org>
> 
> While working on my scheduler governors using Claude, it discovered a bug
> with the sched_ext reweight_task_scx() function. It wrote up the change
> log and created a patch. The change log is below which is mostly from
> Claude, but I did tweak it a little.
> 
> set_load_weight() hands a changed weight to the class's ->reweight_task
> and only writes p->se.load itself when the class has no such hook:
> 
> 	if (update_load && p->sched_class->reweight_task)
> 		p->sched_class->reweight_task(task_rq(p), p, &lw);
> 	else
> 		p->se.load = lw;
> 
> reweight_task_fair() updates se.load as part of reweighting, but
> reweight_task_scx() only updates p->scx.weight. So a task whose nice
> value changes while it is in the ext class keeps the fair load weight it
> had before, and nothing refreshes it when the task goes back to fair:
> neither switched_from_scx() nor scx_disable_task() does, and fair never
> recomputes a task's weight when it switches in. Forks copy the stale
> se.load too.
> 
> There are two ways to hit it:
> 
>  - renice a task while a BPF scheduler runs it, then unload the
>    scheduler (or move the task out of SCHED_EXT);
> 
>  - move a task from SCHED_EXT to SCHED_NORMAL and change its nice value
>    in the same sched_setattr(). set_load_weight() then runs while the
>    task is still in the ext class but already disabled, and
>    reweight_task_scx() returns before it gets anywhere.
> 
> Reproduced on v7.4-rc5 under QEMU with scx_simple (switch-all) for the
> first case and scx_qmap -p for the second. Two CPU-bound tasks pinned to
> one CPU, nice 0 and nice 10, measured for 3s after the nice-10 one was
> reniced under SCX and the scheduler unloaded:
> 
> 	                          nice 0    nice 10   ratio  nice-10 weight
> 	no sched_ext (control)    2711ms     290ms    9.33   112640
> 	reniced under sched_ext   1500ms    1501ms    1.00   1048576 (nice 0)
> 	... with this patch       2708ms     292ms    9.29   112640
> 
> In the sched_setattr() case, a SCHED_EXT task switched to SCHED_NORMAL
> with nice 5 kept weight 1048576 (nice 0) instead of 343040.
> 
> The stale weight survives wakeups and is only corrected by a later
> set_load_weight() for the task, such as another renice while in fair.
> 
> Store the new weight in se.load at the top of reweight_task_scx(),
> before its early returns, so that the sched_setattr() case is covered
> too: storing it next to the p->scx.weight update fixes the first case
> but not the second. The task is not on a cfs_rq while it is in the ext
> class, so this is the same plain store set_load_weight() already does for
> rt, dl and idle-policy tasks.
> 
> The bug was found by Claude Code while working on unrelated scheduler
> changes. It also wrote the QEMU reproducer, the fix and this changelog.
> 
> Cc: stable@vger.kernel.org
> Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
> 
> This is my first completely vibe coded patch. Working on my scheduler
> governors project using Claude Max (thank you Anthropic for the tokens!),
> the agent discovered this bug in sched_ext. It asked me if I wanted to send
> it upstream. I first asked it to make sure that it was still an issue with
> v7.4-rc5 as the tree I was working on was at v7.2. It looked at v7.4-rc5
> and told me that it didn't find anything to address the bug. It then built
> v7.4-rc5, booted it in qemu, created a test for it, and found that it was
> still a bug.
> 
> I told it to fix it, which it did, but the first patch was a bit invasive
> in the core scheduler code. I asked it if it could fix it in the sched_ext
> code, where it said "That's a great idea" and created this one-line patch.
> It then wrote the change log and told me how to send it and who to send it
> to. It even asked me if I wanted it to send it! I told it "No!". (Does this
> mean I've been talking with AI bots directly with no human in the loop?? I
> thought they were simply cut-and-pasting the output :-/).
> 
> It noticed that the "Assisted-by" tag is no longer needed, but I insisted
> that it included it. As I looked at the "From:" line, I thought to myself,
> it's going to say that I'm the author of this patch. THAT IS A LIE!!!!
> 
> <RANT>
> 
> This is my first full experience with an AI agent doing code. It was not
> much different than working with junior developers that I have mentored in
> the past.

I'm currently in Japan (I will present at OSSJ next week). A week ago I
spent a few days of vacation in Teshima with a colleague of mine, who
started working for my company when they were a junior straight out of
university. Every time I hear someone comparing a coding agent to a
junior developer, I think how sad it would be to travel, dine and go out
for drinks with the sole company of an LLM. I think it's our collective
responsibility (as a society, not just in the kernel) to fight against
this dystopian narrative and refuse the future sold by AI companies.

> I just told it what to do. It found a bug. It created a test case
> and proved it to be true. I just sat back and watched the token counter rise.
> Now it expects this patch to be sent with me as the author. I can't! God
> Dammit! I entered open source programming because I loved looking at the
> output from very talented programmers. I learned from them so one day I
> could be just as talented and show off what I could do. Open Source is a
> great place to find like minded individuals who are talented and you can
> work together teaching and learning at the same time. I've always said that
> my code was my art. I'm a huge advocate of "giving credit where credit is
> due". If I got something from someone, I always gave them credit even when
> it went against my interests. I love showing off the work of others too.
> 
> I didn't write this patch. Putting my name on it is exactly the same as
> going to ChatGPT and having it create a picture and say that I drew it.
> The picture is art and so is code. I will not claim any code created by an
> agent as my own. For this patch, I'm adding "(LLM)" to my "From:" line to
> point out that this came from an agent and not from me. I only supervised
> it, I didn't create it.
> 
> God help us for the future of programming if most people entering are just
> using AI agents and not ever writing the code themselves. The first version
> of this patch worked perfectly fine. It was my decades of experience that
> told me it wasn't proper engineering to do it that way. People who just
> vide code will never get the experience for proper engineering. AI agents
> could possibly handle these bad coding choices, but they are going to
> compound and eventually these bad decisions AI makes will become an issue
> even for AI. The reason I know these were bad decisions is because of
> decades of experience in making bad decisions and understanding their
> impact. I learned this the hard way and I'm much better because of that
> now. AI makes mistakes all the time (I even saw in the logs that it tried
> something and it accidentally deleted something it didn't mean to and had
> to redo it). But the engineering design mistakes it makes now will require
> destroying the entire project and rewriting later. Maybe AI could handle
> that but will people understand what was wrong with the design if they were
> not the ones that created it? It's going to be costly regardless. Tokens
> had better become cheaper by then!

Amen. This is a well documented issue, you're far from the first one to
raise it. It honestly puzzle me to see so many people burrying their
head in the send in response to AI, embracing the technology while
refusing to see the vast amount of problems it generates. I'm cautiously
optimistic though, I see an increasing number of maintainers who were
quite positive about coding agents slowly realizing that this is not
sustainable.

> Anyway, I'm keeping the Assisted-by tag and marking my authorship with
> "(LLM)" to make it obvious that I did not write this code. I wasn't invited
> to the last Maintainers Summit so I couldn't voice my opinion on the matter
> when they decided to get rid of the "Assisted-by" tag. One of the
> complaints was people who vide coded didn't add that tag and we couldn't
> enforce it. Well, to me, those that do that are no better than those using
> ChatGPT to create artwork and calling it their own!
> 
> </RANT>

This experience seems to have left a bitter taste in your mouth. I'm
curious to know why you decided to inflict upon yourself something you
described in such a negative way. Or maybe I'm misreading you and you
didn't find it that negative overall.

>  kernel/sched/ext/ext.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index efa1d01d03af..81404b37fbd1 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -5019,6 +5019,15 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p,
>  
>  	lockdep_assert_rq_held(task_rq(p));
>  
> +	/*
> +	 * set_load_weight() leaves se.load to the class when it has
> +	 * ->reweight_task. Keep it current: it is the weight the task takes
> +	 * back to the fair class. This must come before the early returns
> +	 * below, as a task switching from SCX to fair through
> +	 * sched_setscheduler() is reweighted here after scx_disable_task().
> +	 */
> +	p->se.load = *lw;
> +
>  	if (task_dead_and_done(p))
>  		return;
>  

-- 
Regards,

Laurent Pinchart

      parent reply	other threads:[~2026-12-06  7:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:35 [RANT][PATCH] sched_ext: Fix stale fair load weight after renice under SCX Steven Rostedt
2026-12-04 15:00 ` sashiko-bot
2026-12-04 15:19 ` Tejun Heo
2026-12-04 15:40 ` Andrea Righi
2026-12-04 15:44   ` Tejun Heo
2026-12-04 15:59   ` Steven Rostedt
2026-12-04 16:33     ` Andrea Righi
2026-12-04 16:53       ` Steven Rostedt
2026-12-04 17:04         ` Andrea Righi
2026-12-04 17:16           ` Steven Rostedt
2026-12-04 17:27             ` Tejun Heo
2026-12-04 17:38               ` Sasha Levin
2026-12-04 17:29             ` Andrea Righi
2026-12-04 17:59               ` Steven Rostedt
2026-12-04 17:36           ` Sasha Levin
2026-12-04 16:19   ` Peter Zijlstra
2026-12-04 18:06 ` Linus Torvalds
2026-12-04 18:47   ` Steven Rostedt
2026-12-04 18:57     ` Linus Torvalds
2026-12-04 19:29       ` Steven Rostedt
2026-12-05 13:29         ` Steven Rostedt
2026-12-06  7:25 ` Laurent Pinchart [this message]

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=20261206072525.GA1047183@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sashal@kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=void@manifault.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.