[RFC PATCH v2 5/5] perf stat: Ensure only topdown kernel events used on x86

From: Andrew Kilroy
Date: Tue Jan 11 2022 - 10:08:53 EST


Based on advice here:

https://lore.kernel.org/linux-perf-users/12e0deef-08db-445f-4958-bcd5c3e10367@xxxxxxxxxxxxxxx/#t

Only use the existing kernel events topdown mechanism on x86, not the
json metrics approach. Disabling the json metrics because of concerns
that due to SMT it's not straightforward to express the various formulas
as json for certain x86 cpus.

Signed-off-by: Andrew Kilroy <andrew.kilroy@xxxxxxx>
---
tools/perf/builtin-stat.c | 22 +++++++++++++---------
tools/perf/util/topdown.c | 6 +++---
2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2f579d29f9f5..eee58fbf1986 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1814,16 +1814,20 @@ enum topdown_mechanism {

static enum topdown_mechanism choose_topdown_mechanism(void)
{
- int kernel_events_supported = topdown_kernel_events_supported();
-
- if (kernel_events_supported > 0) {
- pr_debug("topdown kernel events are supported\n");
- return TOPDOWN_KERNEL_EVENTS;
- } else if (kernel_events_supported == 0) {
- pr_debug("topdown kernel events are unsupported\n");
- return TOPDOWN_JSON_METRICS;
+ if (topdown_can_use_json_metrics()) {
+ int kernel_events_supported = topdown_kernel_events_supported();
+
+ if (kernel_events_supported > 0) {
+ pr_debug("topdown kernel events are supported\n");
+ return TOPDOWN_KERNEL_EVENTS;
+ } else if (kernel_events_supported == 0) {
+ pr_debug("topdown kernel events are unsupported\n");
+ return TOPDOWN_JSON_METRICS;
+ } else {
+ return TOPDOWN_DETECTION_ERROR;
+ }
} else {
- return TOPDOWN_DETECTION_ERROR;
+ return TOPDOWN_KERNEL_EVENTS;
}
}

diff --git a/tools/perf/util/topdown.c b/tools/perf/util/topdown.c
index a542dddd97f3..36f6c29009fb 100644
--- a/tools/perf/util/topdown.c
+++ b/tools/perf/util/topdown.c
@@ -59,10 +59,10 @@ __weak bool arch_topdown_sample_read(struct evsel *leader __maybe_unused)

bool topdown_can_use_json_metrics(void)
{
-#if defined(__aarch64__)
- return true;
-#else
+#if defined(__i386__) || defined(__x86_64__)
return false;
+#else
+ return true;
#endif
}

--
2.17.1