From: Zhang Qiao <zhangqiao22@huawei.com>
To: <sched-ext@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <tj@kernel.org>,
<void@manifault.com>, <arighi@nvidia.com>, <changwoo@igalia.com>,
<tanghui22@huawei.com>, <zhangqiao22@huawei.com>
Subject: [PATCH 1/4] sched_ext: Extract no-topology CID construction and table finalization
Date: Thu, 5 Nov 2026 14:50:10 +0800 [thread overview]
Message-ID: <20261105065013.784398-2-zhangqiao22@huawei.com> (raw)
In-Reply-To: <20261105065013.784398-1-zhangqiao22@huawei.com>
scx_cid_init() interleaves table allocation, the four-level topology
walk, the no-topo tail and the shard range finalization in a single
~230-line body. Start decomposing it by extracting the last two stages:
- scx_cid_build_notopo() packs the possible-but-unassigned cpus into
shards capped at min(shard_size, SCX_CID_SHARD_MAX_CPUS) and
records the online cpus that ended up without topology info.
- scx_cid_finalize_tables() derives shard_ranges[] from
cid_to_shard[] and publishes nr_shards.
The counters are passed by pointer. Allocation, diagnostics and
cleanup stay in scx_cid_init(). No behavior change.
Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
kernel/sched/ext/cid.c | 120 +++++++++++++++++++++++------------------
1 file changed, 69 insertions(+), 51 deletions(-)
diff --git a/kernel/sched/ext/cid.c b/kernel/sched/ext/cid.c
index a5330b760ecd..b6be8806a7d5 100644
--- a/kernel/sched/ext/cid.c
+++ b/kernel/sched/ext/cid.c
@@ -165,6 +165,71 @@ void scx_cid_retire_tables(void)
call_rcu(&tbls->rcu, scx_cid_tables_free_rcufn);
}
+static void scx_cid_build_notopo(struct scx_cid_tables *tbls, u32 shard_size,
+ u32 *next_cid, s32 *next_shard_idx,
+ struct cpumask *online_no_topo)
+{
+ u32 notopo_in_shard;
+ s32 notopo_shard_cid, notopo_shard_idx;
+ s32 cpu, cid;
+
+ /*
+ * No-topo section: any possible cpu without a cid - normally just the
+ * not-online ones. Pack into shards of up to min(@shard_size,
+ * SCX_CID_SHARD_MAX_CPUS) cids so that every cid has a valid shard
+ * assignment and the hard cap holds even with a large @shard_size.
+ * Collect any currently-online cpus that land here in @online_no_topo
+ * so we can warn about them at the end.
+ */
+ notopo_in_shard = min_t(u32, shard_size, SCX_CID_SHARD_MAX_CPUS);
+ notopo_shard_cid = -1;
+ notopo_shard_idx = -1;
+
+ for_each_cpu(cpu, cpu_possible_mask) {
+ if (tbls->cpu_to_cid[cpu] != -1)
+ continue;
+ if (cpu_online(cpu))
+ cpumask_set_cpu(cpu, online_no_topo);
+
+ cid = (*next_cid)++;
+ tbls->cid_to_cpu[cid] = cpu;
+ tbls->cpu_to_cid[cpu] = cid;
+
+ if (notopo_in_shard >= min_t(u32, shard_size, SCX_CID_SHARD_MAX_CPUS)) {
+ notopo_shard_cid = cid;
+ notopo_shard_idx = (*next_shard_idx)++;
+ notopo_in_shard = 0;
+ }
+ notopo_in_shard++;
+
+ tbls->cid_to_shard[cid] = notopo_shard_idx;
+ tbls->topo[cid] = SCX_CID_TOPO_NEG;
+ tbls->topo[cid].shard_cid = notopo_shard_cid;
+ tbls->topo[cid].shard_idx = notopo_shard_idx;
+ }
+}
+
+static void scx_cid_finalize_tables(struct scx_cid_tables *tbls, u32 next_cid,
+ s32 next_shard_idx)
+{
+ s32 cid;
+
+ /*
+ * Fill shard_ranges[] from cid_to_shard[]. Shards are contiguous
+ * cid ranges by construction: base_cid is the first cid landing in a
+ * shard, nr_cids is the count.
+ */
+ for (cid = 0; cid < next_cid; cid++) {
+ s32 sidx = tbls->cid_to_shard[cid];
+
+ if (tbls->shard_ranges[sidx].nr_cids == 0)
+ tbls->shard_ranges[sidx].base_cid = cid;
+ tbls->shard_ranges[sidx].nr_cids++;
+ }
+
+ tbls->nr_shards = next_shard_idx;
+}
+
/**
* scx_cid_init - build the cid mapping
* @sch: the scx_sched being initialized; used as the scx_error() target
@@ -193,9 +258,7 @@ s32 scx_cid_init(struct scx_sched *sch)
s32 next_cluster_idx = 0;
s32 next_shard_idx = 0;
u32 shard_size, max_cids;
- u32 notopo_in_shard;
- s32 notopo_shard_cid, notopo_shard_idx;
- s32 cpu, cid, si;
+ s32 cpu, si;
/* CMASK_MAX_WORDS in cid.bpf.h covers NR_CPUS up to 8192 */
BUILD_BUG_ON(NR_CPUS > 8192);
@@ -351,40 +414,8 @@ s32 scx_cid_init(struct scx_sched *sch)
}
}
- /*
- * No-topo section: any possible cpu without a cid - normally just the
- * not-online ones. Pack into shards of up to min(@shard_size,
- * SCX_CID_SHARD_MAX_CPUS) cids so that every cid has a valid shard
- * assignment and the hard cap holds even with a large @shard_size.
- * Collect any currently-online cpus that land here in @online_no_topo
- * so we can warn about them at the end.
- */
- notopo_in_shard = min_t(u32, shard_size, SCX_CID_SHARD_MAX_CPUS);
- notopo_shard_cid = -1;
- notopo_shard_idx = -1;
-
- for_each_cpu(cpu, cpu_possible_mask) {
- if (tbls->cpu_to_cid[cpu] != -1)
- continue;
- if (cpu_online(cpu))
- cpumask_set_cpu(cpu, online_no_topo);
-
- cid = next_cid++;
- tbls->cid_to_cpu[cid] = cpu;
- tbls->cpu_to_cid[cpu] = cid;
-
- if (notopo_in_shard >= min_t(u32, shard_size, SCX_CID_SHARD_MAX_CPUS)) {
- notopo_shard_cid = cid;
- notopo_shard_idx = next_shard_idx++;
- notopo_in_shard = 0;
- }
- notopo_in_shard++;
-
- tbls->cid_to_shard[cid] = notopo_shard_idx;
- tbls->topo[cid] = SCX_CID_TOPO_NEG;
- tbls->topo[cid].shard_cid = notopo_shard_cid;
- tbls->topo[cid].shard_idx = notopo_shard_idx;
- }
+ scx_cid_build_notopo(tbls, shard_size, &next_cid, &next_shard_idx,
+ online_no_topo);
if (!cpumask_empty(llc_fallback))
pr_warn("scx_cid: cpus without cacheinfo, using node mask as llc: %*pbl\n",
@@ -393,20 +424,7 @@ s32 scx_cid_init(struct scx_sched *sch)
pr_warn("scx_cid: online cpus with no usable topology: %*pbl\n",
cpumask_pr_args(online_no_topo));
- /*
- * Fill cid_shard_ranges[] from cid_to_shard[]. Shards are contiguous
- * cid ranges by construction: base_cid is the first cid landing in a
- * shard, nr_cids is the count.
- */
- for (cid = 0; cid < next_cid; cid++) {
- s32 sidx = tbls->cid_to_shard[cid];
-
- if (tbls->shard_ranges[sidx].nr_cids == 0)
- tbls->shard_ranges[sidx].base_cid = cid;
- tbls->shard_ranges[sidx].nr_cids++;
- }
-
- tbls->nr_shards = next_shard_idx;
+ scx_cid_finalize_tables(tbls, next_cid, next_shard_idx);
return 0;
}
--
2.43.0
next prev parent reply other threads:[~2026-11-05 6:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 6:50 [PATCH 0/4] sched_ext: Decompose scx_cid_init() Zhang Qiao
2026-11-05 6:50 ` Zhang Qiao [this message]
2026-11-05 6:50 ` [PATCH 2/4] sched_ext: Collect CID construction state in a private builder Zhang Qiao
2026-11-05 6:50 ` [PATCH 3/4] sched_ext: Extract construction of a single LLC CID range Zhang Qiao
2026-11-05 6:50 ` [PATCH 4/4] sched_ext: Extract online CID construction from scx_cid_init Zhang Qiao
2026-11-05 17:10 ` [PATCH 0/4] sched_ext: Decompose scx_cid_init() 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=20261105065013.784398-2-zhangqiao22@huawei.com \
--to=zhangqiao22@huawei.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sched-ext@lists.linux.dev \
--cc=tanghui22@huawei.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®