blob: 831513342d533e8d738d6d3def5133d25e891d71 [file] [log] [blame]
Jamie Iles1b8873a2010-02-02 20:25:44 +01001#undef DEBUG
2
3/*
4 * ARM performance counter support.
5 *
6 * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles
Will Deacon43eab872010-11-13 19:04:32 +00007 * Copyright (C) 2010 ARM Ltd., Will Deacon <will.deacon@arm.com>
Jean PIHET796d1292010-01-26 18:51:05 +01008 *
Jamie Iles1b8873a2010-02-02 20:25:44 +01009 * This code is based on the sparc64 perf event code, which is in turn based
10 * on the x86 code. Callchain code is based on the ARM OProfile backtrace
11 * code.
12 */
13#define pr_fmt(fmt) "hw perfevents: " fmt
14
15#include <linux/interrupt.h>
16#include <linux/kernel.h>
Will Deacon181193f2010-04-30 11:32:44 +010017#include <linux/module.h>
Jamie Iles1b8873a2010-02-02 20:25:44 +010018#include <linux/perf_event.h>
Will Deacon49c006b2010-04-29 17:13:24 +010019#include <linux/platform_device.h>
Jamie Iles1b8873a2010-02-02 20:25:44 +010020#include <linux/spinlock.h>
21#include <linux/uaccess.h>
22
23#include <asm/cputype.h>
24#include <asm/irq.h>
25#include <asm/irq_regs.h>
26#include <asm/pmu.h>
27#include <asm/stacktrace.h>
28
Jamie Iles1b8873a2010-02-02 20:25:44 +010029/*
Will Deaconecf5a892011-07-19 22:43:28 +010030 * ARMv6 supports a maximum of 3 events, starting from index 0. If we add
Jamie Iles1b8873a2010-02-02 20:25:44 +010031 * another platform that supports more, we need to increase this to be the
32 * largest of all platforms.
Jean PIHET796d1292010-01-26 18:51:05 +010033 *
34 * ARMv7 supports up to 32 events:
35 * cycle counter CCNT + 31 events counters CNT0..30.
36 * Cortex-A8 has 1+4 counters, Cortex-A9 has 1+6 counters.
Jamie Iles1b8873a2010-02-02 20:25:44 +010037 */
Will Deaconecf5a892011-07-19 22:43:28 +010038#define ARMPMU_MAX_HWEVENTS 32
Jamie Iles1b8873a2010-02-02 20:25:44 +010039
Mark Rutland8be3f9a2011-05-17 11:20:11 +010040/* The events for a given PMU register set. */
41struct pmu_hw_events {
Jamie Iles1b8873a2010-02-02 20:25:44 +010042 /*
Mark Rutland8be3f9a2011-05-17 11:20:11 +010043 * The events that are active on the PMU for the given index.
Jamie Iles1b8873a2010-02-02 20:25:44 +010044 */
Mark Rutland3fc2c832011-06-24 11:30:59 +010045 struct perf_event **events;
Jamie Iles1b8873a2010-02-02 20:25:44 +010046
47 /*
48 * A 1 bit for an index indicates that the counter is being used for
49 * an event. A 0 means that the counter can be used.
50 */
Mark Rutland3fc2c832011-06-24 11:30:59 +010051 unsigned long *used_mask;
Mark Rutland0f78d2d2011-04-28 10:17:04 +010052
53 /*
54 * Hardware lock to serialize accesses to PMU registers. Needed for the
55 * read/modify/write sequences.
56 */
57 raw_spinlock_t pmu_lock;
Jamie Iles1b8873a2010-02-02 20:25:44 +010058};
Mark Rutland3fc2c832011-06-24 11:30:59 +010059
60static DEFINE_PER_CPU(struct perf_event * [ARMPMU_MAX_HWEVENTS], hw_events);
61static DEFINE_PER_CPU(unsigned long [BITS_TO_LONGS(ARMPMU_MAX_HWEVENTS)], used_mask);
Mark Rutland8be3f9a2011-05-17 11:20:11 +010062static DEFINE_PER_CPU(struct pmu_hw_events, cpu_hw_events);
Will Deacon181193f2010-04-30 11:32:44 +010063
Jamie Iles1b8873a2010-02-02 20:25:44 +010064struct arm_pmu {
Mark Rutland8a16b342011-04-28 16:27:54 +010065 struct pmu pmu;
Will Deacon181193f2010-04-30 11:32:44 +010066 enum arm_perf_pmu_ids id;
Mark Rutland7ae18a52011-06-06 10:37:50 +010067 enum arm_pmu_type type;
Will Deacon0b390e22011-07-27 15:18:59 +010068 cpumask_t active_irqs;
Will Deacon62994832010-11-13 18:45:27 +000069 const char *name;
Jamie Iles1b8873a2010-02-02 20:25:44 +010070 irqreturn_t (*handle_irq)(int irq_num, void *dev);
71 void (*enable)(struct hw_perf_event *evt, int idx);
72 void (*disable)(struct hw_perf_event *evt, int idx);
Mark Rutland8be3f9a2011-05-17 11:20:11 +010073 int (*get_event_idx)(struct pmu_hw_events *hw_events,
Jamie Iles1b8873a2010-02-02 20:25:44 +010074 struct hw_perf_event *hwc);
Will Deacon05d22fd2011-07-19 11:57:30 +010075 int (*set_event_filter)(struct hw_perf_event *evt,
76 struct perf_event_attr *attr);
Jamie Iles1b8873a2010-02-02 20:25:44 +010077 u32 (*read_counter)(int idx);
78 void (*write_counter)(int idx, u32 val);
79 void (*start)(void);
80 void (*stop)(void);
Will Deacon574b69c2011-03-25 13:13:34 +010081 void (*reset)(void *);
Mark Rutlande1f431b2011-04-28 15:47:10 +010082 int (*map_event)(struct perf_event *event);
Jamie Iles1b8873a2010-02-02 20:25:44 +010083 int num_events;
Mark Rutland03b78982011-04-27 11:20:11 +010084 atomic_t active_events;
85 struct mutex reserve_mutex;
Jamie Iles1b8873a2010-02-02 20:25:44 +010086 u64 max_period;
Mark Rutlanda9356a02011-05-04 09:23:15 +010087 struct platform_device *plat_device;
Mark Rutland8be3f9a2011-05-17 11:20:11 +010088 struct pmu_hw_events *(*get_hw_events)(void);
Jamie Iles1b8873a2010-02-02 20:25:44 +010089};
90
Mark Rutland8a16b342011-04-28 16:27:54 +010091#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
92
Jamie Iles1b8873a2010-02-02 20:25:44 +010093/* Set at runtime when we know what CPU type we are. */
Mark Rutland8be3f9a2011-05-17 11:20:11 +010094static struct arm_pmu *cpu_pmu;
Jamie Iles1b8873a2010-02-02 20:25:44 +010095
Will Deacon181193f2010-04-30 11:32:44 +010096enum arm_perf_pmu_ids
97armpmu_get_pmu_id(void)
98{
99 int id = -ENODEV;
100
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100101 if (cpu_pmu != NULL)
102 id = cpu_pmu->id;
Will Deacon181193f2010-04-30 11:32:44 +0100103
104 return id;
105}
106EXPORT_SYMBOL_GPL(armpmu_get_pmu_id);
107
Will Deacon929f5192010-04-30 11:34:26 +0100108int
109armpmu_get_max_events(void)
110{
111 int max_events = 0;
112
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100113 if (cpu_pmu != NULL)
114 max_events = cpu_pmu->num_events;
Will Deacon929f5192010-04-30 11:34:26 +0100115
116 return max_events;
117}
118EXPORT_SYMBOL_GPL(armpmu_get_max_events);
119
Matt Fleming3bf101b2010-09-27 20:22:24 +0100120int perf_num_counters(void)
121{
122 return armpmu_get_max_events();
123}
124EXPORT_SYMBOL_GPL(perf_num_counters);
125
Jamie Iles1b8873a2010-02-02 20:25:44 +0100126#define HW_OP_UNSUPPORTED 0xFFFF
127
128#define C(_x) \
129 PERF_COUNT_HW_CACHE_##_x
130
131#define CACHE_OP_UNSUPPORTED 0xFFFF
132
Jamie Iles1b8873a2010-02-02 20:25:44 +0100133static int
Mark Rutlande1f431b2011-04-28 15:47:10 +0100134armpmu_map_cache_event(const unsigned (*cache_map)
135 [PERF_COUNT_HW_CACHE_MAX]
136 [PERF_COUNT_HW_CACHE_OP_MAX]
137 [PERF_COUNT_HW_CACHE_RESULT_MAX],
138 u64 config)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100139{
140 unsigned int cache_type, cache_op, cache_result, ret;
141
142 cache_type = (config >> 0) & 0xff;
143 if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
144 return -EINVAL;
145
146 cache_op = (config >> 8) & 0xff;
147 if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
148 return -EINVAL;
149
150 cache_result = (config >> 16) & 0xff;
151 if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
152 return -EINVAL;
153
Mark Rutlande1f431b2011-04-28 15:47:10 +0100154 ret = (int)(*cache_map)[cache_type][cache_op][cache_result];
Jamie Iles1b8873a2010-02-02 20:25:44 +0100155
156 if (ret == CACHE_OP_UNSUPPORTED)
157 return -ENOENT;
158
159 return ret;
160}
161
162static int
Mark Rutlande1f431b2011-04-28 15:47:10 +0100163armpmu_map_event(const unsigned (*event_map)[PERF_COUNT_HW_MAX], u64 config)
Will Deacon84fee972010-11-13 17:13:56 +0000164{
Mark Rutlande1f431b2011-04-28 15:47:10 +0100165 int mapping = (*event_map)[config];
166 return mapping == HW_OP_UNSUPPORTED ? -ENOENT : mapping;
Will Deacon84fee972010-11-13 17:13:56 +0000167}
168
169static int
Mark Rutlande1f431b2011-04-28 15:47:10 +0100170armpmu_map_raw_event(u32 raw_event_mask, u64 config)
Will Deacon84fee972010-11-13 17:13:56 +0000171{
Mark Rutlande1f431b2011-04-28 15:47:10 +0100172 return (int)(config & raw_event_mask);
173}
174
175static int map_cpu_event(struct perf_event *event,
176 const unsigned (*event_map)[PERF_COUNT_HW_MAX],
177 const unsigned (*cache_map)
178 [PERF_COUNT_HW_CACHE_MAX]
179 [PERF_COUNT_HW_CACHE_OP_MAX]
180 [PERF_COUNT_HW_CACHE_RESULT_MAX],
181 u32 raw_event_mask)
182{
183 u64 config = event->attr.config;
184
185 switch (event->attr.type) {
186 case PERF_TYPE_HARDWARE:
187 return armpmu_map_event(event_map, config);
188 case PERF_TYPE_HW_CACHE:
189 return armpmu_map_cache_event(cache_map, config);
190 case PERF_TYPE_RAW:
191 return armpmu_map_raw_event(raw_event_mask, config);
192 }
193
194 return -ENOENT;
Will Deacon84fee972010-11-13 17:13:56 +0000195}
196
197static int
Jamie Iles1b8873a2010-02-02 20:25:44 +0100198armpmu_event_set_period(struct perf_event *event,
199 struct hw_perf_event *hwc,
200 int idx)
201{
Mark Rutland8a16b342011-04-28 16:27:54 +0100202 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Peter Zijlstrae7850592010-05-21 14:43:08 +0200203 s64 left = local64_read(&hwc->period_left);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100204 s64 period = hwc->sample_period;
205 int ret = 0;
206
207 if (unlikely(left <= -period)) {
208 left = period;
Peter Zijlstrae7850592010-05-21 14:43:08 +0200209 local64_set(&hwc->period_left, left);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100210 hwc->last_period = period;
211 ret = 1;
212 }
213
214 if (unlikely(left <= 0)) {
215 left += period;
Peter Zijlstrae7850592010-05-21 14:43:08 +0200216 local64_set(&hwc->period_left, left);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100217 hwc->last_period = period;
218 ret = 1;
219 }
220
221 if (left > (s64)armpmu->max_period)
222 left = armpmu->max_period;
223
Peter Zijlstrae7850592010-05-21 14:43:08 +0200224 local64_set(&hwc->prev_count, (u64)-left);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100225
226 armpmu->write_counter(idx, (u64)(-left) & 0xffffffff);
227
228 perf_event_update_userpage(event);
229
230 return ret;
231}
232
233static u64
234armpmu_event_update(struct perf_event *event,
235 struct hw_perf_event *hwc,
Will Deacona7378232011-03-25 17:12:37 +0100236 int idx, int overflow)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100237{
Mark Rutland8a16b342011-04-28 16:27:54 +0100238 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Will Deacona7378232011-03-25 17:12:37 +0100239 u64 delta, prev_raw_count, new_raw_count;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100240
241again:
Peter Zijlstrae7850592010-05-21 14:43:08 +0200242 prev_raw_count = local64_read(&hwc->prev_count);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100243 new_raw_count = armpmu->read_counter(idx);
244
Peter Zijlstrae7850592010-05-21 14:43:08 +0200245 if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
Jamie Iles1b8873a2010-02-02 20:25:44 +0100246 new_raw_count) != prev_raw_count)
247 goto again;
248
Will Deacona7378232011-03-25 17:12:37 +0100249 new_raw_count &= armpmu->max_period;
250 prev_raw_count &= armpmu->max_period;
251
252 if (overflow)
Will Deacon67597882011-04-05 14:01:24 +0100253 delta = armpmu->max_period - prev_raw_count + new_raw_count + 1;
Will Deacona7378232011-03-25 17:12:37 +0100254 else
255 delta = new_raw_count - prev_raw_count;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100256
Peter Zijlstrae7850592010-05-21 14:43:08 +0200257 local64_add(delta, &event->count);
258 local64_sub(delta, &hwc->period_left);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100259
260 return new_raw_count;
261}
262
263static void
Jamie Iles1b8873a2010-02-02 20:25:44 +0100264armpmu_read(struct perf_event *event)
265{
266 struct hw_perf_event *hwc = &event->hw;
267
268 /* Don't read disabled counters! */
269 if (hwc->idx < 0)
270 return;
271
Will Deacona7378232011-03-25 17:12:37 +0100272 armpmu_event_update(event, hwc, hwc->idx, 0);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100273}
274
275static void
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200276armpmu_stop(struct perf_event *event, int flags)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100277{
Mark Rutland8a16b342011-04-28 16:27:54 +0100278 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100279 struct hw_perf_event *hwc = &event->hw;
280
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200281 /*
282 * ARM pmu always has to update the counter, so ignore
283 * PERF_EF_UPDATE, see comments in armpmu_start().
284 */
285 if (!(hwc->state & PERF_HES_STOPPED)) {
286 armpmu->disable(hwc, hwc->idx);
287 barrier(); /* why? */
Will Deacona7378232011-03-25 17:12:37 +0100288 armpmu_event_update(event, hwc, hwc->idx, 0);
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200289 hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE;
290 }
291}
292
293static void
294armpmu_start(struct perf_event *event, int flags)
295{
Mark Rutland8a16b342011-04-28 16:27:54 +0100296 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200297 struct hw_perf_event *hwc = &event->hw;
298
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200299 /*
300 * ARM pmu always has to reprogram the period, so ignore
301 * PERF_EF_RELOAD, see the comment below.
302 */
303 if (flags & PERF_EF_RELOAD)
304 WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
305
306 hwc->state = 0;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100307 /*
308 * Set the period again. Some counters can't be stopped, so when we
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200309 * were stopped we simply disabled the IRQ source and the counter
Jamie Iles1b8873a2010-02-02 20:25:44 +0100310 * may have been left counting. If we don't do this step then we may
311 * get an interrupt too soon or *way* too late if the overflow has
312 * happened since disabling.
313 */
314 armpmu_event_set_period(event, hwc, hwc->idx);
315 armpmu->enable(hwc, hwc->idx);
316}
317
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200318static void
319armpmu_del(struct perf_event *event, int flags)
320{
Mark Rutland8a16b342011-04-28 16:27:54 +0100321 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100322 struct pmu_hw_events *hw_events = armpmu->get_hw_events();
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200323 struct hw_perf_event *hwc = &event->hw;
324 int idx = hwc->idx;
325
326 WARN_ON(idx < 0);
327
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200328 armpmu_stop(event, PERF_EF_UPDATE);
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100329 hw_events->events[idx] = NULL;
330 clear_bit(idx, hw_events->used_mask);
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200331
332 perf_event_update_userpage(event);
333}
334
Jamie Iles1b8873a2010-02-02 20:25:44 +0100335static int
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200336armpmu_add(struct perf_event *event, int flags)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100337{
Mark Rutland8a16b342011-04-28 16:27:54 +0100338 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100339 struct pmu_hw_events *hw_events = armpmu->get_hw_events();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100340 struct hw_perf_event *hwc = &event->hw;
341 int idx;
342 int err = 0;
343
Peter Zijlstra33696fc2010-06-14 08:49:00 +0200344 perf_pmu_disable(event->pmu);
Peter Zijlstra24cd7f52010-06-11 17:32:03 +0200345
Jamie Iles1b8873a2010-02-02 20:25:44 +0100346 /* If we don't have a space for the counter then finish early. */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100347 idx = armpmu->get_event_idx(hw_events, hwc);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100348 if (idx < 0) {
349 err = idx;
350 goto out;
351 }
352
353 /*
354 * If there is an event in the counter we are going to use then make
355 * sure it is disabled.
356 */
357 event->hw.idx = idx;
358 armpmu->disable(hwc, idx);
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100359 hw_events->events[idx] = event;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100360
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200361 hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
362 if (flags & PERF_EF_START)
363 armpmu_start(event, PERF_EF_RELOAD);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100364
365 /* Propagate our changes to the userspace mapping. */
366 perf_event_update_userpage(event);
367
368out:
Peter Zijlstra33696fc2010-06-14 08:49:00 +0200369 perf_pmu_enable(event->pmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100370 return err;
371}
372
Jamie Iles1b8873a2010-02-02 20:25:44 +0100373static int
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100374validate_event(struct pmu_hw_events *hw_events,
Jamie Iles1b8873a2010-02-02 20:25:44 +0100375 struct perf_event *event)
376{
Mark Rutland8a16b342011-04-28 16:27:54 +0100377 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100378 struct hw_perf_event fake_event = event->hw;
Mark Rutland7b9f72c2011-04-27 16:22:21 +0100379 struct pmu *leader_pmu = event->group_leader->pmu;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100380
Mark Rutland7b9f72c2011-04-27 16:22:21 +0100381 if (event->pmu != leader_pmu || event->state <= PERF_EVENT_STATE_OFF)
Will Deacon65b47112010-09-02 09:32:08 +0100382 return 1;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100383
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100384 return armpmu->get_event_idx(hw_events, &fake_event) >= 0;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100385}
386
387static int
388validate_group(struct perf_event *event)
389{
390 struct perf_event *sibling, *leader = event->group_leader;
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100391 struct pmu_hw_events fake_pmu;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100392
393 memset(&fake_pmu, 0, sizeof(fake_pmu));
394
395 if (!validate_event(&fake_pmu, leader))
396 return -ENOSPC;
397
398 list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
399 if (!validate_event(&fake_pmu, sibling))
400 return -ENOSPC;
401 }
402
403 if (!validate_event(&fake_pmu, event))
404 return -ENOSPC;
405
406 return 0;
407}
408
Rabin Vincent0e25a5c2011-02-08 09:24:36 +0530409static irqreturn_t armpmu_platform_irq(int irq, void *dev)
410{
Mark Rutland8a16b342011-04-28 16:27:54 +0100411 struct arm_pmu *armpmu = (struct arm_pmu *) dev;
Mark Rutlanda9356a02011-05-04 09:23:15 +0100412 struct platform_device *plat_device = armpmu->plat_device;
413 struct arm_pmu_platdata *plat = dev_get_platdata(&plat_device->dev);
Rabin Vincent0e25a5c2011-02-08 09:24:36 +0530414
415 return plat->handle_irq(irq, dev, armpmu->handle_irq);
416}
417
Will Deacon0b390e22011-07-27 15:18:59 +0100418static void
Mark Rutland8a16b342011-04-28 16:27:54 +0100419armpmu_release_hardware(struct arm_pmu *armpmu)
Will Deacon0b390e22011-07-27 15:18:59 +0100420{
421 int i, irq, irqs;
Mark Rutlanda9356a02011-05-04 09:23:15 +0100422 struct platform_device *pmu_device = armpmu->plat_device;
Will Deacon0b390e22011-07-27 15:18:59 +0100423
424 irqs = min(pmu_device->num_resources, num_possible_cpus());
425
426 for (i = 0; i < irqs; ++i) {
427 if (!cpumask_test_and_clear_cpu(i, &armpmu->active_irqs))
428 continue;
429 irq = platform_get_irq(pmu_device, i);
430 if (irq >= 0)
Mark Rutland8a16b342011-04-28 16:27:54 +0100431 free_irq(irq, armpmu);
Will Deacon0b390e22011-07-27 15:18:59 +0100432 }
433
Mark Rutland7ae18a52011-06-06 10:37:50 +0100434 release_pmu(armpmu->type);
Will Deacon0b390e22011-07-27 15:18:59 +0100435}
436
Jamie Iles1b8873a2010-02-02 20:25:44 +0100437static int
Mark Rutland8a16b342011-04-28 16:27:54 +0100438armpmu_reserve_hardware(struct arm_pmu *armpmu)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100439{
Rabin Vincent0e25a5c2011-02-08 09:24:36 +0530440 struct arm_pmu_platdata *plat;
441 irq_handler_t handle_irq;
Will Deaconb0e89592011-07-26 22:10:28 +0100442 int i, err, irq, irqs;
Mark Rutlanda9356a02011-05-04 09:23:15 +0100443 struct platform_device *pmu_device = armpmu->plat_device;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100444
Mark Rutland7ae18a52011-06-06 10:37:50 +0100445 err = reserve_pmu(armpmu->type);
Will Deaconb0e89592011-07-26 22:10:28 +0100446 if (err) {
Jamie Iles1b8873a2010-02-02 20:25:44 +0100447 pr_warning("unable to reserve pmu\n");
Will Deaconb0e89592011-07-26 22:10:28 +0100448 return err;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100449 }
450
Rabin Vincent0e25a5c2011-02-08 09:24:36 +0530451 plat = dev_get_platdata(&pmu_device->dev);
452 if (plat && plat->handle_irq)
453 handle_irq = armpmu_platform_irq;
454 else
455 handle_irq = armpmu->handle_irq;
456
Will Deacon0b390e22011-07-27 15:18:59 +0100457 irqs = min(pmu_device->num_resources, num_possible_cpus());
Will Deaconb0e89592011-07-26 22:10:28 +0100458 if (irqs < 1) {
Jamie Iles1b8873a2010-02-02 20:25:44 +0100459 pr_err("no irqs for PMUs defined\n");
460 return -ENODEV;
461 }
462
Will Deaconb0e89592011-07-26 22:10:28 +0100463 for (i = 0; i < irqs; ++i) {
Will Deacon0b390e22011-07-27 15:18:59 +0100464 err = 0;
Will Deacon49c006b2010-04-29 17:13:24 +0100465 irq = platform_get_irq(pmu_device, i);
466 if (irq < 0)
467 continue;
468
Will Deaconb0e89592011-07-26 22:10:28 +0100469 /*
470 * If we have a single PMU interrupt that we can't shift,
471 * assume that we're running on a uniprocessor machine and
Will Deacon0b390e22011-07-27 15:18:59 +0100472 * continue. Otherwise, continue without this interrupt.
Will Deaconb0e89592011-07-26 22:10:28 +0100473 */
Will Deacon0b390e22011-07-27 15:18:59 +0100474 if (irq_set_affinity(irq, cpumask_of(i)) && irqs > 1) {
475 pr_warning("unable to set irq affinity (irq=%d, cpu=%u)\n",
476 irq, i);
477 continue;
Will Deaconb0e89592011-07-26 22:10:28 +0100478 }
479
Rabin Vincent0e25a5c2011-02-08 09:24:36 +0530480 err = request_irq(irq, handle_irq,
Will Deaconddee87f2010-02-25 15:04:14 +0100481 IRQF_DISABLED | IRQF_NOBALANCING,
Mark Rutland8a16b342011-04-28 16:27:54 +0100482 "arm-pmu", armpmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100483 if (err) {
Will Deaconb0e89592011-07-26 22:10:28 +0100484 pr_err("unable to request IRQ%d for ARM PMU counters\n",
485 irq);
Mark Rutland8a16b342011-04-28 16:27:54 +0100486 armpmu_release_hardware(armpmu);
Will Deacon0b390e22011-07-27 15:18:59 +0100487 return err;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100488 }
Will Deacon0b390e22011-07-27 15:18:59 +0100489
490 cpumask_set_cpu(i, &armpmu->active_irqs);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100491 }
492
Will Deacon0b390e22011-07-27 15:18:59 +0100493 return 0;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100494}
495
Jamie Iles1b8873a2010-02-02 20:25:44 +0100496static void
497hw_perf_event_destroy(struct perf_event *event)
498{
Mark Rutland8a16b342011-04-28 16:27:54 +0100499 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Mark Rutland03b78982011-04-27 11:20:11 +0100500 atomic_t *active_events = &armpmu->active_events;
501 struct mutex *pmu_reserve_mutex = &armpmu->reserve_mutex;
502
503 if (atomic_dec_and_mutex_lock(active_events, pmu_reserve_mutex)) {
Mark Rutland8a16b342011-04-28 16:27:54 +0100504 armpmu_release_hardware(armpmu);
Mark Rutland03b78982011-04-27 11:20:11 +0100505 mutex_unlock(pmu_reserve_mutex);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100506 }
507}
508
509static int
Will Deacon05d22fd2011-07-19 11:57:30 +0100510event_requires_mode_exclusion(struct perf_event_attr *attr)
511{
512 return attr->exclude_idle || attr->exclude_user ||
513 attr->exclude_kernel || attr->exclude_hv;
514}
515
516static int
Jamie Iles1b8873a2010-02-02 20:25:44 +0100517__hw_perf_event_init(struct perf_event *event)
518{
Mark Rutland8a16b342011-04-28 16:27:54 +0100519 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100520 struct hw_perf_event *hwc = &event->hw;
521 int mapping, err;
522
Mark Rutlande1f431b2011-04-28 15:47:10 +0100523 mapping = armpmu->map_event(event);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100524
525 if (mapping < 0) {
526 pr_debug("event %x:%llx not supported\n", event->attr.type,
527 event->attr.config);
528 return mapping;
529 }
530
531 /*
Will Deacon05d22fd2011-07-19 11:57:30 +0100532 * We don't assign an index until we actually place the event onto
533 * hardware. Use -1 to signify that we haven't decided where to put it
534 * yet. For SMP systems, each core has it's own PMU so we can't do any
535 * clever allocation or constraints checking at this point.
Jamie Iles1b8873a2010-02-02 20:25:44 +0100536 */
Will Deacon05d22fd2011-07-19 11:57:30 +0100537 hwc->idx = -1;
538 hwc->config_base = 0;
539 hwc->config = 0;
540 hwc->event_base = 0;
541
542 /*
543 * Check whether we need to exclude the counter from certain modes.
544 */
545 if ((!armpmu->set_event_filter ||
546 armpmu->set_event_filter(hwc, &event->attr)) &&
547 event_requires_mode_exclusion(&event->attr)) {
Jamie Iles1b8873a2010-02-02 20:25:44 +0100548 pr_debug("ARM performance counters do not support "
549 "mode exclusion\n");
550 return -EPERM;
551 }
552
553 /*
Will Deacon05d22fd2011-07-19 11:57:30 +0100554 * Store the event encoding into the config_base field.
Jamie Iles1b8873a2010-02-02 20:25:44 +0100555 */
Will Deacon05d22fd2011-07-19 11:57:30 +0100556 hwc->config_base |= (unsigned long)mapping;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100557
558 if (!hwc->sample_period) {
559 hwc->sample_period = armpmu->max_period;
560 hwc->last_period = hwc->sample_period;
Peter Zijlstrae7850592010-05-21 14:43:08 +0200561 local64_set(&hwc->period_left, hwc->sample_period);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100562 }
563
564 err = 0;
565 if (event->group_leader != event) {
566 err = validate_group(event);
567 if (err)
568 return -EINVAL;
569 }
570
571 return err;
572}
573
Peter Zijlstrab0a873e2010-06-11 13:35:08 +0200574static int armpmu_event_init(struct perf_event *event)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100575{
Mark Rutland8a16b342011-04-28 16:27:54 +0100576 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100577 int err = 0;
Mark Rutland03b78982011-04-27 11:20:11 +0100578 atomic_t *active_events = &armpmu->active_events;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100579
Mark Rutlande1f431b2011-04-28 15:47:10 +0100580 if (armpmu->map_event(event) == -ENOENT)
Peter Zijlstrab0a873e2010-06-11 13:35:08 +0200581 return -ENOENT;
Peter Zijlstrab0a873e2010-06-11 13:35:08 +0200582
Jamie Iles1b8873a2010-02-02 20:25:44 +0100583 event->destroy = hw_perf_event_destroy;
584
Mark Rutland03b78982011-04-27 11:20:11 +0100585 if (!atomic_inc_not_zero(active_events)) {
586 mutex_lock(&armpmu->reserve_mutex);
587 if (atomic_read(active_events) == 0)
Mark Rutland8a16b342011-04-28 16:27:54 +0100588 err = armpmu_reserve_hardware(armpmu);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100589
590 if (!err)
Mark Rutland03b78982011-04-27 11:20:11 +0100591 atomic_inc(active_events);
592 mutex_unlock(&armpmu->reserve_mutex);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100593 }
594
595 if (err)
Peter Zijlstrab0a873e2010-06-11 13:35:08 +0200596 return err;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100597
598 err = __hw_perf_event_init(event);
599 if (err)
600 hw_perf_event_destroy(event);
601
Peter Zijlstrab0a873e2010-06-11 13:35:08 +0200602 return err;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100603}
604
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200605static void armpmu_enable(struct pmu *pmu)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100606{
607 /* Enable all of the perf events on hardware. */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100608 struct arm_pmu *armpmu = to_arm_pmu(pmu);
Will Deaconf4f38432011-07-01 14:38:12 +0100609 int idx, enabled = 0;
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100610 struct pmu_hw_events *hw_events = armpmu->get_hw_events();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100611
Will Deaconecf5a892011-07-19 22:43:28 +0100612 for (idx = 0; idx < armpmu->num_events; ++idx) {
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100613 struct perf_event *event = hw_events->events[idx];
Jamie Iles1b8873a2010-02-02 20:25:44 +0100614
615 if (!event)
616 continue;
617
618 armpmu->enable(&event->hw, idx);
Will Deaconf4f38432011-07-01 14:38:12 +0100619 enabled = 1;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100620 }
621
Will Deaconf4f38432011-07-01 14:38:12 +0100622 if (enabled)
623 armpmu->start();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100624}
625
Peter Zijlstraa4eaf7f2010-06-16 14:37:10 +0200626static void armpmu_disable(struct pmu *pmu)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100627{
Mark Rutland8a16b342011-04-28 16:27:54 +0100628 struct arm_pmu *armpmu = to_arm_pmu(pmu);
Mark Rutland48957152011-04-27 10:31:51 +0100629 armpmu->stop();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100630}
631
Mark Rutland03b78982011-04-27 11:20:11 +0100632static void __init armpmu_init(struct arm_pmu *armpmu)
633{
634 atomic_set(&armpmu->active_events, 0);
635 mutex_init(&armpmu->reserve_mutex);
Mark Rutland8a16b342011-04-28 16:27:54 +0100636
637 armpmu->pmu = (struct pmu) {
638 .pmu_enable = armpmu_enable,
639 .pmu_disable = armpmu_disable,
640 .event_init = armpmu_event_init,
641 .add = armpmu_add,
642 .del = armpmu_del,
643 .start = armpmu_start,
644 .stop = armpmu_stop,
645 .read = armpmu_read,
646 };
647}
648
649static int __init armpmu_register(struct arm_pmu *armpmu, char *name, int type)
650{
651 armpmu_init(armpmu);
652 return perf_pmu_register(&armpmu->pmu, name, type);
Mark Rutland03b78982011-04-27 11:20:11 +0100653}
654
Will Deacon43eab872010-11-13 19:04:32 +0000655/* Include the PMU-specific implementations. */
656#include "perf_event_xscale.c"
657#include "perf_event_v6.c"
658#include "perf_event_v7.c"
Will Deacon49e6a322010-04-30 11:33:33 +0100659
Will Deacon574b69c2011-03-25 13:13:34 +0100660/*
661 * Ensure the PMU has sane values out of reset.
662 * This requires SMP to be available, so exists as a separate initcall.
663 */
664static int __init
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100665cpu_pmu_reset(void)
Will Deacon574b69c2011-03-25 13:13:34 +0100666{
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100667 if (cpu_pmu && cpu_pmu->reset)
668 return on_each_cpu(cpu_pmu->reset, NULL, 1);
Will Deacon574b69c2011-03-25 13:13:34 +0100669 return 0;
670}
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100671arch_initcall(cpu_pmu_reset);
Will Deacon574b69c2011-03-25 13:13:34 +0100672
Will Deaconb0e89592011-07-26 22:10:28 +0100673/*
674 * PMU platform driver and devicetree bindings.
675 */
676static struct of_device_id armpmu_of_device_ids[] = {
677 {.compatible = "arm,cortex-a9-pmu"},
678 {.compatible = "arm,cortex-a8-pmu"},
679 {.compatible = "arm,arm1136-pmu"},
680 {.compatible = "arm,arm1176-pmu"},
681 {},
682};
683
684static struct platform_device_id armpmu_plat_device_ids[] = {
685 {.name = "arm-pmu"},
686 {},
687};
688
689static int __devinit armpmu_device_probe(struct platform_device *pdev)
690{
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100691 cpu_pmu->plat_device = pdev;
Will Deaconb0e89592011-07-26 22:10:28 +0100692 return 0;
693}
694
695static struct platform_driver armpmu_driver = {
696 .driver = {
697 .name = "arm-pmu",
698 .of_match_table = armpmu_of_device_ids,
699 },
700 .probe = armpmu_device_probe,
701 .id_table = armpmu_plat_device_ids,
702};
703
704static int __init register_pmu_driver(void)
705{
706 return platform_driver_register(&armpmu_driver);
707}
708device_initcall(register_pmu_driver);
709
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100710static struct pmu_hw_events *armpmu_get_cpu_events(void)
Mark Rutland92f701e2011-05-04 09:23:51 +0100711{
712 return &__get_cpu_var(cpu_hw_events);
713}
714
715static void __init cpu_pmu_init(struct arm_pmu *armpmu)
716{
Mark Rutland0f78d2d2011-04-28 10:17:04 +0100717 int cpu;
718 for_each_possible_cpu(cpu) {
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100719 struct pmu_hw_events *events = &per_cpu(cpu_hw_events, cpu);
Mark Rutland3fc2c832011-06-24 11:30:59 +0100720 events->events = per_cpu(hw_events, cpu);
721 events->used_mask = per_cpu(used_mask, cpu);
Mark Rutland0f78d2d2011-04-28 10:17:04 +0100722 raw_spin_lock_init(&events->pmu_lock);
723 }
Mark Rutland92f701e2011-05-04 09:23:51 +0100724 armpmu->get_hw_events = armpmu_get_cpu_events;
Mark Rutland7ae18a52011-06-06 10:37:50 +0100725 armpmu->type = ARM_PMU_DEVICE_CPU;
Mark Rutland92f701e2011-05-04 09:23:51 +0100726}
727
Will Deaconb0e89592011-07-26 22:10:28 +0100728/*
729 * CPU PMU identification and registration.
730 */
Jamie Iles1b8873a2010-02-02 20:25:44 +0100731static int __init
732init_hw_perf_events(void)
733{
734 unsigned long cpuid = read_cpuid_id();
735 unsigned long implementor = (cpuid & 0xFF000000) >> 24;
736 unsigned long part_number = (cpuid & 0xFFF0);
737
Will Deacon49e6a322010-04-30 11:33:33 +0100738 /* ARM Ltd CPUs. */
Jamie Iles1b8873a2010-02-02 20:25:44 +0100739 if (0x41 == implementor) {
740 switch (part_number) {
741 case 0xB360: /* ARM1136 */
742 case 0xB560: /* ARM1156 */
743 case 0xB760: /* ARM1176 */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100744 cpu_pmu = armv6pmu_init();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100745 break;
746 case 0xB020: /* ARM11mpcore */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100747 cpu_pmu = armv6mpcore_pmu_init();
Jamie Iles1b8873a2010-02-02 20:25:44 +0100748 break;
Jean PIHET796d1292010-01-26 18:51:05 +0100749 case 0xC080: /* Cortex-A8 */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100750 cpu_pmu = armv7_a8_pmu_init();
Jean PIHET796d1292010-01-26 18:51:05 +0100751 break;
752 case 0xC090: /* Cortex-A9 */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100753 cpu_pmu = armv7_a9_pmu_init();
Jean PIHET796d1292010-01-26 18:51:05 +0100754 break;
Will Deacon0c205cb2011-06-03 17:40:15 +0100755 case 0xC050: /* Cortex-A5 */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100756 cpu_pmu = armv7_a5_pmu_init();
Will Deacon0c205cb2011-06-03 17:40:15 +0100757 break;
Will Deacon14abd032011-01-19 14:24:38 +0000758 case 0xC0F0: /* Cortex-A15 */
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100759 cpu_pmu = armv7_a15_pmu_init();
Will Deacon14abd032011-01-19 14:24:38 +0000760 break;
Will Deacon49e6a322010-04-30 11:33:33 +0100761 }
762 /* Intel CPUs [xscale]. */
763 } else if (0x69 == implementor) {
764 part_number = (cpuid >> 13) & 0x7;
765 switch (part_number) {
766 case 1:
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100767 cpu_pmu = xscale1pmu_init();
Will Deacon49e6a322010-04-30 11:33:33 +0100768 break;
769 case 2:
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100770 cpu_pmu = xscale2pmu_init();
Will Deacon49e6a322010-04-30 11:33:33 +0100771 break;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100772 }
773 }
774
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100775 if (cpu_pmu) {
Jean PIHET796d1292010-01-26 18:51:05 +0100776 pr_info("enabled with %s PMU driver, %d counters available\n",
Mark Rutland8be3f9a2011-05-17 11:20:11 +0100777 cpu_pmu->name, cpu_pmu->num_events);
778 cpu_pmu_init(cpu_pmu);
779 armpmu_register(cpu_pmu, "cpu", PERF_TYPE_RAW);
Will Deacon49e6a322010-04-30 11:33:33 +0100780 } else {
781 pr_info("no hardware support available\n");
Will Deacon49e6a322010-04-30 11:33:33 +0100782 }
Jamie Iles1b8873a2010-02-02 20:25:44 +0100783
784 return 0;
785}
Peter Zijlstra004417a2010-11-25 18:38:29 +0100786early_initcall(init_hw_perf_events);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100787
788/*
789 * Callchain handling code.
790 */
Jamie Iles1b8873a2010-02-02 20:25:44 +0100791
792/*
793 * The registers we're interested in are at the end of the variable
794 * length saved register structure. The fp points at the end of this
795 * structure so the address of this struct is:
796 * (struct frame_tail *)(xxx->fp)-1
797 *
798 * This code has been adapted from the ARM OProfile support.
799 */
800struct frame_tail {
Will Deacon4d6b7a72010-11-30 18:15:53 +0100801 struct frame_tail __user *fp;
802 unsigned long sp;
803 unsigned long lr;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100804} __attribute__((packed));
805
806/*
807 * Get the return address for a single stackframe and return a pointer to the
808 * next frame tail.
809 */
Will Deacon4d6b7a72010-11-30 18:15:53 +0100810static struct frame_tail __user *
811user_backtrace(struct frame_tail __user *tail,
Jamie Iles1b8873a2010-02-02 20:25:44 +0100812 struct perf_callchain_entry *entry)
813{
814 struct frame_tail buftail;
815
816 /* Also check accessibility of one struct frame_tail beyond */
817 if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
818 return NULL;
819 if (__copy_from_user_inatomic(&buftail, tail, sizeof(buftail)))
820 return NULL;
821
Frederic Weisbecker70791ce2010-06-29 19:34:05 +0200822 perf_callchain_store(entry, buftail.lr);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100823
824 /*
825 * Frame pointers should strictly progress back up the stack
826 * (towards higher addresses).
827 */
Rabin Vincentcb061992011-02-09 11:35:12 +0100828 if (tail + 1 >= buftail.fp)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100829 return NULL;
830
831 return buftail.fp - 1;
832}
833
Frederic Weisbecker56962b4442010-06-30 23:03:51 +0200834void
835perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100836{
Will Deacon4d6b7a72010-11-30 18:15:53 +0100837 struct frame_tail __user *tail;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100838
Jamie Iles1b8873a2010-02-02 20:25:44 +0100839
Will Deacon4d6b7a72010-11-30 18:15:53 +0100840 tail = (struct frame_tail __user *)regs->ARM_fp - 1;
Jamie Iles1b8873a2010-02-02 20:25:44 +0100841
Sonny Rao860ad782011-04-18 22:12:59 +0100842 while ((entry->nr < PERF_MAX_STACK_DEPTH) &&
843 tail && !((unsigned long)tail & 0x3))
Jamie Iles1b8873a2010-02-02 20:25:44 +0100844 tail = user_backtrace(tail, entry);
845}
846
847/*
848 * Gets called by walk_stackframe() for every stackframe. This will be called
849 * whist unwinding the stackframe and is like a subroutine return so we use
850 * the PC.
851 */
852static int
853callchain_trace(struct stackframe *fr,
854 void *data)
855{
856 struct perf_callchain_entry *entry = data;
Frederic Weisbecker70791ce2010-06-29 19:34:05 +0200857 perf_callchain_store(entry, fr->pc);
Jamie Iles1b8873a2010-02-02 20:25:44 +0100858 return 0;
859}
860
Frederic Weisbecker56962b4442010-06-30 23:03:51 +0200861void
862perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs)
Jamie Iles1b8873a2010-02-02 20:25:44 +0100863{
864 struct stackframe fr;
865
Jamie Iles1b8873a2010-02-02 20:25:44 +0100866 fr.fp = regs->ARM_fp;
867 fr.sp = regs->ARM_sp;
868 fr.lr = regs->ARM_lr;
869 fr.pc = regs->ARM_pc;
870 walk_stackframe(&fr, callchain_trace, entry);
871}