lkml.org 
[lkml]   [2021]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v4 10/11] perf env: Set flag for kernel is 64-bit mode
    Date
    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
    from this info.

    This patch adds a global variable "kernel_is_64_bit", it's initialized
    when a session setups environment, its value 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);
    --
    2.25.1
    \
     
     \ /
      Last update: 2021-07-11 12:42    [W:3.370 / U:0.068 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site