[PATCH v2 17/23] perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu
Ian Rogers
irogers at google.com
Sun May 21 23:43:24 PDT 2023
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 at linux.intel.com>
Signed-off-by: Ian Rogers <irogers at google.com>
---
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.698.g37aff9b760-goog
More information about the linux-arm-kernel
mailing list