From patchwork Sat May 27 07:22: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: 13257601 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 9201DC77B7C for ; Sat, 27 May 2023 08:36:01 +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=YiPFNWtNRxYHjJ UZhFaXmijN+9xXTp6ylA9tRCkVq2tiKhtjA3ld65mmqnuqXgNWTsql//XpEQzEJ7xQ+NCOS1JWKlw r/Pdc3Ua7WKgcUZ9E3oa3nbLqwnykHHyrMjox8ENqQwnwTQuYsJ044fi1yJBPq187vR38t4f/t8KV 3wvbKKq4lcWGUE5z8XGIZKNbwjizlKeiz/WzxQQesJVVrEc1lxXcN21m9TMj/ylZlVvwEGGoyytc2 5F1LzMAoppAMiSGmg2/7jcVb7WqDEvUNKx0xwjVLjcu0mqTpI/OFj1QnbgXCkdLWDUFsFfZgSuH2I AKuY3CB6Om2X6A7GD2LQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2pP0-005FT4-1Z; Sat, 27 May 2023 08:35:54 +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 1q2oGz-0057cb-0w for linux-arm-kernel@lists.infradead.org; Sat, 27 May 2023 07:23:34 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8337a5861so3803064276.0 for ; Sat, 27 May 2023 00:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685172212; x=1687764212; 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=UTkcJQ9GTUFWqOw4t65r0kAx/Mx6gHHo8eOf727kRPDSLg3gf1V12c0nQl4Rw6RcE7 qwxGnstbPTmoD5SkfmoLO30OxMYksdku4Tjxc7CgcChh8mg2KZv+SJ0n8ynHs/6D5qDR sUphbhIbwTECY+2Is/YL9cp6N16DUIWuu1H5r3y4IaD2Vc09i+ijmH/HR4Uwy0Chvc3x 1Uj0LgzxnynlXuXTjoPoGKOW2clftwwB3s5QpS4c4iVreAVB2x6pb6zBge1vUM6Pk6oV yszE0oPFETlXYzAmV6uho2aIhX8UmJzcslvOc+8+HHo4XOgNzYFbEquOsQgYBFbrLnnX IeeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685172212; x=1687764212; 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=jFTJdmWy9FKk0dbyVnXOkWD0eqgnQZdkmnX9ph3ZKJ1E+FtjKE1iVJ7jLlCHNwCsFj WvIF2x7G7J6lV1FQU+iawwkVwwqshXXvsGgSyaRngU+Z6PyNxC7ANV69cRVu1Cxm04zl Sxg9BwHzKWx85aj07Hs88KMnfvOqtLT99GLPAh+lQZm/EqkhPB6t8QLUqp0wdE3mzW9+ LlUuhsB1rylpGlu+YgqlAJmuDp+Cm6k9hQjLLoB7S5rFUoPRgwgyR2eucGTps1P+7D31 UGhgL+ghb/G5AmYYKrImkSzKw8YVYWBUc10z5BFmS6byc2zLtCvp8JdCZmygUoJBc4Cu 9uQw== X-Gm-Message-State: AC+VfDzDvBn/HFD+8YDakhlmHaMbyiewKYSyFxGjDH5bxClvtAIn4D6+ maQq+7Dg2znlIXHRwwDGTfm/DZDH5frX X-Google-Smtp-Source: ACHHUZ7UFBeHBnGcRXmqzitpI1HYPUDBsZrd+2dMBDXrKlieLbDHs54akvgYU2i/GFPg8zIqQQSHaGZmAbNr X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:cb94:0:b0:ba8:1646:c15d with SMTP id b142-20020a25cb94000000b00ba81646c15dmr861617ybg.1.1685172212148; Sat, 27 May 2023 00:23:32 -0700 (PDT) Date: Sat, 27 May 2023 00:22:01 -0700 In-Reply-To: <20230527072210.2900565-1-irogers@google.com> Message-Id: <20230527072210.2900565-26-irogers@google.com> Mime-Version: 1.0 References: <20230527072210.2900565-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v5 25/34] 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-20230527_002333_330500_34664469 X-CRM114-Status: GOOD ( 15.99 ) 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 */