blob: c1cf9c6c3f7705b9c50281d196633d91c8e788e5 [file] [log] [blame]
Deng-Cheng Zhu14f70012010-10-12 19:37:22 +08001/*
2 * Linux performance counter support for MIPS.
3 *
4 * Copyright (C) 2010 MIPS Technologies, Inc.
5 * Author: Deng-Cheng Zhu
6 *
7 * This code is based on the implementation for ARM, which is in turn
8 * based on the sparc64 perf event code and the x86 code. Performance
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +08009 * counter access is based on the MIPS Oprofile code. And the callchain
10 * support references the code of MIPS stacktrace.c.
Deng-Cheng Zhu14f70012010-10-12 19:37:22 +080011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Deng-Cheng Zhu14f70012010-10-12 19:37:22 +080017#include <linux/perf_event.h>
Deng-Cheng Zhu14f70012010-10-12 19:37:22 +080018
Deng-Cheng Zhu14f70012010-10-12 19:37:22 +080019#include <asm/stacktrace.h>
Deng-Cheng Zhu3a9ab992010-10-12 19:37:24 +080020
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080021/* Callchain handling code. */
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080022
23/*
24 * Leave userspace callchain empty for now. When we find a way to trace
David Daneye5dcb582011-09-24 02:29:55 +020025 * the user stack callchains, we will add it here.
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080026 */
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080027
28static void save_raw_perf_callchain(struct perf_callchain_entry *entry,
29 unsigned long reg29)
30{
31 unsigned long *sp = (unsigned long *)reg29;
32 unsigned long addr;
33
34 while (!kstack_end(sp)) {
35 addr = *sp++;
36 if (__kernel_text_address(addr)) {
Deng-Cheng Zhu98f92f22011-01-21 16:19:20 +080037 perf_callchain_store(entry, addr);
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080038 if (entry->nr >= PERF_MAX_STACK_DEPTH)
39 break;
40 }
41 }
42}
43
Deng-Cheng Zhu98f92f22011-01-21 16:19:20 +080044void perf_callchain_kernel(struct perf_callchain_entry *entry,
45 struct pt_regs *regs)
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080046{
47 unsigned long sp = regs->regs[29];
48#ifdef CONFIG_KALLSYMS
49 unsigned long ra = regs->regs[31];
50 unsigned long pc = regs->cp0_epc;
51
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080052 if (raw_show_trace || !__kernel_text_address(pc)) {
53 unsigned long stack_page =
54 (unsigned long)task_stack_page(current);
55 if (stack_page && sp >= stack_page &&
56 sp <= stack_page + THREAD_SIZE - 32)
57 save_raw_perf_callchain(entry, sp);
58 return;
59 }
60 do {
Deng-Cheng Zhu98f92f22011-01-21 16:19:20 +080061 perf_callchain_store(entry, pc);
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080062 if (entry->nr >= PERF_MAX_STACK_DEPTH)
63 break;
64 pc = unwind_stack(current, &sp, pc, &ra);
65 } while (pc);
66#else
Deng-Cheng Zhu7e788d92010-10-12 19:37:23 +080067 save_raw_perf_callchain(entry, sp);
68#endif
69}