[SRU][N:gke][PATCH 086/106] perf: arm_cspmu: nvidia: monitor all ports by default

Tim Whisonant tim.whisonant at canonical.com
Mon Jul 21 16:22:09 UTC 2025


From: Besar Wicaksono <bwicaksono at nvidia.com>

BugLink: https://bugs.launchpad.net/bugs/2117098

Some NVIDIA PMUs like the NVLINK-C2C, CNVLINK, and PCIE PMU provide
port filtering. If the port filter is set to zero, the counter of
these PMUs will not capture any event. To avoid meaningless
experiment, the driver sets the port filter value to a default
non-zero value.

Signed-off-by: Besar Wicaksono <bwicaksono at nvidia.com>
Link: https://lore.kernel.org/r/20241031142118.1865965-5-bwicaksono@nvidia.com
Signed-off-by: Will Deacon <will at kernel.org>
(cherry picked from commit bce61d5c57647ca4565847217fe811260cc60173)
Signed-off-by: Tim Whisonant <tim.whisonant at canonical.com>
---
 Documentation/admin-guide/perf/nvidia-pmu.rst | 12 ++++++++----
 drivers/perf/arm_cspmu/nvidia_cspmu.c         |  6 ++++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Documentation/admin-guide/perf/nvidia-pmu.rst b/Documentation/admin-guide/perf/nvidia-pmu.rst
index 4cfc806070d71..f538ef67e0e8f 100644
--- a/Documentation/admin-guide/perf/nvidia-pmu.rst
+++ b/Documentation/admin-guide/perf/nvidia-pmu.rst
@@ -89,7 +89,8 @@ Example usage:
 The NVLink-C2C has two ports that can be connected to one GPU (occupying both
 ports) or to two GPUs (one GPU per port). The user can use "port" bitmap
 parameter to select the port(s) to monitor. Each bit represents the port number,
-e.g. "port=0x1" corresponds to port 0 and "port=0x3" is for port 0 and 1.
+e.g. "port=0x1" corresponds to port 0 and "port=0x3" is for port 0 and 1. The
+PMU will monitor both ports by default if not specified.
 
 Example for port filtering:
 
@@ -134,7 +135,8 @@ Example usage:
 The NVLink-C2C has two ports that can be connected to one GPU (occupying both
 ports) or to two GPUs (one GPU per port). The user can use "port" bitmap
 parameter to select the port(s) to monitor. Each bit represents the port number,
-e.g. "port=0x1" corresponds to port 0 and "port=0x3" is for port 0 and 1.
+e.g. "port=0x1" corresponds to port 0 and "port=0x3" is for port 0 and 1. The
+PMU will monitor both ports by default if not specified.
 
 Example for port filtering:
 
@@ -160,7 +162,8 @@ see /sys/bus/event_source/devices/nvidia_cnvlink_pmu_<socket-id>.
 Each SoC socket can be connected to one or more sockets via CNVLink. The user can
 use "rem_socket" bitmap parameter to select the remote socket(s) to monitor.
 Each bit represents the socket number, e.g. "rem_socket=0xE" corresponds to
-socket 1 to 3.
+socket 1 to 3. The PMU will monitor all remote sockets by default if not
+specified.
 /sys/bus/event_source/devices/nvidia_cnvlink_pmu_<socket-id>/format/rem_socket
 shows the valid bits that can be set in the "rem_socket" parameter.
 
@@ -199,7 +202,8 @@ see /sys/bus/event_source/devices/nvidia_pcie_pmu_<socket-id>.
 
 Each SoC socket can support multiple root ports. The user can use
 "root_port" bitmap parameter to select the port(s) to monitor, i.e.
-"root_port=0xF" corresponds to root port 0 to 3.
+"root_port=0xF" corresponds to root port 0 to 3. The PMU will monitor all root
+ports by default if not specified.
 /sys/bus/event_source/devices/nvidia_pcie_pmu_<socket-id>/format/root_port
 shows the valid bits that can be set in the "root_port" parameter.
 
diff --git a/drivers/perf/arm_cspmu/nvidia_cspmu.c b/drivers/perf/arm_cspmu/nvidia_cspmu.c
index e48ace63c739d..4a1ef3ecd6622 100644
--- a/drivers/perf/arm_cspmu/nvidia_cspmu.c
+++ b/drivers/perf/arm_cspmu/nvidia_cspmu.c
@@ -175,10 +175,12 @@ static u32 nv_cspmu_event_filter(const struct perf_event *event)
 	const struct nv_cspmu_ctx *ctx =
 		to_nv_cspmu_ctx(to_arm_cspmu(event->pmu));
 
-	if (ctx->filter_mask == 0)
+	const u32 filter_val = event->attr.config1 & ctx->filter_mask;
+
+	if (filter_val == 0)
 		return ctx->filter_default_val;
 
-	return event->attr.config1 & ctx->filter_mask;
+	return filter_val;
 }
 
 enum nv_cspmu_name_fmt {
-- 
2.43.0




More information about the kernel-team mailing list