Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Jinjie Ruan <ruanjinjie@huawei.com>, <ben.horgan@arm.com>,
	<james.morse@arm.com>, <Dave.Martin@arm.com>,
	<fenghuay@nvidia.com>
Cc: <tony.luck@intel.com>, <yu.c.chen@intel.com>,
	<babu.moger@amd.com>, <fustini@kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <patches@lists.linux.dev>
Subject: Re: [RFC PATCH v2 05/10] arm_mpam: resctrl: Give the monitoring domain its own structure
Date: Mon, 26 Oct 2026 09:55:19 -0700	[thread overview]
Message-ID: <f288691b-6064-456e-89fc-2c4b2e6712b6@intel.com> (raw)
In-Reply-To: <52fdd67b-49b6-44b6-8eaa-17b29fd92947@huawei.com>

Hi Jinjie,

On 10/26/26 5:14 AM, Jinjie Ruan wrote:
> 在 2026/10/20 6:07, Reinette Chatre 写道:

...

>> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
>> index 246560247a28..ce5519635c51 100644
>> --- a/drivers/resctrl/mpam_resctrl.c
>> +++ b/drivers/resctrl/mpam_resctrl.c

...

>> @@ -542,7 +542,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
>>  			   enum resctrl_event_id eventid, u64 *val)
>>  {
>>  	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
>> -	struct mpam_resctrl_dom *l3_dom;
>> +	struct mpam_resctrl_mon_dom *l3_dom;
>>  	struct mpam_component *mon_comp;
>>  
>>  	if (!mpam_is_enabled())
>> @@ -551,7 +551,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
>>  	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
>>  		return -EINVAL;
>>  
>> -	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
>> +	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
>>  	mon_comp = l3_dom->mon_comp[eventid];
> 
> Maybe following code could be extracted into a helper
> 
> 553 >-------if (!mpam_is_enabled())
>  554 >------->-------return -EINVAL;
>  555
>  556 >-------if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
>  557 >------->-------return -EINVAL;
>  558
>  559 >-------l3_dom = container_of(d, struct mpam_resctrl_dom,
> resctrl_mon_dom);
>  560 >-------mon_comp = l3_dom->mon_comp[eventid];
> 

Below shows an example of such helper created (for convenience) on top of this
series. Only compile tested. Is this what you had in mind? If it looks ok I will
rebase to the beginning of this series as a new preparatory patch since it refactors
code adjacent to this series.

---8<---
 drivers/resctrl/mpam_resctrl.c | 62 ++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 21 deletions(-)

diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 61fbde9c0960..d75954f8a0ad 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -7,6 +7,7 @@
 #include <linux/cacheinfo.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <linux/list.h>
@@ -536,26 +537,51 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 				 closid, rmid, val);
 }
 
-/* MBWU counters when in ABMC mode */
-int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
-			   u32 closid, u32 rmid, int mon_idx,
-			   enum resctrl_event_id eventid, u64 *val)
+/**
+ * find_mbwu_mon_comp() - Find the component counting @eventid in a domain
+ * @d:		The monitoring domain to search.
+ * @eventid:	The event to find the counting component for.
+ *
+ * The counters reached through this component are the monitors MPAM
+ * pre-allocated for bandwidth counting. Cache occupancy is not counted by
+ * those monitors, it is read on demand via resctrl_arch_rmid_read().
+ *
+ * Return: the component counting @eventid in @d, or an error pointer when
+ * MPAM is disabled, when @eventid is cache occupancy, or when no class was
+ * picked to count @eventid.
+ */
+static struct mpam_component *find_mbwu_mon_comp(struct rdt_l3_mon_domain *d,
+						 enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
 	struct mpam_resctrl_mon_dom *l3_dom;
-	struct mpam_component *mon_comp;
+	struct mpam_resctrl_mon *mon;
 
 	if (!mpam_is_enabled())
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
+	mon = &mpam_resctrl_counters[eventid];
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
 
-	return read_mon_cdp_safe(mon, mon_comp, mpam_feat_msmon_mbwu,
-				 USE_PRE_ALLOCATED, closid, rmid, val);
+	return l3_dom->mon_comp[eventid];
+}
+
+/* MBWU counters when in ABMC mode */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			   u32 closid, u32 rmid, int mon_idx,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	struct mpam_component *mon_comp;
+
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
+		return PTR_ERR(mon_comp);
+
+	return read_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+				 mpam_feat_msmon_mbwu, USE_PRE_ALLOCATED,
+				 closid, rmid, val);
 }
 
 static void __reset_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
@@ -598,20 +624,14 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 			     u32 closid, u32 rmid, int cntr_id,
 			     enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
-	if (!mpam_is_enabled())
-		return;
-
-	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
 		return;
 
-	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
-
-	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
+	reset_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+			   USE_PRE_ALLOCATED, closid, rmid);
 }
 
 /*
---8<--- 

>> @@ -1770,11 +1723,97 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
>>  			return dom;
>>  	}
>>  
>> -	if (r->rid != RDT_RESOURCE_L3)
>> -		return NULL;
>> +	return NULL;
> 
> LGTM
> Reviewed-by: Jinjie Ruan <ruanjinjie@huawei.com>
> 
Thank you very much.

Reinette



  reply	other threads:[~2026-10-26 16:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 22:07 [RFC PATCH v2 00/10] arm_mpam: resctrl: Separate MPAM domains Reinette Chatre
2026-10-19 22:07 ` [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain Reinette Chatre
2026-10-23  8:07   ` Jinjie Ruan
2026-10-23 14:52     ` Reinette Chatre
2026-10-19 22:07 ` [RFC PATCH v2 02/10] arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain() Reinette Chatre
2026-10-23  8:08   ` Jinjie Ruan
2026-10-23 14:53     ` Reinette Chatre
2026-10-19 22:07 ` [RFC PATCH v2 03/10] arm_mpam: resctrl: Do not fail CPU online when domain setup fails Reinette Chatre
2026-10-26  9:51   ` Jinjie Ruan
2026-10-19 22:07 ` [RFC PATCH v2 04/10] arm_mpam: resctrl: Split control and monitoring domain setup into helpers Reinette Chatre
2026-10-26 11:49   ` Jinjie Ruan
2026-10-19 22:07 ` [RFC PATCH v2 05/10] arm_mpam: resctrl: Give the monitoring domain its own structure Reinette Chatre
2026-10-26 12:14   ` Jinjie Ruan
2026-10-26 16:55     ` Reinette Chatre [this message]
2026-10-27  1:12       ` Jinjie Ruan
2026-10-19 22:07 ` [RFC PATCH v2 06/10] arm_mpam: resctrl: Rename struct mpam_resctrl_dom to mpam_resctrl_ctrl_dom Reinette Chatre
2026-10-26 12:40   ` Jinjie Ruan
2026-10-19 22:07 ` [RFC PATCH v2 07/10] arm_mpam: resctrl: Warn when no monitoring component is found for a CPU Reinette Chatre
2026-10-26 13:14   ` Jinjie Ruan
2026-10-19 22:07 ` [RFC PATCH v2 08/10] arm_mpam: resctrl: Require a component for each monitoring event Reinette Chatre
2026-10-19 22:07 ` [RFC PATCH v2 09/10] arm_mpam: resctrl: Require monitoring components to cover the same CPUs Reinette Chatre
2026-10-19 22:07 ` [RFC PATCH v2 10/10] arm_mpam: resctrl: Update the comment on monitoring domain setup Reinette Chatre
2026-10-22 10:45 ` [RFC PATCH v2 00/10] arm_mpam: resctrl: Separate MPAM domains Ben Horgan
2026-10-22 15:43   ` Reinette Chatre

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=f288691b-6064-456e-89fc-2c4b2e6712b6@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=ruanjinjie@huawei.com \
    --cc=tony.luck@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