[RANT][PATCH] sched_ext: Fix stale fair load weight after renice under SCX

From: Steven Rostedt

Date: Fri Dec 04 2026 - 09:35:29 EST


From: Steven Rostedt (LLM) <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxxxxxx
Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---

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 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!

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>


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;

--
2.53.0