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

Peter Newman
2023-04-21T14:18:52Z

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(-)

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().
--
2.40.0.634.g4ca3ef3211-goog