Commit f91fa2ae authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf pmu: Refactor perf_pmu__match()

Move all implementation to pmu code. Don't allocate a fnmatch wildcard
pattern, matching ignoring the suffix already handles this, and only
use fnmatch if the given PMU name has a '*' in it.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Tested-by: default avatarAtish Patra <atishp@rivosinc.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Beeman Strong <beeman@rivosinc.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240416061533.921723-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 90b2c210
...@@ -1611,7 +1611,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state ...@@ -1611,7 +1611,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
struct list_head **listp, struct list_head **listp,
void *loc_) void *loc_)
{ {
char *pattern = NULL;
YYLTYPE *loc = loc_; YYLTYPE *loc = loc_;
struct perf_pmu *pmu; struct perf_pmu *pmu;
int ok = 0; int ok = 0;
...@@ -1631,22 +1630,9 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state ...@@ -1631,22 +1630,9 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
pmu = NULL; pmu = NULL;
/* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */ /* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */
if (asprintf(&pattern, "%s*", event_or_pmu) < 0) {
zfree(listp);
return -ENOMEM;
}
while ((pmu = perf_pmus__scan(pmu)) != NULL) { while ((pmu = perf_pmus__scan(pmu)) != NULL) {
const char *name = pmu->name; if (!parse_events__filter_pmu(parse_state, pmu) &&
perf_pmu__match(pmu, event_or_pmu)) {
if (parse_events__filter_pmu(parse_state, pmu))
continue;
if (!strncmp(name, "uncore_", 7) &&
strncmp(event_or_pmu, "uncore_", 7))
name += 7;
if (!perf_pmu__match(pattern, name, event_or_pmu) ||
!perf_pmu__match(pattern, pmu->alias_name, event_or_pmu)) {
bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu);
if (!parse_events_add_pmu(parse_state, *listp, pmu, if (!parse_events_add_pmu(parse_state, *listp, pmu,
...@@ -1657,7 +1643,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state ...@@ -1657,7 +1643,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state
} }
} }
} }
zfree(&pattern);
if (ok) if (ok)
return 0; return 0;
......
...@@ -2064,18 +2064,29 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, ...@@ -2064,18 +2064,29 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
name ?: "N/A", buf, config_name, config); name ?: "N/A", buf, config_name, config);
} }
int perf_pmu__match(const char *pattern, const char *name, const char *tok) bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok)
{ {
if (!name) const char *name = pmu->name;
return -1; bool need_fnmatch = strchr(tok, '*') != NULL;
if (fnmatch(pattern, name, 0)) if (!strncmp(tok, "uncore_", 7))
return -1; tok += 7;
if (!strncmp(name, "uncore_", 7))
name += 7;
if (tok && !perf_pmu__match_ignoring_suffix(name, tok)) if (perf_pmu__match_ignoring_suffix(name, tok) ||
return -1; (need_fnmatch && !fnmatch(tok, name, 0)))
return true;
return 0; name = pmu->alias_name;
if (!name)
return false;
if (!strncmp(name, "uncore_", 7))
name += 7;
return perf_pmu__match_ignoring_suffix(name, tok) ||
(need_fnmatch && !fnmatch(tok, name, 0));
} }
double __weak perf_pmu__cpu_slots_per_cycle(void) double __weak perf_pmu__cpu_slots_per_cycle(void)
......
...@@ -263,7 +263,7 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, ...@@ -263,7 +263,7 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
const char *config_name); const char *config_name);
void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu); void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
int perf_pmu__match(const char *pattern, const char *name, const char *tok); bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok);
double perf_pmu__cpu_slots_per_cycle(void); double perf_pmu__cpu_slots_per_cycle(void);
int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size); int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment