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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- 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.606.ga4b1b128d6-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel