Skip to contentSkip to conversation

IOMMU/AMD: IOMMU PC PERF uncore PMU implementation

PATCH In review [email protected] 2 participants 2 messages May 13, 2013 – May 14, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 IOMMU/AMD: IOMMU PC PERF uncore PMU implementation

From: Steven L Kinney <[email protected]>

Implement a perf PMU to handle IOMMU PC perf events. This PMU will handle static counter perf events relative to the AMD IOMMU Performance Counters.

To invoke the AMD IOMMU PMU issue a perf tool command such as:

./perf stat -e amd_iommu/config=<config-data>,config1=<config1-data>/u <command>

For example:

./perf stat -e amd_iommu/config=0x8000000000000005,config1=0/u <command>

The resulting count will be how many IOMMU total peripheral memory operations were performed during the command execution window.

---
 arch/x86/kernel/cpu/Makefile                 |    2 +-
 arch/x86/kernel/cpu/perf_event_amd_iommu.c |  409 ++++++++++++++++++++++++++
 arch/x86/kernel/cpu/perf_event_amd_iommu.h |   55 ++++
 3 files changed, 465 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.c
 create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.h
arch/x86/kernel/cpu/Makefile +1 -1
index b0684e4..2a3b676 100644
@@ -30,7 +30,7 @@ obj-$(CONFIG_CPU_SUP_UMC_32)		+= umc.o
 obj-$(CONFIG_PERF_EVENTS)		+= perf_event.o
 
 ifdef CONFIG_PERF_EVENTS
-obj-$(CONFIG_CPU_SUP_AMD)		+= perf_event_amd.o perf_event_amd_uncore.o
+obj-$(CONFIG_CPU_SUP_AMD)		+= perf_event_amd.o perf_event_amd_uncore.o perf_event_amd_iommu.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_p6.o perf_event_knc.o perf_event_p4.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_uncore.o
arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +409 -0

409 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_amd_iommu.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 39 lines · On Mon, May 13, 2013 at 04:44:13PM -0500, [email protected] wrote:

From: Steven L Kinney <[email protected]>

Implement a perf PMU to handle IOMMU PC perf events. This PMU will handle static counter perf events relative to the AMD IOMMU Performance Counters.

To invoke the AMD IOMMU PMU issue a perf tool command such as:

./perf stat -e amd_iommu/config=<config-data>,config1=<config1-data>/u <command>

For example:

./perf stat -e amd_iommu/config=0x8000000000000005,config1=0/u <command>

The resulting count will be how many IOMMU total peripheral memory operations were performed during the command execution window.

---

arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +18 -0
+PMU_FORMAT_ATTR(iommu_raw, "config:63");
 
+static int perf_iommu_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct perf_iommu *perf_iommu;
+	u64 config, config1;
+
+	/* initialize the cntr_assign_mask */
+	cntr_assign_mask = 0;
+
+	/* test the event attr type check for PMU enumeration */
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	perf_iommu = &perf_iommu_fetch;
+
+	if (perf_iommu) {
+		config = event->attr.config;

arch/x86/kernel/cpu/perf_event_amd_iommu.c line 165

Quoted 10 lines
arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +10 -0
+		config1 = event->attr.config1;
+	} else
+		return -EINVAL;
+
+	if (event->pmu != &perf_iommu->pmu)
+		return -ENOENT;
+
+	/* make sure the event->attr.config is raw (vendor specific) */
+	if (!(config & IOMMU_PC_RAW_CONFIG_MASK))
+		return -EINVAL;

Is this really needed? Non of the uncore PMU drivers have a magic config bit either. Seems weird to me.

arch/x86/kernel/cpu/perf_event_amd_iommu.c line 178

Quoted 12 lines
arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +12 -0
+	/* integrate with iommu base devid (0000), assume one iommu */
+	perf_iommu->max_banks =
+		amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID);
+	perf_iommu->max_counters =
+		amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID);
+
+	/* update the hw_perf_event struct with the iommu config data */
+	hwc->config = config;
+	hwc->extra_reg.config = config1;
+
+	return 0;
+}

Also it might make sense to add a few event aliases to both this IOMMU and the AMD uncore driver.

Search for uncore_.*_events in arch/x86/kernel/cpu/perf_event_intel_uncore.c for examples.

This way you can also make the IOMMU a tad more useful by providing some events you think are the most useful for people interested in this thing.