From nobody Thu Sep 24 21:19:45 2026 Received: from mta1.migadu.com (out-87.mta1.migadu.com [95.215.58.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4532494D8 for ; Sun, 20 Sep 2026 03:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874319; cv=none; b=lz8GFzyRTCKMuw3a5NM+C9xaqxh+Z4NXPRaOoIeoXSC93ssQmtR3xDai8Vp9E2ZNkGci/XRTUXP7U+dyTWI4Ynqhy7rO8oEKa281mWwP/AeE8YR9tCV+DOH9gJ3GHKceyMmSnuebwYk71Qi0jTGAu3zJi8je4QqRrdGnbj7BEw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874319; c=relaxed/simple; bh=3W3O8094sWvs6XA3nq+JIrIy9/nDGCyklWmUxuJkhHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M5vYnv/h4gPa2XIFn/Ay80ymv6heP6ITmYM80xYlq0YXyVFbeeuzh7ArSaTvbSKtliwBiAU7PM0i25TvdeFkQvxvI3VmC6LP5E3A+9t4HI7Je9fYCxZyO0n+c3muoL78ID6D5SLHj+CSJhLZxiL7A5WrB8zcVkyo2YGU8nDT+uY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qgs0b/yB; arc=none smtp.client-ip=95.215.58.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qgs0b/yB" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=3W3O8094sWvs6XA3nq+JIrIy9/nDGCyklWmUxuJkhHE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789874315; v=1; x=1790479115; b=qgs0b/yBrERYTjY5M8aM853MXHKXuMqTl3dC3nGJMra6awJnuuNkeTJrBFzelN51nvSJTBHQ SfWWd0IcxpVepjPqqp7TQ0SWF3DZPpWcvVKL2egnR6cK454XBInldUz8OEcljDRkRrcaxvussnG 1jXddu+UWhjRUMr1Ceabtk64= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta12.migadu.com with ESMTPS id 4239474afc06c193; Sun, 20 Sep 2026 03:18:35 +0000 X-Mizu-Trace-ID: 4239474afc06c193 X-Migadu-Flow: FLOW_OUT From: Troy Mitchell Date: Sun, 20 Sep 2026 11:18:02 +0800 Subject: [PATCH RFC 1/3] arch_topology: Add a die level to CPU topology Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-riscv-die-topology-rfc-v1-1-071c0bf61d5f@linux.dev> References: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> In-Reply-To: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> To: Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Catalin Marinas , Will Deacon , Mark Rutland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Troy Mitchell X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3769; i=troy.mitchell@linux.dev; h=from:subject:message-id; bh=3W3O8094sWvs6XA3nq+JIrIy9/nDGCyklWmUxuJkhHE=; b=owGbwMvMwCU2g/N9w09jE33G02pJDFnrA+oZbvrfOL/008GwqU1e10rnnEsruPKnx6tZjXmD7 9yzsq83d5SyMIhxMciKKbJ0P+DZVuATZVsgUOgLM4eVCWwIF6cATGSDLyPDV4f1J8QTD50JTFnE Pbeoz4OnaDZT4+/5xVPzOcQUDz/nY2SYWXIuevPUK6q3tHP+mr9bIRFpt9jxzaX2FT9tmBn4Luj xAgA= X-Developer-Key: i=troy.mitchell@linux.dev; a=openpgp; fpr=3FE5535CF1B0E658E57DB59BAE1C2FBEA7DB42E1 The generic topology model records packages and clusters but has no representation for a die between them. Systems with multiple dies in one package must therefore either report each die as a package or flatten clusters across all dies. Both choices lose part of the physical hierarchy. Add a die identifier and sibling mask between the package and cluster levels. Initialize the identifier to -1 and only build die sibling masks when firmware supplied a valid identifier. CPU topology paths without die information, including the current ACPI parser and the fallback topology, therefore keep the die unknown instead of inventing die 0. Scope cluster sibling matching to a die so each die can number its clusters independently, and maintain the new mask across CPU hotplug. Signed-off-by: Troy Mitchell --- drivers/base/arch_topology.c | 20 +++++++++++++++++--- include/linux/arch_topology.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 8c5e47c28d9a3..ee82827be3351 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -766,6 +766,14 @@ void update_siblings_masks(unsigned int cpuid) cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); =20 + if (cpuid_topo->die_id !=3D cpu_topo->die_id) + continue; + + if (cpuid_topo->die_id >=3D 0) { + cpumask_set_cpu(cpu, &cpuid_topo->die_sibling); + cpumask_set_cpu(cpuid, &cpu_topo->die_sibling); + } + if (cpuid_topo->cluster_id !=3D cpu_topo->cluster_id) continue; =20 @@ -792,6 +800,9 @@ static void clear_cpu_topology(int cpu) cpumask_clear(&cpu_topo->cluster_sibling); cpumask_set_cpu(cpu, &cpu_topo->cluster_sibling); =20 + cpumask_clear(&cpu_topo->die_sibling); + cpumask_set_cpu(cpu, &cpu_topo->die_sibling); + cpumask_clear(&cpu_topo->core_sibling); cpumask_set_cpu(cpu, &cpu_topo->core_sibling); cpumask_clear(&cpu_topo->thread_sibling); @@ -808,6 +819,7 @@ void __init reset_cpu_topology(void) cpu_topo->thread_id =3D -1; cpu_topo->core_id =3D -1; cpu_topo->cluster_id =3D -1; + cpu_topo->die_id =3D -1; cpu_topo->package_id =3D -1; =20 clear_cpu_topology(cpu); @@ -824,6 +836,8 @@ void remove_cpu_topology(unsigned int cpu) cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling)); for_each_cpu(sibling, topology_cluster_cpumask(cpu)) cpumask_clear_cpu(cpu, topology_cluster_cpumask(sibling)); + for_each_cpu(sibling, &cpu_topology[cpu].die_sibling) + cpumask_clear_cpu(cpu, &cpu_topology[sibling].die_sibling); for_each_cpu(sibling, topology_llc_cpumask(cpu)) cpumask_clear_cpu(cpu, topology_llc_cpumask(sibling)); =20 @@ -969,9 +983,9 @@ void store_cpu_topology(unsigned int cpuid) cpuid_topo->core_id =3D cpuid; cpuid_topo->package_id =3D cpu_to_node(cpuid); =20 - pr_debug("CPU%u: package %d core %d thread %d\n", - cpuid, cpuid_topo->package_id, cpuid_topo->core_id, - cpuid_topo->thread_id); + pr_debug("CPU%u: package %d die %d core %d thread %d\n", + cpuid, cpuid_topo->package_id, cpuid_topo->die_id, + cpuid_topo->core_id, cpuid_topo->thread_id); =20 topology_populated: update_siblings_masks(cpuid); diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index ebd7f8935f969..2a5591bb95075 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -63,10 +63,12 @@ struct cpu_topology { int thread_id; int core_id; int cluster_id; + int die_id; int package_id; cpumask_t thread_sibling; cpumask_t core_sibling; cpumask_t cluster_sibling; + cpumask_t die_sibling; cpumask_t llc_sibling; }; =20 --=20 2.55.0 From nobody Thu Sep 24 21:19:45 2026 Received: from mta1.migadu.com (out-98.mta1.migadu.com [95.215.58.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5B853BB131 for ; Sun, 20 Sep 2026 03:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874323; cv=none; b=CyDGm4z9yzwGkt/HCs+WXiAD4Irf2hHkq4LbP2bwd5gsXecuQUf0uJxGwpYJ3RzJOscndE1IbhCDi7mn4P3grZXAtXzgS+rcExnpoGDyiKJfX+tTUJ2wxj9BYBRgaLVXrjoKWadj9NrTIeUPm+KaEH/2j9p77xLZp55HmI2g5Ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874323; c=relaxed/simple; bh=sLuj1hW1gJrgOf+bnaZxdaJK6PTj0i8XPll8TEvnjak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cxq2mVMh9hbRHq/Qj53oPE3nHSefzKe8rDpKB5EafYQSOfDx10LwuqcUeP6DNl9e40CkJxCdC8gWhYKHYu2fO6hbEs+4639boeLwV9gbbcGHhQUjdP1rjXIso6ovGXZEQyG9KN3XtfBKutqeeXwsOewTKFnDFkJ2htv9bdLcgWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dqyr9T+g; arc=none smtp.client-ip=95.215.58.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dqyr9T+g" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=sLuj1hW1gJrgOf+bnaZxdaJK6PTj0i8XPll8TEvnjak=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789874319; v=1; x=1790479119; b=dqyr9T+gOoSShrtuh4ylvdAKLRaghASR/DdxUBa78jCKNZEv6if1f3ZbIO9cnM9A/VyqLyL4 nGrhtyS5g3r/haug09/iRmHJ2C+mRl7hR6eRqIANhBEu7dbShEcc4RjO43yDplrc3t9lFy7mXqH uNnRpP/yaq8wYI9x0HeBA1+g= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta12.migadu.com with ESMTPS id e98d43414bfcadef; Sun, 20 Sep 2026 03:18:39 +0000 X-Mizu-Trace-ID: e98d43414bfcadef X-Migadu-Flow: FLOW_OUT From: Troy Mitchell Date: Sun, 20 Sep 2026 11:18:03 +0800 Subject: [PATCH RFC 2/3] arch_topology: Parse die nodes in /cpu-map Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-riscv-die-topology-rfc-v1-2-071c0bf61d5f@linux.dev> References: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> In-Reply-To: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> To: Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Catalin Marinas , Will Deacon , Mark Rutland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Troy Mitchell X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4640; i=troy.mitchell@linux.dev; h=from:subject:message-id; bh=sLuj1hW1gJrgOf+bnaZxdaJK6PTj0i8XPll8TEvnjak=; b=owGbwMvMwCU2g/N9w09jE33G02pJDFnrAxqen56er69bWaF1aNrfd+c7xHkDNrv4i8ydL73y8 r+pGs/9OkpZGMS4GGTFFFm6H/BsK/CJsi0QKPSFmcPKBDKEgYtTACbyU5mRYe2mb8yC/m483tvu fo22+ijgqelmff7Oxx8+cQrvzO7NDmP473J16dm3EYtL1u6IWfOC47mE61d91Su7V677zTz1Jud zCyYA X-Developer-Key: i=troy.mitchell@linux.dev; a=openpgp; fpr=3FE5535CF1B0E658E57DB59BAE1C2FBEA7DB42E1 The devicetree CPU map can distinguish packages and clusters but cannot describe multiple dies in one package. Such systems have to flatten all clusters into the package, making cluster identifiers package-wide and hiding the die boundary. Recognize an optional sequence of dieN nodes between a socket and its clusters, and propagate the die identifier to every CPU below it. Enumerate clusters independently below each die. When a CPU map has no dieN nodes, continue parsing its existing package and cluster hierarchy but pass -1 as the die identifier. Legacy maps therefore remain compatible without being reported as an explicitly described die 0. Signed-off-by: Troy Mitchell --- drivers/base/arch_topology.c | 48 +++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index ee82827be3351..67a984f3ba8d9 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -498,7 +498,7 @@ static int __init get_cpu_for_node(struct device_node *= node) } =20 static int __init parse_core(struct device_node *core, int package_id, - int cluster_id, int core_id) + int die_id, int cluster_id, int core_id) { char name[20]; bool leaf =3D true; @@ -517,6 +517,7 @@ static int __init parse_core(struct device_node *core, = int package_id, cpu =3D get_cpu_for_node(t); if (cpu >=3D 0) { cpu_topology[cpu].package_id =3D package_id; + cpu_topology[cpu].die_id =3D die_id; cpu_topology[cpu].cluster_id =3D cluster_id; cpu_topology[cpu].core_id =3D core_id; cpu_topology[cpu].thread_id =3D i; @@ -538,6 +539,7 @@ static int __init parse_core(struct device_node *core, = int package_id, } =20 cpu_topology[cpu].package_id =3D package_id; + cpu_topology[cpu].die_id =3D die_id; cpu_topology[cpu].cluster_id =3D cluster_id; cpu_topology[cpu].core_id =3D core_id; } else if (leaf && cpu !=3D -ENODEV) { @@ -549,7 +551,7 @@ static int __init parse_core(struct device_node *core, = int package_id, } =20 static int __init parse_cluster(struct device_node *cluster, int package_i= d, - int cluster_id, int depth) + int die_id, int cluster_id, int depth) { char name[20]; bool leaf =3D true; @@ -572,7 +574,7 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, break; =20 leaf =3D false; - ret =3D parse_cluster(c, package_id, i, depth + 1); + ret =3D parse_cluster(c, package_id, die_id, i, depth + 1); if (depth > 0) pr_warn("Topology for clusters of clusters not yet supported\n"); if (ret !=3D 0) @@ -598,7 +600,8 @@ static int __init parse_cluster(struct device_node *clu= ster, int package_id, } =20 if (leaf) { - ret =3D parse_core(c, package_id, cluster_id, core_id++); + ret =3D parse_core(c, package_id, die_id, cluster_id, + core_id++); if (ret !=3D 0) return ret; } else { @@ -616,6 +619,34 @@ static int __init parse_cluster(struct device_node *cl= uster, int package_id, return 0; } =20 +static int __init parse_die(struct device_node *parent, int package_id) +{ + char name[20]; + bool has_die =3D false; + int die_id =3D 0, ret; + + do { + snprintf(name, sizeof(name), "die%d", die_id); + struct device_node *d __free(device_node) =3D + of_get_child_by_name(parent, name); + + if (!d) + break; + + has_die =3D true; + ret =3D parse_cluster(d, package_id, die_id, -1, 0); + if (ret) + return ret; + + die_id++; + } while (1); + + if (!has_die) + ret =3D parse_cluster(parent, package_id, -1, -1, 0); + + return ret; +} + static int __init parse_socket(struct device_node *socket) { char name[20]; @@ -631,7 +662,7 @@ static int __init parse_socket(struct device_node *sock= et) break; =20 has_socket =3D true; - ret =3D parse_cluster(c, package_id, -1, 0); + ret =3D parse_die(c, package_id); if (ret !=3D 0) return ret; =20 @@ -639,7 +670,7 @@ static int __init parse_socket(struct device_node *sock= et) } while (1); =20 if (!has_socket) - ret =3D parse_cluster(socket, 0, -1, 0); + ret =3D parse_die(socket, 0); =20 /* * Reset the max_smt_thread_num to 1 on failure. Since on failure @@ -667,10 +698,7 @@ static int __init parse_dt_topology(void) return 0; } =20 - /* - * When topology is provided cpu-map is essentially a root - * cluster with restricted subnodes. - */ + /* cpu-map is the root of the processor topology hierarchy. */ struct device_node *map __free(device_node) =3D of_get_child_by_name(cn, "cpu-map"); =20 --=20 2.55.0 From nobody Thu Sep 24 21:19:45 2026 Received: from mta0.migadu.com (out-161.mta0.migadu.com [91.218.175.161]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 575063BB12A for ; Sun, 20 Sep 2026 03:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.161 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874328; cv=none; b=YkB+kU+B5/rEMbv5SjH0dGBFywhnhjSbIwuo1tLq8YQvM6iVri5DmUCqUuKN6TeOOAmxDofNv0HdY3qZmnH+5EyYQTXyFsy0Lwfj01+FaLjyHf96bc3DQvjQYLMBWRsXb5pWsgSNPwMMU6CGh3H91HxV12rrL8SKAuinxm3H4r8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789874328; c=relaxed/simple; bh=8qDy+DqOKnUJZTNHAtWwrfSexO/G9mwrT+liXKYn3E8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TiTHsMiXG3o82RJRRsdC1BqAcyidnIxtgOVQw6EfkAFL14SlL3RQzi4BynchZg1kEfzy1KENtcmDqt8oMjXVdMQCqrf2Uh5J70aw0ZQ1TyPreWpMIXM2L2nQ/MKne7LfccA/oVG2OsQDHgtW4nt4SDqaLfW+fI1WiTic4SS78Ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XUagWimW; arc=none smtp.client-ip=91.218.175.161 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XUagWimW" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=8qDy+DqOKnUJZTNHAtWwrfSexO/G9mwrT+liXKYn3E8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789874323; v=1; x=1790479123; b=XUagWimWY1OpQwjkVhWz4/hu6rrtDujFtW9xyxvxoNQD8smrurJxjOefAAXNjqRiSb62vhys q7CyWLsN3QyEOtXH+3TrU4yOAuJoJPc9p6gHSo0kmFYkRHi3zrC+bEa50uaVDkmntV5NCSqTHCF v6o+tN3I153kenU39IQ0Q9LE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta12.migadu.com with ESMTPS id af7475f348ddaa80; Sun, 20 Sep 2026 03:18:43 +0000 X-Mizu-Trace-ID: af7475f348ddaa80 X-Migadu-Flow: FLOW_OUT From: Troy Mitchell Date: Sun, 20 Sep 2026 11:18:04 +0800 Subject: [PATCH RFC 3/3] riscv: topology: Expose explicit CPU die topology Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-riscv-die-topology-rfc-v1-3-071c0bf61d5f@linux.dev> References: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> In-Reply-To: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev> To: Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: Catalin Marinas , Will Deacon , Mark Rutland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Troy Mitchell X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3696; i=troy.mitchell@linux.dev; h=from:subject:message-id; bh=8qDy+DqOKnUJZTNHAtWwrfSexO/G9mwrT+liXKYn3E8=; b=owGbwMvMwCU2g/N9w09jE33G02pJDFnrAxqfHg36OtFsBf+qk4LF/5dO8c4WXq9/Y5qW6Ladb 89prfKa2lHKwiDGxSArpsjS/YBnW4FPlG2BQKEvzBxWJpAhDFycAjCRug6Gv1I27otKp1RvUgqa 6l1ScmpXBM8S2QszNQLlnSZV9z5X38HwV0Zr61xJX372Vhn7IleB4gPVxzKSv+z/feX5pbV50Ut r2AA= X-Developer-Key: i=troy.mitchell@linux.dev; a=openpgp; fpr=3FE5535CF1B0E658E57DB59BAE1C2FBEA7DB42E1 RISC-V uses the generic CPU topology model but does not provide die topology accessors. The generic sysfs topology code consequently cannot expose die identifiers or die sibling masks when firmware describes them. Simply adding the accessors would create die_id, die_cpus, and die_cpus_list on every RISC-V CPU. That would also expose -1 and a single-CPU mask when neither DT nor ACPI supplied a die hierarchy. Add an architecture-selectable visibility predicate for the die sysfs attributes. Its default preserves the existing sysfs ABI on architectures that already expose die topology. Make RISC-V expose the attributes only when the generic topology parser recorded a non-negative die ID. Legacy DTs, the current ACPI path, and the fallback topology leave die_id at -1, so RISC-V does not create die sysfs files for them. Signed-off-by: Troy Mitchell --- arch/riscv/include/asm/topology.h | 4 ++++ drivers/base/topology.c | 28 +++++++++++++++++++++++++++- include/linux/topology.h | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/topology.h b/arch/riscv/include/asm/top= ology.h index fe1a8bf6902d9..5d99cb39f2819 100644 --- a/arch/riscv/include/asm/topology.h +++ b/arch/riscv/include/asm/topology.h @@ -8,6 +8,10 @@ #include #endif =20 +#define topology_die_id(cpu) (cpu_topology[cpu].die_id) +#define topology_die_cpumask(cpu) (&cpu_topology[cpu].die_sibling) +#define topology_die_sysfs_visible(cpu) (topology_die_id(cpu) >=3D 0) + /* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_tick topology_scale_freq_tick #define arch_set_freq_scale topology_set_freq_scale diff --git a/drivers/base/topology.c b/drivers/base/topology.c index c890e2a5b4280..74d5bb979b1b8 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -171,16 +171,42 @@ static struct attribute *default_attrs[] =3D { static umode_t topology_is_visible(struct kobject *kobj, struct attribute *attr, int unused) { - if (attr =3D=3D &dev_attr_ppin.attr && !topology_ppin(kobj_to_dev(kobj)->= id)) + unsigned int cpu =3D kobj_to_dev(kobj)->id; + +#ifdef TOPOLOGY_DIE_SYSFS + if (attr =3D=3D &dev_attr_die_id.attr && + !topology_die_sysfs_visible(cpu)) + return 0; +#endif + + if (attr =3D=3D &dev_attr_ppin.attr && !topology_ppin(cpu)) return 0; =20 return attr->mode; } =20 +#ifdef TOPOLOGY_DIE_SYSFS +static umode_t topology_bin_is_visible(struct kobject *kobj, + const struct bin_attribute *attr, int unused) +{ + unsigned int cpu =3D kobj_to_dev(kobj)->id; + + if ((attr =3D=3D &bin_attr_die_cpus || + attr =3D=3D &bin_attr_die_cpus_list) && + !topology_die_sysfs_visible(cpu)) + return 0; + + return attr->attr.mode; +} +#endif + static const struct attribute_group topology_attr_group =3D { .attrs =3D default_attrs, .bin_attrs =3D bin_attrs, .is_visible =3D topology_is_visible, +#ifdef TOPOLOGY_DIE_SYSFS + .is_bin_visible =3D topology_bin_is_visible, +#endif .name =3D "topology" }; =20 diff --git a/include/linux/topology.h b/include/linux/topology.h index 709a2dcf4c738..9c2c9096aff36 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -179,6 +179,9 @@ static inline int cpu_to_mem(int cpu) =20 #if defined(topology_die_id) && defined(topology_die_cpumask) #define TOPOLOGY_DIE_SYSFS +#ifndef topology_die_sysfs_visible +#define topology_die_sysfs_visible(cpu) ((void)(cpu), true) +#endif #endif #if defined(topology_cluster_id) && defined(topology_cluster_cpumask) #define TOPOLOGY_CLUSTER_SYSFS --=20 2.55.0