From nobody Mon Jun 8 08:28:38 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.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 585EF48AE2D for ; Thu, 4 Jun 2026 16:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780590996; cv=none; b=q93Iz01t35Ku1zrakHBMvLyKynDX6YheuetUACvfrzrzpLoo1AIWlnSfm2e7KaZIXV5VxYuweg+beeKOEnmiYjpK0Ytvtqm1TJv1a99g/5oXYUrCsrf4rW0IAQcEshLixsZ6i9uMesr/YlVgZL+deoFTWDp1HKaCLba3CimIXtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780590996; c=relaxed/simple; bh=S//dvOBs/USieF1vXWpNPbPuhuIfEQr4R8jo7tO7zf4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U7SikoumeI9IAa/GR054N+puoMGKexPbEYIFC9Yr3Bp7hQM2fWcEV3GT1Dm6D0re6LwTNSw61P3gqAQce8yNur0XF7Hw33Dc1kAF6cBeRA6nFDNp0X0jB6XVTMJujoJGodcrLLD/dw+Gll+98ieIA7mTq0x2Y9DZjy6IsijIYfM= 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=a6gPaQVH; arc=none smtp.client-ip=74.125.82.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="a6gPaQVH" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-135916eefa0so103832c88.1 for ; Thu, 04 Jun 2026 09:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780590994; x=1781195794; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XCZcSKYNKaSrihd7vUWodA5r8ht64vt3LOLPQyq/or8=; b=a6gPaQVHjCeyo9/RLk3DGy+MujCzdCUkpQGtfpEJ7tMZN6zYl7t9Rkk9tADgW5ZNmn BL/AsKhp1gh67wk45DGbWxfv8ld3sVsgBAT+h5a6QNJie4vB9eVR/viq4wMf4ykfQo2n j+7m4PMhOzkH8t/SFTOSIqf4shidtl+OyzFM7K41djiHwPlrdBMAqUMeQj/jEunUY/Je bH3iZQC+eK2Cy3yJU+8H3kKnANm2L7PDY6wtwEED6K5kIkkptOh14P0IIPYx+Ecd2cIx uN7lAnW7r4HFKQ8slByFqxQpLFgjEmqCcYMB6nDLs7sTjwAY0WiV/UzmCYoaXYy6k4JH HgIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780590994; x=1781195794; h=cc: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=XCZcSKYNKaSrihd7vUWodA5r8ht64vt3LOLPQyq/or8=; b=RS7ygtIg+d7jNLhJ7ltxWBqf7ddixrY7O+oEMGp0cPsH5aGflDpSNfT7iv7Ii30Q5I 3olnZMVIgJ9Z0T2ddoXp068UJzaQ+zRwt/QpY3sQTNOgWcj6MRdpLB4EXqUwhE4qgA18 94bNisXpgUti81Y1Qh8g90kNukHogoKG0ttfZTtlwD0D5rqj4zyo/Axs/wKDVgYEvkFp NfwmCEuBd9+lY11wijnMHBC4bf7Bo/R22u6lgRaIOa60cAHM39prcB//V2fW8/NUrMwU z+JhrHEZrtMkGbv6mW9tnhso7zDp/fPeXuYV1uI5nbg8g9XGVil0IvFdn8sTdK729jeh afyw== X-Forwarded-Encrypted: i=1; AFNElJ+HzT3tLPcy6lkKs9G/UETvvQhQFMXRxGRQk11WcGFev4lGmDKq8lgCY2e8g0i5bi8XxVBUjiCboW41P5k=@vger.kernel.org X-Gm-Message-State: AOJu0YzmeXukmqOvqARA/rHbHTz00HDFF1bprb0Ry/y+NBRKZLYO7L8U //wHhKRL8dEfgvmxlN0Hu9Ow+ZHmuK9yNKWQjXi9Wb6/7HeyufAMhb4TaGEOZ+/JPBIoV/52Ldu xWKy5jwW65A== X-Received: from dlbep4.prod.google.com ([2002:a05:7022:1084:b0:132:d312:88dc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701a:c951:b0:137:fb3f:8b65 with SMTP id a92af1059eb24-137fb3f8e2dmr3326779c88.10.1780590994051; Thu, 04 Jun 2026 09:36:34 -0700 (PDT) Date: Thu, 4 Jun 2026 09:36:26 -0700 In-Reply-To: <20260604163627.501078-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: <20260602174129.3192312-1-irogers@google.com> <20260604163627.501078-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260604163627.501078-2-irogers@google.com> Subject: [PATCH v9 1/2] perf pmu: Recognize 'default_core' as a core PMU and document matching From: Ian Rogers To: irogers@google.com Cc: acme@kernel.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The is_pmu_core function checks if a PMU name corresponds to a core CPU PMU. However, it currently fails to recognize "default_core" as a core PMU. When "default_core" is used, the PMU scanning fallback in pmus.c scans the "other_pmus" list. This scan is slow and always misses because "default_core" is a core PMU, leading to unnecessary overhead. Update is_pmu_core to recognize "default_core" directly. Additionally, document the different matching approaches (exact name for x86/s390, sysfs-based cpus file check for ARM/hybrid) to clarify how core PMUs are classified. Also, explicitly treat "default_core" as `all_pmus` in `setup_metric_events= ()` to preserve the original metric resolution behavior for this pseudo-PMU. Assisted-by: Gemini-CLI:Google Gemini 3.1 Pro Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 3 ++- tools/perf/util/pmu.c | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 5a489e97c413..c2ce3e53aaee 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -295,7 +295,8 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, const char *metric_id; struct evsel *ev; size_t ids_size, matched_events, i; - bool all_pmus =3D !strcmp(pmu, "all") || perf_pmus__num_core_pmus() =3D= =3D 1 || !is_pmu_core(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || !strcmp(pmu, "default_core") || + perf_pmus__num_core_pmus() =3D=3D 1 || !is_pmu_core(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 23337d2fa281..9994709ef12b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2029,9 +2029,26 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, = void *state, pmu_format_call return 0; } =20 +/** + * is_pmu_core() - Check if the given PMU name corresponds to a core CPU P= MU. + * @name: The PMU name to check. + * + * Core PMUs can be identified by: + * 1. Exact name match: + * - "cpu": Typically used on x86 architectures. + * - "cpum_cf": Typically used on s390 architectures (CPU Measurement C= ounter Facility). + * - "default_core": A generic name used to refer to the default core P= MU. + * 2. Sysfs file existence check (is_sysfs_pmu_core): + * - Typically used on ARM systems or Intel hybrid architectures (e.g.,= "cpu_atom", + * "cpu_core"). This approach checks if the sysfs directory for the P= MU + * contains a "cpus" file. + */ bool is_pmu_core(const char *name) { - return !strcmp(name, "cpu") || !strcmp(name, "cpum_cf") || is_sysfs_pmu_c= ore(name); + return !strcmp(name, "cpu") || + !strcmp(name, "cpum_cf") || + !strcmp(name, "default_core") || + is_sysfs_pmu_core(name); } =20 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) --=20 2.54.0.1032.g2f8565e1d1-goog From nobody Mon Jun 8 08:28:38 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.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 2CF5940961E for ; Thu, 4 Jun 2026 16:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780590998; cv=none; b=RdvyFkwg8pECVOZvw8PIQu3bvGd4QMmtau9JBJATaWGyuPJ/5nBtFs9FdNkIozb/9dP/Z15ARK/ZV3alqTLf0zGq0/uvhVubZHLCZ2udRI05U24yFNdvVMtrcf/stpf/96IrDo7ZYZSL3Hhah8PorACh/dpFCz5QQfRg5N2xvEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780590998; c=relaxed/simple; bh=KAYhkahAb+18m5LFcYwamkdiSsZ3QqvHTYW8D7Ouw/w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JCQlYAVQDcTgwbJHRe0Q40r9WEASlHjIiBZh9clb+5IWK30RbG6mH4lJaDJ4RZf8SwxEAV8qpLmPanQhuqFGeZI754PZI/fXLfygzWpMAhv7LvJ6IxQ1fmfOsojOTW7UchoCNdIr/1VPvNvtB1TnwKQvHTa6BnkzQpKJjH1VvcE= 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=l8RW8hDO; arc=none smtp.client-ip=74.125.82.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="l8RW8hDO" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304d8613efbso852189eec.1 for ; Thu, 04 Jun 2026 09:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780590996; x=1781195796; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MJQYLG1uMFrbb0Ahpo+z3gzkQ0y5w5F6/NRuMiORe/g=; b=l8RW8hDOaZaYXLLhds7fwhU8IzxZtFZPIXlkZpscgSLzuyehh5XAVHU1HMnl8JzAnC eoPJwPWiZdidWsu3tLMGfK18qCL0q+K4cYA0jKBuxqCiMKOoq4pAmofNMK+vJk09mcHe g5lDn98ynu+0AePB+JcXCKgVAWt4cfzaHWXRJ85AJTS1uaVUmIxOSXJgskO6X9kOlaLc 8ouApP7xkvgioIDHLc8trX72MxJINvyPaWyLCFwPWSD1QYdJNR4EUq66BdNwukAqolSK 2MixUdg5i6PeSOhyZC4H6eoKNo7i9GeL/yvyc0gDfUzBdhQ3Xb9bcvP87B4tK0jJnU4V OhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780590996; x=1781195796; h=cc: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=MJQYLG1uMFrbb0Ahpo+z3gzkQ0y5w5F6/NRuMiORe/g=; b=hV9/suMDnYH4cpXgzxezHyLlD1nhQyR0HjSQ9kjUbtqsMK5cDNQSbmUtilLd9BpYKx mKch0hjh85jp81dzenAnw7zO0gPdtHN8Vx/XvGB0t0NeMaf4Ypw2DLj2BmMHG0VZkSDv Axyn+Q0/OIUkA8f+20sONLiGoeYkH7AKTxMDRgmAfd35GirXtCoDO442ebKhYB0kIg7T 3wqvwy/IR90wcBVcA+EHJSuCwwTkVraj+QIsAFflGNTFI969ixiiEPLsKt7gQKqINo+k OvEYj3ODIBOEjupbXjSHceyJOjXQ/Xbc+ohxWzrWV1a//HsvlpOCueSGkVBD6dyNBBSd a97w== X-Forwarded-Encrypted: i=1; AFNElJ9cbzWwTgw0fUd5qPF44mYARBgeVlV80joGz2ZS7VjsvIFTRM4Ig7zIRNMWUwCy6mByaOTptnLrdEHLges=@vger.kernel.org X-Gm-Message-State: AOJu0Ywpz32iEYKdOn1QWIKfBgZVu3A+wXfhLrDioRmpy8IFdJoKYBaD SLObo/FXAeMbtPlHU2gvBnBXFJxuwVdcArBgJjnPynb0MjxqV1AdrH7HTiPvJQtR3lfoGcNLsqk ZntgzJhS0Og== X-Received: from dyblz38.prod.google.com ([2002:a05:7301:1626:b0:304:1e27:a62f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2284:b0:2e1:e3e6:2909 with SMTP id 5a478bee46e88-3074fa64a4bmr3849860eec.9.1780590995818; Thu, 04 Jun 2026 09:36:35 -0700 (PDT) Date: Thu, 4 Jun 2026 09:36:27 -0700 In-Reply-To: <20260604163627.501078-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: <20260602174129.3192312-1-irogers@google.com> <20260604163627.501078-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260604163627.501078-3-irogers@google.com> Subject: [PATCH v9 2/2] perf test: Truncate printed test descriptions dynamically to avoid terminal wrapping From: Ian Rogers To: irogers@google.com Cc: acme@kernel.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When test descriptions are extremely long (e.g., the truncated perf.data graceful handling test is 103 characters long), they wrap across terminal boundaries. Because the ANSI escape code to delete the line (PERF_COLOR_DELETE_LINE) only clears a single terminal line, visual wrapping leaves orphan wrapped lines on the screen, which results in the test description being printed multiple times. Resolve this by checking the terminal width (get_term_dimensions) and dynamically truncating the printed test description to fit within the available columns, leaving safety space for the prefix index and status suffix. Also, remove the width padding from the test suite headers which do not display inline status messages. This prevents their trailing colons from wrapping onto new lines on standard width terminals. Finally, explicitly clamp the dynamically calculated description width to the formatting buffer's size to satisfy GCC 16's bounds checking and prevent a -Wformat-truncation warning during compilation. JUnit XML output and the failure summary report still print the full, untruncated test descriptions. Assisted-by: Gemini-CLI:Google Gemini 3.1 Pro Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 70 +++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index b64fc2204f22..b7eebfcf7700 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include "util/term.h" #include "builtin.h" #include "config.h" #include "hist.h" @@ -404,19 +406,73 @@ static char *xml_escape(const char *str) return res ? res : strdup(""); } =20 +static const char *format_test_description(const char *desc, int width, in= t max_desc_width, + char *buf, size_t buf_sz) +{ + int len =3D strlen(desc); + + /* + * Clamp to buf_sz to prevent GCC format-truncation warnings + * when terminal width is very large. + */ + if (max_desc_width >=3D (int)buf_sz) + max_desc_width =3D buf_sz - 1; + + if (width > max_desc_width) + width =3D max_desc_width; + + if (len > max_desc_width) { + snprintf(buf, buf_sz, "%.*s...", max_desc_width - 3, desc); + } else { + snprintf(buf, buf_sz, "%-*s", width, desc); + } + return buf; +} + static int print_test_result(struct test_suite *t, int curr_suite, int cur= r_test_case, int result, int width, int running, const char *err_output, double elapsed) { + char desc_buf[256]; + const char *desc =3D test_description(t, curr_test_case); + struct winsize ws; + int max_desc_area_width; + int target_desc_area_width; + int desc_padding; + + get_term_dimensions(&ws); + /* + * Total terminal columns minus space for status e.g. " Running (12 activ= e)" + * which is 20 chars, plus a margin of 3 chars =3D 23 chars. + */ + max_desc_area_width =3D ws.ws_col - 23; + if (max_desc_area_width < 40) + max_desc_area_width =3D 40; + + /* Standard test has prefix "%3d: " which is 5 chars */ + target_desc_area_width =3D width + 5; + if (target_desc_area_width > max_desc_area_width) + target_desc_area_width =3D max_desc_area_width; + if (test_suite__num_test_cases(t) > 1) { char prefix[32]; int len =3D snprintf(prefix, sizeof(prefix), "%3d.%1d:", curr_suite + 1, curr_test_case + 1); - int subw =3D len >=3D 4 ? width + 4 - len : width; =20 - pr_info("%s %-*s:", prefix, subw, test_description(t, curr_test_case)); - } else - pr_info("%3d: %-*s:", curr_suite + 1, width, test_description(t, curr_te= st_case)); + desc_padding =3D target_desc_area_width - (len + 1); + if (desc_padding < 20) + desc_padding =3D 20; + + format_test_description(desc, desc_padding, desc_padding, desc_buf, size= of(desc_buf)); + pr_info("%s %s:", prefix, desc_buf); + } else { + desc_padding =3D target_desc_area_width - 5; + if (desc_padding < 20) + desc_padding =3D 20; + + format_test_description(desc, desc_padding, desc_padding, desc_buf, size= of(desc_buf)); + pr_info("%3d: %s:", curr_suite + 1, desc_buf); + } =20 switch (result) { case TEST_RUNNING: @@ -700,7 +756,7 @@ static void finish_test(struct child_test **child_tests= , int running_test, int c * sub test names. */ if (test_suite__num_test_cases(t) > 1 && curr_test_case =3D=3D 0) - pr_info("%3d: %-*s:\n", curr_suite + 1, width, test_description(t, -1)); + pr_info("%3d: %s:\n", curr_suite + 1, test_description(t, -1)); =20 /* * Busy loop reading from the child's stdout/stderr that are set to be @@ -976,7 +1032,7 @@ static int finish_tests_parallel(struct child_test **c= hild_tests, size_t num_tes if (next_child) { if (test_suite__num_test_cases(next_child->test) > 1 && last_suite_printed !=3D next_child->suite_num) { - pr_info("%3d: %-*s:\n", next_child->suite_num + 1, width, + pr_info("%3d: %s:\n", next_child->suite_num + 1, test_description(next_child->test, -1)); last_suite_printed =3D next_child->suite_num; } @@ -1040,7 +1096,7 @@ static int finish_tests_parallel(struct child_test **= child_tests, size_t num_tes =20 if (test_suite__num_test_cases(child->test) > 1 && last_suite_printed !=3D child->suite_num) { - pr_info("%3d: %-*s:\n", child->suite_num + 1, width, + pr_info("%3d: %s:\n", child->suite_num + 1, test_description(child->test, -1)); last_suite_printed =3D child->suite_num; } --=20 2.54.0.1032.g2f8565e1d1-goog