Linux Perf Users
 help / color / mirror / Atom feed
From: Chun-Tse Shao <ctshao@google.com>
To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	 namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com,  jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	 james.clark@linaro.org, Chun-Tse Shao <ctshao@google.com>
Subject: [PATCH] perf jevents: Add dynamic IIO PCIe bandwidth metrics for Intel
Date: Thu,  9 Jul 2026 11:39:56 -0700	[thread overview]
Message-ID: <20260709183956.1545402-1-ctshao@google.com> (raw)

Generate per-IIO-device PCIe read and write bandwidth metrics
(iio_bandwidth_read_per_device_0, etc.) grouped under
iio_bandwidth_per_device for Sapphire Rapids and newer architectures
in intel_metrics.py.

By using has_event() checks across up to 24 possible IIO stack indices,
runtime perf automatically monitors only the IIO root complexes present
on the system without failing on missing instances.

Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Assisted-by: Gemini:gemini-3.1-pro-preview
---
 tools/perf/pmu-events/intel_metrics.py | 52 ++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index bc2b920d3a0d..4f8a123a375d 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -1132,6 +1132,57 @@ def UncoreUpiBw() -> Optional[MetricGroup]:
     ], description="UPI Bandwidth")
 
 
+def UncoreIioBw() -> Optional[MetricGroup]:
+    if _args.model not in [
+        "sapphirerapids",
+        "emeraldrapids",
+        "graniterapids",
+        "sierraforest",
+        "clearwaterforest",
+    ]:
+      return None
+
+    # On multi-socket x86 servers, there can be multiple IIO stacks per socket.
+    # We generate metrics up to index 23 with has_event check so runtime perf
+    # only measures the IIO instances present on the system.
+    max_iios = 24
+    metrics = []
+    scale = 4 / 1_000_000
+    for i in range(max_iios):
+      rd_event = Event(
+          f"uncore_iio_{i}/UNC_IIO_DATA_REQ_OF_CPU.MEM_READ.ALL_PARTS/"
+      )
+      wr_event = Event(
+          f"uncore_iio_{i}/UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.ALL_PARTS/"
+      )
+      rd_bw = Select(d_ratio(rd_event, interval_sec), has_event(rd_event), 0)
+      wr_bw = Select(d_ratio(wr_event, interval_sec), has_event(wr_event), 0)
+      metrics.append(
+          MetricGroup(
+              f"iio_bandwidth_per_device_iio{i}",
+              [
+                  Metric(
+                      f"iio_bandwidth_read_per_device_{i}",
+                      f"IIO {i} read bandwidth",
+                      rd_bw,
+                      f"{scale}MB/s",
+                  ),
+                  Metric(
+                      f"iio_bandwidth_write_per_device_{i}",
+                      f"IIO {i} write bandwidth",
+                      wr_bw,
+                      f"{scale}MB/s",
+                  ),
+              ],
+          )
+      )
+    return MetricGroup(
+        "iio_bandwidth_per_device",
+        metrics,
+        description="IIO Read/Write Bandwidth per root complex",
+    )
+
+
 def main() -> None:
     global _args
 
@@ -1179,6 +1230,7 @@ def main() -> None:
         UncoreMemBw(),
         UncoreMemSat(),
         UncoreUpiBw(),
+        UncoreIioBw(),
     ])
 
     if _args.metricgroups:
-- 
2.55.0.795.g602f6c329a-goog


             reply	other threads:[~2026-07-09 18:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 18:39 Chun-Tse Shao [this message]
2026-07-09 21:33 ` [PATCH] perf jevents: Add dynamic IIO PCIe bandwidth metrics for Intel Chun-Tse Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260709183956.1545402-1-ctshao@google.com \
    --to=ctshao@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox