Skip to contentSkip to conversation

csky: Add perf callchin support

PATCH Mao Han 1 participant 1 message Apr 1, 2019

Subsystems (2)
lore
Share & tools
lore

Mao Han

author
#0 lore raw

Hi,
This patch set add perf callchain support for C-SKY. Including perf callchain support using frame pointer, perf registers definition, registers initiation for libdw unwinding and some build infrastructure.

Regards,
Mao Han

From c538e33c6705c9284264a5035185edb55ace1786 Mon Sep 17 00:00:00 2001
Message-Id: <c538e33c6705c9284264a5035185edb55ace1786.1554094500.git.han_mao@c-sky.com>
From: Mao Han <[email protected]>
Date: Fri, 8 Mar 2019 13:21:33 +0800
Subject: [PATCH 1/3] csky: Add perf callchin support

This patch add support for perf callchain sampling on csky platform. Both fp and dwarf unwinding are supported with this patch. When fp is used to unwind the stack, the program being sampled and the C library need to be compiled with -mbacktrace for user callchains, kernel callchains require CONFIG_STACKTRACE = y. Unwinding with dwarf requires compilation with -fexceptions, otherwise there will be not debug information inside the excutable file.

---
 arch/csky/Kconfig                      |   2 +
 arch/csky/include/uapi/asm/perf_regs.h |  48 ++++++++++++
 arch/csky/kernel/Makefile              |   2 +
 arch/csky/kernel/perf_callchain.c      | 133 +++++++++++++++++++++++++++++++++
 arch/csky/kernel/perf_regs.c           |  41 ++++++++++
 5 files changed, 226 insertions(+)
 create mode 100644 arch/csky/include/uapi/asm/perf_regs.h
 create mode 100644 arch/csky/kernel/perf_callchain.c
 create mode 100644 arch/csky/kernel/perf_regs.c
arch/csky/Kconfig +2 -0
index 398113c..93b535d 100644
@@ -35,6 +35,8 @@ config CSKY
 	select HAVE_KERNEL_LZO
 	select HAVE_KERNEL_LZMA
 	select HAVE_PERF_EVENTS
+	select HAVE_PERF_REGS
+	select HAVE_PERF_USER_STACK_DUMP
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
arch/csky/include/uapi/asm/perf_regs.h new file +48 -0

48 lines not on this page · raw message

arch/csky/kernel/Makefile +2 -0
index 484e6d3..3549d0d 100644
@@ -9,6 +9,8 @@ obj-$(CONFIG_SMP)			+= smp.o
 obj-$(CONFIG_FUNCTION_TRACER)		+= ftrace.o
 obj-$(CONFIG_STACKTRACE)		+= stacktrace.o
 obj-$(CONFIG_CSKY_PMU_V1)		+= perf_event.o
+obj-$(CONFIG_PERF_EVENTS)               += perf_callchain.o
+obj-$(CONFIG_HAVE_PERF_REGS)            += perf_regs.o
 
 ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
arch/csky/kernel/perf_callchain.c new file +133 -0

133 lines not on this page · raw message

arch/csky/kernel/perf_regs.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.7.4

From adaa5acdec45e65819343b4362efd50fe0442cfa Mon Sep 17 00:00:00 2001
Message-Id: <adaa5acdec45e65819343b4362efd50fe0442cfa.1554094500.git.han_mao@c-sky.com>
In-Reply-To: <c538e33c6705c9284264a5035185edb55ace1786.1554094500.git.han_mao@c-sky.com>
References: <c538e33c6705c9284264a5035185edb55ace1786.1554094500.git.han_mao@c-sky.com>
From: Mao Han <[email protected]>
Date: Fri, 8 Mar 2019 13:30:59 +0800
Subject: [PATCH 2/3] perf: use hweight64 instead of hweight_long

On C-SKY platform, there are 38 registers inside pt_regs. The same layout is directly used by perf to keep uniformity. The mask is 64 bits, but hweight_long can only handle 32 bits, which will casue perf.data analysis mismatch on C-SKY.

---
 tools/perf/util/evsel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evsel.c +1 -1
index dbc0466..89b87a0 100644
@@ -2305,7 +2305,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 		if (data->user_regs.abi) {
 			u64 mask = evsel->attr.sample_regs_user;
 
-			sz = hweight_long(mask) * sizeof(u64);
+			sz = hweight64(mask) * sizeof(u64);
 			OVERFLOW_CHECK(array, sz, max_size);
 			data->user_regs.mask = mask;
 			data->user_regs.regs = (u64 *)array;
Signature · 1 line
2.7.4

From ea9e6905a22065e980234e7ed6b1d802d8bb132f Mon Sep 17 00:00:00 2001
Message-Id: <ea9e6905a22065e980234e7ed6b1d802d8bb132f.1554094500.git.han_mao@c-sky.com>
In-Reply-To: <c538e33c6705c9284264a5035185edb55ace1786.1554094500.git.han_mao@c-sky.com>
References: <c538e33c6705c9284264a5035185edb55ace1786.1554094500.git.han_mao@c-sky.com>
From: Mao Han <[email protected]>
Date: Fri, 8 Mar 2019 13:55:20 +0800
Subject: [PATCH 3/3] perf: add C-SKY dwarf support

This patch add registers initialization and display support for C-SKY.

---
 tools/arch/csky/include/uapi/asm/perf_regs.h | 48 ++++++++++++++
 tools/perf/Makefile.config                   |  6 +-
 tools/perf/arch/csky/Build                   |  1 +
 tools/perf/arch/csky/Makefile                |  3 +
 tools/perf/arch/csky/include/perf_regs.h     | 98 ++++++++++++++++++++++++++++
 tools/perf/arch/csky/util/Build              |  2 +
 tools/perf/arch/csky/util/dwarf-regs.c       | 25 +++++++
 tools/perf/arch/csky/util/unwind-libdw.c     | 58 ++++++++++++++++
 8 files changed, 240 insertions(+), 1 deletion(-)
 create mode 100644 tools/arch/csky/include/uapi/asm/perf_regs.h
 create mode 100644 tools/perf/arch/csky/Build
 create mode 100644 tools/perf/arch/csky/Makefile
 create mode 100644 tools/perf/arch/csky/include/perf_regs.h
 create mode 100644 tools/perf/arch/csky/util/Build
 create mode 100644 tools/perf/arch/csky/util/dwarf-regs.c
 create mode 100644 tools/perf/arch/csky/util/unwind-libdw.c
tools/arch/csky/include/uapi/asm/perf_regs.h new file +48 -0

48 lines not on this page · raw message

tools/perf/Makefile.config +5 -1
index b441c88..20f68d8 100644
@@ -59,6 +59,10 @@ ifeq ($(SRCARCH),arm64)
   LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
 endif
 
+ifeq ($(SRCARCH),csky)
+  NO_PERF_REGS := 0
+endif
+
 ifeq ($(ARCH),s390)
   NO_PERF_REGS := 0
   NO_SYSCALL_TABLE := 0
@@ -77,7 +81,7 @@ endif
 # Disable it on all other architectures in case libdw unwind
 # support is detected in system. Add supported architectures
 # to the check.
-ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390))
+ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky))
   NO_LIBDW_DWARF_UNWIND := 1
 endif
 
tools/perf/arch/csky/Build new file +1 -0
new file mode 100644
index 0000000..54afe4a
@@ -0,0 +1 @@
+libperf-y += util/
tools/perf/arch/csky/Makefile new file +3 -0
new file mode 100644
index 0000000..7fbca17
@@ -0,0 +1,3 @@
+ifndef NO_DWARF
+PERF_HAVE_DWARF_REGS := 1
+endif
tools/perf/arch/csky/include/perf_regs.h new file +98 -0

98 lines not on this page · raw message

tools/perf/arch/csky/util/Build new file +2 -0
new file mode 100644
index 0000000..8e45471
@@ -0,0 +1,2 @@
+libperf-$(CONFIG_DWARF) += dwarf-regs.o
+libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/csky/util/dwarf-regs.c new file +25 -0
new file mode 100644
index 0000000..d9b78e2
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+// Mapping of DWARF debug register numbers into register names.
+
+#include <stddef.h>
+#include <dwarf-regs.h>
+
+#define CSKY_MAX_REGS 71
+
+const char *csky_regs_table[CSKY_MAX_REGS] = {
+        "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
+        "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%sp", "%lr",
+        "%r16", "%r17", "%r18", "%r19", "%r20", "%21", "%22", "%23",
+        "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%tls",
+        "%pc", "%cc", "%hi", "%lo", "%rr", "%rr", "%rr", "%rr",
+        "%rr", "%rr", "%rr", "%rr", "%rr", "%rr", "%rr", "%rr",
+        "%rr", "%rr", "%rr", "%rr", "%vr0", "%vr1", "%vr2", "%vr3",
+        "%vr4", "%vr5", "%vr6", "%vr7", "%vr8", "%vr9", "%vr10", "%vr11",
+        "%vr12", "%vr13", "%vr14", "%vr15", "%rr", "%rr", "%epc",
+};
+
+const char *get_arch_regstr(unsigned int n)
+{
+        return (n < CSKY_MAX_REGS) ? csky_regs_table[n] : NULL;
+}
tools/perf/arch/csky/util/unwind-libdw.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4