Re: [PATCH v8 19/32] x86/resctrl: Complete telemetry event enumeration

From: Reinette Chatre
Date: Thu Aug 14 2025 - 17:42:48 EST


Hi Tony,

On 8/11/25 11:16 AM, Tony Luck wrote:
> Counters for telemetry events are in MMIO space. Each telemetry_region
> structure returned in the pmt_feature_group returned from OOBMSM contains

"OOBMSM" -> "INTEL_PMT_TELEMETRY"?

> the base MMIO address for the counters.
>
> There may be multiple aggregators per package. Scan all the
> telemetry_region structures again and save the number of regions together
> with a flex array of the MMIO addresses for each region indexed by
> package id.
>
> Completed structure for each event group looks like this:
>
> +---------------------+---------------------+
> pkginfo** -->|pkginfo[package ID 0]|pkginfo[package ID 1]|
> +---------------------+---------------------+
> | |
> v v
> +--------------------+ +--------------------+
> |struct pkg_mmio_info| |struct pkg_mmio_info|
> +--------------------+ +--------------------+
> |num_regions = M | |num_regions = N |
> | addrs[0] | | addrs[0] |
> | addrs[1] | | addrs[1] |
> | ... | | ... |
> | addrs[M-1] | | addrs[N-1] |
> +--------------------+ +--------------------+
>
> Build a list (active_event_groups) of all the event groups that
> were successfully enabled. Use it to clean up in intel_aet_exit().

While this adds a note about active_event_groups it does not motivate
*why* this additional data structure is needed. I find this additional
data structure unnecessary and actually makes the code harder to understand.
As I understand event_group::pfg can already be used to determine if the
event group is active or not. Adding a new data structure to track this thus seems
unnecessary. If this is a data structure created for convenience I think it
should rather be replaced by helpers that use event_group::pfg.

>
> Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
> ---

...

> @@ -169,4 +234,13 @@ bool intel_aet_get_events(void)
>
> void __exit intel_aet_exit(void)
> {
> + struct event_group *evg, *tmp;
> +
> + list_for_each_entry_safe(evg, tmp, &active_event_groups, list) {
> + intel_pmt_put_feature_group(evg->pfg);
> + evg->pfg = NULL;
> + free_pkg_mmio_info(evg->pkginfo);
> + evg->pkginfo = NULL;
> + list_del(&evg->list);
> + }
> }

I think above can be simplified by making it symmetrical to
intel_aet_get_events().
For example:

static void put_pmt_feature(struct event_group **evgs, unsigned int num_evg)
{
struct event_group **peg;

for (peg = evgs; peg < &evgs[num_evg]; peg++) {
if (!(*peg)->pfg)
return;
intel_pmt_put_feature_group((*peg)->pfg);
/* rest of cleanup from intel_aet_exit() above */
}
}

void __ exit intel_aet_exit(void) {
put_pmt_feature(known_energy_event_groups,
ARRAY_SIZE(known_energy_event_groups));
put_pmt_feature(known_perf_event_groups,
ARRAY_SIZE(known_perf_event_groups));
}

Reinette