From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
driver-core@lists.linux.dev
Cc: sshegde@linux.ibm.com, christophe.leroy@csgroup.eu,
maddy@linux.ibm.com, gregkh@linuxfoundation.org,
rafael@kernel.org, dakr@kernel.org, johan@kernel.org,
sudeep.holla@kernel.org, ritesh.list@gmail.com,
tim.c.chen@linux.intel.com, yu.c.chen@intel.com
Subject: [PATCH 1/5] cacheinfo: Allow architectures to provide custom cache IDs
Date: Wed, 18 Nov 2026 22:06:35 +0530 [thread overview]
Message-ID: <20261118163639.890546-2-sshegde@linux.ibm.com> (raw)
In-Reply-To: <20261118163639.890546-1-sshegde@linux.ibm.com>
On PowerPC, a firmware cache node does not always correspond to a single
hardware cache instance.
For example, a Power11 CPU device-tree node can describe eight threads
and refer to one L2 and L3 cache-node chain:
CPU node (0-7)
l2-cache = <L2 node>
L2 node
l2-cache = <L3 node>
At the same time, the ibm,thread-groups property divides those threads
into two groups, such as:
0,2,4,6
1,3,5,7
Each group represents a separate hardware cache instance, even though
both groups refer to the same firmware L2 and L3 cache nodes.
Generic cacheinfo currently derives the cache ID from the firmware cache
node. It would therefore assign the same ID to both groups and incorrectly
represent all eight threads as sharing one cache.
Allow an architecture to provide the cache ID for a CPU and cache level.
When the architecture supplies an ID, use it instead of deriving one from
the firmware cache node. Otherwise, retain the existing generic behavior.
[Both draft changelog and code are written by LLM]
Assisted-by: LLM
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
drivers/base/cacheinfo.c | 43 +++++++++++++++++++++++++++++++--------
include/linux/cacheinfo.h | 1 +
2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index eb8a907f6d50..10a9bbce899e 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -243,22 +243,46 @@ static bool match_cache_node(struct device_node *cpu,
#define arch_compact_of_hwid(_x) (_x)
#endif
+/*
+ * Return an architecture-specific cache ID for @cpu and @level.
+ *
+ * Return 0 and store the ID in @id when the architecture provides the
+ * cache identity. Return an error to use the generic firmware-derived
+ * cache ID instead.
+ *
+ * The ID must uniquely identify a cache among caches of the same level
+ * and type.
+ */
+int __weak cacheinfo_get_arch_id(unsigned int cpu, unsigned int level,
+ unsigned int *id)
+{
+ return -ENOENT;
+}
+
static void cache_of_set_id(struct cacheinfo *this_leaf,
- struct device_node *cache_node)
+ struct device_node *cache_node,
+ unsigned int cpu)
{
- struct device_node *cpu;
+ struct device_node *cpu_node;
u32 min_id = ~0;
+ unsigned int arch_id;
+
+ if (!cacheinfo_get_arch_id(cpu, this_leaf->level, &arch_id)) {
+ this_leaf->id = arch_id;
+ this_leaf->attributes |= CACHE_ID;
+ return;
+ }
- for_each_of_cpu_node(cpu) {
- u64 id = of_get_cpu_hwid(cpu, 0);
+ for_each_of_cpu_node(cpu_node) {
+ u64 id = of_get_cpu_hwid(cpu_node, 0);
id = arch_compact_of_hwid(id);
if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
- of_node_put(cpu);
+ of_node_put(cpu_node);
return;
}
- if (match_cache_node(cpu, cache_node))
+ if (match_cache_node(cpu_node, cache_node))
min_id = min(min_id, id);
}
@@ -269,7 +293,8 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
}
static void cache_of_set_props(struct cacheinfo *this_leaf,
- struct device_node *np)
+ struct device_node *np,
+ unsigned int cpu)
{
/*
* init_cache_level must setup the cache level correctly
@@ -283,7 +308,7 @@ static void cache_of_set_props(struct cacheinfo *this_leaf,
cache_get_line_size(this_leaf, np);
cache_nr_sets(this_leaf, np);
cache_associativity(this_leaf);
- cache_of_set_id(this_leaf, np);
+ cache_of_set_id(this_leaf, np, cpu);
}
static int cache_setup_of_node(unsigned int cpu)
@@ -309,7 +334,7 @@ static int cache_setup_of_node(unsigned int cpu)
if (!np)
break;
}
- cache_of_set_props(this_leaf, np);
+ cache_of_set_props(this_leaf, np, cpu);
this_leaf->fw_token = np;
index++;
}
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index 56fa646df0d1..d3557a1b464b 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -93,6 +93,7 @@ bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y);
struct cacheinfo *get_cpu_cacheinfo_llc(unsigned int cpu);
int fetch_cache_info(unsigned int cpu);
int detect_cache_attributes(unsigned int cpu);
+int cacheinfo_get_arch_id(unsigned int cpu, unsigned int level, unsigned int *id);
#ifndef CONFIG_ACPI_PPTT
/*
* acpi_get_cache_info() is only called on ACPI enabled
--
2.54.0
next prev parent reply other threads:[~2026-11-18 16:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 16:36 [PATCH 0/5] cacheinfo, powerpc: Move powerpc to generic cacheinfo Shrikanth Hegde
2026-11-18 16:36 ` Shrikanth Hegde [this message]
2026-11-18 16:36 ` [PATCH 2/5] cacheinfo: Support unified caches described by d-cache properties Shrikanth Hegde
2026-11-18 16:36 ` [PATCH 3/5] cacheinfo: Add teardown and rebuild helpers Shrikanth Hegde
2026-11-18 16:36 ` [PATCH 4/5] powerpc/cacheinfo: Move to generic cacheinfo Shrikanth Hegde
2026-11-18 16:36 ` [PATCH 5/5] sched/topology: Remove stale comment around llc_bytes on powerpc Shrikanth Hegde
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=20261118163639.890546-2-sshegde@linux.ibm.com \
--to=sshegde@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=rafael@kernel.org \
--cc=ritesh.list@gmail.com \
--cc=sudeep.holla@kernel.org \
--cc=tim.c.chen@linux.intel.com \
--cc=yu.c.chen@intel.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®