[RFC PATCH 14/17] x86/resctrl: Add code in rdtgroup_mondata_show() for core monitor events

Tony Luck posted 17 patches 11 months, 1 week ago
There is a newer version of this series
[RFC PATCH 14/17] x86/resctrl: Add code in rdtgroup_mondata_show() for core monitor events
Posted by Tony Luck 11 months, 1 week ago
There may be multiple devices tracking each package, so scan all of them
and add up counters.

Output format depends on the data type. Either a 63 bit integer, or a
fixed point decimal.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/kernel/cpu/resctrl/internal.h    |  6 ++
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  3 +
 arch/x86/kernel/cpu/resctrl/intel_pmt.c   | 88 +++++++++++++++++++++++
 3 files changed, 97 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index 24c4ab331c3c..068a47b015e7 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -639,11 +639,17 @@ void free_rmid(u32 closid, u32 rmid);
 int rdt_get_mon_l3_config(struct rdt_resource *r);
 #ifdef CONFIG_INTEL_PMT_RESCTRL
 int rdt_get_intel_pmt_mon_config(void);
+int rdtgroup_intel_pmt_data_show(struct seq_file *m, struct rdt_resource *r,
+				 int domid, struct rdtgroup *rdtgrp, u32 evtid,
+				 struct rmid_read *rr);
 void rdt_get_intel_pmt_mount(void);
 void setup_intel_pmt_mon_domain(int cpu, int id, struct rdt_resource *r, struct list_head *add_pos);
 void rdt_intel_pmt_exit(void);
 #else
 static inline int rdt_get_intel_pmt_mon_config(void) { return 0; }
+static inline int rdtgroup_intel_pmt_data_show(struct seq_file *m, struct rdt_resource *r,
+					       int domid, struct rdtgroup *rdtgrp, u32 evtid,
+					       struct rmid_read *rr) { return 0; }
 static inline void rdt_get_intel_pmt_mount(void) { }
 static inline void setup_intel_pmt_mon_domain(int cpu, int id, struct rdt_resource *r,
 					      struct list_head *add_pos) { }
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 515a9bec05cd..0c3d407aca08 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -700,6 +700,9 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	case RDT_RESOURCE_L3:
 		ret = rdtgroup_l3_data_show(m, r, domid, rdtgrp, evtid, md.u.sum, &rr);
 		break;
+	case RDT_RESOURCE_INTEL_PMT:
+		ret = rdtgroup_intel_pmt_data_show(m, r, domid, rdtgrp, evtid, &rr);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
diff --git a/arch/x86/kernel/cpu/resctrl/intel_pmt.c b/arch/x86/kernel/cpu/resctrl/intel_pmt.c
index c5557d7f5fbe..4067aacd9d80 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_pmt.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_pmt.c
@@ -320,3 +320,91 @@ void setup_intel_pmt_mon_domain(int cpu, int id, struct rdt_resource *r, struct
 	if (resctrl_mounted && resctrl_arch_mon_capable())
 		mkdir_mondata_subdir_allrdtgrp(r, &hw_dom->hdr);
 }
+
+#define VALID_BIT	BIT_ULL(63)
+#define DATA_BITS	GENMASK_ULL(62, 0)
+
+static u64 scan_pmt_devs(int package, int guid, int offset)
+{
+	u64 rval, val;
+	int ndev = 0;
+
+	rval = 0;
+
+	for (int i = 0; i < pkg_info[package].count; i++) {
+		if (pkg_info[package].regions[i].guid != guid)
+			continue;
+		ndev++;
+		val = readq(pkg_info[package].regions[i].addr + offset);
+
+		if (!(val & VALID_BIT))
+			return ~0ull;
+		rval += val & DATA_BITS;
+	}
+
+	return ndev ? rval : ~0ull;
+}
+
+#define NUM_FRAC_BITS	18
+#define FRAC_MASK	GENMASK(NUM_FRAC_BITS - 1, 0)
+
+static void print_u46_18(struct seq_file *m, u64 val)
+{
+	u64 frac;
+
+	frac = val & FRAC_MASK;
+	frac = frac * 1000000;
+	frac += 1ul << (NUM_FRAC_BITS - 1);
+	frac >>= NUM_FRAC_BITS;
+
+	seq_printf(m, "%llu.%06llu\n", val >> NUM_FRAC_BITS, frac);
+}
+
+int rdtgroup_intel_pmt_data_show(struct seq_file *m, struct rdt_resource *r,
+				 int domid, struct rdtgroup *rdtgrp, u32 evtid,
+				 struct rmid_read *rr)
+{
+	struct rdtgroup *entry;
+	struct list_head *head;
+	u64 val, cval;
+	int offset;
+
+	if (rdtgrp->mon.rmid >= EVT_NUM_RMIDS(evtid)) {
+		seq_puts(m, "unimplemented\n");
+		return 0;
+	}
+
+	offset = rdtgrp->mon.rmid * EVT_STRIDE(evtid);
+	offset += EVT_OFFSET(evtid);
+
+	val = scan_pmt_devs(domid, EVT_GUID(evtid), offset);
+	if (val == ~0ull) {
+		seq_puts(m, "unavailable\n");
+		return 0;
+	}
+
+	if (rdtgrp->type == RDTCTRL_GROUP) {
+		head = &rdtgrp->mon.crdtgrp_list;
+		list_for_each_entry(entry, head, mon.crdtgrp_list) {
+			offset = entry->mon.rmid * EVT_STRIDE(evtid);
+			offset += EVT_OFFSET(evtid);
+			cval = scan_pmt_devs(domid, EVT_GUID(evtid), offset);
+			if (cval == ~0ull) {
+				seq_puts(m, "unavailable\n");
+				return 0;
+			}
+			val += cval;
+		}
+	}
+
+	switch (EVT_TYPE(evtid)) {
+	case EVT_U64:
+		seq_printf(m, "%llu\n", val);
+		break;
+	case EVT_U46_18:
+		print_u46_18(m, val);
+		break;
+	}
+
+	return 0;
+}
-- 
2.48.1