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 B7292EB64DC for ; Tue, 11 Jul 2023 05:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbjGKF7b (ORCPT ); Tue, 11 Jul 2023 01:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjGKF70 (ORCPT ); Tue, 11 Jul 2023 01:59:26 -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 F08691BB for ; Mon, 10 Jul 2023 22:59:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5766e49b802so57150027b3.1 for ; Mon, 10 Jul 2023 22:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689055162; x=1691647162; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=aeSO6Ab0Eyw2ukZaayVI7Jjvjc4sNwkQ48k5lNueGS0=; b=gjXOdgljao5xPM58mg4voHt4zoSAKDxixNMnOBYiCtKDpPGbNg4IIwH76dxS0S2r7D 44z51bcKPkY5eFU3d87bjW2/w5Kn/9Uy5mALMzCewror48jlSfTu2lgtXEU3KncIey7x FFm6VaizZ7DsoOvhmUY6Slv2uH53++P5Kkg/ddNLwDD58JvQ6b+TXKRlcjbDAdZWWvMc yvh3fpIbD28HH5qwyJjdQ/FsFIiu90RCGYy9Q5vxhqkquGTRyM4MXsQY8JOBNg/ReKIW JpfQPubeGBQPPv8kUskm2kncwX60Kidh0bIDO4q3+ep6u0N05EIpq6d70PoRe8QdvGG0 R/jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689055162; x=1691647162; 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=aeSO6Ab0Eyw2ukZaayVI7Jjvjc4sNwkQ48k5lNueGS0=; b=Pfee6ja1MkgyeRIXVFR5K9m+U3yGSwN6bTrmhL0mFDkTLo5ch3zNGL4ao2oLxapeAz VXoQjH0XE+aBy+Ps/xeGNVgluAtg6kKxBgQb8cIUkS3uLX1k+ZuZZx2WLmr+FH29cIzt mmMiK3vlKBcFOOg0afPONxK88aBoIiibFjWDfhFIDvaXDLnWSUDPJ0sR1HMiNER4bx2C 3HCVFqruVNcArVRntHW4Jn+V43XG2ecaz3Z81eqttzkjEoppsKa3vft/m+8Vp0te3kWe NQr6m+/W4LtauAZHGZpdYoIE9SxlnfaaL16fZscoadHZfYJ+IhAov+KCedzOKsunerUW elLA== X-Gm-Message-State: ABy/qLYTbOXZeMHP1qr9ZRy0aST4X4FAwUHeb5lEZ598ueWj5oPODysl 6ySntgthpW+a3+FTz7eb7v7LKN3eXejV X-Google-Smtp-Source: APBJJlGQJZh+yd9CTr3OHMJ/77Fhyx9lb5YbPdo/rb/ivgX6ul3fPMNM2KB6+aemsZegJ3B80xOOqwmEx+le X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:2efd:fc0f:9eaa:3bd5]) (user=irogers job=sendgmr) by 2002:a81:ac47:0:b0:576:92da:cd3d with SMTP id z7-20020a81ac47000000b0057692dacd3dmr107380ywj.8.1689055162240; Mon, 10 Jul 2023 22:59:22 -0700 (PDT) Date: Mon, 10 Jul 2023 22:58:58 -0700 In-Reply-To: <20230711055859.1242497-1-irogers@google.com> Message-Id: <20230711055859.1242497-3-irogers@google.com> Mime-Version: 1.0 References: <20230711055859.1242497-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Subject: [PATCH v1 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org When there are multiple PMUs that differ only by suffix, 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. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 48 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 3581710667b0..87e5fb74e121 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; } +static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu) +{ + bool use_core_pmus = !pmu || pmu->is_core; + int last_pmu_name_len = 0; + unsigned long last_pmu_num = 0; + const char *last_pmu_name = (pmu && pmu->name) ? pmu->name : ""; + + if (!pmu) { + pmu_read_sysfs(/*core_only=*/false); + pmu = list_prepare_entry(pmu, &core_pmus, list); + } else + last_pmu_name_len = 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 = 0; + int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len == pmu_name_len && + (last_pmu_num + 1 == pmu_num) && + !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) { + last_pmu_num++; + continue; + } + return pmu; + } + pmu = NULL; + pmu = list_prepare_entry(pmu, &other_pmus, list); + } + list_for_each_entry_continue(pmu, &other_pmus, list) { + unsigned long pmu_num = 0; + int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len == pmu_name_len && + (last_pmu_num + 1 == 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 = NULL; @@ -432,7 +476,7 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p pmu = NULL; len = 0; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan_skip_duplicates(pmu)) != NULL) { list_for_each_entry(event, &pmu->aliases, list) len++; if (pmu->selectable) @@ -445,7 +489,7 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p } pmu = NULL; j = 0; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan_skip_duplicates(pmu)) != NULL) { bool is_cpu = pmu->is_core; list_for_each_entry(event, &pmu->aliases, list) { -- 2.41.0.390.g38632f3daf-goog