From nobody Sat Feb 7 11:38:04 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 606752FF65F for ; Mon, 26 Jan 2026 22:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465160; cv=none; b=YSO1FWCUWnIc+s2MfkfFNP+mZhzTbTZUB7o1rlYRMw8nRWQAXt2vRO8Qf842fEfnwfkeh1XmZYTzekzzTQJRdLMzL1eQ3k9ExQ+8N9wU8GTRau+dgyXaJMsxoPPI8uWxmlhN9Fw33Uzn6D5+bNCV5JXWZ8MlOsVOAcSor95nID4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465160; c=relaxed/simple; bh=D6IHvh/RYDhrsOnsnqt6RvaM6BELKcPnEPdhv2NRJZU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uoHyBWmQ/2us/4GHmYMbPpML3IblVj00/gneXUdggfhYI7oO8qJGYFPywypLsrxh+NjDpgJ1xDOmPVtvy9oXHyNuktBr1XIONswAR02I5DNmGKg+7gPETLzh0NRnUQV8eMhrYGDqevm/IxOY8Ka3CY45wKof9fNSgMj3ZApy4L8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gzzJejOj; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gzzJejOj" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b71c5826fbso5245506eec.1 for ; Mon, 26 Jan 2026 14:05:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769465157; x=1770069957; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RGvTYo7LJrFeZcKynUHNX0eReEMJ0nid9UIfv18rSLo=; b=gzzJejOjrDijleBlmGyw9oQsbKaR/8fgd5Vqtng8i+qMVSjY13NmnfNYH4daf7erIm N3pDh1sFeoFhpHjYqVuXU9BDMd3jiJ3bu34eYRf8m29pBycFf+MbR78a2dy6Rm2gFtA2 RvZHIyKIZSUzY8hcBW9o/BY349HmvCTT3at4156WSInmxprvWxo44BeYJ1QeUCPsmpfF A7solAzjgzr3Pujmcqu/cUs3RNicvEAyw/EXDH4ob6qRi7tSsLbtnyH0Xy7bbzizU/+9 yXN32ru4arBYwee19vhgIWQAnX2QV57M/57uW28DSOrlKguFpFOaORMl1yLYuP1HJZg8 BGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769465157; x=1770069957; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RGvTYo7LJrFeZcKynUHNX0eReEMJ0nid9UIfv18rSLo=; b=QVJoZF1z+nWCHRH2TKdQeB3PVUDVLv+RU70t5dH4hRRd96ttmr/pDwjVRCkKy2RHtS ojfI9kQHAIMg/4YgyWxFy+xD5k5nuPpH7cbm1ufCBxVuS2fukaXyKcNdx3Dskg4GyUvO q/Ir+3ynhXjDNWNvm2lcmH6ecGjzBlYO5gFzMWAU6aT14U2UfnjK8XcVESW+G00BK8fn BOka6D3gBXKlDGBb7g3emxZKUXxe1S43U97vtq6AqZwo11e1QrcrEre39/ipXqmRdUXs m+g/GaB/6MmiyGYLj561t1ByC6CIPI5OJbMMsWMEUL3Jcalu1p4YeJjbqSCtg9aiclAv EF1Q== X-Forwarded-Encrypted: i=1; AJvYcCWzCSZ87z3cPx46On+g8iYIc8+7JWO8krmqQkOH9MkkIkRliv/AJLKTYg5VhQseYAF7Zq0HADp6zF87GcQ=@vger.kernel.org X-Gm-Message-State: AOJu0YymiNzMn9iHEM4VP8XFvjRkurG9eAy4SMVx031jyY57hhNNGDEm cxee4zpGkuz9Svm9p1mTlNdXrAPVondFmyRFj88RoHKVxL5Mvty3DtrWhg4TkzsDFaX9TcOlahx JUpHFP/yUfQ== X-Received: from dlbcf3.prod.google.com ([2002:a05:7022:4583:b0:123:12b9:c4e5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4399:b0:121:9f05:c4c2 with SMTP id a92af1059eb24-1248ec40fa3mr2859327c88.23.1769465157415; Mon, 26 Jan 2026 14:05:57 -0800 (PST) Date: Mon, 26 Jan 2026 14:05:48 -0800 In-Reply-To: <20260126220550.2573257-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260126220550.2573257-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260126220550.2573257-2-irogers@google.com> Subject: [PATCH v2 1/3] perf script: Fix script_fetch_insn for more than just x86 From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Shimin Guo , Andi Kleen , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ian Rogers --- 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 diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index fad256252bb9..76127eefde8b 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -14,6 +14,5 @@ perf-util-y +=3D iostat.o perf-util-$(CONFIG_LOCAL_LIBUNWIND) +=3D unwind-libunwind.o =20 perf-util-y +=3D auxtrace.o -perf-util-y +=3D archinsn.o perf-util-y +=3D intel-pt.o perf-util-y +=3D intel-bts.o diff --git a/tools/perf/arch/x86/util/archinsn.c b/tools/perf/arch/x86/util= /archinsn.c deleted file mode 100644 index 546feda08428..000000000000 --- a/tools/perf/arch/x86/util/archinsn.c +++ /dev/null @@ -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 =3D false; - - if (!sample->ip) - return; - len =3D thread__memcpy(thread, machine, sample->insn, sample->ip, sizeof(= sample->insn), &is64bit); - if (len <=3D 0) - return; - - ret =3D insn_decode(&insn, sample->insn, len, - is64bit ? INSN_MODE_64 : INSN_MODE_32); - if (ret >=3D 0 && insn.length <=3D len) - sample->insn_len =3D insn.length; -} diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 6ec225c697a4..69af25780fc5 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -37,7 +37,6 @@ #include "ui/ui.h" #include "print_binary.h" #include "print_insn.h" -#include "archinsn.h" #include #include #include @@ -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; @@ -1627,7 +1625,7 @@ static int perf_sample__fprintf_insn(struct perf_samp= le *sample, { int printed =3D 0; =20 - script_fetch_insn(sample, thread, machine, native_arch); + perf_sample__fetch_insn(sample, thread, machine); =20 if (PRINT_FIELD(INSNLEN)) printed +=3D fprintf(fp, " ilen: %d", sample->insn_len); @@ -4034,7 +4032,6 @@ int cmd_script(int argc, const char **argv) .set =3D false, .default_no_sample =3D true, }; - struct utsname uts; char *script_path =3D NULL; const char *dlfilter_file =3D NULL; const char **__argv; @@ -4456,17 +4453,6 @@ int cmd_script(int argc, const char **argv) if (symbol__init(env) < 0) goto out_delete; =20 - uname(&uts); - if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */ - native_arch =3D true; - } else if (env->arch) { - if (!strcmp(uts.machine, env->arch)) - native_arch =3D true; - else if (!strcmp(uts.machine, "x86_64") && - !strcmp(env->arch, "i386")) - native_arch =3D true; - } - script.session =3D session; script__setup_sample_type(&script); =20 diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index 60dcfe56d4d9..c19f44610983 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -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 =3D maps__machine(thread__maps(c->al->thread)); =20 - script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=3D*/t= rue); + 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 */ diff --git a/tools/perf/tests/dlfilter-test.c b/tools/perf/tests/dlfilter-t= est.c index 80a1c941138d..e63790c61d53 100644 --- a/tools/perf/tests/dlfilter-test.c +++ b/tools/perf/tests/dlfilter-test.c @@ -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" diff --git a/tools/perf/util/archinsn.h b/tools/perf/util/archinsn.h deleted file mode 100644 index 448cbb6b8d7e..000000000000 --- a/tools/perf/util/archinsn.h +++ /dev/null @@ -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 diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index c0afcbd954f8..dc31b5e7149e 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -234,8 +234,7 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) struct machine *machine =3D maps__machine(thread__maps(al->thread)); =20 if (machine) - script_fetch_insn(d->sample, al->thread, machine, - /*native_arch=3D*/true); + perf_sample__fetch_insn(d->sample, al->thread, machine); } } =20 diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index 605fee971f55..d885c02a9861 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include "sample.h" #include "debug.h" +#include "thread.h" +#include #include #include #include +#include "../../arch/x86/include/asm/insn.h" =20 void perf_sample__init(struct perf_sample *sample, bool all) { @@ -41,3 +44,71 @@ struct regs_dump *perf_sample__intr_regs(struct perf_sam= ple *sample) } return sample->intr_regs; } + +static int elf_machine_max_instruction_length(uint16_t e_machine) +{ + switch (e_machine) { + /* Fixed 4-byte (32-bit) architectures */ + case EM_AARCH64: + case EM_PPC: + case EM_PPC64: + case EM_MIPS: + case EM_SPARC: + case EM_SPARCV9: + case EM_ALPHA: + case EM_LOONGARCH: + case EM_PARISC: + case EM_SH: + return 4; + + /* Variable length or mixed-mode architectures */ + case EM_ARM: /* Variable due to Thumb/Thumb-2 */ + case EM_RISCV: /* Variable due to Compressed (C) extension */ + case EM_CSKY: /* Variable (16 or 32 bit) */ + case EM_ARC: /* Variable (ARCompact) */ + return 4; + case EM_S390: /* Variable (2, 4, or 6 bytes) */ + return 6; + case EM_68K: + return 10; + case EM_386: + case EM_X86_64: + return 15; + case EM_XTENSA: /* Variable (FLIX) */ + return 16; + default: + return MAX_INSN; + } +} + +void perf_sample__fetch_insn(struct perf_sample *sample, + struct thread *thread, + struct machine *machine) +{ + int ret, len; + bool is64bit =3D false; + uint16_t e_machine; + + if (!sample->ip || sample->insn_len !=3D 0) + return; + + e_machine =3D thread__e_machine(thread, machine); + len =3D elf_machine_max_instruction_length(e_machine); + len =3D thread__memcpy(thread, machine, sample->insn, + sample->ip, len, + &is64bit); + if (len <=3D 0) + return; + + sample->insn_len =3D len; + + if (e_machine =3D=3D EM_386 || e_machine =3D=3D EM_X86_64) { + /* Refine the x86 instruction length with the decoder. */ + struct insn insn; + + ret =3D insn_decode(&insn, sample->insn, len, + is64bit ? INSN_MODE_64 : INSN_MODE_32); + if (ret >=3D 0 && insn.length <=3D len) + sample->insn_len =3D insn.length; + } +} diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index a8307b20a9ea..3cce8dd202aa 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -5,6 +5,9 @@ #include #include =20 +struct machine; +struct thread; + /* number of register is bound by the number of bits in regs_dump::mask (6= 4) */ #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64)) =20 @@ -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); =20 +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. diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 72abb28b7b5a..fa850e44cb46 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -13,7 +13,6 @@ #include #endif =20 -#include "archinsn.h" #include "debug.h" #include "event.h" #include "trace-event.h" @@ -274,21 +273,6 @@ void setup_perl_scripting(void) #endif #endif =20 -#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 =3D=3D 0 && native_arch) - arch_fetch_insn(sample, thread, machine); -} - static const struct { u32 flags; const char *name; diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 71e680bc3d4b..914d9b69ed62 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -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)); =20 -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); =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 11:38:04 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 367C52FFF82 for ; Mon, 26 Jan 2026 22:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465161; cv=none; b=NiYMQCRTaSYEpercSylamypovFKQtrsiOfoEfPbxZr7HfilcHfrzPcoFN2Yt1xIatVlItjM3UU/ZjW0MHuGohctw6Vsye3YUaLi7YzzPTyNAJ4gj+p21ASFJ4HOID7Ze/ghn9mIvJxgcMNR/W2zGcbEGNVUIS3e/5j0eg8GsEFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465161; c=relaxed/simple; bh=QAr4+Nc+Cx9Kyw9xC6h4+6yxNEiU19ywiW6NGK05bUg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NPdFvG3Puom8GznOJYwN2xcruujYt5DnJ4kUOh8wdAr2pWPDF+qfPxtycTF5mtW3UcO5R7It1/K9LwsHUkNgMOYxLqnsJ3IJohdr9xdgSs/PPeHQOZRqZ01lDUO3RdaRv9EIkKJoWHmFDuiGHLgLCtJeY5wLnTOh+V763QP6wDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KQMkr311; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KQMkr311" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b6f0b345e3so23678746eec.0 for ; Mon, 26 Jan 2026 14:06:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769465159; x=1770069959; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uscjFzN7lW6l+hjfQoY8JpHSmnfj6RBxlc4jMPBGOng=; b=KQMkr31197PsRNz8T/h7S+c2hrxwVl0Zw3hg4EWpld4geb7AR/KIlCBQFNrMTBKEHQ BCkJcke5HauXVWXDAj2Inw1PbY5d5fR/gg20UXySXcRFFuCHtu/GlABgjlF+1j+xaL9i E/sK65DkFWk0ep+x3hFoL/csTC9sZQXhqUxwjJPbIDQ6VApqsyqrQc+wGJ1aY5C8Tyg1 RSmO20tuYVlCaXQ1RCFV4gCd1kUZKFrC5eCQcpsXKYIicRBCX8Gh7YL5jEGvqv43bLKz SmNtLXMUmqonc82imyh3/LuCq5YiZ/G/ncaxImwEyChn3tk5fGtxJ5nc1kKeRbT2ObS2 SE3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769465159; x=1770069959; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uscjFzN7lW6l+hjfQoY8JpHSmnfj6RBxlc4jMPBGOng=; b=uc3xXc+I3A6MI2r8a9xo0DFpLVZIEQvC31wjiJmRDOcEoBWhzsZVLGmeogB0eh+14P UWe4N17ZlJ0eVUEUSREy7cswU8+5v2PcLjClagZvwvYCCgcxujFcylVt44f6BUMR31V0 Fe+EJ9j68OictGSwnZWjJdwB2sMYhtQoywsFSPLPzJym6XA11xGgJS42QpRnD1Vyxx/f ru/l0CjTofeQSnzHFi9eUdfwqctoIq/Y7BZvfDT0cYhcld03GgTmOCgi+sUr84HDS+zc cO0/npNgTipeNFEMVx+dwHkV1Af+ErdkIA+/8Q6HGXr84IzF5OUTyeukBZwSrXMZQcrn Q3pg== X-Forwarded-Encrypted: i=1; AJvYcCXp5RCDLgagll6SbV5juExM347lRhHYxaLekM4wiXCsstQdujQr9tlmSt35ztnxHjXzetXUepwaHJ8WKs0=@vger.kernel.org X-Gm-Message-State: AOJu0YwOOHJgqABWZdy4i3HGt1TY6eBZf3jnsFe0OgGsyjmTIS1OTasJ u+ScVYDgJE1QOfc49uStGNdrXmnLIei8Zg9KvgbGBH8mA1P+cuVP2rv9l7yztWf0i/bWsMAtAtn 0ZWyG68zu2A== X-Received: from dyjn14.prod.google.com ([2002:a05:7300:a8e:b0:2ae:5f89:cc45]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:1483:b0:2b0:5bfb:86 with SMTP id 5a478bee46e88-2b764328ef4mr2532668eec.17.1769465159358; Mon, 26 Jan 2026 14:05:59 -0800 (PST) Date: Mon, 26 Jan 2026 14:05:49 -0800 In-Reply-To: <20260126220550.2573257-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260126220550.2573257-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260126220550.2573257-3-irogers@google.com> Subject: [PATCH v2 2/3] perf callchain: Switch callchain_param_setup from an arch to an e_machine From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Shimin Guo , Andi Kleen , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Increase use of e_machine by replacing callchain_param_setup's arch argument to be an e_machine typically read from the session. Signed-off-by: Ian Rogers --- tools/perf/builtin-report.c | 6 ++---- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/callchain.c | 4 ++-- tools/perf/util/callchain.h | 2 +- tools/perf/util/sample.c | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 2e936928e8c0..810ffd66b11c 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -448,7 +448,7 @@ static int report__setup_sample_type(struct report *rep) } } =20 - callchain_param_setup(sample_type, perf_env__arch(perf_session__env(rep->= session))); + callchain_param_setup(sample_type, perf_session__e_machine(session)); =20 if (rep->stitch_lbr && (callchain_param.record_mode !=3D 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; =20 @@ -1297,8 +1296,7 @@ static int process_attr(const struct perf_tool *tool = __maybe_unused, */ sample_type =3D evlist__combined_sample_type(*pevlist); session =3D (*pevlist)->session; - env =3D 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; } =20 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 69af25780fc5..c7d5a325b5cb 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2859,7 +2859,7 @@ static int process_attr(const struct perf_tool *tool,= union perf_event *event, * on events sample_type. */ sample_type =3D 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))); =20 /* Enable fields for callchain entries */ if (symbol_conf.use_callchain && @@ -3834,7 +3834,7 @@ static void script__setup_sample_type(struct perf_scr= ipt *script) struct perf_session *session =3D script->session; u64 sample_type =3D evlist__combined_sample_type(session->evlist); =20 - callchain_param_setup(sample_type, perf_env__arch(session->machines.host.= env)); + callchain_param_setup(sample_type, perf_session__e_machine(session)); =20 if (script->stitch_lbr && (callchain_param.record_mode !=3D CALLCHAIN_LBR= )) { pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 515bb8b5da01..8ff0898799ee 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1681,7 +1681,7 @@ void callchain_cursor_reset(struct callchain_cursor *= cursor) map_symbol__exit(&node->ms); } =20 -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) && @@ -1703,7 +1703,7 @@ void callchain_param_setup(u64 sample_type, const cha= r *arch) * erroneous entries. Always skipping the LR and starting from the FP * can result in missing entries. */ - if (callchain_param.record_mode =3D=3D CALLCHAIN_FP && !strcmp(arch, "arm= 64")) + if (callchain_param.record_mode =3D=3D CALLCHAIN_FP && e_machine =3D=3D E= M_AARCH64) dwarf_callchain_users =3D true; } =20 diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 2a52af8c80ac..df54ddb8c0cb 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -303,7 +303,7 @@ int callchain_branch_counts(struct callchain_root *root, u64 *branch_count, u64 *predicted_count, u64 *abort_count, u64 *cycles_count); =20 -void callchain_param_setup(u64 sample_type, const char *arch); +void callchain_param_setup(u64 sample_type, uint16_t e_machine); =20 bool callchain_cnode_matched(struct callchain_node *base_cnode, struct callchain_node *pair_cnode); diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index d885c02a9861..b9089878ace5 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -92,7 +92,7 @@ void perf_sample__fetch_insn(struct perf_sample *sample, if (!sample->ip || sample->insn_len !=3D 0) return; =20 - e_machine =3D thread__e_machine(thread, machine); + e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/NULL); len =3D elf_machine_max_instruction_length(e_machine); len =3D thread__memcpy(thread, machine, sample->insn, sample->ip, len, --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 11:38:04 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F397B2FF154 for ; Mon, 26 Jan 2026 22:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465163; cv=none; b=lxieaEYxbiVkfJ3DqxIptZMOqA0rtyLdYDeAxpvrALlzzDJYNhhJv7cEU4Pp5YA9OYm70kJqs+v1WQdyxcncoAZ8scEZJpz6XOosjOWabIfyARUw1AdVa9BKU28TcNZCI1dl3D+OmNcId8OMRuPwifvsp19LPvE7wGJnnd+Tmsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769465163; c=relaxed/simple; bh=38ko2KHDWi/gZ4iTRLKTLFlc37YFOdOAQ51KN2SHR0M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lNhjQqv6qthDfj07WN0c+Li56Hr5HIPOtaQ6n0xwufAQJ9mSN9PUm81A0+IucOJY6tcMz+JSucrZt9jtlc0hgvVOdYe6Gp3IxUSIIUQxQEeJ1z2loKMZB94HRgI6LANfRKUkdhSd8s3PdGnlNvbzgREdxIzYGfLu/jk905KJMu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FjmcWBec; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FjmcWBec" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b71bdcd037so3072206eec.1 for ; Mon, 26 Jan 2026 14:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769465161; x=1770069961; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lvPUN1XCezqfBWMGY+HqHwWXFtyxQ+bm96S5E8YV+DI=; b=FjmcWBechZ55hORxJFKv0WmzMe7VAe4at+kIDybZVdBZPtZUqZCaz8Sv16q4yH1JtW LPNzNd2cRPQ1uu/6JCF7rs9BRGGfSRuDNHT3gA9tTYz3tz9BIQyWnHHJdi++xNkdBzrs ZxE1U2E01S1J3bOrLyZRfKLS8NO25skCrkO8zGSv4M1CwhSn3Nw3BlnVllzY0XJwp8gf ogycSUl30pl5tWob3gYmtZRYkPsy2ziUZT5yycdnF16e8Nd6FXNtbTK4hhVGEv8CWnGk P5q4ZHvrouUts0219t4etfJBBqSBeHejC50jsg4FPsJBIJ8jr8irvfLSkcZW/xId8JPc SepA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769465161; x=1770069961; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lvPUN1XCezqfBWMGY+HqHwWXFtyxQ+bm96S5E8YV+DI=; b=GajWs2bbfXFxxND3BL6a0UEUPaxIcwQ5G9iY6IYX7U++jf+eXLVUCvJ8tZO7wxo/gI R8HovWLEHke8Atvg5HJplFvfTBeCJewFlsDHh88mDjecV+fS+xVQAT53YqZwzLOWyLKd 21nZRaz+1S/G4yjrG/0yXU+JCFmFbQg60KmilFt6a5H7kpssZ0LoBtqDZt6Zk8pBGHZt Y48tVdI0mrGr7TmSIQfEJzA0fL0cTdSjDAWUU8v1+NumtDuDJZQ6jbdSXQrByihE/ioh Ky0AMCcNggxE9vhydR/VmZojBQgnhiYu3zpwEMwJ2Gm1Z8YKrUp5Yy6cPPlEqPfNet7d aZfw== X-Forwarded-Encrypted: i=1; AJvYcCUeIpS93pz/WRYQQuPF1woKYpbe3jsEJh6w4GE0nKSoqqEnxrdLSOvlRCx/8YrDQ6/Der133h9hj5HZSFM=@vger.kernel.org X-Gm-Message-State: AOJu0YyLFHcGL6+uOxU3wO1DlMBMTzB/yKxoyUuVDUZS1UjcicS8F2mH qAVgvRF8PskSZmNOBx3pweYdTuH2dxZkXxl1sznQpGOFa6u9jAdRlMlCbK8rq+S6S01aQRkB5Ox oePLf0LxRcQ== X-Received: from dyaw18-n1.prod.google.com ([2002:a05:693c:4152:10b0:2b7:53fc:fbb0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ec16:b0:2b7:4f83:9a84 with SMTP id 5a478bee46e88-2b7639b902dmr2600044eec.17.1769465161226; Mon, 26 Jan 2026 14:06:01 -0800 (PST) Date: Mon, 26 Jan 2026 14:05:50 -0800 In-Reply-To: <20260126220550.2573257-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260126220550.2573257-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260126220550.2573257-4-irogers@google.com> Subject: [PATCH v2 3/3] perf thread-stack: Switch thread_stack__init to use e_machine From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Shimin Guo , Andi Kleen , Leo Yan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Ian Rogers --- tools/perf/util/thread-stack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c index c6a0a27b12c2..c5ce741b0744 100644 --- a/tools/perf/util/thread-stack.c +++ b/tools/perf/util/thread-stack.c @@ -157,10 +157,10 @@ static int thread_stack__init(struct thread_stack *ts= , struct thread *thread, =20 if (thread__maps(thread) && maps__machine(thread__maps(thread))) { struct machine *machine =3D maps__machine(thread__maps(thread)); - const char *arch =3D perf_env__arch(machine->env); + uint16_t e_machine =3D thread__e_machine(thread, machine, /*e_flags=3D*/= NULL); =20 ts->kernel_start =3D machine__kernel_start(machine); - if (!strcmp(arch, "x86")) + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386) ts->rstate =3D X86_RETPOLINE_POSSIBLE; } else { ts->kernel_start =3D 1ULL << 63; --=20 2.52.0.457.g6b5491de43-goog