From nobody Sat Oct 4 00:28:11 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 462602DECCB for ; Thu, 21 Aug 2025 22:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814724; cv=none; b=r9wxrYBQsBSrVT30PkIYYKcng0MhkcSc8+DSAChfUzKYQ6vD9gQ+sEOp9nNnIyJV2q1UlBrK9Ktu8w9epHhfN84L2zDcKpPkXKamhB947AfL39iWaXXsl8AKBhF/TW6ocu0fhjj4EiaXrMOCQuwHKiCSjQIraFEJShYwvsZvnIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814724; c=relaxed/simple; bh=J7ChrngqpcfMVz2fjEKux0G9mXXIk8ji2VlMy8Zpuqs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Gnmp2NVnBh/RZTXhdHRDI7l3I37lIYovnxXk7X05L43s7AkSvKXyjE8Gmt+6TQXCYOEoLtqxBURFAx5C+ftbmVDGdifu4K8WegxoTJnD8CU0adbfP5aVJ7TfXREzeqj/PS9pxq5mbfbRve88lvuIpjLXVTVIaCYk+XCVo0/T+8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kaUGfGV7; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kaUGfGV7" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-324e4c3af5fso1660531a91.3 for ; Thu, 21 Aug 2025 15:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755814722; x=1756419522; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1+LcGUNRQ5RMIFxRYxYFNAWt5Jv3NM5GtSeI5RVke4w=; b=kaUGfGV7wGherh3zcrd2gLDql1rMqFWRGoVB9r7jrc8rguNkx3hPkOKIGiyLlPvSzp H+nFBnofdoAe34N0mPWz9FBCz6SVX4sBQShtKB0BYZoJKWOU5hdRzG/XlIS45ma+wS1M UqM5lBymgx6n6l6VvPTNP/nFg13j+KR4O414YCA6316a0AHwemqeGfL+BYQc+61FgXlN aZmZaOUP3o5RMQ38i3jALaK4mv2yn4ZBkQNSJkpBAaxzSbBOZ/vw7eYvwlRyuHVNs1Rd 2Xs1B3Xbz/PNzTbJabZahP5ONWUZuKnoJGMkDB8BY971XczuAsXhVOFw3qALMFcY+6bd qCDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755814722; x=1756419522; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1+LcGUNRQ5RMIFxRYxYFNAWt5Jv3NM5GtSeI5RVke4w=; b=aiK1njvaP8vfqIKE8AG4+GvvlxapiAoQLqc4jIRtdwHCv3Iv7ZXSKkjFfwBiazDvki 95IWKdzw1t2ZU1wwqt1CQYTM7oWtX/Wd4YH6rQtakm1DtvmIm0my2T9fweI2mMjinOMc V3azk+q/o+uR55l4B2wRgy8zhLYO4EV3M/0SefudwC7ahOEPKelE8ZWmtqVCIZQUmM9G HPtdunXgcerjEdeQZjaSmEZ2idIKThRGsuAMqzv/K2w57Qhkn1Stm4w9/NleciRisoEy sFDGjGIrH/YDRyYFdd1EVbN5mYB0NxUeo55R+8YjYM/pu3lQHJ+WRUPcWliy7hpC86H+ 4Zbw== X-Forwarded-Encrypted: i=1; AJvYcCX704T6yjLriOA3Z6Qd5kSWrmFMCgwznCHEMnzEJhSqGUQ7flwDgx8T7upQeLEhrpyqJIPFMa6XCcS8Kn8=@vger.kernel.org X-Gm-Message-State: AOJu0YxwckBSbYssr0d1k6evoFxh2s/X9lN4OWA9iGXDv3DRVzThXvjv pwQXhPC5i1ZTZccBE7wqIXPqCsN0G98jFk2jR2W5RUgHpWeoActogn4fWtFrXwXG8JBUiNaqKzk 5FLNZbqYMfA== X-Google-Smtp-Source: AGHT+IFRjX/YkmMOyRzOeSEN3Qyl0b3TIZqfvF6f2Y1S8hBFFf5SoflTeJWXoMaNozCBAlu/0mWo3kcVYOG3 X-Received: from pjyp4.prod.google.com ([2002:a17:90a:e704:b0:321:6924:af9a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1d06:b0:324:e03a:662e with SMTP id 98e67ed59e1d1-32515eaeeecmr1419681a91.23.1755814722551; Thu, 21 Aug 2025 15:18:42 -0700 (PDT) Date: Thu, 21 Aug 2025 15:18:31 -0700 In-Reply-To: <20250821221834.1312002-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821221834.1312002-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.rc2.233.g662b1ed5c5-goog Message-ID: <20250821221834.1312002-2-irogers@google.com> Subject: [PATCH v1 1/4] perf test shell lbr: Avoid failures with perf event paranoia From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Chun-Tse Shao , James Clark , Howard Chu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When not running as root and with higher perf event paranoia values the perf record LBR tests could fail rather than skipping the problematic tests. Add the sensitivity to the test and confirm it passes with paranoia values from -1 to 2. Fixes: 32559b99e0f5 ("perf test: Add set of perf record LBR tests") Signed-off-by: Ian Rogers --- tools/perf/tests/shell/record_lbr.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/shell/record_lbr.sh b/tools/perf/tests/shell/= record_lbr.sh index 6fcb5e52b9b4..78a02e90ece1 100755 --- a/tools/perf/tests/shell/record_lbr.sh +++ b/tools/perf/tests/shell/record_lbr.sh @@ -4,6 +4,10 @@ =20 set -e =20 +ParanoidAndNotRoot() { + [ "$(id -u)" !=3D 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)"= -gt $1 ] +} + if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] && [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ] then @@ -23,6 +27,7 @@ cleanup() { } =20 trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" cleanup exit 1 } @@ -123,8 +128,11 @@ lbr_test "-j ind_call" "any indirect call" 2 lbr_test "-j ind_jmp" "any indirect jump" 100 lbr_test "-j call" "direct calls" 2 lbr_test "-j ind_call,u" "any indirect user call" 100 -lbr_test "-a -b" "system wide any branch" 2 -lbr_test "-a -j any_call" "system wide any call" 2 +if ! ParanoidAndNotRoot 1 +then + lbr_test "-a -b" "system wide any branch" 2 + lbr_test "-a -j any_call" "system wide any call" 2 +fi =20 # Parallel parallel_lbr_test "-b" "parallel any branch" 100 & @@ -141,10 +149,16 @@ parallel_lbr_test "-j call" "parallel direct calls" 1= 00 & pid6=3D$! parallel_lbr_test "-j ind_call,u" "parallel any indirect user call" 100 & pid7=3D$! -parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & -pid8=3D$! -parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & -pid9=3D$! +if ParanoidAndNotRoot 1 +then + pid8=3D + pid9=3D +else + parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & + pid8=3D$! + parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & + pid9=3D$! +fi =20 for pid in $pid1 $pid2 $pid3 $pid4 $pid5 $pid6 $pid7 $pid8 $pid9 do --=20 2.51.0.rc2.233.g662b1ed5c5-goog From nobody Sat Oct 4 00:28:11 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25AA52E040E for ; Thu, 21 Aug 2025 22:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814726; cv=none; b=BidQkkTlcl9qckOoPgzDbgDXgCXhoZG3LP8MWyEE/wg1NHXqyY02dLIgwZuKVZviiyYb3iS/vn7b4xC98sjfv1oHnZXYYHtgvjJaOZMXZt+cGukQjZJhwoPBk6lCODSGR4OOlX478fL3L1DY26bQGq5UU+cIexZK+zdSLYlvKaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814726; c=relaxed/simple; bh=pC3oTqGmEsbEt4OxH9Elyo+yIbWIxVyDUKn5/mFJws8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=tkG24StkSxh7CCM99Kn9oTBfBGqCfeHpM8oiKd7p90kCSaO2sGWdYgGR1e7/7dlioHBXCyWa1Fzg0c1OXaw3V0NZ4xOWBz19IADPIsXiHdRe5kQAWhIRBlOR2WDnN6hNF0IGJq4NoLJcdBfSEyVvIltSJrZLudMBqZRh3B2FcAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gUelvo9K; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gUelvo9K" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-24456ebed7bso17801085ad.0 for ; Thu, 21 Aug 2025 15:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755814724; x=1756419524; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=QMK8YRDl6tbueEXroDXpvtDeHvmmbYj4KZWTDPAsswM=; b=gUelvo9Kk1LyRp0PFPIR0Fg1J91aJhxaQ5Mfnv98Y73X3jcM4NiXvqZaH1hpU8mFm2 ZvsBxvT4bQll2QRMKqdknJoKyekbCSK12NegrKvklqd8jtEIR/9m1oxU0ts73L3bV/Ue fJ4QllLh99vx3y0w3clbsLyKMTR1EfCEb4Wg8pLhD0g3PJETE6nOmnMq7NgpFTKz3t6G fGtJ0vDTb40S0C5jOcTpbeq56SbkEbfY47opXwfKjRFJL1qRf+q1HzwbP3O8x95iK08U QF+8XZa4hcTZA2ahTbRfSkqwmQPCd5AVPFSCCh9KbW2MvMRPqCXDNwP7PKymthFLOT/q lerg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755814724; x=1756419524; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QMK8YRDl6tbueEXroDXpvtDeHvmmbYj4KZWTDPAsswM=; b=Ez0phZS0Q/5E8iujP0Ya1cWur/7xDyXs2oCXskZFmR3smd64SI3+k0KX0ymO30HUhG bW5XQu1VBE/SJP2McFG7scMq92LYtkmK6qEZB168Xxg200NaSS9Qm0SiqoI0SmlovQWF TShGi6RPVvpzr09JSmii5YJ4PUhO3M6FFPwabDPmkoMIPzKZbolKntid74hH4xsAzlIQ DsS/WX6zRsRhz3FTCCAXlqzMNXZH5fRqAtTfuX3kYgBRz+Ic37z/wju/FMUf7j+8m59A hXjnys8fXksdAnwHs3oVeQPVOaASf6EW9OTIoP7EDLA2J8zwjTwE1xCyBSnRxpiLzmEw 8Y1Q== X-Forwarded-Encrypted: i=1; AJvYcCWqt1xQx+VajkiH5t5XKXbWppp72k15QX1aYN9ylk8c4KfkFhmoj6kG2z01QPss2Oz9j4ez0MaRgZ8aGS8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw97z2S+L62KIHOniZPlmVmucKqSjIBbsn9Vp5F5GTNfKRZHJ1H tdPV6G+2ylxQqJu7FGyNwlFLBJ8b8+NpWgDh4ff4Xh6PjMEZQjz/U9f7a21JvohKGL0IU+HiGXh BwlsrLmhYdw== X-Google-Smtp-Source: AGHT+IF5v5/MSMYnzH2Y2uzTNLw3UFS8LArgiun1kOHl2+wczk+rayPaWjc7DoSce7GpVnO+D03KscvOqBa1 X-Received: from plbkz8.prod.google.com ([2002:a17:902:f9c8:b0:242:fd00:6a87]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2f44:b0:246:2cb3:5768 with SMTP id d9443c01a7336-2463406731emr9150605ad.30.1755814724357; Thu, 21 Aug 2025 15:18:44 -0700 (PDT) Date: Thu, 21 Aug 2025 15:18:32 -0700 In-Reply-To: <20250821221834.1312002-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821221834.1312002-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.rc2.233.g662b1ed5c5-goog Message-ID: <20250821221834.1312002-3-irogers@google.com> Subject: [PATCH v1 2/4] perf test: Don't leak workload gopipe in PERF_RECORD_* From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Chun-Tse Shao , James Clark , Howard Chu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The test starts a workload and then opens events. If the events fail to open, for example because of perf_event_paranoid, the gopipe of the workload is leaked and the file descriptor leak check fails when the test exits. To avoid this cancel the workload when opening the events fails. Before: ``` $ perf test -vv 7 7: PERF_RECORD_* events & perf_sample fields: --- start --- test child forked, pid 1189568 Using CPUID GenuineIntel-6-B7-1 ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) config 0xa00000000 (cpu_atom/PERF_COUNT_HW_CPU_= CYCLES/) disabled 1 ------------------------------------------------------------ sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 sys_perf_event_open failed, error -13 ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) config 0xa00000000 (cpu_atom/PERF_COUNT_HW_CPU_= CYCLES/) disabled 1 exclude_kernel 1 ------------------------------------------------------------ sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 =3D 3 ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) config 0x400000000 (cpu_core/PERF_COUNT_HW_CPU_= CYCLES/) disabled 1 ------------------------------------------------------------ sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 sys_perf_event_open failed, error -13 ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) config 0x400000000 (cpu_core/PERF_COUNT_HW_CPU_= CYCLES/) disabled 1 exclude_kernel 1 ------------------------------------------------------------ sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 =3D 3 Attempt to add: software/cpu-clock/ ..after resolving event: software/config=3D0/ cpu-clock -> software/cpu-clock/ ------------------------------------------------------------ perf_event_attr: type 1 (PERF_TYPE_SOFTWARE) size 136 config 0x9 (PERF_COUNT_SW_DUMMY) sample_type IP|TID|TIME|CPU read_format ID|LOST disabled 1 inherit 1 mmap 1 comm 1 enable_on_exec 1 task 1 sample_id_all 1 mmap2 1 comm_exec 1 ksymbol 1 bpf_event 1 { wakeup_events, wakeup_watermark } 1 ------------------------------------------------------------ sys_perf_event_open: pid 1189569 cpu 0 group_fd -1 flags 0x8 sys_perf_event_open failed, error -13 perf_evlist__open: Permission denied ---- end(-2) ---- Leak of file descriptor 6 that opened: 'pipe:[14200347]' ---- unexpected signal (6) ---- Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon Failed to read build ID for //anon #0 0x565358f6666e in child_test_sig_handler builtin-test.c:311 #1 0x7f29ce849df0 in __restore_rt libc_sigaction.c:0 #2 0x7f29ce89e95c in __pthread_kill_implementation pthread_kill.c:44 #3 0x7f29ce849cc2 in raise raise.c:27 #4 0x7f29ce8324ac in abort abort.c:81 #5 0x565358f662d4 in check_leaks builtin-test.c:226 #6 0x565358f6682e in run_test_child builtin-test.c:344 #7 0x565358ef7121 in start_command run-command.c:128 #8 0x565358f67273 in start_test builtin-test.c:545 #9 0x565358f6771d in __cmd_test builtin-test.c:647 #10 0x565358f682bd in cmd_test builtin-test.c:849 #11 0x565358ee5ded in run_builtin perf.c:349 #12 0x565358ee6085 in handle_internal_command perf.c:401 #13 0x565358ee61de in run_argv perf.c:448 #14 0x565358ee6527 in main perf.c:555 #15 0x7f29ce833ca8 in __libc_start_call_main libc_start_call_main.h:74 #16 0x7f29ce833d65 in __libc_start_main@@GLIBC_2.34 libc-start.c:128 #17 0x565358e391c1 in _start perf[851c1] 7: PERF_RECORD_* events & perf_sample fields : FAIL= ED! ``` After: ``` $ perf test 7 7: PERF_RECORD_* events & perf_sample fields : Skip= (permissions) ``` Fixes: 16d00fee7038 ("perf tests: Move test__PERF_RECORD into separate obje= ct") Signed-off-by: Ian Rogers --- tools/perf/tests/perf-record.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 0b3c37e66871..8c79b5166a05 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -115,6 +115,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest if (err < 0) { pr_debug("sched__get_first_possible_cpu: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); + evlist__cancel_workload(evlist); goto out_delete_evlist; } =20 @@ -126,6 +127,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0= ) { pr_debug("sched_setaffinity: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); + evlist__cancel_workload(evlist); goto out_delete_evlist; } =20 @@ -137,6 +139,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest if (err < 0) { pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); + evlist__cancel_workload(evlist); goto out_delete_evlist; } =20 @@ -149,6 +152,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest if (err < 0) { pr_debug("evlist__mmap: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); + evlist__cancel_workload(evlist); goto out_delete_evlist; } =20 --=20 2.51.0.rc2.233.g662b1ed5c5-goog From nobody Sat Oct 4 00:28:11 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA9522EAB84 for ; Thu, 21 Aug 2025 22:18:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814728; cv=none; b=Crdnj5QxRXL1nghSUEeu4rSLyHxQ8m/fCxDIgx90rvh/mlc20TsqZAVO5fNyXcS4Gvji7O8Q95RGBZj9vwHPLhYalD1LalOO10zBxPy8WQjGVV3kjMXJFSvWrM6sWrlPXmr8eLbhj3PJbhdNEEEWXUwqERq0tDtGHzJRNDeRbmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814728; c=relaxed/simple; bh=fbQi14GqPscWDRXsuaN+KHcS/bYHMtgBEgiE1yKNiWc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QK6qHMnZlIzTVeBA0f/6oK9JgccQvhYafE9kPhp59dYxFsBpihcceSmzi9qx1eOZvcDGOcVxKqQvlYcz7u61xn4ZdN3k2mSFNKMxWO/wKvU2PPPyhtkEySRhPEE8+hi+MH8efWCo3/2hh4I3p/GjpAYASE/2IdQFxCHWFeyOeTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=W2YscNyg; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="W2YscNyg" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-323266ce853so2802183a91.0 for ; Thu, 21 Aug 2025 15:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755814726; x=1756419526; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=dTccXPd7+v6/+rANPjgROi6ymWhIsKsDtgiSee4TJ28=; b=W2YscNygGieDSHMEeIgrlNztBrJOoV7MZt0jYr/kld0J3grEdETY8Bu8eQizkHEE0H TuDwhm+5gnfdVFM9v48kw1ENiY+xEBJoxa+LOB7GUnMotpI+5K9j2m1788Y+fuIYf4+1 L+TazcblVRMourvTHrREmo6cIddV6JriX2MArksSwH7BrYtLmnfd4BozvsvvnNNtEpOX otezFxg51OpgMcqPf1v+R4WsHm0OfRHBZuhI1Sc/txlcXnoI0KtqZ9JIVJxBbhtt5r5K XuRk6tYSffTQSYvGCDujuFKv9C+7ljn9WLCR5mWt7XfA6oChME/NEBMns/+YUNF3T4V9 1vgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755814726; x=1756419526; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dTccXPd7+v6/+rANPjgROi6ymWhIsKsDtgiSee4TJ28=; b=eNNEP+A4QE7BqkJowWxEkrycw3a8USc+TlVaCrh3m5CEfo5TefjVZCV08W3TxBWicG rmxKBhCE5hHGaDrbfaIOuVH6Wqsh8C/IYp4XrWhrXzYXkuzEbXi7CIjnl6INm4QYb5dQ Oh0KLxjIWYUSzBOU2mi9GLNl3JRShMKV76h7hg4z+afWYDbsHzlayY8JbTDfj53/Tj7f Fk6N79F3ERTEUoJRlP/7p6iMq8kgej2nSZGYqc8aNLZpZPn4e+lRW+Hkmm2HmBkaJDGS 6foVVN9ck2EkU8C2KcXEbG+Ew5eBFuyHbHBgZWs49Qdfg7Sr30w4sNOqlrc9HCvlwE+9 mrsg== X-Forwarded-Encrypted: i=1; AJvYcCWye8cij2+n5A2raZxb6+NdqT+TP37q36sQ1e1Yi2k/YStwEvmvADemZTf4VpcxGOyKLXPXxwc37PPnYxw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyc1562/IRvWlMP91jo9xx4seCIAMYBPni+tqFQ2qDvqxSVNBMK B6Z9UTYIKAxijGJqmYJ+uCfiVVIodunKSRtgHjQMlWB/logmRWjCcst1UhqwEt/wop9EWrECjaG Mik0WrZGOtA== X-Google-Smtp-Source: AGHT+IHYTLEVbWOFzSCLICihvRMf6bXyZv9JRpV/nHlthIixzEwFOPWfEWnbOTko7BA1kkfGaRewlPLUh7vf X-Received: from pjbqa5.prod.google.com ([2002:a17:90b:4fc5:b0:321:c2d6:d1c3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d88:b0:31f:11d6:cea0 with SMTP id 98e67ed59e1d1-32517d1dd5bmr1283481a91.27.1755814726056; Thu, 21 Aug 2025 15:18:46 -0700 (PDT) Date: Thu, 21 Aug 2025 15:18:33 -0700 In-Reply-To: <20250821221834.1312002-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821221834.1312002-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.rc2.233.g662b1ed5c5-goog Message-ID: <20250821221834.1312002-4-irogers@google.com> Subject: [PATCH v1 3/4] perf evsel: Fix uniquification when PMU given without suffix From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Chun-Tse Shao , James Clark , Howard Chu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The PMU name is appearing twice in: ``` $ perf stat -e uncore_imc_free_running/data_total/ -A true Performance counter stats for 'system wide': CPU0 1.57 MiB uncore_imc_free_running_0/uncore_imc_free_ru= nning,data_total/ CPU0 1.58 MiB uncore_imc_free_running_1/uncore_imc_free_ru= nning,data_total/ 0.000892376 seconds time elapsed ``` Use the pmu_name_len_no_suffix to avoid this problem. Fixes: 7d45f402d311 ("perf evlist: Make uniquifying counter names consisten= t") Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d264c143b592..9a6e2d556d35 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -4048,9 +4048,9 @@ bool evsel__set_needs_uniquify(struct evsel *counter,= const struct perf_stat_con =20 void evsel__uniquify_counter(struct evsel *counter) { - const char *name, *pmu_name; - char *new_name, *config; - int ret; + const char *name, *pmu_name, *config; + char *new_name; + int len, ret; =20 /* No uniquification necessary. */ if (!counter->needs_uniquify) @@ -4064,15 +4064,23 @@ void evsel__uniquify_counter(struct evsel *counter) counter->uniquified_name =3D true; =20 name =3D evsel__name(counter); + config =3D strchr(name, '/'); pmu_name =3D counter->pmu->name; - /* Already prefixed by the PMU name. */ - if (!strncmp(name, pmu_name, strlen(pmu_name))) - return; =20 - config =3D strchr(name, '/'); - if (config) { - int len =3D config - name; + /* Already prefixed by the PMU name? */ + len =3D pmu_name_len_no_suffix(pmu_name); + + if (!strncmp(name, pmu_name, len)) { + /* + * If the PMU name is there, then there is no sense in not + * having a slash. Do this for robustness. + */ + if (config =3D=3D NULL) + config =3D name - 1; =20 + ret =3D asprintf(&new_name, "%s/%s", pmu_name, config + 1); + } else if (config) { + len =3D config - name; if (config[1] =3D=3D '/') { /* case: event// */ ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 2); @@ -4084,7 +4092,7 @@ void evsel__uniquify_counter(struct evsel *counter) config =3D strchr(name, ':'); if (config) { /* case: event:.. */ - int len =3D config - name; + len =3D config - name; =20 ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 1); } else { --=20 2.51.0.rc2.233.g662b1ed5c5-goog From nobody Sat Oct 4 00:28:11 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E9F2DA76A for ; Thu, 21 Aug 2025 22:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814730; cv=none; b=NCbQ98oQWzN/mnzRtRedrFazj6rnelZo+noqX/PnlbUyzmhyZOfFlhwPSpfqDTRzOyCrMQBsZhSS9AXQthoZl6mRqPtC9Hf4SOlcYxiXXxPWYKdvFLqHOc8gQmaRnBoHTUri+nJi/Ojz6hiuxsk0e8Ex3lXeSsmo1GyFBV3G3Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755814730; c=relaxed/simple; bh=DHH2rU+Zp3WpjSOcFqndoLEJ1fs8EixAC2cPKeXp1bk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=b2+9uGsEfCkMUR/YefDhNQjSE2Szwy7bOhIQxlvcqTY9GjIdufC9eARaUPam/5T1GZqIuq900jxyS2oOgpchvKHY3kKZR7Ioykz4RlcYlzdOdgmM6T70oJrzrrQsK5n81EI/I7//FJODTZq0kdtTQ0UXju71HTtuFlQbEfBHCa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vwzuF2kb; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vwzuF2kb" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-76e2eb9bb19so2979349b3a.3 for ; Thu, 21 Aug 2025 15:18:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755814728; x=1756419528; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LS/TLPPn/kr4cah7f6KZL8HylpfPU2klxIkY6Orl+xQ=; b=vwzuF2kb/0z5sCi3jEnOUYynwTp6BYZbxlY8Gq5dm2EGZsisdzCG7cl197z0UBu828 spDwVByu6DkzkpeR6do92HxSmuODRekYuY86UxdUS5rYTsw1FEvCDA7ftj3vkIM+i9QZ DBf4SqhYB0hIvYf2cIq74BxjI4Vzz1FuzCnD9NCH+vDxRE63CG1gRPPGAnc+1gAHAPpV cxOFfCa53oGU5QiC6Xm6yl+Dni8853Ff+r/9WogcgIFbAHGXvO4siZ9XIhWjzhGB8/KX 61nEKpAb2OKKKXjUMSAXbWLXKAx8rf5uhFXbDd1G8LbUiro17nKbzsBtuARqB7W2HSfm 3mcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755814728; x=1756419528; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LS/TLPPn/kr4cah7f6KZL8HylpfPU2klxIkY6Orl+xQ=; b=tos+qYhxg2OSUHkCaTGjKG1AtVzTNPRFrNyX9wXx9qJKQNcAXEdligydfAvuUpNYIB /Y81okjDF4IUtdsr8mfTB7mSC3roIZwficXxLob2CCM7UHNrZyqN6JBmN+N/ncRH59h+ YGs+4LOcIY/PBnqxqbZ+1euce5sz8ZjeO9KPBy+MWXPW8PoNIwZk7sTCMzmnb8c8PDyc osaPIIZOb5k8eV0jGrbmfeIoCx0ShvWQouai9jVbXntr82RxvMqWo1SDP1jBnJiloKsL t5iTKaBPfGvBX3Y+50B1ohFtW4QcfNcULZh+1JJkAgE6kf22JIYvtEKcEfeVEp+3/ABO +bvg== X-Forwarded-Encrypted: i=1; AJvYcCULTGaV21Og68nPRtrq/Dpm0cGMeLnJ0jR2PGiA6qCJgdZkzvV43e7J+4ne+yPqBZsgfHyrRKEdtuMo/G8=@vger.kernel.org X-Gm-Message-State: AOJu0YyI5KWrcflkPQ/DJwXsUxljxi7Y6OVh5dSBv2Q9D1DaX2SWvZvW 6grVpZiNWp6tq1I/+a2YID10wTiDVnQsgwnZBlDtnJ1l2Y+TBCLJ/nsdX51JOFEACaBzXlj1/PK eBmZhLwf1uA== X-Google-Smtp-Source: AGHT+IHXPNLlePi8gsgIbXWjR2tpQQEuG8eoufHyr+zgrODcuxIvK91rUyW+ILAqostE++FR034QpB1CchUS X-Received: from pjb3.prod.google.com ([2002:a17:90b:2f03:b0:321:b969:1e5d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a10:b0:243:78a:82aa with SMTP id adf61e73a8af0-24340d5e73dmr1106028637.50.1755814727694; Thu, 21 Aug 2025 15:18:47 -0700 (PDT) Date: Thu, 21 Aug 2025 15:18:34 -0700 In-Reply-To: <20250821221834.1312002-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821221834.1312002-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.rc2.233.g662b1ed5c5-goog Message-ID: <20250821221834.1312002-5-irogers@google.com> Subject: [PATCH v1 4/4] perf test: Avoid uncore_imc/clockticks in uniquification test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Chun-Tse Shao , James Clark , Howard Chu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The detection of uncore_imc may happen for free running PMUs and the clockticks event may be present on uncore_clock. Rewrite the test to detect duplicated/deduplicated events from perf list, not hardcoded to uncore_imc. Fixes: 070b315333ee ("perf test: Restrict uniquifying test to machines with= 'uncore_imc'") Signed-off-by: Ian Rogers --- .../tests/shell/stat+event_uniquifying.sh | 105 ++++++++---------- 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/tools/perf/tests/shell/stat+event_uniquifying.sh b/tools/perf/= tests/shell/stat+event_uniquifying.sh index bf54bd6c3e2e..9bc7a1f520f9 100755 --- a/tools/perf/tests/shell/stat+event_uniquifying.sh +++ b/tools/perf/tests/shell/stat+event_uniquifying.sh @@ -4,74 +4,57 @@ =20 set -e =20 -stat_output=3D$(mktemp /tmp/__perf_test.stat_output.XXXXX) -perf_tool=3Dperf err=3D0 +stat_output=3D$(mktemp /tmp/__perf_test.stat_output.XXXXX) =20 -test_event_uniquifying() { - # We use `clockticks` in `uncore_imc` to verify the uniquify behavior. - pmu=3D"uncore_imc" - event=3D"clockticks" - - # If the `-A` option is added, the event should be uniquified. - # - # $perf list -v clockticks - # - # List of pre-defined events (to be used in -e or -M): - # - # uncore_imc_0/clockticks/ [Kernel PMU event] - # uncore_imc_1/clockticks/ [Kernel PMU event] - # uncore_imc_2/clockticks/ [Kernel PMU event] - # uncore_imc_3/clockticks/ [Kernel PMU event] - # uncore_imc_4/clockticks/ [Kernel PMU event] - # uncore_imc_5/clockticks/ [Kernel PMU event] - # - # ... - # - # $perf stat -e clockticks -A -- true - # - # Performance counter stats for 'system wide': - # - # CPU0 3,773,018 uncore_imc_0/clockticks/ - # CPU0 3,609,025 uncore_imc_1/clockticks/ - # CPU0 0 uncore_imc_2/clockticks/ - # CPU0 3,230,009 uncore_imc_3/clockticks/ - # CPU0 3,049,897 uncore_imc_4/clockticks/ - # CPU0 0 uncore_imc_5/clockticks/ - # - # 0.002029828 seconds time elapsed - - echo "stat event uniquifying test" - uniquified_event_array=3D() - - # Skip if the machine does not have `uncore_imc` device. - if ! ${perf_tool} list pmu | grep -q ${pmu}; then - echo "Target does not support PMU ${pmu} [Skipped]" - err=3D2 - return - fi +cleanup() { + rm -f "${stat_output}" =20 - # Check how many uniquified events. - while IFS=3D read -r line; do - uniquified_event=3D$(echo "$line" | awk '{print $1}') - uniquified_event_array+=3D("${uniquified_event}") - done < <(${perf_tool} list -v ${event} | grep ${pmu}) + trap - EXIT TERM INT +} =20 - perf_command=3D"${perf_tool} stat -e $event -A -o ${stat_output} -- true" - $perf_command +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT =20 - # Check the output contains all uniquified events. - for uniquified_event in "${uniquified_event_array[@]}"; do - if ! cat "${stat_output}" | grep -q "${uniquified_event}"; then - echo "Event is not uniquified [Failed]" - echo "${perf_command}" - cat "${stat_output}" - err=3D1 - break - fi +test_event_uniquifying() { + echo "Uniquification of PMU sysfs events test" + + # Read events from perf list with and without -v. With -v the duplicate = PMUs + # aren't deduplicated. Note, json events are listed by perf list without= a + # PMU. + read -ra pmu_events <<< "$(perf list --raw pmu)" + read -ra pmu_v_events <<< "$(perf list -v --raw pmu)" + # For all non-deduplicated events. + for pmu_v_event in "${pmu_v_events[@]}"; do + # If the event matches an event in the deduplicated events then it mus= n't + # be an event with duplicate PMUs, continue the outer loop. + for pmu_event in "${pmu_events[@]}"; do + if [[ "$pmu_v_event" =3D=3D "$pmu_event" ]]; then + continue 2 + fi + done + # Strip the suffix from the non-deduplicated event's PMU. + event=3D$(echo "$pmu_v_event" | sed -E 's/_[0-9]+//') + for pmu_event in "${pmu_events[@]}"; do + if [[ "$event" =3D=3D "$pmu_event" ]]; then + echo "Testing event ${event} is uniquified to ${pmu_v_event}" + perf stat -e "$event" -A -o ${stat_output} -- true + # Ensure the non-deduplicated event appears in the output. + if ! grep -q "${pmu_v_event}" "${stat_output}"; then + echo "Uniquification of PMU sysfs events test [Failed]" + cat "${stat_output}" + err=3D1 + fi + break + fi + done done } =20 test_event_uniquifying -rm -f "${stat_output}" +cleanup exit $err --=20 2.51.0.rc2.233.g662b1ed5c5-goog