From: zhidao su <soolaugust@gmail.com>
To: tj@kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: void@manifault.com, arighi@nvidia.com, changwoo@igalia.com,
linux-kselftest@vger.kernel.org, Su Zhidao <suzhidao@xiaomi.com>
Subject: [PATCH 2/5] sched_ext: Add comments to scx_bypass() for bypass depth semantics
Date: Fri, 6 Mar 2026 22:03:22 +0800 [thread overview]
Message-ID: <20260306140325.2710927-3-suzhidao@xiaomi.com> (raw)
In-Reply-To: <20260306140325.2710927-1-suzhidao@xiaomi.com>
From: Su Zhidao <suzhidao@xiaomi.com>
The bypass depth counter (scx_bypass_depth) uses WRITE_ONCE/READ_ONCE
to communicate that it can be observed locklessly from IRQ context, even
though modifications are serialized by bypass_lock. The existing code did
not explain this pattern or the re-queue loop's role in propagating the
bypass state change to all CPUs.
Add inline comments to clarify:
- Why bypass_depth uses WRITE_ONCE/READ_ONCE despite lock protection
- How the dequeue/enqueue cycle propagates bypass state to all per-CPU queues
Signed-off-by: Su Zhidao <suzhidao@xiaomi.com>
---
kernel/sched/ext.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 56ff5874af94..053d99c58802 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4229,6 +4229,14 @@ static void scx_bypass(bool bypass)
if (bypass) {
u32 intv_us;
+ /*
+ * Increment bypass depth. Only the first caller (depth 0->1)
+ * needs to set up the bypass state; subsequent callers just
+ * increment the counter and return. The depth counter is
+ * protected by bypass_lock but READ_ONCE/WRITE_ONCE are used
+ * to communicate that the value can be observed locklessly
+ * (e.g., from scx_bypass_lb_timerfn() in softirq context).
+ */
WRITE_ONCE(scx_bypass_depth, scx_bypass_depth + 1);
WARN_ON_ONCE(scx_bypass_depth <= 0);
if (scx_bypass_depth != 1)
@@ -4263,6 +4271,10 @@ static void scx_bypass(bool bypass)
*
* This function can't trust the scheduler and thus can't use
* cpus_read_lock(). Walk all possible CPUs instead of online.
+ *
+ * The dequeue/enqueue cycle forces tasks through the updated code
+ * paths: in bypass mode, do_enqueue_task() routes to the per-CPU
+ * bypass DSQ instead of calling ops.enqueue().
*/
for_each_possible_cpu(cpu) {
struct rq *rq = cpu_rq(cpu);
--
2.43.0
next prev parent reply other threads:[~2026-03-06 14:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 14:03 [PATCH 0/5] sched_ext: bypass state machine cleanup and selftest zhidao su
2026-03-06 14:03 ` [PATCH 1/5] sched_ext: Remove deprecated SCX_OPS_HAS_CGROUP_WEIGHT flag zhidao su
2026-03-06 14:03 ` zhidao su [this message]
2026-03-06 14:03 ` [PATCH 3/5] sched_ext: Use rcu_dereference_bh() in scx_bypass_lb_timerfn() zhidao su
2026-03-06 14:03 ` [PATCH 4/5] sched_ext/selftests: Add bypass mode operational test zhidao su
2026-03-06 15:02 ` Andrea Righi
2026-03-06 14:03 ` [PATCH 5/5] sched_ext: Document scx_bypass_depth migration path zhidao su
2026-03-06 15:02 ` [PATCH 0/5] sched_ext: bypass state machine cleanup and selftest Andrea Righi
-- strict thread matches above, loose matches on Subject: below --
2026-03-06 12:48 [PATCH 2/5] sched_ext: Add comments to scx_bypass() for bypass depth semantics zhidao su
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=20260306140325.2710927-3-suzhidao@xiaomi.com \
--to=soolaugust@gmail.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=sched-ext@lists.linux.dev \
--cc=suzhidao@xiaomi.com \
--cc=tj@kernel.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 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®