summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-06-02 08:25:04 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-06-03 16:46:37 -0300
commitdfe48498e6ab1fff4a27600450d073e117b0bd5f (patch)
tree70c003c1fa0d933f901ae740069799115c09aec8
parent0af46a17c86ec447404d1e1555973186d058b775 (diff)
downloadlinux-dfe48498e6ab1fff4a27600450d073e117b0bd5f.tar.gz
linux-dfe48498e6ab1fff4a27600450d073e117b0bd5f.zip
perf machine: Use perf_env e_machine rather than arch
The arch string is derived from uname and may be normalized causing potential differences meaning the ELF machine can be more precise. Reduce the scope of machine__is as often it is better to use a thread for the e_machine rather than the machine. Switch from string to ELF machine constant comparisons. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Honglei Wang <jameshongleiwang@126.com> Cc: Jan Polensky <japo@linux.ibm.com> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/machine.c35
-rw-r--r--tools/perf/util/machine.h2
2 files changed, 18 insertions, 19 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index e5d1e8b882a9..47be7a44a5f7 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -9,6 +9,7 @@
#include "debug.h"
#include "dso.h"
#include "env.h"
+#include "dwarf-regs.h"
#include "event.h"
#include "evsel.h"
#include "hist.h"
@@ -1627,10 +1628,24 @@ static bool machine__uses_kcore(struct machine *machine)
return dsos__for_each_dso(&machine->dsos, machine__uses_kcore_cb, NULL) != 0 ? true : false;
}
+static bool machine__is(struct machine *machine, uint16_t e_machine)
+{
+ if (!machine)
+ return false;
+
+ if (!machine->env) {
+ if (machine__is_host(machine))
+ return e_machine == EM_HOST;
+ return false;
+ }
+
+ return perf_env__e_machine(machine->env, NULL) == e_machine;
+}
+
static bool perf_event__is_extra_kernel_mmap(struct machine *machine,
struct extra_kernel_map *xm)
{
- return machine__is(machine, "x86_64") &&
+ return machine__is(machine, EM_X86_64) &&
is_entry_trampoline(xm->name);
}
@@ -2786,7 +2801,7 @@ static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread,
static u64 get_leaf_frame_caller(struct perf_sample *sample,
struct thread *thread, int usr_idx)
{
- if (machine__normalized_is(maps__machine(thread__maps(thread)), "arm64"))
+ if (thread__e_machine(thread, /*machine=*/NULL, /*e_flags=*/NULL) == EM_AARCH64)
return get_leaf_frame_caller_aarch64(sample, thread, usr_idx);
else
return 0;
@@ -3157,20 +3172,6 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
return 0;
}
-/*
- * Compares the raw arch string. N.B. see instead perf_env__arch() or
- * machine__normalized_is() if a normalized arch is needed.
- */
-bool machine__is(struct machine *machine, const char *arch)
-{
- return machine && !strcmp(perf_env__raw_arch(machine->env), arch);
-}
-
-bool machine__normalized_is(struct machine *machine, const char *arch)
-{
- return machine && !strcmp(perf_env__arch(machine->env), arch);
-}
-
int machine__nr_cpus_avail(struct machine *machine)
{
return machine ? perf_env__nr_cpus_avail(machine->env) : 0;
@@ -3197,7 +3198,7 @@ int machine__get_kernel_start(struct machine *machine)
* start of kernel text, but still above 2^63. So leave
* kernel_start = 1ULL << 63 for x86_64.
*/
- if (!err && !machine__is(machine, "x86_64"))
+ if (!err && !machine__is(machine, EM_X86_64))
machine->kernel_start = map__start(map);
}
return err;
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 048b24e9bd38..aaddfb70ea66 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -224,8 +224,6 @@ static inline bool machine__is_host(struct machine *machine)
}
bool machine__is_lock_function(struct machine *machine, u64 addr);
-bool machine__is(struct machine *machine, const char *arch);
-bool machine__normalized_is(struct machine *machine, const char *arch);
int machine__nr_cpus_avail(struct machine *machine);
struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);