Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu

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 <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230527072210.2900565-26-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
f24ebe80 597a4276

+8 -18
+2 -4
tools/perf/bench/pmu-scan.c
··· 40 40 41 41 static int save_result(void) 42 42 { 43 - struct perf_pmu *pmu; 43 + struct perf_pmu *pmu = NULL; 44 44 struct list_head *list; 45 45 struct pmu_scan_result *r; 46 46 47 - perf_pmu__scan(NULL); 48 - 49 - perf_pmus__for_each_pmu(pmu) { 47 + while ((pmu = perf_pmu__scan(pmu)) != NULL) { 50 48 r = realloc(results, (nr_pmus + 1) * sizeof(*r)); 51 49 if (r == NULL) 52 50 return -ENOMEM;
+2 -5
tools/perf/tests/event_groups.c
··· 50 50 51 51 static int setup_uncore_event(void) 52 52 { 53 - struct perf_pmu *pmu; 53 + struct perf_pmu *pmu = NULL; 54 54 int i, fd; 55 55 56 - if (list_empty(&pmus)) 57 - perf_pmu__scan(NULL); 58 - 59 - perf_pmus__for_each_pmu(pmu) { 56 + while ((pmu = perf_pmu__scan(pmu)) != NULL) { 60 57 for (i = 0; i < NR_UNCORE_PMUS; i++) { 61 58 if (!strcmp(uncore_pmus[i].name, pmu->name)) { 62 59 pr_debug("Using %s for uncore pmu event\n", pmu->name);
+4 -7
tools/perf/tests/parse-events.c
··· 108 108 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries); 109 109 110 110 perf_evlist__for_each_evsel(&evlist->core, evsel) { 111 - struct perf_pmu *pmu; 111 + struct perf_pmu *pmu = NULL; 112 112 bool type_matched = false; 113 113 114 114 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); 115 - perf_pmus__for_each_pmu(pmu) { 115 + while ((pmu = perf_pmu__scan(pmu)) != NULL) { 116 116 if (pmu->type == evsel->attr.type) { 117 117 TEST_ASSERT_VAL("PMU type expected once", !type_matched); 118 118 type_matched = true; ··· 2243 2243 2244 2244 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2245 2245 { 2246 - struct perf_pmu *pmu; 2246 + struct perf_pmu *pmu = NULL; 2247 2247 int ret = TEST_OK; 2248 2248 2249 - if (list_empty(&pmus)) 2250 - perf_pmu__scan(NULL); 2251 - 2252 - perf_pmus__for_each_pmu(pmu) { 2249 + while ((pmu = perf_pmu__scan(pmu)) != NULL) { 2253 2250 struct stat st; 2254 2251 char path[PATH_MAX]; 2255 2252 struct dirent *ent;
-2
tools/perf/util/pmus.h
··· 5 5 extern struct list_head pmus; 6 6 struct perf_pmu; 7 7 8 - #define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list) 9 - 10 8 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); 11 9 12 10 #endif /* __PMUS_H */