summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/pmu.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-04-07 01:52:55 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-04-07 02:54:01 +0200
commit240e6fd0a923933493192e71f191d9326ba53f0b (patch)
tree58814bdb16abbee2f7756c4325f2657aeb3a7bc4 /tools/perf/util/pmu.c
parentperf pmu: Fewer const casts (diff)
downloadlinux-240e6fd0a923933493192e71f191d9326ba53f0b.tar.xz
linux-240e6fd0a923933493192e71f191d9326ba53f0b.zip
perf pmu: Improve name/comments, avoid a memory allocation
Improve documentation around perf_pmu_alias pmu_name and on functions. Reduce the scope of pmu_uncore_alias_match to just file. Rename perf_pmu__valid_suffix to the more revealing perf_pmu__match_ignoring_suffix. Add a short-cut to perf_pmu__match_ignoring_suffix for PMU names that don't also have a socket value, and can therefore avoid a memory allocation. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.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> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20230406235256.2768773-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/pmu.c')
-rw-r--r--tools/perf/util/pmu.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d033343f75f9..2e4f60b49959 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -686,11 +686,14 @@ __weak const struct pmu_metrics_table *pmu_metrics_table__find(void)
return perf_pmu__find_metrics_table(NULL);
}
-/*
- * Suffix must be in form tok_{digits}, or tok{digits}, or same as pmu_name
- * to be valid.
+/**
+ * perf_pmu__match_ignoring_suffix - Does the pmu_name match tok ignoring any
+ * trailing suffix? The Suffix must be in form
+ * tok_{digits}, or tok{digits}.
+ * @pmu_name: The pmu_name with possible suffix.
+ * @tok: The possible match to pmu_name without suffix.
*/
-static bool perf_pmu__valid_suffix(const char *pmu_name, char *tok)
+static bool perf_pmu__match_ignoring_suffix(const char *pmu_name, const char *tok)
{
const char *p;
@@ -715,11 +718,21 @@ static bool perf_pmu__valid_suffix(const char *pmu_name, char *tok)
return true;
}
-bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
+/**
+ * pmu_uncore_alias_match - does name match the PMU name?
+ * @pmu_name: the json struct pmu_event name. This may lack a suffix (which
+ * matches) or be of the form "socket,pmuname" which will match
+ * "socketX_pmunameY".
+ * @name: a real full PMU name as from sysfs.
+ */
+static bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
{
char *tmp = NULL, *tok, *str;
bool res;
+ if (strchr(pmu_name, ',') == NULL)
+ return perf_pmu__match_ignoring_suffix(name, pmu_name);
+
str = strdup(pmu_name);
if (!str)
return false;
@@ -746,7 +759,7 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
name = strstr(name, tok);
if (!name ||
- (!next_tok && !perf_pmu__valid_suffix(name, tok))) {
+ (!next_tok && !perf_pmu__match_ignoring_suffix(name, tok))) {
res = false;
goto out;
}
@@ -1961,7 +1974,7 @@ int perf_pmu__match(char *pattern, char *name, char *tok)
if (fnmatch(pattern, name, 0))
return -1;
- if (tok && !perf_pmu__valid_suffix(name, tok))
+ if (tok && !perf_pmu__match_ignoring_suffix(name, tok))
return -1;
return 0;