summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/tool_pmu.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2024-10-02 05:20:12 +0200
committerNamhyung Kim <namhyung@kernel.org>2024-10-11 08:40:33 +0200
commit609aa2667f67c1588d4e741110265f74b7713177 (patch)
tree31697c0518481260c9adb5592972ad81ccb829fb /tools/perf/util/tool_pmu.c
parentperf jevents: Add tool event json under a common architecture (diff)
downloadlinux-609aa2667f67c1588d4e741110265f74b7713177.tar.xz
linux-609aa2667f67c1588d4e741110265f74b7713177.zip
perf tool_pmu: Switch to standard pmu functions and json descriptions
Use the regular PMU approaches with tool json events to reduce the amount of special tool_pmu code - tool_pmu__config_terms and tool_pmu__for_each_event_cb are removed. Some functions remain, like tool_pmu__str_to_event, as conveniences to metricgroups. Add tool_pmu__skip_event/tool_pmu__num_skip_events to handle the case that tool json events shouldn't appear on certain architectures. This isn't done in jevents.py due to complexity in the empty-pmu-events.c and when all vendor json is built into the tool. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20241002032016.333748-10-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/util/tool_pmu.c')
-rw-r--r--tools/perf/util/tool_pmu.c109
1 files changed, 32 insertions, 77 deletions
diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c
index cfdc09dece1e..ea9d50f02520 100644
--- a/tools/perf/util/tool_pmu.c
+++ b/tools/perf/util/tool_pmu.c
@@ -33,101 +33,54 @@ static const char *const tool_pmu__event_names[TOOL_PMU__EVENT_MAX] = {
"system_tsc_freq",
};
-
-const char *tool_pmu__event_to_str(enum tool_pmu_event ev)
-{
- if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX)
- return tool_pmu__event_names[ev];
-
- return NULL;
-}
-
-enum tool_pmu_event tool_pmu__str_to_event(const char *str)
+bool tool_pmu__skip_event(const char *name __maybe_unused)
{
- int i;
-
- tool_pmu__for_each_event(i) {
- if (!strcasecmp(str, tool_pmu__event_names[i])) {
#if !defined(__aarch64__)
- /* The slots event should only appear on arm64. */
- if (i == TOOL_PMU__EVENT_SLOTS)
- return TOOL_PMU__EVENT_NONE;
+ /* The slots event should only appear on arm64. */
+ if (strcasecmp(name, "slots") == 0)
+ return true;
#endif
- return i;
- }
- }
- return TOOL_PMU__EVENT_NONE;
+#if !defined(__i386__) && !defined(__x86_64__)
+ /* The system_tsc_freq event should only appear on x86. */
+ if (strcasecmp(name, "system_tsc_freq") == 0)
+ return true;
+#endif
+ return false;
}
-static int tool_pmu__config_term(struct perf_event_attr *attr,
- struct parse_events_term *term,
- struct parse_events_error *err)
+int tool_pmu__num_skip_events(void)
{
- if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER) {
- enum tool_pmu_event ev = tool_pmu__str_to_event(term->config);
+ int num = 0;
- if (ev == TOOL_PMU__EVENT_NONE)
- goto err_out;
-
- attr->config = ev;
- return 0;
- }
-err_out:
- if (err) {
- char *err_str;
-
- parse_events_error__handle(err, term->err_val,
- asprintf(&err_str,
- "unexpected tool event term (%s) %s",
- parse_events__term_type_str(term->type_term),
- term->config) < 0
- ? strdup("unexpected tool event term")
- : err_str,
- NULL);
- }
- return -EINVAL;
+#if !defined(__aarch64__)
+ num++;
+#endif
+#if !defined(__i386__) && !defined(__x86_64__)
+ num++;
+#endif
+ return num;
}
-int tool_pmu__config_terms(struct perf_event_attr *attr,
- struct parse_events_terms *terms,
- struct parse_events_error *err)
+const char *tool_pmu__event_to_str(enum tool_pmu_event ev)
{
- struct parse_events_term *term;
-
- list_for_each_entry(term, &terms->terms, list) {
- if (tool_pmu__config_term(attr, term, err))
- return -EINVAL;
- }
-
- return 0;
+ if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX)
+ return tool_pmu__event_names[ev];
+ return NULL;
}
-int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_event_callback cb)
+enum tool_pmu_event tool_pmu__str_to_event(const char *str)
{
- struct pmu_event_info info = {
- .pmu = pmu,
- .event_type_desc = "Tool event",
- };
int i;
+ if (tool_pmu__skip_event(str))
+ return TOOL_PMU__EVENT_NONE;
+
tool_pmu__for_each_event(i) {
- int ret;
-
- info.name = tool_pmu__event_to_str(i);
- info.alias = NULL;
- info.scale_unit = NULL;
- info.desc = NULL;
- info.long_desc = NULL;
- info.encoding_desc = NULL;
- info.topic = NULL;
- info.pmu_name = pmu->name;
- info.deprecated = false;
- ret = cb(state, &info);
- if (ret)
- return ret;
+ if (!strcasecmp(str, tool_pmu__event_names[i]))
+ return i;
}
- return 0;
+ return TOOL_PMU__EVENT_NONE;
}
bool perf_pmu__is_tool(const struct perf_pmu *pmu)
@@ -546,6 +499,8 @@ struct perf_pmu *perf_pmus__tool_pmu(void)
.caps = LIST_HEAD_INIT(tool.caps),
.format = LIST_HEAD_INIT(tool.format),
};
+ if (!tool.events_table)
+ tool.events_table = find_core_events_table("common", "common");
return &tool;
}