From nobody Mon Feb 9 13:36:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BACCC7EE2C for ; Wed, 24 May 2023 22:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238036AbjEXWUp (ORCPT ); Wed, 24 May 2023 18:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237763AbjEXWTx (ORCPT ); Wed, 24 May 2023 18:19:53 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A3D10EC for ; Wed, 24 May 2023 15:19:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b24b8a4so1861216276.2 for ; Wed, 24 May 2023 15:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966774; x=1687558774; 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=e3QTDmJoeAun/x66qVBqgKH7fCw3cWk6avEC85L7N9Cg8LlgXzAtlioNM7cjPnq1gY a4SWY0Ah5jhpHg9uI5KbifN8N8KX8O8ZwDxTX7fDdgfY4LtKi9vRQKdi3KpOfuPyei/V +0VYoyOigrLvJBZVgHiG7ICrKnWrURTSkfMMJ1hsXfC5zlCmh/ZbIy/Xy6i/SWP6IXaw fN/r6zDvDBu9AHTBmLQfQYFqiG7nCrMRCOMAFvbA6aTyTqlH4XXAuo9AaU9JRDE0Ym3q UKF3Pgqjupvk7wL5YSz8RpDHbO5wh0h1ppMymLaIyJideR1C3C96K8H/eGGLsplQXWu4 PBSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966774; x=1687558774; 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=anqUCr2txO+G70utR2BJ9AO4MmhK9kFOJM/niOphQSUvt+ziDwzAZ1zUBjO90nWRaF lERBSH/Vh2kJB5NXuwHvxK//RsBTUPiwTwNU1YJ3ptN2Pcx4PHUeeEtNSSs0A0jvJtDU cJVPFBVh67v1Fb7pRpYKCdLhGcBrBabjC1r6I7tDZWgjFmCcq5V1odzhy+5ok9Y/Y8O+ isplz+YxZWU1s3jaaxW6BPKrZk8wTI9LFtkOf8iqV+QCRTYD4YcEzSNjMrF6/UGo5xdC MfQYQlT4kfue0GU/mzuQNpvJEIkgC7cDbpz/rrpOqe1pTSsf1pdsivlH/WB6nv8izB+f jdzw== X-Gm-Message-State: AC+VfDyjF7MdgYz+ai0pvm3kxMaSYCguRyn9P/ZQo0RjnKZQtt3Tg2lJ pOHFHghbFFMfhs9B86wlRPsa9k4AWQsc X-Google-Smtp-Source: ACHHUZ7D9drqIRB2MyurLXcxiCePzmUOMC9VFsJ8EjeKLTVsgpR53rwm2NFY69hSSmDfa3llKWHekDfBwYID X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a5b:c03:0:b0:ba8:5bc9:80fe with SMTP id f3-20020a5b0c03000000b00ba85bc980femr795184ybq.1.1684966774678; Wed, 24 May 2023 15:19:34 -0700 (PDT) Date: Wed, 24 May 2023 15:18:22 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-27-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_pmus__for_each_pmu doesn't lazily initialize pmus making its use error prone. Just use perf_pmu__scan as this only impacts non-performance critical tests. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/bench/pmu-scan.c | 6 ++---- tools/perf/tests/event_groups.c | 7 ++----- tools/perf/tests/parse-events.c | 11 ++++------- tools/perf/util/pmus.h | 2 -- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f0f007843bb8..f4a6c37cbe27 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -40,13 +40,11 @@ static struct pmu_scan_result *results; =20 static int save_result(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; struct list_head *list; struct pmu_scan_result *r; =20 - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { r =3D realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r =3D=3D NULL) return -ENOMEM; diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_group= s.c index 029442b4e9c6..3d9a2b524bba 100644 --- a/tools/perf/tests/event_groups.c +++ b/tools/perf/tests/event_groups.c @@ -50,13 +50,10 @@ static int event_open(int type, unsigned long config, i= nt group_fd) =20 static int setup_uncore_event(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int i, fd; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { for (i =3D 0; i < NR_UNCORE_PMUS; i++) { if (!strcmp(uncore_pmus[i].name, pmu->name)) { pr_debug("Using %s for uncore pmu event\n", pmu->name); diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 72a10bed84fd..277607ede060 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -108,11 +108,11 @@ static int test__checkevent_raw(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched =3D true; @@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __m= aybe_unused, int subtest __ma =20 static int test__pmu_events(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int ret =3D TEST_OK; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { struct stat st; char path[PATH_MAX]; struct dirent *ent; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index d475e2960c10..257de10788e8 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -5,8 +5,6 @@ extern struct list_head pmus; struct perf_pmu; =20 -#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list) - const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 #endif /* __PMUS_H */ --=20 2.40.1.698.g37aff9b760-goog