Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86/resctrl: Discover hardware telemetry events

Each CPU collects data for telemetry events that it sends to the nearest
telemetry event aggregator either when the value of MSR_IA32_PQR_ASSOC.RMID
changes, or when a two millisecond timer expires.

There is a feature type ("energy" or "perf"), GUID, and MMIO region associated
with each aggregator. This combination links to an XML description of the
set of telemetry events tracked by the aggregator. XML files are published
by Intel in a GitHub repository¹.

The telemetry event aggregators maintain per-RMID per-event counts of the
total seen for all the CPUs. There may be multiple telemetry event aggregators
per package.

There are separate sets of aggregators for each feature type. Aggregators
in a set may have different GUIDs. All aggregators with the same feature
type and GUID are symmetric keeping counts for the same set of events for
the CPUs that provide data to them.

The XML file for each aggregator provides the following information:
0) Feature type of the events ("perf" or "energy")
1) Which telemetry events are tracked by the aggregator.
2) The order in which the event counters appear for each RMID.
3) The value type of each event counter (integer or fixed-point).
4) The number of RMIDs supported.
5) Which additional aggregator status registers are included.
6) The total size of the MMIO region for an aggregator.

Introduce struct event_group that condenses the relevant information from
an XML file. Hereafter an "event group" refers to a group of events of a
particular feature type (event_group::pfname set to "energy" or "perf") with
a particular GUID.

Use event_group::pfname to determine the feature id needed to obtain the
aggregator details. It will later be used in console messages and with the
rdt= boot parameter.

The INTEL_PMT_TELEMETRY driver enumerates support for telemetry events.
This driver provides intel_pmt_get_regions_by_feature() to list all available
telemetry event aggregators of a given feature type. The list includes the
"guid", the base address in MMIO space for the region where the event counters
are exposed, and the package id where the all the CPUs that report to this
aggregator are located.

Call INTEL_PMT_TELEMETRY's intel_pmt_get_regions_by_feature() for each event
group to obtain a private copy of that event group's aggregator data. Duplicate
the aggregator data between event groups that have the same feature type
but different GUID. Further processing on this private copy will be unique
to the event group.

¹https://github.com/intel/Intel-PMT

[ bp: Zap text explaining the code, s/guid/GUID/g ]

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com

authored by

Tony Luck and committed by
Borislav Petkov (AMD)
1fb2daa6 db64994d

+135
+13
arch/x86/Kconfig
··· 540 540 541 541 Say N if unsure. 542 542 543 + config X86_CPU_RESCTRL_INTEL_AET 544 + bool "Intel Application Energy Telemetry" 545 + depends on X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y 546 + help 547 + Enable per-RMID telemetry events in resctrl. 548 + 549 + Intel feature that collects per-RMID execution data 550 + about energy consumption, measure of frequency independent 551 + activity and other performance metrics. Data is aggregated 552 + per package. 553 + 554 + Say N if unsure. 555 + 543 556 config X86_FRED 544 557 bool "Flexible Return and Event Delivery" 545 558 depends on X86_64
+1
arch/x86/kernel/cpu/resctrl/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o 3 3 obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o 4 + obj-$(CONFIG_X86_CPU_RESCTRL_INTEL_AET) += intel_aet.o 4 5 obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o 5 6 6 7 # To allow define_trace.h's recursive include:
+4
arch/x86/kernel/cpu/resctrl/core.c
··· 738 738 739 739 void resctrl_arch_pre_mount(void) 740 740 { 741 + if (!intel_aet_get_events()) 742 + return; 741 743 } 742 744 743 745 enum { ··· 1101 1099 1102 1100 static void __exit resctrl_arch_exit(void) 1103 1101 { 1102 + intel_aet_exit(); 1103 + 1104 1104 cpuhp_remove_state(rdt_online); 1105 1105 1106 1106 resctrl_exit();
+109
arch/x86/kernel/cpu/resctrl/intel_aet.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Resource Director Technology(RDT) 4 + * - Intel Application Energy Telemetry 5 + * 6 + * Copyright (C) 2025 Intel Corporation 7 + * 8 + * Author: 9 + * Tony Luck <tony.luck@intel.com> 10 + */ 11 + 12 + #define pr_fmt(fmt) "resctrl: " fmt 13 + 14 + #include <linux/err.h> 15 + #include <linux/init.h> 16 + #include <linux/intel_pmt_features.h> 17 + #include <linux/intel_vsec.h> 18 + #include <linux/resctrl.h> 19 + #include <linux/stddef.h> 20 + 21 + #include "internal.h" 22 + 23 + /** 24 + * struct event_group - Events with the same feature type ("energy" or "perf") and GUID. 25 + * @pfname: PMT feature name ("energy" or "perf") of this event group. 26 + * @pfg: Points to the aggregated telemetry space information 27 + * returned by the intel_pmt_get_regions_by_feature() 28 + * call to the INTEL_PMT_TELEMETRY driver that contains 29 + * data for all telemetry regions of type @pfname. 30 + * Valid if the system supports the event group, 31 + * NULL otherwise. 32 + */ 33 + struct event_group { 34 + /* Data fields for additional structures to manage this group. */ 35 + const char *pfname; 36 + struct pmt_feature_group *pfg; 37 + }; 38 + 39 + static struct event_group *known_event_groups[] = { 40 + }; 41 + 42 + #define for_each_event_group(_peg) \ 43 + for (_peg = known_event_groups; \ 44 + _peg < &known_event_groups[ARRAY_SIZE(known_event_groups)]; \ 45 + _peg++) 46 + 47 + /* Stub for now */ 48 + static bool enable_events(struct event_group *e, struct pmt_feature_group *p) 49 + { 50 + return false; 51 + } 52 + 53 + static enum pmt_feature_id lookup_pfid(const char *pfname) 54 + { 55 + if (!strcmp(pfname, "energy")) 56 + return FEATURE_PER_RMID_ENERGY_TELEM; 57 + else if (!strcmp(pfname, "perf")) 58 + return FEATURE_PER_RMID_PERF_TELEM; 59 + 60 + pr_warn("Unknown PMT feature name '%s'\n", pfname); 61 + 62 + return FEATURE_INVALID; 63 + } 64 + 65 + /* 66 + * Request a copy of struct pmt_feature_group for each event group. If there is 67 + * one, the returned structure has an array of telemetry_region structures, 68 + * each element of the array describes one telemetry aggregator. The 69 + * telemetry aggregators may have different GUIDs so obtain duplicate struct 70 + * pmt_feature_group for event groups with same feature type but different 71 + * GUID. Post-processing ensures an event group can only use the telemetry 72 + * aggregators that match its GUID. An event group keeps a pointer to its 73 + * struct pmt_feature_group to indicate that its events are successfully 74 + * enabled. 75 + */ 76 + bool intel_aet_get_events(void) 77 + { 78 + struct pmt_feature_group *p; 79 + enum pmt_feature_id pfid; 80 + struct event_group **peg; 81 + bool ret = false; 82 + 83 + for_each_event_group(peg) { 84 + pfid = lookup_pfid((*peg)->pfname); 85 + p = intel_pmt_get_regions_by_feature(pfid); 86 + if (IS_ERR_OR_NULL(p)) 87 + continue; 88 + if (enable_events(*peg, p)) { 89 + (*peg)->pfg = p; 90 + ret = true; 91 + } else { 92 + intel_pmt_put_feature_group(p); 93 + } 94 + } 95 + 96 + return ret; 97 + } 98 + 99 + void __exit intel_aet_exit(void) 100 + { 101 + struct event_group **peg; 102 + 103 + for_each_event_group(peg) { 104 + if ((*peg)->pfg) { 105 + intel_pmt_put_feature_group((*peg)->pfg); 106 + (*peg)->pfg = NULL; 107 + } 108 + } 109 + }
+8
arch/x86/kernel/cpu/resctrl/internal.h
··· 222 222 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); 223 223 void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r); 224 224 225 + #ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET 226 + bool intel_aet_get_events(void); 227 + void __exit intel_aet_exit(void); 228 + #else 229 + static inline bool intel_aet_get_events(void) { return false; } 230 + static inline void __exit intel_aet_exit(void) { } 231 + #endif 232 + 225 233 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */