]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf evsel: Improvements to __evsel__match
authorIan Rogers <irogers@google.com>
Sun, 5 Oct 2025 18:24:23 +0000 (11:24 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 15 Oct 2025 14:59:11 +0000 (23:59 +0900)
Ensure both the perf_event_attr and alternate_hw_config are checked in
the match. Don't mask the config if the perf_event_attr isn't a
HARDWARE or HW_CACHE event. Add common early exit cases.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/evsel.c

index 56ebefd075f2e35f2d0812994d39182859fd2ceb..ad11cbfcbff1c7189d75517954c4474ad4f3d2a5 100644 (file)
@@ -1940,16 +1940,19 @@ bool __evsel__match(const struct evsel *evsel, u32 type, u64 config)
        u32 e_type = evsel->core.attr.type;
        u64 e_config = evsel->core.attr.config;
 
-       if (e_type != type) {
-               return type == PERF_TYPE_HARDWARE && evsel->pmu && evsel->pmu->is_core &&
-                       evsel->alternate_hw_config == config;
-       }
-
-       if ((type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) &&
-           perf_pmus__supports_extended_type())
+       if (e_type == type && e_config == config)
+               return true;
+       if (type != PERF_TYPE_HARDWARE && type != PERF_TYPE_HW_CACHE)
+               return false;
+       if ((e_type == PERF_TYPE_HARDWARE || e_type == PERF_TYPE_HW_CACHE) &&
+               perf_pmus__supports_extended_type())
                e_config &= PERF_HW_EVENT_MASK;
-
-       return e_config == config;
+       if (e_type == type && e_config == config)
+               return true;
+       if (type == PERF_TYPE_HARDWARE && evsel->pmu && evsel->pmu->is_core &&
+           evsel->alternate_hw_config == config)
+               return true;
+       return false;
 }
 
 int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread)