linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf callchain: Support riscv cross-platform
@ 2023-11-22 15:55 Paran Lee
  2023-11-22 18:51 ` Namhyung Kim
  2023-11-24 11:47 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Paran Lee @ 2023-11-22 15:55 UTC (permalink / raw)
  To: Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Ian Rogers, Adrian Hunter, Sean Christopherson,
	Li Dong, Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-perf-users, linux-riscv, linux-kernel, shjy180909,
	austindh.kim, honggyu.kp, tegongkang, Paran Lee

Support riscv cross platform callchain unwind.
Tested on RISCV 64 Starfive VisionFive2 Board
------------
$ uname -ra
Linux starfive 5.15.0-starfive #
1 SMP Mon Dec 19 07:56:37 EST 2022 riscv64 GNU/Linux
paran@starfive:~/linux-next$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux bookworm/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
------------
paran@starfive:~/linux-next/tools/perf$
 make  NO_AUXTRACE=1  NO_LIBTRACEEVENT=1 -j4
Auto-detecting system features:
...                                   dwarf: [ on  ]
...                      dwarf_getlocations: [ on  ]
...                                   glibc: [ on  ]
...                                  libbfd: [ on  ]
...                          libbfd-buildid: [ on  ]
...                                  libcap: [ on  ]
...                                  libelf: [ on  ]
...                                 libnuma: [ on  ]
...                  numa_num_possible_cpus: [ on  ]
...                                 libperl: [ on  ]
...                               libpython: [ on  ]
...                               libcrypto: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ OFF ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]
...
CC      arch/riscv/util/dwarf-regs.o
CC      arch/riscv/util/unwind-libunwind.o
...
LINK    perf
------------
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
---
 tools/build/Makefile.feature                  |  2 +
 tools/build/feature/Makefile                  |  8 ++++
 tools/perf/Makefile.config                    | 18 +++++++++
 tools/perf/arch/riscv/util/Build              |  1 +
 tools/perf/arch/riscv/util/unwind-libunwind.c | 17 ++++++++
 tools/perf/check-headers.sh                   |  3 ++
 tools/perf/util/libunwind/riscv.c             | 40 +++++++++++++++++++
 tools/perf/util/unwind-libunwind.c            |  5 +++
 8 files changed, 94 insertions(+)
 create mode 100644 tools/perf/arch/riscv/util/unwind-libunwind.c
 create mode 100644 tools/perf/util/libunwind/riscv.c

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 934e2777a2db..e4140dee1d70 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -93,9 +93,11 @@ FEATURE_TESTS_EXTRA :=                  \
          libunwind-x86_64               \
          libunwind-arm                  \
          libunwind-aarch64              \
+         libunwind-riscv                \
          libunwind-debug-frame          \
          libunwind-debug-frame-arm      \
          libunwind-debug-frame-aarch64  \
+         libunwind-debug-frame-riscv    \
          cxx                            \
          llvm                           \
          llvm-version                   \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index dad79ede4e0a..e3218f98f824 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -45,8 +45,10 @@ FILES=                                          \
          test-libunwind-x86_64.bin              \
          test-libunwind-arm.bin                 \
          test-libunwind-aarch64.bin             \
+		 test-libunwind-riscv.bin               \
          test-libunwind-debug-frame-arm.bin     \
          test-libunwind-debug-frame-aarch64.bin \
+		 test-libunwind-debug-frame-riscv.bin   \
          test-pthread-attr-setaffinity-np.bin   \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
@@ -189,12 +191,18 @@ $(OUTPUT)test-libunwind-arm.bin:
 $(OUTPUT)test-libunwind-aarch64.bin:
 	$(BUILD) -lelf -lunwind-aarch64
 
+$(OUTPUT)test-libunwind-riscv.bin:
+	$(BUILD) -lelf -lunwind-riscv
+
 $(OUTPUT)test-libunwind-debug-frame-arm.bin:
 	$(BUILD) -lelf -lunwind-arm
 
 $(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
 	$(BUILD) -lelf -lunwind-aarch64
 
+$(OUTPUT)test-libunwind-debug-frame-riscv.bin:
+	$(BUILD) -lelf -lunwind-riscv
+
 $(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
 
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index b3e6ed10f40c..b72c1b886b28 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -88,6 +88,8 @@ endif
 
 ifeq ($(SRCARCH),riscv)
   NO_PERF_REGS := 0
+    CFLAGS += -I$(OUTPUT)arch/riscv/include/generated
+    LIBUNWIND_LIBS = -lunwind -lunwind-riscv
 endif
 
 ifeq ($(SRCARCH),csky)
@@ -147,6 +149,7 @@ FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_L
 
 FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
+FEATURE_CHECK_LDFLAGS-libunwind-riscv += -lunwind -lunwind-riscv
 FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
 
@@ -651,6 +654,21 @@ ifndef NO_LIBUNWIND
     endif
   endif
 
+  $(call feature_check,libunwind-riscv)
+  ifeq ($(feature-libunwind-riscv), 1)
+    $(call detected,CONFIG_LIBUNWIND_RISCV)
+    CFLAGS += -DHAVE_LIBUNWIND_RISCV_SUPPORT
+    LDFLAGS += -lunwind-riscv
+    EXTLIBS_LIBUNWIND += -lunwind-riscv
+    have_libunwind = 1
+    $(call feature_check,libunwind-debug-frame-riscv)
+    ifneq ($(feature-libunwind-debug-frame-riscv), 1)
+      msg := $(warning No debug_frame support found in libunwind-riscv);
+      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_riscv
+    endif
+  endif
+
+
   ifneq ($(feature-libunwind), 1)
     msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
     NO_LOCAL_LIBUNWIND := 1
diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
index 603dbb5ae4dc..0f75e25ae638 100644
--- a/tools/perf/arch/riscv/util/Build
+++ b/tools/perf/arch/riscv/util/Build
@@ -2,4 +2,5 @@ perf-y += perf_regs.o
 perf-y += header.o
 
 perf-$(CONFIG_DWARF) += dwarf-regs.o
+perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
 perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/arch/riscv/util/unwind-libunwind.c b/tools/perf/arch/riscv/util/unwind-libunwind.c
new file mode 100644
index 000000000000..e9d6c9c06f84
--- /dev/null
+++ b/tools/perf/arch/riscv/util/unwind-libunwind.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+
+#ifndef REMOTE_UNWIND_LIBUNWIND
+#include <libunwind.h>
+#include "perf_regs.h"
+#include "../../../util/unwind.h"
+#endif
+#include "../../../util/debug.h"
+
+int LIBUNWIND__ARCH_REG_ID(int regnum)
+{
+	if (regnum < 0 || regnum >= PERF_REG_RISCV_MAX)
+		return -EINVAL;
+
+	return regnum;
+}
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 66ba33dbcef2..3a774c9544c4 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -48,6 +48,7 @@ FILES=(
   "arch/loongarch/include/uapi/asm/perf_regs.h"
   "arch/mips/include/uapi/asm/perf_regs.h"
   "arch/powerpc/include/uapi/asm/perf_regs.h"
+  "arch/riscv/include/uapi/asm/perf_regs.h"
   "arch/s390/include/uapi/asm/perf_regs.h"
   "arch/x86/include/uapi/asm/perf_regs.h"
   "arch/x86/include/uapi/asm/kvm.h"
@@ -67,6 +68,8 @@ FILES=(
   "arch/mips/include/uapi/asm/errno.h"
   "arch/parisc/include/uapi/asm/errno.h"
   "arch/powerpc/include/uapi/asm/errno.h"
+  "arch/riscv/include/uapi/asm/kvm.h"
+  "arch/riscv/include/uapi/asm/unistd.h"
   "arch/sparc/include/uapi/asm/errno.h"
   "arch/x86/include/uapi/asm/errno.h"
   "include/asm-generic/bitops/arch_hweight.h"
diff --git a/tools/perf/util/libunwind/riscv.c b/tools/perf/util/libunwind/riscv.c
new file mode 100644
index 000000000000..c340c5609161
--- /dev/null
+++ b/tools/perf/util/libunwind/riscv.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This file setups defines to compile arch specific binary from the
+ * generic one.
+ *
+ * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
+ * name and the definition of this function is included directly from
+ * 'arch/riscv/util/unwind-libunwind.c', to make sure that this function
+ * is defined no matter what arch the host is.
+ *
+ * Finally, the arch specific unwind methods are exported which will
+ * be assigned to each riscv thread.
+ */
+
+#define REMOTE_UNWIND_LIBUNWIND
+
+/* Define arch specific functions & regs for libunwind, should be
+ * defined before including "unwind.h"
+ */
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__riscv_reg_id(regnum)
+
+#include "unwind.h"
+#include "libunwind-riscv.h"
+#define perf_event_riscv_regs perf_event_riscv64_regs
+#include <../../../arch/riscv/include/uapi/asm/perf_regs.h>
+#undef perf_event_riscv_regs
+#include "../../arch/riscv/util/unwind-libunwind.c"
+
+/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind,
+ * assign NO_LIBUNWIND_DEBUG_FRAME_RISCV64 to it for compiling riscv
+ * unwind methods.
+ */
+#undef NO_LIBUNWIND_DEBUG_FRAME
+#ifdef NO_LIBUNWIND_DEBUG_FRAME_RISCV
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+#include "util/unwind-libunwind-local.c"
+
+struct unwind_libunwind_ops *
+riscv_unwind_libunwind_ops = &_unwind_libunwind_ops;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 76cd63de80a8..52190f1eaf0d 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -11,6 +11,7 @@
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
 struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
+struct unwind_libunwind_ops __weak *riscv_unwind_libunwind_ops;
 
 static void unwind__register_ops(struct maps *maps, struct unwind_libunwind_ops *ops)
 {
@@ -54,6 +55,10 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
 		if (dso_type == DSO__TYPE_64BIT)
 			ops = arm64_unwind_libunwind_ops;
 	}
+	} else if (!strcmp(arch, "riscv64") || !strcmp(arch, "riscv")) {
+		if (dso_type == DSO__TYPE_64BIT)
+			ops = riscv_unwind_libunwind_ops;
+	}
 
 	if (!ops) {
 		pr_warning_once("unwind: target platform=%s is not supported\n", arch);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf callchain: Support riscv cross-platform
  2023-11-22 15:55 [PATCH] perf callchain: Support riscv cross-platform Paran Lee
@ 2023-11-22 18:51 ` Namhyung Kim
  2023-11-24 11:47 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2023-11-22 18:51 UTC (permalink / raw)
  To: Paran Lee
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Sean Christopherson, Li Dong, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, linux-perf-users, linux-riscv,
	linux-kernel, shjy180909, austindh.kim, honggyu.kp, tegongkang

Hi Paran,

On Wed, Nov 22, 2023 at 7:56 AM Paran Lee <p4ranlee@gmail.com> wrote:
>
> Support riscv cross platform callchain unwind.
> Tested on RISCV 64 Starfive VisionFive2 Board
> ------------
> $ uname -ra
> Linux starfive 5.15.0-starfive #
> 1 SMP Mon Dec 19 07:56:37 EST 2022 riscv64 GNU/Linux
> paran@starfive:~/linux-next$ cat /etc/os-release
> PRETTY_NAME="Debian GNU/Linux bookworm/sid"
> NAME="Debian GNU/Linux"
> ID=debian
> HOME_URL="https://www.debian.org/"
> SUPPORT_URL="https://www.debian.org/support"
> BUG_REPORT_URL="https://bugs.debian.org/"
> ------------
> paran@starfive:~/linux-next/tools/perf$
>  make  NO_AUXTRACE=1  NO_LIBTRACEEVENT=1 -j4
> Auto-detecting system features:
> ...                                   dwarf: [ on  ]
> ...                      dwarf_getlocations: [ on  ]
> ...                                   glibc: [ on  ]
> ...                                  libbfd: [ on  ]
> ...                          libbfd-buildid: [ on  ]
> ...                                  libcap: [ on  ]
> ...                                  libelf: [ on  ]
> ...                                 libnuma: [ on  ]
> ...                  numa_num_possible_cpus: [ on  ]
> ...                                 libperl: [ on  ]
> ...                               libpython: [ on  ]
> ...                               libcrypto: [ on  ]
> ...                               libunwind: [ on  ]
> ...                      libdw-dwarf-unwind: [ on  ]
> ...                                    zlib: [ on  ]
> ...                                    lzma: [ on  ]
> ...                               get_cpuid: [ OFF ]
> ...                                     bpf: [ on  ]
> ...                                  libaio: [ on  ]
> ...                                 libzstd: [ on  ]
> ...
> CC      arch/riscv/util/dwarf-regs.o
> CC      arch/riscv/util/unwind-libunwind.o
> ...
> LINK    perf
> ------------
> Signed-off-by: Paran Lee <p4ranlee@gmail.com>
> ---
>  tools/build/Makefile.feature                  |  2 +
>  tools/build/feature/Makefile                  |  8 ++++
>  tools/perf/Makefile.config                    | 18 +++++++++
>  tools/perf/arch/riscv/util/Build              |  1 +
>  tools/perf/arch/riscv/util/unwind-libunwind.c | 17 ++++++++
>  tools/perf/check-headers.sh                   |  3 ++
>  tools/perf/util/libunwind/riscv.c             | 40 +++++++++++++++++++
>  tools/perf/util/unwind-libunwind.c            |  5 +++
>  8 files changed, 94 insertions(+)
>  create mode 100644 tools/perf/arch/riscv/util/unwind-libunwind.c
>  create mode 100644 tools/perf/util/libunwind/riscv.c
>
> diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
> index 934e2777a2db..e4140dee1d70 100644
> --- a/tools/build/Makefile.feature
> +++ b/tools/build/Makefile.feature
> @@ -93,9 +93,11 @@ FEATURE_TESTS_EXTRA :=                  \
>           libunwind-x86_64               \
>           libunwind-arm                  \
>           libunwind-aarch64              \
> +         libunwind-riscv                \
>           libunwind-debug-frame          \
>           libunwind-debug-frame-arm      \
>           libunwind-debug-frame-aarch64  \
> +         libunwind-debug-frame-riscv    \
>           cxx                            \
>           llvm                           \
>           llvm-version                   \
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index dad79ede4e0a..e3218f98f824 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -45,8 +45,10 @@ FILES=                                          \
>           test-libunwind-x86_64.bin              \
>           test-libunwind-arm.bin                 \
>           test-libunwind-aarch64.bin             \
> +                test-libunwind-riscv.bin               \
>           test-libunwind-debug-frame-arm.bin     \
>           test-libunwind-debug-frame-aarch64.bin \
> +                test-libunwind-debug-frame-riscv.bin   \

Whitespace damaged?  Also I think you need to add
the source files for the feature checks.

Thanks,
Namhyung


>           test-pthread-attr-setaffinity-np.bin   \
>           test-pthread-barrier.bin              \
>           test-stackprotector-all.bin            \
> @@ -189,12 +191,18 @@ $(OUTPUT)test-libunwind-arm.bin:
>  $(OUTPUT)test-libunwind-aarch64.bin:
>         $(BUILD) -lelf -lunwind-aarch64
>
> +$(OUTPUT)test-libunwind-riscv.bin:
> +       $(BUILD) -lelf -lunwind-riscv
> +
>  $(OUTPUT)test-libunwind-debug-frame-arm.bin:
>         $(BUILD) -lelf -lunwind-arm
>
>  $(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
>         $(BUILD) -lelf -lunwind-aarch64
>
> +$(OUTPUT)test-libunwind-debug-frame-riscv.bin:
> +       $(BUILD) -lelf -lunwind-riscv
> +
>  $(OUTPUT)test-libaudit.bin:
>         $(BUILD) -laudit
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index b3e6ed10f40c..b72c1b886b28 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -88,6 +88,8 @@ endif
>
>  ifeq ($(SRCARCH),riscv)
>    NO_PERF_REGS := 0
> +    CFLAGS += -I$(OUTPUT)arch/riscv/include/generated
> +    LIBUNWIND_LIBS = -lunwind -lunwind-riscv
>  endif
>
>  ifeq ($(SRCARCH),csky)
> @@ -147,6 +149,7 @@ FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_L
>
>  FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
>  FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
> +FEATURE_CHECK_LDFLAGS-libunwind-riscv += -lunwind -lunwind-riscv
>  FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
>  FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
>
> @@ -651,6 +654,21 @@ ifndef NO_LIBUNWIND
>      endif
>    endif
>
> +  $(call feature_check,libunwind-riscv)
> +  ifeq ($(feature-libunwind-riscv), 1)
> +    $(call detected,CONFIG_LIBUNWIND_RISCV)
> +    CFLAGS += -DHAVE_LIBUNWIND_RISCV_SUPPORT
> +    LDFLAGS += -lunwind-riscv
> +    EXTLIBS_LIBUNWIND += -lunwind-riscv
> +    have_libunwind = 1
> +    $(call feature_check,libunwind-debug-frame-riscv)
> +    ifneq ($(feature-libunwind-debug-frame-riscv), 1)
> +      msg := $(warning No debug_frame support found in libunwind-riscv);
> +      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_riscv
> +    endif
> +  endif
> +
> +
>    ifneq ($(feature-libunwind), 1)
>      msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
>      NO_LOCAL_LIBUNWIND := 1
> diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
> index 603dbb5ae4dc..0f75e25ae638 100644
> --- a/tools/perf/arch/riscv/util/Build
> +++ b/tools/perf/arch/riscv/util/Build
> @@ -2,4 +2,5 @@ perf-y += perf_regs.o
>  perf-y += header.o
>
>  perf-$(CONFIG_DWARF) += dwarf-regs.o
> +perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
>  perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
> diff --git a/tools/perf/arch/riscv/util/unwind-libunwind.c b/tools/perf/arch/riscv/util/unwind-libunwind.c
> new file mode 100644
> index 000000000000..e9d6c9c06f84
> --- /dev/null
> +++ b/tools/perf/arch/riscv/util/unwind-libunwind.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <errno.h>
> +
> +#ifndef REMOTE_UNWIND_LIBUNWIND
> +#include <libunwind.h>
> +#include "perf_regs.h"
> +#include "../../../util/unwind.h"
> +#endif
> +#include "../../../util/debug.h"
> +
> +int LIBUNWIND__ARCH_REG_ID(int regnum)
> +{
> +       if (regnum < 0 || regnum >= PERF_REG_RISCV_MAX)
> +               return -EINVAL;
> +
> +       return regnum;
> +}
> diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
> index 66ba33dbcef2..3a774c9544c4 100755
> --- a/tools/perf/check-headers.sh
> +++ b/tools/perf/check-headers.sh
> @@ -48,6 +48,7 @@ FILES=(
>    "arch/loongarch/include/uapi/asm/perf_regs.h"
>    "arch/mips/include/uapi/asm/perf_regs.h"
>    "arch/powerpc/include/uapi/asm/perf_regs.h"
> +  "arch/riscv/include/uapi/asm/perf_regs.h"
>    "arch/s390/include/uapi/asm/perf_regs.h"
>    "arch/x86/include/uapi/asm/perf_regs.h"
>    "arch/x86/include/uapi/asm/kvm.h"
> @@ -67,6 +68,8 @@ FILES=(
>    "arch/mips/include/uapi/asm/errno.h"
>    "arch/parisc/include/uapi/asm/errno.h"
>    "arch/powerpc/include/uapi/asm/errno.h"
> +  "arch/riscv/include/uapi/asm/kvm.h"
> +  "arch/riscv/include/uapi/asm/unistd.h"
>    "arch/sparc/include/uapi/asm/errno.h"
>    "arch/x86/include/uapi/asm/errno.h"
>    "include/asm-generic/bitops/arch_hweight.h"
> diff --git a/tools/perf/util/libunwind/riscv.c b/tools/perf/util/libunwind/riscv.c
> new file mode 100644
> index 000000000000..c340c5609161
> --- /dev/null
> +++ b/tools/perf/util/libunwind/riscv.c
> @@ -0,0 +1,40 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * This file setups defines to compile arch specific binary from the
> + * generic one.
> + *
> + * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
> + * name and the definition of this function is included directly from
> + * 'arch/riscv/util/unwind-libunwind.c', to make sure that this function
> + * is defined no matter what arch the host is.
> + *
> + * Finally, the arch specific unwind methods are exported which will
> + * be assigned to each riscv thread.
> + */
> +
> +#define REMOTE_UNWIND_LIBUNWIND
> +
> +/* Define arch specific functions & regs for libunwind, should be
> + * defined before including "unwind.h"
> + */
> +#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__riscv_reg_id(regnum)
> +
> +#include "unwind.h"
> +#include "libunwind-riscv.h"
> +#define perf_event_riscv_regs perf_event_riscv64_regs
> +#include <../../../arch/riscv/include/uapi/asm/perf_regs.h>
> +#undef perf_event_riscv_regs
> +#include "../../arch/riscv/util/unwind-libunwind.c"
> +
> +/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind,
> + * assign NO_LIBUNWIND_DEBUG_FRAME_RISCV64 to it for compiling riscv
> + * unwind methods.
> + */
> +#undef NO_LIBUNWIND_DEBUG_FRAME
> +#ifdef NO_LIBUNWIND_DEBUG_FRAME_RISCV
> +#define NO_LIBUNWIND_DEBUG_FRAME
> +#endif
> +#include "util/unwind-libunwind-local.c"
> +
> +struct unwind_libunwind_ops *
> +riscv_unwind_libunwind_ops = &_unwind_libunwind_ops;
> diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
> index 76cd63de80a8..52190f1eaf0d 100644
> --- a/tools/perf/util/unwind-libunwind.c
> +++ b/tools/perf/util/unwind-libunwind.c
> @@ -11,6 +11,7 @@
>  struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
>  struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
>  struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
> +struct unwind_libunwind_ops __weak *riscv_unwind_libunwind_ops;
>
>  static void unwind__register_ops(struct maps *maps, struct unwind_libunwind_ops *ops)
>  {
> @@ -54,6 +55,10 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized
>                 if (dso_type == DSO__TYPE_64BIT)
>                         ops = arm64_unwind_libunwind_ops;
>         }
> +       } else if (!strcmp(arch, "riscv64") || !strcmp(arch, "riscv")) {
> +               if (dso_type == DSO__TYPE_64BIT)
> +                       ops = riscv_unwind_libunwind_ops;
> +       }
>
>         if (!ops) {
>                 pr_warning_once("unwind: target platform=%s is not supported\n", arch);
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf callchain: Support riscv cross-platform
  2023-11-22 15:55 [PATCH] perf callchain: Support riscv cross-platform Paran Lee
  2023-11-22 18:51 ` Namhyung Kim
@ 2023-11-24 11:47 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-11-24 11:47 UTC (permalink / raw)
  To: Paran Lee, Namhyung Kim, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Sean Christopherson, Li Dong, Paul Walmsley,
	Palmer Dabbelt, Albert Ou
  Cc: oe-kbuild-all, linux-perf-users, linux-riscv, linux-kernel,
	shjy180909, austindh.kim, honggyu.kp, tegongkang, Paran Lee

Hi Paran,

kernel test robot noticed the following build errors:

[auto build test ERROR on perf-tools-next/perf-tools-next]
[also build test ERROR on tip/perf/core perf-tools/perf-tools linus/master acme/perf/core v6.7-rc2 next-20231124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Paran-Lee/perf-callchain-Support-riscv-cross-platform/20231123-000232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
patch link:    https://lore.kernel.org/r/20231122155548.2449-1-p4ranlee%40gmail.com
patch subject: [PATCH] perf callchain: Support riscv cross-platform
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231124/202311241453.S2nsKqhx-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311241453.S2nsKqhx-lkp@intel.com/

All errors (new ones prefixed by >>):

   Makefile.config:1176: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
     PERF_VERSION = 6.6.rc1.g1f4d296e5f76
   util/unwind-libunwind.c: In function 'unwind__prepare_access':
>> util/unwind-libunwind.c:43:17: error: label 'out_register' used but not defined
      43 |                 goto out_register;
         |                 ^~~~
>> util/unwind-libunwind.c:28:13: error: unused variable 'err' [-Werror=unused-variable]
      28 |         int err;
         |             ^~~
>> util/unwind-libunwind.c:25:38: error: variable 'ops' set but not used [-Werror=unused-but-set-variable]
      25 |         struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
         |                                      ^~~
   util/unwind-libunwind.c: At top level:
>> util/unwind-libunwind.c:58:11: error: expected identifier or '(' before 'else'
      58 |         } else if (!strcmp(arch, "riscv64") || !strcmp(arch, "riscv")) {
         |           ^~~~
>> util/unwind-libunwind.c:63:9: error: expected identifier or '(' before 'if'
      63 |         if (!ops) {
         |         ^~
>> util/unwind-libunwind.c:67:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
      67 | out_register:
         |             ^
>> util/unwind-libunwind.c:70:9: error: data definition has no type or storage class [-Werror]
      70 |         err = maps__unwind_libunwind_ops(maps)->prepare_access(maps);
         |         ^~~
>> util/unwind-libunwind.c:70:9: error: type defaults to 'int' in declaration of 'err' [-Werror=implicit-int]
>> util/unwind-libunwind.c:70:42: error: 'maps' undeclared here (not in a function)
      70 |         err = maps__unwind_libunwind_ops(maps)->prepare_access(maps);
         |                                          ^~~~
   util/unwind-libunwind.c:71:9: error: expected identifier or '(' before 'if'
      71 |         if (initialized)
         |         ^~
>> util/unwind-libunwind.c:73:9: error: expected identifier or '(' before 'return'
      73 |         return err;
         |         ^~~~~~
>> util/unwind-libunwind.c:74:1: error: expected identifier or '(' before '}' token
      74 | }
         | ^
   util/unwind-libunwind.c: In function 'unwind__flush_access':
>> util/unwind-libunwind.c:76:40: error: declaration of 'maps' shadows previous non-variable [-Werror=shadow]
      76 | void unwind__flush_access(struct maps *maps)
         |                           ~~~~~~~~~~~~~^~~~
   util/unwind-libunwind.c: In function 'unwind__finish_access':
   util/unwind-libunwind.c:84:41: error: declaration of 'maps' shadows previous non-variable [-Werror=shadow]
      84 | void unwind__finish_access(struct maps *maps)
         |                            ~~~~~~~~~~~~~^~~~
   util/unwind-libunwind.c: In function 'unwind__prepare_access':
>> util/unwind-libunwind.c:58:9: error: control reaches end of non-void function [-Werror=return-type]
      58 |         } else if (!strcmp(arch, "riscv64") || !strcmp(arch, "riscv")) {
         |         ^
   util/unwind-libunwind.c: At top level:
>> util/unwind-libunwind.c:16:13: error: 'unwind__register_ops' defined but not used [-Werror=unused-function]
      16 | static void unwind__register_ops(struct maps *maps, struct unwind_libunwind_ops *ops)
         |             ^~~~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors
   make[7]: *** [tools/build/Makefile.build:105: tools/perf/util/unwind-libunwind.o] Error 1
   make[7]: *** Waiting for unfinished jobs....
   make[6]: *** [tools/build/Makefile.build:158: util] Error 2
   make[5]: *** [Makefile.perf:669: tools/perf/perf-in.o] Error 2
   make[5]: *** Waiting for unfinished jobs....
   make[4]: *** [Makefile.perf:242: sub-make] Error 2
   make[3]: *** [Makefile:70: all] Error 2
--
>> diff: tools/arch/riscv/include/uapi/asm/kvm.h: No such file or directory
     diff -u tools/include/uapi/linux/kvm.h include/uapi/linux/kvm.h
     diff -u tools/include/uapi/linux/mount.h include/uapi/linux/mount.h
     diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h
     diff -u tools/arch/x86/include/asm/disabled-features.h arch/x86/include/asm/disabled-features.h
     diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h
     diff -u tools/arch/x86/include/uapi/asm/prctl.h arch/x86/include/uapi/asm/prctl.h
     diff -u tools/arch/arm64/include/uapi/asm/perf_regs.h arch/arm64/include/uapi/asm/perf_regs.h
     diff -u tools/arch/s390/include/uapi/asm/kvm.h arch/s390/include/uapi/asm/kvm.h
     diff -u tools/arch/riscv/include/uapi/asm/kvm.h arch/riscv/include/uapi/asm/kvm.h
     diff -u tools/arch/riscv/include/uapi/asm/unistd.h arch/riscv/include/uapi/asm/unistd.h

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-24 11:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 15:55 [PATCH] perf callchain: Support riscv cross-platform Paran Lee
2023-11-22 18:51 ` Namhyung Kim
2023-11-24 11:47 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).