[PATCH v11 03/19] perf evsel/evlist: Avoid unnecessary #includes

From: Ian Rogers

Date: Fri Jun 05 2026 - 15:23:39 EST


Use forward declarations and remove unnecessary #includes in
evsel.h. Sort the forward declarations in evsel.h and evlist.h. Move
some PMU code into evsel.c.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/evlist.h | 15 +++++++++------
tools/perf/util/evsel.c | 5 +++++
tools/perf/util/evsel.h | 25 ++++++++++++-------------
3 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index e507f5f20ef6..e54761c670b6 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -2,29 +2,32 @@
#ifndef __PERF_EVLIST_H
#define __PERF_EVLIST_H 1

+#include <signal.h>
+
#include <linux/compiler.h>
#include <linux/kernel.h>
-#include <linux/refcount.h>
#include <linux/list.h>
+#include <linux/refcount.h>
+#include <pthread.h>
+#include <unistd.h>
+
#include <api/fd/array.h>
#include <internal/evlist.h>
#include <internal/evsel.h>
#include <perf/evlist.h>
+
#include "affinity.h"
#include "events_stats.h"
#include "evsel.h"
#include "rblist.h"
-#include <pthread.h>
-#include <signal.h>
-#include <unistd.h>

-struct pollfd;
-struct thread_map;
struct perf_cpu_map;
struct perf_stat_config;
+struct pollfd;
struct record_opts;
struct strbuf;
struct target;
+struct thread_map;

/*
* State machine of bkw_mmap_state:
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 34c03f47a913..19e48b9260e9 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -370,6 +370,11 @@ void evsel__set_sample_id(struct evsel *evsel,
evsel->core.attr.read_format |= PERF_FORMAT_ID;
}

+bool evsel__is_non_perf_event_open_pmu(const struct evsel *evsel)
+{
+ return evsel->pmu && evsel->pmu->type > PERF_PMU_TYPE_PE_END;
+}
+
/**
* evsel__is_function_event - Return whether given evsel is a function
* trace event
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 8178858d168a..6b28cd754a18 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -2,28 +2,30 @@
#ifndef __PERF_EVSEL_H
#define __PERF_EVSEL_H 1

-#include <linux/list.h>
#include <stdbool.h>
-#include <sys/types.h>
+
+#include <linux/list.h>
#include <linux/perf_event.h>
#include <linux/types.h>
+#include <sys/types.h>
+
#include <internal/evsel.h>
#include <perf/evsel.h>
+
#include "symbol_conf.h"
-#include "pmus.h"
-#include "pmu.h"

+struct bperf_follower_bpf;
+struct bperf_leader_bpf;
+struct bpf_counter_ops;
struct bpf_object;
struct cgroup;
+struct hashmap;
struct perf_counts;
+struct perf_pmu;
struct perf_stat_config;
struct perf_stat_evsel;
-union perf_event;
-struct bpf_counter_ops;
struct target;
-struct hashmap;
-struct bperf_leader_bpf;
-struct bperf_follower_bpf;
+union perf_event;

typedef int (evsel__sb_cb_t)(union perf_event *event, void *data);

@@ -356,10 +358,6 @@ void arch_evsel__apply_ratio_to_prev(struct evsel *evsel, struct perf_event_attr
int evsel__set_filter(struct evsel *evsel, const char *filter);
int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
int evsel__append_addr_filter(struct evsel *evsel, const char *filter);
-static inline bool evsel__is_non_perf_event_open_pmu(const struct evsel *evsel)
-{
- return evsel->pmu && evsel->pmu->type > PERF_PMU_TYPE_PE_END;
-}

int evsel__enable_cpu(struct evsel *evsel, int cpu_map_idx);
int evsel__enable(struct evsel *evsel);
@@ -478,6 +476,7 @@ static inline bool evsel__is_group_event(struct evsel *evsel)
return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1;
}

+bool evsel__is_non_perf_event_open_pmu(const struct evsel *evsel);
bool evsel__is_function_event(struct evsel *evsel);

static inline bool evsel__is_bpf_output(struct evsel *evsel)
--
2.54.0.1032.g2f8565e1d1-goog