aboutsummaryrefslogtreecommitdiffstats
path: root/arch/tile/kernel
diff options
context:
space:
mode:
authorTony Lu <zlu@tilera.com>2013-08-09 13:26:09 -0400
committerChris Metcalf <cmetcalf@tilera.com>2013-08-30 10:20:13 -0400
commita61fd5e3662d576998d72f80376f23b6ef083d6e (patch)
tree396778bb72c002fb3cca77c9430ec3fb327daa1e /arch/tile/kernel
parent9ae09838470a68edf0245cd60c623df2d5993a8f (diff)
tile: support ftrace on tilegx
This commit adds support for static ftrace, graph function support, and dynamic tracer support. Signed-off-by: Tony Lu <zlu@tilera.com> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Diffstat (limited to 'arch/tile/kernel')
-rw-r--r--arch/tile/kernel/Makefile6
-rw-r--r--arch/tile/kernel/ftrace.c246
-rw-r--r--arch/tile/kernel/mcount_64.S224
-rw-r--r--arch/tile/kernel/vmlinux.lds.S1
4 files changed, 477 insertions, 0 deletions
diff --git a/arch/tile/kernel/Makefile b/arch/tile/kernel/Makefile
index c4a957aad26a..2e6eaa11b60d 100644
--- a/arch/tile/kernel/Makefile
+++ b/arch/tile/kernel/Makefile
@@ -9,6 +9,11 @@ obj-y := backtrace.o entry.o hvglue.o irq.o messaging.o \
9 sysfs.o time.o traps.o unaligned.o vdso.o \ 9 sysfs.o time.o traps.o unaligned.o vdso.o \
10 intvec_$(BITS).o regs_$(BITS).o tile-desc_$(BITS).o 10 intvec_$(BITS).o regs_$(BITS).o tile-desc_$(BITS).o
11 11
12ifdef CONFIG_FUNCTION_TRACER
13CFLAGS_REMOVE_ftrace.o = -pg
14CFLAGS_REMOVE_early_printk.o = -pg
15endif
16
12obj-$(CONFIG_HARDWALL) += hardwall.o 17obj-$(CONFIG_HARDWALL) += hardwall.o
13obj-$(CONFIG_COMPAT) += compat.o compat_signal.o 18obj-$(CONFIG_COMPAT) += compat.o compat_signal.o
14obj-$(CONFIG_SMP) += smpboot.o smp.o tlb.o 19obj-$(CONFIG_SMP) += smpboot.o smp.o tlb.o
@@ -22,5 +27,6 @@ obj-$(CONFIG_PCI) += pci.o
22endif 27endif
23obj-$(CONFIG_TILE_USB) += usb.o 28obj-$(CONFIG_TILE_USB) += usb.o
24obj-$(CONFIG_TILE_HVGLUE_TRACE) += hvglue_trace.o 29obj-$(CONFIG_TILE_HVGLUE_TRACE) += hvglue_trace.o
30obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o mcount_64.o
25 31
26obj-y += vdso/ 32obj-y += vdso/
diff --git a/arch/tile/kernel/ftrace.c b/arch/tile/kernel/ftrace.c
new file mode 100644
index 000000000000..f1c452092eeb
--- /dev/null
+++ b/arch/tile/kernel/ftrace.c
@@ -0,0 +1,246 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
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, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx specific ftrace support
15 */
16
17#include <linux/ftrace.h>
18#include <linux/uaccess.h>
19
20#include <asm/cacheflush.h>
21#include <asm/ftrace.h>
22#include <asm/sections.h>
23
24#include <arch/opcode.h>
25
26#ifdef CONFIG_DYNAMIC_FTRACE
27
28static inline tilegx_bundle_bits NOP(void)
29{
30 return create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
31 create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
32 create_Opcode_X0(RRR_0_OPCODE_X0) |
33 create_UnaryOpcodeExtension_X1(NOP_UNARY_OPCODE_X1) |
34 create_RRROpcodeExtension_X1(UNARY_RRR_0_OPCODE_X1) |
35 create_Opcode_X1(RRR_0_OPCODE_X1);
36}
37
38static int machine_stopped __read_mostly;
39
40int ftrace_arch_code_modify_prepare(void)
41{
42 machine_stopped = 1;
43 return 0;
44}
45
46int ftrace_arch_code_modify_post_process(void)
47{
48 flush_icache_range(0, CHIP_L1I_CACHE_SIZE());
49 machine_stopped = 0;
50 return 0;
51}
52
53/*
54 * Put { move r10, lr; jal ftrace_caller } in a bundle, this lets dynamic
55 * tracer just add one cycle overhead to every kernel function when disabled.
56 */
57static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
58 bool link)
59{
60 tilegx_bundle_bits opcode_x0, opcode_x1;
61 long pcrel_by_instr = (addr - pc) >> TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES;
62
63 if (link) {
64 /* opcode: jal addr */
65 opcode_x1 =
66 create_Opcode_X1(JUMP_OPCODE_X1) |
67 create_JumpOpcodeExtension_X1(JAL_JUMP_OPCODE_X1) |
68 create_JumpOff_X1(pcrel_by_instr);
69 } else {
70 /* opcode: j addr */
71 opcode_x1 =
72 create_Opcode_X1(JUMP_OPCODE_X1) |
73 create_JumpOpcodeExtension_X1(J_JUMP_OPCODE_X1) |
74 create_JumpOff_X1(pcrel_by_instr);
75 }
76
77 if (addr == FTRACE_ADDR) {
78 /* opcode: or r10, lr, zero */
79 opcode_x0 =
80 create_Dest_X0(10) |
81 create_SrcA_X0(TREG_LR) |
82 create_SrcB_X0(TREG_ZERO) |
83 create_RRROpcodeExtension_X0(OR_RRR_0_OPCODE_X0) |
84 create_Opcode_X0(RRR_0_OPCODE_X0);
85 } else {
86 /* opcode: fnop */
87 opcode_x0 =
88 create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
89 create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
90 create_Opcode_X0(RRR_0_OPCODE_X0);
91 }
92
93 return opcode_x1 | opcode_x0;
94}
95
96static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
97{
98 return NOP();
99}
100
101static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr)
102{
103 return ftrace_gen_branch(pc, addr, true);
104}
105
106static int ftrace_modify_code(unsigned long pc, unsigned long old,
107 unsigned long new)
108{
109 unsigned long pc_wr;
110
111 /* Check if the address is in kernel text space and module space. */
112 if (!kernel_text_address(pc))
113 return -EINVAL;
114
115 /* Operate on writable kernel text mapping. */
116 pc_wr = pc - MEM_SV_START + PAGE_OFFSET;
117
118 if (probe_kernel_write((void *)pc_wr, &new, MCOUNT_INSN_SIZE))
119 return -EPERM;
120
121 smp_wmb();
122
123 if (!machine_stopped && num_online_cpus() > 1)
124 flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
125
126 return 0;
127}
128
129int ftrace_update_ftrace_func(ftrace_func_t func)
130{
131 unsigned long pc, old;
132 unsigned long new;
133 int ret;
134
135 pc = (unsigned long)&ftrace_call;
136 memcpy(&old, &ftrace_call, MCOUNT_INSN_SIZE);
137 new = ftrace_call_replace(pc, (unsigned long)func);
138
139 ret = ftrace_modify_code(pc, old, new);
140
141 return ret;
142}
143
144int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
145{
146 unsigned long new, old;
147 unsigned long ip = rec->ip;
148
149 old = ftrace_nop_replace(rec);
150 new = ftrace_call_replace(ip, addr);
151
152 return ftrace_modify_code(rec->ip, old, new);
153}
154
155int ftrace_make_nop(struct module *mod,
156 struct dyn_ftrace *rec, unsigned long addr)
157{
158 unsigned long ip = rec->ip;
159 unsigned long old;
160 unsigned long new;
161 int ret;
162
163 old = ftrace_call_replace(ip, addr);
164 new = ftrace_nop_replace(rec);
165 ret = ftrace_modify_code(ip, old, new);
166
167 return ret;