[PATCH v9 09/18] perf sort: Use perf_env e_machine rather than arch

Ian Rogers
2026-05-03T00:23:13Z

Use the e_machine rather than the arch to determine x86 or PPC types.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/sort.c | 58 +++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 26 deletions(-)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 0020089cb13c..90bc4a31bb55 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1,40 +1,45 @@
// SPDX-License-Identifier: GPL-2.0
+#include "sort.h"
+
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
-#include <regex.h>
#include <stdlib.h>
+
+#include <elf.h>
+#include <linux/kernel.h>
#include <linux/mman.h>
+#include <linux/string.h>
#include <linux/time64.h>
+
+#include <regex.h>
+
+#include "annotate-data.h"
+#include "annotate.h"
+#include "branch.h"
+#include "cacheline.h"
+#include "cgroup.h"
+#include "comm.h"
#include "debug.h"
#include "dso.h"
-#include "sort.h"
+#include "event.h"
+#include "evlist.h"
+#include "evsel.h"
#include "hist.h"
-#include "cacheline.h"
-#include "comm.h"
+#include "machine.h"
#include "map.h"
-#include "maps.h"
-#include "symbol.h"
#include "map_symbol.h"
-#include "branch.h"
-#include "thread.h"
-#include "evsel.h"
-#include "evlist.h"
-#include "srcline.h"
-#include "strlist.h"
-#include "strbuf.h"
+#include "maps.h"
#include "mem-events.h"
#include "mem-info.h"
-#include "annotate.h"
-#include "annotate-data.h"
-#include "event.h"
-#include "time-utils.h"
-#include "cgroup.h"
-#include "machine.h"
#include "session.h"
+#include "srcline.h"
+#include "strbuf.h"
+#include "strlist.h"
+#include "symbol.h"
+#include "thread.h"
+#include "time-utils.h"
#include "trace-event.h"
-#include <linux/kernel.h>
-#include <linux/string.h>

#ifdef HAVE_LIBTRACEEVENT
#include <event-parse.h>
@@ -2673,9 +2678,10 @@ struct sort_dimension {

static int arch_support_sort_key(const char *sort_key, struct perf_env *env)
{
- const char *arch = perf_env__arch(env);
+ uint16_t e_machine = perf_env__e_machine(env, /*e_eflags=*/NULL);

- if (!strcmp("x86", arch) || !strcmp("powerpc", arch)) {
+ if (e_machine == EM_X86_64 || e_machine == EM_386 || e_machine == EM_PPC64 ||
+ e_machine == EM_PPC) {
if (!strcmp(sort_key, "p_stage_cyc"))
return 1;
if (!strcmp(sort_key, "local_p_stage_cyc"))
@@ -2686,14 +2692,14 @@ static int arch_support_sort_key(const char *sort_key, struct perf_env *env)

static const char *arch_perf_header_entry(const char *se_header, struct perf_env *env)
{
- const char *arch = perf_env__arch(env);
+ uint16_t e_machine = perf_env__e_machine(env, /*e_eflags=*/NULL);

- if (!strcmp("x86", arch)) {
+ if (e_machine == EM_X86_64 || e_machine == EM_386) {
if (!strcmp(se_header, "Local Pipeline Stage Cycle"))
return "Local Retire Latency";
else if (!strcmp(se_header, "Pipeline Stage Cycle"))
return "Retire Latency";
- } else if (!strcmp("powerpc", arch)) {
+ } else if (e_machine == EM_PPC64 || e_machine == EM_PPC) {
if (!strcmp(se_header, "Local INSTR Latency"))
return "Finish Cyc";
else if (!strcmp(se_header, "INSTR Latency"))
--
2.54.0.545.g6539524ca2-goog