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>
---
tools/perf/util/evsel.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9c086d743d34..477cddf08c5c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1863,16 +1863,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)
--
2.51.0.384.g4c02a37b29-goog