It's useful to know that the kernel is running in 32-bit or 64-bit mode. E.g. We can decide perf tool is running in compat mode when detects kernel is running in 64-bit mode and the tool is in 32-bit mode with the compiler macro BITS_PER_LONG is 32.
This patch adds a global variable "kernel_is_64_bit", during the environment initialization for the session, the kernel running mode is decided by checking the architecture string.
Signed-off-by: Leo Yan leo.yan@linaro.org --- tools/perf/util/env.c | 17 ++++++++++++++++- tools/perf/util/env.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ebc5e9ad35db..345635a2e842 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -11,6 +11,7 @@ #include <stdlib.h> #include <string.h>
+int kernel_is_64_bit; struct perf_env perf_env;
#ifdef HAVE_LIBBPF_SUPPORT @@ -172,6 +173,19 @@ static void perf_env__purge_bpf(struct perf_env *env __maybe_unused) } #endif // HAVE_LIBBPF_SUPPORT
+static void perf_env__init_kernel_mode(struct perf_env *env) +{ + const char *arch = perf_env__raw_arch(env); + + 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)) + kernel_is_64_bit = 1; + else + kernel_is_64_bit = 0; +} + void perf_env__exit(struct perf_env *env) { int i; @@ -217,13 +231,14 @@ void perf_env__exit(struct perf_env *env) zfree(&env->hybrid_cpc_nodes); }
-void perf_env__init(struct perf_env *env __maybe_unused) +void perf_env__init(struct perf_env *env) { #ifdef HAVE_LIBBPF_SUPPORT env->bpf_progs.infos = RB_ROOT; env->bpf_progs.btfs = RB_ROOT; init_rwsem(&env->bpf_progs.lock); #endif + perf_env__init_kernel_mode(env); }
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 6824a7423a2d..cc989ff49740 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -139,6 +139,7 @@ enum perf_compress_type { struct bpf_prog_info_node; struct btf_node;
+extern int kernel_is_64_bit; extern struct perf_env perf_env;
void perf_env__exit(struct perf_env *env);