[PATCH v3 26/47] arm_mpam: resctrl: Wait for cacheinfo to be ready

Ben Horgan posted 47 patches 4 weeks ago
There is a newer version of this series
[PATCH v3 26/47] arm_mpam: resctrl: Wait for cacheinfo to be ready
Posted by Ben Horgan 4 weeks ago
In order to calculate the rmid realloc threshold the size of the cache
needs to be known. Cache domains will also be named after the cache id. So
that this information can be extracted from cacheinfo we need to wait for
it to be ready. The cacheinfo information is populated in device_initcall()
so we wait for that.

Signed-off-by: James Morse <james.morse@arm.com>
[horgan: split out from another patch]
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
---
This is moved into it's own patch to allow all uses of cacheinfo to be
valid when they are introduced.
---
 drivers/resctrl/mpam_resctrl.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 92b2a2d4b51d..3ca977527698 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -16,6 +16,7 @@
 #include <linux/resctrl.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 
 #include <asm/mpam.h>
 
@@ -45,6 +46,13 @@ static bool exposed_mon_capable;
  */
 static bool cdp_enabled;
 
+/*
+ * We use cacheinfo to discover the size of the caches and their id. cacheinfo
+ * populates this from a device_initcall(). mpam_resctrl_setup() must wait.
+ */
+static bool cacheinfo_ready;
+static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready);
+
 bool resctrl_arch_alloc_capable(void)
 {
 	return exposed_alloc_capable;
@@ -745,6 +753,8 @@ int mpam_resctrl_setup(void)
 	struct mpam_resctrl_res *res;
 	enum resctrl_res_level rid;
 
+	wait_event(wait_cacheinfo_ready, cacheinfo_ready);
+
 	cpus_read_lock();
 	for_each_mpam_resctrl_control(res, rid) {
 		INIT_LIST_HEAD_RCU(&res->resctrl_res.ctrl_domains);
@@ -784,6 +794,15 @@ int mpam_resctrl_setup(void)
 	return 0;
 }
 
+static int __init __cacheinfo_ready(void)
+{
+	cacheinfo_ready = true;
+	wake_up(&wait_cacheinfo_ready);
+
+	return 0;
+}
+device_initcall_sync(__cacheinfo_ready);
+
 #ifdef CONFIG_MPAM_KUNIT_TEST
 #include "test_mpam_resctrl.c"
 #endif
-- 
2.43.0
Re: [PATCH v3 26/47] arm_mpam: resctrl: Wait for cacheinfo to be ready
Posted by Jonathan Cameron 3 weeks, 6 days ago
On Mon, 12 Jan 2026 16:58:53 +0000
Ben Horgan <ben.horgan@arm.com> wrote:

> In order to calculate the rmid realloc threshold the size of the cache
> needs to be known. Cache domains will also be named after the cache id. So
> that this information can be extracted from cacheinfo we need to wait for
> it to be ready. The cacheinfo information is populated in device_initcall()
> so we wait for that.
> 
> Signed-off-by: James Morse <james.morse@arm.com>
> [horgan: split out from another patch]
> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
> ---
> This is moved into it's own patch to allow all uses of cacheinfo to be
> valid when they are introduced.

I don't mind the patch but I'm not entirely following this comment. Is
the point that previously there was a sneaky user before this was added in
the series?

Anyhow, that's not in the patch itself so
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Re: [PATCH v3 26/47] arm_mpam: resctrl: Wait for cacheinfo to be ready
Posted by Ben Horgan 3 weeks, 6 days ago
Hi Jonathan,

On 1/13/26 15:01, Jonathan Cameron wrote:
> On Mon, 12 Jan 2026 16:58:53 +0000
> Ben Horgan <ben.horgan@arm.com> wrote:
> 
>> In order to calculate the rmid realloc threshold the size of the cache
>> needs to be known. Cache domains will also be named after the cache id. So
>> that this information can be extracted from cacheinfo we need to wait for
>> it to be ready. The cacheinfo information is populated in device_initcall()
>> so we wait for that.
>>
>> Signed-off-by: James Morse <james.morse@arm.com>
>> [horgan: split out from another patch]
>> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
>> ---
>> This is moved into it's own patch to allow all uses of cacheinfo to be
>> valid when they are introduced.
> 
> I don't mind the patch but I'm not entirely following this comment. Is
> the point that previously there was a sneaky user before this was added in
> the series?

Yes, arm_mpam: resctrl: Add support for 'MB' resource, accesses
cacheinfo so wanted to order this patch before that.

> 
> Anyhow, that's not in the patch itself so
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

Thanks,

Ben