diff mbox series

[v1,6/9] x86/resctrl: Create soft RMID version of __mon_event_count()

Message ID 20230421141723.2405942-7-peternewman@google.com (mailing list archive)
State New
Headers show
Series x86/resctrl: Use soft RMIDs for reliable MBM on AMD | expand

Commit Message

Peter Newman April 21, 2023, 2:17 p.m. UTC
When RMIDs are soft, __mon_event_count() only needs to report the
current byte count in memory and should not touch the hardware RMIDs.

Create a parallel version for the soft RMID configuration and update
__mon_event_count() to choose between it and the original depending on
whether the soft RMID static key is enabled.

Signed-off-by: Peter Newman <peternewman@google.com>
---
 arch/x86/kernel/cpu/resctrl/monitor.c | 33 ++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Reinette Chatre May 11, 2023, 9:38 p.m. UTC | #1
Hi Peter,

On 4/21/2023 7:17 AM, Peter Newman wrote:
> When RMIDs are soft, __mon_event_count() only needs to report the
> current byte count in memory and should not touch the hardware RMIDs.
> 
> Create a parallel version for the soft RMID configuration and update
> __mon_event_count() to choose between it and the original depending on
> whether the soft RMID static key is enabled.

Please note that the changelog refers to "whether the soft RMID static
key is enabled" but the patch uses a bool instead of a static key.

> 
> Signed-off-by: Peter Newman <peternewman@google.com>
> ---
>  arch/x86/kernel/cpu/resctrl/monitor.c | 33 ++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
> index bb857eefa3b0..3d54a634471a 100644
> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
> @@ -487,7 +487,30 @@ void resctrl_mbm_flush_cpu(void)
>  		__mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d);
>  }
>  
> -static int __mon_event_count(u32 rmid, struct rmid_read *rr)
> +static int __mon_event_count_soft_rmid(u32 rmid, struct rmid_read *rr)
> +{
> +	struct mbm_state *m;
> +
> +	WARN_ON(!is_mbm_event(rr->evtid));
> +	m = get_mbm_state(rr->d, rmid, rr->evtid);
> +	if (!m)
> +		/* implies !is_mbm_event(...) */
> +		return -1;
> +
> +	rr->val += atomic64_read(&m->soft_rmid_bytes);
> +
> +	if (rr->first) {
> +		/*
> +		 * Discard any bandwidth resulting from the initial HW counter
> +		 * reads.
> +		 */
> +		atomic64_set(&m->soft_rmid_bytes, 0);
> +	}

The above is not clear to me. If rr->first is true then it would read
soft_rmid_bytes and then immediately reset it? 


Reinette
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index bb857eefa3b0..3d54a634471a 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -487,7 +487,30 @@  void resctrl_mbm_flush_cpu(void)
 		__mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d);
 }
 
-static int __mon_event_count(u32 rmid, struct rmid_read *rr)
+static int __mon_event_count_soft_rmid(u32 rmid, struct rmid_read *rr)
+{
+	struct mbm_state *m;
+
+	WARN_ON(!is_mbm_event(rr->evtid));
+	m = get_mbm_state(rr->d, rmid, rr->evtid);
+	if (!m)
+		/* implies !is_mbm_event(...) */
+		return -1;
+
+	rr->val += atomic64_read(&m->soft_rmid_bytes);
+
+	if (rr->first) {
+		/*
+		 * Discard any bandwidth resulting from the initial HW counter
+		 * reads.
+		 */
+		atomic64_set(&m->soft_rmid_bytes, 0);
+	}
+
+	return 0;
+}
+
+static int __mon_event_count_default(u32 rmid, struct rmid_read *rr)
 {
 	struct mbm_state *m;
 	u64 tval = 0;
@@ -509,6 +532,14 @@  static int __mon_event_count(u32 rmid, struct rmid_read *rr)
 	return 0;
 }
 
+static int __mon_event_count(u32 rmid, struct rmid_read *rr)
+{
+	if (rdt_mon_soft_rmid)
+		return __mon_event_count_soft_rmid(rmid, rr);
+	else
+		return __mon_event_count_default(rmid, rr);
+}
+
 /*
  * mbm_bw_count() - Update bw count from values previously read by
  *		    __mon_event_count().