diff options
author | Anju T <anju@linux.vnet.ibm.com> | 2016-02-20 00:02:46 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-04-21 09:32:59 -0400 |
commit | ed4a4ef85cf5b75231079501030db28dd59f920a (patch) | |
tree | 52291203962d97f8688bde489852a04971dce2b3 | |
parent | 1bfadabfebc671a6af0f5008b524b681ce757dec (diff) |
powerpc/perf: Add support for sampling interrupt register state
The perf infrastructure uses a bit mask to find out valid registers to
display. Define a register mask for supported registers defined in
uapi/asm/perf_regs.h. The bit positions also correspond to register IDs
which is used by perf infrastructure to fetch the register values.
CONFIG_HAVE_PERF_REGS enables sampling of the interrupted machine state.
Signed-off-by: Anju T <anju@linux.vnet.ibm.com>
[mpe: Add license, use CONFIG_PPC64, fix 32-bit build]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | arch/powerpc/Kconfig | 1 | ||||
-rw-r--r-- | arch/powerpc/perf/Makefile | 2 | ||||
-rw-r--r-- | arch/powerpc/perf/perf_regs.c | 104 |
3 files changed, 106 insertions, 1 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 9b5c7bcc06c4..b14966d67149 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig | |||
@@ -116,6 +116,7 @@ config PPC | |||
116 | select GENERIC_ATOMIC64 if PPC32 | 116 | select GENERIC_ATOMIC64 if PPC32 |
117 | select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE | 117 | select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE |
118 | select HAVE_PERF_EVENTS | 118 | select HAVE_PERF_EVENTS |
119 | select HAVE_PERF_REGS | ||
119 | select HAVE_REGS_AND_STACK_ACCESS_API | 120 | select HAVE_REGS_AND_STACK_ACCESS_API |
120 | select HAVE_HW_BREAKPOINT if PERF_EVENTS && PPC_BOOK3S_64 | 121 | select HAVE_HW_BREAKPOINT if PERF_EVENTS && PPC_BOOK3S_64 |
121 | select ARCH_WANT_IPC_PARSE_VERSION | 122 | select ARCH_WANT_IPC_PARSE_VERSION |
diff --git a/arch/powerpc/perf/Makefile b/arch/powerpc/perf/Makefile index f9c083a5652a..77b6394a7c50 100644 --- a/arch/powerpc/perf/Makefile +++ b/arch/powerpc/perf/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror | 1 | subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror |
2 | 2 | ||
3 | obj-$(CONFIG_PERF_EVENTS) += callchain.o | 3 | obj-$(CONFIG_PERF_EVENTS) += callchain.o perf_regs.o |
4 | 4 | ||
5 | obj-$(CONFIG_PPC_PERF_CTRS) += core-book3s.o bhrb.o | 5 | obj-$(CONFIG_PPC_PERF_CTRS) += core-book3s.o bhrb.o |
6 | obj64-$(CONFIG_PPC_PERF_CTRS) += power4-pmu.o ppc970-pmu.o power5-pmu.o \ | 6 | obj64-$(CONFIG_PPC_PERF_CTRS) += power4-pmu.o ppc970-pmu.o power5-pmu.o \ |
diff --git a/arch/powerpc/perf/perf_regs.c b/arch/powerpc/perf/perf_regs.c new file mode 100644 index 000000000000..d24a8a3668fa --- /dev/null +++ b/arch/powerpc/perf/perf_regs.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * Copyright 2016 Anju T, IBM Corporation. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/errno.h> | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/sched.h> | ||
13 | #include <linux/perf_event.h> | ||
14 | #include <linux/bug.h> | ||
15 | #include <linux/stddef.h> | ||
16 | #include <asm/ptrace.h> | ||
17 | #include <asm/perf_regs.h> | ||
18 | |||
19 | #define PT_REGS_OFFSET(id, r) [id] = offsetof(struct pt_regs, r) | ||
20 | |||
21 | #define REG_RESERVED (~((1ULL << PERF_REG_POWERPC_MAX) - 1)) | ||
22 | |||
23 | static unsigned int pt_regs_offset[PERF_REG_POWERPC_MAX] = { | ||
24 | PT_REGS_OFFSET(PERF_REG_POWERPC_R0, gpr[0]), | ||
25 | PT_REGS_OFFSET(PERF_REG_POWERPC_R1, gpr[1]), | ||
26 | PT_REGS_OFFSET(PERF_REG_POWERPC_R2, gpr[2]), | ||
27 | PT_REGS_OFFSET(PERF_REG_POWERPC_R3, gpr[3]), | ||
28 | PT_REGS_OFFSET(PERF_REG_POWERPC_R4, gpr[4]), | ||
29 | PT_REGS_OFFSET(PERF_REG_POWERPC_R5, gpr[5]), | ||
30 | PT_REGS_OFFSET(PERF_REG_POWERPC_R6, gpr[6]), | ||
31 | PT_REGS_OFFSET(PERF_REG_POWERPC_R7, gpr[7]), | ||
32 | PT_REGS_OFFSET(PERF_REG_POWERPC_R8, gpr[8]), | ||
33 | PT_REGS_OFFSET(PERF_REG_POWERPC_R9, gpr[9]), | ||
34 | PT_REGS_OFFSET(PERF_REG_POWERPC_R10, gpr[10]), | ||
35 | PT_REGS_OFFSET(PERF_REG_POWERPC_R11, gpr[11]), | ||
36 | PT_REGS_OFFSET(PERF_REG_POWERPC_R12, gpr[12]), | ||
37 | PT_REGS_OFFSET(PERF_REG_POWERPC_R13, gpr[13]), | ||
38 | PT_REGS_OFFSET(PERF_REG_POWERPC_R14, gpr[14]), | ||
39 | PT_REGS_OFFSET(PERF_REG_POWERPC_R15, gpr[15]), | ||
40 | PT_REGS_OFFSET(PERF_REG_POWERPC_R16, gpr[16]), | ||
41 | PT_REGS_OFFSET(PERF_REG_POWERPC_R17, gpr[17]), | ||
42 | PT_REGS_OFFSET(PERF_REG_POWERPC_R18, gpr[18]), | ||
43 | PT_REGS_OFFSET(PERF_REG_POWERPC_R19, gpr[19]), | ||
44 | PT_REGS_OFFSET(PERF_REG_POWERPC_R20, gpr[20]), | ||
45 | PT_REGS_OFFSET(PERF_REG_POWERPC_R21, gpr[21]), | ||
46 | PT_REGS_OFFSET(PERF_REG_POWERPC_R22, gpr[22]), | ||
47 | PT_REGS_OFFSET(PERF_REG_POWERPC_R23, gpr[23]), | ||
48 | PT_REGS_OFFSET(PERF_REG_POWERPC_R24, gpr[24]), | ||
49 | PT_REGS_OFFSET(PERF_REG_POWERPC_R25, gpr[25]), | ||
50 | PT_REGS_OFFSET(PERF_REG_POWERPC_R26, gpr[26]), | ||
51 | PT_REGS_OFFSET(PERF_REG_POWERPC_R27, gpr[27]), | ||
52 | PT_REGS_OFFSET(PERF_REG_POWERPC_R28, gpr[28]), | ||
53 | PT_REGS_OFFSET(PERF_REG_POWERPC_R29, gpr[29]), | ||
54 | PT_REGS_OFFSET(PERF_REG_POWERPC_R30, gpr[30]), | ||
55 | PT_REGS_OFFSET(PERF_REG_POWERPC_R31, gpr[31]), | ||
56 | PT_REGS_OFFSET(PERF_REG_POWERPC_NIP, nip), | ||
57 | PT_REGS_OFFSET(PERF_REG_POWERPC_MSR, msr), | ||
58 | PT_REGS_OFFSET(PERF_REG_POWERPC_ORIG_R3, orig_gpr3), | ||
59 | PT_REGS_OFFSET(PERF_REG_POWERPC_CTR, ctr), | ||
60 | PT_REGS_OFFSET(PERF_REG_POWERPC_LINK, link), | ||
61 | PT_REGS_OFFSET(PERF_REG_POWERPC_XER, xer), | ||
62 | PT_REGS_OFFSET(PERF_REG_POWERPC_CCR, ccr), | ||
63 | #ifdef CONFIG_PPC64 | ||
64 | PT_REGS_OFFSET(PERF_REG_POWERPC_SOFTE, softe), | ||
65 | #else | ||
66 | PT_REGS_OFFSET(PERF_REG_POWERPC_SOFTE, mq), | ||
67 | #endif | ||
68 | PT_REGS_OFFSET(PERF_REG_POWERPC_TRAP, trap), | ||
69 | PT_REGS_OFFSET(PERF_REG_POWERPC_DAR, dar), | ||
70 | PT_REGS_OFFSET(PERF_REG_POWERPC_DSISR, dsisr), | ||
71 | }; | ||
72 | |||
73 | u64 perf_reg_value(struct pt_regs *regs, int idx) | ||
74 | { | ||
75 | if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX)) | ||
76 | return 0; | ||
77 | |||
78 | return regs_get_register(regs, pt_regs_offset[idx]); | ||
79 | } | ||
80 | |||
81 | int perf_reg_validate(u64 mask) | ||
82 | { | ||
83 | if (!mask || mask & REG_RESERVED) | ||
84 | return -EINVAL; | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | u64 perf_reg_abi(struct task_struct *task) | ||
89 | { | ||
90 | #ifdef CONFIG_PPC64 | ||
91 | if (!test_tsk_thread_flag(task, TIF_32BIT)) | ||
92 | return PERF_SAMPLE_REGS_ABI_64; | ||
93 | else | ||
94 | #endif | ||
95 | return PERF_SAMPLE_REGS_ABI_32; | ||
96 | } | ||
97 | |||
98 | void perf_get_regs_user(struct perf_regs *regs_user, | ||
99 | struct pt_regs *regs, | ||
100 | struct pt_regs *regs_user_copy) | ||
101 | { | ||
102 | regs_user->regs = task_pt_regs(current); | ||
103 | regs_user->abi = perf_reg_abi(current); | ||
104 | } | ||