Skip to content

Commit f24ebe8

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 597a427 commit f24ebe8

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

tools/perf/bench/pmu-scan.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ static struct pmu_scan_result *results;
4040

4141
static int save_result(void)
4242
{
43-
struct perf_pmu *pmu;
43+
struct perf_pmu *pmu = NULL;
4444
struct list_head *list;
4545
struct pmu_scan_result *r;
4646

47-
perf_pmu__scan(NULL);
48-
49-
perf_pmus__for_each_pmu(pmu) {
47+
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
5048
r = realloc(results, (nr_pmus + 1) * sizeof(*r));
5149
if (r == NULL)
5250
return -ENOMEM;

tools/perf/tests/event_groups.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@ static int event_open(int type, unsigned long config, int group_fd)
5050

5151
static int setup_uncore_event(void)
5252
{
53-
struct perf_pmu *pmu;
53+
struct perf_pmu *pmu = NULL;
5454
int i, fd;
5555

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) {
6057
for (i = 0; i < NR_UNCORE_PMUS; i++) {
6158
if (!strcmp(uncore_pmus[i].name, pmu->name)) {
6259
pr_debug("Using %s for uncore pmu event\n", pmu->name);

tools/perf/tests/parse-events.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ static int test__checkevent_raw(struct evlist *evlist)
108108
TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
109109

110110
perf_evlist__for_each_evsel(&evlist->core, evsel) {
111-
struct perf_pmu *pmu;
111+
struct perf_pmu *pmu = NULL;
112112
bool type_matched = false;
113113

114114
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) {
116116
if (pmu->type == evsel->attr.type) {
117117
TEST_ASSERT_VAL("PMU type expected once", !type_matched);
118118
type_matched = true;
@@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __maybe_unused, int subtest __ma
22432243

22442244
static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
22452245
{
2246-
struct perf_pmu *pmu;
2246+
struct perf_pmu *pmu = NULL;
22472247
int ret = TEST_OK;
22482248

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) {
22532250
struct stat st;
22542251
char path[PATH_MAX];
22552252
struct dirent *ent;

tools/perf/util/pmus.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
extern struct list_head pmus;
66
struct perf_pmu;
77

8-
#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list)
9-
108
const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str);
119

1210
#endif /* __PMUS_H */

0 commit comments

Comments
 (0)