]>
Commit | Line | Data |
---|---|---|
bc0c38d1 SR |
1 | #ifndef _LINUX_KERNEL_TRACE_H |
2 | #define _LINUX_KERNEL_TRACE_H | |
3 | ||
4 | #include <linux/fs.h> | |
5 | #include <asm/atomic.h> | |
6 | #include <linux/sched.h> | |
7 | #include <linux/clocksource.h> | |
3928a8a2 | 8 | #include <linux/ring_buffer.h> |
bd8ac686 | 9 | #include <linux/mmiotrace.h> |
d13744cd | 10 | #include <linux/ftrace.h> |
3f5ec136 | 11 | #include <trace/boot.h> |
02af61bb | 12 | #include <linux/kmemtrace.h> |
12922110 | 13 | #include <trace/power.h> |
bc0c38d1 | 14 | |
9504504c SR |
15 | #include <linux/trace_seq.h> |
16 | ||
72829bc3 TG |
17 | enum trace_type { |
18 | __TRACE_FIRST_TYPE = 0, | |
19 | ||
20 | TRACE_FN, | |
21 | TRACE_CTX, | |
22 | TRACE_WAKE, | |
23 | TRACE_STACK, | |
dd0e545f | 24 | TRACE_PRINT, |
48ead020 | 25 | TRACE_BPRINT, |
72829bc3 | 26 | TRACE_SPECIAL, |
bd8ac686 PP |
27 | TRACE_MMIO_RW, |
28 | TRACE_MMIO_MAP, | |
9f029e83 | 29 | TRACE_BRANCH, |
74239072 FW |
30 | TRACE_BOOT_CALL, |
31 | TRACE_BOOT_RET, | |
287b6e68 FW |
32 | TRACE_GRAPH_RET, |
33 | TRACE_GRAPH_ENT, | |
02b67518 | 34 | TRACE_USER_STACK, |
a93751ca | 35 | TRACE_HW_BRANCHES, |
ee08c6ec FW |
36 | TRACE_SYSCALL_ENTER, |
37 | TRACE_SYSCALL_EXIT, | |
36994e58 FW |
38 | TRACE_KMEM_ALLOC, |
39 | TRACE_KMEM_FREE, | |
f3f47a67 | 40 | TRACE_POWER, |
c71a8961 | 41 | TRACE_BLK, |
72829bc3 | 42 | |
f0868d1e | 43 | __TRACE_LAST_TYPE, |
72829bc3 TG |
44 | }; |
45 | ||
777e208d SR |
46 | /* |
47 | * The trace entry - the most basic unit of tracing. This is what | |
48 | * is printed in the end as a single line in the trace output, such as: | |
49 | * | |
50 | * bash-15816 [01] 235.197585: idle_cpu <- irq_enter | |
51 | */ | |
52 | struct trace_entry { | |
53 | unsigned char type; | |
777e208d SR |
54 | unsigned char flags; |
55 | unsigned char preempt_count; | |
56 | int pid; | |
02b67518 | 57 | int tgid; |
777e208d SR |
58 | }; |
59 | ||
bc0c38d1 SR |
60 | /* |
61 | * Function trace entry - function address and parent function addres: | |
62 | */ | |
63 | struct ftrace_entry { | |
777e208d | 64 | struct trace_entry ent; |
bc0c38d1 SR |
65 | unsigned long ip; |
66 | unsigned long parent_ip; | |
67 | }; | |
15e6cb36 | 68 | |
287b6e68 FW |
69 | /* Function call entry */ |
70 | struct ftrace_graph_ent_entry { | |
b91facc3 | 71 | struct trace_entry ent; |
287b6e68 FW |
72 | struct ftrace_graph_ent graph_ent; |
73 | }; | |
74 | ||
15e6cb36 | 75 | /* Function return entry */ |
287b6e68 | 76 | struct ftrace_graph_ret_entry { |
b91facc3 | 77 | struct trace_entry ent; |
287b6e68 | 78 | struct ftrace_graph_ret ret; |
15e6cb36 | 79 | }; |
d13744cd | 80 | extern struct tracer boot_tracer; |
bc0c38d1 SR |
81 | |
82 | /* | |
83 | * Context switch trace entry - which task (and prio) we switched from/to: | |
84 | */ | |
85 | struct ctx_switch_entry { | |
777e208d | 86 | struct trace_entry ent; |
bc0c38d1 SR |
87 | unsigned int prev_pid; |
88 | unsigned char prev_prio; | |
89 | unsigned char prev_state; | |
90 | unsigned int next_pid; | |
91 | unsigned char next_prio; | |
bac524d3 | 92 | unsigned char next_state; |
80b5e940 | 93 | unsigned int next_cpu; |
bc0c38d1 SR |
94 | }; |
95 | ||
f0a920d5 IM |
96 | /* |
97 | * Special (free-form) trace entry: | |
98 | */ | |
99 | struct special_entry { | |
777e208d | 100 | struct trace_entry ent; |
f0a920d5 IM |
101 | unsigned long arg1; |
102 | unsigned long arg2; | |
103 | unsigned long arg3; | |
104 | }; | |
105 | ||
86387f7e IM |
106 | /* |
107 | * Stack-trace entry: | |
108 | */ | |
109 | ||
74f4e369 | 110 | #define FTRACE_STACK_ENTRIES 8 |
86387f7e IM |
111 | |
112 | struct stack_entry { | |
777e208d | 113 | struct trace_entry ent; |
86387f7e IM |
114 | unsigned long caller[FTRACE_STACK_ENTRIES]; |
115 | }; | |
116 | ||
02b67518 TE |
117 | struct userstack_entry { |
118 | struct trace_entry ent; | |
119 | unsigned long caller[FTRACE_STACK_ENTRIES]; | |
120 | }; | |
121 | ||
dd0e545f | 122 | /* |
5e1607a0 | 123 | * trace_printk entry: |
dd0e545f | 124 | */ |
48ead020 | 125 | struct bprint_entry { |
777e208d | 126 | struct trace_entry ent; |
9de36825 | 127 | unsigned long ip; |
769b0441 | 128 | const char *fmt; |
9de36825 | 129 | u32 buf[]; |
1427cdf0 | 130 | }; |
1427cdf0 | 131 | |
48ead020 FW |
132 | struct print_entry { |
133 | struct trace_entry ent; | |
134 | unsigned long ip; | |
48ead020 FW |
135 | char buf[]; |
136 | }; | |
137 | ||
777e208d SR |
138 | #define TRACE_OLD_SIZE 88 |
139 | ||
140 | struct trace_field_cont { | |
141 | unsigned char type; | |
142 | /* Temporary till we get rid of this completely */ | |
143 | char buf[TRACE_OLD_SIZE - 1]; | |
144 | }; | |
145 | ||
146 | struct trace_mmiotrace_rw { | |
147 | struct trace_entry ent; | |
148 | struct mmiotrace_rw rw; | |
149 | }; | |
150 | ||
151 | struct trace_mmiotrace_map { | |
152 | struct trace_entry ent; | |
153 | struct mmiotrace_map map; | |
154 | }; | |
155 | ||
74239072 | 156 | struct trace_boot_call { |
777e208d | 157 | struct trace_entry ent; |
74239072 FW |
158 | struct boot_trace_call boot_call; |
159 | }; | |
160 | ||
161 | struct trace_boot_ret { | |
162 | struct trace_entry ent; | |
163 | struct boot_trace_ret boot_ret; | |
777e208d SR |
164 | }; |
165 | ||
52f232cb SR |
166 | #define TRACE_FUNC_SIZE 30 |
167 | #define TRACE_FILE_SIZE 20 | |
9f029e83 | 168 | struct trace_branch { |
52f232cb SR |
169 | struct trace_entry ent; |
170 | unsigned line; | |
171 | char func[TRACE_FUNC_SIZE+1]; | |
172 | char file[TRACE_FILE_SIZE+1]; | |
173 | char correct; | |
174 | }; | |
175 | ||
a93751ca | 176 | struct hw_branch_entry { |
1e9b51c2 | 177 | struct trace_entry ent; |
a93751ca MM |
178 | u64 from; |
179 | u64 to; | |
1e9b51c2 MM |
180 | }; |
181 | ||
f3f47a67 AV |
182 | struct trace_power { |
183 | struct trace_entry ent; | |
184 | struct power_trace state_data; | |
185 | }; | |
186 | ||
ca2b84cb EGM |
187 | enum kmemtrace_type_id { |
188 | KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */ | |
189 | KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */ | |
190 | KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */ | |
191 | }; | |
192 | ||
36994e58 FW |
193 | struct kmemtrace_alloc_entry { |
194 | struct trace_entry ent; | |
195 | enum kmemtrace_type_id type_id; | |
196 | unsigned long call_site; | |
197 | const void *ptr; | |
198 | size_t bytes_req; | |
199 | size_t bytes_alloc; | |
200 | gfp_t gfp_flags; | |
201 | int node; | |
202 | }; | |
203 | ||
204 | struct kmemtrace_free_entry { | |
205 | struct trace_entry ent; | |
206 | enum kmemtrace_type_id type_id; | |
207 | unsigned long call_site; | |
208 | const void *ptr; | |
209 | }; | |
210 | ||
bed1ffca FW |
211 | struct syscall_trace_enter { |
212 | struct trace_entry ent; | |
213 | int nr; | |
214 | unsigned long args[]; | |
215 | }; | |
216 | ||
217 | struct syscall_trace_exit { | |
218 | struct trace_entry ent; | |
219 | int nr; | |
220 | unsigned long ret; | |
221 | }; | |
222 | ||
223 | ||
fc5e27ae PP |
224 | /* |
225 | * trace_flag_type is an enumeration that holds different | |
226 | * states when a trace occurs. These are: | |
9244489a | 227 | * IRQS_OFF - interrupts were disabled |
9de36825 | 228 | * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags |
9244489a SR |
229 | * NEED_RESCED - reschedule is requested |
230 | * HARDIRQ - inside an interrupt handler | |
231 | * SOFTIRQ - inside a softirq handler | |
fc5e27ae PP |
232 | */ |
233 | enum trace_flag_type { | |
234 | TRACE_FLAG_IRQS_OFF = 0x01, | |
9244489a SR |
235 | TRACE_FLAG_IRQS_NOSUPPORT = 0x02, |
236 | TRACE_FLAG_NEED_RESCHED = 0x04, | |
237 | TRACE_FLAG_HARDIRQ = 0x08, | |
238 | TRACE_FLAG_SOFTIRQ = 0x10, | |
fc5e27ae PP |
239 | }; |
240 | ||
5bf9a1ee | 241 | #define TRACE_BUF_SIZE 1024 |
bc0c38d1 SR |
242 | |
243 | /* | |
244 | * The CPU trace array - it consists of thousands of trace entries | |
245 | * plus some other descriptor data: (for example which task started | |
246 | * the trace, etc.) | |
247 | */ | |
248 | struct trace_array_cpu { | |
bc0c38d1 | 249 | atomic_t disabled; |
2cadf913 | 250 | void *buffer_page; /* ring buffer spare */ |
4e3c3333 | 251 | |
c7aafc54 | 252 | /* these fields get copied into max-trace: */ |
c7aafc54 | 253 | unsigned long trace_idx; |
53d0aa77 | 254 | unsigned long overrun; |
bc0c38d1 SR |
255 | unsigned long saved_latency; |
256 | unsigned long critical_start; | |
257 | unsigned long critical_end; | |
258 | unsigned long critical_sequence; | |
259 | unsigned long nice; | |
260 | unsigned long policy; | |
261 | unsigned long rt_priority; | |
262 | cycle_t preempt_timestamp; | |
263 | pid_t pid; | |
264 | uid_t uid; | |
265 | char comm[TASK_COMM_LEN]; | |
266 | }; | |
267 | ||
268 | struct trace_iterator; | |
269 | ||
270 | /* | |
271 | * The trace array - an array of per-CPU trace arrays. This is the | |
272 | * highest level data structure that individual tracers deal with. | |
273 | * They have on/off state as well: | |
274 | */ | |
275 | struct trace_array { | |
3928a8a2 | 276 | struct ring_buffer *buffer; |
bc0c38d1 | 277 | unsigned long entries; |
bc0c38d1 SR |
278 | int cpu; |
279 | cycle_t time_start; | |
b3806b43 | 280 | struct task_struct *waiter; |
bc0c38d1 SR |
281 | struct trace_array_cpu *data[NR_CPUS]; |
282 | }; | |
283 | ||
7104f300 SR |
284 | #define FTRACE_CMP_TYPE(var, type) \ |
285 | __builtin_types_compatible_p(typeof(var), type *) | |
286 | ||
287 | #undef IF_ASSIGN | |
288 | #define IF_ASSIGN(var, entry, etype, id) \ | |
289 | if (FTRACE_CMP_TYPE(var, etype)) { \ | |
290 | var = (typeof(var))(entry); \ | |
291 | WARN_ON(id && (entry)->type != id); \ | |
292 | break; \ | |
293 | } | |
294 | ||
295 | /* Will cause compile errors if type is not found. */ | |
296 | extern void __ftrace_bad_type(void); | |
297 | ||
298 | /* | |
299 | * The trace_assign_type is a verifier that the entry type is | |
300 | * the same as the type being assigned. To add new types simply | |
301 | * add a line with the following format: | |
302 | * | |
303 | * IF_ASSIGN(var, ent, type, id); | |
304 | * | |
305 | * Where "type" is the trace type that includes the trace_entry | |
306 | * as the "ent" item. And "id" is the trace identifier that is | |
307 | * used in the trace_type enum. | |
308 | * | |
309 | * If the type can have more than one id, then use zero. | |
310 | */ | |
311 | #define trace_assign_type(var, ent) \ | |
312 | do { \ | |
313 | IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \ | |
314 | IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \ | |
7104f300 | 315 | IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \ |
02b67518 | 316 | IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\ |
7104f300 | 317 | IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \ |
48ead020 | 318 | IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \ |
7104f300 SR |
319 | IF_ASSIGN(var, ent, struct special_entry, 0); \ |
320 | IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \ | |
321 | TRACE_MMIO_RW); \ | |
322 | IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \ | |
323 | TRACE_MMIO_MAP); \ | |
74239072 FW |
324 | IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\ |
325 | IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\ | |
9f029e83 | 326 | IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \ |
287b6e68 FW |
327 | IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \ |
328 | TRACE_GRAPH_ENT); \ | |
329 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ | |
330 | TRACE_GRAPH_RET); \ | |
a93751ca | 331 | IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\ |
9de36825 | 332 | IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \ |
36994e58 FW |
333 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ |
334 | TRACE_KMEM_ALLOC); \ | |
335 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ | |
336 | TRACE_KMEM_FREE); \ | |
bed1ffca FW |
337 | IF_ASSIGN(var, ent, struct syscall_trace_enter, \ |
338 | TRACE_SYSCALL_ENTER); \ | |
339 | IF_ASSIGN(var, ent, struct syscall_trace_exit, \ | |
340 | TRACE_SYSCALL_EXIT); \ | |
7104f300 SR |
341 | __ftrace_bad_type(); \ |
342 | } while (0) | |
2c4f035f FW |
343 | |
344 | /* Return values for print_line callback */ | |
345 | enum print_line_t { | |
346 | TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */ | |
347 | TRACE_TYPE_HANDLED = 1, | |
b91facc3 FW |
348 | TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */ |
349 | TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */ | |
2c4f035f FW |
350 | }; |
351 | ||
adf9f195 FW |
352 | |
353 | /* | |
354 | * An option specific to a tracer. This is a boolean value. | |
355 | * The bit is the bit index that sets its value on the | |
356 | * flags value in struct tracer_flags. | |
357 | */ | |
358 | struct tracer_opt { | |
9de36825 IM |
359 | const char *name; /* Will appear on the trace_options file */ |
360 | u32 bit; /* Mask assigned in val field in tracer_flags */ | |
adf9f195 FW |
361 | }; |
362 | ||
363 | /* | |
364 | * The set of specific options for a tracer. Your tracer | |
365 | * have to set the initial value of the flags val. | |
366 | */ | |
367 | struct tracer_flags { | |
368 | u32 val; | |
9de36825 | 369 | struct tracer_opt *opts; |
adf9f195 FW |
370 | }; |
371 | ||
372 | /* Makes more easy to define a tracer opt */ | |
373 | #define TRACER_OPT(s, b) .name = #s, .bit = b | |
374 | ||
034939b6 | 375 | |
6eaaa5d5 FW |
376 | /** |
377 | * struct tracer - a specific tracer and its callbacks to interact with debugfs | |
378 | * @name: the name chosen to select it on the available_tracers file | |
379 | * @init: called when one switches to this tracer (echo name > current_tracer) | |
380 | * @reset: called when one switches to another tracer | |
381 | * @start: called when tracing is unpaused (echo 1 > tracing_enabled) | |
382 | * @stop: called when tracing is paused (echo 0 > tracing_enabled) | |
383 | * @open: called when the trace file is opened | |
384 | * @pipe_open: called when the trace_pipe file is opened | |
385 | * @wait_pipe: override how the user waits for traces on trace_pipe | |
386 | * @close: called when the trace file is released | |
387 | * @read: override the default read callback on trace_pipe | |
388 | * @splice_read: override the default splice_read callback on trace_pipe | |
389 | * @selftest: selftest to run on boot (see trace_selftest.c) | |
390 | * @print_headers: override the first lines that describe your columns | |
391 | * @print_line: callback that prints a trace | |
392 | * @set_flag: signals one of your private flags changed (trace_options file) | |
393 | * @flags: your private flags | |
bc0c38d1 SR |
394 | */ |
395 | struct tracer { | |
396 | const char *name; | |
1c80025a | 397 | int (*init)(struct trace_array *tr); |
bc0c38d1 | 398 | void (*reset)(struct trace_array *tr); |
9036990d SR |
399 | void (*start)(struct trace_array *tr); |
400 | void (*stop)(struct trace_array *tr); | |
bc0c38d1 | 401 | void (*open)(struct trace_iterator *iter); |
107bad8b | 402 | void (*pipe_open)(struct trace_iterator *iter); |
6eaaa5d5 | 403 | void (*wait_pipe)(struct trace_iterator *iter); |
bc0c38d1 | 404 | void (*close)(struct trace_iterator *iter); |
107bad8b SR |
405 | ssize_t (*read)(struct trace_iterator *iter, |
406 | struct file *filp, char __user *ubuf, | |
407 | size_t cnt, loff_t *ppos); | |
3c56819b EGM |
408 | ssize_t (*splice_read)(struct trace_iterator *iter, |
409 | struct file *filp, | |
410 | loff_t *ppos, | |
411 | struct pipe_inode_info *pipe, | |
412 | size_t len, | |
413 | unsigned int flags); | |
60a11774 SR |
414 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
415 | int (*selftest)(struct tracer *trace, | |
416 | struct trace_array *tr); | |
417 | #endif | |
8bba1bf5 | 418 | void (*print_header)(struct seq_file *m); |
2c4f035f | 419 | enum print_line_t (*print_line)(struct trace_iterator *iter); |
adf9f195 FW |
420 | /* If you handled the flag setting, return 0 */ |
421 | int (*set_flag)(u32 old_flags, u32 bit, int set); | |
bc0c38d1 SR |
422 | struct tracer *next; |
423 | int print_max; | |
9de36825 | 424 | struct tracer_flags *flags; |
034939b6 | 425 | struct tracer_stat *stats; |
bc0c38d1 SR |
426 | }; |
427 | ||
f9520750 | 428 | |
b04cc6b1 FW |
429 | #define TRACE_PIPE_ALL_CPU -1 |
430 | ||
bc0c38d1 SR |
431 | /* |
432 | * Trace iterator - used by printout routines who present trace | |
433 | * results to users and which routines might sleep, etc: | |
434 | */ | |
435 | struct trace_iterator { | |
436 | struct trace_array *tr; | |
437 | struct tracer *trace; | |
107bad8b | 438 | void *private; |
b04cc6b1 | 439 | int cpu_file; |
d7350c3f FW |
440 | struct mutex mutex; |
441 | struct ring_buffer_iter *buffer_iter[NR_CPUS]; | |
4e3c3333 | 442 | |
53d0aa77 SR |
443 | /* The below is zeroed out in pipe_read */ |
444 | struct trace_seq seq; | |
bc0c38d1 | 445 | struct trace_entry *ent; |
4e3c3333 | 446 | int cpu; |
3928a8a2 | 447 | u64 ts; |
4e3c3333 | 448 | |
bc0c38d1 SR |
449 | unsigned long iter_flags; |
450 | loff_t pos; | |
4c11d7ae | 451 | long idx; |
a309720c | 452 | |
4462344e | 453 | cpumask_var_t started; |
bc0c38d1 SR |
454 | }; |
455 | ||
b6f11df2 | 456 | int tracer_init(struct tracer *t, struct trace_array *tr); |
9036990d | 457 | int tracing_is_enabled(void); |
45dcd8b8 | 458 | void trace_wake_up(void); |
3928a8a2 | 459 | void tracing_reset(struct trace_array *tr, int cpu); |
213cc060 | 460 | void tracing_reset_online_cpus(struct trace_array *tr); |
bc0c38d1 | 461 | int tracing_open_generic(struct inode *inode, struct file *filp); |
5452af66 FW |
462 | struct dentry *trace_create_file(const char *name, |
463 | mode_t mode, | |
464 | struct dentry *parent, | |
465 | void *data, | |
466 | const struct file_operations *fops); | |
467 | ||
bc0c38d1 | 468 | struct dentry *tracing_init_dentry(void); |
d618b3e6 IM |
469 | void init_tracer_sysprof_debugfs(struct dentry *d_tracer); |
470 | ||
51a763dd ACM |
471 | struct ring_buffer_event; |
472 | ||
473 | struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | |
474 | unsigned char type, | |
475 | unsigned long len, | |
476 | unsigned long flags, | |
477 | int pc); | |
478 | void trace_buffer_unlock_commit(struct trace_array *tr, | |
479 | struct ring_buffer_event *event, | |
480 | unsigned long flags, int pc); | |
481 | ||
ef5580d0 SR |
482 | struct ring_buffer_event * |
483 | trace_current_buffer_lock_reserve(unsigned char type, unsigned long len, | |
484 | unsigned long flags, int pc); | |
485 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | |
486 | unsigned long flags, int pc); | |
07edf712 FW |
487 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, |
488 | unsigned long flags, int pc); | |
77d9f465 | 489 | void trace_current_buffer_discard_commit(struct ring_buffer_event *event); |
ef5580d0 | 490 | |
45dcd8b8 PP |
491 | struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, |
492 | struct trace_array_cpu *data); | |
c4a8e8be FW |
493 | |
494 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | |
495 | int *ent_cpu, u64 *ent_ts); | |
496 | ||
45dcd8b8 | 497 | void tracing_generic_entry_update(struct trace_entry *entry, |
38697053 SR |
498 | unsigned long flags, |
499 | int pc); | |
45dcd8b8 | 500 | |
6eaaa5d5 FW |
501 | void default_wait_pipe(struct trace_iterator *iter); |
502 | void poll_wait_pipe(struct trace_iterator *iter); | |
503 | ||
bc0c38d1 SR |
504 | void ftrace(struct trace_array *tr, |
505 | struct trace_array_cpu *data, | |
506 | unsigned long ip, | |
507 | unsigned long parent_ip, | |
38697053 | 508 | unsigned long flags, int pc); |
bc0c38d1 | 509 | void tracing_sched_switch_trace(struct trace_array *tr, |
bc0c38d1 SR |
510 | struct task_struct *prev, |
511 | struct task_struct *next, | |
38697053 | 512 | unsigned long flags, int pc); |
bc0c38d1 | 513 | void tracing_record_cmdline(struct task_struct *tsk); |
57422797 IM |
514 | |
515 | void tracing_sched_wakeup_trace(struct trace_array *tr, | |
57422797 IM |
516 | struct task_struct *wakee, |
517 | struct task_struct *cur, | |
38697053 | 518 | unsigned long flags, int pc); |
f0a920d5 IM |
519 | void trace_special(struct trace_array *tr, |
520 | struct trace_array_cpu *data, | |
521 | unsigned long arg1, | |
522 | unsigned long arg2, | |
38697053 | 523 | unsigned long arg3, int pc); |
6fb44b71 | 524 | void trace_function(struct trace_array *tr, |
6fb44b71 SR |
525 | unsigned long ip, |
526 | unsigned long parent_ip, | |
38697053 | 527 | unsigned long flags, int pc); |
bc0c38d1 | 528 | |
287b6e68 | 529 | void trace_graph_return(struct ftrace_graph_ret *trace); |
e49dc19c | 530 | int trace_graph_entry(struct ftrace_graph_ent *trace); |
1e9b51c2 | 531 | |
41bc8144 SR |
532 | void tracing_start_cmdline_record(void); |
533 | void tracing_stop_cmdline_record(void); | |
e168e051 SR |
534 | void tracing_sched_switch_assign_trace(struct trace_array *tr); |
535 | void tracing_stop_sched_switch_record(void); | |
536 | void tracing_start_sched_switch_record(void); | |
bc0c38d1 SR |
537 | int register_tracer(struct tracer *type); |
538 | void unregister_tracer(struct tracer *type); | |
539 | ||
540 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); | |
541 | ||
542 | extern unsigned long tracing_max_latency; | |
543 | extern unsigned long tracing_thresh; | |
544 | ||
545 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); | |
546 | void update_max_tr_single(struct trace_array *tr, | |
547 | struct task_struct *tsk, int cpu); | |
548 | ||
53614991 | 549 | void __trace_stack(struct trace_array *tr, |
53614991 SR |
550 | unsigned long flags, |
551 | int skip, int pc); | |
552 | ||
e309b41d | 553 | extern cycle_t ftrace_now(int cpu); |
bc0c38d1 | 554 | |
bc0c38d1 SR |
555 | #ifdef CONFIG_CONTEXT_SWITCH_TRACER |
556 | typedef void | |
557 | (*tracer_switch_func_t)(void *private, | |
5b82a1b0 | 558 | void *__rq, |
bc0c38d1 SR |
559 | struct task_struct *prev, |
560 | struct task_struct *next); | |
561 | ||
562 | struct tracer_switch_ops { | |
563 | tracer_switch_func_t func; | |
564 | void *private; | |
565 | struct tracer_switch_ops *next; | |
566 | }; | |
bc0c38d1 SR |
567 | #endif /* CONFIG_CONTEXT_SWITCH_TRACER */ |
568 | ||
4ca53085 | 569 | extern void trace_find_cmdline(int pid, char comm[]); |
f7d48cbd | 570 | |
bc0c38d1 SR |
571 | #ifdef CONFIG_DYNAMIC_FTRACE |
572 | extern unsigned long ftrace_update_tot_cnt; | |
d05cdb25 SR |
573 | #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func |
574 | extern int DYN_FTRACE_TEST_NAME(void); | |
bc0c38d1 SR |
575 | #endif |
576 | ||
60a11774 | 577 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
60a11774 SR |
578 | extern int trace_selftest_startup_function(struct tracer *trace, |
579 | struct trace_array *tr); | |
7447dce9 FW |
580 | extern int trace_selftest_startup_function_graph(struct tracer *trace, |
581 | struct trace_array *tr); | |
60a11774 SR |
582 | extern int trace_selftest_startup_irqsoff(struct tracer *trace, |
583 | struct trace_array *tr); | |
60a11774 SR |
584 | extern int trace_selftest_startup_preemptoff(struct tracer *trace, |
585 | struct trace_array *tr); | |
60a11774 SR |
586 | extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace, |
587 | struct trace_array *tr); | |
60a11774 SR |
588 | extern int trace_selftest_startup_wakeup(struct tracer *trace, |
589 | struct trace_array *tr); | |
fb1b6d8b SN |
590 | extern int trace_selftest_startup_nop(struct tracer *trace, |
591 | struct trace_array *tr); | |
60a11774 SR |
592 | extern int trace_selftest_startup_sched_switch(struct tracer *trace, |
593 | struct trace_array *tr); | |
a6dd24f8 IM |
594 | extern int trace_selftest_startup_sysprof(struct tracer *trace, |
595 | struct trace_array *tr); | |
80e5ea45 SR |
596 | extern int trace_selftest_startup_branch(struct tracer *trace, |
597 | struct trace_array *tr); | |
60a11774 SR |
598 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
599 | ||
c7aafc54 | 600 | extern void *head_page(struct trace_array_cpu *data); |
cf8e3474 | 601 | extern unsigned long long ns2usecs(cycle_t nsec); |
1fd8f2a3 | 602 | extern int |
40ce74f1 | 603 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); |
48ead020 | 604 | extern int |
40ce74f1 | 605 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); |
c7aafc54 | 606 | |
4e655519 IM |
607 | extern unsigned long trace_flags; |
608 | ||
15e6cb36 | 609 | /* Standard output formatting function used for function return traces */ |
fb52607a FW |
610 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
611 | extern enum print_line_t print_graph_function(struct trace_iterator *iter); | |
0706f1c4 SR |
612 | extern enum print_line_t |
613 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); | |
ea4e2bc4 SR |
614 | |
615 | #ifdef CONFIG_DYNAMIC_FTRACE | |
616 | /* TODO: make this variable */ | |
617 | #define FTRACE_GRAPH_MAX_FUNCS 32 | |
618 | extern int ftrace_graph_count; | |
619 | extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS]; | |
620 | ||
621 | static inline int ftrace_graph_addr(unsigned long addr) | |
622 | { | |
623 | int i; | |
624 | ||
625 | if (!ftrace_graph_count || test_tsk_trace_graph(current)) | |
626 | return 1; | |
627 | ||
628 | for (i = 0; i < ftrace_graph_count; i++) { | |
629 | if (addr == ftrace_graph_funcs[i]) | |
630 | return 1; | |
631 | } | |
632 | ||
633 | return 0; | |
634 | } | |
15e6cb36 | 635 | #else |
ea4e2bc4 SR |
636 | static inline int ftrace_trace_addr(unsigned long addr) |
637 | { | |
6b253930 IM |
638 | return 1; |
639 | } | |
640 | static inline int ftrace_graph_addr(unsigned long addr) | |
641 | { | |
642 | return 1; | |
ea4e2bc4 SR |
643 | } |
644 | #endif /* CONFIG_DYNAMIC_FTRACE */ | |
ea4e2bc4 | 645 | #else /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 646 | static inline enum print_line_t |
fb52607a | 647 | print_graph_function(struct trace_iterator *iter) |
15e6cb36 FW |
648 | { |
649 | return TRACE_TYPE_UNHANDLED; | |
650 | } | |
ea4e2bc4 | 651 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 652 | |
978f3a45 | 653 | extern struct pid *ftrace_pid_trace; |
804a6851 SR |
654 | |
655 | static inline int ftrace_trace_task(struct task_struct *task) | |
656 | { | |
77d683f3 | 657 | if (!ftrace_pid_trace) |
804a6851 SR |
658 | return 1; |
659 | ||
660 | return test_tsk_trace_trace(task); | |
661 | } | |
662 | ||
4fcdae83 SR |
663 | /* |
664 | * trace_iterator_flags is an enumeration that defines bit | |
665 | * positions into trace_flags that controls the output. | |
666 | * | |
667 | * NOTE: These bits must match the trace_options array in | |
668 | * trace.c. | |
669 | */ | |
4e655519 IM |
670 | enum trace_iterator_flags { |
671 | TRACE_ITER_PRINT_PARENT = 0x01, | |
672 | TRACE_ITER_SYM_OFFSET = 0x02, | |
673 | TRACE_ITER_SYM_ADDR = 0x04, | |
674 | TRACE_ITER_VERBOSE = 0x08, | |
675 | TRACE_ITER_RAW = 0x10, | |
676 | TRACE_ITER_HEX = 0x20, | |
677 | TRACE_ITER_BIN = 0x40, | |
678 | TRACE_ITER_BLOCK = 0x80, | |
679 | TRACE_ITER_STACKTRACE = 0x100, | |
4ac3ba41 | 680 | TRACE_ITER_SCHED_TREE = 0x200, |
f09ce573 | 681 | TRACE_ITER_PRINTK = 0x400, |
b2a866f9 | 682 | TRACE_ITER_PREEMPTONLY = 0x800, |
9f029e83 | 683 | TRACE_ITER_BRANCH = 0x1000, |
12ef7d44 | 684 | TRACE_ITER_ANNOTATE = 0x2000, |
b54d3de9 | 685 | TRACE_ITER_USERSTACKTRACE = 0x4000, |
66896a85 | 686 | TRACE_ITER_SYM_USEROBJ = 0x8000, |
c4a8e8be | 687 | TRACE_ITER_PRINTK_MSGONLY = 0x10000, |
c032ef64 SR |
688 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ |
689 | TRACE_ITER_LATENCY_FMT = 0x40000, | |
af4617bd | 690 | TRACE_ITER_GLOBAL_CLK = 0x80000, |
be6f164a | 691 | TRACE_ITER_SLEEP_TIME = 0x100000, |
a2a16d6a | 692 | TRACE_ITER_GRAPH_TIME = 0x200000, |
4e655519 IM |
693 | }; |
694 | ||
15e6cb36 FW |
695 | /* |
696 | * TRACE_ITER_SYM_MASK masks the options in trace_flags that | |
697 | * control the output of kernel symbols. | |
698 | */ | |
699 | #define TRACE_ITER_SYM_MASK \ | |
700 | (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR) | |
701 | ||
43a15386 FW |
702 | extern struct tracer nop_trace; |
703 | ||
8f0a056f SR |
704 | /** |
705 | * ftrace_preempt_disable - disable preemption scheduler safe | |
706 | * | |
707 | * When tracing can happen inside the scheduler, there exists | |
708 | * cases that the tracing might happen before the need_resched | |
709 | * flag is checked. If this happens and the tracer calls | |
710 | * preempt_enable (after a disable), a schedule might take place | |
711 | * causing an infinite recursion. | |
712 | * | |
57794a9d | 713 | * To prevent this, we read the need_resched flag before |
8f0a056f SR |
714 | * disabling preemption. When we want to enable preemption we |
715 | * check the flag, if it is set, then we call preempt_enable_no_resched. | |
716 | * Otherwise, we call preempt_enable. | |
717 | * | |
57794a9d | 718 | * The rational for doing the above is that if need_resched is set |
8f0a056f SR |
719 | * and we have yet to reschedule, we are either in an atomic location |
720 | * (where we do not need to check for scheduling) or we are inside | |
721 | * the scheduler and do not want to resched. | |
722 | */ | |
723 | static inline int ftrace_preempt_disable(void) | |
724 | { | |
725 | int resched; | |
726 | ||
727 | resched = need_resched(); | |
728 | preempt_disable_notrace(); | |
729 | ||
730 | return resched; | |
731 | } | |
732 | ||
733 | /** | |
734 | * ftrace_preempt_enable - enable preemption scheduler safe | |
735 | * @resched: the return value from ftrace_preempt_disable | |
736 | * | |
737 | * This is a scheduler safe way to enable preemption and not miss | |
738 | * any preemption checks. The disabled saved the state of preemption. | |
57794a9d | 739 | * If resched is set, then we are either inside an atomic or |
8f0a056f SR |
740 | * are inside the scheduler (we would have already scheduled |
741 | * otherwise). In this case, we do not want to call normal | |
742 | * preempt_enable, but preempt_enable_no_resched instead. | |
743 | */ | |
744 | static inline void ftrace_preempt_enable(int resched) | |
745 | { | |
746 | if (resched) | |
747 | preempt_enable_no_resched_notrace(); | |
748 | else | |
749 | preempt_enable_notrace(); | |
750 | } | |
751 | ||
2ed84eeb | 752 | #ifdef CONFIG_BRANCH_TRACER |
9f029e83 SR |
753 | extern int enable_branch_tracing(struct trace_array *tr); |
754 | extern void disable_branch_tracing(void); | |
755 | static inline int trace_branch_enable(struct trace_array *tr) | |
52f232cb | 756 | { |
9f029e83 SR |
757 | if (trace_flags & TRACE_ITER_BRANCH) |
758 | return enable_branch_tracing(tr); | |
52f232cb SR |
759 | return 0; |
760 | } | |
9f029e83 | 761 | static inline void trace_branch_disable(void) |
52f232cb SR |
762 | { |
763 | /* due to races, always disable */ | |
9f029e83 | 764 | disable_branch_tracing(); |
52f232cb SR |
765 | } |
766 | #else | |
9f029e83 | 767 | static inline int trace_branch_enable(struct trace_array *tr) |
52f232cb SR |
768 | { |
769 | return 0; | |
770 | } | |
9f029e83 | 771 | static inline void trace_branch_disable(void) |
52f232cb SR |
772 | { |
773 | } | |
2ed84eeb | 774 | #endif /* CONFIG_BRANCH_TRACER */ |
52f232cb | 775 | |
1852fcce SR |
776 | /* set ring buffers to default size if not already done so */ |
777 | int tracing_update_buffers(void); | |
778 | ||
fd994989 SR |
779 | /* trace event type bit fields, not numeric */ |
780 | enum { | |
781 | TRACE_EVENT_TYPE_PRINTF = 1, | |
782 | TRACE_EVENT_TYPE_RAW = 2, | |
783 | }; | |
784 | ||
cf027f64 TZ |
785 | struct ftrace_event_field { |
786 | struct list_head link; | |
787 | char *name; | |
788 | char *type; | |
789 | int offset; | |
790 | int size; | |
791 | }; | |
792 | ||
c32e827b | 793 | struct ftrace_event_call { |
cf027f64 TZ |
794 | char *name; |
795 | char *system; | |
796 | struct dentry *dir; | |
797 | int enabled; | |
798 | int (*regfunc)(void); | |
799 | void (*unregfunc)(void); | |
800 | int id; | |
801 | int (*raw_init)(void); | |
802 | int (*show_format)(struct trace_seq *s); | |
803 | int (*define_fields)(void); | |
804 | struct list_head fields; | |
0a19e53c | 805 | int n_preds; |
7ce7e424 | 806 | struct filter_pred **preds; |
ac199db0 PZ |
807 | |
808 | #ifdef CONFIG_EVENT_PROFILE | |
809 | atomic_t profile_count; | |
810 | int (*profile_enable)(struct ftrace_event_call *); | |
811 | void (*profile_disable)(struct ftrace_event_call *); | |
812 | #endif | |
c32e827b SR |
813 | }; |
814 | ||
cfb180f3 TZ |
815 | struct event_subsystem { |
816 | struct list_head list; | |
817 | const char *name; | |
818 | struct dentry *entry; | |
0a19e53c | 819 | int n_preds; |
cfb180f3 TZ |
820 | struct filter_pred **preds; |
821 | }; | |
822 | ||
823 | #define events_for_each(event) \ | |
824 | for (event = __start_ftrace_events; \ | |
825 | (unsigned long)event < (unsigned long)__stop_ftrace_events; \ | |
826 | event++) | |
827 | ||
0a19e53c TZ |
828 | #define MAX_FILTER_PRED 8 |
829 | #define MAX_FILTER_STR_VAL 128 | |
7ce7e424 TZ |
830 | |
831 | struct filter_pred; | |
832 | ||
833 | typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event); | |
834 | ||
835 | struct filter_pred { | |
836 | filter_pred_fn_t fn; | |
837 | u64 val; | |
0a19e53c | 838 | char str_val[MAX_FILTER_STR_VAL]; |
7ce7e424 TZ |
839 | int str_len; |
840 | char *field_name; | |
841 | int offset; | |
842 | int not; | |
843 | int or; | |
844 | int compound; | |
845 | int clear; | |
846 | }; | |
847 | ||
cf027f64 TZ |
848 | int trace_define_field(struct ftrace_event_call *call, char *type, |
849 | char *name, int offset, int size); | |
0a19e53c | 850 | extern int init_preds(struct ftrace_event_call *call); |
7ce7e424 | 851 | extern void filter_free_pred(struct filter_pred *pred); |
0a19e53c | 852 | extern void filter_print_preds(struct filter_pred **preds, int n_preds, |
4bda2d51 | 853 | struct trace_seq *s); |
7ce7e424 TZ |
854 | extern int filter_parse(char **pbuf, struct filter_pred *pred); |
855 | extern int filter_add_pred(struct ftrace_event_call *call, | |
856 | struct filter_pred *pred); | |
0a19e53c | 857 | extern void filter_disable_preds(struct ftrace_event_call *call); |
7ce7e424 | 858 | extern int filter_match_preds(struct ftrace_event_call *call, void *rec); |
cfb180f3 TZ |
859 | extern void filter_free_subsystem_preds(struct event_subsystem *system); |
860 | extern int filter_add_subsystem_pred(struct event_subsystem *system, | |
861 | struct filter_pred *pred); | |
eb02ce01 TZ |
862 | extern int filter_current_check_discard(struct ftrace_event_call *call, |
863 | void *rec, | |
864 | struct ring_buffer_event *event); | |
7ce7e424 | 865 | |
eb02ce01 | 866 | static inline int |
e1112b4d | 867 | filter_check_discard(struct ftrace_event_call *call, void *rec, |
eb02ce01 | 868 | struct ring_buffer *buffer, |
e1112b4d TZ |
869 | struct ring_buffer_event *event) |
870 | { | |
0a19e53c | 871 | if (unlikely(call->n_preds) && !filter_match_preds(call, rec)) { |
eb02ce01 TZ |
872 | ring_buffer_discard_commit(buffer, event); |
873 | return 1; | |
874 | } | |
875 | ||
876 | return 0; | |
e1112b4d TZ |
877 | } |
878 | ||
879 | #define __common_field(type, item) \ | |
880 | ret = trace_define_field(event_call, #type, "common_" #item, \ | |
881 | offsetof(typeof(field.ent), item), \ | |
882 | sizeof(field.ent.item)); \ | |
883 | if (ret) \ | |
884 | return ret; | |
885 | ||
c32e827b SR |
886 | void event_trace_printk(unsigned long ip, const char *fmt, ...); |
887 | extern struct ftrace_event_call __start_ftrace_events[]; | |
888 | extern struct ftrace_event_call __stop_ftrace_events[]; | |
889 | ||
ac199db0 PZ |
890 | #define for_each_event(event) \ |
891 | for (event = __start_ftrace_events; \ | |
892 | (unsigned long)event < (unsigned long)__stop_ftrace_events; \ | |
893 | event++) | |
894 | ||
e9fb2b6d SR |
895 | extern const char *__start___trace_bprintk_fmt[]; |
896 | extern const char *__stop___trace_bprintk_fmt[]; | |
897 | ||
bdc06758 SR |
898 | /* |
899 | * The double __builtin_constant_p is because gcc will give us an error | |
900 | * if we try to allocate the static variable to fmt if it is not a | |
901 | * constant. Even with the outer if statement optimizing out. | |
902 | */ | |
e9fb2b6d SR |
903 | #define event_trace_printk(ip, fmt, args...) \ |
904 | do { \ | |
905 | __trace_printk_check_format(fmt, ##args); \ | |
906 | tracing_record_cmdline(current); \ | |
907 | if (__builtin_constant_p(fmt)) { \ | |
908 | static const char *trace_printk_fmt \ | |
909 | __attribute__((section("__trace_printk_fmt"))) = \ | |
910 | __builtin_constant_p(fmt) ? fmt : NULL; \ | |
911 | \ | |
912 | __trace_bprintk(ip, trace_printk_fmt, ##args); \ | |
913 | } else \ | |
914 | __trace_printk(ip, fmt, ##args); \ | |
915 | } while (0) | |
916 | ||
e1112b4d TZ |
917 | #undef TRACE_EVENT_FORMAT |
918 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ | |
919 | extern struct ftrace_event_call event_##call; | |
e45f2e2b TZ |
920 | #undef TRACE_EVENT_FORMAT_NOFILTER |
921 | #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt) | |
e1112b4d TZ |
922 | #include "trace_event_types.h" |
923 | ||
bc0c38d1 | 924 | #endif /* _LINUX_KERNEL_TRACE_H */ |