Skip to contentSkip to conversation

x86,fs/resctrl telemetry monitoring

PATCH New Tony Luck 3 participants 6 messages Jan 8 – Jan 9

Subsystems (2)
lore
Share & tools
lore

Tony Luck

author maintainer
#0 lore raw

v17 cover x86,fs/resctrl telemetry monitoring

Updates to v17 series[0] to address Boris' suggestion[1] to use DO_ONCE() instead of open-coding with atomic operations to only execute some code once.

The substantive changes are in patch 13 where the open-coded "only once" logic has been removed from resctrl_arch_pre_mount() and replaced using DO_ONCE_SLEEPABLE(resctrl_arch_pre_mount); in rdt_get_tree().

This change requires some trivial changes to patches 16 and 29 so that they apply cleanly on top of the changes to resctrl_arch_pre_mount().

I dropped Reinette's Reviewed-by tag from patch 13 because of the changes. But she commented[2]:
"Placing DO_ONCE_SLEEPABLE() in rdt_get_tree() is fine by me"

-Tony

[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/20260105191711.GBaVwON5nZn-uO6Sqg@fat_crate.local/
[2] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH 13/32 x86,fs/resctrl: Add an architectural hook called for first mount

Enumeration of Intel telemetry events is an asynchronous process involving several mutually dependent drivers added as auxiliary devices during the device_initcall() phase of Linux boot. The process finishes after the probe functions of these drivers completes. But this happens after resctrl_arch_late_init() is executed.

Tracing the enumeration process shows that it does complete a full seven seconds before the earliest possible mount of the resctrl file system (when included in /etc/fstab for automatic mount by systemd).

Add a hook at the beginning of the mount code that will be used to check for telemetry events and initialize if any are found.

The hook is only called on the first mount of the resctrl file system as that is all that is needed for telemetry enumeration.

resctrl filesystem calls the hook with no locks held. Architecture code is responsible for any required locking.

---
 include/linux/resctrl.h            | 6 ++++++
 arch/x86/kernel/cpu/resctrl/core.c | 4 ++++
 fs/resctrl/rdtgroup.c              | 3 +++
 3 files changed, 13 insertions(+)
include/linux/resctrl.h +6 -0
index c43526cdf304..2f938a5a16f8 100644
@@ -514,6 +514,12 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
 void resctrl_online_cpu(unsigned int cpu);
 void resctrl_offline_cpu(unsigned int cpu);
 
+/*
+ * Architecture hook called at beginning of first file system mount attempt.
+ * No locks are held.
+ */
+void resctrl_arch_pre_mount(void);
+
 /**
  * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
  *			      for this resource and domain.
arch/x86/kernel/cpu/resctrl/core.c +4 -0
index 9222eee7ce07..a2b7f869b4b0 100644
@@ -726,6 +726,10 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
 	return 0;
 }
 
+void resctrl_arch_pre_mount(void)
+{
+}
+
 enum {
 	RDT_FLAG_CMT,
 	RDT_FLAG_MBM_TOTAL,
fs/resctrl/rdtgroup.c +3 -0
index 771e40f02ba6..0e3b8bcf4e53 100644
@@ -18,6 +18,7 @@
 #include <linux/fs_parser.h>
 #include <linux/sysfs.h>
 #include <linux/kernfs.h>
+#include <linux/once.h>
 #include <linux/resctrl.h>
 #include <linux/seq_buf.h>
 #include <linux/seq_file.h>
@@ -2785,6 +2786,8 @@ static int rdt_get_tree(struct fs_context *fc)
 	struct rdt_resource *r;
 	int ret;
 
+	DO_ONCE_SLEEPABLE(resctrl_arch_pre_mount);
+
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 	/*
Signature · 1 line
2.52.0
maintainer
#2 lore raw

Re: [PATCH 13/32] x86,fs/resctrl: Add an architectural hook called for first mount

Hi Tony,

Quoted 10 lines · Tony Luck

Enumeration of Intel telemetry events is an asynchronous process involving several mutually dependent drivers added as auxiliary devices during the device_initcall() phase of Linux boot. The process finishes after the probe functions of these drivers completes. But this happens after resctrl_arch_late_init() is executed.

Tracing the enumeration process shows that it does complete a full seven seconds before the earliest possible mount of the resctrl file system (when included in /etc/fstab for automatic mount by systemd).

Quoted 5 lines

Add a hook at the beginning of the mount code that will be used to check for telemetry events and initialize if any are found.

The hook is only called on the first mount of the resctrl file system as that is all that is needed for telemetry enumeration.

Needs imperative. "Only call the hook on the first mount ..."?
Although, to help with brevity, the last three sentences could be merged. For example:

Add a hook for use by telemetry event enumeration and initialization and run it once at the beginning of resctrl mount without any locks held. Architecture is responsible for any required locking.

Quoted 6 lines

resctrl filesystem calls the hook with no locks held. Architecture code is responsible for any required locking.

---

| Reviewed-by: Reinette Chatre <[email protected]>

Reinette

maintainer
#3 lore raw

Re: [PATCH 13/32] x86,fs/resctrl: Add an architectural hook called for first mount

Quoted 6 lines · Reinette Chatre

Needs imperative. "Only call the hook on the first mount ..."?
Although, to help with brevity, the last three sentences could be merged. For example:

Add a hook for use by telemetry event enumeration and initialization and run it once at the beginning of resctrl mount without any locks held. Architecture is responsible for any required locking.

Done.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#4 lore raw

PATCH 16/32 x86/resctrl: Discover hardware telemetry events

In reply to Tony Luck

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 [1].

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.

Return the aggregator data to INTEL_PMT_TELEMETRY at resctrl exit time.

resctrl will silently ignore unknown guid values.

Add a new Kconfig option CONFIG_X86_CPU_RESCTRL_INTEL_AET for the Intel specific parts of telemetry code. This depends on the INTEL_PMT_TELEMETRY and INTEL_TPMI drivers being built-in to the kernel for enumeration of telemetry features.

---
 arch/x86/kernel/cpu/resctrl/internal.h  |   8 ++
 arch/x86/kernel/cpu/resctrl/core.c      |   4 +
 arch/x86/kernel/cpu/resctrl/intel_aet.c | 109 ++++++++++++++++++++++++
 arch/x86/Kconfig                        |  13 +++
 arch/x86/kernel/cpu/resctrl/Makefile    |   1 +
 5 files changed, 135 insertions(+)
 create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.c
arch/x86/kernel/cpu/resctrl/internal.h +8 -0
index 11d06995810e..f2e6e3577df0 100644
@@ -222,4 +222,12 @@ void __init intel_rdt_mbm_apply_quirk(void);
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
 void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);
 
+#ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET
+bool intel_aet_get_events(void);
+void __exit intel_aet_exit(void);
+#else
+static inline bool intel_aet_get_events(void) { return false; }
+static inline void __exit intel_aet_exit(void) { }
+#endif
+
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/core.c +4 -0
index f3d7e2263630..595f7eae9294 100644
@@ -738,6 +738,8 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
 
 void resctrl_arch_pre_mount(void)
 {
+	if (!intel_aet_get_events())
+		return;
 }
 
 enum {
@@ -1099,6 +1101,8 @@ late_initcall(resctrl_arch_late_init);
 
 static void __exit resctrl_arch_exit(void)
 {
+	intel_aet_exit();
+
 	cpuhp_remove_state(rdt_online);
 
 	resctrl_exit();
arch/x86/kernel/cpu/resctrl/intel_aet.c new file +109 -0

109 lines not on this page · raw message

arch/x86/Kconfig +13 -0
index 80527299f859..0d874a92daed 100644
@@ -540,6 +540,19 @@ config X86_CPU_RESCTRL
 
 	  Say N if unsure.
 
+config X86_CPU_RESCTRL_INTEL_AET
+	bool "Intel Application Energy Telemetry"
+	depends on X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEMETRY=y && INTEL_TPMI=y
+	help
+	  Enable per-RMID telemetry events in resctrl.
+
+	  Intel feature that collects per-RMID execution data
+	  about energy consumption, measure of frequency independent
+	  activity and other performance metrics. Data is aggregated
+	  per package.
+
+	  Say N if unsure.
+
 config X86_FRED
 	bool "Flexible Return and Event Delivery"
 	depends on X86_64
arch/x86/kernel/cpu/resctrl/Makefile +1 -0
index d8a04b195da2..273ddfa30836 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_X86_CPU_RESCTRL)		+= core.o rdtgroup.o monitor.o
 obj-$(CONFIG_X86_CPU_RESCTRL)		+= ctrlmondata.o
+obj-$(CONFIG_X86_CPU_RESCTRL_INTEL_AET)	+= intel_aet.o
 obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK)	+= pseudo_lock.o
 
 # To allow define_trace.h's recursive include:
Signature · 1 line
2.52.0
author maintainer
#5 lore raw

PATCH 29/32 x86/resctrl: Enable RDT_RESOURCE_PERF_PKG

In reply to Tony Luck

Since telemetry events are enumerated on resctrl mount the RDT_RESOURCE_PERF_PKG resource is not considered "monitoring capable" during early resctrl initialization. This means that the domain list for RDT_RESOURCE_PERF_PKG is not built when the CPU hot plug notifiers are registered and run for the first time right after resctrl initialization.

Mark the RDT_RESOURCE_PERF_PKG as "monitoring capable" upon successful telemetry event enumeration to ensure future CPU hotplug events include this resource and initialize its domain list for CPUs that are already online.

Print to console log announcing the name of the telemetry feature detected.

---
 arch/x86/kernel/cpu/resctrl/core.c      | 16 ++++++++++++++++
 arch/x86/kernel/cpu/resctrl/intel_aet.c |  6 ++++++
 2 files changed, 22 insertions(+)
arch/x86/kernel/cpu/resctrl/core.c +16 -0
index a3c65f46e8b4..5500c4f03100 100644
@@ -766,8 +766,24 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
 
 void resctrl_arch_pre_mount(void)
 {
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_resctrl;
+	int cpu;
+
 	if (!intel_aet_get_events())
 		return;
+
+	/*
+	 * Late discovery of telemetry events means the domains for the
+	 * resource were not built. Do that now.
+	 */
+	cpus_read_lock();
+	mutex_lock(&domain_list_lock);
+	r->mon_capable = true;
+	rdt_mon_capable = true;
+	for_each_online_cpu(cpu)
+		domain_add_cpu_mon(cpu, r);
+	mutex_unlock(&domain_list_lock);
+	cpus_read_unlock();
 }
 
 enum {
arch/x86/kernel/cpu/resctrl/intel_aet.c +6 -0
index e50c04afc8eb..3ee51b05a297 100644
@@ -274,6 +274,12 @@ static bool enable_events(struct event_group *e, struct pmt_feature_group *p)
 	else
 		r->mon.num_rmid = e->num_rmid;
 
+	if (skipped_events)
+		pr_info("%s %s:0x%x monitoring detected (skipped %d events)\n", r->name,
+			e->pfname, e->guid, skipped_events);
+	else
+		pr_info("%s %s:0x%x monitoring detected\n", r->name, e->pfname, e->guid);
+
 	return true;
 }
 
Signature · 1 line
2.52.0