From patchwork Sun Jul 4 07:16:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52D58C07E95 for ; Sun, 4 Jul 2021 07:21:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0380361879 for ; Sun, 4 Jul 2021 07:21:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0380361879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yl/5IlVv4OBRdnvUAAnNU9AxD/kRhsVlAySzv42Kyks=; b=4YNJ/vjDuOhx/8 wKJYqK+yZnbDqCcncXgfufmlrf98etIZVkzxhbKOsPnSLuurqAI4w2/mA3oHps3K0nU2OwDDoQl4N qffYPsQWsnZUaRGaXMNoalcS5KffL99akLQPp5q+20mnBNjTz1RuHTW/h2tzjewN+A8BvBdyIZ5Dv ZbcG/KEaTgpktwke+R0Ut6ypj2/Nm5Z3dVdGXMxP8juXBo2cyy27AKsSVKzF7+tM1/ftQNWALzNXC DydBewQXb1MoYsBzSnKQuuCYhOzod/aV+puUodLKyPvyQdMPmXNrAG0PooDImrDntzz2xOjKxXXS6 O5xEe/uVe0bbAoBIr9Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwPk-005sCk-8O; Sun, 04 Jul 2021 07:19:40 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNi-005rSZ-MH for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:36 +0000 Received: by mail-pl1-x62b.google.com with SMTP id c15so8340443pls.13 for ; Sun, 04 Jul 2021 00:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=brLMJrOwQbG83P71X9VPeuY9tvE7zleojiqdMG48VEY=; b=dAw3luOtdje26JAgPM3asmsdnTkplFoo7KvC7H2I/C61UvF35Nzg2HweTqvr7niy3w ys2DktQwpbPTEFPl0Gr/LGVnnmdjqAiSgtMTBegUSKLAKijAFCJfajwQv+Cd5RGAzHmG 2ZW/bq9w3dRLhP013Ef9EVJCV6lTlgAqzoLTcD3ESWEF+uKS4NoXNviD/aH9X6UWQgP4 lKlBL6ss0GmwsSwpyv9rWMl+w6krPT1lD+UF+xJGHDeWJoTZ1dDm97Y8zYPIZ48dL6lL I1eIWQPqDSjVmyb1U+uhUS9Ut5csTpmxVqHZDKDqkYDlt9PLsEW4HsM6wfuSYs0J9fbw IQSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=brLMJrOwQbG83P71X9VPeuY9tvE7zleojiqdMG48VEY=; b=S53ZDlA2QjfN9M1/emK5BtaTZepoNMVl3Os95AL0ZdtV9udkzXI1R2/Cq7lWI2RZXH XwrQCXyhXR765MNgvRdHD+LQinJR4B/n38oouLo2cYirlP3bxee5TKnO3eZP02ARJybC KDXWxQ/hV9BexdNI3ecN9zaw3I49Fq4zEJ008OHaEWLG7EUfo7hub9qW9Eeat2ICByMp FDFe2tLGPmICAR++VdeyRS+P+t+zyzFTie06GBp5IZt/BpjI5OjhIAck6NWxKKNyxlW6 CHSKxEEHZkhJPcLzkS73nKy+BRK/U5RGSpkpMmurHeUSxUFRR9cspY5Wct6XeYNrTTae BgBw== X-Gm-Message-State: AOAM532vpz3y6ld0hgW4teMmAmri5EyIGFy1aCI6g1H321ZWaEmWTyxm 84kgTopM7tWybz9EnJdEpEfv0g== X-Google-Smtp-Source: ABdhPJzEIeBGPpbSgBBcebonFiiSAj58V7y8TRazuYUDjwzJmrKKnWu6NqjrWvwDYuhHUmwXg3kOVg== X-Received: by 2002:a17:902:9006:b029:107:394a:387 with SMTP id a6-20020a1709029006b0290107394a0387mr7069924plp.35.1625383053898; Sun, 04 Jul 2021 00:17:33 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id s43sm983678pfw.50.2021.07.04.00.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:33 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 09/10] perf env: Set kernel bit mode Date: Sun, 4 Jul 2021 15:16:43 +0800 Message-Id: <20210704071644.107397-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001734_784921_CB551037 X-CRM114-Status: GOOD ( 18.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 #include +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);