From nobody Thu Apr 2 17:10:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AFB6336EDA for ; Tue, 10 Feb 2026 22:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761591; cv=none; b=BNdqxwtCXnKuBYJpucdERXgi+HawQVKpcCqFdrbjrnBCua3z0cT1w47ofeMbJDtah4NDHZctBooG3XFgrgMDp96BLQ7UU24rKy6l1JWRL4ZH+H2W0tNggmBM9KYv0dEiV3dn/5P6rxFaRzEr4jeuXYxPm3+tcKqB7sXGK0nAB6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770761591; c=relaxed/simple; bh=T3k34hbPq1z9/RrkdAzRCXvBVVy+/ochK3PX9bbZfIk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aNEWZQrvLB9XgaRGuVW8dPyOPEMImLtxIif74W9VJ0P/eSfd20kLPkPbBvUeI3zSyNR/djdmgpJ9BjnczB7f1IoJ+lJcPKOiQIh9O3d+EDnGGS9kD/PtaN6jF5Vlx146gcJdqRMeNKg0nz3RiiIM73DdZ9T7pGof+rvFAd+dpqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F07cAAwc; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F07cAAwc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770761591; x=1802297591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T3k34hbPq1z9/RrkdAzRCXvBVVy+/ochK3PX9bbZfIk=; b=F07cAAwcHT0ODqmzXtDL9rEZVHxLTQ74NAQmCmbgo7SQx+f7yD/NObO5 A4pZHS8zfU06rjv22RhvM2YanidQalAJigfH5d6XgCSqjoMCQGbaZJ9RD sthm12u6v3kVFgfFYefkXGA84EjTBS2hnS1kZyA9KbpDGTWOm/1kQ8iFS prpI1NIbHSETBUmLWY7fGWQ0bW+wAGsX0HMNrWBWk2x4ZwQqd4zc4+iM4 QQYi1oGLk4IAWRbxgdFP2cB17rPIyrjvPTal/vWLdS2s16Wz/jD56jYIW N84NzvEpZi+HcooAb4LrsnSTX8wCAbLEFNA3Q0TGayp+1YlgOAry8pWSz w==; X-CSE-ConnectionGUID: UJ8OCAktR8q4NLljxweDFA== X-CSE-MsgGUID: +4doCTFVT6WE36a2nw4yEA== X-IronPort-AV: E=McAfee;i="6800,10657,11697"; a="82631291" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="82631291" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2026 14:13:10 -0800 X-CSE-ConnectionGUID: KzpshQ8vSvGb7c+EVFX4hA== X-CSE-MsgGUID: Meul46aLQpqEDG4rc/ZJUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="216373897" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by fmviesa004.fm.intel.com with ESMTP; 10 Feb 2026 14:13:08 -0800 From: Tim Chen To: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot Cc: Chen Yu , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Tim Chen , Aubrey Li , Zhao Liu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org Subject: [PATCH v3 04/21] sched/cache: Make LLC id continuous Date: Tue, 10 Feb 2026 14:18:44 -0800 Message-Id: <60a05a3f50d14a7bf3b968f62cca87893c5c552c.1770760558.git.tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Chen Yu Introduce an index mapping between CPUs and their LLCs. This provides a continuous per LLC index needed for cache-aware load balancing in later patches. The existing per_cpu llc_id usually points to the first CPU of the LLC domain, which is sparse and unsuitable as an array index. Using llc_id directly would waste memory. With the new mapping, CPUs in the same LLC share a continuous id: per_cpu(llc_id, CPU=3D0...15) =3D 0 per_cpu(llc_id, CPU=3D16...31) =3D 1 per_cpu(llc_id, CPU=3D32...47) =3D 2 ... Once a CPU has been assigned an llc_id, this ID persists even when the CPU is taken offline and brought back online, which can facilitate the management of the ID. Co-developed-by: Tim Chen Signed-off-by: Tim Chen Co-developed-by: K Prateek Nayak Signed-off-by: K Prateek Nayak Signed-off-by: Chen Yu --- Notes: v2->v3: Allocate the LLC id according to the topology level data directly, rath= er than calculating from the sched domain. This simplifies the code. (Peter Zijlstra, K Prateek Nayak) kernel/sched/topology.c | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index cf643a5ddedd..ca46b5cf7f78 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -20,6 +20,7 @@ void sched_domains_mutex_unlock(void) /* Protected by sched_domains_mutex: */ static cpumask_var_t sched_domains_tmpmask; static cpumask_var_t sched_domains_tmpmask2; +static int tl_max_llcs; =20 static int __init sched_debug_setup(char *str) { @@ -658,7 +659,7 @@ static void destroy_sched_domains(struct sched_domain *= sd) */ DEFINE_PER_CPU(struct sched_domain __rcu *, sd_llc); DEFINE_PER_CPU(int, sd_llc_size); -DEFINE_PER_CPU(int, sd_llc_id); +DEFINE_PER_CPU(int, sd_llc_id) =3D -1; DEFINE_PER_CPU(int, sd_share_id); DEFINE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared); DEFINE_PER_CPU(struct sched_domain __rcu *, sd_numa); @@ -684,7 +685,6 @@ static void update_top_cache_domain(int cpu) =20 rcu_assign_pointer(per_cpu(sd_llc, cpu), sd); per_cpu(sd_llc_size, cpu) =3D size; - per_cpu(sd_llc_id, cpu) =3D id; rcu_assign_pointer(per_cpu(sd_llc_shared, cpu), sds); =20 sd =3D lowest_flag_domain(cpu, SD_CLUSTER); @@ -2567,10 +2567,18 @@ build_sched_domains(const struct cpumask *cpu_map, = struct sched_domain_attr *att =20 /* Set up domains for CPUs specified by the cpu_map: */ for_each_cpu(i, cpu_map) { - struct sched_domain_topology_level *tl; + struct sched_domain_topology_level *tl, *tl_llc =3D NULL; + int lid; =20 sd =3D NULL; for_each_sd_topology(tl) { + int flags =3D 0; + + if (tl->sd_flags) + flags =3D (*tl->sd_flags)(); + + if (flags & SD_SHARE_LLC) + tl_llc =3D tl; =20 sd =3D build_sched_domain(tl, cpu_map, attr, sd, i); =20 @@ -2581,6 +2589,39 @@ build_sched_domains(const struct cpumask *cpu_map, s= truct sched_domain_attr *att if (cpumask_equal(cpu_map, sched_domain_span(sd))) break; } + + lid =3D per_cpu(sd_llc_id, i); + if (lid =3D=3D -1) { + int j; + + /* + * Assign the llc_id to the CPUs that do not + * have an LLC. + */ + if (!tl_llc) { + per_cpu(sd_llc_id, i) =3D tl_max_llcs++; + + continue; + } + + /* try to reuse the llc_id of its siblings */ + for_each_cpu(j, tl_llc->mask(tl_llc, i)) { + if (i =3D=3D j) + continue; + + lid =3D per_cpu(sd_llc_id, j); + + if (lid !=3D -1) { + per_cpu(sd_llc_id, i) =3D lid; + + break; + } + } + + /* a new LLC is detected */ + if (lid =3D=3D -1) + per_cpu(sd_llc_id, i) =3D tl_max_llcs++; + } } =20 if (WARN_ON(!topology_span_sane(cpu_map))) --=20 2.32.0