2023-06-06 02:02:18

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

This patch series is to refactor arch related functions for register
parsing, which follows up the discussion for v1:
https://lore.kernel.org/lkml/[email protected]/

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

--
2.34.1



2023-06-06 02:02:35

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 1/6] perf parse-regs: Refactor arch register parsing functions

Every architecture has a specific register parsing function for
returning register name based on register index, to support cross
analysis (e.g. we use perf x86 binary to parse Arm64's perf data), we
build all these register parsing functions into the tool, this is why
we place all related functions into util/perf_regs.c.

Unfortunately, since util/perf_regs.c needs to include every arch's
perf_regs.h, this easily introduces duplicated definitions coming from
multiple headers, finally it's fragile for building and difficult for
maintenance.

We cannot simply move these register parsing functions into the
corresponding 'arch' folder, the folder is only conditionally built
based on the target architecture.

Therefore, this commit creates a new folder util/perf-regs-arch/ and
uses a dedicated source file to keep every architecture's register
parsing function to avoid definition conflicts.

This is only a refactoring, no functionality change is expected.

Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/util/Build | 1 +
tools/perf/util/perf-regs-arch/Build | 9 +
.../util/perf-regs-arch/perf_regs_aarch64.c | 86 +++
.../perf/util/perf-regs-arch/perf_regs_arm.c | 50 ++
.../perf/util/perf-regs-arch/perf_regs_csky.c | 90 +++
.../util/perf-regs-arch/perf_regs_loongarch.c | 81 ++
.../perf/util/perf-regs-arch/perf_regs_mips.c | 77 ++
.../util/perf-regs-arch/perf_regs_powerpc.c | 135 ++++
.../util/perf-regs-arch/perf_regs_riscv.c | 82 ++
.../perf/util/perf-regs-arch/perf_regs_s390.c | 86 +++
.../perf/util/perf-regs-arch/perf_regs_x86.c | 88 +++
tools/perf/util/perf_regs.c | 716 ------------------
tools/perf/util/perf_regs.h | 9 +
13 files changed, 794 insertions(+), 716 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

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 0d68be51a739..4e385f7a1196 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -26,6 +26,7 @@ perf-y += parse-events.o
perf-y += print-events.o
perf-y += tracepoint.o
perf-y += perf_regs.o
+perf-y += perf-regs-arch/
perf-y += path.o
perf-y += print_binary.o
perf-y += rlimit.o
diff --git a/tools/perf/util/perf-regs-arch/Build b/tools/perf/util/perf-regs-arch/Build
new file mode 100644
index 000000000000..d9d596d330a7
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/Build
@@ -0,0 +1,9 @@
+perf-y += perf_regs_aarch64.o
+perf-y += perf_regs_arm.o
+perf-y += perf_regs_csky.o
+perf-y += perf_regs_loongarch.o
+perf-y += perf_regs_mips.o
+perf-y += perf_regs_powerpc.o
+perf-y += perf_regs_riscv.o
+perf-y += perf_regs_s390.o
+perf-y += perf_regs_x86.o
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_aarch64.c b/tools/perf/util/perf-regs-arch/perf_regs_aarch64.c
new file mode 100644
index 000000000000..c02c045af46e
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_aarch64.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/arm64/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_arm64(int id)
+{
+ switch (id) {
+ case PERF_REG_ARM64_X0:
+ return "x0";
+ case PERF_REG_ARM64_X1:
+ return "x1";
+ case PERF_REG_ARM64_X2:
+ return "x2";
+ case PERF_REG_ARM64_X3:
+ return "x3";
+ case PERF_REG_ARM64_X4:
+ return "x4";
+ case PERF_REG_ARM64_X5:
+ return "x5";
+ case PERF_REG_ARM64_X6:
+ return "x6";
+ case PERF_REG_ARM64_X7:
+ return "x7";
+ case PERF_REG_ARM64_X8:
+ return "x8";
+ case PERF_REG_ARM64_X9:
+ return "x9";
+ case PERF_REG_ARM64_X10:
+ return "x10";
+ case PERF_REG_ARM64_X11:
+ return "x11";
+ case PERF_REG_ARM64_X12:
+ return "x12";
+ case PERF_REG_ARM64_X13:
+ return "x13";
+ case PERF_REG_ARM64_X14:
+ return "x14";
+ case PERF_REG_ARM64_X15:
+ return "x15";
+ case PERF_REG_ARM64_X16:
+ return "x16";
+ case PERF_REG_ARM64_X17:
+ return "x17";
+ case PERF_REG_ARM64_X18:
+ return "x18";
+ case PERF_REG_ARM64_X19:
+ return "x19";
+ case PERF_REG_ARM64_X20:
+ return "x20";
+ case PERF_REG_ARM64_X21:
+ return "x21";
+ case PERF_REG_ARM64_X22:
+ return "x22";
+ case PERF_REG_ARM64_X23:
+ return "x23";
+ case PERF_REG_ARM64_X24:
+ return "x24";
+ case PERF_REG_ARM64_X25:
+ return "x25";
+ case PERF_REG_ARM64_X26:
+ return "x26";
+ case PERF_REG_ARM64_X27:
+ return "x27";
+ case PERF_REG_ARM64_X28:
+ return "x28";
+ case PERF_REG_ARM64_X29:
+ return "x29";
+ case PERF_REG_ARM64_SP:
+ return "sp";
+ case PERF_REG_ARM64_LR:
+ return "lr";
+ case PERF_REG_ARM64_PC:
+ return "pc";
+ case PERF_REG_ARM64_VG:
+ return "vg";
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_arm.c b/tools/perf/util/perf-regs-arch/perf_regs_arm.c
new file mode 100644
index 000000000000..e8b0fcd72f34
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_arm.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/arm/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_arm(int id)
+{
+ switch (id) {
+ case PERF_REG_ARM_R0:
+ return "r0";
+ case PERF_REG_ARM_R1:
+ return "r1";
+ case PERF_REG_ARM_R2:
+ return "r2";
+ case PERF_REG_ARM_R3:
+ return "r3";
+ case PERF_REG_ARM_R4:
+ return "r4";
+ case PERF_REG_ARM_R5:
+ return "r5";
+ case PERF_REG_ARM_R6:
+ return "r6";
+ case PERF_REG_ARM_R7:
+ return "r7";
+ case PERF_REG_ARM_R8:
+ return "r8";
+ case PERF_REG_ARM_R9:
+ return "r9";
+ case PERF_REG_ARM_R10:
+ return "r10";
+ case PERF_REG_ARM_FP:
+ return "fp";
+ case PERF_REG_ARM_IP:
+ return "ip";
+ case PERF_REG_ARM_SP:
+ return "sp";
+ case PERF_REG_ARM_LR:
+ return "lr";
+ case PERF_REG_ARM_PC:
+ return "pc";
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_csky.c b/tools/perf/util/perf-regs-arch/perf_regs_csky.c
new file mode 100644
index 000000000000..e343b1cef7ba
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_csky.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../arch/csky/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_csky(int id)
+{
+ switch (id) {
+ case PERF_REG_CSKY_A0:
+ return "a0";
+ case PERF_REG_CSKY_A1:
+ return "a1";
+ case PERF_REG_CSKY_A2:
+ return "a2";
+ case PERF_REG_CSKY_A3:
+ return "a3";
+ case PERF_REG_CSKY_REGS0:
+ return "regs0";
+ case PERF_REG_CSKY_REGS1:
+ return "regs1";
+ case PERF_REG_CSKY_REGS2:
+ return "regs2";
+ case PERF_REG_CSKY_REGS3:
+ return "regs3";
+ case PERF_REG_CSKY_REGS4:
+ return "regs4";
+ case PERF_REG_CSKY_REGS5:
+ return "regs5";
+ case PERF_REG_CSKY_REGS6:
+ return "regs6";
+ case PERF_REG_CSKY_REGS7:
+ return "regs7";
+ case PERF_REG_CSKY_REGS8:
+ return "regs8";
+ case PERF_REG_CSKY_REGS9:
+ return "regs9";
+ case PERF_REG_CSKY_SP:
+ return "sp";
+ case PERF_REG_CSKY_LR:
+ return "lr";
+ case PERF_REG_CSKY_PC:
+ return "pc";
+#if defined(__CSKYABIV2__)
+ case PERF_REG_CSKY_EXREGS0:
+ return "exregs0";
+ case PERF_REG_CSKY_EXREGS1:
+ return "exregs1";
+ case PERF_REG_CSKY_EXREGS2:
+ return "exregs2";
+ case PERF_REG_CSKY_EXREGS3:
+ return "exregs3";
+ case PERF_REG_CSKY_EXREGS4:
+ return "exregs4";
+ case PERF_REG_CSKY_EXREGS5:
+ return "exregs5";
+ case PERF_REG_CSKY_EXREGS6:
+ return "exregs6";
+ case PERF_REG_CSKY_EXREGS7:
+ return "exregs7";
+ case PERF_REG_CSKY_EXREGS8:
+ return "exregs8";
+ case PERF_REG_CSKY_EXREGS9:
+ return "exregs9";
+ case PERF_REG_CSKY_EXREGS10:
+ return "exregs10";
+ case PERF_REG_CSKY_EXREGS11:
+ return "exregs11";
+ case PERF_REG_CSKY_EXREGS12:
+ return "exregs12";
+ case PERF_REG_CSKY_EXREGS13:
+ return "exregs13";
+ case PERF_REG_CSKY_EXREGS14:
+ return "exregs14";
+ case PERF_REG_CSKY_TLS:
+ return "tls";
+ case PERF_REG_CSKY_HI:
+ return "hi";
+ case PERF_REG_CSKY_LO:
+ return "lo";
+#endif
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_loongarch.c b/tools/perf/util/perf-regs-arch/perf_regs_loongarch.c
new file mode 100644
index 000000000000..6f937464067b
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_loongarch.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/loongarch/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_loongarch(int id)
+{
+ switch (id) {
+ case PERF_REG_LOONGARCH_PC:
+ return "PC";
+ case PERF_REG_LOONGARCH_R1:
+ return "%r1";
+ case PERF_REG_LOONGARCH_R2:
+ return "%r2";
+ case PERF_REG_LOONGARCH_R3:
+ return "%r3";
+ case PERF_REG_LOONGARCH_R4:
+ return "%r4";
+ case PERF_REG_LOONGARCH_R5:
+ return "%r5";
+ case PERF_REG_LOONGARCH_R6:
+ return "%r6";
+ case PERF_REG_LOONGARCH_R7:
+ return "%r7";
+ case PERF_REG_LOONGARCH_R8:
+ return "%r8";
+ case PERF_REG_LOONGARCH_R9:
+ return "%r9";
+ case PERF_REG_LOONGARCH_R10:
+ return "%r10";
+ case PERF_REG_LOONGARCH_R11:
+ return "%r11";
+ case PERF_REG_LOONGARCH_R12:
+ return "%r12";
+ case PERF_REG_LOONGARCH_R13:
+ return "%r13";
+ case PERF_REG_LOONGARCH_R14:
+ return "%r14";
+ case PERF_REG_LOONGARCH_R15:
+ return "%r15";
+ case PERF_REG_LOONGARCH_R16:
+ return "%r16";
+ case PERF_REG_LOONGARCH_R17:
+ return "%r17";
+ case PERF_REG_LOONGARCH_R18:
+ return "%r18";
+ case PERF_REG_LOONGARCH_R19:
+ return "%r19";
+ case PERF_REG_LOONGARCH_R20:
+ return "%r20";
+ case PERF_REG_LOONGARCH_R21:
+ return "%r21";
+ case PERF_REG_LOONGARCH_R22:
+ return "%r22";
+ case PERF_REG_LOONGARCH_R23:
+ return "%r23";
+ case PERF_REG_LOONGARCH_R24:
+ return "%r24";
+ case PERF_REG_LOONGARCH_R25:
+ return "%r25";
+ case PERF_REG_LOONGARCH_R26:
+ return "%r26";
+ case PERF_REG_LOONGARCH_R27:
+ return "%r27";
+ case PERF_REG_LOONGARCH_R28:
+ return "%r28";
+ case PERF_REG_LOONGARCH_R29:
+ return "%r29";
+ case PERF_REG_LOONGARCH_R30:
+ return "%r30";
+ case PERF_REG_LOONGARCH_R31:
+ return "%r31";
+ default:
+ break;
+ }
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_mips.c b/tools/perf/util/perf-regs-arch/perf_regs_mips.c
new file mode 100644
index 000000000000..f48fbca2f947
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_mips.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/mips/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_mips(int id)
+{
+ switch (id) {
+ case PERF_REG_MIPS_PC:
+ return "PC";
+ case PERF_REG_MIPS_R1:
+ return "$1";
+ case PERF_REG_MIPS_R2:
+ return "$2";
+ case PERF_REG_MIPS_R3:
+ return "$3";
+ case PERF_REG_MIPS_R4:
+ return "$4";
+ case PERF_REG_MIPS_R5:
+ return "$5";
+ case PERF_REG_MIPS_R6:
+ return "$6";
+ case PERF_REG_MIPS_R7:
+ return "$7";
+ case PERF_REG_MIPS_R8:
+ return "$8";
+ case PERF_REG_MIPS_R9:
+ return "$9";
+ case PERF_REG_MIPS_R10:
+ return "$10";
+ case PERF_REG_MIPS_R11:
+ return "$11";
+ case PERF_REG_MIPS_R12:
+ return "$12";
+ case PERF_REG_MIPS_R13:
+ return "$13";
+ case PERF_REG_MIPS_R14:
+ return "$14";
+ case PERF_REG_MIPS_R15:
+ return "$15";
+ case PERF_REG_MIPS_R16:
+ return "$16";
+ case PERF_REG_MIPS_R17:
+ return "$17";
+ case PERF_REG_MIPS_R18:
+ return "$18";
+ case PERF_REG_MIPS_R19:
+ return "$19";
+ case PERF_REG_MIPS_R20:
+ return "$20";
+ case PERF_REG_MIPS_R21:
+ return "$21";
+ case PERF_REG_MIPS_R22:
+ return "$22";
+ case PERF_REG_MIPS_R23:
+ return "$23";
+ case PERF_REG_MIPS_R24:
+ return "$24";
+ case PERF_REG_MIPS_R25:
+ return "$25";
+ case PERF_REG_MIPS_R28:
+ return "$28";
+ case PERF_REG_MIPS_R29:
+ return "$29";
+ case PERF_REG_MIPS_R30:
+ return "$30";
+ case PERF_REG_MIPS_R31:
+ return "$31";
+ default:
+ break;
+ }
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_powerpc.c b/tools/perf/util/perf-regs-arch/perf_regs_powerpc.c
new file mode 100644
index 000000000000..dda1b4b169fc
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_powerpc.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_powerpc(int id)
+{
+ switch (id) {
+ case PERF_REG_POWERPC_R0:
+ return "r0";
+ case PERF_REG_POWERPC_R1:
+ return "r1";
+ case PERF_REG_POWERPC_R2:
+ return "r2";
+ case PERF_REG_POWERPC_R3:
+ return "r3";
+ case PERF_REG_POWERPC_R4:
+ return "r4";
+ case PERF_REG_POWERPC_R5:
+ return "r5";
+ case PERF_REG_POWERPC_R6:
+ return "r6";
+ case PERF_REG_POWERPC_R7:
+ return "r7";
+ case PERF_REG_POWERPC_R8:
+ return "r8";
+ case PERF_REG_POWERPC_R9:
+ return "r9";
+ case PERF_REG_POWERPC_R10:
+ return "r10";
+ case PERF_REG_POWERPC_R11:
+ return "r11";
+ case PERF_REG_POWERPC_R12:
+ return "r12";
+ case PERF_REG_POWERPC_R13:
+ return "r13";
+ case PERF_REG_POWERPC_R14:
+ return "r14";
+ case PERF_REG_POWERPC_R15:
+ return "r15";
+ case PERF_REG_POWERPC_R16:
+ return "r16";
+ case PERF_REG_POWERPC_R17:
+ return "r17";
+ case PERF_REG_POWERPC_R18:
+ return "r18";
+ case PERF_REG_POWERPC_R19:
+ return "r19";
+ case PERF_REG_POWERPC_R20:
+ return "r20";
+ case PERF_REG_POWERPC_R21:
+ return "r21";
+ case PERF_REG_POWERPC_R22:
+ return "r22";
+ case PERF_REG_POWERPC_R23:
+ return "r23";
+ case PERF_REG_POWERPC_R24:
+ return "r24";
+ case PERF_REG_POWERPC_R25:
+ return "r25";
+ case PERF_REG_POWERPC_R26:
+ return "r26";
+ case PERF_REG_POWERPC_R27:
+ return "r27";
+ case PERF_REG_POWERPC_R28:
+ return "r28";
+ case PERF_REG_POWERPC_R29:
+ return "r29";
+ case PERF_REG_POWERPC_R30:
+ return "r30";
+ case PERF_REG_POWERPC_R31:
+ return "r31";
+ case PERF_REG_POWERPC_NIP:
+ return "nip";
+ case PERF_REG_POWERPC_MSR:
+ return "msr";
+ case PERF_REG_POWERPC_ORIG_R3:
+ return "orig_r3";
+ case PERF_REG_POWERPC_CTR:
+ return "ctr";
+ case PERF_REG_POWERPC_LINK:
+ return "link";
+ case PERF_REG_POWERPC_XER:
+ return "xer";
+ case PERF_REG_POWERPC_CCR:
+ return "ccr";
+ case PERF_REG_POWERPC_SOFTE:
+ return "softe";
+ case PERF_REG_POWERPC_TRAP:
+ return "trap";
+ case PERF_REG_POWERPC_DAR:
+ return "dar";
+ case PERF_REG_POWERPC_DSISR:
+ return "dsisr";
+ case PERF_REG_POWERPC_SIER:
+ return "sier";
+ case PERF_REG_POWERPC_MMCRA:
+ return "mmcra";
+ case PERF_REG_POWERPC_MMCR0:
+ return "mmcr0";
+ case PERF_REG_POWERPC_MMCR1:
+ return "mmcr1";
+ case PERF_REG_POWERPC_MMCR2:
+ return "mmcr2";
+ case PERF_REG_POWERPC_MMCR3:
+ return "mmcr3";
+ case PERF_REG_POWERPC_SIER2:
+ return "sier2";
+ case PERF_REG_POWERPC_SIER3:
+ return "sier3";
+ case PERF_REG_POWERPC_PMC1:
+ return "pmc1";
+ case PERF_REG_POWERPC_PMC2:
+ return "pmc2";
+ case PERF_REG_POWERPC_PMC3:
+ return "pmc3";
+ case PERF_REG_POWERPC_PMC4:
+ return "pmc4";
+ case PERF_REG_POWERPC_PMC5:
+ return "pmc5";
+ case PERF_REG_POWERPC_PMC6:
+ return "pmc6";
+ case PERF_REG_POWERPC_SDAR:
+ return "sdar";
+ case PERF_REG_POWERPC_SIAR:
+ return "siar";
+ default:
+ break;
+ }
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_riscv.c b/tools/perf/util/perf-regs-arch/perf_regs_riscv.c
new file mode 100644
index 000000000000..c504b047cac2
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_riscv.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/riscv/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_riscv(int id)
+{
+ switch (id) {
+ case PERF_REG_RISCV_PC:
+ return "pc";
+ case PERF_REG_RISCV_RA:
+ return "ra";
+ case PERF_REG_RISCV_SP:
+ return "sp";
+ case PERF_REG_RISCV_GP:
+ return "gp";
+ case PERF_REG_RISCV_TP:
+ return "tp";
+ case PERF_REG_RISCV_T0:
+ return "t0";
+ case PERF_REG_RISCV_T1:
+ return "t1";
+ case PERF_REG_RISCV_T2:
+ return "t2";
+ case PERF_REG_RISCV_S0:
+ return "s0";
+ case PERF_REG_RISCV_S1:
+ return "s1";
+ case PERF_REG_RISCV_A0:
+ return "a0";
+ case PERF_REG_RISCV_A1:
+ return "a1";
+ case PERF_REG_RISCV_A2:
+ return "a2";
+ case PERF_REG_RISCV_A3:
+ return "a3";
+ case PERF_REG_RISCV_A4:
+ return "a4";
+ case PERF_REG_RISCV_A5:
+ return "a5";
+ case PERF_REG_RISCV_A6:
+ return "a6";
+ case PERF_REG_RISCV_A7:
+ return "a7";
+ case PERF_REG_RISCV_S2:
+ return "s2";
+ case PERF_REG_RISCV_S3:
+ return "s3";
+ case PERF_REG_RISCV_S4:
+ return "s4";
+ case PERF_REG_RISCV_S5:
+ return "s5";
+ case PERF_REG_RISCV_S6:
+ return "s6";
+ case PERF_REG_RISCV_S7:
+ return "s7";
+ case PERF_REG_RISCV_S8:
+ return "s8";
+ case PERF_REG_RISCV_S9:
+ return "s9";
+ case PERF_REG_RISCV_S10:
+ return "s10";
+ case PERF_REG_RISCV_S11:
+ return "s11";
+ case PERF_REG_RISCV_T3:
+ return "t3";
+ case PERF_REG_RISCV_T4:
+ return "t4";
+ case PERF_REG_RISCV_T5:
+ return "t5";
+ case PERF_REG_RISCV_T6:
+ return "t6";
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_s390.c b/tools/perf/util/perf-regs-arch/perf_regs_s390.c
new file mode 100644
index 000000000000..e71e2302394c
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_s390.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/s390/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_s390(int id)
+{
+ switch (id) {
+ case PERF_REG_S390_R0:
+ return "R0";
+ case PERF_REG_S390_R1:
+ return "R1";
+ case PERF_REG_S390_R2:
+ return "R2";
+ case PERF_REG_S390_R3:
+ return "R3";
+ case PERF_REG_S390_R4:
+ return "R4";
+ case PERF_REG_S390_R5:
+ return "R5";
+ case PERF_REG_S390_R6:
+ return "R6";
+ case PERF_REG_S390_R7:
+ return "R7";
+ case PERF_REG_S390_R8:
+ return "R8";
+ case PERF_REG_S390_R9:
+ return "R9";
+ case PERF_REG_S390_R10:
+ return "R10";
+ case PERF_REG_S390_R11:
+ return "R11";
+ case PERF_REG_S390_R12:
+ return "R12";
+ case PERF_REG_S390_R13:
+ return "R13";
+ case PERF_REG_S390_R14:
+ return "R14";
+ case PERF_REG_S390_R15:
+ return "R15";
+ case PERF_REG_S390_FP0:
+ return "FP0";
+ case PERF_REG_S390_FP1:
+ return "FP1";
+ case PERF_REG_S390_FP2:
+ return "FP2";
+ case PERF_REG_S390_FP3:
+ return "FP3";
+ case PERF_REG_S390_FP4:
+ return "FP4";
+ case PERF_REG_S390_FP5:
+ return "FP5";
+ case PERF_REG_S390_FP6:
+ return "FP6";
+ case PERF_REG_S390_FP7:
+ return "FP7";
+ case PERF_REG_S390_FP8:
+ return "FP8";
+ case PERF_REG_S390_FP9:
+ return "FP9";
+ case PERF_REG_S390_FP10:
+ return "FP10";
+ case PERF_REG_S390_FP11:
+ return "FP11";
+ case PERF_REG_S390_FP12:
+ return "FP12";
+ case PERF_REG_S390_FP13:
+ return "FP13";
+ case PERF_REG_S390_FP14:
+ return "FP14";
+ case PERF_REG_S390_FP15:
+ return "FP15";
+ case PERF_REG_S390_MASK:
+ return "MASK";
+ case PERF_REG_S390_PC:
+ return "PC";
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf-regs-arch/perf_regs_x86.c b/tools/perf/util/perf-regs-arch/perf_regs_x86.c
new file mode 100644
index 000000000000..eb5d249afa70
--- /dev/null
+++ b/tools/perf/util/perf-regs-arch/perf_regs_x86.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifdef HAVE_PERF_REGS_SUPPORT
+
+#include "../perf_regs.h"
+#include "../../../arch/x86/include/uapi/asm/perf_regs.h"
+
+const char *__perf_reg_name_x86(int id)
+{
+ switch (id) {
+ case PERF_REG_X86_AX:
+ return "AX";
+ case PERF_REG_X86_BX:
+ return "BX";
+ case PERF_REG_X86_CX:
+ return "CX";
+ case PERF_REG_X86_DX:
+ return "DX";
+ case PERF_REG_X86_SI:
+ return "SI";
+ case PERF_REG_X86_DI:
+ return "DI";
+ case PERF_REG_X86_BP:
+ return "BP";
+ case PERF_REG_X86_SP:
+ return "SP";
+ case PERF_REG_X86_IP:
+ return "IP";
+ case PERF_REG_X86_FLAGS:
+ return "FLAGS";
+ case PERF_REG_X86_CS:
+ return "CS";
+ case PERF_REG_X86_SS:
+ return "SS";
+ case PERF_REG_X86_DS:
+ return "DS";
+ case PERF_REG_X86_ES:
+ return "ES";
+ case PERF_REG_X86_FS:
+ return "FS";
+ case PERF_REG_X86_GS:
+ return "GS";
+ case PERF_REG_X86_R8:
+ return "R8";
+ case PERF_REG_X86_R9:
+ return "R9";
+ case PERF_REG_X86_R10:
+ return "R10";
+ case PERF_REG_X86_R11:
+ return "R11";
+ case PERF_REG_X86_R12:
+ return "R12";
+ case PERF_REG_X86_R13:
+ return "R13";
+ case PERF_REG_X86_R14:
+ return "R14";
+ case PERF_REG_X86_R15:
+ return "R15";
+
+#define XMM(x) \
+ case PERF_REG_X86_XMM ## x: \
+ case PERF_REG_X86_XMM ## x + 1: \
+ return "XMM" #x;
+ XMM(0)
+ XMM(1)
+ XMM(2)
+ XMM(3)
+ XMM(4)
+ XMM(5)
+ XMM(6)
+ XMM(7)
+ XMM(8)
+ XMM(9)
+ XMM(10)
+ XMM(11)
+ XMM(12)
+ XMM(13)
+ XMM(14)
+ XMM(15)
+#undef XMM
+ default:
+ return NULL;
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index 9bdbaa37f813..5af1b95c3d01 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -22,722 +22,6 @@ uint64_t __weak arch__user_reg_mask(void)

#ifdef HAVE_PERF_REGS_SUPPORT

-#define perf_event_arm_regs perf_event_arm64_regs
-#include "../../arch/arm64/include/uapi/asm/perf_regs.h"
-#undef perf_event_arm_regs
-
-#include "../../arch/arm/include/uapi/asm/perf_regs.h"
-#include "../../arch/csky/include/uapi/asm/perf_regs.h"
-#include "../../arch/loongarch/include/uapi/asm/perf_regs.h"
-#include "../../arch/mips/include/uapi/asm/perf_regs.h"
-#include "../../arch/powerpc/include/uapi/asm/perf_regs.h"
-#include "../../arch/riscv/include/uapi/asm/perf_regs.h"
-#include "../../arch/s390/include/uapi/asm/perf_regs.h"
-#include "../../arch/x86/include/uapi/asm/perf_regs.h"
-
-static const char *__perf_reg_name_arm64(int id)
-{
- switch (id) {
- case PERF_REG_ARM64_X0:
- return "x0";
- case PERF_REG_ARM64_X1:
- return "x1";
- case PERF_REG_ARM64_X2:
- return "x2";
- case PERF_REG_ARM64_X3:
- return "x3";
- case PERF_REG_ARM64_X4:
- return "x4";
- case PERF_REG_ARM64_X5:
- return "x5";
- case PERF_REG_ARM64_X6:
- return "x6";
- case PERF_REG_ARM64_X7:
- return "x7";
- case PERF_REG_ARM64_X8:
- return "x8";
- case PERF_REG_ARM64_X9:
- return "x9";
- case PERF_REG_ARM64_X10:
- return "x10";
- case PERF_REG_ARM64_X11:
- return "x11";
- case PERF_REG_ARM64_X12:
- return "x12";
- case PERF_REG_ARM64_X13:
- return "x13";
- case PERF_REG_ARM64_X14:
- return "x14";
- case PERF_REG_ARM64_X15:
- return "x15";
- case PERF_REG_ARM64_X16:
- return "x16";
- case PERF_REG_ARM64_X17:
- return "x17";
- case PERF_REG_ARM64_X18:
- return "x18";
- case PERF_REG_ARM64_X19:
- return "x19";
- case PERF_REG_ARM64_X20:
- return "x20";
- case PERF_REG_ARM64_X21:
- return "x21";
- case PERF_REG_ARM64_X22:
- return "x22";
- case PERF_REG_ARM64_X23:
- return "x23";
- case PERF_REG_ARM64_X24:
- return "x24";
- case PERF_REG_ARM64_X25:
- return "x25";
- case PERF_REG_ARM64_X26:
- return "x26";
- case PERF_REG_ARM64_X27:
- return "x27";
- case PERF_REG_ARM64_X28:
- return "x28";
- case PERF_REG_ARM64_X29:
- return "x29";
- case PERF_REG_ARM64_SP:
- return "sp";
- case PERF_REG_ARM64_LR:
- return "lr";
- case PERF_REG_ARM64_PC:
- return "pc";
- case PERF_REG_ARM64_VG:
- return "vg";
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-static const char *__perf_reg_name_arm(int id)
-{
- switch (id) {
- case PERF_REG_ARM_R0:
- return "r0";
- case PERF_REG_ARM_R1:
- return "r1";
- case PERF_REG_ARM_R2:
- return "r2";
- case PERF_REG_ARM_R3:
- return "r3";
- case PERF_REG_ARM_R4:
- return "r4";
- case PERF_REG_ARM_R5:
- return "r5";
- case PERF_REG_ARM_R6:
- return "r6";
- case PERF_REG_ARM_R7:
- return "r7";
- case PERF_REG_ARM_R8:
- return "r8";
- case PERF_REG_ARM_R9:
- return "r9";
- case PERF_REG_ARM_R10:
- return "r10";
- case PERF_REG_ARM_FP:
- return "fp";
- case PERF_REG_ARM_IP:
- return "ip";
- case PERF_REG_ARM_SP:
- return "sp";
- case PERF_REG_ARM_LR:
- return "lr";
- case PERF_REG_ARM_PC:
- return "pc";
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-static const char *__perf_reg_name_csky(int id)
-{
- switch (id) {
- case PERF_REG_CSKY_A0:
- return "a0";
- case PERF_REG_CSKY_A1:
- return "a1";
- case PERF_REG_CSKY_A2:
- return "a2";
- case PERF_REG_CSKY_A3:
- return "a3";
- case PERF_REG_CSKY_REGS0:
- return "regs0";
- case PERF_REG_CSKY_REGS1:
- return "regs1";
- case PERF_REG_CSKY_REGS2:
- return "regs2";
- case PERF_REG_CSKY_REGS3:
- return "regs3";
- case PERF_REG_CSKY_REGS4:
- return "regs4";
- case PERF_REG_CSKY_REGS5:
- return "regs5";
- case PERF_REG_CSKY_REGS6:
- return "regs6";
- case PERF_REG_CSKY_REGS7:
- return "regs7";
- case PERF_REG_CSKY_REGS8:
- return "regs8";
- case PERF_REG_CSKY_REGS9:
- return "regs9";
- case PERF_REG_CSKY_SP:
- return "sp";
- case PERF_REG_CSKY_LR:
- return "lr";
- case PERF_REG_CSKY_PC:
- return "pc";
-#if defined(__CSKYABIV2__)
- case PERF_REG_CSKY_EXREGS0:
- return "exregs0";
- case PERF_REG_CSKY_EXREGS1:
- return "exregs1";
- case PERF_REG_CSKY_EXREGS2:
- return "exregs2";
- case PERF_REG_CSKY_EXREGS3:
- return "exregs3";
- case PERF_REG_CSKY_EXREGS4:
- return "exregs4";
- case PERF_REG_CSKY_EXREGS5:
- return "exregs5";
- case PERF_REG_CSKY_EXREGS6:
- return "exregs6";
- case PERF_REG_CSKY_EXREGS7:
- return "exregs7";
- case PERF_REG_CSKY_EXREGS8:
- return "exregs8";
- case PERF_REG_CSKY_EXREGS9:
- return "exregs9";
- case PERF_REG_CSKY_EXREGS10:
- return "exregs10";
- case PERF_REG_CSKY_EXREGS11:
- return "exregs11";
- case PERF_REG_CSKY_EXREGS12:
- return "exregs12";
- case PERF_REG_CSKY_EXREGS13:
- return "exregs13";
- case PERF_REG_CSKY_EXREGS14:
- return "exregs14";
- case PERF_REG_CSKY_TLS:
- return "tls";
- case PERF_REG_CSKY_HI:
- return "hi";
- case PERF_REG_CSKY_LO:
- return "lo";
-#endif
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-static inline const char *__perf_reg_name_loongarch(int id)
-{
- switch (id) {
- case PERF_REG_LOONGARCH_PC:
- return "PC";
- case PERF_REG_LOONGARCH_R1:
- return "%r1";
- case PERF_REG_LOONGARCH_R2:
- return "%r2";
- case PERF_REG_LOONGARCH_R3:
- return "%r3";
- case PERF_REG_LOONGARCH_R4:
- return "%r4";
- case PERF_REG_LOONGARCH_R5:
- return "%r5";
- case PERF_REG_LOONGARCH_R6:
- return "%r6";
- case PERF_REG_LOONGARCH_R7:
- return "%r7";
- case PERF_REG_LOONGARCH_R8:
- return "%r8";
- case PERF_REG_LOONGARCH_R9:
- return "%r9";
- case PERF_REG_LOONGARCH_R10:
- return "%r10";
- case PERF_REG_LOONGARCH_R11:
- return "%r11";
- case PERF_REG_LOONGARCH_R12:
- return "%r12";
- case PERF_REG_LOONGARCH_R13:
- return "%r13";
- case PERF_REG_LOONGARCH_R14:
- return "%r14";
- case PERF_REG_LOONGARCH_R15:
- return "%r15";
- case PERF_REG_LOONGARCH_R16:
- return "%r16";
- case PERF_REG_LOONGARCH_R17:
- return "%r17";
- case PERF_REG_LOONGARCH_R18:
- return "%r18";
- case PERF_REG_LOONGARCH_R19:
- return "%r19";
- case PERF_REG_LOONGARCH_R20:
- return "%r20";
- case PERF_REG_LOONGARCH_R21:
- return "%r21";
- case PERF_REG_LOONGARCH_R22:
- return "%r22";
- case PERF_REG_LOONGARCH_R23:
- return "%r23";
- case PERF_REG_LOONGARCH_R24:
- return "%r24";
- case PERF_REG_LOONGARCH_R25:
- return "%r25";
- case PERF_REG_LOONGARCH_R26:
- return "%r26";
- case PERF_REG_LOONGARCH_R27:
- return "%r27";
- case PERF_REG_LOONGARCH_R28:
- return "%r28";
- case PERF_REG_LOONGARCH_R29:
- return "%r29";
- case PERF_REG_LOONGARCH_R30:
- return "%r30";
- case PERF_REG_LOONGARCH_R31:
- return "%r31";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *__perf_reg_name_mips(int id)
-{
- switch (id) {
- case PERF_REG_MIPS_PC:
- return "PC";
- case PERF_REG_MIPS_R1:
- return "$1";
- case PERF_REG_MIPS_R2:
- return "$2";
- case PERF_REG_MIPS_R3:
- return "$3";
- case PERF_REG_MIPS_R4:
- return "$4";
- case PERF_REG_MIPS_R5:
- return "$5";
- case PERF_REG_MIPS_R6:
- return "$6";
- case PERF_REG_MIPS_R7:
- return "$7";
- case PERF_REG_MIPS_R8:
- return "$8";
- case PERF_REG_MIPS_R9:
- return "$9";
- case PERF_REG_MIPS_R10:
- return "$10";
- case PERF_REG_MIPS_R11:
- return "$11";
- case PERF_REG_MIPS_R12:
- return "$12";
- case PERF_REG_MIPS_R13:
- return "$13";
- case PERF_REG_MIPS_R14:
- return "$14";
- case PERF_REG_MIPS_R15:
- return "$15";
- case PERF_REG_MIPS_R16:
- return "$16";
- case PERF_REG_MIPS_R17:
- return "$17";
- case PERF_REG_MIPS_R18:
- return "$18";
- case PERF_REG_MIPS_R19:
- return "$19";
- case PERF_REG_MIPS_R20:
- return "$20";
- case PERF_REG_MIPS_R21:
- return "$21";
- case PERF_REG_MIPS_R22:
- return "$22";
- case PERF_REG_MIPS_R23:
- return "$23";
- case PERF_REG_MIPS_R24:
- return "$24";
- case PERF_REG_MIPS_R25:
- return "$25";
- case PERF_REG_MIPS_R28:
- return "$28";
- case PERF_REG_MIPS_R29:
- return "$29";
- case PERF_REG_MIPS_R30:
- return "$30";
- case PERF_REG_MIPS_R31:
- return "$31";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *__perf_reg_name_powerpc(int id)
-{
- switch (id) {
- case PERF_REG_POWERPC_R0:
- return "r0";
- case PERF_REG_POWERPC_R1:
- return "r1";
- case PERF_REG_POWERPC_R2:
- return "r2";
- case PERF_REG_POWERPC_R3:
- return "r3";
- case PERF_REG_POWERPC_R4:
- return "r4";
- case PERF_REG_POWERPC_R5:
- return "r5";
- case PERF_REG_POWERPC_R6:
- return "r6";
- case PERF_REG_POWERPC_R7:
- return "r7";
- case PERF_REG_POWERPC_R8:
- return "r8";
- case PERF_REG_POWERPC_R9:
- return "r9";
- case PERF_REG_POWERPC_R10:
- return "r10";
- case PERF_REG_POWERPC_R11:
- return "r11";
- case PERF_REG_POWERPC_R12:
- return "r12";
- case PERF_REG_POWERPC_R13:
- return "r13";
- case PERF_REG_POWERPC_R14:
- return "r14";
- case PERF_REG_POWERPC_R15:
- return "r15";
- case PERF_REG_POWERPC_R16:
- return "r16";
- case PERF_REG_POWERPC_R17:
- return "r17";
- case PERF_REG_POWERPC_R18:
- return "r18";
- case PERF_REG_POWERPC_R19:
- return "r19";
- case PERF_REG_POWERPC_R20:
- return "r20";
- case PERF_REG_POWERPC_R21:
- return "r21";
- case PERF_REG_POWERPC_R22:
- return "r22";
- case PERF_REG_POWERPC_R23:
- return "r23";
- case PERF_REG_POWERPC_R24:
- return "r24";
- case PERF_REG_POWERPC_R25:
- return "r25";
- case PERF_REG_POWERPC_R26:
- return "r26";
- case PERF_REG_POWERPC_R27:
- return "r27";
- case PERF_REG_POWERPC_R28:
- return "r28";
- case PERF_REG_POWERPC_R29:
- return "r29";
- case PERF_REG_POWERPC_R30:
- return "r30";
- case PERF_REG_POWERPC_R31:
- return "r31";
- case PERF_REG_POWERPC_NIP:
- return "nip";
- case PERF_REG_POWERPC_MSR:
- return "msr";
- case PERF_REG_POWERPC_ORIG_R3:
- return "orig_r3";
- case PERF_REG_POWERPC_CTR:
- return "ctr";
- case PERF_REG_POWERPC_LINK:
- return "link";
- case PERF_REG_POWERPC_XER:
- return "xer";
- case PERF_REG_POWERPC_CCR:
- return "ccr";
- case PERF_REG_POWERPC_SOFTE:
- return "softe";
- case PERF_REG_POWERPC_TRAP:
- return "trap";
- case PERF_REG_POWERPC_DAR:
- return "dar";
- case PERF_REG_POWERPC_DSISR:
- return "dsisr";
- case PERF_REG_POWERPC_SIER:
- return "sier";
- case PERF_REG_POWERPC_MMCRA:
- return "mmcra";
- case PERF_REG_POWERPC_MMCR0:
- return "mmcr0";
- case PERF_REG_POWERPC_MMCR1:
- return "mmcr1";
- case PERF_REG_POWERPC_MMCR2:
- return "mmcr2";
- case PERF_REG_POWERPC_MMCR3:
- return "mmcr3";
- case PERF_REG_POWERPC_SIER2:
- return "sier2";
- case PERF_REG_POWERPC_SIER3:
- return "sier3";
- case PERF_REG_POWERPC_PMC1:
- return "pmc1";
- case PERF_REG_POWERPC_PMC2:
- return "pmc2";
- case PERF_REG_POWERPC_PMC3:
- return "pmc3";
- case PERF_REG_POWERPC_PMC4:
- return "pmc4";
- case PERF_REG_POWERPC_PMC5:
- return "pmc5";
- case PERF_REG_POWERPC_PMC6:
- return "pmc6";
- case PERF_REG_POWERPC_SDAR:
- return "sdar";
- case PERF_REG_POWERPC_SIAR:
- return "siar";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *__perf_reg_name_riscv(int id)
-{
- switch (id) {
- case PERF_REG_RISCV_PC:
- return "pc";
- case PERF_REG_RISCV_RA:
- return "ra";
- case PERF_REG_RISCV_SP:
- return "sp";
- case PERF_REG_RISCV_GP:
- return "gp";
- case PERF_REG_RISCV_TP:
- return "tp";
- case PERF_REG_RISCV_T0:
- return "t0";
- case PERF_REG_RISCV_T1:
- return "t1";
- case PERF_REG_RISCV_T2:
- return "t2";
- case PERF_REG_RISCV_S0:
- return "s0";
- case PERF_REG_RISCV_S1:
- return "s1";
- case PERF_REG_RISCV_A0:
- return "a0";
- case PERF_REG_RISCV_A1:
- return "a1";
- case PERF_REG_RISCV_A2:
- return "a2";
- case PERF_REG_RISCV_A3:
- return "a3";
- case PERF_REG_RISCV_A4:
- return "a4";
- case PERF_REG_RISCV_A5:
- return "a5";
- case PERF_REG_RISCV_A6:
- return "a6";
- case PERF_REG_RISCV_A7:
- return "a7";
- case PERF_REG_RISCV_S2:
- return "s2";
- case PERF_REG_RISCV_S3:
- return "s3";
- case PERF_REG_RISCV_S4:
- return "s4";
- case PERF_REG_RISCV_S5:
- return "s5";
- case PERF_REG_RISCV_S6:
- return "s6";
- case PERF_REG_RISCV_S7:
- return "s7";
- case PERF_REG_RISCV_S8:
- return "s8";
- case PERF_REG_RISCV_S9:
- return "s9";
- case PERF_REG_RISCV_S10:
- return "s10";
- case PERF_REG_RISCV_S11:
- return "s11";
- case PERF_REG_RISCV_T3:
- return "t3";
- case PERF_REG_RISCV_T4:
- return "t4";
- case PERF_REG_RISCV_T5:
- return "t5";
- case PERF_REG_RISCV_T6:
- return "t6";
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-static const char *__perf_reg_name_s390(int id)
-{
- switch (id) {
- case PERF_REG_S390_R0:
- return "R0";
- case PERF_REG_S390_R1:
- return "R1";
- case PERF_REG_S390_R2:
- return "R2";
- case PERF_REG_S390_R3:
- return "R3";
- case PERF_REG_S390_R4:
- return "R4";
- case PERF_REG_S390_R5:
- return "R5";
- case PERF_REG_S390_R6:
- return "R6";
- case PERF_REG_S390_R7:
- return "R7";
- case PERF_REG_S390_R8:
- return "R8";
- case PERF_REG_S390_R9:
- return "R9";
- case PERF_REG_S390_R10:
- return "R10";
- case PERF_REG_S390_R11:
- return "R11";
- case PERF_REG_S390_R12:
- return "R12";
- case PERF_REG_S390_R13:
- return "R13";
- case PERF_REG_S390_R14:
- return "R14";
- case PERF_REG_S390_R15:
- return "R15";
- case PERF_REG_S390_FP0:
- return "FP0";
- case PERF_REG_S390_FP1:
- return "FP1";
- case PERF_REG_S390_FP2:
- return "FP2";
- case PERF_REG_S390_FP3:
- return "FP3";
- case PERF_REG_S390_FP4:
- return "FP4";
- case PERF_REG_S390_FP5:
- return "FP5";
- case PERF_REG_S390_FP6:
- return "FP6";
- case PERF_REG_S390_FP7:
- return "FP7";
- case PERF_REG_S390_FP8:
- return "FP8";
- case PERF_REG_S390_FP9:
- return "FP9";
- case PERF_REG_S390_FP10:
- return "FP10";
- case PERF_REG_S390_FP11:
- return "FP11";
- case PERF_REG_S390_FP12:
- return "FP12";
- case PERF_REG_S390_FP13:
- return "FP13";
- case PERF_REG_S390_FP14:
- return "FP14";
- case PERF_REG_S390_FP15:
- return "FP15";
- case PERF_REG_S390_MASK:
- return "MASK";
- case PERF_REG_S390_PC:
- return "PC";
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-static const char *__perf_reg_name_x86(int id)
-{
- switch (id) {
- case PERF_REG_X86_AX:
- return "AX";
- case PERF_REG_X86_BX:
- return "BX";
- case PERF_REG_X86_CX:
- return "CX";
- case PERF_REG_X86_DX:
- return "DX";
- case PERF_REG_X86_SI:
- return "SI";
- case PERF_REG_X86_DI:
- return "DI";
- case PERF_REG_X86_BP:
- return "BP";
- case PERF_REG_X86_SP:
- return "SP";
- case PERF_REG_X86_IP:
- return "IP";
- case PERF_REG_X86_FLAGS:
- return "FLAGS";
- case PERF_REG_X86_CS:
- return "CS";
- case PERF_REG_X86_SS:
- return "SS";
- case PERF_REG_X86_DS:
- return "DS";
- case PERF_REG_X86_ES:
- return "ES";
- case PERF_REG_X86_FS:
- return "FS";
- case PERF_REG_X86_GS:
- return "GS";
- case PERF_REG_X86_R8:
- return "R8";
- case PERF_REG_X86_R9:
- return "R9";
- case PERF_REG_X86_R10:
- return "R10";
- case PERF_REG_X86_R11:
- return "R11";
- case PERF_REG_X86_R12:
- return "R12";
- case PERF_REG_X86_R13:
- return "R13";
- case PERF_REG_X86_R14:
- return "R14";
- case PERF_REG_X86_R15:
- return "R15";
-
-#define XMM(x) \
- case PERF_REG_X86_XMM ## x: \
- case PERF_REG_X86_XMM ## x + 1: \
- return "XMM" #x;
- XMM(0)
- XMM(1)
- XMM(2)
- XMM(3)
- XMM(4)
- XMM(5)
- XMM(6)
- XMM(7)
- XMM(8)
- XMM(9)
- XMM(10)
- XMM(11)
- XMM(12)
- XMM(13)
- XMM(14)
- XMM(15)
-#undef XMM
- default:
- return NULL;
- }
-
- return NULL;
-}
-
const char *perf_reg_name(int id, const char *arch)
{
const char *reg_name = NULL;
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index ce1127af05e4..6b19a2867171 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -36,6 +36,15 @@ extern const struct sample_reg sample_reg_masks[];

const char *perf_reg_name(int id, const char *arch);
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
+const char *__perf_reg_name_arm64(int id);
+const char *__perf_reg_name_arm(int id);
+const char *__perf_reg_name_csky(int id);
+const char *__perf_reg_name_loongarch(int id);
+const char *__perf_reg_name_mips(int id);
+const char *__perf_reg_name_powerpc(int id);
+const char *__perf_reg_name_riscv(int id);
+const char *__perf_reg_name_s390(int id);
+const char *__perf_reg_name_x86(int id);

#else
#define PERF_REGS_MASK 0
--
2.34.1


2023-06-06 02:02:49

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 6/6] perf parse-regs: Move out arch specific header from util/perf_regs.h

util/perf_regs.h includes another perf_regs.h:

#include <perf_regs.h>

Here it includes architecture specific header, for example, if we build
arm64 target, the header tools/perf/arch/arm64/include/perf_regs.h is
included.

We use this implicit way to include architecture specific header, which
is not directive; furthermore, util/perf_regs.c is coupled with the
architecture specific definitions.

This patch moves out arch specific header from util/perf_regs.h for
generalizing the 'util' folder, as a result, the source files in 'arch'
folder explicitly include architecture's perf_regs.h.

Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/arch/arm/util/perf_regs.c | 1 +
tools/perf/arch/arm/util/unwind-libdw.c | 1 +
tools/perf/arch/arm64/util/machine.c | 1 +
tools/perf/arch/arm64/util/perf_regs.c | 1 +
tools/perf/arch/arm64/util/unwind-libdw.c | 1 +
tools/perf/arch/csky/util/perf_regs.c | 1 +
tools/perf/arch/csky/util/unwind-libdw.c | 1 +
tools/perf/arch/loongarch/util/perf_regs.c | 1 +
tools/perf/arch/loongarch/util/unwind-libdw.c | 1 +
tools/perf/arch/mips/util/perf_regs.c | 1 +
tools/perf/arch/powerpc/util/perf_regs.c | 1 +
tools/perf/arch/powerpc/util/unwind-libdw.c | 1 +
tools/perf/arch/riscv/util/perf_regs.c | 1 +
tools/perf/arch/riscv/util/unwind-libdw.c | 1 +
tools/perf/arch/s390/util/perf_regs.c | 1 +
tools/perf/arch/s390/util/unwind-libdw.c | 1 +
tools/perf/arch/x86/util/perf_regs.c | 1 +
tools/perf/arch/x86/util/unwind-libdw.c | 1 +
tools/perf/util/perf_regs.h | 2 --
19 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/arm/util/perf_regs.c b/tools/perf/arch/arm/util/perf_regs.c
index d9d4777bf7f9..2c56e8b56ddf 100644
--- a/tools/perf/arch/arm/util/perf_regs.c
+++ b/tools/perf/arch/arm/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c
index 1834a0cd9ce3..4e02cef461e3 100644
--- a/tools/perf/arch/arm/util/unwind-libdw.c
+++ b/tools/perf/arch/arm/util/unwind-libdw.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../../util/unwind-libdw.h"
#include "../../../util/perf_regs.h"
#include "../../../util/sample.h"
diff --git a/tools/perf/arch/arm64/util/machine.c b/tools/perf/arch/arm64/util/machine.c
index 235a0a1e1ec7..ba1144366e85 100644
--- a/tools/perf/arch/arm64/util/machine.c
+++ b/tools/perf/arch/arm64/util/machine.c
@@ -6,6 +6,7 @@
#include "debug.h"
#include "symbol.h"
#include "callchain.h"
+#include "perf_regs.h"
#include "record.h"
#include "util/perf_regs.h"

diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c
index 76e2e30702cd..1b79d8eab22f 100644
--- a/tools/perf/arch/arm64/util/perf_regs.c
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -6,6 +6,7 @@
#include <linux/kernel.h>
#include <linux/zalloc.h>

+#include "perf_regs.h"
#include "../../../perf-sys.h"
#include "../../../util/debug.h"
#include "../../../util/event.h"
diff --git a/tools/perf/arch/arm64/util/unwind-libdw.c b/tools/perf/arch/arm64/util/unwind-libdw.c
index 09385081bb03..e056d50ab42e 100644
--- a/tools/perf/arch/arm64/util/unwind-libdw.c
+++ b/tools/perf/arch/arm64/util/unwind-libdw.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../../util/unwind-libdw.h"
#include "../../../util/perf_regs.h"
#include "../../../util/sample.h"
diff --git a/tools/perf/arch/csky/util/perf_regs.c b/tools/perf/arch/csky/util/perf_regs.c
index b17fc30abb29..c0877c264d49 100644
--- a/tools/perf/arch/csky/util/perf_regs.c
+++ b/tools/perf/arch/csky/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/csky/util/unwind-libdw.c b/tools/perf/arch/csky/util/unwind-libdw.c
index 4bb4a06776e4..79df4374ab18 100644
--- a/tools/perf/arch/csky/util/unwind-libdw.c
+++ b/tools/perf/arch/csky/util/unwind-libdw.c
@@ -2,6 +2,7 @@
// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.

#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../util/unwind-libdw.h"
#include "../../util/perf_regs.h"
#include "../../util/event.h"
diff --git a/tools/perf/arch/loongarch/util/perf_regs.c b/tools/perf/arch/loongarch/util/perf_regs.c
index d9d4777bf7f9..2c56e8b56ddf 100644
--- a/tools/perf/arch/loongarch/util/perf_regs.c
+++ b/tools/perf/arch/loongarch/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/loongarch/util/unwind-libdw.c b/tools/perf/arch/loongarch/util/unwind-libdw.c
index a9415385230a..7b3b9a4b21f8 100644
--- a/tools/perf/arch/loongarch/util/unwind-libdw.c
+++ b/tools/perf/arch/loongarch/util/unwind-libdw.c
@@ -2,6 +2,7 @@
/* Copyright (C) 2020-2023 Loongson Technology Corporation Limited */

#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../util/unwind-libdw.h"
#include "../../util/perf_regs.h"
#include "../../util/sample.h"
diff --git a/tools/perf/arch/mips/util/perf_regs.c b/tools/perf/arch/mips/util/perf_regs.c
index b17fc30abb29..c0877c264d49 100644
--- a/tools/perf/arch/mips/util/perf_regs.c
+++ b/tools/perf/arch/mips/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c
index 1d264bf55955..b38aa056eea0 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -4,6 +4,7 @@
#include <regex.h>
#include <linux/zalloc.h>

+#include "perf_regs.h"
#include "../../../util/perf_regs.h"
#include "../../../util/debug.h"
#include "../../../util/event.h"
diff --git a/tools/perf/arch/powerpc/util/unwind-libdw.c b/tools/perf/arch/powerpc/util/unwind-libdw.c
index e616642c754c..e9a5a8bb67d9 100644
--- a/tools/perf/arch/powerpc/util/unwind-libdw.c
+++ b/tools/perf/arch/powerpc/util/unwind-libdw.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <elfutils/libdwfl.h>
#include <linux/kernel.h>
+#include "perf_regs.h"
#include "../../../util/unwind-libdw.h"
#include "../../../util/perf_regs.h"
#include "../../../util/sample.h"
diff --git a/tools/perf/arch/riscv/util/perf_regs.c b/tools/perf/arch/riscv/util/perf_regs.c
index b17fc30abb29..c0877c264d49 100644
--- a/tools/perf/arch/riscv/util/perf_regs.c
+++ b/tools/perf/arch/riscv/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/riscv/util/unwind-libdw.c b/tools/perf/arch/riscv/util/unwind-libdw.c
index 54a198714eb8..5c98010d8b59 100644
--- a/tools/perf/arch/riscv/util/unwind-libdw.c
+++ b/tools/perf/arch/riscv/util/unwind-libdw.c
@@ -2,6 +2,7 @@
/* Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. */

#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../util/unwind-libdw.h"
#include "../../util/perf_regs.h"
#include "../../util/sample.h"
diff --git a/tools/perf/arch/s390/util/perf_regs.c b/tools/perf/arch/s390/util/perf_regs.c
index b17fc30abb29..c0877c264d49 100644
--- a/tools/perf/arch/s390/util/perf_regs.c
+++ b/tools/perf/arch/s390/util/perf_regs.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include "perf_regs.h"
#include "../../util/perf_regs.h"

const struct sample_reg sample_reg_masks[] = {
diff --git a/tools/perf/arch/s390/util/unwind-libdw.c b/tools/perf/arch/s390/util/unwind-libdw.c
index 7d92452d5287..f50fb6dbb35c 100644
--- a/tools/perf/arch/s390/util/unwind-libdw.c
+++ b/tools/perf/arch/s390/util/unwind-libdw.c
@@ -5,6 +5,7 @@
#include "../../util/event.h"
#include "../../util/sample.h"
#include "dwarf-regs-table.h"
+#include "perf_regs.h"


bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index 218747a8b039..b813502a2727 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -5,6 +5,7 @@
#include <linux/kernel.h>
#include <linux/zalloc.h>

+#include "perf_regs.h"
#include "../../../perf-sys.h"
#include "../../../util/perf_regs.h"
#include "../../../util/debug.h"
diff --git a/tools/perf/arch/x86/util/unwind-libdw.c b/tools/perf/arch/x86/util/unwind-libdw.c
index ef71e8bf80bf..edb77e20e083 100644
--- a/tools/perf/arch/x86/util/unwind-libdw.c
+++ b/tools/perf/arch/x86/util/unwind-libdw.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <elfutils/libdwfl.h>
+#include "perf_regs.h"
#include "../../../util/unwind-libdw.h"
#include "../../../util/perf_regs.h"
#include "util/sample.h"
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 8583c52572b1..4f6a3c1ba901 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -30,8 +30,6 @@ uint64_t arch__user_reg_mask(void);
#ifdef HAVE_PERF_REGS_SUPPORT
extern const struct sample_reg sample_reg_masks[];

-#include <perf_regs.h>
-
#define DWARF_MINIMAL_REGS(arch) \
((1ULL << perf_arch_reg_ip(arch)) | (1ULL << perf_arch_reg_sp(arch)))

--
2.34.1


2023-06-06 02:03:00

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 5/6] perf parse-regs: Remove PERF_REGS_{MAX|MASK} from common code

The macros PERF_REGS_MAX and PERF_REGS_MASK are architecture specific,
let's remove them from the common file util/perf_regs.c.

As a side effect, the weak functions arch__intr_reg_mask() and
arch__user_reg_mask() just return zeros, every arch defines its own
functions in the 'arch' folder for returning right values.

Note, we don't need to return intr/user register masks dynamically, this
is because these two functions are invoked during recording phase but
not decoding phase, they are always invoked on the native environment,
thus we don't need to parse them dynamically.

Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/arch/arm/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/arm64/util/perf_regs.c | 5 +++++
tools/perf/arch/csky/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/loongarch/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/mips/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/powerpc/util/perf_regs.c | 5 +++++
tools/perf/arch/riscv/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/s390/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/x86/util/perf_regs.c | 5 +++++
tools/perf/util/evsel.c | 2 +-
tools/perf/util/perf_regs.c | 4 ++--
tools/perf/util/perf_regs.h | 4 +---
12 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/tools/perf/arch/arm/util/perf_regs.c b/tools/perf/arch/arm/util/perf_regs.c
index 2833e101a7c6..d9d4777bf7f9 100644
--- a/tools/perf/arch/arm/util/perf_regs.c
+++ b/tools/perf/arch/arm/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c
index 006692c9b040..76e2e30702cd 100644
--- a/tools/perf/arch/arm64/util/perf_regs.c
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -139,6 +139,11 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
return SDT_ARG_VALID;
}

+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
uint64_t arch__user_reg_mask(void)
{
struct perf_event_attr attr = {
diff --git a/tools/perf/arch/csky/util/perf_regs.c b/tools/perf/arch/csky/util/perf_regs.c
index 2864e2e3776d..b17fc30abb29 100644
--- a/tools/perf/arch/csky/util/perf_regs.c
+++ b/tools/perf/arch/csky/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/loongarch/util/perf_regs.c b/tools/perf/arch/loongarch/util/perf_regs.c
index 2833e101a7c6..d9d4777bf7f9 100644
--- a/tools/perf/arch/loongarch/util/perf_regs.c
+++ b/tools/perf/arch/loongarch/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/mips/util/perf_regs.c b/tools/perf/arch/mips/util/perf_regs.c
index 2864e2e3776d..b17fc30abb29 100644
--- a/tools/perf/arch/mips/util/perf_regs.c
+++ b/tools/perf/arch/mips/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c
index 8d07a78e742a..1d264bf55955 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -226,3 +226,8 @@ uint64_t arch__intr_reg_mask(void)
}
return mask;
}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/riscv/util/perf_regs.c b/tools/perf/arch/riscv/util/perf_regs.c
index 2864e2e3776d..b17fc30abb29 100644
--- a/tools/perf/arch/riscv/util/perf_regs.c
+++ b/tools/perf/arch/riscv/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/s390/util/perf_regs.c b/tools/perf/arch/s390/util/perf_regs.c
index 2864e2e3776d..b17fc30abb29 100644
--- a/tools/perf/arch/s390/util/perf_regs.c
+++ b/tools/perf/arch/s390/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__intr_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index 8ad4112ad10c..218747a8b039 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -317,3 +317,8 @@ uint64_t arch__intr_reg_mask(void)

return PERF_REGS_MASK;
}
+
+uint64_t arch__user_reg_mask(void)
+{
+ return PERF_REGS_MASK;
+}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index dfba2bc79cfc..4168996c7a02 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -878,7 +878,7 @@ static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *o
evsel__set_sample_bit(evsel, REGS_USER);
evsel__set_sample_bit(evsel, STACK_USER);
if (opts->sample_user_regs &&
- DWARF_MINIMAL_REGS(arch) != PERF_REGS_MASK) {
+ DWARF_MINIMAL_REGS(arch) != arch__user_reg_mask()) {
attr->sample_regs_user |= DWARF_MINIMAL_REGS(arch);
pr_warning("WARNING: The use of --call-graph=dwarf may require all the user registers, "
"specifying a subset with --user-regs may render DWARF unwinding unreliable, "
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index 23584efd4886..e2275856b570 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -13,12 +13,12 @@ int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,

uint64_t __weak arch__intr_reg_mask(void)
{
- return PERF_REGS_MASK;
+ return 0;
}

uint64_t __weak arch__user_reg_mask(void)
{
- return PERF_REGS_MASK;
+ return 0;
}

#ifdef HAVE_PERF_REGS_SUPPORT
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 790c1a26bbfe..8583c52572b1 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -68,10 +68,8 @@ uint64_t __perf_reg_ip_x86(void);
uint64_t __perf_reg_sp_x86(void);

#else
-#define PERF_REGS_MASK 0
-#define PERF_REGS_MAX 0

-#define DWARF_MINIMAL_REGS(arch) PERF_REGS_MASK
+#define DWARF_MINIMAL_REGS(arch) 0

static inline const char *perf_reg_name(int id __maybe_unused, const char *arch __maybe_unused)
{
--
2.34.1


2023-07-12 23:00:18

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

On Mon, Jun 5, 2023 at 6:46 PM Leo Yan <[email protected]> wrote:
>
> This patch series is to refactor arch related functions for register
> parsing, which follows up the discussion for v1:
> https://lore.kernel.org/lkml/[email protected]/
>
> 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

Sorry for the slow review. For the series:
Acked-by: Ian Rogers <[email protected]>

Some thoughts:
uint64_t __perf_reg_ip_arm(void)
uint64_t seems like we're giving a lot of space for future register
encodings. I think some of the other functions use this size of value
due to returning a bitmap/mask, but here it isn't clear and just feels
excessive.

Do we need the "__" prefix on all the functions?

In Makefile.config there are NO_PERF_REGS and CONFIG_PERF_REGS then
the define HAVE_PERF_REGS_SUPPORT. Is this still relevant? If we had
an architecture with no support, couldn't it still read a perf.data
file from a supported architecture? It would be nice to remove at
least NO_PERF_REGS and HAVE_PERF_REGS_SUPPORT.

This change is very worthwhile fix and cleanup, it didn't introduce
what is pondered above, hence the acked-by.

Thanks!
Ian

> 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
>
> --
> 2.34.1
>

2023-08-15 19:11:41

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Wed, Jul 12, 2023 at 03:37:36PM -0700, Ian Rogers escreveu:
> On Mon, Jun 5, 2023 at 6:46 PM Leo Yan <[email protected]> wrote:
> >
> > This patch series is to refactor arch related functions for register
> > parsing, which follows up the discussion for v1:
> > https://lore.kernel.org/lkml/[email protected]/
> >
> > 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
>
> Sorry for the slow review. For the series:
> Acked-by: Ian Rogers <[email protected]>
>
> Some thoughts:
> uint64_t __perf_reg_ip_arm(void)
> uint64_t seems like we're giving a lot of space for future register
> encodings. I think some of the other functions use this size of value
> due to returning a bitmap/mask, but here it isn't clear and just feels
> excessive.
>
> Do we need the "__" prefix on all the functions?
>
> In Makefile.config there are NO_PERF_REGS and CONFIG_PERF_REGS then
> the define HAVE_PERF_REGS_SUPPORT. Is this still relevant? If we had
> an architecture with no support, couldn't it still read a perf.data
> file from a supported architecture? It would be nice to remove at
> least NO_PERF_REGS and HAVE_PERF_REGS_SUPPORT.
>
> This change is very worthwhile fix and cleanup, it didn't introduce
> what is pondered above, hence the acked-by.

Agreed, applied to perf-tools-next, sorry for the delay.

- Arnaldo

2023-08-16 11:14:54

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Tue, Aug 15, 2023 at 03:45:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Agreed, applied to perf-tools-next, sorry for the delay.
>
> Had to add this to make 'perf test python' to work. Please run 'perf
> test' before sending patches.

One more, please also do a 'make -C tools/perf build-test', with it I
caught this:

make_no_libunwind_O: cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH

CC /tmp/tmp.yeEGyQq2HR/util/expr-flex.o
util/unwind-libdw.c: In function ‘memory_read’:
util/unwind-libdw.c:173:28: error: implicit declaration of function ‘perf_env__arch’ [-Werror=implicit-function-declaration]
173 | const char *arch = perf_env__arch(ui->machine->env);
| ^~~~~~~~~~~~~~
util/unwind-libdw.c:173:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
util/unwind-libdw.c: In function ‘unwind__get_entries’:
util/unwind-libdw.c:258:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
258 | const char *arch = perf_env__arch(ui_buf.machine->env);
| ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[6]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:98: /tmp/tmp.yeEGyQq2HR/util/unwind-libdw.o] Error 1
make[6]: *** Waiting for unfinished jobs....
make[5]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:150: util] Error 2
make[4]: *** [Makefile.perf:662: /tmp/tmp.yeEGyQq2HR/perf-in.o] Error 2
make[4]: *** Waiting for unfinished jobs....
CC /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events.o
LD /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events-in.o
make[3]: *** [Makefile.perf:238: sub-make] Error 2
make[2]: *** [Makefile:70: all] Error 2
make[1]: *** [tests/make:337: make_no_libunwind_O] Error 1
make: *** [Makefile:103: build-test] Error 2
make: Leaving directory '/var/home/acme/git/perf-tools-next/tools/perf'

real 1m29.784s
user 10m41.597s
sys 2m55.948s
⬢[acme@toolbox perf-tools-next]$

I'm trying to fix

2023-08-16 15:19:15

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Tue, Aug 15, 2023 at 03:24:04PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Jul 12, 2023 at 03:37:36PM -0700, Ian Rogers escreveu:
> > On Mon, Jun 5, 2023 at 6:46 PM Leo Yan <[email protected]> wrote:
> > >
> > > This patch series is to refactor arch related functions for register
> > > parsing, which follows up the discussion for v1:
> > > https://lore.kernel.org/lkml/[email protected]/
> > >
> > > 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
> >
> > Sorry for the slow review. For the series:
> > Acked-by: Ian Rogers <[email protected]>
> >
> > Some thoughts:
> > uint64_t __perf_reg_ip_arm(void)
> > uint64_t seems like we're giving a lot of space for future register
> > encodings. I think some of the other functions use this size of value
> > due to returning a bitmap/mask, but here it isn't clear and just feels
> > excessive.
> >
> > Do we need the "__" prefix on all the functions?
> >
> > In Makefile.config there are NO_PERF_REGS and CONFIG_PERF_REGS then
> > the define HAVE_PERF_REGS_SUPPORT. Is this still relevant? If we had
> > an architecture with no support, couldn't it still read a perf.data
> > file from a supported architecture? It would be nice to remove at
> > least NO_PERF_REGS and HAVE_PERF_REGS_SUPPORT.
> >
> > This change is very worthwhile fix and cleanup, it didn't introduce
> > what is pondered above, hence the acked-by.
>
> Agreed, applied to perf-tools-next, sorry for the delay.

Had to add this to make 'perf test python' to work. Please run 'perf
test' before sending patches.

- Arnaldo

diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index d4c9b4cd35efa556..26e1c8d973ea0b95 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -40,3 +40,12 @@ util/rwsem.c
util/hashmap.c
util/perf_regs.c
util/fncache.c
+util/perf-regs-arch/perf_regs_aarch64.c
+util/perf-regs-arch/perf_regs_arm.c
+util/perf-regs-arch/perf_regs_csky.c
+util/perf-regs-arch/perf_regs_loongarch.c
+util/perf-regs-arch/perf_regs_mips.c
+util/perf-regs-arch/perf_regs_powerpc.c
+util/perf-regs-arch/perf_regs_riscv.c
+util/perf-regs-arch/perf_regs_s390.c
+util/perf-regs-arch/perf_regs_x86.c

2023-08-17 16:16:24

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Tue, Aug 15, 2023 at 03:52:38PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Tue, Aug 15, 2023 at 03:45:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Agreed, applied to perf-tools-next, sorry for the delay.
> >
> > Had to add this to make 'perf test python' to work. Please run 'perf
> > test' before sending patches.
>
> One more, please also do a 'make -C tools/perf build-test', with it I
> caught this:
>
> make_no_libunwind_O: cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
> cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH

+#include "util/env.h"

As now we need it for perf_env__arch(ui->machine->env)

> CC /tmp/tmp.yeEGyQq2HR/util/expr-flex.o
> util/unwind-libdw.c: In function ‘memory_read’:
> util/unwind-libdw.c:173:28: error: implicit declaration of function ‘perf_env__arch’ [-Werror=implicit-function-declaration]
> 173 | const char *arch = perf_env__arch(ui->machine->env);
> | ^~~~~~~~~~~~~~
> util/unwind-libdw.c:173:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> util/unwind-libdw.c: In function ‘unwind__get_entries’:
> util/unwind-libdw.c:258:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> 258 | const char *arch = perf_env__arch(ui_buf.machine->env);
> | ^~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[6]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:98: /tmp/tmp.yeEGyQq2HR/util/unwind-libdw.o] Error 1
> make[6]: *** Waiting for unfinished jobs....
> make[5]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:150: util] Error 2
> make[4]: *** [Makefile.perf:662: /tmp/tmp.yeEGyQq2HR/perf-in.o] Error 2
> make[4]: *** Waiting for unfinished jobs....
> CC /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events.o
> LD /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events-in.o
> make[3]: *** [Makefile.perf:238: sub-make] Error 2
> make[2]: *** [Makefile:70: all] Error 2
> make[1]: *** [tests/make:337: make_no_libunwind_O] Error 1
> make: *** [Makefile:103: build-test] Error 2
> make: Leaving directory '/var/home/acme/git/perf-tools-next/tools/perf'
>
> real 1m29.784s
> user 10m41.597s
> sys 2m55.948s
> ⬢[acme@toolbox perf-tools-next]$
>
> I'm trying to fix

--

- Arnaldo

2023-08-17 17:11:33

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Wed, Aug 16, 2023 at 08:46:23AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Aug 16, 2023 at 10:07:15AM +0800, Leo Yan escreveu:
> > On Tue, Aug 15, 2023 at 03:57:17PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Tue, Aug 15, 2023 at 03:52:38PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > Em Tue, Aug 15, 2023 at 03:45:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > > > Agreed, applied to perf-tools-next, sorry for the delay.
> > > > >
> > > > > Had to add this to make 'perf test python' to work. Please run 'perf
> > > > > test' before sending patches.
> > > >
> > > > One more, please also do a 'make -C tools/perf build-test', with it I
> > > > caught this:
> > > >
> > > > make_no_libunwind_O: cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
> > > > cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
> > >
> > > +#include "util/env.h"
> > >
> > > As now we need it for perf_env__arch(ui->machine->env)
> >
> > Sorry for inconvenience.
> >
> > I saw this patch series has been picked into the branch:
> > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf-tools-next
> >
> > If want me to follow up, let me know. Thank you!
>
> Right, I'll fix this ones:
>
> [perfbuilder@five ~]$ grep "unused variable" dm.log/*:*
> dm.log/ubuntu:18.04-x-m68k:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
> dm.log/ubuntu:18.04-x-riscv64:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
> dm.log/ubuntu:18.04-x-sh4:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
> dm.log/ubuntu:18.04-x-sparc64:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
> [perfbuilder@five ~]$
>
> And move that to perf-tools-next, we can go on from there.
>
> The above is because we don't define CONFIG_PERF_REGS for these
> architectures and thus that variable ends up not being used, so I'm
> fixing up like below, in the cset where you made DWARF_MINIMAL_REGS
> receive the arch parameter.

I added this to the cset commit message:

Committer notes:

Make DWARF_MINIMAL_REGS() an inline function, so that we can use the
__maybe_unused attribute for the 'arch' parameter, as this will avoid a
build failure when that variable is unused in the callers. That happens
when building on unsupported architectures, the ones without
HAVE_PERF_REGS_SUPPORT defined.


> Also I haven't checked how gracefully we react when processing a
> perf.data collected in one of those unsupported arches, can you please
> check?
>
> - Arnaldo
>
> diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
> index 790c1a26bbfe9b4b..de1673057e502de9 100644
> --- a/tools/perf/util/perf_regs.h
> +++ b/tools/perf/util/perf_regs.h
> @@ -32,9 +32,6 @@ extern const struct sample_reg sample_reg_masks[];
>
> #include <perf_regs.h>
>
> -#define DWARF_MINIMAL_REGS(arch) \
> - ((1ULL << perf_arch_reg_ip(arch)) | (1ULL << perf_arch_reg_sp(arch)))
> -
> const char *perf_reg_name(int id, const char *arch);
> int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
> uint64_t perf_arch_reg_ip(const char *arch);
> @@ -67,11 +64,19 @@ const char *__perf_reg_name_x86(int id);
> uint64_t __perf_reg_ip_x86(void);
> uint64_t __perf_reg_sp_x86(void);
>
> +static inline uint64_t DWARF_MINIMAL_REGS(const char *arch)
> +{
> + return (1ULL << perf_arch_reg_ip(arch)) | (1ULL << perf_arch_reg_sp(arch));
> +}
> +
> #else
> #define PERF_REGS_MASK 0
> #define PERF_REGS_MAX 0
>
> -#define DWARF_MINIMAL_REGS(arch) PERF_REGS_MASK
> +static inline uint64_t DWARF_MINIMAL_REGS(const char *arch __maybe_unused)
> +{
> + return PERF_REGS_MASK;
> +}
>
> static inline const char *perf_reg_name(int id __maybe_unused, const char *arch __maybe_unused)
> {
>
> > > > CC /tmp/tmp.yeEGyQq2HR/util/expr-flex.o
> > > > util/unwind-libdw.c: In function ‘memory_read’:
> > > > util/unwind-libdw.c:173:28: error: implicit declaration of function ‘perf_env__arch’ [-Werror=implicit-function-declaration]
> > > > 173 | const char *arch = perf_env__arch(ui->machine->env);
> > > > | ^~~~~~~~~~~~~~
> > > > util/unwind-libdw.c:173:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> > > > util/unwind-libdw.c: In function ‘unwind__get_entries’:
> > > > util/unwind-libdw.c:258:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> > > > 258 | const char *arch = perf_env__arch(ui_buf.machine->env);
> > > > | ^~~~~~~~~~~~~~
> > > > cc1: all warnings being treated as errors
> > > > make[6]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:98: /tmp/tmp.yeEGyQq2HR/util/unwind-libdw.o] Error 1
> > > > make[6]: *** Waiting for unfinished jobs....
> > > > make[5]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:150: util] Error 2
> > > > make[4]: *** [Makefile.perf:662: /tmp/tmp.yeEGyQq2HR/perf-in.o] Error 2
> > > > make[4]: *** Waiting for unfinished jobs....
> > > > CC /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events.o
> > > > LD /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events-in.o
> > > > make[3]: *** [Makefile.perf:238: sub-make] Error 2
> > > > make[2]: *** [Makefile:70: all] Error 2
> > > > make[1]: *** [tests/make:337: make_no_libunwind_O] Error 1
> > > > make: *** [Makefile:103: build-test] Error 2
> > > > make: Leaving directory '/var/home/acme/git/perf-tools-next/tools/perf'
> > > >
> > > > real 1m29.784s
> > > > user 10m41.597s
> > > > sys 2m55.948s
> > > > ⬢[acme@toolbox perf-tools-next]$
> > > >
> > > > I'm trying to fix
> > >
> > > --
> > >
> > > - Arnaldo
>
> --
>
> - Arnaldo

--

- Arnaldo

2023-08-18 15:16:39

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] perf parse-regs: Refactor architecture functions

Em Wed, Aug 16, 2023 at 10:07:15AM +0800, Leo Yan escreveu:
> On Tue, Aug 15, 2023 at 03:57:17PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Tue, Aug 15, 2023 at 03:52:38PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Tue, Aug 15, 2023 at 03:45:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > > Agreed, applied to perf-tools-next, sorry for the delay.
> > > >
> > > > Had to add this to make 'perf test python' to work. Please run 'perf
> > > > test' before sending patches.
> > >
> > > One more, please also do a 'make -C tools/perf build-test', with it I
> > > caught this:
> > >
> > > make_no_libunwind_O: cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
> > > cd . && make NO_LIBUNWIND=1 FEATURES_DUMP=/var/home/acme/git/perf-tools-next/tools/perf/BUILD_TEST_FEATURE_DUMP -j32 O=/tmp/tmp.yeEGyQq2HR DESTDIR=/tmp/tmp.ITgoO16jjH
> >
> > +#include "util/env.h"
> >
> > As now we need it for perf_env__arch(ui->machine->env)
>
> Sorry for inconvenience.
>
> I saw this patch series has been picked into the branch:
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/log/?h=tmp.perf-tools-next
>
> If want me to follow up, let me know. Thank you!

Right, I'll fix this ones:

[perfbuilder@five ~]$ grep "unused variable" dm.log/*:*
dm.log/ubuntu:18.04-x-m68k:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
dm.log/ubuntu:18.04-x-riscv64:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
dm.log/ubuntu:18.04-x-sh4:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
dm.log/ubuntu:18.04-x-sparc64:util/evsel.c:848:14: error: unused variable 'arch' [-Werror=unused-variable]
[perfbuilder@five ~]$

And move that to perf-tools-next, we can go on from there.

The above is because we don't define CONFIG_PERF_REGS for these
architectures and thus that variable ends up not being used, so I'm
fixing up like below, in the cset where you made DWARF_MINIMAL_REGS
receive the arch parameter.

Also I haven't checked how gracefully we react when processing a
perf.data collected in one of those unsupported arches, can you please
check?

- Arnaldo

diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 790c1a26bbfe9b4b..de1673057e502de9 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -32,9 +32,6 @@ extern const struct sample_reg sample_reg_masks[];

#include <perf_regs.h>

-#define DWARF_MINIMAL_REGS(arch) \
- ((1ULL << perf_arch_reg_ip(arch)) | (1ULL << perf_arch_reg_sp(arch)))
-
const char *perf_reg_name(int id, const char *arch);
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
uint64_t perf_arch_reg_ip(const char *arch);
@@ -67,11 +64,19 @@ const char *__perf_reg_name_x86(int id);
uint64_t __perf_reg_ip_x86(void);
uint64_t __perf_reg_sp_x86(void);

+static inline uint64_t DWARF_MINIMAL_REGS(const char *arch)
+{
+ return (1ULL << perf_arch_reg_ip(arch)) | (1ULL << perf_arch_reg_sp(arch));
+}
+
#else
#define PERF_REGS_MASK 0
#define PERF_REGS_MAX 0

-#define DWARF_MINIMAL_REGS(arch) PERF_REGS_MASK
+static inline uint64_t DWARF_MINIMAL_REGS(const char *arch __maybe_unused)
+{
+ return PERF_REGS_MASK;
+}

static inline const char *perf_reg_name(int id __maybe_unused, const char *arch __maybe_unused)
{

> > > CC /tmp/tmp.yeEGyQq2HR/util/expr-flex.o
> > > util/unwind-libdw.c: In function ‘memory_read’:
> > > util/unwind-libdw.c:173:28: error: implicit declaration of function ‘perf_env__arch’ [-Werror=implicit-function-declaration]
> > > 173 | const char *arch = perf_env__arch(ui->machine->env);
> > > | ^~~~~~~~~~~~~~
> > > util/unwind-libdw.c:173:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> > > util/unwind-libdw.c: In function ‘unwind__get_entries’:
> > > util/unwind-libdw.c:258:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
> > > 258 | const char *arch = perf_env__arch(ui_buf.machine->env);
> > > | ^~~~~~~~~~~~~~
> > > cc1: all warnings being treated as errors
> > > make[6]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:98: /tmp/tmp.yeEGyQq2HR/util/unwind-libdw.o] Error 1
> > > make[6]: *** Waiting for unfinished jobs....
> > > make[5]: *** [/var/home/acme/git/perf-tools-next/tools/build/Makefile.build:150: util] Error 2
> > > make[4]: *** [Makefile.perf:662: /tmp/tmp.yeEGyQq2HR/perf-in.o] Error 2
> > > make[4]: *** Waiting for unfinished jobs....
> > > CC /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events.o
> > > LD /tmp/tmp.yeEGyQq2HR/pmu-events/pmu-events-in.o
> > > make[3]: *** [Makefile.perf:238: sub-make] Error 2
> > > make[2]: *** [Makefile:70: all] Error 2
> > > make[1]: *** [tests/make:337: make_no_libunwind_O] Error 1
> > > make: *** [Makefile:103: build-test] Error 2
> > > make: Leaving directory '/var/home/acme/git/perf-tools-next/tools/perf'
> > >
> > > real 1m29.784s
> > > user 10m41.597s
> > > sys 2m55.948s
> > > ⬢[acme@toolbox perf-tools-next]$
> > >
> > > I'm trying to fix
> >
> > --
> >
> > - Arnaldo

--

- Arnaldo