4 * @remark Copyright 2004 Oprofile Authors
5 * @remark Copyright 2010 ARM Ltd.
6 * @remark Read the file COPYING
8 * @author Zwane Mwaikambo
9 * @author Will Deacon [move to perf]
12 #include <linux/cpumask.h>
13 #include <linux/err.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/mutex.h>
17 #include <linux/oprofile.h>
18 #include <linux/perf_event.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <asm/stacktrace.h>
22 #include <linux/uaccess.h>
24 #include <asm/perf_event.h>
25 #include <asm/ptrace.h>
27 #ifdef CONFIG_HW_PERF_EVENTS
28 char *op_name_from_perf_id(void)
30 enum arm_perf_pmu_ids id
= armpmu_get_pmu_id();
33 case ARM_PERF_PMU_ID_XSCALE1
:
35 case ARM_PERF_PMU_ID_XSCALE2
:
37 case ARM_PERF_PMU_ID_V6
:
39 case ARM_PERF_PMU_ID_V6MP
:
41 case ARM_PERF_PMU_ID_CA8
:
43 case ARM_PERF_PMU_ID_CA9
:
44 return "arm/armv7-ca9";
50 static int report_trace(struct stackframe
*frame
, void *d
)
52 unsigned int *depth
= d
;
55 oprofile_add_trace(frame
->pc
);
63 * The registers we're interested in are at the end of the variable
64 * length saved register structure. The fp points at the end of this
65 * structure so the address of this struct is:
66 * (struct frame_tail *)(xxx->fp)-1
69 struct frame_tail
*fp
;
72 } __attribute__((packed
));
74 static struct frame_tail
* user_backtrace(struct frame_tail
*tail
)
76 struct frame_tail buftail
[2];
78 /* Also check accessibility of one struct frame_tail beyond */
79 if (!access_ok(VERIFY_READ
, tail
, sizeof(buftail
)))
81 if (__copy_from_user_inatomic(buftail
, tail
, sizeof(buftail
)))
84 oprofile_add_trace(buftail
[0].lr
);
86 /* frame pointers should strictly progress back up the stack
87 * (towards higher addresses) */
88 if (tail
>= buftail
[0].fp
)
91 return buftail
[0].fp
-1;
94 static void arm_backtrace(struct pt_regs
* const regs
, unsigned int depth
)
96 struct frame_tail
*tail
= ((struct frame_tail
*) regs
->ARM_fp
) - 1;
98 if (!user_mode(regs
)) {
99 struct stackframe frame
;
100 frame
.fp
= regs
->ARM_fp
;
101 frame
.sp
= regs
->ARM_sp
;
102 frame
.lr
= regs
->ARM_lr
;
103 frame
.pc
= regs
->ARM_pc
;
104 walk_stackframe(&frame
, report_trace
, &depth
);
108 while (depth
-- && tail
&& !((unsigned long) tail
& 3))
109 tail
= user_backtrace(tail
);
112 int __init
oprofile_arch_init(struct oprofile_operations
*ops
)
114 ops
->backtrace
= arm_backtrace
;
116 return oprofile_perf_init(ops
);
119 void __exit
oprofile_arch_exit(void)
121 oprofile_perf_exit();
124 int __init
oprofile_arch_init(struct oprofile_operations
*ops
)
126 pr_info("oprofile: hardware counters not available\n");
129 void __exit
oprofile_arch_exit(void) {}
130 #endif /* CONFIG_HW_PERF_EVENTS */