Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2543787rwd; Sun, 21 May 2023 23:56:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6A5yFniqsUgDfiVOLAE+/SPE/exSYcCWd1cykhJHqLMRjXWDWlaj5N7HRVNvGcjNlKWX8a X-Received: by 2002:a17:90b:180f:b0:255:5d65:3a86 with SMTP id lw15-20020a17090b180f00b002555d653a86mr3222821pjb.8.1684738559760; Sun, 21 May 2023 23:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684738559; cv=none; d=google.com; s=arc-20160816; b=auVdXsjt/ImfW+AUyFOT6xECHMfFRM9G+XVtwLnoKGlbg8qWDcaiCAwrrKopxqPr4D BDEoRxC0JC9D9zw1/2c5vCV+DptiBYscueYgsyslNM4LXUrkAMoCXtc8y9IXdkAcRIys RG/0NcpftLHWssP/Lr9v62qHyYi1o2uDl58MLSaBvo9CI/7j2CQgr9+ez/wbhQajKjpd iHDLqJ6FE2b3ro58okPnBNRGMA9UaFPar+aDBnYP9E5wG+y8gTR52d/LCgTOT9fSAab7 tXCHAbBwPPJ91nURo/CCAVekl8yrVNHu9sk6bYf+T/vME0REIRm3g8lSvUfka20soP0V vYKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=plvWfoUBbNbJMjPvmt4YOS2bcbpVRx36BLPKHSncNAvRIYpiy5U3KIbuYddcZXmBdW mWyjkmcKcFq4CtppmcZ7y9weSmnpJ5EIaERMni9ZT1XDkWfCwkQ+I4NHG0lHlSUj+qCL 4s5I+FZpmOrFRWFmfZ1GF3gS1TVeaVWquPSQ6w/qhAvGOu1yOyrnANpMWVGfiPjY3o3U UOtliI3iV9yFo+dAJI182rjS0d8E1O6ree2P4lk2EvSQ/BipfQWW34wdXvXryMIIDi4/ iMjEQIOd1ISA/3n9KdPAxqYG+QxtvkA77iX12QSnB8FWz/lXkC9aNv1mVp74uzAKgVGZ tGtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=OY46Jgo7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v62-20020a638941000000b005304208cfe3si4228276pgd.685.2023.05.21.23.55.45; Sun, 21 May 2023 23:55:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=OY46Jgo7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232062AbjEVGqh (ORCPT + 99 others); Mon, 22 May 2023 02:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231996AbjEVGpq (ORCPT ); Mon, 22 May 2023 02:45:46 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7BB9171C for ; Sun, 21 May 2023 23:44:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-564fb1018bcso16944437b3.0 for ; Sun, 21 May 2023 23:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684737855; x=1687329855; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=OY46Jgo7JQurCKnzauPQ47/oSJ0vOgQW7/xCwH9klbZgxX7c4l/YjZaz+gZzKJVM8w namx7v10lMVDPsl4OTwDTfjU7GogSy8YqSPRFC/9k0RNLcjNZXzch0aqy9rVu1GAk7MN hoQqi/3EnfHnv0SBLPRB8Bstd32Lql577boPt/pOqaQAxwaCJHRjqnI3r/hsGjWVFLCW DwJm7JAfd09zT2DhG7ADqvjy2iUwFSpSO41/sPXW8WQvNvn6fpwxPfUwUumdfpadTifr pWHQgMHsmpOWYLPl1ijEGa7e4zg1GYpQlqbWfjQ8+0XEgYO+GMPNMUJy1e3yiyqdSKyd tGiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684737855; x=1687329855; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=CXAThucdpdzlHPLK9u9p7oHqMrp3kwYYv1nxIOHay61vxwPcmWnvudVS8qlOVAWXLF Nx3S7ew1CXuPCh4rX7KWy9pDHVYZQj+L15MFcDpO7VE69HhRSooWvV1kYO2v1be1xf0j lCwuJKIDXBfbwSZa7KMU28ua2KWgP2NjpkjjQAclvZsEWyetIVqsvRDXUfSvHck2tlZB VPVwmRNQPBxpzmWnM/CMse9bx2ZlXp2cZCSS3RhADgeiKjaNJm5kT6FJDdBXMi25T7HN b5yKlGWfCZCpKdDfvhjfKlbEkLQsUuFNgLWmKWRvr2AyAqre4l0Y46LfMMyFXa8FkqMz JPqQ== X-Gm-Message-State: AC+VfDw0x7SnJBYcz5gz334KQ9BmhfuCkG2mZY1ImsErkABbI7YWGcMz QHpZvTrcY78G0GS9x1r2jaKJA/kBvdK6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:48d9:8c21:e099:7301]) (user=irogers job=sendgmr) by 2002:a0d:ec10:0:b0:561:4cde:92cc with SMTP id q16-20020a0dec10000000b005614cde92ccmr6170274ywn.8.1684737855588; Sun, 21 May 2023 23:44:15 -0700 (PDT) Date: Sun, 21 May 2023 23:43:24 -0700 In-Reply-To: <20230522064330.189127-1-irogers@google.com> Message-Id: <20230522064330.189127-18-irogers@google.com> Mime-Version: 1.0 References: <20230522064330.189127-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v2 17/23] perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/bench/pmu-scan.c | 6 ++---- tools/perf/tests/event_groups.c | 7 ++----- tools/perf/tests/parse-events.c | 11 ++++------- tools/perf/util/pmus.h | 2 -- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f0f007843bb8..f4a6c37cbe27 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -40,13 +40,11 @@ static struct pmu_scan_result *results; 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 */ -- 2.40.1.698.g37aff9b760-goog