perf more ELF machine usage
Ian Rogers
reviewercover perf more ELF machine usage
Switch 3 more cases where the perf_env arch was being used to determine the architecture type and switch to using the ELF machine. This includes the addition of minimal instruction parsing in perf script for architectures other than x86, or x86 when cross-platform.
Note: this series will conflict with the e_flags series:
https://lore.kernel.org/lkml/[email protected]/
that adds an additional out argument to thread__e_machine. In all the cases here that argument should be NULL. So:
thread__e_machine(thread, machine)
becomes:
thread__e_machine(thread, machine, /*e_flags=*/NULL)
Ian Rogers (3):
perf script: Fix script_fetch_insn for more than just x86 perf callchain: Switch callchain_param_setup from an arch to an
e_machine
perf thread-stack: Switch thread_stack__init to use e_machine
tools/perf/arch/x86/util/Build | 1 - tools/perf/arch/x86/util/archinsn.c | 27 ------- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 20 +----- .../scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/tests/dlfilter-test.c | 1 - tools/perf/util/archinsn.h | 12 ---- tools/perf/util/callchain.c | 5 +- tools/perf/util/callchain.h | 2 +- tools/perf/util/dlfilter.c | 3 +- tools/perf/util/sample.c | 71 +++++++++++++++++++ tools/perf/util/sample.h | 7 ++ tools/perf/util/thread-stack.c | 4 +- tools/perf/util/trace-event-scripting.c | 16 ----- tools/perf/util/trace-event.h | 3 - 15 files changed, 91 insertions(+), 89 deletions(-) delete mode 100644 tools/perf/arch/x86/util/archinsn.c delete mode 100644 tools/perf/util/archinsn.h
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Ian Rogers
reviewerPATCH 1/3 perf script: Fix script_fetch_insn for more than just x86
The script_fetch_insn code was only supported on natively running x86. Implement a crude elf_machine_max_instruction_length function and use to give an instruction length on more than just x86. Use the ELF machine to determine the length to use to support cross-architecture development.
--- tools/perf/arch/x86/util/Build | 1 - tools/perf/arch/x86/util/archinsn.c | 27 ------- tools/perf/builtin-script.c | 16 +---- .../scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/tests/dlfilter-test.c | 1 - tools/perf/util/archinsn.h | 12 ---- tools/perf/util/dlfilter.c | 3 +- tools/perf/util/sample.c | 71 +++++++++++++++++++ tools/perf/util/sample.h | 7 ++ tools/perf/util/trace-event-scripting.c | 16 ----- tools/perf/util/trace-event.h | 3 - 11 files changed, 81 insertions(+), 78 deletions(-) delete mode 100644 tools/perf/arch/x86/util/archinsn.c delete mode 100644 tools/perf/util/archinsn.h
tools/perf/arch/x86/util/Build +0 -1
@@ -14,6 +14,5 @@ perf-util-y += iostat.o perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o perf-util-y += auxtrace.o -perf-util-y += archinsn.o perf-util-y += intel-pt.o perf-util-y += intel-bts.o
tools/perf/arch/x86/util/archinsn.c deleted +0 -27
@@ -1,27 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "archinsn.h" -#include "event.h" -#include "machine.h" -#include "thread.h" -#include "symbol.h" -#include "../../../../arch/x86/include/asm/insn.h" - -void arch_fetch_insn (struct perf_sample *sample, -struct thread *thread, -struct machine *machine) -{ -struct insn insn; -int len, ret; -bool is64bit = false; - -if (!sample->ip) -return ; - len =thread__memcpy (thread, machine, sample->insn, sample->ip,sizeof (sample->insn), &is64bit); -if (len <=0 ) -return ; - - ret =insn_decode (&insn, sample->insn, len, - is64bit ?INSN_MODE_64 :INSN_MODE_32 ); -if (ret >=0 && insn.length <= len) - sample->insn_len = insn.length; -}
tools/perf/builtin-script.c +1 -15
@@ -37,7 +37,6 @@#include "ui/ui.h" #include "print_binary.h" #include "print_insn.h" -#include "archinsn.h" #include <linux/bitmap.h> #include <linux/compiler.h> #include <linux/kernel.h>
@@ -90,7 +89,6 @@ static bool print_flags;static const char *cpu_list; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);static int max_blocks; -static bool native_arch;static struct dlfilter *dlfilter;static int dlargc;static char **dlargv;
@@ -1618,7 +1616,7 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample, {int printed =0 ; -script_fetch_insn (sample, thread, machine, native_arch); +perf_sample__fetch_insn (sample, thread, machine);if (PRINT_FIELD (INSNLEN )) printed +=fprintf (fp," ilen: %d" , sample->insn_len);
@@ -4016,7 +4014,6 @@ int cmd_script(int argc, const char **argv) .set = false, .default_no_sample = true, }; -struct utsname uts;char *script_path =NULL ;const char *dlfilter_file =NULL ;const char **__argv;
@@ -4438,17 +4435,6 @@ int cmd_script(int argc, const char **argv)if (symbol__init (env) <0 ) goto out_delete; -uname (&uts); -if (data.is_pipe) {/* Assume pipe_mode indicates native_arch */ - native_arch = true; - }else if (env->arch) { -if (!strcmp (uts.machine, env->arch)) - native_arch = true; -else if (!strcmp (uts.machine,"x86_64" ) && - !strcmp (env->arch,"i386" )) - native_arch = true; - } - script.session = session;script__setup_sample_type (&script);
tools/perf/scripts/python/Perf-Trace-Util/Context.c +1 -1
@@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)if (c->sample->ip && !c->sample->insn_len &&thread__maps (c->al->thread)) {struct machine *machine =maps__machine (thread__maps (c->al->thread)); -script_fetch_insn (c->sample, c->al->thread, machine,/*native_arch=*/ true); +perf_sample__fetch_insn (c->sample, c->al->thread, machine); }if (!c->sample->insn_len) Py_RETURN_NONE;/* N.B. This is a return statement */
tools/perf/tests/dlfilter-test.c +0 -1
@@ -30,7 +30,6 @@#include "symbol.h" #include "synthetic-events.h" #include "util.h" -#include "archinsn.h" #include "dlfilter.h" #include "tests.h" #include "util/sample.h"
tools/perf/util/archinsn.h deleted +0 -12
@@ -1,12 +0,0 @@ -#ifndef INSN_H -#define INSN_H 1 - -struct perf_sample ; -struct machine ; -struct thread ; - -void arch_fetch_insn (struct perf_sample *sample, -struct thread *thread, -struct machine *machine); - -#endif
tools/perf/util/dlfilter.c +1 -2
@@ -234,8 +234,7 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len)struct machine *machine =maps__machine (thread__maps (al->thread));if (machine) -script_fetch_insn (d->sample, al->thread, machine, -/*native_arch=*/ true); +perf_sample__fetch_insn (d->sample, al->thread, machine); } }
tools/perf/util/sample.c +71 -0
83 lines not on this page · raw message
tools/perf/util/sample.h +7 -0
@@ -5,6 +5,9 @@#include <linux/perf_event.h> #include <linux/types.h> +struct machine ; +struct thread ; +/* number of register is bound by the number of bits in regs_dump::mask (64) */ #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
@@ -127,6 +130,10 @@ void perf_sample__exit(struct perf_sample *sample);struct regs_dump *perf_sample__user_regs (struct perf_sample *sample);struct regs_dump *perf_sample__intr_regs (struct perf_sample *sample); +void perf_sample__fetch_insn (struct perf_sample *sample, +struct thread *thread, +struct machine *machine); +/* * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get * 8-byte alignment.
tools/perf/util/trace-event-scripting.c +0 -16
@@ -13,7 +13,6 @@#include <event-parse.h> #endif -#include "archinsn.h" #include "debug.h" #include "event.h" #include "trace-event.h"
@@ -274,21 +273,6 @@ void setup_perl_scripting(void)#endif #endif -#if !defined(__i386__) && !defined(__x86_64__) -void arch_fetch_insn (struct perf_sample *sample__maybe_unused , -struct thread *thread__maybe_unused , -struct machine *machine__maybe_unused ) -{ -} -#endif - -void script_fetch_insn (struct perf_sample *sample,struct thread *thread, -struct machine *machine,bool native_arch) -{ -if (sample->insn_len ==0 && native_arch) -arch_fetch_insn (sample, thread, machine); -} - static const struct { u32 flags; const char *name;
tools/perf/util/trace-event.h +0 -3
@@ -116,9 +116,6 @@ extern unsigned int scripting_max_stack;struct scripting_ops *script_spec__lookup (const char *spec);int script_spec__for_each (int (*cb)(struct scripting_ops *ops,const char *spec)); -void script_fetch_insn (struct perf_sample *sample,struct thread *thread, -struct machine *machine,bool native_arch); -void setup_perl_scripting (void );void setup_python_scripting (void );
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Ian Rogers
reviewerPATCH 2/3 perf callchain: Switch callchain_param_setup from an arch to an e_machine
In reply to Ian RogersIncrease use of e_machine by replacing callchain_param_setup's arch argument to be an e_machine typically read from the session.
--- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/callchain.c | 5 +++-- tools/perf/util/callchain.h | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-)
tools/perf/builtin-report.c +2 -4
@@ -448,7 +448,7 @@ static int report__setup_sample_type(struct report *rep) } } -callchain_param_setup (sample_type,perf_env__arch (perf_session__env (rep->session))); +callchain_param_setup (sample_type,perf_session__e_machine (session));if (rep->stitch_lbr && (callchain_param.record_mode !=CALLCHAIN_LBR )) { ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
@@ -1283,7 +1283,6 @@ static int process_attr(const struct perf_tool *tool __maybe_unused, struct evlist **pevlist) {struct perf_session *session; -struct perf_env *env;u64 sample_type;int err;
@@ -1297,8 +1296,7 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,*/ sample_type =evlist__combined_sample_type (*pevlist); session = (*pevlist)->session; - env =perf_session__env (session); -callchain_param_setup (sample_type,perf_env__arch (env)); +callchain_param_setup (sample_type,perf_session__e_machine (session));return 0 ; }
tools/perf/builtin-script.c +2 -2
@@ -2841,7 +2841,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,* on events sample_type. */ sample_type =evlist__combined_sample_type (evlist); -callchain_param_setup (sample_type,perf_env__arch (perf_session__env (scr->session))); +callchain_param_setup (sample_type,perf_session__e_machine (evsel__session (evsel)));/* Enable fields for callchain entries */ if (symbol_conf.use_callchain &&
@@ -3816,7 +3816,7 @@ static void script__setup_sample_type(struct perf_script *script)struct perf_session *session = script->session;u64 sample_type =evlist__combined_sample_type (session->evlist); -callchain_param_setup (sample_type,perf_env__arch (session->machines.host.env)); +callchain_param_setup (sample_type,perf_session__e_machine (session));if (script->stitch_lbr && (callchain_param.record_mode !=CALLCHAIN_LBR )) { pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
tools/perf/util/callchain.c +3 -2
@@ -31,6 +31,7 @@#include "callchain.h" #include "branch.h" #include "symbol.h" +#include "thread.h" #include "util.h" #include "../perf.h"
@@ -1679,7 +1680,7 @@ void callchain_cursor_reset(struct callchain_cursor *cursor)map_symbol__exit (&node->ms); } -void callchain_param_setup (u64 sample_type,const char *arch) +void callchain_param_setup (u64 sample_type,uint16_t e_machine) {if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) { if ((sample_type & PERF_SAMPLE_REGS_USER) &&
@@ -1701,7 +1702,7 @@ void callchain_param_setup(u64 sample_type, const char *arch)* erroneous entries. Always skipping the LR and starting from the FP * can result in missing entries. */ -if (callchain_param.record_mode ==CALLCHAIN_FP && !strcmp (arch,"arm64" )) +if (callchain_param.record_mode ==CALLCHAIN_FP && e_machine ==EM_AARCH64 ) dwarf_callchain_users = true; }
tools/perf/util/callchain.h +1 -1
@@ -303,7 +303,7 @@ int callchain_branch_counts(struct callchain_root *root, u64 *branch_count, u64 *predicted_count, u64 *abort_count, u64 *cycles_count); -void callchain_param_setup (u64 sample_type,const char *arch); +void callchain_param_setup (u64 sample_type,uint16_t e_machine);bool callchain_cnode_matched (struct callchain_node *base_cnode,struct callchain_node *pair_cnode);
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Ian Rogers
reviewerPATCH 3/3 perf thread-stack: Switch thread_stack__init to use e_machine
In reply to Ian RogersThe architecture type is used to set the retpoline state. Rather than use the arch string switch to using the ELF machine that's readily available within the thread.
--- tools/perf/util/thread-stack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/thread-stack.c +2 -2
@@ -157,10 +157,10 @@ static int thread_stack__init(struct thread_stack *ts, struct thread *thread,if (thread__maps (thread) &&maps__machine (thread__maps (thread))) {struct machine *machine =maps__machine (thread__maps (thread)); -const char *arch =perf_env__arch (machine->env); +uint16_t e_machine =thread__e_machine (thread, machine); ts->kernel_start =machine__kernel_start (machine); -if (!strcmp (arch,"x86" )) +if (e_machine ==EM_X86_64 || e_machine ==EM_386 ) ts->rstate =X86_RETPOLINE_POSSIBLE ; }else { ts->kernel_start =1ULL <<63 ;
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Arnaldo Carvalho de Melo
maintainerQuoted 6 lines · Ian Rogers
Switch 3 more cases where the
perf_envarch was being used to determine the architecture type and switch to using the ELF machine. This includes the addition of minimal instruction parsing in perf script for architectures other than x86, or x86 when cross-platform.
Quoted 7 lines
Note: this series will conflict with the
e_flagsseries:
https://lore.kernel.org/lkml/[email protected]/
that adds an additional out argument tothread__e_machine. In all the cases here that argument should be NULL. So:
thread__e_machine(thread, machine)
becomes:
thread__e_machine(thread, machine, /*e_flags=*/NULL)
This one isn't applying.
- Arnaldo
Quoted 28 lines
Ian Rogers (3):
perf script: Fixscript_fetch_insnfor more than just x86 perf callchain: Switchcallchain_param_setupfrom an arch to an
e_machine
perf thread-stack: Switchthread_stack__initto usee_machinetools/perf/arch/x86/util/Build | 1 - tools/perf/arch/x86/util/archinsn.c | 27 ------- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 20 +----- .../scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/tests/dlfilter-test.c | 1 - tools/perf/util/archinsn.h | 12 ---- tools/perf/util/callchain.c | 5 +- tools/perf/util/callchain.h | 2 +- tools/perf/util/dlfilter.c | 3 +- tools/perf/util/sample.c | 71 +++++++++++++++++++ tools/perf/util/sample.h | 7 ++ tools/perf/util/thread-stack.c | 4 +- tools/perf/util/trace-event-scripting.c | 16 ----- tools/perf/util/trace-event.h | 3 - 15 files changed, 91 insertions(+), 89 deletions(-) delete mode 100644 tools/perf/arch/x86/util/archinsn.c delete mode 100644 tools/perf/util/archinsn.hSignature · 1 line
2.52.0.457.g6b5491de43-goog
Arnaldo Carvalho de Melo
maintainerQuoted 15 lines · Arnaldo Carvalho de Melo
Quoted 6 lines · Ian Rogers
Switch 3 more cases where the
perf_envarch was being used to determine the architecture type and switch to using the ELF machine. This includes the addition of minimal instruction parsing in perf script for architectures other than x86, or x86 when cross-platform.Quoted 7 lines
Note: this series will conflict with the
e_flagsseries:
https://lore.kernel.org/lkml/[email protected]/
that adds an additional out argument tothread__e_machine. In all the cases here that argument should be NULL. So:
thread__e_machine(thread, machine)
becomes:
thread__e_machine(thread, machine, /*e_flags=*/NULL)
Quoted 1 line
This one isn't applying.
⬢ [acme@toolbx perf-tools-next]$ git am ./20260123_irogers_perf_more_elf_machine_usage.mbx
Applying: perf script: Fix script_fetch_insn for more than just x86
Applying: perf callchain: Switch callchain_param_setup from an arch to an e_machine
error: patch failed: tools/perf/util/callchain.c:31
error: tools/perf/util/callchain.c: patch does not apply
Patch failed at 0002 perf callchain: Switch callchain_param_setup from an arch to an e_machine
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
⬢ [acme@toolbx perf-tools-next]$
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Ian Rogers
Switch 3 more cases where the
perf_envarch was being used to determine the architecture type and switch to using the ELF machine. This includes the addition of minimal instruction parsing in perf script for architectures other than x86, or x86 when cross-platform.Note: this series will conflict with the
e_flagsseries:
https://lore.kernel.org/lkml/[email protected]/
that adds an additional out argument tothread__e_machine. In all the cases here that argument should be NULL. So:
thread__e_machine(thread, machine)
becomes:
thread__e_machine(thread, machine, /*e_flags=*/NULL)
Quoted 5 lines
Quoted 1 line
This one isn't applying.
⬢ [acme@toolbx perf-tools-next]$ git am ./20260123_irogers_perf_more_elf_machine_usage.mbx
Applying: perf script: Fixscript_fetch_insnfor more than just x86
Applying: perf callchain: Switchcallchain_param_setupfrom an arch to ane_machine
So, please try to refresh it with what is in tmp.perf-tools-next now.
⬢ [acme@toolbx perf-tools-next]$ git log --oneline -100a6fb6604746c92b (HEAD -> perf-tools-next, x1/perf-tools-next, x1/HEAD, perf-tools-next/tmp.perf-tools-next, five/perf-tools-next, five/HEAD, acme/tmp.perf-tools-next) perf session: Print all machines in session dump 2becdd163ab37c9d perf unwind-libdw: Wire up e_flags for CSKY0403930f7b1534e3 perf perf_regs: Accurately compute register names for CSKY4e66527f8859a661 perf thread: Add optional e_flags output argument to thread__e_machine7d0ebeb6c0f735d4 perf dso: Factor out e_machine reading for use in thread76b2cf07a6d2a836 perf vendor events amd: Fix Zen 5 MAB allocation events008603bda19b2968 perf test: Fix test perf evlist for z/VM s390xdda5f926a1006c73 perf annotate: Fix BUILD_NONDISTRO=1 missing args->ms conversions to pointer9966b382d06733f7 tools headers: Don't check arm64's unistd.h129bb23a6f7d0226 Revert "perf tools: Fix arm64 build by generating unistd_64.h"
⬢ [acme@toolbx perf-tools-next]$
- Arnaldo
Ian Rogers
reviewerQuoted 26 lines · Arnaldo Carvalho de Melo
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Ian Rogers
Switch 3 more cases where the
perf_envarch was being used to determine the architecture type and switch to using the ELF machine. This includes the addition of minimal instruction parsing in perf script for architectures other than x86, or x86 when cross-platform.Note: this series will conflict with the
e_flagsseries:
https://lore.kernel.org/lkml/[email protected]/
that adds an additional out argument tothread__e_machine. In all the cases here that argument should be NULL. So:
thread__e_machine(thread, machine)
becomes:
thread__e_machine(thread, machine, /*e_flags=*/NULL)Quoted 5 lines
Quoted 1 line
This one isn't applying.
⬢ [acme@toolbx perf-tools-next]$ git am ./20260123_irogers_perf_more_elf_machine_usage.mbx
Applying: perf script: Fixscript_fetch_insnfor more than just x86
Applying: perf callchain: Switchcallchain_param_setupfrom an arch to ane_machineSo, please try to refresh it with what is in tmp.perf-tools-next now.
Quoted 12 lines
⬢ [acme@toolbx perf-tools-next]$ git log --oneline -10
0a6fb6604746c92b(HEAD -> perf-tools-next, x1/perf-tools-next, x1/HEAD, perf-tools-next/tmp.perf-tools-next, five/perf-tools-next, five/HEAD, acme/tmp.perf-tools-next) perf session: Print all machines in session dump2becdd163ab37c9dperf unwind-libdw: Wire upe_flagsfor CSKY0403930f7b1534e3perfperf_regs: Accurately compute register names for CSKY4e66527f8859a661perf thread: Add optionale_flagsoutput argument tothread__e_machine7d0ebeb6c0f735d4perf dso: Factor oute_machinereading for use in thread76b2cf07a6d2a836perf vendor events amd: Fix Zen 5 MAB allocation events008603bda19b2968perf test: Fix test perf evlist for z/VM s390xdda5f926a1006c73perf annotate: Fix BUILD_NONDISTRO=1 missingargs->msconversions to pointer9966b382d06733f7tools headers: Don't check arm64'sunistd.h129bb23a6f7d0226Revert "perf tools: Fix arm64 build by generatingunistd_64.h"
⬢ [acme@toolbx perf-tools-next]$
Thanks, sent now:
https://lore.kernel.org/lkml/[email protected]/
Ian
Quoted 1 line
- Arnaldo