From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.218 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793859420; b=yJ3DSiWD2+D8B8qElwF6hvLCl7FWL25mIn5Kz86tOYSMFw4hcdlPNs7T2xq+gsP8cyoI cABXEj9VAaEwHKtE4ol/T7TXmjQHicXUKyl+5Ixx9KiGr4fW5NEwp880xTe01VnCPfH9n AAbbyT43IYbdwLhPpAUUj1G1hjqZx2TJg6G+83ljRiUhkKxZYoIiyoGcYdcPT5dOlNWM5 i1e42AOvmeXCKMlenXJsaefxGTZq/Aeu4UGpL2rVgwMDWEw4AybpYVntwdyFT2Ls9SqtH 0Wx/PbKnghCsA43kFS2Yxw5spwP3slTiNx0fVMhMFXNSNcOySFeoTZ+27O6nok4gkKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793859420; h=DMARC-Filter:dkim-signature:Received:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:X-Originating-IP:X-ClientProxiedBy; bh=VDyU0RzFw5XhVgtF969cBIIIGjCobkQTfAtkDKO6N08=; b=ihIhKjGXYAqm/q0J52GBFooEdnS8h4rZF2+5UE2Ki1jKB3+jlpJpsTGOnvNnX03I5HKF OiWTq+KY676l4405gPm9lDfdo28yMxUKRePIoPBE7gETImxPAWU06yxSN+h65c+7jfiFj ee+uzLuTkcvxqzMPMgsxPcx5PbvLTO7zAuQ1JwPuYWlymR+NzraGzNnxdDT9g2giADMKY tYk6iLMcMFfukRSt2Km1yA4ky5A7Lcgq+akuW+fNS11gOGLKvM/VFcC2b47IvwG9vNSTD /EqdiqdmQoOT1tgvKzLrcFhm2QI/pKc5brTCtHfi71pV3WAR0OSUXM368XwyB/ThX+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=HXvKi0sx; arc=none smtp.remote-ip=113.46.200.218 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (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 C2877606A330 for ; Thu, 5 Nov 2026 06:16:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C2877606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=HXvKi0sx dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=VDyU0RzFw5XhVgtF969cBIIIGjCobkQTfAtkDKO6N08=; b=HXvKi0sx4ZEbupdiEZTUCD4UsD7eSWx3gzqeDm3z+roYTgQojaO/2CM4tJwZ410AsceCVwkHR fnmvJuU1LragrH5cPT3YHsYaXJ++ts06KM8q3jn99kdajyMhQ3m1GrEXuS091J28xmtDgJEwsoZ I7liaFoegOyTyO+HRqflxls= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4jKsWj1kxNzpSvl; Thu, 5 Nov 2026 14:16:17 +0800 (CST) Received: from kwepemk300016.china.huawei.com (unknown [7.202.195.98]) by mail.maildlp.com (Postfix) with ESMTPS id C2C1D4057D; Thu, 5 Nov 2026 14:16:43 +0800 (CST) Received: from huawei.com (10.67.174.191) by kwepemk300016.china.huawei.com (7.202.195.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Thu, 5 Nov 2026 14:16:43 +0800 From: Zhang Qiao To: CC: , , , , , , Subject: [PATCH 1/4] sched_ext: Extract no-topology CID construction and table finalization Date: Thu, 5 Nov 2026 14:50:10 +0800 Message-ID: <20261105065013.784398-2-zhangqiao22@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20261105065013.784398-1-zhangqiao22@huawei.com> References: <20261105065013.784398-1-zhangqiao22@huawei.com> 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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemk300016.china.huawei.com (7.202.195.98) 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 --- 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