Message ID | 20210809112727.596876-2-leo.yan@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf: Support compat mode for AUX ring buffer | expand |
Em Mon, Aug 09, 2021 at 07:27:25PM +0800, Leo Yan escreveu: > It's useful to know that the kernel is running in 32-bit or 64-bit > mode. E.g. We can decide if perf tool is running in compat mode > based on the info. > > This patch adds an item "kernel_is_64_bit" into session's environment > structure perf_env, its value is initialized based on the architecture > string. Thanks, applied. - Arnaldo > Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com> > Signed-off-by: Leo Yan <leo.yan@linaro.org> > --- > tools/perf/util/env.c | 24 +++++++++++++++++++++++- > tools/perf/util/env.h | 3 +++ > 2 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c > index ab341050be46..8f7ff0035c41 100644 > --- a/tools/perf/util/env.c > +++ b/tools/perf/util/env.c > @@ -219,13 +219,35 @@ 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 > + env->kernel_is_64_bit = -1; > +} > + > +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)) > + env->kernel_is_64_bit = 1; > + else > + env->kernel_is_64_bit = 0; > +} > + > +int perf_env__kernel_is_64_bit(struct perf_env *env) > +{ > + if (env->kernel_is_64_bit == -1) > + perf_env__init_kernel_mode(env); > + > + return env->kernel_is_64_bit; > } > > 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..1f5175820a05 100644 > --- a/tools/perf/util/env.h > +++ b/tools/perf/util/env.h > @@ -61,6 +61,7 @@ struct perf_env { > unsigned long long total_mem; > unsigned int msr_pmu_type; > unsigned int max_branches; > + int kernel_is_64_bit; > > int nr_cmdline; > int nr_sibling_cores; > @@ -143,6 +144,8 @@ extern struct perf_env perf_env; > > void perf_env__exit(struct perf_env *env); > > +int perf_env__kernel_is_64_bit(struct perf_env *env); > + > int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); > > int perf_env__read_cpuid(struct perf_env *env); > -- > 2.25.1 >
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ab341050be46..8f7ff0035c41 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -219,13 +219,35 @@ 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 + env->kernel_is_64_bit = -1; +} + +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)) + env->kernel_is_64_bit = 1; + else + env->kernel_is_64_bit = 0; +} + +int perf_env__kernel_is_64_bit(struct perf_env *env) +{ + if (env->kernel_is_64_bit == -1) + perf_env__init_kernel_mode(env); + + return env->kernel_is_64_bit; } 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..1f5175820a05 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -61,6 +61,7 @@ struct perf_env { unsigned long long total_mem; unsigned int msr_pmu_type; unsigned int max_branches; + int kernel_is_64_bit; int nr_cmdline; int nr_sibling_cores; @@ -143,6 +144,8 @@ extern struct perf_env perf_env; void perf_env__exit(struct perf_env *env); +int perf_env__kernel_is_64_bit(struct perf_env *env); + int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); int perf_env__read_cpuid(struct perf_env *env);
It's useful to know that the kernel is running in 32-bit or 64-bit mode. E.g. We can decide if perf tool is running in compat mode based on the info. This patch adds an item "kernel_is_64_bit" into session's environment structure perf_env, its value is initialized based on the architecture string. Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Leo Yan <leo.yan@linaro.org> --- tools/perf/util/env.c | 24 +++++++++++++++++++++++- tools/perf/util/env.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-)