Re: [PATCH RFC 02/15] cacheinfo: Expose the code to generate a cache-id from a device_node
From: Yin Li
Date: Mon Aug 31 2026 - 01:44:27 EST
On 8/26/2026 3:11 AM, Drew Fustini wrote:
On Tue, Aug 11, 2026 at 09:30:31PM +0800, Yin Li wrote:
From: James Morse <james.morse@xxxxxxx>
The MPAM driver identifies caches by id for use with resctrl. It
needs to know the cache-id when probe-ing, but the value isn't set
in cacheinfo until device_initcall(). Even after device_initcall(),
the cache-id is only available if at least one CPU associated with
the cache is online.
Instead of making the driver wait, expose the code that generates the
cache-id. The parts of the MPAM driver that run early can use this to
set up the resctrl structures before cacheinfo is ready in
device_initcall().
This patch would also be helpful for resctrl support on RISC-V, too. The
probe function in the CBQRI capacity allocation platform driver [1] has
the same problem. The current solution is to scan the online CPUs for a
cacheinfo leaf whose fw_token is the cache node from the phandle.
However, that does not work if no cpu sharing that cache is online yet.
Hi Drew,
Thanks for the review.
Good to know that cache_of_calculate_id() could help with the RISC-V
CBQRI driver as well. Since the function is guarded by CONFIG_OF in
cacheinfo.h, it should be available on DT-based RISC-V platforms
without any issue. You're welcome to use it.
[..]
+u32 cache_of_calculate_id(struct device_node *cache_node)
{
struct device_node *cpu;
u32 min_id = ~0;
@@ -238,15 +237,23 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
id = arch_compact_of_hwid(id);
if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
of_node_put(cpu);
- return;
+ return ~0;
Maybe this should be U32_MAX instead?
Regarding the ~0 vs U32_MAX point:
You're right that U32_MAX is more appropriate than ~0 here. This is
addressed in patch 06/15 ("arm_mpam: Fix cache ID sentinel from ~0UL
to U32_MAX to match u32 return type").
https://lore.kernel.org/all/20260811-mpam-resctrl-dt-knp-support-v1-6-ea6397bead59@xxxxxxxxxxxxxxxx/
The fix is in a separate patch because this patch is based on James
Morse's original unmerged work — I kept my fixes separate for easier
review. The plan is to fold them back in once James has responded.
Thanks,
Drew
[1] https://lore.kernel.org/all/20260729-dfustini-atl-sc-cbqri-dt-v6-8-7c22b05d461b@xxxxxxxxxx/
--
Thx and BRs,
Yin