From nobody Sat Jun 13 04:48:46 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 DE2A118FDBE for ; Sun, 3 May 2026 00:22:55 +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=1777767777; cv=none; b=XD5c9AvU6qE4nEpz1FTPSNFGhBdRcsJfwb/dibIJ6Gvbg0Ln0g8JXaRygSsOn3xi+JsJb6HcRXfjwRMrNjZirfJdS9/f/XyLedxRv8zFtNuOUltvSypPm7GdapW2+g6O7STIE3quuUqftS8hunB8huUDf4VxxlDARqHxXG58xCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767777; c=relaxed/simple; bh=E5WuLgSvCu+Huy2Y/j/l91kxZitYlpVjBvqNsRrWqHA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U3zh4LMTUe52DsJY8nLrHm3X1dDTBGE0+NhPTvXKpVIeQ/HuS91PsWI6xjHF1T8/mOox4VZ2DjhidITwLC5W4djk95lYHKznt5O4MkspbYddc2rhh4mQNj/3KqnLfs71BCHcsx35qEa3udB6Gmy3nmZdLxRb7GtvePMd5SZcXnY= 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=N3TVLzwl; 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="N3TVLzwl" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12dfe12d285so760659c88.0 for ; Sat, 02 May 2026 17:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767775; x=1778372575; 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=NE4nGAv7YSfIGpZCRFnu2hIyoVTHwCm9GN3Jcb5rWf4=; b=N3TVLzwlhHo0qgxkVv+tC0V9NRE6/QnnuVwYgHL8QbLDlrKMQeLt/4eUvU4FIjDlz5 vhVO0iRD6mqqepauIUKvMMQRNWGbjx4cdE9TM0Wg1Qh2jqyfd0tewMlqlbLey7KmJ88Q ws6KRbM+8wxha9cThMDCLfQKIIaQJsAtUXR/OsmMCpIsUlsn7cRGTXZXF449L28juFVT k5/uyBXHPf4XSvekLnz7MxbQ1IQpOpHp4ll6NGqwZYWv8e1H48jIdLdxEMK+xbLozmCv 2J6ItblbBOm0FZlmJLm0d3lHPn6qE+ytBAfEOp6BWj9us7RKTNthrC5FsfMfUTmafpOb W7wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767775; x=1778372575; 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=NE4nGAv7YSfIGpZCRFnu2hIyoVTHwCm9GN3Jcb5rWf4=; b=U+QP3Cjcr4FevIcfgvlBFc5/vIZm9CimcywPo/57uxovhA+ftis6jIWY+yUzvNKWMN FmwwHXONzOj4jwRMfNeLgkAaMSiiYPES2ZR6abtj/SNtyWWeUuwhUicWXKcoYRNlv5f4 JEmKe5PLAoBRXOAcm+jSFH9qxyhbF7fXYATzDNK4Qh3Xstf6jjb+Dk+7zWuB687m4dLK aI0sGlnXLefTWyfBVxbQiU7r5IaxbnM4vUqqKcPbRwbcqrzcOQEHbxNQllUalLVTIjZS 9LImh7twOI9LLKip180o7YeshtkcLjt6/FenzKeNpZoirvGzYkDPpqf1vFM2Mk1R0rLP oojA== X-Forwarded-Encrypted: i=1; AFNElJ+rCyggtJpP7maDtb86Klo0Y5FTxOqWMHQdJBsbe4SOP654rSLdrkZHxqQDP2hTlnQ74vIMWirMMfB95gU=@vger.kernel.org X-Gm-Message-State: AOJu0YzvCSzboq6FZy+ZBK8RBBSZAKNDfcdM7zLsXiKWDp+uNHxzeBWw MyDbjncePduOWUYM1WqSjN8qSsaxTsYq5CotK7IY3pV4S7YRKATkriOO6VALR7QZcyD31m9Il2R DY6ePj/MyDg== X-Received: from dlbps8.prod.google.com ([2002:a05:7023:888:b0:12d:b2ba:b551]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:404:b0:12d:de3e:cbfd with SMTP id a92af1059eb24-12dfd8411d0mr1946033c88.36.1777767774726; Sat, 02 May 2026 17:22:54 -0700 (PDT) Date: Sat, 2 May 2026 17:22:31 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-2-irogers@google.com> Subject: [PATCH v9 01/18] perf env: Add perf_env__e_machine helper and use in perf_env__arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 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. Use a binary search for some efficiency in this, but handle somewhat complex duplicate rules. Switch perf_env__arch to be derived the e_machine for consistency. This switches arch from being uname derived to matching that of the perf binary (via EM_HOST). Update session to use the helper, which may mean using EM_HOST when no threads are available. This also updates the perf data file header that gets the e_machine/e_flags from the session. Signed-off-by: Ian Rogers --- tools/perf/util/env.c | 231 +++++++++++++++++++++++++++++++------- tools/perf/util/env.h | 2 + tools/perf/util/header.c | 35 ++++-- tools/perf/util/session.c | 26 +++-- 4 files changed, 231 insertions(+), 63 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 1e54e2c86360..0edc67a468ab 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,12 +311,21 @@ 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); + uint16_t e_machine =3D env->e_machine; =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)) + if (env->arch && (e_machine =3D=3D EM_NONE || e_machine =3D=3D EM_MIPS ||= e_machine =3D=3D EM_RISCV)) { + if (str_ends_with(env->arch, "64") || !strncmp(env->arch, "s390x", 5)) + env->kernel_is_64_bit =3D 1; + else + env->kernel_is_64_bit =3D 0; + return; + } + if (e_machine =3D=3D EM_NONE) + e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); + + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_AARCH64 || + e_machine =3D=3D EM_PPC64 || e_machine =3D=3D EM_SPARCV9 || + e_machine =3D=3D EM_S390) env->kernel_is_64_bit =3D 1; else env->kernel_is_64_bit =3D 0; @@ -588,51 +599,187 @@ void cpu_cache_level__free(struct cpu_cache_level *c= ache) zfree(&cache->size); } =20 +struct arch_to_e_machine { + const char *prefix; + uint16_t e_machine; +}; + /* - * Return architecture name in a normalized form. - * The conversion logic comes from the Makefile. + * A mapping from an arch prefix string to an ELF machine that can be used= in a + * bsearch. Some arch prefixes are shared an need additional processing as + * marked next to the architecture. The prefixes handle both perf's archit= ecture + * naming and those from uname. */ -static const char *normalize_arch(char *arch) -{ - if (!strcmp(arch, "x86_64")) - return "x86"; - if (arch[0] =3D=3D 'i' && arch[2] =3D=3D '8' && arch[3] =3D=3D '6') - return "x86"; - if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5)) - return "sparc"; - if (!strncmp(arch, "aarch64", 7) || !strncmp(arch, "arm64", 5)) - return "arm64"; - if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110")) - return "arm"; - if (!strncmp(arch, "s390", 4)) - return "s390"; - if (!strncmp(arch, "parisc", 6)) - return "parisc"; - if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3)) - return "powerpc"; - if (!strncmp(arch, "mips", 4)) - return "mips"; - if (!strncmp(arch, "sh", 2) && isdigit(arch[2])) - return "sh"; - if (!strncmp(arch, "loongarch", 9)) - return "loongarch"; - - return arch; +static const struct arch_to_e_machine prefix_to_e_machine[] =3D { + {"aarch64", EM_AARCH64}, + {"alpha", EM_ALPHA}, + {"arc", EM_ARC}, + {"arm", EM_ARM}, /* Check also for EM_AARCH64. */ + {"avr", EM_AVR}, /* Check also for EM_AVR32. */ + {"bfin", EM_BLACKFIN}, + {"blackfin", EM_BLACKFIN}, + {"cris", EM_CRIS}, + {"csky", EM_CSKY}, + {"hppa", EM_PARISC}, + {"i386", EM_386}, + {"i486", EM_386}, + {"i586", EM_386}, + {"i686", EM_386}, + {"loongarch", EM_LOONGARCH}, + {"m32r", EM_M32R}, + {"m68k", EM_68K}, + {"microblaze", EM_MICROBLAZE}, + {"mips", EM_MIPS}, + {"msp430", EM_MSP430}, + {"parisc", EM_PARISC}, + {"powerpc", EM_PPC}, /* Check also for EM_PPC64. */ + {"ppc", EM_PPC}, /* Check also for EM_PPC64. */ + {"riscv", EM_RISCV}, + {"s390", EM_S390}, + {"sa110", EM_ARM}, + {"sh", EM_SH}, + {"sparc", EM_SPARC}, /* Check also for EM_SPARCV9. */ + {"sun4u", EM_SPARC}, + {"x86", EM_X86_64}, /* Check also for EM_386. */ + {"xtensa", EM_XTENSA}, +}; + +static int compare_prefix(const void *key, const void *element) +{ + const char *search_key =3D key; + const struct arch_to_e_machine *map_element =3D element; + size_t prefix_len =3D strlen(map_element->prefix); + + return strncmp(search_key, map_element->prefix, prefix_len); +} + +static uint16_t perf_arch_to_e_machine(const char *perf_arch, int is_64_bi= t) +{ + /* Binary search for a matching prefix. */ + const struct arch_to_e_machine *result; + + if (!perf_arch) + return EM_HOST; + + result =3D bsearch(perf_arch, + prefix_to_e_machine, ARRAY_SIZE(prefix_to_e_machine), + sizeof(prefix_to_e_machine[0]), + compare_prefix); + + if (!result) { + pr_debug("Unknown perf arch for ELF machine mapping: %s\n", perf_arch); + return EM_NONE; + } + + /* + * Handle conflicting prefixes. If the is_64_bit is unknown (-1) then + * assume 64-bit. We can't use perf_env__kernel_is_64_bit as that + * depends on the arch string. + */ + switch (result->e_machine) { + case EM_ARM: + return !strcmp(perf_arch, "arm64") ? EM_AARCH64 : EM_ARM; + case EM_AVR: + return !strcmp(perf_arch, "avr32") ? EM_AVR32 : EM_AVR; + case EM_PPC: + return (is_64_bit !=3D 0) || strstarts(perf_arch, "ppc64") ? EM_PPC64 : = EM_PPC; + case EM_SPARC: + return (is_64_bit !=3D 0) || !strcmp(perf_arch, "sparc64") ? EM_SPARCV9 = : EM_SPARC; + case EM_X86_64: + return (is_64_bit !=3D 0) || !strcmp(perf_arch, "x86_64") ? 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_HOST; + + if (env) + e_machine =3D perf_arch_to_e_machine(env->arch, env->kernel_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); + if (env) { + 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 */ - 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; + if (!env) + return e_machine_to_perf_arch(EM_HOST); + + if (env->arch) + return env->arch; =20 - return normalize_arch(arch_name); + /* + * Lazily compute/allocate arch. The e_machine may have been + * read from a data file and so may not be EM_HOST. + */ + e_machine =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); + arch =3D e_machine_to_perf_arch(e_machine); + env->arch =3D strdup(arch); + /* + * Avoid potential crashes on the arch string if memory allocation in + * strdup fails and NULL were to be returned. + */ + return env->arch ?: arch; } =20 #if defined(HAVE_LIBTRACEEVENT) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index c7052ac1f856..7151a9138e3f 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); const char *perf_env__cpuid(struct perf_env *env); diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index f30e48eb3fc3..f1ae61392cce 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -379,21 +379,28 @@ 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) { + /* Force the computation in the perf_env of the e_machine of the threads= . */ + perf_session__e_machine(evlist->session, /*e_flags=3D*/NULL); + arch =3D perf_env__arch(perf_session__env(evlist->session)); + } =20 - return do_write_string(ff, uts.machine); + if (!arch) { + int ret =3D uname(&uts); + + 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; @@ -2684,10 +2691,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 fe0de2a0277f..3e64db2d27c2 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -3023,14 +3023,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); @@ -3048,10 +3053,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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 E121B1DED4C for ; Sun, 3 May 2026 00:22:57 +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=1777767779; cv=none; b=tk1XHW0s6GOruMEuDDD+wLnsnLiGMnZMOxqa7gbvXRGiLB3xGg2JkkWC8cDMLS+bP4EcHKxDQ0UrEsdMj/VSinCHQfq2RKZSyBQmBLum1Y0LX39WE6cUVf9VcT5Jz25fhCLQ+9puOV8n83x4pMlz2FoU74GDslv6TTbhiw53rkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767779; c=relaxed/simple; bh=dePQroO1x6u4W4p4OjprVA1y6YkSFx4TAjmbutXcF6o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FfFNTdfLph2BCYaBVnprgpOvE3nGWXJ0kTKf0nztqsoZnKffJovOpJnc7O7PkIxKBBiuGqJibegSktBqbhATEUNZOKdPk/Ul+rhds5j6SdrnAcQp5uFDuYRsMEQhlzitIbEzFhkW9gmm06gMzhHNYQwsqQqgc2TwrU3CBD6DLrY= 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=S0Y8DjzW; 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="S0Y8DjzW" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2ef62078ee7so1117131eec.0 for ; Sat, 02 May 2026 17:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767777; x=1778372577; 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=M+bU3LlfHduMRXriJM/lVN2ewJoBx+eB8b+i1D8BIsU=; b=S0Y8DjzWxBUJAh0cSjPL+2V2ZYSceL7ND2E7C0tqWv7YSInah4w+tsXB/SLuTX6Ylz /BjRnEU0pR4AbMknisl007RKX8qccuCyGgLHDn5MQ0YEGYdcM5fQ7RB3uGhvdu2ZtwFH M/EyDxbnYtxP6CmHm2vLZXvjppmaa5JC3AlA7v0RRKic/KR1Ie1RqnKoHJkMSroDiT3M p8+dYW/t31arWo65qt1uIE5DYVtnDCRxo9n0eFFgZH7Oaky5evNU/o1R7S5zcNPJEYH0 QM30H6t/hrbFHFh4V23C5UaZVGjtQV9Lql2VkiuZqXnDVZo2+XmpTN54/VDizGPAocI7 QBQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767777; x=1778372577; 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=M+bU3LlfHduMRXriJM/lVN2ewJoBx+eB8b+i1D8BIsU=; b=O/5a/LlSIwmqiz3v9LOOj/2HhdtZgjVUWOi7f28IQrM0fQIwVwNmarFm7wWy5oYHgY u+CEgSqrpjwm5NzwSfM6JaHzGzp8jXN3VmsDUVrtVBIiOQSlI21JRvYXCtU1x/C3PBNZ oQC3ccHiknVUTC6I89XcMauCSrlubjV6HVZv2wE6CujP5NuDUMBByhMqxPfdd4fdzZAF 3JZiWEl0Z3RlpZsvRezNhkZ5s1RUD8XGhmfiO7XlKTsHgIh7ycWGUqDn5UDBNl+Pd6Ka Q/4rWGgY0d5SnpOYQnaSqxsnAcgyQg0+uX2rokNlr0QL/60kf2H8q5ZB/nDe8FYDOz3C augg== X-Forwarded-Encrypted: i=1; AFNElJ+/JPQSKXKL1LiWO9MCgGwlRBwojb5Sf2Lfpo2PTFxD1P7vGLKl0ivniGKjLVpjg3exQXiVAMc25zJQjfE=@vger.kernel.org X-Gm-Message-State: AOJu0YwQgO6Jw/9GqsHO07LDgPhirHu2OYI3o6Afafv25doI7S1Sixc1 K/giDse8mEnPiWLrRT++EboySthgIAaqigxoLvf9Xwmv40CxBmCSyXDhlDC9S2je+wKvHA8gQYz ipX9VP9aY7Q== X-Received: from dycue4.prod.google.com ([2002:a05:7300:84:b0:2e5:fa99:f6e4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:5712:b0:2de:aafb:feff with SMTP id 5a478bee46e88-2efb8b96397mr1802106eec.2.1777767776760; Sat, 02 May 2026 17:22:56 -0700 (PDT) Date: Sat, 2 May 2026 17:22:32 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-3-irogers@google.com> Subject: [PATCH v9 02/18] perf tests topology: Switch env->arch use to env->e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some arch string comparisons weren't normalized. Avoid potential issues with normalized names vs uname values by swtiching to using the e_machine. Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index f54502ebef4b..d4c5c330c679 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 =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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 D0FAD1DED5B for ; Sun, 3 May 2026 00:22:59 +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=1777767781; cv=none; b=oHkOen7C6bsZJEUMz8e9VWb18enNAfRdmSr03AYl8bdsUPZHxvpfX12dBOtI1w7eHIvQQJ0o4t5nDf8UuIoAIvOwQxmfTu4wNU+Z1X+chsysmn+o1nLjSDUGQMSyHrDYXucXBT0HrEWEcdlLvJ8ZC1bjXHoSknykMWpqlt2n3Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767781; c=relaxed/simple; bh=8PL93q6LEy/RmlxfgsqWPGb3e4SH9u+3BZxs6IJPiDY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=H4Rus4/aF1au/P7OuJa6BF3ALJtNdkUxwRdrw5Qb8aJ3YPtfmnbV/ldC3U7EZ+vbtLQJnYuUm1ThE8ipbv8pVnqJuHnR8E99wN2fUdjkGQYirPImWrWuQwNcugWAQADhRfAYRyz8beycSuRoFK0ULf6UxZau8NvXy34j1JKmELk= 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=BCWsFuDd; 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="BCWsFuDd" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12dfe06b670so4797300c88.0 for ; Sat, 02 May 2026 17:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767779; x=1778372579; 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=yEm+9CK0i9MQLsvr/lRfYtx0/DM0+D55tOmGa7sB074=; b=BCWsFuDdKVZ3V7mTxBVAfb/uz+mHwskt56L7B9lAfc3+RUCUrOBADivfzyRX02v9hu H4bERbZvBK1fDIbzonTRnxuwhRcPzZIZ8aLKz4GxoA6BpdKp9qyAkziKvee7Z/jg+lfp kXxYc9rzW1arGGNlNLPIDfqRwbwfkZoT9hik/eYISEqhumib+JEDEYgrRvRfLtpWqGeR JMyTCe+5hIq7uXtAi7sVkg+Lq4S4grPR26t107iNsnTcNl8jVeTuLHCZ/MZSOIPc0gFq WO87L+tcDMn32GynvxVDts4SqrFee9Bj0bkHTP5a52SX9j0I/ius7AI74xDeD2UGMqw9 2Nww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767779; x=1778372579; 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=yEm+9CK0i9MQLsvr/lRfYtx0/DM0+D55tOmGa7sB074=; b=SSdigtp3mZL9EFUk3JkDeURy0TErFcgCcWcb8I/qbl4/+B7pahUrhAb/t1th5Tk5pf Uh7dwuvp7ekWrtfStm1VY68oAu/yvgHYwE8GNKUvujAVRjEmvhdTD81w+oULH5/OoLZP QfZo45qBnnMeqbGDHxBg1aX2IjPi5+HanT6whPzhv+ol3GKB7P1nGlOU1/ac9bfunesM 7WKZpVTMz8S3+2hrcstPlA+OyH46vHjmAuYxrgG507inweBZJ2w4RSXTmPELqXOBaC4V GEiTTFhGyludz7Q6hr3uQ0qGHCequ3JZjqKB71gMbFOEt1lQpPuIGi2qZ4LPI+59awe0 KuAA== X-Forwarded-Encrypted: i=1; AFNElJ9/xDEibFLvD2t1Thu7ip2mlGR6cbgG71kgR1p5Jw4uynjb75EAqViTADp4LX4v/lRwDl2XgNzooqsDzqI=@vger.kernel.org X-Gm-Message-State: AOJu0YwMxiFX/sA9xFmOwcYKWEiNycTWu1Z8tV/doMZpt1jMhhzDB0kX fnJjJ4MHL82e24WV/UIhrzPXIvsIfoIA4KLl2lFLnUlHOqSRls8L6ZyiWkxl4/ZGZVoHGFXx2+/ stYlBtLctfQ== X-Received: from dlai27.prod.google.com ([2002:a05:701b:271b:b0:12c:8c98:df0e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4391:b0:128:ce44:be8f with SMTP id a92af1059eb24-12dfd7da1c2mr1992714c88.2.1777767778906; Sat, 02 May 2026 17:22:58 -0700 (PDT) Date: Sat, 2 May 2026 17:22:33 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-4-irogers@google.com> Subject: [PATCH v9 03/18] perf env, dso, thread: Add _endian variants for e_machine helpers From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_arch_is_big_endian(), dso__read_e_machine_endian(), dso__e_machine_endian(), and thread__e_machine_endian() to support bi-endianness and cross-architecture analysis without breaking the existing API. These helpers allow querying the absolute endianness of a DSO or thread, which is required for tools like Capstone that need to set the correct disassembly mode. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 19 +++++++++++++------ tools/perf/util/dso.h | 14 ++++++++++++-- tools/perf/util/env.c | 12 ++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/thread.c | 22 ++++++++++++++++------ tools/perf/util/thread.h | 8 +++++++- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index b791e1b6b2cf..6439b2a3c898 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 ? machine->env->arch : 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 0edc67a468ab..1a4db133262b 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -339,6 +339,18 @@ 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")) + 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 7151a9138e3f..c355df2dba7b 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 22be77225bb0..8611293deca9 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -449,7 +449,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; @@ -458,7 +458,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; @@ -468,6 +469,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) @@ -478,11 +480,13 @@ 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; @@ -491,6 +495,7 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 .machine =3D machine, .e_flags =3D 0, .e_machine =3D EM_NONE, + .is_big_endian =3D false, }; =20 if (e_machine !=3D EM_NONE) { @@ -510,7 +515,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, + is_big_endian); thread__put(parent); goto out; } @@ -522,6 +528,8 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 if (args.e_machine !=3D EM_NONE) { e_machine =3D args.e_machine; local_e_flags =3D args.e_flags; + if (is_big_endian) + *is_big_endian =3D args.is_big_endian; } else { /* Maps failed, perhaps we're live with map events disabled. */ bool is_live =3D machine->machines =3D=3D NULL; @@ -536,7 +544,7 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 } /* Read from /proc/pid/exe if live. */ if (is_live) - e_machine =3D read_proc_e_machine_for_pid(pid, &local_e_flags); + e_machine =3D read_proc_e_machine_for_pid(pid, &local_e_flags, is_big_e= ndian); } out: if (e_machine !=3D EM_NONE) { @@ -545,6 +553,8 @@ uint16_t thread__e_machine(struct thread *thread, struc= t machine *machine, uint3 } 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..8b58590c89de 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -311,7 +311,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) { --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 D4AFB1F419A for ; Sun, 3 May 2026 00:23:01 +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=1777767784; cv=none; b=kynXG2duaoYPcsmdPOiAOFa8kzhqmh2UKyvasgGby+d7c0p7/Jo09QMathjoOAyU3shecWvmyXBmftKxiYorgfmZv549y6eRYGj3nZnPMs03jC3hd2u8rS5W72sy3zY69CL8NJZczo4dfuKVozHOVD9pt/VXasw8pAwwmHaHqEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767784; c=relaxed/simple; bh=PO3Yy8xeA9w2QKJ+hooEkIab7oMYSoY1HxvISsaH+tk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=anPXAr/3+vd20ocWTNmQlSwhoqHG29spWhF4FLCh4GHhI8vUIsagJ0YjWjC7jFoJPfgbOArBFWd3ut3ELXWnH47V38Lf+AKIJe/iF11WdwbRY9x5b8oZofQhMN5Uppu5lboy+O9OV0K8FnuJcTyoMX+O5+ecsigDSxlhuB7rL8A= 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=NDGjgBn/; 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="NDGjgBn/" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12c726f4019so4280703c88.1 for ; Sat, 02 May 2026 17:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767781; x=1778372581; 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=MOjpSSG5hiDUctQJqaNUda8jZZzKwcMd5j3IEHpXIyM=; b=NDGjgBn/t9xKGRYvrkiuv+JZcAz093WPCsnqzst2OUBnSrkVqTKCjIqxVD8vo1ZTVF 9CO0JqAagT8Vw2MO/UgspTxFAR3wAh1pZA1meRcpqya6EklTpqMnRZ6/9/kfmGMXKkb8 8RQgC94qaM4wmIkM89OhmbLe+s8tUBJTb1M4BmvH5cDS+raFD21NjTr54X8uQovozwWU 7L77j4AprDlUyfLhFAJagSKT9fjLad5szwa+OqgcgOCHrxJDKQWa/Xs3MlcXEyXCJnEr FNV8/dBydROrqyyS3Bj2uWfYhPcCHYii0/jWmeKpbmoRhv9YU5CeBCfmSc4c8g6dnBJ1 jyqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767781; x=1778372581; 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=MOjpSSG5hiDUctQJqaNUda8jZZzKwcMd5j3IEHpXIyM=; b=gh9NYw7ZL+rgq4rCFvccDdtKuMbVC6cAMX+aABj5TA9Ofk0CdJ4ouNfBZ9h+CavAIE vS+iqoVMaFEdfsUr2iYkxBQoLKBPnfhT14a2Uu6jd6EvJcL/IIFiTVcH1o2uM5c92nWe l82W6qu/tfJEO+0bNFWTeLHw0RgnCVwHFu6NzpE5J2ftbOto3sgYoDniRevBjijaKATG 1m3/RaT3iARTUEJXChvyM7A2UPYi0yU7uZzkR+KZQxDcp267Jq+CVTXGjGrRl2XO+wdg OaSgcz3gerlYXWxV/c7+GgrdGQyq8vaxU/6u6hnEXv9BlGOiukDw+MDw+qJHV3WwWzcE em3A== X-Forwarded-Encrypted: i=1; AFNElJ97hqmuVDf1nL5gUbVStsaBagOOvzDevVagW7C/LDPbRXJ19yiBlWnV9HO+nbQUZ6AWkDYAhOPqtAql6CU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywg8fpkOIq2pOGon2PN7V+mw8Pw9WD1/oE0hb0GipcOJzW3wupU 1U9F3botcvAyOVBMqBkLclq4G4jhxkDS13jgLDcvSj3UQjWdUDvTay0G/iNt6DksNoQOFcB+upR sG7AzijMTSA== X-Received: from dlbcj12.prod.google.com ([2002:a05:7022:698c:b0:12d:b1c5:1596]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6725:b0:124:9fd8:4ba9 with SMTP id a92af1059eb24-12dfd7ca4b5mr2124757c88.12.1777767780844; Sat, 02 May 2026 17:23:00 -0700 (PDT) Date: Sat, 2 May 2026 17:22:34 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-5-irogers@google.com> Subject: [PATCH v9 04/18] perf capstone: Determine architecture from e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid the use of arch string that is imprecise and use the e_machine. Do more e_machine to capstone machine translations adding MIPS and RISCV. Remove unnecessary maybe_unused annotations. Signed-off-by: Ian Rogers --- tools/perf/util/capstone.c | 129 ++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 44 deletions(-) diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index 25cf6e15ec27..870394b46911 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,67 @@ 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; + *mode |=3D is64 ? CS_MODE_64 : CS_MODE_32; + + switch (e_machine) { + case EM_X86_64: + case EM_386: + *arch =3D CS_ARCH_X86; + 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: + case EM_PPC64: + *arch =3D CS_ARCH_PPC; + return true; + case EM_SPARC: + *arch =3D CS_ARCH_SPARC; + return true; + case EM_SPARCV9: + *arch =3D CS_ARCH_SPARC; + *mode |=3D CS_MODE_V9; + return true; + case EM_RISCV: + *arch =3D CS_ARCH_RISCV; + *mode |=3D is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32; + return true; + default: + return false; + } +} + +static int capstone_init(uint16_t e_machine, csh *cs_handle, bool is64, bo= ol is_big_endian, bool disassembler_style) { enum cs_arch arch; enum cs_mode mode; =20 - if (machine__is(machine, "x86_64") && is64) { - arch =3D CS_ARCH_X86; - mode =3D CS_MODE_64; - } else if (machine__normalized_is(machine, "x86")) { - arch =3D CS_ARCH_X86; - mode =3D CS_MODE_32; - } else if (machine__normalized_is(machine, "arm64")) { - arch =3D CS_ARCH_ARM64; - mode =3D CS_MODE_ARM; - } else if (machine__normalized_is(machine, "arm")) { - arch =3D CS_ARCH_ARM; - mode =3D CS_MODE_ARM + CS_MODE_V8; - } else if (machine__normalized_is(machine, "s390")) { - arch =3D CS_ARCH_SYSZ; - mode =3D CS_MODE_BIG_ENDIAN; - } else { + if (!e_machine_to_capstone(e_machine, is64, is_big_endian, &arch, &mode)) return -1; - } =20 if (perf_cs_open(arch, mode, cs_handle) !=3D CS_ERR_OK) { pr_warning_once("cs_open failed\n"); return -1; } =20 - if (machine__normalized_is(machine, "x86")) { + if (arch =3D=3D CS_ARCH_X86) { /* * In case of using capstone_init while symbol__disassemble * setting CS_OPT_SYNTAX_ATT depends if disassembler_style opts @@ -211,29 +246,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 +356,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 +377,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 +408,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 +503,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 +523,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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 EC4EE1B4F1F for ; Sun, 3 May 2026 00:23:03 +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=1777767785; cv=none; b=h3DoqyFZaz2D344PS10SyW89HcQEkhYLHjgPnfRDhfWbvzVzyjKcV/WApu9R35xybIYhBnylg5uL14fG6kSnoOZ2WfOYN9uja1+8+UhK91tXmblMEzulRhmfAiGbhRH/Rcn2D/2X99Dl6dUgHUTxfJS4eON4yHZrqyN7dXrY7H4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767785; c=relaxed/simple; bh=9QpqEPy+XyRDsxWYvbQ4axWxs+A3ZbBA767almG0lQA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UrQHbiD9Fu/PVi6Rzm7j87+BWGtVwFaujijEZt6/cK9mi3kroxB4IYMHAuOkODSGD23sCSk16Qz88A6X6DZ36NbJZgb0+5YLSo+wERfq278MuLlcLEYQ9T+Yd39IfUG8RbgAjf6UL9zu0uu3mggK8UUjLj/1zHt5GZ2fVRBE2do= 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=qGxvUwA8; 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="qGxvUwA8" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12e683ca86bso2944224c88.1 for ; Sat, 02 May 2026 17:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767783; x=1778372583; 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=NeQPgFPRPmQNsYTAg5Wkl/fjmvLR66LnLvQXotERGZQ=; b=qGxvUwA8Eg3nnr5TR71ZdWacGRIXpgNCRK8oYfpUbxtR2roOi1SeCcltRflUD0yOV7 wKeM1QmgZDiP4OvsfXGpA6ASZzC3z+USfCE/KIs+d0Kbe6yvpF/esmNj4VWfXsYLDPt3 8cuE9y0SyzW9UkaEgoKmFcn+qbMJaJxiSoKw02FkC2aw/nQEVdLIrKXrckqO2wvV8BNY gQnXAdNAhGL4+b3QILsMVfA8QBT+GhaJFPc31g8TQGsub9Xq9IgoR/ydGeby4fkOxEla uBaJbwJ6QIL9fcLUn1hoiIyu4jw96RKcSmzZrjD1utXcTKbTxJBQV00q0mHMyb/3vqxr Sa5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767783; x=1778372583; 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=NeQPgFPRPmQNsYTAg5Wkl/fjmvLR66LnLvQXotERGZQ=; b=I0MitlXXbhZtLXVV1yeU1/BlDgdsxsnUwrCI82lXxw127SzI/Bj39Q2GUkxhYxYoFT 1+THclm41JL0Br51AIfcfCHr7sYcSQ4qGiGbdh3/DxNPQandfo/SF6acsRBEHZl3CKHu TnO1ZJvxoZCRiTV6aNbAjt1y74tjymXot9xvumqf+3+QAWK8GjjkG+qTVuo0aVzOcwHg vO478bnQYaiSD5xghkvdE63/lLVKbp/RJ2hFONW/pAUqhrnIhYA06/TbY5QFW2+8XX4q cLii410Ufpt3OfTob2QrC+UGz/apjKA5kzD5M2O4xRMztLT/LaW7wvgRpsjuxTb7r4QY SOLQ== X-Forwarded-Encrypted: i=1; AFNElJ+DmGdqOHqT8LzH/ti9CZHeHS30Owj+lGtNnrkFwT2T1uR216eZbyntkjTUxswyuvImfAZawDHrt9lTEdw=@vger.kernel.org X-Gm-Message-State: AOJu0YyoYv2EEH3UVN/i4+iaxz/MD6rvUGPnnXRNMFc3DUlk9D+xaGZs CSfABjsljb4M3hwSDWlvaCYn5s/VANBGJhT+XRIJaTRhhKsEByTx3d/EIybeys0SLjLHlnky7/P EGQeRyYIL1Q== X-Received: from dlbcf14.prod.google.com ([2002:a05:7022:458e:b0:12d:ba61:2512]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61a:b0:128:d2b3:5df with SMTP id a92af1059eb24-12dfd81a65emr2186874c88.23.1777767782878; Sat, 02 May 2026 17:23:02 -0700 (PDT) Date: Sat, 2 May 2026 17:22:35 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-6-irogers@google.com> Subject: [PATCH v9 05/18] perf print_insn: Use e_machine for fallback IP length check From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid string comparisons with perf_env arch, switch to using the more precise ELF machine. Sort header files and fix missing definitions. Signed-off-by: Ian Rogers --- tools/perf/util/print_insn.c | 23 ++++++++++++++--------- tools/perf/util/print_insn.h | 3 +++ 2 files changed, 17 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 07d11af3fc1c..1f2c2f25f973 100644 --- a/tools/perf/util/print_insn.h +++ b/tools/perf/util/print_insn.h @@ -5,6 +5,9 @@ #include #include =20 +#include + +struct addr_location; struct perf_sample; struct thread; struct machine; --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 E05711FC101 for ; Sun, 3 May 2026 00:23: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=1777767787; cv=none; b=MoTOZ0d5SaKMW4ISI1blSfVVU7JZhj516IrFMlmEidWuWg6KR5mhQ/dfsD7ShTcoskJ+d4dRcWQgumxH+yLMjIcSmjfRVkslJpg45h7BmAeI+As78fXjpBF8+YuyWP/VB4Wnv8rOIVLuNKMYYPYdziLUrwuUjvJiE15d1Y19H4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767787; c=relaxed/simple; bh=AU7EKzo/kXrsAjfgR40n40MqM3yvsMJ1cD4bHl4i3uU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W45v5EEzWb+z3gXib95fc9VeTC2cjObkR94oUTPTzEOglTYzrHveGXfKHcTxxaB6EHMxeHXBL5Hzd4hUsivXPt5knkzx1OSjK6DgaxkTN0aPBVrfVeQrELwZRdmiLsj2T4lQHpW65UUeT/Od6VckBugh5gqytsU02dCccktK/6I= 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=vT6C4J10; 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="vT6C4J10" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2edfb206494so2629645eec.0 for ; Sat, 02 May 2026 17:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767785; x=1778372585; 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=mje3fRK1Ca3WEYFTmWriS1ZD47KIvC5apYOlB73RA4c=; b=vT6C4J10HPbUjs0bkIL076r272onB7owiR2QoBkiuSqR+dNTQDR+qrFQNbWxXTq79I RYJy07r803GihksM6UlqxPRpqOZTjZjnxRY8gdIO4bHSpc3nDAhucfzSnCer1TzNpitu Qs+DLPrPiO91LkXMWSQPBTlh2+99nddaorovVe3Mu+vi8RaQ8BbQ26GWzstXsGp2Af2x CFOc1m7GbQWnSJ/bSq231hR7lqiBSGzXVFtDUFZyVx29I+NTAscJ+SlCPB5z7juy0AZB LqVw1YQR9j4T0rrwe9KloahPdPmkjeDak1IrMftf6LwsWM/3PgnJi4u+2eisQRXjnMNc BW0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767785; x=1778372585; 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=mje3fRK1Ca3WEYFTmWriS1ZD47KIvC5apYOlB73RA4c=; b=WGDZeZCp5UWyqYAJNrd5OVzyKbwTFfmQ5tKdhABXMiPukPinUnqcbtts46xVcQ7QP8 EIhOpWViVwXaOMShWEVjTb9CTxDTSMhPKZMPhcTVQPdSgCiJ+90crRrme9kkEj21IB/h NGRLELH/vSVDLhCCcG0jRwBe8jocrKb5Wh5B1wufQciBKF+/b69mO1Ta1ztsl2YfnKQQ Uhm+w8uauqOj+5D2Y4qgferkQEGhIm5MJyIMR7pBZ7DtJQaPQuKngkoEgSDcrL6RWgQv 1F8YMy/J7OrO+XWhlZ5Fn5G5MDzWHdvP4kGT5BZINH9Qlk1rtkjDoEmNbNtViVVA2dTT Ri/w== X-Forwarded-Encrypted: i=1; AFNElJ/SmfUisFV6X6YO9nLTN+0cGijjkyFaMrId8TnNadTQoM9jsYHhhmIBa3tIAIWpOEJkYgAKdJut86wMiP4=@vger.kernel.org X-Gm-Message-State: AOJu0YyLJAq4+bagifluCFPIXWjIZ+Gc9lxy3cJgvudWx+fvo7Y0R4Gl fASYjY+2KkM96uAeRvkq0gBRwnssDIkChRQxHEydhmFtLCkXL4utV4Y71iVnyOFhmpoxsnu2GrS yu5vs1rY9ig== X-Received: from dlbsv4.prod.google.com ([2002:a05:7022:3a04:b0:12d:b86f:f7a6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:fe05:b0:12d:b28e:75b1 with SMTP id a92af1059eb24-12dfd81a89fmr1953500c88.22.1777767784628; Sat, 02 May 2026 17:23:04 -0700 (PDT) Date: Sat, 2 May 2026 17:22:36 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-7-irogers@google.com> Subject: [PATCH v9 06/18] perf symbol: Avoid use of machine__is From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch to using the ELF machine from the dso or running machine rather than the machine perf_env arch that may fall back on EM_HOST. This also avoids potentially imprecise string comparisons. Signed-off-by: Ian Rogers --- tools/perf/util/symbol.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index fcaeeddbbb6b..a4b1f837a5a5 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_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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 BDBF321146C for ; Sun, 3 May 2026 00:23:07 +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=1777767789; cv=none; b=Zm5rWC3c9qvMCvZVkknkjBdtteDobbjn3y36YozTcEv0aC4SGEevo/rGqPKZ4NyPhmQ4C1Be4iW58HNU8USm66EcxVnKyMd3Th4PV8/lfpJTr4Jat94YfmT+ly57MUS17uRdBydYV5w76rlP8QRAKFPqGWs+kMZ4buCiTELxMVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767789; c=relaxed/simple; bh=/g19K4HeaUNMX95kGXSMwY9kZbGyi17nk8eWwkTFbEo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LltZhVBQ7PUDWg52ewoyWGKgwA9P6tB77Yf23nype6p+jfbM5Tp3No0fqg3MiDcF6Gdq27W+qu344zN2dAEjJaR8PR4DZCnPCiSuVAtMdXw0qKXzdYDIl3XP/dTER2rKURftHgeBPSMJyn89IYIjcEr5P1M/JMSv2lU2vdm9/Og= 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=qcNJ+e6A; 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="qcNJ+e6A" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ee34588671so2551352eec.0 for ; Sat, 02 May 2026 17:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767787; x=1778372587; 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=uTtIRHRKCWvPzr+ogiuYCalROJTpC+azMEHxFbhdWy4=; b=qcNJ+e6AZ4yfr18FX3vTVoQbU/TJHqfjGfea1tTBhLFMdClOPYoe0wzKoKRRMhRPEq Ug+4XASpWfpG1DZi6EoEgjNVTQFYYZLatVpOlXgMuaLAP5tjyo9113bp+Uzuf4vNeECv ISSp0NVQMr0PzdIP9Pz5UX3s/7TvgmsBhreuMAUzk7ka51EM9czUIrMbVXHeu2KQVjBJ lEeqySOlmOCBJzwelc6tonTotQ+NJeXQidKVSwy1D/+6JLxi+lEeTU4USwOtw1KiGHG9 PapSZ8SdTsJn8NUUeupmFhXcKAFgD8Vp6XkteCdU8aPGmF12fjbQzf1ctZIN2lJTUrI9 PcCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767787; x=1778372587; 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=uTtIRHRKCWvPzr+ogiuYCalROJTpC+azMEHxFbhdWy4=; b=BHU+OvalL2bymP2fnI/+WSKJcN8oigFR3wqmMZRmMpdwI2b5Kv4nQDjk4h8fzxZxLi HPOodctyUCrjejKddhlAhx6bYx0fFr8WNrcBo0LAypnOBnyMAlC699uPg2M1TQ1KxZb9 c/EhNh954sGhl64WiZ5zJWS5XJiyaBBDpnOsHYj41E1Qrtri5IHhleofNAoAbKNfsHxf kAAn6JJCaOdBogPGACrHyCC4jP4qF/JnGtjjWXoJxFAD9jGvVbtUYogJYsap8ZjQM3N4 Jv9xDU8rCkIL8FVRCVWihFg8Ln5MJr/H6SkuEuxsa5ZBHEw7MknliYd7u9h27/9gWBoF j1ug== X-Forwarded-Encrypted: i=1; AFNElJ/kKfy4/KfNEipzto+3w+Zipe352CbPoVyIJ1WU/NIdQmjBIgX9pq/et4ZbEVuW17S0HeLv/JHOs6MwZDU=@vger.kernel.org X-Gm-Message-State: AOJu0YwmHmPajcrncAL41SMICTv332ALFML1dNEf6rd301nD1KwZZn8+ 5Tf+4qRJLVsjWdwgYatdjlEybp2iwN03+HRVJuEJ7J7mXSc6NsWV4ovl4ZF3xRShzqdCQdakjea 8pGo3kj/RCA== X-Received: from dybgi1.prod.google.com ([2002:a05:7301:81:b0:2df:c53c:24a5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:fe0b:b0:2ed:b131:240e with SMTP id 5a478bee46e88-2efba1750bfmr2023743eec.23.1777767786711; Sat, 02 May 2026 17:23:06 -0700 (PDT) Date: Sat, 2 May 2026 17:22:37 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-8-irogers@google.com> Subject: [PATCH v9 07/18] perf machine: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The arch string is derived from uname and may be normalized causing potential differences meaning the ELF machine can be more precise. Reduce the scope of machine__is as often it is better to use a thread for the e_machine rather than the machine. Switch from string to ELF machine constant comparisons. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 25 ++++++++----------------- tools/perf/util/machine.h | 2 -- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..6d32d3cb5cb7 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1611,10 +1611,15 @@ 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) +{ + return machine && perf_env__e_machine(machine->env, NULL) =3D=3D e_machin= e; +} + 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 @@ -2770,7 +2775,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; @@ -3141,20 +3146,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; @@ -3181,7 +3172,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 22a42c5825fa..003c970b3e4b 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -227,8 +227,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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 BAF381C5F13 for ; Sun, 3 May 2026 00:23: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=1777767791; cv=none; b=Tb5J+/h1jK5yML74+RBkpX4roy2vNl+a3NIwPSaARthcE6Zr2wXkQ4d8jV/wGyP+O4kpltWBpZC9JkXxLhPYnGCpuLAet9RlttEEprne3mNbs7rRaC/QcN12afMmqdiqYjvyWj9gLt0LsuM6vnAwG/arEt9chE61XOthdf3SyvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767791; c=relaxed/simple; bh=6xq1XvZTYkhssOORuD8+pN+gvzmbIFzNJbcBBfSr9dY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UoqWcbNRFHGpdjaETVMMOe1c5LsqUV7pbKzbE82PpdbQVsP+0WBQKQY75nOEDzE67oUuyutS9JkG3K3WAVQDtnWxSQ33gKbwKCA1JaHkbpXTdcPdbY4LU3LQkzAjl6FhqetvKxEjZI6cIST0yvoSvlqySm2P3Ni0+CtS7Q/+9rc= 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=JlR5Sme9; 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="JlR5Sme9" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2d93379001eso1722822eec.1 for ; Sat, 02 May 2026 17:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767789; x=1778372589; 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=dkO8i+3RSnAMWHfyM3s9GsrhLkxGMQAxj7N6Sn6bOa4=; b=JlR5Sme98+/ZqwN1B0KJel9NcQFfNMXtUoqX01qnzhSnp/XEi81uHK1+0hH3ORFJ9I 2i8yOIKmnjpM4RkjeK7VrjlEBetJsROJ6y99isQ5u4iWo2EHA2GvurcPOt6eNGtOJ7Yg tX8to1IjMyO4+XnnAbGv44uubV+aK1ivwo0QqgKZxhNIUmaPxssHKRz8mbtyiui9Qtf3 HkHwJ2q5Bfob4V39+eezHlwIYk3phMbWBROvZExzaXCXRkChYSifWtwly9m6QegyGMM+ dJ2iLMEH9Ke/zj0VJHN0jHLunZpQRS+YI02U8eYYdZMmZ7L9xftHhNB8NSPnXw0+3Kla nxbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767789; x=1778372589; 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=dkO8i+3RSnAMWHfyM3s9GsrhLkxGMQAxj7N6Sn6bOa4=; b=JHXIrqqPxf+EN76ccGCmAh4IJs2CuTTkwRs+4mgavTDnhDI+YfQ/Y9sf1yn3o/f007 1R/bSs5TZZokv7ayX6gep8bA+JOYGb0aiTI6UswonwGG2IGOZuU3/J/N+3iyhsBbNia8 uhRvfN1cpwUJq8ig/hvRF9XUK/iXSizOV+E5vMUxDMb7nsySd1W+nPb71/C+90E4Jt9a vFCo6rfOAZ4jJdjfmaYt7egzWPA+JKakkQ8b2AZ4yatACJmcvgrIJFmHbBftbQP1+pfs SpVrke3miFXflnxhC/l9e2gEKvO5Bx3BP5Xpvr2F4h/XcTjop+5HxBTR3msW4yDy2Cy3 6dMA== X-Forwarded-Encrypted: i=1; AFNElJ8BzCjAiIEHgi08fOJWj/Mfx0o3BYNNAm6iH7s90YYP5L3UGolpJ3ZRJ8Fc6N970zYOioL7tq4v53et9ZM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4HV9/re5s3nC0OhsJe2jlm3terIh2/rFbIIB7qBo55onjlMuo MpoO/riJ2c3v0f4WzSBFA/UIxhKhkup1ct+3KjDVQIeHkLBDyPh3GVWiZMsR2Itz/eAZ8Hg+dj0 NqqAhrGaYNQ== X-Received: from dlww3.prod.google.com ([2002:a05:7022:ea23:b0:12b:eb91:8863]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e1e:b0:11d:f89d:85a0 with SMTP id a92af1059eb24-12dfd81a598mr2313415c88.27.1777767788829; Sat, 02 May 2026 17:23:08 -0700 (PDT) Date: Sat, 2 May 2026 17:22:38 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-9-irogers@google.com> Subject: [PATCH v9 08/18] perf sample-raw: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than the arch to determine S390 and x86 types. Signed-off-by: Ian Rogers --- tools/perf/util/sample-raw.c | 21 +++++++++++---------- tools/perf/util/sample-raw.h | 6 +++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/sample-raw.c b/tools/perf/util/sample-raw.c index bcf442574d6e..be998c713a0d 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_eflags=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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 00D5F202F70 for ; Sun, 3 May 2026 00:23:13 +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=1777767798; cv=none; b=iVUmxQCze2jI2XAXptDoyK5HjgVou4Z3ARTbmovX0l3rz3IaRo7y6rCBmzxwK7K5G9qCVHNb9TcK4/rVRKIiksMWxit8HmrF5BLQu/9jzxRES70Ed/P7AVeqFcTw3iCXjz00ks8m3DKUdcLZrpQuoEBIgA+wwfT1JgkM/HXUrHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767798; c=relaxed/simple; bh=3YxL5VzE6bHl3FdRH/Jn9cIz8yFva46ZW763ff/pUc0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rSsghtxnpsOkyENZj35zJxmOOBiyA9P7SRnOHtDO6ENw/hm8Is7I1VUcvL4lFYjwLS8FmadksgxtcVWr/aD3cjbyGnM3MuJVayRERbmLnWlwxEo8Gl+qfkV5kqczb3nuwEtaflIzGwhjlUXby1RxaOuwVr7+Duj0tX0HLiPueuI= 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=dLJHpHro; 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="dLJHpHro" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12dba1e866dso3087973c88.1 for ; Sat, 02 May 2026 17:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767791; x=1778372591; 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=/6FeuxlGm3VrKdgs8XUfTlIan59NM0soqe95RHdyhTY=; b=dLJHpHroKqVd5fnvGBI+1fe5sA9FFPEbsYNby1D0Nr44ta/8F+fpw8aBr1vkRPu7rR Wr4gcy9EERlCVeKjAmrg0k8AVeshXAC/IQKMOehRCvCdY0A/G3dcJ42Ph7scPzqiTxKv 3JcOtDUw+Yg4ZwVCmqJ19myvKoiWzGNXB/Eq723nJobwyPkw9PYFDxrQ4hqhqbrakVyQ 5Am0P19M2cPZAZCQPjH+35hXHVIzf5BnQWJvYN7H5Ei3OhrfSvBLXgdm79mK9B+/vFKy ePpv4rQ4rrO0TyCO8AVJ9PUqN2T/SrZRM9cY1BgU5kkTofKaq1SBQGsDRPMdsAkXO0/j 4HDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767791; x=1778372591; 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=/6FeuxlGm3VrKdgs8XUfTlIan59NM0soqe95RHdyhTY=; b=HYLuiQjTXA8Q8ZJwurSZpP09qAyLh8wvyJSzIa6d6BtkYDk4NYcXoTq1pKbWpgz5Vm bpPOqD6mkBqALk6V/TGBShDXGrtFSQoJYz5+sKaMQn6TTTzuhAzJ6XcFwtvwb2LQnWy2 J60IXxz7KENIw0drIN3bOeSR+PtmPjZpSEBZhnblMTWOzCAEGG5rhd541ze+4LO3nNtQ Xn5nwN9LQ9fDYPGCE1pmMcN9eVSedGuVflLQoKyOF4Djy5oyfZXiy2BS3nkn9+3+lChV o24NIen/7dei8pxRN55cKFHeoVeP2VgDKChMpHs7pRccYway4MgNWA9w7kXH//aStPH0 VSrw== X-Forwarded-Encrypted: i=1; AFNElJ8T/7Va37IJnl6wX0HwlfU7EBvjDVNBQRP+F3qw4uqfRwsDFgpF0lbB0JYZOC/kIJhUeNmqejQL9Ynvpa8=@vger.kernel.org X-Gm-Message-State: AOJu0YwVPIFs8t4vFSZtRHE2NICC0y1LSGc3+FyQMyp7GdH/7rgiek/m Bo7IdEu4A3u4oSXRDOLXkDCJXtJ31G8nAQi18wsxdVfo+rC/28APhvsmgYUEGSgS5Ua4nkfFmjV rtT/M68DHfA== X-Received: from dyib18.prod.google.com ([2002:a05:7300:79d2:b0:2d9:3c6b:a26b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:203:b0:12c:9037:5126 with SMTP id a92af1059eb24-12dec61125amr5551297c88.9.1777767790824; Sat, 02 May 2026 17:23:10 -0700 (PDT) Date: Sat, 2 May 2026 17:22:39 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-10-irogers@google.com> Subject: [PATCH v9 09/18] perf sort: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than the arch to determine x86 or PPC types. Signed-off-by: Ian Rogers --- tools/perf/util/sort.c | 58 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 0020089cb13c..90bc4a31bb55 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1,40 +1,45 @@ // SPDX-License-Identifier: GPL-2.0 +#include "sort.h" + #include #include #include -#include #include + +#include +#include #include +#include #include + +#include + +#include "annotate-data.h" +#include "annotate.h" +#include "branch.h" +#include "cacheline.h" +#include "cgroup.h" +#include "comm.h" #include "debug.h" #include "dso.h" -#include "sort.h" +#include "event.h" +#include "evlist.h" +#include "evsel.h" #include "hist.h" -#include "cacheline.h" -#include "comm.h" +#include "machine.h" #include "map.h" -#include "maps.h" -#include "symbol.h" #include "map_symbol.h" -#include "branch.h" -#include "thread.h" -#include "evsel.h" -#include "evlist.h" -#include "srcline.h" -#include "strlist.h" -#include "strbuf.h" +#include "maps.h" #include "mem-events.h" #include "mem-info.h" -#include "annotate.h" -#include "annotate-data.h" -#include "event.h" -#include "time-utils.h" -#include "cgroup.h" -#include "machine.h" #include "session.h" +#include "srcline.h" +#include "strbuf.h" +#include "strlist.h" +#include "symbol.h" +#include "thread.h" +#include "time-utils.h" #include "trace-event.h" -#include -#include =20 #ifdef HAVE_LIBTRACEEVENT #include @@ -2673,9 +2678,10 @@ struct sort_dimension { =20 static int arch_support_sort_key(const char *sort_key, struct perf_env *en= v) { - const char *arch =3D perf_env__arch(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_eflags=3D*/NULL); =20 - if (!strcmp("x86", arch) || !strcmp("powerpc", arch)) { + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386 || e_machine = =3D=3D EM_PPC64 || + e_machine =3D=3D EM_PPC) { if (!strcmp(sort_key, "p_stage_cyc")) return 1; if (!strcmp(sort_key, "local_p_stage_cyc")) @@ -2686,14 +2692,14 @@ static int arch_support_sort_key(const char *sort_k= ey, struct perf_env *env) =20 static const char *arch_perf_header_entry(const char *se_header, struct pe= rf_env *env) { - const char *arch =3D perf_env__arch(env); + uint16_t e_machine =3D perf_env__e_machine(env, /*e_eflags=3D*/NULL); =20 - if (!strcmp("x86", arch)) { + if (e_machine =3D=3D EM_X86_64 || e_machine =3D=3D EM_386) { if (!strcmp(se_header, "Local Pipeline Stage Cycle")) return "Local Retire Latency"; else if (!strcmp(se_header, "Pipeline Stage Cycle")) return "Retire Latency"; - } else if (!strcmp("powerpc", arch)) { + } else if (e_machine =3D=3D EM_PPC64 || e_machine =3D=3D EM_PPC) { if (!strcmp(se_header, "Local INSTR Latency")) return "Finish Cyc"; else if (!strcmp(se_header, "INSTR Latency")) --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.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 871351DED63 for ; Sun, 3 May 2026 00:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767799; cv=none; b=Pg7sycm2Z+1OZVgER/0rtRZgD91fIKtXLcIcsKgDXnRUDmMch1GpRQ9pWrWuFxmoUo17Z/d6zEhkMNrUbfhi3NQ4N6CRqguNfLc3akfjT9jKIhMs3dZgGx3ZwVZMXO3jC06btq5bwhRzGvnqDTZVTXpfJvgNMdieiklXRjX4bZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767799; c=relaxed/simple; bh=eqeOWxhFyM7dwpKHN7IomuaifDbDMcmVmoxsj1Wk+h4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hSh9nxcRnv4d4GJifAoE4OCPgJO/Xwgm9fAoYMqj4rxVHsMB9figykGjvNle8zLbnjJWW74LffKqTMHWE0Z/CH+Ay/Sr+k9SdYoExCDLIGln3ljFsvnuLLtvVfWQnTSLw6ntiRpAXFyHCD347igHlzg+C19e37Ggdxa21y1Rd+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MnQwJBGM; arc=none smtp.client-ip=209.85.216.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="MnQwJBGM" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-362d9dd9a49so3223665a91.0 for ; Sat, 02 May 2026 17:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767793; x=1778372593; 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=c1UEnrZj6LrH1rbpoINuKLPntj2HeRkp2Oo3eKcuhyg=; b=MnQwJBGMQvLqOqZAAAcfIYDJzayjknxvLK9qFRqRLKqAOOxTsrDUio9iQ+Adf94QDX zrSL8BWOWFGW+SdtDyOeuCETL+la2t81drwRCNKP+YI2TpuopIO81gC59HbH8qgP4st1 E0A+yAz4utkeeL+6mLepZkpl9LRhKPBJ6ESn1BoOuJhxSQvFkYowclCldTvRr9sykBTf GhNwNRR2/JihhEoDztcxeVIBcDUQc4vZ6CAudiTTmE3RgkRBEuFyQtVqg9fUUVneb7cT 99WCVpoCv01WgBLho1WQ3eRa4fQdKBnzs6XBux348ynARRn2xTfbib7wlGEQMeUU5YRh s8aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767793; x=1778372593; 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=c1UEnrZj6LrH1rbpoINuKLPntj2HeRkp2Oo3eKcuhyg=; b=EwqO0214yXs0Q2QlNFcI8n5iPuBihBheeOpF7MYZyLwiQTDaOaJfUPhroYTtcHbCgn T6QTMojL0Img/9SRGhVl57pnAxGLH+rKXCp8MFvStQpVTndjCoPyIQgMgrxElBhsOwxB yigvFTFTgRGL7anlS5bfozq28wNqabvOutwSN7ik/7snnbElYvYMTiWNs9saVrXZjUJP LCMFdpSoY2E4QIiDCTaQTJ7tw50AwPj25z9uzVxUYUZ1XNTFiKFikAJcRiVKvgLHhkHP 56BQWVFg2DvigzHDrj4rgNw8q/nOCieP8h2Rgl5yMhOy3zVVV9vRuO/b2UKZwUt1F6x5 TLTw== X-Forwarded-Encrypted: i=1; AFNElJ8afn4WMjenGxyUZGI/IlL953401HgmaPw0p7nxYzQqW3cyBNOtBcnYtW00jaRsdV1g/+wBi8u/QM209VE=@vger.kernel.org X-Gm-Message-State: AOJu0YxNnpfskTKLQpsGR2NFj4QxzPT/8QxxpGmeHCyl18B3WZr7hNO0 gWmLNJ+PWRzCEnQ9hOWjureeALtcG3Wmg/QOgDtFLizEM8W07/Zf3ByVxPtwb2gHFFEeSjMtIX5 dtcMrMffJYQ== X-Received: from pjbmg18.prod.google.com ([2002:a17:90b:3712:b0:362:ba47:7b37]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b0e:b0:35f:bd51:cf60 with SMTP id 98e67ed59e1d1-3650cd7115fmr4357446a91.1.1777767792718; Sat, 02 May 2026 17:23:12 -0700 (PDT) Date: Sat, 2 May 2026 17:22:40 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-11-irogers@google.com> Subject: [PATCH v9 10/18] perf arch common: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching. Signed-off-by: Ian Rogers --- tools/perf/arch/common.c | 62 ++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c index 21836f70f231..1d8aff9b32d6 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-", @@ -145,7 +150,8 @@ static int perf_env__lookup_binutils_path(struct perf_e= nv *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 +159,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 (e_machine =3D=3D EM_HOST) goto out; =20 cross_env =3D getenv("CROSS_COMPILE"); @@ -170,30 +176,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 +220,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,5 +255,5 @@ int perf_env__lookup_objdump(struct perf_env *env, char= **path) */ bool perf_env__single_address_space(struct perf_env *env) { - return strcmp(perf_env__arch(env), "sparc"); + return perf_env__e_machine(env, /*e_flags=3D*/NULL) !=3D EM_SPARCV9; } --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 C9A0117A586 for ; Sun, 3 May 2026 00:23:15 +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=1777767801; cv=none; b=lQOmfpJAA3VhblnOjyQppbv+2btCPpdtMurwmqq0NHETMo8YnsyE7EJFkemT+f5fYGwgV13jaiv5owQrWUbk8r/UjEqnHxKVOUzzHcbPyVdyrJkG9zU2xCVgPg514gO82HdQyfcAWnJeeUcmgAf3iBVlmjF85hiH0plJ0sCQ//c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767801; c=relaxed/simple; bh=NkDzTpISKGLznN8DpCYnw5FlKY6SegO9ajNHEUGCkJ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ms87JGXbFQTX7Y1hUiHn0ePA0c+ireYxKjxQRvRzR6CPn7ByTP4SmSl3xHy8Eo6ofK6UK50iRGA7rmzLKAfTQIcyLjDGkfzl4v/Vv2xRlGUDiB7RmKMMDyO3A2RERMc7tUaEZdyxnwkWJ4U6ze41dnyK68RFTwW46ch7h90qJNo= 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=GdYTU2PK; 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="GdYTU2PK" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12dfe12d285so762398c88.0 for ; Sat, 02 May 2026 17:23:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767795; x=1778372595; 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=ptY6oVWnZ5/CE0Bj1nWU4voD2W/pshYyEHj8eE03jqQ=; b=GdYTU2PKbcSzUH0ZJXIhX+sdJzJ86wlWCswF45l+2j0w/aJ5vIZi4ebKljkMoN2ZQo ipGYwFmX7koc3Bmfa++pWetC/9Vy9vbOW0sDhZPx3DP0mawjK3oxF7HpDYTzbYP7rZWo OZT35YnZoJlADwMGbnj2QAK9BEVnpMkZWe/HbOaNU375bZRAlbreSPJo+CWt8m2ogGj3 sxAaMexHkdCQx238dtBMrXxeapbdyw6kFdiB3UlB+zhET+ymwEEQPJrjqxwcDlZFfW/n QKsKCJKDJmxZ0b3RRY1ShHI8szOHJGK+935QBcYOXi2JGb93wD7hv5MsqiXFE2pY49+e xuYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767795; x=1778372595; 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=ptY6oVWnZ5/CE0Bj1nWU4voD2W/pshYyEHj8eE03jqQ=; b=Q2Ti3qUO1i+trzDRVUwL+T92BMYSHQztMb9wyIWyxAilbdZRYgyaVMchnRENCn0ERC XGudFVPRfTtCCsAxQFPZ+J+1f/VcNBtpOGprUgxmAjRdPH1DFuSC2i7k3xGZ38MIHDSD UtFkB05JGOs2YCU7JDMCuFyG3h7sxaUQvmehJLEIAfulOENNd1FAQJkkUQgDUvXGRLFn KfKSOrwbz09CPpFfe9Y2L4nIodN7QnIrHdzTX5/YAupHxJHBZcMPqDYFdhTvgqdEkbqt OGn5vfTKE33bQk/a6e8qM7vW62iJxzI3260h1CCrjfHLW78ZKcYS59xv2Da4OBNE0X5l vR0g== X-Forwarded-Encrypted: i=1; AFNElJ+jJlY5QGk5ww+k2GhTKJlb0a8epdDiBNQ0bVE2cRTMsoaB+ycxGPzlbRZHtFbaICvp/o/GGZwUlW5smZM=@vger.kernel.org X-Gm-Message-State: AOJu0YwLHKfTVOmz0YLSa+qh7YP0XPpV0XhV9kbDJThEO+EF3VEy3Z0x 2GC42BpxOQ2Bfgq0ApS/xMXiwFq0y6GasVHj/SkE4WJiDX0JxISOk8GXWsBhzRp+zT9CPmQJIGr cDoC/ZPESKg== X-Received: from dlbps10.prod.google.com ([2002:a05:7023:88a:b0:12c:b3eb:b31e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:224:b0:12a:72af:83d1 with SMTP id a92af1059eb24-12dfd7c5ed9mr2445709c88.11.1777767794714; Sat, 02 May 2026 17:23:14 -0700 (PDT) Date: Sat, 2 May 2026 17:22:41 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-12-irogers@google.com> Subject: [PATCH v9 11/18] perf header: In print_pmu_caps use perf_env e_machine From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from arch to e_machine in print_pmu_caps. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index f1ae61392cce..bdf6c5d0fd5d 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2348,15 +2348,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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 9E6221E5B88 for ; Sun, 3 May 2026 00:23:17 +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=1777767801; cv=none; b=c+33HDS6QSalzLxput9dME93UmHeLKujsOHbnMqsF7oyUA24+sZQsGukphE7kil+nQ1twAMzBr7i8BOAiCsI2iX7jHyfHAvjioExHmZGTUbgo3axKAyAfwWBsjLJ2CGZsGSHuLckLZp0BFLy6UHawO3Oc2OcPiaFu9y1ts8N+BI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767801; c=relaxed/simple; bh=d95RN7/rMJzrpe1UoXLER23VbQTmBzaPGsXRYVYoWgg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mgiLWkjH43UJqUn+m1tYsIIMq2H9qB7fPi43GNGCJ5BrAhKh8eY2taszZG6rdZ/w7wyxxiCV5Bq6gOS1DEcFY8TQF6YavfIW7L6SAIxM9c2oL6oOBnVLpm0WTpy8d0lsJaNrefybalfX5lL57p6HpD+bVYQzwwQIQv52jP3I8cs= 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=LTe7jf/1; 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="LTe7jf/1" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12c8ccc7593so2441569c88.1 for ; Sat, 02 May 2026 17:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767797; x=1778372597; 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=22j8DoF2fXHm+jGHFBjOBjrvQEypyYf+IRlyHBjQD5I=; b=LTe7jf/1QwwTcq36henFTWK9JftSDZjimq6F8m7MIncX1q3HEUR70vzMv5CVFzqMMU KBx2XUBi+ooEB7mCnWbG0697ntMEDAmrnyVMFSlQRAuGMN+Zb7gcB31bPHVm2lDdANDk OZQsrUbFI+SJUXco1EW35iKy/iOThveGvvuP1VinxIxigTyHm0pRdsGq812TvrBKb7HL m1Ye1H+6bK8KWVHkOxnEQWJYQZ4b0fJDsMam1paea6b2EtnL8Y8j5pEdAQtvSynqWvXL GCHt4T01oC9DfJ5ISfs6nyyo2RO+J/UJX6FcMGwq7NFq9X+2agHZXq0YvRhymsYy4Yqu ttWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767797; x=1778372597; 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=22j8DoF2fXHm+jGHFBjOBjrvQEypyYf+IRlyHBjQD5I=; b=cKcqd2cebIaV47kJjYnD8OqNpJvMYmwS5xOfcztBrLvqoLrSmnCSTxHn5gDLsuLrIp +/ddvDM5kJI1B4urtDUxesDYSqAOjk4HqWPEvrG1tJ1L5tHHIR96aW98fm2gMPE/VOaJ HMzOXudVNkmVMIJIZoeDVjy6juX4CLbRGPDMWGdlzwmrXbVWCjI5y7VzJw4HytD0rEVX UlMakbMYXMT/HCeXu6mcQtfWiJt7Kzb4NE0ZlCi4xjh2DaOdqyal9WvrO44qCVk9GUlv oPiHA2U655wzYj9aDVbOwiWRZi/fryQJ0mT3yaOr34ojxue61xEk8x6gYzL1//66dR4u pGbw== X-Forwarded-Encrypted: i=1; AFNElJ/tpPiGOnV4ZBpywXe549s2LZj6bV6MDHh5SIylnOq57jax0CtgQewrPE8mkmthckMfzjrdr4vjwwaQS8A=@vger.kernel.org X-Gm-Message-State: AOJu0YywuY/tL80tEiW1zDKY8ufnNaIwzCkKEeHxT8bCrWKEY1VHhK6c 6L3Vu3AzMcSNjHDDiYZhFk3B2LoEIVce1Ps6lOwB3Qg69QewysawUECzxGvp2YNqf3GFTWGxO3j toqilkfnTog== X-Received: from dll26.prod.google.com ([2002:a05:7022:21a:b0:12d:b48e:8597]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:68a1:b0:128:dcbd:e27c with SMTP id a92af1059eb24-12dfd823241mr2253597c88.20.1777767796555; Sat, 02 May 2026 17:23:16 -0700 (PDT) Date: Sat, 2 May 2026 17:22:42 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-13-irogers@google.com> Subject: [PATCH v9 12/18] perf c2c: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching for AARCH64. Add include of dwarf-regs.h in case the EM_AARCH64 isn't defined, sort the headers given this include. Signed-off-by: Ian Rogers --- tools/perf/builtin-c2c.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 72a7802775ee..c55cab53531b 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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 CC5BF21771B for ; Sun, 3 May 2026 00:23:19 +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=1777767804; cv=none; b=q+vSt+lm0dhh0s+uOPAdx3LR3V42TgL/Qox3U+KW/MgEgCWHfq7i6TdyrYIU9LmK2GtGlLhtLaQJoStHvkmYMQOSdtPazT9oml4jR8TtAIh/yfj6XSZsRwcywVP1XbdPV9y7TTnffihi9skTk5MMTj4Y/5tly41MP5FuiIPjAj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767804; c=relaxed/simple; bh=uvhPGJ8aFyrj8sz3RY0F7uCaw7UwOHqluJDNG48CN5w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JbOJHGlNk5rYYY6eQABHZ9oo/ly7vzeFTJ2OrW1COjZNiBSaOAWmOPQpS2xxKOxzt8zwxlBus0Yquj1lqBKqYn/cJC2bea4s2/K6HFgLy9FTwYDBrhQ8Sb1lvlWs0OZbp6ESG9DF0ejgcOJsuPdFcKmr4AEOkdWFnvbUvEuaXYc= 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=ir6JcRfn; 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="ir6JcRfn" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12c8ccc7593so2441584c88.1 for ; Sat, 02 May 2026 17:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767799; x=1778372599; 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=D5+XfQfSgM6vL4wGV0II5aik5OsLQWVkexovkX+K6RU=; b=ir6JcRfn+fI3ai2inAHCgum7TT4eeyhx3PV980fZlANonfV14RihGMmFt8cCq5A+b7 aWB62sLS5UTdPl/M6RmEC7kRX8iwey9m/MkS2AHo+pwX985O5YUPUhHURsx4MbBctIXF PDuGtuzPRD4S38WP9edMgoXrV89OrAJIvzpixdkuK90L8Nxl4MB+NhbKSl7NWOSzm9iW PkowJUfQPINZY4G3die4va3o5pFo0SADrg015kJDlyZask3S1DsnTgW9gLXlwhUJgwBt 5PDInkh0ASkkovqBaGQoMU8A1Yo4DZc2J3rudSCsRx22NEyy4RO4sxkhUW8fs7dEu3tH /3HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767799; x=1778372599; 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=D5+XfQfSgM6vL4wGV0II5aik5OsLQWVkexovkX+K6RU=; b=VlbnqpoK+4t4GKXTW7qnJSIi4BvgH4JCBJvymos1UVSly+z6+si73wboMkOPz8QGzK /O4j/kNgqF68pOUOjfa5Ie+I5qkdxjJYzrCAdVtVdafMNiM0gxD7QhYdOf/s8q9aYEu9 XvGRsRwmNL0eqLhd4kGEZHq+NWygoGucTJvghdYdLaaOwk30kdR9BwwLfyTmlPv0YLrP cY8sTFgwId7pqokkbTv14TxvMyfg14s8qDSvG73wio0Js4Sb9EPQrmn4oL4gvD7G5Aus 9XkKUe2/4LSpI1hSSPqpCtiejs6T2ldIEaJpL1dolZM98D+1HAlLLPT6suBXPhK0o1sJ lHAg== X-Forwarded-Encrypted: i=1; AFNElJ8pTqK1BkC9ZwY9yyAKfs8XZbF0HLyDBt+OQ2Zx8Ay+H6D13NEZe84RrEEwzbOeCgs1CeEboow+A4sgiIk=@vger.kernel.org X-Gm-Message-State: AOJu0YwlvFbhY+qTcPLlL7D0RULv/Da3/YuvCkxdgbNDNQgeyXpkn4K6 i/j0bip7MgnfpISMgBKN7wN9agTexxAA4WxdsHtyYpAygOu9U3t0vV8JqY6HPHIBnxITvd+7v0+ bXd6ZKmheAQ== X-Received: from dlbbo32.prod.google.com ([2002:a05:7022:43a0:b0:12d:b396:eadf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61e:b0:12a:6e97:c21f with SMTP id a92af1059eb24-12dfd71099dmr2240616c88.0.1777767798592; Sat, 02 May 2026 17:23:18 -0700 (PDT) Date: Sat, 2 May 2026 17:22:43 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-14-irogers@google.com> Subject: [PATCH v9 13/18] perf lock-contention: Use perf_env e_machine rather than arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the e_machine rather than arch string matching for powerpc. Signed-off-by: Ian Rogers --- tools/perf/util/lock-contention.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/lock-contention.c b/tools/perf/util/lock-conte= ntion.c index 92e7b7b572a2..119a7206f3cd 100644 --- a/tools/perf/util/lock-contention.c +++ b/tools/perf/util/lock-contention.c @@ -104,7 +104,8 @@ bool match_callstack_filter(struct machine *machine, u6= 4 *callstack, int max_sta struct map *kmap; struct symbol *sym; u64 ip; - const char *arch =3D perf_env__arch(machine->env); + uint16_t e_machine =3D perf_env__e_machine(machine->env, /*e_flags=3D*/NU= LL); + bool is_powerpc =3D e_machine =3D=3D EM_PPC64 || e_machine =3D=3D EM_PPC; =20 if (list_empty(&callstack_filters)) return true; @@ -125,8 +126,7 @@ bool match_callstack_filter(struct machine *machine, u6= 4 *callstack, int max_sta * incase first or second callstack index entry has 0 * address for powerpc. */ - if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || - (i !=3D 1 && i !=3D 2)))) + if (!callstack || (!callstack[i] && (!is_powerpc || (i !=3D 1 && i !=3D = 2)))) break; =20 ip =3D callstack[i]; --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 8D68F2165EA for ; Sun, 3 May 2026 00:23:21 +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=1777767804; cv=none; b=ZeeuY8JDvmyV5b3L8vNjCWAte0e4PmN+/J9dwl2qadHj9I3pb8o3ufFIfQ3MzhkdRYLvhD7B/9MWYBI6qSgt2gf0ZY4sUPNhYl2usCwvE2EWkpblPBCYnuCrLkagcAWSiZkzhQRN5bY5FpVpFL7FjHuUq7/dBXuWbs0aZxbCT28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767804; c=relaxed/simple; bh=5jhU6nHm5t52x/E6UfkGF7nwddgtnU+zivsqR1+Mzjk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aGWADy91ljj/X4GUNUCRtfi0yUm5JJEdOFCsNYNefbuNa2t5mrWodyZObSvMZLkJn81WXL7WDqfU0m53IF0rgHrEngwcTKDDZuXrttJ2ESoyH5KuBRbAvfB/DflYzxyVH3Fbiej/HECiSrS84N62W0tGXUYep1jwRlPQN2fWHkU= 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=TYceMjjb; 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="TYceMjjb" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2c0f6593ef5so4566406eec.1 for ; Sat, 02 May 2026 17:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767801; x=1778372601; 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=osisIhDCjYBr9yPonf3Zb/MCBx8M3bxED2pwUnaO1Z4=; b=TYceMjjbMCAx09wqdZsUILtf/KsVZt555XHv9Mxm6UadLzOY3I7yq3xnwyz4V6lw7U kQdp2+JAzvl7IlfGR9xHnpEdfowacawVtBFkzQcq9Snsx6kaN/NH7yX9CcrI9BHzOnJA fAAR3F87KNYAgdC2KsGj5hVPQM+Pi75uSbJaJ2YadPrQvk+VmWDrl2jq4r41wtQYkSgz kQse58jCTI4rqOuwsuZDmt89htv9WDA2Y/2n48Z4hUWz9F0x7rADNRVZn0PZujxbGrKq 159TP4cnYzqCL0hVixIkk5X2eie6rVxLrTtbB2bKvSk9dd2LewUWEpOjjqvkiRnLeEPw CdEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767801; x=1778372601; 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=osisIhDCjYBr9yPonf3Zb/MCBx8M3bxED2pwUnaO1Z4=; b=cyiCCdpIt8KPYAq+QH0rF7PFluvdaPV/OWYotiTb5c8SopTz1Ld1f9VzVhDpm1Jq10 PDl5kHt8VHLIfT8PtW7eYqNada26fbYjeeOPvVy5+joRpthMW/+hFytTJzt3CD2myNWN u0QfwjoehJGFyMxlFboQE6QTitiLapfBVtZjOD+kdka0F8qCEawOfX+GlGFCSdbDLTVC u2ZA7QC0n+tXAfZ5V5S6Tc2wVzlfWy1gRM2RTj7QA0YUTlStPXYv2wmi5gGanI20I6h8 UY9+i4Qt0OhQogiiMT9QK6OIDz/n206MUX7X8kuqzUGna75Xa0mZqem/VT/rar/MXe9S YcrQ== X-Forwarded-Encrypted: i=1; AFNElJ/SFZY+q9GxUupxU27k6seTpilrT3KHD5NJHx1h/MpnFa8U3eMsVj7lvWhUZps5eWu2VGAp3UROiUkHUa8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3mgLYAneorf5nUFXGfwYhMSY411dvi4KFtL5m9MnY/eqDjhRn zTK2mMxB/s+qx1EenwQZHRLmncZhQ8qAY30gA2zzpCEIA+GRHeSq5LwVV6nBl1++f1P7YSA1tPv 3v953DvFFxQ== X-Received: from dleb18-n1.prod.google.com ([2002:a05:701b:4252:10b0:12c:1286:e1ba]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:50f:b0:12a:6c4b:9d01 with SMTP id a92af1059eb24-12dfd79e70fmr1907543c88.7.1777767800375; Sat, 02 May 2026 17:23:20 -0700 (PDT) Date: Sat, 2 May 2026 17:22:44 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-15-irogers@google.com> Subject: [PATCH v9 14/18] perf env: Refactor perf_env__arch_strerrno From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_env__arch_strerrno is only available with libtraceevent so hide the declaration if no libtraceevent. The previous approach maps an architecture string to a function pointer to a function that takes an int errno values and returns a string. The new approach takes an e_machine and an errno value and returns a string. As the only call site is in builtin-trace.c, the e_machine is already present and potentially more specific than the perf_env arch string that is a single global value. The major complication in this approach is having the shell script that generates the C code map a linux directory name to the matching ELF machine constants. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 7 ++-- tools/perf/trace/beauty/arch_errno_names.sh | 40 ++++++++++++++++++--- tools/perf/util/env.c | 13 +++---- tools/perf/util/env.h | 7 ++-- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index e58c49d047a2..d278af18542f 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -3008,9 +3008,8 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, } 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); } @@ -4890,7 +4889,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/arch_errno_names.sh b/tools/perf/trace= /beauty/arch_errno_names.sh index b22890b8d272..89b742927168 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -52,21 +52,49 @@ 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 'static arch_syscalls__strerrno_t *\n' - printf 'arch_syscalls__strerrno_function(const char *arch)\n' + printf 'static 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 +102,8 @@ cat < +#include +#include =20 EoHEADER =20 diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 1a4db133262b..8ac7aff0b27c 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -798,17 +798,12 @@ const char *perf_env__arch(struct perf_env *env) #include "trace/beauty/arch_errno_names.c" #endif =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)); - - 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); } +#endif =20 const char *perf_env__cpuid(struct perf_env *env) { diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index c355df2dba7b..ba51b871c401 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -67,8 +67,6 @@ struct cpu_domain_map { struct domain_info **domains; }; =20 -typedef const char *(arch_syscalls__strerrno_t)(int err); - struct perf_env { char *hostname; char *os_release; @@ -158,7 +156,6 @@ struct perf_env { */ bool enabled; } clock; - arch_syscalls__strerrno_t *arch_strerrno; }; =20 enum perf_compress_type { @@ -191,7 +188,9 @@ void cpu_cache_level__free(struct cpu_cache_level *cach= e); uint16_t perf_env__e_machine_nocache(struct perf_env *env, uint32_t *e_fla= gs); uint16_t perf_env__e_machine(struct perf_env *env, uint32_t *e_flags); const char *perf_env__arch(struct perf_env *env); -const char *perf_env__arch_strerrno(struct perf_env *env, int err); +#if defined(HAVE_LIBTRACEEVENT) +const char *perf_env__arch_strerrno(uint16_t e_machine, int err); +#endif const char *perf_env__cpuid(struct perf_env *env); const char *perf_env__raw_arch(struct perf_env *env); int perf_env__nr_cpus_avail(struct perf_env *env); --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 51466223DCE for ; Sun, 3 May 2026 00:23:23 +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=1777767804; cv=none; b=sA06FtEMLTqDGBIFv8W/URFEQM4qcheZXhEkNaDQNMaHZqvaC+IoAOaaVlRx5YuGm/XkLAwze9uZCKpVNyGjL4Itx3cATW5ztiZizy0TGJmmikrkSvoujx1tskTfs+7GQbIxbQtDB/Hchu80BTdj/RWA50F2BAZO5VG/qmP5I1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767804; c=relaxed/simple; bh=oPhtIYTZ3hsEu6jjU4s7MOVLcdebH8MFtbow08cDcec=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HWETKFaO5Ux6toViBPl0/nD2uubY2kHAyIo/+PVZCkSUKTfQ39oN95i9883FgLsq6ZmQyi0NM+NP+FBSH0wBa7SkWy6owhUXoTUEesyeqoI3EfyUIl7jq84BwiQ93XX50IU/vRuEXeW8ZxAG4OXzdu9/Te0iJ5nt4czPC170ccE= 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=seTRxAm+; 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="seTRxAm+" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12c726f4055so4949697c88.1 for ; Sat, 02 May 2026 17:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767802; x=1778372602; 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=sNEOtAMR5QCvXyZplIv0gRH0b0eemE/yfoOhcH4gY8c=; b=seTRxAm+PXXk57IHi0xp6FUtTD8iXSUWiuDHAdwVSIApNRPBNXFjZuKPW2Q1pTwPv8 5OJ8BlWYHEMXYb8K4ibOdmHrr7fs89WVt5qTAG3biPwTrZi9UBAYR+VLTyut1QVbaPET HDecS/pjCSPhpRwJWtF6KC8eeORE+e0zI1dGNYLd1NpwoDSVB8+meodRedvwizgz4l93 akRRsms41myoNnvN82Qa9rzjg82JvDUnJaYBPIy0uDHAePA2JWcVgWiRN68EWRY8aS8O n3x4GWcel+DD4AR4s3473ichokk5h0T2LMHlnVT9WLPCOXfvCv3xKZe+EdkT9rs6sIU/ L1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767802; x=1778372602; 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=sNEOtAMR5QCvXyZplIv0gRH0b0eemE/yfoOhcH4gY8c=; b=GPFLIN21Lalho9TzshLkq48Vn8/LbEOZSKLIaFCEiMU9JSnDXIftYQx3YuhYUW+AJ1 QA3TghgOL73YLAxjCr+Kc+R6zHLXqED2xQg7kdlwfooRLxnQ5T8TcQXv266nnuhPfyT8 VvnzC9LXrKfgnVdTMdgQtXERI+erIjrgpBLDyUrEx7yID63kS4LZ/AtDQP4kjOWm4QfT Fb+++YAWTMF22yDVKjDxDfVah7KO+ckiwv6B+kyt5znFOIIEYvdwHfC0X5rgzP1y4wPn 7+uVhWXPph9Ed2t+vnwehf90Wsfv2Xe8iqs44lZd7hM1BLdl5KD3zlNcdh+N58yv7z9c mgbw== X-Forwarded-Encrypted: i=1; AFNElJ/26BW+ZUVMdsvEVhWrU0TuIhMmz60MGC3tln/ljS9my8KOLzvYngd9mQ4sbtlT8hMy6+lnTwefq7trmsk=@vger.kernel.org X-Gm-Message-State: AOJu0YwZDHOOir6j/dFeUdRoCLCiyC/7hiw0a2aBS5GUfS9ptUpkTaxS YZQkRwV6SvPcaJNPHF42Y5guR4uzVLb8CutR6X7MFqf/gCGIkN5Zk3k92Kg6zKLu4kGfpmuOrDt bjQGeTebfSA== X-Received: from dlbtx10.prod.google.com ([2002:a05:7022:fc0a:b0:12d:4be7:8b60]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:78f:b0:12d:ca32:59f with SMTP id a92af1059eb24-12dfd7e5bdbmr2156723c88.11.1777767802181; Sat, 02 May 2026 17:23:22 -0700 (PDT) Date: Sat, 2 May 2026 17:22:45 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-16-irogers@google.com> Subject: [PATCH v9 15/18] perf env: Remove unused perf_env__raw_arch From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The switch to using e_machine has made the perf_env__raw_arch function unused so remove it. Signed-off-by: Ian Rogers --- tools/perf/util/env.c | 18 ------------------ tools/perf/util/env.h | 1 - 2 files changed, 19 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 8ac7aff0b27c..29d5fe37528b 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -463,19 +463,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) @@ -594,11 +581,6 @@ int perf_env__read_core_pmu_caps(struct perf_env *env) return ret; } =20 -const char *perf_env__raw_arch(struct perf_env *env) -{ - return env && !perf_env__read_arch(env) ? env->arch : "unknown"; -} - int perf_env__nr_cpus_avail(struct perf_env *env) { return env && !perf_env__read_nr_cpus_avail(env) ? env->nr_cpus_avail : 0; diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index ba51b871c401..bc4801d8399b 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -192,7 +192,6 @@ const char *perf_env__arch(struct perf_env *env); const char *perf_env__arch_strerrno(uint16_t e_machine, int err); #endif const char *perf_env__cpuid(struct perf_env *env); -const char *perf_env__raw_arch(struct perf_env *env); int perf_env__nr_cpus_avail(struct perf_env *env); =20 void perf_env__init(struct perf_env *env); --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 4B3FB235C01 for ; Sun, 3 May 2026 00:23: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=1777767806; cv=none; b=gWgubY3cBx3iWsEL1fY74MOt9hlmXIw+t3Pom9H8Lup9sV7pe17Uzn2sWYf6mR0lHI0d/5TTAWnJSa1k7tyqTUqXSPxCzbgx+xCH1PDiBShRhOPqVLKe6zn8PiNIECLlQjQ4CrwBRtfipeDgvav4CfnVwcLImy8MIa8vIb1ECgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767806; c=relaxed/simple; bh=w5kpdZYj1td3iRz5bsagJOu+tDvOqzls3fa/ZafOK4s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JVjuT2aThTBDUqrLqQ4xBbxAb7nn7S0S0Wkt2CkSYAe8dL7l5prAVNjFjRoVksqcQdDmQClHYfNTgOXY6En/HqzhSPx6dlitQyY3A3PFtvOcvjSfCvHU5SdP6VaXNpRz352tkGTN1tPTE/lrt7UbRCfQa6o1XBSxNRVhc/YCT7w= 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=C6/teL5l; 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="C6/teL5l" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-12dba1e866dso3088034c88.1 for ; Sat, 02 May 2026 17:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767804; x=1778372604; 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=9x9Wl/o6+3fkfHLuSXv5iQt4Ma9xKjje9sib/Ct92Ic=; b=C6/teL5lTIOfyiRp+NHXpFYmdq+x6+/Udq+gRtAdRFQL9gqQ7oW9WRbM2LORgV9cke XkheO4HrANutjI5OqmB+jf6GrsU8cZDMT8XSLe9A1RLBFne0Yn+bRTTS43fUu0nBdHPR Cne3Q/DUYkkj+/4jfwjfXaMda/cgHJqkesi08qF9k5LeZFnKTo9A2dhJRMTalryfpbTR Tds/HW5x0b3bqFM0JWCV8V8otXxRRR5CDCUKwpEfuQWB5Kdusgha9SU/r6cyAMS0BVRd ZTW691c0/bfr87crzZkgU6N8kIvKxJks5yh2P29UjhiVosYY4hL055ookrgLLpf7hK2J yo3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767804; x=1778372604; 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=9x9Wl/o6+3fkfHLuSXv5iQt4Ma9xKjje9sib/Ct92Ic=; b=j75UE9w2w1Av4QNwwxGumXo1EKZvD/brYxcT22WQzLY1wZNVkW3OhoQrGOvIPIJxV2 rWNANlqwuS3w+VFNd5iZdb/vjSNn1IHi7klTOmAdLRbOPuxA/tdaeagePOvxYCFg86+l x6zf2qe6AauVSaXJqZH1iR4KlOR8ujoZK2YOwP0wm8Boc7yb36JNZtldY8Huto/M+hVL xPLr50hucsvJRbB6wG1kmgIz7Vg2wZz+aXhlpiT5m1cVSGvo32+Z3o5I0RHY6Bnkbaar l47jImj9ifrmgGyRirtXLOMya2sQFPicukG6Xy9dyrZaOu5gnrvMIPld5x058B7mFBgs AUpw== X-Forwarded-Encrypted: i=1; AFNElJ9hiCwJTtFzbKDDHNXPOqefc5QMifO3DOtrwTlwZejM676KvE5Au/Oz0ELX14WWxS8J969HcPhXYnfDavM=@vger.kernel.org X-Gm-Message-State: AOJu0YwRlEu5rBVCc7ZwGe0Re2rdsapXXww6wDNeQ+VAIPHscO6eDPVw IAg5FDyuXUK3/+gfZZtOdhJDQMh+qPZ+cR8rh1paT0Nibw8SSOaRiOIehY2jgKMUdhtHCy/68Sz n26gWutikcA== X-Received: from dlrr17.prod.google.com ([2002:a05:701a:c951:b0:12d:b6de:8dbe]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ef01:b0:12d:c4b7:5625 with SMTP id a92af1059eb24-12dfd5439b5mr2076377c88.9.1777767804253; Sat, 02 May 2026 17:23:24 -0700 (PDT) Date: Sat, 2 May 2026 17:22:46 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-17-irogers@google.com> Subject: [PATCH v9 16/18] perf env: Add helper to lazily compute the os_release From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In live mode the os_release isn't being initialized, make a lazy initialization helper that assumes when the os_release isn't initialized this is live mode. Signed-off-by: Ian Rogers --- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/env.c | 21 +++++++++++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/header.c | 16 +++++++++++----- tools/perf/util/symbol.c | 4 ++-- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-conve= rt-bt.c index 3b8f2df823a9..2c88420fe33e 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/env.c b/tools/perf/util/env.c index 29d5fe37528b..45dde40042b5 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -351,6 +351,27 @@ bool perf_arch_is_big_endian(const char *arch) return false; } =20 +const char *perf_env__os_release(struct perf_env *env) +{ + struct utsname uts; + int ret; + + if (!env) + return perf_version_string; + + if (env->os_release) + return env->os_release; + + /* + * The os_release is being accessed but wasn't initialized from a data + * file, assume this is 'live' mode and use the release from uname. If + * uname or strdup fails then use the current perf tool version. + */ + ret =3D uname(&uts); + env->os_release =3D strdup(ret < 0 ? perf_version_string : uts.release); + return env->os_release ?: perf_version_string; +} + int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []) { int i; diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index bc4801d8399b..bbf10446204c 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -173,6 +173,7 @@ void perf_env__exit(struct perf_env *env); =20 int perf_env__kernel_is_64_bit(struct perf_env *env); bool perf_arch_is_big_endian(const char *arch); +const char *perf_env__os_release(struct perf_env *env); =20 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv= []); =20 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index bdf6c5d0fd5d..ce0c392ead69 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -370,13 +370,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 a4b1f837a5a5..fabed5b0fa57 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.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 91EED23909C for ; Sun, 3 May 2026 00:23:27 +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=1777767810; cv=none; b=BjtfBv6Z3ruXu/Ndv9uRDnSutXFBB8ahTKkdzS7SIsBKKOT3nqF3U1tEjH930WPmMcrD9xP5QzS59iWuyUFROIGJw+jmkZhT7SvDOzwrkV6gh5bcoVBw61d504OXqAJc/23RoT5f5KJ94fjKy6eqqNKCVFnD5D4BSCgabwmQeTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767810; c=relaxed/simple; bh=Z3faXq9f+WjFAO1liLiqiUfN9lS40EI+yJDKsK+1Hj4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W5U6keZzYba98wEnedTYxeCTVYVhSjtu/bn6iNNt/LibA7xu4LnIdgTpkFIHE9ECb6PeSPD2E5O0BVW0qQAOF1VO/z34RSKatFZkjKRs0gT6F9YxXcmezFXekV6dcQH3wxSGC+HN5LhTCUMRhz3xFrLKulI6ZmB0kqqAMPYqdSI= 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=gHhGrr+i; 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="gHhGrr+i" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2de07c12745so3840294eec.1 for ; Sat, 02 May 2026 17:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767807; x=1778372607; 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=S8L3HbKdTMOPvVdgusvGD3VxW6jAd7Z4D4VnDnu6U2g=; b=gHhGrr+io2W1nQWFbHI+GQ9orltbovLTVW38gbbLW2ZWb7Z/cKwm+c7TgFJtpDx7RJ C7PsltkygyBvyd/tzTIy8BFVouVbdgLtzSbUoq08Yfrsrx68yn3kj6dpnKay8A7fk/Tu AU1e3BQTnqStpED0Z/ZInFpYvG9cwmmwddCAE3F28r2jUDUmWw+KQUh7L2K5IYuTud3j NKtobmmxMDFmhneIv6EK0QSi/BG0PND1BYWuLL0tXJ3OFDmXQTh4/ZNhTTRVt3r38x/M SeytCw3YvLkU+koJ0GRdHzscFVbp4+6uRrJ9KXkav/t2i0jlEcO1Ivc8Fq0RUj7bddNh 4vKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767807; x=1778372607; 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=S8L3HbKdTMOPvVdgusvGD3VxW6jAd7Z4D4VnDnu6U2g=; b=QqrLv+J9bGbbS0/PMWyhzZ9n1elkWAXeLI3Wex3zTrp7Ge4lh0EBp8Bhk8qI+O5PG6 1NZEfBvimpO2GVkdJLjWXpbEfomfiW7uxvJNFeHknkCsoWydlNj9WsZI5zudghXo3Zq2 YgY6IY1rdVDlccfiKBdg6zDOlaMR+yxuJSqd0ndqdQQMn9W4AcV42lVaFazKyayEd2GH qldZABNbql2Jzoc5bRkpPGJg1bZJdsPWXAAT3KE2HAMMogodvWy3xW8TmOZEGxZucssY I56Kkw966NV+UHyKy5SNV5MNuK26CYkSqyligFrkBVn46gQAK6R+HC0C054ZtxCNfgU6 M/iw== X-Forwarded-Encrypted: i=1; AFNElJ8b7MjIC6CgradSPy1FKAKKfJRVwNcx6/tKcMLSlzB0XB7EKHcKHdc3KAdtNXwatEo2a3wl4at2DYgR8lk=@vger.kernel.org X-Gm-Message-State: AOJu0YxP9NGCQIxE4DtUJck4VaBJUeqdwrDNKCElnb+96nhFuVcTbWu2 lp/HtEuKnMlXqDRDHycw8EZ5nsHVmy7jNczJnwpcfREd3HZWvCo0kG3y6skjH9XBas5ns4X7wfD dQTutnI8iDg== X-Received: from dlam9-n2.prod.google.com ([2002:a05:701b:2089:20b0:12d:c6d9:5fd7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4c:b0:128:cedb:33c6 with SMTP id a92af1059eb24-12dfd7d1ac1mr2025683c88.16.1777767806736; Sat, 02 May 2026 17:23:26 -0700 (PDT) Date: Sat, 2 May 2026 17:22:47 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-18-irogers@google.com> Subject: [PATCH v9 17/18] perf symbol: Add setters for bitfields sharing a byte to avoid concurrent update issues From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A problem with putting bitfields into struct symbol is that other bits in the symbol could be updated concurrently and only one update to the underlying storage unit happen, leading to lost updates. To avoid this, use atomics to atomically read or set part of 16-bits of flags in the symbol. Add accessors to simplify this. The idle value has 3 values in preparation for a later change that will lazily update it. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 6 +- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/builtin-top.c | 6 +- tools/perf/tests/symbols.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 2 +- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate.c | 5 +- tools/perf/util/auxtrace.c | 6 +- tools/perf/util/callchain.c | 4 +- tools/perf/util/dlfilter.c | 2 +- tools/perf/util/evsel_fprintf.c | 6 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/machine.c | 2 +- tools/perf/util/probe-event.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 2 +- .../scripting-engines/trace-event-python.c | 4 +- tools/perf/util/sort.c | 8 +- tools/perf/util/srcline.c | 10 +-- tools/perf/util/symbol-elf.c | 3 +- tools/perf/util/symbol.c | 84 +++++++++++++++---- tools/perf/util/symbol.h | 70 ++++++++++++---- tools/perf/util/symbol_fprintf.c | 4 +- 25 files changed, 171 insertions(+), 75 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index f174bc69cec4..390327c7f78d 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -439,9 +439,9 @@ static int perf_event__convert_sample_callchain(const s= truct perf_tool *tool, node =3D cursor->first; for (k =3D 0; k < cursor->nr && i < PERF_MAX_STACK_DEPTH; k++) { if (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 */; + ; /* kernel IPs were added already */ + else if (node->ms.sym && symbol__inlined(node->ms.sym)) + ; /* we can't handle inlined callchains */ else inject->raw_callchain->ips[i++] =3D node->ip; =20 diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 9d3a4c779a41..7337ee956dc9 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -725,7 +725,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 95c0bdba6b11..3c9ada8539c3 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -753,7 +753,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 555247568e7a..7c874a258cb4 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2371,7 +2371,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); @@ -3035,7 +3035,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 f6eb543de537..9a0c388a7ec3 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) @@ -830,7 +830,7 @@ static void perf_event__process_sample(const struct per= f_tool *tool, } } =20 - if (al.sym =3D=3D NULL || !al.sym->idle) { + if (al.sym =3D=3D NULL || !symbol__is_idle(al.sym)) { struct hists *hists =3D evsel__hists(evsel); struct hist_entry_iter iter =3D { .evsel =3D evsel, 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 e745f3034a0e..2ecb514888ba 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -235,7 +235,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 @@ -2224,7 +2225,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 a224687ffbc1..afcdefe95fee 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2663,7 +2663,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); } @@ -2681,8 +2681,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 f031cbbeeba8..9a107f42acdd 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 fc9eec8b54b8..6a405a9d829c 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -2979,7 +2979,7 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u6= 4 *ptss_ip) start =3D dso__first_symbol(map__dso(map)); =20 for (sym =3D start; sym; sym =3D dso__next_symbol(sym)) { - if (sym->binding =3D=3D STB_GLOBAL && + if (symbol__binding(sym) =3D=3D STB_GLOBAL && !strcmp(sym->name, "__switch_to")) { ip =3D map__unmap_ip(map, sym->start); if (ip >=3D map__start(map) && ip < map__end(map)) { diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 6d32d3cb5cb7..7e38dde160b7 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1078,7 +1078,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 e261a57b87d4..3e0490030ddd 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -304,7 +304,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 5a30caaec73e..9d62a0921aee 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -437,7 +437,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)); @@ -1275,7 +1275,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 db164d258163..877d4889cd0d 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); @@ -437,7 +437,7 @@ void inline_node__delete(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 7afa8a117139..a9045d6fcb95 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 fabed5b0fa57..4702b8989354 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -50,7 +50,7 @@ =20 static int dso__load_kernel_sym(struct dso *dso, struct map *map); static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map); -static bool symbol__is_idle(const char *name); +static bool symbol__compute_is_idle(const char *name); =20 int vmlinux_path__nr_entries; char **vmlinux_path; @@ -163,24 +163,24 @@ static int choose_best_symbol(struct symbol *syma, st= ruct symbol *symb) else if ((a =3D=3D 0) && (b > 0)) return SYMBOL_B; =20 - if (syma->type !=3D symb->type) { - if (syma->type =3D=3D STT_NOTYPE) + if (symbol__type(syma) !=3D symbol__type(symb)) { + if (symbol__type(syma) =3D=3D STT_NOTYPE) return SYMBOL_B; - if (symb->type =3D=3D STT_NOTYPE) + if (symbol__type(symb) =3D=3D STT_NOTYPE) return SYMBOL_A; } =20 /* Prefer a non weak symbol over a weak one */ - a =3D syma->binding =3D=3D STB_WEAK; - b =3D symb->binding =3D=3D STB_WEAK; + a =3D symbol__binding(syma) =3D=3D STB_WEAK; + b =3D symbol__binding(symb) =3D=3D STB_WEAK; if (b && !a) return SYMBOL_A; if (a && !b) return SYMBOL_B; =20 /* Prefer a global symbol over a non global one */ - a =3D syma->binding =3D=3D STB_GLOBAL; - b =3D symb->binding =3D=3D STB_GLOBAL; + a =3D symbol__binding(syma) =3D=3D STB_GLOBAL; + b =3D symbol__binding(symb) =3D=3D STB_GLOBAL; if (a && !b) return SYMBOL_A; if (b && !a) @@ -227,14 +227,14 @@ void symbols__fixup_duplicate(struct rb_root_cached *= symbols) continue; =20 if (choose_best_symbol(curr, next) =3D=3D SYMBOL_A) { - if (next->type =3D=3D STT_GNU_IFUNC) - curr->ifunc_alias =3D true; + if (symbol__type(next) =3D=3D STT_GNU_IFUNC) + symbol__set_ifunc_alias(curr, true); rb_erase_cached(&next->rb_node, symbols); symbol__delete(next); goto again; } else { - if (curr->type =3D=3D STT_GNU_IFUNC) - next->ifunc_alias =3D true; + if (symbol__type(curr) =3D=3D STT_GNU_IFUNC) + symbol__set_ifunc_alias(next, true); nd =3D rb_next(&curr->rb_node); rb_erase_cached(&curr->rb_node, symbols); symbol__delete(curr); @@ -322,8 +322,8 @@ struct symbol *symbol__new(u64 start, u64 len, u8 bindi= ng, u8 type, const char * =20 sym->start =3D start; sym->end =3D len ? start + len : start; - sym->type =3D type; - sym->binding =3D binding; + atomic_init(&sym->flags, (type << SYMBOL_FLAG_TYPE_SHIFT) | + (binding << SYMBOL_FLAG_BINDING_SHIFT)); sym->namelen =3D namelen - 1; =20 pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n", @@ -345,6 +345,49 @@ void symbol__delete(struct symbol *sym) free(((void *)sym) - symbol_conf.priv_size); } =20 +void symbol__set_ignore(struct symbol *sym, bool ignore) +{ + if (ignore) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_IGNORE); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_IGNORE); +} + +void symbol__set_annotate2(struct symbol *sym, bool annotate2) +{ + if (annotate2) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_ANNOTATE2); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_ANNOTATE2); +} + +void symbol__set_inlined(struct symbol *sym, bool inlined) +{ + if (inlined) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_INLINED); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_INLINED); +} + +void symbol__set_ifunc_alias(struct symbol *sym, bool ifunc_alias) +{ + if (ifunc_alias) + atomic_fetch_or(&sym->flags, SYMBOL_FLAG_IFUNC_ALIAS); + else + atomic_fetch_and(&sym->flags, ~SYMBOL_FLAG_IFUNC_ALIAS); +} + +static void symbol__set_idle(struct symbol *sym, bool idle) +{ + uint16_t old_flags =3D atomic_load(&sym->flags); + uint16_t new_flags; + uint16_t idle_val =3D idle ? SYMBOL_IDLE__IDLE : SYMBOL_IDLE__NOT_IDLE; + + do { + new_flags =3D old_flags & ~SYMBOL_FLAG_IDLE_MASK; + new_flags |=3D (idle_val << SYMBOL_FLAG_IDLE_SHIFT); + } while (!atomic_compare_exchange_weak(&sym->flags, &old_flags, new_flags= )); +} void symbols__delete(struct rb_root_cached *symbols) { struct symbol *pos; @@ -375,7 +418,7 @@ void __symbols__insert(struct rb_root_cached *symbols, */ if (name[0] =3D=3D '.') name++; - sym->idle =3D symbol__is_idle(name); + symbol__set_idle(sym, symbol__compute_is_idle(name)); } =20 while (*p !=3D NULL) { @@ -717,11 +760,19 @@ int modules__parse(const char *filename, void *arg, return err; } =20 +bool symbol__is_idle(const struct symbol *sym) +{ + uint16_t flags =3D atomic_load(&sym->flags); + uint16_t idle_val =3D (flags & SYMBOL_FLAG_IDLE_MASK) >> SYMBOL_FLAG_IDLE= _SHIFT; + + return idle_val =3D=3D SYMBOL_IDLE__IDLE; +} + /* * These are symbols in the kernel image, so make sure that * sym is from a kernel DSO. */ -static bool symbol__is_idle(const char *name) +static bool symbol__compute_is_idle(const char *name) { const char * const idle_symbols[] =3D { "acpi_idle_do_entry", @@ -2492,6 +2543,7 @@ void symbol__exit(void) { if (!symbol_conf.initialized) return; + strlist__delete(symbol_conf.bt_stop_list); strlist__delete(symbol_conf.sym_list); strlist__delete(symbol_conf.dso_list); diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index bd6eb90c8668..a199646f21f7 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,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). @@ -54,20 +72,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. */ @@ -77,6 +82,43 @@ 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(&sym->flags) & SYMBOL_FLAG_TYPE_MASK) >> SYMBOL_FLAG_= TYPE_SHIFT; +} + +static inline u8 symbol__binding(const struct symbol *sym) +{ + return (atomic_load(&sym->flags) & SYMBOL_FLAG_BINDING_MASK) >> SYMBOL_FL= AG_BINDING_SHIFT; +} + +static inline bool symbol__ignore(const struct symbol *sym) +{ + return (atomic_load(&sym->flags) & SYMBOL_FLAG_IGNORE) !=3D 0; +} + +static inline bool symbol__inlined(const struct symbol *sym) +{ + return (atomic_load(&sym->flags) & SYMBOL_FLAG_INLINED) !=3D 0; +} + +static inline bool symbol__is_annotate2(const struct symbol *sym) +{ + return (atomic_load(&sym->flags) & SYMBOL_FLAG_ANNOTATE2) !=3D 0; +} + +static inline bool symbol__ifunc_alias(const struct symbol *sym) +{ + return (atomic_load(&sym->flags) & SYMBOL_FLAG_IFUNC_ALIAS) !=3D 0; +} + +bool symbol__is_idle(const struct symbol *sym); + +void symbol__set_ignore(struct symbol *sym, bool ignore); +void symbol__set_annotate2(struct symbol *sym, bool annotate2); +void symbol__set_inlined(struct symbol *sym, bool inlined); +void symbol__set_ifunc_alias(struct symbol *sym, bool ifunc_alias); + /* symbols__for_each_entry - iterate over symbols (rb_root) * * @symbols: the rb_root of symbols diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fpri= ntf.c index 53e1af4ed9ac..4dc8d5761f52 100644 --- a/tools/perf/util/symbol_fprintf.c +++ b/tools/perf/util/symbol_fprintf.c @@ -11,8 +11,8 @@ size_t symbol__fprintf(struct symbol *sym, FILE *fp) { return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", sym->start, sym->end, - sym->binding =3D=3D STB_GLOBAL ? 'g' : - sym->binding =3D=3D STB_LOCAL ? 'l' : 'w', + symbol__binding(sym) =3D=3D STB_GLOBAL ? 'g' : + symbol__binding(sym) =3D=3D STB_LOCAL ? 'l' : 'w', sym->name); } =20 --=20 2.54.0.545.g6539524ca2-goog From nobody Sat Jun 13 04:48:46 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 EA7B8261388 for ; Sun, 3 May 2026 00:23:29 +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=1777767813; cv=none; b=cr/Zz6AzgWYnpxwX0wLlFzeGEcDxDxbQLK0u9jfr8c1upNnofpPd5W5QbNxwVvhrBBludKU69EEBtFAIgz+Bg/p0D4b84VMriko/I+iuiKYpskQQbxOgP9lmdfxuArFznvu9vXmItWKeIHhxej0GTRARu8rH0H41+3KTzIQ9ElA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777767813; c=relaxed/simple; bh=pikKL0ytl7bvVH0d9CpEQgzbFoqeQtrn9npsggARIwo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qEy3Ey8Z/kEfEivs+ZD6ShcJCl073z05MZ6E8lDxHCyy460VxHQUAnIZUZb72VoAlpxk2yyl7lMiXMGrFOb3gKrzjLOyrNuIqzSYWAMUcIKYlMdO86X3eVvClT+SSykCjlhcKMqptJVvgGELF6h97rxT9i59K9lkVyL0Tc6afhA= 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=A2sx0D2A; 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="A2sx0D2A" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2de07c12745so3840370eec.1 for ; Sat, 02 May 2026 17:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777767809; x=1778372609; 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=5SiYbjUQxW7Zl0nlxdQib3Qm3zWmIiIf5vHfJT4wj/o=; b=A2sx0D2AcjWzXD9/HyrbKjvnxn+Ql+7MZwSmeAOGl/arI2pW9ARdofHUqeSTA7pbLv WlSWnDOPihQ+Fy8ea4uLO89Kz4HWThqP/WmaBl3JuTla21Ze3ix8ceFB6QR4ETvijeWE 0MIKsli58xyXSYk/CadR9Gs7ULBNFFTSkxWHqj/TS1qpS2PRLR6L068xHF/VToXO5chS UQBqyK1O5UDCrwnIPQdBMlVzrIYsAMASrvVEldZG95fPDYxl+kbFRbgn61da2VNJa2Xz hFgqQldOkqnQCXB6hApsx9F85a333fbDTnQH0SDuB1IKyFCUEXZG3ZdDem4aGKK/RJld ND3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777767809; x=1778372609; 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=5SiYbjUQxW7Zl0nlxdQib3Qm3zWmIiIf5vHfJT4wj/o=; b=UJvuXScvoh1ygxbz5b9t5DMYPYsTRXI/m0D2ofa+0LWkWaKRXj7zKQgXMcJBSZ4cGY oR6xCsIaaN1OzzqV67smnDA63xcJv+LB85KbAnUJsQSZiyjCSgH8TC0AG360ayCljRj7 fTfyT/rN3V3+sbHTDJGhncRXv+PEnR6D1X2M5bLQ9qdYk3gAq4qoCS4IIHD8w5GpW+ZU hCWF425J8Fds/DnvdqOrsaQFCKRNMBXEl3AQ+XCsndGDKn1e7L8wTNyiTjODWGdbQCVK /X0+Y51xRCOZtTAjyY2KTLF3xZYN3WkqFw9ltELGujHJh7TaKuRCt5bRyJvJElHQjnWE kzyg== X-Forwarded-Encrypted: i=1; AFNElJ9+ZKvei8uhXeyqWv26620LlAF/fTmAMLj8peb+2J3yDdaVAFZZgVoWgoGWTkT0216xkxQwuK2agh+HC6M=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3ed2DmzTpMcoMWW37oHyTfGRZvxd5Medm6G00fKGpUvER1MkY RMFymP/Cg6a6azjQPs5ZU0/w/31ESeSQYXuCF0q2ruq93m8EYf4v0f4OA0z+dd4n5EDA+jfzNA1 9S9vUhSapEg== X-Received: from dybgh27.prod.google.com ([2002:a05:7301:1b:b0:2df:7541:1895]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:1007:b0:2da:1a81:5ae with SMTP id 5a478bee46e88-2efb83ade46mr1983186eec.10.1777767808747; Sat, 02 May 2026 17:23:28 -0700 (PDT) Date: Sat, 2 May 2026 17:22:48 -0700 In-Reply-To: <20260503002248.1040791-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: <20260502065935.291960-1-irogers@google.com> <20260503002248.1040791-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260503002248.1040791-19-irogers@google.com> Subject: [PATCH v9 18/18] perf symbol: Lazily compute idle From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org, tmricht@linux.ibm.com 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 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. 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/ The change switches x86 matches to use strstarts which means intel_idle_irq is matched as part of strstarts(name, "intel_idle"), a change suggested by Honglei Wang in: https://lore.kernel.org/lkml/20260323085255.98173-1-jameshongleiwang@126.co= m/ Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- tools/perf/builtin-top.c | 3 +- tools/perf/util/symbol-elf.c | 2 +- tools/perf/util/symbol.c | 114 +++++++++++++++++++++-------------- tools/perf/util/symbol.h | 8 +-- 4 files changed, 74 insertions(+), 53 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 9a0c388a7ec3..efb4b1172190 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -830,7 +830,8 @@ static void perf_event__process_sample(const struct per= f_tool *tool, } } =20 - if (al.sym =3D=3D NULL || !symbol__is_idle(al.sym)) { + 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(evsel); struct hist_entry_iter iter =3D { .evsel =3D evsel, diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index a9045d6fcb95..69484abc07b6 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1728,7 +1728,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 4702b8989354..2caa6b8b8609 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; @@ -401,8 +400,7 @@ void symbols__delete(struct rb_root_cached *symbols) } } =20 -void __symbols__insert(struct rb_root_cached *symbols, - struct symbol *sym, bool kernel) +void __symbols__insert(struct rb_root_cached *symbols, struct symbol *sym) { struct rb_node **p =3D &symbols->rb_root.rb_node; struct rb_node *parent =3D NULL; @@ -410,17 +408,6 @@ void __symbols__insert(struct rb_root_cached *symbols, struct symbol *s; bool leftmost =3D true; =20 - if (kernel) { - const char *name =3D sym->name; - /* - * ppc64 uses function descriptors and appends a '.' to the - * start of every instruction address. Remove it. - */ - if (name[0] =3D=3D '.') - name++; - symbol__set_idle(sym, symbol__compute_is_idle(name)); - } - while (*p !=3D NULL) { parent =3D *p; s =3D rb_entry(parent, struct symbol, rb_node); @@ -437,7 +424,7 @@ void __symbols__insert(struct rb_root_cached *symbols, =20 void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym) { - __symbols__insert(symbols, sym, false); + __symbols__insert(symbols, sym); } =20 static struct symbol *symbols__find(struct rb_root_cached *symbols, u64 ip) @@ -598,7 +585,7 @@ void dso__reset_find_symbol_cache(struct dso *dso) =20 void dso__insert_symbol(struct dso *dso, struct symbol *sym) { - __symbols__insert(dso__symbols(dso), sym, dso__kernel(dso)); + __symbols__insert(dso__symbols(dso), sym); =20 /* update the symbol cache if necessary */ if (dso__last_find_result_addr(dso) >=3D sym->start && @@ -760,55 +747,90 @@ int modules__parse(const char *filename, void *arg, return err; } =20 -bool symbol__is_idle(const struct symbol *sym) -{ - uint16_t flags =3D atomic_load(&sym->flags); - 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__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); +} + +bool symbol__is_idle(struct symbol *sym, const struct dso *dso, struct per= f_env *env) { - const char * const idle_symbols[] =3D { + 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 =3D perf_env__e_machine(env, /*e_flags=3D*/NULL); + + { + uint16_t flags =3D atomic_load(&sym->flags); + uint16_t idle_val =3D (flags & SYMBOL_FLAG_IDLE_MASK) >> SYMBOL_FLAG_IDL= E_SHIFT; + + if (idle_val !=3D SYMBOL_IDLE__UNKNOWN) + return idle_val =3D=3D SYMBOL_IDLE__IDLE; + } + + if (!dso || dso__kernel(dso) =3D=3D DSO_SPACE__USER) { + symbol__set_idle(sym, /*idle=3D*/false); + return false; + } + + /* + * ppc64 uses function descriptors and appends a '.' to the + * start of every instruction address. Remove it. + */ + if (name[0] =3D=3D '.') + name++; + + if (bsearch(name, idle_symbols, ARRAY_SIZE(idle_symbols), + sizeof(idle_symbols[0]), sym_name_cmp)) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } =20 - if (idle_symbols_list) - return strlist__has_entry(idle_symbols_list, name); + if (e_machine =3D=3D EM_386 || e_machine =3D=3D EM_X86_64) { + if (strstarts(name, "mwait_idle") || + strstarts(name, "intel_idle")) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + } =20 - idle_symbols_list =3D strlist__new(NULL, NULL); + if (e_machine =3D=3D EM_PPC64 && !strcmp(name, "ppc64_runlatch_off")) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } =20 - for (i =3D 0; idle_symbols[i]; i++) - strlist__add(idle_symbols_list, idle_symbols[i]); + if (e_machine =3D=3D EM_S390 && strstarts(name, "psw_idle")) { + int major =3D 0, minor =3D 0; + const char *release =3D perf_env__os_release(env); =20 - return strlist__has_entry(idle_symbols_list, name); + /* Before v6.10, s390 used psw_idle. */ + if (release && sscanf(release, "%d.%d", &major, &minor) =3D=3D 2 && + (major < 6 || (major =3D=3D 6 && minor < 10))) { + symbol__set_idle(sym, /*idle=3D*/true); + return true; + } + } + + symbol__set_idle(sym, /*idle=3D*/false); + return false; } =20 static int map__process_kallsym_symbol(void *arg, const char *name, @@ -837,7 +859,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 a199646f21f7..422e98a4ea2f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -28,6 +28,7 @@ struct map; struct maps; struct option; struct build_id; +struct perf_env; =20 /* * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; @@ -60,7 +61,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). @@ -112,7 +112,7 @@ static inline bool symbol__ifunc_alias(const struct sym= bol *sym) return (atomic_load(&sym->flags) & SYMBOL_FLAG_IFUNC_ALIAS) !=3D 0; } =20 -bool symbol__is_idle(const struct symbol *sym); +bool symbol__is_idle(struct symbol *sym, const struct dso *dso, struct per= f_env *env); =20 void symbol__set_ignore(struct symbol *sym, bool ignore); void symbol__set_annotate2(struct symbol *sym, bool annotate2); @@ -196,7 +196,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); @@ -236,8 +235,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.545.g6539524ca2-goog