From patchwork Fri May 26 21:54: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: 13257431 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 04ED8C77B73 for ; Fri, 26 May 2023 23:06: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=xVMPAodlHAKOAsiJnCX+hAEqgtWsrGAcsv1GapfLgGQ=; b=0GnKyVYoeRxrNx BOfsUOGgOGmsCdQFf8D47PB7HRZHKJQPaf3VNlDIZWVieRlZS4wUoKZjDhfcimg+woti0RTvUF68N e2hEnAyIc5+8EO+2KotfOVeu0UmAihdKfGxbxxJfTsRrUuj/A0c6FSBl5DtrtJOGQEWDRscBDdqko 90uisvYKpPvdt/Mi378BqePbjIz7MgrkKY7iZFKi/2ec+e6krKlYmKVxaP992MOfNy4licqF3EZEW ADEWvQvhxqEvjdMV+7vmaUBQ37uP/KMcJfhgyTLgBOqe1Kq5YfALTiJgsCNTURXuPsfpJkCENbc3y kSA4bT+NiDPkUP+w2csQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2gVK-004Ev2-0X; Fri, 26 May 2023 23:05:50 +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 1q2fOz-0043JW-1q for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:55:14 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb53e6952so2679939276.0 for ; Fri, 26 May 2023 14:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138112; x=1687730112; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T/X9gvmqqlTr2f+usNH0lBMlck3ST4ivZvyTzKecxnA=; b=65p+PGvBBSTJXTUKvDEvTX52HLsGXIN0McqSA3HwufIBaYpAFamqKbdTBekOVORjpa XIMfWf13BpPomeVwm7X6wOpkxIzD6mo8f7RMl9P4el5HI2pfv2TQTpZnC71TqLue0dcw 64PabADsTap6OYPsTjKY/P2VrnxsMgTm0pAo8vTnP2FrD4gJ02LufnzRDYAzeqMOgprA 6i1tNW9chg3NqfKbX8111epyJTQrR4TmfUkWg8USza2ed4z1SJmJZBX265DJ/n2Y1e/t 2uTSQutHDnb/DzVvRQkorC7zHfcQLLNKQ6kRPr7fW8CJCjS5m/YRSJ7VxLOWBG/6XZ0X pWPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138112; x=1687730112; 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=T/X9gvmqqlTr2f+usNH0lBMlck3ST4ivZvyTzKecxnA=; b=DFFQx8iDm1vRdHQEH5MRccKejcR7p83Maui0aJkVdfD3UCsPk5fHM8Ead4cmcx4cAG g8s+hFGUSkmt9tpncBFycM841yco//BVsyB/qo1+h3Sx78hhlomv2HALBYBMkt7XJTvN xQ/SMccoz98gM5e0Ej5eDb0Uc2CI0lmFylQDXN0aVwBlhUvZ+++LtCoHLJilZwdW/q5J SJVWbLCbBiFIqvxTs/GnOYu990FJAeOpAnyU+sDOWVVShJG+BDeDnHV8BKohxQ9Fdzvo Q+eF8YtN6J3xGcaLAgiaYD8v8XqwqYbaRktPMGHGO2XqvFgiBOy59Uj4ZiK43DW4nVi3 yshQ== X-Gm-Message-State: AC+VfDxFVkxCoxsXh9iMom2sgpoKS49D/8mQkozBoQ2GGI9WXfqRkavF EKmzG3f8nSHecbRHS20QMpsnTMxx9mk/ X-Google-Smtp-Source: ACHHUZ6gxH9Jydh1jcuLGZQPtV/wofR+I6ueG/3SpSJ2Pp7mGx6yUANCLB0wC8G9bjzuKqk+P4ubuDM6L3oe X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:ab13:0:b0:ba8:757c:2523 with SMTP id u19-20020a25ab13000000b00ba8757c2523mr1699724ybi.9.1685138112380; Fri, 26 May 2023 14:55:12 -0700 (PDT) Date: Fri, 26 May 2023 14:54:01 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-27-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 26/35] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_145513_608614_5B71A3A6 X-CRM114-Status: GOOD ( 16.51 ) 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 */