From: Tony Luck <tony.luck@intel.com>
To: Fenghua Yu <fenghuay@nvidia.com>,
Reinette Chatre <reinette.chatre@intel.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Peter Newman <peternewman@google.com>,
James Morse <james.morse@arm.com>,
Babu Moger <babu.moger@amd.com>,
Drew Fustini <dfustini@baylibre.com>,
Dave Martin <Dave.Martin@arm.com>
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
Tony Luck <tony.luck@intel.com>
Subject: [PATCH v2 13/16] x86/resctrl: Add code to display core telemetry events
Date: Fri, 21 Mar 2025 16:16:03 -0700 [thread overview]
Message-ID: <20250321231609.57418-14-tony.luck@intel.com> (raw)
In-Reply-To: <20250321231609.57418-1-tony.luck@intel.com>
These can be read from any CPU. Rely on the smp_call*() functions
picking the current CPU when given a free choice from cpu_online_mask.
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>
---
include/linux/resctrl.h | 3 ++
fs/resctrl/internal.h | 4 +-
arch/x86/kernel/cpu/resctrl/intel_aet.c | 53 +++++++++++++++++++++++++
fs/resctrl/ctrlmondata.c | 23 ++++++++++-
fs/resctrl/monitor.c | 23 +++++++++--
5 files changed, 100 insertions(+), 6 deletions(-)
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 999e0802a26e..e900764393f4 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -532,8 +532,11 @@ void resctrl_exit(void);
#ifdef CONFIG_INTEL_AET_RESCTRL
void rdt_get_intel_aet_mount(void);
+bool intel_aet_read_event(int domid, int rmid, int evtid, u64 *val, bool *fptype);
#else
static inline void rdt_get_intel_aet_mount(void) { }
+static inline bool intel_aet_read_event(int domid, int rmid, int evtid, u64 *val,
+ bool *fptype) { return false; }
#endif
#endif /* _RESCTRL_H */
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index f5a698b49e97..4d65a781034e 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -98,6 +98,7 @@ struct mon_data {
* domains in @r sharing L3 @ci.id
* @evtid: Which monitor event to read.
* @first: Initialize MBM counter when true.
+ * @fptype:If true indicates @val is in 46.18 fixed point format
* @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing domains.
* @err: Error encountered when reading counter.
* @val: Returned value of event counter. If @rgrp is a parent resource group,
@@ -112,6 +113,7 @@ struct rmid_read {
struct rdt_mon_domain *d;
unsigned int evtid;
bool first;
+ bool fptype;
struct cacheinfo *ci;
int err;
u64 val;
@@ -343,7 +345,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);
void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
- cpumask_t *cpumask, int evtid, int first);
+ const cpumask_t *cpumask, int evtid, int first);
int resctrl_mon_resource_init(void);
diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
index bab8e4de26b3..41ebb2ee9b41 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
@@ -357,3 +357,56 @@ void rdt_get_intel_aet_mount(void)
r->mon_capable = false;
}
}
+
+#define VALID_BIT BIT_ULL(63)
+#define DATA_BITS GENMASK_ULL(62, 0)
+
+/*
+ * Walk the array of telemetry groups on a specific package.
+ * Read and sum values for a specific counter (described by
+ * guid and offset).
+ * Return failure (~0x0ull) if any counter isn't valid.
+ */
+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;
+}
+
+/*
+ * Read counter for an event on a domain (summing all aggregators
+ * on the domain).
+ */
+bool intel_aet_read_event(int domid, int rmid, int evtid, u64 *val, bool *fptype)
+{
+ u64 evtcount;
+ int offset;
+
+ if (rmid >= EVT_NUM_RMIDS(evtid))
+ return false;
+
+ offset = rmid * EVT_STRIDE(evtid);
+ offset += EVT_OFFSET(evtid);
+ evtcount = scan_pmt_devs(domid, EVT_GUID(evtid), offset);
+ *fptype = evtid == PMT_EVENT_ENERGY || evtid == PMT_EVENT_ACTIVITY;
+
+ if (evtcount != ~0ull || *val == 0)
+ *val += evtcount;
+
+ return evtcount != ~0ull;
+}
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index d56b78450a99..5612f5f64574 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -548,7 +548,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
- cpumask_t *cpumask, int evtid, int first)
+ const cpumask_t *cpumask, int evtid, int first)
{
int cpu;
@@ -585,6 +585,21 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx);
}
+#define NUM_FRAC_BITS 18
+#define FRAC_MASK GENMASK(NUM_FRAC_BITS - 1, 0)
+
+static void show_fp_value(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_mondata_show(struct seq_file *m, void *arg)
{
struct kernfs_open_file *of = m->private;
@@ -594,6 +609,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
u32 resid, evtid, domid;
struct rdtgroup *rdtgrp;
struct rdt_resource *r;
+ const cpumask_t *mask;
struct mon_data *md;
int ret = 0;
@@ -642,7 +658,8 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
goto out;
}
d = container_of(hdr, struct rdt_mon_domain, hdr);
- mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false);
+ mask = (resid == RDT_RESOURCE_L3) ? &d->hdr.cpu_mask : cpu_online_mask;
+ mon_event_read(&rr, r, d, rdtgrp, mask, evtid, false);
}
checkresult:
@@ -651,6 +668,8 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
seq_puts(m, "Error\n");
else if (rr.err == -EINVAL)
seq_puts(m, "Unavailable\n");
+ else if (rr.fptype)
+ show_fp_value(m, rr.val);
else
seq_printf(m, "%llu\n", rr.val);
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 3fe21dcf0fde..f4049ae5344c 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -447,6 +447,24 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
m->prev_bw = cur_bw;
}
+static int mon_event_count_one_group(int closid, int rmid, struct rmid_read *rr)
+{
+ bool ret;
+
+ switch (rr->r->rid) {
+ case RDT_RESOURCE_L3:
+ rr->fptype = false;
+ return __mon_event_count(closid, rmid, rr);
+ case RDT_RESOURCE_INTEL_AET:
+ ret = intel_aet_read_event(rr->d->hdr.id, rmid, rr->evtid, &rr->val, &rr->fptype);
+ if (!ret)
+ rr->err = -EINVAL;
+ return ret ? 0 : -EINVAL;
+ }
+
+ return -EINVAL;
+}
+
/*
* This is scheduled by mon_event_read() to read the CQM/MBM counters
* on a domain.
@@ -460,7 +478,7 @@ void mon_event_count(void *info)
rdtgrp = rr->rgrp;
- ret = __mon_event_count(rdtgrp->closid, rdtgrp->mon.rmid, rr);
+ ret = mon_event_count_one_group(rdtgrp->closid, rdtgrp->mon.rmid, rr);
/*
* For Ctrl groups read data from child monitor groups and
@@ -471,8 +489,7 @@ void mon_event_count(void *info)
if (rdtgrp->type == RDTCTRL_GROUP) {
list_for_each_entry(entry, head, mon.crdtgrp_list) {
- if (__mon_event_count(entry->closid, entry->mon.rmid,
- rr) == 0)
+ if (mon_event_count_one_group(entry->closid, entry->mon.rmid, rr) == 0)
ret = 0;
}
}
--
2.48.1
next prev parent reply other threads:[~2025-03-21 23:16 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 23:15 [PATCH v2 00/16] x86/resctrl telemetry monitoring Tony Luck
2025-03-21 23:15 ` [PATCH v2 01/16] x86/rectrl: Fake OOBMSM interface Tony Luck
2025-03-31 16:14 ` Reinette Chatre
2025-03-31 21:09 ` Luck, Tony
2025-03-21 23:15 ` [PATCH v2 02/16] x86/resctrl: Move L3 initialization out of domain_add_cpu_mon() Tony Luck
2025-03-21 23:15 ` [PATCH v2 03/16] x86/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types Tony Luck
2025-03-21 23:15 ` [PATCH v2 04/16] x86/resctrl: Change generic monitor functions to use struct rdt_domain_hdr Tony Luck
2025-03-31 16:15 ` Reinette Chatre
2025-03-31 21:14 ` Luck, Tony
2025-03-21 23:15 ` [PATCH v2 05/16] x86/resctrl: Add and initialize rdt_resource for package scope core monitor Tony Luck
2025-03-31 16:18 ` Reinette Chatre
2025-03-31 21:22 ` Luck, Tony
2025-03-31 23:49 ` Reinette Chatre
2025-03-21 23:15 ` [PATCH v2 06/16] x86/resctrl: Prepare for resource specific event ids Tony Luck
2025-03-21 23:15 ` [PATCH v2 07/16] x86/resctrl: Add initialization hook for Intel PMT events Tony Luck
2025-03-31 16:20 ` Reinette Chatre
2025-03-31 21:53 ` Luck, Tony
2025-04-01 0:07 ` Reinette Chatre
2025-03-21 23:15 ` [PATCH v2 08/16] x86/resctrl: Add Intel PMT domain specific code Tony Luck
2025-03-21 23:15 ` [PATCH v2 09/16] x86/resctrl: Add detailed descriptions for Clearwater Forest events Tony Luck
2025-03-31 16:21 ` Reinette Chatre
2025-03-31 22:07 ` Luck, Tony
2025-04-01 0:13 ` Reinette Chatre
2025-03-21 23:16 ` [PATCH v2 10/16] x86/resctrl: Allocate per-package structures for known events Tony Luck
2025-03-31 16:21 ` Reinette Chatre
2025-03-31 22:23 ` Luck, Tony
2025-04-01 0:22 ` Luck, Tony
2025-03-21 23:16 ` [PATCH v2 11/16] x86/resctrl: Link known events onto RDT_RESOURCE_INTEL_AET.evt_list Tony Luck
2025-03-31 16:23 ` Reinette Chatre
2025-03-31 22:29 ` Luck, Tony
2025-03-21 23:16 ` [PATCH v2 12/16] x86/resctrl: Build lookup table for package events Tony Luck
2025-03-21 23:16 ` Tony Luck [this message]
2025-03-31 16:23 ` [PATCH v2 13/16] x86/resctrl: Add code to display core telemetry events Reinette Chatre
2025-03-31 22:42 ` Luck, Tony
2025-03-21 23:16 ` [PATCH v2 14/16] x86/resctrl: Add status files to info/PKG_MON Tony Luck
2025-03-21 23:16 ` [PATCH v2 15/16] x86/resctrl: Enable package event monitoring Tony Luck
2025-03-21 23:16 ` [PATCH v2 16/16] x86/resctrl: Update Documentation for package events Tony Luck
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=20250321231609.57418-14-tony.luck@intel.com \
--to=tony.luck@intel.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=dfustini@baylibre.com \
--cc=fenghuay@nvidia.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=patches@lists.linux.dev \
--cc=peternewman@google.com \
--cc=reinette.chatre@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
all inboxes | Powered by JetHome®