mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Besar Wicaksono <bwicaksono@nvidia.com>
To: <acme@kernel.org>, <namhyung@kernel.org>, <irogers@google.com>,
	<ctshao@google.com>
Cc: <linux-tegra@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-perf-users@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <vsethi@nvidia.com>,
	<rwiley@nvidia.com>, <skelley@nvidia.com>, <mochs@nvidia.com>,
	<rajjoshi@nvidia.com>, <treding@nvidia.com>,
	<jonathanh@nvidia.com>, <john.garry@linux.dev>, <will@kernel.org>,
	<james.clark@linaro.org>, <mike.leach@arm.com>,
	<leo.yan@linux.dev>, <mark.rutland@arm.com>,
	<alexander.shishkin@linux.intel.com>, <jolsa@kernel.org>,
	<adrian.hunter@intel.com>,
	Besar Wicaksono <bwicaksono@nvidia.com>
Subject: [PATCH v3 7/7] perf pmus: Treat both numbers of NVIDIA PCIe PMU names as suffix
Date: Wed, 4 Nov 2026 16:07:16 +0000	[thread overview]
Message-ID: <20261104160716.2910873-8-bwicaksono@nvidia.com> (raw)
In-Reply-To: <20261104160716.2910873-1-bwicaksono@nvidia.com>

The NVIDIA PCIe and PCIe target PMUs are named <name>_<socket>_rc_<rc>,
like nvidia_pcie_pmu_1_rc_3. pmu_name_len_no_suffix() only strips the
last number, so perf treats the PMUs of each socket as a different PMU.
An event or metric on all PCIe PMUs then gives one result per socket,
each labelled with the first RC of its socket.

Make pmu_name_len_no_suffix() strip both numbers of these names, so the
instances on all sockets are merged as one PMU, nvidia_pcie_pmu or
nvidia_pcie_tgt_pmu. Also accept that name on the command line, as perf
list shows it, and sort these PMUs by socket and then by RC.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Besar Wicaksono <bwicaksono@nvidia.com>
---
 tools/perf/util/pmu.c  |  9 +++++++++
 tools/perf/util/pmus.c | 23 +++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 01753d5c69d1..1ae8bcf71c68 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -926,6 +926,15 @@ static bool perf_pmu__match_wildcard(const char *pmu_name, const char *tok)
 	bool has_underscore = false;
 	size_t tok_len = strlen(tok);
 
+	if (strstarts(pmu_name, "nvidia_")) {
+		/* NVIDIA PMU with a non-ABI suffix of nvidia_..._[0-9]+_rc_[0-9]+. */
+		const char *rc = strstr(pmu_name, "_rc_");
+
+		if (rc && isdigit(rc[-1]) && tok_len == pmu_name_len_no_suffix(pmu_name) &&
+		    !strncmp(pmu_name, tok, tok_len))
+			return true;
+	}
+
 	/* Check start of pmu_name for equality. */
 	if (strncmp(pmu_name, tok, tok_len))
 		return false;
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index 1355b317f3ed..8d3238fd23f1 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -67,6 +67,15 @@ size_t pmu_name_len_no_suffix(const char *str)
 {
 	int orig_len, len;
 	bool has_hex_digits = false;
+	const char *rc = strstr(str, "_rc_");
+
+	if (strstarts(str, "nvidia_") && rc && isdigit(rc[-1])) {
+		/* NVIDIA PMU with a non-ABI suffix of nvidia_..._[0-9]+_rc_[0-9]+. */
+		while (isdigit(rc[-1]))
+			rc--;
+		if (rc[-1] == '_')
+			return rc - str - 1;
+	}
 
 	orig_len = len = strlen(str);
 
@@ -106,6 +115,20 @@ int pmu_name_cmp(const char *lhs_pmu_name, const char *rhs_pmu_name)
 	if (rhs_pmu_name_len + 1 < strlen(rhs_pmu_name))
 		rhs_num = strtoull(&rhs_pmu_name[rhs_pmu_name_len + 1], NULL, 16);
 
+	if (lhs_num == rhs_num && strstarts(lhs_pmu_name, "nvidia_")) {
+		/*
+		 * NVIDIA PMU with a non-ABI suffix of nvidia_..._[0-9]+_rc_[0-9]+:
+		 * compare the RC too.
+		 */
+		const char *lhs_rc = strstr(lhs_pmu_name, "_rc_");
+		const char *rhs_rc = strstr(rhs_pmu_name, "_rc_");
+
+		if (lhs_rc && rhs_rc && isdigit(lhs_rc[-1]) && isdigit(rhs_rc[-1])) {
+			lhs_num = strtoull(lhs_rc + 4, NULL, 10);
+			rhs_num = strtoull(rhs_rc + 4, NULL, 10);
+		}
+	}
+
 	return lhs_num < rhs_num ? -1 : (lhs_num > rhs_num ? 1 : 0);
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-11-04 16:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 16:07 [PATCH v3 0/7] perf: Add NVIDIA Tegra410 uncore PMU events and metrics Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 1/7] perf jevents: Add support for NVIDIA Tegra410 UCF PMU aliasing Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 2/7] perf jevents: Add support for NVIDIA Tegra410 PCIE " Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 3/7] perf jevents: Add support for NVIDIA Tegra410 PCIE-TGT " Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 4/7] perf jevents: Add support for NVIDIA Tegra410 CPU Memory Latency " Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 5/7] perf jevents: Add support for NVIDIA Tegra410 C2C " Besar Wicaksono
2026-11-04 16:20   ` Ian Rogers
2026-11-04 16:46     ` Besar Wicaksono
2026-11-04 16:07 ` [PATCH v3 6/7] perf stat: Check merged PMU instance's cpumasks when skipping zero counts Besar Wicaksono
2026-11-04 16:07 ` Besar Wicaksono [this message]
2026-11-04 16:25 ` [PATCH v3 0/7] perf: Add NVIDIA Tegra410 uncore PMU events and metrics Ian Rogers

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=20261104160716.2910873-8-bwicaksono@nvidia.com \
    --to=bwicaksono@nvidia.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ctshao@google.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=john.garry@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=leo.yan@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mike.leach@arm.com \
    --cc=mochs@nvidia.com \
    --cc=namhyung@kernel.org \
    --cc=rajjoshi@nvidia.com \
    --cc=rwiley@nvidia.com \
    --cc=skelley@nvidia.com \
    --cc=treding@nvidia.com \
    --cc=vsethi@nvidia.com \
    --cc=will@kernel.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

all inboxes | Powered by JetHome®