]> www.infradead.org Git - users/hch/misc.git/commitdiff
perf evsel: Give warning for broken Intel topdown event grouping
authorIan Rogers <irogers@google.com>
Mon, 25 Aug 2025 21:12:02 +0000 (14:12 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 12 Sep 2025 18:48:12 +0000 (15:48 -0300)
Extend arch_evsel__open_strerror() from just AMD IBS events to Intel
core PMU events, to give a message when a slots event isn't a group
leader or when a perf metric event is duplicated within an event
group.

As generating the warning happens after non-arch specific warnings are
generated, disable the missing system wide (-a) flag warning for the
core PMU.

This assumes core PMU events should support per-thread/process and
system-wide.

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Yoshihiro Furudera <fj5100bi@fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/x86/util/evsel.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 9bc80fff3aa0e26294b071423c59a3aeb15f4d22..e67701d26f24a420f4b420c2ff85d4384c3083c0 100644 (file)
@@ -1,10 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/env.h"
 #include "util/pmu.h"
 #include "util/pmus.h"
+#include "util/stat.h"
+#include "util/strbuf.h"
 #include "linux/string.h"
 #include "topdown.h"
 #include "evsel.h"
@@ -102,13 +106,15 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
        }
 }
 
-int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
+static int amd_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
 {
-       if (!x86__is_amd_cpu())
+       struct perf_pmu *pmu;
+
+       if (evsel->core.attr.precise_ip == 0)
                return 0;
 
-       if (!evsel->core.attr.precise_ip &&
-           !(evsel->pmu && !strncmp(evsel->pmu->name, "ibs", 3)))
+       pmu = evsel__find_pmu(evsel);
+       if (!pmu || strncmp(pmu->name, "ibs", 3))
                return 0;
 
        /* More verbose IBS errors. */
@@ -118,6 +124,54 @@ int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
                return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
                                 "again without the privilege modifiers (like 'k') at the end.");
        }
+       return 0;
+}
+
+static int intel_evsel__open_strerror(struct evsel *evsel, int err, char *msg, size_t size)
+{
+       struct strbuf sb = STRBUF_INIT;
+       int ret;
+
+       if (err != EINVAL)
+               return 0;
 
+       if (!topdown_sys_has_perf_metrics())
+               return 0;
+
+       if (arch_is_topdown_slots(evsel)) {
+               if (!evsel__is_group_leader(evsel)) {
+                       evlist__uniquify_evsel_names(evsel->evlist, &stat_config);
+                       evlist__format_evsels(evsel->evlist, &sb, 2048);
+                       ret = scnprintf(msg, size, "Topdown slots event can only be group leader "
+                                       "in '%s'.", sb.buf);
+                       strbuf_release(&sb);
+                       return ret;
+               }
+       } else if (arch_is_topdown_metrics(evsel)) {
+               struct evsel *pos;
+
+               evlist__for_each_entry(evsel->evlist, pos) {
+                       if (pos == evsel || !arch_is_topdown_metrics(pos))
+                               continue;
+
+                       if (pos->core.attr.config != evsel->core.attr.config)
+                               continue;
+
+                       evlist__uniquify_evsel_names(evsel->evlist, &stat_config);
+                       evlist__format_evsels(evsel->evlist, &sb, 2048);
+                       ret = scnprintf(msg, size, "Perf metric event '%s' is duplicated "
+                                       "in the same group (only one event is allowed) in '%s'.",
+                                       evsel__name(evsel), sb.buf);
+                       strbuf_release(&sb);
+                       return ret;
+               }
+       }
        return 0;
 }
+
+int arch_evsel__open_strerror(struct evsel *evsel, int err, char *msg, size_t size)
+{
+       return x86__is_amd_cpu()
+               ? amd_evsel__open_strerror(evsel, msg, size)
+               : intel_evsel__open_strerror(evsel, err, msg, size);
+}
index 496f42434327bb59989644be89cb0ec363ae6702..6a31f9699b49f982186f3cb0364ef3e88d62bbec 100644 (file)
@@ -3716,6 +3716,7 @@ static int dump_perf_event_processes(char *msg, size_t size)
 }
 
 int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
+                                    int err __maybe_unused,
                                     char *msg __maybe_unused,
                                     size_t size __maybe_unused)
 {
@@ -3725,6 +3726,7 @@ int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
 int evsel__open_strerror(struct evsel *evsel, struct target *target,
                         int err, char *msg, size_t size)
 {
+       struct perf_pmu *pmu;
        char sbuf[STRERR_BUFSIZE];
        int printed = 0, enforced = 0;
        int ret;
@@ -3840,7 +3842,8 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
                        return scnprintf(msg, size, "The 'aux_action' feature is not supported, update the kernel.");
                if (perf_missing_features.aux_output)
                        return scnprintf(msg, size, "The 'aux_output' feature is not supported, update the kernel.");
-               if (!target__has_cpu(target))
+               pmu = evsel__find_pmu(evsel);
+               if (!pmu->is_core && !target__has_cpu(target))
                        return scnprintf(msg, size,
        "Invalid event (%s) in per-thread mode, enable system wide with '-a'.",
                                        evsel__name(evsel));
@@ -3853,7 +3856,7 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
                break;
        }
 
-       ret = arch_evsel__open_strerror(evsel, msg, size);
+       ret = arch_evsel__open_strerror(evsel, err, msg, size);
        if (ret)
                return ret;
 
index 5797a02e5d6a9e0691896ba2b6f7e3267c42b042..e927a3a4fe0e55c9af5b75aa34ac29490d89fec9 100644 (file)
@@ -341,7 +341,7 @@ void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
 
 void arch_evsel__set_sample_weight(struct evsel *evsel);
 void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
-int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size);
+int arch_evsel__open_strerror(struct evsel *evsel, int err, char *msg, size_t size);
 
 int evsel__set_filter(struct evsel *evsel, const char *filter);
 int evsel__append_tp_filter(struct evsel *evsel, const char *filter);