From nobody Thu Dec 18 08:11:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B509AC04FE0 for ; Mon, 14 Aug 2023 16:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbjHNQiR (ORCPT ); Mon, 14 Aug 2023 12:38:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbjHNQiH (ORCPT ); Mon, 14 Aug 2023 12:38:07 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A279E5B for ; Mon, 14 Aug 2023 09:38:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5840ea40c59so60779317b3.2 for ; Mon, 14 Aug 2023 09:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692031085; x=1692635885; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9M5Kp6au+xtW2CeK8507RoWf4CnApWNQmihr10EV/wQ=; b=KGWwShhyYHQqv5ngOlRXeEsBiMOJRnDM/DZuzfqzoLDqOmXIQSl9ZimX0NceVp5F1g my8S/oTKd1PbqI/7q6okf48Xe0Zio1rd3vVSZZTJiQCVclxVj3wYoCMubVQC6HkOyHz/ Gxum+O6N9bAwsmRs3ZoPYIDktu/+5SPTHz8tq3pcKOBQt++Pognjni7hyhL1FCpg2WKi w75ayAGB5wl3ebgCuu8GQnL6C6di135YaTHIAzZ7RCFQdHbF074p3WnrfKgECTnbOEF3 00HFgKRyoJzzd8O6IN1z+kB+WGRRLt826eqXC0MgdrPOZ8OkucXRSZHD0h+7SiJgcW1B duxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692031085; x=1692635885; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9M5Kp6au+xtW2CeK8507RoWf4CnApWNQmihr10EV/wQ=; b=Z3xhv2XiLL6F2YX9er+Md7mau4U1MrSwaHDXJrmAAv2uPVX3LzFDRgsmIyitab15MA d6tMDiIzeGMlPPFCyKMmmXW4vv3TEGratl30Q5OP/3u2DW/EQpnsAyGphwzehwN0L134 mF3EBKkG0hTMF/6MAonGXOyKUaeJSO9qpETMqnijqOLk3tltTasE7HLekoXD1GV4XwEQ p+Gc/zAeOQb6fX8Hp2RQhKvKX+7C7QRknwZjSfJk7TQyl06K/OdCpw9/8dKgOzkTff9O dKz7uc7wkn9eWZa4lK3Scj4e7SHhouOWN21kQkV9q3/Fwd5wuiuYqQUc0yI/zWgG1J68 /Jpg== X-Gm-Message-State: AOJu0YxjE2YXPant2MmEHhlb5KCac7fLkIa8To7bYOKIoE17rx7xAnkr qMddHjIZXTBtTeuNYucfWvTSO0C3XIQZ X-Google-Smtp-Source: AGHT+IGtd9vjdp1qvZb1M4Cmv9dej5Ze/an+8QoegeIi5mbhiIxJbZRrPKcsxOnBeYfjqARfHc8SO3fkXIGc X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a919:6125:510f:f0ef]) (user=irogers job=sendgmr) by 2002:a25:ce53:0:b0:d4f:22c:69a3 with SMTP id x80-20020a25ce53000000b00d4f022c69a3mr123751ybe.10.1692031084826; Mon, 14 Aug 2023 09:38:04 -0700 (PDT) Date: Mon, 14 Aug 2023 09:37:55 -0700 In-Reply-To: <20230814163757.3077138-1-irogers@google.com> Message-Id: <20230814163757.3077138-2-irogers@google.com> Mime-Version: 1.0 References: <20230814163757.3077138-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v3 1/3] perf pmus: Sort pmus by name then suffix From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sort PMUs by name. If two PMUs have the same name but differ by suffix, sort the suffixes numerically. For example, "breakpoint" comes before "cpu", "uncore_imc_free_running_0" comes before "uncore_imc_free_running_1". Suffixes need to be treated specially as otherwise they will be ordered like 0, 1, 10, 11, .., 2, 20, 21, .., etc. Only PMUs starting 'uncore_' are considered to have a potential suffix. Sorting of PMUs is done so that later patches can skip duplicate uncore PMUs that differ only by there suffix. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index c58ba9fb6a36..3581710667b0 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -1,8 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include +#include #include #include #include @@ -33,6 +35,31 @@ static LIST_HEAD(other_pmus); static bool read_sysfs_core_pmus; static bool read_sysfs_all_pmus; =20 +static int pmu_name_len_no_suffix(const char *str, unsigned long *num) +{ + int orig_len, len; + + orig_len =3D len =3D strlen(str); + + /* Non-uncore PMUs have their full length, for example, i915. */ + if (strncmp(str, "uncore_", 7)) + return len; + + /* + * Count trailing digits and '_', if '_{num}' suffix isn't present use + * the full length. + */ + while (len > 0 && isdigit(str[len - 1])) + len--; + + if (len > 0 && len !=3D orig_len && str[len - 1] =3D=3D '_') { + if (num) + *num =3D strtoul(&str[len], NULL, 10); + return len - 1; + } + return orig_len; +} + void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; @@ -122,6 +149,25 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, con= st char *name) return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); } =20 +static int pmus_cmp(void *priv __maybe_unused, + const struct list_head *lhs, const struct list_head *rhs) +{ + unsigned long lhs_num, rhs_num; + struct perf_pmu *lhs_pmu =3D container_of(lhs, struct perf_pmu, list); + struct perf_pmu *rhs_pmu =3D container_of(rhs, struct perf_pmu, list); + const char *lhs_pmu_name =3D lhs_pmu->name ?: ""; + const char *rhs_pmu_name =3D rhs_pmu->name ?: ""; + int lhs_pmu_name_len =3D pmu_name_len_no_suffix(lhs_pmu_name, &lhs_num); + int rhs_pmu_name_len =3D pmu_name_len_no_suffix(rhs_pmu_name, &rhs_num); + int ret =3D strncmp(lhs_pmu_name, rhs_pmu_name, + lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_l= en); + + if (lhs_pmu_name_len !=3D rhs_pmu_name_len || ret !=3D 0 || lhs_pmu_name_= len =3D=3D 0) + return ret; + + return lhs_num < rhs_num ? -1 : (lhs_num > rhs_num ? 1 : 0); +} + /* Add all pmus in sysfs to pmu list: */ static void pmu_read_sysfs(bool core_only) { @@ -156,6 +202,8 @@ static void pmu_read_sysfs(bool core_only) if (!perf_pmu__create_placeholder_core_pmu(&core_pmus)) pr_err("Failure to set up any core PMUs\n"); } + list_sort(NULL, &core_pmus, pmus_cmp); + list_sort(NULL, &other_pmus, pmus_cmp); if (!list_empty(&core_pmus)) { read_sysfs_core_pmus =3D true; if (!core_only) --=20 2.41.0.640.ga95def55d0-goog From nobody Thu Dec 18 08:11:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 954E0C001E0 for ; Mon, 14 Aug 2023 16:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbjHNQiS (ORCPT ); Mon, 14 Aug 2023 12:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232971AbjHNQiI (ORCPT ); Mon, 14 Aug 2023 12:38:08 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E949C94 for ; Mon, 14 Aug 2023 09:38:07 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d63e5f828a0so5256414276.0 for ; Mon, 14 Aug 2023 09:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692031087; x=1692635887; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=igst4mk2Qe0yy+cOTE8q+SB7QjnlDxT/LagI8IxyHvs=; b=Cg7MCoQRuNdld7xCqa7bytZ8lmwbE26tEsLWyUL2QSRJC2JRmm5fWDi9RxftN4na0G thkDV/wLONNXNYcsp8QBsUiOr9w+ewWT2hEQkgOebp9Yl5ngIiB4tX+SRUarU0xTiSXZ 1TjnzjbP0FELbaHdqCZ+RtYA3ufrMN3KULk3/cc05YTkUnWOeJ4LimKJxGftR01rdwZx VNbIJQq3bXpOVRecztpIED99ADOg+XULA4+sIIN2HQ2zQe5/kuBvzAWUyj4HpA23zoXN aCar0jwy9gQYWUyWs6Nd1nzWvJHr1RESaI/5mwrlzWx9iLwmGlF0Kg1JPIwQwgEET8iH 0eww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692031087; x=1692635887; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=igst4mk2Qe0yy+cOTE8q+SB7QjnlDxT/LagI8IxyHvs=; b=YCnQXXfLP/GnPUA5rgnZwA5+7bqSHfRhvGVVE5V0dWIxlM28QSIBqqURhxfzZtTTPf hENgIUxyGiTdLdXQWxUqenQvT8ByPdbdsMolT8tA2IlnRPlCLGWGMoJY/M5vFKQrLtRr j4MhXsi/H6bpTey89RBMYRrnG9weawx5D9hP1bZXUnAupqVXWwKRDqbDZXQHwe5oLhfk ev7/VSpi3hRVlawNKkUY8xvyMEeJRK2uzGjbJvAZBJK2wOVMCehKoL5MwPTI9A9f85k7 P+BgvTCdNyPt2auyQVu9ShIj8CMMSs/LJyiJ5uzaTEdb8ECR4w+bdsB0XxGY+yCMyQp7 XXAQ== X-Gm-Message-State: AOJu0YzgttREBBqxvX9E0ly2WwIr6ptsbIyazvR/zLTelSwkJAG8lsQF 72eBjtP0xj1TqtTIe0kO82vAWDaspgsB X-Google-Smtp-Source: AGHT+IGY085eR7sAPeFw2Vv2wVsPZoEMHrzUEnpYB0pv6wew4vvJ+t0oIZrJHInKhW9izPUdoejmhtgVEAGj X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a919:6125:510f:f0ef]) (user=irogers job=sendgmr) by 2002:a25:abcf:0:b0:d45:1b81:1154 with SMTP id v73-20020a25abcf000000b00d451b811154mr133130ybi.2.1692031087237; Mon, 14 Aug 2023 09:38:07 -0700 (PDT) Date: Mon, 14 Aug 2023 09:37:56 -0700 In-Reply-To: <20230814163757.3077138-1-irogers@google.com> Message-Id: <20230814163757.3077138-3-irogers@google.com> Mime-Version: 1.0 References: <20230814163757.3077138-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v3 2/3] perf pmus: Add scan that ignores duplicates, use for perf list From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When there are multiple PMUs that differ only by suffix, by default just list the first one and skip all others. As the PMUs are sorted, the scan routine checks that the PMU names match and the numbers are consecutive. If "-v" is passed to "perf list" then list all PMUs. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 8 +++++ tools/perf/util/pmus.c | 54 ++++++++++++++++++++++++++++++++-- tools/perf/util/print-events.h | 1 + 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 7fec2cca759f..8fe4ddf02c14 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -423,6 +423,13 @@ static void json_print_metric(void *ps __maybe_unused,= const char *group, strbuf_release(&buf); } =20 +static bool default_skip_duplicate_pmus(void *ps) +{ + struct print_state *print_state =3D ps; + + return !print_state->long_desc; +} + int cmd_list(int argc, const char **argv) { int i, ret =3D 0; @@ -434,6 +441,7 @@ int cmd_list(int argc, const char **argv) .print_end =3D default_print_end, .print_event =3D default_print_event, .print_metric =3D default_print_metric, + .skip_duplicate_pmus =3D default_skip_duplicate_pmus, }; const char *cputype =3D NULL; const char *unit_name =3D NULL; diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 3581710667b0..5073843aca19 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -275,6 +275,50 @@ struct perf_pmu *perf_pmus__scan_core(struct perf_pmu = *pmu) return NULL; } =20 +static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *p= mu) +{ + bool use_core_pmus =3D !pmu || pmu->is_core; + int last_pmu_name_len =3D 0; + unsigned long last_pmu_num =3D 0; + const char *last_pmu_name =3D (pmu && pmu->name) ? pmu->name : ""; + + if (!pmu) { + pmu_read_sysfs(/*core_only=3D*/false); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } else + last_pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &last_pmu_= num); + + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) { + unsigned long pmu_num =3D 0; + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len =3D=3D pmu_name_len && + (last_pmu_num + 1 =3D=3D pmu_num) && + !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) { + last_pmu_num++; + continue; + } + return pmu; + } + pmu =3D NULL; + pmu =3D list_prepare_entry(pmu, &other_pmus, list); + } + list_for_each_entry_continue(pmu, &other_pmus, list) { + unsigned long pmu_num =3D 0; + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len =3D=3D pmu_name_len && + (last_pmu_num + 1 =3D=3D pmu_num) && + !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) { + last_pmu_num++; + continue; + } + return pmu; + } + return NULL; +} + const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; @@ -429,10 +473,16 @@ void perf_pmus__print_pmu_events(const struct print_c= allbacks *print_cb, void *p int printed =3D 0; int len, j; struct sevent *aliases; + struct perf_pmu *(*scan_fn)(struct perf_pmu *); + + if (print_cb->skip_duplicate_pmus(print_state)) + scan_fn =3D perf_pmus__scan_skip_duplicates; + else + scan_fn =3D perf_pmus__scan; =20 pmu =3D NULL; len =3D 0; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D scan_fn(pmu)) !=3D NULL) { list_for_each_entry(event, &pmu->aliases, list) len++; if (pmu->selectable) @@ -445,7 +495,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p } pmu =3D NULL; j =3D 0; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D scan_fn(pmu)) !=3D NULL) { bool is_cpu =3D pmu->is_core; =20 list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index d7fab411e75c..bf4290bef0cd 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -26,6 +26,7 @@ struct print_callbacks { const char *expr, const char *threshold, const char *unit); + bool (*skip_duplicate_pmus)(void *print_state); }; =20 /** Print all events, the default when no options are specified. */ --=20 2.41.0.640.ga95def55d0-goog From nobody Thu Dec 18 08:11:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3128C04FE2 for ; Mon, 14 Aug 2023 16:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231580AbjHNQiT (ORCPT ); Mon, 14 Aug 2023 12:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbjHNQiL (ORCPT ); Mon, 14 Aug 2023 12:38:11 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76438BC for ; Mon, 14 Aug 2023 09:38:10 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58c4d30c349so6110327b3.2 for ; Mon, 14 Aug 2023 09:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692031089; x=1692635889; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=nscFVL3MFrP2MCfpvE3b34w9xAwW74LjxwP+hgfykt8=; b=U9uMvD45gGusaDttinkNdE3G1frqMqeAZgoBEl4kO4UpMSWz4uWQkmm43ItG1zVAvH fuLK6gjRAPwOQOV4fZgW/QRxRBwKlmOC5QrTISPScN/qBXuZRy6dNElCLDQUtWlKfThS PZylvUlNMqaxUD75Q2ifyLOkbO7VD7UdgS5ttzVfVu1FZEW0XHuPythKS8iw5BBzTJih rJvoYUF/cLxCyfnI+My/Gd+IGoVDih7slULOv4pud4S3f1Omp1bDGhiXSUn9wdzr62lO bCxa+t8ZVLf/TlGEn0RFe4eWcb5VK619rNI6hdDdov0SFBQ0T571QEwEQVLzdOYUdY3v lbqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692031089; x=1692635889; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nscFVL3MFrP2MCfpvE3b34w9xAwW74LjxwP+hgfykt8=; b=lTBSIbwapO7fIbHRomUgHEkNBeMfaGO5juLw6OQee4VG8iJbcbAEFK2ZLB9w1+gsAW oOshmaUqqSDE7OrqLzoBoDgztQpoZVZ05o1ep+I8rlElsnc3LGevQplW+y4jD1d3UHif HfCAwi8VFyN3FUKWUr16rkwNj0lD1DaB4yUnx2WlbUkN5dvPueQEj/TYCH5aKw2PyurQ VnJ+jFQol4l6QE45RSThFKt9P2xnv3bm5yMqbNvwuk9CSv0jXD+RrseyTREoyscz9V6d VrlWKBEXAkqP7qnm2us2zEw8HhEKJPEThhCu24z2uT+mmMqft7lONgS3PSq+6rOfTC6+ w/iA== X-Gm-Message-State: AOJu0YzinJlarDbL03zurAJfa0RwDO3okQ2nQ0Y7yhRjZ0qMoVP/AjvD d89spDHeOWDflBiF9EgzvHA2Tene+DWc X-Google-Smtp-Source: AGHT+IGILuj3oJi0XcEflNpwgbZiMygoIL9Z0oYEluFBltIoEdxznvbSgnXaL7yKzRFf5SLq8mw8deBFfqrB X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a919:6125:510f:f0ef]) (user=irogers job=sendgmr) by 2002:a81:441f:0:b0:589:a5c6:4a8e with SMTP id r31-20020a81441f000000b00589a5c64a8emr146149ywa.1.1692031089732; Mon, 14 Aug 2023 09:38:09 -0700 (PDT) Date: Mon, 14 Aug 2023 09:37:57 -0700 In-Reply-To: <20230814163757.3077138-1-irogers@google.com> Message-Id: <20230814163757.3077138-4-irogers@google.com> Mime-Version: 1.0 References: <20230814163757.3077138-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v3 3/3] perf pmus: Don't print duplicate PMU suffix in list by default From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Duplicate PMUs are no longer printed by default but the suffix of the first is printed. When duplicate PMUs are being skipped avoid printing the suffix. Before: ``` $ perf list ... uncore_imc_free_running_0/data_read/ [Kernel PMU event] uncore_imc_free_running_0/data_total/ [Kernel PMU event] uncore_imc_free_running_0/data_write/ [Kernel PMU event] ``` After: ``` $ perf list ... uncore_imc_free_running/data_read/ [Kernel PMU event] uncore_imc_free_running/data_total/ [Kernel PMU event] uncore_imc_free_running/data_write/ [Kernel PMU event] ... $ perf list -v uncore_imc_free_running_0/data_read/ [Kernel PMU event] uncore_imc_free_running_0/data_total/ [Kernel PMU event] uncore_imc_free_running_0/data_write/ [Kernel PMU event] uncore_imc_free_running_1/data_read/ [Kernel PMU event] uncore_imc_free_running_1/data_total/ [Kernel PMU event] uncore_imc_free_running_1/data_write/ [Kernel PMU event] ... ``` Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 5073843aca19..b0ecb2e5bdcc 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -440,10 +440,13 @@ static int sub_non_neg(int a, int b) } =20 static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, - const struct perf_pmu_alias *alias) + const struct perf_pmu_alias *alias, bool skip_duplicate_pmus) { struct parse_events_term *term; - int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); + int pmu_name_len =3D skip_duplicate_pmus + ? pmu_name_len_no_suffix(pmu->name, /*num=3D*/NULL) + : (int)strlen(pmu->name); + int used =3D snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias= ->name); =20 list_for_each_entry(term, &alias->terms, list) { if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) @@ -473,9 +476,10 @@ void perf_pmus__print_pmu_events(const struct print_ca= llbacks *print_cb, void *p int printed =3D 0; int len, j; struct sevent *aliases; + bool skip_duplicate_pmus =3D print_cb->skip_duplicate_pmus(print_state); struct perf_pmu *(*scan_fn)(struct perf_pmu *); =20 - if (print_cb->skip_duplicate_pmus(print_state)) + if (skip_duplicate_pmus) scan_fn =3D perf_pmus__scan_skip_duplicates; else scan_fn =3D perf_pmus__scan; @@ -518,6 +522,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p *desc =3D NULL, *long_desc =3D NULL, *encoding_desc =3D NULL, *topic =3D NULL, *pmu_name =3D NULL; + int pmu_name_len; bool deprecated =3D false; size_t buf_used; =20 @@ -528,7 +533,8 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p if (!aliases[j].event) { /* A selectable event. */ pmu_name =3D aliases[j].pmu->name; - buf_used =3D snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; + pmu_name_len =3D pmu_name_len_no_suffix(pmu_name, /*num=3D*/NULL); + buf_used =3D snprintf(buf, sizeof(buf), "%.*s//", pmu_name_len, pmu_nam= e) + 1; name =3D buf; } else { if (aliases[j].event->desc) { @@ -536,7 +542,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p buf_used =3D 0; } else { name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, - aliases[j].event); + aliases[j].event, skip_duplicate_pmus); if (aliases[j].is_cpu) { alias =3D name; name =3D aliases[j].event->name; @@ -554,8 +560,10 @@ void perf_pmus__print_pmu_events(const struct print_ca= llbacks *print_cb, void *p long_desc =3D aliases[j].event->long_desc; topic =3D aliases[j].event->topic; encoding_desc =3D buf + buf_used; + pmu_name_len =3D pmu_name_len_no_suffix(pmu_name, /*num=3D*/NULL); buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", pmu_name, aliases[j].event->str) + 1; + "%.*s/%s/", pmu_name_len, pmu_name, + aliases[j].event->str) + 1; deprecated =3D aliases[j].event->deprecated; } print_cb->print_event(print_state, --=20 2.41.0.640.ga95def55d0-goog