Skip to contentSkip to conversation

Support mips unwinding and dwarf-regs.

PATCH New Archer Yan 1 participant 2 messages Sep 11, 2019

Subsystems (2)
lore
Share & tools
lore
author
#1 lore raw

PATCH 2/2 Support extracting off-line stack traces from user-space with perf.

In reply to Archer Yan

1. Add perf_event_mips_regs/perf_reg_value/perf_reg_validate to support features HAVE_PERF_REGS/HAVE_PERF_USER_STACK_DUMP in kernel;
2. Add dwarf reg table in perf tool for dwarf unwinding.

[[email protected]: Repick this patch for unwinding userstack backtrace
by perf and libunwind on MIPS based CPU.]

[[email protected]: Add perf_get_regs_user() which is required after 'commit 88a7c26af8da ("perf: Move task_pt_regs sampling into arch code")'.]

Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 arch/mips/Kconfig                             |  2 +
 arch/mips/include/uapi/asm/perf_regs.h        | 42 ++++++++++++
 arch/mips/kernel/Makefile                     |  2 +-
 arch/mips/kernel/perf_regs.c                  | 67 +++++++++++++++++++
 tools/perf/Makefile.config                    |  6 ++
 tools/perf/arch/mips/Build                    |  2 +-
 tools/perf/arch/mips/Makefile                 |  4 --
 .../perf/arch/mips/include/dwarf-regs-table.h | 31 +++++++++
 tools/perf/arch/mips/include/perf_regs.h      |  2 +-
 tools/perf/arch/mips/util/Build               |  4 +-
 tools/perf/arch/mips/util/dwarf-regs.c        |  3 +-
 tools/perf/arch/mips/util/unwind-libunwind.c  |  3 +-
 tools/perf/util/dwarf-regs.c                  |  3 +
 13 files changed, 159 insertions(+), 12 deletions(-)
 create mode 100644 arch/mips/include/uapi/asm/perf_regs.h
 create mode 100644 arch/mips/kernel/perf_regs.c
 create mode 100644 tools/perf/arch/mips/include/dwarf-regs-table.h
arch/mips/Kconfig +2 -0
index d50fafd7bf3a..4b68beb285b5 100644
@@ -69,6 +69,8 @@ config MIPS
 	select HAVE_NMI
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select HAVE_PERF_REGS
+	select HAVE_PERF_USER_STACK_DUMP
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RSEQ
 	select HAVE_STACKPROTECTOR
arch/mips/include/uapi/asm/perf_regs.h new file +42 -0

42 lines not on this page · raw message

arch/mips/kernel/Makefile +1 -1
index 89b07ea8d249..d8fb04540505 100644
@@ -100,7 +100,7 @@ CFLAGS_cpu-bugs64.o	= $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/n
 
 obj-$(CONFIG_HAVE_STD_PC_SERIAL_PORT)	+= 8250-platform.o
 
-obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o
+obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o perf_regs.o
 obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event_mipsxx.o
 
 obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o
arch/mips/kernel/perf_regs.c new file +67 -0

67 lines not on this page · raw message

tools/perf/Makefile.config +6 -0
index 89ac5a1f1550..f382c282fb8e 100644
@@ -74,6 +74,12 @@ ifeq ($(NO_PERF_REGS),0)
   $(call detected,CONFIG_PERF_REGS)
 endif
 
+ifeq ($(ARCH),mips)
+  NO_PERF_REGS := 0
+  CFLAGS += -I../../arch/mips/include/uapi -I../../arch/mips/include/generated/uapi
+  LIBUNWIND_LIBS = -lunwind -lunwind-mips
+endif
+
 ifneq ($(NO_SYSCALL_TABLE),1)
   CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
 endif
tools/perf/arch/mips/Build +1 -1
index 54afe4a467e7..e4e5f33c84d8 100644
@@ -1 +1 @@
-libperf-y += util/
+perf-y += util/
tools/perf/arch/mips/Makefile +0 -4
index fe9b61e322a5..7fbca175099e 100644
@@ -1,7 +1,3 @@
 ifndef NO_DWARF
 PERF_HAVE_DWARF_REGS := 1
-LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
-endif
-ifndef NO_LIBUNWIND
-LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o
 endif
tools/perf/arch/mips/include/dwarf-regs-table.h new file +31 -0
new file mode 100644
index 000000000000..169a3f9679d5
@@ -0,0 +1,31 @@
+/*
+ * dwarf-regs-table.h : Mapping of DWARF debug register numbers into
+ * register names.
+ *
+ * Copyright (C) 2013 Cavium, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifdef DEFINE_DWARF_REGSTR_TABLE
+#undef REG_DWARFNUM_NAME
+#define REG_DWARFNUM_NAME(reg, idx)	([idx] = "$" #reg)
+static const char *mips_regstr_tbl[] = {
+	"$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+	"$10", "$11", "$12", "$13", "$14", "$15", "$16", "$17", "$18", "$19",
+	"$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27", "$28", "$29",
+	"$30", "$31",
+	REG_DWARFNUM_NAME(hi,   64),
+	REG_DWARFNUM_NAME(lo,   65),
+
+};
+#endif
tools/perf/arch/mips/include/perf_regs.h +1 -1
index bc47b25d95dd..871bc6febe22 100644
@@ -3,9 +3,9 @@
 #define ARCH_PERF_REGS_H
 
 #include <stdlib.h>
-#include "../../util/types.h"
 #include <asm/perf_regs.h>
 
+#define PERF_REGS_MAX PERF_REG_MIPS_MAX
 #define PERF_REG_IP PERF_REG_MIPS_PC
 #define PERF_REG_SP PERF_REG_MIPS_R29
 
tools/perf/arch/mips/util/Build +2 -2
index 7da83b5ebc4c..678a68830ceb 100644
@@ -1,2 +1,2 @@
-libperf-$(CONFIG_DWARF)                += dwarf-regs.o
-libperf-$(CONFIG_LIBUNWIND)    += unwind-libunwind.o
+perf-$(CONFIG_DWARF)                += dwarf-regs.o
+perf-$(CONFIG_LIBUNWIND)    += unwind-libunwind.o
tools/perf/arch/mips/util/dwarf-regs.c +1 -2
index 165e0179ea11..423abf158c99 100644
@@ -14,8 +14,7 @@
  * GNU General Public License for more details.
  *
  */
-
-#include <libio.h>
+#include <stdio.h>
 #include <dwarf-regs.h>
 
 static const char *mips_gpr_names[32] = {
tools/perf/arch/mips/util/unwind-libunwind.c +2 -1
index 7af25427943f..0d8c99c29da6 100644
@@ -4,8 +4,9 @@
 #include <libunwind.h>
 #include "perf_regs.h"
 #include "../../util/unwind.h"
+#include "util/debug.h"
 
-int unwind__arch_reg_id(int regnum)
+int libunwind__arch_reg_id(int regnum)
 {
 	switch (regnum) {
 	case UNW_MIPS_R1 ... UNW_MIPS_R25:
tools/perf/util/dwarf-regs.c +3 -0
index db55eddce8cd..0bf60e6d28b5 100644
@@ -25,6 +25,7 @@
 #include "../arch/s390/include/dwarf-regs-table.h"
 #include "../arch/sparc/include/dwarf-regs-table.h"
 #include "../arch/xtensa/include/dwarf-regs-table.h"
+#include "../arch/mips/include/dwarf-regs-table.h"
 
 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL)
 
@@ -54,6 +55,8 @@ const char *get_dwarf_regstr(unsigned int n, unsigned int machine)
 		return __get_dwarf_regstr(sparc_regstr_tbl, n);
 	case EM_XTENSA:
 		return __get_dwarf_regstr(xtensa_regstr_tbl, n);
+	case EM_MIPS:
+		return __get_dwarf_regstr(mips_regstr_tbl, n);
 	default:
 		pr_err("ELF MACHINE %x is not supported.\n", machine);
 	}
Signature · 1 line
2.17.1

Archer Yan

author
#0 lore raw

PATCH 1/2 Support mips unwinding and dwarf-regs.

From: David Daney <[email protected]>

Map perf APIs(perf_reg_name/get_arch_regstr/unwind__arch_reg_id) with MIPS specific registers.

[[email protected]: repick this patch for unwinding userstack backtrace by perf and libunwind on MIPS based CPU.]

Cc Jiri Olsa <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/arch/mips/Build                   |  2 +-
 tools/perf/arch/mips/Makefile                |  7 ++
 tools/perf/arch/mips/include/perf_regs.h     | 84 ++++++++++++++++++++
 tools/perf/arch/mips/util/Build              |  2 +
 tools/perf/arch/mips/util/dwarf-regs.c       | 37 +++++++++
 tools/perf/arch/mips/util/unwind-libunwind.c | 21 +++++
 6 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/arch/mips/Makefile
 create mode 100644 tools/perf/arch/mips/include/perf_regs.h
 create mode 100644 tools/perf/arch/mips/util/Build
 create mode 100644 tools/perf/arch/mips/util/dwarf-regs.c
 create mode 100644 tools/perf/arch/mips/util/unwind-libunwind.c
tools/perf/arch/mips/Build +1 -1
index 1bb8bf6d7fd4..54afe4a467e7 100644
@@ -1 +1 @@
-# empty
+libperf-y += util/
tools/perf/arch/mips/Makefile new file +7 -0
new file mode 100644
index 000000000000..fe9b61e322a5
@@ -0,0 +1,7 @@
+ifndef NO_DWARF
+PERF_HAVE_DWARF_REGS := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
+endif
+ifndef NO_LIBUNWIND
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o
+endif
tools/perf/arch/mips/include/perf_regs.h new file +84 -0

84 lines not on this page · raw message

tools/perf/arch/mips/util/Build new file +2 -0
new file mode 100644
index 000000000000..7da83b5ebc4c
@@ -0,0 +1,2 @@
+libperf-$(CONFIG_DWARF)                += dwarf-regs.o
+libperf-$(CONFIG_LIBUNWIND)    += unwind-libunwind.o
tools/perf/arch/mips/util/dwarf-regs.c new file +37 -0
new file mode 100644
index 000000000000..165e0179ea11
@@ -0,0 +1,37 @@
+/*
+ * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
+ *
+ * Copyright (C) 2013 Cavium, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <libio.h>
+#include <dwarf-regs.h>
+
+static const char *mips_gpr_names[32] = {
+	"$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+	"$10", "$11", "$12", "$13", "$14", "$15", "$16", "$17", "$18", "$19",
+	"$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27", "$28", "$29",
+	"$30", "$31"
+};
+
+const char *get_arch_regstr(unsigned int n)
+{
+	if (n < 32)
+		return mips_gpr_names[n];
+	if (n == 64)
+		return "hi";
+	if (n == 65)
+		return "lo";
+	return NULL;
+}
tools/perf/arch/mips/util/unwind-libunwind.c new file +21 -0
new file mode 100644
index 000000000000..7af25427943f
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <errno.h>
+#include <libunwind.h>
+#include "perf_regs.h"
+#include "../../util/unwind.h"
+
+int unwind__arch_reg_id(int regnum)
+{
+	switch (regnum) {
+	case UNW_MIPS_R1 ... UNW_MIPS_R25:
+		return regnum - UNW_MIPS_R1 + PERF_REG_MIPS_R1;
+	case UNW_MIPS_R28 ... UNW_MIPS_R31:
+		return regnum - UNW_MIPS_R28 + PERF_REG_MIPS_R28;
+	case UNW_MIPS_PC:
+		return PERF_REG_MIPS_PC;
+	default:
+		pr_err("unwind: invalid reg id %d\n", regnum);
+		return -EINVAL;
+	}
+}
Signature · 1 line
2.17.1