From patchwork Tue Jun 6 01:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13268146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2DA51C7EE24 for ; Tue, 6 Jun 2023 01:47:02 +0000 (UTC) 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: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:In-Reply-To:References: List-Owner; bh=zFoFZC8yj7aXtI61JASa/u1JnuRAAwR9TQx+wb/l0uc=; b=SDySdm00BlRzzg h+su808XddGWV5fQzsS37JaOsJj0b0jVlD3MYpN15oAsovj9oUz3OpACgs02e/kMS/wZQaFgbDJQa 6X24Ou3UI3caJnGamWRfiqcaIH0KwVnH8x1AJoF/JF6wVerjm2tZaXq6T+D60QtIat4D0GwXsy+b7 oX3X03vUm857bETDyn6n5XwMa5TLCTjsoo2vvoQsE/KsjU9TR1XSvLrcGFBN+CZ7N9mwA+NsdcwtO NjddZbOoc8FxL6g6rufHNLxHYJ7FFg+IjsnwZJSyHq3SSuPkjuWO2vjFCne/NcuW0VmgZvz9IoJHF Qa+KzWLeHxqjYTgmHKdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6LmJ-00HMPo-0x; Tue, 06 Jun 2023 01:46:31 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6LmF-00HMOK-1m for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2023 01:46:29 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so4941241a12.1 for ; Mon, 05 Jun 2023 18:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686015985; x=1688607985; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PndMKVa+Er1qdCOJiafxXClL6d1Yt+58ItU6tFuigm0=; b=Hh64hU1z+qXcJKy0p3CJpPMRxoO4gff0IpJVXMTII+Hqst8/7/Hj+tN4ff3SNGPMWJ nT3Lh6BuKSHhe7CAAlH4XFMJDJh9sHp4seEA7HPgApSFVVhplkAIpg9u7Zp8pnk4ci0V Vj4ffA3Twz2FgLgoRmz7kAF51Bul23/4EA9/UUCGv5LVkFEDOsCUbB25+CjBWwaFgA+S or+82PZ2XQjX8gz+XrtRnYLHeju1Se8ZCbwd8tpa3RBQefL78+IqoMl6GuKicT5H75cd ima2n6KE3iSqdyxMeI4Fjigz/vF9bIyocKGQTGr+tOh3YpggnUaj5TT2xaTdx8nEBuLv AZLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686015985; x=1688607985; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PndMKVa+Er1qdCOJiafxXClL6d1Yt+58ItU6tFuigm0=; b=MjeXyIIWuE7F4E9+LDCIRB6iS3ea3i8nhPBqjauFCNMHgchbsBoblMWmCujfST5+YA Eug+OZA3EzVDxMET7SMdRtpY5UGIBDDvxSdCfHYF2K6ibMU0cSuHyH+p0SEbVrjr585J ktZzLwNiQZtKF5e0gYs01KGEw26kg/xRXTzvngoSWfB/TMXZBCCNwUx0mqKyfyNSgv7C GCvV/rkrYk9la5Sdju7CSbG5qFGgQMCcqUY54DTQuyp7jlU6Tcx+DL9j5oQaYmzYcqiD WegidC+884u+cV3cfvokfNKmGr+veeHbHL/Vpbd3vCC/inM2v7s48F12RCnFtfZS3M4O IYjg== X-Gm-Message-State: AC+VfDxCe5KVtRhONIUuRktYKgoK4wjc7evyiZgj0j/aJvyiBzl87fIK BFqiShVVtbcxazZ/i/accVUByg== X-Google-Smtp-Source: ACHHUZ4wpMb9zmn0oxmXwR0j3PDi+Kimi9DJ1y8WGup9FRsXEKDHRsM3AuBwTtE0VRxEQZaVWZmQIQ== X-Received: by 2002:a17:903:1111:b0:1af:c1a7:3bb5 with SMTP id n17-20020a170903111100b001afc1a73bb5mr925280plh.4.1686015984705; Mon, 05 Jun 2023 18:46:24 -0700 (PDT) Received: from leoy-huanghe.lan ([240e:389:8603:ad00:6600:a29f:6ab:1788]) by smtp.gmail.com with ESMTPSA id s10-20020a170902a50a00b001a64851087bsm7197805plq.272.2023.06.05.18.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 18:46:24 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , James Clark , Mike Leach , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Ming Wang , Eric Lin , Kan Liang , Sandipan Das , Ivan Babrou , Fangrui Song , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Leo Yan Subject: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions Date: Tue, 6 Jun 2023 09:45:53 +0800 Message-Id: <20230606014559.21783-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230605_184627_819942_0518A3E0 X-CRM114-Status: GOOD ( 18.47 ) 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 This patch series is to refactor arch related functions for register parsing, which follows up the discussion for v1: https://lore.kernel.org/lkml/20230520025537.1811986-1-leo.yan@linaro.org/ Compared to patch series v1, this patch series introduces new functions perf_arch_reg_{ip|sp}(), so this can allow the tool to support cross analysis. To verify the cross analysis, I used below steps: - Firstly, I captured perf data on Arm64 machine: $ perf record --call-graph fp -- ./test_program Or ... $ perf record --call-graph dwarf -- ./test_program Then, I also archived associated debug data: $ perf archive - Secondly, I copied the perf data file and debug tar file on my x86 machine: $ scp perf.data perf.data.tar.bz2 leoy@IP_ADDRESS:/target/path/ - On x86 machine, I need to build perf for support multi-arch unwinding: $ git clone http://git.savannah.gnu.org/r/libunwind.git $ cd libunwind $ autoreconf -i # Build and install libunwind aarch64: $ ./configure prefix=/home/leoy/Work/tools/libunwind/install/ \ --target=aarch64-linux-gnu CC=x86_64-linux-gnu-gcc $ make && make install # Build and install libunwind x86: $ ./configure prefix=/home/leoy/Work/tools/libunwind/install/ \ --target=x86_64-linux-gnu CC=x86_64-linux-gnu-gcc $ make && make install - Build perf tool for support multi-archs: $ cd $LINUX/tools/perf $ make VF=1 DEBUG=1 LIBUNWIND_DIR=/home/leoy/Work/tools/libunwind/install At the end, I verified the x86 perf tool can do cross analysis for aarch64's perf data file. Note, I still see x86 perf tool cannot display the complete callgraph for aarch64, but it should not the issue caused by this series, which will be addressed by separate patches. I also built this patch series on my Arm64 and x86 machines, both can compile perf tool successfully; but I have no chance to build other archs natively. Changes from v1: - For support cross analysis for IP/SP registers, introduced patch 0002 (James Clark, Ian Rogers). Leo Yan (6): perf parse-regs: Refactor arch register parsing functions perf parse-regs: Introduce functions perf_arch_reg_{ip|sp}() perf unwind: Use perf_arch_reg_{ip|sp}() to substitute macros perf parse-regs: Remove unused macros PERF_REG_{IP|SP} perf parse-regs: Remove PERF_REGS_{MAX|MASK} from common code perf parse-regs: Move out arch specific header from util/perf_regs.h tools/perf/arch/arm/include/perf_regs.h | 3 - tools/perf/arch/arm/util/perf_regs.c | 11 + tools/perf/arch/arm/util/unwind-libdw.c | 1 + tools/perf/arch/arm64/include/perf_regs.h | 3 - tools/perf/arch/arm64/util/machine.c | 1 + tools/perf/arch/arm64/util/perf_regs.c | 6 + tools/perf/arch/arm64/util/unwind-libdw.c | 1 + tools/perf/arch/csky/include/perf_regs.h | 3 - tools/perf/arch/csky/util/perf_regs.c | 11 + tools/perf/arch/csky/util/unwind-libdw.c | 1 + tools/perf/arch/loongarch/include/perf_regs.h | 2 - tools/perf/arch/loongarch/util/perf_regs.c | 11 + tools/perf/arch/loongarch/util/unwind-libdw.c | 1 + tools/perf/arch/mips/include/perf_regs.h | 2 - tools/perf/arch/mips/util/perf_regs.c | 11 + tools/perf/arch/powerpc/include/perf_regs.h | 3 - tools/perf/arch/powerpc/util/perf_regs.c | 6 + tools/perf/arch/powerpc/util/unwind-libdw.c | 1 + tools/perf/arch/riscv/include/perf_regs.h | 3 - tools/perf/arch/riscv/util/perf_regs.c | 11 + tools/perf/arch/riscv/util/unwind-libdw.c | 1 + tools/perf/arch/s390/include/perf_regs.h | 3 - tools/perf/arch/s390/util/perf_regs.c | 11 + tools/perf/arch/s390/util/unwind-libdw.c | 1 + tools/perf/arch/x86/include/perf_regs.h | 2 - tools/perf/arch/x86/util/perf_regs.c | 6 + tools/perf/arch/x86/util/unwind-libdw.c | 1 + tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 6 +- tools/perf/util/libunwind/arm64.c | 2 - tools/perf/util/libunwind/x86_32.c | 2 - tools/perf/util/perf-regs-arch/Build | 9 + .../util/perf-regs-arch/perf_regs_aarch64.c | 96 +++ .../perf/util/perf-regs-arch/perf_regs_arm.c | 60 ++ .../perf/util/perf-regs-arch/perf_regs_csky.c | 100 +++ .../util/perf-regs-arch/perf_regs_loongarch.c | 91 +++ .../perf/util/perf-regs-arch/perf_regs_mips.c | 87 ++ .../util/perf-regs-arch/perf_regs_powerpc.c | 145 ++++ .../util/perf-regs-arch/perf_regs_riscv.c | 92 +++ .../perf/util/perf-regs-arch/perf_regs_s390.c | 96 +++ .../perf/util/perf-regs-arch/perf_regs_x86.c | 98 +++ tools/perf/util/perf_regs.c | 772 ++---------------- tools/perf/util/perf_regs.h | 49 +- tools/perf/util/unwind-libdw.c | 7 +- tools/perf/util/unwind-libunwind-local.c | 6 +- tools/perf/util/unwind.h | 8 - 46 files changed, 1078 insertions(+), 766 deletions(-) create mode 100644 tools/perf/util/perf-regs-arch/Build create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_aarch64.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_arm.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_csky.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_loongarch.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_mips.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_powerpc.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_riscv.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_s390.c create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_x86.c Acked-by: Ian Rogers