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