]>
Commit | Line | Data |
---|---|---|
c32e827b SR |
1 | /* |
2 | * Stage 3 of the trace events. | |
3 | * | |
4 | * Override the macros in <trace/trace_event_types.h> to include the following: | |
5 | * | |
6 | * static void ftrace_event_<call>(proto) | |
7 | * { | |
ef18012b | 8 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); |
c32e827b SR |
9 | * } |
10 | * | |
11 | * static int ftrace_reg_event_<call>(void) | |
12 | * { | |
ef18012b | 13 | * int ret; |
c32e827b | 14 | * |
ef18012b SR |
15 | * ret = register_trace_<call>(ftrace_event_<call>); |
16 | * if (!ret) | |
17 | * pr_info("event trace: Could not activate trace point " | |
18 | * "probe to <call>"); | |
19 | * return ret; | |
c32e827b SR |
20 | * } |
21 | * | |
22 | * static void ftrace_unreg_event_<call>(void) | |
23 | * { | |
ef18012b | 24 | * unregister_trace_<call>(ftrace_event_<call>); |
c32e827b SR |
25 | * } |
26 | * | |
27 | * For those macros defined with TRACE_FORMAT: | |
28 | * | |
29 | * static struct ftrace_event_call __used | |
30 | * __attribute__((__aligned__(4))) | |
31 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
ef18012b SR |
32 | * .name = "<call>", |
33 | * .regfunc = ftrace_reg_event_<call>, | |
34 | * .unregfunc = ftrace_unreg_event_<call>, | |
c32e827b SR |
35 | * } |
36 | * | |
37 | * | |
157587d7 | 38 | * For those macros defined with TRACE_EVENT: |
c32e827b SR |
39 | * |
40 | * static struct ftrace_event_call event_<call>; | |
41 | * | |
42 | * static void ftrace_raw_event_<call>(proto) | |
43 | * { | |
ef18012b SR |
44 | * struct ring_buffer_event *event; |
45 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | |
46 | * unsigned long irq_flags; | |
47 | * int pc; | |
48 | * | |
49 | * local_save_flags(irq_flags); | |
50 | * pc = preempt_count(); | |
51 | * | |
52 | * event = trace_current_buffer_lock_reserve(event_<call>.id, | |
53 | * sizeof(struct ftrace_raw_<call>), | |
54 | * irq_flags, pc); | |
55 | * if (!event) | |
56 | * return; | |
57 | * entry = ring_buffer_event_data(event); | |
58 | * | |
59 | * <assign>; <-- Here we assign the entries by the __field and | |
0e3d0f05 | 60 | * __array macros. |
c32e827b | 61 | * |
ef18012b | 62 | * trace_current_buffer_unlock_commit(event, irq_flags, pc); |
c32e827b SR |
63 | * } |
64 | * | |
65 | * static int ftrace_raw_reg_event_<call>(void) | |
66 | * { | |
ef18012b | 67 | * int ret; |
c32e827b | 68 | * |
ef18012b SR |
69 | * ret = register_trace_<call>(ftrace_raw_event_<call>); |
70 | * if (!ret) | |
71 | * pr_info("event trace: Could not activate trace point " | |
72 | * "probe to <call>"); | |
73 | * return ret; | |
c32e827b SR |
74 | * } |
75 | * | |
76 | * static void ftrace_unreg_event_<call>(void) | |
77 | * { | |
ef18012b | 78 | * unregister_trace_<call>(ftrace_raw_event_<call>); |
c32e827b SR |
79 | * } |
80 | * | |
81 | * static struct trace_event ftrace_event_type_<call> = { | |
ef18012b | 82 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
c32e827b SR |
83 | * }; |
84 | * | |
85 | * static int ftrace_raw_init_event_<call>(void) | |
86 | * { | |
ef18012b | 87 | * int id; |
c32e827b | 88 | * |
ef18012b SR |
89 | * id = register_ftrace_event(&ftrace_event_type_<call>); |
90 | * if (!id) | |
91 | * return -ENODEV; | |
92 | * event_<call>.id = id; | |
93 | * return 0; | |
c32e827b SR |
94 | * } |
95 | * | |
96 | * static struct ftrace_event_call __used | |
97 | * __attribute__((__aligned__(4))) | |
98 | * __attribute__((section("_ftrace_events"))) event_<call> = { | |
ef18012b | 99 | * .name = "<call>", |
0e3d0f05 | 100 | * .system = "<system>", |
ef18012b SR |
101 | * .raw_init = ftrace_raw_init_event_<call>, |
102 | * .regfunc = ftrace_reg_event_<call>, | |
103 | * .unregfunc = ftrace_unreg_event_<call>, | |
981d081e | 104 | * .show_format = ftrace_format_<call>, |
c32e827b SR |
105 | * } |
106 | * | |
107 | */ | |
108 | ||
2939b046 SR |
109 | #undef TP_FMT |
110 | #define TP_FMT(fmt, args...) fmt "\n", ##args | |
c32e827b SR |
111 | |
112 | #define _TRACE_FORMAT(call, proto, args, fmt) \ | |
113 | static void ftrace_event_##call(proto) \ | |
114 | { \ | |
efed792d | 115 | event_trace_printk(_RET_IP_, #call ": " fmt); \ |
c32e827b SR |
116 | } \ |
117 | \ | |
118 | static int ftrace_reg_event_##call(void) \ | |
119 | { \ | |
120 | int ret; \ | |
121 | \ | |
122 | ret = register_trace_##call(ftrace_event_##call); \ | |
633ddaa7 | 123 | if (ret) \ |
c32e827b | 124 | pr_info("event trace: Could not activate trace point " \ |
633ddaa7 | 125 | "probe to " #call "\n"); \ |
c32e827b SR |
126 | return ret; \ |
127 | } \ | |
128 | \ | |
129 | static void ftrace_unreg_event_##call(void) \ | |
130 | { \ | |
131 | unregister_trace_##call(ftrace_event_##call); \ | |
132 | } \ | |
28bea271 PZ |
133 | \ |
134 | static struct ftrace_event_call event_##call; \ | |
135 | \ | |
136 | static int ftrace_init_event_##call(void) \ | |
137 | { \ | |
138 | int id; \ | |
139 | \ | |
140 | id = register_ftrace_event(NULL); \ | |
141 | if (!id) \ | |
142 | return -ENODEV; \ | |
143 | event_##call.id = id; \ | |
144 | return 0; \ | |
145 | } | |
c32e827b SR |
146 | |
147 | #undef TRACE_FORMAT | |
148 | #define TRACE_FORMAT(call, proto, args, fmt) \ | |
149 | _TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt)) \ | |
150 | static struct ftrace_event_call __used \ | |
151 | __attribute__((__aligned__(4))) \ | |
152 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
ef18012b | 153 | .name = #call, \ |
9cc26a26 | 154 | .system = __stringify(TRACE_SYSTEM), \ |
28bea271 | 155 | .raw_init = ftrace_init_event_##call, \ |
c32e827b SR |
156 | .regfunc = ftrace_reg_event_##call, \ |
157 | .unregfunc = ftrace_unreg_event_##call, \ | |
158 | } | |
159 | ||
da4d0302 SR |
160 | #undef __entry |
161 | #define __entry entry | |
d20e3b03 | 162 | |
da4d0302 | 163 | #undef TRACE_EVENT |
30a8fecc | 164 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
c32e827b SR |
165 | \ |
166 | static struct ftrace_event_call event_##call; \ | |
167 | \ | |
168 | static void ftrace_raw_event_##call(proto) \ | |
169 | { \ | |
170 | struct ring_buffer_event *event; \ | |
171 | struct ftrace_raw_##call *entry; \ | |
172 | unsigned long irq_flags; \ | |
173 | int pc; \ | |
174 | \ | |
175 | local_save_flags(irq_flags); \ | |
176 | pc = preempt_count(); \ | |
177 | \ | |
178 | event = trace_current_buffer_lock_reserve(event_##call.id, \ | |
ef18012b | 179 | sizeof(struct ftrace_raw_##call), \ |
c32e827b SR |
180 | irq_flags, pc); \ |
181 | if (!event) \ | |
182 | return; \ | |
183 | entry = ring_buffer_event_data(event); \ | |
184 | \ | |
da4d0302 | 185 | assign; \ |
c32e827b SR |
186 | \ |
187 | trace_current_buffer_unlock_commit(event, irq_flags, pc); \ | |
188 | } \ | |
189 | \ | |
190 | static int ftrace_raw_reg_event_##call(void) \ | |
191 | { \ | |
192 | int ret; \ | |
193 | \ | |
194 | ret = register_trace_##call(ftrace_raw_event_##call); \ | |
633ddaa7 | 195 | if (ret) \ |
c32e827b | 196 | pr_info("event trace: Could not activate trace point " \ |
633ddaa7 | 197 | "probe to " #call "\n"); \ |
c32e827b SR |
198 | return ret; \ |
199 | } \ | |
200 | \ | |
201 | static void ftrace_raw_unreg_event_##call(void) \ | |
202 | { \ | |
203 | unregister_trace_##call(ftrace_raw_event_##call); \ | |
204 | } \ | |
205 | \ | |
206 | static struct trace_event ftrace_event_type_##call = { \ | |
207 | .trace = ftrace_raw_output_##call, \ | |
208 | }; \ | |
209 | \ | |
210 | static int ftrace_raw_init_event_##call(void) \ | |
211 | { \ | |
212 | int id; \ | |
213 | \ | |
214 | id = register_ftrace_event(&ftrace_event_type_##call); \ | |
215 | if (!id) \ | |
216 | return -ENODEV; \ | |
217 | event_##call.id = id; \ | |
218 | return 0; \ | |
219 | } \ | |
220 | \ | |
221 | static struct ftrace_event_call __used \ | |
222 | __attribute__((__aligned__(4))) \ | |
223 | __attribute__((section("_ftrace_events"))) event_##call = { \ | |
ef18012b | 224 | .name = #call, \ |
9cc26a26 | 225 | .system = __stringify(TRACE_SYSTEM), \ |
c32e827b | 226 | .raw_init = ftrace_raw_init_event_##call, \ |
da4d0302 SR |
227 | .regfunc = ftrace_raw_reg_event_##call, \ |
228 | .unregfunc = ftrace_raw_unreg_event_##call, \ | |
981d081e | 229 | .show_format = ftrace_format_##call, \ |
c32e827b | 230 | } |