Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf unwind: Support for powerpc

Porting PPC to libdw only needs an architecture-specific hook to move
the register state from perf to libdw.

The ARM and x86 architectures already use libdw, and it is useful to
have as much common code for the unwinder as possible. Mark Wielaard
has contributed a frame-based unwinder to libdw, so that unwinding works
even for binaries that do not have CFI information. In addition,
libunwind is always preferred to libdw by the build machinery so this
cannot introduce regressions on machines that have both libunwind and
libdw installed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Milian Wolff <milian.wolff@kdab.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1496312681-20133-1-git-send-email-pbonzini@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Paolo Bonzini and committed by
Arnaldo Carvalho de Melo
a7f0fda0 daefd0bc

+76 -1
+1 -1
tools/perf/Makefile.config
··· 61 61 # Disable it on all other architectures in case libdw unwind 62 62 # support is detected in system. Add supported architectures 63 63 # to the check. 64 - ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm)) 64 + ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm powerpc)) 65 65 NO_LIBDW_DWARF_UNWIND := 1 66 66 endif 67 67
+2
tools/perf/arch/powerpc/util/Build
··· 5 5 6 6 libperf-$(CONFIG_DWARF) += dwarf-regs.o 7 7 libperf-$(CONFIG_DWARF) += skip-callchain-idx.o 8 + 8 9 libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o 10 + libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
+73
tools/perf/arch/powerpc/util/unwind-libdw.c
··· 1 + #include <elfutils/libdwfl.h> 2 + #include "../../util/unwind-libdw.h" 3 + #include "../../util/perf_regs.h" 4 + #include "../../util/event.h" 5 + 6 + /* See backends/ppc_initreg.c and backends/ppc_regs.c in elfutils. */ 7 + static const int special_regs[3][2] = { 8 + { 65, PERF_REG_POWERPC_LINK }, 9 + { 101, PERF_REG_POWERPC_XER }, 10 + { 109, PERF_REG_POWERPC_CTR }, 11 + }; 12 + 13 + bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 14 + { 15 + struct unwind_info *ui = arg; 16 + struct regs_dump *user_regs = &ui->sample->user_regs; 17 + Dwarf_Word dwarf_regs[32], dwarf_nip; 18 + size_t i; 19 + 20 + #define REG(r) ({ \ 21 + Dwarf_Word val = 0; \ 22 + perf_reg_value(&val, user_regs, PERF_REG_POWERPC_##r); \ 23 + val; \ 24 + }) 25 + 26 + dwarf_regs[0] = REG(R0); 27 + dwarf_regs[1] = REG(R1); 28 + dwarf_regs[2] = REG(R2); 29 + dwarf_regs[3] = REG(R3); 30 + dwarf_regs[4] = REG(R4); 31 + dwarf_regs[5] = REG(R5); 32 + dwarf_regs[6] = REG(R6); 33 + dwarf_regs[7] = REG(R7); 34 + dwarf_regs[8] = REG(R8); 35 + dwarf_regs[9] = REG(R9); 36 + dwarf_regs[10] = REG(R10); 37 + dwarf_regs[11] = REG(R11); 38 + dwarf_regs[12] = REG(R12); 39 + dwarf_regs[13] = REG(R13); 40 + dwarf_regs[14] = REG(R14); 41 + dwarf_regs[15] = REG(R15); 42 + dwarf_regs[16] = REG(R16); 43 + dwarf_regs[17] = REG(R17); 44 + dwarf_regs[18] = REG(R18); 45 + dwarf_regs[19] = REG(R19); 46 + dwarf_regs[20] = REG(R20); 47 + dwarf_regs[21] = REG(R21); 48 + dwarf_regs[22] = REG(R22); 49 + dwarf_regs[23] = REG(R23); 50 + dwarf_regs[24] = REG(R24); 51 + dwarf_regs[25] = REG(R25); 52 + dwarf_regs[26] = REG(R26); 53 + dwarf_regs[27] = REG(R27); 54 + dwarf_regs[28] = REG(R28); 55 + dwarf_regs[29] = REG(R29); 56 + dwarf_regs[30] = REG(R30); 57 + dwarf_regs[31] = REG(R31); 58 + if (!dwfl_thread_state_registers(thread, 0, 32, dwarf_regs)) 59 + return false; 60 + 61 + dwarf_nip = REG(NIP); 62 + dwfl_thread_state_register_pc(thread, dwarf_nip); 63 + for (i = 0; i < ARRAY_SIZE(special_regs); i++) { 64 + Dwarf_Word val = 0; 65 + perf_reg_value(&val, user_regs, special_regs[i][1]); 66 + if (!dwfl_thread_state_registers(thread, 67 + special_regs[i][0], 1, 68 + &val)) 69 + return false; 70 + } 71 + 72 + return true; 73 + }