From nobody Mon Jun 8 06:36:12 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 2AEAE3803FD for ; Mon, 1 Jun 2026 06:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296859; cv=none; b=azn23SkoARFzgPmmz58kSE9pZeSDzb2qYMGFSsC3RcsJbWmjR0m1Ypf8O4H02bgkJyY8vOBJyfvd4LgwmoJs4H+Z9A6VPuplcO87jV3xasiTF6TU5gSJeLhgAgxshj8yQ5LpZGErGg1S91kayooZdJI8F7T3b6DBX2NH6wLs1+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296859; c=relaxed/simple; bh=IEXCGVJtERzqMAp1H5OD0+bpoOcYMisJpGhX1y/e7Sc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kf5ttcuHdp8eQ2ST1Hr9Ag+bPpkguJ4UTELfZvLmBTgKaWVIfroRxA0B6WfntkXQrG02NU/uw+teJshtUG3jBD8SvxkEahE3uj2txJhhxw52FOeulL7TKlBG8V8tNn33sPiX0lElz9aPGp3TWUF4FZOr3Qm8E1p4hSuh5OIuD24= 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=HJEmVs8M; arc=none smtp.client-ip=74.125.82.74 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="HJEmVs8M" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137dd3a60e8so1236408c88.0 for ; Sun, 31 May 2026 23:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296855; x=1780901655; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hF0jxFy4fSGz+r6lDhFvr2i2eisffYkvRRILwCTwN+U=; b=HJEmVs8MAeX/kWgbbNCGgsu19bKIMdvIn1jOr6wwsrF2N5xrum3LO+URF0q0tHvZ9o K2tNwqrCgUic9RDtbn6G0Vb3gB0x3JaS39sPKIL/EaOLJeHr8Tq4njKhIOqcDorvnvvN YMFlQWOSLI7kGHRqtUDYRtRDXEuIGFogP2HZo/XNVgfjNhJzi4VUKotYQmt9vr8MK9Q5 ECbbo1Z35jZ+d9rsAUA3G3s76gXlqQseO1ap0OrYDjlWJgWmfqWacD+jN2cDILFN/Q+v DZvwZIDqeaoXQIPQ92YSfdeuxHf7zBoiQFn/hNqsxy/QH/sItyIQOtE5X6slj6BpjD9W 2UUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296855; x=1780901655; h=cc: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=hF0jxFy4fSGz+r6lDhFvr2i2eisffYkvRRILwCTwN+U=; b=cprw+sFhgpwn7xm71IBztn0F+R88gqW7cnl64CMLIxhymhC2zxM+TftSdtzsesWS4d G38Fubarz3kx2UxGwyPNJkyj/wECxioudxTAgeVTuCNxzQLMu3u/uJtYr0tsaCUXEV/2 t9x8R0aE3+wF1r3eLo5tS45jZxGYbpXa4bhkF09TWrtTy4+RmFqoEW7y7neWjflCiXzV LVjQxr6BHpy8HAV88XFD2xcX56JEt66CjpS6DFuBFC7P+4XpIwnGmNsrhtaK/w9f+GBI +69OycsbETHdN+mA96TmYRl576nrz1dNLeShe7D/Q7F/S+HXale9nrvBXCJhQLA4YyAy JeUQ== X-Forwarded-Encrypted: i=1; AFNElJ/IbR5OGwCRu8bt3faGDxQPrKjqWJl0OJ/jNF1qD3BmbISCQE+8w0Au8CgDVoJ28Au68HIlO7/zjceLJRQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxEiUNNF5vqwyGiAn02SxzQBDNpSzUyxK8J6YXvBJZ4iibVzKdC QxJ+u5XH4/UKvo00XZ1IvJFFF8P0ik0eiyINH6m4hPGSnEkrCUnRrV4oZvJuCRaQkJIexo2Hc9O lXXtsKr3FJg== X-Received: from dlee16.prod.google.com ([2002:a05:7022:6290:b0:136:3f5e:fe1c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:43:b0:136:6230:5834 with SMTP id a92af1059eb24-137d427a4bbmr4077235c88.31.1780296855115; Sun, 31 May 2026 23:54:15 -0700 (PDT) Date: Sun, 31 May 2026 23:53:50 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-2-irogers@google.com> Subject: [PATCH v10 01/18] perf env: Add perf_env__e_machine helper and use in perf_env__arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper that lazily computes the e_machine and falls back to EM_HOST. Use the perf_env's arch to compute the e_machine if available, using a binary search for efficiency while handling duplicate rules. Switch perf_env__arch to be derived from e_machine for consistency. To support 32-bit compat binaries on 64-bit hosts during dynamic local or live operations, unpopulated arch fallback paths query uname() at runtime to dynamically resolve the correct host e_machine, safely preventing bitness misclassification regressions. Update session and header to use the helper to safely record e_machine and flags without forcing premature thread scanning. Signed-off-by: Ian Rogers --- tools/perf/util/env.c | 300 ++++++++++++++++++++++++++++++++------ tools/perf/util/env.h | 2 + tools/perf/util/header.c | 32 ++-- tools/perf/util/session.c | 26 ++-- 4 files changed, 295 insertions(+), 65 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 20953ef7b9d8..23dcd7a108a1 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include "cpumap.h" +#include "dwarf-regs.h" #include "debug.h" #include "env.h" #include "util/header.h" #include "util/rwsem.h" #include +#include #include #include #include @@ -309,15 +311,27 @@ void perf_env__init(struct perf_env *env) =20 static void perf_env__init_kernel_mode(struct perf_env *env) { - const char *arch =3D perf_env__raw_arch(env); + const char *arch =3D env->arch; =20 - if (!strncmp(arch, "x86_64", 6) || !strncmp(arch, "aarch64", 7) || - !strncmp(arch, "arm64", 5) || !strncmp(arch, "mips64", 6) || - !strncmp(arch, "parisc64", 8) || !strncmp(arch, "riscv64", 7) || - !strncmp(arch, "s390x", 5) || !strncmp(arch, "sparc64", 7)) - env->kernel_is_64_bit =3D 1; - else - env->kernel_is_64_bit =3D 0; + if (!arch) { + static struct utsname uts =3D { .machine[0] =3D '\0', }; + + if (uts.machine[0] =3D=3D '\0') + uname(&uts); + if (uts.machine[0] !=3D '\0') + arch =3D uts.machine; + } + + if (arch) { + if (str_ends_with(arch, "64") || !strncmp(arch, "s390x", 5)) + env->kernel_is_64_bit =3D 1; + else + env->kernel_is_64_bit =3D 0; + return; + } + + /* Fallback if completely unresolvable (assume host-bitness) */ + env->kernel_is_64_bit =3D (sizeof(void *) =3D=3D 8) ? 1 : 0; } =20 int perf_env__kernel_is_64_bit(struct perf_env *env) @@ -588,51 +602,249 @@ void cpu_cache_level__free(struct cpu_cache_level *c= ache) zfree(&cache->size); } =20 +struct arch_to_e_machine { + const char *prefix; + uint16_t e_machine; +}; + /* - * Return architecture name in a normalized form. - * The conversion logic comes from the Makefile. + * A mapping from an arch prefix string to an ELF machine that can be used= in a + * bsearch. Some arch prefixes are shared an need additional processing as + * marked next to the architecture. The prefixes handle both perf's archit= ecture + * naming and those from uname. */ -static const char *normalize_arch(char *arch) -{ - if (!strcmp(arch, "x86_64")) - return "x86"; - if (arch[0] =3D=3D 'i' && arch[2] =3D=3D '8' && arch[3] =3D=3D '6') - return "x86"; - if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5)) - return "sparc"; - if (!strncmp(arch, "aarch64", 7) || !strncmp(arch, "arm64", 5)) - return "arm64"; - if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110")) - return "arm"; - if (!strncmp(arch, "s390", 4)) - return "s390"; - if (!strncmp(arch, "parisc", 6)) - return "parisc"; - if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3)) - return "powerpc"; - if (!strncmp(arch, "mips", 4)) - return "mips"; - if (!strncmp(arch, "sh", 2) && isdigit(arch[2])) - return "sh"; - if (!strncmp(arch, "loongarch", 9)) - return "loongarch"; - - return arch; +static const struct arch_to_e_machine prefix_to_e_machine[] =3D { + {"aarch64", EM_AARCH64}, + {"alpha", EM_ALPHA}, + {"arc", EM_ARC}, + {"arm", EM_ARM}, /* Check also for EM_AARCH64. */ + {"avr", EM_AVR}, /* Check also for EM_AVR32. */ + {"bfin", EM_BLACKFIN}, + {"blackfin", EM_BLACKFIN}, + {"cris", EM_CRIS}, + {"csky", EM_CSKY}, + {"hppa", EM_PARISC}, + {"i386", EM_386}, + {"i486", EM_386}, + {"i586", EM_386}, + {"i686", EM_386}, + {"loongarch", EM_LOONGARCH}, + {"m32r", EM_M32R}, + {"m68k", EM_68K}, + {"microblaze", EM_MICROBLAZE}, + {"mips", EM_MIPS}, + {"msp430", EM_MSP430}, + {"parisc", EM_PARISC}, + {"powerpc", EM_PPC}, /* Check also for EM_PPC64. */ + {"ppc", EM_PPC}, /* Check also for EM_PPC64. */ + {"riscv", EM_RISCV}, + {"s390", EM_S390}, + {"sa110", EM_ARM}, + {"sh", EM_SH}, + {"sparc", EM_SPARC}, /* Check also for EM_SPARCV9. */ + {"sun4u", EM_SPARC}, + {"x86", EM_X86_64}, /* Check also for EM_386. */ + {"xtensa", EM_XTENSA}, +}; + +static int compare_prefix(const void *key, const void *element) +{ + const char *search_key =3D key; + const struct arch_to_e_machine *map_element =3D element; + size_t prefix_len =3D strlen(map_element->prefix); + + return strncmp(search_key, map_element->prefix, prefix_len); +} + +static uint16_t perf_arch_to_e_machine(const char *perf_arch, int is_64_bi= t) +{ + /* Binary search for a matching prefix. */ + const struct arch_to_e_machine *result; + + if (!perf_arch) + return EM_HOST; + + result =3D bsearch(perf_arch, + prefix_to_e_machine, ARRAY_SIZE(prefix_to_e_machine), + sizeof(prefix_to_e_machine[0]), + compare_prefix); + + if (!result) { + pr_debug("Unknown perf arch for ELF machine mapping: %s\n", perf_arch); + return EM_NONE; + } + + /* + * Handle conflicting prefixes. If the is_64_bit is unknown (-1) then + * assume 64-bit. We can't use perf_env__kernel_is_64_bit as that + * depends on the arch string. + */ + switch (result->e_machine) { + case EM_ARM: + return !strcmp(perf_arch, "arm64") || !strcmp(perf_arch, "aarch64") ? EM= _AARCH64 : EM_ARM; + case EM_AVR: + return !strcmp(perf_arch, "avr32") ? EM_AVR32 : EM_AVR; + case EM_PPC: + if (is_64_bit =3D=3D 1) + return EM_PPC64; + if (is_64_bit =3D=3D 0) + return EM_PPC; + return strstarts(perf_arch, "ppc64") ? EM_PPC64 : EM_PPC; + case EM_SPARC: + if (is_64_bit =3D=3D 1) + return EM_SPARCV9; + if (is_64_bit =3D=3D 0) + return EM_SPARC; + return !strcmp(perf_arch, "sparc64") || !strcmp(perf_arch, "sun4u") ? EM= _SPARCV9 : EM_SPARC; + case EM_X86_64: + if (is_64_bit =3D=3D 1) + return EM_X86_64; + if (is_64_bit =3D=3D 0) + return EM_386; + return !strcmp(perf_arch, "x86_64") || !strcmp(perf_arch, "x86") ? EM_X8= 6_64 : EM_386; + default: + return result->e_machine; + } +} + +static const char *e_machine_to_perf_arch(uint16_t e_machine) +{ + /* + * Table for if either the perf arch string differs from uname or there + * are >1 ELF machine with the prefix. + */ + static const struct arch_to_e_machine extras[] =3D { + {"arm64", EM_AARCH64}, + {"avr32", EM_AVR32}, + {"powerpc", EM_PPC}, + {"powerpc", EM_PPC64}, + {"sparc", EM_SPARCV9}, + {"x86", EM_386}, + {"x86", EM_X86_64}, + {"none", EM_NONE}, + }; + + for (size_t i =3D 0; i < ARRAY_SIZE(extras); i++) { + if (extras[i].e_machine =3D=3D e_machine) + return extras[i].prefix; + } + + for (size_t i =3D 0; i < ARRAY_SIZE(prefix_to_e_machine); i++) { + if (prefix_to_e_machine[i].e_machine =3D=3D e_machine) + return prefix_to_e_machine[i].prefix; + + } + return "unknown"; +} + +uint16_t perf_env__e_machine_nocache(struct perf_env *env, uint32_t *e_fla= gs) +{ + uint16_t e_machine =3D EM_NONE; + const char *arch =3D NULL; + int is_64_bit =3D -1; + + if (e_flags) + *e_flags =3D 0; + + if (env) { + arch =3D env->arch; + is_64_bit =3D env->kernel_is_64_bit; + } + + if (!arch) { + static struct utsname uts =3D { .machine[0] =3D '\0', }; + + if (uts.machine[0] =3D=3D '\0') + uname(&uts); + if (uts.machine[0] !=3D '\0') + arch =3D uts.machine; + } + + e_machine =3D perf_arch_to_e_machine(arch, is_64_bit); + + if (e_flags) + *e_flags =3D (e_machine =3D=3D EM_HOST) ? EF_HOST : 0; + + return e_machine; +} + +uint16_t perf_env__e_machine(struct perf_env *env, uint32_t *e_flags) +{ + uint16_t e_machine; + uint32_t local_e_flags =3D 0; + + if (env && env->e_machine !=3D EM_NONE) { + if (e_flags) + *e_flags =3D env->e_flags; + + return env->e_machine; + } + e_machine =3D perf_env__e_machine_nocache(env, &local_e_flags); + /* + * Only cache the e_machine in perf_env if env->arch is not NULL. + * If env->arch is NULL, the e_machine is just a fallback to EM_HOST. + * Caching it permanently would prevent dynamic, more accurate + * thread-based session e_machine scanning later in + * perf_session__e_machine(). + */ + if (env && env->arch) { + env->e_machine =3D e_machine; + env->e_flags =3D local_e_flags; + } + if (e_flags) + *e_flags =3D local_e_flags; + + return e_machine; } =20 const char *perf_env__arch(struct perf_env *env) { - char *arch_name; + uint16_t e_machine; + const char *arch; =20 - if (!env || !env->arch) { /* Assume local operation */ + if (!env) { static struct utsname uts =3D { .machine[0] =3D '\0', }; - if (uts.machine[0] =3D=3D '\0' && uname(&uts) < 0) - return NULL; - arch_name =3D uts.machine; - } else - arch_name =3D env->arch; + uint16_t host_e_machine; + + if (uts.machine[0] =3D=3D '\0') + uname(&uts); + if (uts.machine[0] !=3D '\0') { + host_e_machine =3D perf_arch_to_e_machine(uts.machine, -1); + return e_machine_to_perf_arch(host_e_machine); + } + return e_machine_to_perf_arch(EM_HOST); + } + + if (env->arch) + return env->arch; =20 - return normalize_arch(arch_name); + /* + * Lazily compute/allocate arch. The e_machine may have been + * read from a data file and so may not be EM_HOST. + */ + e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); + arch =3D e_machine_to_perf_arch(e_machine); + + if (e_machine =3D=3D EM_RISCV && perf_env__kernel_is_64_bit(env) =3D=3D 1) + arch =3D "riscv64"; + else if (e_machine =3D=3D EM_MIPS && perf_env__kernel_is_64_bit(env) =3D= =3D 1) + arch =3D "mips64"; + else if (e_machine =3D=3D EM_PARISC && perf_env__kernel_is_64_bit(env) = =3D=3D 1) + arch =3D "parisc64"; + + /* + * Only cache the normalized arch string in env->arch if the + * e_machine was successfully resolved (i.e. not the unpopulated + * fallback to EM_HOST), allowing threads to dynamically indicate + * a better ELF machine type later. + */ + if (env && env->e_machine !=3D EM_NONE) + env->arch =3D strdup(arch); + /* + * Avoid potential crashes on the arch string if memory allocation in + * strdup fails and NULL were to be returned. + */ + return env->arch ?: arch; } =20 const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, i= nt err __maybe_unused) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 739d884fc236..bde192fd5be5 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -187,6 +187,8 @@ int perf_env__read_cpu_topology_map(struct perf_env *en= v); =20 void cpu_cache_level__free(struct cpu_cache_level *cache); =20 +uint16_t perf_env__e_machine_nocache(struct perf_env *env, uint32_t *e_fla= gs); +uint16_t perf_env__e_machine(struct perf_env *env, uint32_t *e_flags); const char *perf_env__arch(struct perf_env *env); const char *perf_env__arch_strerrno(struct perf_env *env, int err); arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch); diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 5b1fa1653d2a..220e7720fbdb 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -441,21 +441,25 @@ static int write_osrelease(struct feat_fd *ff, return do_write_string(ff, uts.release); } =20 -static int write_arch(struct feat_fd *ff, - struct evlist *evlist __maybe_unused) +static int write_arch(struct feat_fd *ff, struct evlist *evlist) { struct utsname uts; - int ret; + const char *arch =3D NULL; =20 - ret =3D uname(&uts); - if (ret < 0) - return -1; + if (evlist->session) + arch =3D perf_env__arch(perf_session__env(evlist->session)); + + if (!arch) { + int ret =3D uname(&uts); =20 - return do_write_string(ff, uts.machine); + if (ret < 0) + return -1; + arch =3D uts.machine; + } + return do_write_string(ff, arch); } =20 -static int write_e_machine(struct feat_fd *ff, - struct evlist *evlist __maybe_unused) +static int write_e_machine(struct feat_fd *ff, struct evlist *evlist) { /* e_machine expanded from 16 to 32-bits for alignment. */ uint32_t e_flags; @@ -2841,10 +2845,18 @@ static int process_##__feat(struct feat_fd *ff, voi= d *data __maybe_unused) \ FEAT_PROCESS_STR_FUN(hostname, hostname); FEAT_PROCESS_STR_FUN(osrelease, os_release); FEAT_PROCESS_STR_FUN(version, version); -FEAT_PROCESS_STR_FUN(arch, arch); FEAT_PROCESS_STR_FUN(cpudesc, cpu_desc); FEAT_PROCESS_STR_FUN(cpuid, cpuid); =20 +static int process_arch(struct feat_fd *ff, void *data __maybe_unused) +{ + free(ff->ph->env.arch); + ff->ph->env.arch =3D do_read_string(ff); + if (!ff->ph->env.arch) + return -ENOMEM; + return 0; +} + static int process_e_machine(struct feat_fd *ff, void *data __maybe_unused) { int ret; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index e2e821b77766..4791c052aebe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -4080,14 +4080,19 @@ uint16_t perf_session__e_machine(struct perf_sessio= n *session, uint32_t *e_flags return EM_HOST; } =20 + /* + * Is the env caching an e_machine? If not we want to compute from the + * more accurate threads. + */ env =3D perf_session__env(session); - if (env && env->e_machine !=3D EM_NONE) { - if (e_flags) - *e_flags =3D env->e_flags; - - return env->e_machine; - } + if (env && env->e_machine !=3D EM_NONE) + return perf_env__e_machine(env, e_flags); =20 + /* + * Compute from threads, note this is more accurate than + * perf_env__e_machine that falls back on EM_HOST and doesn't consider + * mixed 32-bit and 64-bit threads. + */ machines__for_each_thread(&session->machines, perf_session__e_machine_cb, &args); @@ -4105,10 +4110,9 @@ uint16_t perf_session__e_machine(struct perf_session= *session, uint32_t *e_flags =20 /* * Couldn't determine from the perf_env or current set of - * threads. Default to the host. + * threads. Potentially use logic that uses the arch string otherwise + * default to the host. Don't cache in the perf_env in case later + * threads indicate a better ELF machine type. */ - if (e_flags) - *e_flags =3D EF_HOST; - - return EM_HOST; + return perf_env__e_machine_nocache(env, e_flags); } --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:12 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 2DC15380FD4 for ; Mon, 1 Jun 2026 06:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296862; cv=none; b=rFX95eYouiwcS7X4ACXamou/bzSOK5q/Lkwnp8Tt6JbHJMninbRTElLDcRgDMitV4LcD5714+HNPukeM1ZRCLlrj8jzUKLrawNDLeHzKZ6euJLQD0tJVI3O+xXFmBjv+b+0DTv03eCz+GJXm8ltamdTkbssj+LMgh12Lj7mRTQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296862; c=relaxed/simple; bh=48MTwwxutkWuwNYEB0j4Z6toHbvDR1lbDWS17/rbrec=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OqvITE5zWJi+0DX7atX+6Dy5KAjWv8yrOK+Mc4v9pEXG4FmQ2vItFw0e42NGHNoVvxsyRRLYgcNvbzGMSTOkzS1pebABnu9WlVHOHjwJ6+pOEACn/qA6W0YaXPOqkwkPtYwcf+lKMvhQdRPwK7lRiCsPnsZl9azrOltySE0Vfqw= 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=HciQggJV; arc=none smtp.client-ip=74.125.82.73 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="HciQggJV" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1353bfdbf99so2240932c88.0 for ; Sun, 31 May 2026 23:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296857; x=1780901657; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lWCzjKtw1MKO6Le8nWoWhxrpaG2iRVskYU2y07AMluU=; b=HciQggJVGiXWSl9v+0WyfxUV7LCm9U7GimZCwrPDDRb6cBi0bh5buRZHFTtqrZinil NWuca02MbkMxxJtYq6r1VTW9BEGUz12KM2DvP1/Uv9agW47B9/W2e/DKvTVSbCWbhuKB 0amqOUeSNR7NIDYUAFM6MCKj4yBw1XUFKXqV4r5YoUN6k0/s7mo+U7rYmUNLTXfFM70Z 3BezFzaUcugIQWUI75XiFHObl9ZNs/qreC7FhJwc8sf/9/l+qMT+81yJ4kO99TJvDlX0 dic0D7NIVaoCh292Oe7Kj/bzriX1ZRLr1HW1IgnAWOplHFeXggYU9NhZuOWki0t2ABzt e7Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296857; x=1780901657; h=cc: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=lWCzjKtw1MKO6Le8nWoWhxrpaG2iRVskYU2y07AMluU=; b=aDKTMTEnUjSDIeGZHMsoHMvgW60LzWrepkmBItrsxxJ9Bwe3PXDwKjLBLNuWxamOm1 KbriJ8VUfHS40+MBGdHY+wxhwMFld9Iv2Mo/hgH5padJz9YN9HjRhY9+YGeQydnWahWo LVl1krrgZzEI/8e7KqJS/9G5//qsgosXYxW52rz51/xYk2gEGZqZsEIEycwlZpJMxIh8 wsTSB3amC3nuoFofiNtiAJcUpUZW0qUqiVOTPvTCY903wmOuw+srDDQ0SBxrTVVxc8nE NRhEsOpdXZBVLgpbl4dv3sDo2VdZ2Os9BoXIZUMYKtLgVC3LcIRnQgIOJiBUHOJ8tJS2 4Z+Q== X-Forwarded-Encrypted: i=1; AFNElJ8omGMiNeZry7O86M+Fm/txWy+kXHmmtAtwvuUq7fRk/CpirHL+AVRKXbC8DKTNH9qgya0aZmmcGgkzKtI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp0K3MQf10vZIsKR9ge1Fkt7v66Tc9ktpO2grFLpeNN26K0Cmp Se2HxFHV82hxNRSXtG7WU2aCobfj338RW6/qEZ+zCrvDClNFIweJFebo68T58vGPOHur1yqBE0Q FoBpFqXM4ig== X-Received: from dlbpt1.prod.google.com ([2002:a05:7022:e801:b0:136:ac69:b0eb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f414:b0:11b:f056:a19b with SMTP id a92af1059eb24-137d4012ceemr3520584c88.18.1780296856820; Sun, 31 May 2026 23:54:16 -0700 (PDT) Date: Sun, 31 May 2026 23:53:51 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-3-irogers@google.com> Subject: [PATCH v10 02/18] perf tests topology: Switch env->arch use to env->e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some arch string comparisons weren't normalized. Avoid potential issues with normalized names vs uname values by swtiching to using the e_machine. Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index f54502ebef4b..bd7b859dea66 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -11,6 +11,7 @@ #include "pmus.h" #include "target.h" #include +#include "dwarf-regs.h" =20 #define TEMPL "/tmp/perf-test-XXXXXX" #define DATA_SIZE 10 @@ -74,6 +75,7 @@ static int check_cpu_topology(char *path, struct perf_cpu= _map *map) struct aggr_cpu_id id; struct perf_cpu cpu; struct perf_env *env; + uint16_t e_machine; =20 session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); @@ -101,7 +103,9 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) * condition is true (see do_core_id_test in header.c). So always * run this test on those platforms. */ - if (!env->cpu && strncmp(env->arch, "s390", 4) && strncmp(env->arch, "aar= ch64", 7)) + e_machine =3D perf_env__e_machine(env, NULL); + + if (!env->cpu && e_machine !=3D EM_S390 && e_machine !=3D EM_AARCH64) return TEST_SKIP; =20 /* @@ -110,7 +114,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) * physical_package_id will be set to -1. Hence skip this * test if physical_package_id returns -1 for cpu from perf_cpu_map. */ - if (!strncmp(env->arch, "ppc64le", 7)) { + if (e_machine =3D=3D EM_PPC64) { if (cpu__get_socket_id(perf_cpu_map__cpu(map, 0)) =3D=3D -1) return TEST_SKIP; } --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:12 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 2E1463822B7 for ; Mon, 1 Jun 2026 06:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296864; cv=none; b=CAMSNsMEYHlS3YCLL918DwXOcRKaq+GBzebU5iZBcJLtR/ErXdKkc8FMGk9aAunpaX6H1nsuFiqLBLp75kDg8pi4gLkiDUC8X//MvaTDUuijo8lE+HrSolzArFYBdHwu1V4QEjSvIACOJXKzCSJNZN1d2Ordhn9sxBYtEmEL4pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296864; c=relaxed/simple; bh=xiNyuixfvZSVBPpWnPyAbuM4RcR6DKqp5rCTPFn5Vr8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=J8Vbpx7tmYpc1v4RvxHZzZ7KYL6b1YZwp3lm4E4Ch3z3AJdBaAc7iOMRm1c1VevRrwVzIU4Gx95AlZbR0em9Ak94GjIKqsjSJVeP1FJU00GErHCKLUpOuV7HDWXt0CzMIUaSQp4zAbOZx7oqAouMDWLUN+53sKgAUhSbiiw02Tc= 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=LtJRf6zM; arc=none smtp.client-ip=74.125.82.73 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="LtJRf6zM" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137dd516985so1655542c88.1 for ; Sun, 31 May 2026 23:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296859; x=1780901659; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=H+Hx7srfn40If55DPatzqKalqdjucGxcj8cFUkFjYzg=; b=LtJRf6zMD2DwMAXruvGjkYK3URz42NF1ypqPanTZw18vKLHpY7C91oqTXSRwKi9crs nOUW+8CxLfltkjeRXBaFIavWVOfvbfPvMs52sh9ApPbcogN3rm6AuQhx+AY/NYYd58ga cj91jW8pNzJvgJwEup+RQ2X8LG/gUp2ihNJkecAX96lBSrJzfmLaDF/f0MsWUCqhSj9i sfwW6aU8cWNApaRtRxJttGzTXSAnynXfPmxnj3cUpDl0eQRkLzIg9aVSI1+XvwKx4gIY 7m5tRwoxpgDD3c//OjMrS09hBsfzLf0PqjbhyBI7ih92yqzAh17mCyXjbrS8hIn3UNMC NsrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296859; x=1780901659; h=cc: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=H+Hx7srfn40If55DPatzqKalqdjucGxcj8cFUkFjYzg=; b=YbTtMizQ99HDUELXxYlndfqrHHm5D9QCrnu4bIfBwEmCfKfTK51ShJMltU3ebNdi04 udkRQm1jVaWxgEQqSeSeOk9RNxzdh2AVyKIVwLk6JxV0aiFpwiOVnwEKn/xORSfuoj5Z stSZL0QqLDwZnnbRnp6ofXCwu7XoAUYCbs6DOlo+wCEMlOO2ozlQrlIo1cZzlUPF4OWE 6C1ITwxYYTSaXAJl/RnExb+GjlFlEHW781LRCTisAw02ZKIpURzoVoO7vSE+BiMy8vBg yO6JSmrrIuLU7WmhMyVPcVRwdaOzGLEtKAV72rs1/hhNUSF4gAQGT1QDqwN2ydAepDR3 bigw== X-Forwarded-Encrypted: i=1; AFNElJ+JtWjQOVhLfg1STYyVMtbLDS9cwigvv2lhOXWQSsp/BLu56O7lDg+n7RgsuqEl8oVSu292gnx8Hie1AeQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2I4hivWdOSrsgOxKEMPO2q9jHC7L0NbZTP5AA5JWjBJE/M1vI fOv3piDLq4PVD2mUC66sijmXlbRMKQ1O+Tx92wniDfqFx1rZ6Ggd+yJbnHRIHO5vr2Z8KlrglUm JwF0sSy6Yuw== X-Received: from dlkk5.prod.google.com ([2002:a05:7022:6085:b0:135:dc3d:ab61]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ef18:b0:134:a710:d908 with SMTP id a92af1059eb24-137d3e03856mr4145694c88.13.1780296858971; Sun, 31 May 2026 23:54:18 -0700 (PDT) Date: Sun, 31 May 2026 23:53:52 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-4-irogers@google.com> Subject: [PATCH v10 03/18] perf env, dso, thread: Add _endian variants for e_machine helpers From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_arch_is_big_endian(), dso__read_e_machine_endian(), dso__e_machine_endian(), and thread__e_machine_endian() to support bi-endianness and cross-architecture analysis without breaking the existing API. These helpers allow querying the absolute endianness of a DSO or thread, which is required for tools like Capstone that need to set the correct disassembly mode. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 19 +++++++++----- tools/perf/util/dso.h | 14 +++++++++-- tools/perf/util/env.c | 16 ++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/thread.c | 54 ++++++++++++++++++++++++++++++---------- tools/perf/util/thread.h | 23 ++++++++++++++++- 6 files changed, 105 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index b791e1b6b2cf..7dced896c64e 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1220,7 +1220,8 @@ static enum dso_swap_type dso_swap_type__from_elf_dat= a(unsigned char eidata) } =20 /* Reads e_machine from fd, optionally caching data in dso. */ -uint16_t dso__read_e_machine(struct dso *optional_dso, int fd, uint32_t *e= _flags) +uint16_t dso__read_e_machine_endian(struct dso *optional_dso, int fd, uint= 32_t *e_flags, + bool *is_big_endian) { uint16_t e_machine =3D EM_NONE; unsigned char e_ident[EI_NIDENT]; @@ -1250,6 +1251,9 @@ uint16_t dso__read_e_machine(struct dso *optional_dso= , int fd, uint32_t *e_flags if (swap_type =3D=3D DSO_SWAP__UNSET) return EM_NONE; // Bad ELF data encoding. =20 + if (is_big_endian) + *is_big_endian =3D (e_ident[EI_DATA] =3D=3D ELFDATA2MSB); + /* Cache the need for swapping. */ if (optional_dso) { assert(dso__needs_swap(optional_dso) =3D=3D DSO_SWAP__UNSET || @@ -1288,7 +1292,8 @@ uint16_t dso__read_e_machine(struct dso *optional_dso= , int fd, uint32_t *e_flags return e_machine; } =20 -uint16_t dso__e_machine(struct dso *dso, struct machine *machine, uint32_t= *e_flags) +uint16_t dso__e_machine_endian(struct dso *dso, struct machine *machine, u= int32_t *e_flags, + bool *is_big_endian) { uint16_t e_machine =3D EM_NONE; int fd; @@ -1308,9 +1313,11 @@ uint16_t dso__e_machine(struct dso *dso, struct mach= ine *machine, uint32_t *e_fl case DSO_BINARY_TYPE__BPF_IMAGE: case DSO_BINARY_TYPE__OOL: case DSO_BINARY_TYPE__JAVA_JIT: - if (e_flags) - *e_flags =3D EF_HOST; - return EM_HOST; + if (is_big_endian) { + *is_big_endian =3D perf_arch_is_big_endian( + machine && machine->env ? perf_env__arch(machine->env) : NULL); + } + return perf_env__e_machine(machine ? machine->env : NULL, e_flags); case DSO_BINARY_TYPE__DEBUGLINK: case DSO_BINARY_TYPE__BUILD_ID_CACHE: case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: @@ -1338,7 +1345,7 @@ uint16_t dso__e_machine(struct dso *dso, struct machi= ne *machine, uint32_t *e_fl try_to_open_dso(dso, machine); fd =3D dso__data(dso)->fd; if (fd >=3D 0) - e_machine =3D dso__read_e_machine(dso, fd, e_flags); + e_machine =3D dso__read_e_machine_endian(dso, fd, e_flags, is_big_endian= ); else if (e_flags) *e_flags =3D 0; =20 diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index ede691e9a249..2916b954a804 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -866,8 +866,18 @@ int dso__data_file_size(struct dso *dso, struct machin= e *machine); off_t dso__data_size(struct dso *dso, struct machine *machine); ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size); -uint16_t dso__read_e_machine(struct dso *optional_dso, int fd, uint32_t *e= _flags); -uint16_t dso__e_machine(struct dso *dso, struct machine *machine, uint32_t= *e_flags); +uint16_t dso__read_e_machine_endian(struct dso *optional_dso, int fd, uint= 32_t *e_flags, + bool *is_big_endian); +static inline uint16_t dso__read_e_machine(struct dso *optional_dso, int f= d, uint32_t *e_flags) +{ + return dso__read_e_machine_endian(optional_dso, fd, e_flags, NULL); +} +uint16_t dso__e_machine_endian(struct dso *dso, struct machine *machine, u= int32_t *e_flags, + bool *is_big_endian); +static inline uint16_t dso__e_machine(struct dso *dso, struct machine *mac= hine, uint32_t *e_flags) +{ + return dso__e_machine_endian(dso, machine, e_flags, NULL); +} ssize_t dso__data_read_addr(struct dso *dso, struct map *map, struct machine *machine, u64 addr, u8 *data, ssize_t size); diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 23dcd7a108a1..b8331d4dd347 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -342,6 +342,22 @@ int perf_env__kernel_is_64_bit(struct perf_env *env) return env->kernel_is_64_bit; } =20 +bool perf_arch_is_big_endian(const char *arch) +{ + if (!arch) + return __BYTE_ORDER__ =3D=3D __ORDER_BIG_ENDIAN__; + + if (str_ends_with(arch, "_be") || !strcmp(arch, "sparc") || !strcmp(arch,= "sparc64") || + !strcmp(arch, "s390") || !strcmp(arch, "s390x") || !strcmp(arch, "pow= erpc") || + !strcmp(arch, "ppc") || !strcmp(arch, "ppc64") || + !strcmp(arch, "mips") || !strcmp(arch, "mips64") || !strcmp(arch, "pa= risc") || + !strcmp(arch, "parisc64") || !strcmp(arch, "m68k") || + !strcmp(arch, "armeb") || !strcmp(arch, "mipseb") || !strcmp(arch, "m= ips64eb")) + return true; + + return false; +} + int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []) { int i; diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index bde192fd5be5..dd9907dbc345 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -175,6 +175,7 @@ void free_cpu_domain_info(struct cpu_domain_map **cd_ma= p, u32 schedstat_version, void perf_env__exit(struct perf_env *env); =20 int perf_env__kernel_is_64_bit(struct perf_env *env); +bool perf_arch_is_big_endian(const char *arch); =20 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []); =20 diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index aac9cb75dcf4..23a0775a8260 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -56,6 +56,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) thread__set_cpu(thread, -1); thread__set_guest_cpu(thread, -1); thread__set_e_machine(thread, EM_NONE); + thread__set_e_is_big_endian(thread, false); thread__set_lbr_stitch_enable(thread, false); INIT_LIST_HEAD(thread__namespaces_list(thread)); INIT_LIST_HEAD(thread__comm_list(thread)); @@ -429,7 +430,7 @@ void thread__find_cpumode_addr_location(struct thread *= thread, u64 addr, } } =20 -static uint16_t read_proc_e_machine_for_pid(pid_t pid, uint32_t *e_flags) +static uint16_t read_proc_e_machine_for_pid(pid_t pid, uint32_t *e_flags, = bool *is_big_endian) { char path[6 /* "/proc/" */ + 11 /* max length of pid */ + 5 /* "/exe\0" *= /]; int fd; @@ -438,7 +439,8 @@ static uint16_t read_proc_e_machine_for_pid(pid_t pid, = uint32_t *e_flags) snprintf(path, sizeof(path), "/proc/%d/exe", pid); fd =3D open(path, O_RDONLY); if (fd >=3D 0) { - e_machine =3D dso__read_e_machine(/*optional_dso=3D*/NULL, fd, e_flags); + e_machine =3D dso__read_e_machine_endian(/*optional_dso=3D*/NULL, fd, e_= flags, + is_big_endian); close(fd); } return e_machine; @@ -448,6 +450,7 @@ struct thread__e_machine_callback_args { struct machine *machine; uint32_t e_flags; uint16_t e_machine; + bool is_big_endian; }; =20 static int thread__e_machine_callback(struct map *map, void *_args) @@ -458,24 +461,36 @@ static int thread__e_machine_callback(struct map *map= , void *_args) if (!dso) return 0; // No dso, continue search. =20 - args->e_machine =3D dso__e_machine(dso, args->machine, &args->e_flags); + args->e_machine =3D + dso__e_machine_endian(dso, args->machine, &args->e_flags, &args->is_big_= endian); return args->e_machine !=3D EM_NONE ? 1 /* stop search */ : 0 /* continue= search */; } =20 -uint16_t thread__e_machine(struct thread *thread, struct machine *machine,= uint32_t *e_flags) +uint16_t thread__e_machine_endian(struct thread *thread, struct machine *m= achine, uint32_t *e_flags, + bool *is_big_endian) { pid_t tid, pid; - uint16_t e_machine =3D RC_CHK_ACCESS(thread)->e_machine; + uint16_t e_machine; uint32_t local_e_flags =3D 0; - struct thread__e_machine_callback_args args =3D { - .machine =3D machine, - .e_flags =3D 0, - .e_machine =3D EM_NONE, - }; + struct thread__e_machine_callback_args args; + + if (!thread) { + if (is_big_endian) + *is_big_endian =3D perf_arch_is_big_endian(NULL); + return perf_env__e_machine(machine ? machine->env : NULL, e_flags); + } + + e_machine =3D RC_CHK_ACCESS(thread)->e_machine; + args.machine =3D machine; + args.e_flags =3D 0; + args.e_machine =3D EM_NONE; + args.is_big_endian =3D false; =20 if (e_machine !=3D EM_NONE) { if (e_flags) *e_flags =3D thread__e_flags(thread); + if (is_big_endian) + *is_big_endian =3D thread__e_is_big_endian(thread); return e_machine; } =20 @@ -483,6 +498,7 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 struct maps *maps =3D thread__maps(thread); =20 machine =3D maps__machine(maps); + args.machine =3D machine; } tid =3D thread__tid(thread); pid =3D thread__pid(thread); @@ -490,7 +506,8 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 struct thread *parent =3D machine__findnew_thread(machine, pid, pid); =20 if (parent) { - e_machine =3D thread__e_machine(parent, machine, &local_e_flags); + e_machine =3D thread__e_machine_endian(parent, machine, &local_e_flags, + &args.is_big_endian); thread__put(parent); goto out; } @@ -515,16 +532,27 @@ uint16_t thread__e_machine(struct thread *thread, str= uct machine *machine, uint3 is_live =3D !!session->data; } /* Read from /proc/pid/exe if live. */ - if (is_live) - e_machine =3D read_proc_e_machine_for_pid(pid, &local_e_flags); + if (is_live) { + e_machine =3D read_proc_e_machine_for_pid(pid, &local_e_flags, + &args.is_big_endian); + } else if (machine && machine->env) { + /* Offline analysis: fallback to environment metadata. */ + e_machine =3D perf_env__e_machine(machine->env, &local_e_flags); + args.is_big_endian =3D perf_arch_is_big_endian(perf_env__arch(machine->= env)); + } } out: if (e_machine !=3D EM_NONE) { thread__set_e_machine(thread, e_machine); thread__set_e_flags(thread, local_e_flags); + thread__set_e_is_big_endian(thread, args.is_big_endian); + if (is_big_endian) + *is_big_endian =3D args.is_big_endian; } else { e_machine =3D EM_HOST; local_e_flags =3D EF_HOST; + if (is_big_endian) + *is_big_endian =3D (__BYTE_ORDER__ =3D=3D __ORDER_BIG_ENDIAN__); } if (e_flags) *e_flags =3D local_e_flags; diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index f5792d3e8a16..d82fce8173ae 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -69,6 +69,11 @@ DECLARE_RC_STRUCT(thread) { * computed. */ uint16_t e_machine; + /** + * @e_is_big_endian: True if the ELF architecture of the thread is big en= dian. + * Valid if e_machine !=3D EM_NONE. + */ + bool e_is_big_endian; /* LBR call stack stitch */ bool lbr_stitch_enable; struct lbr_stitch *lbr_stitch; @@ -311,7 +316,13 @@ static inline void thread__set_filter_entry_depth(stru= ct thread *thread, int dep RC_CHK_ACCESS(thread)->filter_entry_depth =3D depth; } =20 -uint16_t thread__e_machine(struct thread *thread, struct machine *machine,= uint32_t *e_flags); +uint16_t thread__e_machine_endian(struct thread *thread, struct machine *m= achine, uint32_t *e_flags, + bool *is_big_endian); +static inline uint16_t thread__e_machine(struct thread *thread, struct mac= hine *machine, + uint32_t *e_flags) +{ + return thread__e_machine_endian(thread, machine, e_flags, NULL); +} =20 static inline void thread__set_e_machine(struct thread *thread, uint16_t e= _machine) { @@ -328,6 +339,16 @@ static inline void thread__set_e_flags(struct thread *= thread, uint32_t e_flags) RC_CHK_ACCESS(thread)->e_flags =3D e_flags; } =20 +static inline bool thread__e_is_big_endian(const struct thread *thread) +{ + return RC_CHK_ACCESS(thread)->e_is_big_endian; +} + +static inline void thread__set_e_is_big_endian(struct thread *thread, bool= is_big_endian) +{ + RC_CHK_ACCESS(thread)->e_is_big_endian =3D is_big_endian; +} + =20 static inline bool thread__lbr_stitch_enable(const struct thread *thread) { --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:12 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 5540638238C for ; Mon, 1 Jun 2026 06:54:22 +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=1780296867; cv=none; b=QVkX3HvgcEg3r4Pop7C23+qmLfHOVcbVilxVKYnEYM2hV1SEx/2PxqCQeYPC2GP4aitSdgqD7pSocklSGX8eIvzCA/5Zy6++rfr5tXiDtPNNsdZz3gZv2WCk/MZfK4bqeiBE9Vw4UnvX/zuA0IpdBas1M72rCzsBu01IC3W2zt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296867; c=relaxed/simple; bh=2rdPbvONqK6vO/TG1IXQmWjlio2E2XNJcW9eEuwEU04=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NIPJpwD/UKoKUQoP3ZHXGhw2Yol1/Je4ec2PaR7ndjDJzfAUoJJ2vpZEB7TzlI7/WhjoA3SNXJH+9DkZ3iduglTuE0GOtc3a+mAG1Lp0pAqAByks6PQaYIKTYdqBbxLrMDn4dCctnB0K92Ew0JIXV5EKvh0jTFy8KOSeaW/OMIg= 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=FOCOLm6k; 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="FOCOLm6k" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304d2447962so2621694eec.0 for ; Sun, 31 May 2026 23:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296861; x=1780901661; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xtZI7+G+AMAkreQGK5BUkiZ7KHz12ldSV3zxkUlfOB8=; b=FOCOLm6kGK/5yiFfYQ2/3Gk7T6AsD83KFHMP70+rd/WLFYbnqhKwwhxenwyCYpLsjB xW3H8wUYQHGh/VcTdLCRbbtccmA58aSZ5J0nM52u69qMUWq3Odu1M0VovyIF6b9AQahv yKymTGb9CE0tZlCggallJqJkh23uOXbPrzPb4GeCjOXW/UYbRl4dW4IPepu4h2Y5frlX dJ+e212mReK93afsaTntXuZurZb7Ial33PXBxA+7r0Ndlhw+BKiXQFcPJ2h7PTZKgi/S DVLGzhaJ4QLFw3Iqwb6qa/0vQ5C63TuPesyCnWsVNsaXDIwGipBTotsz4Sh2kZFMduaR tAkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296861; x=1780901661; h=cc: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=xtZI7+G+AMAkreQGK5BUkiZ7KHz12ldSV3zxkUlfOB8=; b=s/1w1B2p7I/C/wbq5QgxWOvE7TOHpiCtIe1fqQN+l7sii/Fz3sWQTD8rQSiMDi+WOS IUdhcWbqGTph5QJMW3GpJd6DKltEwIKSiJjTraoZbHUbHhXlwfn/QIwneOxqKzbDEnBP z+JrhSKnwfMFIPSeII8jDXfEOfpZPkiFlnKUpadl6vPgGLmo13uKjngmZ/Ut/6DKHyR6 pGRzfrO857d0BdjtxKk7DWmSaa7hUVFPcE2P90A8bugtwF+2OJBjjdsBNeiYDAhzo1lF atGvsFZdBKv5mKLds592/E2illFPCxnkZoOtKITA8Jwc6Xs0uWb8De3Rs4qRPURjZbcS puyA== X-Forwarded-Encrypted: i=1; AFNElJ8ZN4xVgmovuBsVLt27NK4546vPyEHuesGCf147+4iqLVIpXr+uEypWqSak+co5ymJT61FJMpfSzMUNFIE=@vger.kernel.org X-Gm-Message-State: AOJu0YzPunNdP37girL9MVfVh+XAANpCOvfsuOWhDwbiYm30I89FX26G 3ZNSjaQtos0S7NXtxesNd5EC80/hpVk0JDasfPlHgMUiQqaUoXACCgjDqzScytHQ4fGebe9dtoJ 7AZHpa0I9Mg== X-Received: from dlbsi14.prod.google.com ([2002:a05:7022:b88e:b0:12c:3dfa:518e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6b86:b0:12c:15ce:a71b with SMTP id a92af1059eb24-137aeba0f63mr4425425c88.25.1780296860978; Sun, 31 May 2026 23:54:20 -0700 (PDT) Date: Sun, 31 May 2026 23:53:53 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-5-irogers@google.com> Subject: [PATCH v10 04/18] perf capstone: Determine architecture from e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid the use of arch string that is imprecise and use the e_machine. Do more e_machine to capstone machine translations adding MIPS and RISCV. Remove unnecessary maybe_unused annotations. Signed-off-by: Ian Rogers --- tools/perf/util/capstone.c | 132 ++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 44 deletions(-) diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index 25cf6e15ec27..065b5d4d448a 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -1,7 +1,19 @@ // SPDX-License-Identifier: GPL-2.0 #include "capstone.h" -#include "annotate.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include + #include "addr_location.h" +#include "annotate.h" #include "debug.h" #include "disasm.h" #include "dso.h" @@ -11,13 +23,6 @@ #include "print_insn.h" #include "symbol.h" #include "thread.h" -#include -#include -#include -#include -#include - -#include =20 #ifdef LIBCAPSTONE_DLOPEN static void *perf_cs_dll_handle(void) @@ -137,37 +142,70 @@ static enum cs_err perf_cs_close(csh *handle) #endif } =20 -static int capstone_init(struct machine *machine, csh *cs_handle, bool is6= 4, +static bool e_machine_to_capstone(uint16_t e_machine, bool is64, bool is_b= ig_endian, + enum cs_arch *arch, enum cs_mode *mode) +{ + *mode =3D is_big_endian ? CS_MODE_BIG_ENDIAN : CS_MODE_LITTLE_ENDIAN; + + switch (e_machine) { + case EM_X86_64: + case EM_386: + *arch =3D CS_ARCH_X86; + *mode |=3D is64 ? CS_MODE_64 : CS_MODE_32; + return true; + case EM_AARCH64: + *arch =3D CS_ARCH_ARM64; + *mode |=3D CS_MODE_ARM; + return true; + case EM_ARM: + *arch =3D CS_ARCH_ARM; + *mode |=3D CS_MODE_ARM | CS_MODE_V8; + return true; + case EM_S390: + *arch =3D CS_ARCH_SYSZ; + return true; + case EM_MIPS: + *arch =3D CS_ARCH_MIPS; + *mode |=3D is64 ? CS_MODE_MIPS64 : CS_MODE_MIPS32; + return true; + case EM_PPC: + *arch =3D CS_ARCH_PPC; + return true; + case EM_PPC64: + *arch =3D CS_ARCH_PPC; + *mode |=3D CS_MODE_64; + return true; + case EM_SPARC: + *arch =3D CS_ARCH_SPARC; + return true; + case EM_SPARCV9: + *arch =3D CS_ARCH_SPARC; + *mode |=3D CS_MODE_V9; + return true; + case EM_RISCV: + *arch =3D CS_ARCH_RISCV; + *mode |=3D is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32; + return true; + default: + return false; + } +} + +static int capstone_init(uint16_t e_machine, csh *cs_handle, bool is64, bo= ol is_big_endian, bool disassembler_style) { enum cs_arch arch; enum cs_mode mode; =20 - if (machine__is(machine, "x86_64") && is64) { - arch =3D CS_ARCH_X86; - mode =3D CS_MODE_64; - } else if (machine__normalized_is(machine, "x86")) { - arch =3D CS_ARCH_X86; - mode =3D CS_MODE_32; - } else if (machine__normalized_is(machine, "arm64")) { - arch =3D CS_ARCH_ARM64; - mode =3D CS_MODE_ARM; - } else if (machine__normalized_is(machine, "arm")) { - arch =3D CS_ARCH_ARM; - mode =3D CS_MODE_ARM + CS_MODE_V8; - } else if (machine__normalized_is(machine, "s390")) { - arch =3D CS_ARCH_SYSZ; - mode =3D CS_MODE_BIG_ENDIAN; - } else { + if (!e_machine_to_capstone(e_machine, is64, is_big_endian, &arch, &mode)) return -1; - } =20 if (perf_cs_open(arch, mode, cs_handle) !=3D CS_ERR_OK) { pr_warning_once("cs_open failed\n"); return -1; } =20 - if (machine__normalized_is(machine, "x86")) { + if (arch =3D=3D CS_ARCH_X86) { /* * In case of using capstone_init while symbol__disassemble * setting CS_OPT_SYNTAX_ATT depends if disassembler_style opts @@ -211,29 +249,28 @@ static size_t print_insn_x86(struct thread *thread, u= 8 cpumode, struct cs_insn * return printed; } =20 - -ssize_t capstone__fprintf_insn_asm(struct machine *machine __maybe_unused, - struct thread *thread __maybe_unused, - u8 cpumode __maybe_unused, bool is64bit __maybe_unused, - const uint8_t *code __maybe_unused, - size_t code_size __maybe_unused, - uint64_t ip __maybe_unused, int *lenp __maybe_unused, - int print_opts __maybe_unused, FILE *fp __maybe_unused) +ssize_t capstone__fprintf_insn_asm(struct machine *machine, struct thread = *thread, u8 cpumode, + bool is64bit, const uint8_t *code, size_t code_size, uint64_t ip, + int *lenp, int print_opts, FILE *fp) { size_t printed; struct cs_insn *insn; csh cs_handle; size_t count; + bool is_big_endian =3D false; + uint16_t e_machine =3D thread__e_machine_endian(thread, machine, + /*e_flags=3D*/NULL, &is_big_endian); int ret; =20 /* TODO: Try to initiate capstone only once but need a proper place. */ - ret =3D capstone_init(machine, &cs_handle, is64bit, true); + ret =3D capstone_init(e_machine, &cs_handle, is64bit, is_big_endian, + /*disassembler_style=3D*/true); if (ret < 0) return ret; =20 count =3D perf_cs_disasm(cs_handle, code, code_size, ip, 1, &insn); if (count > 0) { - if (machine__normalized_is(machine, "x86")) + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386) printed =3D print_insn_x86(thread, cpumode, &insn[0], print_opts, fp); else printed =3D fprintf(fp, "%s %s", insn[0].mnemonic, insn[0].op_str); @@ -322,9 +359,8 @@ static int find_file_offset(u64 start, u64 len, u64 pgo= ff, void *arg) return 0; } =20 -int symbol__disassemble_capstone(const char *filename __maybe_unused, - struct symbol *sym __maybe_unused, - struct annotate_args *args __maybe_unused) +int symbol__disassemble_capstone(const char *filename, struct symbol *sym, + struct annotate_args *args) { struct annotation *notes =3D symbol__annotation(sym); struct map *map =3D args->ms->map; @@ -344,6 +380,8 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, char disasm_buf[512]; struct disasm_line *dl; bool disassembler_style =3D false; + uint16_t e_machine; + bool is_big_endian =3D false; =20 if (args->options->objdump_path) return -1; @@ -373,8 +411,10 @@ int symbol__disassemble_capstone(const char *filename = __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, - disassembler_style) < 0) + e_machine =3D thread__e_machine_endian(args->ms->thread, + /*machine=3D*/NULL, + /*e_flags=3D*/NULL, &is_big_endian); + if (capstone_init(e_machine, &handle, is_64bit, is_big_endian, disassembl= er_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -466,6 +506,8 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, struct disasm_line *dl; u32 *line; bool disassembler_style =3D false; + uint16_t e_machine; + bool is_big_endian =3D false; =20 if (args->options->objdump_path) return -1; @@ -484,8 +526,10 @@ int symbol__disassemble_capstone_powerpc(const char *f= ilename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, - disassembler_style) < 0) + e_machine =3D thread__e_machine_endian(args->ms->thread, + /*machine=3D*/NULL, + /*e_flags=3D*/NULL, &is_big_endian); + if (capstone_init(e_machine, &handle, is_64bit, is_big_endian, disassembl= er_style) < 0) goto err; =20 needs_cs_close =3D true; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 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 1C5BE380FFF for ; Mon, 1 Jun 2026 06:54:24 +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=1780296869; cv=none; b=j0NOpwwkMfgSkoX41O1JMujrskx8rjqVYMaysIhiKEGplDSWOUQHeysvIzBVTIiLBx09Bjg6Q8/aLOD6/Qe7XeHBH1BRBWh633UjARgZFMmAxlWx58jZ72K3KXVx0krclbxQ2xEExlu/UxajCAnOvm4Tng9rkxHbdIIKGSg5lho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296869; c=relaxed/simple; bh=ZWlpiDR5rqxF9BsLX33/iMtIeBO3s9wTTkZvmeMp3Jk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=adzfqu/I0TT3UO10lPB36ZrirDEmZ5D4Bx7gwVA8aRlFKfbMLLLXK1KnsPfdd89X+k1tKJaiUOt9So/c1JKs6HMH2EfSfE9tQPupSQl5Gie+3+Q7+33rUE+NzadI1JxC8p+szTiJa1aBvOjIJyJpKdrXkVs5kqViqcxWz53ZGgw= 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=Xf/m9KUT; 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="Xf/m9KUT" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304e7fc90b1so2962253eec.1 for ; Sun, 31 May 2026 23:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296864; x=1780901664; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+yvjTMhUQpFCMKyM3D3vzIS0OTnjZbpM9x7Pw9L2nmE=; b=Xf/m9KUTvmxY9NYEEXiyc6QZunhkHQSvk9NLjVHvD0ZCic1V48tSyDdXkoL6BvROk0 3WPuTUlnyUEBRPRJzE2AMYefINbZ2xZR2dZKKqnO2HsfbISaZo4OATWjR4u1ZAOa0AtK 86gFxj6SW4A+SsysSZr0GEZLHHrH2b8Gl/UfvokIw2cqzm0yZHxyoMUK6ykm2T/yGIuH esDXj+og5qbTtWPMTGVN6PZ87n1KroYlEWk2PYVGMD6/srZmq+FV88WzmXngUF4Otw7W grF8zNj5ilnBAH6GWMxhsWbycicf2x4P8MYjUhcAhEIYte6h6F1LixKB5oYxp0EbDEMD mS3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296864; x=1780901664; h=cc: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=+yvjTMhUQpFCMKyM3D3vzIS0OTnjZbpM9x7Pw9L2nmE=; b=g+L3//HzlBkLVZISlIasA3B5CjmNm5h+RV0E22wO1B7Mg9T5pMMnxbXN67JyXpnsau WLTTv6xlpaAKPIzXfvUt4pJ1pqdQR7hvmOmV5Y4+x2JM/0AFGHEPqKIbihGCXOWWM/eL Kf67enoVCLrEzk3GFnUv+sEQ3XgOV92jD2cP/0+awJJVcv15XL9pvuxetnTb9mZyHb8S 1W8q5b9lnL5Fy7wGWW+FBmdieU8MEZfW9P59Y9H8s79Ocrel0jS8ZOEIirvg5Dp+F6Nu YGLW29Dw3cuezmMK/qZiTmID1Cu1LBbQaK3uvSLEQsCQdTQJc+7yqLRCvhEI/2G8xRtt whFg== X-Forwarded-Encrypted: i=1; AFNElJ/z+frYS6AgmGZU+6uy6IV344UVPF4zpWkcjvFWS8UnsMfDbbN3F9kYXc80qjwsLUQKQW1R813peloRdBs=@vger.kernel.org X-Gm-Message-State: AOJu0YwTU+HxUvDjCuoNZy5uXWYsHtRpw0VwPkM/rbFuLw3PMZ5+zgjl 3CExG1teCeZEJJFURmVDQxwqfaS5nfOSrltWEA3KB+HZMamSLXhS5GgsnwQA1Rx2alFdXHcI/Kn VmS6VRbwoRA== X-Received: from dybcr38.prod.google.com ([2002:a05:7300:aca6:b0:2d9:8c75:b19e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:8605:b0:2dd:6937:79d5 with SMTP id 5a478bee46e88-304fa4c7c24mr4877511eec.8.1780296863813; Sun, 31 May 2026 23:54:23 -0700 (PDT) Date: Sun, 31 May 2026 23:53:54 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-6-irogers@google.com> Subject: [PATCH v10 05/18] perf print_insn: Use e_machine for fallback IP length check From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid string comparisons with perf_env arch, switch to using the more precise ELF machine. Sort header files and fix missing definitions. Signed-off-by: Ian Rogers --- tools/perf/util/print_insn.c | 23 ++++++++++++++--------- tools/perf/util/print_insn.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c index 02e6fbb8ca04..4068436f26ea 100644 --- a/tools/perf/util/print_insn.c +++ b/tools/perf/util/print_insn.c @@ -4,19 +4,24 @@ * * Author(s): Changbin Du */ +#include "print_insn.h" + #include -#include #include +#include + +#include + #include "capstone.h" #include "debug.h" +#include "dso.h" +#include "dump-insn.h" +#include "env.h" +#include "machine.h" +#include "map.h" #include "sample.h" #include "symbol.h" -#include "machine.h" #include "thread.h" -#include "print_insn.h" -#include "dump-insn.h" -#include "map.h" -#include "dso.h" =20 size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp) { @@ -33,13 +38,13 @@ size_t sample__fprintf_insn_raw(struct perf_sample *sam= ple, FILE *fp) static bool is64bitip(struct machine *machine, struct addr_location *al) { const struct dso *dso =3D al->map ? map__dso(al->map) : NULL; + uint16_t e_machine; =20 if (dso) return dso__is_64_bit(dso); =20 - return machine__is(machine, "x86_64") || - machine__normalized_is(machine, "arm64") || - machine__normalized_is(machine, "s390"); + e_machine =3D perf_env__e_machine(machine->env, /*e_flags=3D*/NULL); + return e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_AARCH64 || e_mac= hine =3D=3D EM_S390; } =20 ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u= 8 cpumode, diff --git a/tools/perf/util/print_insn.h b/tools/perf/util/print_insn.h index a54f7e858e49..cefa5c5f246e 100644 --- a/tools/perf/util/print_insn.h +++ b/tools/perf/util/print_insn.h @@ -5,6 +5,8 @@ #include #include =20 +#include + struct addr_location; struct machine; struct perf_insn; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 01443382392 for ; Mon, 1 Jun 2026 06:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296871; cv=none; b=Eg1gaRbXH9IFcnMnyxsyG4QwPidZSlVsOFD4c5CaMmnsbvOSHiPeNkbljU++MDQSZiEAOkmf0YOZ5dDObqSpdijLRkT0FhduW4uVfsQfsJnLFOan9CdiwQZq8gn1DCkJzwWe2NvC024CromJuqAdW0V1e+gvBj0WvQjHyytmhhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296871; c=relaxed/simple; bh=Y8Rf13zfpkxw1oj6pH0PZcyvU9uedOBfB/1NbOk7564=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C3zvdwmzOJBHQm3XBIDH1luwo4JfzBH6IgKM038QHkwJ2uAhHJQTRHllZpBGdBNWf/EjNeABve4oV3AnYqkXzpc5erGEkkdV5L6PR+vHchmxPKcPxxOsvQ2ExvHDDNNKgJxyeFcxM3YwOZxtJVNY2sME8W8wcTQTrfBgenmJ/XE= 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=UVFcsvRC; arc=none smtp.client-ip=74.125.82.74 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="UVFcsvRC" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-13537722193so12924200c88.0 for ; Sun, 31 May 2026 23:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296866; x=1780901666; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZR+AyCfqaiav/AMnhzc3hZKuPa0HeRBaZVNt7UCysX0=; b=UVFcsvRC4bpMHmjQUa4awCg2i+K4o2FDRrE87AWCve8xTEbNQN8yo7TlJ4RGMJwL+e uALFKkOYUEHtRd4f15CdbSQaMBwR/1MD2+yC9h1I3ZvyvOYvhk4LvdW/HK7U96mFlnf9 1lS98qOukRQrVcLQysL794axUwyysfmLJtrgUg43/xNgqwzHzQVGRA7oUWGhEqAjXn31 bf3YTMoJ6HQ9fR4FraKqAB7itzImKMMutsPDeGTdY8NM5gE+I2aJgxRs6iEHXj5ie8Uy I5N7/bxmjYhQsIIF2gVVG3vz6deECLaATNP/iw0rocKD6KCJI3tHncjpxUFO/0NdFZKL 3R9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296866; x=1780901666; h=cc: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=ZR+AyCfqaiav/AMnhzc3hZKuPa0HeRBaZVNt7UCysX0=; b=acJxNHDscKhUlx+9rv88suZuOMS1vtIOrqd/zAw53suzSsKWdDbo0L24op9g9mZtzO aUPCp0iO8Tz/FWcD1GMDnklBTiWYyM9IBIp5T17wxtIZuMyvVgTB/50TE5/nkznBPAzG f02RCC+YjJM49ZRoYHnwmgICET6Uh9E9oZ/88M6KLtvFhBJkIoG7bXXpFBUsL6fRBXn1 WMJx2dpfXSbH8qZ7q+1DSdmclBPjpF7nxQHWP8BEGF/iGXaRN40Eys41l3ktwcw3cjmF PzEd9z7J+aSSHs9pTpEzDdCZn26hmw1HY1vZfPEMmkFBuYlaFP/j23g6Lf4AK8zkmRTy 4YvQ== X-Forwarded-Encrypted: i=1; AFNElJ8oi6kl7wldR6fs6CmJzRdfnU6yMVUYxKTt2NGiKm4cWwK8LS7mUabPkRUaVERZ7eUjsGDsgfb+SB4nbv8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0qmpWoEK+I3L1sYFV2Ze5VuxoVCjeww5pvqGFjHrSqn6gLZba FoKbH5UMSNN+7wFueSk8EWOntqsJEKvwk895x5GehBhDLuWhrlt7rYJtkCqrIRlkVmO4RXFHurl 7QwIf8ftzOg== X-Received: from dlee26.prod.google.com ([2002:a05:7022:629a:b0:136:787c:b82c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2228:b0:136:e42d:2c2b with SMTP id a92af1059eb24-137d3f1367bmr4361266c88.17.1780296865875; Sun, 31 May 2026 23:54:25 -0700 (PDT) Date: Sun, 31 May 2026 23:53:55 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-7-irogers@google.com> Subject: [PATCH v10 06/18] perf symbol: Avoid use of machine__is From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using the ELF machine from the dso or running machine rather than the machine perf_env arch that may fall back on EM_HOST. This also avoids potentially imprecise string comparisons. Signed-off-by: Ian Rogers --- tools/perf/util/symbol.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 714b6e6048fa..2ce512f08a1d 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -851,6 +851,23 @@ static int maps__split_kallsyms_for_kcore(struct maps = *kmaps, struct dso *dso) return count; } =20 +static uint16_t machine_or_dso_e_machine(struct machine *machine, struct d= so *dso) +{ + uint16_t e_machine =3D EM_NONE; + /* DSO should be most accurate */ + if (dso) + e_machine =3D dso__e_machine(dso, machine, /*e_flags=3D*/NULL); + + if (e_machine !=3D EM_NONE) + return e_machine; + + /* Check the global environment next. */ + if (machine && machine->env && machine->env->e_machine !=3D EM_NONE) + return machine->env->e_machine; + + return perf_env__e_machine(machine ? machine->env : NULL, /*e_flags=3D*/N= ULL); +} + /* * Split the symbols into maps, making sure there are no overlaps, i.e. the * kernel range is broken in several maps, named [kernel].N, as we don't h= ave @@ -866,14 +883,13 @@ static int maps__split_kallsyms(struct maps *kmaps, s= truct dso *dso, u64 delta, struct rb_root_cached *root =3D dso__symbols(dso); struct rb_node *next =3D rb_first_cached(root); int kernel_range =3D 0; - bool x86_64; + uint16_t e_machine =3D EM_NONE; =20 if (!kmaps) return -1; =20 machine =3D maps__machine(kmaps); - - x86_64 =3D machine__is(machine, "x86_64"); + e_machine =3D machine_or_dso_e_machine(machine, dso); =20 while (next) { char *module; @@ -925,7 +941,7 @@ static int maps__split_kallsyms(struct maps *kmaps, str= uct dso *dso, u64 delta, */ pos->start =3D map__map_ip(curr_map, pos->start); pos->end =3D map__map_ip(curr_map, pos->end); - } else if (x86_64 && is_entry_trampoline(pos->name)) { + } else if (e_machine =3D=3D EM_X86_64 && is_entry_trampoline(pos->name))= { /* * These symbols are not needed anymore since the * trampoline maps refer to the text section and it's @@ -1428,7 +1444,7 @@ static int dso__load_kcore(struct dso *dso, struct ma= p *map, free(new_node); } =20 - if (machine__is(machine, "x86_64")) { + if (machine_or_dso_e_machine(machine, dso) =3D=3D EM_X86_64) { u64 addr; =20 /* @@ -1716,7 +1732,7 @@ int dso__load(struct dso *dso, struct map *map) ret =3D dso__load_guest_kernel_sym(dso, map); =20 machine =3D maps__machine(map__kmaps(map)); - if (machine__is(machine, "x86_64")) + if (machine && machine_or_dso_e_machine(machine, dso) =3D=3D EM_X86_64) machine__map_x86_64_entry_trampolines(machine, dso); goto out; } --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 C9801383985 for ; Mon, 1 Jun 2026 06:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296873; cv=none; b=irpAFuFEN4Y+Uaq+tOs7NQPGEdGTXuRiK+Emrr4OXzPpbf+iqtEpTX7H8ZMgDDrgX2QTp3yHh/xJ3en9S2zDhDIFba5XwyjspVc3cPsurfdIfLvsqXuToV7OeVeVosJGGuA+niO0erHnh8khdqRgKPL/m7FK6pl3f77yZ1jfB64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296873; c=relaxed/simple; bh=MFEe6LPphunpb6kkXYtvg8HS6T7M6CMwxT39S2tasIk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XN0x7OFlDyRuS3apPUG7n2x4U2rg+U804GKYGLZ9Fwp33FexVbPXtwv0TmdhbrxluG5ELSJNzWM3aD+niNk6kw1gfRliAP9hBQb/APrX1YgNq9H8FhEjNInNK9tWaEVeoypVe4qfgd4L5H6/j8y8uW2bSLeSV/+jA5lGehhVOrI= 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=KIB4vflA; arc=none smtp.client-ip=74.125.82.73 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="KIB4vflA" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137d4309062so2555632c88.0 for ; Sun, 31 May 2026 23:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296868; x=1780901668; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TMPK/u4znZdID92cCsTtghz3RJZxs3ue0UuQgkEbF/o=; b=KIB4vflAPJF26bbYF3f2nMtsxsjNRjUaIIGTYZxQ7YUCp6EKQtXUyDSIK/Z+Okvelg JKj6Oe0j7zSWaVo3lXgAiZw340yAx0OEyTeSRAmKGZxFdXUVZV9ZlueoPSORnlV616Kx fCOEfWiTWLbaZrTLoUcpb6B9heSGHsI69Mh6R9cBoxp5uNeJWqqYExdz8twNsSfFS+Pi qWraTpjp6OkILcrJyO2kFQzvxqXlBZxHUUQBswHPYEV6MxmuD0kuFI0DJ7PmS/LSac8C KXCrO2b1R3o5dcm5Gnu/RVNgOAWHCtfdc2TvyNLlV9M8hCBLkV70eMQO4um25Iw0Nyqh E68g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296868; x=1780901668; h=cc: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=TMPK/u4znZdID92cCsTtghz3RJZxs3ue0UuQgkEbF/o=; b=DoOBj5kuEV7fRvuE4BxtRzhfuak3TLC8lZrLXVsSWoIZrD6wMtkSpLgzXB0fj1NBMH abosinGwc13JEzs+E6/ghtTl2IAAjG1J4lzSHydKT/W51tryeJDMKJVtLdG13xAxa3aS WeqTEYCG+gIDNzDDNz3jR3x4fM5Ood16mPX3sYVLqniAUgx3J9r2HGfLZNLAB6yGQXLF SPgYW1kVlhFJLzdLpSIQs9h7V6cmMJJo2EFJtfYd0/EmksJ2Y6UXU+PvJ1PLW9+nRsOi YgDFS3w2MbpTx72N40Yll4BVUqoVbHVdLCa6atUaQeaFX6pknXuxpp+zmJKxSrbSZcGq v2nA== X-Forwarded-Encrypted: i=1; AFNElJ83S0j9SLYjKy2iv91A2RzKO1fIaGM5SAUR0jiZ462xRTpdspXT5Rf5oL+TfHRIkoCyA+fWIt4JoAgHMlI=@vger.kernel.org X-Gm-Message-State: AOJu0YwEz+VXPqW9sa+njRc2bcWeIvN7Fu3UbUT48Wv97LjGiDUMRU8a Seliuz1LuhB/QdpcgXlv4co+X9d8eE9warqNnyBVnPmmuM4iLnnU3LVRNmGXg22PJP0+9X5y6Wt 9u/4U+swpNQ== X-Received: from dycnb7.prod.google.com ([2002:a05:7301:b07:b0:304:d169:68d5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:100b:b0:304:d32e:65e5 with SMTP id 5a478bee46e88-304fa4df7b1mr3917439eec.8.1780296867507; Sun, 31 May 2026 23:54:27 -0700 (PDT) Date: Sun, 31 May 2026 23:53:56 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-8-irogers@google.com> Subject: [PATCH v10 07/18] perf machine: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- tools/perf/util/machine.c | 35 ++++++++++++++++++----------------- tools/perf/util/machine.h | 2 -- 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 *mac= hine) return dsos__for_each_dso(&machine->dsos, machine__uses_kcore_cb, NULL) != =3D 0 ? true : false; } =20 +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 =3D=3D EM_HOST; + return false; + } + + return perf_env__e_machine(machine->env, NULL) =3D=3D 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); } =20 @@ -2786,7 +2801,7 @@ static int find_prev_cpumode(struct ip_callchain *cha= in, 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=3D*/NULL, /*e_flags=3D*/NULL) =3D= =3D 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; } =20 -/* - * 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 =3D 1ULL << 63 for x86_64. */ - if (!err && !machine__is(machine, "x86_64")) + if (!err && !machine__is(machine, EM_X86_64)) machine->kernel_start =3D 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 *mac= hine) } =20 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); =20 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,= pid_t tid); --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 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 7D9F43839A9 for ; Mon, 1 Jun 2026 06:54:30 +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=1780296874; cv=none; b=nUw8EhcmF9MabKRnzTXz044Ny6HIBKPQjICD4JPl7tWoGcs2j7WVFJzyfPmEQlXL0ETnmJUcnlsXBDXpJQ7DVsSuQJu434jqTMtDWuWMCVPsL44UMmMw/jYBgMbXsGrPzI5FpY8VL0F5+7L3VqAcTnq6o45taLNVgt9S1l1oRXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296874; c=relaxed/simple; bh=aypWcCWChxu4UgN3+4mGLRj5jbgQ/7vpfZhxtHZU+1I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=suDsN/AAYrbDkFZWTrCqZ8+C2Uyepu71085XoCU98xPAFB530e6v5szJsBSso4RLlGIxpt6HBUUoSKE1qWRKjpxcez8kf3vgc+lTOvyTOUyhAA9njCesh5QpLGHAqDdOZ+tJ5Vfw/RbpYQZzJMh+vE3IUq7T26hrBrvzmY6JG88= 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=sX8fYHxd; 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="sX8fYHxd" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304f1820babso3371126eec.1 for ; Sun, 31 May 2026 23:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296869; x=1780901669; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VjPKO70Uw6tNKKfbzB4deN86ngAx0uxqS2L1F9dC/t8=; b=sX8fYHxdTi6roA/+OFmIcge4ReR0bn0L/uh7gXi0aUX3n+/gfKpZqG4K1nhHLBUIiW qnyF/CLNSm1oQwLE+Cd7+60bcN86RccENVvlxPANB/L7O7GxfjkZ2qEdAWhjf2IzYrl2 ICRYxXUaKQ7xWbUUwH1nxUtd3NxlFMBB9x01t89ux2V+zImQWgNs4pqcrX481pKUgVT5 dS4oTYzCIbWv0zMEVcX2I9Hr3iijIq648mj3jRPvvMclvkOe+90yPxsR4Eq2ebPtYOyk RbJmwUTVkYh7ziG5F55Wvx56aBkM7hjeMfGpF+Hl3T+lq6XImQgXr99Y1gwSrWUsXT32 QrCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296869; x=1780901669; h=cc: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=VjPKO70Uw6tNKKfbzB4deN86ngAx0uxqS2L1F9dC/t8=; b=jXEq9TpWdBhUCDoizog34pwbfhFdn48MbsJQ4diGQpaMwOQidSPCdjDBTcZEfE2j7L uoZitePyLIy727sD+dmsROdnnTYrU8lq7Y1StZNu8qkD4RQqkZOVajGJUIkQ4mKWV/CH eUNRHKn2GLoKI60VemfemA9q9UerQKo1/W12BXORoUyZL5DBXe/sNL/ngqeczARVRiMm otWPEsHydwWohnSpVhEsfkuc1pMPwraS5OFTdYEbaB0pl6sPri7v0WEvd2RDjANgOgAW akvoR6gwVHNMZwz3Uqk8I5UqZKE3MUwe3RID410dSvxjJFAIhP9vxL1ERhOoX+At251p +Z4w== X-Forwarded-Encrypted: i=1; AFNElJ/MeV9V9pc2q8IoneQQ6NjNg8Ei8jRdrlbLg7N/RYtzdne296uLL66V9E5QZTTZZdnqF8xrmcEuZEmI4fM=@vger.kernel.org X-Gm-Message-State: AOJu0YwST9C1fWdjrZmcpNmyno9HKrulOrLFQcZTraLeIciqkcKwPiFO RRfznOHIwed2vFRhj2HwS6hiVG8jrJ8wpSs4c6kCRKGHw76Z2+KRuYHGjtdzkn05+mjj/NIekZQ GNdZ/UUFcEw== X-Received: from dyay11.prod.google.com ([2002:a05:693c:62cb:b0:304:eefd:96c6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:c87:b0:304:2e9b:8f57 with SMTP id 5a478bee46e88-304fa6ef8a1mr4377062eec.34.1780296869235; Sun, 31 May 2026 23:54:29 -0700 (PDT) Date: Sun, 31 May 2026 23:53:57 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-9-irogers@google.com> Subject: [PATCH v10 08/18] perf sample-raw: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than the arch to determine S390 and x86 types. Signed-off-by: Ian Rogers --- tools/perf/util/sample-raw.c | 21 +++++++++++---------- tools/perf/util/sample-raw.h | 6 +++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/sample-raw.c b/tools/perf/util/sample-raw.c index bcf442574d6e..e20b73c0c5bd 100644 --- a/tools/perf/util/sample-raw.c +++ b/tools/perf/util/sample-raw.c @@ -1,11 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include "sample-raw.h" =20 -#include +#include #include -#include "evlist.h" + #include "env.h" +#include "evlist.h" #include "header.h" -#include "sample-raw.h" #include "session.h" =20 /* @@ -14,14 +15,14 @@ */ void evlist__init_trace_event_sample_raw(struct evlist *evlist, struct per= f_env *env) { - const char *arch_pf =3D perf_env__arch(env); - const char *cpuid =3D perf_env__cpuid(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); =20 - if (arch_pf && !strcmp("s390", arch_pf)) + if (e_machine =3D=3D EM_S390) { evlist->trace_event_sample_raw =3D evlist__s390_sample_raw; - else if (arch_pf && !strcmp("x86", arch_pf) && - cpuid && strstarts(cpuid, "AuthenticAMD") && - evlist__has_amd_ibs(evlist)) { - evlist->trace_event_sample_raw =3D evlist__amd_sample_raw; + } else if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386) { + const char *cpuid =3D perf_env__cpuid(env); + + if (cpuid && strstarts(cpuid, "AuthenticAMD") && evlist__has_amd_ibs(evl= ist)) + evlist->trace_event_sample_raw =3D evlist__amd_sample_raw; } } diff --git a/tools/perf/util/sample-raw.h b/tools/perf/util/sample-raw.h index 896e9a87e373..c8d38c841c8c 100644 --- a/tools/perf/util/sample-raw.h +++ b/tools/perf/util/sample-raw.h @@ -2,7 +2,10 @@ #ifndef __SAMPLE_RAW_H #define __SAMPLE_RAW_H 1 =20 +#include + struct evlist; +struct perf_env; union perf_event; struct perf_sample; =20 @@ -12,4 +15,5 @@ bool evlist__has_amd_ibs(struct evlist *evlist); void evlist__amd_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample); void evlist__init_trace_event_sample_raw(struct evlist *evlist, struct per= f_env *env); -#endif /* __PERF_EVLIST_H */ + +#endif /* __SAMPLE_RAW_H */ --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 07ACE383C6B for ; Mon, 1 Jun 2026 06:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296875; cv=none; b=rAmJ2pNPl44kPEIjPbS6k3kFU0NcKG5zeEaNCBMbnCa22v7yzSS3920oWXUonr/cWx83GhRG3EX6jlQbCuaiiGjA+ho5wkcoqfypeaA1rNk5Ggr4JlxWE9MLkAPqsUFwcqZmBgA94bouLDytjiR5bn4upXSwX2DAZ36IvhSTpEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296875; c=relaxed/simple; bh=/QMmXJBKQNb4K6haqK+hePSPO4Dmf7jySR0tC2WlGiw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GLQTcKb/XI3blDvNcA402QGuCYns6MBduq6+WxdCf0M2+DiGy2jAXfC7rbGTioqk+FqqXaL2cByIwZJKcXmuSpmwPbDsx7DUTq5DLsOkhyymikGfsZucbxStN/Tx0UTdw/LPcTIxgqFEmMLetIwhkLMYqsWr3uxKIK4i2ePu2t8= 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=vK3h5V62; arc=none smtp.client-ip=74.125.82.73 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="vK3h5V62" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1353bfdbf99so2241523c88.0 for ; Sun, 31 May 2026 23:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296871; x=1780901671; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HaYSSe7MrXhzop/WSi7SwbpLSKEaLKbhaDVaNUSRXpI=; b=vK3h5V62BNA3uVNX2sXn7dvr3FdKsr7xv67UM3M+8R01bAVPxUYd29t4NYjXzboLsZ uH4+swlrNWVAly9gCIvgj+tTOVwP5WYLMfRCSZjyTFQLexcdyc+fl866li3nbtou8ZBt 91FsPSgTl6ffKg1MEiSOVUjpCupqWEpFd1mQpF52LQBWW70zN/ojv7S+apUKK9ljNVsH HPaqLvm9efIBX/Bms0AAPXwuVGi7cTqr9eqoqh2QBXUI+GWM/rSD1sqBHHxDvhrP6InJ ODZOEQsXivFi0vetmS2cDqDeTREUy6rI4FQ1nMEsMs2Iwtpg10fDokTeNOnXmwMYgtJx cRXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296871; x=1780901671; h=cc: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=HaYSSe7MrXhzop/WSi7SwbpLSKEaLKbhaDVaNUSRXpI=; b=OiVfmtfId78xI9CptWkB3ebgTfILKn0Hu3gEb/nGTllWqXu5wZ391uq7YKyVk21DQY NiUPv4S0lmD+eukJS35xjzyIdIQBHIsA47kBquHSKNhL6hd2b3Cygna+uP8FrWvcQLMc inrXV4Ry2YYJhHVhprnZpz6ACnAmvg9o2gxL1Uvie5fe0Yb+lLC5verzaTD4aP2TpBvQ tdz9y+UsQT+I+PCDwcS07IBJWvc2V8lOw3sjxwHkisP7hvEg3mVVgnWEq47RHtk5YVqE dGsjutvxmqz+Aedq8gorEY3ImhKkmno32XFD6kTcbi+gUQvKdVPyyQecQX658VJJHf7o a1nA== X-Forwarded-Encrypted: i=1; AFNElJ83A8f+lAwVZu4GDAakvklZcqrmWMmVR6J6BirZ9B3R4PHT3KS1lkTQ3nACUa0UmPaIO1VIOaWakQmcX6A=@vger.kernel.org X-Gm-Message-State: AOJu0YwMf97uB8IxAWSHv7qupQAaJTRa3Zux86SzJBvDbve4iDIIZpc4 QQIoL+K187UTm8cI+ulhd47rvsgiq1gDHkfgA2I0u/F3BKW3ZkQ8pyMI2+a/Eb5VrcNjCUjsz2O JkGHi2tiPRw== X-Received: from dlbbo37.prod.google.com ([2002:a05:7022:43a5:b0:135:d0cf:93de]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:117:b0:11a:e426:911a with SMTP id a92af1059eb24-137d3f132bbmr5142893c88.15.1780296870856; Sun, 31 May 2026 23:54:30 -0700 (PDT) Date: Sun, 31 May 2026 23:53:58 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-10-irogers@google.com> Subject: [PATCH v10 09/18] perf sort: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than the arch to determine x86 or PPC types. Signed-off-by: Ian Rogers --- 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 #include #include -#include #include + +#include +#include #include +#include #include + +#include + +#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 -#include =20 #ifdef HAVE_LIBTRACEEVENT #include @@ -2673,9 +2678,10 @@ struct sort_dimension { =20 static int arch_support_sort_key(const char *sort_key, struct perf_env *en= v) { - const char *arch =3D perf_env__arch(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_eflags=3D*/NULL); =20 - if (!strcmp("x86", arch) || !strcmp("powerpc", arch)) { + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386 || e_machine = =3D=3D EM_PPC64 || + e_machine =3D=3D 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_k= ey, struct perf_env *env) =20 static const char *arch_perf_header_entry(const char *se_header, struct pe= rf_env *env) { - const char *arch =3D perf_env__arch(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_eflags=3D*/NULL); =20 - if (!strcmp("x86", arch)) { + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D 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 =3D=3D EM_PPC64 || e_machine =3D=3D EM_PPC) { if (!strcmp(se_header, "Local INSTR Latency")) return "Finish Cyc"; else if (!strcmp(se_header, "INSTR Latency")) --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 D4C1D383C8F for ; Mon, 1 Jun 2026 06:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296876; cv=none; b=u43uXymXJVwMfQlf1szu5yBT3uCe4zIvmWGb6vze6rJKReZC89SLEWxaVLqIJ+5yW5K+9lZp3KDXo4RHKt2fPtSJA32GaJ+UPqyVO0J/ecutXbpsfLzLZgW2kSxLr52G4/1G/+KxapOcj5V1V/3rpx5DgwwVTZXvNSAL5kI4tiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296876; c=relaxed/simple; bh=paAhGMuVcFCJawkYRHI1yb+PMES60j9yTRYSD8knZOU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hGV+Gw6TPteIjoBf3ntvJqKvZEihNwXhUe67PvhaxnEqoeQw4tBdmEDSLJCWS2l+LLuOiYK9jFhpKB5jre/I38bS1ByNFx/SkkjOE+V0sxgFVl04LrlPuY3L16S1co4//JAd0mMkpgX6VB2b/dHmozclCjehBTj7KLsmHBVdQ/o= 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=DLOlB3aC; arc=none smtp.client-ip=74.125.82.74 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="DLOlB3aC" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-135916eefa0so13425972c88.1 for ; Sun, 31 May 2026 23:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296873; x=1780901673; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=stvvHCX8qouUxL2lu5v4L2Thox3XkwMaO5uo38gU10I=; b=DLOlB3aCpDWRfmFK/zRCT7ik4CXnc64mjK9KiPVXN49T7rZeIJbOSDgIPUu+QpGBtn Tnd/Smmeg/WMwYZmRyGU764GOl4yPNro2eKFietI75gOmLZW+v9SL3+nGTJQtE0JAOu3 5vbeHFw2C3AJ+StFwaBhdMgiB1jyqOGeZJn3YdjxG891a1WKWvuVo5wAzgqVCGcUSyo9 h66NavW7Mtb+exYbwz/lQLbdr0jSgUQyF4PXneumhA/l18g5VT2x1iIALX6/ORskZ328 Yf1Ol8Y1fWDiSJEtIra6ZO4vneRQldPwC+Dfh7RtXBe0lssO/qdU37lmPnmrCJCTD6HA +FmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296873; x=1780901673; h=cc: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=stvvHCX8qouUxL2lu5v4L2Thox3XkwMaO5uo38gU10I=; b=inkiexsLrRaRsgXFVgX12k8Nb1rxEpt8/ZtmOZfN6DeR5hX2TSkq2fGoGriUOnouZy 95ubfTS2z7kLbxW8nxCaGo7OaAxuEi/r5niNsWPmPrtQnExHcSLr8WdIYSkCRcpLk2/p rPfnw6YwEkycO4VHbsgkoNwUI0Tkwc1xLk7/OW4jy6UifOLh7lDrk97rPYk8I4KMLB1w wsmy8gcdJiXpuHRvXfx82sQiQ2yGvAiv5d/4bUfqp1G18IhFFkq/mPl9q8XD/2YWLkHg rlvPg7t1jt3DIapZLd3rzOdOe1T3Kjdiu5vdwpatXfxJdz7QnU4+jIx+IqnhtxLp3OGi +sQA== X-Forwarded-Encrypted: i=1; AFNElJ+fO7HTJuPip/iCB+j1s7cIOL5nX5J6VuhRlgsH1VRtAc5qTDamZVw05l1JVD8x7qsOLzVIdBZ6r3TrSio=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5cLpmxlt3ddwpyUaB2aJlRJEQOFd+/vXocM4dXm9Igoapx6KK gJxITz1Yw6tMH3/XL9NkCY13+hRWU+NGUNHc7J2ilwBqzQyMKdS94jJEakOTtNFQFZf2ov5XjSl F9uvcBPQMSA== X-Received: from dlea3-n2.prod.google.com ([2002:a05:701b:4203:20b0:135:dd6a:be57]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:41:b0:135:608a:2864 with SMTP id a92af1059eb24-137d42494e3mr4069314c88.33.1780296872813; Sun, 31 May 2026 23:54:32 -0700 (PDT) Date: Sun, 31 May 2026 23:53:59 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-11-irogers@google.com> Subject: [PATCH v10 10/18] perf arch common: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching. Signed-off-by: Ian Rogers --- tools/perf/arch/common.c | 92 ++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 23 deletions(-) diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c index ad0cab830a4d..805a15ed99bc 100644 --- a/tools/perf/arch/common.c +++ b/tools/perf/arch/common.c @@ -1,13 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 +#include "common.h" + #include #include #include #include + +#include #include -#include "common.h" -#include "../util/env.h" + +#include + #include "../util/debug.h" -#include +#include "../util/env.h" =20 static const char *const arc_triplets[] =3D { "arc-linux-", @@ -141,11 +146,40 @@ static int lookup_triplets(const char *const *triplet= s, const char *name) return -1; } =20 +static bool is_native_compatible(struct perf_env *env, uint16_t target, ui= nt16_t host) +{ + if (target !=3D host) { + /* A 64-bit host can natively disassemble its 32-bit compat architecture= */ + if (host =3D=3D EM_X86_64 && target =3D=3D EM_386) + return true; + if (host =3D=3D EM_AARCH64 && target =3D=3D EM_ARM) + return true; + if (host =3D=3D EM_PPC64 && target =3D=3D EM_PPC) + return true; + if (host =3D=3D EM_SPARCV9 && target =3D=3D EM_SPARC) + return true; + return false; + } + + /* target =3D=3D host case */ + if (target =3D=3D EM_RISCV) { + bool target_is_64 =3D perf_env__kernel_is_64_bit(env); + bool host_is_64 =3D (sizeof(void *) =3D=3D 8); + + /* 32-bit host cannot natively disassemble 64-bit target */ + if (!host_is_64 && target_is_64) + return false; + } + + return true; +} + static int perf_env__lookup_binutils_path(struct perf_env *env, const char *name, char **path) { int idx; - const char *arch =3D perf_env__arch(env), *cross_env; + uint16_t e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); + const char *cross_env; const char *const *path_list; char *buf =3D NULL; =20 @@ -153,7 +187,7 @@ static int perf_env__lookup_binutils_path(struct perf_e= nv *env, * We don't need to try to find objdump path for native system. * Just use default binutils path (e.g.: "objdump"). */ - if (!strcmp(perf_env__arch(NULL), arch)) + if (is_native_compatible(env, e_machine, EM_HOST)) goto out; =20 cross_env =3D getenv("CROSS_COMPILE"); @@ -170,30 +204,42 @@ static int perf_env__lookup_binutils_path(struct perf= _env *env, zfree(&buf); } =20 - if (!strcmp(arch, "arc")) + switch (e_machine) { + case EM_ARC: path_list =3D arc_triplets; - else if (!strcmp(arch, "arm")) + break; + case EM_ARM: path_list =3D arm_triplets; - else if (!strcmp(arch, "arm64")) + break; + case EM_AARCH64: path_list =3D arm64_triplets; - else if (!strcmp(arch, "powerpc")) + break; + case EM_PPC: + case EM_PPC64: path_list =3D powerpc_triplets; - else if (!strcmp(arch, "riscv32")) - path_list =3D riscv32_triplets; - else if (!strcmp(arch, "riscv64")) - path_list =3D riscv64_triplets; - else if (!strcmp(arch, "sh")) + break; + case EM_RISCV: + path_list =3D perf_env__kernel_is_64_bit(env) ? riscv64_triplets : riscv= 32_triplets; + break; + case EM_SH: path_list =3D sh_triplets; - else if (!strcmp(arch, "s390")) + break; + case EM_S390: path_list =3D s390_triplets; - else if (!strcmp(arch, "sparc")) + break; + case EM_SPARC: + case EM_SPARCV9: path_list =3D sparc_triplets; - else if (!strcmp(arch, "x86")) + break; + case EM_X86_64: + case EM_386: path_list =3D x86_triplets; - else if (!strcmp(arch, "mips")) + break; + case EM_MIPS: path_list =3D mips_triplets; - else { - ui__error("binutils for %s not supported.\n", arch); + break; + default: + ui__error("binutils for %s not supported.\n", perf_env__arch(env)); goto out_error; } =20 @@ -202,7 +248,7 @@ static int perf_env__lookup_binutils_path(struct perf_e= nv *env, ui__error("Please install %s for %s.\n" "You can add it to PATH, set CROSS_COMPILE or " "override the default using --%s.\n", - name, arch, name); + name, perf_env__arch(env), name); goto out_error; } =20 @@ -237,7 +283,7 @@ int perf_env__lookup_objdump(struct perf_env *env, char= **path) */ bool perf_env__single_address_space(struct perf_env *env) { - const char *arch =3D perf_env__arch(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); =20 - return strcmp(arch, "s390") && strcmp(arch, "sparc"); + return e_machine !=3D EM_SPARC && e_machine !=3D EM_SPARCV9; } --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 484FB385D67 for ; Mon, 1 Jun 2026 06:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296877; cv=none; b=hLxa8bBYXsj3RVilQ+cF7J0pXnI2D32efrHDkXd26okrjIR5FJlezEv8YoCD46rJi31b47v4ee+9YvPTLfUOCT7isLLy1pxX5/IW24MOrRLNK4/yYZVl540KD7cdThrxbWhdWyuNyzfVTYJ/FJr2NAabayh6gjBqSH6uAB5QYmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296877; c=relaxed/simple; bh=byA4iiiItOzrCIc40YhkXBiIapb+JQVAmtrP03YEzGE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ACidllagItCcxWgFpJpJUdhRzvuAl4NSD6AT3pwKXRtVOje79qZ8CUlLpQd9eWbtqITDYzBjtnF8wv7Hi0BMMbQhUoOpTUX2/OajKKjgRux/Lf29kywM0iuv30yATX6Wynl+pQxkbnD1FsSxUsIXdRBzQ2oiu4z/U1EIZEo9h0g= 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=RAbfKXEU; arc=none smtp.client-ip=74.125.82.73 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="RAbfKXEU" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137d003cf09so2042022c88.1 for ; Sun, 31 May 2026 23:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296875; x=1780901675; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tY794Th1Kf4p0/W+HEvStNmZU5/pHa8B5HzKhPU3Ew0=; b=RAbfKXEUWhb+vPWbmJcRpCS5wDCuhyfejIxJ3ypHBRsjs2vyCAKtfOStxzDUGQmvY5 YwT2/JK6OWkxmDlyqcDnBx4E9+lmDy2UzPtd0h8fL9ntexLEljKcMc9xGGdYPujjdE58 Cz+Fpv2Gexaf8etagf/HwIV3C8TRaaFpjF8fEXF7+nwkFlHbhXThNu6/zzfJc2HHJVVR MMTXOAVh8KcJELD51ZxdxRzCJ3F7nPfkw16gHZdkRnj+arIl9qfqm8FzYb7R5YqnlSqW Iy8yXlKAtWu8Bg6Dd2Spf1nThpNmwqfiHfBX3QVtWF1rDBqgfEsm0oXjSIRK06v8slS9 iEHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296875; x=1780901675; h=cc: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=tY794Th1Kf4p0/W+HEvStNmZU5/pHa8B5HzKhPU3Ew0=; b=CzdDEglvG2XUKXCjizZk15nqhD2w8avdrT6nbSDBkltUf8NOovNmb+H7sNeeV3gyaj KdkCIN3upJA8N4pi4J3TDkR7o7eyeAnSa76IzQ4acKrAYj/5WmuIrBQrYzrhObrBu0FH NIKVs9b+KIwiPv0EB51XPweOl53wqWv9T69wdeuRYLOW7xvVEi4A/mvY2CfVwnG6O0oy DeKRfEGzinqHchAZvq/8t9P4f8bgZbuXG25RqeCUGjqjeYF0uEUqSxkMs1s+NV2x7WA0 YRlCs+k4SuF0dJpVQDLnpy3+JupXHrONh4cXi88UI5Lv4qFRyU9VksqXh3XduwJFCz/I LPeg== X-Forwarded-Encrypted: i=1; AFNElJ9C0MPpB4HxjmES41tq29VDXQT4us0JJhaF6Id34N2azi4x2ouue8/j0GQkwtkavW7LBnkK7iKFDSkE4nI=@vger.kernel.org X-Gm-Message-State: AOJu0YxHnjWXo6769F4XY3xRGsdAM89MdL2di6Kosk4YjYnROBuLBtyA 9Qf0CvuQ6rrVSzgw8kIDESd2D73k3/m02Ar8rW680orgNtFvEBxYAaYk93JLztMrUB95beq8VNx v7Ada9oUpCw== X-Received: from dlak23.prod.google.com ([2002:a05:701b:2917:b0:130:592b:1b03]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:41a4:b0:136:e639:9c17 with SMTP id a92af1059eb24-137d42615b3mr3994750c88.23.1780296875217; Sun, 31 May 2026 23:54:35 -0700 (PDT) Date: Sun, 31 May 2026 23:54:00 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-12-irogers@google.com> Subject: [PATCH v10 11/18] perf header: In print_pmu_caps use perf_env e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from arch to e_machine in print_pmu_caps. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 220e7720fbdb..ecdac427d9c4 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2461,15 +2461,16 @@ static void print_cpu_pmu_caps(struct feat_fd *ff, = FILE *fp) static void print_pmu_caps(struct feat_fd *ff, FILE *fp) { struct perf_env *env =3D &ff->ph->env; - struct pmu_caps *pmu_caps; + uint16_t e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); =20 for (int i =3D 0; i < env->nr_pmus_with_caps; i++) { - pmu_caps =3D &env->pmu_caps[i]; + struct pmu_caps *pmu_caps =3D &env->pmu_caps[i]; + __print_pmu_caps(fp, pmu_caps->nr_caps, pmu_caps->caps, pmu_caps->pmu_name); } =20 - if (strcmp(perf_env__arch(env), "x86") =3D=3D 0 && + if ((e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386) && perf_env__has_pmu_mapping(env, "ibs_op")) { char *max_precise =3D perf_env__find_pmu_cap(env, "cpu", "max_precise"); =20 --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 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 2C0A2386571 for ; Mon, 1 Jun 2026 06:54:38 +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=1780296879; cv=none; b=Q0uOzt3MwPA3dbNqSEHVaIRCEsZS23b3e27Ty5Yf7QAGNdEO0e8xlNwMUkK9HsEEXaRxSoWa+v7DPSIR+dvx9fMpqQnlm7ifchRLakaMuoIHR2zubDt6tFe+XtJR1OIPwHY6eU3sRZV/1E/zf4siz+Aw8c9xDlPa6H0Cc7vfRiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296879; c=relaxed/simple; bh=ZS+PuPcuxfpypEg7CyiU1rjR7Jy+Z+y6peaFHU7xaDg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qFx/84Oay1yo49hwWEkI8/H66qKcmMXUyKVU/qn6PWznR5iR6YnqcGNlD5tTIgQZPLHrko0wlmaxMYuLt4nK8zs8U1EwnwZ2OysbJyFLDjhCfIf/9wpbAPCbLYFjiJYRKirNXHXmne1eWoh0bON4LqCrZZxSfedP35iZB3uLlQ4= 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=mvah0QIC; 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="mvah0QIC" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304f23c55b2so2503356eec.0 for ; Sun, 31 May 2026 23:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296877; x=1780901677; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rVM9lLh1LoUGa3yn0TIFcsOtKqCsDpL9U10ydZo9Txk=; b=mvah0QICuzN63pcUJ8lLVRWbbzkn9hQZdAcMt24rGXPQpRm/DHlE4gEqtt+mu9FUfb lC1WN4fVdTXI51AWhZp7mNA+gm5CNV+GwinmQApyZe/qcDrzDALOqtEtlTBQ3cdiJLcP fl4LS9DClyMBEFEw4U9q3+iKGzl0Nkhk4mrBI58wGYz1LcErUtp1DqPLOWKEFbNxwWxX LQWDJD32gTDs/Mhm5w9mTTRGMTOTcwqlkdsYb+4YgfuM63ZrHsBc+pdMdgjWg0q1/b6i Kl+tdSZdWQFwplxAGajzTt8Hct70MsPPO+iWFZzSxWqUAQJ3fikdoscUz3Zpj/75sAfC FK5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296877; x=1780901677; h=cc: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=rVM9lLh1LoUGa3yn0TIFcsOtKqCsDpL9U10ydZo9Txk=; b=cSA5uU+jdGIttoSet4zaOHK8Jx+adbQBOkgqDZLmeyskd+teq8SiChZ6aAZ+77Mx1l UZFwxQ2K/6j8514zsrueNtcfjcC9B+ESZeTnwAmfMLiXv68Uo0wEL2mu0iaqiOxrx26O GYUPiKUM9cvtRfeZv4jGkQptQ+Qpr+44dVfGC44qOEktBNv+9On7x8CQDIB1MCccXQ4i 9bHG+Ub4UqzalfiMyX+dux6KGamqXIr+hfwsH7x58FI9Ilf89qNDLrc2dPhb0HA6F3T0 EWwpx91bPmmm5GLmqturDJmnqc9qhSeG5wHkRCC4nncC2v6y8czi73e0zdGf3xk7/vRl YThA== X-Forwarded-Encrypted: i=1; AFNElJ+iQXFJtUXZJ+xDo+2cfuN33wb2bsKudkqrkm5ard3+Hi2ck9IH4T6v8yujK0J5ksUqe1b3pncVkaEoDYI=@vger.kernel.org X-Gm-Message-State: AOJu0YxC5Wo5+OP1LWkJkECEcduF6HfNthfQEHww6RZDEkALMItCI9x4 LFOC8mc8ePRUIqz0AViu/HnhFwC3VtVc4JmXUydcqgs/xY0n2PdkKDlTnvIAT29svdobxwHm5Hl 8UuMXEcIaPA== X-Received: from dyaf2-n1.prod.google.com ([2002:a05:693c:8382:10b0:304:dfee:3633]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ef83:b0:2de:2f38:a7cb with SMTP id 5a478bee46e88-304fa64c547mr3992863eec.18.1780296877117; Sun, 31 May 2026 23:54:37 -0700 (PDT) Date: Sun, 31 May 2026 23:54:01 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-13-irogers@google.com> Subject: [PATCH v10 12/18] perf c2c: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching for AARCH64. Add include of dwarf-regs.h in case the EM_AARCH64 isn't defined, sort the headers given this include. Signed-off-by: Ian Rogers --- tools/perf/builtin-c2c.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 36f386949923..def5ed395f17 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -12,41 +12,45 @@ */ #include #include + +#include #include #include #include #include #include -#include #include -#include "debug.h" -#include "builtin.h" + +#include #include #include #include -#include "map_symbol.h" -#include "mem-events.h" -#include "session.h" -#include "hist.h" -#include "sort.h" -#include "tool.h" + +#include "builtin.h" #include "cacheline.h" #include "data.h" +#include "debug.h" #include "event.h" #include "evlist.h" #include "evsel.h" -#include "ui/browsers/hists.h" -#include "thread.h" -#include "mem2node.h" +#include "hist.h" +#include "map_symbol.h" +#include "mem-events.h" #include "mem-info.h" -#include "symbol.h" -#include "ui/ui.h" -#include "ui/progress.h" +#include "mem2node.h" #include "pmus.h" +#include "session.h" +#include "sort.h" #include "string2.h" -#include "util/util.h" -#include "util/symbol.h" +#include "symbol.h" +#include "thread.h" +#include "tool.h" +#include "ui/browsers/hists.h" +#include "ui/progress.h" +#include "ui/ui.h" #include "util/annotate.h" +#include "util/symbol.h" +#include "util/util.h" =20 struct c2c_hists { struct hists hists; @@ -3202,7 +3206,7 @@ static int perf_c2c__report(int argc, const char **ar= gv) * default display type. */ if (!display) { - if (!strcmp(perf_env__arch(env), "arm64")) + if (perf_env__e_machine(env, /*e_flags=3D*/NULL) =3D=3D EM_AARCH64) display =3D "peer"; else display =3D "tot"; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 4CD4D386576 for ; Mon, 1 Jun 2026 06:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296881; cv=none; b=XA0OtON1exOdaazpEhMimxOXNKsN4hFJpICHf3uaAEn8O5vaoWc2WVPOnjuY+YP9gowsqqIfx5QASBKTUCUiOCjjTycyZVuig2czNik4sw+MNQMCcHmfBWg/W9RzWZAEnJv/n0yb6+MLeJRWxScpPoJNc5rPojiHKo2lZR6cv/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296881; c=relaxed/simple; bh=q8F5fXyoFYv4Qz6hTTwJfP/908BeEKRkibPni3u/nVc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bU2L6D5OeId4zK+IWh0xudeFeN8mQUhl7mQCa4VxpIWc9Bgnu+p9i5y6EwrwZqvZLDw7Nieon/zSl3cZi6bzFFVdOf3xi8BnbOpDMHZaeUTyNtcnpSZkCrC2X8TEqRhHMGhhiQ5AOOgIIdtUcO0gNaGovu5PguXejA/aV7HuPHs= 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=GlX1ueRQ; arc=none smtp.client-ip=74.125.82.74 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="GlX1ueRQ" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137dd3a60e8so1236738c88.0 for ; Sun, 31 May 2026 23:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296879; x=1780901679; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p3BK9PCy7aBGu0lizAF2iiEjPcXEwff1QpswcRMbmnA=; b=GlX1ueRQ9FfPohjCKa0zwkefZ31FvEj8PWvm+FRN0Myed/tRc+wyMIZzPObgbZ5VgP yYnfZo91sQG4rhBJg4KJe1sO/lhZUQnycvep5t2OwM8N0yz+JpAl4116br12fKdi60+g 3IG5Ef7VdUqbUYURmox90H09xTj04Fn7Idqp1taAiy67tyjzUz0luNEYe/wS+U41FowH oiWrXAVL9gDooxDK7PtNy5TOidy/5vwmG/0Jbphty9e9vxsxfwF2SOnqMI+JyFvY4zTo 1+uU2IkZUn9zpjlYn3x3S4USFo275w35HLFLV8HfEcJVfOJ+mZbRpucmbTDcoZc6raCf 4aJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296879; x=1780901679; h=cc: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=p3BK9PCy7aBGu0lizAF2iiEjPcXEwff1QpswcRMbmnA=; b=nRdyul1nllpsB+0XCYbJdvqX7VDcGnNnPGv4R+YWZaHyQp7UHyObc1XiwsS6okjaMf z7x5XL/8Ka5tVUKpME0mPIM3IrFZWq8bv+r2eZrkE77t6KInH8k24pN3VJ4OfNU/C+Sp 1fwTs3YEl7k3uB45OoBhsvApEaDE/nlP4mrwR5qqxX85Hura65qHKX9Bzg214UCyXX/W jNjm/nBGeVjPmtBjo7bkBdU7BSgbJFsrXvLu3y7oYTkvDYGLUK5DQMGwTY+YeBVb7wv4 57xT6ahamPWKIIKG3jEu3cL4O+g7fiOaVyZ9vFsilp9Og3M688RDWbivN0uQxL22Y/Fb mjUw== X-Forwarded-Encrypted: i=1; AFNElJ+DV268Mz6aaSANU2AsIhydT4tgPc8eI1o6kypv53/tkc6QsOtz/f31uQ+Yj98rdByXF95mR6VXOhUEO7Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yzg4cr0Z9VA8NiS9P1HeyEwNKoPgI0uMg8jt1KUTp1poKR+IGhN 0sprxgW8ppIjz8bXkroMAr9ciYGHamicHhPXQLD4kub5COFXhzzY6hBogOeicaPb6EnJvvTYMd5 laLvLFmPc1w== X-Received: from dlbqq4.prod.google.com ([2002:a05:7022:ed04:b0:137:ea37:a378]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6192:b0:132:956b:3a3 with SMTP id a92af1059eb24-137d401b909mr3976817c88.10.1780296879243; Sun, 31 May 2026 23:54:39 -0700 (PDT) Date: Sun, 31 May 2026 23:54:02 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-14-irogers@google.com> Subject: [PATCH v10 13/18] perf lock-contention: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching for powerpc. Signed-off-by: Ian Rogers --- tools/perf/util/lock-contention.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/lock-contention.c b/tools/perf/util/lock-conte= ntion.c index 92e7b7b572a2..119a7206f3cd 100644 --- a/tools/perf/util/lock-contention.c +++ b/tools/perf/util/lock-contention.c @@ -104,7 +104,8 @@ bool match_callstack_filter(struct machine *machine, u6= 4 *callstack, int max_sta struct map *kmap; struct symbol *sym; u64 ip; - const char *arch =3D perf_env__arch(machine->env); + uint16_t e_machine =3D perf_env__e_machine(machine->env, /*e_flags=3D*/NU= LL); + bool is_powerpc =3D e_machine =3D=3D EM_PPC64 || e_machine =3D=3D EM_PPC; =20 if (list_empty(&callstack_filters)) return true; @@ -125,8 +126,7 @@ bool match_callstack_filter(struct machine *machine, u6= 4 *callstack, int max_sta * incase first or second callstack index entry has 0 * address for powerpc. */ - if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || - (i !=3D 1 && i !=3D 2)))) + if (!callstack || (!callstack[i] && (!is_powerpc || (i !=3D 1 && i !=3D = 2)))) break; =20 ip =3D callstack[i]; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 37CCE3876B5 for ; Mon, 1 Jun 2026 06:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296884; cv=none; b=GK4pwjKNIME10jGjHSUhUqGRLGY0UyMCuZNudf2uDbG1Mt/ewqSCHh03RX5hBE5sHC/qbHT5hlgwafAShVLWyG9LIMisgShuWuhext/WKxgRFwu367JBKRctwH7nme7y2N6uUEyRsm12TgcIsXaKfUSsYWqD7oclyIxwX5RZqfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296884; c=relaxed/simple; bh=AfVtJGxFq3/GN+KKs+vE+6HNkbzX+bmU4sHY3PCjgPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Lq2yUllmLS5Kb2QUw76HUE9YB8hDXrRDEANsSilXl0fKYvLo6YiebFVBEdflpDmHP9DzsvwrWngeShcyNK7JVtnc7QwkFm3yTZTupOyBdy2NQFZNAXJIRLaMQnCCKnh1JqkSO+mBcoyNPA3W5BqJ5TQZObPLCyXNeXwaBmZxMPE= 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=cZIMiSLm; arc=none smtp.client-ip=74.125.82.73 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="cZIMiSLm" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137ea73393cso272089c88.0 for ; Sun, 31 May 2026 23:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296881; x=1780901681; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=m9l7jwInauSUuEQMp0ByvVmmWHt+qu3CfU7xQtt2+Fw=; b=cZIMiSLmQi3kM5VZUNNF+EbsvHjQRl/dTHVCZiCOR8XX3ECeInVE2V1JQj9kdCiOwJ zpVy1s0sDe8iGal4CdzkyZ9OhE/lEPCgxyZniOoJs/um6qkSKTZxqwYsbZP366oZFyxa Lh0GVeErLs+uoAZ2fcgq4rsMHV2eGZ5al1zZk3n2jhrE6vtZjccod+Bs9VKy7mE86nwM U3EJL3P9Xc6qrCJrVdYS5HvQaqUCwgnvQlS8wrFF8d2v9Nhm7DaY1xHM/3shWcqgOkLH wUkPsLLypJS3kNk9/zJJN36OOoQVh1g402EWgSEkVscIYDqlI08HTXr55/D3vsQSLUS1 DnSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296881; x=1780901681; h=cc: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=m9l7jwInauSUuEQMp0ByvVmmWHt+qu3CfU7xQtt2+Fw=; b=eJCFm+lx87vF1+1HahKjCpY38t/GOLZdjc8kM5VE94pVr7W1o9ARMq75tS8lzAyZBT Kp3VYtHEV2wu95J4s2PbnHIyRQo0i1y1K4uYei8HvoG70be5EAQjdH4/OuQ8WiHoe4WN 6FtSgHSL4d1c+krIgK6HKIIqxJ0KUFP4F7pv/9pcpw3KfzQZXRGESYQY0V+7pW5CZvTN 4fNf4z0h2FYoaO3Ypc/Ni9A0RX6o8s1ep0o3NNMygtMPU9nYfQ4OEsWbAYH/IbwXL52W gWk5DOc5RnUXdq1uukLdeoqIfaFL7nh/HCfcPyvbqWlXsVCEXTyepc+dekQvkuADCdfy a0Mw== X-Forwarded-Encrypted: i=1; AFNElJ9fgPmPKcnx2oaL88WzUBvknhDRpS/NVra/ejCl1Uoj5mAtiEEbhn9OnMsmkgJAopqObCcmMJymn77hTLY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzc4p5LaNbroiR6ZRz1ildKlcjY3dS/xaIIMhgSyxcfWHJJGHCz kECLajwAh1a1mR2O+u1rx7uSeprhmNoDF362S7nWCAx7fgU6i6Jw5Wm449M9BNr+UmW6cdmbwmd nHIU3TqhaIw== X-Received: from dleb13-n1.prod.google.com ([2002:a05:701b:424d:10b0:135:d8c9:120a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e24:b0:12c:6a24:a24f with SMTP id a92af1059eb24-137d4294858mr4288098c88.33.1780296881243; Sun, 31 May 2026 23:54:41 -0700 (PDT) Date: Sun, 31 May 2026 23:54:03 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-15-irogers@google.com> Subject: [PATCH v10 14/18] perf env: Refactor perf_env__arch_strerrno From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_env__arch_strerrno is only available with libtraceevent so hide the declaration if no libtraceevent. The previous approach maps an architecture string to a function pointer to a function that takes an int errno values and returns a string. The new approach takes an e_machine and an errno value and returns a string. As the only call site is in builtin-trace.c, the e_machine is already present and potentially more specific than the perf_env arch string that is a single global value. The major complication in this approach is having the shell script that generates the C code map a linux directory name to the matching ELF machine constants. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 7 ++-- tools/perf/trace/beauty/Build | 1 + tools/perf/trace/beauty/arch_errno_names.sh | 41 ++++++++++++++++++--- tools/perf/util/env.c | 15 +++----- tools/perf/util/env.h | 8 ++-- tools/perf/util/libdw.c | 2 +- 6 files changed, 51 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 2530b4035e4f..377f0a18b00e 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3032,9 +3032,8 @@ static int trace__sys_exit(struct trace *trace, } else if (ret < 0) { errno_print: { char bf[STRERR_BUFSIZE]; - struct perf_env *env =3D evsel__env(evsel) ?: &trace->host_env; const char *emsg =3D str_error_r(-ret, bf, sizeof(bf)); - const char *e =3D perf_env__arch_strerrno(env, err); + const char *e =3D perf_env__arch_strerrno(e_machine, err); =20 fprintf(trace->output, "-1 %s (%s)", e, emsg); } @@ -4921,7 +4920,9 @@ static size_t syscall__dump_stats(struct trace *trace= , int e_machine, FILE *fp, =20 for (e =3D 0; e < stats->max_errno; ++e) { if (stats->errnos[e] !=3D 0) - fprintf(fp, "\t\t\t\t%s: %d\n", perf_env__arch_strerrno(trace->host-= >env, e + 1), stats->errnos[e]); + fprintf(fp, "\t\t\t\t%s: %d\n", + perf_env__arch_strerrno(e_machine, e + 1), + stats->errnos[e]); } } lines++; diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build index 996e63cdf765..bf9553f683f8 100644 --- a/tools/perf/trace/beauty/Build +++ b/tools/perf/trace/beauty/Build @@ -36,6 +36,7 @@ perf-y +=3D signum.o perf-y +=3D socket_type.o perf-y +=3D waitid_options.o perf-util-y +=3D arch_errno_names.o + perf-y +=3D tracepoints/ =20 ifdef SHELLCHECK diff --git a/tools/perf/trace/beauty/arch_errno_names.sh b/tools/perf/trace= /beauty/arch_errno_names.sh index d48d8561a7bb..aae3d92a7893 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -52,21 +52,50 @@ process_arch() |IFS=3D, create_errno_lookup_func "$arch" } =20 +arch_to_e_machine() +{ + case "$1" in + alpha) printf '\tcase EM_ALPHA:\n' ;; + arc) printf '\tcase EM_ARC:\n' ;; + arm) printf '\tcase EM_ARM:\n' ;; + arm64) printf '\tcase EM_AARCH64:\n' ;; + csky) printf '\tcase EM_CSKY:\n' ;; + hexagon) printf '\tcase EM_HEXAGON:\n' ;; + loongarch) printf '\tcase EM_LOONGARCH:\n' ;; + microblaze) printf '\tcase EM_MICROBLAZE:\n' ;; + mips) printf '\tcase EM_MIPS:\n' ;; + parisc) printf '\tcase EM_PARISC:\n' ;; + powerpc) printf '\tcase EM_PPC:\n\tcase EM_PPC64:\n' ;; + riscv) printf '\tcase EM_RISCV:\n' ;; + s390) printf '\tcase EM_S390:\n' ;; + sh) printf '\tcase EM_SH:\n' ;; + sparc) printf '\tcase EM_SPARC:\n\tcase EM_SPARCV9:\n' ;; + x86) printf '\tcase EM_386:\n\tcase EM_X86_64:\n' ;; + xtensa) printf '\tcase EM_XTENSA:\n' ;; + esac +} + create_arch_errno_table_func() { archlist=3D"$1" default=3D"$2" =20 - printf 'arch_syscalls__strerrno_t *\n' - printf 'arch_syscalls__strerrno_function(const char *arch)\n' + printf 'const char *arch_syscalls__strerrno(uint16_t e_machine, int err);= \n\n' + printf '__attribute__((unused)) const char *\n' + printf 'arch_syscalls__strerrno(uint16_t e_machine, int err)\n' printf '{\n' + printf '\tswitch (e_machine) {\n' for arch in $archlist; do arch_str=3D$(arch_string "$arch") - printf '\tif (!strcmp(arch, "%s"))\n' "$arch_str" - printf '\t\treturn errno_to_name__%s;\n' "$arch_str" + ems=3D$(arch_to_e_machine "$arch_str") + if [ -n "$ems" ]; then + printf '%s\n' "$ems" + printf '\t\treturn errno_to_name__%s(err);\n' "$arch_str" + fi done arch_str=3D$(arch_string "$default") - printf '\treturn errno_to_name__%s;\n' "$arch_str" + printf '\tdefault:\n\t\treturn errno_to_name__%s(err);\n' "$arch_str" + printf '\t}\n' printf '}\n' } =20 @@ -74,6 +103,8 @@ cat < +#include +#include =20 EoHEADER =20 diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index b8331d4dd347..0db74ee05d08 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -863,17 +863,14 @@ const char *perf_env__arch(struct perf_env *env) return env->arch ?: arch; } =20 -const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, i= nt err __maybe_unused) -{ -#if defined(HAVE_LIBTRACEEVENT) - if (env->arch_strerrno =3D=3D NULL) - env->arch_strerrno =3D arch_syscalls__strerrno_function(perf_env__arch(e= nv)); +const char *arch_syscalls__strerrno(uint16_t e_machine, int err); =20 - return env->arch_strerrno ? env->arch_strerrno(err) : "no arch specific s= trerrno function"; -#else - return "!HAVE_LIBTRACEEVENT"; -#endif +#if defined(HAVE_LIBTRACEEVENT) +const char *perf_env__arch_strerrno(uint16_t e_machine, int err) +{ + return arch_syscalls__strerrno(e_machine, err); } +#endif =20 const char *perf_env__cpuid(struct perf_env *env) { diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index dd9907dbc345..ba51b871c401 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -67,8 +67,6 @@ struct cpu_domain_map { struct domain_info **domains; }; =20 -typedef const char *(arch_syscalls__strerrno_t)(int err); - struct perf_env { char *hostname; char *os_release; @@ -158,7 +156,6 @@ struct perf_env { */ bool enabled; } clock; - arch_syscalls__strerrno_t *arch_strerrno; }; =20 enum perf_compress_type { @@ -191,8 +188,9 @@ void cpu_cache_level__free(struct cpu_cache_level *cach= e); uint16_t perf_env__e_machine_nocache(struct perf_env *env, uint32_t *e_fla= gs); uint16_t perf_env__e_machine(struct perf_env *env, uint32_t *e_flags); const char *perf_env__arch(struct perf_env *env); -const char *perf_env__arch_strerrno(struct perf_env *env, int err); -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch); +#if defined(HAVE_LIBTRACEEVENT) +const char *perf_env__arch_strerrno(uint16_t e_machine, int err); +#endif const char *perf_env__cpuid(struct perf_env *env); const char *perf_env__raw_arch(struct perf_env *env); int perf_env__nr_cpus_avail(struct perf_env *env); diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c index 84713b2a7ad5..d5d2958902c0 100644 --- a/tools/perf/util/libdw.c +++ b/tools/perf/util/libdw.c @@ -130,7 +130,7 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args) return 0; =20 abort_delete_sym: - if (inline_sym->inlined) + if (symbol__inlined(inline_sym)) symbol__delete(inline_sym); abort_enomem: args->err =3D -ENOMEM; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 32FA138837C for ; Mon, 1 Jun 2026 06:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296886; cv=none; b=e1P8ShMjdFVApPL/0vnNNzSdyFuviM88u4AUPWfK7eCqE6u90ZvthxFt+Fy97R0RlG6V2zwoZ0oQs/hpW9c9cBO52A1W/5k0mW9cIpO8pwE0AfABmJrNUxR9EmVcyPE6y6lRLIqhyAHqIgXZ8H8XVUfn2zf8VAg74q4IRgIjOTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296886; c=relaxed/simple; bh=8uoMqp0aJqUYXNK2EQueIMtfgaoPa8+9VIrvtSfSCEw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qmEhzJ/wTrBadp8IxJNbADu3n8RH++ST4AsgcwyDB80ShjYKXERYy6evRO0jnvLYJBhq9YdCJhVSKIezjofhMs/0XPZsQaIQqHIcolW4nsFPd6+UU+pQ+0F5B5TE88KYG2r8CdByj/HsLCeucYyiKerTg34Ug7F86I535LhTtVk= 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=A8g8YyMf; arc=none smtp.client-ip=74.125.82.73 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="A8g8YyMf" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1353bfdbf99so2242075c88.0 for ; Sun, 31 May 2026 23:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296883; x=1780901683; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fuHGKH4OW88soTL/FBOGBXyBBZAx32Y7kqwtbJIjGP8=; b=A8g8YyMfZBqPQabprZ/l2ebQWZk4bXjPnl/HoMAoMAwIK8n/MANjKtnRex3RSw/VhE kMMVOyC7xnBWfNpnxHuKrbF1uQjxQsm/693iT5k0gcIaP6aitUVGcm1hn/VGuPrxwEBB NwzhRPoFHs5QpS5/DU98SqnChiEfEHa5qbM1WZpo9ennzHDW3oRQix88w4iLlKn6k284 qPXcXz2BshigQgUjzV8UCAJ3TUPs8gHt+cvCTBpzcb6y1uePnM+9tPPt6rk8ivPNO8Hd hensjGdzKxphCU/4yKz44e4u6XHZPAHgilEtu2+rU9qnebktTyvYmDnY3oCDYcQKGzBc ehkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296883; x=1780901683; h=cc: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=fuHGKH4OW88soTL/FBOGBXyBBZAx32Y7kqwtbJIjGP8=; b=YbMOM31TbvNVbqRXNG6jh1vFDgJ8GXWmxJBKHDhkHgU1+zmP+T5friL559MoqfS8te ofi3oO0GyXLGcc6YyyXCbGLOGJsVOGwKkLRasmHU2KJYMvPpa41iBwsUpKsJhrNLf4wm brTty89UXzQjgaWBld+7pTA4+EQjwCVXxDHGKtNgSiiiPk1MPHua0nk+CRXgerE8wVvv GkW4YKHvNoOGxXJTG9XXIg7sKZAAlHvVPfpBAaYSKnTikQ65u8CS/PyQhZ26p9X1Rjvf 1O051Fz2wF1Y+FtwOwQ4vOiHYUS3H0nYdeYgAu+QD2S7yU4F6KmMjEQ8KjNhOq4m9Hkg R7WQ== X-Forwarded-Encrypted: i=1; AFNElJ+3NS7fKgc+fNtjagytzGNFm5AhLDEnTaiqyBZK7Rb5MewSog/kzFBiHUunv7RfDXMDyCq6hmjU7vaRsRc=@vger.kernel.org X-Gm-Message-State: AOJu0Yzyv8jOKfxnvNW55uoLa2fLqbP2cogMwS8DEClruo9sJwlPCc2G as7rfeV9rLaHFz8VBYveQr9HsSFxM2xZqo5e0OAIDTNhTpfxGJ9q68eR2H9Bf9clPvsn5jpLDCI OJkXuYG6tXw== X-Received: from dlc3.prod.google.com ([2002:a05:7022:383:b0:12d:b2ba:b551]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6299:b0:137:64ce:70cf with SMTP id a92af1059eb24-137d3697e54mr3749858c88.0.1780296883235; Sun, 31 May 2026 23:54:43 -0700 (PDT) Date: Sun, 31 May 2026 23:54:04 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-16-irogers@google.com> Subject: [PATCH v10 15/18] perf env: Remove unused perf_env__raw_arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The switch to using e_machine has made the perf_env__raw_arch function unused so remove it. Signed-off-by: Ian Rogers --- tools/perf/util/env.c | 18 ------------------ tools/perf/util/env.h | 1 - 2 files changed, 19 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 0db74ee05d08..f61e10864613 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -470,19 +470,6 @@ int perf_env__read_cpuid(struct perf_env *env) return 0; } =20 -static int perf_env__read_arch(struct perf_env *env) -{ - struct utsname uts; - - if (env->arch) - return 0; - - if (!uname(&uts)) - env->arch =3D strdup(uts.machine); - - return env->arch ? 0 : -ENOMEM; -} - static int perf_env__read_nr_cpus_avail(struct perf_env *env) { if (env->nr_cpus_avail =3D=3D 0) @@ -601,11 +588,6 @@ int perf_env__read_core_pmu_caps(struct perf_env *env) return ret; } =20 -const char *perf_env__raw_arch(struct perf_env *env) -{ - return env && !perf_env__read_arch(env) ? env->arch : "unknown"; -} - int perf_env__nr_cpus_avail(struct perf_env *env) { return env && !perf_env__read_nr_cpus_avail(env) ? env->nr_cpus_avail : 0; diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index ba51b871c401..bc4801d8399b 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -192,7 +192,6 @@ const char *perf_env__arch(struct perf_env *env); const char *perf_env__arch_strerrno(uint16_t e_machine, int err); #endif const char *perf_env__cpuid(struct perf_env *env); -const char *perf_env__raw_arch(struct perf_env *env); int perf_env__nr_cpus_avail(struct perf_env *env); =20 void perf_env__init(struct perf_env *env); --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 40913388862 for ; Mon, 1 Jun 2026 06:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296889; cv=none; b=hSxgozdjWYcTU8AN7fKAm1n6zjgnZvCazCeYt2TSkzLk7p79vgioLihyVFSkocWPfPk78teMh/cnisElOZRURi+k3nFZ0ue/f6hPv6Bn63DyWUJiqwh8D4CIpXwXK0y5gKcU8duJns2nSSZG5gfxd9o7+XLAVTQcxMyw2h7WEIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296889; c=relaxed/simple; bh=ppIZRWJCIdi0R6WxKrossCdeWWpHulk9rHQKH754pEA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WQzlUEq93kX2BGETX3vBZwgdRMEmc0+m8rIlxVYGiIWl9UNwK8jYVcFaNu4ahKEmKDBuOiJeo4FGkVh5+H3lHUxgm40wH1Ioa5WhKjzrOHnIZDwr5JI6mOwefYIR/udYIpju3I52QC7TKd5S7uR/OwIiXPq7EUOzoQaxoih0NmY= 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=ghlNsQHw; arc=none smtp.client-ip=74.125.82.73 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="ghlNsQHw" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137dd5100c7so1647425c88.1 for ; Sun, 31 May 2026 23:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296886; x=1780901686; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6O94M81hJ4N35pLsSIuLDeaMOkTmNZoPh2aSEVGaEqc=; b=ghlNsQHwX9GTXdqA8qpt95798fpEdhQsnJRg+E0OaM9iKHZ+pNOOmnWHPl8o9lweTq aFf4AN32g/2ccYG6wEsEi5L1BAA82V5NIaLWsVFFextutLMfJoFDEuHmA7z+/2G50AOx bpj7jM1H39X/MrTAqiGJHcqXyE0SAQmuMlmP5MY0zZtvn0jVhIu74BVaSsTR6VIQGf4i rOy7DQ1p26tenJum9BnCnmawaB0FRY327UmommIekIc2u8qFap7ttrhijoHPTp03kEZJ SNOzKroPqs1ki2WSIt4Jj7PRJXhAezOsDWoUuf539dq6HTRGtCCv9fpbGRtywieDcOFe OGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296886; x=1780901686; h=cc: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=6O94M81hJ4N35pLsSIuLDeaMOkTmNZoPh2aSEVGaEqc=; b=EskzcfkBeytRHrWqI6pFkJVuRikz2GbZPjRhkqFU0v88hb8dxoRHCzBwh4JnOqvbjk v/juwqdaiNBX8oF/zqg3ElQ7IrZbbagijzVRpEVWphKEN+SUu7KTGttoaZjbshTFQ/dT UPT6lUZZRWRWdLADe1s3FZlV+JZTjC6dIRwjCoRKYaoqO6gEXm37HCSVzggPBz7E0GPy vvGQYlCC23/a70xULjjecr0l7fAD/sCE0tlZX5VytXggvSxAJAbOh8jVgsVUptp5US0w e9r4xFAcohPKG4IHhW3I01vRHDDDruThXNwKXJTzxB48Ex2xCSIvOyHXL1JdRogZyZzJ 6nWQ== X-Forwarded-Encrypted: i=1; AFNElJ8b0j8TeDh8cHfR85xncrdaf0htuVauTFVk1Pi9vKM1jBDys5mOHzqZBDHEQ5FDy+Orjf1xE/sQyU8/5ho=@vger.kernel.org X-Gm-Message-State: AOJu0YyTx7ec7b7b6aw25iZiYe6r5XYbfweuTX+2876pKJi1QB5yqxqk Ra86WcLfvWLY9RobOE7ofnR+NE8kjm2gClTKQscwVTQj3uQdXPLiXqp4+6YVEE4RsrTrCDnjbjJ Cq71LHKrgHA== X-Received: from dlnn6.prod.google.com ([2002:a05:7022:6186:b0:137:e705:d11f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:497:b0:130:7246:10aa with SMTP id a92af1059eb24-137d3c0a46bmr3914743c88.12.1780296885587; Sun, 31 May 2026 23:54:45 -0700 (PDT) Date: Sun, 31 May 2026 23:54:05 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-17-irogers@google.com> Subject: [PATCH v10 16/18] perf env: Add helper to lazily compute the os_release From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In live mode the os_release isn't being initialized, make a lazy initialization helper that assumes when the os_release isn't initialized this is live mode. Signed-off-by: Ian Rogers --- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 6 ++++-- tools/perf/util/env.c | 21 +++++++++++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/header.c | 16 +++++++++++----- tools/perf/util/symbol.c | 4 ++-- 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-conve= rt-bt.c index b3f745cff2a7..cc51b8677c8e 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -1414,7 +1414,7 @@ do { \ =20 ADD("host", env->hostname); ADD("sysname", "Linux"); - ADD("release", env->os_release); + ADD("release", perf_env__os_release(env)); ADD("version", env->version); ADD("machine", env->arch); ADD("domain", "kernel"); diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-con= vert-json.c index a7da93a7ff0e..c71dfb77c697 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -16,6 +16,7 @@ #include "linux/err.h" #include "util/auxtrace.h" #include "util/debug.h" +#include "util/env.h" #include "util/dso.h" #include "util/event.h" #include "util/evsel.h" @@ -272,7 +273,7 @@ static void output_headers(struct perf_session *session= , struct convert_json *c) { struct stat st; const struct perf_header *header =3D &session->header; - const struct perf_env *env =3D perf_session__env(session); + struct perf_env *env =3D perf_session__env(session); int ret; int fd =3D perf_data__fd(session->data); int i; @@ -296,7 +297,8 @@ static void output_headers(struct perf_session *session= , struct convert_json *c) output_json_key_format(out, true, 2, "feat-offset", "%" PRIu64, header->f= eat_offset); =20 output_json_key_string(out, true, 2, "hostname", env->hostname); - output_json_key_string(out, true, 2, "os-release", env->os_release); + output_json_key_string(out, true, 2, "os-release", + perf_env__os_release(env)); output_json_key_string(out, true, 2, "arch", env->arch); =20 if (env->cpu_desc) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index f61e10864613..b4fb7420b604 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -358,6 +358,27 @@ bool perf_arch_is_big_endian(const char *arch) return false; } =20 +const char *perf_env__os_release(struct perf_env *env) +{ + struct utsname uts; + int ret; + + if (!env) + return perf_version_string; + + if (env->os_release) + return env->os_release; + + /* + * The os_release is being accessed but wasn't initialized from a data + * file, assume this is 'live' mode and use the release from uname. If + * uname or strdup fails then use the current perf tool version. + */ + ret =3D uname(&uts); + env->os_release =3D strdup(ret < 0 ? perf_version_string : uts.release); + return env->os_release ?: perf_version_string; +} + int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []) { int i; diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index bc4801d8399b..bbf10446204c 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -173,6 +173,7 @@ void perf_env__exit(struct perf_env *env); =20 int perf_env__kernel_is_64_bit(struct perf_env *env); bool perf_arch_is_big_endian(const char *arch); +const char *perf_env__os_release(struct perf_env *env); =20 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []); =20 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index ecdac427d9c4..d7f41db7322c 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -432,13 +432,19 @@ static int write_osrelease(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { struct utsname uts; - int ret; + const char *release =3D NULL; =20 - ret =3D uname(&uts); - if (ret < 0) - return -1; + if (evlist->session) + release =3D perf_env__os_release(perf_session__env(evlist->session)); =20 - return do_write_string(ff, uts.release); + if (!release) { + int ret =3D uname(&uts); + + if (ret < 0) + return -1; + release =3D uts.release; + } + return do_write_string(ff, release); } =20 static int write_arch(struct feat_fd *ff, struct evlist *evlist) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 2ce512f08a1d..077d19af5240 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2225,7 +2225,7 @@ static int vmlinux_path__init(struct perf_env *env) { struct utsname uts; char bf[PATH_MAX]; - char *kernel_version; + const char *kernel_version; unsigned int i; =20 vmlinux_path =3D malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) + @@ -2242,7 +2242,7 @@ static int vmlinux_path__init(struct perf_env *env) return 0; =20 if (env) { - kernel_version =3D env->os_release; + kernel_version =3D perf_env__os_release(env); } else { if (uname(&uts) < 0) goto out_fail; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 8C569388883 for ; Mon, 1 Jun 2026 06:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296891; cv=none; b=UQstWkF/GrwCt+Xc57gpgDDkTMGWAIYVrxx9dk8yKgUi4SS2+3HId1QLjGGvNGfCJDvufUutS04wz9e//LdMx+hle4IIoC9GkeHwvfCaJNUAkgMaESu6n2HKDuEFb2SbfIggwtEH0GXglVMdzdkEwe8hLUJKkrX81rrLrRm15C4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296891; c=relaxed/simple; bh=3tOWTkdIQ6y9A3AHCTUHvpXFj/hWjrWnaeuAAFXIj1E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Tm4pNDPifZF+mKuZleHfJCbCrnVqM5wuzvMgljS9YOVOZgU40+b17SyirMyzOo5EmsZeLvtXgrqnhUqGK4z/6NkMVfIH+hUsJZOHmPUzfTY3anZfQrtnnraNDtbPY2pDWmQkmT8Bk9zJJgKUHJJ6tR2gBtWXQiE7T7cFSmQGEtg= 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=Kk0m2Ejo; arc=none smtp.client-ip=74.125.82.73 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="Kk0m2Ejo" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1361d52b3a0so16860821c88.0 for ; Sun, 31 May 2026 23:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296888; x=1780901688; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9D9hZaJY7OUE6bHNXGDNMtwYbF4ppKbcP/Lazaf/1gw=; b=Kk0m2EjoZrGAiJvz83ClExlwaY9F64bYUj1OLmdTw5NzQXOqT76DY9Let2eH6st+O9 KZuRaDUBkdgEBk+1MT0PEE3Uy0o/2c0mG4PXNY01ejOcy+zOU0s4HpXoX8Ax/lbNY8G3 Socbp4qKv8VhdUM6hbLOSl45sJL2870nczHid0tk3Cxr9l5cnJDr8YOfXLV8voNtIsXu CrU/E/mRJkYx+LogTMsYwakwPOranbIOqNA4KozEUT//dksr2S6IZ4kc+NgUnqIb/mxK W6jhMnwT2/igTcq9YxfYceLEk7Y8AXURuY1WuUNEu3KDy42r+nFz1+LOjeCnF1Urq832 Wg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296888; x=1780901688; h=cc: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=9D9hZaJY7OUE6bHNXGDNMtwYbF4ppKbcP/Lazaf/1gw=; b=BctL4h+WHxPS09Bn6dEk9f/qbVk+XJPT3uB84ZfurbRxMTR/zmtnpntWFIh8Rx4/XX N8biKDSb3fR0naaqKSLaByl3v8lIooQ61x1hXEoWhGaso+4B4SIVJoJhlAuVKGcsUZz3 C7Ziu6iXLh2KWU8IX4I/XoKspehyTOEznT4nSQ4vl7x7BgoebLHozbH7JB5T0Szl1kn6 dkx9deH4xpsGXJLhWNFzRkAABHbZ/fd9RXNAvQ/o2lkmd9/lj6L+FP9fytsqQn2bYgSo CqfP6NivKb1CtTrLhilbIxX2HFBcGx5C/myZaoB6otfX5HDoeqbwW+DU19ULRaJcn23l X4IA== X-Forwarded-Encrypted: i=1; AFNElJ/mrX2zyh3WW8FYbPlz8z6hhTJ5IUSQFwGjAJT7Np5jyclMOELP/Slm0TNEC8PkmlcX3uJM9qNzUQEHgDo=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6XXQ53YInjWpdArAZz8QtPyLrTx57o7TGSytI9Uc777v9wcCU rxIJ6uaL3IQ0F2aEv2idWYpgqOnCaublwDtoKQquoEKxLVMyFGIChtvNUSKesYg6Ho0/sv0bThX Nw7E14IWWtQ== X-Received: from dlbut10.prod.google.com ([2002:a05:7022:7e0a:b0:135:b7ea:e2d3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e23:b0:12a:71ab:8235 with SMTP id a92af1059eb24-137d3d09572mr3542855c88.6.1780296887343; Sun, 31 May 2026 23:54:47 -0700 (PDT) Date: Sun, 31 May 2026 23:54:06 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-18-irogers@google.com> Subject: [PATCH v10 17/18] perf symbol: Add setters for bitfields sharing a byte to avoid concurrent update issues From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A problem with putting bitfields into struct symbol is that other bits in the symbol could be updated concurrently and only one update to the underlying storage unit happen, leading to lost updates. To avoid this, use atomics to atomically read or set part of 16-bits of flags in the symbol. Add accessors to simplify this. The idle value has 3 values in preparation for a later change that will lazily update it. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/builtin-top.c | 6 +- tools/perf/tests/symbols.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 2 +- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate.c | 5 +- tools/perf/util/auxtrace.c | 6 +- tools/perf/util/callchain.c | 4 +- tools/perf/util/dlfilter.c | 2 +- tools/perf/util/evsel_fprintf.c | 6 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/machine.c | 2 +- tools/perf/util/probe-event.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 2 +- .../scripting-engines/trace-event-python.c | 4 +- tools/perf/util/sort.c | 8 +- tools/perf/util/srcline.c | 10 +-- tools/perf/util/symbol-elf.c | 3 +- tools/perf/util/symbol.c | 84 +++++++++++++++---- tools/perf/util/symbol.h | 76 +++++++++++++---- tools/perf/util/symbol_fprintf.c | 4 +- 25 files changed, 175 insertions(+), 73 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d8cb1f562f69..d65bea7d081a 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -552,7 +552,7 @@ static int perf_event__convert_sample_callchain(const s= truct perf_tool *tool, if (machine->single_address_space && machine__kernel_ip(machine, node->ip)) /* kernel IPs were added already */; - else if (node->ms.sym && node->ms.sym->inlined) + else if (node->ms.sym && symbol__inlined(node->ms.sym)) /* we can't handle inlined callchains */; else inject->raw_callchain->ips[i++] =3D node->ip; diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 99dc293a0744..77e87e75613d 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -769,7 +769,7 @@ static void timehist_save_callchain(struct perf_kwork *= kwork, if (sym) { if (!strcmp(sym->name, "__softirqentry_text_start") || !strcmp(sym->name, "__do_softirq")) - sym->ignore =3D 1; + symbol__set_ignore(sym, true); } =20 callchain_cursor_advance(cursor); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 973d97af8501..b79001529d01 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -749,7 +749,7 @@ static int hists__resort_cb(struct hist_entry *he, void= *arg) struct report *rep =3D arg; struct symbol *sym =3D he->ms.sym; =20 - if (rep->symbol_ipc && sym && !sym->annotate2) { + if (rep->symbol_ipc && sym && !symbol__is_annotate2(sym)) { struct evsel *evsel =3D hists_to_evsel(he->hists); =20 symbol__annotate2(&he->ms, evsel, NULL); diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 812a1b0d56d6..b6da74c5befa 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2367,7 +2367,7 @@ static void save_task_callchain(struct perf_sched *sc= hed, if (!strcmp(sym->name, "schedule") || !strcmp(sym->name, "__schedule") || !strcmp(sym->name, "preempt_schedule")) - sym->ignore =3D 1; + symbol__set_ignore(sym, true); } =20 callchain_cursor_advance(cursor); @@ -3025,7 +3025,7 @@ static size_t callchain__fprintf_folded(FILE *fp, str= uct callchain_node *node) list_for_each_entry(chain, &node->val, list) { if (chain->ip >=3D PERF_CONTEXT_MAX) continue; - if (chain->ms.sym && chain->ms.sym->ignore) + if (chain->ms.sym && symbol__ignore(chain->ms.sym)) continue; ret +=3D fprintf(fp, "%s%s", first ? "" : sep, callchain_list__sym_name(chain, bf, sizeof(bf), diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index c8474f7ac658..35b57a831362 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -186,8 +186,8 @@ static void ui__warn_map_erange(struct map *map, struct= symbol *sym, u64 ip) "Please report to linux-kernel@vger.kernel.org\n", ip, dso__long_name(dso), dso__symtab_origin(dso), map__start(map), map__end(map), sym->start, sym->end, - sym->binding =3D=3D STB_GLOBAL ? 'g' : - sym->binding =3D=3D STB_LOCAL ? 'l' : 'w', sym->name, + symbol__binding(sym) =3D=3D STB_GLOBAL ? 'g' : + symbol__binding(sym) =3D=3D STB_LOCAL ? 'l' : 'w', sym->name, err ? "[unknown]" : uts.machine, err ? "[unknown]" : uts.release, perf_version_string); if (use_browser <=3D 0) @@ -828,7 +828,7 @@ static void perf_event__process_sample(const struct per= f_tool *tool, } } =20 - if (al.sym =3D=3D NULL || !al.sym->idle) { + if (al.sym =3D=3D NULL || !symbol__is_idle(al.sym, al.map ? map__dso(al.m= ap) : NULL, machine->env)) { struct hists *hists =3D evsel__hists(sample->evsel); struct hist_entry_iter iter =3D { .sample =3D sample, diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c index f4ffe5804f40..c09e04f36035 100644 --- a/tools/perf/tests/symbols.c +++ b/tools/perf/tests/symbols.c @@ -125,7 +125,7 @@ static int test_dso(struct dso *dso) for (nd =3D rb_first_cached(dso__symbols(dso)); nd; nd =3D rb_next(nd)) { struct symbol *sym =3D rb_entry(nd, struct symbol, rb_node); =20 - if (sym->type !=3D STT_FUNC && sym->type !=3D STT_GNU_IFUNC) + if (symbol__type(sym) !=3D STT_FUNC && symbol__type(sym) !=3D STT_GNU_IF= UNC) continue; =20 /* Check for overlapping function symbols */ diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux= -kallsyms.c index 524d46478364..7409abe4aa36 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -346,7 +346,7 @@ static int test__vmlinux_matches_kallsyms(struct test_s= uite *test __maybe_unused * such as __indirect_thunk_end. */ continue; - } else if (is_ignored_symbol(sym->name, sym->type)) { + } else if (is_ignored_symbol(sym->name, symbol__type(sym))) { /* * Ignore hidden symbols, see scripts/kallsyms.c for the details */ diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index ea17e6d29a7e..e220c4dfc881 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -1185,7 +1185,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, if (dso__annotate_warned(dso)) return -1; =20 - if (not_annotated || !sym->annotate2) { + if (not_annotated || !symbol__is_annotate2(sym)) { err =3D symbol__annotate2(ms, evsel, &browser.arch); if (err) { annotate_browser__symbol_annotate_error(&browser, err); diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c index c61ba3174a24..075a575cdc5d 100644 --- a/tools/perf/ui/browsers/map.c +++ b/tools/perf/ui/browsers/map.c @@ -32,8 +32,8 @@ static void map_browser__write(struct ui_browser *browser= , void *nd, int row) ui_browser__set_percent_color(browser, 0, current_entry); ui_browser__printf(browser, "%*" PRIx64 " %*" PRIx64 " %c ", mb->addrlen, sym->start, mb->addrlen, sym->end, - sym->binding =3D=3D STB_GLOBAL ? 'g' : - sym->binding =3D=3D STB_LOCAL ? 'l' : 'w'); + symbol__binding(sym) =3D=3D STB_GLOBAL ? 'g' : + symbol__binding(sym) =3D=3D STB_LOCAL ? 'l' : 'w'); width =3D browser->width - ((mb->addrlen * 2) + 4); if (width > 0) ui_browser__write_nstring(browser, sym->name, width); diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 470569745abe..02505222d8c2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -236,7 +236,8 @@ static int __symbol__inc_addr_samples(struct map_symbol= *ms, h =3D annotated_source__histogram(src, evsel); if (h =3D=3D NULL) { pr_debug("%s(%d): ENOMEM! sym->name=3D%s, start=3D%#" PRIx64 ", addr=3D%= #" PRIx64 ", end=3D%#" PRIx64 ", func: %d\n", - __func__, __LINE__, sym->name, sym->start, addr, sym->end, sym->type = =3D=3D STT_FUNC); + __func__, __LINE__, sym->name, sym->start, addr, sym->end, + symbol__type(sym) =3D=3D STT_FUNC); return -ENOMEM; } =20 @@ -2223,7 +2224,7 @@ int symbol__annotate2(struct map_symbol *ms, struct e= vsel *evsel, =20 annotation__init_column_widths(notes, sym); annotation__update_column_widths(notes); - sym->annotate2 =3D 1; + symbol__set_annotate2(sym, true); =20 return 0; } diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index fcf564e0d777..5f4aa1701aef 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2694,7 +2694,7 @@ static bool dso_sym_match(struct symbol *sym, const c= har *name, int *cnt, { /* Same name, and global or the n'th found or any */ return !arch__compare_symbol_names(name, sym->name) && - ((!idx && sym->binding =3D=3D STB_GLOBAL) || + ((!idx && symbol__binding(sym) =3D=3D STB_GLOBAL) || (idx > 0 && ++*cnt =3D=3D idx) || idx < 0); } @@ -2712,8 +2712,8 @@ static void print_duplicate_syms(struct dso *dso, con= st char *sym_name) if (dso_sym_match(sym, sym_name, &cnt, -1)) { pr_err("#%d\t0x%"PRIx64"\t%c\t%s\n", ++cnt, sym->start, - sym->binding =3D=3D STB_GLOBAL ? 'g' : - sym->binding =3D=3D STB_LOCAL ? 'l' : 'w', + symbol__binding(sym) =3D=3D STB_GLOBAL ? 'g' : + symbol__binding(sym) =3D=3D STB_LOCAL ? 'l' : 'w', sym->name); near =3D true; } else if (near) { diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 5c2282051e39..8981ae879ebb 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -801,7 +801,7 @@ static enum match_result match_chain(struct callchain_c= ursor_node *node, * symbol start. Otherwise do a faster comparison based * on the symbol start address. */ - if (cnode->ms.sym->inlined || node->ms.sym->inlined) { + if (symbol__inlined(cnode->ms.sym) || symbol__inlined(node->ms.sym)) { match =3D match_chain_strings(cnode->ms.sym->name, node->ms.sym->name); if (match !=3D MATCH_ERROR) @@ -1245,7 +1245,7 @@ char *callchain_list__sym_name(struct callchain_list = *cl, int printed; =20 if (cl->ms.sym) { - const char *inlined =3D cl->ms.sym->inlined ? " (inlined)" : ""; + const char *inlined =3D symbol__inlined(cl->ms.sym) ? " (inlined)" : ""; =20 if (show_srcline && cl->srcline) printed =3D scnprintf(bf, bfsize, "%s %s%s", diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index dc31b5e7149e..e11e144af62b 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -56,7 +56,7 @@ static void al_to_d_al(struct addr_location *al, struct p= erf_dlfilter_al *d_al) d_al->symoff =3D al->addr - map__start(al->map) - sym->start; else d_al->symoff =3D 0; - d_al->sym_binding =3D sym->binding; + d_al->sym_binding =3D symbol__binding(sym); } else { d_al->sym =3D NULL; d_al->sym_start =3D 0; diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprint= f.c index 5521d00bff2c..0f7a25500a44 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -146,7 +146,7 @@ int sample__fprintf_callchain(struct perf_sample *sampl= e, int left_alignment, sym =3D node->ms.sym; map =3D node->ms.map; =20 - if (sym && sym->ignore && print_skip_ignored) + if (sym && symbol__ignore(sym) && print_skip_ignored) goto next; =20 printed +=3D fprintf(fp, "%-*.*s", left_alignment, left_alignment, " "); @@ -182,7 +182,7 @@ int sample__fprintf_callchain(struct perf_sample *sampl= e, int left_alignment, addr_location__exit(&node_al); } =20 - if (print_dso && (!sym || !sym->inlined)) + if (print_dso && (!sym || !symbol__inlined(sym))) printed +=3D map__fprintf_dsoname_dsoff(map, print_dsoff, addr, fp); =20 if (print_srcline) { @@ -192,7 +192,7 @@ int sample__fprintf_callchain(struct perf_sample *sampl= e, int left_alignment, printed +=3D map__fprintf_srcline(map, addr, "\n ", fp); } =20 - if (sym && sym->inlined) + if (sym && symbol__inlined(sym)) printed +=3D fprintf(fp, " (inlined)"); =20 if (!print_oneline) diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index b8add2b20033..56a9e439f5f8 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3000,7 +3000,7 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u6= 4 *ptss_ip) start =3D dso__first_symbol(map__dso(map)); =20 for (sym =3D start; sym; sym =3D dso__next_symbol(sym)) { - if (sym->binding =3D=3D STB_GLOBAL && + if (symbol__binding(sym) =3D=3D STB_GLOBAL && !strcmp(sym->name, "__switch_to")) { ip =3D map__unmap_ip(map, sym->start); if (ip >=3D map__start(map) && ip < map__end(map)) { diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 47be7a44a5f7..da1ad58758af 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1095,7 +1095,7 @@ static u64 find_entry_trampoline(struct dso *dso) unsigned int i; =20 for (; sym; sym =3D dso__next_symbol(sym)) { - if (sym->binding !=3D STB_GLOBAL) + if (symbol__binding(sym) !=3D STB_GLOBAL) continue; for (i =3D 0; i < ARRAY_SIZE(syms); i++) { if (!strcmp(sym->name, syms[i])) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 34b4badd2c14..11ae4a09412c 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -416,7 +416,7 @@ static int find_alternative_probe_point(struct debuginf= o *dinfo, map__for_each_symbol_by_name(map, pp->function, sym, idx) { if (uprobes) { address =3D sym->start; - if (sym->type =3D=3D STT_GNU_IFUNC) + if (symbol__type(sym) =3D=3D STT_GNU_IFUNC) pr_warning("Warning: The probe function (%s) is a GNU indirect functio= n.\n" "Consider identifying the final function used at run time and set = the probe directly on that.\n", pp->function); @@ -3189,7 +3189,7 @@ static int find_probe_trace_events_from_map(struct pe= rf_probe_event *pev, for (j =3D 0; j < num_matched_functions; j++) { sym =3D syms[j]; =20 - if (sym->type !=3D STT_FUNC) + if (symbol__type(sym) !=3D STT_FUNC) continue; =20 /* There can be duplicated symbols in the map */ diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index 7a18ea4b7d50..410dc4cd0600 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -303,7 +303,7 @@ static SV *perl_process_callchain(struct perf_sample *s= ample, } if (!hv_stores(sym, "start", newSVuv(node->ms.sym->start)) || !hv_stores(sym, "end", newSVuv(node->ms.sym->end)) || - !hv_stores(sym, "binding", newSVuv(node->ms.sym->binding)) || + !hv_stores(sym, "binding", newSVuv(symbol__binding(node->ms.sym))) = || !hv_stores(sym, "name", newSVpvn(node->ms.sym->name, node->ms.sym->namelen)) || !hv_stores(elem, "sym", newRV_noinc((SV*)sym))) { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index cee1f32d7022..8f832ae316ca 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -436,7 +436,7 @@ static PyObject *python_process_callchain(struct perf_s= ample *sample, pydict_set_item_string_decref(pysym, "end", PyLong_FromUnsignedLongLong(node->ms.sym->end)); pydict_set_item_string_decref(pysym, "binding", - _PyLong_FromLong(node->ms.sym->binding)); + _PyLong_FromLong(symbol__binding(node->ms.sym))); pydict_set_item_string_decref(pysym, "name", _PyUnicode_FromStringAndSize(node->ms.sym->name, node->ms.sym->namelen)); @@ -1270,7 +1270,7 @@ static int python_export_symbol(struct db_export *dbe= , struct symbol *sym, tuple_set_d64(t, 1, dso__db_id(dso)); tuple_set_d64(t, 2, sym->start); tuple_set_d64(t, 3, sym->end); - tuple_set_s32(t, 4, sym->binding); + tuple_set_s32(t, 4, symbol__binding(sym)); tuple_set_string(t, 5, sym->name); =20 call_object(tables->symbol_handler, t, "symbol_table"); diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 90bc4a31bb55..005e7d85dc4a 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -469,7 +469,7 @@ int64_t _sort__sym_cmp(struct symbol *sym_l, struct sym= bol *sym_r) if (sym_l =3D=3D sym_r) return 0; =20 - if (sym_l->inlined || sym_r->inlined) { + if (symbol__inlined(sym_l) || symbol__inlined(sym_r)) { int ret =3D strcmp(sym_l->name, sym_r->name); =20 if (ret) @@ -536,7 +536,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol = *ms, =20 ret +=3D repsep_snprintf(bf + ret, size - ret, "[%c] ", level); if (sym && map) { - if (sym->type =3D=3D STT_OBJECT) { + if (symbol__type(sym) =3D=3D STT_OBJECT) { ret +=3D repsep_snprintf(bf + ret, size - ret, "%s", sym->name); ret +=3D repsep_snprintf(bf + ret, size - ret, "+0x%llx", ip - map__unmap_ip(map, sym->start)); @@ -544,7 +544,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol = *ms, ret +=3D repsep_snprintf(bf + ret, size - ret, "%.*s", width - ret, sym->name); - if (sym->inlined) + if (symbol__inlined(sym)) ret +=3D repsep_snprintf(bf + ret, size - ret, " (inlined)"); } @@ -1483,7 +1483,7 @@ static int _hist_entry__addr_snprintf(struct map_symb= ol *ms, =20 ret +=3D repsep_snprintf(bf + ret, size - ret, "[%c] ", level); if (sym && map) { - if (sym->type =3D=3D STT_OBJECT) { + if (symbol__type(sym) =3D=3D STT_OBJECT) { ret +=3D repsep_snprintf(bf + ret, size - ret, "%s", sym->name); ret +=3D repsep_snprintf(bf + ret, size - ret, "+0x%llx", ip - map__unmap_ip(map, sym->start)); diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index 62884428fb5a..b082178c279b 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -113,16 +113,16 @@ struct symbol *new_inline_sym(struct dso *dso, /* ensure that we don't alias an inlined symbol, which could * lead to double frees in inline_node__delete */ - assert(!base_sym->inlined); + assert(!symbol__inlined(base_sym)); } else { /* create a fake symbol for the inline frame */ inline_sym =3D symbol__new(base_sym ? base_sym->start : 0, base_sym ? (base_sym->end - base_sym->start) : 0, - base_sym ? base_sym->binding : 0, - base_sym ? base_sym->type : 0, + base_sym ? symbol__binding(base_sym) : 0, + base_sym ? symbol__type(base_sym) : 0, funcname); if (inline_sym) - inline_sym->inlined =3D 1; + symbol__set_inlined(inline_sym, true); } =20 free(demangled); @@ -440,7 +440,7 @@ void inline_node__clear_frames(struct inline_node *node) list_del_init(&ilist->list); zfree_srcline(&ilist->srcline); /* only the inlined symbols are owned by the list */ - if (ilist->symbol && ilist->symbol->inlined) + if (ilist->symbol && symbol__inlined(ilist->symbol)) symbol__delete(ilist->symbol); free(ilist); } diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 77e6dcba8fda..c5ed5e051976 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -350,7 +350,8 @@ static bool get_ifunc_name(Elf *elf, struct dso *dso, G= Elf_Ehdr *ehdr, sym =3D dso__find_symbol_nocache(dso, addr); =20 /* Expecting the address to be an IFUNC or IFUNC alias */ - if (!sym || sym->start !=3D addr || (sym->type !=3D STT_GNU_IFUNC && !sym= ->ifunc_alias)) + if (!sym || sym->start !=3D addr || + (symbol__type(sym) !=3D STT_GNU_IFUNC && !symbol__ifunc_alias(sym))) return false; =20 snprintf(buf, buf_sz, "%s@plt", sym->name); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 077d19af5240..e38aee22fe5c 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -50,7 +50,7 @@ =20 static int dso__load_kernel_sym(struct dso *dso, struct map *map); static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map); -static bool symbol__is_idle(const char *name); +static bool symbol__compute_is_idle(const char *name); =20 int vmlinux_path__nr_entries; char **vmlinux_path; @@ -163,24 +163,24 @@ static int choose_best_symbol(struct symbol *syma, st= ruct symbol *symb) else if ((a =3D=3D 0) && (b > 0)) return SYMBOL_B; =20 - if (syma->type !=3D symb->type) { - if (syma->type =3D=3D STT_NOTYPE) + if (symbol__type(syma) !=3D symbol__type(symb)) { + if (symbol__type(syma) =3D=3D STT_NOTYPE) return SYMBOL_B; - if (symb->type =3D=3D STT_NOTYPE) + if (symbol__type(symb) =3D=3D STT_NOTYPE) return SYMBOL_A; } =20 /* Prefer a non weak symbol over a weak one */ - a =3D syma->binding =3D=3D STB_WEAK; - b =3D symb->binding =3D=3D STB_WEAK; + a =3D symbol__binding(syma) =3D=3D STB_WEAK; + b =3D symbol__binding(symb) =3D=3D STB_WEAK; if (b && !a) return SYMBOL_A; if (a && !b) return SYMBOL_B; =20 /* Prefer a global symbol over a non global one */ - a =3D syma->binding =3D=3D STB_GLOBAL; - b =3D symb->binding =3D=3D STB_GLOBAL; + a =3D symbol__binding(syma) =3D=3D STB_GLOBAL; + b =3D symbol__binding(symb) =3D=3D STB_GLOBAL; if (a && !b) return SYMBOL_A; if (b && !a) @@ -227,14 +227,14 @@ void symbols__fixup_duplicate(struct rb_root_cached *= symbols) continue; =20 if (choose_best_symbol(curr, next) =3D=3D SYMBOL_A) { - if (next->type =3D=3D STT_GNU_IFUNC) - curr->ifunc_alias =3D true; + if (symbol__type(next) =3D=3D STT_GNU_IFUNC) + symbol__set_ifunc_alias(curr, true); rb_erase_cached(&next->rb_node, symbols); symbol__delete(next); goto again; } else { - if (curr->type =3D=3D STT_GNU_IFUNC) - next->ifunc_alias =3D true; + if (symbol__type(curr) =3D=3D STT_GNU_IFUNC) + symbol__set_ifunc_alias(next, true); nd =3D rb_next(&curr->rb_node); rb_erase_cached(&curr->rb_node, symbols); symbol__delete(curr); @@ -322,8 +322,8 @@ struct symbol *symbol__new(u64 start, u64 len, u8 bindi= ng, u8 type, const char * =20 sym->start =3D start; sym->end =3D len ? start + len : start; - sym->type =3D type; - sym->binding =3D binding; + atomic_init(&sym->flags, (type << SYMBOL_FLAG_TYPE_SHIFT) | + (binding << SYMBOL_FLAG_BINDING_SHIFT)); sym->namelen =3D namelen - 1; =20 pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n", @@ -345,6 +345,49 @@ void symbol__delete(struct symbol *sym) free(((void *)sym) - symbol_conf.priv_size); } =20 +void symbol__set_ignore(struct symbol *sym, bool ignore) +{ + if (ignore) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_IGNORE); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_IGNORE); +} + +void symbol__set_annotate2(struct symbol *sym, bool annotate2) +{ + if (annotate2) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_ANNOTATE2); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_ANNOTATE2); +} + +void symbol__set_inlined(struct symbol *sym, bool inlined) +{ + if (inlined) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_INLINED); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_INLINED); +} + +void symbol__set_ifunc_alias(struct symbol *sym, bool ifunc_alias) +{ + if (ifunc_alias) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_IFUNC_ALIAS); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_IFUNC_ALIAS); +} + +static void symbol__set_idle(struct symbol *sym, bool idle) +{ + uint16_t old_flags =3D atomic_load(&sym->flags); + uint16_t new_flags; + uint16_t idle_val =3D idle ? SYMBOL_IDLE__IDLE : SYMBOL_IDLE__NOT_IDLE; + + do { + new_flags =3D old_flags & ~SYMBOL_FLAG_IDLE_MASK; + new_flags |=3D (idle_val << SYMBOL_FLAG_IDLE_SHIFT); + } while (!atomic_compare_exchange_weak(&sym->flags, &old_flags, new_flags= )); +} void symbols__delete(struct rb_root_cached *symbols) { struct symbol *pos; @@ -375,7 +418,7 @@ void __symbols__insert(struct rb_root_cached *symbols, */ if (name[0] =3D=3D '.') name++; - sym->idle =3D symbol__is_idle(name); + symbol__set_idle(sym, symbol__compute_is_idle(name)); } =20 while (*p !=3D NULL) { @@ -717,11 +760,19 @@ int modules__parse(const char *filename, void *arg, return err; } =20 +bool symbol__is_idle(const struct symbol *sym) +{ + uint16_t flags =3D atomic_load_explicit(&sym->flags, memory_order_relaxed= ); + uint16_t idle_val =3D (flags & SYMBOL_FLAG_IDLE_MASK) >> SYMBOL_FLAG_IDLE= _SHIFT; + + return idle_val =3D=3D SYMBOL_IDLE__IDLE; +} + /* * These are symbols in the kernel image, so make sure that * sym is from a kernel DSO. */ -static bool symbol__is_idle(const char *name) +static bool symbol__compute_is_idle(const char *name) { const char * const idle_symbols[] =3D { "acpi_idle_do_entry", @@ -2492,6 +2543,7 @@ void symbol__exit(void) { if (!symbol_conf.initialized) return; + strlist__delete(symbol_conf.bt_stop_list); strlist__delete(symbol_conf.sym_list); strlist__delete(symbol_conf.dso_list); diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 95592779eb77..cd760f40676a 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,23 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx); #endif =20 +enum symbol_idle_kind { + SYMBOL_IDLE__UNKNOWN =3D 0, + SYMBOL_IDLE__NOT_IDLE =3D 1, + SYMBOL_IDLE__IDLE =3D 2, +}; + +#define SYMBOL_FLAG_TYPE_SHIFT 0 +#define SYMBOL_FLAG_TYPE_MASK (0xF << SYMBOL_FLAG_TYPE_SHIFT) +#define SYMBOL_FLAG_BINDING_SHIFT 4 +#define SYMBOL_FLAG_BINDING_MASK (0xF << SYMBOL_FLAG_BINDING_SHIFT) +#define SYMBOL_FLAG_IDLE_SHIFT 8 +#define SYMBOL_FLAG_IDLE_MASK (0x3 << SYMBOL_FLAG_IDLE_SHIFT) +#define SYMBOL_FLAG_IGNORE (1 << 10) +#define SYMBOL_FLAG_INLINED (1 << 11) +#define SYMBOL_FLAG_ANNOTATE2 (1 << 12) +#define SYMBOL_FLAG_IFUNC_ALIAS (1 << 13) + /** * A symtab entry. When allocated this may be preceded by an annotation (s= ee * symbol__annotation) and/or a browser_index (see symbol__browser_index). @@ -69,20 +87,7 @@ struct symbol { u64 end; /** Length of the string name. */ u16 namelen; - /** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */ - u8 type:4; - /** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL.= */ - u8 binding:4; - /** Set true for kernel symbols of idle routines. */ - u8 idle:1; - /** Resolvable but tools ignore it (e.g. idle routines). */ - u8 ignore:1; - /** Symbol for an inlined function. */ - u8 inlined:1; - /** Has symbol__annotate2 been performed. */ - u8 annotate2:1; - /** Symbol is an alias of an STT_GNU_IFUNC */ - u8 ifunc_alias:1; + _Atomic uint16_t flags; /** Architecture specific. Unused except on PPC where it holds st_other. = */ u8 arch_sym; /** The name of length namelen associated with the symbol. */ @@ -92,6 +97,49 @@ struct symbol { void symbol__delete(struct symbol *sym); void symbols__delete(struct rb_root_cached *symbols); =20 +static inline u8 symbol__type(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_TYPE_MASK) >> SYMBOL_FLAG_TYPE_SHIFT; +} + +static inline u8 symbol__binding(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_BINDING_MASK) >> SYMBOL_FLAG_BINDING_SHIFT; +} + +static inline bool symbol__ignore(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_IGNORE) !=3D 0; +} + +static inline bool symbol__inlined(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_INLINED) !=3D 0; +} + +static inline bool symbol__is_annotate2(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_ANNOTATE2) !=3D 0; +} + +static inline bool symbol__ifunc_alias(const struct symbol *sym) +{ + return (atomic_load_explicit(&sym->flags, memory_order_relaxed) & + SYMBOL_FLAG_IFUNC_ALIAS) !=3D 0; +} + +bool symbol__is_idle(const struct symbol *sym); + +void symbol__set_ignore(struct symbol *sym, bool ignore); +void symbol__set_annotate2(struct symbol *sym, bool annotate2); +void symbol__set_inlined(struct symbol *sym, bool inlined); +void symbol__set_ifunc_alias(struct symbol *sym, bool ifunc_alias); + /* symbols__for_each_entry - iterate over symbols (rb_root) * * @symbols: the rb_root of symbols diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fpri= ntf.c index 53e1af4ed9ac..4dc8d5761f52 100644 --- a/tools/perf/util/symbol_fprintf.c +++ b/tools/perf/util/symbol_fprintf.c @@ -11,8 +11,8 @@ size_t symbol__fprintf(struct symbol *sym, FILE *fp) { return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", sym->start, sym->end, - sym->binding =3D=3D STB_GLOBAL ? 'g' : - sym->binding =3D=3D STB_LOCAL ? 'l' : 'w', + symbol__binding(sym) =3D=3D STB_GLOBAL ? 'g' : + symbol__binding(sym) =3D=3D STB_LOCAL ? 'l' : 'w', sym->name); } =20 --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 06:36:13 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 1354B3812E4 for ; Mon, 1 Jun 2026 06:54:50 +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=1780296891; cv=none; b=dUiBu1Nd8+0eiSA9bN2/kTBSatq08eedyEcdFA25hBvywkeKLsMBVCzNysVTTZydUE4zdBlWA+4SrgSdBV+OBwE8oYQVPEFxN1u6OaadcVkNqYqEQqfVa2k+zYgIhui+nv7ibNoJ7ViuTPzAco99cEgM8v4Oea7e/DgiExBd1Zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780296891; c=relaxed/simple; bh=5xvAvdgKgKUSLkPUuUFXChCEQ2iZ+ze6iAflk1I66LE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I0hnA1J5Jo0sSdWH5IN5W+7RRjv2mWjlaY/j1tWlFSpqC7viGhU9mlnz1+xPwt35678l/hzZ/n/TUl1tNKOy6pOfJmFpIoiRVmMNuFq7I7u+5x+FcHmzAMm7dkpxauXi079vmuwyYuMvHM2c8CYoyPClXBMq52YGLV395/ebl50= 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=gMykhEw/; 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="gMykhEw/" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304d8613efbso4352134eec.1 for ; Sun, 31 May 2026 23:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780296889; x=1780901689; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PZU2BjldRmsZ92Fm6E3ygysEhszUk2oihyZsWsjsQ6s=; b=gMykhEw/7YXaRdz0FpV3FxEIQXf4rgGlavBwMPv6AviTAtI7tF2pCvzU3y6+oyg0CU vh/fP8oq3IXFrxDDY5HMDd3dXA99puFtX2Acnx4f3rY5fI6pOhaJCrKRSh6HJjdk6f0H LGA0ef++yrXQv+N3/VJV6p9jRBnZBh3byNNIE9w3LgDN3msGxQIkxJDNnTIxHQuaECOc Jm8PDYSYu/D1s/U7zQKPDUnaB77uEbZUB0ebwSGLjslv8s+woleespB3NHk4ivG3ab8J xeTvgAauQGKvzTV6raFYbkjkcpl2Xbsfcxgg/sApVpgtetp3yQVEI/99jCrOybXeKxeJ LBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780296889; x=1780901689; h=cc: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=PZU2BjldRmsZ92Fm6E3ygysEhszUk2oihyZsWsjsQ6s=; b=Ux9ytqR/SgdyL74ERKfEVgXqNsphmJFQFXg0VwmgMrp0sThJOxK2mm/k6PLjyCmmYy nVqKzTBfyfYaeOjDlUf1bSfBo3mU77WQkgLcOgAFlcuR51XNboSZC/cXieE77z10GoxP euEwiPRIURPklRENiOpp/NWL2EBgaP5cXf8vaIQ3OGDpbXeeCCAv6KTfnqOF00wz0Pjx yAMPSrsP2Iui7QmJc5ZFbBNuUPOYUoAUy9kvHUOO4xjnHqNjt8M8P/pwiu154ud+dmYo ZF6Q3DOTL5NbFWBaa5l3zd+LV8ggFvUPylRHMbYPBfizM2tRpLUb1OLYI045yQj3fWhN EsZg== X-Forwarded-Encrypted: i=1; AFNElJ9w7vvFGA5aAamj9Ah0LS7t5N/sdCFSRmt6KE+cHfiqNIKeuJq14gjpRc3Wr/IUcO/2zdvrVo5tBBr2Chc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/lvuPgi7ed6QRI0f2UFDKegdvV+lghF4uBNXaI1Jo+x7kHUzr JWn2DMalOuXuHpAfia0aCWgUfKQ4/E7Vd8WveZn6LkVMftOnBFIY2pV5ymNS8agFdMny0VuKAPq uWa60zm8a7g== X-Received: from dycnb7.prod.google.com ([2002:a05:7301:b07:b0:304:d169:68d5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6427:b0:304:5db8:da95 with SMTP id 5a478bee46e88-304fa67ad4amr4275671eec.23.1780296889103; Sun, 31 May 2026 23:54:49 -0700 (PDT) Date: Sun, 31 May 2026 23:54:07 -0700 In-Reply-To: <20260601065407.1597927-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: <20260503002248.1040791-1-irogers@google.com> <20260601065407.1597927-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601065407.1597927-19-irogers@google.com> Subject: [PATCH v10 18/18] perf symbol: Lazily compute idle From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, jameshongleiwang@126.com, japo@linux.ibm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, sumanthk@linux.ibm.com, tmricht@linux.ibm.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from an idle boolean to a helper symbol__is_idle function. In the function lazily compute whether a symbol is an idle function taking into consideration the kernel version and architecture of the machine. As symbols__insert no longer needs to know if a symbol is for the kernel, remove the argument. To protect against drop-filtering of legitimate setup, online, or hotplug management functions (such as intel_idle_init), x86 matches are strictly constrained to exact known run-loops (intel_idle, intel_idle_irq, mwait_idle, mwait_idle_with_hints). If the target environment OS release is unresolvable (such as on guest traces), default to treating psw_idle as idle to prevent false negatives and match legacy trace behavior safely. This change is inspired by mailing list discussion, particularly from Thomas Richter and Heiko Carstens : https://lore.kernel.org/lkml/20260219113850.354271-1-tmricht@linux.ibm.com/ Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/util/symbol-elf.c | 2 +- tools/perf/util/symbol.c | 141 +++++++++++++++++++++++------------ tools/perf/util/symbol.h | 8 +- 3 files changed, 99 insertions(+), 52 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index c5ed5e051976..186e6d92ac3d 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1734,7 +1734,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, =20 arch__sym_update(f, &sym); =20 - __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); + __symbols__insert(dso__symbols(curr_dso), f); nr++; } dso__put(curr_dso); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index e38aee22fe5c..59d814193909 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -50,7 +50,6 @@ =20 static int dso__load_kernel_sym(struct dso *dso, struct map *map); static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map); -static bool symbol__compute_is_idle(const char *name); =20 int vmlinux_path__nr_entries; char **vmlinux_path; @@ -379,7 +378,7 @@ void symbol__set_ifunc_alias(struct symbol *sym, bool i= func_alias) =20 static void symbol__set_idle(struct symbol *sym, bool idle) { - uint16_t old_flags =3D atomic_load(&sym->flags); + uint16_t old_flags =3D atomic_load_explicit(&sym->flags, memory_order_rel= axed); uint16_t new_flags; uint16_t idle_val =3D idle ? SYMBOL_IDLE__IDLE : SYMBOL_IDLE__NOT_IDLE; =20 @@ -401,8 +400,7 @@ void symbols__delete(struct rb_root_cached *symbols) } } =20 -void __symbols__insert(struct rb_root_cached *symbols, - struct symbol *sym, bool kernel) +void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym) { struct rb_node **p =3D &symbols->rb_root.rb_node; struct rb_node *parent =3D NULL; @@ -410,17 +408,6 @@ void __symbols__insert(struct rb_root_cached *symbols, struct symbol *s; bool leftmost =3D true; =20 - if (kernel) { - const char *name =3D sym->name; - /* - * ppc64 uses function descriptors and appends a '.' to the - * start of every instruction address. Remove it. - */ - if (name[0] =3D=3D '.') - name++; - symbol__set_idle(sym, symbol__compute_is_idle(name)); - } - while (*p !=3D NULL) { parent =3D *p; s =3D rb_entry(parent, struct symbol, rb_node); @@ -437,7 +424,7 @@ void __symbols__insert(struct rb_root_cached *symbols, =20 void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym) { - __symbols__insert(symbols, sym, false); + __symbols__insert(symbols, sym); } =20 static struct symbol *symbols__find(struct rb_root_cached *symbols, u64 ip) @@ -598,7 +585,7 @@ void dso__reset_find_symbol_cache(struct dso *dso) =20 void dso__insert_symbol(struct dso *dso, struct symbol *sym) { - __symbols__insert(dso__symbols(dso), sym, dso__kernel(dso)); + __symbols__insert(dso__symbols(dso), sym); =20 /* update the symbol cache if necessary */ if (dso__last_find_result_addr(dso) >=3D sym->start && @@ -760,55 +747,117 @@ int modules__parse(const char *filename, void *arg, return err; } =20 -bool symbol__is_idle(const struct symbol *sym) -{ - uint16_t flags =3D atomic_load_explicit(&sym->flags, memory_order_relaxed= ); - uint16_t idle_val =3D (flags & SYMBOL_FLAG_IDLE_MASK) >> SYMBOL_FLAG_IDLE= _SHIFT; - - return idle_val =3D=3D SYMBOL_IDLE__IDLE; -} =20 /* * These are symbols in the kernel image, so make sure that * sym is from a kernel DSO. */ -static bool symbol__compute_is_idle(const char *name) +static int sym_name_cmp(const void *a, const void *b) +{ + const char *name =3D a; + const char *const *sym =3D b; + + return strcmp(name, *sym); +} + +static bool match_x86_idle_routine(const char *name, const char *base) { - const char * const idle_symbols[] =3D { + if (strstarts(name, base)) { + size_t len =3D strlen(base); + + if (name[len] =3D=3D '\0' || name[len] =3D=3D '.') + return true; + } + return false; +} + +bool symbol__is_idle(struct symbol *sym, const struct dso *dso, struct per= f_env *env) +{ + static const char * const idle_symbols[] =3D { "acpi_idle_do_entry", "acpi_processor_ffh_cstate_enter", "arch_cpu_idle", "cpu_idle", "cpu_startup_entry", - "idle_cpu", - "intel_idle", - "intel_idle_ibrs", "default_idle", - "native_safe_halt", "enter_idle", "exit_idle", - "mwait_idle", - "mwait_idle_with_hints", - "mwait_idle_with_hints.constprop.0", + "idle_cpu", + "native_safe_halt", "poll_idle", - "ppc64_runlatch_off", "pseries_dedicated_idle_sleep", - "psw_idle", - "psw_idle_exit", - NULL }; - int i; - static struct strlist *idle_symbols_list; + const char *name =3D sym->name; + uint16_t e_machine; + + { + uint16_t flags =3D atomic_load_explicit(&sym->flags, memory_order_relaxe= d); + uint16_t idle_val =3D (flags & SYMBOL_FLAG_IDLE_MASK) >> SYMBOL_FLAG_IDL= E_SHIFT; + + if (idle_val !=3D SYMBOL_IDLE__UNKNOWN) + return idle_val =3D=3D SYMBOL_IDLE__IDLE; + } + + if (!dso || dso__kernel(dso) =3D=3D DSO_SPACE__USER) { + symbol__set_idle(sym, /*idle=3D*/false); + return false; + } + + /* + * ppc64 uses function descriptors and appends a '.' to the + * start of every instruction address. Remove it. + */ + if (name[0] =3D=3D '.') + name++; =20 - if (idle_symbols_list) - return strlist__has_entry(idle_symbols_list, name); + if (bsearch(name, idle_symbols, ARRAY_SIZE(idle_symbols), + sizeof(idle_symbols[0]), sym_name_cmp)) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } =20 - idle_symbols_list =3D strlist__new(NULL, NULL); + e_machine =3D env ? perf_env__e_machine(env, NULL) : + (dso ? dso__e_machine((struct dso *)dso, NULL, NULL) : EM_NONE); =20 - for (i =3D 0; idle_symbols[i]; i++) - strlist__add(idle_symbols_list, idle_symbols[i]); + if (e_machine =3D=3D EM_386 || e_machine =3D=3D EM_X86_64) { + if (match_x86_idle_routine(name, "intel_idle") || + match_x86_idle_routine(name, "intel_idle_irq") || + match_x86_idle_routine(name, "intel_idle_ibrs") || + match_x86_idle_routine(name, "mwait_idle") || + match_x86_idle_routine(name, "mwait_idle_with_hints")) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + } =20 - return strlist__has_entry(idle_symbols_list, name); + if (e_machine =3D=3D EM_PPC64 && !strcmp(name, "ppc64_runlatch_off")) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + + if (e_machine =3D=3D EM_S390 && strstarts(name, "psw_idle")) { + int major =3D 0, minor =3D 0; + const char *release =3D env ? perf_env__os_release(env) : NULL; + + /* + * If we can't determine the release (e.g. unpopulated guest traces), + * default to idle. + */ + if (!release) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + + /* Before v6.10, s390 used psw_idle. */ + if (sscanf(release, "%d.%d", &major, &minor) =3D=3D 2 && + (major < 6 || (major =3D=3D 6 && minor < 10))) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + } + + symbol__set_idle(sym, /*idle=3D*/false); + return false; } =20 static int map__process_kallsym_symbol(void *arg, const char *name, @@ -837,7 +886,7 @@ static int map__process_kallsym_symbol(void *arg, const= char *name, * We will pass the symbols to the filter later, in * map__split_kallsyms, when we have split the maps per module */ - __symbols__insert(root, sym, !strchr(name, '[')); + __symbols__insert(root, sym); =20 return 0; } diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index cd760f40676a..a71525335703 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -28,6 +28,7 @@ struct map; struct maps; struct option; struct build_id; +struct perf_env; =20 /* * Ignore kernel mapping symbols, matching kernel is_mapping_symbol() logi= c. @@ -75,7 +76,6 @@ enum symbol_idle_kind { #define SYMBOL_FLAG_INLINED (1 << 11) #define SYMBOL_FLAG_ANNOTATE2 (1 << 12) #define SYMBOL_FLAG_IFUNC_ALIAS (1 << 13) - /** * A symtab entry. When allocated this may be preceded by an annotation (s= ee * symbol__annotation) and/or a browser_index (see symbol__browser_index). @@ -133,7 +133,7 @@ static inline bool symbol__ifunc_alias(const struct sym= bol *sym) SYMBOL_FLAG_IFUNC_ALIAS) !=3D 0; } =20 -bool symbol__is_idle(const struct symbol *sym); +bool symbol__is_idle(struct symbol *sym, const struct dso *dso, struct per= f_env *env); =20 void symbol__set_ignore(struct symbol *sym, bool ignore); void symbol__set_annotate2(struct symbol *sym, bool annotate2); @@ -217,7 +217,6 @@ int filename__read_debuglink(const char *filename, char= *debuglink, size_t size); bool filename__has_section(const char *filename, const char *sec); =20 -struct perf_env; int symbol__init(struct perf_env *env); void symbol__exit(void); void symbol__elf_init(void); @@ -257,8 +256,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct= symsrc *ss); =20 char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name= ); =20 -void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym, - bool kernel); +void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym); void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym); void symbols__fixup_duplicate(struct rb_root_cached *symbols); void symbols__fixup_end(struct rb_root_cached *symbols, bool is_kallsyms); --=20 2.54.0.823.g6e5bcc1fc9-goog