Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Move x86__is_amd_cpu() to util/env.c

It can be called from non-x86 platform so let's move it to the general
util directory. Also add a new helper perf_env__is_x86_amd_cpu() so
that it can be called with an existing perf_env as well.

Reviewed-by: James Clark <james.clark@linaro.org>
Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Cc: James Clark <james.clark@arm.com>
Cc: Atish Patra <atishp@atishpatra.org>
Cc: Mingwei Zhang <mizhang@google.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Link: https://lore.kernel.org/r/20241016062359.264929-7-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

+28 -28
-1
tools/perf/arch/x86/util/Build
··· 10 10 perf-util-y += mem-events.o 11 11 perf-util-y += evsel.o 12 12 perf-util-y += iostat.o 13 - perf-util-y += env.o 14 13 15 14 perf-util-$(CONFIG_LIBDW) += dwarf-regs.o 16 15 perf-util-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
-19
tools/perf/arch/x86/util/env.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include "linux/string.h" 3 - #include "util/env.h" 4 - #include "env.h" 5 - 6 - bool x86__is_amd_cpu(void) 7 - { 8 - struct perf_env env = { .total_mem = 0, }; 9 - static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */ 10 - 11 - if (is_amd) 12 - goto ret; 13 - 14 - perf_env__cpuid(&env); 15 - is_amd = env.cpuid && strstarts(env.cpuid, "AuthenticAMD") ? 1 : -1; 16 - perf_env__exit(&env); 17 - ret: 18 - return is_amd >= 1 ? true : false; 19 - }
-7
tools/perf/arch/x86/util/env.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _X86_ENV_H 3 - #define _X86_ENV_H 4 - 5 - bool x86__is_amd_cpu(void); 6 - 7 - #endif /* _X86_ENV_H */
+1 -1
tools/perf/arch/x86/util/pmu.c
··· 16 16 #include "../../../util/fncache.h" 17 17 #include "../../../util/pmus.h" 18 18 #include "mem-events.h" 19 - #include "env.h" 19 + #include "util/env.h" 20 20 21 21 void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused) 22 22 {
+23
tools/perf/util/env.c
··· 5 5 #include "util/header.h" 6 6 #include "linux/compiler.h" 7 7 #include <linux/ctype.h> 8 + #include <linux/string.h> 8 9 #include <linux/zalloc.h> 9 10 #include "cgroup.h" 10 11 #include <errno.h> ··· 639 638 *width = env->cpu_pmu_caps ? env->br_cntr_width : 640 639 env->pmu_caps->br_cntr_width; 641 640 } 641 + } 642 + 643 + bool perf_env__is_x86_amd_cpu(struct perf_env *env) 644 + { 645 + static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */ 646 + 647 + if (is_amd == 0) 648 + is_amd = env->cpuid && strstarts(env->cpuid, "AuthenticAMD") ? 1 : -1; 649 + 650 + return is_amd >= 1 ? true : false; 651 + } 652 + 653 + bool x86__is_amd_cpu(void) 654 + { 655 + struct perf_env env = { .total_mem = 0, }; 656 + bool is_amd; 657 + 658 + perf_env__cpuid(&env); 659 + is_amd = perf_env__is_x86_amd_cpu(&env); 660 + perf_env__exit(&env); 661 + 662 + return is_amd; 642 663 }
+4
tools/perf/util/env.h
··· 195 195 void perf_env__find_br_cntr_info(struct perf_env *env, 196 196 unsigned int *nr, 197 197 unsigned int *width); 198 + 199 + bool x86__is_amd_cpu(void); 200 + bool perf_env__is_x86_amd_cpu(struct perf_env *env); 201 + 198 202 #endif /* __PERF_ENV_H */