From nobody Mon Jun 8 04:24:56 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 025053EDE67 for ; Tue, 2 Jun 2026 15:25:27 +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=1780413930; cv=none; b=gINeSDRX193FqnJQcvYVccP/3psvcSo7nOsJvi+SXYK3Wr1dfFGSQQjF1Di/4+5XVrl+kMsGegiG53rgHYdEiuGc0kjdWPmR0GFW2B7mcbCyPpM7Odh2EeDB839EdsDMgMqkqebdDOlKoTMWfROZS4ELhvZnW+zlnO7nUHDGCpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413930; c=relaxed/simple; bh=u7c9g9Q86wywE0esgfVk6mGtB1xAEG3jjpKJRDS8jao=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GwnkJB2Ym/2xP66zP9JYH6cYYGls9McJcsaH8XTZPsXQm2brnHmtFC/gn8uC4TuAkYyOW4JU6jbzvPevKLDxoAvZyd0yBLmO9oHqZGO8SBOacsgy91P5gpoR78R6raUKYrmz4RFa5YZbbtOjMsk+QqrawfXSrWt71A5FjsfiwL0= 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=fhXAsy1X; 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="fhXAsy1X" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137ea73393cso6482281c88.0 for ; Tue, 02 Jun 2026 08:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413927; x=1781018727; 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=fhXAsy1X95Y5i6g+cno1msulwC6sEQ11rX1VKZ39jt7sT6CHq/9vYaS2chuiMhjUSd SGYskOF5HruxdyxoI3WTdDedev8V4YsbA3nK80Vx5r1JKULEXVv7Uz+Tg+89Qdybw6b+ uonUBhTT70ZTrPoQuO6iaGV6RW07NsrCvlsZSUhIrw7iG7qNQjW9/iyT5RTYvIFKdm12 XjwRgnQKhQ6fhmu+0/0NI+TkZTTk/1vDrYm/K83EIBOG1HQHBF6KP4WMu19jGdAcshK5 bZOzkQjbs7dXkynNDHpMqEatMX9pdtPAFxTVg/233l/BTqaO/QFAet3m56beg3Ze/CIv jKtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413927; x=1781018727; 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=PVZ0K4Nke2NL8sCLpsDZVrlHFH5WUM4Xp3CH6q5tLtUZDTumcWnABst3XTfHCFTH6w wte1kfLyBknaLW9ET3oEtNDsgyUg4Kr3BY+Bl5ICr8jFr/+lmS90+UabfsktzIN9abLS ZA7PSdiZFFf4oD+cFDTlaJGBBaVIKMf6W3+qqRohaF1DNiSGCXVsrplNTjE0vfXMVatS d+HjYyBbLCj9gU49ZGrWUlg1Qe3ihmAWLJLU+qrVKlHFhhi5XOW0dLzMvPkFYfYOW1Zk pAOlm1dCd+HzxbZLNZfmIy7crhEUzqF6EIIkBqVl2AspBO4tiu0oNd22GIzGAx+hcfla NwpQ== X-Forwarded-Encrypted: i=1; AFNElJ8vmJjT/oqF6dAexHz+QEUHJ483ALfbG6h/cK6Mj+Q5f2uIlyY8qRydfaqMnmV1eyblwS32xNu8bC8tkAM=@vger.kernel.org X-Gm-Message-State: AOJu0YxzlvRrwEvn28nB4mEtC1/PTe7EbNnNSzIT59see0RhFOJK1TmQ oM4AKrX6CTOZHGYRB/IWolcCEuiMwvf1auJBolg2ypzAoxWGQCSe0MuNzmP0YpTQR6puMsI07zg bAjmCMxxcDQ== X-Received: from dlbtv3.prod.google.com ([2002:a05:7022:3c83:b0:137:ee95:320c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2601:b0:137:567:14c9 with SMTP id a92af1059eb24-137d4271eefmr7038062c88.25.1780413926762; Tue, 02 Jun 2026 08:25:26 -0700 (PDT) Date: Tue, 2 Jun 2026 08:24:58 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-2-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 D6E9B3EDAD8 for ; Tue, 2 Jun 2026 15:25:30 +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=1780413932; cv=none; b=dB1ks/vzJJ236SriDF0jdDVOJwe5nu2PEPlIrzJurVz1/0O3KoiHY6UU8SBWKhmWhhGpMBGZUuIISmhnCNzEl3b4PvLXpExPtwkDr14IiOAMkyrzSICPkA8QhIKQu8Do7R8jpzI0fQ58sHnmPIw8r4seHpHC/FiCZFzgIojpz5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413932; c=relaxed/simple; bh=N60q5hQpJzgcj0gMAcG8lAo3SHZ3TJCXTm5Qt0ml33o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=h7J8ppmMCb8vaM0avaV18/CAJZds8vF7r+X69pvHQY5Mhzl33DXOw1sstEHN7qUA0CfdYzSYjhEAGUSKLDEk3g4BCafOB/OWgPrk/KnKsvSLpodusSKqhbovBjKYjEll9+v/nA+vxGvEXJNP7MWyOfQo3I0Gju2xiJmMP/LaEE8= 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=gSuV75b/; 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="gSuV75b/" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137d003cf09so9030880c88.1 for ; Tue, 02 Jun 2026 08:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413930; x=1781018730; 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=gSuV75b/Gj26Caqgr14V7fPCPCz6vamEemDAnVy176kYqNSxbxuLculdIER3NXZ/RM C3LD26z5iUhPUUQE83XSg+XPqxmw4Z4d4Ei55pR8yyU191VsdBBmzEF02FwcrlMMgLSa 74dOGSG/RTxWpaDnYwRdoPK6fMNZlZ7A6KbpQ6+89i7MfIP0+FZI5AOtE9x2lCPnV2xa NpV8fXAdy99GLIacVyv5e5IuosKSmBxFWMC9Sa9YY1QYrYgBR/k8/hwQx0u6pytefqXf sIFoIc7xDG+gWiSxpowBa72BYSa9GzwpQDwxaYYidCYzzakrE49QMi9VT1tAKOheiaC7 zPMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413930; x=1781018730; 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=UIKcmjirxq13BgCwQR/dJ2ch/N/OJCevxJNQ9Qp5C8IvLIKRmcUqTMwdDJZkWLncex clygm/RqKO9Rpyw2OE3gnFeeYUC084FEHrUNEY8+Qz0BhvQ8o5bddTuxhCcx8eqJL0F6 JSi4dyEkClAWOOWyUQnKZYQCh8wCqqskiU8zbYEr87sidG4GI8hy3l4Djg3J54S6wFn5 uX3DIcGVXSG0fPZaz3cVURG3mnQ4EMtuR9TjPpaGHBot1tQms0Z01O2c8wFzIXKwfPM4 6R1MSzNHz2U/87X0orZ3xXVjFqtM7sV9zDekF7/v/MOqT11rSQeOaCECSgWJtPmQdMW8 iZig== X-Forwarded-Encrypted: i=1; AFNElJ/cnmZqMpm1iCM8/DOWm7nf+nmRLUYYsk0IpvYZzMn6Xkoos4W+VDx+73BlzTYdt20jNQwwnYz4q9ZjW94=@vger.kernel.org X-Gm-Message-State: AOJu0Yz96NsH2VN6W863Ahe2TGLNteLODSmuYxfajeiDvCSARXD6iWLP L27vdLknhzk/hfJwJeYAwO2rmzObulv9OvbBoT+xhCrvMaO8It2wNLtp3/lSEDWDwfG939cKwwu WsKb8b8jaJw== X-Received: from dlbut14.prod.google.com ([2002:a05:7022:7e0e:b0:137:ee55:b187]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:11f:b0:134:d708:1a24 with SMTP id a92af1059eb24-137d412366amr7692863c88.17.1780413929669; Tue, 02 Jun 2026 08:25:29 -0700 (PDT) Date: Tue, 2 Jun 2026 08:24:59 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-3-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 89D863F075C for ; Tue, 2 Jun 2026 15:25:34 +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=1780413936; cv=none; b=aIBvRKeq+kTMc/Gk1PupM/+bSPPrB54wAR+KjMqohcVGmsCy0tbmpUWnPViMs5QQPfbDdND3wnUP9u5h+JqceuHd4fjhFQaOjChTzmRxkKZpXyRw4p+NL/BXAkWsSWCXB5Y5CWggNgfCPxOP0vGDPl53EgADvRbueTXT7/IpNbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413936; c=relaxed/simple; bh=azv2pBu2JzgGiyYsHqFDUXP8g7tfdhTUd7ip2wDqkv4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I+FY1tmxObQQfBA5M5SVbiuZhCwC21IVIjNe9UZ4XZSXMEBHzQqulUH22BRsiFt60jWwkmrI7Ue9jlDDPPe1uDssqEGlApe46dLXkMUkJTGSsI5cGT+KetEGMDjE8Bbr0Bnyt6/CsJH2IoJHELEY9wlTiGQhhooMlsa+FPQ3W+I= 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=Me6nXYi9; 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="Me6nXYi9" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-135916eefa0so20324717c88.1 for ; Tue, 02 Jun 2026 08:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413934; x=1781018734; 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=Me6nXYi9Q8TuvAxNoY4/WrfEoq8LhDnuoghXk1Dcu7BGlETsm6CbBJl1uOWxGa91oR N7zuL+2GOIDsdXPW73A6vHusaU7mm1NOpiHoO6TEP9tKee6PKj8jKSb97TPo38N4JtIT SQd8OfUGtrVpBqZkSolyrJUbl7VNbTEd62Nm6vraC2+UwmjBMwhDiNsjZjQV6q5OiBlg Q5inMlLdN+jiegLC7xV54n5dQf9s3b0fnjhqo7PJx8ptublw1V+7ucmYNjyPaiZzRyQv Q91sdz5FBCFZF2nTQRyCbo1BLYg/i7lbwBAGtS1sJ77V7R49f2PaVyhJqq5NHwl4P7AK uZkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413934; x=1781018734; 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=KH5Ryq2eAtlIlVKqNaLbrHFG7rko8TBSa97u1fXq0s8gSd9hfmFThY0+quqUd9ma84 rn5x7uEkxPv9G+oPFzlbKa6Q/jujTKT+NK/1zJiKXGq3g+brRfauAvAQtNDtjSta2RLo veMjVfgz9aPKUSLag1OxLKH0a19rAshr/zGIabIae3C87JzRnX4E5o3mtwej/6jcZQah zncG66ojyE2QsF5t9WYr3Su7WWh0Z+x3sTJaMXm/RobsGdM3rWXUNrgnhi0QmoSd5XMu xt/Kho0iTuCWAZDFvXHs4KHT/f9kSsG8ku2qhhDYI6Znjmbwgt+4Yu85DLERNIKeQUwT mwUQ== X-Forwarded-Encrypted: i=1; AFNElJ+m7DiMOCsy7GjDotTxCvKzNtLHcXjIsLighdg6hGsGKwE9EzLxXrj7gJhZP2a1xhINiwb0u2HK3/spwqI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+KujcUWD5Wa2tU+32yzGpBKs2RDTMmMnmi3Vrnrem2lTTIKSo U+O5Mtbr5/Bgmk54Xj6/42NBlVuSfiqWwDgg4ioZRbkdTSj8oVQkqhJ6ISlUk/ze1HDliCb598B Dh6xgTN5jFw== 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:45a7:b0:12a:b39a:339f with SMTP id a92af1059eb24-137d413a1eamr6230153c88.21.1780413933329; Tue, 02 Jun 2026 08:25:33 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:00 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-4-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F369360EFF for ; Tue, 2 Jun 2026 15:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413939; cv=none; b=EUgsVX14E/4eiqRTXSAYxX8KdFtWrDKNzi5GWpzlEeJbY2tfUCqHtQpeRsE9OlGitFBdZ6AHnyOmazTUZv426pA3YoxqMhPe7yGDYXAPmpOUzzhh71041EPaNWs+bnkawnyak73COtYIuwrbnJW6BTKh/Oi//WtLaJby7jo+2sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413939; c=relaxed/simple; bh=v2jPVgU7NcmbpJgeZh9blErLQKEVvFwnJwLEwzd0nZY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=L7ffXNKatsg6OZQekAM7aU4mAb/OloLHYp9k+++S/BJf70i9e/cVYvWjAB314Fg1tQdAX2ZtVUaSnU185mSMJ75bs2AacbSjoSNddKj97GMsZavQuugKvLIKCwlB0SOrf6UoiHecEcsUyX0qEkgwoyv2pEZ2Sd4o0+6W2hG75Zs= 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=G1wLqWxW; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G1wLqWxW" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304d8e9563eso6438910eec.0 for ; Tue, 02 Jun 2026 08:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413937; x=1781018737; 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=G1wLqWxWbkz5Y53IWFiQzk5mf4UxFG0NYS2L7pWeIz0jWBGoG55F2L+AUaPeUhV+f/ VKcSetci7hM9CCVQ1zPMT5R0Xq2lqf5jaaQ13s7D/kMlXRLPtAcmIWLzXm2TKSsZbjnm EA0sl+r3aiipjWBYs25x2LUJ1k+TUEXGfoD1UQAULMxhi0fjHyebOgQK5WZq3n8pJLIt MJEeKlNeTEx0+pTUo48d7MHf+PGB3XhHglPr5euSU6VoBMXpWQGPHjYKx6PbD+FDCLR4 i6rGLtmhJcWjOENAybAwhon6RoveGfJUDZux6L2EOkc8Qd7nnlQsn9ekaGo2OmHFo2EJ Lasg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413937; x=1781018737; 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=Gu3jAX1bRG1bg/LwT4MnIDb6XctlhNv30M6AzPgXREU+u02vGdFvD+bVO7d69Oocud 6w29AAqS4PmGNHgmPmtkekv6b5e2+m2ZS1aWdC0845h/xn2mraSiBsOmKWpUol3y9tvE IuZ2vPQM5vycK2awMXvQgQ93nxE9DBJNxgzfSwzpxOsEbFr9MZtehcCQo5vsnXwbYJj6 sZgJOvgMB+JTYO28imOzQveCcUlL6phQ/125FN6s92O9DGz+q6o6DlwXysDMpx/fUoLW BkvGVXvFaWaJSN3RvFtavig0JvD4gwzGsJKqILlRukKlpyMCPPw6QFer/C3xTosw3iG2 tvoA== X-Forwarded-Encrypted: i=1; AFNElJ+lv28ULL4rMCm01QW2dl3T9Q8Zl4VowiZ1UF1qfDquRyp+4jM18iG+6zgwSwxWtMcckdkuhKcAG4EX4SA=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9G6er4HuZ+i/JRsg+a5VMtZy3r5AurhPtjoH2X2F1ISujr/n1 Fo1875NSoXYTA/qVkpPjwBgfK/8yACiAxAgA09T3sjYQKkntWyckM1pT0RLNR7bv6vxkLt2QHr1 aismEccBW8A== X-Received: from dyng38.prod.google.com ([2002:a05:7300:7f26:b0:304:ba41:e879]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:5714:b0:304:1fb6:88fd with SMTP id 5a478bee46e88-304fa693196mr8262550eec.29.1780413936861; Tue, 02 Jun 2026 08:25:36 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:01 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-5-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 C48CF3F1AA1 for ; Tue, 2 Jun 2026 15:25:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413942; cv=none; b=TFJ4zA92/EPDhM6IXaz3sxjtchHYtkKlLmxXyItB+olzES7JeuvODWv8MQ53BUCLXsjpL6lDtLMyybCKxuNLAYQUekBeuOdd32abJxsVKZMrxJHHQMBk3OeV5ZL/yyDiQpfj/0YEb63cSer2l/IiG2aVPQqjoaNrmUQNppVeNXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413942; c=relaxed/simple; bh=Hot18PBTr0xlrnqsGHwaghakJVRFa4BOmAiFycM1yig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Egch2z+/XYoGLtdHcxbwCcPSQO1KTPLuwtndcp7/tx5kGz49N9D6vxFdUJ9qbI+AE2M/9oow1QxoFaktJ6qb65YccAGua/6oTWIEqaRmgLRDejz2KwzlQ0uo7BhSKcCP+IhnrjMssQtnz4Nr8p9pEvB/pyjfANrzpVEJR4/KpiM= 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=sy9vV1MS; arc=none smtp.client-ip=209.85.210.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="sy9vV1MS" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8423efbfb61so1897595b3a.0 for ; Tue, 02 Jun 2026 08:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413940; x=1781018740; 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=sy9vV1MShk0vYFVjWEOVubQOwH7fGf95PjyaYdVWIbR0B1km0hkoY8LpFK/RcT/tGa Dzm8qLfC/1VbX2qHwAJCto9zpTjvZBvPSfAybOm+ICW4mYvnCJZEgE0To1eHFWIoJmJn DxvyUfdvjG68fxa23swL8zPTOIEEGusFhFm4oWilLDoPUUvi82bGPPXAJG2IaP/57EGh U9bU86iRBqADpTZOIyHxu20pt8h8fg3k1yXonFdzXBoo0sp+uTyzsmi8mGmbfvuonkLl vWmFUf6rkK17MUlKQsOyfxR7FlNhDPdu3h5JA2lHTadA14Cm8psCHKFmk7vix88hEdiv SD1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413940; x=1781018740; 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=TKdb/v8bV8/2vmDyzY/B50vwe19Qv3BPLZT+qIkvX5eZEugkHjrrOVXQ3ohnHXh5G5 gLV3Iw1hdYO7KviXZdPUnljSnJxf96+KAtxlmrbYQCfE7YFXStTRNraTpzLhsVZj9Gx1 xD+OyxKdPprAf25EQrHONPaU0MKlmizTBITnJiMvOYNHvhx3xXh5FgZSWaEWKJFG41/T YGDery9oo0vHiKBTE1V41kar8u5k2wc/pTPrtM6EoM1Xv5ijTDl7MOBUaHBGX0RG77KQ RB7g15YWnzeg+2m7YmAvdi5Bq5D+l8wPAvRRS6FalOMLDJuksamPuy90unLK73yfoHVK Aj3Q== X-Forwarded-Encrypted: i=1; AFNElJ+Chzp9kaQtpudy1kP+SinWX84Zp0TlrNqk+s0c7n/6ZlNNvgB15r1UKrEQ4TX0X54uv0Wmo4I+bL11Q34=@vger.kernel.org X-Gm-Message-State: AOJu0YxbhM77cjrbdpuhQ9od3LocOpuCs0/Ae7seZuHNTiPja1ST13e0 ppZqMbWTECSVZlVBOpTB4eAud7tn+V/BN9UBWMtjAwiExQLlvE6M9modx1nfO2xWr/qdkDImJu6 kRXHBzWsRrQ== X-Received: from pfbfh16.prod.google.com ([2002:a05:6a00:3910:b0:83f:1851:35f1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:984:b0:837:f79d:909 with SMTP id d2e1a72fcca58-84282fa448bmr60769b3a.39.1780413939718; Tue, 02 Jun 2026 08:25:39 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:02 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-6-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843481ACEDE for ; Tue, 2 Jun 2026 15:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413947; cv=none; b=Spa1ALKu5U8dSgeckXeumAVO1aFStzn5lOrFSN9rSluIwF88lQVh8J6cp7MgIFigLkJ2aIFbFhrFBNyemBiwHOwkCwNRcc9kCyfsY98VbFFjN5DOznF5nU1wuV22lEu6t1CojkOHxji4wtqXa6ZMLAdyZZ+q/kflQhOxLQ+05wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413947; c=relaxed/simple; bh=0E8FGILepgrTA6ONyBxd8a3wp5kiZDScmQzg7pssilk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JdgEv0r3EDyWrmwRF6YBrSLxKVwTzqg9oq1OeL6hD6kNOQf0hoW2nrgVhuWE/iTHEFcy8Cj8g82JHD3KIYRB6l5FQdDgJ4DjCX6u7jNTiex2DXJy6HAqDM0WZbQ7VOtfCg70nrxit22X8RR2tJF/mvytvUSZw/qGbus9gl+wPi0= 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=ikXpNy7U; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ikXpNy7U" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304e7fc90b1so4363445eec.1 for ; Tue, 02 Jun 2026 08:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413946; x=1781018746; 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=ikXpNy7UB8DL1vy3PrIkQ4VBxLWiJu1DXO5EtoldvJ10lemz6lMNH0kgmtfpdUxXNj QGLwmef6aTyEz4a7sciYbVk9xquIz5lNzt3mwtLPcIqG5UNjefBRIXMezqgCl7WAs3Ph iRpOH2YRrCphZ6Y4IzyQtbYXOHHZcL6O0zx4lLZc/jh39eluiImqmListDDijCrwzyvw T34mvyFaoezyYduCFapvQP++HGgfLru2IdYC4O6oPaFUpn/nVu8bOdJVd0GcDX8/qYCM IoTsa6+7zhrY3J4fKjoqFYl1P1Jp9GNZzhPoD2ldSRpXkv0LPUCbhBGoS4Bl0EY23XJv WZcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413946; x=1781018746; 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=iL/EMf380dD0GzPAuDP7PhoCEhF45fV3NHjvFsMVKe5rB+DWHs1Wfr/QhR95297FmV 39gtg1TvU03cbOwEmrUkuHeaBvmvUro6tX1fhx7SdjYPPQ9EUO6/EBIRph6er2t+63di h/hw4ze5gyupTBKAh+bPBCDGbqQNHQj2wOZs/g5BA3vcjTZxabkFT87hIrbT3EiOwRm0 Y3/zsSUgQiStOlHt/ig9PAsR58UE2HP3doZva4RltnceGa0qrEqDpWf0wc1ILIYdBqMa GjgvKUla9X+aD7nhhnOg1dHcrYAB8XXbc57cZgESs0IkNQk23wM9p0D/b/419BIckP6x YPMA== X-Forwarded-Encrypted: i=1; AFNElJ8OkLTtOduR6yT4YFwaO3cppKmpWgQkeBGgPbKTKtrV4Bujog48+tFBWn0xWDc3aGwZGIQCVxYaBgzfaR8=@vger.kernel.org X-Gm-Message-State: AOJu0YwkCwddTTw0KeL2Hh9LXjhYyYtno6OY94r7cKFTiHENYfajJ15s dguxcJV8AuWnMHDxfwXIxzPJ4NH8xJv4mIdfZGSgwVvpstuoqXxFkSjr9Nh+RPTI9E1Bs7NXbXa sOU7Bo7+wZA== X-Received: from dyckx5.prod.google.com ([2002:a05:7300:c7c5:b0:2d5:d26c:d4bc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:80c6:b0:2c5:220c:5670 with SMTP id 5a478bee46e88-304fa49cde7mr6868612eec.2.1780413945550; Tue, 02 Jun 2026 08:25:45 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:03 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-7-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 C8E993EFD35 for ; Tue, 2 Jun 2026 15:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413951; cv=none; b=N0X8YCG1Jk0hHhFkgLsYvlnuiYIa3C2+A0olXMQG6E+TBUTuQ7/X7QGjFLJIEsIyPXh6gj93+Hb6D27HsVN2EWHddv/9LxCjoKlk8XvRtCTBltN9T6dcGgmIc7nrx526Pj3JODeD8EB1uVYjQOxpzWNL4EL2x85rSmvTx+NkBqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413951; c=relaxed/simple; bh=Z4WrN2+59MV/rg4sfdg9lA449vNSt4qPYiJQIWHMBoA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l1HGwiResu/zoZf7ggvocKrc3Mm1UxJCP03wMedoQ+d3VZTy47jUfLWRcdaRIEsHNBFNO7HLgr1uMFMv4NntzC2YRithsHa/IiJgNM72nKmzvux9PWdDzD1DRBNz7vdoK4hqOcv16fmSwG7hFgMtGwFz/juE25GCCtpwHqSqZpU= 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=cHpOT/OE; 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="cHpOT/OE" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304ec73b015so6545530eec.1 for ; Tue, 02 Jun 2026 08:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413950; x=1781018750; 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=cHpOT/OEgbZR75uBRgqUZxEpYX7h5px/RexbA6cj6fQ9J2qubmxEGRWtHjMe2GFyNF +YxS0NRgLmtcJKxhqGuPVN0JFKlk82Q2gpf9OXRL5lIs9D9ubVIAf7MDyQoYyrOlyyt2 Enugjl3oW/PskPxxjhy+kLLc4oEpWtfe7YEFKm6dXW8MtogdFspNbhERyCHgGVmeoTi2 1EeSwMmoU/GiEXZghI00ZxmvUrTvjYC9ZlzAMGdalI5DP76ZFu/tkoUJSBbeE4ChCuTa 75eemB2VkTnHP/wynGz4Ja1fl8RdcCEYr/QXze7hF3Ocxv5qjY0LEEBTehvcVy1AdztJ zMWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413950; x=1781018750; 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=U3p8ehrkEQhW6wez2Qe16U6Jy1uVIUSxQ77zumuKgB37fbYkJmvFCKNVxGjkLngcy0 YNsOQ+GzXmleUGkOHiV8ttb0sV5oRIQ1HMeTZ8Q6Ln8hi9+T5iQ7oJL7eLVtJjxct4yw PXIzVSeut0889M0BOH6VBOII0c0nz7hzfyh0S1NNfg3VqVKocYX7wr3n8orRKCJ9wjmb hDXCJCK9gnROMxfMIyd7woq5cFyEIA8zyPqaoJueP/HgaZZ+BHA2DQfhSXUdXyrfSUiL dQQLJtAXKmondl1kzc/beGGZ41QteLcA6eRkMveu/8R3WqwMX53XA7sXKs1PG0rCr9fQ 39bQ== X-Forwarded-Encrypted: i=1; AFNElJ9Kt2HJHIYXSN6pzVblsDbVpNkYSnWrGV3AmI3ad5IchxOkph2Xp3AH4YKc57VNupEWdqBbiZBWPxCDDbA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Es9HSg5o8BLNk7JT66X+VW6TujS4GHZJ9W9IN5J/IDNN1Arg +Dj4CPZN34Hxfs51j5jjB0Kvkb9Z4vES6i7CUechFnp5iybfaEHOMqClFWnWFQ0csTEl+YfPewL eNZIElKbEig== X-Received: from dyaf4-n2.prod.google.com ([2002:a05:693c:8384:20b0:2f1:5dbf:fd4e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4306:b0:2ef:9961:27fa with SMTP id 5a478bee46e88-304fa5ee3bcmr8041922eec.18.1780413949696; Tue, 02 Jun 2026 08:25:49 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:04 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-8-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D44833F4118 for ; Tue, 2 Jun 2026 15:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413955; cv=none; b=EObFDYZ4H8pEqKQBDaNyt3XxR5pArcG/mGJlVlx8YOyGy6waM0V5Nt5v7pGhJ0NHZnwtZx6HCfbwTf2XCRM4DU+sjuOr6AmjbjDcVNwgqqP7tBBLmBZfUVeCHsrzyXeFhrtY7aDO0VRW1eOka3DH+oCmjWVSgIyMbvFU/JQNwp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413955; c=relaxed/simple; bh=uggu9Ed4XgP8/oXGEguF4UCtlrWJYr5XzPWI3Iz/dyc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vF2EOtndijHF+fVu5FziSXHp/78yNeTBZGmmTOH/q0siPgOtGBIaaklm0KkhA1JpMs10nFr1rVJhj42Io9JnRzDnbtaq1b+l0yeMsuWKXFxpy7815yBvZDRECCiOqRZVLSFSlF/21gE65eNkd1CrkbYQ+W1BcWmiC+TZu9vFj2A= 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=bLL7YU71; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bLL7YU71" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-3074797dfa9so557146eec.1 for ; Tue, 02 Jun 2026 08:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413953; x=1781018753; 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=bLL7YU711vgqrPEVEMaCyi/R/tttlJI0YnOZmYYTk5GlUhpK4VdJGUk+Q5S0AtSWcM 5E+HgHw7ne8cLZPBPwWJDA5InizSbDBMYi2QvIouHkM/9u6a9QMrJc9riABlQ4x0ZZI7 LVu4hCzheP647CB1K6b4JSq4HlDkX/bU/PyeXQ5XePI7t6VLznnYM6rfbX+2j4HyGTi9 ZyGP/KvRw12nPFaLyHEWW+4/f1kBSBo3jv7DK/WkMqqt3lT/VRYs5GIrcFjNVQkxM6FM vPYX+xNxwwDd+NZcGX3IjWCht0w9YACM5KDTzD+USjO1tZAqbw8LY99OFQ6CdB00NWBO jdVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413953; x=1781018753; 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=iCIb8TREES+EsAr6yMkrWVPsQyIU1Q4q1rvPBo8NI3CS4qzAE6/OwxYrW/E03BqIW0 l4v2IWxqayPz45Mehic1ohJfDcvzOGvF48YJB6jtXh6FFhV8IXVxRGTfADrB4C5Tplw/ egfbm2fKYtDsoGfG72I2m1zZvqi1Ep5FB4ojEzKb40NeSvHrDQ/C7eroLsAKfsfSzTro Wo9xYWTN22F4/hkg2K3M9molC8S4BCrCl9qCvORwS2pFNw3Yz9NMfs/CZTuYgLUncu0I PQXJATqrbD2udwShjHtZLsNLkHZAmL6aKkBkfKYaw+RghTHRUmyXg9f+LMmhCRCi4k+2 lvdg== X-Forwarded-Encrypted: i=1; AFNElJ8pfosLC0mqk+KZH8NcnWDI8xJ+qBW1xjICWaBAx30xJ84kSizsjgnfhegiVveOhiR0DNPnI9Ko4jtUWno=@vger.kernel.org X-Gm-Message-State: AOJu0YzyVfXf90jRdm0cZHFH789pKmxOrBWsKFGqwmiATnbCdl15rwxc /InwthynBKtJ+UslktIEujkjhbPKSrqK8jEmUTWqmEaVPfRRpPlLg4GWLtHREcZ/pHQLgL7JsLr GZ3HepT24iw== X-Received: from dycns4.prod.google.com ([2002:a05:7300:f784:b0:2ed:a84e:18d3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:72c5:b0:304:5a53:7dac with SMTP id 5a478bee46e88-304fa62a1c5mr7250460eec.25.1780413952808; Tue, 02 Jun 2026 08:25:52 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:05 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-9-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 6C96F3F44F6 for ; Tue, 2 Jun 2026 15:25:56 +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=1780413957; cv=none; b=Q5rn+BIO5jTuKwAyShznzdPYzDsLoY7uurmox9LUk2UIZ005ChAfKa/qvEUhIajDq+pFvTTC6jKoisR9Ud0SW0kPuU0o+DZp63RacSHEUCBPjUJ9PzR5U4JkhHznXMDbPMFrij6R4LTQ6zPUCQrysdtOQ8m2AeQMg1g0qafZnIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413957; c=relaxed/simple; bh=F2CPix35dUffd03PpiODYF/Y/HMWspE7itJrwYnRzhA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F5ihadIkXOxLP5NF/BniC3XuiXQDZIaK2VALvYmcUZcUGFwLzSw12Scwb03MuSeNUXXDTK2BxLgeh2+2/vRIu6V21+YnVJ9HMZ8AR+HCJvmaH2TT0cRA9+ae3r5InBjNnmFgKNrOy2RAmP0rDWEN//h1EPcI/tQnaB5/lddw0BU= 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=ekN9WwZe; 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="ekN9WwZe" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304b8d0ee63so9674367eec.0 for ; Tue, 02 Jun 2026 08:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413956; x=1781018756; 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=ekN9WwZe9vgxhiSymjEgDXS81b7P/iklusnYLDLAD9J2mHHKujbhioOhrFW+n8GDFs QeFEx4KtGuiu1DKwYYsBTqhMgQRntUozcV23KSP5C4vFuLR6qkJlKz1aPJusj2dBUMvb 1ces9Df/FU9+V9w5Xm6zLSt53awWFkVxMouBbDsmuNVlEWtWTcXf2IsaP59lVG/+RRBG LPAddkaVWwwPdYsmMRX+oBw2ekP6qrWyqGPoUD5+XxsGdBqwljqSoriO2Kz71C2W1DPd iIQ7Y6Qs8FqcU2D0QTsc+sU2K5XPsX/8gDOQVDR+6XVH4smoEPaUE0Hy05Qy4mYn4u4b /+5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413956; x=1781018756; 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=r3QCe4B7IJLwlwnecauiJ4CSnCTardtaLY34Nhgjln5UZdOjU+FczUgqJMVJnwVzge x9WcfV6hYf6tsUsZpkFDYCRv11NB5K52R6/wQfRjPFsPEiEmveoHYYKyOnCysQtwo0Gn UZPz6RVcrmoqK5M8U2IaXKOJ9O0go1EPgPNNwPc5hq5f+Bgg3g5WVWVUsbGBW79S+nFB gw9DjsrQWiSszsMYxwPJeHg+rEOHZAOKuqgxjLYacy/R8FhEJWr4mUf3ToiNSwrArBdZ UTL2J3P31BPmwGvu4OfuJMtth4fJ5eTNN81OdX1OGyB3w59Ponbfh0ct7j0310Nocu9S PdZw== X-Forwarded-Encrypted: i=1; AFNElJ8aVPm1hLUpSKca5hdfvw+02k6eYEnJfqusyMFxoLS1c/vwfh+yluTyuCLzA2KHTHBewX2Jo2M8tyIetm0=@vger.kernel.org X-Gm-Message-State: AOJu0YxYf0tovbWNdI37+ILM9l/9Ajv7q4C4YTOjRAYYza/6tBsCEGUC WarBt+j6rhi1OSSNTyBSM6z6EW39OO+7wQEbBFSmZkw9JIXkGw8jYNKRpTYWfjVtCPj4pZnHk0f Qlc4T2f+/uQ== X-Received: from dleb5-n1.prod.google.com ([2002:a05:701b:4245:10b0:136:23d8:d537]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b81:b0:137:ed87:817e with SMTP id a92af1059eb24-137ed878419mr2517652c88.28.1780413955440; Tue, 02 Jun 2026 08:25:55 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:06 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-10-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 6972C3F4DF1 for ; Tue, 2 Jun 2026 15:25:59 +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=1780413961; cv=none; b=eIPDcPcQYZBYgzjYkVceM5W284lmnNyhzc6ZehwxyOtqjJhX0HRe3W3jm1CnYt4osAn69RqaCfzLQv5DIFbfl4dzAittfiKNuUTNQlQhssW8AWIAuQdfMi7taNJKdNFORmZM7kIrGsa8TtwiJWRUFxHR6mJ+KUf13DemzjEw/TI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413961; c=relaxed/simple; bh=1TN4Off0WzSGb6E8PmC/hd8tjykbHBLDgI/eo85jqRM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Mzmu8fAam1UM1Q0lUT52Tr2XG1yeaz+9V8clJqv+dYAxRHOM+/aycn6I9C8J/LoB8BSuEIS0XdEinQc1DnTZcKu9qKmgfTAyq7Z4sJ6p6Nf5vtX6gTFPh2ZVzaZ0rWMzA7ho5OMceSid2fp/qwfYhkxFRKTVeuwTnrK0UiTLGfs= 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=QMP+zJGt; 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="QMP+zJGt" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304ea1eea05so13103624eec.0 for ; Tue, 02 Jun 2026 08:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413959; x=1781018759; 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=QMP+zJGtnvFT73U1jqLeFMADiKW2z8QOJ/wfVraG3sJzwmVtxRM+HYka9bjkHs4taX 9maICGexzYAUB3159+uzcFq9ytVTu7C1AJKjLOopitZ9pSXNDpLzogB7TSyYVz/bPL/V iky8GfvZAgMLH7wuO09Qp4LXQT83UgKWGUw8RwhFwaRDoTIdoLB9b1VVZxIs6jc5V308 0LiA3kXf+Jl2rS39HgsMtSKp38AIi/fawnsKlN8ATSrYiswJwJy1AoInbW8QltS8hZTM j54M9+Xyxil7ytsahzzBkCzMpXB3CdoEgM/WlU6/eHDL11hKkjGvfSUxmJTIVNMDz9tu 0tQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413959; x=1781018759; 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=oWr7DFpfvcxR4X7TLC2V2kfD808RGk2WwWmk93kQByOwOgUyXINrCm/PPXiA0eHLHa ufyGAA4i/KOgdxm/1uTxME6zTW09CttPw/TYOVXAFEXi2dGWvoFGZrEzQe0qGCSRsHAt teVeC0HUhbp3d1RUArqFrRjcyX0rVN3r3TN3RrxQm4fpKgyj+aDczOacQRro6NMGC3SG BrfC1YQh903An23Mc9pszQhtqSM1UPGWWbcyuJxyylglWfL4k10SDtDApgJrI+dwLaAq 25r0EO6sqdPXVGV1HXkpTNZIvUv69KxmcGV01SUu8ay6GcXXnj8GnpDzCifOXs/okT4q 81Rg== X-Forwarded-Encrypted: i=1; AFNElJ/5lHsqV7M0yO8XujeEmLLU9hBQGftgvZejwlWpC02wwj5E7o0i6zcq5H8kHyqbUVCwsZUiLXIceom9INw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6x7AAWslU7MUv0H/7Vx3U9fAdCd8sZDBlC1d59G1HTPYICQUy JOJ21XLhN6UI/sJ47Vd6bR+B6zUw2dbR5ZwuYggq83pdnt9QA/oetiQuDTqJ+ydB63PVGRUajKL V+FWG5nRYhw== X-Received: from dybsy7.prod.google.com ([2002:a05:7301:7007:b0:303:98b0:efec]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:7243:b0:304:eaa8:11ea with SMTP id 5a478bee46e88-304fa781775mr9133294eec.34.1780413958358; Tue, 02 Jun 2026 08:25:58 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:07 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-11-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FCDD3F54B0 for ; Tue, 2 Jun 2026 15:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413963; cv=none; b=Z7jjpvuZp9yuCHsYzWn/c0VGBVBF5FCATLFKZdKnbTl1m7Jo6NVqJeixJWoq+mRAeTvsqvY0fMVPETZv4UMTcmAk7BdgtOTqflv5ssjpIa2UBbsmug4pUJ3vj8RW6WMxZGjwnCMy1fHpqN8c2D+5Fpg6TRE8+i1KKE+NBYrOZnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413963; c=relaxed/simple; bh=1vKpGyCR08D55Ms8rIa5echQivY8IcjS5P3lKw+8Tnw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rs68uc0PZ18olAdgy464PInE7n/ZsJpaINloZFBLxELTpBILnzWJW+6JlWn0s10elTaB/NFzD9BD1zmSEAji5N1P6E62twJyjspRtK/ISxBHdj6wJeF/BNOSMeDC9IIMEp40PPayC/uz3tzL8tV6XTE1qd4iuT27ozq8N1ao05g= 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=Ix7WyXc+; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ix7WyXc+" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-3074797dfa9so557309eec.1 for ; Tue, 02 Jun 2026 08:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413961; x=1781018761; 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=Ix7WyXc+RO/SIsZQ/51osuaNBAKel9vxBPUyA2hkK33zp+zoEdNttQty7nkXCNO8DX ibIbHK7OYyCUMcZOUUN4nqFRUEmwKDx+7Ar06B0Y43N+XR3XMINZ5rjv+ht4Jb9ewuPl JkusNiIXzi0I8qpFLXVjfK/j54asBAnPpjEBTZusmTE8iRFFZEJ94lTkPA5Bof34SHiB ArymQJmZl51inpQYmeyPA+fzk522JsTjrTOgSHdN8l8xr1NX6nVxwp/AbKtdwNGR96D+ 7gyNdo62cpxMPyXqvXK/AAkB45SCICck4lzbMP08ZBUBq5L5veJntLEFqt4pfL6JFge2 46RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413961; x=1781018761; 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=BuyXn9YLqE65UYEgc60SAQ4QAEnwsRUKS5y3QHwRn8EkB7i8XwaZfaTachhLLrVZvd N2FRvDt/rG2sF2FDkirMGVHNc0hAnsqtqrjLdjkDaLCvVSV81jQz6jjC/XSICttDFLyO Zjt3iRpqZpeV7E1q/+J+WWd1GvixaCyfqKE9U2/SK5kgTd2eIV60JwTN+RkXZJQoMR9H FnkEGLZ4RzzVqqh44ai9DBEjuVzosBt3YD6xMtXGzOes5A7huwTtv7BIszfGQBl5Cnsh wYa5qQmWZOaS7WcvmU/QA7G06qSnsIRpDdRJAkv4WYW0bu9TXIgBXyxNSL3QIzgaXUt6 6rgw== X-Forwarded-Encrypted: i=1; AFNElJ/I4KBvVFtZVSmtiDP/gnrjNVRtL77Fkcr3aojr2euHCwQvMZGfPLIWaCfev/AzrSkhMVRcYkbH5ISsHh4=@vger.kernel.org X-Gm-Message-State: AOJu0YwmOh9hGmIKh2KHr96+CsJWbb5zJbpvM1LZyivjcXctM+hHgkZW 04V4rl1Z/60ezPIWbh/gTK4dNbfUPU8e067Fk3Y6R0JvOS4Hzgj36w2AQTHSP2QnMGCpD5QdKn9 MjUDfDKtOMA== X-Received: from dyhd9.prod.google.com ([2002:a05:7300:8289:b0:303:521c:29a5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6d22:b0:304:e997:e211 with SMTP id 5a478bee46e88-304fa5e6456mr7994998eec.21.1780413961232; Tue, 02 Jun 2026 08:26:01 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:08 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-12-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 296E63F5BD3 for ; Tue, 2 Jun 2026 15:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413966; cv=none; b=FSgOMRSiyxOXjyGejpha4IpCcEoOzsnv9pxj/rkZdFbft3Oo1JiRNYEKR3xAxdbxBm2lQ5ge8U4AZA5c33zqcP5EdBbZYPcn7OyBLG1ORbHhirz+TLtPbo1mM959kFuEtuHg7n4RAKk5Xib9qv0rEqwropqviNDErXn2sXmNpcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413966; c=relaxed/simple; bh=bD79XLC74sOKkh5WkeXQ/YhX86xrlFEHMGX/zIPcIz8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YHDT5hzwYP+R4Axyiy3xfnLPhFKaGvvdszwLRKhlc6deQdPFOUjq9gab9utCaP+WP3cU4/t/tcwDS+23eIsdukNQmggY4vaAndODDHxEH6xINgl279OiADjnOLX8BmUJT3GICbzmHkimVO+gAoGuyX8KyqnlxCXrmYEco6/cwKg= 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=Km5DRfsv; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Km5DRfsv" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304f1820babso5367861eec.1 for ; Tue, 02 Jun 2026 08:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413964; x=1781018764; 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=Km5DRfsv+f5xxRu2ihHNHYWx/KUOA7T7M55QEisEBRe4HjTvX5NL8Ed/hetGsP3Z5g y2nLh38kQw6nUfqggRizl5CDUP9OuEh/eLJlPzD8RTA/anYniKcXUTUiC21qCGjG2E0o W+KYIxYf4a5riLW9MWP4+8WSbiUAtfLhypldW/D8BZaF18gsbwNZdgOGtutpuwYRMjHs J7y5lLpDosLQyE+4fVrqGGNKt5jC3EUQ3WvMXC9AbAc+mbxvcwKF4PkyXrbUic1dXSVp rgMEs1Pf619D5KOT9KJs0+L/Uh7ufSNeYr00UTwkUAIH/NUYxEfSG1UrIBeXkgQdou7j FnMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413964; x=1781018764; 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=dWxFNybkUyPvB3Sphv8qP80golNjW5MRn8fhhEbAJFbwiDVcNsqPtAbWMBOeiv5gGE Hz42+1w3qBd9lHyK4ngGzhW+0nc+q1UWu5Ac2pYd0oS9KpPIBiMO88paBuAxEI2gmfQb u5FoB37O9qp8UnIVim9fmZhi+E/U3S9hgP8tem/fKGBU5FVPc6FtyMveHXPovIHmLRvw nqmQ4IOUUzN1CaEFQD3rd1woCra5OETbKPFGAArCI9vulxZwgCKhzeVVbqlCbb0N+00i M/OmNgur3ZeE7bvrIhpI5bjxHqMxJylAja+VS6IwazvOoWD7czd7HsKSP/7Lu/RQ0Ft8 IzAA== X-Forwarded-Encrypted: i=1; AFNElJ82dg5i8RRvUIctJKXU2RWVBhPyJ/tGq4CQJaGgTzJuRIT/+AaawpthIz8YAze989AmXlPA9VVNuh0hWKo=@vger.kernel.org X-Gm-Message-State: AOJu0YyJgF2D03GJ2/L4oCGJux9gTJX0b+x4VrgdMmtRpt4lhiwYN6Od xI3DCCLXkTJLqLnjLrrHsaCctolT7pob2Rzz+m6KIAu8QutQ+IaSgmrGzZuaQy+esY0COYCcqzs dGZTFLLhoMg== 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:3b05:b0:304:df0e:9dba with SMTP id 5a478bee46e88-304fa6a755cmr7709352eec.31.1780413963910; Tue, 02 Jun 2026 08:26:03 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:09 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-13-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2CA03EEAE9 for ; Tue, 2 Jun 2026 15:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413971; cv=none; b=PbpaGWqK9c3MYutI9PM/27tVBWQvdutxfxcnbaKzrVHDi8SBAdUusJglZ0GgzO7B1lpNKC6XGR4pl95jicK3z3jZ7ALqr4W16YUP1dIvu/1RyYvMJjspmYSAnhZKLwrm59WYPqhHv/l+fLGXcHp10TOKhHkhaQKhKURq4SfnqJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413971; 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=rKd/fv/Rvn7YVAWK0LIh3Pt8L3lc+HVepeU7NoFtzoyNYg9NCbWe1chQIS4C0w7Jqk57mRcAeMwldyawZpiSYdpp+kDBp5QGXgAlsQIDipCUaJVt41aiDCOuYvV3dq9LohZCpkuz7iJyt5xP1KGW9QILUBsE6a49ePHZZOlMgY0= 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=jV3tLdh5; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jV3tLdh5" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304ea1eea05so13104104eec.0 for ; Tue, 02 Jun 2026 08:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413969; x=1781018769; 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=jV3tLdh53S6/psuxN5XoCrpRBTYhZqnep4LMGgeYNfGngb6NegJigv63DJ6QsnRLEg 3+yAghUJpRV/+usJwDpBYuKcuMMv5XA7rCClPfwzlVl8JRbGQ/cmIS3rR8Gqw7H5WmVx J29lE7zZPSShztwVwR6JSB9XqXU1LaZtGoR3+usSYp2b3ol2urrn1WMgpPJf4kviS+SW R0aFkq2unmeBQuGEDO9C6EQBA4CyT2tYhVTA8zgAVvPS+L40C0xxdzGGsmIFSACe3kwM LhYU6/lhYw+7F5rwnvjJROjRwCHVGT6ZjwumFnwRDRKPtM+0UnAZPlI+ZgZZPNJLon2G NsFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413969; x=1781018769; 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=bNbf8dBY4JpWKwaX4R44Mkl2lqxRUZNlxvdUmZLDWv0oLMRJslk+pDbwlXbC0tKxRC vxRo153xFSg50KF1MmtUeDNwc36xrN1AW9pfzJAmkGNHrPwLdqa04udPPKZ1DaShxMLP lxoHgFNWCP9bcn82SQLZ5aFiC5/ii60nTN25aQN9BVg+Si4QdHnYRXKfEWlCHIqg02Ro b3E7Pt9SymEWlHv19TqQhIg7kLhi7TQxnQiER6L1kvvd6JXDdTP1WK93iFst47zSbaGR 7MyPK9OKQZHnCJDPBHHUa5Qi0z8zDvID6txvV1sKfXEKFZ+psaKtAjF8SLsERGzf+1Ye A85Q== X-Forwarded-Encrypted: i=1; AFNElJ8cYM+GXNKZEBUjtCO6CoR/8Gk99U7FpDr51QAJpOdrIXTNCtPbZq4s5c9ZLt+Z+AHz/fZnti8cwGR0Sxk=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm7exnpKq8NL/slGISQpagZD9gCMEPAGKcbf8McDRoPhWhAJ63 f3sH4geGRJYIH9TAwTiJdPCAY6euYpt2gy8NSwioS9mqBa5/B3QxaOIzxyXnxjgGl2SNGav8AB0 fw41kJi/QxQ== X-Received: from dyce13.prod.google.com ([2002:a05:7300:724d:b0:2d7:e13b:ef99]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:cc0e:b0:304:5a9c:6452 with SMTP id 5a478bee46e88-304fa6800aemr7694858eec.17.1780413968876; Tue, 02 Jun 2026 08:26:08 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:10 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-14-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C11363F7869 for ; Tue, 2 Jun 2026 15:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413974; cv=none; b=c7SjpsAA57vWJlVzY/IGqK+4dw19V6bHhIQwUrBmdIgXlNC8XaA052SDAyU03qAHQcvZxNRFKIWL0aiN+ZI/2zWYPfi5hqJL1jr3ByPDmNQ41/d8uT1pYyN+RU4ouZ6oO2QIbH4w8H+WUh8ClElv/gaZJ7I6Ahd85aR7HaI73eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413974; c=relaxed/simple; bh=ogbImCbJZIA7lXP83GwEH6CI3+06smm7TRrjXInKNow=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ScqNndO+ZLWwoBFmvvU4TmXBg/W3TD65tepir+sVI1ZYHJoqfeuJppqng3k6qDqMImdwDzGK/g4cbDXmfcYxMXuyeUBfNFMXJTNN/49of6W72LcVfXg5EmmVwyZW2MdWkrcDLIU0ShRwWYd+nEfid2VBfA88RQO/jmjVcfitgrw= 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=e6DkGDfq; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="e6DkGDfq" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-3041ab826ddso19224527eec.0 for ; Tue, 02 Jun 2026 08:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413972; x=1781018772; 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=MbG72918MZZkcYCC+Pq7rtZ2nlhsMI+rthFBTDKNlsE=; b=e6DkGDfqqrTGOsO1XJcjWf8roRK9djwGxDUWeg1ePc6Tq0XEXyeEsEGi2/mE+f5IUf WQwM4L8QsXBEslXIrzvTe1V7Pr0vtidIGQLwKOITauKg0zDFKH4DxY+xi4+FPYmMeFnD 2sDPiWKATLr/DGNtIbBdP64q4IupzyXCRXa52r1xk16jji25oFpd+JOfeuzC5X1pKdFH DXzZXzYxh8W4QPph8t7BiNm0vE+eap2d1wCmuGiSRN/ujGLDJBf6HCF6uY9QsedZ/KIS H22MxIbanxOqQdxAzuvnoEKYk7wxtfv6ysw3i/b1wwoHfBgBTAhPzd8sxYuKn7ycvfD2 GhTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413972; x=1781018772; 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=MbG72918MZZkcYCC+Pq7rtZ2nlhsMI+rthFBTDKNlsE=; b=l8aOLarAromIuGTelMa3h1yc77ImqQ9Ejn4G68YKHzZz0BUkCWmZ/wfUvTwYCmJwyG sXgdOw9e3wLvSEQNp/HOyGow1g8LGCNVmk+jlM1KuZzCAL7SfvFEdQWDAQfrH+K8tGnA 4fat7JkmThBI4Ilsg9jZu4i1YvNKbhBoOjHZz6VxEIlXnbJBLIVhSxXqYTa6bCu+WbyE C4BQmsm+YgSEeQIYZbCIhbGH4lWTyxL6nWxs9wqqG3IdGYOh8HiqmSJrcJKK38W9fCfj FS3I40lNKnUHuJk0oJlAq95oGw03VCpzjcoeas/jP2/Jf0Om/TCZeTREVCNU4IqV1ZfK A5/Q== X-Forwarded-Encrypted: i=1; AFNElJ9WT/Mx3sB88acNDNoh2bzWg9n2NJfb5INM6Si+pnONoNzo/n859+S3TNNaBiNRONZgDadYCDjsFX0tID4=@vger.kernel.org X-Gm-Message-State: AOJu0YykkUkb0FuNL+xxSjrhpTdAlUD9gC0qS3DhII1/txEqvrenbyS9 8dvZ7tfL3GYOxDXBWvSPDNedXvvDR7MvrbIHzUKzbpjT76QNRyaRXRs91LSe1jFHmy/u01EWyum 4kJxJUWKXsg== X-Received: from dybry9.prod.google.com ([2002:a05:7301:4d09:b0:304:d831:cdfc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:6c84:b0:2ea:ed70:3ea8 with SMTP id 5a478bee46e88-304fa6939demr7896561eec.29.1780413971734; Tue, 02 Jun 2026 08:26:11 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:11 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-15-irogers@google.com> Subject: [PATCH v12 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" The previous approach maps an architecture string to a function pointer to a function that takes an int errno value 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. Since the errno-to-name mapping is now generated statically and no longer depends on libtraceevent, we can remove the HAVE_LIBTRACEEVENT guards entirely, making perf_env__arch_strerrno unconditionally available. 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. To ensure compatibility with older hosts that have older glibc versions, output fallback definitions for newer ELF machine constants (EM_AARCH64, EM_CSKY, EM_LOONGARCH) if they are not defined in the system . Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-trace.c | 7 +-- tools/perf/trace/beauty/Build | 1 + tools/perf/trace/beauty/arch_errno_names.sh | 53 +++++++++++++++++++-- tools/perf/util/env.c | 13 ++--- tools/perf/util/env.h | 6 +-- 5 files changed, 58 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..8751bfa4a2b2 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,20 @@ cat < +#include +#include + +#ifndef EM_AARCH64 +#define EM_AARCH64 183 +#endif + +#ifndef EM_CSKY +#define EM_CSKY 252 +#endif + +#ifndef EM_LOONGARCH +#define EM_LOONGARCH 258 +#endif =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:24:56 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 8972A3F7A9F for ; Tue, 2 Jun 2026 15:26:15 +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=1780413976; cv=none; b=TZflDW9AvmvBc3hjf7ZmA+U8vXhLuzAW7XxHO90QRG6O5/CerxqZDQ5ejoTafviwLQFpv4voo15C5N3ojQcz/gQgplzlozH6SpTIBp9O4FeU+1s1vLV/k0H3PMMdStdxzgbSwsB4xarILODjcCZcSGlexJnppz6mksBgaOlLbuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413976; c=relaxed/simple; bh=wBx2XjIbGKm4f6lxUHRV7mNoOSTxIfLQoUK89yQfzt4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xy93Y6e0+tz170XihPvwb4fUQWHtdjae3l7RXLrL/Z1nkBdiN5UM8XUGFN5/Gv/P0bIUXe+Hvlpm0eBtKBnovh8jZBFTcRZx/+GlyEdL39TuEUGy0ZNn1Uyp8vQra1wC66Qf3nD2C8B1hEMfER+xA0sz5PStJJmd0Fqs3+1RUm0= 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=WLgBe3Eg; 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="WLgBe3Eg" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-3074797dfa9so557564eec.1 for ; Tue, 02 Jun 2026 08:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413975; x=1781018775; 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=WLgBe3EgWJEmIlat/WvXPEEfmDVj/AEn8Xe9Xl+LMCnJ1SR6v5ggvgUGuip9wjvdlZ 5no5yejQdCwxve+KI8s4HDO71FoxN7IjtpRVqrRcs8yyXrEhd/MGXhkqczShXae1Vs6i GnRbHddNJyGWLSA6ZSr2SFCFiTZJYvFSvShV8pvr+1cSWKNSFhNkBFUJ43K8ES690+8z YX6M3/IT4vhdj4ruExMdPLWFVSCRWDmfy5B9Di11Bj4P1V0K0H58c+F/TCFzGBBcEqqA TpxrYQ7ZXZ60FugwmQHxLTRRNUpXbqMcqp1UxbtWZFlbOabcorx0bhyo8l7z5uRNKUiK JsXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413975; x=1781018775; 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=ZWXmuZfIZWIbtaxSIFAKMDsaU1zv4T9juh2fdRfa8vIn52DS3+Z97T4FfFY9UEvipO PZxZXqq7eWSzSZ8d4R7B4CfVXiEmvPyFbVOeaklxV7j/t6nTurA0M35sqeOX8AsP8usi j5zQyVXAiMLInD97eBpA2Dia2TaF/xAXtGIqrD/AXg/8kIUMymk/SNm7GJvSv/gbFMmQ 05y8eJ+jis9X0vefqJuOyzGdPHDb3ZI896V7mPCdCbm0T7zJQnd1L3CMXM/nZ3r0phqv O9pz/8+VHPRueh8ZMKZigCwc5g7jKMZ76fGMFQQt6F3aWpTtuKpdxC1TYeDDmLqsuLct DdgA== X-Forwarded-Encrypted: i=1; AFNElJ/4Snqk5CTi9JTWlr1EGKA+I+cqUvqW19hTBJwMvUHf62gplwzEQg293cR/jNXJgZlnq4rmrx8GID1D1Js=@vger.kernel.org X-Gm-Message-State: AOJu0YyVj6ubtJLBss6DGrLLSQuPt+2B29uAT4gXxQQ/i7FGpSl8ajrc 31ls8JvyIwSWntj4r7jXXlI/5kv6sOz0V1jEqlXLvpNRPHcmXDm1qV3602ZTBTDh61LdWy5AShE gluvJ179LkA== X-Received: from dybmd42.prod.google.com ([2002:a05:7301:182a:b0:300:7c0d:9eac]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:4918:b0:304:630d:e4ec with SMTP id 5a478bee46e88-304fa666a76mr7942028eec.28.1780413974271; Tue, 02 Jun 2026 08:26:14 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:12 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-16-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 119E43F8715 for ; Tue, 2 Jun 2026 15:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413980; cv=none; b=ijcY32VJ7dPF9jzC3R5cqqaaqV+hNsV4EZnKr9xRqIg2GhkNJONYhBfvR+UvFaLmpMEhy/sy7D1duEGnCQugvSmRavlN6mU2FKafxji2ntkuAqt7g3c02R5KC81z40haGjVoMoCpRFISCYuIVkRpQ6CHnIT932dpWof0AGTPnUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413980; c=relaxed/simple; bh=WPG8dPv9TK2SdNtl17T4gx5NaWiw3DgHmq0K8beS3Jk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XLMBuu7h8Tcwi1kFLWskI8r/txjRtPYam6dkha7HNK6G2OzolHJ9FyIx4yOo0/sOz4dQXR4kmR/xpt3Wu1xSRL4OvG3wfkQq8hMe8Wl0ZXKja5oKa1P3YRd/2Gd8aeg4RIIOlEsrGb4OGMdRZEGdvExLQj0puqMdAnaAYVHkctc= 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=vIb5BiMK; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vIb5BiMK" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304b8d0ee63so9674842eec.0 for ; Tue, 02 Jun 2026 08:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413977; x=1781018777; 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=a++q+Cspvy+lo3emUzDENGkW1idP9N7NULAFivLQywA=; b=vIb5BiMK4bcVFBatmIj5bh0MraYz0F+Md9NOPhrr9TYuQQbAEWGhvZseRXBYlg5Bm5 wxF0vj7kUDV56HegRYe9rCxUthWT2SJ+YPp+WQ5122dCeUnQtZfzNr/0lbCKxFBN7pB0 SK7krd99O5RobleoXp9PPxeMg3bwyqJWQbNpa6+btBwTQkcRVlIPo7GAhHJKHXZNuqjQ VIPPQ2rcyj8HKaz9dHToAa3OEYdh46PSPy/8q3xSs+1Lk+gGISAVbVOako4ZKD1gwSOv WJHMmkDj5eeO1YA8UzrL0Zja+BaVzLASVl7VFNEcRf3LOCc4K8Ssykgu6uw89IccXPtR FwCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413977; x=1781018777; 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=a++q+Cspvy+lo3emUzDENGkW1idP9N7NULAFivLQywA=; b=a+jVRWp9sWStqnZJsBRUraqO2/Vz/MvobeB7P7z9hp1soGAc7deOJPbd+NfgyNHTp7 BOQHxz3zXUpUN3BDN1KqpEoAWuE7ncP11H0o2lL2HgErgcYZlRMSimlCHX9l7JW1H2oq SEzKbQ+m1yIhMRp05L2xkRn6Iu2zfrU9IsLTm25XIceV0IUPi1zCLJa5xTIZw5nnVv/C 5H44M2msZxV+tnNeJooHwypHhre1r+hP1rNet4jffY9Er8i5prM/cNjajnDDpDkZ+ZWY 7JicTYFfA5h0DaVA+t8zkEOTIB6/gnkbT42libv6d04/Aj+d0pnoGMBkX74YfpPYghZm +zrA== X-Forwarded-Encrypted: i=1; AFNElJ86XwKMPJblAwmIUkEDTxcjjDFL6/blLmpbfnMCEONUaZb96+sY2zd1CzWGFiDaPaHU7gt973Qdajzq9Kg=@vger.kernel.org X-Gm-Message-State: AOJu0YyvLMm28636FNbbswC44rkEAHS2+kfWlQzEFnYkBOyW8/nRxBkw A9baRSYrU69o3ZP4q3Z/4LbfiExzXijtjmsjC+YEm+ziDNWJDl1GeDkgz9T43HivDEWtK2jKleW EfM2WFUIaXQ== X-Received: from dybpi11.prod.google.com ([2002:a05:7301:420b:b0:304:de31:a7b2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4312:b0:2ce:25be:c8e8 with SMTP id 5a478bee46e88-304fa5a8b1amr8918813eec.17.1780413976931; Tue, 02 Jun 2026 08:26:16 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:13 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-17-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- tools/perf/util/env.c | 5 +++++ tools/perf/util/env.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 28c54c58193e..03d90a45992c 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) @@ -1014,6 +1017,7 @@ bool x86__is_amd_cpu(void) struct perf_env env =3D { .total_mem =3D 0, }; bool is_amd; =20 + perf_env__init(&env); perf_env__cpuid(&env); is_amd =3D perf_env__is_x86_amd_cpu(&env); perf_env__exit(&env); @@ -1036,6 +1040,7 @@ bool x86__is_intel_cpu(void) struct perf_env env =3D { .total_mem =3D 0, }; bool is_intel; =20 + perf_env__init(&env); perf_env__cpuid(&env); is_intel =3D perf_env__is_x86_intel_cpu(&env); perf_env__exit(&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:24:56 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E46373F9281 for ; Tue, 2 Jun 2026 15:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413983; cv=none; b=nmMNu5WWaaNP5EeVgwJ4n1r0sbDjO4SDVUiPeB28vPyKkjTX1ZXWvzApzT7WoAiQYo2RVEaoA+e0BtNcBFXTnPM9H0pdkwQUdkv2YZ4dPcDVKMG/zNa2uBFD1sorUJ6IuPSjYM0Matpp+rOsA5/e0jH5KHHiiiatK8ENjlQRJL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413983; c=relaxed/simple; bh=IELIlmNvVvIt3AL/nzEPMhdDrA1nwKMzWpu8GcZtdps=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LoaudXidu5sBoQ0FHxUSO9p2dTzr8IBHLpTttn/Z78SwlhvhJBB/KfB3YUVcC2JK2+JnpERBZCiksLZmkOxwLNh8Sgdsa+sxzZ+fkCmJMNzzidGxCkVgY1rbRW4d597BCcNSWLxljFQ00iWUk/p0fclwaCwa9dkBBmZWpJ3tkg0= 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=O7m7accz; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O7m7accz" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304c652be4eso4069663eec.1 for ; Tue, 02 Jun 2026 08:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413980; x=1781018780; 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=7iB2IkCiPQWyvpQ1QBll6VQTrbjQBhFOeCn5EJNQ4TY=; b=O7m7accz3lt3KsweqIdhFuCS44IMezmr7HoRfRaFFphm/543HB7ohFLep1wdDRNeNQ T/v8alqL+GDc1fzGes/W1TfGyPzB/FY9R3uGtSoyXiDDZh+JNNX5CBf/Juf0Gjb2jgZd 4500hvL2KXfxkTbZvaX64iJQFA9TecURPQuT2my+Ow7BqC5+joKZLOJIvFxduVDf7s7h 5pAA/GA7RMzdGSiUu5ECa1xl4y3/kjYtIIV9sXTpi0wNAtAcPhkBT1GvXGGNfz8LUE9I q5EzNQHwmSAg3LS8tb+An2ENCqfb3ml2dGwOIYyecuvfnARAOFXHQvBPlDyp+9RunqPH YWqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413980; x=1781018780; 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=7iB2IkCiPQWyvpQ1QBll6VQTrbjQBhFOeCn5EJNQ4TY=; b=VlP+z+XbQVIzCnPuqI7O9zsjHYPY07kkcvCtk3jX8XX2Z0Eu3fSDLd8CQ1qsg0cA4P SRu+zvgxqvZ1mGp2lmOIyoaNl0uMeu6mmp7ypS1vLhBab5uhny8pcUYkfIhkwv72Qt41 msdxWI7vMSCoj1rfAV0zVbXIkOIyXRR7t8AjP6AQyxyQEaVhwuQHSz4vjElQhp3J0y7e QOLJgzJYj8V4bGv40VRkZGVgFvj32ZNWkOyEWhRedbJWMHh+GoKjCpogfga0s9VIHFaB XRlSiwJ8h4NmdQJ4O07JDVGAn+srhh4leuUTnVK0rHB0CxPTivsQPspycRtz+6LT7L+u cVFg== X-Forwarded-Encrypted: i=1; AFNElJ9AXJr0PHgNCB5xgaw/Mcl2K5AqSe8iCuzZg/++F5ltz1U9jQpUJbQ+lsXGnVB6mSqdsi/ZDPJJTqv2j6k=@vger.kernel.org X-Gm-Message-State: AOJu0YyjXS6CHXqemSxaAkgnnzia5mj7JTDTj+zS6xJ2ClbEIPEkP5yp GQk67QpcQcDZxZyhAzFRIbrg0Sq2Ak8ftSYL2YRT1elsqAU6+ZWWm5yNOE4so/DRMTQA6oT+V5Q qBK2hYp5fFA== X-Received: from dlak10.prod.google.com ([2002:a05:701b:290a:b0:137:ef14:6ec7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f207:b0:12c:1288:ce63 with SMTP id a92af1059eb24-137ee2f9aadmr1486105c88.13.1780413979700; Tue, 02 Jun 2026 08:26:19 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:14 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-18-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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 03d90a45992c..c0e2b9d5f0b2 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:24:56 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 AFA263D1CB0 for ; Tue, 2 Jun 2026 15:26: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=1780413989; cv=none; b=lx7ZAHzM+xr+B7muUnQ6oZ1hwrwprwGVJhl2x3PhgF6LC7zFQg4mFyRT0xeyRSk4XrMu/ikBMReMLdmDRsLPK4B4m8nl/r2wFYKkp37BbZCquQVa5OZrcec4Vdq2K7U1gZdCApXFU2czx4iYMu7chXAUerP3NJShX5eXLHaufwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413989; 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=tdVwIQu4ieijoV1ylk5kcZn89jfTf7Ckcj/YzG94dVH25UVEbPxdMZRByX8w2TNeiIzJDNLdNPrkP/ArpbmTU1VWEcN1WxlUFAZckc3kIquTgqGia+IB1kKFYv5gL8mZ4BkNW/dUWc4/Xy7fOrF62iJ58SdCd2NmF6yg5yTJ4jA= 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=ZwU/LgMl; 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="ZwU/LgMl" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137dd5100c7so4296908c88.1 for ; Tue, 02 Jun 2026 08:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413985; x=1781018785; 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=ZwU/LgMlhIYF1EvTDPgMyEnYhZ2pg73LrFq55EOTToCfq2l56JCPuygH+kPuuo9/tg 9iJ1GP+25O+RIUhxOTrHGQb3A44kBh7ArowpdqsKohpK8goQuPpUBC4b/CqyiJcqfaL7 fI6LBIF8ir0pZrwv7JC48psy+AYBQhqF1Vg/Te517qVaG7qTbI5404i/zS59b8fUikdX 5gzsBZ9qofOvxV9s3/ZxcimvbzcMwK/vgA8/n3Ymu8IG4Z5gpB33THkkK9BK71GA9NZt L3y+szuwTQCWVUFVzqh4YEqEVYReNFwz8ub6Nj7ujF0CM4C/bisMNEv6kLO/4IgDxkAW hH9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413985; x=1781018785; 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=Wj2spcby3fej4m1ZCGxu57CZHUWOgY9STgxmbJLcdjkiTLnsBczuOxAkHIcqOdZnYr y2vzRpJNhNqVAs+vNzEG782fnn5tqa/S+eRx3kgKS8NKPpBBszc0p/0Bmij53o4b2w+/ 2JNoiZDGFenPn82dj8CoWZVar/FcmUun5XEwWvLvWDO3qKFcCkqY/iDasb13IgpW5NJM 45XpYTn66D7cmsnI50kb4ReR4YH6rTx787kpCkjU6YowPHiM8shi5Sdybmd6L6ggQehz qke1vBcoq9N23Irj8ViOy5a6Od3HFtxHhkGzOuVMMMdJ9x99O7qKePMMzc5VISrHKESK /reA== X-Forwarded-Encrypted: i=1; AFNElJ9GmCz0BEq7j74Dhk9vqeOqQy2AkhqS4LWoKxwPcrn7T1REjElXmvdRpKgPVqa2HdhlV5jaSYnmkZwyIUI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8hJf5eJsB/GVaVMZNHIMliwzLoh9ndADZ+45QVpCtq4fljXiN U384gXFST8fJcR95XF/azhADpQVzZwTY0JNDJ3tDctEH0JHocTav+tJPikRNjifNzDzgvuN3Qae FqxjSAewGvw== X-Received: from dlec13-n1.prod.google.com ([2002:a05:701b:428d:10b0:136:1d52:aebc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:60a4:b0:136:da48:a3e0 with SMTP id a92af1059eb24-137d4131b70mr7683620c88.28.1780413984111; Tue, 02 Jun 2026 08:26:24 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:15 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-19-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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:24:56 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 13C813EF652 for ; Tue, 2 Jun 2026 15:26: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=1780413989; cv=none; b=nhuHIQijMDnQIIIq/N0RwprOCIMYR6rZKuZOwYckSRprofs+cOcB1ajIty2XJtRUthI9ilJL21ACFPOi6VQ2pV7xW85bY/ekj+yNFtRsvGjF75X4eKKDfpOf914I2lOKm0GPH8YmNTIaFFzmHp5T9AyEGzphUNEKetDkSj6vyq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780413989; c=relaxed/simple; bh=gthxRtD5VEATbV+0nsoc/5x3IeZxemKQBzZozOhGM4M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YTNbvPgENqjz99Q4aoadTgR50btiYrqnEYxwioeAcx8xIzfptOnigJjQDwncbusmun72iYQ6ORb63oBin9CjhllCbidMOLyWcjng0C9zLruzvJtEhfyBJvndeK2AreXn6FwHFqm8Jn9kEgkU782xZIG1g23Q3hrLUDBj/IihDn0= 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=JgPNuW+r; 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="JgPNuW+r" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137d4309062so9548860c88.0 for ; Tue, 02 Jun 2026 08:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780413987; x=1781018787; 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=JgPNuW+rfFSxmtZqVVjrtaeOvJQfJzqpJmUqlxtH8LVHbROCRFSawH8im60q3Sklk4 c2gy344ruCy9JQ8feKc3fUp/AfoVS3l8O/oBA8Jt482WDntwDsAH2TTLvVpHPXdRrNA8 nBCVU9CRuN7gN14OZULlVyG5+j+5GV6I0sni2i+rsJSb8EUYgC+VebjxaMkKrQntKKi9 H/P/uZfJRp0HMwZh/5Xx4uKkWOHeLY2ak2brwOLpbKwa1w4HP3sR7FhziZc0BFG6N3Tp a+X3rGrE6awbOT80f/TYBZ+l46qjeLQVFHia0b/03i2CeGlOJiLTIJ+R4O/MwKIabGn3 pFhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780413987; x=1781018787; 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=ou1wwYWvlbqkHDS/9OBbwyfrijlOuQp1l+RT3QPCW+zdEQMZRHHf43TLLjdizBUiso nizpuj+hIQpouZydNGSaiDiWK6OI613UF8IA8QpfhpHLeqkreWSEDAI/4E0RXHeL8WJx B+LlM9n7qVMmOzZ754UeEAeDj6wodzZb45xEs7Z1inqDlXATQnfy/ikuNeNilqQHpsq3 Kg+nq4sKTkYz9pB4nrtJCU6aC25+OqkLSt9dI/9CDWzXsrWsw3pYYurG7mbhJE86YOzX JV8I4Oil4OdeHuFWG2tGnkvTMt7UZKnI4StAXjIJseYSliKGLZZs4aoCMNqNW9sHfajA v8UA== X-Forwarded-Encrypted: i=1; AFNElJ8OUs9wVHq0il/v3yuaPcBflb6gh0ypeoCD6CzsirZKnJVrIivs/33/tVWsQ4AKMDwckyBP1ncQ7mnSWlU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxhus00zxkEEB//CvuMIJj5luFXT84NkxTmIszntOgo6mRoX3z7 +n4el6BtcXUporxBC43Lro9iOzGehpnf/cQYLU+CqF8NxmcV5ri6ey7tXU/KYvy2zF/A8KhHniI Q/leS9wk4xw== X-Received: from dldz13-n1.prod.google.com ([2002:a05:701b:418d:10b0:137:f3ad:9756]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e24:b0:137:8921:4fe1 with SMTP id a92af1059eb24-137d428c098mr8147771c88.37.1780413986839; Tue, 02 Jun 2026 08:26:26 -0700 (PDT) Date: Tue, 2 Jun 2026 08:25:16 -0700 In-Reply-To: <20260602152516.2831152-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: <20260602062452.2583619-1-irogers@google.com> <20260602152516.2831152-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602152516.2831152-20-irogers@google.com> Subject: [PATCH v12 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 Acked-by: Namhyung Kim --- 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