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