From: Troy Mitchell <troy.mitchell@linux.dev>
To: Sudeep Holla <sudeep.holla@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
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 <troy.mitchell@linux.dev>
Subject: [PATCH RFC 3/3] riscv: topology: Expose explicit CPU die topology
Date: Sun, 20 Sep 2026 11:18:04 +0800 [thread overview]
Message-ID: <20260920-riscv-die-topology-rfc-v1-3-071c0bf61d5f@linux.dev> (raw)
In-Reply-To: <20260920-riscv-die-topology-rfc-v1-0-071c0bf61d5f@linux.dev>
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 <troy.mitchell@linux.dev>
---
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/topology.h
index fe1a8bf6902d9..5d99cb39f2819 100644
--- a/arch/riscv/include/asm/topology.h
+++ b/arch/riscv/include/asm/topology.h
@@ -8,6 +8,10 @@
#include <asm/numa.h>
#endif
+#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) >= 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[] = {
static umode_t topology_is_visible(struct kobject *kobj,
struct attribute *attr, int unused)
{
- if (attr == &dev_attr_ppin.attr && !topology_ppin(kobj_to_dev(kobj)->id))
+ unsigned int cpu = kobj_to_dev(kobj)->id;
+
+#ifdef TOPOLOGY_DIE_SYSFS
+ if (attr == &dev_attr_die_id.attr &&
+ !topology_die_sysfs_visible(cpu))
+ return 0;
+#endif
+
+ if (attr == &dev_attr_ppin.attr && !topology_ppin(cpu))
return 0;
return attr->mode;
}
+#ifdef TOPOLOGY_DIE_SYSFS
+static umode_t topology_bin_is_visible(struct kobject *kobj,
+ const struct bin_attribute *attr, int unused)
+{
+ unsigned int cpu = kobj_to_dev(kobj)->id;
+
+ if ((attr == &bin_attr_die_cpus ||
+ attr == &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 = {
.attrs = default_attrs,
.bin_attrs = bin_attrs,
.is_visible = topology_is_visible,
+#ifdef TOPOLOGY_DIE_SYSFS
+ .is_bin_visible = topology_bin_is_visible,
+#endif
.name = "topology"
};
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)
#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
--
2.55.0
prev parent reply other threads:[~2026-09-20 3:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 3:18 [PATCH RFC 0/3] riscv: Add explicit die-level CPU topology Troy Mitchell
2026-09-20 3:18 ` [PATCH RFC 1/3] arch_topology: Add a die level to " Troy Mitchell
2026-09-20 3:18 ` [PATCH RFC 2/3] arch_topology: Parse die nodes in /cpu-map Troy Mitchell
2026-09-21 11:14 ` Sudeep Holla
2026-09-22 8:06 ` Troy Mitchell
2026-09-20 3:18 ` Troy Mitchell [this message]
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=20260920-riscv-die-topology-rfc-v1-3-071c0bf61d5f@linux.dev \
--to=troy.mitchell@linux.dev \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sudeep.holla@kernel.org \
--cc=will@kernel.org \
/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