From nobody Sat Feb 7 18:20:54 2026 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 7A723C77B73 for ; Mon, 22 May 2023 06:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbjEVGnn (ORCPT ); Mon, 22 May 2023 02:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjEVGnj (ORCPT ); Mon, 22 May 2023 02:43:39 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D29DB0 for ; Sun, 21 May 2023 23:43:37 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-6438e9e9f91so3208379b3a.2 for ; Sun, 21 May 2023 23:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737817; x=1687329817; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lBsInQBW9Hd6NrV2kgL2lBOHmq5skpLBdaRHsPn9wFo=; b=IsBHWfURhBnQt5SjTPn1pi7+4PMOXGN+LQE7bicbvU/obr+5V07EbidkcZT4f4nmHd gK4OEw5VXfjIJmYZCjeYPSStTVISe8EkZpkzAWD5JSkXITMmeD3cnxYNk2ejTuP+amK8 ZgCuy0s7+NbuZCV0xq5f0EH0GbSRnb8M5C3TSTGUWL/G9zqx7UMackjx1QO0osuhVmiS i9lkiOxk8NlFc1lA8cFPArB5aQ2kBrvVqHRuHJvU5xWULf4UA0y7+c6k4tE6c0bJwt5K x7S7UGPMvK1UwBSSdbQGy58Vu425kIRscId1qNtrReCZOmYXg9dZIN3nHKsr5CsAN+Q8 OvyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737817; x=1687329817; 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=lBsInQBW9Hd6NrV2kgL2lBOHmq5skpLBdaRHsPn9wFo=; b=b72FMedDq4r2gtTJlLjUORsq15YZV7bpTCAtJhv5Y3pLQOJd+LB52ZQ0pCE+642XLw ACszBf269sTrgGoYRM85LNGI3g2vzkgy4GKSl/zSul8kpMTn4H2vzc8gB9G4Qh0vTndp FiPQcksbnivzXpc9echJ9EoD8/ojFpkDJwWYC4A98b3OxC/x/PSBPUTRzMBZKHfVokYc ohlM0Eyek1PxqaPZkGAeS/XhzVtfW4u38Oa8o+XlryuQzdXPuj3chXnGPWsEyZmhq/SW cdaJTZuFWlC0iXF//WENKvNwG33/VKyZ4S4UCGtPxZEdiQk++6BvY90G8dR1utPryYXW s4KQ== X-Gm-Message-State: AC+VfDwvfV/UN3uIUUWEIiwIeNZ0YBCEoaBseYlcKtCKurWL3dZ5W41h 1tEMyPwuSNRvvhaQh7LuJI8Ocv8Ln9IT X-Google-Smtp-Source: ACHHUZ7R80k0G5dXy0aY7qqjnAIv6WcMxlvm1HYYVN0ubdsoCNyqKTE+zydtyixrAxVXSFr13wzJZA2h3ppE X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a05:6a00:985:b0:64c:b6d6:6f60 with SMTP id u5-20020a056a00098500b0064cb6d66f60mr4167569pfg.1.1684737816788; Sun, 21 May 2023 23:43:36 -0700 (PDT) Date: Sun, 21 May 2023 23:43:08 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-2-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 01/23] perf tools: Warn if no user requested CPUs match PMU's CPUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" In commit 1d3351e631fc ("perf tools: Enable on a list of CPUs for hybrid") perf on hybrid will warn if a user requested CPU doesn't match the PMU of the given event but only for hybrid PMUs. Make the logic generic for all PMUs and remove the hybrid logic. Warn if a CPU is requested that is offline for uncore events. Warn if a CPU is requested for a core PMU, but the CPU isn't within the cpu map of that PMU. For example on a 16 (0-15) CPU system: ``` $ perf stat -e imc_free_running/data_read/,cycles -C 16 true WARNING: Requested CPU(s) '16' not supported by PMU 'uncore_imc_free_runnin= g_1' for event 'imc_free_running/data_read/' WARNING: Requested CPU(s) '16' not supported by PMU 'uncore_imc_free_runnin= g_0' for event 'imc_free_running/data_read/' WARNING: Requested CPU(s) '16' not supported by PMU 'cpu' for event 'cycles' Performance counter stats for 'CPU(s) 16': MiB imc_free_running/data_read/ cycles 0.000570094 seconds time elapsed ``` Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 6 +-- tools/perf/builtin-stat.c | 5 +-- tools/perf/util/cpumap.h | 2 +- tools/perf/util/evlist-hybrid.c | 74 --------------------------------- tools/perf/util/evlist-hybrid.h | 1 - tools/perf/util/evlist.c | 44 ++++++++++++++++++++ tools/perf/util/evlist.h | 2 + tools/perf/util/pmu.c | 33 --------------- tools/perf/util/pmu.h | 4 -- 9 files changed, 49 insertions(+), 122 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ec0f2d5f189f..9d212236c75a 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4198,11 +4198,7 @@ int cmd_record(int argc, const char **argv) /* Enable ignoring missing threads when -u/-p option is defined. */ rec->opts.ignore_missing_thread =3D rec->opts.target.uid !=3D UINT_MAX ||= rec->opts.target.pid; =20 - if (evlist__fix_hybrid_cpus(rec->evlist, rec->opts.target.cpu_list)) { - pr_err("failed to use cpu list %s\n", - rec->opts.target.cpu_list); - goto out; - } + evlist__warn_user_requested_cpus(rec->evlist, rec->opts.target.cpu_list); =20 rec->opts.target.hybrid =3D perf_pmu__has_hybrid(); =20 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bc45cee3f77c..612467216306 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2462,10 +2462,7 @@ int cmd_stat(int argc, const char **argv) } } =20 - if (evlist__fix_hybrid_cpus(evsel_list, target.cpu_list)) { - pr_err("failed to use cpu list %s\n", target.cpu_list); - goto out; - } + evlist__warn_user_requested_cpus(evsel_list, target.cpu_list); =20 target.hybrid =3D perf_pmu__has_hybrid(); if (evlist__create_maps(evsel_list, &target) < 0) { diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index e3426541e0aa..c1de993c083f 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -59,7 +59,7 @@ struct perf_cpu cpu__max_present_cpu(void); /** * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, us= e a single dummy map with an entry of -1. */ -static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus) +static inline bool cpu_map__is_dummy(const struct perf_cpu_map *cpus) { return perf_cpu_map__nr(cpus) =3D=3D 1 && perf_cpu_map__cpu(cpus, 0).cpu = =3D=3D -1; } diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index 57f02beef023..db3f5fbdebe1 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -86,77 +86,3 @@ bool evlist__has_hybrid(struct evlist *evlist) =20 return false; } - -int evlist__fix_hybrid_cpus(struct evlist *evlist, const char *cpu_list) -{ - struct perf_cpu_map *cpus; - struct evsel *evsel, *tmp; - struct perf_pmu *pmu; - int ret, unmatched_count =3D 0, events_nr =3D 0; - - if (!perf_pmu__has_hybrid() || !cpu_list) - return 0; - - cpus =3D perf_cpu_map__new(cpu_list); - if (!cpus) - return -1; - - /* - * The evsels are created with hybrid pmu's cpus. But now we - * need to check and adjust the cpus of evsel by cpu_list because - * cpu_list may cause conflicts with cpus of evsel. For example, - * cpus of evsel is cpu0-7, but the cpu_list is cpu6-8, we need - * to adjust the cpus of evsel to cpu6-7. And then propatate maps - * in evlist__create_maps(). - */ - evlist__for_each_entry_safe(evlist, tmp, evsel) { - struct perf_cpu_map *matched_cpus, *unmatched_cpus; - char buf1[128], buf2[128]; - - pmu =3D perf_pmu__find_hybrid_pmu(evsel->pmu_name); - if (!pmu) - continue; - - ret =3D perf_pmu__cpus_match(pmu, cpus, &matched_cpus, - &unmatched_cpus); - if (ret) - goto out; - - events_nr++; - - if (perf_cpu_map__nr(matched_cpus) > 0 && - (perf_cpu_map__nr(unmatched_cpus) > 0 || - perf_cpu_map__nr(matched_cpus) < perf_cpu_map__nr(cpus) || - perf_cpu_map__nr(matched_cpus) < perf_cpu_map__nr(pmu->cpus))) { - perf_cpu_map__put(evsel->core.cpus); - perf_cpu_map__put(evsel->core.own_cpus); - evsel->core.cpus =3D perf_cpu_map__get(matched_cpus); - evsel->core.own_cpus =3D perf_cpu_map__get(matched_cpus); - - if (perf_cpu_map__nr(unmatched_cpus) > 0) { - cpu_map__snprint(matched_cpus, buf1, sizeof(buf1)); - pr_warning("WARNING: use %s in '%s' for '%s', skip other cpus in list.= \n", - buf1, pmu->name, evsel->name); - } - } - - if (perf_cpu_map__nr(matched_cpus) =3D=3D 0) { - evlist__remove(evlist, evsel); - evsel__delete(evsel); - - cpu_map__snprint(cpus, buf1, sizeof(buf1)); - cpu_map__snprint(pmu->cpus, buf2, sizeof(buf2)); - pr_warning("WARNING: %s isn't a '%s', please use a CPU list in the '%s'= range (%s)\n", - buf1, pmu->name, pmu->name, buf2); - unmatched_count++; - } - - perf_cpu_map__put(matched_cpus); - perf_cpu_map__put(unmatched_cpus); - } - if (events_nr) - ret =3D (unmatched_count =3D=3D events_nr) ? -1 : 0; -out: - perf_cpu_map__put(cpus); - return ret; -} diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index aacdb1b0f948..19f74b4c340a 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -10,6 +10,5 @@ int evlist__add_default_hybrid(struct evlist *evlist, bool precise); void evlist__warn_hybrid_group(struct evlist *evlist); bool evlist__has_hybrid(struct evlist *evlist); -int evlist__fix_hybrid_cpus(struct evlist *evlist, const char *cpu_list); =20 #endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a0504316b06f..5d0d99127a90 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2465,3 +2465,47 @@ void evlist__check_mem_load_aux(struct evlist *evlis= t) } } } + +/** + * evlist__warn_user_requested_cpus() - Check each evsel against requested= CPUs + * and warn if the user CPU list is inapplicable for the event's PMUs + * CPUs. Uncore PMUs list a CPU in sysfs, but this may be overwritten = by a + * user requested CPU and so any online CPU is applicable. Core PMUs h= andle + * events on the CPUs in their list and otherwise the event isn't supp= orted. + * @evlist: The list of events being checked. + * @cpu_list: The user provided list of CPUs. + */ +void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *c= pu_list) +{ + struct perf_cpu_map *user_requested_cpus; + struct evsel *pos; + + if (!cpu_list) + return; + + user_requested_cpus =3D perf_cpu_map__new(cpu_list); + if (!user_requested_cpus) + return; + + evlist__for_each_entry(evlist, pos) { + const struct perf_cpu_map *to_test; + struct perf_cpu cpu; + int idx; + bool warn =3D true; + const struct perf_pmu *pmu =3D evsel__find_pmu(pos); + + to_test =3D pmu && pmu->is_uncore ? cpu_map__online() : evsel__cpus(pos); + + perf_cpu_map__for_each_cpu(cpu, idx, to_test) { + if (perf_cpu_map__has(user_requested_cpus, cpu)) { + warn =3D false; + break; + } + } + if (warn) { + pr_warning("WARNING: Requested CPU(s) '%s' not supported by PMU '%s' fo= r event '%s'\n", + cpu_list, pmu ? pmu->name : "cpu", evsel__name(pos)); + } + } + perf_cpu_map__put(user_requested_cpus); +} diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index e7e5540cc970..5e7ff44f3043 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -447,4 +447,6 @@ struct evsel *evlist__find_evsel(struct evlist *evlist,= int idx); =20 int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf); void evlist__check_mem_load_aux(struct evlist *evlist); +void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *c= pu_list); + #endif /* __PERF_EVLIST_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f4f0afbc391c..1e0be23d4dd7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2038,39 +2038,6 @@ int perf_pmu__match(char *pattern, char *name, char = *tok) return 0; } =20 -int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus, - struct perf_cpu_map **mcpus_ptr, - struct perf_cpu_map **ucpus_ptr) -{ - struct perf_cpu_map *pmu_cpus =3D pmu->cpus; - struct perf_cpu_map *matched_cpus, *unmatched_cpus; - struct perf_cpu cpu; - int i, matched_nr =3D 0, unmatched_nr =3D 0; - - matched_cpus =3D perf_cpu_map__default_new(); - if (!matched_cpus) - return -1; - - unmatched_cpus =3D perf_cpu_map__default_new(); - if (!unmatched_cpus) { - perf_cpu_map__put(matched_cpus); - return -1; - } - - perf_cpu_map__for_each_cpu(cpu, i, cpus) { - if (!perf_cpu_map__has(pmu_cpus, cpu)) - RC_CHK_ACCESS(unmatched_cpus)->map[unmatched_nr++] =3D cpu; - else - RC_CHK_ACCESS(matched_cpus)->map[matched_nr++] =3D cpu; - } - - perf_cpu_map__set_nr(unmatched_cpus, unmatched_nr); - perf_cpu_map__set_nr(matched_cpus, matched_nr); - *mcpus_ptr =3D matched_cpus; - *ucpus_ptr =3D unmatched_cpus; - return 0; -} - double __weak perf_pmu__cpu_slots_per_cycle(void) { return NAN; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 0e0cb6283594..49033bb134f3 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -257,10 +257,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *p= mu); bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); =20 -int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus, - struct perf_cpu_map **mcpus_ptr, - struct perf_cpu_map **ucpus_ptr); - char *pmu_find_real_name(const char *name); char *pmu_find_alias_name(const char *name); double perf_pmu__cpu_slots_per_cycle(void); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 906AFC77B73 for ; Mon, 22 May 2023 06:43:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231801AbjEVGnr (ORCPT ); Mon, 22 May 2023 02:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjEVGnl (ORCPT ); Mon, 22 May 2023 02:43:41 -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 E769FDB for ; Sun, 21 May 2023 23:43:39 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561f1c2af16so50819867b3.0 for ; Sun, 21 May 2023 23:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737819; x=1687329819; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=YoYQrktSOccz718yMhyWafTj7aToTsjoW8qdnpiUZYY=; b=p4E3xAl4XG1dKT000lYOPmwBSht2Qw2MVH35qpYGcnO9gDR1I/yWJmhkM2Y/cdCj+Q zuWQEAmrev+Yx2pU9KoOdGwuAjyfi0QspHLQEHvx3oVAzDsKGOFw2kHAlz4tsnof/O31 yezQYBJcjfWx/N7dtIRCs2X8oq/QyaOvco7lZJytBmbJaljJw5LnGHe4W0mb8IlYxPc5 wU+G/8UUCXSsbloow9Q4ZGdstpRp+gbLed12UVBy+PuecKiTQz9mvgxUofGWJIxg6D32 w/qwzsxMxnGXJV+b7pCmIX3JUCE5wfmnyJ9Y25NvyycPG8Dinxa595ydHwPeJthq4b0u KxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737819; x=1687329819; 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=YoYQrktSOccz718yMhyWafTj7aToTsjoW8qdnpiUZYY=; b=LxlH2vJsN8Hktvh2x4bJXg+9r21gb/eG9xc9XtplUK7ZedUxNgi+2bYG4cwW1J8UuX n0ktpOY7ebvmWoiUAYnpyYsyeVnsK7S+yqU7wV++gLOGmr26oAqS3eZD9DMK9hYavCoa pF2DFi7Mr8k2B1FqyUmh+I1266olNwOvD/Vw/NU53j6YtgYzXXfNvdPNFhelYqB03+S8 gwmGpq0GNIp0Tvth1UP1DrY4np9ozzFtYDGJE+mOUPbQ0vPy7/rCdinOasP0vM9W1Ubw XI5hf5IR71ViBbGdwFUkuCzYIwqQ1lKDLeJVi5WM6C9o0F6UFwnM8hQIWr3OKOTvmUZe vQwA== X-Gm-Message-State: AC+VfDxuQ99SY0L0R8xjJ7+SKm5UOcwms5dC9u9pk1KgFuRDNjSInbVS A88mhaWYVwhfK3F/UISELAVbDSE5n+kp X-Google-Smtp-Source: ACHHUZ5zk5F+ezydcSeNEXKAuTWtoOxv1KsUK53ta6Dl2Ey4DOCdRM1cKjKUCN/xLGjgziKs06G4WAqcGHSR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a81:a9c9:0:b0:561:c10b:6ebb with SMTP id g192-20020a81a9c9000000b00561c10b6ebbmr6099609ywh.1.1684737819008; Sun, 21 May 2023 23:43:39 -0700 (PDT) Date: Sun, 21 May 2023 23:43:09 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-3-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 02/23] perf evlist: Remove evlist__warn_hybrid_group From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Parse events now corrects PMU groups in parse_events__sort_events_and_fix_groups and so this warning is no longer possible. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 3 --- tools/perf/util/evlist-hybrid.c | 32 -------------------------------- tools/perf/util/evlist-hybrid.h | 1 - 3 files changed, 36 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 612467216306..084cc570b8e8 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -187,9 +187,6 @@ static void evlist__check_cpu_maps(struct evlist *evlis= t) { struct evsel *evsel, *warned_leader =3D NULL; =20 - if (evlist__has_hybrid(evlist)) - evlist__warn_hybrid_group(evlist); - evlist__for_each_entry(evlist, evsel) { struct evsel *leader =3D evsel__leader(evsel); =20 diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index db3f5fbdebe1..0f59c80f27b2 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -41,38 +41,6 @@ int evlist__add_default_hybrid(struct evlist *evlist, bo= ol precise) return 0; } =20 -static bool group_hybrid_conflict(struct evsel *leader) -{ - struct evsel *pos, *prev =3D NULL; - - for_each_group_evsel(pos, leader) { - if (!evsel__is_hybrid(pos)) - continue; - - if (prev && strcmp(prev->pmu_name, pos->pmu_name)) - return true; - - prev =3D pos; - } - - return false; -} - -void evlist__warn_hybrid_group(struct evlist *evlist) -{ - struct evsel *evsel; - - evlist__for_each_entry(evlist, evsel) { - if (evsel__is_group_leader(evsel) && - evsel->core.nr_members > 1 && - group_hybrid_conflict(evsel)) { - pr_warning("WARNING: events in group from " - "different hybrid PMUs!\n"); - return; - } - } -} - bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index 19f74b4c340a..4b000eda6626 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -8,7 +8,6 @@ #include =20 int evlist__add_default_hybrid(struct evlist *evlist, bool precise); -void evlist__warn_hybrid_group(struct evlist *evlist); bool evlist__has_hybrid(struct evlist *evlist); =20 #endif /* __PERF_EVLIST_HYBRID_H */ --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 E4DD5C7EE26 for ; Mon, 22 May 2023 06:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjEVGnx (ORCPT ); Mon, 22 May 2023 02:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjEVGno (ORCPT ); Mon, 22 May 2023 02:43:44 -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 82B24B0 for ; Sun, 21 May 2023 23:43:42 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56183784dd3so66015587b3.3 for ; Sun, 21 May 2023 23:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737821; x=1687329821; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=YaDoJOiblpY/xwThq9/yxzSkfB0RljY01fRvhkKU/3U=; b=S4jsBBf3UDIm+wf5LTSsn+4RDqLY9Zu0/rNL7BDAAXSDcS5bboOZTSD6OyoLFCa8b+ zbZRf4HIJlxO12BJl2+//0R8rru/BdTYzI9KB2ac5jbnKMruXrMlvIimOf4DeCOHFV21 8srCTQhYMS46uXV/5de6NBmWaz9lyVLZoZm7XBd82p1CUZY+an4TYo/qFqAw+JefCMrD XNbVNZPi1HO+TTe8/KghIT43Ktqg4AvkwPe/gWPPwIr/npKqME7ZJvBViMq7XJAn6w0E hbQZ+lPLqsbpqK7REgCwhQVv99WpzpFrXdGv2ipLdh5FhTHyxA7KcMxEQLYII4MaemZp 6mtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737821; x=1687329821; 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=YaDoJOiblpY/xwThq9/yxzSkfB0RljY01fRvhkKU/3U=; b=ECU7IIz4TdQtA5+MjzdvsKUY8WvefqJdSmg0Hz9ppY91rYyL74A9kiZQpOHlES2L3G e0Zd+/qmVnbu1AFGzrxeIHSWyFrwgM7YEu3UYG+8VvcLPEAgf2ZlkgW+vwz3Lvi6dz8B xB4Nr754LvFIbt1zgFA9zNtZ5HJGuwEdyRsbqDs0vPvocjzcyhzGLh3gBHzgzJPWsnOo mYKS4RGsC6FpaeJ4PD9cml0Tjqfd3dE0NHJluf+YqmKHZYSymufRY94rd/Gzr+/PZKZ1 4jYoIK1zBMZVzguyXrlVZT6U7VDNUiliftQZNK+ARIJCly3tuv4VRBmYamnI4zKUhVCv 8MBg== X-Gm-Message-State: AC+VfDycUYPdFc7oesekNYr+ATdVVj6GtA7ofwJniTwXfi+uQ1xpyDN4 K+h0AjiDU/5nL78kqli2E5/E3YuWUyVa X-Google-Smtp-Source: ACHHUZ4NjuniklZ49Ql0FqujJ07USmImHZxcXDLXkE5rToeqVl9a+lPdLIoReaIbfqx+XFwUUl/aZSzWWvfK X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:aaad:0:b0:ba8:93c3:331a with SMTP id t42-20020a25aaad000000b00ba893c3331amr5997933ybi.5.1684737821235; Sun, 21 May 2023 23:43:41 -0700 (PDT) Date: Sun, 21 May 2023 23:43:10 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-4-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 03/23] perf evlist: Remove __evlist__add_default From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" __evlist__add_default adds a cycles event to a typically empty evlist and was extended for hybrid with evlist__add_default_hybrid, as more than 1 PMU was necessary. Rather than have dedicated logic for the cycles event, this change switches to parsing 'cycles:P' which will handle wildcarding the PMUs appropriately for hybrid. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/evsel.c | 20 -------------- tools/perf/builtin-record.c | 13 +++------ tools/perf/builtin-top.c | 10 ++++--- tools/perf/util/evlist-hybrid.c | 25 ----------------- tools/perf/util/evlist-hybrid.h | 1 - tools/perf/util/evlist.c | 22 ++++++--------- tools/perf/util/evlist.h | 7 ----- tools/perf/util/evsel.c | 46 -------------------------------- tools/perf/util/evsel.h | 3 --- 9 files changed, 17 insertions(+), 130 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index ea3972d785d1..153cdca94cd4 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -16,26 +16,6 @@ void arch_evsel__set_sample_weight(struct evsel *evsel) evsel__set_sample_bit(evsel, WEIGHT_STRUCT); } =20 -void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) -{ - struct perf_env env =3D { .total_mem =3D 0, } ; - - if (!perf_env__cpuid(&env)) - return; - - /* - * On AMD, precise cycles event sampling internally uses IBS pmu. - * But IBS does not have filtering capabilities and perf by default - * sets exclude_guest =3D 1. This makes IBS pmu event init fail and - * thus perf ends up doing non-precise sampling. Avoid it by clearing - * exclude_guest. - */ - if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD")) - attr->exclude_guest =3D 0; - - free(env.cpuid); -} - /* Check whether the evsel's PMU supports the perf metrics */ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) { diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 9d212236c75a..a107a7adbcf4 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4161,18 +4161,11 @@ int cmd_record(int argc, const char **argv) record.opts.tail_synthesize =3D true; =20 if (rec->evlist->core.nr_entries =3D=3D 0) { - if (perf_pmu__has_hybrid()) { - err =3D evlist__add_default_hybrid(rec->evlist, - !record.opts.no_samples); - } else { - err =3D __evlist__add_default(rec->evlist, - !record.opts.no_samples); - } + bool can_profile_kernel =3D perf_event_paranoid_check(1); =20 - if (err < 0) { - pr_err("Not enough memory for event selector list\n"); + err =3D parse_event(rec->evlist, can_profile_kernel ? "cycles:P" : "cycl= es:Pu"); + if (err) goto out; - } } =20 if (rec->opts.target.tid && !rec->opts.no_inherit_set) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 48ee49e95c5e..27a7f068207d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1653,10 +1653,12 @@ int cmd_top(int argc, const char **argv) if (annotate_check_args(&top.annotation_opts) < 0) goto out_delete_evlist; =20 - if (!top.evlist->core.nr_entries && - evlist__add_default(top.evlist) < 0) { - pr_err("Not enough memory for event selector list\n"); - goto out_delete_evlist; + if (!top.evlist->core.nr_entries) { + bool can_profile_kernel =3D perf_event_paranoid_check(1); + int err =3D parse_event(top.evlist, can_profile_kernel ? "cycles:P" : "c= ycles:Pu"); + + if (err) + goto out_delete_evlist; } =20 status =3D evswitch__init(&top.evswitch, top.evlist, stderr); diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index 0f59c80f27b2..64f78d06fe19 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -16,31 +16,6 @@ #include #include =20 -int evlist__add_default_hybrid(struct evlist *evlist, bool precise) -{ - struct evsel *evsel; - struct perf_pmu *pmu; - __u64 config; - struct perf_cpu_map *cpus; - - perf_pmu__for_each_hybrid_pmu(pmu) { - config =3D PERF_COUNT_HW_CPU_CYCLES | - ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT); - evsel =3D evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - config); - if (!evsel) - return -ENOMEM; - - cpus =3D perf_cpu_map__get(pmu->cpus); - evsel->core.cpus =3D cpus; - evsel->core.own_cpus =3D perf_cpu_map__get(cpus); - evsel->pmu_name =3D strdup(pmu->name); - evlist__add(evlist, evsel); - } - - return 0; -} - bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index 4b000eda6626..0cded76eb344 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -7,7 +7,6 @@ #include "evlist.h" #include =20 -int evlist__add_default_hybrid(struct evlist *evlist, bool precise); bool evlist__has_hybrid(struct evlist *evlist); =20 #endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 5d0d99127a90..ae05761b3dc9 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -93,8 +93,15 @@ struct evlist *evlist__new(void) struct evlist *evlist__new_default(void) { struct evlist *evlist =3D evlist__new(); + bool can_profile_kernel; + int err; + + if (!evlist) + return NULL; =20 - if (evlist && evlist__add_default(evlist)) { + can_profile_kernel =3D perf_event_paranoid_check(1); + err =3D parse_event(evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu"= ); + if (err) { evlist__delete(evlist); evlist =3D NULL; } @@ -237,19 +244,6 @@ static void evlist__set_leader(struct evlist *evlist) perf_evlist__set_leader(&evlist->core); } =20 -int __evlist__add_default(struct evlist *evlist, bool precise) -{ - struct evsel *evsel; - - evsel =3D evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - PERF_COUNT_HW_CPU_CYCLES); - if (evsel =3D=3D NULL) - return -ENOMEM; - - evlist__add(evlist, evsel); - return 0; -} - static struct evsel *evlist__dummy_event(struct evlist *evlist) { struct perf_event_attr attr =3D { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 5e7ff44f3043..664c6bf7b3e0 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -100,13 +100,6 @@ void evlist__delete(struct evlist *evlist); void evlist__add(struct evlist *evlist, struct evsel *entry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); =20 -int __evlist__add_default(struct evlist *evlist, bool precise); - -static inline int evlist__add_default(struct evlist *evlist) -{ - return __evlist__add_default(evlist, true); -} - int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs= , size_t nr_attrs); =20 int __evlist__add_default_attrs(struct evlist *evlist, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2f5910b31fa9..b39615124672 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -316,48 +316,6 @@ struct evsel *evsel__new_idx(struct perf_event_attr *a= ttr, int idx) return evsel; } =20 -static bool perf_event_can_profile_kernel(void) -{ - return perf_event_paranoid_check(1); -} - -struct evsel *evsel__new_cycles(bool precise __maybe_unused, __u32 type, _= _u64 config) -{ - struct perf_event_attr attr =3D { - .type =3D type, - .config =3D config, - .exclude_kernel =3D !perf_event_can_profile_kernel(), - }; - struct evsel *evsel; - - event_attr_init(&attr); - - /* - * Now let the usual logic to set up the perf_event_attr defaults - * to kick in when we return and before perf_evsel__open() is called. - */ - evsel =3D evsel__new(&attr); - if (evsel =3D=3D NULL) - goto out; - - arch_evsel__fixup_new_cycles(&evsel->core.attr); - - evsel->precise_max =3D true; - - /* use asprintf() because free(evsel) assumes name is allocated */ - if (asprintf(&evsel->name, "cycles%s%s%.*s", - (attr.precise_ip || attr.exclude_kernel) ? ":" : "", - attr.exclude_kernel ? "u" : "", - attr.precise_ip ? attr.precise_ip + 1 : 0, "ppp") < 0) - goto error_free; -out: - return evsel; -error_free: - evsel__delete(evsel); - evsel =3D NULL; - goto out; -} - int copy_config_terms(struct list_head *dst, struct list_head *src) { struct evsel_config_term *pos, *tmp; @@ -1130,10 +1088,6 @@ void __weak arch_evsel__set_sample_weight(struct evs= el *evsel) evsel__set_sample_bit(evsel, WEIGHT); } =20 -void __weak arch_evsel__fixup_new_cycles(struct perf_event_attr *attr __ma= ybe_unused) -{ -} - void __weak arch__post_evsel_config(struct evsel *evsel __maybe_unused, struct perf_event_attr *attr __maybe_unused) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index df8928745fc6..429b172cc94d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -243,8 +243,6 @@ static inline struct evsel *evsel__newtp(const char *sy= s, const char *name) } #endif =20 -struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config); - #ifdef HAVE_LIBTRACEEVENT struct tep_event *event_format__new(const char *sys, const char *name); #endif @@ -312,7 +310,6 @@ void __evsel__reset_sample_bit(struct evsel *evsel, enu= m perf_event_sample_forma void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); =20 void arch_evsel__set_sample_weight(struct evsel *evsel); -void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr); void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *= attr); =20 int evsel__set_filter(struct evsel *evsel, const char *filter); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 E4898C77B73 for ; Mon, 22 May 2023 06:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbjEVGoD (ORCPT ); Mon, 22 May 2023 02:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbjEVGnu (ORCPT ); Mon, 22 May 2023 02:43:50 -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 7B12CFA for ; Sun, 21 May 2023 23:43:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561e68fe434so69893317b3.1 for ; Sun, 21 May 2023 23:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737823; x=1687329823; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=kNgNWBNSvhI2LdRPQMDKfimHjU6ZbLIi1N3gayQ3XwM=; b=fLfeMNWhWGjBnz8I2kF02sEXnlbyKMewm4HvVki+LT09eA/ZO6QerDU4WcLWmJx5/5 8pafXQAyqHA10+IbZAI11bcyGeUriZtsy7bfEFkSrB62lDrOvPPAUMeG6kEapKrEdRcc Op3chXdMIOONy9MvG6ESbDbhZuZvAI1f8NRWD8iqNV19qDkKHwjxCP8QyBsp3Ijq8/Qk yX+nxttzJ/Bdag/Dw+le8WAEs7d1xGeHFgejRD19trWwgIGfApdiZZLN9+8YqJGHSJjv gC4zwEiz55pG+XeRq5NSTFZT27tYXO8IwfVNpGPmHnxdKzS3lkLXK8WWoLsOyLySL5qe mxqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737823; x=1687329823; 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=kNgNWBNSvhI2LdRPQMDKfimHjU6ZbLIi1N3gayQ3XwM=; b=GZ/DgMX16LC2bw8lz+m7Qim/A6CxByzzyfUPLmQkpYAyBBqieaCh4FbhpRJnV7ZKxF meQA0301aK87UMFhaJW52DZDJYP/Wiz242Hyt9COy+JjzbTKOve9fhFPLgl0bCU2Ohnv 0JS9sJHlu1ajBizi85HVuzgSdWxJI2UiUBvVGUKrNg1Av/W0s8gUL/8y7ripA66v2XT9 aiSCuzfYA5MlMxkM0esBeYlZroKUp8PqcMQGjDWXAj9p8FO3QStpnhDhM5l23fQIsqB6 A7vrpVXmURt/r69o8kZOQZssOTWlLf3nJ8e4/w9SpNBtJsBAqUu8HWQX91EXYceFJeCU es0w== X-Gm-Message-State: AC+VfDy+9fDokTU+wqyuSo4UjDd4Uov3bMNgxx1uzTBLnKuMpBY/Vga3 UCW0psRyZR9e6/pENRtYhsVvwZAr1JK4 X-Google-Smtp-Source: ACHHUZ65ZxYkd4VjzV2wILE/JAKZwhUl0VdjsxL84Uua3GHluPKtGiZsSXQcDjfNUuh5Hu0e7v6ymNYhu3rX X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a05:690c:2e85:b0:55a:6bb1:c91 with SMTP id eu5-20020a05690c2e8500b0055a6bb10c91mr5596191ywb.3.1684737823768; Sun, 21 May 2023 23:43:43 -0700 (PDT) Date: Sun, 21 May 2023 23:43:11 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-5-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 04/23] perf evlist: Reduce scope of evlist__has_hybrid From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Function is only used in printout, reduce scope to stat-display.c. Remove the now empty evlist-hybrid.c and evlist-hybrid.h. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 1 - tools/perf/builtin-stat.c | 1 - tools/perf/util/Build | 1 - tools/perf/util/evlist-hybrid.c | 31 ------------------------------- tools/perf/util/evlist-hybrid.h | 12 ------------ tools/perf/util/evlist.c | 1 - tools/perf/util/stat-display.c | 15 ++++++++++++++- 7 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 tools/perf/util/evlist-hybrid.c delete mode 100644 tools/perf/util/evlist-hybrid.h diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index a107a7adbcf4..ed7915af7871 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -50,7 +50,6 @@ #include "util/pfm.h" #include "util/clockid.h" #include "util/pmu-hybrid.h" -#include "util/evlist-hybrid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" #include "asm/bug.h" diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 084cc570b8e8..bd51da5fd3a5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -48,7 +48,6 @@ #include "util/pmu.h" #include "util/event.h" #include "util/evlist.h" -#include "util/evlist-hybrid.h" #include "util/evsel.h" #include "util/debug.h" #include "util/color.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index c146736ead19..21e4cdcba504 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -11,7 +11,6 @@ perf-y +=3D db-export.o perf-y +=3D env.o perf-y +=3D event.o perf-y +=3D evlist.o -perf-y +=3D evlist-hybrid.o perf-y +=3D sideband_evlist.o perf-y +=3D evsel.o perf-y +=3D evsel_fprintf.o diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c deleted file mode 100644 index 64f78d06fe19..000000000000 --- a/tools/perf/util/evlist-hybrid.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include -#include -#include "cpumap.h" -#include "evlist.h" -#include "evsel.h" -#include "../perf.h" -#include "util/pmu-hybrid.h" -#include "util/evlist-hybrid.h" -#include "debug.h" -#include -#include -#include -#include -#include -#include -#include - -bool evlist__has_hybrid(struct evlist *evlist) -{ - struct evsel *evsel; - - evlist__for_each_entry(evlist, evsel) { - if (evsel->pmu_name && - perf_pmu__is_hybrid(evsel->pmu_name)) { - return true; - } - } - - return false; -} diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h deleted file mode 100644 index 0cded76eb344..000000000000 --- a/tools/perf/util/evlist-hybrid.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __PERF_EVLIST_HYBRID_H -#define __PERF_EVLIST_HYBRID_H - -#include -#include -#include "evlist.h" -#include - -bool evlist__has_hybrid(struct evlist *evlist); - -#endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ae05761b3dc9..f301484ea9a6 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -28,7 +28,6 @@ #include "util/string2.h" #include "util/perf_api_probe.h" #include "util/evsel_fprintf.h" -#include "util/evlist-hybrid.h" #include "util/pmu.h" #include "util/sample.h" #include "util/bpf-filter.h" diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bf5a6c14dfcd..ede0477d958a 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -20,7 +20,6 @@ #include "util.h" #include "iostat.h" #include "pmu-hybrid.h" -#include "evlist-hybrid.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -677,6 +676,20 @@ static bool is_mixed_hw_group(struct evsel *counter) return false; } =20 +static bool evlist__has_hybrid(struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) { + if (evsel->pmu_name && + perf_pmu__is_hybrid(evsel->pmu_name)) { + return true; + } + } + + return false; +} + static void printout(struct perf_stat_config *config, struct outstate *os, double uval, u64 run, u64 ena, double noise, int aggr_idx) { --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 9A266C77B75 for ; Mon, 22 May 2023 06:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbjEVGoI (ORCPT ); Mon, 22 May 2023 02:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231840AbjEVGn7 (ORCPT ); Mon, 22 May 2023 02:43:59 -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 04D0F11F for ; Sun, 21 May 2023 23:43:46 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561bad0999aso118631197b3.0 for ; Sun, 21 May 2023 23:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737826; x=1687329826; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=W9DfnOdikH3r4sRR6uJadc40/tDQZnaZykRd3SidUOQ=; b=sUKOe06VYXgAPoC1kZ/JEBk/KIIt721wKDO93SGwBGmKHnaCdkpmlozbwRVnlX0R8b Rb7HgyaRky/f/t+T1it4H6IlXkK1GNI5oGt87azl9raXYYnEO9LMGMpzGUqwstsrvsDx 5hBZlq2intPxVAJydVaH1Ew9AGmTKl5Rj6kHaBY0dnvU0jjw80XNvZno4ynVH3cvfzJU rTlr3tqmw2i6STR8e+E8HLPh0ClDs1VE3BaY6sy5VAwaow1zxKjqROuPeMR3r1nnewxy teGV9QUc8GOLkA1BdGY0pkNcxBK4oKDxA81y69XlDs9G2gr6vutPOzFElwMgDeYByEda Od+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737826; x=1687329826; 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=W9DfnOdikH3r4sRR6uJadc40/tDQZnaZykRd3SidUOQ=; b=KJpbCaZbo+FPDiUoeT7bhNB4y5ZpVLga2Xk2+lX5l5SmeWPgJ46OhPDCEX3ZGfwxR6 5kf4EEhFHOL7unjTjNCZhdOY7eTidJWYGSqsIDt3rCEhab6i7IiiTQiF+mKfEHQ7ULDV Fjb+y79uV7jWJD4Y6+oya2SgLyGeYeExu/oqSDDPPPgoMe2IDeM96xJHsl6sQlCImuKR s1DgXXJjQRfquIn+KmaAcxhkjrRIAfJa2/eRDGBiLZcDmK5zoc+nHqjM8zZ6fWLVv00z cOIEn46qrl59o9s3ulrRLRdty+XK71CMhojxAIl/4nh1GeufzWOgljgCwIM0Fz1ZZq1E 507A== X-Gm-Message-State: AC+VfDyjjpY+edqQqLOmXQKwUEKRu0xfHD2jJxq9ySQ3aSENrxFc82Q+ XcELDEd1X37K5REiI35g7N0t3WbbBXQ6 X-Google-Smtp-Source: ACHHUZ6+xS2/tDwhj1rz0cMHvCJLdtFZKj2zO6vJyF411b9Xn5wGCSlFO55glJa/Rk5M0VXX/CTkfQdDwpHj X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a81:8d10:0:b0:54f:bb71:c7b3 with SMTP id d16-20020a818d10000000b0054fbb71c7b3mr6008927ywg.9.1684737826149; Sun, 21 May 2023 23:43:46 -0700 (PDT) Date: Sun, 21 May 2023 23:43:12 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-6-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 05/23] perf pmu: Remove perf_pmu__hybrid_mounted From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" perf_pmu__hybrid_mounted is used to detect whether cpu_core or cpu_atom is mounted with a non-empty cpus file by pmu_lookup. pmu_lookup will attempt to read the cpus file too and so the check can be folded into this. Checking hybrid_mounted in pmu_is_uncore is redundant as the next cpumask read will fail returning false. Reduce the scope of perf_pmu__find_hybrid_pmu by making it static. Signed-off-by: Ian Rogers --- tools/perf/util/pmu-hybrid.c | 15 +-------------- tools/perf/util/pmu-hybrid.h | 3 --- tools/perf/util/pmu.c | 26 ++++++++++++++------------ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c index bc4cb0738c35..7fe943dd3217 100644 --- a/tools/perf/util/pmu-hybrid.c +++ b/tools/perf/util/pmu-hybrid.c @@ -18,20 +18,7 @@ =20 LIST_HEAD(perf_pmu__hybrid_pmus); =20 -bool perf_pmu__hybrid_mounted(const char *name) -{ - int cpu; - char pmu_name[PATH_MAX]; - struct perf_pmu pmu =3D {.name =3D pmu_name}; - - if (strncmp(name, "cpu_", 4)) - return false; - - strlcpy(pmu_name, name, sizeof(pmu_name)); - return perf_pmu__scan_file(&pmu, "cpus", "%u", &cpu) > 0; -} - -struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) +static struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) { struct perf_pmu *pmu; =20 diff --git a/tools/perf/util/pmu-hybrid.h b/tools/perf/util/pmu-hybrid.h index 206b94931531..8dbcae935020 100644 --- a/tools/perf/util/pmu-hybrid.h +++ b/tools/perf/util/pmu-hybrid.h @@ -13,9 +13,6 @@ extern struct list_head perf_pmu__hybrid_pmus; #define perf_pmu__for_each_hybrid_pmu(pmu) \ list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) =20 -bool perf_pmu__hybrid_mounted(const char *name); - -struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); bool perf_pmu__is_hybrid(const char *name); =20 static inline int perf_pmu__hybrid_pmu_num(void) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 1e0be23d4dd7..729b1f166f80 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -617,9 +617,6 @@ static bool pmu_is_uncore(int dirfd, const char *name) { int fd; =20 - if (perf_pmu__hybrid_mounted(name)) - return false; - fd =3D perf_pmu__pathname_fd(dirfd, name, "cpumask", O_PATH); if (fd < 0) return false; @@ -898,6 +895,16 @@ static int pmu_max_precise(int dirfd, struct perf_pmu = *pmu) return max_precise; } =20 +/** + * perf_pmu__skip_empty_cpus() - should pmu_lookup skip the named PMU if t= he + * cpus or cpumask file isn't present? + * @name: Name of PMU. + */ +static bool perf_pmu__skip_empty_cpus(const char *name) +{ + return !strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom"); +} + static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) { struct perf_pmu *pmu; @@ -905,15 +912,8 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) LIST_HEAD(aliases); __u32 type; char *name =3D pmu_find_real_name(lookup_name); - bool is_hybrid =3D perf_pmu__hybrid_mounted(name); char *alias_name; =20 - /* - * Check pmu name for hybrid and the pmu may be invalid in sysfs - */ - if (!strncmp(name, "cpu_", 4) && !is_hybrid) - return NULL; - /* * The pmu data we store & need consists of the pmu * type value and format definitions. Load both right @@ -933,8 +933,10 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) return NULL; =20 pmu->cpus =3D pmu_cpumask(dirfd, name); - pmu->name =3D strdup(name); + if (!pmu->cpus && perf_pmu__skip_empty_cpus(name)) + goto err; =20 + pmu->name =3D strdup(name); if (!pmu->name) goto err; =20 @@ -964,7 +966,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); =20 - if (is_hybrid) + if (!strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom")) list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus); else INIT_LIST_HEAD(&pmu->hybrid_list); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 89088C77B73 for ; Mon, 22 May 2023 06:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232006AbjEVGoW (ORCPT ); Mon, 22 May 2023 02:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231879AbjEVGoC (ORCPT ); Mon, 22 May 2023 02:44:02 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C03718C for ; Sun, 21 May 2023 23:43:49 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8337a5861so7054936276.0 for ; Sun, 21 May 2023 23:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737828; x=1687329828; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=HtRUH772YtV0qPeVzoZd+sfJkmumkzDNUnRMC3UQCcg=; b=NNBwSTFIiyCdqGqw2b4i1yq/47LRh1xsrfmZCRo5cZzQEbwSVLZ8pKnE+LfMB0Sv+i K9kzhfBKgcoOUFOTBvVHqvFFLphQylLkC/nFisqyST+/nJXcd8cwaBGE6BgBre+NgYAP WKt/wMtN9hu9fZzdFy/eNrxJVtdBJtabp/zCjiO7E+PCNJF99AkqENLV/v0zcgMAM7QT 4QZfT7Ly7tvupd9MQeK3tVfiSL6GpEJ/YT3Kmx422mU5BI2N5hxtFUvkJVBX+D7vKg9G zBBBVfrfJ4+Wj7flOcPQ3wHBqx2lSGgBPaHrBCo3TETeDdZczX21WOmwgmqPA8WVCZtc xXXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737828; x=1687329828; 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=HtRUH772YtV0qPeVzoZd+sfJkmumkzDNUnRMC3UQCcg=; b=Vn0MIW6RZrbSZHvwTZ6qxRt3FqZRAuTqGBjp3uAsJyHEaNSIuLk5BCpemKoZRlaWYM QoJ6aK+KhGYWjH1qYLC4p6n4CGG7NYF8DJ4L8DuxJo0zHBqPNpJFSiL4/Q5/0ToCZfnk txUGJfO4oXk+uyhnYm8rjqMXHF2mhECj3NB+IKTNMruVmZdppFeW1s1F+wO1/sMpmHET XjTJwNMiWkixpafKyKLZqNdeyz47r68eMQguhC2wNxetpg5xWPnTdJcrmPDvVRpp5vKT F+jP50mS3DvRfnfxSUVkM7APrsXm6zAtVqIuHxisFXuZP1uwEkYJ+MZB0Te41hNPLZVC hKhA== X-Gm-Message-State: AC+VfDy/Q6RbEpzTg29UgoK+Sah6wWPp6JmKLGMYnjY5PzUnKTKte4kb k0L9zTUMGT9hVcHizd5li2cxAkk9T/Z9 X-Google-Smtp-Source: ACHHUZ5cD6+QLwi88ybhahjD/VfP3IQA+LiC4RmuZCcr7iQO6gQPZoJVP/dq9tXyYF3U2Q6o1YAKOVomcwIR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a5b:98b:0:b0:ba7:8628:93e2 with SMTP id c11-20020a5b098b000000b00ba7862893e2mr5636237ybq.4.1684737828309; Sun, 21 May 2023 23:43:48 -0700 (PDT) Date: Sun, 21 May 2023 23:43:13 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-7-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 06/23] perf pmu: Detect ARM and hybrid PMUs with sysfs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" is_arm_pmu_core detects a core PMU via the presence of a "cpus" file rather than a "cpumask" file. This pattern holds for hybrid PMUs so rename the function and remove redundant perf_pmu__is_hybrid tests. Add a new helper is_pmu_hybrid similar to is_pmu_core. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 29 ++++++++++++++++++----------- tools/perf/util/pmu.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 729b1f166f80..0fa451c60c77 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -640,12 +640,14 @@ static char *pmu_id(const char *name) return str; } =20 -/* - * PMU CORE devices have different name other than cpu in sysfs on some - * platforms. - * Looking for possible sysfs files to identify the arm core device. +/** + * is_sysfs_pmu_core() - PMU CORE devices have different name other than c= pu in + * sysfs on some platforms like ARM or Intel hybrid. Looking for + * possible the cpus file in sysfs files to identify whether this = is a + * core device. + * @name: The PMU name such as "cpu_atom". */ -static int is_arm_pmu_core(const char *name) +static int is_sysfs_pmu_core(const char *name) { char path[PATH_MAX]; =20 @@ -811,7 +813,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, = struct perf_pmu *pmu, struct pmu_add_cpu_aliases_map_data data =3D { .head =3D head, .name =3D pmu->name, - .cpu_name =3D is_arm_pmu_core(pmu->name) ? pmu->name : "cpu", + .cpu_name =3D is_sysfs_pmu_core(pmu->name) ? pmu->name : "cpu", .pmu =3D pmu, }; =20 @@ -1649,22 +1651,27 @@ static int cmp_sevent(const void *a, const void *b) =20 bool is_pmu_core(const char *name) { - return !strcmp(name, "cpu") || is_arm_pmu_core(name); + return !strcmp(name, "cpu") || is_sysfs_pmu_core(name); +} + +bool is_pmu_hybrid(const char *name) +{ + return !strcmp(name, "cpu_atom") || !strcmp(name, "cpu_core"); } =20 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + return is_pmu_core(pmu->name); } =20 bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + return is_pmu_core(pmu->name); } =20 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { - return !perf_pmu__is_hybrid(pmu->name); + return !is_pmu_hybrid(pmu->name); } =20 static bool pmu_alias_is_duplicate(struct sevent *alias_a, @@ -1718,7 +1725,7 @@ void print_pmu_events(const struct print_callbacks *p= rint_cb, void *print_state) pmu =3D NULL; j =3D 0; while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + bool is_cpu =3D is_pmu_core(pmu->name); =20 list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event =3D event; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 49033bb134f3..99e0273027bf 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -220,6 +220,7 @@ void perf_pmu__del_formats(struct list_head *formats); struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); =20 bool is_pmu_core(const char *name); +bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 879EFC77B75 for ; Mon, 22 May 2023 06:44:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232035AbjEVGo3 (ORCPT ); Mon, 22 May 2023 02:44:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbjEVGoD (ORCPT ); Mon, 22 May 2023 02:44:03 -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 E4DA61A4 for ; Sun, 21 May 2023 23:43:51 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba81b24b8a4so6825995276.2 for ; Sun, 21 May 2023 23:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737831; x=1687329831; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=BuxkA8aKV6AKQDyTxhZEBY1QXMea1aO9KvWEXYFaDV0=; b=Wny7cS+8agscH7kiozGeG/23zdqV5hRMOkq3A76rYH7Gjbw+CuOVfq2iXuHsu80E5T YRmQ5Ona7FHZ1dy38IzXa5Ub8HbHqjf0+cD4vzsZtUP7ARHh9ObtC3nlrqguhQ/FQnV8 +mrTO0UrA54cA6dRwbCCFiXgr7vFm8p+nzvcQLzSPD8Cfwhz5yhZQPCL9F4rxlrGjqOz pAcaKtIyc3laswVYRolExGhwKtFcq3KeB74OtdfCgwVbpLLE9L6s7EfeAu8+X1AhGyg+ PleeLkMwUQPddCrjR6XMGLmVKePX+zENoGBSjIa9K1G04TJKGfblzqceYty0PmYtIy4W j09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737831; x=1687329831; 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=BuxkA8aKV6AKQDyTxhZEBY1QXMea1aO9KvWEXYFaDV0=; b=LaPzoS5qxkGSIrO9+mfmOAdpbeeJVAy0AGYKtfWXqlmpZSW3H8UNe7lokCGW2DVEC4 ZRhCW0VNcWRc36QZBZ2WDXPVQ6ib/3DZy0p+/B3Ge+o+O7PcM86Zf7z4NXwj+ZzRdSAB TP4d8QqEbosnww7XOLL5aBdJbJ8OXvD7mKKoq81EmEoNp+z+upq1NnWpm3Ko3/doZYbb xTnVl97x3Y+Bia/pwLFxBYWpdlEKuVMhkNL7fa8R3T+G17/PjDTx8HKKlZWnpq99s/zm DP81QB/moDUCrsEDPzaZJCtUK8mY+quO7eL+k6ISyINqENkhfksW1oKhw5VfakwTZr5w lTkg== X-Gm-Message-State: AC+VfDyz4afLc7HspzuSilml8qpBkYl1ZPaR7Lys1X4roGQKntsWvugt Pb/AkvT0nJpf0ghkZDgNwrWJsXoklC2m X-Google-Smtp-Source: ACHHUZ7yBhemL5Zfp+6Mb1mVUpfqt5JkMqFSlUv27bdZVJmzGQnH4k6PtMTPKLmkxP6cJJfNK5hvrNYe0npN X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a05:6902:283:b0:ba8:4c16:78b7 with SMTP id v3-20020a056902028300b00ba84c1678b7mr5956768ybh.12.1684737830760; Sun, 21 May 2023 23:43:50 -0700 (PDT) Date: Sun, 21 May 2023 23:43:14 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-8-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 07/23] perf pmu: Add is_core to pmu From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Cache is_pmu_core in the pmu to avoid recomputation. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 7 ++++--- tools/perf/util/pmu.h | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0fa451c60c77..930ec3786964 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -954,6 +954,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) } =20 pmu->type =3D type; + pmu->is_core =3D is_pmu_core(name); pmu->is_uncore =3D pmu_is_uncore(dirfd, name); if (pmu->is_uncore) pmu->id =3D pmu_id(name); @@ -1661,12 +1662,12 @@ bool is_pmu_hybrid(const char *name) =20 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } =20 bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } =20 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) @@ -1725,7 +1726,7 @@ void print_pmu_events(const struct print_callbacks *p= rint_cb, void *print_state) pmu =3D NULL; j =3D 0; while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D is_pmu_core(pmu->name); + bool is_cpu =3D pmu->is_core; =20 list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event =3D event; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 99e0273027bf..af10d137e2b5 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -59,6 +59,13 @@ struct perf_pmu { * @selectable: Can the PMU name be selected as if it were an event? */ bool selectable; + /** + * @is_core: Is the PMU the core CPU PMU? Determined by the name being + * "cpu" or by the presence of + * /bus/event_source/devices//cpus. There may be >1 core + * PMU on systems like Intel hybrid. + */ + bool is_core; /** * @is_uncore: Is the PMU not within the CPU core? Determined by the * presence of /bus/event_source/devices//cpumask. --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 D5276C77B73 for ; Mon, 22 May 2023 06:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbjEVGoi (ORCPT ); Mon, 22 May 2023 02:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231975AbjEVGoF (ORCPT ); Mon, 22 May 2023 02:44:05 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B489E40 for ; Sun, 21 May 2023 23:43:54 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1ae8ed1c293so11475385ad.3 for ; Sun, 21 May 2023 23:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737833; x=1687329833; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wY12k1F5dOPmIa0ikykHN2ccarTwqFRAmkOKXrH13wU=; b=2VubbBxC7SiuoDKB/MAjz1AyE91qcGOI3gAFX+O+h98PNa+/AOLmXiTcQNj35qdvGi 5sdEkIn7TR+FtSzi81M8ZbsqvKi4CK5TEtis1ZZ7l2pW10E3a9EDpGXp/gPOSn4kCmBS PRvYHeDkjO192X2t2le0lojDNk20x1MmMrAaQ4zIGqDLfxc/g7aPiSxfSvdY1iLOkUY+ nM3AcHDW1A2p05Cr8SlrDS4wY1FlPOkpgooicnN+08ft1d7bSQINpa/R7aPer6HqWEYE 6P5pgis7h9FnEBg5GEKw13ti0LIPVc65TT4U7Mje+kUGLdIbksls4/rsWFsB8actKpFL nHtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737833; x=1687329833; 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=wY12k1F5dOPmIa0ikykHN2ccarTwqFRAmkOKXrH13wU=; b=EFNFngq84SXiAXD8mOQZOdAVxiTzZvipJ1DLlBIfUrgN/TCmvnaE1VLCgiXz7YMXB2 sgU7dtYRpGaHCEbitjVR2WZVTyx4GWuIdHQhgANDBwk/JUrMyBgAGg6U16ymYUBnviiP 4IimJFtk3yxjGsAdM1kjKYtKIkY8LLE+WKrIHZUOXfLjXzxw2PvNXiGA+bE4Y1D78d4Q uC5dIqJshVG1xRtAnvUNmnIoLLv3q+g5YLM0RV5ZWz/yjh6j5K5CTmeHyYxtD1KrtRHg bAf54vkfUi7afn0H+v8pGEv4pEqoVSl8lE4G7ZDAVIMmo6/jAyXmwE42O6J5dDiacOoq 12/Q== X-Gm-Message-State: AC+VfDwh1dGYwRvx2/aYcK6KgMko06mGGkDgR0V2QYV6IlcEcApPXg5s 51WAp8Ni0UsxHatbeDYDPReigkaRpcyI X-Google-Smtp-Source: ACHHUZ7RTmbSeAZX0hhQh6vBvLsB75U+w1V7MkmWtfmbzfrbFZyAQderN0XWHUlGDMNmQUiYGrKTJOUDDuEz X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a17:903:710:b0:1ac:921c:87f6 with SMTP id kk16-20020a170903071000b001ac921c87f6mr2268283plb.8.1684737833230; Sun, 21 May 2023 23:43:53 -0700 (PDT) Date: Sun, 21 May 2023 23:43:15 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-9-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 08/23] perf pmu: Rewrite perf_pmu__has_hybrid to avoid list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Rather than list empty on perf_pmu__hybrid_pmus, detect if any core PMUs match the hybrid name. Computed values held in statics to avoid recomputation. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 930ec3786964..2da28739e0d3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -60,8 +60,6 @@ struct perf_pmu_format { struct list_head list; }; =20 -static bool hybrid_scanned; - static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); =20 /* @@ -2026,12 +2024,20 @@ void perf_pmu__warn_invalid_config(struct perf_pmu = *pmu, __u64 config, =20 bool perf_pmu__has_hybrid(void) { + static bool hybrid_scanned, has_hybrid; + if (!hybrid_scanned) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid =3D true; + break; + } + } hybrid_scanned =3D true; - perf_pmu__scan(NULL); } - - return !list_empty(&perf_pmu__hybrid_pmus); + return has_hybrid; } =20 int perf_pmu__match(char *pattern, char *name, char *tok) --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 15FDBC77B73 for ; Mon, 22 May 2023 06:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbjEVGow (ORCPT ); Mon, 22 May 2023 02:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbjEVGoP (ORCPT ); Mon, 22 May 2023 02:44:15 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A092BE53 for ; Sun, 21 May 2023 23:43:56 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8337a578dso7610806276.1 for ; Sun, 21 May 2023 23:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737836; x=1687329836; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cjAbWq1xZ7aD31R1h5+Cy8ZSDZyyIBasEI10DVMtL4M=; b=E0nxZGShWtenEGxKFPR3VtzZCurGG1j7euF2OoC5z+45QG+ULtTsGSDi31e4Wt3NE7 dZ3pJuvbP3B4AtT/za6BIYrmnxc2a8mXYgd9Fg6oCrS3B/kIlL3ReM6uPG3jGfff7lPN sTXH7zoYfRwjM5z86Xeovmpuzwg2P/boqnyGDLaPHnZiOiDnAJ0Yxb59xZo3t4mcuyFf fz4b9OtojC2w5ZoUs/9Oo/1olDAM8WYvmJf3J45nU0H5KiCtRzNDaHE+ffRjnFC1AX3W YJsc39e+mG2JDSRZUNhLyLY6/rsZQP1ZNC0oiHMCS88I7+iehhT6hiPDrYtpTRttSPLP Svlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737836; x=1687329836; 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=cjAbWq1xZ7aD31R1h5+Cy8ZSDZyyIBasEI10DVMtL4M=; b=K/euqoFWG8HIZY2Uvei4N+PGcIBLJZ6uuHZOizDdVEJHmdTStUirPnR3CbFVvFmMzE 7LDfXtTuxe27aJDHhYuReZ6VFvX8/qoV+6PlyxH/QhQXnCQqYvGUBWWQpxGKeVYs0+Sq 2QlDq2SwyMWSL0OONLZgkqmWQisg5hkNIie0uvhhenZND+ckrcv4Do178cZ8mNNtcptu G1cGBnrS/ZuLalLTATX+vQXTQ5W92Zcw2XxMpbNJ6RJD612Qz76+HVlLfuN+9VpRxwMj KPuhQOFlsYbObjBhFIDb9K5vgCVO2AOjgAbAyRQI2mjjfgkwQSnHFml1Y7S/MiUAteN1 NA1Q== X-Gm-Message-State: AC+VfDz3SZIMaJ7dhNcoayER8pxEEybKvTn/y+c6v9vczuofECCWdQKD OcFGRSLFUxTzPsiYD1XFbIHy7gkS+poh X-Google-Smtp-Source: ACHHUZ7UYLUCv03X5Bt6HUtR5w7vwMGWg5NGikYWsYaP3pPvUgsRYY/eLv+3oFgeC8ULmAK/RXYhwieFfyc6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:949:0:b0:ba1:6f1b:8905 with SMTP id u9-20020a250949000000b00ba16f1b8905mr5870686ybm.4.1684737835844; Sun, 21 May 2023 23:43:55 -0700 (PDT) Date: Sun, 21 May 2023 23:43:16 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-10-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 09/23] perf x86: Iterate hybrid PMUs as core PMUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Rather than iterating over a separate hybrid list, iterate all PMUs with the hybrid ones having is_core as true. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/tests/hybrid.c | 2 +- tools/perf/arch/x86/util/evlist.c | 25 +++++++++++++++++-------- tools/perf/arch/x86/util/perf_regs.c | 14 ++++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index 941a9edfed4e..944bd1b4bab6 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -3,7 +3,7 @@ #include "debug.h" #include "evlist.h" #include "evsel.h" -#include "pmu-hybrid.h" +#include "pmu.h" #include "tests/tests.h" =20 static bool test_config(const struct evsel *evsel, __u64 expected_config) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 1b6065841fb0..03f7eb4cf0a4 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -4,7 +4,6 @@ #include "util/evlist.h" #include "util/parse-events.h" #include "util/event.h" -#include "util/pmu-hybrid.h" #include "topdown.h" #include "evsel.h" =20 @@ -12,9 +11,6 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, struct perf_event_attr *attrs, size_t nr_attrs) { - struct perf_cpu_map *cpus; - struct evsel *evsel, *n; - struct perf_pmu *pmu; LIST_HEAD(head); size_t i =3D 0; =20 @@ -25,15 +21,24 @@ static int ___evlist__add_default_attrs(struct evlist *= evlist, return evlist__add_attrs(evlist, attrs, nr_attrs); =20 for (i =3D 0; i < nr_attrs; i++) { + struct perf_pmu *pmu =3D NULL; + if (attrs[i].type =3D=3D PERF_TYPE_SOFTWARE) { - evsel =3D evsel__new(attrs + i); + struct evsel *evsel =3D evsel__new(attrs + i); + if (evsel =3D=3D NULL) goto out_delete_partial_list; list_add_tail(&evsel->core.node, &head); continue; } =20 - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + struct perf_cpu_map *cpus; + struct evsel *evsel; + + if (!pmu->is_core) + continue; + evsel =3D evsel__new(attrs + i); if (evsel =3D=3D NULL) goto out_delete_partial_list; @@ -51,8 +56,12 @@ static int ___evlist__add_default_attrs(struct evlist *e= vlist, return 0; =20 out_delete_partial_list: - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); + { + struct evsel *evsel, *n; + + __evlist__for_each_entry_safe(&head, n, evsel) + evsel__delete(evsel); + } return -1; } =20 diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index 0ed177991ad0..26abc159fc0e 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -10,7 +10,6 @@ #include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/pmu.h" -#include "../../../util/pmu-hybrid.h" =20 const struct sample_reg sample_reg_masks[] =3D { SMPL_REG(AX, PERF_REG_X86_AX), @@ -286,7 +285,6 @@ uint64_t arch__intr_reg_mask(void) .disabled =3D 1, .exclude_kernel =3D 1, }; - struct perf_pmu *pmu; int fd; /* * In an unnamed union, init it here to build on older gcc versions @@ -294,12 +292,20 @@ uint64_t arch__intr_reg_mask(void) attr.sample_period =3D 1; =20 if (perf_pmu__has_hybrid()) { + struct perf_pmu *pmu =3D NULL; + __u64 type =3D PERF_TYPE_RAW; + /* * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - pmu =3D list_first_entry(&perf_pmu__hybrid_pmus, typeof(*pmu), hybrid_li= st); - attr.config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core) { + type =3D pmu->type; + break; + } + } + attr.config |=3D type << PERF_PMU_TYPE_SHIFT; } =20 event_attr_init(&attr); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 24B03C7EE2D for ; Mon, 22 May 2023 06:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbjEVGpW (ORCPT ); Mon, 22 May 2023 02:45:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbjEVGoX (ORCPT ); Mon, 22 May 2023 02:44:23 -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 69E6BE6E for ; Sun, 21 May 2023 23:43:59 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8c9e9e164so6502859276.2 for ; Sun, 21 May 2023 23:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737838; x=1687329838; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/eS5iHSDHpFh4XdVaHBCbrVny8PCbF73cyIUIzaUWEw=; b=CgHDDcC/bqqMU21nt7St6njPl7Rn53Y47s5fIwnhxiq0CxfpVDxjt0xXLXOSODasdE Tk92JdTJATwtUezQWA6Z3gAwX+/ec7MKOKi800MmW7EPwUD5McVn2WEkSU4FYIwhjsio bw2hdH9lbS+rBKpwWxSbj+5Q73Lr8QN+jiM9/Oe9R90fCdPuAH7vTos2YCQ3N+S79Eu0 BA+PakRJh0qnm3y+jvU9D/MpI1oRvkom0oF/O6tCx18sSb18tnGsaRyfw1RCfP4TVMxv JNQ8+aMDPkUf8byLtKJtCqK+oHpyDMG9NStLm93IyJNFOzz5AQdPIM4QueYCtzvzDvMS qzRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737838; x=1687329838; 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=/eS5iHSDHpFh4XdVaHBCbrVny8PCbF73cyIUIzaUWEw=; b=YcBElS8JHIul0l1ahDiW6iNSxMOrdCwLzH2ny8/WJhiPIp/IlRBZdrsLMLk9GhgxOY Ll+eHxM3AYU3xZs3zNLr44brm9iHk0bk0ianOhGaOzCveI81fM+DNy/+xNMBOSWtKaI7 L8uZJLqq5ye2XGWbJALTZkrZktIyRELOwjKGN/QuOcKrg0dsUAuFaSL/DMyhDFBQBVUl AkD7VByGT1C4/AsM+Xo0n5l5TMPM+f/I8PB/qDh2gnAayrYY2g4ut7aaLCAFW6A0Ous7 tw8pZtoGWuSbFx2JLgIeidsatWZGYknVIva5JN3UfjUzUnXD/11+xx51NwbKiGeG/JEW 0qug== X-Gm-Message-State: AC+VfDxNQuzfI+YUbG9sYYPweUKNmWdJdJIE0CJNuhO33BGnCdGy5PuI d3J+3s7851LoPUzXiP5gGpibDVTX9UU7 X-Google-Smtp-Source: ACHHUZ4CGsfKcHUrmkLQzmUyhJN0XIWwtaPsa/Q19mBM+K+hLEXsAmiFVhHxp8qWU/VEY2xhQQxccmo/4t6P X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:ac20:0:b0:ba8:91c0:3c50 with SMTP id w32-20020a25ac20000000b00ba891c03c50mr4043339ybi.7.1684737838276; Sun, 21 May 2023 23:43:58 -0700 (PDT) Date: Sun, 21 May 2023 23:43:17 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-11-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 10/23] perf topology: Avoid hybrid list for hybrid topology From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Avoid perf_pmu__for_each_hybrid_pmu in hybrid_topology__new by scanning all PMUs and processing the is_core ones. Add early exit for non-hybrid. Signed-off-by: Ian Rogers --- tools/perf/util/cputopo.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index ca1d833a0c26..a5c259bd5cc0 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -12,7 +12,7 @@ #include "cpumap.h" #include "debug.h" #include "env.h" -#include "pmu-hybrid.h" +#include "pmu.h" =20 #define PACKAGE_CPUS_FMT \ "%s/devices/system/cpu/cpu%d/topology/package_cpus_list" @@ -469,11 +469,17 @@ static int load_hybrid_node(struct hybrid_topology_no= de *node, =20 struct hybrid_topology *hybrid_topology__new(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; struct hybrid_topology *tp =3D NULL; - u32 nr, i =3D 0; + u32 nr =3D 0, i =3D 0; =20 - nr =3D perf_pmu__hybrid_pmu_num(); + if (!perf_pmu__has_hybrid()) + return NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core) + nr++; + } if (nr =3D=3D 0) return NULL; =20 @@ -482,7 +488,10 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; + if (load_hybrid_node(&tp->nodes[i], pmu)) { hybrid_topology__delete(tp); return NULL; --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 89141C77B73 for ; Mon, 22 May 2023 06:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbjEVGp0 (ORCPT ); Mon, 22 May 2023 02:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbjEVGo3 (ORCPT ); Mon, 22 May 2023 02:44:29 -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 9730D110 for ; Sun, 21 May 2023 23:44:01 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-560def4d06dso108025867b3.3 for ; Sun, 21 May 2023 23:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737841; x=1687329841; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=CIGkjMa1wc+2YqtFlHRehMAQM+xcg0ilJ/4qFtAGVUY=; b=giCC+5/4EUcXQRjSQC89cXvki8U/QoJ9QC39UFUvlE9YhMX8kXt+mGCgtOVL2fwtXj 9RRXs0XsNodd8TFub2bKATVyzVjUmQlK1P0rhHHp9wE9dfKGXVKfCAURZsNDk7WxcP2D h835LQNtW3Wd2tuIudgPGE8KyNR2JwIotugDRzykL7GBLizoZIaz68fYsOGB9C8T8DI+ jc0l/pmDf9LnEOzNcFcYNFZ/XzEU7ymU25rBjR5MV69SzbT7VmAi3dtlFxAhCZv60fcq gIoVZ/moxoftYgJuPbyGRDIm/09CXqJaVW7KiOsI4rnR824BsuEbwA4eCd0bOg17T/YW WTXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737841; x=1687329841; 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=CIGkjMa1wc+2YqtFlHRehMAQM+xcg0ilJ/4qFtAGVUY=; b=J1wzxtLJA8BHiVP6hbMYVBbJXXf6Prq4ChsssyIAwzZdzVegowIOcxL99oP6LQE2Lc A1VllNu57inodqfrQriDGmkvV1iaaRY/ZWkERRM0HPwuccFadF0Qpk1WcyxCY6+v5T0k 4tbK9uIfLz2qEtM9LneDu8TJiRtbjZFk4T6a/xObh2uf6pUm/M8rSUTnl6yUwyb0dwzJ AXYam4nE7RgWiBQqwycJze/ZGfPknX5zFg2FtxlGEcZtNY9vB8BTon+jkrv6/odLi3fN bd11A64iOU1T+jKr2wbtX3p8n6lpmFojw4gEOJ9mU8GrSbnFdGhnxXxp9Kv+cSHO/mKu gSng== X-Gm-Message-State: AC+VfDy0/JoIsIQDBZ8d+LtjSgFWJBjVnt7un8Gtcxm2XugUMvYF6Ok+ 489IuHJZE0DmlWVOcNtOxHZo9Km4mW68 X-Google-Smtp-Source: ACHHUZ4nAbzyYcfkbGak1Sz9NF7WumnGusg226YGZEcoPxxDT3NS3cnRH1HvigWM5JuF2sxAF410WFubqFPH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a81:b54f:0:b0:561:1d3b:af3f with SMTP id c15-20020a81b54f000000b005611d3baf3fmr6010864ywk.8.1684737840821; Sun, 21 May 2023 23:44:00 -0700 (PDT) Date: Sun, 21 May 2023 23:43:18 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-12-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 11/23] perf evsel: Compute is_hybrid from PMU being core From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Short-cut when has_hybrid is false, otherwise return if the evsel's PMU is core. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b39615124672..2c0ed7d25466 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -46,8 +46,8 @@ #include "memswap.h" #include "util.h" #include "util/hashmap.h" -#include "pmu-hybrid.h" #include "off_cpu.h" +#include "pmu.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" #include "util/bpf-filter.h" @@ -3133,7 +3133,13 @@ void evsel__zero_per_pkg(struct evsel *evsel) =20 bool evsel__is_hybrid(const struct evsel *evsel) { - return evsel->pmu_name && perf_pmu__is_hybrid(evsel->pmu_name); + struct perf_pmu *pmu; + + if (!perf_pmu__has_hybrid()) + return false; + + pmu =3D evsel__find_pmu(evsel); + return pmu->is_core; } =20 struct evsel *evsel__leader(const struct evsel *evsel) --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 922CBC77B75 for ; Mon, 22 May 2023 06:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbjEVGpb (ORCPT ); Mon, 22 May 2023 02:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbjEVGoc (ORCPT ); Mon, 22 May 2023 02:44:32 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5102E77 for ; Sun, 21 May 2023 23:44:03 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1ae4c498f0cso57154805ad.2 for ; Sun, 21 May 2023 23:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737843; x=1687329843; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2FXlJjlrAGttKZp5HRCBcxE0XLHUZdESbTdmHXPLxLA=; b=uQtwox96BxP135Bg+/OnbOh3t08WB231lF5dBoWs7XQck3bMUZTrhASU7PKQAgggKP jSpsuc5XfKDqSPJHqPONlBMeCiCuAYxyq9G13gocGHbCjwrVKS8GQeoPc2GKmmE8Tx1C NRfTkZIEXeREFqZkO4pPRJOEYBVsDEHzQ7odWrerf1XOVIWDvBKpEIqp8oa3ghLjEz7r AXgpmpnzyuu/aPMZidML9SMkQTKmt7mO0sJFG22Q3FSry6nzENTgDrmFt7B97wbsyw70 6sXgYPTuRLxVZlDUpldlsI8ciPex4R9nYB55AxN8N0WAGBn+9wScSF40AGy1FM5W+EXe FCNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737843; x=1687329843; 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=2FXlJjlrAGttKZp5HRCBcxE0XLHUZdESbTdmHXPLxLA=; b=Wl8Drtu3vEdvkoBzn6QAY/Lw13ISLYrmFR3VQiFkyskc3OG7qkWQIP8vYGlGM+8x9u NMvddM/BlA4CtUvyCx0JNbK65Aqv7ve86BpTDShqvNQVeXHcsJtq7wuroPl2xQgn4ong wv29VEjrTrqKy6zf8OWo2hpfsCQ7zLET1wfxly+DjbBajicgNgnm/HdL9oOnOYRm4RiG +8vlDJzyR6foJeyeDqfz53hEId+LC9dY80Qvj4UeC09/L/+sm9U5k35a8r0pNve7X7Qy 0F40dxwzWBKPo9fEo/NuRLUikzl2QH35+WlDhKCWW9zjs4HfsNEoYigkREyJBgBsStu8 hG0Q== X-Gm-Message-State: AC+VfDyNLTQE1UXGbmmArwX9HnfDvXnjsQTa9fmhlvId375nPhnhaVB9 J+dHbeh4wfr6ay7s3riOAUPkU0mQZlNL X-Google-Smtp-Source: ACHHUZ55HBbHoyydmqJrkbpfG3EYrND8RbS1855ZiyjfgI4tGdjEHQmraCmjxhBrJZkKd5Ar5y0srVkir//K X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a17:902:f152:b0:1a6:c58e:9b9e with SMTP id d18-20020a170902f15200b001a6c58e9b9emr2177250plb.7.1684737843278; Sun, 21 May 2023 23:44:03 -0700 (PDT) Date: Sun, 21 May 2023 23:43:19 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-13-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 12/23] perf header: Avoid hybrid PMU list in write_pmu_caps From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Avoid perf_pmu__for_each_hybrid_pmu by iterating all PMUs are dumping the core ones. This will eventually allow removal of the hybrid PMU list. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 276870221ce0..e24cc8f316cd 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -51,7 +51,6 @@ #include "bpf-event.h" #include "bpf-utils.h" #include "clockid.h" -#include "pmu-hybrid.h" =20 #include #include @@ -1589,17 +1588,21 @@ static int write_pmu_caps(struct feat_fd *ff, * Write hybrid pmu caps first to maintain compatibility with * older perf tool. */ - pmu =3D NULL; - perf_pmu__for_each_hybrid_pmu(pmu) { - ret =3D __write_pmu_caps(ff, pmu, true); - if (ret < 0) - return ret; + if (perf_pmu__has_hybrid()) { + pmu =3D NULL; + while ((pmu =3D perf_pmu__scan(pmu))) { + if (!pmu->is_core) + continue; + + ret =3D __write_pmu_caps(ff, pmu, true); + if (ret < 0) + return ret; + } } =20 pmu =3D NULL; while ((pmu =3D perf_pmu__scan(pmu))) { - if (!pmu->name || !strcmp(pmu->name, "cpu") || - !pmu->nr_caps || perf_pmu__is_hybrid(pmu->name)) + if (pmu->is_core || !pmu->nr_caps) continue; =20 ret =3D __write_pmu_caps(ff, pmu, true); --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 6244DC77B75 for ; Mon, 22 May 2023 06:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbjEVGp4 (ORCPT ); Mon, 22 May 2023 02:45:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjEVGpN (ORCPT ); Mon, 22 May 2023 02:45:13 -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 2519510F6 for ; Sun, 21 May 2023 23:44:21 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-559c416b024so65827437b3.1 for ; Sun, 21 May 2023 23:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737845; x=1687329845; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LP27CftfdHYnLweWt0lX22v4lNIGIpmQh1ljDLrV4jA=; b=MhqwCJBtPyT5b02ahng0nI7ganYJvCeSMOskyson56OnoKeJ481W1TYdZWj1JoQ95r wuDPYIkhk/NZwXe0CTxVQKbfv+gqsM0j26sRc+OeTdtmHigaxZV6fk/yseq3N0YnQHX9 0KnUlv9Zqv7SggUA1BhxajbxFcxpcDkcYZFIZq04EHtQcg185xnzwBc/fT7tb7tebere 9XsVoFpw5B5enV926TymTvp6irXOwGEGnbP/Kg9xFJlCyTIF+gVlxrZ8Am7aD97VN0BW Na+J7IgiziND4KB+K5rXmzS+kHNRU8d9qu5XJW/oHj2sBTxSLuqP4ed7kGE29lS3EXiw 3/pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737845; x=1687329845; 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=LP27CftfdHYnLweWt0lX22v4lNIGIpmQh1ljDLrV4jA=; b=O+bWy2s4aBEc7aQmVbZi/F3uAN7SBWHwGLPAvUBhvuW3g2lWEP30wDvLulj07nRSl8 ls3/tXw6OD4TT7SyFit2g5kF0smdVVHtx9V14rIoCyA2KiT+mAf+LgzcYrUH2QT5iHlk kBc140k3t4nrST5HeOie8VATWufL+7e/4e8qYUdyi/m8Hl1FcPWGT00cXlZQpM7er+aT yQXPasrJL369A/gCqkGRp2I0OniFGBTtjomndJ+gJMK1Pliu/Y1tioPgz8EiJcJTchcL Y9HpN296VW9lN4ukdOXUjTCPyuC1hXdkALMfHHKuhKoaMQoHxRMUgzrqKmBV2nwKMxs3 s46A== X-Gm-Message-State: AC+VfDz1eQJsC8P2aoPpxyjXK0bEjkTfoAvYnPtvxyE9TSrirnPwQoOA 0WU4vFHNFkFhHZrjZaBqTWZGjE9hhmrC X-Google-Smtp-Source: ACHHUZ6D6GJ/kDIQ4pJeBPj2fMGgwl7DniHm6drdApF9GQl/cS7AHqn9R8+z1PDzPpRbQhZDI9VADrzkzCRy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a5b:e85:0:b0:ba8:97f8:620f with SMTP id z5-20020a5b0e85000000b00ba897f8620fmr5949030ybr.8.1684737845479; Sun, 21 May 2023 23:44:05 -0700 (PDT) Date: Sun, 21 May 2023 23:43:20 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-14-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 13/23] perf metrics: Remove perf_pmu__is_hybrid use From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Switch from perf_pmu__is_hybrid to avoid implicitly using the hybrid PMU list. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 7de721e9d895..72583f62eda8 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -11,7 +11,6 @@ #include "evsel.h" #include "strbuf.h" #include "pmu.h" -#include "pmu-hybrid.h" #include "print-events.h" #include "smt.h" #include "expr.h" @@ -274,7 +273,7 @@ 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_pmu__is_hybrid(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmu__has_hybrid() || !is_p= mu_hybrid(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); @@ -288,8 +287,7 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, struct expr_id_data *val_ptr; =20 /* Don't match events for the wrong hybrid PMU. */ - if (!all_pmus && ev->pmu_name && - perf_pmu__is_hybrid(ev->pmu_name) && + if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) && strcmp(ev->pmu_name, pmu)) continue; /* --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 1A95CC77B75 for ; Mon, 22 May 2023 06:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231986AbjEVGqV (ORCPT ); Mon, 22 May 2023 02:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232037AbjEVGpk (ORCPT ); Mon, 22 May 2023 02:45:40 -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 0E10A1B5 for ; Sun, 21 May 2023 23:44:33 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561a80d872dso97041677b3.3 for ; Sun, 21 May 2023 23:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737847; x=1687329847; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=nTVXYQjQQATmf8Mkt9G679/N0B13fTOwc5aaHfZePg0=; b=iiAigpdsXnQfOAaO/v/Fv96nlaEAFhaaiUurcRIqIJTdcXk4yZT84UKPYZtT8gnXAl rrcTqe20TVqxTno06d806fmEBBSujg/yLqe6D5QSiSJzOa3tLfqxS8LxbCeNL5R2HOG2 wP6M1Wb+0Yn0RrqnaHR1pvTYu4IWwIPuNBv/cMJilRLa7ju2TZAhD55yGnze+5INTpae huN1BhxYAcSrWnNTtXfdgLgNpfhGE0CZRhepAgkRlqWsUZ71tKCmJPcCEriyj97T6wcH QivLA0P58eOG42Re93b11WLQpl0JnX/4wAuQsaX1WvpK5OF0lpCB9UlGfCAkYBLJGbl4 ngVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737847; x=1687329847; 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=nTVXYQjQQATmf8Mkt9G679/N0B13fTOwc5aaHfZePg0=; b=a1LVekeVUoX18XesMj7qrk/wo6wBip00OiS+JD0FiRu2WeS99Ak610vfGS9pWUPl3b wviOCrgjabs3XqKT3O0MKaAM76eOcJe4wP7KUOruAVKWpHJvj8gaOvUZGSPXnXVCoe3i Ui2GnSXPS3A2xCjK9IkySeS+t04g1AIRz4ClKZukHQMzM8KwAEf4WiZ7UnMGCAjZall1 o/WehhiJq42ZQP78synvKiFS1oYkKCif9GS15vBBeaiOUkTypoBzTnKqdU/RmSbUKWHr VY8y8WKH9qxe3d4StewJvRks9j46yaFMnWpVtKyb/ODl7Y1o8QynsChI2O5r+z2Bz4Pa XG4g== X-Gm-Message-State: AC+VfDzDW322GQVze4vbpjfWKPVF38jeZWFWljbRC8HIGyqNACmzWOf6 dBZJeuIN4jJLFDBSPo2rv16lhZdcR5Xj X-Google-Smtp-Source: ACHHUZ7Sf8g2b29rTvR7d1W+WDJ54MMM6khifbI9MGuLm1xPmEkEB6hz+aOq+v1LLmQ9r+uQjhqSIRv7LUwm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a81:a9c7:0:b0:564:c5fd:6d98 with SMTP id g190-20020a81a9c7000000b00564c5fd6d98mr3718059ywh.10.1684737847732; Sun, 21 May 2023 23:44:07 -0700 (PDT) Date: Sun, 21 May 2023 23:43:21 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-15-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 14/23] perf stat: Avoid hybrid PMU list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" perf_pmu__is_hybrid implicitly uses the hybrid PMU list. Instead return false if hybrid isn't present, if it is then see if any evsel's PMUs are core. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ede0477d958a..164715113b9e 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -19,7 +19,7 @@ #include #include "util.h" #include "iostat.h" -#include "pmu-hybrid.h" +#include "pmu.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,11 +680,14 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; =20 + if (!perf_pmu__has_hybrid()) + return false; + evlist__for_each_entry(evlist, evsel) { - if (evsel->pmu_name && - perf_pmu__is_hybrid(evsel->pmu_name)) { + struct perf_pmu *pmu =3D evsel__find_pmu(evsel); + + if (pmu->is_core) return true; - } } =20 return false; --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 49D34C7EE26 for ; Mon, 22 May 2023 06:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232042AbjEVGq0 (ORCPT ); Mon, 22 May 2023 02:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232040AbjEVGpo (ORCPT ); Mon, 22 May 2023 02:45:44 -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 2E431170E for ; Sun, 21 May 2023 23:44:34 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561d565cb0aso58364827b3.3 for ; Sun, 21 May 2023 23:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737850; x=1687329850; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7bz/V8CqypyvqmwmpjlJAAxdnavB5CnpXkgu/FKkIKY=; b=uesBH9Ocnhu4jadWrkTYQZpto91uzJhFm+3d9oizHbM42Dv8lls0N1N1KfI9KzcENG gcEbJZ6Ep3TH+yMkpcldqOX/zHHuhOdQJSd09w2kxW9EUU0pU4gss6trX/5FLQOavxWI 2lM4PzBiHfCSrhbXR3ioA5ZI+H/bYFggDOwhuQCBYIALjvireunuQ8cPum2zxTdtqiAh fdHMlsqPdbVOSuHjemUzQA1e8AL9JaIBV8rSyk/4rpOfD/Lbwvrm0vsD7UgOsMYJ+ubX GLabZY3OSi5+FXU6Y++zESmvYOCwHM6sAwWT9U9ocuGuq2nnEVdRA6AowBBmdJDxGrWb 0j0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737850; x=1687329850; 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=7bz/V8CqypyvqmwmpjlJAAxdnavB5CnpXkgu/FKkIKY=; b=lFZOwFZTG3286P3ToZYr7elcDMiDWIp9dEnMgp43UzxokILv4JlxbRS2KcgR8djumL Smla5RLHfRyATJDBidVq2jQKNp6y/anEcJUSeoJYCX+wPJMxCqJy/DXD4wRGWnSVELEP lvf9sYamqOQSq2oowHhZpL+eEVnK8rjHeXboaEwtIdKYwVCq1HGsbLMSULtgxg/4P5P/ DZzO9z5a/QZi9PwoK9w2GWI6/S3T5DItFj9TqSHrsenaOwBQwP8U8HVAPhxXCsEp8rL/ K2F945f0VWCRqUKU9mTLIzrgwj2nhpFj++wCC75KzHXgKFa9xJr5jZtehHMO4Ww0EHYh +YoQ== X-Gm-Message-State: AC+VfDxQ9O/jbZ4c77iXsbBCqIXuvdpfX+PREWBojhobs4PEIx+wRgTd ApWbgFzx5dCuiKBw0vB9IH0FLDlMq3Wt X-Google-Smtp-Source: ACHHUZ4SVZi+MKHmaTDCo88NiUIu3zK/VV3+iEM2W5uNlPU3Cj4mNZ52SG/SzMMZzerZ24tVdmQ4Yh62UWOx X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a81:4425:0:b0:561:985a:5b4c with SMTP id r37-20020a814425000000b00561985a5b4cmr6225657ywa.5.1684737850785; Sun, 21 May 2023 23:44:10 -0700 (PDT) Date: Sun, 21 May 2023 23:43:22 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-16-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 15/23] perf mem: Avoid hybrid PMU list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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 perf_pmu__num_mem_pmus that scans/counts the number of PMUs for mem events. Switch perf_pmu__for_each_hybrid_pmu to iterating all PMUs and only handling is_core ones. Signed-off-by: Ian Rogers --- tools/perf/builtin-c2c.c | 7 ++----- tools/perf/builtin-mem.c | 7 ++----- tools/perf/util/mem-events.c | 20 ++++++++++++++------ tools/perf/util/pmu.c | 17 +++++++++++++++++ tools/perf/util/pmu.h | 1 + 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 08455e26b606..2757ccc19c5e 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -42,7 +42,6 @@ #include "ui/ui.h" #include "ui/progress.h" #include "pmu.h" -#include "pmu-hybrid.h" #include "string2.h" #include "util/util.h" =20 @@ -3259,10 +3258,8 @@ static int perf_c2c__record(int argc, const char **a= rgv) argc =3D parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); =20 - if (!perf_pmu__has_hybrid()) - rec_argc =3D argc + 11; /* max number of arguments */ - else - rec_argc =3D argc + 11 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support = them. */ + rec_argc =3D argc + 11 * perf_pmu__num_mem_pmus(); =20 rec_argv =3D calloc(rec_argc + 1, sizeof(char *)); if (!rec_argv) diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 65465930ef8e..f4f1ff76d49d 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -18,7 +18,6 @@ #include "util/map.h" #include "util/symbol.h" #include "util/pmu.h" -#include "util/pmu-hybrid.h" #include "util/sample.h" #include "util/string2.h" #include "util/util.h" @@ -93,10 +92,8 @@ static int __cmd_record(int argc, const char **argv, str= uct perf_mem *mem) argc =3D parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); =20 - if (!perf_pmu__has_hybrid()) - rec_argc =3D argc + 9; /* max number of arguments */ - else - rec_argc =3D argc + 9 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support = them. */ + rec_argc =3D argc + 9 * perf_pmu__num_mem_pmus(); =20 if (mem->cpu_list) rec_argc +=3D 2; diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index ed1ee4b05356..c9e422a38258 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -13,7 +13,6 @@ #include "debug.h" #include "symbol.h" #include "pmu.h" -#include "pmu-hybrid.h" =20 unsigned int perf_mem_events__loads_ldlat =3D 30; =20 @@ -120,7 +119,6 @@ int perf_mem_events__init(void) =20 for (j =3D 0; j < PERF_MEM_EVENTS__MAX; j++) { struct perf_mem_event *e =3D perf_mem_events__ptr(j); - struct perf_pmu *pmu; char sysfs_name[100]; =20 /* @@ -135,7 +133,12 @@ int perf_mem_events__init(void) e->sysfs_name, "cpu"); e->supported =3D perf_mem_event__supported(mnt, sysfs_name); } else { - perf_pmu__for_each_hybrid_pmu(pmu) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); @@ -170,9 +173,12 @@ static void perf_mem_events__print_unsupport_hybrid(st= ruct perf_mem_event *e, { const char *mnt =3D sysfs__mount(); char sysfs_name[100]; - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; =20 - perf_pmu__for_each_hybrid_pmu(pmu) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); if (!perf_mem_event__supported(mnt, sysfs_name)) { @@ -210,7 +216,9 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; rec_argv[i++] =3D "-e"; s =3D perf_mem_events__name(j, pmu->name); if (s) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 2da28739e0d3..acbf504c895a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1673,6 +1673,23 @@ bool perf_pmu__auto_merge_stats(const struct perf_pm= u *pmu) return !is_pmu_hybrid(pmu->name); } =20 +static bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) +{ + return pmu->is_core; +} + +int perf_pmu__num_mem_pmus(void) +{ + struct perf_pmu *pmu =3D NULL; + int count =3D 0; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (perf_pmu__is_mem_pmu(pmu)) + count++; + } + return count; +} + static bool pmu_alias_is_duplicate(struct sevent *alias_a, struct sevent *alias_b) { diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index af10d137e2b5..5f5de7c20ab6 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -231,6 +231,7 @@ bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); +int perf_pmu__num_mem_pmus(void); void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state); bool pmu_have_event(const char *pname, const char *name); =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 72D77C77B75 for ; Mon, 22 May 2023 06:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232048AbjEVGqf (ORCPT ); Mon, 22 May 2023 02:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbjEVGpp (ORCPT ); Mon, 22 May 2023 02:45:45 -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 EBB9A1713 for ; Sun, 21 May 2023 23:44:34 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba81b37d9d2so10504067276.3 for ; Sun, 21 May 2023 23:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737853; x=1687329853; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5Al8n0k/MOmhCKwKIt85nYWIEUmpLppr72awr1+CGgU=; b=NRSPMRCMMk4yCl9aATyLE1j4w6QMTrj7QYrgxgNA1AZspvYnM4uk+l8p+A1ULzuYB2 HqylL1p7j5YLFtQXWNlBuOutD312NCh6++Bj2d3p+9WxVsv27krAdNjcZufcLFuXEXps 3+vrJQx2orTZ34VVMM29lJgjLmc3Nm/NDYqLX7jD2bCXrlpgDtZiv0xltqKIXn99jTBj gwAJv3R61atvs+wnZqNw6Jg5r80lTa+v8JbYz4+twz5/I9M5hedFEXkQkXmgVsun0Ay5 h5qe+GYpNcqjOXaoEABzcl/WLHsjLUj2A0sJXMMEbpvN9dMt28vRzgfCchzMX4S95mum 0wYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737853; x=1687329853; 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=5Al8n0k/MOmhCKwKIt85nYWIEUmpLppr72awr1+CGgU=; b=GUuhMK97D2kNvQYJjn2Avsd/fGkRyFh9+cn0ma8A4KNHRpEg25k38sD2bDkRNyF0ZC U/gjhBWYLytgl4tKEWQL4IUpDglilZFX90AnaL7DH5nlj7YS6myiZHV9OaPUkZ2n4be+ Yak1BJDyHEDA0tMtYswgr44T63IvLPVi+NHhRq8lq3Yq5sQ5vZczuN0/pBrIwGJhRiFZ 4nAOuzktBuuNDwOCO+76znrWw470uPQpHKSrcYsuHZapjPNlutkOF57JJFGt/54L5nfL 6hvplsy0HpNn5sCMNFddDf+wGbm3gRdBYZbgFAgPg0G7PHER0h0Hv4H0+zJlPSFd7EXS 7ktw== X-Gm-Message-State: AC+VfDzYoc+Dc6qG1oN7EV3hygy7X6vqlbQL0eWc6xSsbGhKDaxI5qh1 YH6OvNNQ6hwaiK5hQ6XWxXyU4Crf2rqP X-Google-Smtp-Source: ACHHUZ4MopxFK8PkMA8bZw6C/M/45VQoWf5f7qTtr02GP4SbysvIfkITf+LZ6X0zk9St8CWzVHVaiI+Ssqjq X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:81cc:0:b0:ba8:6dc0:cacf with SMTP id n12-20020a2581cc000000b00ba86dc0cacfmr4107240ybm.12.1684737853151; Sun, 21 May 2023 23:44:13 -0700 (PDT) Date: Sun, 21 May 2023 23:43:23 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-17-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 16/23] perf pmu: Remove perf_pmu__hybrid_pmus list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Rather than iterate hybrid PMUs, inhererently Intel specific, iterate all PMUs checking whether they are core. To only get hybrid cores, first call perf_pmu__has_hybrid. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 1 - tools/perf/util/Build | 1 - tools/perf/util/pmu-hybrid.c | 39 ------------------------------ tools/perf/util/pmu-hybrid.h | 29 ---------------------- tools/perf/util/pmu.c | 7 ------ tools/perf/util/pmu.h | 2 -- tools/perf/util/print-events.c | 1 - tools/perf/util/python-ext-sources | 1 - 8 files changed, 81 deletions(-) delete mode 100644 tools/perf/util/pmu-hybrid.c delete mode 100644 tools/perf/util/pmu-hybrid.h diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ed7915af7871..aebe103fb734 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -49,7 +49,6 @@ #include "util/util.h" #include "util/pfm.h" #include "util/clockid.h" -#include "util/pmu-hybrid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" #include "asm/bug.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 21e4cdcba504..0d68be51a739 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -73,7 +73,6 @@ perf-y +=3D pmu.o perf-y +=3D pmus.o perf-y +=3D pmu-flex.o perf-y +=3D pmu-bison.o -perf-y +=3D pmu-hybrid.o perf-y +=3D svghelper.o perf-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o perf-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c deleted file mode 100644 index 7fe943dd3217..000000000000 --- a/tools/perf/util/pmu-hybrid.c +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fncache.h" -#include "pmu-hybrid.h" - -LIST_HEAD(perf_pmu__hybrid_pmus); - -static struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) -{ - struct perf_pmu *pmu; - - if (!name) - return NULL; - - perf_pmu__for_each_hybrid_pmu(pmu) { - if (!strcmp(name, pmu->name)) - return pmu; - } - - return NULL; -} - -bool perf_pmu__is_hybrid(const char *name) -{ - return perf_pmu__find_hybrid_pmu(name) !=3D NULL; -} diff --git a/tools/perf/util/pmu-hybrid.h b/tools/perf/util/pmu-hybrid.h deleted file mode 100644 index 8dbcae935020..000000000000 --- a/tools/perf/util/pmu-hybrid.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __PMU_HYBRID_H -#define __PMU_HYBRID_H - -#include -#include -#include -#include -#include "pmu.h" - -extern struct list_head perf_pmu__hybrid_pmus; - -#define perf_pmu__for_each_hybrid_pmu(pmu) \ - list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) - -bool perf_pmu__is_hybrid(const char *name); - -static inline int perf_pmu__hybrid_pmu_num(void) -{ - struct perf_pmu *pmu; - int num =3D 0; - - perf_pmu__for_each_hybrid_pmu(pmu) - num++; - - return num; -} - -#endif /* __PMU_HYBRID_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index acbf504c895a..bcf9d78a0003 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -32,7 +32,6 @@ #include "string2.h" #include "strbuf.h" #include "fncache.h" -#include "pmu-hybrid.h" #include "util/evsel_config.h" =20 struct perf_pmu perf_pmu__fake; @@ -967,11 +966,6 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); =20 - if (!strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom")) - list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus); - else - INIT_LIST_HEAD(&pmu->hybrid_list); - pmu->default_config =3D perf_pmu__get_default_config(pmu); =20 return pmu; @@ -2144,7 +2138,6 @@ void perf_pmu__destroy(void) =20 list_for_each_entry_safe(pmu, tmp, &pmus, list) { list_del(&pmu->list); - list_del(&pmu->hybrid_list); =20 perf_pmu__delete(pmu); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 5f5de7c20ab6..cb51ad6e40fa 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -119,8 +119,6 @@ struct perf_pmu { struct list_head caps; /** @list: Element on pmus list in pmu.c. */ struct list_head list; - /** @hybrid_list: Element on perf_pmu__hybrid_pmus. */ - struct list_head hybrid_list; =20 /** * @missing_features: Features to inhibit when events on this PMU are diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 69492cbd6921..8d823bc906e6 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -26,7 +26,6 @@ #include "strlist.h" #include "tracepoint.h" #include "pfm.h" -#include "pmu-hybrid.h" #include "thread_map.h" =20 #define MAX_NAME_LEN 100 diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ex= t-sources index aa5156c2bcff..d4c9b4cd35ef 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -39,5 +39,4 @@ util/affinity.c util/rwsem.c util/hashmap.c util/perf_regs.c -util/pmu-hybrid.c util/fncache.c --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 31713C77B73 for ; Mon, 22 May 2023 06:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232067AbjEVGqj (ORCPT ); Mon, 22 May 2023 02:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231996AbjEVGpq (ORCPT ); Mon, 22 May 2023 02:45:46 -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 D7BB9171C for ; Sun, 21 May 2023 23:44:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-564fb1018bcso16944437b3.0 for ; Sun, 21 May 2023 23:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737855; x=1687329855; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=OY46Jgo7JQurCKnzauPQ47/oSJ0vOgQW7/xCwH9klbZgxX7c4l/YjZaz+gZzKJVM8w namx7v10lMVDPsl4OTwDTfjU7GogSy8YqSPRFC/9k0RNLcjNZXzch0aqy9rVu1GAk7MN hoQqi/3EnfHnv0SBLPRB8Bstd32Lql577boPt/pOqaQAxwaCJHRjqnI3r/hsGjWVFLCW DwJm7JAfd09zT2DhG7ADqvjy2iUwFSpSO41/sPXW8WQvNvn6fpwxPfUwUumdfpadTifr pWHQgMHsmpOWYLPl1ijEGa7e4zg1GYpQlqbWfjQ8+0XEgYO+GMPNMUJy1e3yiyqdSKyd tGiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737855; x=1687329855; 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=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=CXAThucdpdzlHPLK9u9p7oHqMrp3kwYYv1nxIOHay61vxwPcmWnvudVS8qlOVAWXLF Nx3S7ew1CXuPCh4rX7KWy9pDHVYZQj+L15MFcDpO7VE69HhRSooWvV1kYO2v1be1xf0j lCwuJKIDXBfbwSZa7KMU28ua2KWgP2NjpkjjQAclvZsEWyetIVqsvRDXUfSvHck2tlZB VPVwmRNQPBxpzmWnM/CMse9bx2ZlXp2cZCSS3RhADgeiKjaNJm5kT6FJDdBXMi25T7HN b5yKlGWfCZCpKdDfvhjfKlbEkLQsUuFNgLWmKWRvr2AyAqre4l0Y46LfMMyFXa8FkqMz JPqQ== X-Gm-Message-State: AC+VfDw0x7SnJBYcz5gz334KQ9BmhfuCkG2mZY1ImsErkABbI7YWGcMz QHpZvTrcY78G0GS9x1r2jaKJA/kBvdK6 X-Google-Smtp-Source: ACHHUZ7X4vALKAJN8Hm4kK+hK6jc7G3nkp7UVAsNSWjonR+3UF14FYxQwQ/ABnx9rlRiM9YAPy7DUXkqHcCe X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a0d:ec10:0:b0:561:4cde:92cc with SMTP id q16-20020a0dec10000000b005614cde92ccmr6170274ywn.8.1684737855588; Sun, 21 May 2023 23:44:15 -0700 (PDT) Date: Sun, 21 May 2023 23:43:24 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-18-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 17/23] perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" perf_pmus__for_each_pmu doesn't lazily initialize pmus making its use error prone. Just use perf_pmu__scan as this only impacts non-performance critical tests. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/bench/pmu-scan.c | 6 ++---- tools/perf/tests/event_groups.c | 7 ++----- tools/perf/tests/parse-events.c | 11 ++++------- tools/perf/util/pmus.h | 2 -- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f0f007843bb8..f4a6c37cbe27 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -40,13 +40,11 @@ static struct pmu_scan_result *results; =20 static int save_result(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; struct list_head *list; struct pmu_scan_result *r; =20 - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { r =3D realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r =3D=3D NULL) return -ENOMEM; diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_group= s.c index 029442b4e9c6..3d9a2b524bba 100644 --- a/tools/perf/tests/event_groups.c +++ b/tools/perf/tests/event_groups.c @@ -50,13 +50,10 @@ static int event_open(int type, unsigned long config, i= nt group_fd) =20 static int setup_uncore_event(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int i, fd; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { for (i =3D 0; i < NR_UNCORE_PMUS; i++) { if (!strcmp(uncore_pmus[i].name, pmu->name)) { pr_debug("Using %s for uncore pmu event\n", pmu->name); diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 72a10bed84fd..277607ede060 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -108,11 +108,11 @@ static int test__checkevent_raw(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched =3D true; @@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __m= aybe_unused, int subtest __ma =20 static int test__pmu_events(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int ret =3D TEST_OK; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { struct stat st; char path[PATH_MAX]; struct dirent *ent; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index d475e2960c10..257de10788e8 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -5,8 +5,6 @@ extern struct list_head pmus; struct perf_pmu; =20 -#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list) - const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 #endif /* __PMUS_H */ --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 7CFABC77B73 for ; Mon, 22 May 2023 06:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbjEVGqo (ORCPT ); Mon, 22 May 2023 02:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232050AbjEVGpr (ORCPT ); Mon, 22 May 2023 02:45:47 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71E61723 for ; Sun, 21 May 2023 23:44:37 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb52dbb00so4182992276.1 for ; Sun, 21 May 2023 23:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737858; x=1687329858; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d/uSoOkKrLV2P01KOT7/05nAwNtg1NZmOZIVSrGqD1k=; b=Hsaqh04sZH/6Axr8ud/gVY1mROhs8Rgqfgn3Y6WJCmxYCSI7DaGYNAhEuMcZgVnSI4 IQR6K++KxTf6MIelXu6H8ZQLGME/L+HPhjveHZLKnPA191Tl+09GgrGKkqPWt8TmlvHo jeVR+5yWMZzereK4/fMT3bLb2G8m7w8726xoO/zepx/JtlKitnPX+61eYsxkuUrnRVU6 wSJN3wccgS72kCUEAtjLu4A8Oa23qTc8IiMin5sw1NImbyJAqwPLcuLN2veTrRx4MDwF l16tIVZoj/7USrIbJVfBWqY6dDVnkVbZgvW1X/t4ZlhijkBPzzOBVdpYx+gGvPGIzrZ2 j4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737858; x=1687329858; 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=d/uSoOkKrLV2P01KOT7/05nAwNtg1NZmOZIVSrGqD1k=; b=gwy3YRtQRpDRiiMoFdwgJCC/GzI6Wv511pd9Ud+BnG4Lw0rAf8rusl1HJDGxlOws9o 0YYZuu3KJg5VEyd4QeFsFCPiyYAJ/bSQXcofNBQxiZhcO9SIYwbs4bC9iG+g4eCCjQG3 rvFVamzxRKrfyMexLbNMVTTSTNfKo8oMWWtWI6DdpAPgekOH000D9czhBdiwqh42skws Z9kAAG05rEcOz8GLSRMJTfqNBi5CRFtUBCVsgeBydOHgRsWgykgblUUgIqgNF+m1O6i5 GIh9roNXdIBpH01LPEo+HelxIXamnz6J/d2Vbwln1oY2T6uiEqMWWBxIqov3E434Ipui i0Qw== X-Gm-Message-State: AC+VfDxRzuKrzCyzm4ELzoPE1m4/emLAjCHbxcNOekF8GCfQj8h/S/VO q0tSdwWA2Ompi6fwWJAg6kssS7LyRNvA X-Google-Smtp-Source: ACHHUZ4uNM8OVXJ/aKWdYng9uyMorPPzwcRVbMIZHNe3K1lLGLszwH0/SAAzHzeBkaQpq1TeMKuVgHtITpHE X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:689:0:b0:ba8:3401:a466 with SMTP id 131-20020a250689000000b00ba83401a466mr3789212ybg.6.1684737858138; Sun, 21 May 2023 23:44:18 -0700 (PDT) Date: Sun, 21 May 2023 23:43:25 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-19-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 18/23] perf x86 mem: minor refactor to is_mem_loads_aux_event From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Find the PMU and then the event off of it. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/mem-events.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/ut= il/mem-events.c index f683ac702247..02d65e446f46 100644 --- a/tools/perf/arch/x86/util/mem-events.c +++ b/tools/perf/arch/x86/util/mem-events.c @@ -55,13 +55,13 @@ struct perf_mem_event *perf_mem_events__ptr(int i) =20 bool is_mem_loads_aux_event(struct evsel *leader) { - if (perf_pmu__find("cpu")) { - if (!pmu_have_event("cpu", "mem-loads-aux")) - return false; - } else if (perf_pmu__find("cpu_core")) { - if (!pmu_have_event("cpu_core", "mem-loads-aux")) - return false; - } + struct perf_pmu *pmu =3D perf_pmu__find("cpu"); + + if (!pmu) + pmu =3D perf_pmu__find("cpu_core"); + + if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + return false; =20 return leader->core.attr.config =3D=3D MEM_LOADS_AUX; } --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 BFED0C77B73 for ; Mon, 22 May 2023 06:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232102AbjEVGqv (ORCPT ); Mon, 22 May 2023 02:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbjEVGpy (ORCPT ); Mon, 22 May 2023 02:45:54 -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 20F58E45 for ; Sun, 21 May 2023 23:44:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-564fb1018bcso16946387b3.0 for ; Sun, 21 May 2023 23:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737860; x=1687329860; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=q4PCog4fBphYXUBm7L+XDm7z09EEO/De5JMkpBWh6fI=; b=tursbSFx4QXBoknbInF7ZorO35aY9GflleKy9fa2yBzo1PlPIRTuuBJ/LCZR7FqTiB rYQmpAy3TlOyqJPr8zdk7A+AmepMmxJhY0a8+5gK5sJYKKtaxaBwei6WUkk555fTzy/j yZjJ5fYesCe8iIM50eKxfL97+E7rkt5m5tNTmcMn6JPb2Ej8sCpAGI/KXP8Fx5gtYu3l cIV59hyEimir3pyhrKqgPZIZP3cnKPk6yNU5tSQL9ksup9p0OIyQB+slaLqnN4ZU/1hg wLP+r3bYiRvdQdL4yAkA/B6kheTX9/tFZZWbFvi9gYyxhZsIsgI8jOAqskkjRrRBpflU tIRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737860; x=1687329860; 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=q4PCog4fBphYXUBm7L+XDm7z09EEO/De5JMkpBWh6fI=; b=J0WXGFkYXtCqi48N8EDZYd1y/HTX7npLnJr1W7z8uvI3OTnfTEhh8YJ4QWy22BKfHG xJ8flSx6zSWsVJDiMg5L14ZzScEngl+qbPfAmbsTA5t6YcqpIz9Ak6qckuO6ykiebXn0 DbzFcNrU/YCQJqP2pdnBme/P0yviqS1DLkUCLWrvfIxrZk6asQmAqU42G81lmwNRaJy+ 7nJGIMR1IcmMCmwl4e+KMEqeJEQT6iXZEsxGfOAd/u0+T3NfsokpYm4LwGOxflo8Fqpy a26KLdAufa1dpFWmu6SsHf3dgoXLP01N9RMurAAT6VQ5KIj50fe2ppbwAoFxIHlnj2+t DqNQ== X-Gm-Message-State: AC+VfDySwMYXjggcsfmNMDqLHZZIY79PmYBvVj8sQfXowAJwtL12CQzH ObqNtMLbHEAXhffAUGIGq+u8vQs35+dn X-Google-Smtp-Source: ACHHUZ4p89Yp37xQFWqNUiZu/EfRgpmL5pFffFmwhkxLjy4j8R1b+8VLqokmGa+hdJDNt3/n6//vic8xgppk X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a0d:ec10:0:b0:561:4cde:92cc with SMTP id q16-20020a0dec10000000b005614cde92ccmr6170366ywn.8.1684737860647; Sun, 21 May 2023 23:44:20 -0700 (PDT) Date: Sun, 21 May 2023 23:43:26 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-20-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 19/23] perf pmu: Separate pmu and pmus From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Separate and hide the pmus list in pmus.[ch]. Move pmus functionality out of pmu.[ch] into pmus.[ch] renaming pmus functions which were prefixed perf_pmu__ to perf_pmus__. Signed-off-by: Ian Rogers --- tools/perf/arch/arm/util/auxtrace.c | 7 +- tools/perf/arch/arm/util/cs-etm.c | 4 +- tools/perf/arch/arm64/util/pmu.c | 3 +- tools/perf/arch/x86/tests/hybrid.c | 5 +- tools/perf/arch/x86/util/auxtrace.c | 5 +- tools/perf/arch/x86/util/evlist.c | 5 +- tools/perf/arch/x86/util/evsel.c | 7 +- tools/perf/arch/x86/util/intel-bts.c | 4 +- tools/perf/arch/x86/util/intel-pt.c | 4 +- tools/perf/arch/x86/util/mem-events.c | 9 +- tools/perf/arch/x86/util/perf_regs.c | 5 +- tools/perf/arch/x86/util/topdown.c | 5 +- tools/perf/bench/pmu-scan.c | 10 +- tools/perf/builtin-c2c.c | 4 +- tools/perf/builtin-list.c | 4 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-record.c | 8 +- tools/perf/builtin-stat.c | 6 +- tools/perf/tests/attr.c | 4 +- tools/perf/tests/event_groups.c | 2 +- tools/perf/tests/parse-events.c | 8 +- tools/perf/tests/parse-metric.c | 4 +- tools/perf/tests/pmu-events.c | 3 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/tests/topology.c | 4 +- tools/perf/util/cputopo.c | 7 +- tools/perf/util/env.c | 5 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.c | 15 +- tools/perf/util/mem-events.c | 11 +- tools/perf/util/metricgroup.c | 5 +- tools/perf/util/parse-events.c | 15 +- tools/perf/util/parse-events.y | 3 +- tools/perf/util/pfm.c | 6 +- tools/perf/util/pmu.c | 411 +------------------------- tools/perf/util/pmu.h | 13 +- tools/perf/util/pmus.c | 397 ++++++++++++++++++++++++- tools/perf/util/pmus.h | 14 +- tools/perf/util/print-events.c | 5 +- tools/perf/util/stat-display.c | 3 +- 40 files changed, 534 insertions(+), 507 deletions(-) diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util= /auxtrace.c index adec6c9ee11d..3b8eca0ffb17 100644 --- a/tools/perf/arch/arm/util/auxtrace.c +++ b/tools/perf/arch/arm/util/auxtrace.c @@ -14,6 +14,7 @@ #include "../../../util/debug.h" #include "../../../util/evlist.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "cs-etm.h" #include "arm-spe.h" #include "hisi-ptt.h" @@ -40,7 +41,7 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_sp= es, int *err) return NULL; } =20 - arm_spe_pmus[*nr_spes] =3D perf_pmu__find(arm_spe_pmu_name); + arm_spe_pmus[*nr_spes] =3D perf_pmus__find(arm_spe_pmu_name); if (arm_spe_pmus[*nr_spes]) { pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n", __func__, __LINE__, *nr_spes, @@ -87,7 +88,7 @@ static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_p= tts, int *err) rewinddir(dir); while ((dent =3D readdir(dir))) { if (strstr(dent->d_name, HISI_PTT_PMU_NAME) && idx < *nr_ptts) { - hisi_ptt_pmus[idx] =3D perf_pmu__find(dent->d_name); + hisi_ptt_pmus[idx] =3D perf_pmus__find(dent->d_name); if (hisi_ptt_pmus[idx]) idx++; } @@ -131,7 +132,7 @@ struct auxtrace_record if (!evlist) return NULL; =20 - cs_etm_pmu =3D perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu =3D perf_pmus__find(CORESIGHT_ETM_PMU_NAME); arm_spe_pmus =3D find_all_arm_spe_pmus(&nr_spes, err); hisi_ptt_pmus =3D find_all_hisi_ptt_pmus(&nr_ptts, err); =20 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 9ca040bfb1aa..7c51fa182b51 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -25,7 +25,7 @@ #include "../../../util/evsel.h" #include "../../../util/perf_api_probe.h" #include "../../../util/evsel_config.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/cs-etm.h" #include // page_size #include "../../../util/session.h" @@ -881,7 +881,7 @@ struct auxtrace_record *cs_etm_record_init(int *err) struct perf_pmu *cs_etm_pmu; struct cs_etm_recording *ptr; =20 - cs_etm_pmu =3D perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu =3D perf_pmus__find(CORESIGHT_ETM_PMU_NAME); =20 if (!cs_etm_pmu) { *err =3D -EINVAL; diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index ef1ed645097c..2504d43a39a7 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -3,6 +3,7 @@ #include #include "../../../util/cpumap.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include #include =20 @@ -10,7 +11,7 @@ static struct perf_pmu *pmu__find_core_pmu(void) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!is_pmu_core(pmu->name)) continue; =20 diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index 944bd1b4bab6..e466735d68d5 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -4,6 +4,7 @@ #include "evlist.h" #include "evsel.h" #include "pmu.h" +#include "pmus.h" #include "tests/tests.h" =20 static bool test_config(const struct evsel *evsel, __u64 expected_config) @@ -113,7 +114,7 @@ static int test__hybrid_raw1(struct evlist *evlist) struct perf_evsel *evsel; =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu =3D perf_pmu__find_by_type(evsel->attr.type); + struct perf_pmu *pmu =3D perf_pmus__find_by_type(evsel->attr.type); =20 TEST_ASSERT_VAL("missing pmu", pmu); TEST_ASSERT_VAL("unexpected pmu", !strncmp(pmu->name, "cpu_", 4)); @@ -280,7 +281,7 @@ static int test_events(const struct evlist_test *events= , int cnt) =20 int test__hybrid(struct test_suite *test __maybe_unused, int subtest __may= be_unused) { - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return TEST_SKIP; =20 return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events)); diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util= /auxtrace.c index 330d03216b0e..354780ff1605 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -10,6 +10,7 @@ #include "../../../util/header.h" #include "../../../util/debug.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/auxtrace.h" #include "../../../util/intel-pt.h" #include "../../../util/intel-bts.h" @@ -25,8 +26,8 @@ struct auxtrace_record *auxtrace_record__init_intel(struc= t evlist *evlist, bool found_pt =3D false; bool found_bts =3D false; =20 - intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); - intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); + intel_pt_pmu =3D perf_pmus__find(INTEL_PT_PMU_NAME); + intel_bts_pmu =3D perf_pmus__find(INTEL_BTS_PMU_NAME); =20 evlist__for_each_entry(evlist, evsel) { if (intel_pt_pmu && evsel->core.attr.type =3D=3D intel_pt_pmu->type) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 03f7eb4cf0a4..03240c640c7f 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include "util/pmu.h" +#include "util/pmus.h" #include "util/evlist.h" #include "util/parse-events.h" #include "util/event.h" @@ -17,7 +18,7 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, for (i =3D 0; i < nr_attrs; i++) event_attr_init(attrs + i); =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return evlist__add_attrs(evlist, attrs, nr_attrs); =20 for (i =3D 0; i < nr_attrs; i++) { @@ -32,7 +33,7 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, continue; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; =20 diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 153cdca94cd4..25da46c8cca9 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -4,6 +4,7 @@ #include "util/evsel.h" #include "util/env.h" #include "util/pmu.h" +#include "util/pmus.h" #include "linux/string.h" #include "evsel.h" #include "util/debug.h" @@ -30,7 +31,7 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evse= l) * should be good enough to detect the perf metrics feature. */ if ((evsel->core.attr.type =3D=3D PERF_TYPE_RAW) && - pmu_have_event(pmu_name, "slots")) + perf_pmus__have_event(pmu_name, "slots")) return true; =20 return false; @@ -98,8 +99,8 @@ void arch__post_evsel_config(struct evsel *evsel, struct = perf_event_attr *attr) if (!evsel_pmu) return; =20 - ibs_fetch_pmu =3D perf_pmu__find("ibs_fetch"); - ibs_op_pmu =3D perf_pmu__find("ibs_op"); + ibs_fetch_pmu =3D perf_pmus__find("ibs_fetch"); + ibs_op_pmu =3D perf_pmus__find("ibs_op"); =20 if (ibs_fetch_pmu && ibs_fetch_pmu->type =3D=3D evsel_pmu->type) { if (attr->config & IBS_FETCH_L3MISSONLY) { diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/uti= l/intel-bts.c index 439c2956f3e7..d2c8cac11470 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -17,7 +17,7 @@ #include "../../../util/evlist.h" #include "../../../util/mmap.h" #include "../../../util/session.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/debug.h" #include "../../../util/record.h" #include "../../../util/tsc.h" @@ -416,7 +416,7 @@ static int intel_bts_find_snapshot(struct auxtrace_reco= rd *itr, int idx, =20 struct auxtrace_record *intel_bts_recording_init(int *err) { - struct perf_pmu *intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); + struct perf_pmu *intel_bts_pmu =3D perf_pmus__find(INTEL_BTS_PMU_NAME); struct intel_bts_recording *btsr; =20 if (!intel_bts_pmu) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index 17336da08b58..74b70fd379df 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -23,7 +23,7 @@ #include "../../../util/mmap.h" #include #include "../../../util/parse-events.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/debug.h" #include "../../../util/auxtrace.h" #include "../../../util/perf_api_probe.h" @@ -1185,7 +1185,7 @@ static u64 intel_pt_reference(struct auxtrace_record = *itr __maybe_unused) =20 struct auxtrace_record *intel_pt_recording_init(int *err) { - struct perf_pmu *intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); + struct perf_pmu *intel_pt_pmu =3D perf_pmus__find(INTEL_PT_PMU_NAME); struct intel_pt_recording *ptr; =20 if (!intel_pt_pmu) diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/ut= il/mem-events.c index 02d65e446f46..32879d12a8d5 100644 --- a/tools/perf/arch/x86/util/mem-events.c +++ b/tools/perf/arch/x86/util/mem-events.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "util/pmu.h" +#include "util/pmus.h" #include "util/env.h" #include "map_symbol.h" #include "mem-events.h" @@ -55,12 +56,12 @@ struct perf_mem_event *perf_mem_events__ptr(int i) =20 bool is_mem_loads_aux_event(struct evsel *leader) { - struct perf_pmu *pmu =3D perf_pmu__find("cpu"); + struct perf_pmu *pmu =3D perf_pmus__find("cpu"); =20 if (!pmu) - pmu =3D perf_pmu__find("cpu_core"); + pmu =3D perf_pmus__find("cpu_core"); =20 - if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + if (pmu && !perf_pmu__have_event(pmu, "mem-loads-aux")) return false; =20 return leader->core.attr.config =3D=3D MEM_LOADS_AUX; @@ -82,7 +83,7 @@ char *perf_mem_events__name(int i, char *pmu_name) pmu_name =3D (char *)"cpu"; } =20 - if (pmu_have_event(pmu_name, "mem-loads-aux")) { + if (perf_pmus__have_event(pmu_name, "mem-loads-aux")) { scnprintf(mem_loads_name, sizeof(mem_loads_name), MEM_LOADS_AUX_NAME, pmu_name, pmu_name, perf_mem_events__loads_ldlat); diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index 26abc159fc0e..befa7f3659b9 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -10,6 +10,7 @@ #include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" =20 const struct sample_reg sample_reg_masks[] =3D { SMPL_REG(AX, PERF_REG_X86_AX), @@ -291,7 +292,7 @@ uint64_t arch__intr_reg_mask(void) */ attr.sample_period =3D 1; =20 - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { struct perf_pmu *pmu =3D NULL; __u64 type =3D PERF_TYPE_RAW; =20 @@ -299,7 +300,7 @@ uint64_t arch__intr_reg_mask(void) * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->is_core) { type =3D pmu->type; break; diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index 9ad5e5c7bd27..3f9a267d4501 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -2,6 +2,7 @@ #include "api/fs/fs.h" #include "util/evsel.h" #include "util/pmu.h" +#include "util/pmus.h" #include "util/topdown.h" #include "topdown.h" #include "evsel.h" @@ -22,8 +23,8 @@ bool topdown_sys_has_perf_metrics(void) * The slots event is only available when the core PMU * supports the perf metrics feature. */ - pmu =3D perf_pmu__find_by_type(PERF_TYPE_RAW); - if (pmu && pmu_have_event(pmu->name, "slots")) + pmu =3D perf_pmus__find_by_type(PERF_TYPE_RAW); + if (pmu && perf_pmu__have_event(pmu, "slots")) has_perf_metrics =3D true; =20 cached =3D true; diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f4a6c37cbe27..51cae2d03353 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -44,7 +44,7 @@ static int save_result(void) struct list_head *list; struct pmu_scan_result *r; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { r =3D realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r =3D=3D NULL) return -ENOMEM; @@ -68,7 +68,7 @@ static int save_result(void) nr_pmus++; } =20 - perf_pmu__destroy(); + perf_pmus__destroy(); return 0; } =20 @@ -81,7 +81,7 @@ static int check_result(void) =20 for (int i =3D 0; i < nr_pmus; i++) { r =3D &results[i]; - pmu =3D perf_pmu__find(r->name); + pmu =3D perf_pmus__find(r->name); if (pmu =3D=3D NULL) { pr_err("Cannot find PMU %s\n", r->name); return -1; @@ -144,7 +144,7 @@ static int run_pmu_scan(void) =20 for (i =3D 0; i < iterations; i++) { gettimeofday(&start, NULL); - perf_pmu__scan(NULL); + perf_pmus__scan(NULL); gettimeofday(&end, NULL); =20 timersub(&end, &start, &diff); @@ -152,7 +152,7 @@ static int run_pmu_scan(void) update_stats(&stats, runtime_us); =20 ret =3D check_result(); - perf_pmu__destroy(); + perf_pmus__destroy(); if (ret < 0) break; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 2757ccc19c5e..05dfd98af170 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -41,7 +41,7 @@ #include "symbol.h" #include "ui/ui.h" #include "ui/progress.h" -#include "pmu.h" +#include "pmus.h" #include "string2.h" #include "util/util.h" =20 @@ -3259,7 +3259,7 @@ static int perf_c2c__record(int argc, const char **ar= gv) PARSE_OPT_KEEP_UNKNOWN); =20 /* Max number of arguments multiplied by number of PMUs that can support = them. */ - rec_argc =3D argc + 11 * perf_pmu__num_mem_pmus(); + rec_argc =3D argc + 11 * perf_pmus__num_mem_pmus(); =20 rec_argv =3D calloc(rec_argc + 1, sizeof(char *)); if (!rec_argv) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index c6bd0aa4a56e..6a2e74bdb1db 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -522,7 +522,7 @@ int cmd_list(int argc, const char **argv) strcmp(argv[i], "hwcache") =3D=3D 0) print_hwcache_events(&print_cb, ps); else if (strcmp(argv[i], "pmu") =3D=3D 0) - print_pmu_events(&print_cb, ps); + perf_pmus__print_pmu_events(&print_cb, ps); else if (strcmp(argv[i], "sdt") =3D=3D 0) print_sdt_events(&print_cb, ps); else if (strcmp(argv[i], "metric") =3D=3D 0 || strcmp(argv[i], "metrics"= ) =3D=3D 0) { @@ -562,7 +562,7 @@ int cmd_list(int argc, const char **argv) event_symbols_sw, PERF_COUNT_SW_MAX); print_tool_events(&print_cb, ps); print_hwcache_events(&print_cb, ps); - print_pmu_events(&print_cb, ps); + perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index f4f1ff76d49d..960bfd4b732a 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -17,7 +17,7 @@ #include "util/dso.h" #include "util/map.h" #include "util/symbol.h" -#include "util/pmu.h" +#include "util/pmus.h" #include "util/sample.h" #include "util/string2.h" #include "util/util.h" @@ -93,7 +93,7 @@ static int __cmd_record(int argc, const char **argv, stru= ct perf_mem *mem) PARSE_OPT_KEEP_UNKNOWN); =20 /* Max number of arguments multiplied by number of PMUs that can support = them. */ - rec_argc =3D argc + 9 * perf_pmu__num_mem_pmus(); + rec_argc =3D argc + 9 * perf_pmus__num_mem_pmus(); =20 if (mem->cpu_list) rec_argc +=3D 2; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aebe103fb734..e1f3525205bb 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -48,6 +48,8 @@ #include "util/bpf-event.h" #include "util/util.h" #include "util/pfm.h" +#include "util/pmu.h" +#include "util/pmus.h" #include "util/clockid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" @@ -1292,7 +1294,7 @@ static int record__open(struct record *rec) * of waiting or event synthesis. */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || - perf_pmu__has_hybrid()) { + perf_pmus__has_hybrid()) { pos =3D evlist__get_tracking_event(evlist); if (!evsel__is_dummy_event(pos)) { /* Set up dummy event. */ @@ -2191,7 +2193,7 @@ static void record__uniquify_name(struct record *rec) char *new_name; int ret; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return; =20 evlist__for_each_entry(evlist, pos) { @@ -4191,7 +4193,7 @@ int cmd_record(int argc, const char **argv) =20 evlist__warn_user_requested_cpus(rec->evlist, rec->opts.target.cpu_list); =20 - rec->opts.target.hybrid =3D perf_pmu__has_hybrid(); + rec->opts.target.hybrid =3D perf_pmus__has_hybrid(); =20 if (callchain_param.enabled && callchain_param.record_mode =3D=3D CALLCHA= IN_FP) arch__add_leaf_frame_record_opts(&rec->opts); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bd51da5fd3a5..4b315e04e079 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1882,11 +1882,11 @@ static int add_default_attributes(void) =20 if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0) return -1; - if (pmu_have_event("cpu", "stalled-cycles-frontend")) { + if (perf_pmus__have_event("cpu", "stalled-cycles-frontend")) { if (evlist__add_default_attrs(evsel_list, frontend_attrs) < 0) return -1; } - if (pmu_have_event("cpu", "stalled-cycles-backend")) { + if (perf_pmus__have_event("cpu", "stalled-cycles-backend")) { if (evlist__add_default_attrs(evsel_list, backend_attrs) < 0) return -1; } @@ -2460,7 +2460,7 @@ int cmd_stat(int argc, const char **argv) =20 evlist__warn_user_requested_cpus(evsel_list, target.cpu_list); =20 - target.hybrid =3D perf_pmu__has_hybrid(); + target.hybrid =3D perf_pmus__has_hybrid(); if (evlist__create_maps(evsel_list, &target) < 0) { if (target__has_task(&target)) { pr_err("Problems finding threads of monitor\n"); diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 56fba08a3037..674876e6c8e6 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -34,7 +34,7 @@ #include "event.h" #include "util.h" #include "tests.h" -#include "pmu.h" +#include "pmus.h" =20 #define ENV "PERF_TEST_ATTR" =20 @@ -185,7 +185,7 @@ static int test__attr(struct test_suite *test __maybe_u= nused, int subtest __mayb char path_dir[PATH_MAX]; char *exec_path; =20 - if (perf_pmu__has_hybrid()) + if (perf_pmus__has_hybrid()) return TEST_SKIP; =20 /* First try development tree tests. */ diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_group= s.c index 3d9a2b524bba..ccd9d8b2903f 100644 --- a/tools/perf/tests/event_groups.c +++ b/tools/perf/tests/event_groups.c @@ -53,7 +53,7 @@ static int setup_uncore_event(void) struct perf_pmu *pmu =3D NULL; int i, fd; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { for (i =3D 0; i < NR_UNCORE_PMUS; i++) { if (!strcmp(uncore_pmus[i].name, pmu->name)) { pr_debug("Using %s for uncore pmu event\n", pmu->name); diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 277607ede060..9d05bc551791 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -112,7 +112,7 @@ static int test__checkevent_raw(struct evlist *evlist) bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched =3D true; @@ -1443,12 +1443,12 @@ static int test__checkevent_config_cache(struct evl= ist *evlist) =20 static bool test__pmu_cpu_valid(void) { - return !!perf_pmu__find("cpu"); + return !!perf_pmus__find("cpu"); } =20 static bool test__intel_pt_valid(void) { - return !!perf_pmu__find("intel_pt"); + return !!perf_pmus__find("intel_pt"); } =20 static int test__intel_pt(struct evlist *evlist) @@ -2246,7 +2246,7 @@ static int test__pmu_events(struct test_suite *test _= _maybe_unused, int subtest struct perf_pmu *pmu =3D NULL; int ret =3D TEST_OK; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct stat st; char path[PATH_MAX]; struct dirent *ent; diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metri= c.c index c05148ea400c..1d6493a5a956 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -11,7 +11,7 @@ #include "debug.h" #include "expr.h" #include "stat.h" -#include "pmu.h" +#include "pmus.h" =20 struct value { const char *event; @@ -303,7 +303,7 @@ static int test__parse_metric(struct test_suite *test _= _maybe_unused, int subtes TEST_ASSERT_VAL("recursion fail failed", test_recursion_fail() =3D=3D 0); TEST_ASSERT_VAL("Memory bandwidth", test_memory_bandwidth() =3D=3D 0); =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() =3D= =3D 0); TEST_ASSERT_VAL("test metric group", test_metric_group() =3D=3D 0); } diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 734004f1a37d..64ecb7845af4 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -2,6 +2,7 @@ #include "math.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "tests.h" #include #include @@ -708,7 +709,7 @@ static int test__aliases(struct test_suite *test __mayb= e_unused, struct perf_pmu *pmu =3D NULL; unsigned long i; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { int count =3D 0; =20 if (!is_pmu_core(pmu->name)) diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index b3bd14b025a8..cff6ab87b2f6 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -20,7 +20,7 @@ #include "tests.h" #include "util/mmap.h" #include "util/sample.h" -#include "pmu.h" +#include "pmus.h" =20 static int spin_sleep(void) { @@ -375,7 +375,7 @@ static int test__switch_tracking(struct test_suite *tes= t __maybe_unused, int sub cpu_clocks_evsel =3D evlist__last(evlist); =20 /* Second event */ - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { cycles =3D "cpu_core/cycles/u"; err =3D parse_event(evlist, cycles); if (err) { diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index c4630cfc80ea..49e80d15420b 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -8,7 +8,7 @@ #include "session.h" #include "evlist.h" #include "debug.h" -#include "pmu.h" +#include "pmus.h" #include =20 #define TEMPL "/tmp/perf-test-XXXXXX" @@ -41,7 +41,7 @@ static int session_write_header(char *path) session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { session->evlist =3D evlist__new_default(); TEST_ASSERT_VAL("can't get evlist", session->evlist); } else { diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index a5c259bd5cc0..4578c26747e1 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -13,6 +13,7 @@ #include "debug.h" #include "env.h" #include "pmu.h" +#include "pmus.h" =20 #define PACKAGE_CPUS_FMT \ "%s/devices/system/cpu/cpu%d/topology/package_cpus_list" @@ -473,10 +474,10 @@ struct hybrid_topology *hybrid_topology__new(void) struct hybrid_topology *tp =3D NULL; u32 nr =3D 0, i =3D 0; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->is_core) nr++; } @@ -488,7 +489,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 4a4fdad820d6..9eabf3ec56e9 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -10,6 +10,7 @@ #include #include #include +#include "pmus.h" #include "strbuf.h" =20 struct perf_env perf_env; @@ -323,7 +324,7 @@ int perf_env__read_pmu_mappings(struct perf_env *env) u32 pmu_num =3D 0; struct strbuf sb; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; pmu_num++; @@ -337,7 +338,7 @@ int perf_env__read_pmu_mappings(struct perf_env *env) if (strbuf_init(&sb, 128 * pmu_num) < 0) return -ENOMEM; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2c0ed7d25466..42d6dfacf191 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -48,6 +48,7 @@ #include "util/hashmap.h" #include "off_cpu.h" #include "pmu.h" +#include "pmus.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" #include "util/bpf-filter.h" @@ -3135,7 +3136,7 @@ bool evsel__is_hybrid(const struct evsel *evsel) { struct perf_pmu *pmu; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; =20 pmu =3D evsel__find_pmu(evsel); diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e24cc8f316cd..fa3f7dbbd90e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -37,6 +37,7 @@ #include "debug.h" #include "cpumap.h" #include "pmu.h" +#include "pmus.h" #include "vdso.h" #include "strbuf.h" #include "build-id.h" @@ -744,7 +745,7 @@ static int write_pmu_mappings(struct feat_fd *ff, * Do a first pass to count number of pmu to avoid lseek so this * works in pipe mode as well. */ - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; pmu_num++; @@ -754,7 +755,7 @@ static int write_pmu_mappings(struct feat_fd *ff, if (ret < 0) return ret; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; =20 @@ -1550,7 +1551,7 @@ static int __write_pmu_caps(struct feat_fd *ff, struc= t perf_pmu *pmu, static int write_cpu_pmu_caps(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { - struct perf_pmu *cpu_pmu =3D perf_pmu__find("cpu"); + struct perf_pmu *cpu_pmu =3D perf_pmus__find("cpu"); int ret; =20 if (!cpu_pmu) @@ -1570,7 +1571,7 @@ static int write_pmu_caps(struct feat_fd *ff, int nr_pmu =3D 0; int ret; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name || !strcmp(pmu->name, "cpu") || perf_pmu__caps_parse(pmu) <=3D 0) continue; @@ -1588,9 +1589,9 @@ static int write_pmu_caps(struct feat_fd *ff, * Write hybrid pmu caps first to maintain compatibility with * older perf tool. */ - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->is_core) continue; =20 @@ -1601,7 +1602,7 @@ static int write_pmu_caps(struct feat_fd *ff, } =20 pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (pmu->is_core || !pmu->nr_caps) continue; =20 diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index c9e422a38258..08ac3ea2e366 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -13,6 +13,7 @@ #include "debug.h" #include "symbol.h" #include "pmu.h" +#include "pmus.h" =20 unsigned int perf_mem_events__loads_ldlat =3D 30; =20 @@ -128,14 +129,14 @@ int perf_mem_events__init(void) if (!e->tag) continue; =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, "cpu"); e->supported =3D perf_mem_event__supported(mnt, sysfs_name); } else { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 @@ -175,7 +176,7 @@ static void perf_mem_events__print_unsupport_hybrid(str= uct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 @@ -201,7 +202,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, if (!e->record) continue; =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { if (!e->supported) { pr_err("failed: event '%s' not supported\n", perf_mem_events__name(j, NULL)); @@ -216,7 +217,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; rec_argv[i++] =3D "-e"; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 72583f62eda8..27310eff49ab 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -11,6 +11,7 @@ #include "evsel.h" #include "strbuf.h" #include "pmu.h" +#include "pmus.h" #include "print-events.h" #include "smt.h" #include "expr.h" @@ -273,7 +274,7 @@ 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_pmu__has_hybrid() || !is_p= mu_hybrid(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmus__has_hybrid() || !is_= pmu_hybrid(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); @@ -488,7 +489,7 @@ static int metricgroup__sys_event_iter(const struct pmu= _metric *pm, if (!pm->metric_expr || !pm->compat) return 0; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { =20 if (!pmu->id || strcmp(pmu->id, pm->compat)) continue; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b93264f8a37c..984b230e14d4 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -21,6 +21,7 @@ #include "parse-events-bison.h" #include "parse-events-flex.h" #include "pmu.h" +#include "pmus.h" #include "asm/bug.h" #include "util/parse-branch-options.h" #include "util/evsel_config.h" @@ -451,7 +452,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, const char *config_name =3D get_config_name(head_config); const char *metric_id =3D get_config_metric_id(head_config); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; @@ -1192,7 +1193,7 @@ static int config_term_pmu(struct perf_event_attr *at= tr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE) { - const struct perf_pmu *pmu =3D perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu =3D perf_pmus__find_by_type(attr->type); =20 if (perf_pmu__supports_legacy_cache(pmu)) { attr->type =3D PERF_TYPE_HW_CACHE; @@ -1202,7 +1203,7 @@ static int config_term_pmu(struct perf_event_attr *at= tr, term->type_term =3D PARSE_EVENTS__TERM_TYPE_USER; } if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_HARDWARE) { - const struct perf_pmu *pmu =3D perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu =3D perf_pmus__find_by_type(attr->type); =20 if (!pmu) { pr_debug("Failed to find PMU for type %d", attr->type); @@ -1479,7 +1480,7 @@ int parse_events_add_numeric(struct parse_events_stat= e *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=3D*/NULL, type, config, head_config); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { int ret; =20 if (!perf_pmu__supports_wildcard_numeric(pmu)) @@ -1528,7 +1529,7 @@ int parse_events_add_pmu(struct parse_events_state *p= arse_state, struct parse_events_error *err =3D parse_state->error; LIST_HEAD(config_terms); =20 - pmu =3D parse_state->fake_pmu ?: perf_pmu__find(name); + pmu =3D parse_state->fake_pmu ?: perf_pmus__find(name); =20 if (verbose > 1 && !(pmu && pmu->selectable)) { fprintf(stderr, "Attempting to add event pmu '%s' with '", @@ -1673,7 +1674,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 INIT_LIST_HEAD(list); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct perf_pmu_alias *alias; bool auto_merge_stats; =20 @@ -2409,7 +2410,7 @@ static int set_filter(struct evsel *evsel, const void= *arg) return 0; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) if (pmu->type =3D=3D evsel->core.attr.type) { found =3D true; break; diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 4e1f5de35be8..abd6ab460e12 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -15,6 +15,7 @@ #include #include #include "pmu.h" +#include "pmus.h" #include "evsel.h" #include "parse-events.h" #include "parse-events-bison.h" @@ -316,7 +317,7 @@ PE_NAME opt_pmu_config if (asprintf(&pattern, "%s*", $1) < 0) CLEANUP_YYABORT; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { char *name =3D pmu->name; =20 if (parse_events__filter_pmu(parse_state, pmu)) diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index 6c11914c179f..076aecc22c16 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -10,7 +10,7 @@ #include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/pmu.h" +#include "util/pmus.h" #include "util/pfm.h" #include "util/strbuf.h" =20 @@ -49,7 +49,7 @@ int parse_libpfm_events_option(const struct option *opt, = const char *str, /* * force loading of the PMU list */ - perf_pmu__scan(NULL); + perf_pmus__scan(NULL); =20 for (q =3D p; strsep(&p, ",{}"); q =3D p) { sep =3D p ? str + (p - p_orig - 1) : ""; @@ -86,7 +86,7 @@ int parse_libpfm_events_option(const struct option *opt, = const char *str, goto error; } =20 - pmu =3D perf_pmu__find_by_type((unsigned int)attr.type); + pmu =3D perf_pmus__find_by_type((unsigned int)attr.type); evsel =3D parse_events__add_event(evlist->core.nr_entries, &attr, q, /*metric_id=3D*/NULL, pmu); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index bcf9d78a0003..3217a859c65b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -4,20 +4,15 @@ #include #include #include -#include #include -#include #include #include #include #include #include -#include #include #include #include -#include -#include #include #include #include "debug.h" @@ -59,8 +54,6 @@ struct perf_pmu_format { struct list_head list; }; =20 -static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); - /* * Parse & process all the sysfs attributes located under * the directory specified in 'dir' parameter. @@ -554,31 +547,6 @@ static int pmu_alias_terms(struct perf_pmu_alias *alia= s, return 0; } =20 -/* Add all pmus in sysfs to pmu list: */ -static void pmu_read_sysfs(void) -{ - int fd; - DIR *dir; - struct dirent *dent; - - fd =3D perf_pmu__event_source_devices_fd(); - if (fd < 0) - return; - - dir =3D fdopendir(fd); - if (!dir) - return; - - while ((dent =3D readdir(dir))) { - if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) - continue; - /* add to static LIST_HEAD(pmus): */ - perf_pmu__find2(fd, dent->d_name); - } - - closedir(dir); -} - /* * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/ar= m64) * may have a "cpus" file. @@ -904,7 +872,7 @@ static bool perf_pmu__skip_empty_cpus(const char *name) return !strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom"); } =20 -static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name) { struct perf_pmu *pmu; LIST_HEAD(format); @@ -964,7 +932,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) INIT_LIST_HEAD(&pmu->caps); list_splice(&format, &pmu->format); list_splice(&aliases, &pmu->aliases); - list_add_tail(&pmu->list, &pmus); + list_add_tail(&pmu->list, pmus); =20 pmu->default_config =3D perf_pmu__get_default_config(pmu); =20 @@ -992,61 +960,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *p= mu) } } =20 -static struct perf_pmu *pmu_find(const char *name) -{ - struct perf_pmu *pmu; - - list_for_each_entry(pmu, &pmus, list) { - if (!strcmp(pmu->name, name) || - (pmu->alias_name && !strcmp(pmu->alias_name, name))) - return pmu; - } - - return NULL; -} - -struct perf_pmu *perf_pmu__find_by_type(unsigned int type) -{ - struct perf_pmu *pmu; - - list_for_each_entry(pmu, &pmus, list) - if (pmu->type =3D=3D type) - return pmu; - - return NULL; -} - -struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu) -{ - /* - * pmu iterator: If pmu is NULL, we start at the begin, - * otherwise return the next pmu. Returns NULL on end. - */ - if (!pmu) { - pmu_read_sysfs(); - pmu =3D list_prepare_entry(pmu, &pmus, list); - } - list_for_each_entry_continue(pmu, &pmus, list) - return pmu; - return NULL; -} - -struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) -{ - struct perf_pmu *pmu =3D NULL; - - if (evsel->pmu) - return evsel->pmu; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (pmu->type =3D=3D evsel->core.attr.type) - break; - } - - ((struct evsel *)evsel)->pmu =3D pmu; - return pmu; -} - bool evsel__is_aux_event(const struct evsel *evsel) { struct perf_pmu *pmu =3D evsel__find_pmu(evsel); @@ -1083,43 +996,6 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu,= struct evsel *evsel, evsel->core.attr.config |=3D field_prep(bits, val); } =20 -struct perf_pmu *perf_pmu__find(const char *name) -{ - struct perf_pmu *pmu; - int dirfd; - - /* - * Once PMU is loaded it stays in the list, - * so we keep us from multiple reading/parsing - * the pmu format definitions. - */ - pmu =3D pmu_find(name); - if (pmu) - return pmu; - - dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D pmu_lookup(dirfd, name); - close(dirfd); - - return pmu; -} - -static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) -{ - struct perf_pmu *pmu; - - /* - * Once PMU is loaded it stays in the list, - * so we keep us from multiple reading/parsing - * the pmu format definitions. - */ - pmu =3D pmu_find(name); - if (pmu) - return pmu; - - return pmu_lookup(dirfd, name); -} - static struct perf_pmu_format * pmu_find_format(struct list_head *formats, const char *name) { @@ -1549,99 +1425,6 @@ void perf_pmu__del_formats(struct list_head *formats) } } =20 -static int sub_non_neg(int a, int b) -{ - if (b > a) - return 0; - return a - b; -} - -static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, - const struct perf_pmu_alias *alias) -{ - struct parse_events_term *term; - int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); - - list_for_each_entry(term, &alias->terms, list) { - if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) - used +=3D snprintf(buf + used, sub_non_neg(len, used), - ",%s=3D%s", term->config, - term->val.str); - } - - if (sub_non_neg(len, used) > 0) { - buf[used] =3D '/'; - used++; - } - if (sub_non_neg(len, used) > 0) { - buf[used] =3D '\0'; - used++; - } else - buf[len - 1] =3D '\0'; - - return buf; -} - -/** Struct for ordering events as output in perf list. */ -struct sevent { - /** PMU for event. */ - const struct perf_pmu *pmu; - /** - * Optional event for name, desc, etc. If not present then this is a - * selectable PMU and the event name is shown as "//". - */ - const struct perf_pmu_alias *event; - /** Is the PMU for the CPU? */ - bool is_cpu; -}; - -static int cmp_sevent(const void *a, const void *b) -{ - const struct sevent *as =3D a; - const struct sevent *bs =3D b; - const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; - const char *a_name =3D "//", *a_desc =3D NULL, *a_topic =3D ""; - const char *b_name =3D "//", *b_desc =3D NULL, *b_topic =3D ""; - int ret; - - if (as->event) { - a_name =3D as->event->name; - a_desc =3D as->event->desc; - a_topic =3D as->event->topic ?: ""; - a_pmu_name =3D as->event->pmu_name; - } - if (bs->event) { - b_name =3D bs->event->name; - b_desc =3D bs->event->desc; - b_topic =3D bs->event->topic ?: ""; - b_pmu_name =3D bs->event->pmu_name; - } - /* Put extra events last. */ - if (!!a_desc !=3D !!b_desc) - return !!a_desc - !!b_desc; - - /* Order by topics. */ - ret =3D strcmp(a_topic, b_topic); - if (ret) - return ret; - - /* Order CPU core events to be first */ - if (as->is_cpu !=3D bs->is_cpu) - return as->is_cpu ? -1 : 1; - - /* Order by PMU name. */ - if (as->pmu !=3D bs->pmu) { - a_pmu_name =3D a_pmu_name ?: (as->pmu->name ?: ""); - b_pmu_name =3D b_pmu_name ?: (bs->pmu->name ?: ""); - ret =3D strcmp(a_pmu_name, b_pmu_name); - if (ret) - return ret; - } - - /* Order by event name. */ - return strcmp(a_name, b_name); -} - bool is_pmu_core(const char *name) { return !strcmp(name, "cpu") || is_sysfs_pmu_core(name); @@ -1667,167 +1450,18 @@ bool perf_pmu__auto_merge_stats(const struct perf_= pmu *pmu) return !is_pmu_hybrid(pmu->name); } =20 -static bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) +bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) { return pmu->is_core; } =20 -int perf_pmu__num_mem_pmus(void) -{ - struct perf_pmu *pmu =3D NULL; - int count =3D 0; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (perf_pmu__is_mem_pmu(pmu)) - count++; - } - return count; -} - -static bool pmu_alias_is_duplicate(struct sevent *alias_a, - struct sevent *alias_b) -{ - const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; - const char *a_name =3D "//", *b_name =3D "//"; - - - if (alias_a->event) { - a_name =3D alias_a->event->name; - a_pmu_name =3D alias_a->event->pmu_name; - } - if (alias_b->event) { - b_name =3D alias_b->event->name; - b_pmu_name =3D alias_b->event->pmu_name; - } - - /* Different names -> never duplicates */ - if (strcmp(a_name, b_name)) - return false; - - /* Don't remove duplicates for different PMUs */ - a_pmu_name =3D a_pmu_name ?: (alias_a->pmu->name ?: ""); - b_pmu_name =3D b_pmu_name ?: (alias_b->pmu->name ?: ""); - return strcmp(a_pmu_name, b_pmu_name) =3D=3D 0; -} - -void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state) -{ - struct perf_pmu *pmu; - struct perf_pmu_alias *event; - char buf[1024]; - int printed =3D 0; - int len, j; - struct sevent *aliases; - - pmu =3D NULL; - len =3D 0; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - list_for_each_entry(event, &pmu->aliases, list) - len++; - if (pmu->selectable) - len++; - } - aliases =3D zalloc(sizeof(struct sevent) * len); - if (!aliases) { - pr_err("FATAL: not enough memory to print PMU events\n"); - return; - } - pmu =3D NULL; - j =3D 0; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D pmu->is_core; - - list_for_each_entry(event, &pmu->aliases, list) { - aliases[j].event =3D event; - aliases[j].pmu =3D pmu; - aliases[j].is_cpu =3D is_cpu; - j++; - } - if (pmu->selectable) { - aliases[j].event =3D NULL; - aliases[j].pmu =3D pmu; - aliases[j].is_cpu =3D is_cpu; - j++; - } - } - len =3D j; - qsort(aliases, len, sizeof(struct sevent), cmp_sevent); - for (j =3D 0; j < len; j++) { - const char *name, *alias =3D NULL, *scale_unit =3D NULL, - *desc =3D NULL, *long_desc =3D NULL, - *encoding_desc =3D NULL, *topic =3D NULL, - *pmu_name =3D NULL; - bool deprecated =3D false; - size_t buf_used; - - /* Skip duplicates */ - if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) - continue; - - 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; - name =3D buf; - } else { - if (aliases[j].event->desc) { - name =3D aliases[j].event->name; - buf_used =3D 0; - } else { - name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, - aliases[j].event); - if (aliases[j].is_cpu) { - alias =3D name; - name =3D aliases[j].event->name; - } - buf_used =3D strlen(buf) + 1; - } - pmu_name =3D aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); - if (strlen(aliases[j].event->unit) || aliases[j].event->scale !=3D 1.0)= { - scale_unit =3D buf + buf_used; - buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%G%s", aliases[j].event->scale, - aliases[j].event->unit) + 1; - } - desc =3D aliases[j].event->desc; - long_desc =3D aliases[j].event->long_desc; - topic =3D aliases[j].event->topic; - encoding_desc =3D buf + buf_used; - buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", pmu_name, aliases[j].event->str) + 1; - deprecated =3D aliases[j].event->deprecated; - } - print_cb->print_event(print_state, - pmu_name, - topic, - name, - alias, - scale_unit, - deprecated, - "Kernel PMU event", - desc, - long_desc, - encoding_desc); - } - if (printed && pager_in_use()) - printf("\n"); - - zfree(&aliases); - return; -} - -bool pmu_have_event(const char *pname, const char *name) +bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name) { - struct perf_pmu *pmu; struct perf_pmu_alias *alias; =20 - pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (strcmp(pname, pmu->name)) - continue; - list_for_each_entry(alias, &pmu->aliases, list) - if (!strcmp(alias->name, name)) - return true; + list_for_each_entry(alias, &pmu->aliases, list) { + if (!strcmp(alias->name, name)) + return true; } return false; } @@ -2033,24 +1667,6 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *= pmu, __u64 config, name ?: "N/A", buf, config); } =20 -bool perf_pmu__has_hybrid(void) -{ - static bool hybrid_scanned, has_hybrid; - - if (!hybrid_scanned) { - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { - has_hybrid =3D true; - break; - } - } - hybrid_scanned =3D true; - } - return has_hybrid; -} - int perf_pmu__match(char *pattern, char *name, char *tok) { if (!name) @@ -2118,7 +1734,7 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_= name, const char *filename, return openat(dirfd, path, flags); } =20 -static void perf_pmu__delete(struct perf_pmu *pmu) +void perf_pmu__delete(struct perf_pmu *pmu) { perf_pmu__del_formats(&pmu->format); perf_pmu__del_aliases(pmu); @@ -2131,14 +1747,3 @@ static void perf_pmu__delete(struct perf_pmu *pmu) zfree(&pmu->alias_name); free(pmu); } - -void perf_pmu__destroy(void) -{ - struct perf_pmu *pmu, *tmp; - - list_for_each_entry_safe(pmu, tmp, &pmus, list) { - list_del(&pmu->list); - - perf_pmu__delete(pmu); - } -} diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index cb51ad6e40fa..f1f3e8a2e00e 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -198,8 +198,6 @@ struct perf_pmu_alias { char *pmu_name; }; =20 -struct perf_pmu *perf_pmu__find(const char *name); -struct perf_pmu *perf_pmu__find_by_type(unsigned int type); void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu); int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct list_head *head_terms, @@ -222,16 +220,13 @@ void perf_pmu__set_format(unsigned long *bits, long f= rom, long to); int perf_pmu__format_parse(int dirfd, struct list_head *head); void perf_pmu__del_formats(struct list_head *formats); =20 -struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); - bool is_pmu_core(const char *name); bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); -int perf_pmu__num_mem_pmus(void); -void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state); -bool pmu_have_event(const char *pname, const char *name); +bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu); +bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name); =20 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name); FILE *perf_pmu__open_file_at(struct perf_pmu *pmu, int dirfd, const char *= name); @@ -261,7 +256,6 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu= , __u64 config, const char *name); void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu); =20 -bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); =20 char *pmu_find_real_name(const char *name); @@ -273,6 +267,7 @@ int perf_pmu__pathname_scnprintf(char *buf, size_t size, int perf_pmu__event_source_devices_fd(void); int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *fil= ename, int flags); =20 -void perf_pmu__destroy(void); +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name); +void perf_pmu__delete(struct perf_pmu *pmu); =20 #endif /* __PMU_H */ diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 140e11f00b29..2fb28e583366 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -1,16 +1,136 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include +#include +#include +#include #include +#include +#include "debug.h" +#include "evsel.h" #include "pmus.h" #include "pmu.h" +#include "print-events.h" =20 -LIST_HEAD(pmus); +static LIST_HEAD(pmus); + +void perf_pmus__destroy(void) +{ + struct perf_pmu *pmu, *tmp; + + list_for_each_entry_safe(pmu, tmp, &pmus, list) { + list_del(&pmu->list); + + perf_pmu__delete(pmu); + } +} + +static struct perf_pmu *pmu_find(const char *name) +{ + struct perf_pmu *pmu; + + list_for_each_entry(pmu, &pmus, list) { + if (!strcmp(pmu->name, name) || + (pmu->alias_name && !strcmp(pmu->alias_name, name))) + return pmu; + } + + return NULL; +} + +struct perf_pmu *perf_pmus__find(const char *name) +{ + struct perf_pmu *pmu; + int dirfd; + + /* + * Once PMU is loaded it stays in the list, + * so we keep us from multiple reading/parsing + * the pmu format definitions. + */ + pmu =3D pmu_find(name); + if (pmu) + return pmu; + + dirfd =3D perf_pmu__event_source_devices_fd(); + pmu =3D perf_pmu__lookup(&pmus, dirfd, name); + close(dirfd); + + return pmu; +} + +static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) +{ + struct perf_pmu *pmu; + + /* + * Once PMU is loaded it stays in the list, + * so we keep us from multiple reading/parsing + * the pmu format definitions. + */ + pmu =3D pmu_find(name); + if (pmu) + return pmu; + + return perf_pmu__lookup(&pmus, dirfd, name); +} + +/* Add all pmus in sysfs to pmu list: */ +static void pmu_read_sysfs(void) +{ + int fd; + DIR *dir; + struct dirent *dent; + + fd =3D perf_pmu__event_source_devices_fd(); + if (fd < 0) + return; + + dir =3D fdopendir(fd); + if (!dir) + return; + + while ((dent =3D readdir(dir))) { + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) + continue; + /* add to static LIST_HEAD(pmus): */ + perf_pmu__find2(fd, dent->d_name); + } + + closedir(dir); +} + +struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +{ + struct perf_pmu *pmu; + + list_for_each_entry(pmu, &pmus, list) + if (pmu->type =3D=3D type) + return pmu; + + return NULL; +} + +struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) +{ + /* + * pmu iterator: If pmu is NULL, we start at the begin, + * otherwise return the next pmu. Returns NULL on end. + */ + if (!pmu) { + pmu_read_sysfs(); + pmu =3D list_prepare_entry(pmu, &pmus, list); + } + list_for_each_entry_continue(pmu, &pmus, list) + return pmu; + return NULL; +} =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!strcmp(pmu->name, str)) return pmu; /* Ignore "uncore_" prefix. */ @@ -26,3 +146,276 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(c= onst char *str) } return NULL; } + +int perf_pmus__num_mem_pmus(void) +{ + struct perf_pmu *pmu =3D NULL; + int count =3D 0; + + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + if (perf_pmu__is_mem_pmu(pmu)) + count++; + } + return count; +} + +/** Struct for ordering events as output in perf list. */ +struct sevent { + /** PMU for event. */ + const struct perf_pmu *pmu; + /** + * Optional event for name, desc, etc. If not present then this is a + * selectable PMU and the event name is shown as "//". + */ + const struct perf_pmu_alias *event; + /** Is the PMU for the CPU? */ + bool is_cpu; +}; + +static int cmp_sevent(const void *a, const void *b) +{ + const struct sevent *as =3D a; + const struct sevent *bs =3D b; + const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; + const char *a_name =3D "//", *a_desc =3D NULL, *a_topic =3D ""; + const char *b_name =3D "//", *b_desc =3D NULL, *b_topic =3D ""; + int ret; + + if (as->event) { + a_name =3D as->event->name; + a_desc =3D as->event->desc; + a_topic =3D as->event->topic ?: ""; + a_pmu_name =3D as->event->pmu_name; + } + if (bs->event) { + b_name =3D bs->event->name; + b_desc =3D bs->event->desc; + b_topic =3D bs->event->topic ?: ""; + b_pmu_name =3D bs->event->pmu_name; + } + /* Put extra events last. */ + if (!!a_desc !=3D !!b_desc) + return !!a_desc - !!b_desc; + + /* Order by topics. */ + ret =3D strcmp(a_topic, b_topic); + if (ret) + return ret; + + /* Order CPU core events to be first */ + if (as->is_cpu !=3D bs->is_cpu) + return as->is_cpu ? -1 : 1; + + /* Order by PMU name. */ + if (as->pmu !=3D bs->pmu) { + a_pmu_name =3D a_pmu_name ?: (as->pmu->name ?: ""); + b_pmu_name =3D b_pmu_name ?: (bs->pmu->name ?: ""); + ret =3D strcmp(a_pmu_name, b_pmu_name); + if (ret) + return ret; + } + + /* Order by event name. */ + return strcmp(a_name, b_name); +} + +static bool pmu_alias_is_duplicate(struct sevent *alias_a, + struct sevent *alias_b) +{ + const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; + const char *a_name =3D "//", *b_name =3D "//"; + + + if (alias_a->event) { + a_name =3D alias_a->event->name; + a_pmu_name =3D alias_a->event->pmu_name; + } + if (alias_b->event) { + b_name =3D alias_b->event->name; + b_pmu_name =3D alias_b->event->pmu_name; + } + + /* Different names -> never duplicates */ + if (strcmp(a_name, b_name)) + return false; + + /* Don't remove duplicates for different PMUs */ + a_pmu_name =3D a_pmu_name ?: (alias_a->pmu->name ?: ""); + b_pmu_name =3D b_pmu_name ?: (alias_b->pmu->name ?: ""); + return strcmp(a_pmu_name, b_pmu_name) =3D=3D 0; +} + +static int sub_non_neg(int a, int b) +{ + if (b > a) + return 0; + return a - b; +} + +static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, + const struct perf_pmu_alias *alias) +{ + struct parse_events_term *term; + int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); + + list_for_each_entry(term, &alias->terms, list) { + if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) + used +=3D snprintf(buf + used, sub_non_neg(len, used), + ",%s=3D%s", term->config, + term->val.str); + } + + if (sub_non_neg(len, used) > 0) { + buf[used] =3D '/'; + used++; + } + if (sub_non_neg(len, used) > 0) { + buf[used] =3D '\0'; + used++; + } else + buf[len - 1] =3D '\0'; + + return buf; +} + +void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state) +{ + struct perf_pmu *pmu; + struct perf_pmu_alias *event; + char buf[1024]; + int printed =3D 0; + int len, j; + struct sevent *aliases; + + pmu =3D NULL; + len =3D 0; + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + list_for_each_entry(event, &pmu->aliases, list) + len++; + if (pmu->selectable) + len++; + } + aliases =3D zalloc(sizeof(struct sevent) * len); + if (!aliases) { + pr_err("FATAL: not enough memory to print PMU events\n"); + return; + } + pmu =3D NULL; + j =3D 0; + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + bool is_cpu =3D pmu->is_core; + + list_for_each_entry(event, &pmu->aliases, list) { + aliases[j].event =3D event; + aliases[j].pmu =3D pmu; + aliases[j].is_cpu =3D is_cpu; + j++; + } + if (pmu->selectable) { + aliases[j].event =3D NULL; + aliases[j].pmu =3D pmu; + aliases[j].is_cpu =3D is_cpu; + j++; + } + } + len =3D j; + qsort(aliases, len, sizeof(struct sevent), cmp_sevent); + for (j =3D 0; j < len; j++) { + const char *name, *alias =3D NULL, *scale_unit =3D NULL, + *desc =3D NULL, *long_desc =3D NULL, + *encoding_desc =3D NULL, *topic =3D NULL, + *pmu_name =3D NULL; + bool deprecated =3D false; + size_t buf_used; + + /* Skip duplicates */ + if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) + continue; + + 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; + name =3D buf; + } else { + if (aliases[j].event->desc) { + name =3D aliases[j].event->name; + buf_used =3D 0; + } else { + name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, + aliases[j].event); + if (aliases[j].is_cpu) { + alias =3D name; + name =3D aliases[j].event->name; + } + buf_used =3D strlen(buf) + 1; + } + pmu_name =3D aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); + if (strlen(aliases[j].event->unit) || aliases[j].event->scale !=3D 1.0)= { + scale_unit =3D buf + buf_used; + buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%G%s", aliases[j].event->scale, + aliases[j].event->unit) + 1; + } + desc =3D aliases[j].event->desc; + long_desc =3D aliases[j].event->long_desc; + topic =3D aliases[j].event->topic; + encoding_desc =3D buf + buf_used; + buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%s/%s/", pmu_name, aliases[j].event->str) + 1; + deprecated =3D aliases[j].event->deprecated; + } + print_cb->print_event(print_state, + pmu_name, + topic, + name, + alias, + scale_unit, + deprecated, + "Kernel PMU event", + desc, + long_desc, + encoding_desc); + } + if (printed && pager_in_use()) + printf("\n"); + + zfree(&aliases); + return; +} + +bool perf_pmus__have_event(const char *pname, const char *name) +{ + struct perf_pmu *pmu =3D perf_pmus__find(pname); + + return pmu && perf_pmu__have_event(pmu, name); +} + +bool perf_pmus__has_hybrid(void) +{ + static bool hybrid_scanned, has_hybrid; + + if (!hybrid_scanned) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid =3D true; + break; + } + } + hybrid_scanned =3D true; + } + return has_hybrid; +} + +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) +{ + struct perf_pmu *pmu =3D evsel->pmu; + + if (!pmu) { + pmu =3D perf_pmus__find_by_type(evsel->core.attr.type); + ((struct evsel *)evsel)->pmu =3D pmu; + } + return pmu; +} diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 257de10788e8..2a771d9f8da7 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -2,9 +2,21 @@ #ifndef __PMUS_H #define __PMUS_H =20 -extern struct list_head pmus; struct perf_pmu; +struct print_callbacks; + +void perf_pmus__destroy(void); + +struct perf_pmu *perf_pmus__find(const char *name); +struct perf_pmu *perf_pmus__find_by_type(unsigned int type); + +struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 +int perf_pmus__num_mem_pmus(void); +void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state); +bool perf_pmus__have_event(const char *pname, const char *name); +bool perf_pmus__has_hybrid(void); + #endif /* __PMUS_H */ diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 8d823bc906e6..9cee7bb7a561 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -20,6 +20,7 @@ #include "metricgroup.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "print-events.h" #include "probe-file.h" #include "string2.h" @@ -271,7 +272,7 @@ int print_hwcache_events(const struct print_callbacks *= print_cb, void *print_sta struct perf_pmu *pmu =3D NULL; const char *event_type_descriptor =3D event_type_descriptors[PERF_TYPE_HW= _CACHE]; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { /* * Skip uncore PMUs for performance. PERF_TYPE_HW_CACHE type * attributes can accept software PMUs in the extended type, so @@ -404,7 +405,7 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) =20 print_hwcache_events(print_cb, print_state); =20 - print_pmu_events(print_cb, print_state); + perf_pmus__print_pmu_events(print_cb, print_state); =20 print_cb->print_event(print_state, /*topic=3D*/NULL, diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 164715113b9e..51d22c19e5ab 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -20,6 +20,7 @@ #include "util.h" #include "iostat.h" #include "pmu.h" +#include "pmus.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,7 +681,7 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; =20 evlist__for_each_entry(evlist, evsel) { --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 BD63FC7EE2D for ; Mon, 22 May 2023 06:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231892AbjEVGrI (ORCPT ); Mon, 22 May 2023 02:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbjEVGp4 (ORCPT ); Mon, 22 May 2023 02:45:56 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33892E59 for ; Sun, 21 May 2023 23:44:48 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5308f5d8ac9so3103256a12.0 for ; Sun, 21 May 2023 23:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737863; x=1687329863; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=72TLmH2W4t53itRP03fYxeW8kLc6/TPjYOWxUzORf6s=; b=PkcphY2m0bQMP0ZyOPR2RVtJqOGpihkKEzqjJx2gsfkBHgH0/jhHTds2NEz+jcqEaQ GEZp8iaHj5YbTLwfpGDM1VWbzKUQb3ZwD5qVrIScXOptbBakU1B9WWl6OMzvvDXD/qjr 9NjnR1NwhWK93augXd2wfjyijzsVpZY5zogVBdbivezR++w7GWS2bmikbkuKyJT1fhk9 mvt627X1v5l8MOerB3HVmQIs6QqpC9Lh17LK6CA51uEMojlHr/rXQ01IkLE1linnl4be h5MyEujS5CEJoUhlUJL+G+nb53xhyD5JClPjM/E/b7YApOJagzbyhKTXcDIamxfb15x4 Tznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737863; x=1687329863; 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=72TLmH2W4t53itRP03fYxeW8kLc6/TPjYOWxUzORf6s=; b=KZfVNvxy942ziEIJmjP1Nm8R8yNcRTV2/RuhPiZvw74t8/e2rjRcs1dEfnNGXSRQad aPaWZ4LD8j+0iy39Ui0FjSSpm/bUQRlx3GR2NW+di4765Yqb4Lg8uRJ7j79R36F5mhX3 FfZFv+cAuXKBvk0b6RdZxd81dURSdjms8dkkzn0ndwfoKQuiH2aAzIn6Qe0ZNqQFdGi5 K8j6jS4GbBU7mX/iFB6zMCyZ6uBtWYGrFXrMT4jVs6FMlJTi9KLsPTSAHSvgGk3YkNTT /a7QXl5RYQTzrrAfit28XAfscpAbln4wW2HsIzZf20PRg6ETqdqZ5HHk3wiYmdCSA8be t86g== X-Gm-Message-State: AC+VfDzSEss+EQpH8hEom53aPNrewJI8fEIqT/cRxw7X/21tnHlHgGD2 kSP/3VH9rAAJ0wmmxbGfhIsqXFPubqL/ X-Google-Smtp-Source: ACHHUZ7jra7VZJT4OEslfuoWrE8z9a03q8ZBonIBgERnfxnhpKhmMegq1vNMXydobj60GaqrAsHWT9h/tiWA X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a63:da02:0:b0:520:4dfb:530a with SMTP id c2-20020a63da02000000b005204dfb530amr2200802pgh.8.1684737863132; Sun, 21 May 2023 23:44:23 -0700 (PDT) Date: Sun, 21 May 2023 23:43:27 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-21-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 20/23] perf pmus: Split pmus list into core and other From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Split the pmus list into core and other. This will later allow for the core and other pmus to be populated separately. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 2fb28e583366..10f5648073bb 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -12,13 +12,19 @@ #include "pmu.h" #include "print-events.h" =20 -static LIST_HEAD(pmus); +static LIST_HEAD(core_pmus); +static LIST_HEAD(other_pmus); =20 void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; =20 - list_for_each_entry_safe(pmu, tmp, &pmus, list) { + list_for_each_entry_safe(pmu, tmp, &core_pmus, list) { + list_del(&pmu->list); + + perf_pmu__delete(pmu); + } + list_for_each_entry_safe(pmu, tmp, &other_pmus, list) { list_del(&pmu->list); =20 perf_pmu__delete(pmu); @@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) { + list_for_each_entry(pmu, &core_pmus, list) { + if (!strcmp(pmu->name, name) || + (pmu->alias_name && !strcmp(pmu->alias_name, name))) + return pmu; + } + list_for_each_entry(pmu, &other_pmus, list) { if (!strcmp(pmu->name, name) || (pmu->alias_name && !strcmp(pmu->alias_name, name))) return pmu; @@ -53,7 +64,7 @@ struct perf_pmu *perf_pmus__find(const char *name) return pmu; =20 dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(&pmus, dirfd, name); + pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); close(dirfd); =20 return pmu; @@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const = char *name) if (pmu) return pmu; =20 - return perf_pmu__lookup(&pmus, dirfd, name); + return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -93,7 +104,7 @@ static void pmu_read_sysfs(void) while ((dent =3D readdir(dir))) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; - /* add to static LIST_HEAD(pmus): */ + /* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */ perf_pmu__find2(fd, dent->d_name); } =20 @@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int= type) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) + list_for_each_entry(pmu, &core_pmus, list) { if (pmu->type =3D=3D type) return pmu; - + } + list_for_each_entry(pmu, &other_pmus, list) { + if (pmu->type =3D=3D type) + return pmu; + } return NULL; } =20 +/* + * pmu iterator: If pmu is NULL, we start at the begin, otherwise return t= he + * next pmu. Returns NULL on end. + */ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) { - /* - * pmu iterator: If pmu is NULL, we start at the begin, - * otherwise return the next pmu. Returns NULL on end. - */ + bool use_core_pmus =3D !pmu || pmu->is_core; + if (!pmu) { pmu_read_sysfs(); - pmu =3D list_prepare_entry(pmu, &pmus, list); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + pmu =3D NULL; + pmu =3D list_prepare_entry(pmu, &other_pmus, list); } - list_for_each_entry_continue(pmu, &pmus, list) + list_for_each_entry_continue(pmu, &other_pmus, list) return pmu; return NULL; } --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 460EEC7EE26 for ; Mon, 22 May 2023 06:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbjEVGrM (ORCPT ); Mon, 22 May 2023 02:47:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbjEVGp7 (ORCPT ); Mon, 22 May 2023 02:45:59 -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 07B6E1729 for ; Sun, 21 May 2023 23:44:50 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561f1c2af16so50827117b3.0 for ; Sun, 21 May 2023 23:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737865; x=1687329865; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=e/zDhGYmSYwIY3XTw78CiadtIGytk9ZJaXCr9PdDxvQ=; b=gd9gxG/2Ielbr0Bwodts99ppTP+CDR3zPpb9RGt/KzqBG2lKBLfolD1sn45vE5jrNp MwrFtLKseZDFyMDVA4ZW2P/X84lWtjlSa46hxsXFZkm4eEAlW1j8NShOqOo/cwuDHDeh 7fblnnw0KfEha/3BP5Rxt7X8w0zWowQUeS331nFjHtOuUDNYqHGSH1IndTAPkVoWzBwH p+PASCeH2QcZsJ57AM01Q+K0hlPYkcczQ3A4UjJd5szJsIkPbPVjkx+xRPw03yJq0nuE bCSbqPQsuKbmIhtmH2R1KgLhlBVtG4iM7XDWwc+rih6nuUZ7JOMCfNZjAjPL/Yj4Z1Kz OHpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737865; x=1687329865; 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=e/zDhGYmSYwIY3XTw78CiadtIGytk9ZJaXCr9PdDxvQ=; b=RelkmPGcTMED00OaBYOuDAqGW5XlksL4GT/LxDsz0NZtrVdiWwkaMosb0e1LlycA2B 64m54no/QQ15NpJ6bAdPcF9D4b1Wu95rvGPGjGv8d2QrvgjYBAgCgB6vycnpsrYeihrV mLVNd2lhmA44bvek0wjnyGiRDo9s/Fi93r9bbA/t3IYJMjwPw7l6pt8aDb8VkTVkaive geURuf/zd71dSQIXwX61dBoLU+ofe7f0RNVMJb1OSSaTWMtOzxBvp6HETfBms1tl+MgV x6S19b17JJecfuzSyHSQLljDU7xA8UqrD3/rSVjMHaZnwV67T8aC5PrzK1RI9fa5IqoT hvVQ== X-Gm-Message-State: AC+VfDyvzYJ69NzWSKk/kd9uVo2WkmQZH7YMMLvvtFInMxZPrxaCkqQa OMPNIAkq8fI39Wlc5gMNqYh3D/SfE6w1 X-Google-Smtp-Source: ACHHUZ7hQicGHtucbbu9xRxzegdWd3UkqaH+RXMHj8ZLml5x0U2mPqGcknC57brDNFmv+xEOQyWVDSpYZ/Kg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:fe01:0:b0:ba8:8ab3:3806 with SMTP id k1-20020a25fe01000000b00ba88ab33806mr5908499ybe.13.1684737865483; Sun, 21 May 2023 23:44:25 -0700 (PDT) Date: Sun, 21 May 2023 23:43:28 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-22-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 21/23] perf pmus: Allow just core PMU scanning From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" Scanning all PMUs is expensive as all PMUs sysfs entries are loaded, benchmarking shows more than 4x the cost: ``` $ perf bench internals pmu-scan -i 1000 Computing performance of sysfs PMU event scan for 1000 times Average core PMU scanning took: 989.231 usec (+- 1.535 usec) Average PMU scanning took: 4309.425 usec (+- 74.322 usec) ``` Add new perf_pmus__scan_core routine that scans just core PMUs. Replace perf_pmus__scan calls with perf_pmus__scan_core when non-core PMUs are being ignored. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 5 +-- tools/perf/arch/x86/util/evlist.c | 5 +-- tools/perf/arch/x86/util/perf_regs.c | 8 ++--- tools/perf/bench/pmu-scan.c | 50 ++++++++++++++++------------ tools/perf/tests/pmu-events.c | 5 +-- tools/perf/util/cputopo.c | 10 ++---- tools/perf/util/header.c | 5 +-- tools/perf/util/mem-events.c | 14 ++------ tools/perf/util/parse-events.c | 13 +++----- tools/perf/util/pmu.c | 10 ------ tools/perf/util/pmu.h | 2 -- tools/perf/util/pmus.c | 28 ++++++++++++---- tools/perf/util/pmus.h | 1 + tools/perf/util/print-events.c | 11 +++--- 14 files changed, 73 insertions(+), 94 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 2504d43a39a7..561de0cb6b95 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -11,10 +11,7 @@ static struct perf_pmu *pmu__find_core_pmu(void) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu))) { - if (!is_pmu_core(pmu->name)) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu))) { /* * The cpumap should cover all CPUs. Otherwise, some CPUs may * not support some events or have different event IDs. diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 03240c640c7f..8a6a0b98b976 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -33,13 +33,10 @@ static int ___evlist__add_default_attrs(struct evlist *= evlist, continue; } =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; =20 - if (!pmu->is_core) - continue; - evsel =3D evsel__new(attrs + i); if (evsel =3D=3D NULL) goto out_delete_partial_list; diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index befa7f3659b9..116384f19baf 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -300,11 +300,9 @@ uint64_t arch__intr_reg_mask(void) * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core) { - type =3D pmu->type; - break; - } + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + type =3D pmu->type; + break; } attr.config |=3D type << PERF_PMU_TYPE_SHIFT; } diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index 51cae2d03353..c7d207f8e13c 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -22,6 +22,7 @@ struct pmu_scan_result { int nr_aliases; int nr_formats; int nr_caps; + bool is_core; }; =20 static const struct option options[] =3D { @@ -53,6 +54,7 @@ static int save_result(void) r =3D results + nr_pmus; =20 r->name =3D strdup(pmu->name); + r->is_core =3D pmu->is_core; r->nr_caps =3D pmu->nr_caps; =20 r->nr_aliases =3D 0; @@ -72,7 +74,7 @@ static int save_result(void) return 0; } =20 -static int check_result(void) +static int check_result(bool core_only) { struct pmu_scan_result *r; struct perf_pmu *pmu; @@ -81,6 +83,9 @@ static int check_result(void) =20 for (int i =3D 0; i < nr_pmus; i++) { r =3D &results[i]; + if (core_only && !r->is_core) + continue; + pmu =3D perf_pmus__find(r->name); if (pmu =3D=3D NULL) { pr_err("Cannot find PMU %s\n", r->name); @@ -130,7 +135,6 @@ static int run_pmu_scan(void) struct timeval start, end, diff; double time_average, time_stddev; u64 runtime_us; - unsigned int i; int ret; =20 init_stats(&stats); @@ -142,26 +146,30 @@ static int run_pmu_scan(void) return -1; } =20 - for (i =3D 0; i < iterations; i++) { - gettimeofday(&start, NULL); - perf_pmus__scan(NULL); - gettimeofday(&end, NULL); - - timersub(&end, &start, &diff); - runtime_us =3D diff.tv_sec * USEC_PER_SEC + diff.tv_usec; - update_stats(&stats, runtime_us); - - ret =3D check_result(); - perf_pmus__destroy(); - if (ret < 0) - break; + for (int j =3D 0; j < 2; j++) { + bool core_only =3D (j =3D=3D 0); + + for (unsigned int i =3D 0; i < iterations; i++) { + gettimeofday(&start, NULL); + if (core_only) + perf_pmus__scan_core(NULL); + else + perf_pmus__scan(NULL); + gettimeofday(&end, NULL); + timersub(&end, &start, &diff); + runtime_us =3D diff.tv_sec * USEC_PER_SEC + diff.tv_usec; + update_stats(&stats, runtime_us); + + ret =3D check_result(core_only); + perf_pmus__destroy(); + if (ret < 0) + break; + } + time_average =3D avg_stats(&stats); + time_stddev =3D stddev_stats(&stats); + pr_info(" Average%s PMU scanning took: %.3f usec (+- %.3f usec)\n", + core_only ? " core" : "", time_average, time_stddev); } - - time_average =3D avg_stats(&stats); - time_stddev =3D stddev_stats(&stats); - pr_info(" Average PMU scanning took: %.3f usec (+- %.3f usec)\n", - time_average, time_stddev); - delete_result(); return 0; } diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 64ecb7845af4..64383fc34ef1 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -709,12 +709,9 @@ static int test__aliases(struct test_suite *test __may= be_unused, struct perf_pmu *pmu =3D NULL; unsigned long i; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { int count =3D 0; =20 - if (!is_pmu_core(pmu->name)) - continue; - if (list_empty(&pmu->format)) { pr_debug2("skipping testing core PMU %s\n", pmu->name); continue; diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 4578c26747e1..3723a1cec768 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -477,9 +477,8 @@ struct hybrid_topology *hybrid_topology__new(void) if (!perf_pmus__has_hybrid()) return NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core) - nr++; + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + nr++; } if (nr =3D=3D 0) return NULL; @@ -489,10 +488,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { if (load_hybrid_node(&tp->nodes[i], pmu)) { hybrid_topology__delete(tp); return NULL; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index fa3f7dbbd90e..c701cc474d79 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1591,10 +1591,7 @@ static int write_pmu_caps(struct feat_fd *ff, */ if (perf_pmus__has_hybrid()) { pmu =3D NULL; - while ((pmu =3D perf_pmus__scan(pmu))) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu))) { ret =3D __write_pmu_caps(ff, pmu, true); if (ret < 0) return ret; diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 08ac3ea2e366..c5596230a308 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -136,10 +136,7 @@ int perf_mem_events__init(void) } else { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); @@ -176,10 +173,7 @@ static void perf_mem_events__print_unsupport_hybrid(st= ruct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); if (!perf_mem_event__supported(mnt, sysfs_name)) { @@ -217,9 +211,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { rec_argv[i++] =3D "-e"; s =3D perf_mem_events__name(j, pmu->name); if (s) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 984b230e14d4..47ee628a65bb 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -452,15 +452,12 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, const char *config_name =3D get_config_name(head_config); const char *metric_id =3D get_config_metric_id(head_config); =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + /* Legacy cache events are only supported by core PMUs. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; =20 - /* Skip unsupported PMUs. */ - if (!perf_pmu__supports_legacy_cache(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; =20 @@ -1480,12 +1477,10 @@ int parse_events_add_numeric(struct parse_events_st= ate *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=3D*/NULL, type, config, head_config); =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + /* Wildcards on numeric values are only supported by core PMUs. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { int ret; =20 - if (!perf_pmu__supports_wildcard_numeric(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 3217a859c65b..4844ed8049f1 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1440,21 +1440,11 @@ bool perf_pmu__supports_legacy_cache(const struct p= erf_pmu *pmu) return pmu->is_core; } =20 -bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) -{ - return pmu->is_core; -} - bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { return !is_pmu_hybrid(pmu->name); } =20 -bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) -{ - return pmu->is_core; -} - bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name) { struct perf_pmu_alias *alias; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index f1f3e8a2e00e..02fec0a7d4c8 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -223,9 +223,7 @@ void perf_pmu__del_formats(struct list_head *formats); bool is_pmu_core(const char *name); bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); -bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); -bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu); bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name); =20 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name); diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 10f5648073bb..5736e99facd1 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -87,7 +87,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const = char *name) } =20 /* Add all pmus in sysfs to pmu list: */ -static void pmu_read_sysfs(void) +static void pmu_read_sysfs(bool core_only) { int fd; DIR *dir; @@ -104,6 +104,8 @@ static void pmu_read_sysfs(void) while ((dent =3D readdir(dir))) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; + if (core_only && !is_pmu_core(dent->d_name)) + continue; /* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */ perf_pmu__find2(fd, dent->d_name); } @@ -135,7 +137,7 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) bool use_core_pmus =3D !pmu || pmu->is_core; =20 if (!pmu) { - pmu_read_sysfs(); + pmu_read_sysfs(/*core_only=3D*/false); pmu =3D list_prepare_entry(pmu, &core_pmus, list); } if (use_core_pmus) { @@ -150,6 +152,18 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) return NULL; } =20 +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu) +{ + if (!pmu) { + pmu_read_sysfs(/*core_only=3D*/true); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + return NULL; +} + const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; @@ -176,9 +190,9 @@ int perf_pmus__num_mem_pmus(void) struct perf_pmu *pmu =3D NULL; int count =3D 0; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (perf_pmu__is_mem_pmu(pmu)) - count++; + /* All core PMUs are for mem events. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + count++; } return count; } @@ -422,8 +436,8 @@ bool perf_pmus__has_hybrid(void) if (!hybrid_scanned) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + if (is_pmu_hybrid(pmu->name)) { has_hybrid =3D true; break; } diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 2a771d9f8da7..9de0222ed52b 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -11,6 +11,7 @@ struct perf_pmu *perf_pmus__find(const char *name); struct perf_pmu *perf_pmus__find_by_type(unsigned int type); =20 struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu); =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 9cee7bb7a561..7a5f87392720 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -272,12 +272,11 @@ int print_hwcache_events(const struct print_callbacks= *print_cb, void *print_sta struct perf_pmu *pmu =3D NULL; const char *event_type_descriptor =3D event_type_descriptors[PERF_TYPE_HW= _CACHE]; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - /* - * Skip uncore PMUs for performance. PERF_TYPE_HW_CACHE type - * attributes can accept software PMUs in the extended type, so - * also skip. - */ + /* + * Only print core PMUs, skipping uncore for performance and + * PERF_TYPE_SOFTWARE that can succeed in opening legacy cache evenst. + */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { if (pmu->is_uncore || pmu->type =3D=3D PERF_TYPE_SOFTWARE) continue; =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 A4BFAC77B73 for ; Mon, 22 May 2023 06:47:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbjEVGrP (ORCPT ); Mon, 22 May 2023 02:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbjEVGqA (ORCPT ); Mon, 22 May 2023 02:46:00 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 356D71730 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba83fed51adso10456746276.0 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737868; x=1687329868; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/+aFtpu9F2yGljXWeZ17LuoYXO4ZNmuRrdV4BNXebZU=; b=WaMOe5OUll0Sz3acYm4uBfP9Z16Iny/8w4BooK0DItssmCmNzxlUurQkN2coR0gNZn VA9XDIt83nTT1n/huWCKal3K6IbRP/7461ldA4ftEms4RfXQKm6GC4TaZwpQGFfcTKqB oIYrXtvyVFtZKxpNNgMT7H8kXvww57QD6IXbvkv3pwYxvv3Xz5UXm4RtaYEssAp4liK9 C4nuzxzYmak9iZYoexyN6LBpeLG85ppM9G08VP2VyuaeDKLi2TYGZxF9s9/ynZ4RtTJn U7hw7jr42r3RXEZu0ZFOeXm+Q48UG/nUdfFzp8U7CchRVHGNj9b29tj0LfL0gIUiaLWu xB8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737868; x=1687329868; 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=/+aFtpu9F2yGljXWeZ17LuoYXO4ZNmuRrdV4BNXebZU=; b=EMCVvgnEt+fPf4PN8CcE0WC+CNZhmT5tPBs6sonyHmk/q1SIJ5ETDogEb34sri1jHl g/GQlmep3hV5y1IjVIzqdj0BPoDuNipzqql0eWkI3k1wcRIGQFGh9fEcS5xkE+zMQqcA NxrxmR2mxgL7SV9++RCHw/hZzNi57yFuScCYoccS9pQGhkdIMlwGaWYQu1VUj0vGHDGH Q4lD91ae8AelSlbvozt3+9S2yfPR92zfe6ksFRQjpteCtfuR32C1/C3rGz2dC3Ny/JD7 Fzl4RgxmUe+VD6tBAL+hwA+Rk6R8EliJOwypBes4141W9fGiZp6XS/2O5W0pZYH2EIYn qrbg== X-Gm-Message-State: AC+VfDwBzxC7FfwuIxcCvD3Xr98QsfxQXmrGlUPhw+IWbQz6kyBdGwB6 T/PQspe8BOXW24FWuXokyTn5TMghcuMe X-Google-Smtp-Source: ACHHUZ4VYf6iGuG5alZmBIczqrBWEaYLm65RVnA3VZh2jBU21XmP0FFw2fc2n/SzpDwfAuNUisc8brDXSjVm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a25:bb41:0:b0:b9a:6508:1b5f with SMTP id b1-20020a25bb41000000b00b9a65081b5fmr3592765ybk.11.1684737868018; Sun, 21 May 2023 23:44:28 -0700 (PDT) Date: Sun, 21 May 2023 23:43:29 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-23-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 22/23] perf pmus: Avoid repeated sysfs scanning From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" perf_pmus__scan will process every directory in sysfs to see if it is a PMU, attempting to add it if not already in the pmus list. Add two booleans to record whether this scanning has been done for core or all PMUs. Skip scanning in the event that scanning has already occurred. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 5736e99facd1..22e9e46ab765 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -14,6 +14,8 @@ =20 static LIST_HEAD(core_pmus); static LIST_HEAD(other_pmus); +static bool read_sysfs_core_pmus; +static bool read_sysfs_all_pmus; =20 void perf_pmus__destroy(void) { @@ -29,6 +31,8 @@ void perf_pmus__destroy(void) =20 perf_pmu__delete(pmu); } + read_sysfs_core_pmus =3D false; + read_sysfs_all_pmus =3D false; } =20 static struct perf_pmu *pmu_find(const char *name) @@ -53,6 +57,7 @@ struct perf_pmu *perf_pmus__find(const char *name) { struct perf_pmu *pmu; int dirfd; + bool core_pmu; =20 /* * Once PMU is loaded it stays in the list, @@ -63,8 +68,15 @@ struct perf_pmu *perf_pmus__find(const char *name) if (pmu) return pmu; =20 + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); + pmu =3D perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name= ); close(dirfd); =20 return pmu; @@ -73,6 +85,7 @@ struct perf_pmu *perf_pmus__find(const char *name) static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) { struct perf_pmu *pmu; + bool core_pmu; =20 /* * Once PMU is loaded it stays in the list, @@ -83,7 +96,14 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const= char *name) if (pmu) return pmu; =20 - return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + + return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -93,6 +113,9 @@ static void pmu_read_sysfs(bool core_only) DIR *dir; struct dirent *dent; =20 + if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) + return; + fd =3D perf_pmu__event_source_devices_fd(); if (fd < 0) return; @@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) } =20 closedir(dir); + if (core_only) { + read_sysfs_core_pmus =3D true; + } else { + read_sysfs_core_pmus =3D true; + read_sysfs_all_pmus =3D true; + } } =20 struct perf_pmu *perf_pmus__find_by_type(unsigned int type) --=20 2.40.1.698.g37aff9b760-goog From nobody Sat Feb 7 18:20:54 2026 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 D64CCC77B73 for ; Mon, 22 May 2023 06:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbjEVGrS (ORCPT ); Mon, 22 May 2023 02:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbjEVGqI (ORCPT ); Mon, 22 May 2023 02:46:08 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC8B1735 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8bab3b392so6666442276.1 for ; Sun, 21 May 2023 23:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737870; x=1687329870; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=AR9zIJFSwa/PWauN3jIDvjQbr00g5VzBP70Tf1LOL1E=; b=rQdTaU9Co7hmCz7sZhlTtMZNm3PLADpPrQkIYy4P6ZRDmrhzsp6Xf0YAjRm0wBZdn+ 6xDYWZ++iJgI6JA/TGL8WcomWza08xozk8lfhLPjUgoHYFyir2BnZuybBvqke06qMHiL Ks4GWm+M4VtI/9tZt17Lc5EgktlOwb2PxgJuYJvEljGKwIkIAmtJkdUurOIUjmzFgkyi u9cG90qy2vNY6gDgClRU/aMiY994YcRs9Y/JPbQTmuzIwlqn75sDUp+W1KRj6BpWpW+t FVrnRzdTvlOE7agFuNOID8UTjbXD2bmq8YnConWaa1Uwsej2BW3iD0MJjU0dy9mKbCxo K1Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737870; x=1687329870; 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=AR9zIJFSwa/PWauN3jIDvjQbr00g5VzBP70Tf1LOL1E=; b=JOUlEyeus0k+Dl4RnKZ+TBdVkS0CICBZp94uze3g0SHFOWtRpsdpSXbpqi2m37Rqsy 99jSfSYXvZtVKtnizUdlPQaBvl9rMpEcqAzIykZG+butSnbaPC+RXqH333+MoM8j7B+F hF4nzSNe5ty2ZyThdv5VopWFEq18XYpaorc12AdC9iNDTN9n9q5sJiSr2wzhmAPcr5mN dDQ5NmBO+Kcit2BN3E746n3IIrPl9U60eMrR3c19W9d8ltGgjlMKUAyp09Vxcx8766rr efZ45dlmvJdQQWmjXe6RTdCbAonFcj533esMmLB2H/qd3RgGYrp5Q23e5nUsxaDziJyh Cg3w== X-Gm-Message-State: AC+VfDxNEE4XeCNiiiYs60T5ccf02HvY3CVxfaOy3EFJ5885Hbo4Z3iq zK/UJ8H+s2srR+oRFeZDxdPZ9+oUZ1Cf X-Google-Smtp-Source: ACHHUZ4LNBZ9sStTvrt17WoyzQgUctNLJyZ9xJ+MBkHUvinjj2Hmn4Vu3vh1z5UIvrHcyXCUstYSzvEiMpg6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a05:6902:1343:b0:ba8:4d1c:dd04 with SMTP id g3-20020a056902134300b00ba84d1cdd04mr6161248ybu.1.1684737870515; Sun, 21 May 2023 23:44:30 -0700 (PDT) Date: Sun, 21 May 2023 23:43:30 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-24-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 23/23] perf pmus: Ensure all PMUs are read for find_by_type From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@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" perf_pmus__find_by_type may be called for something like a raw event, in which case the PMU isn't guaranteed to have been looked up. Add a second check to make sure all PMUs are loaded. Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 22e9e46ab765..ce75c7adca84 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -142,7 +142,7 @@ static void pmu_read_sysfs(bool core_only) } } =20 -struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +static struct perf_pmu *__perf_pmus__find_by_type(unsigned int type) { struct perf_pmu *pmu; =20 @@ -150,6 +150,7 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int t= ype) if (pmu->type =3D=3D type) return pmu; } + list_for_each_entry(pmu, &other_pmus, list) { if (pmu->type =3D=3D type) return pmu; @@ -157,6 +158,18 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int = type) return NULL; } =20 +struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +{ + struct perf_pmu *pmu =3D __perf_pmus__find_by_type(type); + + if (pmu || read_sysfs_all_pmus) + return pmu; + + pmu_read_sysfs(/*core_only=3D*/false); + pmu =3D __perf_pmus__find_by_type(type); + return pmu; +} + /* * pmu iterator: If pmu is NULL, we start at the begin, otherwise return t= he * next pmu. Returns NULL on end. --=20 2.40.1.698.g37aff9b760-goog