]>
Commit | Line | Data |
---|---|---|
bac5fb97 | 1 | |
bc0c38d1 SR |
2 | #ifndef _LINUX_KERNEL_TRACE_H |
3 | #define _LINUX_KERNEL_TRACE_H | |
4 | ||
5 | #include <linux/fs.h> | |
60063497 | 6 | #include <linux/atomic.h> |
bc0c38d1 SR |
7 | #include <linux/sched.h> |
8 | #include <linux/clocksource.h> | |
3928a8a2 | 9 | #include <linux/ring_buffer.h> |
bd8ac686 | 10 | #include <linux/mmiotrace.h> |
4e5292ea | 11 | #include <linux/tracepoint.h> |
d13744cd | 12 | #include <linux/ftrace.h> |
24f1e32c | 13 | #include <linux/hw_breakpoint.h> |
9504504c | 14 | #include <linux/trace_seq.h> |
af658dca | 15 | #include <linux/trace_events.h> |
52f5684c | 16 | #include <linux/compiler.h> |
19a7fe20 | 17 | #include <linux/trace_seq.h> |
9504504c | 18 | |
12ab74ee SR |
19 | #ifdef CONFIG_FTRACE_SYSCALLS |
20 | #include <asm/unistd.h> /* For NR_SYSCALLS */ | |
21 | #include <asm/syscall.h> /* some archs define it here */ | |
22 | #endif | |
23 | ||
72829bc3 TG |
24 | enum trace_type { |
25 | __TRACE_FIRST_TYPE = 0, | |
26 | ||
27 | TRACE_FN, | |
28 | TRACE_CTX, | |
29 | TRACE_WAKE, | |
30 | TRACE_STACK, | |
dd0e545f | 31 | TRACE_PRINT, |
48ead020 | 32 | TRACE_BPRINT, |
bd8ac686 PP |
33 | TRACE_MMIO_RW, |
34 | TRACE_MMIO_MAP, | |
9f029e83 | 35 | TRACE_BRANCH, |
287b6e68 FW |
36 | TRACE_GRAPH_RET, |
37 | TRACE_GRAPH_ENT, | |
02b67518 | 38 | TRACE_USER_STACK, |
c71a8961 | 39 | TRACE_BLK, |
09ae7234 | 40 | TRACE_BPUTS, |
72829bc3 | 41 | |
f0868d1e | 42 | __TRACE_LAST_TYPE, |
72829bc3 TG |
43 | }; |
44 | ||
bc0c38d1 | 45 | |
0a1c49db SR |
46 | #undef __field |
47 | #define __field(type, item) type item; | |
86387f7e | 48 | |
d7315094 SR |
49 | #undef __field_struct |
50 | #define __field_struct(type, item) __field(type, item) | |
86387f7e | 51 | |
d7315094 SR |
52 | #undef __field_desc |
53 | #define __field_desc(type, container, item) | |
02b67518 | 54 | |
0a1c49db SR |
55 | #undef __array |
56 | #define __array(type, item, size) type item[size]; | |
1427cdf0 | 57 | |
d7315094 SR |
58 | #undef __array_desc |
59 | #define __array_desc(type, container, item, size) | |
777e208d | 60 | |
0a1c49db SR |
61 | #undef __dynamic_array |
62 | #define __dynamic_array(type, item) type item[]; | |
777e208d | 63 | |
0a1c49db SR |
64 | #undef F_STRUCT |
65 | #define F_STRUCT(args...) args | |
74239072 | 66 | |
0a1c49db | 67 | #undef FTRACE_ENTRY |
02aa3162 JO |
68 | #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \ |
69 | struct struct_name { \ | |
70 | struct trace_entry ent; \ | |
71 | tstruct \ | |
0a1c49db | 72 | } |
777e208d | 73 | |
0a1c49db | 74 | #undef FTRACE_ENTRY_DUP |
02aa3162 | 75 | #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter) |
1e9b51c2 | 76 | |
e59a0bff | 77 | #undef FTRACE_ENTRY_REG |
02aa3162 JO |
78 | #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \ |
79 | filter, regfn) \ | |
80 | FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ | |
81 | filter) | |
e59a0bff | 82 | |
0a1c49db | 83 | #include "trace_entries.h" |
36994e58 | 84 | |
0a1c49db SR |
85 | /* |
86 | * syscalls are special, and need special handling, this is why | |
87 | * they are not included in trace_entries.h | |
88 | */ | |
bed1ffca FW |
89 | struct syscall_trace_enter { |
90 | struct trace_entry ent; | |
91 | int nr; | |
92 | unsigned long args[]; | |
93 | }; | |
94 | ||
95 | struct syscall_trace_exit { | |
96 | struct trace_entry ent; | |
97 | int nr; | |
99df5a6a | 98 | long ret; |
bed1ffca FW |
99 | }; |
100 | ||
93ccae7a | 101 | struct kprobe_trace_entry_head { |
413d37d1 MH |
102 | struct trace_entry ent; |
103 | unsigned long ip; | |
413d37d1 MH |
104 | }; |
105 | ||
93ccae7a | 106 | struct kretprobe_trace_entry_head { |
413d37d1 MH |
107 | struct trace_entry ent; |
108 | unsigned long func; | |
109 | unsigned long ret_ip; | |
413d37d1 MH |
110 | }; |
111 | ||
fc5e27ae PP |
112 | /* |
113 | * trace_flag_type is an enumeration that holds different | |
114 | * states when a trace occurs. These are: | |
9244489a | 115 | * IRQS_OFF - interrupts were disabled |
9de36825 | 116 | * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags |
bd9cfca9 | 117 | * NEED_RESCHED - reschedule is requested |
9244489a SR |
118 | * HARDIRQ - inside an interrupt handler |
119 | * SOFTIRQ - inside a softirq handler | |
fc5e27ae PP |
120 | */ |
121 | enum trace_flag_type { | |
122 | TRACE_FLAG_IRQS_OFF = 0x01, | |
9244489a SR |
123 | TRACE_FLAG_IRQS_NOSUPPORT = 0x02, |
124 | TRACE_FLAG_NEED_RESCHED = 0x04, | |
125 | TRACE_FLAG_HARDIRQ = 0x08, | |
126 | TRACE_FLAG_SOFTIRQ = 0x10, | |
e5137b50 | 127 | TRACE_FLAG_PREEMPT_RESCHED = 0x20, |
7e6867bf | 128 | TRACE_FLAG_NMI = 0x40, |
fc5e27ae PP |
129 | }; |
130 | ||
5bf9a1ee | 131 | #define TRACE_BUF_SIZE 1024 |
bc0c38d1 | 132 | |
2b6080f2 SR |
133 | struct trace_array; |
134 | ||
bc0c38d1 SR |
135 | /* |
136 | * The CPU trace array - it consists of thousands of trace entries | |
137 | * plus some other descriptor data: (for example which task started | |
138 | * the trace, etc.) | |
139 | */ | |
140 | struct trace_array_cpu { | |
bc0c38d1 | 141 | atomic_t disabled; |
2cadf913 | 142 | void *buffer_page; /* ring buffer spare */ |
4e3c3333 | 143 | |
438ced17 | 144 | unsigned long entries; |
bc0c38d1 SR |
145 | unsigned long saved_latency; |
146 | unsigned long critical_start; | |
147 | unsigned long critical_end; | |
148 | unsigned long critical_sequence; | |
149 | unsigned long nice; | |
150 | unsigned long policy; | |
151 | unsigned long rt_priority; | |
2f26ebd5 | 152 | unsigned long skipped_entries; |
bc0c38d1 SR |
153 | cycle_t preempt_timestamp; |
154 | pid_t pid; | |
d20b92ab | 155 | kuid_t uid; |
bc0c38d1 | 156 | char comm[TASK_COMM_LEN]; |
3fdaf80f SRRH |
157 | |
158 | bool ignore_pid; | |
345ddcc8 SRRH |
159 | #ifdef CONFIG_FUNCTION_TRACER |
160 | bool ftrace_ignore_pid; | |
161 | #endif | |
bc0c38d1 SR |
162 | }; |
163 | ||
2b6080f2 | 164 | struct tracer; |
37aea98b | 165 | struct trace_option_dentry; |
2b6080f2 | 166 | |
12883efb SRRH |
167 | struct trace_buffer { |
168 | struct trace_array *tr; | |
169 | struct ring_buffer *buffer; | |
170 | struct trace_array_cpu __percpu *data; | |
171 | cycle_t time_start; | |
172 | int cpu; | |
173 | }; | |
174 | ||
9a38a885 SRRH |
175 | #define TRACE_FLAGS_MAX_SIZE 32 |
176 | ||
37aea98b SRRH |
177 | struct trace_options { |
178 | struct tracer *tracer; | |
179 | struct trace_option_dentry *topts; | |
180 | }; | |
181 | ||
49090107 | 182 | struct trace_pid_list { |
f4d34a87 SR |
183 | int pid_max; |
184 | unsigned long *pids; | |
49090107 SRRH |
185 | }; |
186 | ||
bc0c38d1 SR |
187 | /* |
188 | * The trace array - an array of per-CPU trace arrays. This is the | |
189 | * highest level data structure that individual tracers deal with. | |
190 | * They have on/off state as well: | |
191 | */ | |
192 | struct trace_array { | |
ae63b31e | 193 | struct list_head list; |
277ba044 | 194 | char *name; |
12883efb SRRH |
195 | struct trace_buffer trace_buffer; |
196 | #ifdef CONFIG_TRACER_MAX_TRACE | |
197 | /* | |
198 | * The max_buffer is used to snapshot the trace when a maximum | |
199 | * latency is reached, or when the user initiates a snapshot. | |
200 | * Some tracers will use this to store a maximum trace while | |
201 | * it continues examining live traces. | |
202 | * | |
203 | * The buffers for the max_buffer are set up the same as the trace_buffer | |
204 | * When a snapshot is taken, the buffer of the max_buffer is swapped | |
205 | * with the buffer of the trace_buffer and the buffers are reset for | |
206 | * the trace_buffer so the tracing can continue. | |
207 | */ | |
208 | struct trace_buffer max_buffer; | |
45ad21ca | 209 | bool allocated_snapshot; |
6d9b3fa5 | 210 | unsigned long max_latency; |
12883efb | 211 | #endif |
49090107 | 212 | struct trace_pid_list __rcu *filtered_pids; |
0b9b12c1 SRRH |
213 | /* |
214 | * max_lock is used to protect the swapping of buffers | |
215 | * when taking a max snapshot. The buffers themselves are | |
216 | * protected by per_cpu spinlocks. But the action of the swap | |
217 | * needs its own lock. | |
218 | * | |
219 | * This is defined as a arch_spinlock_t in order to help | |
220 | * with performance when lockdep debugging is enabled. | |
221 | * | |
222 | * It is also used in other places outside the update_max_tr | |
223 | * so it needs to be defined outside of the | |
224 | * CONFIG_TRACER_MAX_TRACE. | |
225 | */ | |
226 | arch_spinlock_t max_lock; | |
499e5470 | 227 | int buffer_disabled; |
12ab74ee SR |
228 | #ifdef CONFIG_FTRACE_SYSCALLS |
229 | int sys_refcount_enter; | |
230 | int sys_refcount_exit; | |
7f1d2f82 SRRH |
231 | struct trace_event_file __rcu *enter_syscall_files[NR_syscalls]; |
232 | struct trace_event_file __rcu *exit_syscall_files[NR_syscalls]; | |
12ab74ee | 233 | #endif |
2b6080f2 SR |
234 | int stop_count; |
235 | int clock_id; | |
37aea98b | 236 | int nr_topts; |
2b6080f2 | 237 | struct tracer *current_trace; |
983f938a | 238 | unsigned int trace_flags; |
9a38a885 | 239 | unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE]; |
ae63b31e | 240 | unsigned int flags; |
2b6080f2 | 241 | raw_spinlock_t start_lock; |
ae63b31e | 242 | struct dentry *dir; |
2b6080f2 SR |
243 | struct dentry *options; |
244 | struct dentry *percpu_dir; | |
ae63b31e | 245 | struct dentry *event_dir; |
37aea98b | 246 | struct trace_options *topts; |
ae63b31e SR |
247 | struct list_head systems; |
248 | struct list_head events; | |
ccfe9e42 | 249 | cpumask_var_t tracing_cpumask; /* only trace on set CPUs */ |
a695cb58 | 250 | int ref; |
f20a5806 SRRH |
251 | #ifdef CONFIG_FUNCTION_TRACER |
252 | struct ftrace_ops *ops; | |
345ddcc8 | 253 | struct trace_pid_list __rcu *function_pids; |
f20a5806 SRRH |
254 | /* function tracing enabled */ |
255 | int function_enabled; | |
256 | #endif | |
bc0c38d1 SR |
257 | }; |
258 | ||
ae63b31e SR |
259 | enum { |
260 | TRACE_ARRAY_FL_GLOBAL = (1 << 0) | |
261 | }; | |
262 | ||
263 | extern struct list_head ftrace_trace_arrays; | |
264 | ||
a8227415 AL |
265 | extern struct mutex trace_types_lock; |
266 | ||
8e2e2fa4 SRRH |
267 | extern int trace_array_get(struct trace_array *tr); |
268 | extern void trace_array_put(struct trace_array *tr); | |
269 | ||
ae63b31e SR |
270 | /* |
271 | * The global tracer (top) should be the first trace array added, | |
272 | * but we check the flag anyway. | |
273 | */ | |
274 | static inline struct trace_array *top_trace_array(void) | |
275 | { | |
276 | struct trace_array *tr; | |
277 | ||
da9c3413 | 278 | if (list_empty(&ftrace_trace_arrays)) |
dc81e5e3 YY |
279 | return NULL; |
280 | ||
ae63b31e SR |
281 | tr = list_entry(ftrace_trace_arrays.prev, |
282 | typeof(*tr), list); | |
283 | WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL)); | |
284 | return tr; | |
285 | } | |
286 | ||
7104f300 SR |
287 | #define FTRACE_CMP_TYPE(var, type) \ |
288 | __builtin_types_compatible_p(typeof(var), type *) | |
289 | ||
290 | #undef IF_ASSIGN | |
291 | #define IF_ASSIGN(var, entry, etype, id) \ | |
292 | if (FTRACE_CMP_TYPE(var, etype)) { \ | |
293 | var = (typeof(var))(entry); \ | |
294 | WARN_ON(id && (entry)->type != id); \ | |
295 | break; \ | |
296 | } | |
297 | ||
298 | /* Will cause compile errors if type is not found. */ | |
299 | extern void __ftrace_bad_type(void); | |
300 | ||
301 | /* | |
302 | * The trace_assign_type is a verifier that the entry type is | |
303 | * the same as the type being assigned. To add new types simply | |
304 | * add a line with the following format: | |
305 | * | |
306 | * IF_ASSIGN(var, ent, type, id); | |
307 | * | |
308 | * Where "type" is the trace type that includes the trace_entry | |
309 | * as the "ent" item. And "id" is the trace identifier that is | |
310 | * used in the trace_type enum. | |
311 | * | |
312 | * If the type can have more than one id, then use zero. | |
313 | */ | |
314 | #define trace_assign_type(var, ent) \ | |
315 | do { \ | |
316 | IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \ | |
317 | IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \ | |
7104f300 | 318 | IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \ |
02b67518 | 319 | IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\ |
7104f300 | 320 | IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \ |
48ead020 | 321 | IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \ |
09ae7234 | 322 | IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \ |
7104f300 SR |
323 | IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \ |
324 | TRACE_MMIO_RW); \ | |
325 | IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \ | |
326 | TRACE_MMIO_MAP); \ | |
9f029e83 | 327 | IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \ |
287b6e68 FW |
328 | IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \ |
329 | TRACE_GRAPH_ENT); \ | |
330 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ | |
331 | TRACE_GRAPH_RET); \ | |
7104f300 SR |
332 | __ftrace_bad_type(); \ |
333 | } while (0) | |
2c4f035f | 334 | |
adf9f195 FW |
335 | /* |
336 | * An option specific to a tracer. This is a boolean value. | |
337 | * The bit is the bit index that sets its value on the | |
338 | * flags value in struct tracer_flags. | |
339 | */ | |
340 | struct tracer_opt { | |
9de36825 IM |
341 | const char *name; /* Will appear on the trace_options file */ |
342 | u32 bit; /* Mask assigned in val field in tracer_flags */ | |
adf9f195 FW |
343 | }; |
344 | ||
345 | /* | |
346 | * The set of specific options for a tracer. Your tracer | |
347 | * have to set the initial value of the flags val. | |
348 | */ | |
349 | struct tracer_flags { | |
350 | u32 val; | |
9de36825 | 351 | struct tracer_opt *opts; |
d39cdd20 | 352 | struct tracer *trace; |
adf9f195 FW |
353 | }; |
354 | ||
355 | /* Makes more easy to define a tracer opt */ | |
356 | #define TRACER_OPT(s, b) .name = #s, .bit = b | |
357 | ||
034939b6 | 358 | |
41d9c0be SRRH |
359 | struct trace_option_dentry { |
360 | struct tracer_opt *opt; | |
361 | struct tracer_flags *flags; | |
362 | struct trace_array *tr; | |
363 | struct dentry *entry; | |
364 | }; | |
365 | ||
6eaaa5d5 | 366 | /** |
8434dc93 | 367 | * struct tracer - a specific tracer and its callbacks to interact with tracefs |
6eaaa5d5 FW |
368 | * @name: the name chosen to select it on the available_tracers file |
369 | * @init: called when one switches to this tracer (echo name > current_tracer) | |
370 | * @reset: called when one switches to another tracer | |
05a724bd CH |
371 | * @start: called when tracing is unpaused (echo 1 > tracing_on) |
372 | * @stop: called when tracing is paused (echo 0 > tracing_on) | |
6508fa76 | 373 | * @update_thresh: called when tracing_thresh is updated |
6eaaa5d5 FW |
374 | * @open: called when the trace file is opened |
375 | * @pipe_open: called when the trace_pipe file is opened | |
6eaaa5d5 | 376 | * @close: called when the trace file is released |
c521efd1 | 377 | * @pipe_close: called when the trace_pipe file is released |
6eaaa5d5 FW |
378 | * @read: override the default read callback on trace_pipe |
379 | * @splice_read: override the default splice_read callback on trace_pipe | |
380 | * @selftest: selftest to run on boot (see trace_selftest.c) | |
381 | * @print_headers: override the first lines that describe your columns | |
382 | * @print_line: callback that prints a trace | |
383 | * @set_flag: signals one of your private flags changed (trace_options file) | |
384 | * @flags: your private flags | |
bc0c38d1 SR |
385 | */ |
386 | struct tracer { | |
387 | const char *name; | |
1c80025a | 388 | int (*init)(struct trace_array *tr); |
bc0c38d1 | 389 | void (*reset)(struct trace_array *tr); |
9036990d SR |
390 | void (*start)(struct trace_array *tr); |
391 | void (*stop)(struct trace_array *tr); | |
6508fa76 | 392 | int (*update_thresh)(struct trace_array *tr); |
bc0c38d1 | 393 | void (*open)(struct trace_iterator *iter); |
107bad8b | 394 | void (*pipe_open)(struct trace_iterator *iter); |
bc0c38d1 | 395 | void (*close)(struct trace_iterator *iter); |
c521efd1 | 396 | void (*pipe_close)(struct trace_iterator *iter); |
107bad8b SR |
397 | ssize_t (*read)(struct trace_iterator *iter, |
398 | struct file *filp, char __user *ubuf, | |
399 | size_t cnt, loff_t *ppos); | |
3c56819b EGM |
400 | ssize_t (*splice_read)(struct trace_iterator *iter, |
401 | struct file *filp, | |
402 | loff_t *ppos, | |
403 | struct pipe_inode_info *pipe, | |
404 | size_t len, | |
405 | unsigned int flags); | |
60a11774 SR |
406 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
407 | int (*selftest)(struct tracer *trace, | |
408 | struct trace_array *tr); | |
409 | #endif | |
8bba1bf5 | 410 | void (*print_header)(struct seq_file *m); |
2c4f035f | 411 | enum print_line_t (*print_line)(struct trace_iterator *iter); |
adf9f195 | 412 | /* If you handled the flag setting, return 0 */ |
8c1a49ae SRRH |
413 | int (*set_flag)(struct trace_array *tr, |
414 | u32 old_flags, u32 bit, int set); | |
613f04a0 | 415 | /* Return 0 if OK with change, else return non-zero */ |
bf6065b5 | 416 | int (*flag_changed)(struct trace_array *tr, |
613f04a0 | 417 | u32 mask, int set); |
bc0c38d1 | 418 | struct tracer *next; |
9de36825 | 419 | struct tracer_flags *flags; |
50512ab5 | 420 | int enabled; |
cf6ab6d9 | 421 | int ref; |
f43c738b | 422 | bool print_max; |
607e2ea1 | 423 | bool allow_instances; |
12883efb | 424 | #ifdef CONFIG_TRACER_MAX_TRACE |
f43c738b | 425 | bool use_max_tr; |
12883efb | 426 | #endif |
bc0c38d1 SR |
427 | }; |
428 | ||
f9520750 | 429 | |
e4a3f541 | 430 | /* Only current can touch trace_recursion */ |
e4a3f541 | 431 | |
edc15caf SR |
432 | /* |
433 | * For function tracing recursion: | |
434 | * The order of these bits are important. | |
435 | * | |
436 | * When function tracing occurs, the following steps are made: | |
437 | * If arch does not support a ftrace feature: | |
438 | * call internal function (uses INTERNAL bits) which calls... | |
439 | * If callback is registered to the "global" list, the list | |
440 | * function is called and recursion checks the GLOBAL bits. | |
441 | * then this function calls... | |
442 | * The function callback, which can use the FTRACE bits to | |
443 | * check for recursion. | |
444 | * | |
445 | * Now if the arch does not suppport a feature, and it calls | |
446 | * the global list function which calls the ftrace callback | |
447 | * all three of these steps will do a recursion protection. | |
448 | * There's no reason to do one if the previous caller already | |
449 | * did. The recursion that we are protecting against will | |
450 | * go through the same steps again. | |
451 | * | |
452 | * To prevent the multiple recursion checks, if a recursion | |
453 | * bit is set that is higher than the MAX bit of the current | |
454 | * check, then we know that the check was made by the previous | |
455 | * caller, and we can skip the current check. | |
456 | */ | |
e46cbf75 | 457 | enum { |
567cd4da SR |
458 | TRACE_BUFFER_BIT, |
459 | TRACE_BUFFER_NMI_BIT, | |
460 | TRACE_BUFFER_IRQ_BIT, | |
461 | TRACE_BUFFER_SIRQ_BIT, | |
462 | ||
463 | /* Start of function recursion bits */ | |
464 | TRACE_FTRACE_BIT, | |
edc15caf SR |
465 | TRACE_FTRACE_NMI_BIT, |
466 | TRACE_FTRACE_IRQ_BIT, | |
467 | TRACE_FTRACE_SIRQ_BIT, | |
e46cbf75 | 468 | |
4104d326 | 469 | /* INTERNAL_BITs must be greater than FTRACE_BITs */ |
edc15caf SR |
470 | TRACE_INTERNAL_BIT, |
471 | TRACE_INTERNAL_NMI_BIT, | |
472 | TRACE_INTERNAL_IRQ_BIT, | |
473 | TRACE_INTERNAL_SIRQ_BIT, | |
474 | ||
6224beb1 | 475 | TRACE_BRANCH_BIT, |
e4a3f541 SR |
476 | /* |
477 | * Abuse of the trace_recursion. | |
478 | * As we need a way to maintain state if we are tracing the function | |
479 | * graph in irq because we want to trace a particular function that | |
480 | * was called in irq context but we have irq tracing off. Since this | |
481 | * can only be modified by current, we can reuse trace_recursion. | |
482 | */ | |
e46cbf75 SR |
483 | TRACE_IRQ_BIT, |
484 | }; | |
e4a3f541 | 485 | |
e46cbf75 SR |
486 | #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0) |
487 | #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0) | |
488 | #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit))) | |
e4a3f541 | 489 | |
edc15caf SR |
490 | #define TRACE_CONTEXT_BITS 4 |
491 | ||
492 | #define TRACE_FTRACE_START TRACE_FTRACE_BIT | |
493 | #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1) | |
494 | ||
edc15caf SR |
495 | #define TRACE_LIST_START TRACE_INTERNAL_BIT |
496 | #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1) | |
497 | ||
498 | #define TRACE_CONTEXT_MASK TRACE_LIST_MAX | |
499 | ||
500 | static __always_inline int trace_get_context_bit(void) | |
501 | { | |
502 | int bit; | |
503 | ||
504 | if (in_interrupt()) { | |
505 | if (in_nmi()) | |
506 | bit = 0; | |
507 | ||
508 | else if (in_irq()) | |
509 | bit = 1; | |
510 | else | |
511 | bit = 2; | |
512 | } else | |
513 | bit = 3; | |
514 | ||
515 | return bit; | |
516 | } | |
517 | ||
518 | static __always_inline int trace_test_and_set_recursion(int start, int max) | |
519 | { | |
520 | unsigned int val = current->trace_recursion; | |
521 | int bit; | |
522 | ||
523 | /* A previous recursion check was made */ | |
524 | if ((val & TRACE_CONTEXT_MASK) > max) | |
525 | return 0; | |
526 | ||
527 | bit = trace_get_context_bit() + start; | |
528 | if (unlikely(val & (1 << bit))) | |
529 | return -1; | |
530 | ||
531 | val |= 1 << bit; | |
532 | current->trace_recursion = val; | |
533 | barrier(); | |
534 | ||
535 | return bit; | |
536 | } | |
537 | ||
538 | static __always_inline void trace_clear_recursion(int bit) | |
539 | { | |
540 | unsigned int val = current->trace_recursion; | |
541 | ||
542 | if (!bit) | |
543 | return; | |
544 | ||
545 | bit = 1 << bit; | |
546 | val &= ~bit; | |
547 | ||
548 | barrier(); | |
549 | current->trace_recursion = val; | |
550 | } | |
551 | ||
6d158a81 SR |
552 | static inline struct ring_buffer_iter * |
553 | trace_buffer_iter(struct trace_iterator *iter, int cpu) | |
554 | { | |
555 | if (iter->buffer_iter && iter->buffer_iter[cpu]) | |
556 | return iter->buffer_iter[cpu]; | |
557 | return NULL; | |
558 | } | |
559 | ||
b6f11df2 | 560 | int tracer_init(struct tracer *t, struct trace_array *tr); |
9036990d | 561 | int tracing_is_enabled(void); |
12883efb SRRH |
562 | void tracing_reset(struct trace_buffer *buf, int cpu); |
563 | void tracing_reset_online_cpus(struct trace_buffer *buf); | |
9456f0fa | 564 | void tracing_reset_current(int cpu); |
873c642f | 565 | void tracing_reset_all_online_cpus(void); |
bc0c38d1 | 566 | int tracing_open_generic(struct inode *inode, struct file *filp); |
2e86421d | 567 | bool tracing_is_disabled(void); |
5452af66 | 568 | struct dentry *trace_create_file(const char *name, |
f4ae40a6 | 569 | umode_t mode, |
5452af66 FW |
570 | struct dentry *parent, |
571 | void *data, | |
572 | const struct file_operations *fops); | |
573 | ||
bc0c38d1 | 574 | struct dentry *tracing_init_dentry(void); |
d618b3e6 | 575 | |
51a763dd ACM |
576 | struct ring_buffer_event; |
577 | ||
e77405ad SR |
578 | struct ring_buffer_event * |
579 | trace_buffer_lock_reserve(struct ring_buffer *buffer, | |
580 | int type, | |
581 | unsigned long len, | |
582 | unsigned long flags, | |
583 | int pc); | |
51a763dd | 584 | |
45dcd8b8 PP |
585 | struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, |
586 | struct trace_array_cpu *data); | |
c4a8e8be FW |
587 | |
588 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | |
589 | int *ent_cpu, u64 *ent_ts); | |
590 | ||
7ffbd48d SR |
591 | void __buffer_unlock_commit(struct ring_buffer *buffer, |
592 | struct ring_buffer_event *event); | |
593 | ||
955b61e5 JW |
594 | int trace_empty(struct trace_iterator *iter); |
595 | ||
596 | void *trace_find_next_entry_inc(struct trace_iterator *iter); | |
597 | ||
598 | void trace_init_global_iter(struct trace_iterator *iter); | |
599 | ||
600 | void tracing_iter_reset(struct trace_iterator *iter, int cpu); | |
601 | ||
6fb44b71 | 602 | void trace_function(struct trace_array *tr, |
6fb44b71 SR |
603 | unsigned long ip, |
604 | unsigned long parent_ip, | |
38697053 | 605 | unsigned long flags, int pc); |
0a772620 JO |
606 | void trace_graph_function(struct trace_array *tr, |
607 | unsigned long ip, | |
608 | unsigned long parent_ip, | |
609 | unsigned long flags, int pc); | |
7e9a49ef | 610 | void trace_latency_header(struct seq_file *m); |
62b915f1 JO |
611 | void trace_default_header(struct seq_file *m); |
612 | void print_trace_header(struct seq_file *m, struct trace_iterator *iter); | |
613 | int trace_empty(struct trace_iterator *iter); | |
bc0c38d1 | 614 | |
287b6e68 | 615 | void trace_graph_return(struct ftrace_graph_ret *trace); |
e49dc19c | 616 | int trace_graph_entry(struct ftrace_graph_ent *trace); |
1a0799a8 | 617 | void set_graph_array(struct trace_array *tr); |
1e9b51c2 | 618 | |
41bc8144 SR |
619 | void tracing_start_cmdline_record(void); |
620 | void tracing_stop_cmdline_record(void); | |
bc0c38d1 | 621 | int register_tracer(struct tracer *type); |
b5130b1e | 622 | int is_tracing_stopped(void); |
955b61e5 | 623 | |
098c879e SRRH |
624 | loff_t tracing_lseek(struct file *file, loff_t offset, int whence); |
625 | ||
955b61e5 JW |
626 | extern cpumask_var_t __read_mostly tracing_buffer_mask; |
627 | ||
628 | #define for_each_tracing_cpu(cpu) \ | |
629 | for_each_cpu(cpu, tracing_buffer_mask) | |
bc0c38d1 SR |
630 | |
631 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); | |
632 | ||
0e950173 TB |
633 | extern unsigned long tracing_thresh; |
634 | ||
4e267db1 | 635 | /* PID filtering */ |
76c813e2 SRRH |
636 | |
637 | extern int pid_max; | |
638 | ||
4e267db1 SR |
639 | bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids, |
640 | pid_t search_pid); | |
641 | bool trace_ignore_this_task(struct trace_pid_list *filtered_pids, | |
642 | struct task_struct *task); | |
643 | void trace_filter_add_remove_task(struct trace_pid_list *pid_list, | |
644 | struct task_struct *self, | |
645 | struct task_struct *task); | |
5cc8976b SRRH |
646 | void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos); |
647 | void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos); | |
648 | int trace_pid_show(struct seq_file *m, void *v); | |
76c813e2 SRRH |
649 | void trace_free_pid_list(struct trace_pid_list *pid_list); |
650 | int trace_pid_write(struct trace_pid_list *filtered_pids, | |
651 | struct trace_pid_list **new_pid_list, | |
652 | const char __user *ubuf, size_t cnt); | |
4e267db1 | 653 | |
5d4a9dba | 654 | #ifdef CONFIG_TRACER_MAX_TRACE |
bc0c38d1 SR |
655 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); |
656 | void update_max_tr_single(struct trace_array *tr, | |
657 | struct task_struct *tsk, int cpu); | |
5d4a9dba | 658 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
bc0c38d1 | 659 | |
c0a0d0d3 | 660 | #ifdef CONFIG_STACKTRACE |
e77405ad | 661 | void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, |
c0a0d0d3 FW |
662 | int pc); |
663 | ||
664 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, | |
665 | int pc); | |
666 | #else | |
e1f7992e | 667 | static inline void ftrace_trace_userstack(struct ring_buffer *buffer, |
c0a0d0d3 FW |
668 | unsigned long flags, int pc) |
669 | { | |
670 | } | |
671 | ||
672 | static inline void __trace_stack(struct trace_array *tr, unsigned long flags, | |
673 | int skip, int pc) | |
674 | { | |
675 | } | |
676 | #endif /* CONFIG_STACKTRACE */ | |
53614991 | 677 | |
e309b41d | 678 | extern cycle_t ftrace_now(int cpu); |
bc0c38d1 | 679 | |
4ca53085 | 680 | extern void trace_find_cmdline(int pid, char comm[]); |
c37775d5 | 681 | extern void trace_event_follow_fork(struct trace_array *tr, bool enable); |
f7d48cbd | 682 | |
bc0c38d1 SR |
683 | #ifdef CONFIG_DYNAMIC_FTRACE |
684 | extern unsigned long ftrace_update_tot_cnt; | |
ad97772a | 685 | #endif |
d05cdb25 SR |
686 | #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func |
687 | extern int DYN_FTRACE_TEST_NAME(void); | |
95950c2e SR |
688 | #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2 |
689 | extern int DYN_FTRACE_TEST_NAME2(void); | |
bc0c38d1 | 690 | |
55034cd6 | 691 | extern bool ring_buffer_expanded; |
020e5f85 LZ |
692 | extern bool tracing_selftest_disabled; |
693 | ||
60a11774 | 694 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
60a11774 SR |
695 | extern int trace_selftest_startup_function(struct tracer *trace, |
696 | struct trace_array *tr); | |
7447dce9 FW |
697 | extern int trace_selftest_startup_function_graph(struct tracer *trace, |
698 | struct trace_array *tr); | |
60a11774 SR |
699 | extern int trace_selftest_startup_irqsoff(struct tracer *trace, |
700 | struct trace_array *tr); | |
60a11774 SR |
701 | extern int trace_selftest_startup_preemptoff(struct tracer *trace, |
702 | struct trace_array *tr); | |
60a11774 SR |
703 | extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace, |
704 | struct trace_array *tr); | |
60a11774 SR |
705 | extern int trace_selftest_startup_wakeup(struct tracer *trace, |
706 | struct trace_array *tr); | |
fb1b6d8b SN |
707 | extern int trace_selftest_startup_nop(struct tracer *trace, |
708 | struct trace_array *tr); | |
60a11774 SR |
709 | extern int trace_selftest_startup_sched_switch(struct tracer *trace, |
710 | struct trace_array *tr); | |
80e5ea45 SR |
711 | extern int trace_selftest_startup_branch(struct tracer *trace, |
712 | struct trace_array *tr); | |
8f768993 SRRH |
713 | /* |
714 | * Tracer data references selftest functions that only occur | |
715 | * on boot up. These can be __init functions. Thus, when selftests | |
716 | * are enabled, then the tracers need to reference __init functions. | |
717 | */ | |
718 | #define __tracer_data __refdata | |
719 | #else | |
720 | /* Tracers are seldom changed. Optimize when selftests are disabled. */ | |
721 | #define __tracer_data __read_mostly | |
60a11774 SR |
722 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
723 | ||
c7aafc54 | 724 | extern void *head_page(struct trace_array_cpu *data); |
cf8e3474 | 725 | extern unsigned long long ns2usecs(cycle_t nsec); |
1fd8f2a3 | 726 | extern int |
40ce74f1 | 727 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); |
48ead020 | 728 | extern int |
40ce74f1 | 729 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); |
659372d3 SR |
730 | extern int |
731 | trace_array_vprintk(struct trace_array *tr, | |
732 | unsigned long ip, const char *fmt, va_list args); | |
733 | int trace_array_printk(struct trace_array *tr, | |
734 | unsigned long ip, const char *fmt, ...); | |
12883efb SRRH |
735 | int trace_array_printk_buf(struct ring_buffer *buffer, |
736 | unsigned long ip, const char *fmt, ...); | |
955b61e5 JW |
737 | void trace_printk_seq(struct trace_seq *s); |
738 | enum print_line_t print_trace_line(struct trace_iterator *iter); | |
c7aafc54 | 739 | |
8e1e1df2 BP |
740 | extern char trace_find_mark(unsigned long long duration); |
741 | ||
15e6cb36 | 742 | /* Standard output formatting function used for function return traces */ |
fb52607a | 743 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
62b915f1 JO |
744 | |
745 | /* Flag options */ | |
746 | #define TRACE_GRAPH_PRINT_OVERRUN 0x1 | |
747 | #define TRACE_GRAPH_PRINT_CPU 0x2 | |
748 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 | |
749 | #define TRACE_GRAPH_PRINT_PROC 0x8 | |
750 | #define TRACE_GRAPH_PRINT_DURATION 0x10 | |
751 | #define TRACE_GRAPH_PRINT_ABS_TIME 0x20 | |
ccdb5946 | 752 | #define TRACE_GRAPH_PRINT_IRQS 0x40 |
607e3a29 | 753 | #define TRACE_GRAPH_PRINT_TAIL 0x80 |
55577204 SRRH |
754 | #define TRACE_GRAPH_SLEEP_TIME 0x100 |
755 | #define TRACE_GRAPH_GRAPH_TIME 0x200 | |
6fc84ea7 SRRH |
756 | #define TRACE_GRAPH_PRINT_FILL_SHIFT 28 |
757 | #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT) | |
62b915f1 | 758 | |
55577204 SRRH |
759 | extern void ftrace_graph_sleep_time_control(bool enable); |
760 | extern void ftrace_graph_graph_time_control(bool enable); | |
761 | ||
d7a8d9e9 JO |
762 | extern enum print_line_t |
763 | print_graph_function_flags(struct trace_iterator *iter, u32 flags); | |
764 | extern void print_graph_headers_flags(struct seq_file *s, u32 flags); | |
9d9add34 | 765 | extern void |
0706f1c4 | 766 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); |
62b915f1 JO |
767 | extern void graph_trace_open(struct trace_iterator *iter); |
768 | extern void graph_trace_close(struct trace_iterator *iter); | |
769 | extern int __trace_graph_entry(struct trace_array *tr, | |
770 | struct ftrace_graph_ent *trace, | |
771 | unsigned long flags, int pc); | |
772 | extern void __trace_graph_return(struct trace_array *tr, | |
773 | struct ftrace_graph_ret *trace, | |
774 | unsigned long flags, int pc); | |
775 | ||
ea4e2bc4 SR |
776 | |
777 | #ifdef CONFIG_DYNAMIC_FTRACE | |
778 | /* TODO: make this variable */ | |
779 | #define FTRACE_GRAPH_MAX_FUNCS 32 | |
780 | extern int ftrace_graph_count; | |
781 | extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS]; | |
29ad23b0 NK |
782 | extern int ftrace_graph_notrace_count; |
783 | extern unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS]; | |
ea4e2bc4 SR |
784 | |
785 | static inline int ftrace_graph_addr(unsigned long addr) | |
786 | { | |
787 | int i; | |
788 | ||
9aa72b4b | 789 | if (!ftrace_graph_count) |
ea4e2bc4 SR |
790 | return 1; |
791 | ||
792 | for (i = 0; i < ftrace_graph_count; i++) { | |
e4a3f541 SR |
793 | if (addr == ftrace_graph_funcs[i]) { |
794 | /* | |
795 | * If no irqs are to be traced, but a set_graph_function | |
796 | * is set, and called by an interrupt handler, we still | |
797 | * want to trace it. | |
798 | */ | |
799 | if (in_irq()) | |
800 | trace_recursion_set(TRACE_IRQ_BIT); | |
801 | else | |
802 | trace_recursion_clear(TRACE_IRQ_BIT); | |
ea4e2bc4 | 803 | return 1; |
e4a3f541 | 804 | } |
ea4e2bc4 SR |
805 | } |
806 | ||
807 | return 0; | |
808 | } | |
29ad23b0 NK |
809 | |
810 | static inline int ftrace_graph_notrace_addr(unsigned long addr) | |
811 | { | |
812 | int i; | |
813 | ||
814 | if (!ftrace_graph_notrace_count) | |
815 | return 0; | |
816 | ||
817 | for (i = 0; i < ftrace_graph_notrace_count; i++) { | |
818 | if (addr == ftrace_graph_notrace_funcs[i]) | |
819 | return 1; | |
820 | } | |
821 | ||
822 | return 0; | |
823 | } | |
15e6cb36 | 824 | #else |
6b253930 IM |
825 | static inline int ftrace_graph_addr(unsigned long addr) |
826 | { | |
827 | return 1; | |
ea4e2bc4 | 828 | } |
29ad23b0 NK |
829 | |
830 | static inline int ftrace_graph_notrace_addr(unsigned long addr) | |
831 | { | |
832 | return 0; | |
833 | } | |
ea4e2bc4 | 834 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
ea4e2bc4 | 835 | #else /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 836 | static inline enum print_line_t |
d7a8d9e9 | 837 | print_graph_function_flags(struct trace_iterator *iter, u32 flags) |
15e6cb36 FW |
838 | { |
839 | return TRACE_TYPE_UNHANDLED; | |
840 | } | |
ea4e2bc4 | 841 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 842 | |
756d17ee | 843 | extern struct list_head ftrace_pids; |
804a6851 | 844 | |
1155de47 | 845 | #ifdef CONFIG_FUNCTION_TRACER |
f1ed7c74 | 846 | extern bool ftrace_filter_param __initdata; |
345ddcc8 | 847 | static inline int ftrace_trace_task(struct trace_array *tr) |
804a6851 | 848 | { |
345ddcc8 | 849 | return !this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid); |
804a6851 | 850 | } |
e0a413f6 | 851 | extern int ftrace_is_dead(void); |
591dffda SRRH |
852 | int ftrace_create_function_files(struct trace_array *tr, |
853 | struct dentry *parent); | |
854 | void ftrace_destroy_function_files(struct trace_array *tr); | |
4104d326 SRRH |
855 | void ftrace_init_global_array_ops(struct trace_array *tr); |
856 | void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func); | |
857 | void ftrace_reset_array_ops(struct trace_array *tr); | |
7eea4fce | 858 | int using_ftrace_ops_list_func(void); |
345ddcc8 | 859 | void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer); |
1155de47 | 860 | #else |
345ddcc8 | 861 | static inline int ftrace_trace_task(struct trace_array *tr) |
1155de47 PM |
862 | { |
863 | return 1; | |
864 | } | |
e0a413f6 | 865 | static inline int ftrace_is_dead(void) { return 0; } |
591dffda SRRH |
866 | static inline int |
867 | ftrace_create_function_files(struct trace_array *tr, | |
868 | struct dentry *parent) | |
869 | { | |
870 | return 0; | |
871 | } | |
872 | static inline void ftrace_destroy_function_files(struct trace_array *tr) { } | |
4104d326 SRRH |
873 | static inline __init void |
874 | ftrace_init_global_array_ops(struct trace_array *tr) { } | |
875 | static inline void ftrace_reset_array_ops(struct trace_array *tr) { } | |
345ddcc8 | 876 | static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { } |
4104d326 SRRH |
877 | /* ftace_func_t type is not defined, use macro instead of static inline */ |
878 | #define ftrace_init_array_ops(tr, func) do { } while (0) | |
591dffda SRRH |
879 | #endif /* CONFIG_FUNCTION_TRACER */ |
880 | ||
881 | #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE) | |
882 | void ftrace_create_filter_files(struct ftrace_ops *ops, | |
883 | struct dentry *parent); | |
884 | void ftrace_destroy_filter_files(struct ftrace_ops *ops); | |
885 | #else | |
886 | /* | |
887 | * The ops parameter passed in is usually undefined. | |
888 | * This must be a macro. | |
889 | */ | |
890 | #define ftrace_create_filter_files(ops, parent) do { } while (0) | |
891 | #define ftrace_destroy_filter_files(ops) do { } while (0) | |
892 | #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */ | |
804a6851 | 893 | |
c6650b2e | 894 | bool ftrace_event_is_function(struct trace_event_call *call); |
ced39002 | 895 | |
b63f39ea | 896 | /* |
897 | * struct trace_parser - servers for reading the user input separated by spaces | |
898 | * @cont: set if the input is not complete - no final space char was found | |
899 | * @buffer: holds the parsed user input | |
1537a363 | 900 | * @idx: user input length |
b63f39ea | 901 | * @size: buffer size |
902 | */ | |
903 | struct trace_parser { | |
904 | bool cont; | |
905 | char *buffer; | |
906 | unsigned idx; | |
907 | unsigned size; | |
908 | }; | |
909 | ||
910 | static inline bool trace_parser_loaded(struct trace_parser *parser) | |
911 | { | |
912 | return (parser->idx != 0); | |
913 | } | |
914 | ||
915 | static inline bool trace_parser_cont(struct trace_parser *parser) | |
916 | { | |
917 | return parser->cont; | |
918 | } | |
919 | ||
920 | static inline void trace_parser_clear(struct trace_parser *parser) | |
921 | { | |
922 | parser->cont = false; | |
923 | parser->idx = 0; | |
924 | } | |
925 | ||
926 | extern int trace_parser_get_init(struct trace_parser *parser, int size); | |
927 | extern void trace_parser_put(struct trace_parser *parser); | |
928 | extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, | |
929 | size_t cnt, loff_t *ppos); | |
930 | ||
729358da SRRH |
931 | /* |
932 | * Only create function graph options if function graph is configured. | |
933 | */ | |
934 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | |
935 | # define FGRAPH_FLAGS \ | |
729358da | 936 | C(DISPLAY_GRAPH, "display-graph"), |
729358da SRRH |
937 | #else |
938 | # define FGRAPH_FLAGS | |
729358da SRRH |
939 | #endif |
940 | ||
4ee4301c SRRH |
941 | #ifdef CONFIG_BRANCH_TRACER |
942 | # define BRANCH_FLAGS \ | |
943 | C(BRANCH, "branch"), | |
944 | #else | |
945 | # define BRANCH_FLAGS | |
946 | #endif | |
947 | ||
8179e8a1 SRRH |
948 | #ifdef CONFIG_FUNCTION_TRACER |
949 | # define FUNCTION_FLAGS \ | |
950 | C(FUNCTION, "function-trace"), | |
951 | # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION | |
952 | #else | |
953 | # define FUNCTION_FLAGS | |
954 | # define FUNCTION_DEFAULT_FLAGS 0UL | |
955 | #endif | |
956 | ||
73dddbb5 SRRH |
957 | #ifdef CONFIG_STACKTRACE |
958 | # define STACK_FLAGS \ | |
959 | C(STACKTRACE, "stacktrace"), | |
960 | #else | |
961 | # define STACK_FLAGS | |
962 | #endif | |
963 | ||
4fcdae83 SR |
964 | /* |
965 | * trace_iterator_flags is an enumeration that defines bit | |
966 | * positions into trace_flags that controls the output. | |
967 | * | |
968 | * NOTE: These bits must match the trace_options array in | |
a3418a36 | 969 | * trace.c (this macro guarantees it). |
4fcdae83 | 970 | */ |
a3418a36 SRRH |
971 | #define TRACE_FLAGS \ |
972 | C(PRINT_PARENT, "print-parent"), \ | |
973 | C(SYM_OFFSET, "sym-offset"), \ | |
974 | C(SYM_ADDR, "sym-addr"), \ | |
975 | C(VERBOSE, "verbose"), \ | |
976 | C(RAW, "raw"), \ | |
977 | C(HEX, "hex"), \ | |
978 | C(BIN, "bin"), \ | |
979 | C(BLOCK, "block"), \ | |
a3418a36 | 980 | C(PRINTK, "trace_printk"), \ |
a3418a36 SRRH |
981 | C(ANNOTATE, "annotate"), \ |
982 | C(USERSTACKTRACE, "userstacktrace"), \ | |
983 | C(SYM_USEROBJ, "sym-userobj"), \ | |
984 | C(PRINTK_MSGONLY, "printk-msg-only"), \ | |
985 | C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \ | |
986 | C(LATENCY_FMT, "latency-format"), \ | |
a3418a36 SRRH |
987 | C(RECORD_CMD, "record-cmd"), \ |
988 | C(OVERWRITE, "overwrite"), \ | |
989 | C(STOP_ON_FREE, "disable_on_free"), \ | |
990 | C(IRQ_INFO, "irq-info"), \ | |
991 | C(MARKERS, "markers"), \ | |
c37775d5 | 992 | C(EVENT_FORK, "event-fork"), \ |
8179e8a1 | 993 | FUNCTION_FLAGS \ |
4ee4301c | 994 | FGRAPH_FLAGS \ |
73dddbb5 | 995 | STACK_FLAGS \ |
4ee4301c | 996 | BRANCH_FLAGS |
ce3fed62 | 997 | |
a3418a36 SRRH |
998 | /* |
999 | * By defining C, we can make TRACE_FLAGS a list of bit names | |
1000 | * that will define the bits for the flag masks. | |
1001 | */ | |
1002 | #undef C | |
1003 | #define C(a, b) TRACE_ITER_##a##_BIT | |
1004 | ||
b5e87c05 SRRH |
1005 | enum trace_iterator_bits { |
1006 | TRACE_FLAGS | |
1007 | /* Make sure we don't go more than we have bits for */ | |
1008 | TRACE_ITER_LAST_BIT | |
1009 | }; | |
a3418a36 SRRH |
1010 | |
1011 | /* | |
1012 | * By redefining C, we can make TRACE_FLAGS a list of masks that | |
1013 | * use the bits as defined above. | |
1014 | */ | |
1015 | #undef C | |
1016 | #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT) | |
1017 | ||
1018 | enum trace_iterator_flags { TRACE_FLAGS }; | |
4e655519 | 1019 | |
15e6cb36 FW |
1020 | /* |
1021 | * TRACE_ITER_SYM_MASK masks the options in trace_flags that | |
1022 | * control the output of kernel symbols. | |
1023 | */ | |
1024 | #define TRACE_ITER_SYM_MASK \ | |
1025 | (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR) | |
1026 | ||
43a15386 FW |
1027 | extern struct tracer nop_trace; |
1028 | ||
2ed84eeb | 1029 | #ifdef CONFIG_BRANCH_TRACER |
9f029e83 SR |
1030 | extern int enable_branch_tracing(struct trace_array *tr); |
1031 | extern void disable_branch_tracing(void); | |
1032 | static inline int trace_branch_enable(struct trace_array *tr) | |
52f232cb | 1033 | { |
983f938a | 1034 | if (tr->trace_flags & TRACE_ITER_BRANCH) |
9f029e83 | 1035 | return enable_branch_tracing(tr); |
52f232cb SR |
1036 | return 0; |
1037 | } | |
9f029e83 | 1038 | static inline void trace_branch_disable(void) |
52f232cb SR |
1039 | { |
1040 | /* due to races, always disable */ | |
9f029e83 | 1041 | disable_branch_tracing(); |
52f232cb SR |
1042 | } |
1043 | #else | |
9f029e83 | 1044 | static inline int trace_branch_enable(struct trace_array *tr) |
52f232cb SR |
1045 | { |
1046 | return 0; | |
1047 | } | |
9f029e83 | 1048 | static inline void trace_branch_disable(void) |
52f232cb SR |
1049 | { |
1050 | } | |
2ed84eeb | 1051 | #endif /* CONFIG_BRANCH_TRACER */ |
52f232cb | 1052 | |
1852fcce SR |
1053 | /* set ring buffers to default size if not already done so */ |
1054 | int tracing_update_buffers(void); | |
1055 | ||
cf027f64 TZ |
1056 | struct ftrace_event_field { |
1057 | struct list_head link; | |
92edca07 SR |
1058 | const char *name; |
1059 | const char *type; | |
aa38e9fc | 1060 | int filter_type; |
cf027f64 TZ |
1061 | int offset; |
1062 | int size; | |
a118e4d1 | 1063 | int is_signed; |
cf027f64 TZ |
1064 | }; |
1065 | ||
30e673b2 | 1066 | struct event_filter { |
c9c53ca0 SR |
1067 | int n_preds; /* Number assigned */ |
1068 | int a_preds; /* allocated */ | |
74e9e58c | 1069 | struct filter_pred *preds; |
61e9dea2 | 1070 | struct filter_pred *root; |
8b372562 | 1071 | char *filter_string; |
30e673b2 TZ |
1072 | }; |
1073 | ||
cfb180f3 TZ |
1074 | struct event_subsystem { |
1075 | struct list_head list; | |
1076 | const char *name; | |
1f9963cb | 1077 | struct event_filter *filter; |
e9dbfae5 | 1078 | int ref_count; |
cfb180f3 TZ |
1079 | }; |
1080 | ||
7967b3e0 | 1081 | struct trace_subsystem_dir { |
ae63b31e SR |
1082 | struct list_head list; |
1083 | struct event_subsystem *subsystem; | |
1084 | struct trace_array *tr; | |
1085 | struct dentry *entry; | |
1086 | int ref_count; | |
1087 | int nr_events; | |
1088 | }; | |
1089 | ||
65da9a0a SRRH |
1090 | extern int call_filter_check_discard(struct trace_event_call *call, void *rec, |
1091 | struct ring_buffer *buffer, | |
1092 | struct ring_buffer_event *event); | |
fa66ddb8 | 1093 | |
fa66ddb8 SRRH |
1094 | void trace_buffer_unlock_commit_regs(struct trace_array *tr, |
1095 | struct ring_buffer *buffer, | |
1096 | struct ring_buffer_event *event, | |
1097 | unsigned long flags, int pc, | |
1098 | struct pt_regs *regs); | |
33fddff2 SRRH |
1099 | |
1100 | static inline void trace_buffer_unlock_commit(struct trace_array *tr, | |
1101 | struct ring_buffer *buffer, | |
1102 | struct ring_buffer_event *event, | |
1103 | unsigned long flags, int pc) | |
1104 | { | |
1105 | trace_buffer_unlock_commit_regs(tr, buffer, event, flags, pc, NULL); | |
1106 | } | |
1107 | ||
0fc1b09f SRRH |
1108 | DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event); |
1109 | DECLARE_PER_CPU(int, trace_buffered_event_cnt); | |
1110 | void trace_buffered_event_disable(void); | |
1111 | void trace_buffered_event_enable(void); | |
1112 | ||
1113 | static inline void | |
1114 | __trace_event_discard_commit(struct ring_buffer *buffer, | |
1115 | struct ring_buffer_event *event) | |
1116 | { | |
1117 | if (this_cpu_read(trace_buffered_event) == event) { | |
1118 | /* Simply release the temp buffer */ | |
1119 | this_cpu_dec(trace_buffered_event_cnt); | |
1120 | return; | |
1121 | } | |
1122 | ring_buffer_discard_commit(buffer, event); | |
1123 | } | |
1124 | ||
dad56ee7 SRRH |
1125 | /* |
1126 | * Helper function for event_trigger_unlock_commit{_regs}(). | |
1127 | * If there are event triggers attached to this event that requires | |
1128 | * filtering against its fields, then they wil be called as the | |
1129 | * entry already holds the field information of the current event. | |
1130 | * | |
1131 | * It also checks if the event should be discarded or not. | |
1132 | * It is to be discarded if the event is soft disabled and the | |
1133 | * event was only recorded to process triggers, or if the event | |
1134 | * filter is active and this event did not match the filters. | |
1135 | * | |
1136 | * Returns true if the event is discarded, false otherwise. | |
1137 | */ | |
1138 | static inline bool | |
1139 | __event_trigger_test_discard(struct trace_event_file *file, | |
1140 | struct ring_buffer *buffer, | |
1141 | struct ring_buffer_event *event, | |
1142 | void *entry, | |
1143 | enum event_trigger_type *tt) | |
1144 | { | |
1145 | unsigned long eflags = file->flags; | |
1146 | ||
1147 | if (eflags & EVENT_FILE_FL_TRIGGER_COND) | |
1148 | *tt = event_triggers_call(file, entry); | |
1149 | ||
9cbb1506 SRRH |
1150 | if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) || |
1151 | (unlikely(file->flags & EVENT_FILE_FL_FILTERED) && | |
1152 | !filter_match_preds(file->filter, entry))) { | |
0fc1b09f | 1153 | __trace_event_discard_commit(buffer, event); |
9cbb1506 SRRH |
1154 | return true; |
1155 | } | |
dad56ee7 | 1156 | |
9cbb1506 | 1157 | return false; |
dad56ee7 SRRH |
1158 | } |
1159 | ||
1160 | /** | |
1161 | * event_trigger_unlock_commit - handle triggers and finish event commit | |
1162 | * @file: The file pointer assoctiated to the event | |
1163 | * @buffer: The ring buffer that the event is being written to | |
1164 | * @event: The event meta data in the ring buffer | |
1165 | * @entry: The event itself | |
1166 | * @irq_flags: The state of the interrupts at the start of the event | |
1167 | * @pc: The state of the preempt count at the start of the event. | |
1168 | * | |
1169 | * This is a helper function to handle triggers that require data | |
1170 | * from the event itself. It also tests the event against filters and | |
1171 | * if the event is soft disabled and should be discarded. | |
1172 | */ | |
1173 | static inline void | |
1174 | event_trigger_unlock_commit(struct trace_event_file *file, | |
1175 | struct ring_buffer *buffer, | |
1176 | struct ring_buffer_event *event, | |
1177 | void *entry, unsigned long irq_flags, int pc) | |
1178 | { | |
1179 | enum event_trigger_type tt = ETT_NONE; | |
1180 | ||
1181 | if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) | |
1182 | trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc); | |
1183 | ||
1184 | if (tt) | |
1185 | event_triggers_post_call(file, tt, entry); | |
1186 | } | |
1187 | ||
1188 | /** | |
1189 | * event_trigger_unlock_commit_regs - handle triggers and finish event commit | |
1190 | * @file: The file pointer assoctiated to the event | |
1191 | * @buffer: The ring buffer that the event is being written to | |
1192 | * @event: The event meta data in the ring buffer | |
1193 | * @entry: The event itself | |
1194 | * @irq_flags: The state of the interrupts at the start of the event | |
1195 | * @pc: The state of the preempt count at the start of the event. | |
1196 | * | |
1197 | * This is a helper function to handle triggers that require data | |
1198 | * from the event itself. It also tests the event against filters and | |
1199 | * if the event is soft disabled and should be discarded. | |
1200 | * | |
1201 | * Same as event_trigger_unlock_commit() but calls | |
1202 | * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit(). | |
1203 | */ | |
1204 | static inline void | |
1205 | event_trigger_unlock_commit_regs(struct trace_event_file *file, | |
1206 | struct ring_buffer *buffer, | |
1207 | struct ring_buffer_event *event, | |
1208 | void *entry, unsigned long irq_flags, int pc, | |
1209 | struct pt_regs *regs) | |
1210 | { | |
1211 | enum event_trigger_type tt = ETT_NONE; | |
1212 | ||
1213 | if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) | |
1214 | trace_buffer_unlock_commit_regs(file->tr, buffer, event, | |
1215 | irq_flags, pc, regs); | |
1216 | ||
1217 | if (tt) | |
1218 | event_triggers_post_call(file, tt, entry); | |
1219 | } | |
1220 | ||
61e9dea2 SR |
1221 | #define FILTER_PRED_INVALID ((unsigned short)-1) |
1222 | #define FILTER_PRED_IS_RIGHT (1 << 15) | |
43cd4145 | 1223 | #define FILTER_PRED_FOLD (1 << 15) |
61e9dea2 | 1224 | |
bf93f9ed SR |
1225 | /* |
1226 | * The max preds is the size of unsigned short with | |
1227 | * two flags at the MSBs. One bit is used for both the IS_RIGHT | |
1228 | * and FOLD flags. The other is reserved. | |
1229 | * | |
1230 | * 2^14 preds is way more than enough. | |
1231 | */ | |
1232 | #define MAX_FILTER_PRED 16384 | |
4a3d27e9 | 1233 | |
7ce7e424 | 1234 | struct filter_pred; |
1889d209 | 1235 | struct regex; |
7ce7e424 | 1236 | |
58d9a597 | 1237 | typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event); |
7ce7e424 | 1238 | |
1889d209 FW |
1239 | typedef int (*regex_match_func)(char *str, struct regex *r, int len); |
1240 | ||
3f6fe06d | 1241 | enum regex_type { |
b0f1a59a | 1242 | MATCH_FULL = 0, |
3f6fe06d FW |
1243 | MATCH_FRONT_ONLY, |
1244 | MATCH_MIDDLE_ONLY, | |
1245 | MATCH_END_ONLY, | |
1246 | }; | |
1247 | ||
1889d209 FW |
1248 | struct regex { |
1249 | char pattern[MAX_FILTER_STR_VAL]; | |
1250 | int len; | |
1251 | int field_len; | |
1252 | regex_match_func match; | |
1253 | }; | |
1254 | ||
7ce7e424 | 1255 | struct filter_pred { |
1889d209 FW |
1256 | filter_pred_fn_t fn; |
1257 | u64 val; | |
1258 | struct regex regex; | |
61aaef55 | 1259 | unsigned short *ops; |
1d0e78e3 | 1260 | struct ftrace_event_field *field; |
1889d209 FW |
1261 | int offset; |
1262 | int not; | |
1263 | int op; | |
61e9dea2 SR |
1264 | unsigned short index; |
1265 | unsigned short parent; | |
1266 | unsigned short left; | |
1267 | unsigned short right; | |
7ce7e424 TZ |
1268 | }; |
1269 | ||
4ef56902 TZ |
1270 | static inline bool is_string_field(struct ftrace_event_field *field) |
1271 | { | |
1272 | return field->filter_type == FILTER_DYN_STRING || | |
1273 | field->filter_type == FILTER_STATIC_STRING || | |
1274 | field->filter_type == FILTER_PTR_STRING; | |
1275 | } | |
1276 | ||
1277 | static inline bool is_function_field(struct ftrace_event_field *field) | |
1278 | { | |
1279 | return field->filter_type == FILTER_TRACE_FN; | |
1280 | } | |
1281 | ||
3f6fe06d FW |
1282 | extern enum regex_type |
1283 | filter_parse_regex(char *buff, int len, char **search, int *not); | |
7f1d2f82 | 1284 | extern void print_event_filter(struct trace_event_file *file, |
4bda2d51 | 1285 | struct trace_seq *s); |
7f1d2f82 | 1286 | extern int apply_event_filter(struct trace_event_file *file, |
8b372562 | 1287 | char *filter_string); |
7967b3e0 | 1288 | extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, |
8b372562 TZ |
1289 | char *filter_string); |
1290 | extern void print_subsystem_event_filter(struct event_subsystem *system, | |
ac1adc55 | 1291 | struct trace_seq *s); |
aa38e9fc | 1292 | extern int filter_assign_type(const char *type); |
2425bcb9 | 1293 | extern int create_event_filter(struct trace_event_call *call, |
bac5fb97 TZ |
1294 | char *filter_str, bool set_str, |
1295 | struct event_filter **filterp); | |
1296 | extern void free_event_filter(struct event_filter *filter); | |
7ce7e424 | 1297 | |
b3a8c6fd | 1298 | struct ftrace_event_field * |
2425bcb9 | 1299 | trace_find_event_field(struct trace_event_call *call, char *name); |
2e33af02 | 1300 | |
e870e9a1 | 1301 | extern void trace_event_enable_cmd_record(bool enable); |
277ba044 | 1302 | extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr); |
0c8916c3 | 1303 | extern int event_trace_del_tracer(struct trace_array *tr); |
e870e9a1 | 1304 | |
7f1d2f82 SRRH |
1305 | extern struct trace_event_file *find_event_file(struct trace_array *tr, |
1306 | const char *system, | |
1307 | const char *event); | |
7862ad18 | 1308 | |
85f2b082 TZ |
1309 | static inline void *event_file_data(struct file *filp) |
1310 | { | |
1311 | return ACCESS_ONCE(file_inode(filp)->i_private); | |
1312 | } | |
1313 | ||
20c8928a | 1314 | extern struct mutex event_mutex; |
a59fd602 | 1315 | extern struct list_head ftrace_events; |
ac199db0 | 1316 | |
85f2b082 | 1317 | extern const struct file_operations event_trigger_fops; |
7ef224d1 TZ |
1318 | extern const struct file_operations event_hist_fops; |
1319 | ||
1320 | #ifdef CONFIG_HIST_TRIGGERS | |
1321 | extern int register_trigger_hist_cmd(void); | |
d0bad49b | 1322 | extern int register_trigger_hist_enable_disable_cmds(void); |
7ef224d1 TZ |
1323 | #else |
1324 | static inline int register_trigger_hist_cmd(void) { return 0; } | |
d0bad49b | 1325 | static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; } |
7ef224d1 | 1326 | #endif |
85f2b082 TZ |
1327 | |
1328 | extern int register_trigger_cmds(void); | |
1329 | extern void clear_event_triggers(struct trace_array *tr); | |
1330 | ||
1331 | struct event_trigger_data { | |
1332 | unsigned long count; | |
1333 | int ref; | |
1334 | struct event_trigger_ops *ops; | |
1335 | struct event_command *cmd_ops; | |
d8a30f20 | 1336 | struct event_filter __rcu *filter; |
85f2b082 TZ |
1337 | char *filter_str; |
1338 | void *private_data; | |
104f2810 | 1339 | bool paused; |
db1388b4 | 1340 | bool paused_tmp; |
85f2b082 | 1341 | struct list_head list; |
db1388b4 TZ |
1342 | char *name; |
1343 | struct list_head named_list; | |
1344 | struct event_trigger_data *named_data; | |
85f2b082 TZ |
1345 | }; |
1346 | ||
d0bad49b TZ |
1347 | /* Avoid typos */ |
1348 | #define ENABLE_EVENT_STR "enable_event" | |
1349 | #define DISABLE_EVENT_STR "disable_event" | |
1350 | #define ENABLE_HIST_STR "enable_hist" | |
1351 | #define DISABLE_HIST_STR "disable_hist" | |
1352 | ||
1353 | struct enable_trigger_data { | |
1354 | struct trace_event_file *file; | |
1355 | bool enable; | |
1356 | bool hist; | |
1357 | }; | |
1358 | ||
1359 | extern int event_enable_trigger_print(struct seq_file *m, | |
1360 | struct event_trigger_ops *ops, | |
1361 | struct event_trigger_data *data); | |
1362 | extern void event_enable_trigger_free(struct event_trigger_ops *ops, | |
1363 | struct event_trigger_data *data); | |
1364 | extern int event_enable_trigger_func(struct event_command *cmd_ops, | |
1365 | struct trace_event_file *file, | |
1366 | char *glob, char *cmd, char *param); | |
1367 | extern int event_enable_register_trigger(char *glob, | |
1368 | struct event_trigger_ops *ops, | |
1369 | struct event_trigger_data *data, | |
1370 | struct trace_event_file *file); | |
1371 | extern void event_enable_unregister_trigger(char *glob, | |
1372 | struct event_trigger_ops *ops, | |
1373 | struct event_trigger_data *test, | |
1374 | struct trace_event_file *file); | |
ab4bf008 TZ |
1375 | extern void trigger_data_free(struct event_trigger_data *data); |
1376 | extern int event_trigger_init(struct event_trigger_ops *ops, | |
1377 | struct event_trigger_data *data); | |
1378 | extern int trace_event_trigger_enable_disable(struct trace_event_file *file, | |
1379 | int trigger_enable); | |
1380 | extern void update_cond_flag(struct trace_event_file *file); | |
1381 | extern void unregister_trigger(char *glob, struct event_trigger_ops *ops, | |
1382 | struct event_trigger_data *test, | |
1383 | struct trace_event_file *file); | |
1384 | extern int set_trigger_filter(char *filter_str, | |
1385 | struct event_trigger_data *trigger_data, | |
1386 | struct trace_event_file *file); | |
db1388b4 TZ |
1387 | extern struct event_trigger_data *find_named_trigger(const char *name); |
1388 | extern bool is_named_trigger(struct event_trigger_data *test); | |
1389 | extern int save_named_trigger(const char *name, | |
1390 | struct event_trigger_data *data); | |
1391 | extern void del_named_trigger(struct event_trigger_data *data); | |
1392 | extern void pause_named_trigger(struct event_trigger_data *data); | |
1393 | extern void unpause_named_trigger(struct event_trigger_data *data); | |
1394 | extern void set_named_trigger_data(struct event_trigger_data *data, | |
1395 | struct event_trigger_data *named_data); | |
ab4bf008 | 1396 | extern int register_event_command(struct event_command *cmd); |
d0bad49b TZ |
1397 | extern int unregister_event_command(struct event_command *cmd); |
1398 | extern int register_trigger_hist_enable_disable_cmds(void); | |
ab4bf008 | 1399 | |
85f2b082 TZ |
1400 | /** |
1401 | * struct event_trigger_ops - callbacks for trace event triggers | |
1402 | * | |
1403 | * The methods in this structure provide per-event trigger hooks for | |
1404 | * various trigger operations. | |
1405 | * | |
1406 | * All the methods below, except for @init() and @free(), must be | |
1407 | * implemented. | |
1408 | * | |
1409 | * @func: The trigger 'probe' function called when the triggering | |
1410 | * event occurs. The data passed into this callback is the data | |
1411 | * that was supplied to the event_command @reg() function that | |
c4a59230 TZ |
1412 | * registered the trigger (see struct event_command) along with |
1413 | * the trace record, rec. | |
85f2b082 TZ |
1414 | * |
1415 | * @init: An optional initialization function called for the trigger | |
1416 | * when the trigger is registered (via the event_command reg() | |
1417 | * function). This can be used to perform per-trigger | |
1418 | * initialization such as incrementing a per-trigger reference | |
1419 | * count, for instance. This is usually implemented by the | |
1420 | * generic utility function @event_trigger_init() (see | |
1421 | * trace_event_triggers.c). | |
1422 | * | |
1423 | * @free: An optional de-initialization function called for the | |
1424 | * trigger when the trigger is unregistered (via the | |
1425 | * event_command @reg() function). This can be used to perform | |
1426 | * per-trigger de-initialization such as decrementing a | |
1427 | * per-trigger reference count and freeing corresponding trigger | |
1428 | * data, for instance. This is usually implemented by the | |
1429 | * generic utility function @event_trigger_free() (see | |
1430 | * trace_event_triggers.c). | |
1431 | * | |
1432 | * @print: The callback function invoked to have the trigger print | |
1433 | * itself. This is usually implemented by a wrapper function | |
1434 | * that calls the generic utility function @event_trigger_print() | |
1435 | * (see trace_event_triggers.c). | |
1436 | */ | |
1437 | struct event_trigger_ops { | |
c4a59230 TZ |
1438 | void (*func)(struct event_trigger_data *data, |
1439 | void *rec); | |
85f2b082 TZ |
1440 | int (*init)(struct event_trigger_ops *ops, |
1441 | struct event_trigger_data *data); | |
1442 | void (*free)(struct event_trigger_ops *ops, | |
1443 | struct event_trigger_data *data); | |
1444 | int (*print)(struct seq_file *m, | |
1445 | struct event_trigger_ops *ops, | |
1446 | struct event_trigger_data *data); | |
1447 | }; | |
1448 | ||
1449 | /** | |
1450 | * struct event_command - callbacks and data members for event commands | |
1451 | * | |
1452 | * Event commands are invoked by users by writing the command name | |
1453 | * into the 'trigger' file associated with a trace event. The | |
1454 | * parameters associated with a specific invocation of an event | |
1455 | * command are used to create an event trigger instance, which is | |
1456 | * added to the list of trigger instances associated with that trace | |
1457 | * event. When the event is hit, the set of triggers associated with | |
1458 | * that event is invoked. | |
1459 | * | |
1460 | * The data members in this structure provide per-event command data | |
1461 | * for various event commands. | |
1462 | * | |
1463 | * All the data members below, except for @post_trigger, must be set | |
1464 | * for each event command. | |
1465 | * | |
1466 | * @name: The unique name that identifies the event command. This is | |
1467 | * the name used when setting triggers via trigger files. | |
1468 | * | |
1469 | * @trigger_type: A unique id that identifies the event command | |
1470 | * 'type'. This value has two purposes, the first to ensure that | |
1471 | * only one trigger of the same type can be set at a given time | |
1472 | * for a particular event e.g. it doesn't make sense to have both | |
1473 | * a traceon and traceoff trigger attached to a single event at | |
1474 | * the same time, so traceon and traceoff have the same type | |
1475 | * though they have different names. The @trigger_type value is | |
1476 | * also used as a bit value for deferring the actual trigger | |
1477 | * action until after the current event is finished. Some | |
1478 | * commands need to do this if they themselves log to the trace | |
1479 | * buffer (see the @post_trigger() member below). @trigger_type | |
1480 | * values are defined by adding new values to the trigger_type | |
af658dca | 1481 | * enum in include/linux/trace_events.h. |
85f2b082 | 1482 | * |
353206f5 | 1483 | * @flags: See the enum event_command_flags below. |
a5863dae | 1484 | * |
a88e1cfb TZ |
1485 | * All the methods below, except for @set_filter() and @unreg_all(), |
1486 | * must be implemented. | |
85f2b082 TZ |
1487 | * |
1488 | * @func: The callback function responsible for parsing and | |
1489 | * registering the trigger written to the 'trigger' file by the | |
1490 | * user. It allocates the trigger instance and registers it with | |
1491 | * the appropriate trace event. It makes use of the other | |
1492 | * event_command callback functions to orchestrate this, and is | |
1493 | * usually implemented by the generic utility function | |
1494 | * @event_trigger_callback() (see trace_event_triggers.c). | |
1495 | * | |
1496 | * @reg: Adds the trigger to the list of triggers associated with the | |
1497 | * event, and enables the event trigger itself, after | |
1498 | * initializing it (via the event_trigger_ops @init() function). | |
1499 | * This is also where commands can use the @trigger_type value to | |
1500 | * make the decision as to whether or not multiple instances of | |
1501 | * the trigger should be allowed. This is usually implemented by | |
1502 | * the generic utility function @register_trigger() (see | |
1503 | * trace_event_triggers.c). | |
1504 | * | |
1505 | * @unreg: Removes the trigger from the list of triggers associated | |
1506 | * with the event, and disables the event trigger itself, after | |
1507 | * initializing it (via the event_trigger_ops @free() function). | |
1508 | * This is usually implemented by the generic utility function | |
1509 | * @unregister_trigger() (see trace_event_triggers.c). | |
1510 | * | |
a88e1cfb TZ |
1511 | * @unreg_all: An optional function called to remove all the triggers |
1512 | * from the list of triggers associated with the event. Called | |
1513 | * when a trigger file is opened in truncate mode. | |
1514 | * | |
85f2b082 TZ |
1515 | * @set_filter: An optional function called to parse and set a filter |
1516 | * for the trigger. If no @set_filter() method is set for the | |
1517 | * event command, filters set by the user for the command will be | |
1518 | * ignored. This is usually implemented by the generic utility | |
1519 | * function @set_trigger_filter() (see trace_event_triggers.c). | |
1520 | * | |
1521 | * @get_trigger_ops: The callback function invoked to retrieve the | |
1522 | * event_trigger_ops implementation associated with the command. | |
1523 | */ | |
1524 | struct event_command { | |
1525 | struct list_head list; | |
1526 | char *name; | |
1527 | enum event_trigger_type trigger_type; | |
353206f5 | 1528 | int flags; |
85f2b082 | 1529 | int (*func)(struct event_command *cmd_ops, |
7f1d2f82 | 1530 | struct trace_event_file *file, |
85f2b082 TZ |
1531 | char *glob, char *cmd, char *params); |
1532 | int (*reg)(char *glob, | |
1533 | struct event_trigger_ops *ops, | |
1534 | struct event_trigger_data *data, | |
7f1d2f82 | 1535 | struct trace_event_file *file); |
85f2b082 TZ |
1536 | void (*unreg)(char *glob, |
1537 | struct event_trigger_ops *ops, | |
1538 | struct event_trigger_data *data, | |
7f1d2f82 | 1539 | struct trace_event_file *file); |
a88e1cfb | 1540 | void (*unreg_all)(struct trace_event_file *file); |
85f2b082 TZ |
1541 | int (*set_filter)(char *filter_str, |
1542 | struct event_trigger_data *data, | |
7f1d2f82 | 1543 | struct trace_event_file *file); |
85f2b082 TZ |
1544 | struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param); |
1545 | }; | |
1546 | ||
353206f5 SRRH |
1547 | /** |
1548 | * enum event_command_flags - flags for struct event_command | |
1549 | * | |
1550 | * @POST_TRIGGER: A flag that says whether or not this command needs | |
1551 | * to have its action delayed until after the current event has | |
1552 | * been closed. Some triggers need to avoid being invoked while | |
1553 | * an event is currently in the process of being logged, since | |
1554 | * the trigger may itself log data into the trace buffer. Thus | |
1555 | * we make sure the current event is committed before invoking | |
1556 | * those triggers. To do that, the trigger invocation is split | |
1557 | * in two - the first part checks the filter using the current | |
1558 | * trace record; if a command has the @post_trigger flag set, it | |
1559 | * sets a bit for itself in the return value, otherwise it | |
1560 | * directly invokes the trigger. Once all commands have been | |
1561 | * either invoked or set their return flag, the current record is | |
1562 | * either committed or discarded. At that point, if any commands | |
1563 | * have deferred their triggers, those commands are finally | |
1564 | * invoked following the close of the current event. In other | |
1565 | * words, if the event_trigger_ops @func() probe implementation | |
1566 | * itself logs to the trace buffer, this flag should be set, | |
1567 | * otherwise it can be left unspecified. | |
1568 | * | |
1569 | * @NEEDS_REC: A flag that says whether or not this command needs | |
1570 | * access to the trace record in order to perform its function, | |
1571 | * regardless of whether or not it has a filter associated with | |
1572 | * it (filters make a trigger require access to the trace record | |
1573 | * but are not always present). | |
1574 | */ | |
1575 | enum event_command_flags { | |
1576 | EVENT_CMD_FL_POST_TRIGGER = 1, | |
1577 | EVENT_CMD_FL_NEEDS_REC = 2, | |
1578 | }; | |
1579 | ||
1580 | static inline bool event_command_post_trigger(struct event_command *cmd_ops) | |
1581 | { | |
1582 | return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER; | |
1583 | } | |
1584 | ||
1585 | static inline bool event_command_needs_rec(struct event_command *cmd_ops) | |
1586 | { | |
1587 | return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC; | |
1588 | } | |
1589 | ||
7f1d2f82 | 1590 | extern int trace_event_enable_disable(struct trace_event_file *file, |
85f2b082 | 1591 | int enable, int soft_disable); |
93e31ffb | 1592 | extern int tracing_alloc_snapshot(void); |
85f2b082 | 1593 | |
e9fb2b6d SR |
1594 | extern const char *__start___trace_bprintk_fmt[]; |
1595 | extern const char *__stop___trace_bprintk_fmt[]; | |
1596 | ||
102c9323 SRRH |
1597 | extern const char *__start___tracepoint_str[]; |
1598 | extern const char *__stop___tracepoint_str[]; | |
1599 | ||
b9f9108c | 1600 | void trace_printk_control(bool enabled); |
07d777fe | 1601 | void trace_printk_init_buffers(void); |
81698831 | 1602 | void trace_printk_start_comm(void); |
613f04a0 | 1603 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set); |
2b6080f2 | 1604 | int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled); |
07d777fe | 1605 | |
ca268da6 SRRH |
1606 | /* |
1607 | * Normal trace_printk() and friends allocates special buffers | |
1608 | * to do the manipulation, as well as saves the print formats | |
1609 | * into sections to display. But the trace infrastructure wants | |
1610 | * to use these without the added overhead at the price of being | |
1611 | * a bit slower (used mainly for warnings, where we don't care | |
1612 | * about performance). The internal_trace_puts() is for such | |
1613 | * a purpose. | |
1614 | */ | |
1615 | #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str)) | |
1616 | ||
4e5292ea | 1617 | #undef FTRACE_ENTRY |
02aa3162 | 1618 | #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \ |
2425bcb9 | 1619 | extern struct trace_event_call \ |
52f5684c | 1620 | __aligned(4) event_##call; |
4e5292ea | 1621 | #undef FTRACE_ENTRY_DUP |
02aa3162 JO |
1622 | #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \ |
1623 | FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ | |
1624 | filter) | |
4e5292ea | 1625 | #include "trace_entries.h" |
e1112b4d | 1626 | |
6e48b550 | 1627 | #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER) |
2425bcb9 | 1628 | int perf_ftrace_event_register(struct trace_event_call *call, |
ced39002 JO |
1629 | enum trace_reg type, void *data); |
1630 | #else | |
1631 | #define perf_ftrace_event_register NULL | |
6e48b550 | 1632 | #endif |
ced39002 | 1633 | |
5f893b26 SRRH |
1634 | #ifdef CONFIG_FTRACE_SYSCALLS |
1635 | void init_ftrace_syscalls(void); | |
dbfeaa7a | 1636 | const char *get_syscall_name(int syscall); |
5f893b26 SRRH |
1637 | #else |
1638 | static inline void init_ftrace_syscalls(void) { } | |
dbfeaa7a TZ |
1639 | static inline const char *get_syscall_name(int syscall) |
1640 | { | |
1641 | return NULL; | |
1642 | } | |
5f893b26 SRRH |
1643 | #endif |
1644 | ||
1645 | #ifdef CONFIG_EVENT_TRACING | |
1646 | void trace_event_init(void); | |
0c564a53 | 1647 | void trace_event_enum_update(struct trace_enum_map **map, int len); |
5f893b26 SRRH |
1648 | #else |
1649 | static inline void __init trace_event_init(void) { } | |
cc9e4bde | 1650 | static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { } |
5f893b26 SRRH |
1651 | #endif |
1652 | ||
0daa2302 | 1653 | extern struct trace_iterator *tracepoint_print_iter; |
5f893b26 | 1654 | |
bc0c38d1 | 1655 | #endif /* _LINUX_KERNEL_TRACE_H */ |