From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=216.40.44.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796394922; b=zvi+KU9MVBNVYnP2Kdu4+Mf9621TRIi48Aq/hpifmbw0uspjK5NFqnfJe4jKQVFZW6uE FI0d3arvmNz5zduDIY3ySLHJKjdkLwY9Vwr0+EPvb5nGbvVGWZf1O7Psary84Oj88NY/J eavjCEzN5kKGKvRK9wdFbaHUupX4yOaZzAyt/OCtV6wYmb/JezSHRERQbu4fl9nO+VI7y Lb0XoLLVg2T/AeK4Y+XXdd0FI3iPJ9wE4GenmK7FNyrOXkhG9lqDrvCwM3aCMg+rRxHCB qifHAOQWucTZcXfGgJihpqBIL0UgYIyV1lu+RZU90MYOPfIVy2xx4+fR0ELcRNdz5UQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796394922; h=DMARC-Filter:Received:Received:Date:From:To:Cc:Subject:Message-ID: X-Mailer:MIME-Version:Content-Type:Content-Transfer-Encoding: X-Rspamd-Server:X-Rspamd-Queue-Id:X-Stat-Signature:X-Spam-Status: X-Session-Marker:X-Session-ID:DKIM-Signature:X-HE-Tag:X-HE-Meta; bh=3F9plOaLNw+QLik5/M0Xf1e4fkr1dU+pfkoiATvSgWY=; b=1Ma475+wLZXePLIOEiuWGOx9a6V5Ifvspbi9jFo7KhNFBujZD4N+OK6p0jhVgYwHOofF LtChWT4C4a0psF3IOzecW8naSpl92eYtemI8R6SCb+0SrBNVJmU+1fASxoQs6o4piQEZm dktKJbfFl1WbMhr29B9aGiFetRrjWfhXKEU6KVkux5z/M4z9EL/mnydYD0MvNcI19GRY7 73UgaYHeCsT9JZQZVyngys2l08fqGaANeZphG+OhKusdWDy+n58jE7qVyieHNGp7db1e7 6Farnv6c4v9ZJFe2be6jiQJooy0gXYzm9gNa0ZKwLsUXt6ugyRGLWU6o0TpJU8vV1gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; dkim=pass header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=chg61FQk; arc=none smtp.remote-ip=216.40.44.15 Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DF08606A336 for ; Fri, 4 Dec 2026 14:35:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2DF08606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=chg61FQk Received: from omf02.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 45DD01C20C9; Fri, 4 Dec 2026 14:35:13 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf02.hostedemail.com (Postfix) with ESMTPA id 9137F8000E; Fri, 4 Dec 2026 14:35:10 +0000 (UTC) Date: Fri, 4 Dec 2026 09:35:07 -0500 From: Steven Rostedt To: LKML , sched-ext@lists.linux.dev Cc: Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Jonathan Corbet , Greg Kroah-Hartman , Sasha Levin Subject: [RANT][PATCH] sched_ext: Fix stale fair load weight after renice under SCX Message-ID: <20261204093507.424049cf@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspamout06 X-Rspamd-Queue-Id: 9137F8000E X-Stat-Signature: tpk77rut3o3m8p94omeqyka59ajutaax X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX18aeyfAPgMjeRoFwOIscFWmr/kEZQ7HYik= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=goodmis.org; h=date:from:to:cc:subject:message-id:mime-version:content-type:content-transfer-encoding; s=dkim1; bh=3F9plOaLNw+QLik5/M0Xf1e4fkr1dU+pfkoiATvSgWY=; b=chg61FQkDSqz4RB4tQ+sUTExiYkMWMpB3+COeR6sUsI9Z0AC9IOJx2CGK9tCSnAWYHdOGcS8WC5Ou631jqe23uZZxsQwdvcK2WDqY9NkBbpaIGzFSBJW8GbANyU0Y/0J/EzNgy8jBrkEYsjPBQk9I5XIWRUtmW3W9abtyO++Ig0= X-HE-Tag: 1796394910-329216 X-HE-Meta: U2FsdGVkX181sHPZT4nkD/wR8X+pVTcGiJUQRr7bCyEgEB8qGV4O2HGLq8N50YcFfzemebAMyJdwktq6hGROdb6uBSjGvZlpRdokmEPIrgOtWjKl8jTdieD99Dh1nwrFVJgKRtitfGkbbFSJnBe37P3VxKTUiwDbeJXuMtCR7/MAniFbhZfAYrIMyORaFvfvvinkH4f6g217aA3F6o2+aqnRIZqeUSFzcc5TN7Mfszt0c9nWeCJq3Lzs/HRX496McXTmh7CMt4d9lD9+t0P69s4Jp766RvifiIVEXa657BQYJnSRQJfu+2UAqgtmShcweyQXCJSzDdTc7pRKrO0K6kkJ+RGU4qmHVmwaiYj5cFrMGhvzAkZ6fXxKFquO9zagTyi7ko2JmB2NqC/pDmV+Rg== From: Steven Rostedt (LLM) 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 --- 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!!!! 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! 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