mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics
@ 2026-11-02 21:14 Jacob Lefkowitz via B4 Relay
  2026-11-02 21:14 ` [PATCH v2 1/2] perf jevents: add iommu page table walk metrics Jacob Lefkowitz via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jacob Lefkowitz via B4 Relay @ 2026-11-02 21:14 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: linux-perf-users, linux-kernel, Ben Chaney, Matt Pelland,
	Jacob Lefkowitz

Adds AMD specific metrics for the IOMMU with respect to page table
walks and device table entires. The metrics cover ratios, rates, and
percentages with respect to any event which might be triggered during
a page table walk or device table entry lookup.

The metrics target Zen 2+ processors and use the standard amd_iommu
PMU events. All metrics are tested with 'sleep 10' and behave as
expected. An example output of sleep 10 is provided within each
individual change. 

The changes are split into two patches:
1. perf jevents: add iommu page table walk metrics
2. perf jevents: add amd specific device table entry metrics

The specific metris added are:
- lpm_iommu_dte_miss_rate
- lpm_iommu_dte_lookups
- lpm_iommu_ptw_reads_per_tlb_miss
- lpm_iommu_ptw_nested_read_ratio
- lpm_iommu_ptw_guest_read_ratio
- lpm_iommu_trans_per_sec

Signed-off-by: Jacob Lefkowitz <jlefkowi@akamai.com>
---
Changes in v2:
- Drop min() wrappers d_ratio() for the IOMMU ratio metrics: min(NaN, 1)
  evaluated to 1, reporting a false 100% on sockets with no amd_counts
- Did not test with previously mentioned custom workload and did not add
  to the workloads collection. The workload stressed the CPU TLB,
  but the IOMMU only translates device DMA, so the load never reaches
  the IOMMU.
- Remove unused min import
- Remove global declaration of '_zen_model' within each function
- Link to v1: https://lore.kernel.org/r/20261029-perf-tools-next-v1-0-a75a2b64a15e@akamai.com

---
Jacob Lefkowitz (2):
      perf jevents: add iommu page table walk metrics
      perf jevents: add amd specific device table entry metrics

 tools/perf/pmu-events/amd_metrics.py | 75 ++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
---
base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
change-id: 20261028-perf-tools-next-8fd1d433316a

Best regards,
-- 
Jacob Lefkowitz <jlefkowi@akamai.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] perf jevents: add iommu page table walk metrics
  2026-11-02 21:14 [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics Jacob Lefkowitz via B4 Relay
@ 2026-11-02 21:14 ` Jacob Lefkowitz via B4 Relay
  2026-11-02 21:14 ` [PATCH v2 2/2] perf jevents: add amd specific device table entry metrics Jacob Lefkowitz via B4 Relay
  2026-11-10  3:22 ` [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device " Hang Zhengyang
  2 siblings, 0 replies; 4+ messages in thread
From: Jacob Lefkowitz via B4 Relay @ 2026-11-02 21:14 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: linux-perf-users, linux-kernel, Ben Chaney, Matt Pelland,
	Jacob Lefkowitz

From: Jacob Lefkowitz <jlefkowi@akamai.com>

Adds page table walk metrics specfically to perf jevents for AMD
platforms to enhance observability into IOMMU overhead. The metrics
are supported on Zen 2 and neweer processors. They are implemented
using the amd_iommu PMU events.

The list of metrics added here are:
- lpm_iommu_ptw_reads_per_tlb_miss
- lpm_iommu_ptw_nested_read_ratio
- lpm_iommu_ptw_guest_read_ratio
- lpm_iommu_trans_per_sec

The changes here have been tested with 'sleep 10' as the workload:

perf stat -M iommuptw --per-socket --metric-only -j -a -- sleep 10
{"socket" : "S0", "counters" : 8,
"reads/tlb_miss lpm_iommu_ptw_reads_per_tlb_miss" : "0.5",
"%  lpm_iommu_ptw_nested_read_ratio" : "none",
"%  lpm_iommu_ptw_guest_read_ratio" : "0.0",
"trans/s  lpm_iommu_trans_per_sec" : "971.5"}
{"socket" : "S1", "counters" : 0,
"reads/tlb_miss  lpm_iommu_ptw_reads_per_tlb_miss" : "none",
"%  lpm_iommu_ptw_nested_read_ratio" : "none",
"%  lpm_iommu_ptw_guest_read_ratio" : "none,
"trans/s  lpm_iommu_trans_per_sec" : "none"}

Signed-off-by: Jacob Lefkowitz <jlefkowi@akamai.com>
---
 tools/perf/pmu-events/amd_metrics.py | 45 ++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py
index 42569b9153f4..452b88033492 100755
--- a/tools/perf/pmu-events/amd_metrics.py
+++ b/tools/perf/pmu-events/amd_metrics.py
@@ -318,6 +318,50 @@ def AmdIotlb() -> Optional[MetricGroup]:
     )
 
 
+def AmdIommuptw() -> Optional[MetricGroup]:
+    if _zen_model < 2:
+        return None
+
+    walks = Event("amd_iommu/mem_iommu_tlb_pte_mis/") + Event(
+        "amd_iommu/mem_iommu_tlb_pde_mis/"
+    )
+    pt_rd = Event("amd_iommu/page_tbl_read_tot/")
+    pt_rd_nst = Event("amd_iommu/page_tbl_read_nst/")
+    pt_rd_gst = Event("amd_iommu/page_tbl_read_gst/")
+    trans = Event("amd_iommu/mem_trans_total/")
+
+    return MetricGroup(
+        "iommuptw",
+        [
+            Metric(
+                "lpm_iommu_ptw_reads_per_tlb_miss",
+                "Average IOMMU page table reads per IOTLB miss",
+                d_ratio(pt_rd, walks),
+                "reads/tlb_miss"
+            ),
+            Metric(
+                "lpm_iommu_ptw_nested_read_ratio",
+                "Share of IOMMU page table reads from nested (host) tables",
+                d_ratio(pt_rd_nst, pt_rd),
+                "100%"
+            ),
+            Metric(
+                "lpm_iommu_ptw_guest_read_ratio",
+                "Share of IOMMU page table reads from guest tables",
+                d_ratio(pt_rd_gst, pt_rd),
+                "100%"
+            ),
+            Metric(
+                "lpm_iommu_trans_per_sec",
+                "IOMMU translation requests per second",
+                d_ratio(trans, interval_sec),
+                "trans/s"
+            )
+        ],
+        description="IOMMU page table walk metrics"
+    )
+
+
 def AmdItlb():
     l2h = Event("bp_l1_tlb_miss_l2_tlb_hit", "bp_l1_tlb_miss_l2_hit")
     l2m = Event("bp_l1_tlb_miss_l2_tlb_miss.all", "l2_itlb_misses",)
@@ -526,6 +570,7 @@ def main() -> None:
         AmdCtxSw(),
         AmdDtlb(),
         AmdIotlb(),
+        AmdIommuptw(),
         AmdItlb(),
         AmdLdSt(),
         AmdUpc(),

-- 
2.53.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] perf jevents: add amd specific device table entry metrics
  2026-11-02 21:14 [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics Jacob Lefkowitz via B4 Relay
  2026-11-02 21:14 ` [PATCH v2 1/2] perf jevents: add iommu page table walk metrics Jacob Lefkowitz via B4 Relay
@ 2026-11-02 21:14 ` Jacob Lefkowitz via B4 Relay
  2026-11-10  3:22 ` [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device " Hang Zhengyang
  2 siblings, 0 replies; 4+ messages in thread
From: Jacob Lefkowitz via B4 Relay @ 2026-11-02 21:14 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: linux-perf-users, linux-kernel, Ben Chaney, Matt Pelland,
	Jacob Lefkowitz

From: Jacob Lefkowitz <jlefkowi@akamai.com>

Adds AMD specific device table entry metrics to perf jevents.
These metrics are only allowed on Zen 2+ processors and are
implemented using the 'amd_iommu' PMU events.

The list of metrics added are:
- lpm_iommu_dte_miss_rate
- lpm_iommu_dte_lookups

The metrics were tested with the standard 'sleep' workload:

perf stat -M iommudte --per-socket --metric-only -j -a -- sleep 10
{"socket" : "S0", "counters" : 8,
"lookups/s  lpm_iommu_dte_lookups" : "4117.3",
"%  lpm_iommu_dte_miss_rate" : "0.0"}
{"socket" : "S1", "counters" : 0,
"lookups/s  lpm_iommu_dte_lookups" : "none",
"%  lpm_iommu_dte_miss_rate" : "none"}

Signed-off-by: Jacob Lefkowitz <jlefkowi@akamai.com>
---
 tools/perf/pmu-events/amd_metrics.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py
index 452b88033492..fd0bd9f16529 100755
--- a/tools/perf/pmu-events/amd_metrics.py
+++ b/tools/perf/pmu-events/amd_metrics.py
@@ -318,6 +318,35 @@ def AmdIotlb() -> Optional[MetricGroup]:
     )
 
 
+def AmdIommudte() -> Optional[MetricGroup]:
+    if _zen_model < 2:
+        return None
+
+    dte_hit = Event("amd_iommu/mem_dte_hit/")
+    dte_mis = Event("amd_iommu/mem_dte_mis/")
+    lookups = dte_hit + dte_mis
+
+    return MetricGroup(
+        "iommudte",
+        [
+            Metric(
+                "lpm_iommu_dte_miss_rate",
+                "IOMMU device table cache miss rate",
+                d_ratio(dte_mis, lookups),
+                "100%"
+            ),
+            Metric(
+                "lpm_iommu_dte_lookups",
+                "IOMMU device table cache lookups",
+                d_ratio(lookups, interval_sec),
+                "lookups/s"
+            )
+        ],
+        description="IOMMU Device Table Cache Metrics"
+    )
+
+
+
 def AmdIommuptw() -> Optional[MetricGroup]:
     if _zen_model < 2:
         return None
@@ -570,6 +599,7 @@ def main() -> None:
         AmdCtxSw(),
         AmdDtlb(),
         AmdIotlb(),
+        AmdIommudte(),
         AmdIommuptw(),
         AmdItlb(),
         AmdLdSt(),

-- 
2.53.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics
  2026-11-02 21:14 [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics Jacob Lefkowitz via B4 Relay
  2026-11-02 21:14 ` [PATCH v2 1/2] perf jevents: add iommu page table walk metrics Jacob Lefkowitz via B4 Relay
  2026-11-02 21:14 ` [PATCH v2 2/2] perf jevents: add amd specific device table entry metrics Jacob Lefkowitz via B4 Relay
@ 2026-11-10  3:22 ` Hang Zhengyang
  2 siblings, 0 replies; 4+ messages in thread
From: Hang Zhengyang @ 2026-11-10  3:22 UTC (permalink / raw)
  To: Jacob Lefkowitz
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark, Ravi Bangoria,
	Ben Chaney, Matt Pelland, linux-perf-users, linux-kernel

On Mon, 02 Nov 2026 21:14:15 +0000, Jacob Lefkowitz wrote:
> Adds AMD specific metrics for the IOMMU with respect to page table
> walks and device table entires.

Tested on Zen 3 (Ryzen 7 PRO 5850U) on top of perf-tools-next
13a8d580433a.  Both groups show up and count, perf test 130 and 131
pass, and under O_DIRECT reads from NVMe the values match the raw
amd_iommu_0 counts.

Tested-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>

Two values look odd on this machine:

 - lpm_iommu_ptw_nested_read_ratio is 100% with no guest running:
   page_tbl_read_nst equals page_tbl_read_tot.

 - lpm_iommu_ptw_reads_per_tlb_miss is about 0.2: 142588 page table
   reads against 440805 pte and 192018 pde misses.

Ravi, are these expected on Zen 3?

(Tested with the help of an AI assistant; I checked the results.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-10  3:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 21:14 [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device entry metrics Jacob Lefkowitz via B4 Relay
2026-11-02 21:14 ` [PATCH v2 1/2] perf jevents: add iommu page table walk metrics Jacob Lefkowitz via B4 Relay
2026-11-02 21:14 ` [PATCH v2 2/2] perf jevents: add amd specific device table entry metrics Jacob Lefkowitz via B4 Relay
2026-11-10  3:22 ` [PATCH v2 0/2] perf jevents: Add IOMMU PTW & device " Hang Zhengyang

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®