From nobody Thu Oct 2 07:46:33 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 ADA502FB081 for ; Thu, 18 Sep 2025 22:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758234130; cv=none; b=Ki741OU1Nuswd6HVnXaHHOR93Fa1i6e+I0ceLcnrkYZ63KkdBAOs2UqtlQjINdNT0KzrSku8Apnjn1gyl3DeV+kl2zFEjX9012ebBApAfAG0vHjzTQ+MaH09XqQ01sG8l3YFbVUr3XNw7Ce+fl9pDQphmMfGiC07VjpMa0uzLJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758234130; c=relaxed/simple; bh=B1qncqkGZBlGmoRjWSdOLv2hw8gFwrEhONtGaXyf8dg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=RiG2JsvdHsyssyJwymQIIZxmUfjKHf98GOi/RROHvXhGzlSMWzUd8nA9xfW2xl77TjZCXmCzQ3VfwCKkkWOsDHdUALhTMykgq/3ksx7zVFCjVmIss8NYJkCELf5SHnSNZsuk8JFecYMg6Bm4gGhlvfFF2pgQ9ajL02BCEDTSGTM= 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=j76WnC9L; arc=none smtp.client-ip=209.85.210.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="j76WnC9L" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-76e6e71f7c6so1421030b3a.0 for ; Thu, 18 Sep 2025 15:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758234128; x=1758838928; 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=bKYJvBahvbkcM2QwKRyULEXALXOTmp7qcHJNyKe9Ay8=; b=j76WnC9LapzL/aoJ4uRXcqAFx09djFjEJAAAT9m1mkRAkhNNPLsiLJCzUOQ6UYpkdV r0a/3hjPcdydaLUyIH9Y2nzMREUMoIiks3vxt/6b6Jr2G8zAoYLCLLvEPvaHijOALvET v6YlnmDoIfmSyxlMcf5uhpeU+3lMkwUxpNfsjaotsyBg2c+zH3zDV1OM2/HSV7D/K2mL ceaZ4avrIQdRjgYUYnEskzYPhlLksQtdrOphll8U+TaLQjHWXDAEZDD2nI+QvYNprw2B in72+dW643zkiF4W96Gol0B4FTXYITK73a/s5eU3y9JEbMF7EPUhBHK3oq+77eLg8DvH ETrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758234128; x=1758838928; 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=bKYJvBahvbkcM2QwKRyULEXALXOTmp7qcHJNyKe9Ay8=; b=Ijya9hokKGi1l76cYBmY1uRXPgDIIfKoZVmNsRFkMjxzxZjHQi5KuvD/EE10Bvckbw 2ClRqu83Zn62p+NiaSuM+ONO3DDJLBjyFoDJztAyojJpZDkpyVHkZ8AwllSoSqfTAQTl YFgZbVzgSEPa94GIeb/S/T1WRTzWAJDjfqgL+geQEH1gwKr2ZMD4yBKex8ZsZSHVbTPv 1HRazlJ0Z0zJ+vJWryqMJBCgkWayDTh+IGfrcsl0bTOXcPg6rNtY1AAW9jZSO9QF9+uf O/zq0ML9/trP5so6NVSEIs/3kW0AZffkhp+vap3/isFjKX3P/ys+3leVGnZ0vNtozFm3 SC9A== X-Forwarded-Encrypted: i=1; AJvYcCXgjBAUeGZ9ntdjJduLm6skVCShL95s8gpTU1jp8OMVPfKb9iQm3zNtNoB/ua6nAFSA9TFEsme2gvw7GDw=@vger.kernel.org X-Gm-Message-State: AOJu0YxGmS9QKOrd3cqrXiSWgiHosp2jQNljtXvZJoNtRgaCa2BOu/qh BrSYIGoH6/JKC4rmJT2o4mCwBvgXBtGEv3WnjQJCl34fBl5ugYaxEff0in/LPrkDBm8LV+twfNz yQv8eCSDNuA== X-Google-Smtp-Source: AGHT+IGyVyZpa+TsJ31qkvSyn/bfX+ssskli1JTbTQJdQOR6kUCT2UtSkRRnK/WsF8nvoUuZaQhOwxbAcvJh X-Received: from pfblo12.prod.google.com ([2002:a05:6a00:3d0c:b0:77e:40c7:d12e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3e1b:b0:76e:99fc:dde7 with SMTP id d2e1a72fcca58-77e4eaa9a5amr1230546b3a.22.1758234127950; Thu, 18 Sep 2025 15:22:07 -0700 (PDT) Date: Thu, 18 Sep 2025 15:22:00 -0700 In-Reply-To: <20250918222202.1353854-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: <20250918222202.1353854-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.470.ga7dc726c21-goog Message-ID: <20250918222202.1353854-2-irogers@google.com> Subject: [PATCH v2 1/3] 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 , Athira Rajeev , 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 d895df037707..efbd9cd60c63 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -130,6 +130,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 @@ -141,6 +142,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 @@ -152,6 +154,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 @@ -164,6 +167,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.470.ga7dc726c21-goog From nobody Thu Oct 2 07:46:33 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 6D19E2FF65A for ; Thu, 18 Sep 2025 22:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758234131; cv=none; b=VyA2fk+MYAtMKgdUt/hw970CUZHjI9SZ99JQ/gbG7gBJw/dVTURAH1fNMwty8NqPnoDBPX5wKjk6/nMNt3jaFG6Zly0NBDWVUdfwKXRL8z+Casgpwy4n0BPZBnLAJjjZWlHFBAbk0ICmKVCrLnUd0jD/sWC5V2r2v9y6zfEVvgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758234131; c=relaxed/simple; bh=bVc3kDgnMxi3LeNcvdebA35fa49RA/BlURQA67guNaM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uy5sEIl/7lmmzdRYIij7nZQYYXNkoFjy+E5rmliA+1t4eomU1PmolBB5xDOuemUkWsQjuf0dWf14FbMv0HkqI6hIyK51ky8iexOjFb2Jvt7+Cwld/7jKhHbCPnHIyF6V8sX6XCxAr9OLHSnF+Fl2oHj/2TaCrF/arwC1eHqL7kM= 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=iunOri8I; arc=none smtp.client-ip=209.85.214.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="iunOri8I" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-252afdfafe1so15024255ad.0 for ; Thu, 18 Sep 2025 15:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758234130; x=1758838930; 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=2qfPNJqadhLlZpiek/PBm8YyMz6t+BW/rS3q4ughwwA=; b=iunOri8IPXlkTcrNA/mR9aOpUEBov7zcFb5MuhHfZQ8Bkutf59HG8nnGqwc3C+qQx+ fJNRSBmnw9iI8d2FMi5AS8vVZupfWAAw1b3IhrY6OlU1iagKaZpAOxVjNLmKu8u430US O7NG4IXrb+oftzQ7REGzT89t1B9FzXyCTX/p72yjLl7MiFXoimgzaGQ5bnuDaLQ0mhgo zSOvMlUhZdReCIO7KioP9bPZkQUx+b7EIO3TZRYUnMWoSJodLs/A5WL8LImFonSIuUKJ Mpc4vOuy8oJ/1nNdcW8+CU1fP8vOxWylUxJbvKiGpCQRDudyj4AB9Xfg+ISGSogDPBeq TGjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758234130; x=1758838930; 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=2qfPNJqadhLlZpiek/PBm8YyMz6t+BW/rS3q4ughwwA=; b=OMH8YCbrOfav9H/tfwndZgJpqt72P++K17sbKAiN7waSygx9WgECgpPx+hvuQxXU8x /6r6jtO6wkB911aZTCKTviBIlTaKADscmQUm+MOHRq2QICe+8aS9Dq7t4kMUutsBRrMw YXsH831m8i67pAWuFGWYfIaaQDN4W6eof2CN22QYz2S0I+UyS308VP2X3YNrSiRVKhiq 53DkEG4F68VggQNkzDonMFIKiUJClvKwhX7LyX49RtVYOXXR4IFTqLLwfZSz+BK3/tEW vogaFgLUpMkaKVwnbqn8bhPoApBXSUU0BQXUIfqCrFrSnux8qTt0XzBE/ztPMTmYPJlD Nr2w== X-Forwarded-Encrypted: i=1; AJvYcCWVVjsJm5ZAtlRCVn2FZwrOHmDofMkWVaZb4wicKptxwR2NsDP4ATWUdIdQGl2lfB6O1WyHuRfvI8xrYx0=@vger.kernel.org X-Gm-Message-State: AOJu0YzKF1/HhxXdIef7H/ciOOxkIr5M9SRltLOUV6O+o6EfNGCL67zg AmWq+451+mvgzz8N7yFFcyN3b9A+zNE55ouQyMJkWl0/knq9+zB7VkeTSwgENsvTkESkRzFcrY2 0vVbtfuRRoQ== X-Google-Smtp-Source: AGHT+IHAb2iMgpayxv+HM2x01Rh9wJpNBeSAoQCuaNCvhxmKHijGOa+73Gu/v/DdBjyrrIF9u0m/JcRWON1Y X-Received: from plho12.prod.google.com ([2002:a17:903:23cc:b0:263:a081:54b2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:32c4:b0:269:aecc:a454 with SMTP id d9443c01a7336-269ba3c5027mr16373625ad.11.1758234129653; Thu, 18 Sep 2025 15:22:09 -0700 (PDT) Date: Thu, 18 Sep 2025 15:22:01 -0700 In-Reply-To: <20250918222202.1353854-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: <20250918222202.1353854-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.470.ga7dc726c21-goog Message-ID: <20250918222202.1353854-3-irogers@google.com> Subject: [PATCH v2 2/3] 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 , Athira Rajeev , 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 6a31f9699b49..6947072598b1 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -4053,9 +4053,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) @@ -4069,15 +4069,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); @@ -4089,7 +4097,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.470.ga7dc726c21-goog From nobody Thu Oct 2 07:46:33 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 9C1BD30C0FA for ; Thu, 18 Sep 2025 22:22:12 +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=1758234134; cv=none; b=USpe4bbnd39IfgEtSONq64EwwxynZa/dr5h/r68uEkdzz4JMiWs4V/dd9tSTvKTNaCl1hmFtVllp1nLuGM8yCKPUXOBcXZeOYib6ZOetF5AYlrZN1ESMkIUiHfbMg670f/9TQ4OX87TIzRKcB+MjNv37gDRx5at5WK6Wuk+wTz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758234134; c=relaxed/simple; bh=TwqoMqLQHjUxI2rkeJmleYPOhZn3UgjHTrrdcI1tvtg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bVH8CKS2PbFw6lB88X7s/brk3KrA0RSd35G3XG4xJV49sChEnyvlrEuVXbuodXhl9FDxUMIQtu1AjHaNwpfVPLKHVcotpicApdWDPezkUpQDe1xL+E5j9FuWKkCCl0Z8SPcxXOCDV8+zjVtKtTbK8HN+ID9xDkb2q+2TPrekZiQ= 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=mlpREUlv; 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="mlpREUlv" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-269a2b255aaso14467105ad.3 for ; Thu, 18 Sep 2025 15:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758234132; x=1758838932; 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=rxusbh2pXscDQhVlXFTi2xaqfqmPjhhvMWLhfAOar+Y=; b=mlpREUlvP6e6n7GOUsRf0ozKfZih0ZW3SnZMpMfcDw8FVQ3Q7ixTXjjKvhzQFvS760 9/gQXa5ca44XjHNNLjx/QqjSWDVo/PRTvotjnbAyjodzCyLHmPwBpatm9B+ZxbcjGq2y 9yY/v4pfwY2sLFkCjIcyHgH27YHw3vi2QYTT/NBMOjVC1y5qHMhKxaTXN13qLqxv3LDn gYwXYuZ1wOq0JnE9IDJDXvDBeNbu7UKJLhZaOpEYwPoYxuHmFzmhbsig8xP7x8Pu7oJ6 LnTfzTR7qgRBsUA2SIOSkZdo22FYMqHWuDTHc4boV+LzAAxNmo22OidCT0E6X0DFLZBb vJQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758234132; x=1758838932; 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=rxusbh2pXscDQhVlXFTi2xaqfqmPjhhvMWLhfAOar+Y=; b=oiNRgADY8p9Mi9Azz/HIWp6NC/9Vpl+NdKsxzKzxCERNfM/dA7kc3avPAjOJqCtzHc zFZ9+X+2JdkGfkpV1ZHIKd5jvu0KFS3zVUTniPHupNNsu8CBsBBctnJDFBT760DFHT89 MenLzwGS1NJ/fgUCSfyBFTwMYG7qCKCfevbN06X/4NvGolyf0V2EDNnDbANZLYljS0Ef o81nB4ibCyMO8MDW1sURelARvOZGHfawpbGGnDW+XTxSr/vPkNFMONyTWXan+I+Z+r0P KeLmDcGbTAhB+8vlappp5RcHnau0pbMHG/tvYYsHtFPOrd0Mz2c5vh0y1Pd7LKxCDlxR 8Icw== X-Forwarded-Encrypted: i=1; AJvYcCU2U03EQM1c1CXNQC3fNkkG38o0JFN8X5849jkbClui+rdC0uArzv4L4n2qjHbAZjvTLREohp7etYIw/94=@vger.kernel.org X-Gm-Message-State: AOJu0YwEDLSuSslRz9i1Wg+4kYvwGel9EszYE7Twth4+R0SA4scgJkAB k0SqEpyaBPjXk0Rv+JQ9qcKqmnEPnJbLXe7nWTYm5kAMV6RS7UGc4OG/I9Moa63SD9wgZZfBR8y w0n1/cTkVoA== X-Google-Smtp-Source: AGHT+IF1i3RQ5YoxqBTNWNiUwo8wn69WpweQEoJjE2pE6tp3kNd89jJ6Dl20BgOSosjGWmWOoivuP5joC6Lb X-Received: from pjbsv6.prod.google.com ([2002:a17:90b:5386:b0:330:8c66:4984]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:246:b0:269:a8a8:4029 with SMTP id d9443c01a7336-269ba3ea13bmr18290485ad.5.1758234131690; Thu, 18 Sep 2025 15:22:11 -0700 (PDT) Date: Thu, 18 Sep 2025 15:22:02 -0700 In-Reply-To: <20250918222202.1353854-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: <20250918222202.1353854-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.470.ga7dc726c21-goog Message-ID: <20250918222202.1353854-4-irogers@google.com> Subject: [PATCH v2 3/3] 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 , Athira Rajeev , 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. If perf stat fails then assume it is permissions and skip the test. Fixes: 070b315333ee ("perf test: Restrict uniquifying test to machines with= 'uncore_imc'") Signed-off-by: Ian Rogers Tested-by: Qiao Zhao --- .../tests/shell/stat+event_uniquifying.sh | 109 ++++++++---------- 1 file changed, 49 insertions(+), 60 deletions(-) diff --git a/tools/perf/tests/shell/stat+event_uniquifying.sh b/tools/perf/= tests/shell/stat+event_uniquifying.sh index bf54bd6c3e2e..b5dec6b6da36 100755 --- a/tools/perf/tests/shell/stat+event_uniquifying.sh +++ b/tools/perf/tests/shell/stat+event_uniquifying.sh @@ -4,74 +4,63 @@ =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() +cleanup() { + rm -f "${stat_output}" =20 - # 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 + trap - EXIT TERM INT +} =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_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT =20 - perf_command=3D"${perf_tool} stat -e $event -A -o ${stat_output} -- true" - $perf_command +test_event_uniquifying() { + echo "Uniquification of PMU sysfs events test" =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 + # 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}" + if ! perf stat -e "$event" -A -o ${stat_output} -- true; then + echo "Error running perf stat for event '$event' [Skip]" + if [ $err =3D 0 ]; then + err=3D2 + fi + continue + fi + # 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.470.ga7dc726c21-goog