]>
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 | 15 | #include <linux/trace_seq.h> |
97f20251 | 16 | #include <linux/ftrace_event.h> |
9504504c | 17 | |
72829bc3 TG |
18 | enum trace_type { |
19 | __TRACE_FIRST_TYPE = 0, | |
20 | ||
21 | TRACE_FN, | |
22 | TRACE_CTX, | |
23 | TRACE_WAKE, | |
24 | TRACE_STACK, | |
dd0e545f | 25 | TRACE_PRINT, |
48ead020 | 26 | TRACE_BPRINT, |
72829bc3 | 27 | TRACE_SPECIAL, |
bd8ac686 PP |
28 | TRACE_MMIO_RW, |
29 | TRACE_MMIO_MAP, | |
9f029e83 | 30 | TRACE_BRANCH, |
74239072 FW |
31 | TRACE_BOOT_CALL, |
32 | TRACE_BOOT_RET, | |
287b6e68 FW |
33 | TRACE_GRAPH_RET, |
34 | TRACE_GRAPH_ENT, | |
02b67518 | 35 | TRACE_USER_STACK, |
a93751ca | 36 | TRACE_HW_BRANCHES, |
36994e58 FW |
37 | TRACE_KMEM_ALLOC, |
38 | TRACE_KMEM_FREE, | |
f3f47a67 | 39 | TRACE_POWER, |
c71a8961 | 40 | TRACE_BLK, |
72829bc3 | 41 | |
f0868d1e | 42 | __TRACE_LAST_TYPE, |
72829bc3 TG |
43 | }; |
44 | ||
0a1c49db SR |
45 | enum kmemtrace_type_id { |
46 | KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */ | |
47 | KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */ | |
48 | KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */ | |
287b6e68 FW |
49 | }; |
50 | ||
d13744cd | 51 | extern struct tracer boot_tracer; |
bc0c38d1 | 52 | |
0a1c49db SR |
53 | #undef __field |
54 | #define __field(type, item) type item; | |
48ead020 | 55 | |
d7315094 SR |
56 | #undef __field_struct |
57 | #define __field_struct(type, item) __field(type, item) | |
58 | ||
59 | #undef __field_desc | |
60 | #define __field_desc(type, container, item) | |
61 | ||
0a1c49db SR |
62 | #undef __array |
63 | #define __array(type, item, size) type item[size]; | |
777e208d | 64 | |
d7315094 SR |
65 | #undef __array_desc |
66 | #define __array_desc(type, container, item, size) | |
67 | ||
0a1c49db SR |
68 | #undef __dynamic_array |
69 | #define __dynamic_array(type, item) type item[]; | |
777e208d | 70 | |
0a1c49db SR |
71 | #undef F_STRUCT |
72 | #define F_STRUCT(args...) args | |
74239072 | 73 | |
0a1c49db SR |
74 | #undef FTRACE_ENTRY |
75 | #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \ | |
76 | struct struct_name { \ | |
77 | struct trace_entry ent; \ | |
78 | tstruct \ | |
79 | } | |
777e208d | 80 | |
0a1c49db SR |
81 | #undef TP_ARGS |
82 | #define TP_ARGS(args...) args | |
52f232cb | 83 | |
0a1c49db SR |
84 | #undef FTRACE_ENTRY_DUP |
85 | #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk) | |
1e9b51c2 | 86 | |
0a1c49db | 87 | #include "trace_entries.h" |
36994e58 | 88 | |
0a1c49db SR |
89 | /* |
90 | * syscalls are special, and need special handling, this is why | |
91 | * they are not included in trace_entries.h | |
92 | */ | |
bed1ffca FW |
93 | struct syscall_trace_enter { |
94 | struct trace_entry ent; | |
95 | int nr; | |
96 | unsigned long args[]; | |
97 | }; | |
98 | ||
99 | struct syscall_trace_exit { | |
100 | struct trace_entry ent; | |
101 | int nr; | |
102 | unsigned long ret; | |
103 | }; | |
104 | ||
fc5e27ae PP |
105 | /* |
106 | * trace_flag_type is an enumeration that holds different | |
107 | * states when a trace occurs. These are: | |
9244489a | 108 | * IRQS_OFF - interrupts were disabled |
9de36825 | 109 | * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags |
bd9cfca9 | 110 | * NEED_RESCHED - reschedule is requested |
9244489a SR |
111 | * HARDIRQ - inside an interrupt handler |
112 | * SOFTIRQ - inside a softirq handler | |
fc5e27ae PP |
113 | */ |
114 | enum trace_flag_type { | |
115 | TRACE_FLAG_IRQS_OFF = 0x01, | |
9244489a SR |
116 | TRACE_FLAG_IRQS_NOSUPPORT = 0x02, |
117 | TRACE_FLAG_NEED_RESCHED = 0x04, | |
118 | TRACE_FLAG_HARDIRQ = 0x08, | |
119 | TRACE_FLAG_SOFTIRQ = 0x10, | |
fc5e27ae PP |
120 | }; |
121 | ||
5bf9a1ee | 122 | #define TRACE_BUF_SIZE 1024 |
bc0c38d1 SR |
123 | |
124 | /* | |
125 | * The CPU trace array - it consists of thousands of trace entries | |
126 | * plus some other descriptor data: (for example which task started | |
127 | * the trace, etc.) | |
128 | */ | |
129 | struct trace_array_cpu { | |
bc0c38d1 | 130 | atomic_t disabled; |
2cadf913 | 131 | void *buffer_page; /* ring buffer spare */ |
4e3c3333 | 132 | |
bc0c38d1 SR |
133 | unsigned long saved_latency; |
134 | unsigned long critical_start; | |
135 | unsigned long critical_end; | |
136 | unsigned long critical_sequence; | |
137 | unsigned long nice; | |
138 | unsigned long policy; | |
139 | unsigned long rt_priority; | |
2f26ebd5 | 140 | unsigned long skipped_entries; |
bc0c38d1 SR |
141 | cycle_t preempt_timestamp; |
142 | pid_t pid; | |
143 | uid_t uid; | |
144 | char comm[TASK_COMM_LEN]; | |
145 | }; | |
146 | ||
bc0c38d1 SR |
147 | /* |
148 | * The trace array - an array of per-CPU trace arrays. This is the | |
149 | * highest level data structure that individual tracers deal with. | |
150 | * They have on/off state as well: | |
151 | */ | |
152 | struct trace_array { | |
3928a8a2 | 153 | struct ring_buffer *buffer; |
bc0c38d1 | 154 | unsigned long entries; |
bc0c38d1 SR |
155 | int cpu; |
156 | cycle_t time_start; | |
b3806b43 | 157 | struct task_struct *waiter; |
bc0c38d1 SR |
158 | struct trace_array_cpu *data[NR_CPUS]; |
159 | }; | |
160 | ||
7104f300 SR |
161 | #define FTRACE_CMP_TYPE(var, type) \ |
162 | __builtin_types_compatible_p(typeof(var), type *) | |
163 | ||
164 | #undef IF_ASSIGN | |
165 | #define IF_ASSIGN(var, entry, etype, id) \ | |
166 | if (FTRACE_CMP_TYPE(var, etype)) { \ | |
167 | var = (typeof(var))(entry); \ | |
168 | WARN_ON(id && (entry)->type != id); \ | |
169 | break; \ | |
170 | } | |
171 | ||
172 | /* Will cause compile errors if type is not found. */ | |
173 | extern void __ftrace_bad_type(void); | |
174 | ||
175 | /* | |
176 | * The trace_assign_type is a verifier that the entry type is | |
177 | * the same as the type being assigned. To add new types simply | |
178 | * add a line with the following format: | |
179 | * | |
180 | * IF_ASSIGN(var, ent, type, id); | |
181 | * | |
182 | * Where "type" is the trace type that includes the trace_entry | |
183 | * as the "ent" item. And "id" is the trace identifier that is | |
184 | * used in the trace_type enum. | |
185 | * | |
186 | * If the type can have more than one id, then use zero. | |
187 | */ | |
188 | #define trace_assign_type(var, ent) \ | |
189 | do { \ | |
190 | IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \ | |
191 | IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \ | |
7104f300 | 192 | IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \ |
02b67518 | 193 | IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\ |
7104f300 | 194 | IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \ |
48ead020 | 195 | IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \ |
7104f300 SR |
196 | IF_ASSIGN(var, ent, struct special_entry, 0); \ |
197 | IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \ | |
198 | TRACE_MMIO_RW); \ | |
199 | IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \ | |
200 | TRACE_MMIO_MAP); \ | |
74239072 FW |
201 | IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\ |
202 | IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\ | |
9f029e83 | 203 | IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \ |
287b6e68 FW |
204 | IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \ |
205 | TRACE_GRAPH_ENT); \ | |
206 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ | |
207 | TRACE_GRAPH_RET); \ | |
a93751ca | 208 | IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\ |
9de36825 | 209 | IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \ |
36994e58 FW |
210 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ |
211 | TRACE_KMEM_ALLOC); \ | |
212 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ | |
213 | TRACE_KMEM_FREE); \ | |
7104f300 SR |
214 | __ftrace_bad_type(); \ |
215 | } while (0) | |
2c4f035f | 216 | |
adf9f195 FW |
217 | /* |
218 | * An option specific to a tracer. This is a boolean value. | |
219 | * The bit is the bit index that sets its value on the | |
220 | * flags value in struct tracer_flags. | |
221 | */ | |
222 | struct tracer_opt { | |
9de36825 IM |
223 | const char *name; /* Will appear on the trace_options file */ |
224 | u32 bit; /* Mask assigned in val field in tracer_flags */ | |
adf9f195 FW |
225 | }; |
226 | ||
227 | /* | |
228 | * The set of specific options for a tracer. Your tracer | |
229 | * have to set the initial value of the flags val. | |
230 | */ | |
231 | struct tracer_flags { | |
232 | u32 val; | |
9de36825 | 233 | struct tracer_opt *opts; |
adf9f195 FW |
234 | }; |
235 | ||
236 | /* Makes more easy to define a tracer opt */ | |
237 | #define TRACER_OPT(s, b) .name = #s, .bit = b | |
238 | ||
034939b6 | 239 | |
6eaaa5d5 FW |
240 | /** |
241 | * struct tracer - a specific tracer and its callbacks to interact with debugfs | |
242 | * @name: the name chosen to select it on the available_tracers file | |
243 | * @init: called when one switches to this tracer (echo name > current_tracer) | |
244 | * @reset: called when one switches to another tracer | |
245 | * @start: called when tracing is unpaused (echo 1 > tracing_enabled) | |
246 | * @stop: called when tracing is paused (echo 0 > tracing_enabled) | |
247 | * @open: called when the trace file is opened | |
248 | * @pipe_open: called when the trace_pipe file is opened | |
249 | * @wait_pipe: override how the user waits for traces on trace_pipe | |
250 | * @close: called when the trace file is released | |
251 | * @read: override the default read callback on trace_pipe | |
252 | * @splice_read: override the default splice_read callback on trace_pipe | |
253 | * @selftest: selftest to run on boot (see trace_selftest.c) | |
254 | * @print_headers: override the first lines that describe your columns | |
255 | * @print_line: callback that prints a trace | |
256 | * @set_flag: signals one of your private flags changed (trace_options file) | |
257 | * @flags: your private flags | |
bc0c38d1 SR |
258 | */ |
259 | struct tracer { | |
260 | const char *name; | |
1c80025a | 261 | int (*init)(struct trace_array *tr); |
bc0c38d1 | 262 | void (*reset)(struct trace_array *tr); |
9036990d SR |
263 | void (*start)(struct trace_array *tr); |
264 | void (*stop)(struct trace_array *tr); | |
bc0c38d1 | 265 | void (*open)(struct trace_iterator *iter); |
107bad8b | 266 | void (*pipe_open)(struct trace_iterator *iter); |
6eaaa5d5 | 267 | void (*wait_pipe)(struct trace_iterator *iter); |
bc0c38d1 | 268 | void (*close)(struct trace_iterator *iter); |
107bad8b SR |
269 | ssize_t (*read)(struct trace_iterator *iter, |
270 | struct file *filp, char __user *ubuf, | |
271 | size_t cnt, loff_t *ppos); | |
3c56819b EGM |
272 | ssize_t (*splice_read)(struct trace_iterator *iter, |
273 | struct file *filp, | |
274 | loff_t *ppos, | |
275 | struct pipe_inode_info *pipe, | |
276 | size_t len, | |
277 | unsigned int flags); | |
60a11774 SR |
278 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
279 | int (*selftest)(struct tracer *trace, | |
280 | struct trace_array *tr); | |
281 | #endif | |
8bba1bf5 | 282 | void (*print_header)(struct seq_file *m); |
2c4f035f | 283 | enum print_line_t (*print_line)(struct trace_iterator *iter); |
adf9f195 FW |
284 | /* If you handled the flag setting, return 0 */ |
285 | int (*set_flag)(u32 old_flags, u32 bit, int set); | |
bc0c38d1 SR |
286 | struct tracer *next; |
287 | int print_max; | |
9de36825 | 288 | struct tracer_flags *flags; |
bc0c38d1 SR |
289 | }; |
290 | ||
f9520750 | 291 | |
b04cc6b1 FW |
292 | #define TRACE_PIPE_ALL_CPU -1 |
293 | ||
b6f11df2 | 294 | int tracer_init(struct tracer *t, struct trace_array *tr); |
9036990d | 295 | int tracing_is_enabled(void); |
45dcd8b8 | 296 | void trace_wake_up(void); |
3928a8a2 | 297 | void tracing_reset(struct trace_array *tr, int cpu); |
213cc060 | 298 | void tracing_reset_online_cpus(struct trace_array *tr); |
9456f0fa SR |
299 | void tracing_reset_current(int cpu); |
300 | void tracing_reset_current_online_cpus(void); | |
bc0c38d1 | 301 | int tracing_open_generic(struct inode *inode, struct file *filp); |
5452af66 FW |
302 | struct dentry *trace_create_file(const char *name, |
303 | mode_t mode, | |
304 | struct dentry *parent, | |
305 | void *data, | |
306 | const struct file_operations *fops); | |
307 | ||
bc0c38d1 | 308 | struct dentry *tracing_init_dentry(void); |
d618b3e6 IM |
309 | void init_tracer_sysprof_debugfs(struct dentry *d_tracer); |
310 | ||
51a763dd ACM |
311 | struct ring_buffer_event; |
312 | ||
e77405ad SR |
313 | struct ring_buffer_event * |
314 | trace_buffer_lock_reserve(struct ring_buffer *buffer, | |
315 | int type, | |
316 | unsigned long len, | |
317 | unsigned long flags, | |
318 | int pc); | |
319 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, | |
51a763dd ACM |
320 | struct ring_buffer_event *event, |
321 | unsigned long flags, int pc); | |
322 | ||
45dcd8b8 PP |
323 | struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, |
324 | struct trace_array_cpu *data); | |
c4a8e8be FW |
325 | |
326 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | |
327 | int *ent_cpu, u64 *ent_ts); | |
328 | ||
6eaaa5d5 FW |
329 | void default_wait_pipe(struct trace_iterator *iter); |
330 | void poll_wait_pipe(struct trace_iterator *iter); | |
331 | ||
bc0c38d1 SR |
332 | void ftrace(struct trace_array *tr, |
333 | struct trace_array_cpu *data, | |
334 | unsigned long ip, | |
335 | unsigned long parent_ip, | |
38697053 | 336 | unsigned long flags, int pc); |
bc0c38d1 | 337 | void tracing_sched_switch_trace(struct trace_array *tr, |
bc0c38d1 SR |
338 | struct task_struct *prev, |
339 | struct task_struct *next, | |
38697053 | 340 | unsigned long flags, int pc); |
57422797 IM |
341 | |
342 | void tracing_sched_wakeup_trace(struct trace_array *tr, | |
57422797 IM |
343 | struct task_struct *wakee, |
344 | struct task_struct *cur, | |
38697053 | 345 | unsigned long flags, int pc); |
f0a920d5 IM |
346 | void trace_special(struct trace_array *tr, |
347 | struct trace_array_cpu *data, | |
348 | unsigned long arg1, | |
349 | unsigned long arg2, | |
38697053 | 350 | unsigned long arg3, int pc); |
6fb44b71 | 351 | void trace_function(struct trace_array *tr, |
6fb44b71 SR |
352 | unsigned long ip, |
353 | unsigned long parent_ip, | |
38697053 | 354 | unsigned long flags, int pc); |
bc0c38d1 | 355 | |
287b6e68 | 356 | void trace_graph_return(struct ftrace_graph_ret *trace); |
e49dc19c | 357 | int trace_graph_entry(struct ftrace_graph_ent *trace); |
1a0799a8 | 358 | void set_graph_array(struct trace_array *tr); |
1e9b51c2 | 359 | |
41bc8144 SR |
360 | void tracing_start_cmdline_record(void); |
361 | void tracing_stop_cmdline_record(void); | |
e168e051 SR |
362 | void tracing_sched_switch_assign_trace(struct trace_array *tr); |
363 | void tracing_stop_sched_switch_record(void); | |
364 | void tracing_start_sched_switch_record(void); | |
bc0c38d1 SR |
365 | int register_tracer(struct tracer *type); |
366 | void unregister_tracer(struct tracer *type); | |
b5130b1e | 367 | int is_tracing_stopped(void); |
bc0c38d1 SR |
368 | |
369 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); | |
370 | ||
5d4a9dba | 371 | #ifdef CONFIG_TRACER_MAX_TRACE |
bc0c38d1 SR |
372 | extern unsigned long tracing_max_latency; |
373 | extern unsigned long tracing_thresh; | |
374 | ||
375 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); | |
376 | void update_max_tr_single(struct trace_array *tr, | |
377 | struct task_struct *tsk, int cpu); | |
5d4a9dba | 378 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
bc0c38d1 | 379 | |
c0a0d0d3 | 380 | #ifdef CONFIG_STACKTRACE |
e77405ad | 381 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
c0a0d0d3 FW |
382 | int skip, int pc); |
383 | ||
e77405ad | 384 | void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, |
c0a0d0d3 FW |
385 | int pc); |
386 | ||
387 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, | |
388 | int pc); | |
389 | #else | |
390 | static inline void ftrace_trace_stack(struct trace_array *tr, | |
391 | unsigned long flags, int skip, int pc) | |
392 | { | |
393 | } | |
394 | ||
395 | static inline void ftrace_trace_userstack(struct trace_array *tr, | |
396 | unsigned long flags, int pc) | |
397 | { | |
398 | } | |
399 | ||
400 | static inline void __trace_stack(struct trace_array *tr, unsigned long flags, | |
401 | int skip, int pc) | |
402 | { | |
403 | } | |
404 | #endif /* CONFIG_STACKTRACE */ | |
53614991 | 405 | |
e309b41d | 406 | extern cycle_t ftrace_now(int cpu); |
bc0c38d1 | 407 | |
4ca53085 | 408 | extern void trace_find_cmdline(int pid, char comm[]); |
f7d48cbd | 409 | |
bc0c38d1 SR |
410 | #ifdef CONFIG_DYNAMIC_FTRACE |
411 | extern unsigned long ftrace_update_tot_cnt; | |
d05cdb25 SR |
412 | #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func |
413 | extern int DYN_FTRACE_TEST_NAME(void); | |
bc0c38d1 SR |
414 | #endif |
415 | ||
020e5f85 LZ |
416 | extern int ring_buffer_expanded; |
417 | extern bool tracing_selftest_disabled; | |
5e5bf483 | 418 | DECLARE_PER_CPU(local_t, ftrace_cpu_disabled); |
020e5f85 | 419 | |
60a11774 | 420 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
60a11774 SR |
421 | extern int trace_selftest_startup_function(struct tracer *trace, |
422 | struct trace_array *tr); | |
7447dce9 FW |
423 | extern int trace_selftest_startup_function_graph(struct tracer *trace, |
424 | struct trace_array *tr); | |
60a11774 SR |
425 | extern int trace_selftest_startup_irqsoff(struct tracer *trace, |
426 | struct trace_array *tr); | |
60a11774 SR |
427 | extern int trace_selftest_startup_preemptoff(struct tracer *trace, |
428 | struct trace_array *tr); | |
60a11774 SR |
429 | extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace, |
430 | struct trace_array *tr); | |
60a11774 SR |
431 | extern int trace_selftest_startup_wakeup(struct tracer *trace, |
432 | struct trace_array *tr); | |
fb1b6d8b SN |
433 | extern int trace_selftest_startup_nop(struct tracer *trace, |
434 | struct trace_array *tr); | |
60a11774 SR |
435 | extern int trace_selftest_startup_sched_switch(struct tracer *trace, |
436 | struct trace_array *tr); | |
a6dd24f8 IM |
437 | extern int trace_selftest_startup_sysprof(struct tracer *trace, |
438 | struct trace_array *tr); | |
80e5ea45 SR |
439 | extern int trace_selftest_startup_branch(struct tracer *trace, |
440 | struct trace_array *tr); | |
321bb5e1 MM |
441 | extern int trace_selftest_startup_hw_branches(struct tracer *trace, |
442 | struct trace_array *tr); | |
60a11774 SR |
443 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
444 | ||
c7aafc54 | 445 | extern void *head_page(struct trace_array_cpu *data); |
cf8e3474 | 446 | extern unsigned long long ns2usecs(cycle_t nsec); |
1fd8f2a3 | 447 | extern int |
40ce74f1 | 448 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); |
48ead020 | 449 | extern int |
40ce74f1 | 450 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); |
659372d3 SR |
451 | extern int |
452 | trace_array_vprintk(struct trace_array *tr, | |
453 | unsigned long ip, const char *fmt, va_list args); | |
454 | int trace_array_printk(struct trace_array *tr, | |
455 | unsigned long ip, const char *fmt, ...); | |
c7aafc54 | 456 | |
4e655519 IM |
457 | extern unsigned long trace_flags; |
458 | ||
5079f326 Z |
459 | extern int trace_clock_id; |
460 | ||
15e6cb36 | 461 | /* Standard output formatting function used for function return traces */ |
fb52607a FW |
462 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
463 | extern enum print_line_t print_graph_function(struct trace_iterator *iter); | |
0706f1c4 SR |
464 | extern enum print_line_t |
465 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); | |
ea4e2bc4 SR |
466 | |
467 | #ifdef CONFIG_DYNAMIC_FTRACE | |
468 | /* TODO: make this variable */ | |
469 | #define FTRACE_GRAPH_MAX_FUNCS 32 | |
470 | extern int ftrace_graph_count; | |
471 | extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS]; | |
472 | ||
473 | static inline int ftrace_graph_addr(unsigned long addr) | |
474 | { | |
475 | int i; | |
476 | ||
477 | if (!ftrace_graph_count || test_tsk_trace_graph(current)) | |
478 | return 1; | |
479 | ||
480 | for (i = 0; i < ftrace_graph_count; i++) { | |
481 | if (addr == ftrace_graph_funcs[i]) | |
482 | return 1; | |
483 | } | |
484 | ||
485 | return 0; | |
486 | } | |
15e6cb36 | 487 | #else |
ea4e2bc4 SR |
488 | static inline int ftrace_trace_addr(unsigned long addr) |
489 | { | |
6b253930 IM |
490 | return 1; |
491 | } | |
492 | static inline int ftrace_graph_addr(unsigned long addr) | |
493 | { | |
494 | return 1; | |
ea4e2bc4 SR |
495 | } |
496 | #endif /* CONFIG_DYNAMIC_FTRACE */ | |
ea4e2bc4 | 497 | #else /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 498 | static inline enum print_line_t |
fb52607a | 499 | print_graph_function(struct trace_iterator *iter) |
15e6cb36 FW |
500 | { |
501 | return TRACE_TYPE_UNHANDLED; | |
502 | } | |
ea4e2bc4 | 503 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
15e6cb36 | 504 | |
978f3a45 | 505 | extern struct pid *ftrace_pid_trace; |
804a6851 | 506 | |
1155de47 | 507 | #ifdef CONFIG_FUNCTION_TRACER |
804a6851 SR |
508 | static inline int ftrace_trace_task(struct task_struct *task) |
509 | { | |
77d683f3 | 510 | if (!ftrace_pid_trace) |
804a6851 SR |
511 | return 1; |
512 | ||
513 | return test_tsk_trace_trace(task); | |
514 | } | |
1155de47 PM |
515 | #else |
516 | static inline int ftrace_trace_task(struct task_struct *task) | |
517 | { | |
518 | return 1; | |
519 | } | |
520 | #endif | |
804a6851 | 521 | |
b63f39ea | 522 | /* |
523 | * struct trace_parser - servers for reading the user input separated by spaces | |
524 | * @cont: set if the input is not complete - no final space char was found | |
525 | * @buffer: holds the parsed user input | |
526 | * @idx: user input lenght | |
527 | * @size: buffer size | |
528 | */ | |
529 | struct trace_parser { | |
530 | bool cont; | |
531 | char *buffer; | |
532 | unsigned idx; | |
533 | unsigned size; | |
534 | }; | |
535 | ||
536 | static inline bool trace_parser_loaded(struct trace_parser *parser) | |
537 | { | |
538 | return (parser->idx != 0); | |
539 | } | |
540 | ||
541 | static inline bool trace_parser_cont(struct trace_parser *parser) | |
542 | { | |
543 | return parser->cont; | |
544 | } | |
545 | ||
546 | static inline void trace_parser_clear(struct trace_parser *parser) | |
547 | { | |
548 | parser->cont = false; | |
549 | parser->idx = 0; | |
550 | } | |
551 | ||
552 | extern int trace_parser_get_init(struct trace_parser *parser, int size); | |
553 | extern void trace_parser_put(struct trace_parser *parser); | |
554 | extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, | |
555 | size_t cnt, loff_t *ppos); | |
556 | ||
4fcdae83 SR |
557 | /* |
558 | * trace_iterator_flags is an enumeration that defines bit | |
559 | * positions into trace_flags that controls the output. | |
560 | * | |
561 | * NOTE: These bits must match the trace_options array in | |
562 | * trace.c. | |
563 | */ | |
4e655519 IM |
564 | enum trace_iterator_flags { |
565 | TRACE_ITER_PRINT_PARENT = 0x01, | |
566 | TRACE_ITER_SYM_OFFSET = 0x02, | |
567 | TRACE_ITER_SYM_ADDR = 0x04, | |
568 | TRACE_ITER_VERBOSE = 0x08, | |
569 | TRACE_ITER_RAW = 0x10, | |
570 | TRACE_ITER_HEX = 0x20, | |
571 | TRACE_ITER_BIN = 0x40, | |
572 | TRACE_ITER_BLOCK = 0x80, | |
573 | TRACE_ITER_STACKTRACE = 0x100, | |
4ac3ba41 | 574 | TRACE_ITER_SCHED_TREE = 0x200, |
f09ce573 | 575 | TRACE_ITER_PRINTK = 0x400, |
b2a866f9 | 576 | TRACE_ITER_PREEMPTONLY = 0x800, |
9f029e83 | 577 | TRACE_ITER_BRANCH = 0x1000, |
12ef7d44 | 578 | TRACE_ITER_ANNOTATE = 0x2000, |
b54d3de9 | 579 | TRACE_ITER_USERSTACKTRACE = 0x4000, |
66896a85 | 580 | TRACE_ITER_SYM_USEROBJ = 0x8000, |
c4a8e8be | 581 | TRACE_ITER_PRINTK_MSGONLY = 0x10000, |
c032ef64 SR |
582 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ |
583 | TRACE_ITER_LATENCY_FMT = 0x40000, | |
5079f326 Z |
584 | TRACE_ITER_SLEEP_TIME = 0x80000, |
585 | TRACE_ITER_GRAPH_TIME = 0x100000, | |
4e655519 IM |
586 | }; |
587 | ||
15e6cb36 FW |
588 | /* |
589 | * TRACE_ITER_SYM_MASK masks the options in trace_flags that | |
590 | * control the output of kernel symbols. | |
591 | */ | |
592 | #define TRACE_ITER_SYM_MASK \ | |
593 | (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR) | |
594 | ||
43a15386 FW |
595 | extern struct tracer nop_trace; |
596 | ||
8f0a056f SR |
597 | /** |
598 | * ftrace_preempt_disable - disable preemption scheduler safe | |
599 | * | |
600 | * When tracing can happen inside the scheduler, there exists | |
601 | * cases that the tracing might happen before the need_resched | |
602 | * flag is checked. If this happens and the tracer calls | |
603 | * preempt_enable (after a disable), a schedule might take place | |
604 | * causing an infinite recursion. | |
605 | * | |
57794a9d | 606 | * To prevent this, we read the need_resched flag before |
8f0a056f SR |
607 | * disabling preemption. When we want to enable preemption we |
608 | * check the flag, if it is set, then we call preempt_enable_no_resched. | |
609 | * Otherwise, we call preempt_enable. | |
610 | * | |
57794a9d | 611 | * The rational for doing the above is that if need_resched is set |
8f0a056f SR |
612 | * and we have yet to reschedule, we are either in an atomic location |
613 | * (where we do not need to check for scheduling) or we are inside | |
614 | * the scheduler and do not want to resched. | |
615 | */ | |
616 | static inline int ftrace_preempt_disable(void) | |
617 | { | |
618 | int resched; | |
619 | ||
620 | resched = need_resched(); | |
621 | preempt_disable_notrace(); | |
622 | ||
623 | return resched; | |
624 | } | |
625 | ||
626 | /** | |
627 | * ftrace_preempt_enable - enable preemption scheduler safe | |
628 | * @resched: the return value from ftrace_preempt_disable | |
629 | * | |
630 | * This is a scheduler safe way to enable preemption and not miss | |
631 | * any preemption checks. The disabled saved the state of preemption. | |
57794a9d | 632 | * If resched is set, then we are either inside an atomic or |
8f0a056f SR |
633 | * are inside the scheduler (we would have already scheduled |
634 | * otherwise). In this case, we do not want to call normal | |
635 | * preempt_enable, but preempt_enable_no_resched instead. | |
636 | */ | |
637 | static inline void ftrace_preempt_enable(int resched) | |
638 | { | |
639 | if (resched) | |
640 | preempt_enable_no_resched_notrace(); | |
641 | else | |
642 | preempt_enable_notrace(); | |
643 | } | |
644 | ||
2ed84eeb | 645 | #ifdef CONFIG_BRANCH_TRACER |
9f029e83 SR |
646 | extern int enable_branch_tracing(struct trace_array *tr); |
647 | extern void disable_branch_tracing(void); | |
648 | static inline int trace_branch_enable(struct trace_array *tr) | |
52f232cb | 649 | { |
9f029e83 SR |
650 | if (trace_flags & TRACE_ITER_BRANCH) |
651 | return enable_branch_tracing(tr); | |
52f232cb SR |
652 | return 0; |
653 | } | |
9f029e83 | 654 | static inline void trace_branch_disable(void) |
52f232cb SR |
655 | { |
656 | /* due to races, always disable */ | |
9f029e83 | 657 | disable_branch_tracing(); |
52f232cb SR |
658 | } |
659 | #else | |
9f029e83 | 660 | static inline int trace_branch_enable(struct trace_array *tr) |
52f232cb SR |
661 | { |
662 | return 0; | |
663 | } | |
9f029e83 | 664 | static inline void trace_branch_disable(void) |
52f232cb SR |
665 | { |
666 | } | |
2ed84eeb | 667 | #endif /* CONFIG_BRANCH_TRACER */ |
52f232cb | 668 | |
1852fcce SR |
669 | /* set ring buffers to default size if not already done so */ |
670 | int tracing_update_buffers(void); | |
671 | ||
fd994989 SR |
672 | /* trace event type bit fields, not numeric */ |
673 | enum { | |
674 | TRACE_EVENT_TYPE_PRINTF = 1, | |
675 | TRACE_EVENT_TYPE_RAW = 2, | |
676 | }; | |
677 | ||
cf027f64 TZ |
678 | struct ftrace_event_field { |
679 | struct list_head link; | |
680 | char *name; | |
681 | char *type; | |
aa38e9fc | 682 | int filter_type; |
cf027f64 TZ |
683 | int offset; |
684 | int size; | |
a118e4d1 | 685 | int is_signed; |
cf027f64 TZ |
686 | }; |
687 | ||
30e673b2 TZ |
688 | struct event_filter { |
689 | int n_preds; | |
690 | struct filter_pred **preds; | |
8b372562 | 691 | char *filter_string; |
1f9963cb | 692 | bool no_reset; |
30e673b2 TZ |
693 | }; |
694 | ||
cfb180f3 TZ |
695 | struct event_subsystem { |
696 | struct list_head list; | |
697 | const char *name; | |
698 | struct dentry *entry; | |
1f9963cb | 699 | struct event_filter *filter; |
dc82ec98 | 700 | int nr_events; |
cfb180f3 TZ |
701 | }; |
702 | ||
7ce7e424 TZ |
703 | struct filter_pred; |
704 | ||
8b372562 TZ |
705 | typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event, |
706 | int val1, int val2); | |
7ce7e424 TZ |
707 | |
708 | struct filter_pred { | |
709 | filter_pred_fn_t fn; | |
710 | u64 val; | |
0a19e53c | 711 | char str_val[MAX_FILTER_STR_VAL]; |
7ce7e424 TZ |
712 | int str_len; |
713 | char *field_name; | |
714 | int offset; | |
715 | int not; | |
8b372562 TZ |
716 | int op; |
717 | int pop_n; | |
7ce7e424 TZ |
718 | }; |
719 | ||
8b372562 | 720 | extern void print_event_filter(struct ftrace_event_call *call, |
4bda2d51 | 721 | struct trace_seq *s); |
8b372562 TZ |
722 | extern int apply_event_filter(struct ftrace_event_call *call, |
723 | char *filter_string); | |
724 | extern int apply_subsystem_event_filter(struct event_subsystem *system, | |
725 | char *filter_string); | |
726 | extern void print_subsystem_event_filter(struct event_subsystem *system, | |
ac1adc55 | 727 | struct trace_seq *s); |
aa38e9fc | 728 | extern int filter_assign_type(const char *type); |
7ce7e424 | 729 | |
eb02ce01 | 730 | static inline int |
e1112b4d | 731 | filter_check_discard(struct ftrace_event_call *call, void *rec, |
eb02ce01 | 732 | struct ring_buffer *buffer, |
e1112b4d TZ |
733 | struct ring_buffer_event *event) |
734 | { | |
30e673b2 | 735 | if (unlikely(call->filter_active) && !filter_match_preds(call, rec)) { |
eb02ce01 TZ |
736 | ring_buffer_discard_commit(buffer, event); |
737 | return 1; | |
738 | } | |
739 | ||
740 | return 0; | |
e1112b4d TZ |
741 | } |
742 | ||
20c8928a | 743 | extern struct mutex event_mutex; |
a59fd602 | 744 | extern struct list_head ftrace_events; |
ac199db0 | 745 | |
e9fb2b6d SR |
746 | extern const char *__start___trace_bprintk_fmt[]; |
747 | extern const char *__stop___trace_bprintk_fmt[]; | |
748 | ||
e1112b4d TZ |
749 | #undef TRACE_EVENT_FORMAT |
750 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ | |
751 | extern struct ftrace_event_call event_##call; | |
e45f2e2b TZ |
752 | #undef TRACE_EVENT_FORMAT_NOFILTER |
753 | #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt) | |
e1112b4d TZ |
754 | #include "trace_event_types.h" |
755 | ||
bc0c38d1 | 756 | #endif /* _LINUX_KERNEL_TRACE_H */ |