From nobody Mon Jun 8 04:15:15 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 ABF703A71B6 for ; Tue, 2 Jun 2026 06:25:14 +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=1780381517; cv=none; b=BSoBeKYnUeg577GwlU9fWdtuUG8NRYmBfBYaZblR4KaBPW7foXpc6znrhRPnRnrDj9f8Tw0wRRAWMcF7/60J9Zy2DDyFbFvEYB/wAsIgHQFsk1JrGQKpPv5PPuk7ZQuRaNS0Fm5oD7cDbhCTgvDQjT81WHZ6YvHat7GbwsK+bJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381517; c=relaxed/simple; bh=u7c9g9Q86wywE0esgfVk6mGtB1xAEG3jjpKJRDS8jao=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dzxLqGdXD+z6ZgEUEFYQJ2A/wIw8AW7ij6UXUSSgS6x5SXlrxq2CLhjJUdUbabcMG7UNTavplYZAKY89g7bwyDW2OHV+erwBj9AJZvDFx10NqJyci5m1u87MHtWVrOw3iKCXAEmBX1h+SGKEoduC1CLwn0G4x+l8qgiWWVuCnWs= 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=gC9AC2iO; 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="gC9AC2iO" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-135f2aa4742so8124555c88.1 for ; Mon, 01 Jun 2026 23:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381514; x=1780986314; 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=NAp5/4oVpEVueI41uYe2KoxBgXwZNMSEVO0HVMFnuUY=; b=gC9AC2iOsdjKQYJ0o3jnGXIljBP7Yp0U3ub7vEKZSq/TLlbRzqfU0KBt4woRzASZMp pvCud+0hoe0f/Ka8LOjYg7bvDIvmDpRibEad1QAXib9V7a4TJ5w/l5wqMeGRWJqd3QAY yoRvFLDou+x8in3FL6/a3CQDu7guLzHePGNrd0RkiMx1yzkWvQR/VvHrywJiYK7D65Z2 E0iE9zIO5OvX3XjH7BtwoQinoRDJcmXp817LPofp+k+KBvBrDrEj/Y+R5RAQFl1bWgE3 9MM/YxlNhFCRSgfhEB3vACDWdIML41+yivGvDBoA4auP2ZYbLfziRKHUzDjx0Y5564dd tYwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381514; x=1780986314; 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=NAp5/4oVpEVueI41uYe2KoxBgXwZNMSEVO0HVMFnuUY=; b=jmWMJu3rKep5NCke1OSzMEFvF/0b9gTh6J2Fd/Ga0GJ/zNZSma+JNYCcE+I4uOhi9E ynUw4gYKJdbonUooGENH5fgruThNR+FnpRJ1lK29jJtQbOGizPlMX8WyhftkMTuCsGtx BECptlvhAdIbL2cEHK9bVc8lNjuaGObNes4cfE781IQvyWophhN3hkek25CV8h75qrgD RExi8jHHKzJnTdCXWzZbNKVcgI1GJMn6SCvzzQ6T6RLYl/guwh00DnskZRkm7JJbgE2D j5EarB4taUNcHbCEbkOX/2KPv7s0v7sBXgMzXct4inD7iSLrADkwkViwQKo3CKdSnSJu NVFQ== X-Forwarded-Encrypted: i=1; AFNElJ/PgWQfEfd/D66an+/B/meT/7Ikb4oKFO7e7oiZcUeUswOwoDFp4rJEaa1tj8woz14Lyk+ekRyoLqttGKA=@vger.kernel.org X-Gm-Message-State: AOJu0Yye3As+1eivKImzJhBsCrKo0M09w5PyYJj0e/cBEH7PPATFsmhL rjdPFGnNTQr0kArYg0Pb7bvUG5vPHuI6bR8YnCw/XEux6aACmD52KU7q7ONUaq4udaT+3/aODNH T6pZQQTKFyg== 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:527:b0:132:f27:5302 with SMTP id a92af1059eb24-137d3f1828amr5925719c88.3.1780381513567; Mon, 01 Jun 2026 23:25:13 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:33 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-2-irogers@google.com> Subject: [PATCH v11 01/19] 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 | 286 ++++++++++++++++++++++++++++++++------ tools/perf/util/env.h | 2 + tools/perf/util/header.c | 32 +++-- tools/perf/util/session.c | 26 ++-- 4 files changed, 282 insertions(+), 64 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 20953ef7b9d8..0cd23b5fc651 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 (strstr(arch, "64") || strstr(arch, "s390x")) + 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,237 @@ 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"; +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); =20 - return arch; + 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_X86_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; =20 - return normalize_arch(arch_name); + 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); + } + + /* + * 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"; + + return 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 7C6563A75B1 for ; Tue, 2 Jun 2026 06:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381518; cv=none; b=M3xEU3tJBeIwNL/JtKANzf8PBvF7DHlORMs2YTwJo4nkooFD0u5uY/wDrZu9A6xRNXEr1j6Rnrnt1QpK82hsO3JmKYpXF+8enTr2gTFi6IXILedrPxO5LxzsBGv+ZUIF/OB+88IIaqBSJgKmHuk52eaVBAtJl2KERwHN4DEPUb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381518; c=relaxed/simple; bh=N60q5hQpJzgcj0gMAcG8lAo3SHZ3TJCXTm5Qt0ml33o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WevZKNFsA8F4EdPLRzJ2X2xCFKZgiumhzrSvECsai8/4kRSov51PUV2b7OpcTQEYsq689OXi+Jr9/BZqWjZGgFc4MSWLYYPyOOKJjh9S7+CtjR9aM+jd6Q0XjPMuLqLnBlE7FBakzydI8J1Ww+Cr77OICPdgQ2YjK4vHOgK9IEA= 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=v8CvCraB; arc=none smtp.client-ip=209.85.214.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="v8CvCraB" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2c0c32faa62so40455065ad.2 for ; Mon, 01 Jun 2026 23:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381516; x=1780986316; 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=E6fn3ycVGPkqm/HwQfVKkDuGLWZA0DVIOGZWD1+VZ2w=; b=v8CvCraB8D4PdTshoGoVd5mGBcvXtaWaJktnijPXVVEwLjRNmgZOYUquMo/4GEcjp+ BTydK+TsnElNZzHWEtdYWlPzVji8Y6IRe4E1g6KR418FMjYGvVev/WjCJgD+oMq4plgc 9ByQ5x7ue4e8m+gt5EieGtFhnXVPDdo5+6iNdleLVXZvB3gNfkkmqgFseX1/VGg3ekiy wFC9xpuWgmk6L7VY9IKukcBuS+dJi/4EOKvYt8u0AAVuk+DxDSUEXwGFfsufzcYU9TN9 8Fj/gmBZD3WfywdLSkx7lKfjWdnFQ91vRLIYRUVlOMTciDtnRuG39U/zkHj5GK2gg+wb okag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381516; x=1780986316; 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=E6fn3ycVGPkqm/HwQfVKkDuGLWZA0DVIOGZWD1+VZ2w=; b=Ka0LOxD+pDdzmCQi3CWROjoeKaP4i1hbUCa8/FF69YqOSqzjjedvrEG7IA7PBKnEsS 6kNHSrQzTw9rnSRKoHhn2Nq0BjwY16aseBVj3BxF8kaYgE2395VtAdcxGBkjazOnY48C KFnQmNNqhB8nQQ7NKIg+jTrnA79Qt5yGeLZYXZN5QwHHHDf0h3G1o4/XdVsmoVrSEuwH u0aFpZ6KsAerIIpBD7sNemHJpk/HzqZGaZksmDHI1K6efIt/BlPcrXekTpqPDffIpxzi IjIy4zsgkDhAjrpHrr0wANEaDoj29o8WSW/fP139iXbmCdSmCWrIR84XtKLvNXXnbXwK SuqQ== X-Forwarded-Encrypted: i=1; AFNElJ9KHJtXKEpdZ3yTEO3+CrMO11WQH9f9yCbnr8GdP7ABtVDJS4XHFyy78eyFp73uP0PytyQw5ZPVNam0RLA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywt6MiVq7vrXyWaYViw9yNP3Aaa2/CPMRpQnSqRM/mnmqFJG76F BeV2C8GHePb+0/wqRmyS/X5kdZKBlO9lYNZ9O4PuQakI8m8K/B0xAI+qgR8dINEAf3A7CJvRVCm FzoAvJS/hfA== X-Received: from plbkv3.prod.google.com ([2002:a17:903:28c3:b0:2c0:b770:dcd7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc87:b0:2bf:372f:12c with SMTP id d9443c01a7336-2bf372f02e7mr160363465ad.26.1780381515609; Mon, 01 Jun 2026 23:25:15 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:34 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-3-irogers@google.com> Subject: [PATCH v11 02/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 6D97B3A7193 for ; Tue, 2 Jun 2026 06:25:18 +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=1780381520; cv=none; b=Suudt1Er2Crh2EJKO0wcPFeo2yttlg74hpxrhZQ3TE+DAB/7O8KsA7KqviMZn57q0qgPVacSGzmYzKbVms/AjrNz8p++NATNv6wA7pdOIjA6s70mXaD8oMVQTHSv7Cgx4JSj8wCv6S8Qiv2AnsFlKgbXa+lelmIqHFHxvPzGtAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381520; c=relaxed/simple; bh=azv2pBu2JzgGiyYsHqFDUXP8g7tfdhTUd7ip2wDqkv4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vA6E0hqP+BF/fOdXlVhpQP4d+BXO/OpkDZiNmfg56LFHktIVQ3iFLGYfp9zOaMfAvDcea9BghREgKbLe0dguQdj0DRMxUyVrnRTVs1HQvJFsemcHxJ+RIiQuoI4o8Iz4mm0a1I7WuAlMA5GHO5r+O3KpQsphvjec2u1Ab6k5vTo= 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=QHsqRqQD; 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="QHsqRqQD" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304f23c55b2so3584638eec.0 for ; Mon, 01 Jun 2026 23:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381517; x=1780986317; 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=k0xbxLEfFS6BKwiC2R63DBW2gx2OwZfI2gcRMPfbI9Q=; b=QHsqRqQDQLpAS7R6+z4dkeJY5dYYHknP6dRi1GFToADn5vWfQv6xnDsGCrq6CFkdza LQzAVAiz8qBSz+Y388/mYzq2Y6CtXiWSBQAl+EYGX9PapYfWALIKiDw743ELRQ2mVNrB PMXAmgoWLpsKB5txOPkmqtTBkZtNgz9euyKwX50XeEmNL9kHwSOZVTrIfEDeXz/ezuUW X33SiBcwr0xMdV9xjw01ikSiXj3B9deHs5lIME3tff4KKHfzVTo3LyIru1wVR+HLjCX7 4uSx8F7ozRZQJmdjAycm5wkK1nUGBtNlN8SA4pKkc/kqVuIyrSn2gYLMIJ8CGqSS+8XM 0ujg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381517; x=1780986317; 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=k0xbxLEfFS6BKwiC2R63DBW2gx2OwZfI2gcRMPfbI9Q=; b=iq4wA5kMSpBzOazGIEbX5+buqX+sTDjJAuc93+Tu/mde2QZ9tBUPSSNX2frn53mZk4 NA1Xv2kB4CmN+g7yYHmqfSwhKKrCGTig7NwHjGgyvT5ICobZWHABbY9hSjoljrrJ2Pzf YkSlw2kVl2lXjr61TzL9fJ41UkJLfxbWexkvYRKmNtII82wZRGavAWN/OqmHQykYrszH pUJBzwSxZuVZPgCpt5WN3Ji++FlAm5p6sHnovXQ3BE9ggKqkQ/Kzg4lFom71nB9KBQ50 4JHqbyFMqwrLuf5qlUw7mkodvr3oCqH/SyNbYv9XWNlayHVHUymJrJC2iJ4x8D48c+aG MCwg== X-Forwarded-Encrypted: i=1; AFNElJ9yNJhDGkKEw+J/ToB913RXmLhMUetKtu1YaM8MHC31CNvVEQExO5fXrSyq9kafuZbd8/b13+NoiKhfL6o=@vger.kernel.org X-Gm-Message-State: AOJu0YyzGBjSnOMYJ4L4wni7sZEdiIisqcvB+DCW+DFnRJ3QOGuL6gTw EVP44Irs7h6HZqUeYcgNl7KSk7pelNJbV7trb1mYqPA60QUUi3WfZNuye+SApA7nn01jInD2ETg /jysGkaPaKw== X-Received: from dlbuu12.prod.google.com ([2002:a05:7022:7e8c:b0:135:da3e:b81]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f502:b0:137:ddaf:7e89 with SMTP id a92af1059eb24-137ddaf7f47mr2527507c88.15.1780381517292; Mon, 01 Jun 2026 23:25:17 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:35 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-4-irogers@google.com> Subject: [PATCH v11 03/19] 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 | 58 ++++++++++++++++++++++++++++++---------- tools/perf/util/thread.h | 23 +++++++++++++++- 6 files changed, 108 insertions(+), 23 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 0cd23b5fc651..fae70b07ba8d 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..ba33c0dfc18f 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,38 @@ 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( + machine && machine->env ? perf_env__arch(machine->env) : 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 +500,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 +508,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 +534,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); + thread__set_e_machine(thread, e_machine); + 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 06CE33A785D for ; Tue, 2 Jun 2026 06:25:19 +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=1780381521; cv=none; b=L8N24OFIDUeU5NqobX9nKnAyOaGQwB0N7r1U1AwE24xbkthKQmF1ZcOfITPsfpDuiQk7ipHk2qOFmIpbkD/eLPThq98XsKyPUzaSQzC/eJj1iGhFYGvxFfAw+mZz3mOoI3MDRTohMkw1jRFfb+hVcd3zhai1e/ExWsODXe71IzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381521; c=relaxed/simple; bh=v2jPVgU7NcmbpJgeZh9blErLQKEVvFwnJwLEwzd0nZY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AyqfmVu4kCsuLo/4VzrEVpFhm16YM48Z+Upb/jMr8MWND5Aggk04t+n1f5qK+C83kdxi3aopoYuWhS9VSL7iJYdFX0yrp9nEfRSqxY3aMcSR0mtrHw8ilIq0L7A5oRGYlkSS+5OqrEZJ8LI5Y7xUGb16jpsXW8gb6B5ibwKZ8Qc= 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=QCdQqVSm; 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="QCdQqVSm" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304b8d0ee63so8931193eec.0 for ; Mon, 01 Jun 2026 23:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381519; x=1780986319; 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=GulsNcduO8h3GBAwGX8U7EGxU2yFd28SwAXlNyW06wQ=; b=QCdQqVSm70jA43AKH9Il+6QwSvlj+w3N4CYX792i6EKDFsH6/Umr2ZVoN4qV3eQKT+ pZoIa/wlI0WqbowabZwXkBu1ofoRw1VEsUkO2AByVm+2OggasUMoDJAdP4IJZo4tBg0x 3JsLX0GyF4FLhK8REZvXGchWSD8DXj8RuWCqsjjh+YmXEc/9B4++WC39UPSikSXZ428/ TMqgN5/8fM1iidnjay6CI6LgKZaIgE6Uwdvj+OUaA3jGetVt8XLagBoX/onyIG/PyEn4 oli3z4GZpBQGP/s5c8DaV09A07o8mUQbuscwbF+z1og/Rs1X15F+JUEq1vmH5AM6VsdX Wf2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381519; x=1780986319; 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=GulsNcduO8h3GBAwGX8U7EGxU2yFd28SwAXlNyW06wQ=; b=qRnL6n/amYJSzYQr91JSoBvwGbQqrRZH6++GOiFafFWHZXmGH0R4a/tlhkl/p99ytt +Mq9LVjc+b268iZSYPOzVREc88EcgYSO2M1dhdzGIhTTAECHeap6riCNXtmCKNuS8PUD s7i8iwMumFdqgJloN19O/D9nn768W1p2YcSHL48UIm8jGPa1OxO27wO53FxkPH964m/n /XSwPABxNwSOp+VxFu8uKIa5VzaRVIm/uPiIWu2RZV8DE3wVZqF+QBP1aOLALT5VGs7V rt1jhKoQcCLAXja1BeCSqeMsRZG3kqsgsbkOcZv3Hu5fbdUKlYknpGt04YtMkD2oTsUa HxsQ== X-Forwarded-Encrypted: i=1; AFNElJ+PHgAb4fn/ntepIKj04Uqy5OgduoqoekCCbd5tzdBVhDujdBSv9hbHyqG/cPRW/bKUo0uImpKKl82zctg=@vger.kernel.org X-Gm-Message-State: AOJu0YyxHZWj8/b3X7n7F8yM3Q296VZ0DqfdCsVipmEGzzXxifl1iFAb lEHhGNqdrNblojb6Qujm2BbQ/ofcMBAnUqxQQUrNrgaTLrlnKYXeUaLpmjhiqd6kAMtecICYhRx 2b0ZXwIXF1A== X-Received: from dycui22.prod.google.com ([2002:a05:693c:6016:b0:304:ddaa:acd5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:e683:b0:304:d8e2:3c4d with SMTP id 5a478bee46e88-304fa61a258mr5764207eec.25.1780381519005; Mon, 01 Jun 2026 23:25:19 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:36 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-5-irogers@google.com> Subject: [PATCH v11 04/19] 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..5ad537fea436 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) | CS_MODE_RISCVC; + 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 B7DF933B6FB for ; Tue, 2 Jun 2026 06:25:21 +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=1780381525; cv=none; b=puXNOP2cFK8//vS8aN6ioZttgKfp0GOJ2zBv0LCmqOd5jMUGxL9p9DOhnq2T3TdZLDroQng58e9hA/GHBTEKYimUR6jvaAINg/QZd1gfgCOSxMUyZMkrTmNK8plOWpsM4jDJQoVcj5NlyJZL0BEzeLULcqE1wzQFvQnK1ooBkio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381525; c=relaxed/simple; bh=Hot18PBTr0xlrnqsGHwaghakJVRFa4BOmAiFycM1yig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dVbUi4CG7lmmTZEadDedYH5htswnhHH+XfgbE6cybrGVWq/OwfwsI/TEg3P4aDF09xJs4Jl+Fb8TPb7LV4FJ7Pe00/K4BRMozC5B3bp0gD5FqxjlG4vD//2ei6o3btSbOY+y768mMh5bIuE/fwRi6wRAVl237MqQpnHnOTeWH/k= 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=R8lCBVQF; 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="R8lCBVQF" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137f2083280so51120c88.1 for ; Mon, 01 Jun 2026 23:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381521; x=1780986321; 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=/EoAq3VzUdAcwStCvHawZbW5RNzlYMnSm/cb/ao/L3Q=; b=R8lCBVQFs3MuX105/x+grWR17I9bYx/XpEZc+qNcucHlQGFk357xaCPEEdXL5c1Kuf ROx7J9YWEZZFMWcFmVlyUoIYh2ossySjiIPTmWxSun1GahTKTj0aiNu6T7Syb+Sa5uGR 759jldXok0u9KbucE53tgCVevDsdx9GMTGHR21AVotWs+lANs7u4NpHt2MWKEfyjc2Na RIET7xInxmWayDLMl4rA1PmlzAK+ZS/08SdVZgJaVc4ubfWBo2W1hVXOKRRAaPD61u2h 3mItux04AFSdZe82NjsC9MOjPuD4o5Pw61vgIIZSqY0wj6NtGDf2EySZv4f8lKga2wRW +SKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381521; x=1780986321; 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=/EoAq3VzUdAcwStCvHawZbW5RNzlYMnSm/cb/ao/L3Q=; b=OmA5tSf3Wrz8Vms7oSFMtTHuIYdMuZz8haydxuqaRePztki365WJgfgyY3UlM1rbWp qtN5CBkMYrVnWscsHWdmEU7C2CRjgeY2Vc+FfZJaAe3FoRtFpfZMO1vo9RLih0IE1x0H yFFcw8cOwfU4g9puf8YCEqCooIKt2JJoiQ0JRE8k5rrQXF18+g7NNlTimEKaD8ikCrrs xdmHLKsAnW7fZkB2PxZ9sRgub06qxA3pkZWIz//GfJkoiujD/jQh+HVq938ZvcHaM6hT WAKeDvFVwywrTEo597c9VT+PMHMujDw6XGWafum5tcusfmeEQj0gWoV7ZyWxGPACyCoD Qz+A== X-Forwarded-Encrypted: i=1; AFNElJ9denuXRqsp6f77nkNhFsfViKFWfgqEDIo8ZnDldQbMzdIzsH56julRo6J0+MINr+kdbpQmtoShhsFy7Y4=@vger.kernel.org X-Gm-Message-State: AOJu0YyGZqF7sSeMcnlco0to+J9PgcG+WyzV2u/KFTdN8JZ/Gs9zZVR/ 6sToLiLIDQBbF8yYBJd56i1zR/U1J+dox3siCfbpJQzKo/Y30bLgVzOH/xZdJtTcvZBUpxt3itu Q6orAkiW1Tg== X-Received: from dlbrh17.prod.google.com ([2002:a05:7022:f311:b0:136:7c75:5916]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:421:b0:136:d421:9efa with SMTP id a92af1059eb24-137d425e193mr6582863c88.32.1780381520724; Mon, 01 Jun 2026 23:25:20 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:37 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-6-irogers@google.com> Subject: [PATCH v11 05/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 D6B193A7597 for ; Tue, 2 Jun 2026 06:25:25 +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=1780381529; cv=none; b=Ud8X2SdZP7n1XcfqLyl1BhZJj2j9txigVWYL67GDCvQphKPwixC88uAUeG9rexQAn3dA3EEegkQYY6RS+de/q/yl+ljuyYwnIqUxJsxUgipfac/3Of8x/O6Ean5anLGLN4jj2CIqdBltmzrdLqwJ+ZVIRetbUP2LVEsObOk+gLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381529; c=relaxed/simple; bh=0E8FGILepgrTA6ONyBxd8a3wp5kiZDScmQzg7pssilk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C3sbnK8i+tAOac/jOSqny9c5NDvS0aJRSHsgYkRsvI7OjPduogPH8QnBDqrrzLMRdEKRdXQ4Wcrf131ftbJCAnj563Gp5fVRUsotscOlb5ulhMlvHsKXosJY+lkLiuv0VAgZCkOijyF7QsOAKExtY5blvD0+LcVKcwLwt8LP1Ls= 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=Encjqj4Z; 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="Encjqj4Z" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1361d52b3a0so18745794c88.0 for ; Mon, 01 Jun 2026 23:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381523; x=1780986323; 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=/QgB1qOgUmUCrnPstfXNyo3WG7TO2qaKYGbmxO6cXBE=; b=Encjqj4ZAKg5mJcwc0bmvhvOrfLyVrxuKf2Xju5npBEMJy0MI5eRcxTuwipSyGSMGO C/HCY61XfUrCCgDD9K+uznAQF0rjmNF6/E2P2bIwnXcyydS2pB269Il9ZygBGuyLkYC+ I7d6shqncCWjIERig/2KjGW37ayNZACCVbRLl5PT54T6qynfR+Ss6v0U0MdaQ0VlQ1ig /3CkNwfFsFqBjLEjJYolxtRvQfr+HVz0kUqbt8gDvEgGwuck5IjMWUbUbyMPztPLUKhR CDv5m5LIiY7NV5UHn9ACgpLGS1OpSLtr4nOXlDuaBTi5XVeoJixwWcE3GRBaSBa0x1Yg JOhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381523; x=1780986323; 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=/QgB1qOgUmUCrnPstfXNyo3WG7TO2qaKYGbmxO6cXBE=; b=UUFcq5txDgS2C02ceckVpxm5hzvDmoBnw7MzC0/kAERsX1LbZMk/tWsDHz8pUyeGta HUhT/gSfMXtGfz+TA+b6zCFq92sEvB9s16xqqxdnp7H1etHa91Zp8N0A5Jo7yhsYyzu0 bPoVAMe0xR00Rugjl2+vTdicU507biSxcL+uuYzVJctGIEWXsCfsGCc51Mj0r6wnoNUj uqvKFGSGeZOjs9db9NrYQLIkhd7tgqtW4iJv2Z6EFSqRFMjHI8irV3kzv6iwZIvTF748 ZEDPfkLvLkYzqLCjV1r8oEC2vjXEiHk2CC8SlGXG2cnvhe4biTVkUpvmAQ+AdZXZCKSZ JuMA== X-Forwarded-Encrypted: i=1; AFNElJ/pmGwhuaqwuOUw9nC6JTm6JMh3CX5lVaAxD4y252V0VB/Tdr093OicQEmMDPh8ZeprpUJZVm5yqQPqeew=@vger.kernel.org X-Gm-Message-State: AOJu0YycQ2yvmLnMoNMvLK1rGmFMtPBMkjLYw57N+q3Lt4T/HEn4zJ2T Bn9CI2IQIAgYSjb0xaXb6twJZvkgEMEpWDlsd1VBJKY8Yu+KHPl8gJ/yg71U4FLiR3YYBcEO9LB 4RlMMeBqufw== X-Received: from dled10-n2.prod.google.com ([2002:a05:701b:42ca:20b0:135:30b6:b9dc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701b:2211:b0:137:ea00:3f3a with SMTP id a92af1059eb24-137ea0042e4mr1120906c88.9.1780381523005; Mon, 01 Jun 2026 23:25:23 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:38 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-7-irogers@google.com> Subject: [PATCH v11 06/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 F033D3A6F1A for ; Tue, 2 Jun 2026 06:25:25 +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=1780381529; cv=none; b=DIIW3Ew+Mydx61ntObBGeQ86aVUmbS7K9/xtPKGGvrtOlxN0IwnFegWFTfn0FSRT6Bty8Po17hIjo59pI//MnlPkpqcszMuzK3FjkGgPttWpd2ttIhyF69oQ0vkfN5n9g3AP+cKZ6szOGRV7j1UpkjcQV5RGsVAOp+gEws6a2t4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381529; c=relaxed/simple; bh=Z4WrN2+59MV/rg4sfdg9lA449vNSt4qPYiJQIWHMBoA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C8b0aQS1Z4HWaAfy6Q+w68J8eazjyKX06sbscQNE+81hYRNAVfSSCvpaVV33nzKHx+iDcka1GdZGldsM17IKwT5qU+kBBPAWO5tpoC/tq7FQ9qURrWG+ln6sqoHLk8T8TaeLrD3J7sflWmiN79dVLA1E0cYPChA2JCegE6zWqlQ= 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=PqZleeph; 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="PqZleeph" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137d4309062so7461358c88.0 for ; Mon, 01 Jun 2026 23:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381525; x=1780986325; 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=VKmVi04Xi/VezwoSJHiJtxgWwe8v8etyrpuu8J1PVow=; b=PqZleephCnuDN9GCf1D5MkIltAqz9msJ/N8X20new5AVszrCAoBqDxoOkdQjGg9P7V TroN395OYqw5be3XDenvGvjvUEoE5nfjMwNUGP13/vkLKNXXa+0UVLa/vp7RMKy3H72c S1Mqh1tro3PyBs113qQqiUeMTti1xRinnSoyC332xwqvsOM5eYDH7aAmKDAr4+e3M4e8 KPRxa32K8bqB8Fb2WRb9iUEAEUXGN565XHVyi51EGgfBcI4TQWfRwX4rb76PnG356BJ7 vEx4I4slgHTSPf6ZZVQLviMQWmwCy4l//3eqHqcawDTZDd9pHTD3uDOkBef7A8mjWed+ htUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381525; x=1780986325; 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=VKmVi04Xi/VezwoSJHiJtxgWwe8v8etyrpuu8J1PVow=; b=PNMAata7jXx6Sb25VaeKT27KOaj/5ZX8fF8ZeiY/pedTaAGBWUR4+UIZfkYoxql3U3 SlYISAhJ8rYIaTVbjlBWLelnthIWrQxb4OOG7l8Mw8MXf4zyY0Ft8sHD+XoQm74WTKWb 22dSovK2BYph2KpoLQgTktwQrzr0mzkuXb+58jt+dysuFuy0ftJX3L5bEA6oucXlfryb fD+YBiGPm2DBVqjxM30+wRZyLMVPWE47yJa3jaWJhXDAeUVAeZx01rA4c7yUzbB28YqA iGcS7tYdWYCTwWVrYNQ0h0ioPFW7ylzY1LSlhFvkYJHm+R7AHdb2Xif4tUIhcpDdDJSq YZng== X-Forwarded-Encrypted: i=1; AFNElJ+M8G10FUKTIU8ac+Ce1+qq05VLRrcUHHuxwiXHGUOQcy/tih4MuPh2EcV/V4vnqvmGFBqboS9T6mXrGLY=@vger.kernel.org X-Gm-Message-State: AOJu0YxsxVokBiUmRNAJIJWBXNDSe4TiihNr5qSOToMlzkg/HPwzHXn4 IDXypAkW8KFZ3dodAZHI4k1Pxb1sDfJnjewiMpZMR5UenSOqdJeS2jvU0sEcovCEZqcsOYwW8En Wh4w9HWyJLg== X-Received: from dlea2-n1.prod.google.com ([2002:a05:701b:4202:10b0:12d:bc1d:8783]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f98:b0:12a:7165:7405 with SMTP id a92af1059eb24-137d3f197b8mr7137251c88.8.1780381525020; Mon, 01 Jun 2026 23:25:25 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:39 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-8-irogers@google.com> Subject: [PATCH v11 07/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 D6A6B3A71B6 for ; Tue, 2 Jun 2026 06:25:27 +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=1780381529; cv=none; b=f+4W0Uo7MotmwL9IO5TFqa6kU2ZAYJzNCpnv/u4jr/LsONU8I0UcK7WyU5eAUZjCR/CFAfDL1d8mLlWw/kvYM+chvAvOGflwD582/1vg0mnpGbyfItYEn6ADYAIQh0Erso2t0o72hF96FsOEDww7T2jY1x2u/XlD5FLLYDvWz0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381529; c=relaxed/simple; bh=uggu9Ed4XgP8/oXGEguF4UCtlrWJYr5XzPWI3Iz/dyc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u9h08FMRVO9YbKBoXhNvx6Ryfhy/blPO93ijBxgPyvTqAC+Oy2M5hn/bDihE7alpBulVbLSbQvXz2C04D16wk4mm43viZwKA7/FogWNFsD6nKIf07aG8ScxPlonZMdJtf3SUhuLgDOHZeOgcyLlQ3NCkpKY2j1fzBasn6QXrrSE= 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=bz4w//hF; 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="bz4w//hF" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137ea73393cso4577738c88.0 for ; Mon, 01 Jun 2026 23:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381527; x=1780986327; 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=yYKqXq805w0wcFXBmJBfrrbsatOJmwPurkk7tKq881M=; b=bz4w//hFF78+7LixCM/Fhr1E4g1C8RgduWVuNHprrUvwvhqg7UyRytFg37R7Xs/eGj 1NDi9xtIhvqo2U//7IcrkKDJ8PGeGJMIF8vMUMD7xi9X0CEB0EUPqb/JwkmFEMy/b8Q9 UzU74I+9l0S4x+nnDozGUMt2C+Om+Km5O6w8NmuZakjLU39nzO5JSmGDf4vYDMi8briE XuRpBRvDCyafkI5RdDslw1m6+cMBpwa5e6bjwQigTn36jtr9YiUZCI9+EXBRdMj+SSMf bF7OU5U5OFlAos/XpsKkrliWoAY4AIScf3JAate7mhMtjo2J2A9j86Wsrq3kgS0fFGW2 cpIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381527; x=1780986327; 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=yYKqXq805w0wcFXBmJBfrrbsatOJmwPurkk7tKq881M=; b=jKkQC1iZcHQbKN6i+DzSdicbAz1hA0kNJt2Cfpa2fagiZ11mAISraJwrcorS97uaxl UPrfbDXA32hN6MGS/INwnPi6uAwaXwLU5+GbxXXKrXAJyeqhiiFE+4R7hy9CLAkciyI6 HsDSAtJfqyKs9wcGmnGvyzxZgnJUOi5nPWvtJpqqCw5WWZxHjJHm4+v1ELC/pisyiVwZ Ab09Ecxp07L0TnY2r65x8D+ODyvvppc4WKZIvm0DZSIJIZzDftiBo+EyTN3Sqpr0TVIn l9d73ZIUXjlj2YRoOw1Kp08eF9WhAjFRITyY/wFOADo3DIvf4CFK2qkOxa4Qw4GA4BCg oP1g== X-Forwarded-Encrypted: i=1; AFNElJ+iVaZe1DOFnU4j6v8r5UZiFWpiNCCQbsHS78Lb9SU/B+AB7ZboEV2bLDvQJq7nJaKOlezjfXODS78b464=@vger.kernel.org X-Gm-Message-State: AOJu0YyhEqHmAumI0SII7DweJ61xvdP6HFlEgdKzIhICq03+/rLRbq1q 7gjZHpQvlt0rd5fbJ/uAEPg38YG5VlF/j6ghvFez1xtRCH0v2Z7G5Wg3KMfSsc78YVVFiu7JLnQ 4jOkkT1YWAg== X-Received: from dlea10-n2.prod.google.com ([2002:a05:701b:420a:20b0:12c:8ccc:748c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4393:b0:137:e532:f53f with SMTP id a92af1059eb24-137e532f5f8mr2730516c88.34.1780381526867; Mon, 01 Jun 2026 23:25:26 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:40 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-9-irogers@google.com> Subject: [PATCH v11 08/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 B7D263A6F19 for ; Tue, 2 Jun 2026 06:25:29 +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=1780381535; cv=none; b=iZ91Vwke2WUP8fPGxKNomek7/iSWKsvpBfOoiXLljGEuk5EC2F2ZBEcqjBZ1ByfkUQ8T93gCK3ymWityA4OXZH+9ExThfF+1Wm77eSGS2aSPaRoyeMLHpEPEPISTQmscxwHQ/dzhuSd7UPkW+WFxx7jrpZLSLX5N6qhQucMP+LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381535; c=relaxed/simple; bh=F2CPix35dUffd03PpiODYF/Y/HMWspE7itJrwYnRzhA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M3k4CzNTbte7nb1f6P1Gze6aqXMx96oYsc615X4ttrm8DaGM/ncx1QwvSfdihjFQ2hi6P/knML1osOF9a6E+8vU/hw0geIEbz3HbYjudpH7ubiAHNVf/hr+LMwo9SJqhIMOYmkNI2MgujmdIhIcShFRfSS63hp5rmZqvR9igX8M= 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=uCF8uO1P; 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="uCF8uO1P" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-135fe34cb98so601000c88.0 for ; Mon, 01 Jun 2026 23:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381529; x=1780986329; 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=amlPmLXVpdwhmAERUmH3g/HD3HbPai/uUl8j2YKLcm4=; b=uCF8uO1PJqt9HWOH7i0GzqZCWYntUdeDU1Zvnkl+j30DucnRDc36cBlYyYwGhg0Qbe 3+u5KOqcAHvCxhr00J8DAG7+71Wk5Cd9BYQahy2iG7Dc2QwQoGXdQGQJpWnVayr1fs4Q EcyGi7KrfomcE5KDoUyjzVQJcm8FEpKfgxusCJF/bDaVl9buXS4WZbg+C502l2MObWaI 25phoh9rpMICT4bshIPqZvgmN3zSo4CY5hNmmdIqjhj7n0aYAZN75ZZ+9kEGQXov3sa6 Q7SCo+3Y+L+TnZ2vUhiu1yzI6DwcDdnWAMxh/WBb0UAVCG86z5CbOVeX6bIVkfd0Ot/P eg6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381529; x=1780986329; 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=amlPmLXVpdwhmAERUmH3g/HD3HbPai/uUl8j2YKLcm4=; b=pnceJds9cpTbnJ9/K67a+F0WuWmUnL2Z8vGx9kWpbsk+63eQpSz/kAzB3RmXfFjY6u rWaUPML25MSzpYkyL+F5v69swKk6PJ/cddJ/nAZgZw8PYFECe3SpWhl5rMTBHQrnrUKh VPfWE89+ObDj/Xovp7z7irogY/KGGfG8mFcx/FoBkShITrcV5xgAJgfs3duAPFJM0W3o 5qc6lT+ppc1LaX37cDp0TNXVpfs4YBL3gULbSpetYX7zk0BPhTaxaAsF4srxIiHs2dos azO7AP+U9la6zDEzQh59steL6jIxigLgbhv/PADqHwkhYRNXDNLmSITNw36Q7VmO0ohS v4kg== X-Forwarded-Encrypted: i=1; AFNElJ+UpLJlquADaT4JvDRGSp65Ds54K7PDyCPBemFAJovcXP3bepLorEHvtBMMMclsT9YEoHJpva7M+QpYhKY=@vger.kernel.org X-Gm-Message-State: AOJu0YzUdNWM6LUnibN9BQOu41GsucngRuAwMpkCRnzbbYfMEG9oHYpX 4Jv87q4u5Suld4bf6z2mYnrweRDktqJ2RdpGZmNqMofPf0ZFISodDF/jhGKiiBBE65SAiGW2EtE /SS9sehDIIw== X-Received: from dlbbq39.prod.google.com ([2002:a05:7022:6727:b0:135:cac1:fe63]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:60a4:b0:136:d237:b428 with SMTP id a92af1059eb24-137d412b133mr6736941c88.22.1780381528852; Mon, 01 Jun 2026 23:25:28 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:41 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-10-irogers@google.com> Subject: [PATCH v11 09/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 F29403A8398 for ; Tue, 2 Jun 2026 06:25:31 +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=1780381535; cv=none; b=aBX1j/b2G8rNdgllF4p1e50Sxvwc+jdZwlAOR0eNTZgIfJxMTnqzUos1n1yYUbcA8hmsgyiZG7VuxI/V4AOdLrIx9L9kTbI/CwvBvWi+/DJyXHlS1er/85pvkQEUNefTPq+iDO0YkAJ6cwTpglK89+NHIafGxTCLswE5xf/LtJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381535; c=relaxed/simple; bh=1TN4Off0WzSGb6E8PmC/hd8tjykbHBLDgI/eo85jqRM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=O3XGXdMK+hYavbYqjHOJo5iftjk3vv3I/C3t9nzUJRG6uR5LlXvWLk2F53mZOrf8gneJK65997xu5OQonCUfo06RusGrDEooqk2q9bFusb9V4Pg+a7qz5dUZCh/vIYPemb5xE0GweMM7QAYnQOb3aZEBbdIPYXX5uIxkfs2fvQw= 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=DRBSAwTT; 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="DRBSAwTT" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-13709ab38a8so11425432c88.0 for ; Mon, 01 Jun 2026 23:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381531; x=1780986331; 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=gjedQh85bqRmyx/dzkbLSjIKr+my71zFRmku8NoRk3U=; b=DRBSAwTTSSzgnOM8NUQtStnr6+h5zNk760t1JLHAwrb7JkEkce94lmCc6PMZdtMN8d P3k7pRcOM9/eymuW6pqTb6epZ4eOzY5zkB8iEzDsFdIPDDQQHC+CrR1XtbSAp6UnvJh/ wzI60k2MUkQaYD5r6Cch8mSyO5sZniL3YQVR8rM5V1w+IRNoWI5FESYkgbBxqUf75GVq shyZ8nepWacXb/YyxuYTrQ/gkJZbgjEdqQegzKT6Vp+jpLbAOHXbQ46RXFpkc0qXO2LI EnjmOElBr3SXPheYauK69zMXDyAIyUETG7YFDGqFKOs8JoQOyfl1VLfUAGQUGZj1JZ1p WRAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381531; x=1780986331; 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=gjedQh85bqRmyx/dzkbLSjIKr+my71zFRmku8NoRk3U=; b=rtydfueiNSMssKMsy2CPu0BvYFPBSkChK9giO7qtE9JB3vgsT1EZpQlACiWXvqfNr1 T45QMSM1K5B62A/qHksf/fDz5mTfgFttVuuApGBn27yCPBux3RqJL+WH+yIjX8wPVXnb /drjXubN/oveERMwnJBP+Xj/sXLNlr3RmognmM373yERtGGB8kw3eLLwf3UJv6mXaMoy j6L0exlAmbM57iIrR1zJyaBpaIiOLOkhg5muHOQRtt/bmussdSg/I/oGNinJqkTWZpO3 9Y3Aed6Rl1Ff7vKfzuHoOlem2wzGZdmLk7p8BHQhpBUulUxx0jW6WHlul1WJHaBWyRii cqSQ== X-Forwarded-Encrypted: i=1; AFNElJ8h/Yke1+s3FsGlOiHQt2j2iHEmOB9mm0E7Xu+IGX76wAhtIyLAZ2fGz2ieLkd9soYwHQWFzXyAPmcrO6A=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2+nE5qh38XUNec/nCPL1UV6TLa5eeYId5TRaf8MDxnhUocR2Z wg9eS5bEBmj8jPTSBe03p+E1ppgge+ZuM3qAJf5cVbf3bYQqxD3JBcaJhME+syy8UFmOtstXveQ fgiS/LYIlNQ== X-Received: from dlbsj13.prod.google.com ([2002:a05:7022:f90d:b0:137:e5ae:4179]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:382:b0:137:1ae1:bc2e with SMTP id a92af1059eb24-137d412f9camr6070348c88.11.1780381530903; Mon, 01 Jun 2026 23:25:30 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:42 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-11-irogers@google.com> Subject: [PATCH v11 10/19] 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..5ad50e331c55 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 && e_machine = !=3D EM_S390; } --=20 2.54.0.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 B0C2633B6FB for ; Tue, 2 Jun 2026 06:25: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=1780381536; cv=none; b=iGb5Q1M+IyHHrbMEjIWt+t0EP45+UXpPthwVHmz3BpvAJ2rYuNVovKRqQNa2v2u5/MRxCHDHLicPthWN1qVQSx0QH6y4PCoDsnUvHk9IfyytfvfRerSwc2hjG0R7iyuYc96jTXl2JnAVJmLho9G5UfS5ZsXv9HbhvzvEVZwRmOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381536; c=relaxed/simple; bh=1vKpGyCR08D55Ms8rIa5echQivY8IcjS5P3lKw+8Tnw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lYAwg9xrIUQ0UhtxXKsOKE6v9Cu9LjRxXECauY6NT+6xEzqZxKu7ZBH7ztac+ymI5zI13vlmI7CXtDM66hXQxB/5mPrdU5XIRcOpBWmz/8UJkZSr1VoDCBxFgd0lXvp5bRw4/qqLwY32GyhDNw+6WsayoPy6yGAPnX1/I3WcEWo= 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=en9U/efh; 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="en9U/efh" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137f2083280so51560c88.1 for ; Mon, 01 Jun 2026 23:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381533; x=1780986333; 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=r4kzHtgoNcTXiq9f50i9J7MtKzWtq9qgg2LJuweT+II=; b=en9U/efh9TZRuMMp9aSK8V7Xyxsu0tFIfrEPl5LH2kvUHZ3H8SPLPWzl+ljAemfkPz z/Hgc4EO5Jn+1rc1lFZqGOPVPTinkZ08fwo93zpxvDCx6NS0xs7xfrZq2YbYnR+LecjH 1zKwfOc0oWQldTqWdQvwNEO569PeiHC7ygkwvJtZTd1E9aRz0uAfyefRGhqkZklGvV9e MaAbsyTUEwD7mi6cvhppxsq0HWXf4GbZiBMc2uIRvF+wgNj23Zj/4CM2bjPovsEKaMD6 aQMuj41a10aZu1fdLVpUKyuj57Gt8kgKihisXM6MpejyQ096kgACYP0I67IZm1PH3qVz 1uMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381533; x=1780986333; 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=r4kzHtgoNcTXiq9f50i9J7MtKzWtq9qgg2LJuweT+II=; b=lE02fuPTiMdS0DjyAHt4dCiz4K/3RWCeTFK+aZwMbNwAsDLEhb7/Z66WjQDiEexB1p DUY2+5h1BNcLPyf5bqyKMfP9y7N1/DchNq5UDtceCvH47Be0QxzSl+/iBlJf0QR2v38K gS1rGyRCohbHPTg1ES1k8wGuEpOKXHZHxtRsNcbEOzgDobkDh3eu3SP7IAbUpluQC1j4 LOSua1FaTvEIB4ffw4c5FSunEWWVqB7NAzHNL0Nduo8xpM49QqbVSMcyLmDO2Rdsiqaw szt6VBEj1oQSmCQAqYZoiP8RgjHGMgNCLHI6XR3W2B3DIQidkbxGRPyjU95VNGTL/cXj yNYQ== X-Forwarded-Encrypted: i=1; AFNElJ/cNPk6RR+5MUV1Oypmr4i3aYuKbQV8wpcDWZa8BnhK9wMJnbGg7sPpKLnMeETe22VMVguDmtszs3794bc=@vger.kernel.org X-Gm-Message-State: AOJu0YwtqyVGGZPD9sntnPlKpQgGOUpnHGyewfUkhaFNhfIvP30QvyHC h+7RzGTsrh7xQZqFzPU8B+9geBarKy7G6X688p8jmSfTDXrgdDYPii+1FPIv/uzHW8FAm2DwVAJ moXSUbidQHw== X-Received: from dlbsj5.prod.google.com ([2002:a05:7022:f905:b0:134:b02e:a831]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:503:b0:136:58eb:a486 with SMTP id a92af1059eb24-137d3d09851mr5747955c88.1.1780381532714; Mon, 01 Jun 2026 23:25:32 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:43 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-12-irogers@google.com> Subject: [PATCH v11 11/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 663A53A7852 for ; Tue, 2 Jun 2026 06:25:35 +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=1780381537; cv=none; b=ZvCu4Hjs8IfQVctupzBgdhx36/2eMVpkzNb1Iy15kTmexyRD0obaPH/hIUbg2E/Z5p7s/KvUkc7tB5A3xvlUqHKvvaEKbxAu4264W12tWUIxTr79XF/2ZMEVTpwU9puceELneKXtRAiY7d+yCZtfneTzhBjuahHC/+A9yfu3eO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381537; c=relaxed/simple; bh=bD79XLC74sOKkh5WkeXQ/YhX86xrlFEHMGX/zIPcIz8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U2r87ZVETNC7nqpEA/DLDjzFp2I5uBPx/1gbSB7Znu4xl5hNyV/gUjeyZYumXY9sKlkJzB6pqTodXcyDWRSsbOtbgWlSp30Gm9Ki+tA+lsGSDVjy3AZeqm2YtNGHN0vhWJGwoDTRWSPVSut0gBurID+N7nmu733IsORUJsCDjmA= 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=GCqkCG71; 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="GCqkCG71" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137dbe27199so3995951c88.1 for ; Mon, 01 Jun 2026 23:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381535; x=1780986335; 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=CY84B4INAWbD1Cf/mmc/o03IBqOHUDgX8UA9AM+aba4=; b=GCqkCG71POHy89+Z7zMJpvFdoGelCZHpvKghn7LthQ/XMbRKWhF5IQR8tG9j1IzaPv uDfdzt5YSzd7nzMsKfwzsfnsMGYXJkeOzYPU2eSAMz1rUG2NJ1ugJ+30kRd2ofHeRyj8 vwWPbksecnmobwvMrc2pq9WtenNxJL+F0X+C/HHjgHLcsKeLuWHesm+i+j28QwJsyHFi /yxK8MdSZUpgyRaQqZM9PAQ5//pQ21mYRkYIcTjfxsADEu0iUSON+2TCWzMyTNQK9agl Hk8dPo2NAqeUFBNJTNRavREeFhUOZty9nCV1Zf9D+Q/EdYZhfuP2TYdDQF392BVGRE34 LVtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381535; x=1780986335; 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=CY84B4INAWbD1Cf/mmc/o03IBqOHUDgX8UA9AM+aba4=; b=mH0WwbLmH2iUVc2GQKiRuRv7Qir+I4Q6O+935DhshMcfPDA7Efr3Wiof1q9uhiDp+O RnRRjhJuazfydZZDHy93cwOnospuPBh3o2WCyXuDAl1o1R7WHBCvF/PUsVhYA96Ht2Y7 f9qwCalQgnxCrJrZ8AAFBjx/z7KWpWiI3zeog04pLJl/FGZgKXSAcsh/oBebE63kzMfV mfZ8vyEK/i7F5UMtIWdxH/V8t2z8umcXagEQzUbu47gZgp1SAmc44rPsprOPpPS0i4oX OIgsz9CXuzgThvNl38tBTAAX/QGq5Y8oBPnI7eOycH4QvO4AAwwftxRH1GtXJfnceeUa ifKA== X-Forwarded-Encrypted: i=1; AFNElJ8o1rF98gIbIbenAR78zSe/72ad2jjtdeIDHU2HwYPsDSB8+V88VYEOGXoV+t8y078dSRR6u9oo/+xYLrE=@vger.kernel.org X-Gm-Message-State: AOJu0YymHt7aGxbz/F8/2DTKtiZ1bEqnITjFTYCc3WOH0/ovqQVhGsHk rDPV4loR3ZA0q5NPUwhdtxO191WHE33OjMB5heOPFGrmBnHgkV66FWYerLiZiwDx5DM8UY4+t9Q Pq86fZeRnBA== X-Received: from dlea10-n2.prod.google.com ([2002:a05:701b:420a:20b0:12c:8ccc:748c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61b:b0:12d:b7e5:a691 with SMTP id a92af1059eb24-137d4026bcamr6351510c88.7.1780381534349; Mon, 01 Jun 2026 23:25:34 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:44 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-13-irogers@google.com> Subject: [PATCH v11 12/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 7540F3A9DA9 for ; Tue, 2 Jun 2026 06:25:39 +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=1780381540; cv=none; b=gAeinFumCdArPBHE12oSEvUk0C2sc/4gzbfrobLP88p0dQK8ScWZJdI92kUttcfBe+iQBr0LSD5G1QESSQ4VXNiN0HPQR4jl9b9kGC4AEqnMQzwc1k9lsgr7lPj0Me6VTf4ZEkAhYfse1PVA300OgRG0FDNIryPSp0jI4X7guVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381540; c=relaxed/simple; bh=AJ+cfGDfN/nv1QtOco5T/vUczZG+yKOvnd/MSYaYhLs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B+bxQYWpPOAN2pd34EZ+UFz/ieeo4Of2p2yId7JVyO1wvk3hJ2FF5/mpurX2o5Nx7Hsm7/wqRmjUtHN/x61ABkXu4nz/7bFQCtmoOmEgm0ODQAZuk1cwAcDKAofmpXb0w8nrtC1kZ5YjakqmreiH84TrlfmzK8zUeYK41hgY9zo= 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=oHGKwFsI; 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="oHGKwFsI" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-13537722193so17644170c88.0 for ; Mon, 01 Jun 2026 23:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381537; x=1780986337; 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=if2KD53xtMqvcoFidrX8tSNh3zZDo7SrSprlPMzY0lU=; b=oHGKwFsIKRIp7YRGLY/NOKTV78JHzr7SVuXjmzaFcYVcj+zWbEelGypeLpyiF612BM V0fqhq8euLwgV12/Dyb5zXPyAfZgEtN2d9ARqzN+mzD+EUHK2J7NhsJdjvvbPeyOIFuM Dv7/RVU62bMZ644ZNmzk4tjiZM8RGR+5SQg7H/CzV4uo665tKGLt8MCgcqRHUsESuTnM lKUB7y9bQ+ET4xlJ+zyvIggMqqx6DqQ6T3z+vT4pRVeFE1RhCurGd09oahR/upvHozGW VJvYgOi+wFk5urRAiFR9AyWhHYKJ0dfHhkyKTyhdmJVfdZp7kMfkWg756FvrjQMJOd5f wSmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381537; x=1780986337; 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=if2KD53xtMqvcoFidrX8tSNh3zZDo7SrSprlPMzY0lU=; b=Pn9iTfirD5FJLz8lTkg0SfB2qDXrrpieXSs0aLXgO0OTU/xwAXuzCQJ3qZdp9cacYz CefjSvdip6juIt0/4m4G6OkhFIYVxz4pPEbXsN+eS7rJ9TI30fgjz7JB7j7KdhaPo2b6 uBCB9nI2bLBIaMEWH9ZvLZv7GRl9uuF8FzGbm1KNgK6EIlVS4H4tfSZF2tMDpZuV9rz7 xqi41RjFgMg3WAaj86OZEfMsfaubqHW0evDFVz+xiRCcYudwOMUqDvgEPm/ITJeJDG4+ LUtvB7xoAKWRbkTZLPUGyDcEIDu6w4Hb96NgXoIh67cOU0auc4x5dxSF4SirjXvVvK3N IY1w== X-Forwarded-Encrypted: i=1; AFNElJ+xHseq2l7hksQISbs+b8YFYiv37+ta6PRHFKmjVQJsFRuiX3OqJG3DT08HlxV3kcd/s4L9ybn7+Ki0Ux8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8kcaHVQwHk6eFvVqtdPzktkBYdw/1qGf74l0wM4XGMrno6JIn 8fykgwNB3zfg0QX1lS9hFpnKex5U5b0XkKn6RkzKvn4pn9Ti/D1LGasRrtMCnuNsgQp+bR4TWhq Xl75PGYKVJA== X-Received: from dldoa2.prod.google.com ([2002:a05:701a:ca82:b0:137:efa2:589d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:238c:b0:12b:ebb9:1c18 with SMTP id a92af1059eb24-137d4243a4cmr6526798c88.31.1780381536359; Mon, 01 Jun 2026 23:25:36 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:45 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-14-irogers@google.com> Subject: [PATCH v11 13/19] 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 1879C3A839B for ; Tue, 2 Jun 2026 06:25:39 +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=1780381540; cv=none; b=kefuN/lq4Nz7zEbLWPRsxEX+fyPiGlnbDY3yWRHJ5LvOEYDUlPA3FPQxCa6WOG2cqzvDcKb4Dz8ETp7wuvEFX9dj0l7dVtEsVxglklPdNUrJwdgRULe0raENGm32tw7rh7pPofucJFuu9RpcQO2WxXHdMXpPmSWZECcyMbAB+s4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381540; c=relaxed/simple; bh=SqxISLW1CA6sEUZz+3i2XQAzpM0vkpmankpAgb9Yfl4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Y6QVFydd6LXpPmToaXa+oZfJ30UkTsdLu6Z3Jqp7ajopcYRvst3va303TNkL2HMCqfPo7wLGJwtju/1qg3yJvouzGtvD9iM7FD9ltOPKEwzWTsnkOF0gUX068okW2QyK89jgAvzD864JA0rI7Q7cw+AL2wS9jiQI5VJp5Akae9s= 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=dmWzo0IJ; 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="dmWzo0IJ" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304f23c55b2so3584863eec.0 for ; Mon, 01 Jun 2026 23:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381538; x=1780986338; 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=LATv8zYjtJ7yPtRej1rBNl3vNhfPbdBjAvEhoz51t4o=; b=dmWzo0IJYxyMk7HRMRLAnwTlAsi7+S9J4Pr1+bnp5uQjYO4euZRK5nAUZD5MY4TAvA CelWpvMIGADkfrmtmif5bKrljXs4INxCTynWpgD/pmR7KT+QcQ8ELzu/hPkD7Nlqwwss qsGZULidTq1jp9ygnXetKQW8AYxV+nkErgEYB3XBJHE2tBx7sl+tSFVeHlpedvWwrQn1 GDODvG7ZnhDOSa+9HdjP8OCzmyBm86pvccTKoAP9qiDVKsMIpEGIFxs24Yr9s8Yiw3KC Hl0fngcA/kP4FqwgPM5VEzFlQx5iG8/Jx+W16+C3ffHgBdmnwxiGBJtsed2dEks7GCYo o4Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381538; x=1780986338; 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=LATv8zYjtJ7yPtRej1rBNl3vNhfPbdBjAvEhoz51t4o=; b=gOo6TYKMcohwXgYh7YRKulFyguCszV8n6qV8RwxInR0JwLsv12VVIwEk/dBFdB6yhe hbI13bjCVYaxFatLYi6oW7UfJFPG70mtwlD0XX880RuutnVc90vwwfaRDooyFGHpwDUD Jbo2GxYuSmqASpVytQFKcNPw04GgVl20T7II6dj/7dSWn304k/M79gYPQgNDJ6IT21Kv WMecDVbhrIhOyWFkrJXzmvnBJe9l5ONl3hTTIXzPrYnW/ksZkFaDTjzzMUedmchHM7EU WWVOL4FBWti9OJmNSWeFEr6AN3m/EP1ax7e3uWAPp/BYyGajqaOqNx359brFR1j6GOiW U2VQ== X-Forwarded-Encrypted: i=1; AFNElJ9i8KMDAxc7L9E21GsQUHRawNTWW3UwuACHTaMi0hZDngkkYIIOZJx/XSRM+BJyO/GE2kOt/FU586p7wao=@vger.kernel.org X-Gm-Message-State: AOJu0YwCWTdJ4Tbt4ZCzGpZSDiS7LEvsUEOg76OjtDETUi0/pth0R4hy f2VjzAInwxWe+5rDPOGhyAXWkjkCk9dbeDYjmIEaN7OUC6Ci11Ej9BCpFDKQ2hAlXqjbLFONwhA NUdi0H7+pnA== X-Received: from dycpw7.prod.google.com ([2002:a05:7300:de47:b0:2f9:af7:5043]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:2c86:b0:304:5b65:5971 with SMTP id 5a478bee46e88-304fa64c86cmr6484195eec.20.1780381538079; Mon, 01 Jun 2026 23:25:38 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:46 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-15-irogers@google.com> Subject: [PATCH v11 14/19] 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 | 13 ++----- tools/perf/util/env.h | 6 +-- 5 files changed, 46 insertions(+), 22 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 fae70b07ba8d..b41562fb06c6 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -851,16 +851,11 @@ const char *perf_env__arch(struct perf_env *env) return 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 +const char *perf_env__arch_strerrno(uint16_t e_machine, int err) +{ + return arch_syscalls__strerrno(e_machine, err); } =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..5a917271ca0d 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,7 @@ 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); +const char *perf_env__arch_strerrno(uint16_t e_machine, int err); 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 2.54.0.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 3370B3A9D8A for ; Tue, 2 Jun 2026 06:25:41 +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=1780381542; cv=none; b=lcA2lfaYoAU0YuES8TLDgOOdyuivcwJPJ0bHhTUeWjDBlyMjlOKiOA9TmKjxPpBJT3GG9vIbh9ya3/E86gy/mKSJmgzh7ljlEGP0TEWVHxNmS4s/foOA7a5uwTdGJuLsYckDtByAOhTEhmQ6Qbwu8hz/QFXgIRtb3zqaJLjtVIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381542; c=relaxed/simple; bh=wBx2XjIbGKm4f6lxUHRV7mNoOSTxIfLQoUK89yQfzt4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pO+rrSu1zQQQ1SSGF8U4U/Rv2Wj9g9OGCcecLYCaHXDCMftDbmmdLMVw/MzWeCb+Wrz4EyWgLQnZ0TPZDbqAhG3t2x/qX3hE7BKX0vN/lAKlz13CJgyms6oPyaX0uXJn5C3oaUl5iofm0K1qQM9gCscU0bhln+i4DWEjpfZoywk= 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=ckZliROS; 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="ckZliROS" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137dd5100c7so3632172c88.1 for ; Mon, 01 Jun 2026 23:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381540; x=1780986340; 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=harhKEg0rLSKe3QU5NRI1JfZjDmZUxT37Wq4SdyYcDA=; b=ckZliROSsgzWyApV3wmO6jGdaMMrutW79bBgzWt5Y7Ng7gtmIsemLzG1vd9N8V3Y3z D23XfxaXFPlVBP+sfm5wNa6ZyadZTiJRhxenBjgEG6oe2zp5CwRpoOcgzNH94C6StWpU duY1lPRtjZt6rJrvNyCqdBAf4CStxNHPMvgcrwczPJOjBLZ+4noH9Ni7fe90x2WT//sR KQ6bMQIAZgd+JUuO75cPfOSvK2ES61LoeNJ5JTe0MfWNFsMG8xwLktltIUg6LuXNxQ0M noTVfVy4GoKmmqtIZ3AJoehDbUbrVjrECbgwPmArwPbGUTzz0eVluTa867wie/bloCep o3PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381540; x=1780986340; 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=harhKEg0rLSKe3QU5NRI1JfZjDmZUxT37Wq4SdyYcDA=; b=L0Y7Ac4TDXMPXw2fJlSZPQ80Y1k+DJ30pj9HGpXkNkp+iWlJLpuvgYSIdTBqq95x12 NCJiBmn/DNZmidraA8sFrf1GM23CX1s0ogt2lLWjBsNmIgLAIektv20ovaNmLiZj7Lqr aWnL7aNEYIebr1WpmEdtIW3cRcTtwbg1mZxDCu602s8mIAqe6UnCa4P+STZtJgXSsxmt MzWqT7lt2Nyzr8oB7Fs23KaK9CBgFdX2/QyOjZUmTIS7bMEoXAcnDcAre7eDQFMRVywh TPGZxbt4GCFCR861MyD/b0RQcddTOyJCzHrxkeHKYZfvJXO4p1vFOAXRMM2A9w4HYYsW HfMw== X-Forwarded-Encrypted: i=1; AFNElJ8D1RxE0UrnInOXuYdWM8xbfILQ670JuyL9r+DvdKuBpmL+5KWKJeP8K82jNx96Mc5d+Yhzm9+0FwYVHGc=@vger.kernel.org X-Gm-Message-State: AOJu0YytqraED/73Lcqn+3/6LOg6ysdc7DKfxM/3N+cYAxLlUnHut7zo XOWvrL+Hn64H8Y+yboU6PwsScdcmS5/EAq3lLKaCmRoZDW0ZhLvUrdp5RGJ1YJxddBVKjXiJXNO aHgfSq+hflA== X-Received: from dlan16-n1.prod.google.com ([2002:a05:7022:eb50:10b0:137:c9b:c045]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:60a4:b0:136:da48:a3e0 with SMTP id a92af1059eb24-137d4131b70mr6816594c88.28.1780381540139; Mon, 01 Jun 2026 23:25:40 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:47 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-16-irogers@google.com> Subject: [PATCH v11 15/19] 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 b41562fb06c6..28c54c58193e 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 5a917271ca0d..83e74328798f 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -190,7 +190,6 @@ uint16_t perf_env__e_machine(struct perf_env *env, uint= 32_t *e_flags); const char *perf_env__arch(struct perf_env *env); const char *perf_env__arch_strerrno(uint16_t e_machine, int err); 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 AB7CB3AB47A for ; Tue, 2 Jun 2026 06:25:42 +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=1780381544; cv=none; b=H3iIMgmzC6v+COsaCTFb/Yc7dPdcmUuvcZDhNlQqeJA8IltMgkgyWo1ssYnW78oN1yPhlAv1qCn9efJ6m2bp323fZj9Lr+8FQgwaWrGpoGZKCTnn9gdxggLGnTHxBpuT3/7RMrdXO+/yE0iHoTn81TYeOgN4JjULpJTvNocBkh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381544; c=relaxed/simple; bh=+HWu3kknbAU6zmq4lRWiOai1xYxbk6BxTlgjRcQiUOM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bAGMwJRHnD4uzGKNkz17ctw2HPu78fzix/dIdabtTIkVm7tC8O4UpOcVpl42lK710uagBRr556adC2DnLAQgi8XowEK3BgCL6rtkXQ7Hih9xd7+MZXng3+096pd3GH1HNuz0tUh+MIYcl+blCDukP1OgL/et5VpE18EAcoGbeUM= 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=VuDnb/3u; 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="VuDnb/3u" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304d8613efbso5500562eec.1 for ; Mon, 01 Jun 2026 23:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381542; x=1780986342; 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=EkWPJsl54oiAo7QwOctwflOU3eh1lLgDAtP7+GmkHCE=; b=VuDnb/3u4hTpBZlzHl/Paax+nkqp9sJE9qg5aNeJ8yAOw9bTlt7LfIEOcpZZb7oxjJ 6DNlBVa7hsfH2lKKtlyVNvPskbCoUEsJzETmLC2ZODvJ7DJXQYf9jO3Sl7d9NERVSQT0 /yN09O+0X7NS/pu37XkW6xzqzG9y7lQ9KoVNy/dv1Ex6QBV2dYvKrw2je7co/aNhCgX3 3m13gmqDDlQaIseBLYNlbUCyMjVMdPfch0gC97EkWoyCc5Ohu+y1iNR+cTJjNKF6B6Kl DakwzYoax+vCW+2MsqkrV7HxJsIM4e5ss085X5mTIFjOekju1J+ng9ZFzWvzk5TltJEz xpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381542; x=1780986342; 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=EkWPJsl54oiAo7QwOctwflOU3eh1lLgDAtP7+GmkHCE=; b=aEaY3Q/LIh2I7X48uHqORAtWwWs9Np/vd207inMQFbuyMzpMjvN0h7JiLZjHcmvLhD r6Gct4XYrwFE1C3aRxK8vr4UMO+sWAcO0vEv7VvhglRztyrELYkzB7J7hmlp9r7gIITr zBq0uu6UHSWhUidggzbzU4k2G28JuGwK9VoS3KZjjs7QpHDkPY8szOxPgqihKEemaHvk 7pnwDjWC/r+WSVlqKrVKVHAxHTBKvMeahmAL4VPRMi/M+X7CM4LgTqftyEN9xOVWVTV3 J6nfjdCF0KZIoG3za3cRmc/F56vmGPXgxrggI782hxB6PojDbKLHPMJWV7Ve9uzRqtlM sh0w== X-Forwarded-Encrypted: i=1; AFNElJ9ki+Ec/D54z/UKC1kFUorzIJO0WjMUywn2dIUHwP24abhIKNAS0jRa5O+8pb3C+SyBLOHnbU2aTuNWgag=@vger.kernel.org X-Gm-Message-State: AOJu0Ywh0a3XFRGsRtIM6YQ+40C/3uSIIPs03onQpeB4mnC7nRDY8CYq npp71JNBfsmYYLaRFciAZBbn05fsAqlRV8p8Tih5elihx5e6ShiYAH9j3Mm2e/XotO7TasUcuFd PPEe+XRQQhQ== X-Received: from dlak23.prod.google.com ([2002:a05:701b:2917:b0:135:e116:73ce]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6ba4:b0:137:eac4:82e4 with SMTP id a92af1059eb24-137eac4897amr2386077c88.17.1780381541777; Mon, 01 Jun 2026 23:25:41 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:48 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-17-irogers@google.com> Subject: [PATCH v11 16/19] perf env: Add mutex to protect lazy environment initialization 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" Introduce a mutex to 'struct perf_env' to safely protect lazy metadata setup, such as os_release or e_machine resolution, preventing concurrent initialization data races and memory leaks during multi-threaded profiling or symbol loading. Signed-off-by: Ian Rogers --- tools/perf/util/env.c | 3 +++ tools/perf/util/env.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 28c54c58193e..4de07cc7ef5d 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -250,6 +250,8 @@ void perf_env__exit(struct perf_env *env) { int i, j; =20 + mutex_destroy(&env->lock); + perf_env__purge_bpf(env); perf_env__purge_cgroups(env); zfree(&env->hostname); @@ -307,6 +309,7 @@ void perf_env__init(struct perf_env *env) init_rwsem(&env->bpf_progs.lock); #endif env->kernel_is_64_bit =3D -1; + mutex_init(&env->lock); } =20 static void perf_env__init_kernel_mode(struct perf_env *env) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 83e74328798f..6aaf80c640bd 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -6,6 +6,7 @@ #include #include "cpumap.h" #include "rwsem.h" +#include "mutex.h" =20 struct perf_cpu_map; =20 @@ -156,6 +157,8 @@ struct perf_env { */ bool enabled; } clock; + /* Protects lazy environment initialization (e.g. os_release, e_machine).= */ + struct mutex lock; }; =20 enum perf_compress_type { --=20 2.54.0.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 EFBA23ADB99 for ; Tue, 2 Jun 2026 06:25:44 +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=1780381546; cv=none; b=I4aYE5NBA2pV1AkNgEhaxGN25JHsrlyK4jdY1om/8T0DAbfeJjirUl1eATTNbk7+2ZzU+eva0wHWBx4SIAwtj6zn2OIUdGo9EaTrtovr95kEkTPxuWLfDM8vGwyWih9P5uBpWrgFCVMWiAq8A7GfSiYX3ptVFuRP48ckZ+dT8n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381546; c=relaxed/simple; bh=oEPhQLX1Ek4JDEAMVVpTFAR48XHl01x2bHjumb3ugBY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OWcyCWaoh6qvMw9JQJDG8Qp571fcBDlohY3Mf+wXuBqASIgaq1qnW0TzSROVD2tDOmv5O4eJWnZE5YGQ8fsxCEsiHMHmKJUc7S8zen05/DSBk0Sk2SDuHWVgaKSqyFAKpesai5BmFmvckOX2x3kuiyou9Klbq/P+/YJLr/ADuPc= 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=l9U+5Vxw; 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="l9U+5Vxw" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304df51ff3eso5042643eec.0 for ; Mon, 01 Jun 2026 23:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381544; x=1780986344; 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=UDEMzS2LWsX2K2Wf8/+Lc3Fjy/mUFJQImrq1SId6ylE=; b=l9U+5VxwcVO4v0mmz0hm+WJWIi+ppLlIkfTSRdlpT4NDMuM2DulkpyQ4jF2E8GVMD2 i70e2iQ/gKKlOSgm4nYHX0RbSWZ6j/00WxyT0jC5WXDoQsD89ddClbCeu4iGSkq56Pdy hKuiNVZ5s71CwBDbMNVtWF2uqKgiwe3qAE2EIE0QilAqL3t1aiCtKDemYlLx8zdHPhI1 U3WQmGnsb+iXIM4YJGiWNshJeUwC0ilr8WXU2JxGnLWt5xHYU3OjUa3MLHp4QOtWrcjV 0nBprkTKj26hth0UEz2nB2+yFVqKXyhItfWQuI/HbVqSmkRGCYd0D9O3zKuU0oTU3uR9 DeHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381544; x=1780986344; 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=UDEMzS2LWsX2K2Wf8/+Lc3Fjy/mUFJQImrq1SId6ylE=; b=XGcrgS0uZ612GnED5LR8tem6IKryEloo5D+X0b0YD2Mn5oSx4tuH94/sqNcIdy9Dv5 gkh6MwIj1nsRXQx+WTUlxEQGF8ufJ2/xm+q0JF966+sjeTHjhG71+A8+GWDycQArW3qA rIs7e7U8SLKyLPA60tzUiqW0K9MsC9Q5BPNuY0G44CXxzW09PgBKd8SNLISZeejBDuoR wMq/oWZFG2sgYKJAMbA8nZIHoeOYKk8i8MYjMx+NCNkFjWYfL4xtop4Hpvat9H59UMpY FG2HycIe1udhSBbVeJV7nRJU5qFHL4d2TdoSDPcmerADmxXmjax1baSPnZJXNrORbWbl Nv+Q== X-Forwarded-Encrypted: i=1; AFNElJ814WV/oxYKLISw3z6kzB6pidrJtf/ORRBUncb6SsUSexCE0s16udELKadek1ziPo0iPTd5FYpDaLg2IbQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxm9R8b7VRkOzUPMty+0wRi6IkhOle3qbd1r/T7CFJTkA+1+HGp zgE5O54M0QNhT2W2xntw6nrPmtjgU3Ox6h/gkUReEgwre+AJxBRUKYI5m3Ndk36OwniwKZfbWDd FT7yg8Sq9YQ== X-Received: from dycmo12.prod.google.com ([2002:a05:693c:26cc:b0:2e5:fa99:f6e4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:8605:b0:304:de43:130 with SMTP id 5a478bee46e88-304fa4cfa07mr7002031eec.2.1780381543973; Mon, 01 Jun 2026 23:25:43 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:49 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-18-irogers@google.com> Subject: [PATCH v11 17/19] 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 | 38 +++++++++++++++++++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/header.c | 16 ++++++++---- tools/perf/util/symbol.c | 4 +-- 6 files changed, 57 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 4de07cc7ef5d..61b30f08493a 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -361,6 +361,44 @@ 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; + const char *release; + + if (!env) + return perf_version_string; + + mutex_lock(&env->lock); + if (env->os_release) { + release =3D env->os_release; + goto out; + } + + /* + * If env->arch is set, this is an offline target environment. + * If the os_release is not populated in the file, we do not want + * to poison it with the host's release which would break guest checks. + */ + if (env->arch) { + release =3D NULL; + goto out; + } + + /* + * 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); + release =3D env->os_release ?: perf_version_string; +out: + mutex_unlock(&env->lock); + return release; +} + 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 6aaf80c640bd..7621d1f73b83 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -176,6 +176,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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 05ECE3AFAEB for ; Tue, 2 Jun 2026 06:25:46 +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=1780381549; cv=none; b=mZ/NsLO0Az2Hb9JIi+oXpiYPmgKo+D3NW71TaXBPuwg/86N08U/f46cGrUDSLKPcI3nQBFixri+8eAeGuG7dR/bjtb7ylrSpb54wTivUpQR3Mrs/VNiQrx8Thf4HIvc05KYF7AXgXxzd6t5a/pI6+HYK0kyIcqs7jQslaOiRQV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381549; c=relaxed/simple; bh=LePQNqGvJ2A+ROpIEFl18sb1h+CnJ+2PiWF+y9+Y388=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=P6lzZPCkfOAqY/pt5RB8TtL/yzgDR+2yyO+mMoDyLwyqMmmShiaiW+nHV40uJkHY4oj4CfjsQ9JkqSzrzuHxd0DgTlsCxgTJeF2sd1QWofBE9ffriXdYpgJf6fgHB8w0SEdrxGnX257lkfDaLAekciPPEI9P8RFxYKHAHosTclE= 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=Qwbpy6qE; 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="Qwbpy6qE" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304b8d0ee63so8931631eec.0 for ; Mon, 01 Jun 2026 23:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381546; x=1780986346; 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=x7R5sAqdverw0RxtQJ1e+c3ZDc+RMlk7YTjzX/tVENw=; b=Qwbpy6qENtngsfM0/4HnOni2WuBoikeWJHJ4IBEPJTBzN4qOOwOxFM8/jJ/JTuLojt S9K+jbGUB+tlqXexFCvpj4tUcOZVrNTH9FYLNvjvm9HG7zxqFFVeBxVXJKiY3i1fABIk 3kb5Y4uG6x520SVAMiehI8ujeEGJh7/8Nf7Y0i4WPlD4/xw61faozjSobdkQTFTkD+DU Y1MLuTFUjM4cAQTmVPKOS6M/5c0Ny+b6XIFJM966Hin1RzL6XQjGHdEJgxnMjxdCRf7Z 3ka1T5icOrziQHn/O+uAeJEqgU4SjPWUDrEsXptqvr6wqvDAjNaEecmj3FtxMHU1SHO5 r4Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381546; x=1780986346; 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=x7R5sAqdverw0RxtQJ1e+c3ZDc+RMlk7YTjzX/tVENw=; b=XGx+RdQ6bSRn/H9XvLAu/yBxqY46MxoJmIdO09TnRNwUWAWN6bL1NPvyFEGsRWcywU V7DQECivJtXIUoIOWU/vd3gZO42pB3RaFK07517o4P04/7zUNTGhaYXXhSyyvncOLqxA afw09l9g5y3ovIHqGbT7u07IRm+hmnI1G1NPf3rcimZv6CyT6cb72HLZ79shcBCTrMkZ jzoq/62aKgZAcir3mH7E9F2utVMMD9/sOWjXE9uoGUCcxuifBFCbd7WmfjnCN0jR2N0z g43zJnH5EiRDsnMkduR5l7PJzWzkvIzlLa/SwJdxBJZRlu/wYJ3f0IdyVNPqdGcEpqL7 msdQ== X-Forwarded-Encrypted: i=1; AFNElJ+soPxfYl/FXz4fWmNC6d39hBSndqnIo3WLASgF0DgJSQmN5bSwToXV+79SEy+XkcbNNJJ5x1jLCGnrYxc=@vger.kernel.org X-Gm-Message-State: AOJu0YxgXvFSAlUKRGZFtjRTE4V7RViIXgFFEz7kWOdbiUPBPoA/YwwL N/R44thiG2tCy6LV4xvqx1obnDnf5td8aHismn3LwpxFbfbRMV9grl47oBAjN1OdN94HQb0rDhN ADUpwQlK7cg== X-Received: from dybbs37.prod.google.com ([2002:a05:7300:a225:b0:2f9:af7:504f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4312:b0:2ce:25be:c8e8 with SMTP id 5a478bee46e88-304fa5a8b1amr7822170eec.17.1780381545916; Mon, 01 Jun 2026 23:25:45 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:50 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-19-irogers@google.com> Subject: [PATCH v11 18/19] 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 | 10 +-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/builtin-top.c | 7 +- 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/libdw.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 | 86 +++++++++++++++---- tools/perf/util/symbol.h | 78 +++++++++++++---- tools/perf/util/symbol_fprintf.c | 4 +- 26 files changed, 183 insertions(+), 80 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d8cb1f562f69..75ffe31d03fe 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -549,13 +549,11 @@ static int perf_event__convert_sample_callchain(const= struct perf_tool *tool, =20 node =3D cursor->first; for (k =3D 0; k < cursor->nr && i < PERF_MAX_STACK_DEPTH; k++) { - 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) - /* we can't handle inlined callchains */; - else + if (!(machine->single_address_space && + machine__kernel_ip(machine, node->ip)) && + !(node->ms.sym && symbol__inlined(node->ms.sym))) { inject->raw_callchain->ips[i++] =3D node->ip; + } =20 node =3D node->next; } 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..1211401616ee 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,8 @@ 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.map) : NULL, machine->e= nv)) { 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/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; 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..ddd3106b03b1 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,21 @@ int modules__parse(const char *filename, void *arg, return err; } =20 +bool symbol__is_idle(struct symbol *sym, + const struct dso *dso __maybe_unused, + struct perf_env *env __maybe_unused) +{ + 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 +2545,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..16a27074a474 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -27,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. @@ -58,6 +60,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 +88,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 +98,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(struct symbol *sym, const struct dso *dso, struct per= f_env *env); + +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 @@ -169,7 +218,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); 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.929.g9b7fa37559-goog From nobody Mon Jun 8 04:15:15 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 DDF393B19A5 for ; Tue, 2 Jun 2026 06:25:48 +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=1780381550; cv=none; b=tiHU2SwhHLqjSm+a3Ky6fXFc4A1nbTRY28NkWuUjTdU1IXPCC7SieaLOkoEGLh9QIAA/k+6yxwRYHMNHBGTF0MGWr/UBAmrg9SUgcDxd2HK8kn5tMOatEJwTomGOISBBVKoQaQ5IS9OEhgxOrQQTIr3SYSU7xP+583wIIUZCsTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780381550; c=relaxed/simple; bh=gthxRtD5VEATbV+0nsoc/5x3IeZxemKQBzZozOhGM4M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jo3BQTuEzCuHRlb2cHtTSLEsY9kc4pC294BRkaRsHGv0liYglUsk9RE/UA/h0lvAwTuRNM/tbSHke+8+w5FOI/q33CBdqnVbHaxAvV++cGQZw/iyuIMxI4l5o11WfZGwJUpToED5IFc6mQxSO8pzcsT55mwnuRWknwCgV3o1/t4= 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=DAknzgqW; 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="DAknzgqW" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-3041ab826ddso18573164eec.0 for ; Mon, 01 Jun 2026 23:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780381548; x=1780986348; 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=AyqcFhrF9yKP3hkIxQRO9vNVLIIWlwktE1+hfye7zWw=; b=DAknzgqWSc93/tz/eYHFOh8QL7OWqQCTh4LOagDl14HBGEzojVg2xhGhZl2KzoZY+8 9002L6FXMYL0dA+/0T5DdMM/uy3GoVGAhFSxiQ+gkqo0xb37ibjQrhW5mdOhVufGs79i n3rwjrQeTPFyT3BHZZ853UWT+0FreUmU3yEZ8WpyYcUeT2UBrFLiyAMgO4QL9CHQG7dV +3Aza3s1opK/O4iCA215AWSVNnn75aCNdHqS2ulQ3VZLjCS7wN6jjYDpfJ/4FsQSFaKR VN+uWyIOk9qxm3Q1zYpIQsYF5EFLG5irGOInwtWXxJun14RE/OOpoMHe7fbVrC3yz6MP 49BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780381548; x=1780986348; 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=AyqcFhrF9yKP3hkIxQRO9vNVLIIWlwktE1+hfye7zWw=; b=kXA3c9KV35FpHHClW2lCRb6Qq2CPTPmkodMiB6wVr3I+xr3i2eYgzOwnryKgBijGRx v5pkmIzHJA6l0z0ThgFp3WfQa8SVNcib0yW3Smt+fm6Z+q0Q0AaiKqkrjuGt/JnrCdNi yDghdiZFbzTFQxpz1CPyxV5tMG5QGzwZxn8BI5UTDUUocMEaaN+tDuOaTmklR81OxILd px+XBs79bzpcguJzhlhrxciIwjFqj8ILx0aw7BjLBQBbK49QOaziMgL/0XqOXCibDsH2 3KHL1t+MTtN38sl5z3prnl2Ai6sipHeqho8/R2TnVDTxDfZZE5Y/FrVkvHHTekDOim3Q 85HQ== X-Forwarded-Encrypted: i=1; AFNElJ9TpcSSoU73KvyKaOmIL+8uqShgPGsMtpbxpzcSciIK0S7KZA85tmo0CBWKMPSpbrclr4dWewejSY1PlrU=@vger.kernel.org X-Gm-Message-State: AOJu0YyhpL4tiM30uLOQyVc4aME4x9DQORCPa97PwHMwnbSxqB7ZTLMU HV8hirF/U/LkO4Vc1v8cRcmgF043X12EprCSCwQvisamuM2Jrh89L3cQm8s8aV7U41WIOSmSybb AQm9qMOqvjA== X-Received: from dyclw21.prod.google.com ([2002:a05:693c:2115:b0:304:3262:502a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6da3:b0:304:997c:d47a with SMTP id 5a478bee46e88-304fa4eded0mr6081789eec.10.1780381547885; Mon, 01 Jun 2026 23:25:47 -0700 (PDT) Date: Mon, 1 Jun 2026 23:24:51 -0700 In-Reply-To: <20260602062452.2583619-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: <20260601065407.1597927-1-irogers@google.com> <20260602062452.2583619-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602062452.2583619-20-irogers@google.com> Subject: [PATCH v11 19/19] 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 | 146 +++++++++++++++++++++++------------ tools/perf/util/symbol.h | 4 +- 3 files changed, 100 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 ddd3106b03b1..0c46b24ee098 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,57 +747,120 @@ int modules__parse(const char *filename, void *arg, return err; } =20 -bool symbol__is_idle(struct symbol *sym, - const struct dso *dso __maybe_unused, - struct perf_env *env __maybe_unused) -{ - 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; =20 - if (idle_symbols_list) - return strlist__has_entry(idle_symbols_list, name); + { + 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; =20 - idle_symbols_list =3D strlist__new(NULL, NULL); + if (idle_val !=3D SYMBOL_IDLE__UNKNOWN) + return idle_val =3D=3D SYMBOL_IDLE__IDLE; + } =20 - for (i =3D 0; idle_symbols[i]; i++) - strlist__add(idle_symbols_list, idle_symbols[i]); + 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++; + + 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; + } + + e_machine =3D (env && env->arch) ? perf_env__e_machine(env, NULL) : EM_NO= NE; + if (e_machine =3D=3D EM_NONE && dso) + e_machine =3D dso__e_machine((struct dso *)dso, NULL, NULL); + if (e_machine =3D=3D EM_NONE && env) + e_machine =3D perf_env__e_machine(env, NULL); + + 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; + } + } + + 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; =20 - return strlist__has_entry(idle_symbols_list, name); + /* + * 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, @@ -839,7 +889,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 16a27074a474..a71525335703 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -76,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). @@ -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.929.g9b7fa37559-goog