From patchwork Wed May 17 14:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245269 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC549C77B75 for ; Wed, 17 May 2023 16:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UPTtWMvs1paqUvKTinpJ/dREf4p6TAx9gv4Dn5nzcdI=; b=XWd9hDoz/XopTg kitddrBTIlTdIOZxdtYmom2a2bTatkY+lOMIwG8U4t/3qNFP1Cex5QZJqxax/AvtXI6zWteEKoKWH ji2oBukgsom5VWdpZYKEDSZu2IZHG9HPEDu7syyVdaOfbSkacvrDYtwzK0G9a0IQpGmKMQnHSIc7z QSCGUrtoxVsUfbIzDH3UFxaknqO6onFXqaaxhyN1sEK/6jTHRHKRDShTeWNXYDl1y6DDIjgmYfIwP jO3xcAaht2TUSS/DHKchPRFNLzynWl1rUAZN64lud6+5YZF6f42Lf6qLSkYCTMRLzmPqOm60n602n 5WzmKntdnQnZgJEQUdgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJZy-00AOPn-1h; Wed, 17 May 2023 16:00:42 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIby-00ADNK-0h for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:44 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b37d9d2so1428233276.3 for ; Wed, 17 May 2023 07:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335518; x=1686927518; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3eVxch5HkrXcvtZDoKB8mG6yQaW8EDMVFT2dDJ7c0EQ=; b=Qw6z/kLBpcVq/JoVK0qd8TrvOLjxRkkeofCkZw3VawfY33PEQp6ysLlKqe+Qpek5H+ QxTi+LoeomBzGF9tiUHgFW8dMumnWrf/fSBPYKothRxMPZgEK6GO8vhCtPmU6L04W4NU LK96K16jx20km3YCBU/fs6zuU2YX4PYzrDZLh56oEiP+YtqyWCbo+z/c8s+S/kYWkFsC 9uK14XAtSFVI4cLv0Ynj1p6InakNMLliOndxsCK6MefMkZVnILNEWuLPf6dAyZDhLtRa YU/QXfDsNWihyiNQNZipuzDFwlaVVSjDQEdhJ9FjpbUjW27X4ey4iMz2tSQWHtBMkLMY 34fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335518; x=1686927518; 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=3eVxch5HkrXcvtZDoKB8mG6yQaW8EDMVFT2dDJ7c0EQ=; b=c1QbobccHvfTfBoZ3XYTS5bgs76pZenIQNyF1kdwWxvAuTAzqRP3G4s30XG4DJ3IvH WyTH4zkhafF+IUuTXfaR1sNdVhmXaUZtqLTWHvUY0SUSWkMwNbz8mQpYR1N/odDQN2Cp u5GXPWdhZW3M7KGkyox7yUPILzb3Zw0f7WD0DZDvqVaF8Z3afwGtHLgU4Ao9MJCFIesh 66yjn46YrWH5GDNMvvKpE2cxflFbeyBNsaDsK8kEkJS3TmqmO+YdZ77ILVLg3PGUODv/ HpmAnDUe5/Pm9CqV8fNEfD/a1qvj3bhaqAw0jGfHJ3uB2yVRN+XT3hxlk8MxMC6vR/Wv R8UA== X-Gm-Message-State: AC+VfDzP2KhHf+22D+vIsDH0IR5gw4LxknHJDWw4z+sXN0HOcTBw8Nmx xH2LK9ZwiZZTHEb58NjaGzH/fWk1OZvw X-Google-Smtp-Source: ACHHUZ7Zbu4vTTvAzvR4DKN2J4WvTul1Bk0aZxVEhErOU5DQzLZoacUnDMePsK57bZidTKQfzfTq0jLeWMn7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:26c4:0:b0:ba8:4ba3:5b54 with SMTP id m187-20020a2526c4000000b00ba84ba35b54mr1544087ybm.11.1684335517684; Wed, 17 May 2023 07:58:37 -0700 (PDT) Date: Wed, 17 May 2023 07:57:41 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-2-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075842_263797_581A813C X-CRM114-Status: GOOD ( 30.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_running_1' for event 'imc_free_running/data_read/' WARNING: Requested CPU(s) '16' not supported by PMU 'uncore_imc_free_running_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 = rec->opts.target.uid != UINT_MAX || rec->opts.target.pid; - 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); rec->opts.target.hybrid = perf_pmu__has_hybrid(); 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) } } - 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); target.hybrid = 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, use 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) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1; } diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybrid.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) 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 = 0, events_nr = 0; - - if (!perf_pmu__has_hybrid() || !cpu_list) - return 0; - - cpus = 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 = perf_pmu__find_hybrid_pmu(evsel->pmu_name); - if (!pmu) - continue; - - ret = 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 = perf_cpu_map__get(matched_cpus); - evsel->core.own_cpus = 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) == 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 = (unmatched_count == 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-hybrid.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); #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 *evlist) } } } + +/** + * 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 handle + * events on the CPUs in their list and otherwise the event isn't supported. + * @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 *cpu_list) +{ + struct perf_cpu_map *user_requested_cpus; + struct evsel *pos; + + if (!cpu_list) + return; + + user_requested_cpus = 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 = true; + const struct perf_pmu *pmu = evsel__find_pmu(pos); + + to_test = 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 = false; + break; + } + } + if (warn) { + pr_warning("WARNING: Requested CPU(s) '%s' not supported by PMU '%s' for 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); 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 *cpu_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; } -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 = pmu->cpus; - struct perf_cpu_map *matched_cpus, *unmatched_cpus; - struct perf_cpu cpu; - int i, matched_nr = 0, unmatched_nr = 0; - - matched_cpus = perf_cpu_map__default_new(); - if (!matched_cpus) - return -1; - - unmatched_cpus = 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++] = cpu; - else - RC_CHK_ACCESS(matched_cpus)->map[matched_nr++] = cpu; - } - - perf_cpu_map__set_nr(unmatched_cpus, unmatched_nr); - perf_cpu_map__set_nr(matched_cpus, matched_nr); - *mcpus_ptr = matched_cpus; - *ucpus_ptr = 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 *pmu); bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); -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); From patchwork Wed May 17 14:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245267 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A605FC7EE23 for ; Wed, 17 May 2023 16:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Mfi6im+0g284ZcwtTEWuQu/RYdr96X93OmLiwnDrZpI=; b=rJFFSHADR68EUc 8Lzps4iI0D6xqtszTlXF7ca80mpxmPJn/2UjZkGhKUy8sfIVaVtp0AAorBKmsSjVm/jaT2mTWxch+ j9RwN7R1jBRxhXODBF51S9nLGP864YExiZJYmGbJ2GC/iQ2P7gFi8eTQyuQeLiKDDLqHVjp6poxdY mX2+b9BQoYCc8ifh0Vay870bq8JSD+/K3Hkp12THDu1kzp+TelvPrLWS+eTZagCwWGYmW81dCwRad GlEnMJd8tNvYzqRmdXjFTKQaVKlfOIt4sgAj/kk099r6Gzc7vTYLBfp+9JurhNOLh1JIeBoUnnYFy r0i55F0zV1sPf+3wKm2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJZx-00AOPF-3B; Wed, 17 May 2023 16:00:41 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIby-00ADNh-1C for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:43 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b238ee8so1496420276.0 for ; Wed, 17 May 2023 07:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335520; x=1686927520; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=co4J+RLQCrSsAkDbz+O0JQN5mf/3HC6cUdD7SOOuvnw=; b=KdRTZhvOJomjWjIy1icXpBmC245/59/sRUbHHt+KQUTyK7w6Yq+vR0TRAv3ybdI5OG TPKAdklu/9GchHUfMhrjwzE/2gk+b5odq2C0RdCfgi4V8plv6OCPfwJpk9ecrXuNxtJg Q/X5O4+GJ3RlbgXiLznCywRf7fRqCokSHUsclUyGIfiTOCVOFfoyyXXTnn2pPJwUzqK1 1cutCf5Tyd+VjNLNAR/pZATVHkIAI/R2SGAyBZ4v2hqbjXPm2CUKX/cUFzaGrqpklj58 ND3Hi/19GNwv+arcdVULoqX6unerqdZgvV/T4g/xhNO0txuiBEceokB9eQxUoHzY3cIV DpAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335520; x=1686927520; 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=co4J+RLQCrSsAkDbz+O0JQN5mf/3HC6cUdD7SOOuvnw=; b=YoZZUetjCE/E3sEIPIWcvPpxPEryqnErdm018g1iPLLyZTZc5QSiCi7aZCNCv9LSjL ptzMyF3/ibn0qk4UgOmUvLD0WrckHYWBoq0jYk/MoKVBsJnLhSQF07lnv7apny1pmp1E malFXevjcqdtn4pTY5c1bbXcpms8aOgeRaC7iosuX5/mTeFDoWfleUtAQLEsSEn19OaO 5sBErC3aOhb/Gdf2y7RkhKMvXQ+srnKxqxpNEg/gNZ1SR2U6Z7jMNgDuh/paIJ7j8lmL +yhUb0Okupjx6Pa8hVaSudpJJAecjabt5MGbjlAqohVs676sQyp6oQPDT85tdX197Uwn nGmw== X-Gm-Message-State: AC+VfDx+9Gw3gL6xLf2tbUzdUZDtrTJiPt0endgL5qpUDD08292RbxcL vaVtXXqE0U6mQL2MJT/xxbpZYQN8ACna X-Google-Smtp-Source: ACHHUZ6XUS995g82GPvS4dREMZj76DbvNdtPUZXP+4TKIsfpmu0mHvVd9YjkhzjZA6P40Xi31dE98BouBXNt X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a5b:5c8:0:b0:ba1:919a:8f08 with SMTP id w8-20020a5b05c8000000b00ba1919a8f08mr17403057ybp.2.1684335519983; Wed, 17 May 2023 07:58:39 -0700 (PDT) Date: Wed, 17 May 2023 07:57:42 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-3-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075842_425125_A0B86046 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *evlist) { struct evsel *evsel, *warned_leader = NULL; - if (evlist__has_hybrid(evlist)) - evlist__warn_hybrid_group(evlist); - evlist__for_each_entry(evlist, evsel) { struct evsel *leader = evsel__leader(evsel); diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybrid.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, bool precise) return 0; } -static bool group_hybrid_conflict(struct evsel *leader) -{ - struct evsel *pos, *prev = 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 = 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-hybrid.h index 19f74b4c340a..4b000eda6626 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -8,7 +8,6 @@ #include 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); #endif /* __PERF_EVLIST_HYBRID_H */ From patchwork Wed May 17 14:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245270 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E18AC77B7F for ; Wed, 17 May 2023 16:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=k8uFBVpor4xOGKDEJTQ4xQnZYAHqzuAhvj1Nlg5KiXw=; b=YvkVXZci52HDgU FcBfdWPGtD2O3400bFFVfWHMnPXr9tFlISARJnG6jh4p3aWkxUMnWjjQHe0TAFL+n7pwQde7EkCTF ECeaMT2nBuInZ3+IPKa5AtJfl69oz0AdfRxj+ke+cbFCzOZVVgpbVemyD5FkS2xDwi8brMmqsOges orOOLjUszxwxPuM2N82VsO14GMcDsc3Xf6CmTWHmlzhydJWjCdgrHWETFuqHpccVCyp/5Oe4POKBO g9t431EYUI+Mk1UQnisf1XDgDi5BPnHqDIXiUvqs9oyKWes2NsrO6q+s/WlKv981d7NBhwIrVB62m u4919pZ+m0+Smg9vPPyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJZz-00AOQX-0A; Wed, 17 May 2023 16:00:43 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIbz-00ADPF-1q for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:46 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-559c416b024so8538607b3.1 for ; Wed, 17 May 2023 07:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335522; x=1686927522; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=saPyrvzGXhKRl+6mw7g0Gp4BFuZvM56Mw/9QfNyRLG8=; b=1NiIJfU9yHTLlVidnurLRr0a0DBqYJFjDLdH9GPkaA4MhNt8CX7qBlqfLeK6YeZIOq QdIf4XRqtK1FC5uPmSVsKhpNKXu0BlSbU69RqvuV3HGBfzAwEEOy9aJbVgkT22HJrqoX dTdHfkEJc2fnv+6zQxBaZ4VDcymdmR6AbTt153pd6nxBNiAmYxbjvgag5MmDFfA6zhXF DaxwT4FXnCulEvqVlkYTJ0HFO5+jH2+65OyF7SVA8dq7+Xpxt+bE2SbZQujCiZrA/Ntn PtKXZogZjjRBKSOHiyPeFRerqO3DGqAyKG+YRTZblQUY3uq4fkd3DWWdr3OvmIkuzZG0 F7rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335522; x=1686927522; 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=saPyrvzGXhKRl+6mw7g0Gp4BFuZvM56Mw/9QfNyRLG8=; b=LqonkPA56oYNMZp4TA/nTk/aufJZoDAcJvPYjUSoLB2mPdN+2uD5vhXxWLwyNEXFL3 0Bjs/LBsJEgBBdKEyEwl5zzlqJFt6QNWyOZU4Bg7H/NtzQNBbJ91MjHLqITHEOcucLTJ f7iRmrKHPttvn5Tlc1Y2P7HbxNSOQHnZXz6EAC9IP2ZKa00ItDBVEp3/uuoo9YOHjNXC bWz2J1XbPUWqa9SGubKtwS91JBZtKbAAmJe/ZV2OrHtMWODf+FG6EGk2f4JAZ9o6iAf2 hzEn1d1qPywh1T+c3nkQRwu8Xqe3m/YZL8NFNdK+Z8swqx1y5EGtJcRq1t9TCSAlyeFR bBnA== X-Gm-Message-State: AC+VfDxIe98lcKL6VaVlLmYwc+kdrS7FRzf89VDpx67WR8AKY8SzWXg/ 9AJvsIzEjk6sQhsBtjRU7IQ22+BsKe31 X-Google-Smtp-Source: ACHHUZ7pgldHe5XaiUh0rVuMEtTQQMyzU5ZSMv88uu0ryr7fgsytJbHQhawdAzQri7V6qN2kOEOVdsQOrb9n X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:7e11:0:b0:541:61aa:9e60 with SMTP id o17-20020a817e11000000b0054161aa9e60mr24529149ywn.6.1684335522322; Wed, 17 May 2023 07:58:42 -0700 (PDT) Date: Wed, 17 May 2023 07:57:43 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-4-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075843_616431_064B8695 X-CRM114-Status: GOOD ( 23.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org __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' 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/evsel.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); } -void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) -{ - struct perf_env env = { .total_mem = 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 = 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 = 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..85f2bd035a94 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 = true; if (rec->evlist->core.nr_entries == 0) { - if (perf_pmu__has_hybrid()) { - err = evlist__add_default_hybrid(rec->evlist, - !record.opts.no_samples); - } else { - err = __evlist__add_default(rec->evlist, - !record.opts.no_samples); - } + bool can_profile_kernel = perf_event_paranoid_check(1); - if (err < 0) { - pr_err("Not enough memory for event selector list\n"); + err = parse_event(rec->evlist, can_profile_kernel ? "cycles" : "cycles:u"); + if (err) goto out; - } } 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..d1e6d23bee3e 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; - 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 = perf_event_paranoid_check(1); + int err = parse_event(top.evlist, can_profile_kernel ? "cycles" : "cycles:u"); + + if (err) + goto out_delete_evlist; } status = evswitch__init(&top.evswitch, top.evlist, stderr); diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybrid.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 -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 = PERF_COUNT_HW_CPU_CYCLES | - ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT); - evsel = evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - config); - if (!evsel) - return -ENOMEM; - - cpus = perf_cpu_map__get(pmu->cpus); - evsel->core.cpus = cpus; - evsel->core.own_cpus = perf_cpu_map__get(cpus); - evsel->pmu_name = 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-hybrid.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 -int evlist__add_default_hybrid(struct evlist *evlist, bool precise); 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 5d0d99127a90..b8ca99afdfe5 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 = evlist__new(); + bool can_profile_kernel; + int err; + + if (!evlist) + return NULL; - if (evlist && evlist__add_default(evlist)) { + can_profile_kernel = perf_event_paranoid_check(1); + err = parse_event(evlist, can_profile_kernel ? "cycles" : "cycles:u"); + if (err) { evlist__delete(evlist); evlist = NULL; } @@ -237,19 +244,6 @@ static void evlist__set_leader(struct evlist *evlist) perf_evlist__set_leader(&evlist->core); } -int __evlist__add_default(struct evlist *evlist, bool precise) -{ - struct evsel *evsel; - - evsel = evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - PERF_COUNT_HW_CPU_CYCLES); - if (evsel == NULL) - return -ENOMEM; - - evlist__add(evlist, evsel); - return 0; -} - static struct evsel *evlist__dummy_event(struct evlist *evlist) { struct perf_event_attr attr = { 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); -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); 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 *attr, int idx) return evsel; } -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 = { - .type = type, - .config = config, - .exclude_kernel = !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 = evsel__new(&attr); - if (evsel == NULL) - goto out; - - arch_evsel__fixup_new_cycles(&evsel->core.attr); - - evsel->precise_max = 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 = 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 evsel *evsel) evsel__set_sample_bit(evsel, WEIGHT); } -void __weak arch_evsel__fixup_new_cycles(struct perf_event_attr *attr __maybe_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 *sys, const char *name) } #endif -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, enum perf_event_sample_forma void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); 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); int evsel__set_filter(struct evsel *evsel, const char *filter); From patchwork Wed May 17 14:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245271 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ECD63C7EE23 for ; Wed, 17 May 2023 16:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vvnDWrMJTKqFGxVFFOcBzExhLcyd9TllptIVWvTCUbE=; b=0B6Krxv5czmTqe MMZHX4cZoD8Xqs9I6cAC1CyixtmSRFKt3RCbuBvqXaxRFmesZCF78dWVvEmGsSj97xFnTWmDbtbpj aACrwpGW8m/gcrzQj7WD5OGAj358/4t/CVweVajPCA+VWo28F5gxs22QVUfwfrfb/etGcbq/HEekT 8BiL1vfLxmvUxWgYpTuExSduGaGEjl1qzLu2CQQ7Rzu/oW5kGF3ysxJt+cEjTkdUseHdiyrcXkBGt a9zozbpn2A0ONC9G0azMiwbNv/AnEdrvuBy+uN6IzU/Lguh5WUolYIb6Vy7XpRuWCM37sQeWjT9x6 NxDRLeVGE+3449JcaEeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJZz-00AORg-3C; Wed, 17 May 2023 16:00:43 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIc1-00ADRG-2N for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:47 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba87d7d2988so1394030276.0 for ; Wed, 17 May 2023 07:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335524; x=1686927524; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=teh0Pm56RFznH4cxkDKohWyHgUByyEY0rmKe5R5AKbA=; b=wWB8dU0B/1m8OAWhyWPhbMoCb17J0pVHH/Nn8OOvAlhtzMj3PFhsQv28cHl2/LKmNd OoSbnLQo9Xf2ARgZc4vVBjIyoWOoNa9Tf0g7QdD6stBADHbAD5QzTmRJN1IIoml0rSra qMzZd16fsFwGpKJB7AuKGZPB/gwTY6H0yRwhXamE/WM4jKlXjykrkBAuhxe1Xgt3BYDJ A5ICdu5Aqdx3OV8ioh21rHffUc7AL7tZlQf/bkTwIwlnpRR8iVXX07CQUkCdqWEzJ0Z2 A57SJD4hFnmRcw+Dj4IAtnOg8vbOCOuJ1n40PV/YySW/8QgyuELnt30DU08bzW5dw46V AiCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335524; x=1686927524; 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=teh0Pm56RFznH4cxkDKohWyHgUByyEY0rmKe5R5AKbA=; b=abEQHyqGSpGGis3NR++NeDMhXXbzuzKfHY61MOBTFV9N41+QOPt23U+BRdlQWfML/l aJginOlBdf3qwiLHAAStqvq1J80CRzbJ/on0Pe+TeblSzXIFSuoBtscVMbYZl+suX7cL 6q5lps5Eqt8v22d+XXdf/DsCK9FDGRJ8rzyHykB7Z97Qb2JYGblafGuQ8xzg45HK1HOt pC575vQ0RQ7hoPbxvbhTRJeOG/LyuMJHEZVvCtrXkJ7vvXHrMILofdFG9Zww8JB6Xxjo ojKoHfxvPu38owyFUYaSZNLjTm3JEus30gHJ8cha9iH4V3xIJG9khpsCN0vGpZKDqwDS 6x6A== X-Gm-Message-State: AC+VfDwydWPAtIqYELOOUU6FgX8wKgjYBamgaat0KEjlFSznRurNxueo pFDCeQsX8LksqFnY6PEDtSo8plLVPW9b X-Google-Smtp-Source: ACHHUZ6aWp5bxbOg1yJ6tAm7uZDYxctfA/HJomA7YEauHsizgUYJzlmvyLfg+V0tXVLIvDwNb5sUOFMeJ+NI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:b10e:0:b0:b8f:5474:2f33 with SMTP id g14-20020a25b10e000000b00b8f54742f33mr1624564ybj.5.1684335524558; Wed, 17 May 2023 07:58:44 -0700 (PDT) Date: Wed, 17 May 2023 07:57:44 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-5-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075845_775757_BBE57DBC X-CRM114-Status: GOOD ( 15.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 85f2bd035a94..42135be760ab 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 += db-export.o perf-y += env.o perf-y += event.o perf-y += evlist.o -perf-y += evlist-hybrid.o perf-y += sideband_evlist.o perf-y += evsel.o perf-y += evsel_fprintf.o diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybrid.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-hybrid.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 b8ca99afdfe5..cb996d94bd64 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" #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -677,6 +676,20 @@ static bool is_mixed_hw_group(struct evsel *counter) return false; } +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) { From patchwork Wed May 17 14:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245273 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D6BAC77B75 for ; Wed, 17 May 2023 16:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s08mDKDN46NWbm70sxlAhMX/+DbV4noeD35e6UQyMVE=; b=Ana3d7ZaXNEv6O JQ697huq/YNKrX4eUvOg/QrKk2srUA5Sob3S6ivsnsBUaYEyeBGfrhcWm931ZrYeWnaNmTIbbq/9R fUnB+idIN+VrGI5Hn49QpKM6VoI7yvkTSKzqbjPp3Xu8uA35dfkqjzf0GZqj5Gg5RlZ1WkUurmhME PZGOG/SVnVAeVCict9Z6e7q3fGEJsJYI118g+eXJutC/MpsOxutS9RKodvWJA5zaUtt9Vu2EckR8k /noAj9w0sZQaw74gZ2Hgluoi2HyX1RUrUzpAiz++9zssMmexJBdfmkMjuAjk3TvVOxDNM+06rgYQ9 URgJaWtpu+1591KYR1EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJa0-00AOSH-1u; Wed, 17 May 2023 16:00:44 +0000 Received: from mail-yb1-f202.google.com ([209.85.219.202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIc6-00ADSR-30 for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:52 +0000 Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba83fed50e1so837089276.1 for ; Wed, 17 May 2023 07:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335527; x=1686927527; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=dGJ3I0sfnW9+HhqJrbZVaDNsnOcUvsKxgQCM/RuCj1g=; b=0fdnUhY+TMWb9aEJBfbvo+Ecs2aVlGpoHeshyuUuYq3uNW0RTZbbnZTQHswiL+XzoF 6Rgv++pxqPZG8yrFpDciCSjvrdPCtmj5wJ5zvRi0HcFLMfuVH2azHA8xeZtanM4KW0i+ qZXO1Y0Y/SCyUWSmdV/rPGFoOh28GmwSILrXaq2dyHMYDaHopWy/xYWJBlktXJia1Nsy MFGyeidGam/4Q8nA5zl2XvS3kHh6rM/TOhHaaZfHhpHJ6nBZFBs0UA1NO4VOpLM+2QFm eWi1qvJylP9lPcIa0JfUnYo+T7o1Jae2GTu7wBIMHLTSH73PKSwbe/DljbjGQqHfR9gF 7wSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335527; x=1686927527; 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=dGJ3I0sfnW9+HhqJrbZVaDNsnOcUvsKxgQCM/RuCj1g=; b=N+ORntWBAl0baQEQJJTVHh8dswHo9rc7S128zA0iMJZesF5dkyq3ziKOybX0pOh/tX /4n+tIcsFxbIrq9bZjP0FY6CN23HsF8IaWF7y3Pxnz+bJItqcteQ56gOjcIofdiOCwqh xpkKqYVhg5TlUObGMIcGh1vuYzVYZzYZGbyUA2mAPplXHMp03n8G1SEORK2wdSJQuVVg aULTjZstnd2dTBOXurPCjMpD7wvbPIJ7kxZsj1/91TCSA+vtORpp7pcfZT7lfbjlsnyb d/sAx6XAnGlLELEqMgdsHVngbkJOwS2C+4xEigCdufHWZyXxzQCWixo63vAV4AS5RAZw cm4A== X-Gm-Message-State: AC+VfDy+mK6jtXnhfB2CswDdx9u4xAawstIyBYTkpUPZas80D5RlRBys 80M4qVs5OY0s+TfHeUpa7QJcq8xbboIl X-Google-Smtp-Source: ACHHUZ6TGmbGisEH9U1Doeu6RHHiqlYqMzqFuYh0bS2DqarU1ktis49bisL9SmtMJub1VDAq7mlqISDKyEWI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6902:104:b0:ba7:8628:93e2 with SMTP id o4-20020a056902010400b00ba7862893e2mr1612679ybh.4.1684335527084; Wed, 17 May 2023 07:58:47 -0700 (PDT) Date: Wed, 17 May 2023 07:57:45 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-6-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075850_970167_B890C03B X-CRM114-Status: GOOD ( 18.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 @@ LIST_HEAD(perf_pmu__hybrid_pmus); -bool perf_pmu__hybrid_mounted(const char *name) -{ - int cpu; - char pmu_name[PATH_MAX]; - struct perf_pmu pmu = {.name = 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; 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) -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); 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; - if (perf_pmu__hybrid_mounted(name)) - return false; - fd = 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; } +/** + * perf_pmu__skip_empty_cpus() - should pmu_lookup skip the named PMU if the + * 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 char *lookup_name) LIST_HEAD(aliases); __u32 type; char *name = pmu_find_real_name(lookup_name); - bool is_hybrid = perf_pmu__hybrid_mounted(name); char *alias_name; - /* - * 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 char *lookup_name) return NULL; pmu->cpus = pmu_cpumask(dirfd, name); - pmu->name = strdup(name); + if (!pmu->cpus && perf_pmu__skip_empty_cpus(name)) + goto err; + pmu->name = strdup(name); if (!pmu->name) goto err; @@ -964,7 +966,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); - 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); From patchwork Wed May 17 14:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245222 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2227DC77B7A for ; Wed, 17 May 2023 15:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TluaHf0ZZRcz4M+qWHZjeCfH+MxvcC1B6Zo76YV6zEg=; b=CkOKRrIEOvaO0E Wj3ug/RJIrYMY9Gdpta2PfTag+j6N4vpCrdwLvGaRutA4Xq+16ivY27iLfGnEIaFzqHUmp+8M/1xA 9JLfUuNq8OSSzFqXPFP5M3614HtZGBf7HdH5HLSKPwruPxX1nCcC68IuGy/EJtuRORxrk3BglCih6 Wi/idCklZS37YTsy/N2JW7YmOnRQeQAusesH7GqVT++6MsTbKtlUJ56i9wY4MNmMhOzubVKhs7Ghj 1dVBJeRZ0AzDFuB1WpUZeAaQn13OUVvdW8um7zoBQNKStUFry8yI1DkdEGBsC5BAU++8EW8r+d2Hy WD1AvCkE3nMBPCZhET/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGc-00AKYj-2D; Wed, 17 May 2023 15:40:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGY-00AKUS-2N for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=M7JvoC3iLPsTar91Pn3VOoDH0ua0dyX+PVCo/jOZfiM=; b=gcu5VptjbNWnhiSsWIQk+a3d6n fa5rsJYRDNZi0QNXxDytG0nb3vjMbTdjsBKF6rmam/tXH8G6gvlQcA+7PT+YYk0DcxBclBO/vDslF zH4Yf1qaz45sOmmLmOVC2NvTQQR0GH2CW/SGXd0d5WfneYw2Fm/P7kTnDVLGIHVtbSs9w/i1svLNX groOcJcFHJVoacQ9e7IwP3nD8xmdy5XDCHfVdMMJO++aan8qD/YgWR9ktdfOgizp805u0Fdxl2/q8 Lb628GSH5FJv2v4x5ZpN5CLFTQwRuNeBMNReroMYyav5hErjDVzV+z7S4/nJTvgiM9PAPRcMk6pAY sr0cuUhg==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIc8-00DFq5-2U for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:54 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-559ea6b1065so13810807b3.0 for ; Wed, 17 May 2023 07:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335529; x=1686927529; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=M7JvoC3iLPsTar91Pn3VOoDH0ua0dyX+PVCo/jOZfiM=; b=SR1oODanQJ57O3lCwCzldhf40RyfzaHFodbuZ4dyCVKH5c90WuytcRyDMFZG6JI14X ofT0rA60mNO8JN+Zlzow+H0ZMNq42GIvgIiEJM57kunHKqrGy5Hnn2vqg3scdF646ivM pRrvg/mJng7FgnydwyaR0PCuTDsYdYqpcBF+5/FLeR8qkKHxDupiq25hONltK0YMz7fQ Vdue9njw5Y6DOsnIsAceuTnmVgWlnRP4ILzBMNo77/3k73GHUXZ3tTeb6OFJrDZ8ulHG k9Ei5w+1MuplvLBtfnx0wEHwyn89Cn/i8YktgQgTEK8ub4BbUPjyxJnGgFSLU7QLxXbg a8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335529; x=1686927529; 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=M7JvoC3iLPsTar91Pn3VOoDH0ua0dyX+PVCo/jOZfiM=; b=USuZfoh3x/YXb56GsXoeuCW+0PHtnREFPPhVclCcvEGZdca87iYAOa8duCymqXZdhA fXWVE8GIpvRJJec3on2Hw4znkIgEyr0fshGzdAdSXjFbFDpPeWSpNn+ZZu9StV8L3EyY VYnM1+jM6w2wp79PTvF8+eVz8aJDHhVY5pmv8zLH8VzUN7xC3vOxSrFEPpJitzduVLv9 25wAAUN5CJgjZhpsZr7ichA43PgKsej97fKIoiJXip58uhO5H3rDE+4wQyEtKxFyAwK/ hSDo1zIbc/LCUGGe7/eQSB3/gWWNKf6CBEajUobtApJgBC2OjPVskIVhOL/x6UM6FvVn fNxQ== X-Gm-Message-State: AC+VfDwxbeeTL/XeIG55/DFipMXgxB5+kl9fcuBhOOqOI/pLzw7s08oD N2b8qmqm4jgvjZane0UDs5sqbdi+PDoM X-Google-Smtp-Source: ACHHUZ44pWiXmYrxWRfX2o7cQvQA6ozXCf7evHZDMWgVIRN82ipaAcPs0zIRQlrgCV4Lo0MxXcqAdZzYuVPJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:c402:0:b0:55d:ea61:d8e9 with SMTP id j2-20020a81c402000000b0055dea61d8e9mr20859476ywi.7.1684335529254; Wed, 17 May 2023 07:58:49 -0700 (PDT) Date: Wed, 17 May 2023 07:57:46 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-7-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155852_864228_FCEC782F X-CRM114-Status: GOOD ( 17.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } -/* - * 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 cpu 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]; @@ -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 = { .head = head, .name = pmu->name, - .cpu_name = is_arm_pmu_core(pmu->name) ? pmu->name : "cpu", + .cpu_name = is_sysfs_pmu_core(pmu->name) ? pmu->name : "cpu", .pmu = pmu, }; @@ -1649,22 +1651,27 @@ static int cmp_sevent(const void *a, const void *b) 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"); } 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); } 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); } bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { - return !perf_pmu__is_hybrid(pmu->name); + return !is_pmu_hybrid(pmu->name); } static bool pmu_alias_is_duplicate(struct sevent *alias_a, @@ -1718,7 +1725,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state) pmu = NULL; j = 0; while ((pmu = perf_pmu__scan(pmu)) != NULL) { - bool is_cpu = is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + bool is_cpu = is_pmu_core(pmu->name); list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event = 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); 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); From patchwork Wed May 17 14:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245272 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F3B7C77B7A for ; Wed, 17 May 2023 16:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=odvbOQpSUZEw4Y36R9No0s6Z8+0tfmAQJUZaW75B76s=; b=P0RiYCFV+Re95H pBKzYeSH6SseM1K8OW8E11iVEJS3vtVuPFLAolaYEgRDCIokQHmSNYsk94I7OpsU+F+QF9I18YmQ2 tcaTXdfuS2+StmdiuTriRHmcn1IYnTtLAap+v9ZETq3Gcc/Xu13pR7kUTFJoajKZk6AUh3Wud5G6L U+SSWHftO0mm6QzV+n3pBCnQ70NL7UXRAOLON97P16N1/VW3ezp2B4kOcbBhs0wbOcOQkGOdLsSaI WSr3zXYvKNo7ip3JYP7fB6SVPRkMoiy3G/DU/jtMUCRRa4zy6XNnlItcbxG//v/lGeeeyv8jpfzR0 M+SLB/ZNgzrdFMVzP43Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJa1-00AOSz-0a; Wed, 17 May 2023 16:00:45 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIc8-00ADUL-2G for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:54 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8217b3d30so999277276.2 for ; Wed, 17 May 2023 07:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335531; x=1686927531; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KA2y3jyQTsl7bjOICY6NhHPKj7ufhNOPyvMqFoPtgZA=; b=nljeFfxFSjqFfJqFStpIFN0yXSLDlIJAsXrvpuUvYrzfgwPDYXCv05IGjt8JAYLOMu GIWqE6phlYNkqkWg1UlvdP9uFzTnCLcKUhhQZhxm0Hpim9t+Z0kHz+ttA/5X72bOa/HG gIXZGSBzf9lnCHE0W2XP4S6w8Sqj0vZ+OnuTQAtK0jDwkc52avQEgxhjfSnwPT8NTkKm ZqGMOALc5jdW8KC/iXGwy2CMR5Xz/bEot5QGTbz3PBAgzvxOa/0U+N4xOxh07EgCnS1a hV4fKa3uvhrgW4ZWmwNZZGwysWZKpw8xHvj6xyvlf+wFUmfwd6vofN5SIYMFcd4Usfu+ 8YBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335531; x=1686927531; 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=KA2y3jyQTsl7bjOICY6NhHPKj7ufhNOPyvMqFoPtgZA=; b=PIZhOZVyHiJKqg/0jukVsME3TuLniIR953Qhf7ezFrrVmNu2YkOzdrSbJ7Pw7Qdu0G tN698n2NmYNuHeZ2VfmxRUvILRborgSGvRgMWPWHle1Ol6Xc3gPv/xGFis5ywTaze34X /c7swHjQuVQWw5mChSJ/dZOe0adIf7+Poy7n6lWMLOvyYG+izvBxqJ9vdAe4YretZI4u bhzs75WivOzqeHS5WKQgGloPybqYm5lvqVe2HRUSVsc8FsFNgmfLqOUOwVRfT1fZL3cB qRycChBu47tEQbwxMR7PoOEe+UtI6e2ha2gssHVWuBRr2CGM4obL+ZrQ7VReqZiX1gBQ 0cMA== X-Gm-Message-State: AC+VfDxv7iqSdHd7hecYFx/PMIeFfCYR0z3eD4ZTgk4wUCHALfDNWqxk bpoG60TmKsMsdLoKNfUqFkxw20Zclkdh X-Google-Smtp-Source: ACHHUZ7XjP/AcWyCffYYC9nXeJBjM5TS+YMrfsqU5e91nSKBzb1vGFoVNbDb5wbW3KyZZ72fzUAIER8KKBrj X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:3211:0:b0:ba8:2415:f27c with SMTP id y17-20020a253211000000b00ba82415f27cmr3416215yby.3.1684335531452; Wed, 17 May 2023 07:58:51 -0700 (PDT) Date: Wed, 17 May 2023 07:57:47 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-8-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075852_744469_2EF597AF X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 char *lookup_name) } pmu->type = type; + pmu->is_core = is_pmu_core(name); pmu->is_uncore = pmu_is_uncore(dirfd, name); if (pmu->is_uncore) pmu->id = pmu_id(name); @@ -1661,12 +1662,12 @@ bool is_pmu_hybrid(const char *name) bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) @@ -1725,7 +1726,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state) pmu = NULL; j = 0; while ((pmu = perf_pmu__scan(pmu)) != NULL) { - bool is_cpu = is_pmu_core(pmu->name); + bool is_cpu = pmu->is_core; list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event = 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. From patchwork Wed May 17 14:57:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245215 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4550C7EE2A for ; Wed, 17 May 2023 15:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FS27bJ7Cj8v+w4i8HishofrhD0f8GVDSrrwlvRZb5C4=; b=4NEZ8tAO98uNuZ qDY/MKSVFDizAA9ucEnQj7pB4k0PuCuLAYKXG6hxg6Ryq3RdSsxVnsocDe/f/Mz4UGIzIxkHA3vm6 TdzJ8jWgqWAfOlQzKpmt7FV5c+YrwOpy01IbEL0HyR+yP4STp3fnKG2cudivv0aODCCNm2J0QQ0gA TzVFSh2ZUt3rPJwLAhhLAjkEqX7v55oAfaFmaR16QSTxZvKKjaWOA2q5MEXJixnRq6HAlWxCMP4/h tZBxYceP7maeBrMLdUfjWcvqIf+rF66OUgNLjFUJ+bZSsMenZ0rBqlIi9tuyacMbo+E8oFkY9z/9C rLFvtpSqAWg1Bx+Uzq5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGE-00AKIY-14; Wed, 17 May 2023 15:40:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGA-00AKHE-0Y for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=CJew5c6+Wqs3H0xvybKSYHiC9UyD346jsUjXmSkm68Q=; b=Byc19E6YwUZ1ab3jvsolXQXfmx GL9LgIMTRIbvumLykSOfxzpiY5+S3ClfOFPFbMVkv+OE0NbRaKxGgMx0E1yAHrGWjZMCCDOYZtyno b7hhykWElbY3DvlDpLQcFtc9UHYgLDGBfiZgHSo1d2yIO0gWxLA3PXD/Y3vA/v64R6zn9bnnaVpAg wOsKnSneQAFwzn9Hh5KhFTOHFGaCiH5X4cG+b0+I2wAPt54F6KyiUahQrpuuiarEf5Ijm1eTF5+PU 5K0KQK9T+fvGsXwW+zhz3e/v5MqhowDbaQd1cfvtZG39ezb25CnVuj1Bpv5L1KcFDn3Y3w721/CkS adLzqS9Q==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcB-00DFqZ-0C for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:56 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9963a72fd9so1637306276.0 for ; Wed, 17 May 2023 07:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335533; x=1686927533; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=CJew5c6+Wqs3H0xvybKSYHiC9UyD346jsUjXmSkm68Q=; b=E8lhndMhmlxnQknUI5Dvjo+mrBhFisWj9VZveazhd506WZHGDpEpNTAA4Yddkqsl7k jfJyBqIDjPc4Peu1Z7l2PLIpT2OlwLN7k0yil0b3L0Xc6ftQVuWqwQVvJ927+frXyQsj il0XlcJNxtqmGmmJdQRikIaxVYSOSKzWndKRmHzkJ69L03cnjBBiarQPneD4eDyD0TCM zjVeMG3cFTWRp6JoHxnm7w1C4ofoTabe5R7ibfucFb4zvMJKtbsuhDGR54Ka+tvGrVNf rnr2fcH7a6n/tfx+ZH/tH/9efv5MVq39uvTuw1pr0TAIBTs2xJA1FPulheWN0xhen8jk XmXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335533; x=1686927533; 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=CJew5c6+Wqs3H0xvybKSYHiC9UyD346jsUjXmSkm68Q=; b=GhqvbDsy3PRZAc3Iy6n2TeX+S+5HKvKJ1kc/XV2j0PHRgYB6LOwdKAkaSTX/M3O9jW JKQ2UZ/l1CO7C/jUTXhG8DDj+ju4Kkx9nvnnaGmIMy950g69CdboFrCMLwO+E1Frc7Mw Pkdg6pzyD4BPntwedr9YQh5wmHbKGWB4gLth5GFCFPkN3osn6DjGX+iv139xb+1K8PBF xjheVee+AclzU7zKNiyE/C+4+3AQxIc1Em6eL13E2XeFesdXxpt3EEF5+0LxczNW7LUo REdlfcOayYTenaaq00J+emkZkXrlN1fWNPnWwJBGomUmXyex/CCw+Dd6oIbQE7qFTtMG bMYQ== X-Gm-Message-State: AC+VfDyIeIYTvSNLY2JiC0Fhmo2WtBBbIpR7lxuab9oZbdgHLW4Oqzyf IUL/4BECwWOiQ3L7fLhu+ef09F60lD4a X-Google-Smtp-Source: ACHHUZ56HXknOGNqzw7/nwItcz7tOnm7evTpjMpIUjxB0+elX8F+7fCvpauDoNX6mFTOCbcf1NkWmM7mzMNu X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:6542:0:b0:b95:4128:bff6 with SMTP id z63-20020a256542000000b00b954128bff6mr24731255ybb.1.1684335533487; Wed, 17 May 2023 07:58:53 -0700 (PDT) Date: Wed, 17 May 2023 07:57:48 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-9-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155855_347870_217D298E X-CRM114-Status: GOOD ( 14.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }; -static bool hybrid_scanned; - static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); /* @@ -2026,12 +2024,20 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, bool perf_pmu__has_hybrid(void) { + static bool hybrid_scanned, has_hybrid; + if (!hybrid_scanned) { + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid = true; + break; + } + } hybrid_scanned = true; - perf_pmu__scan(NULL); } - - return !list_empty(&perf_pmu__hybrid_pmus); + return has_hybrid; } int perf_pmu__match(char *pattern, char *name, char *tok) From patchwork Wed May 17 14:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245214 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8675FC77B7A for ; Wed, 17 May 2023 15:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=50U0ih4jDmCib1dT9dr4q9gnUu25NGBdrsrFTm1noC0=; b=Hd1cyaYELSM9Gp tlZ6aHmH4tg+Iu3U7gb4myqWAzfvuybAjDWLzy4RPqIG0PcPeyffM5ucKbuvQ9pq04eFrx3QEVKrK HWTsAkKQxqCYzceT6Yw3D+f6P5Y0U3C7BaOIV0xrhgk6FHKlNOY6KQ30ZGdeaePLLpSZREW0wvH0N 4IHu6zCNHk/OTaylfmhxlf8qzQhDxA61j19H5toFWlcWux4d5XEBZUrxuKtFw++2ED9Yi8RX9bTNd QQimu0y81ELvbGJYZyrcEIrCI85wjDbUYu6zYRwRtwwTUZlTQLnKb15bo+719ITy4QDl2gi2k0FCW RpRV3EoNfLn+Vdt+BXYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGE-00AKIr-2n; Wed, 17 May 2023 15:40:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGB-00AKHc-1q for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8jJ35DtNbRKB+WNziMleSSiJd5T6wAbvpTtW48pRcrc=; b=gLqCgF0ZQXBHCrg97Ippn8zQkM NlxkE0EcV32fA3gy5VRksaeBsKleU5hNYKVz9HFUemhjx7a1Fzbkb2BZLaGVmuQ2CW3GuV4cdqx4P vDF0QUrxaFarWCTRCYd9WfLiFfkxXtfQa5xanaMpUW8AsI4EJHrCkv10fmd73ER5+pgXdbYbJujKn 7cssY4ljsQOdpQImJ4xEec1orlGRs+vy67q57UY+n/FZ7Bkbqu5TaSe3m1HhVXT2vdKHAk6o4A2AR 9Vj5GSjTwKrC6zAhPHwKytikkPS73wGuI/XRNYK8NGgs5Owgm9MJlTzMFb9cUwN7frxdITRnTgJxd atNsc33A==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcD-00DFr9-0y for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:58:59 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561a80d872dso12440797b3.3 for ; Wed, 17 May 2023 07:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335535; x=1686927535; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=8jJ35DtNbRKB+WNziMleSSiJd5T6wAbvpTtW48pRcrc=; b=lKBvUUw2Vn96syerPxcDZE8E2exBej8Qb7LquIlOdgJx3jGYp5ksAsA0QVnAo/nwpW 2Pqmmb3BEwD7aGpyrQ2kqWU+kVsplbxKLthqOOWc+PDoImmrOOLWr0aEVQSkUDf+LIIB 0Tj/fY/g1tY2dN65yYIdvO3G/NoOYSuEVrPxzNEE2oKevgNYYLi5EaoIDG+MKi3tpnHk wcdIQL06vTNGYlSDaIxlGNjwlh/Uu5EN3klZKgagv2rugGSEIUhfMmNqT0J3x7m2gx/n rZoeXumF8pm028Ian1W1kWDXFofi5SZUQjkypWkmYWOTHK6GxEllZzSLp+718xsnwNcv sFVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335535; x=1686927535; 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=8jJ35DtNbRKB+WNziMleSSiJd5T6wAbvpTtW48pRcrc=; b=UDHBJnnGqVP0rrPZd+fjOzs6GrqR9+ilW0bdsc5c+bqyCMSqx/OZaXLcvLZHiIzVJT bErQrMfYp1BMtaJxcZVLKCU/PcrPgbJJtg4G3/2fZatRDPeEBnHj38a7tSn7pGB6qq25 XFqvEQEAK5kP6fMtRqBZ0h9T2KSRz6+rj8oof1Htl3zaJOuTQkwBPgQPncayRd1O6UuT 7Pgc7eBtaEa9IwO/71lvDt6R7StDP9r9w1PUxcG6THQy4anQ86uYsvXqNF5xssJKYpCb 5NAvw3fP5iiDZFL2kWJzbM/HgBmrbwWxc/bhceeXXYwIC04BiW0XPr8qDb+q4nt83amg SiGg== X-Gm-Message-State: AC+VfDxQnh/y7eeMJC/EkxaNeb5BRAVzaYyxv/mKlhe2E2jnQyH/Zda2 mY3dCitQvSnXDHo5vPqKzHIOgzPSOxPG X-Google-Smtp-Source: ACHHUZ6Xm7nhwlZ+D6gLz7kiTfpTYaq3ElipX/SETPRjeTCx8hdgsnGs+yw+2XZ4ky6eAZ+u2VoPTXVxGB45 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:aa0a:0:b0:54c:2409:c306 with SMTP id i10-20020a81aa0a000000b0054c2409c306mr23372095ywh.6.1684335535732; Wed, 17 May 2023 07:58:55 -0700 (PDT) Date: Wed, 17 May 2023 07:57:49 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-10-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155857_388039_CC0FC71B X-CRM114-Status: GOOD ( 19.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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" 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/evlist.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" @@ -12,9 +11,6 @@ static int ___evlist__add_default_attrs(struct evlist *evlist, 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 = 0; @@ -25,15 +21,24 @@ static int ___evlist__add_default_attrs(struct evlist *evlist, return evlist__add_attrs(evlist, attrs, nr_attrs); for (i = 0; i < nr_attrs; i++) { + struct perf_pmu *pmu = NULL; + if (attrs[i].type == PERF_TYPE_SOFTWARE) { - evsel = evsel__new(attrs + i); + struct evsel *evsel = evsel__new(attrs + i); + if (evsel == NULL) goto out_delete_partial_list; list_add_tail(&evsel->core.node, &head); continue; } - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + struct perf_cpu_map *cpus; + struct evsel *evsel; + + if (!pmu->is_core) + continue; + evsel = evsel__new(attrs + i); if (evsel == NULL) goto out_delete_partial_list; @@ -51,8 +56,12 @@ static int ___evlist__add_default_attrs(struct evlist *evlist, return 0; 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; } diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/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" const struct sample_reg sample_reg_masks[] = { SMPL_REG(AX, PERF_REG_X86_AX), @@ -286,7 +285,6 @@ uint64_t arch__intr_reg_mask(void) .disabled = 1, .exclude_kernel = 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 = 1; if (perf_pmu__has_hybrid()) { + struct perf_pmu *pmu = NULL; + __u64 type = PERF_TYPE_RAW; + /* * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - pmu = list_first_entry(&perf_pmu__hybrid_pmus, typeof(*pmu), hybrid_list); - attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (pmu->is_core) { + type = pmu->type; + break; + } + } + attr.config |= type << PERF_PMU_TYPE_SHIFT; } event_attr_init(&attr); From patchwork Wed May 17 14:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245274 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C778DC77B7A for ; Wed, 17 May 2023 16:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5jlbkeLKQMDNUUkuM17GhTjP4YTfzPhArLde8F/E8Us=; b=uc82XFshlGEmbY Q6vtCbwXTDe6t8TE3z6YukA5yPdyAH0038oRrj0NwPPtGI6asy7u3YV9JBK9kjulWHwGREib3U7K/ yJjmwHhaEHhqb8IkiiHlzP95T7zR0c/g5WZ1YoyS4D4tJOF+7Ri2mR0V5t5iu3GVBxgZf31Qjcwfi X7ThLSrlOht5VWjTj/ZJNekmiHykXjnZbNi8Q+IjSpBmjEvwvoiNn6zsO1oJmrIs6p/EoDVeAGqym OEy5w66sMo4mw74QFJCqqp+T6WWOqHsTYDtSUQZbh51gFW1dUNu2p8WUocHC2gR7JImoP0GZesooc Ae46ZdrwRfl6fTpPM93w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJa1-00AOTk-2S; Wed, 17 May 2023 16:00:45 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcE-00ADUL-2h for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:00 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8217b3d30so999377276.2 for ; Wed, 17 May 2023 07:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335538; x=1686927538; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2iZ6qGB4BkCweU32BlOkjB5bl2jv6IU485B2b23bYK4=; b=Y5dnDT484VQ3r2JO431q20oRcF9/rj7TSNXpH4/0Kyp5Dt+SnjjC+8qa4M5OcMhBoj /zLspjFTDjvzok4DL4jD7SfowhYnDxsXAFz10HpKBxCi9Dfljw5HnajrReBjr3NlGas0 sLLIlAPW/ldwHcslWQnRTU/AFheuuk5Vk1aMohxf1yX9HDSCq7OEwWs9xqwEUJi9R79h RLqa8I/xWWK2JZ99ctC1JDjBP8iWhe7e/5QGlPnM5VBPJCRnVQ2Nqva0Oi10skXA9Mth wSD6mJEVkAADrmMb9smfPkLZVchBMcoioHvMYln/ecP7CWvO+KWeLMqvNmxiNVCwgJGU DAVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335538; x=1686927538; 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=2iZ6qGB4BkCweU32BlOkjB5bl2jv6IU485B2b23bYK4=; b=H2q/ZtIDIjizYPJnaZYQM92HQEk0/iUK6O57xo4kcNCV4hYIa1b2LH5UmYU/OzQDyp 1f0eoykFcW96woSM3XG585AdFSx9w0RzQ9JSrkeG2C6dEpvzXVAoxf8FTEXGa04/UbZL LDRo8XYc9NNkeh0ik56663jg1pYpAFqOOYYYqDoYAZWDzy3WgbrvkJqU0eTm1jGOC35O xqcaXBFtFhCx8A3EwZFqOFJhrdOUQx5Aq7gWWTs2A5c/+nT4ii3wIlDc2mDyXBJOb6LU Nj3hu04rOoJtV08ZBh0WPm9mBcBFGTCOJzFZDHTdIIz3xXxpVwxt00Dzlq4NN6reqTZt pw5A== X-Gm-Message-State: AC+VfDx9SAbDiCCOmckydVTqjdSHNsJqTlleIeNxAFi0yMIIfBFHvtKY Nh/lSHHNNObKwyGKrl2Kt+PrR4sHLajB X-Google-Smtp-Source: ACHHUZ4oMCQZTlliNKp8TzSxbb5PnBuH2tMzAOtI6hD/zQSxkSAp6vw6sP7G2D7vxCfKuH3Ijj6KOxUjy7c3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a5b:e86:0:b0:ba8:4489:74c0 with SMTP id z6-20020a5b0e86000000b00ba8448974c0mr2466852ybr.6.1684335538014; Wed, 17 May 2023 07:58:58 -0700 (PDT) Date: Wed, 17 May 2023 07:57:50 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-11-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075858_872527_BF336BCC X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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" #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_node *node, struct hybrid_topology *hybrid_topology__new(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; struct hybrid_topology *tp = NULL; - u32 nr, i = 0; + u32 nr = 0, i = 0; - nr = perf_pmu__hybrid_pmu_num(); + if (!perf_pmu__has_hybrid()) + return NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (pmu->is_core) + nr++; + } if (nr == 0) return NULL; @@ -482,7 +488,10 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; tp->nr = nr; - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; + if (load_hybrid_node(&tp->nodes[i], pmu)) { hybrid_topology__delete(tp); return NULL; From patchwork Wed May 17 14:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245213 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D075C77B75 for ; Wed, 17 May 2023 15:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FfpK3y9Sg8Wo28TZke2fz2mkk/yBY+x8wJ9MIZkjshg=; b=3gbMibEAR7KzWY NDa8t4djG9goVSbNAEVhoYGIx5fghaSq1Xy0sch5JYwFr4KzbNAps4Ee072d6i+9giCkM4YTwdtl7 6k3EfslytXdtElJ6/u6w8G5I5tax1dXe6tggXfdY9MR/4oovmxN3ESXDFyNFJXvYGGxOCHSncnvh7 NQRa+bLHrE+PEY8kCcanDjEFXKWvnTHFSz+T7+ZC3XLo67V7npxP6dGheamzXoVYHD4fID36C5fqm b4UAAz0tgIfXzHnOnwP6eubYvJTbaXRuOpU3EL3eP66T+Ey7fhHWuIyHpbH1Rwq4oJEDtQT+FGFTk N7iduAR/Jb6wYyYk1I9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJG8-00AKGk-22; Wed, 17 May 2023 15:40:12 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJG7-00AKGF-1f for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=85QXUmSzYQ7qJQE/KiBLPaTz0+VTd9+u5qwdQ9BqgEo=; b=E+eWmkG+dvmHFV3QUcLhUMAmuh N/coSE/yyeACIawB3+83nHKyS2OC3UEqnb60hFh/1BH6yMjS3/ogiUnBOW/R2OVGR8g3TskIhMhI0 FaSpBJvfEjh7R08DXg2U/9CDT41XYr2qNPoFHRM8bxygr130jEj8/2+Qb5GZeg9j/iSdMnaw2xKDw ZcLBDPyZSALy4F1HJzEZ6/Is/3zqithKTfZlxH18RBKpz5v4Eagte7xviF5T37kspUBA6uvAF2lPu l3Cnsq0a9xc72Y0b+q4t3phndQrW22ZHOae03d6NVnmC4D2gaXluhmdHNi3Vnwy+5ZpnVvZYybEmz A1pYLEVQ==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcI-00DFsR-06 for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:03 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba83fed50a6so1688298276.0 for ; Wed, 17 May 2023 07:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335540; x=1686927540; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=85QXUmSzYQ7qJQE/KiBLPaTz0+VTd9+u5qwdQ9BqgEo=; b=IDUYTrDoXWwrrq3ucsv9m2Fp7hhTBFvwQiCG5BJ4RBTtjwcMSozRUM0FMQo2LCDSGs jX8yJaNCn8744PL6du8vEg4nx2zTGnfTpV5GxP6lOeFZHzZ/Y0UN1hT4042AGNJJsLxn /dN/jQDoQIWA+J4HcrtKyTce6f2gaT97DB52DEsAvuE3okght275WgiwR5hayl3HouRn cDjWShFZpT/50RrG2A3z4VKMKdfxW/8qwmMT67UheTsK9/5YPwhfVpljzupyA30d7b1P 3tdlZ1BhlND5x7kpyLiQp4KwVjewMdh1I/l5GZ6ocAbhrutJ2I7eBw5PM0OAif+P4lgn 7j+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335540; x=1686927540; 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=85QXUmSzYQ7qJQE/KiBLPaTz0+VTd9+u5qwdQ9BqgEo=; b=DkANckrrr/Qn7PZVJYj1eyE+5vQ6GlBdl8oBba8u/HBStfhBFp7aq5h+tWdATAG23I X7UDftJaq3+L8g4GcEYPi1/51Qh9efn2vfjxKUx8S1uMAAAcU6lTWMJTQydfnzQouVmP CAW7EmUiDyTnJY5/m3FP6g09JbdIWJDaVt06C7PAovk8sTgAtzK5oWWbZfK+4GZpo2pk vtAYQofuRGikiON8N8X6qAGmecNPE2SMxyfgMYNUrGqrbJgYWXBMLQalJ5Nf2Vszzg5g vkCy7t86hvyqMih3rFXlrSzVxP6iepOzNYolE1wOregW5mkt/KcptJkGq8Y9dxME1fyi I2XA== X-Gm-Message-State: AC+VfDwZVur7PSW3bVx8UImReE05Mcv9dVkfyPh3f+s6dGy3+X/JJ3jB 3/XZfTOzwbyayBX0GBLvn57dUUH/HoBv X-Google-Smtp-Source: ACHHUZ5TwAkgVf6TwpeVN+nOLXdN7MV3y92amRDRD3tVQXRLC8B4atOH6VvndgKA2K+z5KD779f+YtHAi0Et X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:db07:0:b0:ba7:7478:195f with SMTP id g7-20020a25db07000000b00ba77478195fmr6028279ybf.13.1684335540478; Wed, 17 May 2023 07:59:00 -0700 (PDT) Date: Wed, 17 May 2023 07:57:51 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-12-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155902_186825_7888CB76 X-CRM114-Status: GOOD ( 13.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) 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 = evsel__find_pmu(evsel); + return pmu->is_core; } struct evsel *evsel__leader(const struct evsel *evsel) From patchwork Wed May 17 14:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245221 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2D8DC77B75 for ; Wed, 17 May 2023 15:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l+Orobbg72zWJAzGT0L3Mi6Iz40JqrN3QvJNPTletec=; b=ElZ+VF2Pviyxeb 0PMF1HmCGpsAlgk8PNBK/iC5UBLF3ncu4/YOmQCs/3YPi7Pqks5D+SOfvasuG+6DW0reT4ui+qgbk eyNcYHLdSzhUl2Swx4fTqAtcYWE8Cjzgi3WH0M9V5LZJKrr4qYksGCUrSOs8CboBGFOQ+ED7oXe6Q dwwJpqo75wibGQf+SgW8cIZ+MizP/z7a6gVO164S0AU9s9TIz3FYhURLRH9Loxd8V4bVH488cLGD2 LGaz4YULptY2EPc/uuTRDKK/ZDOsnHmY9Dfr62XuV14qRIhDGDBfoBNCbpwZxjbnbpHae0rHCH9EL LSMmGV9MGmyPXK+ePLkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGb-00AKXJ-0o; Wed, 17 May 2023 15:40:41 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGU-00AKRB-1T for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Lf/8hxCzQpNjHzWukJV+4jFN6uFu6lEtBSl3J7I1nZY=; b=enHFztiurdlf5KeTjhDnRM05nj IiNFoy18wmteaTnzBQ7rl5l6wNgLjMSY6EgMFtRf8f2KJidugczPVsv5iosenmAPSAnP0E47YhPgU /UJiAp0MLidMxH64LcjzHJqKC/yy+cgc9Hk6ZuPwUs4irYgkTVWd16WAJdQnNAdKksFdCPe7l+fyg /drY0l+NGO3FKk9NYgeV+Tc7rTDLNYFk3TOeTALrvUrdS2vGZLbFFJZayl+pJBjUrCpkgcURyTBoy KvlBsx9O+Bjc8MyPTgS7vPvGSBirs8lezCO6qMhl4igvDL61qpRrYhs5J8bBNSOaPn3xy7YgMBAsa v6Bmu4XQ==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcK-00DFt5-0Y for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:05 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-55d9a9d19c9so13670867b3.1 for ; Wed, 17 May 2023 07:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335542; x=1686927542; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Lf/8hxCzQpNjHzWukJV+4jFN6uFu6lEtBSl3J7I1nZY=; b=Nay2/Y9VQgRkTRjYQsrtoubcISP/lly9q68dZu16//xSdEEDB6jAKmPvCgKvS1MDp8 HB5c8R9YCQ3z6X0vYwmJ4REAKa1achWvqfjtuQeOkHwKI6mPFZzsXzV0bLAPjJzGizOT yNeqSVIuNkDzx9x0wuPgl9A88c5JaTJ9ftM3pjuLC6DtYfIPMF/0H8GRVJBfhbvb9CWx U2gEue7Js3gsKbw8iT6iavD0UcikLr4+5jvoUoge3l1eQb6CKb1O+sF1DXnLhsb1oshp b6SJZvu6wsr/Xq0RiD+htui3aZHT7Sa86qqAIOR3HV2fLf8MP3pBKAnohyCcqTkm4AXt gl9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335542; x=1686927542; 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=Lf/8hxCzQpNjHzWukJV+4jFN6uFu6lEtBSl3J7I1nZY=; b=WDgIS9Om2YB7mO+ymZR1MMxqqSSgUlC/5BiaTnn/GQg0Rl7AmKYUu0isoUd3LCe3rb +RyIGkItW3KBX8vNW+wWuIeIB3sh3GxKj7wbnyns23G1/BE9wrMpOWxJYvl7dyBCswvg Llmu+BGAcqkdKskL9fYfdzSznAtF0XJEy+ELbVW6zJqFgl6srlAiUK210NrMRxdsTRfX niAPJlAlPVESlu0rcj3kRKq1WElspQLW0MPZwKR0vGANoC2A20LKIkEUII913aog9byL o3HtDEXCB3oh5ygPYmJ9DS6w3p08S7APYSxrj9iBBhZjqcJZ/BD8JcYJKGh2FjmtTshD bAdw== X-Gm-Message-State: AC+VfDwZw9atcA5091Q0vzs7n3U6hpmR1LvNzpGhqtW4VvEa0f9iYxtK dhU7di88KQftZMQ7Ge88o3M/2Dl2MlHN X-Google-Smtp-Source: ACHHUZ6VoZUrC6EiZAlnVlcFeo0+/IFgZymrHY8SipcP/PmqCYApS3tdMoqxNMXgD9tobYPeVb9FmmrqsGUa X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:c402:0:b0:55d:ea61:d8e9 with SMTP id j2-20020a81c402000000b0055dea61d8e9mr20859767ywi.7.1684335542635; Wed, 17 May 2023 07:59:02 -0700 (PDT) Date: Wed, 17 May 2023 07:57:52 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-13-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155904_286471_B39023C9 X-CRM114-Status: GOOD ( 14.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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" #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 = NULL; - perf_pmu__for_each_hybrid_pmu(pmu) { - ret = __write_pmu_caps(ff, pmu, true); - if (ret < 0) - return ret; + if (perf_pmu__has_hybrid()) { + pmu = NULL; + while ((pmu = perf_pmu__scan(pmu))) { + if (!pmu->is_core) + continue; + + ret = __write_pmu_caps(ff, pmu, true); + if (ret < 0) + return ret; + } } pmu = NULL; while ((pmu = 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; ret = __write_pmu_caps(ff, pmu, true); From patchwork Wed May 17 14:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245217 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 598DFC77B75 for ; Wed, 17 May 2023 15:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IM9ygkCg6vLpYabAXDgHBw9swW42IliNEknr3imEurw=; b=VS1V7gTsBdsTLn i2yf//BW0l8K7/D/cuCs86C0BhAlbqDVe1WRyUx3atRhcncuW9JsFDth9lAAyWz74C6acWhvd4z5J cvI5WlXv5QjiBllQtX6SQITPkWVURPJl4wfo8AV/jrKdrVnAHI2ESkYY08h2HxMRLcybEAzU4vKQY ztTblvcs9reCWMIZ0mMvUURFYopGaS+za7ayBMZ0+RSbvFrOAYVEd66UD3Tm/Ihemk32gTyAzk8tu rrT7bn3hwbQwWVZgmFcJj1de+fL7VnhWYd/3/XdUcHMiPplzAKxwxXVoFqBiGD1/088E+kDcey/+F QBb4J4ZL4kDde5T8Smxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGO-00AKMm-2M; Wed, 17 May 2023 15:40:28 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGF-00AKIp-1S for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UfPINWQ70tKE2oQZ4a089MC2MrpK2HVQ5LFJHLrDnLo=; b=EnEnkaKPwG6/P4ySrE5aZLZMzj EsF0/OLrBcMoaMDMDDyaIQmZOUPp8XPt6XVBIf1HVPcTWMOI0Xkbd/fkQa0Ump07wGdNPCu1wqV1D zO6GKf6+SdpK/H08LlKu+n95PJzfpZS/5lYR4vkyvjiZ0vDr3l6/whFW6oQT+q4bOoq3eZmC6aA3q rZetnjv+Mhs/TM5Wo2C5nNfoUvIQNssn3fDsv1EmV1xRSbO2QlpBLhhofFloZ+M+CI9ZdJ9Q0UM0Q KL6PqDXo7Bef8c/Z2iFbWLD1pd1WX7AHbqKNBpPd3cpJzmB6RVsYdE1p4MCfV+QlP8XOpcrgvVacg MP9FoW3A==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcM-00DFtf-2s for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:09 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8337a578dso1005640276.1 for ; Wed, 17 May 2023 07:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335545; x=1686927545; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=UfPINWQ70tKE2oQZ4a089MC2MrpK2HVQ5LFJHLrDnLo=; b=RjY72mZrh3tbCojZgyLmOIuA3HnkY7ChcacoaTo3LyHlFIjA6R0dt4k7fvJu0lRqKg 6w2dGt4RDaj+cdxT8/OT+5rqP5BpHXkJNbD7ckLJy0leTiGjwM9+R+q9pj4FQiklIOvB ThnM8jzgGn6gKDTLdtQjU+T5h9q+BZLNWe+B+I23mnduNJ9XO+/TAsfcsWmG78HIMpvX H9nIED6Vx7wxULb6YEVn/KBzyiCGN3fwXuyfq0vznDDKJ/je9VUxnX/EoxGGffSwMXiF dCtuePtLeQIKdmK/GDr1TL94ROfYUmlw9Spe+k70KVWQR9hhHSswy22rBnM9H20IVKHj 2Mjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335545; x=1686927545; 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=UfPINWQ70tKE2oQZ4a089MC2MrpK2HVQ5LFJHLrDnLo=; b=VzEIWPOsEB8CnWRs5QCaoOidHH6vKCdxbsUPY1/TGHQJwUKpq7WZH0WHU5X2L/dbqD UFLTLgd1w+5h9CQVZDcpUqh5LJ8v7PUBTRDxIyQdfirm9wZXBGGHp3QR5yyEGqS10ijs YE3t7+XXyZQv6KcW94DQQnQgEJYcWbvC5sGfAGvTUn0VOvdmuVvJ7Mtp1z7305kt5jU/ oVqpKpZ+Jx61DH6mo1epI8ioSLoNUaoJXgMNWgngzNF79OEFF3cDKMvo0Vh/CcmtZg5R cdBA9AsYcv7yr7Aa+clervsx5RnRLPiImeRgXbYsaIGjuLTU/QGTx/a8VlV9d4DVbOCt vd9g== X-Gm-Message-State: AC+VfDwDb83KZ5T1gcH8CaJCiNQOgJRnpTdWMBT7BogLmO6QZlM2JS1H j3JPa+QcHCeX6P1nrsjk98tI72A530X7 X-Google-Smtp-Source: ACHHUZ6Yw0szBeMFtJeTPLuEd4Khb/Vry8Fn1wOc9bL6aAM7eU9JIjaTmhnF6uOApdPbx6ynjKo0Es/0C9G/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a25:2fd7:0:b0:ba8:3e2d:58f8 with SMTP id v206-20020a252fd7000000b00ba83e2d58f8mr2707513ybv.5.1684335544964; Wed, 17 May 2023 07:59:04 -0700 (PDT) Date: Wed, 17 May 2023 07:57:53 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-14-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155907_752236_419C3A24 X-CRM114-Status: GOOD ( 13.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = !strcmp(pmu, "all") || !perf_pmu__is_hybrid(pmu); + bool all_pmus = !strcmp(pmu, "all") || !perf_pmu__has_hybrid() || !is_pmu_hybrid(pmu); *out_metric_events = NULL; ids_size = hashmap__size(ids); @@ -288,8 +287,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, struct expr_id_data *val_ptr; /* 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; /* From patchwork Wed May 17 14:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245155 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5217EC77B7D for ; Wed, 17 May 2023 14:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8WZKzYQyo4xBOKVx6p8GQGiiTPt2yK+eMk/FBx99ci8=; b=e9M+Ds3pdJe7e3 BBcddM7F9xLcGx7Gxw3Qlib6Xa5K1Pwvod7aDtRya5sVTzZV737g+W2fhHt811jvPtADrC2Hp2MgH h/xtdDpsg5S3qfp8/hGGjWc5SJOZAiR4NGJQRVBwUm+vw5XNGqJnFxzIBU9AVsyg6gT1Qgd7gYTSO uXJfOZTMMZg7Kg2+pxIclgwmM1OZviQRvFa6TMXO7OdQP6XEoF/CJsFIkZiqQtoYHOv1ksy5JhDsM 3opYD04ZA3baJKA7TtclZxMFRBLym31sXXcRWDHiVrXG99A/XLgPdM01UcQzP7FmVP3pSe8P4jksf IUdx27bqDyR3zCowqvsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcd-00ADfS-1r; Wed, 17 May 2023 14:59:23 +0000 Received: from mail-yb1-f202.google.com ([209.85.219.202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcO-00ADSR-0S for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:09 +0000 Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba83fed50e1so837808276.1 for ; Wed, 17 May 2023 07:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335547; x=1686927547; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=sIHJY1c1GNTLAYnNmYaDkKa9lZTOh2b6niLk2VTctc8=; b=pxyOdOPcLeT6SLboxl+va0YTH/BsH/WhlGhRC8pe6tTnbsMIdRyG0ljVQgrfT8/A8r fHvHHGLrVngOEpDdDgGQ/09tMmOCv5Pd+bzMJ8A6Uf10qZJwlTueTs04oEGGm5WcsVnP Y/7WQj0iNx+k9UwcOOyI3vrA9ToOOeoiEvdIHeNrh34EUHRDGeY2qXrIHqEvL63QfSZC /AdbXBTkhLbvzXcDkiwdg0OsQFcz+JJjaJ82m4OB7aNqr6kHrNQ41oUtUv7j7Ww59sw7 cbJLxixjt3K+5zNozwloPn1RZ2pUcuxs8TTZ/XY0/5YznWMiWRF5VWi8Jq6zdmqyrXti VatA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335547; x=1686927547; 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=sIHJY1c1GNTLAYnNmYaDkKa9lZTOh2b6niLk2VTctc8=; b=hsjpo6Aj8cFvOVimMeGhrKPHMvmQKi2+tIduyMPBTrRqvWPQGTlYJuz+RVzF6jtiZL yUfLElUTWzR2FWtntwaocjVdu4ep7n2W+CCLdxVjr2SvbRXoEiVpgsfRTGog0fA0XP1L 24gpdm3ZU6uc0N9yHs6cgOiccxDXD/qNYTOuae12tpwMQVNzLgwX+6Ft4/kAEXajDwxs csMRoKjLQbBX/a5Ga8ifOJNMiJh7cB4wrJUv2acu9Fdx1LeNMm9u3FS6ghW+I3ve0+sb ogqeD0fnEsXzogr3eAjikiVq5m9LUW8raZb+dq/QnLVOabBkxeQgyCmdZd+52pY8UZxW YM4A== X-Gm-Message-State: AC+VfDyfSNtPSoKrHdelC6+nQ55z9ABoW05St+vLlMqjC0F4gzfyhfej drp/D8PskWBckoI6xk421FwjQK+pjimS X-Google-Smtp-Source: ACHHUZ6D58g6NbtAP9zKEFLU8vrjmWED8tztuQXAU+VNZz78a2f/hTIcWDz3GtSipqhipXcFNnpDY3NOLIWG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6902:104:b0:ba7:8628:93e2 with SMTP id o4-20020a056902010400b00ba7862893e2mr1613221ybh.4.1684335547066; Wed, 17 May 2023 07:59:07 -0700 (PDT) Date: Wed, 17 May 2023 07:57:54 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-15-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075908_183100_F98BA521 X-CRM114-Status: GOOD ( 13.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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" #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,11 +680,14 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; + 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 = evsel__find_pmu(evsel); + + if (pmu->is_core) return true; - } } return false; From patchwork Wed May 17 14:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245218 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF416C77B75 for ; Wed, 17 May 2023 15:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CHEzVYl5ZfI8gFjXwigGoFAKtL5kuLPQz7LNQfnypW4=; b=I4loWxYxb+Jrdg wpGeiKDXLz9WFOcsj5Gtcwv/knRVD9CPaNcvcQcaXaxSuhTmZQzFJCpGa3IwGS87eXYwYYM5UkpkP JwiKBLAEI+q4omigJNzvHqOoYgGcSv4bHXeMPqSjhjE0b0oF96D1o7+cUSdMtr7h2+e+yCBivDkzP QchoOXjSxJnqZ1OOfPYhU077hibexrSic8A4fmnHFFMhTVViVH7E2zfIBwHcec8Yq4auwSPcj3N6c 5u5yfVeVvAVkNkfzFfYFVV9aGK+B3HTWlIj6yII5s9Jf14AGNGS3dJKGHKFbSvDIPLXCvn4mOPAuN JDj0oWBE5uLdS/SHoYpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGU-00AKRt-2y; Wed, 17 May 2023 15:40:34 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGT-00AKPv-05 for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PQELA9dygliHhugHONhOHu8rviJ4MVgnxyXfBOR963U=; b=dsnUIurztaH7MRQmfRaF59Jolm 9Jj9ijFgKD2ZYUr7OFPxKvWdn1gCJZsvPxC01jq+U0qjK04wOqGylYkrqKRtVPxyKZtjB+JorXoCS VM2uX8Ejr2HU/Zj8PzvevfLIBzz1ZX4qiIL+LJrLacgBoDwD0rnBlhHqYwIuz7vPkTGNakCv7ekav pCaTyCYHLyk7Iy1kIUxOg40xIg6PrFTTTvbsv8JTkVykWTi5YD6i3pk8FAbylIXJqgiTH7GRNCB/T U1nPQy7P0iyovQdfuRJz862HxWKg9WfpUNZ656vdpQykMtKO7HfzesX2VgDaffwPZnt4p8QQrVyNZ qKG5akcA==; Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcS-00DFuS-0j for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:14 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64885aeed30so577398b3a.1 for ; Wed, 17 May 2023 07:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335549; x=1686927549; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PQELA9dygliHhugHONhOHu8rviJ4MVgnxyXfBOR963U=; b=jHsbemsA1TZquLshENLqe4oijPjfN3yl6ZsS21ZVx06bh+tX5j0q9XDtD8LwOdVH8n AlwjtH/MzGkjgmMsnT5naSM8qMhLoabC3o8lPftGVT/qz0KQDil49mxU39nqx/9aDMbu HahKJx4okpqIc2MUn9ZCIxmIlD+5NaN1OSsWnXLBKFw5wlpjYRuKvbyX6Nui9SYkIJ7t qMs15Hpv5pGv7f2PpuSZHlWy6QEJk2txJTd1ZY8LuerMhFfnuiUNsUCzt2V4tux30Hjt 3jZ/Zkky68aJZwj+ZFBkOWagoPyM/On4jtJToyVzlTtU+VYwNImmtcIncHLxxygfVILb WzXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335549; x=1686927549; 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=PQELA9dygliHhugHONhOHu8rviJ4MVgnxyXfBOR963U=; b=YjTpXG8VPaUGEgi4HC7Q00K9aDY7dIsixJGjY2obRhDEwbJpNOuBZT/flbEgpJygvm +KRcda+v6kKvzjtp2blT+eYt1ip0E1N6dsL0JhXxebc/z7oWawTd/Q4COzzX1ucx9QoX 80h75amwlszt9kacR+sm5rO+niwmUnDeNj8viRP9j4KCFAB3bRPrVF94WTJThcn+sDX5 rOPGJBvPPIwoSQvBvgDcg+1TqMxdS2OyjBAG+1cOB8+jKUi1IhXD4RKJxJnaAqxPlH5E LnGgrdgG5QDML+4mrTz73zD6BhWxjlymxLfdctjKorDgKNTsoCQfPDhDHGYszINOXEhD Yz0Q== X-Gm-Message-State: AC+VfDyKe3dIIi3TslwGdPuzpNl3zYqpLI9kKgz5QVnoy++DY2asnRd3 Zf/npMI/jhF6zWqPKbcTEUbm7DM2DEPR X-Google-Smtp-Source: ACHHUZ6siVVymk0LoQ94GGZ6axmK1Qp5NQOCLmGGBJeP5Zo58YeQcY6rOkjhCG0XmlOSFqsv9jOJlCJdS9fA X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6a00:1916:b0:643:599b:4dd1 with SMTP id y22-20020a056a00191600b00643599b4dd1mr424011pfi.6.1684335549439; Wed, 17 May 2023 07:59:09 -0700 (PDT) Date: Wed, 17 May 2023 07:57:55 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-16-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155912_327351_08E4B1FA X-CRM114-Status: GOOD ( 18.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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" @@ -3259,10 +3258,8 @@ static int perf_c2c__record(int argc, const char **argv) argc = parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); - if (!perf_pmu__has_hybrid()) - rec_argc = argc + 11; /* max number of arguments */ - else - rec_argc = argc + 11 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support them. */ + rec_argc = argc + 11 * perf_pmu__num_mem_pmus(); rec_argv = 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, struct perf_mem *mem) argc = parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); - if (!perf_pmu__has_hybrid()) - rec_argc = argc + 9; /* max number of arguments */ - else - rec_argc = argc + 9 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support them. */ + rec_argc = argc + 9 * perf_pmu__num_mem_pmus(); if (mem->cpu_list) rec_argc += 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" unsigned int perf_mem_events__loads_ldlat = 30; @@ -120,7 +119,6 @@ int perf_mem_events__init(void) for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { struct perf_mem_event *e = perf_mem_events__ptr(j); - struct perf_pmu *pmu; char sysfs_name[100]; /* @@ -135,7 +133,12 @@ int perf_mem_events__init(void) e->sysfs_name, "cpu"); e->supported = perf_mem_event__supported(mnt, sysfs_name); } else { - perf_pmu__for_each_hybrid_pmu(pmu) { + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |= perf_mem_event__supported(mnt, sysfs_name); @@ -170,9 +173,12 @@ static void perf_mem_events__print_unsupport_hybrid(struct perf_mem_event *e, { const char *mnt = sysfs__mount(); char sysfs_name[100]; - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; - 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; } - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; rec_argv[i++] = "-e"; s = 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_pmu *pmu) return !is_pmu_hybrid(pmu->name); } +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 = NULL; + int count = 0; + + while ((pmu = perf_pmu__scan(pmu)) != 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); From patchwork Wed May 17 14:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245160 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 239FFC77B7F for ; Wed, 17 May 2023 14:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Hog76526Lwbte+VdvmmeZamxP4qdtJkUZsotC9FrypE=; b=CeMMfp3yW4HO+s t+nc7kbwH23OLmhmFYxjkfqdFxRiMecNspLkDIs5i3mhz+Wmcf7BZEMOgcjdKPGbV26jsQngJzpQT 3L80lyqK+oqO/h7u3iiS+ZaorVroMrAoW4jvZXAj6va/+YcRFhHWgEBMHdG5EHFBwiX90ZZWGG3TU 4QsMC3IxT46M6bq9P/7O7Q9XU3Ev6mRkmTu2TU+CNL/jZHT0hKl5bOnHp4ZawlS42YkLpQlLQLRDg tlZ5VbpPElfaRd3EUXdzUW8h91jVy1CtDd2XJXwSSQ02qrIOsjxEFhHavvjPN7q+XPKqIh5elp//U /zhCondboE3D9V+B526Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcn-00ADl8-2J; Wed, 17 May 2023 14:59:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcg-00ADgY-17 for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 14:59:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:To:From:Subject:References :Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KKqoIZuPWcw9eVnTQaV/Yxm1zaZil6JyotfyFlNgjRY=; b=lmeS5P/pz14eIpT3hWI2pmVyh1 mRfqwR8J9s+TvA0TH7o3ofXqyNVUpvkQvbJ2yxFP+39FvMR0uBaBoEixGCr1fxV1nwXJ8hHFl1nI6 I8LX2nXjVidO3C2QLV2gXgECqQR1C6endXlTYIgiXc5TNerdYfzDLmgIrjpY6CYdkI7YmbA78BTbn gmTLDyMLmbqbn9NnIsgrUOV3uFZ0KCGaB+8VHj65se+vPoxpHkD5YZcE5TLA78ZW/uMRPsXqJJ7im kwon0AIUFtRbnfu7c4c9XAPHz2TmgJT2hK/UNw3VXtymRlmR6l3JLQJw3GS4N/Ja0LooHCRnw44VR oZZqk8mA==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pzIcc-005Ald-W0 for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:25 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5617da91670so8300147b3.0 for ; Wed, 17 May 2023 07:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335552; x=1686927552; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KKqoIZuPWcw9eVnTQaV/Yxm1zaZil6JyotfyFlNgjRY=; b=TUFbOf6Vuteciew1H/sR8GFDllTU26HtBigIAOcm6RNblkHLxR1s1nxllnAGP+U6gw 6LetlTntu1sEwfssXYiaidtTavHjq/QXjXhiTXjaqX5+HFtni52UpqVqVCYFD9rfH0ql Uvn/PhwowUE7pFmwze16n/YTEweKs7XEDJA6u953lHrDicn48O1FsUAdfNbl6VnC0/rR QcLMnwEX+jxIZk8F+jP2Tw8gqmYmlQjhix0jgVbuDVGfgfBS8Nna8Hf0XBCkSpAWRcLn L83rAuTyA5bxFDqwXcXNwdPa8PulsCEhXZN4tctpP+DhfuWrANs/C15RHq64A1vEDFz/ 65kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335552; x=1686927552; 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=KKqoIZuPWcw9eVnTQaV/Yxm1zaZil6JyotfyFlNgjRY=; b=QpZJAHXuRXsejJXh5H3nlQngeiwG0aqx5bBIZtfxHiQ509MNN1apcJeRvki3uL+YQ9 6N1jfq2BugYgdya+ce0SJNtQgrdOu6SSKekoE/xo2itp1ZldJqmO+7ePCCNcCeE8liRG Q6l4vowGytMIDVnVm7uLoNzRqgh7PilN98JhTh2Y8wgBz9m1Y5fc6wmv9z9x8y/bnOBt ZSapt84QyrxE0FkbNPMSWdHVeT2HBmUkUB4dyxV1bgz4UsvCPquQpfDR2iTrA8bvKr+v XzH+8BOo+dQr0lhd/zgVorKdnhqLFZN9HfvYcLwdBhymJGp/WHCV9HmIAcmJ9YKbsxKo Ufbg== X-Gm-Message-State: AC+VfDyxX9P1m5W+1P9dNggnl4SH/oLoExqgFl1srxFeQszkMjS+NNrZ f4IXcWYG8cCbA2dpaEsr+PldYIyT2iCs X-Google-Smtp-Source: ACHHUZ6N4HYRzQ3Z7NxRIwYgx8pZoI+LByxp+5DF2IYl0KvI6WWpkWjIJcQZotKUwdlgvE97nF4ub8C4g1CC X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:4314:0:b0:561:8c16:2b66 with SMTP id q20-20020a814314000000b005618c162b66mr1686499ywa.4.1684335552162; Wed, 17 May 2023 07:59:12 -0700 (PDT) Date: Wed, 17 May 2023 07:57:56 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-17-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155923_056883_80486AB7 X-CRM114-Status: GOOD ( 16.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 42135be760ab..aaf18e487757 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 += pmu.o perf-y += pmus.o perf-y += pmu-flex.o perf-y += pmu-bison.o -perf-y += pmu-hybrid.o perf-y += svghelper.o perf-$(CONFIG_LIBTRACEEVENT) += trace-event-info.o perf-y += 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) != 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 = 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" struct perf_pmu perf_pmu__fake; @@ -967,11 +966,6 @@ static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); - 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 = perf_pmu__get_default_config(pmu); return pmu; @@ -2144,7 +2138,6 @@ void perf_pmu__destroy(void) list_for_each_entry_safe(pmu, tmp, &pmus, list) { list_del(&pmu->list); - list_del(&pmu->hybrid_list); 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; /** * @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" #define MAX_NAME_LEN 100 diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-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 From patchwork Wed May 17 14:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245156 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1A6DC77B7D for ; Wed, 17 May 2023 14:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YXDMNpSOi7XRnp/uKSE7v0x5tS6joqj+PJstFrWmHRg=; b=Wz89IQXSiQV8Fc 29O377yPdqRXXJI0kUPsLJUlEVm3D5om/hQz0/IA+zA0rK+2zeWfAeJkB3nwiaVBcNX++Ix9e9+1k yqs+SQbz1vI8l59E5GHRKsxF+CKweO252haOaLHHrFbegv6r+zEXWekPwCmAM7r0PIfD6NGzxvxFV vijzV7fW+uWDJJhEl23UOQm1lxtD8WtTXNuDLpZiuB4TiEZJnD3fERj53IO1sJPGoeLZ1Cx4AjeD4 UcH0+Pil7doGb/HfIQX4OPFbf6WAE01a58LofkWga0mv/6LuBmzvI/Rd+U8182v8NdYwy8ygNXdku d7tI497VVn+9V7c2D4LQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIce-00ADfe-0h; Wed, 17 May 2023 14:59:24 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcX-00ADbp-0V for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:18 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1ae4c08429eso6266245ad.1 for ; Wed, 17 May 2023 07:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335555; x=1686927555; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lI6N+gAi4DZYSVnV114efDFeKpz0k1rpLH9njpuRINE=; b=VdO5yX2Mtt3uOQ2AaB3Q5XB3czFjGwA2fovuTpWU7v+Gys7pziSDULWXNnQnlh/ldX UsKgUfZMpG91Xnv9oI5e6wggea5KzAsJPtPxE8sZLF+lQzDMwAXieu242N1cDu5tDpVs ybGHBKCWMbZv4qCIoIGwZaS9SreYC50E/lUnTL/BV9dwCxbeU19Cj/vXXYJby3ymcVp+ GDwq2Y82oKaD5BzJjUw/5ROkCjU6mMtDcgXzkPjeU4Qb+w6eRlVNvQPa720O9CaXo4Un TbnNL0SBw2RnLKa4hoWLJNhL6ftP84siAsYyzFR9c1s7Q2LdSa6DcZnNYI9pu/RSBgMm hSOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335555; x=1686927555; 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=lI6N+gAi4DZYSVnV114efDFeKpz0k1rpLH9njpuRINE=; b=WJ1FpR/0iYiOFr7u2R1wA2BD+2EZj3//HMUoOH0J8iTyUBcWhm9TUj6n3NUjjR6aOp 3PcAP/JAdvrnsMyh8FejcWHUwZg9c5z+30HVJ771f18qjmAktwmYAHAUImY3NtukS8uS Ul5K5GJRKz2jewu7SRoMWn+h2xDLOd3ayQn4j4xPgeYPuxStIMpCzG30jFETr2Ke34MR fz4e8wE2OrJLLkHKD4te0/FTyeP/LE9AxWx4FzPzv6u2l451+EE5EHI5oK4Lm2rZzbpt s7TYwOuYKc7j7Faq9Hf5pj4iQv+QWOhJZEwoFb/BgG9ZgEZaOogGaTPbbx4Xvl7l2z0Y 14uQ== X-Gm-Message-State: AC+VfDzyBPUEfC34XXXimVetx/jk3TBq9+MUM3f5xrmA5YfVEP5OvRCd MH36xe3pRyxHx5bZIF0RWARDRzztgrxb X-Google-Smtp-Source: ACHHUZ6tg9xCmYqqW9Dcj2t83D3ZIEdg28KNdMklhDpiZRaz2/Kct1tJYmDNWbltkBzSuqq/mfchZfLPgg1h X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a17:902:8f98:b0:1ad:c1ca:55ae with SMTP id z24-20020a1709028f9800b001adc1ca55aemr6879014plo.13.1684335554831; Wed, 17 May 2023 07:59:14 -0700 (PDT) Date: Wed, 17 May 2023 07:57:57 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-18-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075917_198611_810E72AD X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- 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; static int save_result(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; struct list_head *list; struct pmu_scan_result *r; - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { r = realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r == NULL) return -ENOMEM; diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_groups.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, int group_fd) static int setup_uncore_event(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; int i, fd; - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { for (i = 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-events.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 != evlist->core.nr_entries); perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; bool type_matched = false; TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - perf_pmus__for_each_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { if (pmu->type == evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched = true; @@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __maybe_unused, int subtest __ma static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; int ret = TEST_OK; - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != 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; -#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); #endif /* __PMUS_H */ From patchwork Wed May 17 14:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245225 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54089C77B7A for ; Wed, 17 May 2023 15:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UP9l4oMj5xaZR1KAtKQYyT3yqj5m53SNCApaA3LP36U=; b=1BmrlAL7+ug/lu wQJE5E05sYN5pKrFXiUpuRLTMeLGYUy4kiSqNjuBg6ndhI23odjA2AWorC4i85tAZ3/0jStk0DHOb BSXyGAI0cAIqDNJ1OrPo4l53w5LpzoGz9ckF0YYHTiwKCz7fAGubFEP/M/hj6Z7/y2R5pprbJ0Odo Sw9ifrKZhB6M521FhrHKQG/0Rz+M/iDS82hs4KYy1xKv1Zg3FTVpjHrmDl7Pu8LvGMp0oI06J7luN 5H7rFt4pHdJYAyLd4xjhTzG8HQ3C5qDvBDgOXG7/+fDNctMN6E/u615HwahqiiZikVCoDfxRmg3Pm 6Bz06ap8/zzs13EcDA+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJH5-00AKr9-0D; Wed, 17 May 2023 15:41:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJGb-00AKVr-06 for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:40:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2JHMYFOy4Rnq7km0f1P5d0Novi2NnIhZ5v+qGyCXvJA=; b=W2KKFZ738JvWJKLxZ+l2rx9lKU 1gZ2S3Jw0rjoBbWBfKYlXB8Y8oP0zzQgDrzDYE8g3R+d4aPtsXWIgLjdNDLJqYPcsqqS+ahuiM96+ QRrVB8esWCZK9Udy1qAp/IGRwiBFH76VGrCs63j/DSJA2OiuxSRJsvXPLFYafYPjEbeOLZZMEGKNY XHkilimDa5hMwBviKMptq6v7c/zIF5MlR+ZCmEiDl9wxoI6ynQsB2XbQf6y/Kq+1uSQtpd8Czax6l JvDYUHTZgdGNHMktKvzUGQMSZXISXqEIumehgmFACocRY/LZaGtSf4Ifb2mpUHDv9sfWSWAaMFMZp 7Mh/Cu8Q==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcY-00DFt5-01 for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:19 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-55d9a9d19c9so13676397b3.1 for ; Wed, 17 May 2023 07:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335557; x=1686927557; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2JHMYFOy4Rnq7km0f1P5d0Novi2NnIhZ5v+qGyCXvJA=; b=NUt5ix3/hj9HrpcM6MYDNvnTwoSP1xH6wlLrX9e9Tz0miwMSQTtGIKClG5qwv57l6O A//ubPkeYK0kARPpDLYkyvpjLLta860QhwX1nXfQwg8tEZLVlbK1kWXym/2eZ5dZsq8x 6GYSvX9bRBm6eKGkHksg3BVoR2OCrj+UmGMMJkEVE+YWGLO4+6/QkfWQgMT0Iy3tbpGd ywGR+r1YyKpTyXhgNpMcIreGImEsF2uwH3qWnvocCFxv0Q+CgvLR1UjKizk+npEV17LY iPj9Md3WG1Jl5fTkxw6s8n+6E6qDJXYki1HnUtkNIJNcA+Ge2Zpy40/9HA4D8oS+Fc45 I6oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335557; x=1686927557; 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=2JHMYFOy4Rnq7km0f1P5d0Novi2NnIhZ5v+qGyCXvJA=; b=g6unNHzD83Nz5oBBmad7Piruvk+tpYlUnH+nItDjD3TRNpjXteSNZsiq90cK9WQSA2 q8u/z+u8B3VHscNdxbMbCg/hAHh+8L0owI2+SSDprfzw1pxwt2/lfKNX352EM2NItcya Unf7e6fLlaH9duRp5UpFuAQlTwU1kw2tbTbCF76bPKLu9hws9LiirvSd809mLiE5XyXa AFr55iAIDqOay4E7r4OXkNqDOA1tVslLC1reM/5YYkwV05lk+S2G8lCRPYwpE2/njpJA eFpz2Y561K6kyB+UX63ZZxXZu0VA6qPpCo+/PFZsUt2DKp1KBh2Hbrgx9NzCOmYbqGzD 8FNA== X-Gm-Message-State: AC+VfDxr89OtyKOVEX9YtqqNEGxP9wq0ADiCTGk0ld9vThNOEXM+anRo eYssuNaOqZBa9z1XrYZEDk6tIvYGNjXs X-Google-Smtp-Source: ACHHUZ6qLhjY1rr5lAa1CEqcs76khLRuf/sGQ5pDoD/zXoJpttx+p0MDEXNhFEWooXgXjWu1SfGXD+0KmT/A X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:b50d:0:b0:561:4cde:92cc with SMTP id t13-20020a81b50d000000b005614cde92ccmr7867334ywh.8.1684335557303; Wed, 17 May 2023 07:59:17 -0700 (PDT) Date: Wed, 17 May 2023 07:57:58 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-19-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155918_134947_BABECD79 X-CRM114-Status: GOOD ( 12.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Find the PMU and then the event off of it. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- 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/util/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) 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 = perf_pmu__find("cpu"); + + if (!pmu) + pmu = perf_pmu__find("cpu_core"); + + if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + return false; return leader->core.attr.config == MEM_LOADS_AUX; } From patchwork Wed May 17 14:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245161 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D025C7EE23 for ; Wed, 17 May 2023 14:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1PI7CuXDYG9pz6Ga701paZJwuftbrLi7SsNS39MpdnE=; b=SjC1JuCc0Lf7lo 9I7Uhcy6pqoQk+wSMJAnSB5NxtxZaIMQEMGFTForMowMfZUvVHd1kL+MbGYR7Ts8hKeIShDDCAVvD +DxGYjP/2oNTQRlLmf/w5t65XiSPu54iKub5p1d+kZxYXU+KpEPmeLwC9d+NuHtN+PeCYvQk7Agk3 yGGFiFfucn+WpvwilnVip4rpEicHChuhhYG+rlPWHC3OB2xZkNp/f6P1XaPMWuX5ahcvJWqmnHVyB A/mbN7OtGITKWtqVCV+VovxyIw0UtiErDQqcmiCjahUgzZHfD5akNnNLq6ygvCl72DvxSUIfjI0Ze 7KRugaFrO/LJFBeyGpBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcn-00ADkk-0V; Wed, 17 May 2023 14:59:33 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIca-00ADdr-35 for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:26 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-55d9a9d19c9so13678147b3.1 for ; Wed, 17 May 2023 07:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335560; x=1686927560; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Q/cUxUfBiAieL5tH5D1KKPRDXFRCAhM/ItL2DLPZ6mQ=; b=e2SzT5pWg8Vv9XiZeaBBHaM+N+b7SK2LdpDq8p9V0sUo+sgsIIDj/n2a9slENMHzan i/iDx/L167BvrSQ0D1gt7IuLJB1OJvLAVMG4/Rup4jBgnX0BX9DMbUE2iYVpX8Pz91RH GtbSsdDiXAQ76u22wmimgs3Jqu49atyJQquOpHhrrWsYwzaIJsJMIM7rHZUI5kMCZmou R1e5oTSgCdWXqu6W6VH70jcIneKMwU8Kmy6UtUj/FSEaTS710ZzyOsLErm9DE7TK1Jx2 Q32rl5YdpwX8m1x/J0C0FhsQ+7+uP7fK9iGfDivMJcOTNJmGhOc0k+tNd+m90gEi1LVz FolQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335560; x=1686927560; 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=Q/cUxUfBiAieL5tH5D1KKPRDXFRCAhM/ItL2DLPZ6mQ=; b=T+E7Zyu0fI9c/GtZq9grSNAG+NM+4hW9HvVQ0LSyXehAgnsvKKhLBnAy5UzcjOYFBn pRDgZz+A+QmWzHqqBohSj9xMJ+SmjHw941DX/eA1dlcP/En/fv0p1vtRM29SUHjUNqyB Prq1tZ+DTsWrMRsE9JZDJiB33voLf6bkqiXn2mJlAH5qEo2Dhi7Ns3eD7sCpc/XCXd3E wwzuWmUTp4M8efi3gQGi7wB0hZT8NYVP7MAKBGmD2EeaPuNGm38CdEmnD0Q5sETtqpXv Frgl3BI+6qog/p7JQ9fQIlTlarr6cApcHO99OsupVXrE/WDkm97Yw7+9FMgpnQI45u13 vGxg== X-Gm-Message-State: AC+VfDzFOWhBYQC9N9ZTZYINj9/2gCh083l1hKAAIvl8Dmx48XlOisge ks0BCLKBDZkR8MDL0wGi2YswX17sFuDU X-Google-Smtp-Source: ACHHUZ6YTJqxkUqsfQ3KBiBHfraxL5EllJz10oB9Xdt61i7hZT0vbKnOuLvNxaNZvPYZf4Uyyx9YojHnOS3J X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:b50d:0:b0:561:4cde:92cc with SMTP id t13-20020a81b50d000000b005614cde92ccmr7867401ywh.8.1684335559925; Wed, 17 May 2023 07:59:19 -0700 (PDT) Date: Wed, 17 May 2023 07:57:59 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-20-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075921_070507_D47E204E X-CRM114-Status: GOOD ( 21.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_spes, int *err) return NULL; } - arm_spe_pmus[*nr_spes] = perf_pmu__find(arm_spe_pmu_name); + arm_spe_pmus[*nr_spes] = 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_ptts, int *err) rewinddir(dir); while ((dent = readdir(dir))) { if (strstr(dent->d_name, HISI_PTT_PMU_NAME) && idx < *nr_ptts) { - hisi_ptt_pmus[idx] = perf_pmu__find(dent->d_name); + hisi_ptt_pmus[idx] = perf_pmus__find(dent->d_name); if (hisi_ptt_pmus[idx]) idx++; } @@ -131,7 +132,7 @@ struct auxtrace_record if (!evlist) return NULL; - cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu = perf_pmus__find(CORESIGHT_ETM_PMU_NAME); arm_spe_pmus = find_all_arm_spe_pmus(&nr_spes, err); hisi_ptt_pmus = find_all_hisi_ptt_pmus(&nr_ptts, err); diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-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; - cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu = perf_pmus__find(CORESIGHT_ETM_PMU_NAME); if (!cs_etm_pmu) { *err = -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 @@ -10,7 +11,7 @@ static struct perf_pmu *pmu__find_core_pmu(void) { struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { if (!is_pmu_core(pmu->name)) continue; 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" 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; perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu = perf_pmu__find_by_type(evsel->attr.type); + struct perf_pmu *pmu = perf_pmus__find_by_type(evsel->attr.type); 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) int test__hybrid(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return TEST_SKIP; 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(struct evlist *evlist, bool found_pt = false; bool found_bts = false; - intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME); - intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME); + intel_pt_pmu = perf_pmus__find(INTEL_PT_PMU_NAME); + intel_bts_pmu = perf_pmus__find(INTEL_BTS_PMU_NAME); evlist__for_each_entry(evlist, evsel) { if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/evlist.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 *evlist, for (i = 0; i < nr_attrs; i++) event_attr_init(attrs + i); - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return evlist__add_attrs(evlist, attrs, nr_attrs); for (i = 0; i < nr_attrs; i++) { @@ -32,7 +33,7 @@ static int ___evlist__add_default_attrs(struct evlist *evlist, continue; } - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.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 *evsel) * should be good enough to detect the perf metrics feature. */ if ((evsel->core.attr.type == PERF_TYPE_RAW) && - pmu_have_event(pmu_name, "slots")) + perf_pmus__have_event(pmu_name, "slots")) return true; return false; @@ -98,8 +99,8 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr) if (!evsel_pmu) return; - ibs_fetch_pmu = perf_pmu__find("ibs_fetch"); - ibs_op_pmu = perf_pmu__find("ibs_op"); + ibs_fetch_pmu = perf_pmus__find("ibs_fetch"); + ibs_op_pmu = perf_pmus__find("ibs_op"); if (ibs_fetch_pmu && ibs_fetch_pmu->type == 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/util/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_record *itr, int idx, struct auxtrace_record *intel_bts_recording_init(int *err) { - struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME); + struct perf_pmu *intel_bts_pmu = perf_pmus__find(INTEL_BTS_PMU_NAME); struct intel_bts_recording *btsr; 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) struct auxtrace_record *intel_pt_recording_init(int *err) { - struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME); + struct perf_pmu *intel_pt_pmu = perf_pmus__find(INTEL_PT_PMU_NAME); struct intel_pt_recording *ptr; if (!intel_pt_pmu) diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/util/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) bool is_mem_loads_aux_event(struct evsel *leader) { - struct perf_pmu *pmu = perf_pmu__find("cpu"); + struct perf_pmu *pmu = perf_pmus__find("cpu"); if (!pmu) - pmu = perf_pmu__find("cpu_core"); + pmu = perf_pmus__find("cpu_core"); - if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + if (pmu && !perf_pmu__have_event(pmu, "mem-loads-aux")) return false; return leader->core.attr.config == MEM_LOADS_AUX; @@ -82,7 +83,7 @@ char *perf_mem_events__name(int i, char *pmu_name) pmu_name = (char *)"cpu"; } - 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/util/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" const struct sample_reg sample_reg_masks[] = { SMPL_REG(AX, PERF_REG_X86_AX), @@ -291,7 +292,7 @@ uint64_t arch__intr_reg_mask(void) */ attr.sample_period = 1; - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { struct perf_pmu *pmu = NULL; __u64 type = PERF_TYPE_RAW; @@ -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 = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (pmu->is_core) { type = 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 = perf_pmu__find_by_type(PERF_TYPE_RAW); - if (pmu && pmu_have_event(pmu->name, "slots")) + pmu = perf_pmus__find_by_type(PERF_TYPE_RAW); + if (pmu && perf_pmu__have_event(pmu, "slots")) has_perf_metrics = true; cached = 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; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { r = realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r == NULL) return -ENOMEM; @@ -68,7 +68,7 @@ static int save_result(void) nr_pmus++; } - perf_pmu__destroy(); + perf_pmus__destroy(); return 0; } @@ -81,7 +81,7 @@ static int check_result(void) for (int i = 0; i < nr_pmus; i++) { r = &results[i]; - pmu = perf_pmu__find(r->name); + pmu = perf_pmus__find(r->name); if (pmu == NULL) { pr_err("Cannot find PMU %s\n", r->name); return -1; @@ -144,7 +144,7 @@ static int run_pmu_scan(void) for (i = 0; i < iterations; i++) { gettimeofday(&start, NULL); - perf_pmu__scan(NULL); + perf_pmus__scan(NULL); gettimeofday(&end, NULL); timersub(&end, &start, &diff); @@ -152,7 +152,7 @@ static int run_pmu_scan(void) update_stats(&stats, runtime_us); ret = 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" @@ -3259,7 +3259,7 @@ static int perf_c2c__record(int argc, const char **argv) PARSE_OPT_KEEP_UNKNOWN); /* Max number of arguments multiplied by number of PMUs that can support them. */ - rec_argc = argc + 11 * perf_pmu__num_mem_pmus(); + rec_argc = argc + 11 * perf_pmus__num_mem_pmus(); rec_argv = 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") == 0) print_hwcache_events(&print_cb, ps); else if (strcmp(argv[i], "pmu") == 0) - print_pmu_events(&print_cb, ps); + perf_pmus__print_pmu_events(&print_cb, ps); else if (strcmp(argv[i], "sdt") == 0) print_sdt_events(&print_cb, ps); else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 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 = 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, struct perf_mem *mem) PARSE_OPT_KEEP_UNKNOWN); /* Max number of arguments multiplied by number of PMUs that can support them. */ - rec_argc = argc + 9 * perf_pmu__num_mem_pmus(); + rec_argc = argc + 9 * perf_pmus__num_mem_pmus(); if (mem->cpu_list) rec_argc += 2; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aaf18e487757..2fc59e5c123e 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 = 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; - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return; evlist__for_each_entry(evlist, pos) { @@ -4191,7 +4193,7 @@ int cmd_record(int argc, const char **argv) evlist__warn_user_requested_cpus(rec->evlist, rec->opts.target.cpu_list); - rec->opts.target.hybrid = perf_pmu__has_hybrid(); + rec->opts.target.hybrid = perf_pmus__has_hybrid(); if (callchain_param.enabled && callchain_param.record_mode == CALLCHAIN_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) 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) evlist__warn_user_requested_cpus(evsel_list, target.cpu_list); - target.hybrid = perf_pmu__has_hybrid(); + target.hybrid = 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" #define ENV "PERF_TEST_ATTR" @@ -185,7 +185,7 @@ static int test__attr(struct test_suite *test __maybe_unused, int subtest __mayb char path_dir[PATH_MAX]; char *exec_path; - if (perf_pmu__has_hybrid()) + if (perf_pmus__has_hybrid()) return TEST_SKIP; /* First try development tree tests. */ diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_groups.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 = NULL; int i, fd; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { for (i = 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-events.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 = false; TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (pmu->type == evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched = true; @@ -1443,12 +1443,12 @@ static int test__checkevent_config_cache(struct evlist *evlist) static bool test__pmu_cpu_valid(void) { - return !!perf_pmu__find("cpu"); + return !!perf_pmus__find("cpu"); } static bool test__intel_pt_valid(void) { - return !!perf_pmu__find("intel_pt"); + return !!perf_pmus__find("intel_pt"); } 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 = NULL; int ret = TEST_OK; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != 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-metric.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" 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() == 0); TEST_ASSERT_VAL("Memory bandwidth", test_memory_bandwidth() == 0); - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() == 0); TEST_ASSERT_VAL("test metric group", test_metric_group() == 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 __maybe_unused, struct perf_pmu *pmu = NULL; unsigned long i; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { int count = 0; if (!is_pmu_core(pmu->name)) diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.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" static int spin_sleep(void) { @@ -375,7 +375,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub cpu_clocks_evsel = evlist__last(evlist); /* Second event */ - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { cycles = "cpu_core/cycles/u"; err = 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 #define TEMPL "/tmp/perf-test-XXXXXX" @@ -41,7 +41,7 @@ static int session_write_header(char *path) session = perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { session->evlist = 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" #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 = NULL; u32 nr = 0, i = 0; - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return NULL; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (pmu->is_core) nr++; } @@ -488,7 +489,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; tp->nr = nr; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (!pmu->is_core) continue; 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" struct perf_env perf_env; @@ -323,7 +324,7 @@ int perf_env__read_pmu_mappings(struct perf_env *env) u32 pmu_num = 0; struct strbuf sb; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = 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; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = 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; - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; pmu = 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 = perf_pmu__scan(pmu))) { + while ((pmu = 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; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { if (!pmu->name) continue; @@ -1550,7 +1551,7 @@ static int __write_pmu_caps(struct feat_fd *ff, struct perf_pmu *pmu, static int write_cpu_pmu_caps(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { - struct perf_pmu *cpu_pmu = perf_pmu__find("cpu"); + struct perf_pmu *cpu_pmu = perf_pmus__find("cpu"); int ret; if (!cpu_pmu) @@ -1570,7 +1571,7 @@ static int write_pmu_caps(struct feat_fd *ff, int nr_pmu = 0; int ret; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { if (!pmu->name || !strcmp(pmu->name, "cpu") || perf_pmu__caps_parse(pmu) <= 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 = NULL; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { if (!pmu->is_core) continue; @@ -1601,7 +1602,7 @@ static int write_pmu_caps(struct feat_fd *ff, } pmu = NULL; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { if (pmu->is_core || !pmu->nr_caps) continue; 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" unsigned int perf_mem_events__loads_ldlat = 30; @@ -128,14 +129,14 @@ int perf_mem_events__init(void) if (!e->tag) continue; - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, "cpu"); e->supported = perf_mem_event__supported(mnt, sysfs_name); } else { struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (!pmu->is_core) continue; @@ -175,7 +176,7 @@ static void perf_mem_events__print_unsupport_hybrid(struct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (!pmu->is_core) continue; @@ -201,7 +202,7 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, if (!e->record) continue; - 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; } - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { if (!pmu->is_core) continue; rec_argv[i++] = "-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 = !strcmp(pmu, "all") || !perf_pmu__has_hybrid() || !is_pmu_hybrid(pmu); + bool all_pmus = !strcmp(pmu, "all") || !perf_pmus__has_hybrid() || !is_pmu_hybrid(pmu); *out_metric_events = NULL; ids_size = 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; - while ((pmu = perf_pmu__scan(pmu))) { + while ((pmu = perf_pmus__scan(pmu))) { 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 = get_config_name(head_config); const char *metric_id = get_config_metric_id(head_config); - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != 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 *attr, struct parse_events_error *err) { if (term->type_term == PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE) { - const struct perf_pmu *pmu = perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type); if (perf_pmu__supports_legacy_cache(pmu)) { attr->type = PERF_TYPE_HW_CACHE; @@ -1202,7 +1203,7 @@ static int config_term_pmu(struct perf_event_attr *attr, term->type_term = PARSE_EVENTS__TERM_TYPE_USER; } if (term->type_term == PARSE_EVENTS__TERM_TYPE_HARDWARE) { - const struct perf_pmu *pmu = perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type); 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_state *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=*/NULL, type, config, head_config); - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { int ret; if (!perf_pmu__supports_wildcard_numeric(pmu)) @@ -1528,7 +1529,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, struct parse_events_error *err = parse_state->error; LIST_HEAD(config_terms); - pmu = parse_state->fake_pmu ?: perf_pmu__find(name); + pmu = parse_state->fake_pmu ?: perf_pmus__find(name); 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_state *parse_state, INIT_LIST_HEAD(list); - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { struct perf_pmu_alias *alias; bool auto_merge_stats; @@ -2409,7 +2410,7 @@ static int set_filter(struct evsel *evsel, const void *arg) return 0; } - while ((pmu = perf_pmu__scan(pmu)) != NULL) + while ((pmu = perf_pmus__scan(pmu)) != NULL) if (pmu->type == evsel->core.attr.type) { found = 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; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { char *name = pmu->name; 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" @@ -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); for (q = p; strsep(&p, ",{}"); q = p) { sep = p ? str + (p - p_orig - 1) : ""; @@ -86,7 +86,7 @@ int parse_libpfm_events_option(const struct option *opt, const char *str, goto error; } - pmu = perf_pmu__find_by_type((unsigned int)attr.type); + pmu = perf_pmus__find_by_type((unsigned int)attr.type); evsel = parse_events__add_event(evlist->core.nr_entries, &attr, q, /*metric_id=*/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; }; -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 *alias, return 0; } -/* Add all pmus in sysfs to pmu list: */ -static void pmu_read_sysfs(void) -{ - int fd; - DIR *dir; - struct dirent *dent; - - fd = perf_pmu__event_source_devices_fd(); - if (fd < 0) - return; - - dir = fdopendir(fd); - if (!dir) - return; - - while ((dent = 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/arm64) * 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"); } -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 char *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); pmu->default_config = perf_pmu__get_default_config(pmu); @@ -992,61 +960,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *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_pmu__find_by_type(unsigned int type) -{ - struct perf_pmu *pmu; - - list_for_each_entry(pmu, &pmus, list) - if (pmu->type == 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 = 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 = NULL; - - if (evsel->pmu) - return evsel->pmu; - - while ((pmu = perf_pmu__scan(pmu)) != NULL) { - if (pmu->type == evsel->core.attr.type) - break; - } - - ((struct evsel *)evsel)->pmu = pmu; - return pmu; -} - bool evsel__is_aux_event(const struct evsel *evsel) { struct perf_pmu *pmu = 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 |= field_prep(bits, val); } -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 = pmu_find(name); - if (pmu) - return pmu; - - dirfd = perf_pmu__event_source_devices_fd(); - pmu = 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 = 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) } } -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 = snprintf(buf, len, "%s/%s", pmu->name, alias->name); - - list_for_each_entry(term, &alias->terms, list) { - if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) - used += snprintf(buf + used, sub_non_neg(len, used), - ",%s=%s", term->config, - term->val.str); - } - - if (sub_non_neg(len, used) > 0) { - buf[used] = '/'; - used++; - } - if (sub_non_neg(len, used) > 0) { - buf[used] = '\0'; - used++; - } else - buf[len - 1] = '\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 = a; - const struct sevent *bs = b; - const char *a_pmu_name = NULL, *b_pmu_name = NULL; - const char *a_name = "//", *a_desc = NULL, *a_topic = ""; - const char *b_name = "//", *b_desc = NULL, *b_topic = ""; - int ret; - - if (as->event) { - a_name = as->event->name; - a_desc = as->event->desc; - a_topic = as->event->topic ?: ""; - a_pmu_name = as->event->pmu_name; - } - if (bs->event) { - b_name = bs->event->name; - b_desc = bs->event->desc; - b_topic = bs->event->topic ?: ""; - b_pmu_name = bs->event->pmu_name; - } - /* Put extra events last. */ - if (!!a_desc != !!b_desc) - return !!a_desc - !!b_desc; - - /* Order by topics. */ - ret = strcmp(a_topic, b_topic); - if (ret) - return ret; - - /* Order CPU core events to be first */ - if (as->is_cpu != bs->is_cpu) - return as->is_cpu ? -1 : 1; - - /* Order by PMU name. */ - if (as->pmu != bs->pmu) { - a_pmu_name = a_pmu_name ?: (as->pmu->name ?: ""); - b_pmu_name = b_pmu_name ?: (bs->pmu->name ?: ""); - ret = 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); } -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; } -int perf_pmu__num_mem_pmus(void) -{ - struct perf_pmu *pmu = NULL; - int count = 0; - - while ((pmu = perf_pmu__scan(pmu)) != 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 = NULL, *b_pmu_name = NULL; - const char *a_name = "//", *b_name = "//"; - - - if (alias_a->event) { - a_name = alias_a->event->name; - a_pmu_name = alias_a->event->pmu_name; - } - if (alias_b->event) { - b_name = alias_b->event->name; - b_pmu_name = 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 = a_pmu_name ?: (alias_a->pmu->name ?: ""); - b_pmu_name = b_pmu_name ?: (alias_b->pmu->name ?: ""); - return strcmp(a_pmu_name, b_pmu_name) == 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 = 0; - int len, j; - struct sevent *aliases; - - pmu = NULL; - len = 0; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { - list_for_each_entry(event, &pmu->aliases, list) - len++; - if (pmu->selectable) - len++; - } - aliases = zalloc(sizeof(struct sevent) * len); - if (!aliases) { - pr_err("FATAL: not enough memory to print PMU events\n"); - return; - } - pmu = NULL; - j = 0; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { - bool is_cpu = pmu->is_core; - - list_for_each_entry(event, &pmu->aliases, list) { - aliases[j].event = event; - aliases[j].pmu = pmu; - aliases[j].is_cpu = is_cpu; - j++; - } - if (pmu->selectable) { - aliases[j].event = NULL; - aliases[j].pmu = pmu; - aliases[j].is_cpu = is_cpu; - j++; - } - } - len = j; - qsort(aliases, len, sizeof(struct sevent), cmp_sevent); - for (j = 0; j < len; j++) { - const char *name, *alias = NULL, *scale_unit = NULL, - *desc = NULL, *long_desc = NULL, - *encoding_desc = NULL, *topic = NULL, - *pmu_name = NULL; - bool deprecated = 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 = aliases[j].pmu->name; - buf_used = snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; - name = buf; - } else { - if (aliases[j].event->desc) { - name = aliases[j].event->name; - buf_used = 0; - } else { - name = format_alias(buf, sizeof(buf), aliases[j].pmu, - aliases[j].event); - if (aliases[j].is_cpu) { - alias = name; - name = aliases[j].event->name; - } - buf_used = strlen(buf) + 1; - } - pmu_name = aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); - if (strlen(aliases[j].event->unit) || aliases[j].event->scale != 1.0) { - scale_unit = buf + buf_used; - buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%G%s", aliases[j].event->scale, - aliases[j].event->unit) + 1; - } - desc = aliases[j].event->desc; - long_desc = aliases[j].event->long_desc; - topic = aliases[j].event->topic; - encoding_desc = buf + buf_used; - buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", pmu_name, aliases[j].event->str) + 1; - deprecated = 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; - pmu = NULL; - while ((pmu = perf_pmu__scan(pmu)) != 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); } -bool perf_pmu__has_hybrid(void) -{ - static bool hybrid_scanned, has_hybrid; - - if (!hybrid_scanned) { - struct perf_pmu *pmu = NULL; - - while ((pmu = perf_pmu__scan(pmu)) != NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { - has_hybrid = true; - break; - } - } - hybrid_scanned = 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); } -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; }; -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 from, long to); int perf_pmu__format_parse(int dirfd, struct list_head *head); void perf_pmu__del_formats(struct list_head *formats); -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); 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); -bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); 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 *filename, int flags); -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); #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" -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 = pmu_find(name); + if (pmu) + return pmu; + + dirfd = perf_pmu__event_source_devices_fd(); + pmu = 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 = 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 = perf_pmu__event_source_devices_fd(); + if (fd < 0) + return; + + dir = fdopendir(fd); + if (!dir) + return; + + while ((dent = 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 == 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 = list_prepare_entry(pmu, &pmus, list); + } + list_for_each_entry_continue(pmu, &pmus, list) + return pmu; + return NULL; +} const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != 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(const char *str) } return NULL; } + +int perf_pmus__num_mem_pmus(void) +{ + struct perf_pmu *pmu = NULL; + int count = 0; + + while ((pmu = perf_pmus__scan(pmu)) != 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 = a; + const struct sevent *bs = b; + const char *a_pmu_name = NULL, *b_pmu_name = NULL; + const char *a_name = "//", *a_desc = NULL, *a_topic = ""; + const char *b_name = "//", *b_desc = NULL, *b_topic = ""; + int ret; + + if (as->event) { + a_name = as->event->name; + a_desc = as->event->desc; + a_topic = as->event->topic ?: ""; + a_pmu_name = as->event->pmu_name; + } + if (bs->event) { + b_name = bs->event->name; + b_desc = bs->event->desc; + b_topic = bs->event->topic ?: ""; + b_pmu_name = bs->event->pmu_name; + } + /* Put extra events last. */ + if (!!a_desc != !!b_desc) + return !!a_desc - !!b_desc; + + /* Order by topics. */ + ret = strcmp(a_topic, b_topic); + if (ret) + return ret; + + /* Order CPU core events to be first */ + if (as->is_cpu != bs->is_cpu) + return as->is_cpu ? -1 : 1; + + /* Order by PMU name. */ + if (as->pmu != bs->pmu) { + a_pmu_name = a_pmu_name ?: (as->pmu->name ?: ""); + b_pmu_name = b_pmu_name ?: (bs->pmu->name ?: ""); + ret = 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 = NULL, *b_pmu_name = NULL; + const char *a_name = "//", *b_name = "//"; + + + if (alias_a->event) { + a_name = alias_a->event->name; + a_pmu_name = alias_a->event->pmu_name; + } + if (alias_b->event) { + b_name = alias_b->event->name; + b_pmu_name = 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 = a_pmu_name ?: (alias_a->pmu->name ?: ""); + b_pmu_name = b_pmu_name ?: (alias_b->pmu->name ?: ""); + return strcmp(a_pmu_name, b_pmu_name) == 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 = snprintf(buf, len, "%s/%s", pmu->name, alias->name); + + list_for_each_entry(term, &alias->terms, list) { + if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) + used += snprintf(buf + used, sub_non_neg(len, used), + ",%s=%s", term->config, + term->val.str); + } + + if (sub_non_neg(len, used) > 0) { + buf[used] = '/'; + used++; + } + if (sub_non_neg(len, used) > 0) { + buf[used] = '\0'; + used++; + } else + buf[len - 1] = '\0'; + + return buf; +} + +void perf_pmus__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 = 0; + int len, j; + struct sevent *aliases; + + pmu = NULL; + len = 0; + while ((pmu = perf_pmus__scan(pmu)) != NULL) { + list_for_each_entry(event, &pmu->aliases, list) + len++; + if (pmu->selectable) + len++; + } + aliases = zalloc(sizeof(struct sevent) * len); + if (!aliases) { + pr_err("FATAL: not enough memory to print PMU events\n"); + return; + } + pmu = NULL; + j = 0; + while ((pmu = perf_pmus__scan(pmu)) != NULL) { + bool is_cpu = pmu->is_core; + + list_for_each_entry(event, &pmu->aliases, list) { + aliases[j].event = event; + aliases[j].pmu = pmu; + aliases[j].is_cpu = is_cpu; + j++; + } + if (pmu->selectable) { + aliases[j].event = NULL; + aliases[j].pmu = pmu; + aliases[j].is_cpu = is_cpu; + j++; + } + } + len = j; + qsort(aliases, len, sizeof(struct sevent), cmp_sevent); + for (j = 0; j < len; j++) { + const char *name, *alias = NULL, *scale_unit = NULL, + *desc = NULL, *long_desc = NULL, + *encoding_desc = NULL, *topic = NULL, + *pmu_name = NULL; + bool deprecated = 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 = aliases[j].pmu->name; + buf_used = snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; + name = buf; + } else { + if (aliases[j].event->desc) { + name = aliases[j].event->name; + buf_used = 0; + } else { + name = format_alias(buf, sizeof(buf), aliases[j].pmu, + aliases[j].event); + if (aliases[j].is_cpu) { + alias = name; + name = aliases[j].event->name; + } + buf_used = strlen(buf) + 1; + } + pmu_name = aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); + if (strlen(aliases[j].event->unit) || aliases[j].event->scale != 1.0) { + scale_unit = buf + buf_used; + buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%G%s", aliases[j].event->scale, + aliases[j].event->unit) + 1; + } + desc = aliases[j].event->desc; + long_desc = aliases[j].event->long_desc; + topic = aliases[j].event->topic; + encoding_desc = buf + buf_used; + buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%s/%s/", pmu_name, aliases[j].event->str) + 1; + deprecated = 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 = 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 = NULL; + + while ((pmu = perf_pmus__scan(pmu)) != NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid = true; + break; + } + } + hybrid_scanned = true; + } + return has_hybrid; +} + +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) +{ + struct perf_pmu *pmu = evsel->pmu; + + if (!pmu) { + pmu = perf_pmus__find_by_type(evsel->core.attr.type); + ((struct evsel *)evsel)->pmu = 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 -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); const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); +int perf_pmus__num_mem_pmus(void); +void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *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 = NULL; const char *event_type_descriptor = event_type_descriptors[PERF_TYPE_HW_CACHE]; - while ((pmu = perf_pmu__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != 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_cb, void *print_state) print_hwcache_events(print_cb, print_state); - print_pmu_events(print_cb, print_state); + perf_pmus__print_pmu_events(print_cb, print_state); print_cb->print_event(print_state, /*topic=*/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" #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,7 +681,7 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; evlist__for_each_entry(evlist, evsel) { From patchwork Wed May 17 14:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245157 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74870C77B75 for ; Wed, 17 May 2023 14:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+aYjRkUuBDcUzJ2KzCIpQGZ5bdRH09axUnvTdtpgAto=; b=0f9X5YLooJywSI hwAYRCoXfyd74JpeFP6hRaPmiAlAPVcmYPav9TGy1xFc8fn27x3gS3jXWxuWYOF6CvS4UmCsuDCMs K8ukbXRkfb6BqMa1rLlSoB3M6sE5yWDEE7Y/2aNwJrEwPb6utJ9On4PeByyAyeTyi38guAG4R51G1 LEIhmTs91r2PMSHh5ku9Utk/SjfdnlMtMwZvEF8sGsAEqh2RlHT7Cam5FH4RM5TkLqxARm8FQtqUe qCq4UYk+OAyeCuwu04ug3A+NYXlAX+lvQyqQ2FIrbIXyd+UPSEKUJBX6rf9Gzs9R0etUsZmfSvzu9 cOx5ErfJHCNSG8GkUR6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIco-00ADm3-2y; Wed, 17 May 2023 14:59:34 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIce-00ADex-1Z for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:27 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-643842c87dbso896950b3a.1 for ; Wed, 17 May 2023 07:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335562; x=1686927562; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Gq44kqAcq+8j0vM8i7DmjRKdLm4tW5UxG/1gkdirBgE=; b=VHmYUAkEUWg36YLgV+rwU3ZWcraGECwD3Qzgmq3w1f/i09HEF0I4OdmqXnZIMtAcAZ TvSvGmTuPxv47bkmdlz7rcIiB6aYycNA5lDTm5hsP3zSorkj27QEDFdvSgaK4iOqKkn9 9XpCqNYA/cVkubIXrlxrqsTGvUT7h0IzcmsHniG8pFzgk8wLlYz7klezstwmsqftJrfl VEgEn/IAYzEnaQncmQNmsIF/A3Gv5cOsQLIKe+KCXxJCIhTOXUHgHH2OwTsqsvka2VEA X30hKvxJztGGyA+wowlbf9hU0kqTarsjEV1v3neRN55FTrRdjj1H3sFnQnH6U2n0ukO/ KnIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335562; x=1686927562; 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=Gq44kqAcq+8j0vM8i7DmjRKdLm4tW5UxG/1gkdirBgE=; b=PD/+oSfFhrTXPqRau2Pnc264dHZD4bqG/ppKGXO1iAW30lCOn7BmNyIxSvZxxklETm Lg0DuyVUOd7C9gEwbZYpXWOShogPMz5gLuonYRPaBu/ToufwjGOzCIncNSupt0JiIG/y xuRcjJTm/d7Knz6u6gLvJklQUrOV+D1XgIp5Rt86jFItA0rOH0l6BqNqRb14ibkeSx/r HiCI56RuOiZt6tWhWkdIGewXTw2ArItGNTcpo8iCK98Ibq7QtP6jtrBcFokxKR7TQd+x 0hgPZsZ1mH+cZjF3rpHYWuFsO2Kot5hbBYbNSDA12Ju+FH1SjKA51iw4B+kieifRm836 TCFQ== X-Gm-Message-State: AC+VfDw0VhaWZKcXorLg8WEYzbSrpiBnt+U0IJ7WgtpVkkCYj3RjNIbk Zt2U2izKe5zISjxYWThDmaryI3CqRkk7 X-Google-Smtp-Source: ACHHUZ5VgBZWq+DJkhTCA1fH23jV7JtykoO+x4kMt4aMxIEotHunrFLTjmnINXjqoA/ilJDF4+7T0TWXEtyy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6a00:22d0:b0:643:78c3:fea3 with SMTP id f16-20020a056a0022d000b0064378c3fea3mr431257pfj.6.1684335562320; Wed, 17 May 2023 07:59:22 -0700 (PDT) Date: Wed, 17 May 2023 07:58:00 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-21-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 20/23] perf pmus: Split pmus list into core and uncore 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075924_553809_1AE92134 X-CRM114-Status: GOOD ( 18.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Split the pmus list into core and uncore. This will later allow for the core and uncore 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..dd029a810147 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -12,13 +12,19 @@ #include "pmu.h" #include "print-events.h" -static LIST_HEAD(pmus); +static LIST_HEAD(core_pmus); +static LIST_HEAD(uncore_pmus); void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; - 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, &uncore_pmus, list) { list_del(&pmu->list); perf_pmu__delete(pmu); @@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name) { struct perf_pmu *pmu; - 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, &uncore_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; dirfd = perf_pmu__event_source_devices_fd(); - pmu = perf_pmu__lookup(&pmus, dirfd, name); + pmu = perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &uncore_pmus, dirfd, name); close(dirfd); return pmu; @@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) if (pmu) return pmu; - return perf_pmu__lookup(&pmus, dirfd, name); + return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &uncore_pmus, dirfd, name); } /* Add all pmus in sysfs to pmu list: */ @@ -93,7 +104,7 @@ static void pmu_read_sysfs(void) while ((dent = 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(uncore_pmus): */ perf_pmu__find2(fd, dent->d_name); } @@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int type) { struct perf_pmu *pmu; - list_for_each_entry(pmu, &pmus, list) + list_for_each_entry(pmu, &core_pmus, list) { if (pmu->type == type) return pmu; - + } + list_for_each_entry(pmu, &uncore_pmus, list) { + if (pmu->type == type) + return pmu; + } return NULL; } +/* + * pmu iterator: If pmu is NULL, we start at the begin, otherwise return the + * 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 = !pmu || pmu->is_core; + if (!pmu) { pmu_read_sysfs(); - pmu = list_prepare_entry(pmu, &pmus, list); + pmu = list_prepare_entry(pmu, &core_pmus, list); + } + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + pmu = NULL; + pmu = list_prepare_entry(pmu, &uncore_pmus, list); } - list_for_each_entry_continue(pmu, &pmus, list) + list_for_each_entry_continue(pmu, &uncore_pmus, list) return pmu; return NULL; } From patchwork Wed May 17 14:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245158 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C93E2C77B7D for ; Wed, 17 May 2023 14:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TMnWOR+uK0Z5DtXYRhEnP9RHV1iWI1O2+a0KqskO54o=; b=0ZvORZQviNQ4b8 ax9WmvmGh/zrIVnlQ5p9zyQgVB3X/znVbmXwyCNyTwhpwnRBEliulQN6mTJkK5iyaF/7lL5gypmop z4tVE1LIHq2VdENmRPimQWpGSebdel0GUMUEsS+na0JRkIK+T1zA7arV2C6Cx1htyJTO/C5cEmf0I mncp4hgvyb5wEVLlRFf+hmwjsUAbFyo8dVjOoEu1ZtKp9b2IrlTJzcb8lK8sKBlIBO8sQUb3AaWDv AMWaLnlbnL0Tq+4NFdpOIY8UJC8FVTWxxXvjzXfRMLuuSuB5VGi5qc2l7ZAqslPFXvHWvlofHD8FM iMD3Rgrd+jQIJA0ZGHZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcq-00ADn0-0G; Wed, 17 May 2023 14:59:36 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcg-00ADgV-0n for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:30 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561ba4e8ceeso13549987b3.3 for ; Wed, 17 May 2023 07:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335565; x=1686927565; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=yC5DfBqeNU7xMU35WgrfOfKTZ21gNhY61YiNvK3bdAU=; b=l1yJPVun4Yeuvb9fyBcdBnHzUuQ7mDoTl7HeusB29PZLArA8a86pLrEoUOPDk0aA3x 830XSVW0foJybelyPIdUHnT7QwrpbQQbnzjMDvgUqThIq7StAWjx0/O1N+HkkTieADZb ZPOgouyR/lnlX29Gf2qBa1Sxz+i0Hqjq/2IZsyIyj53oS9AkW5NvJ3soipV4a79Spou1 7BBD1Fptdi+umiQ/kpMf28j5O9m/w8GDo8shhMicVrcT8KjCcNtqKrwvZ5aFC2MHsX0m CRoSW3g2gBQs3PyXG46+3GHNDSgrm5XWGGJxElBBgGc+d8MMdxRSGzVuTCBnV5ji4+MJ Uksg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335565; x=1686927565; 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=yC5DfBqeNU7xMU35WgrfOfKTZ21gNhY61YiNvK3bdAU=; b=Y/CM79mFgAMmobgxva6e0WCjC5+vlkgcyfF+WstFqZ6kuThZnBS4z5f7mqCkzDzWIQ QErBbnHfA+zcytreGjDw9cqp4p9HD4gIKQqhkRyKBWDFQLcUKnei/KpcnNPUM6QlGwtE O0E3NzpcmdQJ3vNuMLB0foJ5pc8MCy0fi5n08xpaitcghKP9HkHZio1H+yod37efUDtu L333WuGFH/E800fi7bWK+tqCb1Q+pp2NPl2jCnqqG+j6PuERVPO2tRCiRRs9cvJrwUfM eB0PeM12BsFWUg7tGig8nC1VFgAtZAECoOq9sG/GjwgIE5zFBLbSrojO4XT1trwt/N82 No0w== X-Gm-Message-State: AC+VfDwXCE997x04IgHoAN8GfWyAhthovc1pQ9xIef9a7u9P5wRZShGG ygHqpW4j7fe7vlBMBCXCDXZtM+Zu97oW X-Google-Smtp-Source: ACHHUZ59WuYvewSrI37ZOH5Hdfipn6zydyNzvDhTCA69vFGZyatKEmX+DU3MlbKHb2229ijcox8HebrspBC7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a81:ed0a:0:b0:561:878a:687c with SMTP id k10-20020a81ed0a000000b00561878a687cmr3823173ywm.4.1684335564948; Wed, 17 May 2023 07:59:24 -0700 (PDT) Date: Wed, 17 May 2023 07:58:01 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-22-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075926_313726_D226FDD6 X-CRM114-Status: GOOD ( 25.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = NULL; - while ((pmu = perf_pmus__scan(pmu))) { - if (!is_pmu_core(pmu->name)) - continue; - + while ((pmu = 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/evlist.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; } - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; - if (!pmu->is_core) - continue; - evsel = evsel__new(attrs + i); if (evsel == NULL) goto out_delete_partial_list; diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/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 = perf_pmus__scan(pmu)) != NULL) { - if (pmu->is_core) { - type = pmu->type; - break; - } + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + type = pmu->type; + break; } attr.config |= 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; }; static const struct option options[] = { @@ -53,6 +54,7 @@ static int save_result(void) r = results + nr_pmus; r->name = strdup(pmu->name); + r->is_core = pmu->is_core; r->nr_caps = pmu->nr_caps; r->nr_aliases = 0; @@ -72,7 +74,7 @@ static int save_result(void) return 0; } -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) for (int i = 0; i < nr_pmus; i++) { r = &results[i]; + if (core_only && !r->is_core) + continue; + pmu = perf_pmus__find(r->name); if (pmu == 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; init_stats(&stats); @@ -142,26 +146,30 @@ static int run_pmu_scan(void) return -1; } - for (i = 0; i < iterations; i++) { - gettimeofday(&start, NULL); - perf_pmus__scan(NULL); - gettimeofday(&end, NULL); - - timersub(&end, &start, &diff); - runtime_us = diff.tv_sec * USEC_PER_SEC + diff.tv_usec; - update_stats(&stats, runtime_us); - - ret = check_result(); - perf_pmus__destroy(); - if (ret < 0) - break; + for (int j = 0; j < 2; j++) { + bool core_only = (j == 0); + + for (unsigned int i = 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 = diff.tv_sec * USEC_PER_SEC + diff.tv_usec; + update_stats(&stats, runtime_us); + + ret = check_result(core_only); + perf_pmus__destroy(); + if (ret < 0) + break; + } + time_average = avg_stats(&stats); + time_stddev = stddev_stats(&stats); + pr_info(" Average%s PMU scanning took: %.3f usec (+- %.3f usec)\n", + core_only ? " core" : "", time_average, time_stddev); } - - time_average = avg_stats(&stats); - time_stddev = 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 __maybe_unused, struct perf_pmu *pmu = NULL; unsigned long i; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { int count = 0; - 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; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (pmu->is_core) - nr++; + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + nr++; } if (nr == 0) return NULL; @@ -489,10 +488,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; tp->nr = nr; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (!pmu->is_core) - continue; - + while ((pmu = perf_pmus__scan_core(pmu)) != 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 = NULL; - while ((pmu = perf_pmus__scan(pmu))) { - if (!pmu->is_core) - continue; - + while ((pmu = perf_pmus__scan_core(pmu))) { ret = __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 = NULL; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (!pmu->is_core) - continue; - + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |= perf_mem_event__supported(mnt, sysfs_name); @@ -176,10 +173,7 @@ static void perf_mem_events__print_unsupport_hybrid(struct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (!pmu->is_core) - continue; - + while ((pmu = perf_pmus__scan_core(pmu)) != 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; } - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (!pmu->is_core) - continue; + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { rec_argv[i++] = "-e"; s = 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, int *idx, const char *name, const char *config_name = get_config_name(head_config); const char *metric_id = get_config_metric_id(head_config); - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + /* Legacy cache events are only supported by core PMUs. */ + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; - /* Skip unsupported PMUs. */ - if (!perf_pmu__supports_legacy_cache(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; @@ -1480,12 +1477,10 @@ int parse_events_add_numeric(struct parse_events_state *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=*/NULL, type, config, head_config); - while ((pmu = perf_pmus__scan(pmu)) != NULL) { + /* Wildcards on numeric values are only supported by core PMUs. */ + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { int ret; - if (!perf_pmu__supports_wildcard_numeric(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; 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 perf_pmu *pmu) return pmu->is_core; } -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); } -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); 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 dd029a810147..fcd61bddffc3 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) } /* 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 = 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(uncore_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 = !pmu || pmu->is_core; if (!pmu) { - pmu_read_sysfs(); + pmu_read_sysfs(/*core_only=*/false); pmu = 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; } +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu) +{ + if (!pmu) { + pmu_read_sysfs(/*core_only=*/true); + pmu = 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 = NULL; @@ -176,9 +190,9 @@ int perf_pmus__num_mem_pmus(void) struct perf_pmu *pmu = NULL; int count = 0; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (perf_pmu__is_mem_pmu(pmu)) - count++; + /* All core PMUs are for mem events. */ + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + count++; } return count; } @@ -422,8 +436,8 @@ bool perf_pmus__has_hybrid(void) if (!hybrid_scanned) { struct perf_pmu *pmu = NULL; - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + if (is_pmu_hybrid(pmu->name)) { has_hybrid = 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); struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu); const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); 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 = NULL; const char *event_type_descriptor = event_type_descriptors[PERF_TYPE_HW_CACHE]; - while ((pmu = perf_pmus__scan(pmu)) != 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 = perf_pmus__scan_core(pmu)) != NULL) { if (pmu->is_uncore || pmu->type == PERF_TYPE_SOFTWARE) continue; From patchwork Wed May 17 14:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245159 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F667C77B75 for ; Wed, 17 May 2023 14:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xwiBI/kAXCvM2V64ohX0LIHv1Ich0qEGe/50XubuMYA=; b=Zw2yTQCjkzdHWT iFUvu6ko2nh5de5XW7ecMuxqU2TbMLet441zlXoJyTF1ASRWzhBlfBk6ZANdGKGa1d+Z2N0kL7SQ6 FgahdHAJ1dqfH3E0XXrsmvqUlKEZ21DnOPMEnI4fLXFrIF9e+wGsjj6/p3PHKz77TlsMpy+bPzAia ewDgQ++9QqJpKjsATpYceL55/vRCxko7eIp3m+45XopObkDIomsgKhr9ez40VqLY1ELSwJ3ibbHRx 4pwVcvMMNv14bS5FFYAT7AqJdIknNvi0g/Sahv1pGoVfcdCIbdAHBxBd4rWZfuFdtkNZX6MYCR/8a w7P/EAt+IS7Mw3OmkiyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcp-00ADmY-1b; Wed, 17 May 2023 14:59:35 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIci-00ADhu-1d for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:30 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64350db8497so52472b3a.0 for ; Wed, 17 May 2023 07:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335567; x=1686927567; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=YDiC9RY1zs37JQzy/xyTqLqcVVdBqmzj5pMMgSLBC2k=; b=qAH8dA1MBDw//W5b+cN/DyreQ6vmZocG/5dFnQOttiCARmjK0YdCXVii5SB34CphxF t0EWRnE0ucijXh15k5s8O0tia1jN2x38X9PcYH3Y4zVveSxPafkqFQPA98q+y5/vfYNo FazWN+SzEkBfdi/4u3XgdYANIAsdEDicFwG0/5hwBoolAhev1nR3DqPyK3VDyKCAU35d O3EifEaOZY32H7blE5VyS+nybpP21nHrS4hRx2lYtPmDC+FgDsJVbP4NbQ2r+xhn+UaX aTVJNI9fVWPjQeSkEw4Py4XHBB3s27d5AJq0V7LVs36Sh2kfOP5eWe9tmGamPDySW5mz 9Z3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335567; x=1686927567; 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=YDiC9RY1zs37JQzy/xyTqLqcVVdBqmzj5pMMgSLBC2k=; b=jUdi5UcsYzSgzHrZgqw3Alv8i36vcYIRzBn8/cRo69HoqOWkjF4ohiTTo9LKkYUBga xuIvkq+M+fB6Rao42DytqqX3ebNLl8Q3cgiVKNov1QzBqXrgbsmERptWrucNb6XCjbWA W6br9eUsPd3hUAPOGjdsxtIoTWHUeeYPuMqAtpq+Dp6KVn/3JmylN993FWjbWrRW0fgD lAqFSh6g036KaMSOWfXIgFTd5dh23YcDRlMaQIZ8c5Uastf6OdYdHTP6c/el3kD4fqgA NetZGeBI3qyy/4/dWhAskJq0tyW0mybJbiE3b3m6xipgL+9Y3+gQolQytQF0YsqdQ/Ow ffhA== X-Gm-Message-State: AC+VfDy6eZuQdSiXcY/AmTOIshUTrFoNNLz2h6f9WTRpDTFBZyPOs9gr L1gfZfCcUh1W8wPyWICnoCUuTTli2y3x X-Google-Smtp-Source: ACHHUZ7R1CC0OSVS8g/0P1vzZZ3gyexPDHVj5wxcC6YMu764P99A+vF1FR2cVD8xlr3Hp979O/PgNurnppuJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6a00:2daa:b0:63b:8571:8109 with SMTP id fb42-20020a056a002daa00b0063b85718109mr429383pfb.3.1684335567322; Wed, 17 May 2023 07:59:27 -0700 (PDT) Date: Wed, 17 May 2023 07:58:02 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-23-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_075928_564617_79785F3D X-CRM114-Status: GOOD ( 18.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 fcd61bddffc3..331c6ad40504 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -14,6 +14,8 @@ static LIST_HEAD(core_pmus); static LIST_HEAD(uncore_pmus); +static bool read_sysfs_core_pmus; +static bool read_sysfs_all_pmus; void perf_pmus__destroy(void) { @@ -29,6 +31,8 @@ void perf_pmus__destroy(void) perf_pmu__delete(pmu); } + read_sysfs_core_pmus = false; + read_sysfs_all_pmus = false; } 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; /* * 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; + if (read_sysfs_all_pmus) + return NULL; + + core_pmu = is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + dirfd = perf_pmu__event_source_devices_fd(); - pmu = perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &uncore_pmus, dirfd, name); + pmu = perf_pmu__lookup(core_pmu ? &core_pmus : &uncore_pmus, dirfd, name); close(dirfd); 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; /* * 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; - return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &uncore_pmus, dirfd, name); + if (read_sysfs_all_pmus) + return NULL; + + core_pmu = is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + + return perf_pmu__lookup(core_pmu ? &core_pmus : &uncore_pmus, dirfd, name); } /* 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; + if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) + return; + fd = perf_pmu__event_source_devices_fd(); if (fd < 0) return; @@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) } closedir(dir); + if (core_only) { + read_sysfs_core_pmus = true; + } else { + read_sysfs_core_pmus = true; + read_sysfs_all_pmus = true; + } } struct perf_pmu *perf_pmus__find_by_type(unsigned int type) From patchwork Wed May 17 14:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13245206 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 161BCC77B7D for ; Wed, 17 May 2023 15:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=T/XgCa1eXFcbQLeaDxWKW/rCDlGyIjg3cZD1dAdRJ2E=; b=gMQAy67lNagK+I fRLkjHWXzBnKd8RuWk3xmf7G7E4OXzbjMkfmwP04PJxaJIEnLGbG+wSSQltcWSnOlmLDi9LDY89NS CCb1nY3TkZ415yXrMH8ia9PpbYJWTJfavuzvX+RG3MM/JtcBdT7BemaxSGnUUJy3SnGeTOW93xHOa aR5aeBru+GTlnvlaFXGQehsfa338tUiDM//0ioBAKiN1Wy+1z7Y4NNxKeVF4JDskXWiVizr/bULLj HBx5bKsESRKEZr+BIZjK4LH72F/Zf9m3fP/pZGb+v2myqYashNSoCHaJ7vwKLCS23ZN/XlCpb/qsl Z6MAxIv6qYXyG4RvX/tA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzJ5r-00AJ8l-0F; Wed, 17 May 2023 15:29:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzJ5p-00AJ8I-1Q for linux-arm-kernel@bombadil.infradead.org; Wed, 17 May 2023 15:29:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=u+zByxDvprri5VQ4rcxngDxyCTv45SqKQxUVZ6WFAl8=; b=Quro78kpHRMKbH7QAA+WS3nq+r dk1DkYqfoPDRKogjp6sJnP4Ie+NTlSuFAho6cI5eewpR4jCDTl13Il/hSFXw57FtoDAQ7pYb3zEJc EfXJU3wGUE9qquUNHdfO08me1cab08BxlRk9cqZeoNHle4ycubPFXD1h/fmx1XqKmAGY18IqzwDJW AMOKYXqiXBtHCux1jfzKa3/xd2y9/N8WMo5CxHG5yOGnibwGi3HZv8gSAKymBHEYeiYrGINnXkcba LGCyXIKNopz2bT774JgHqkpm2Qqk241NWw9OfU4KSZPW9ygp7yya3idT9McL1N79B23RSU//utO/5 Y7j3ImTw==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzIcl-00DFwL-0L for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 14:59:32 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba22ced2e95so901453276.1 for ; Wed, 17 May 2023 07:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684335569; x=1686927569; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=u+zByxDvprri5VQ4rcxngDxyCTv45SqKQxUVZ6WFAl8=; b=X27m8yXNS7YV6hq/JvFNnMmsSFMgnEtC0lHw1MpIym8Oz6c4Uh3/VSQ674EJwhKX7y g+ShkfWDEvRemUvxzBBmHg3vE/oiulZ1PfCfm0aNIA1PzEJ16JjSsnB6OknUaX7SB6jO kl2dZgmmym+4sLYku6InDRWz/dDVbcjO3tCyB4wdjMLhTRT/jytO8BxlSVIt0dV5LqVT NDx2fLsz+IW0JLs18pk67UwQGZ/P02WShE/iW/ACZ/PzGR/Io89p2vdQKS2FDV4ya1p0 6w0mL+5iwwsh9PrtZf49Kaf3pCE/s6M95xtyuKHcXiVB8LQ9HqEntp8wL/I4uTp66pc1 m/0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684335569; x=1686927569; 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=u+zByxDvprri5VQ4rcxngDxyCTv45SqKQxUVZ6WFAl8=; b=WbJXeFOfSedrW1eJ6kpg44pTxGziSrmrr3guKR8J1uTejZzvtf1O6HZeCbusEWg9II ofrLyfByAbxxvw6ZPUL4wjq9Tx24s6ch7iwOgsu7sF29jhGkOaJKCI2jjql8rMz9dag3 pcRPIr+kW8PsZEnP1cKuDuY91h5Ho9gmfe/yMp1pay2uTpvGEmdDi2uJYNdBR/6bqqc3 IfhS5qzyq06TuoLNjld6AU6R6SQPpx3PShIYTprbEJwztum0bbCvCqL5kGvCknav+rJ/ wZITGNX/V4j/HJXdfg7arnLP+rgmMxVpZ0LvQ3szlf7TafOkRJDC9CQVp4oAgNsH9feW oGHw== X-Gm-Message-State: AC+VfDy8UDBcfKZ6sFqD9Nk4yPDtsJMVeH0hfGUM3RJB2W3j5AVFhIqb enS/ri2izzMsyyq0PVXAv1+JKVMBikTm X-Google-Smtp-Source: ACHHUZ7UAVxBOYG/LDa6oMf6ainre+wvdt+4UDdQcxKK96Oxl+o3GriG5mOavr8wBDR/SEMUEAtw4PpK7pvH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:628b:7e78:d09b:39b]) (user=irogers job=sendgmr) by 2002:a05:6902:1890:b0:b96:7676:db4a with SMTP id cj16-20020a056902189000b00b967676db4amr26507169ybb.0.1684335569499; Wed, 17 May 2023 07:59:29 -0700 (PDT) Date: Wed, 17 May 2023 07:58:03 -0700 In-Reply-To: <20230517145803.559429-1-irogers@google.com> Message-Id: <20230517145803.559429-24-irogers@google.com> Mime-Version: 1.0 References: <20230517145803.559429-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v1 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 , Raul Silvera , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_155931_275178_D003A798 X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 331c6ad40504..bfb659fa7274 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) } } -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; @@ -150,6 +150,7 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int type) if (pmu->type == type) return pmu; } + list_for_each_entry(pmu, &uncore_pmus, list) { if (pmu->type == type) return pmu; @@ -157,6 +158,18 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int type) return NULL; } +struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +{ + struct perf_pmu *pmu = __perf_pmus__find_by_type(type); + + if (pmu || read_sysfs_all_pmus) + return pmu; + + pmu_read_sysfs(/*core_only=*/false); + pmu = __perf_pmus__find_by_type(type); + return pmu; +} + /* * pmu iterator: If pmu is NULL, we start at the begin, otherwise return the * next pmu. Returns NULL on end.