From nobody Tue Dec 16 19:54:51 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 D6342EE49A5 for ; Thu, 24 Aug 2023 22:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243894AbjHXW1k (ORCPT ); Thu, 24 Aug 2023 18:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240425AbjHXW1Y (ORCPT ); Thu, 24 Aug 2023 18:27:24 -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 6353E1BEB for ; Thu, 24 Aug 2023 15:27:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58fbc0e0c6dso4891597b3.0 for ; Thu, 24 Aug 2023 15:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692916041; x=1693520841; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=yz2521idZC7Ay4NTiFNMcjkHoMtrhiUpIqFT4nzfTmE=; b=MTnsyQ9/Jse2ezqhFINqxxpg5HasXI35lYvN01ug0krp+X2r42cOgjd9Gw+FPdhSai /4E5yuHcfFabrdZ6wt9sUxMQbcGkfrSZIKjRFOMXjOPvaouEZ1dsTN+LfJVsSVO1bPcR MkGEKjEBSCVfZZWj/tU8zf78BED9gU9bPJdHlUeC7cWjfGSTOd/byJkCcW65Ac2LiUJl 4OO0KCqaTIrkg+2SoqafKk+IhRkVWbC918bVHdmWN6TGw7etFNEWo0Qxr6yi9ACgNcDk USzSndu/8JlmT4CHjETEHyZTYbuBQ9nf69SitrRcn2Uw3NoQkIXKMW+J4bIaUi/GxlD2 pt+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692916041; x=1693520841; 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=yz2521idZC7Ay4NTiFNMcjkHoMtrhiUpIqFT4nzfTmE=; b=MPJPAJ9sg7bUAyxtnKrtfzF7nDp8HnYRXb8N2+deh9XDHxQn65RW4G+61qHGy3P6T0 dZLk5cLfqvG4G6a7YfRZaz4ByU9NdOBDpoJx7W7VH66zyHveMCF+/a88WwIFToMscOH3 +QOmzqfUDkzRMzyGBoddFe8De8ckoMPWrLi5UQv18SzosC3w8vEUe4NBcCVKrsdgd741 nlOrz5IvYqrPLGWSQifPJ7UI7qv9pj3FkzTn9Hc47wowVXx0YrtO3ZcQziMSipJ8lNas XGGC/jfW9kHTGAvFHLMRp98gDaV0ErAtHAIRPDtkGlibvV4AB0+WPn8896sN3iN76E5n JOEA== X-Gm-Message-State: AOJu0YzWK+zGBbwPgX4FxxJdJX4vDcOsXqNAyPVzgWcpGJwMwnA1VF0Z LYs2+NXvGFZEKlMhsYCw0kqA/1qYQXd6 X-Google-Smtp-Source: AGHT+IFV2YTX24TKdDAUJ4fkcyCUvTxrmg1T3lOrvDgTQNZMIiZY7MeSOBobk1CP6++gdx2snH68EZ21YZQx X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:fbb9:d9e7:7405:2651]) (user=irogers job=sendgmr) by 2002:a81:af03:0:b0:583:9913:f293 with SMTP id n3-20020a81af03000000b005839913f293mr305363ywh.1.1692916041696; Thu, 24 Aug 2023 15:27:21 -0700 (PDT) Date: Thu, 24 Aug 2023 15:27:15 -0700 In-Reply-To: <20230824222716.553982-1-irogers@google.com> Message-Id: <20230824222716.553982-2-irogers@google.com> Mime-Version: 1.0 References: <20230824222716.553982-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Subject: [PATCH v4 1/2] 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 4dd5912617ff..b1f6a64693fe 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.42.0.rc2.253.gd59a3bf2b4-goog From nobody Tue Dec 16 19:54:51 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 E730EEE49A0 for ; Thu, 24 Aug 2023 22:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243910AbjHXW1l (ORCPT ); Thu, 24 Aug 2023 18:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241943AbjHXW11 (ORCPT ); Thu, 24 Aug 2023 18:27:27 -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 A2EBA1BEB for ; Thu, 24 Aug 2023 15:27:24 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5925fb6087bso4701977b3.2 for ; Thu, 24 Aug 2023 15:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692916044; x=1693520844; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PsGJ9pkJpx1hk+C6giH/EfxO6XgKszScHPOUBP87Wvw=; b=2ZZnG63SDAPkUMfvbHyzPCOEzE2PNnT1Tb2pBjBJRZwouEsM7YnQfdNhP5EEcsE5Nn A7DbUygbMxX2NvU+aq5t9QkfSXum2Yhap/nBm8Uw9NeeD6H1F3c/WIGxje26V7LbGDeK +o7w5OSYZJrVmDSljaPw86OQYaEtxQnXEQpxgtZ3u+0u4LZEp28QQeFn+0am8xMX3gxv +Bo0rzST/6HqC2my1gtpZ9yz5RrzsNx8VrHDtP3nNTX0sgjhvBNg8vM4duwmH7IyEYbp sWlFR66cJjaqNCz8d/vFszWm0s1MuZp058qzrk4EGrKpKlBGmv/IKLE6TpVnhbDqlM34 r5oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692916044; x=1693520844; 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=PsGJ9pkJpx1hk+C6giH/EfxO6XgKszScHPOUBP87Wvw=; b=TBkvyNX5nFV7Z7JCwW5nNwPvPsYndOOlY4Uh9grFVyqDc6Vqt4kIQAwxOFIIPpehDo +IGvIMUqwjc1lypPjRhVA/PqbI/J8urW7U0HT4T+7XpMwyiXM9enFMUAkend1bmM4KWJ O9S/BGiIvNTiQfL3Zqwz8zeao0+roBoMFo5TN7KfKf9UX4D3gkHjM1FXQi2/1a0FOFVX uz8Zg3NcsIY40itjbyx2FMQzxBuGvPNkRvaHlfr+sVH+R4Dv1GOMUX/++PsU3HlRJqzl iTQ4fwEQKPlk7tL+n7tB/hl+G5FiWnQfCy49Eom9GnsEchE1z+a4FqZhDw/0z4+wfDqw 1DBQ== X-Gm-Message-State: AOJu0Yz4EVzOld240Sya/bMHL7Hl51Qx87m3AT/dqz2iyWq2XfvjLxQm jcGvOf6H4P7G5ZlzXqhHCf385NZ6q7Xz X-Google-Smtp-Source: AGHT+IFAgs7eB/hOEvRyPzuYs7Ga70ODy5BsvZT3Fqs1up7wbr4SIWVBJ1BYtG6ErbOwFCDqe5d27wIKHVVA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:fbb9:d9e7:7405:2651]) (user=irogers job=sendgmr) by 2002:a25:ce14:0:b0:c15:cbd1:60da with SMTP id x20-20020a25ce14000000b00c15cbd160damr258473ybe.6.1692916043957; Thu, 24 Aug 2023 15:27:23 -0700 (PDT) Date: Thu, 24 Aug 2023 15:27:16 -0700 In-Reply-To: <20230824222716.553982-1-irogers@google.com> Message-Id: <20230824222716.553982-3-irogers@google.com> Mime-Version: 1.0 References: <20230824222716.553982-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Subject: [PATCH v4 2/2] perf pmus: Skip duplicate PMUs and don't print list suffix 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" Add a PMUs scan that ignores duplicates. 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. With the previous change duplicate PMUs are no longer printed 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] 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] ``` 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/builtin-list.c | 8 +++++ tools/perf/util/pmu.c | 17 +++++++--- tools/perf/util/pmu.h | 3 +- tools/perf/util/pmus.c | 56 ++++++++++++++++++++++++++++--- tools/perf/util/pmus.h | 2 ++ tools/perf/util/print-events.h | 1 + tools/perf/util/s390-sample-raw.c | 3 +- 7 files changed, 79 insertions(+), 11 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/pmu.c b/tools/perf/util/pmu.c index bb2ca29cd7bd..b9ed829318c3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1576,7 +1576,9 @@ int perf_pmu__find_event(struct perf_pmu *pmu, const = char *event, void *state, p .cb =3D cb, }; =20 - return perf_pmu__for_each_event(pmu, &args, find_event_callback); + /* Sub-optimal, but function is only used by tests. */ + return perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=3D*/ false, + &args, find_event_callback); } =20 static void perf_pmu__del_formats(struct list_head *formats) @@ -1650,10 +1652,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) @@ -1675,7 +1680,8 @@ static char *format_alias(char *buf, int len, const s= truct perf_pmu *pmu, return buf; } =20 -int perf_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_= callback cb) +int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmu= s, + void *state, pmu_event_callback cb) { char buf[1024]; struct perf_pmu_alias *event; @@ -1694,7 +1700,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, vo= id *state, pmu_event_callba info.name =3D event->name; buf_used =3D 0; } else { - info.name =3D format_alias(buf, sizeof(buf), pmu, event); + info.name =3D format_alias(buf, sizeof(buf), pmu, event, + skip_duplicate_pmus); if (pmu->is_core) { info.alias =3D info.name; info.name =3D event->name; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index bae0de3ed7a5..b5c506f35b42 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -212,7 +212,8 @@ bool perf_pmu__supports_legacy_cache(const struct perf_= pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name); size_t perf_pmu__num_events(struct perf_pmu *pmu); -int perf_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_= callback cb); +int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmu= s, + void *state, pmu_event_callback cb); bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name); =20 /** diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index b1f6a64693fe..9a748599e4cf 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -35,7 +35,7 @@ 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 pmu_name_len_no_suffix(const char *str, unsigned long *num) { int orig_len, len; =20 @@ -275,6 +275,46 @@ 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) { + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", /*num=3D*/= NULL); + + if (last_pmu_name_len =3D=3D pmu_name_len && + !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) { + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", /*num=3D*/N= ULL); + + if (last_pmu_name_len =3D=3D pmu_name_len && + !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; @@ -400,10 +440,17 @@ void perf_pmus__print_pmu_events(const struct print_c= allbacks *print_cb, void *p int len; struct sevent *aliases; struct events_callback_state state; + bool skip_duplicate_pmus =3D print_cb->skip_duplicate_pmus(print_state); + struct perf_pmu *(*scan_fn)(struct perf_pmu *); + + if (skip_duplicate_pmus) + 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) len +=3D perf_pmu__num_events(pmu); =20 aliases =3D zalloc(sizeof(struct sevent) * len); @@ -417,8 +464,9 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p .aliases_len =3D len, .index =3D 0, }; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - perf_pmu__for_each_event(pmu, &state, perf_pmus__print_pmu_events__callb= ack); + while ((pmu =3D scan_fn(pmu)) !=3D NULL) { + perf_pmu__for_each_event(pmu, skip_duplicate_pmus, &state, + perf_pmus__print_pmu_events__callback); } qsort(aliases, len, sizeof(struct sevent), cmp_sevent); for (int j =3D 0; j < len; j++) { diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index a21464432d0f..4c67153ac257 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -5,6 +5,8 @@ struct perf_pmu; struct print_callbacks; =20 +int pmu_name_len_no_suffix(const char *str, unsigned long *num); + void perf_pmus__destroy(void); =20 struct perf_pmu *perf_pmus__find(const char *name); 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. */ diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sampl= e-raw.c index dc1ed3e95d4d..115b16edb451 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -171,7 +171,8 @@ static char *get_counter_name(int set, int nr, struct p= erf_pmu *pmu) if (!pmu) return NULL; =20 - perf_pmu__for_each_event(pmu, &data, get_counter_name_callback); + perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=3D*/ true, + &data, get_counter_name_callback); return data.result; } =20 --=20 2.42.0.rc2.253.gd59a3bf2b4-goog