From nobody Sat Feb 7 17:09:31 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 3F6C2137750 for ; Sat, 24 Jan 2026 00:16:20 +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=1769213781; cv=none; b=dZcgJGmwjTIrVTYPHqUMHAdrDnSY0WDOUVKSJTHMtdXj4bFp6pJa21fPBVC+1xWkiFBKsIDB2UTsVt5taSFZbx+h59iMoH/nZ5HFM7r0Iyjn0yR1VNezIoED+GmcjIhUcnhXf3w2BXaK8SXi1eNxLhN7OsFKWK8p46TGfXeTqms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769213781; c=relaxed/simple; bh=D7GSXZHJxuwLT9nYxPxzqyHjM0asoUVFMFq1khSyD9M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=UR/YCVFXhVERI1XoZ0XWduC0dzIUzIqFx6USIPoJLe2yFJYLa8K/hu6AvfWPRwDqy1P7GTxlbBfptkxJ1IYr9pOMeWxsIWylWs7uZtABVZA+w5UG7DT4JAM4rE5b0dl800Y+ByTmyNXg/lIl6PTNzji4EIo46zSKNSO9x68+t9I= 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=ZxFRCl+G; 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="ZxFRCl+G" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b74766fae7so939550eec.0 for ; Fri, 23 Jan 2026 16:16:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769213779; x=1769818579; 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=71clqYtrvxTcP8hDC5pO0EDsKlw6xvkRsj75GQMSL04=; b=ZxFRCl+GMO2J7yuMrI6kaE6fEOE8XRTXUITiv9Bt5gGuq/2QHGH22WJZXSRV8pq+PK fMeMKFqm2XUZVUHmyfiteXua7n/mP2FrMJ/bbqIOHFMQIxnxAtBNmSAzFfp0B5QeLY10 bQ1gP/kcv43CxO6NetDTsvugCh5Tuc/FSY+XDH4XjZyiLsautAKktBsdE+BCo7ZAgWMK q7nQeaad/QH9HggChdwvSjjh9KDbqndq84Gh/iDuiu12QVCIQ6q9Jowyd3v8+ofhnov7 D43X1Y/hF1YYE/AnWMfcFCK5yyvpS48rZxQCoSEAyC8iVZoZG3mWhWH8rJTWfia8KEkn b5Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769213779; x=1769818579; 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=71clqYtrvxTcP8hDC5pO0EDsKlw6xvkRsj75GQMSL04=; b=ZK4iqX33F4dRtxIBfVtFcZAj/GBEExRaXZT09upAuRUkyD66CmUlqZg8BH3gphwDAB XoVWq/6JUzWsp6Ol5NKsFUW5WN2JDPEYKqrUt/FaALepvvFsN+HwsP0NgxEztRtvOsQR 84TLmy3bxzyhMVUvCs79AezrfqudFVKxpXgF0AV1rumB0ssFcSOIs5G2n0wwC9YJhH8K Vb+tqvywwtT2qstdofQTv9UpJq60IpDxaqmjmfjUX57MFbw0nkzx/Q6kWuXmEjbbN+ke 54TAtL0fhqdsDPtwXwcCZSitLyeZ8N6LGE/xIS2eGiihOvw0YCbIgnsvlWeCixqfidh3 2wRg== X-Forwarded-Encrypted: i=1; AJvYcCVCuxvEPx3Rvc30+oMm/eC6h3p08CG6Xy8TFyA5BA+S2Rex8z1ZY9nWXROVlyVDx+ljcd5KlS1j5XBBEU4=@vger.kernel.org X-Gm-Message-State: AOJu0YwsvOiWzOeM9xtdoBe9DgXJViifT8EQIPJNEK/KXzn7HU/ptuRr iT+B26b9MR7GUjUhYjYeFgcf7KZ9aq/rDsO4Pz+UC4uM4uO9/sy9S7vLZduNMrY68Jqr+X2YkLG UVVSVDhW54A== X-Received: from dycna19.prod.google.com ([2002:a05:7300:ea93:b0:2b7:481:7150]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:e607:b0:2a4:3594:72ed with SMTP id 5a478bee46e88-2b739b6d28dmr2210277eec.28.1769213779370; Fri, 23 Jan 2026 16:16:19 -0800 (PST) Date: Fri, 23 Jan 2026 16:16:09 -0800 In-Reply-To: <20260124001611.1332019-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: <20260124001611.1332019-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260124001611.1332019-2-irogers@google.com> Subject: [PATCH v1 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 372bede30230..b4bf68b17948 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; @@ -1618,7 +1616,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); @@ -4016,7 +4014,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; @@ -4438,17 +4435,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 17:09:31 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 EEAB218E025 for ; Sat, 24 Jan 2026 00:16:21 +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=1769213783; cv=none; b=XQXSQ277fpTXdkSXYXh/9Y5reHt2IMCKbHFpUv9vQqPb6tJsis2t3SDiwXQ0QkPL2jvr0jerdHJUuVOCIcrCGKf5COfDBQUguir+hXGk5xVnpYJII6HgxS8AkKkeeY616911zrD51hNPOS2+9dd4gBoUNEPyHZh0VXlV9x3uEBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769213783; c=relaxed/simple; bh=xoTKdY5MAIMg9s3+CbhKXcBihq4xRVvKEKcGiPiugSA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=GA8DkVAEQ0Sik8592/KUNdAASLHWEV4iYlGL0G42lH45yxI6YD3IKBl+8hhVV4uyo54ImHK4T/OIFgMNj+xJjskp+O9shU8x78nyglDHwBh+IyYhKgStfF+BqWeDbYtNhX2d8HzJQ2aCVg7SvXqz7tpaXrj6kSfR4OKJoXhg0x4= 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=gMs7HADo; 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="gMs7HADo" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b738854780so2210308eec.0 for ; Fri, 23 Jan 2026 16:16:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769213781; x=1769818581; 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=XeLoVbBU1gOuq2z/uTQrFDkA2VXk5of7fAyzn6BOLT8=; b=gMs7HADoo2WMWFCMQTWMWDk30Xei1R5b4a7bUP96rONxLiOMTxKtyAIE7lCED+o6F3 GTW2Qb2UQM8Cp2R1Qp/ZRu+EPivgk3tZXk78yFK21VCS+B9fcMrf+u7DkQcuwZ5ogJL8 /lTYsZNfAmZNqf4o5qqjNPqwjgx0dXE5CYVHFo33hvOVeneURzmwtrJ8+7mnZdtGx6vc zYBaZykBLgRQFTDJs1LCCktSce7UO4DBwfDsO1BNvgkHmj16iY/jtYpJCPIJTDWajUF4 uEGM1gwv8zZEHT1UtSpXm/+jw02/aPofPKAGhTacu3VaJQd0D5BwJPVPGaAlTqA5vZy9 0Mrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769213781; x=1769818581; 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=XeLoVbBU1gOuq2z/uTQrFDkA2VXk5of7fAyzn6BOLT8=; b=QbaEHfd4jXeymi6FIeMobIxZ+hAw7ig1HuOolWFQCCduf8/NpSYEwpv03nDbYDkpJ8 4Npkyhh/FfQtv4B1gyXRVNPAoajHJRcYtA483+VIwQqWPxuBA56kJ3sUasf1EQEZIdWZ UMcVglvJLUE6hO5OTOsLRLTtsLOXAFeXfrOTzFQUVsGvRIR2G8P8kLDSQJ+UsSna7ebg /F3ytodfUT2VTxd4pQcjhja+tKkmyRkEh2nu7XWMHVk4G8BB4boyaPgBRYAKmvfdFPG1 3Twfd/Rf5b31beaGMO8utTBLJvw5+waX2MmDQAPdKaMqsPDSz5mwajee3zcMGtq6L7Yk 6Z5A== X-Forwarded-Encrypted: i=1; AJvYcCXLO4Ap8P4zjW5/HApPSlABDAr0Z+KvKDo0ZoGQrmxHa9vwU2UOh3Dq2MUXFo1Xhzkm2vQqvbh7VhZ1oBc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0wjbrpLSf/ShITGTvOFqpQVsbFaNGFUx9lHaFOrVW7lb80T5Q 551rFNGPP/ayLsTbJbVhCw1Golz1yjTIu52DSsNGX8bZ7muAP9LgWEclRUBX1XVl9Pu8mvu0gBr zIS9q8TwfBw== X-Received: from dlbcf5.prod.google.com ([2002:a05:7022:4585:b0:123:291f:3e5b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e0b:b0:119:e56b:91e6 with SMTP id a92af1059eb24-1247dbf8170mr2467131c88.23.1769213781257; Fri, 23 Jan 2026 16:16:21 -0800 (PST) Date: Fri, 23 Jan 2026 16:16:10 -0800 In-Reply-To: <20260124001611.1332019-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: <20260124001611.1332019-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260124001611.1332019-3-irogers@google.com> Subject: [PATCH v1 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 | 5 +++-- tools/perf/util/callchain.h | 2 +- 4 files changed, 8 insertions(+), 9 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 b4bf68b17948..c7c0d195b78b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2841,7 +2841,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 && @@ -3816,7 +3816,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 428e5350d7a2..53ae382432c8 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -31,6 +31,7 @@ #include "callchain.h" #include "branch.h" #include "symbol.h" +#include "thread.h" #include "util.h" #include "../perf.h" =20 @@ -1679,7 +1680,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) && @@ -1701,7 +1702,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); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 17:09:31 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 CABDD335BA for ; Sat, 24 Jan 2026 00:16:23 +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=1769213785; cv=none; b=RFDGaehtr0SKipa0H4HsaTK/tZoAeMRDyCtsPBN2Hfs7DpgTx4q86dWNsSQoD3EvnUK7eJtKp9VwBBEgUaSeFlAZXQUbpxvf4HOEBIVmATD4O3x/QmxhqUkSlKwEG5ZlpyE9/fy2oWCqQTS3FAoo4l8QCXPUhM6nGUwsSWCW5z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769213785; c=relaxed/simple; bh=WWbTmbdSLorrseRj7mprNfnA5YwkHHLrYNGP7YB9W+A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=N3rV+cYQ0gbc853VHYEE5egu/EsR3Ue+qBWK/1jSHBBD2I+xOSB06IWXwPdj0UNxdX+nGo9H5NtqmhcuxH6oIdGOvCUcS5fgcmdYhGwTiYb2hwXEvsNgY0w9CJNIMdC61y3M3sQqclufl2WvPDbCPiRoHHqxpWj3B2WnwSPwnD0= 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=VyphcaEH; 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="VyphcaEH" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b74766fae7so939589eec.0 for ; Fri, 23 Jan 2026 16:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769213783; x=1769818583; 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=hsppo8YRwJ65Q6pcz9zCc1oZe5VMY/WbrSPn1MsLzfk=; b=VyphcaEHqNg8eypULshX/PW/OboFx616JpyqJMIBq2lQSfYzPxIsr8LBerEk4DnOEz GWnaAsWxiJIBcs3/aARmI1wcolUJ6q92JdE/jFsUdUD/VSVNuqSVExNYqlY838xAuXuP 1hcwKr+fMeTV1QW6KHInzmES/t5q7yqukINjGPa7E5v8J808SWpG00AumfZMJdcxGqDP shUQg3ZkSz1ikwh9chOA+AovEnm6DXZOKI85c8bZZkOfB5dgfapmOaE8adDhFuYmGzs2 O64Vgs/tTi6IvXyDVMYVI8jj5h3X5wHGhDWsjXLeHXP9NoA1fwgsklv7yw2lVQF+hh4y pwLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769213783; x=1769818583; 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=hsppo8YRwJ65Q6pcz9zCc1oZe5VMY/WbrSPn1MsLzfk=; b=PdM7F9jYHZIOY8dOIWic4lNtEsATDMzm8UL7QB3Pr/1XBRvnE/H3/bcoec+2kXG5MM qj8qlUua4Ufo5uskEOyPxKyFe0reeToiXQfK+JUIepn2W8dWr9oAUzno+9lkCMKiUboZ zsaiQ44lnG6+6CrRB+Dno9VvTIgr4NeYg2oYTMAN72V5IJAxttI21keDcbUazULR5GEn CKxczuEd057uuSy6cNVVjB3kA7Mt/ku6pJhFXTFLBlGIxw+K0JA5MIVeDRIIE1lq48BZ khjZoab1MX07I0lBZKEPzlVTZbLnjMT9+oChuuP+MLd8EFNhm3KwN4zYkkVHgsS/6Dzk ELkQ== X-Forwarded-Encrypted: i=1; AJvYcCWd6+cIpg6+28EKmYfBuqclXU/gme+fpJ8On4s2iUYvU+//8L2M+hauddSAulsAt9FYWv1CEy/mbpFPmjI=@vger.kernel.org X-Gm-Message-State: AOJu0YxfJ1SXD5PXYsop5eJaS/+QaEACq3bt9XYOXPGDSt0+g7XnJ1Mt bwlN88rHQZYCHW1NUC7AHPLop+/k9U1c3rSjKbUKhpBJKpUQ97Rl3ut+UXdfTDLNFypBuoppacB e+bZK5Mg9dA== X-Received: from dybpt23.prod.google.com ([2002:a05:7301:4097:b0:2b6:f58c:f252]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:fa84:b0:2b7:98d:7b54 with SMTP id 5a478bee46e88-2b739992976mr2667626eec.14.1769213783002; Fri, 23 Jan 2026 16:16:23 -0800 (PST) Date: Fri, 23 Jan 2026 16:16:11 -0800 In-Reply-To: <20260124001611.1332019-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: <20260124001611.1332019-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260124001611.1332019-4-irogers@google.com> Subject: [PATCH v1 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..dac76d03f741 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); =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