tracing/filters: Refactor subsystem filter code
[linux-2.6.git] / kernel / trace / trace.h
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>
8 #include <linux/ring_buffer.h>
9 #include <linux/mmiotrace.h>
10 #include <linux/tracepoint.h>
11 #include <linux/ftrace.h>
12 #include <trace/boot.h>
13 #include <linux/kmemtrace.h>
14
15 #include <linux/trace_seq.h>
16 #include <linux/ftrace_event.h>
17
18 enum trace_type {
19         __TRACE_FIRST_TYPE = 0,
20
21         TRACE_FN,
22         TRACE_CTX,
23         TRACE_WAKE,
24         TRACE_STACK,
25         TRACE_PRINT,
26         TRACE_BPRINT,
27         TRACE_SPECIAL,
28         TRACE_MMIO_RW,
29         TRACE_MMIO_MAP,
30         TRACE_BRANCH,
31         TRACE_BOOT_CALL,
32         TRACE_BOOT_RET,
33         TRACE_GRAPH_RET,
34         TRACE_GRAPH_ENT,
35         TRACE_USER_STACK,
36         TRACE_HW_BRANCHES,
37         TRACE_KMEM_ALLOC,
38         TRACE_KMEM_FREE,
39         TRACE_BLK,
40
41         __TRACE_LAST_TYPE,
42 };
43
44 enum 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. */
48 };
49
50 extern struct tracer boot_tracer;
51
52 #undef __field
53 #define __field(type, item)             type    item;
54
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
61 #undef __array
62 #define __array(type, item, size)       type    item[size];
63
64 #undef __array_desc
65 #define __array_desc(type, container, item, size)
66
67 #undef __dynamic_array
68 #define __dynamic_array(type, item)     type    item[];
69
70 #undef F_STRUCT
71 #define F_STRUCT(args...)               args
72
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         }
79
80 #undef TP_ARGS
81 #define TP_ARGS(args...)        args
82
83 #undef FTRACE_ENTRY_DUP
84 #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk)
85
86 #include "trace_entries.h"
87
88 /*
89  * syscalls are special, and need special handling, this is why
90  * they are not included in trace_entries.h
91  */
92 struct syscall_trace_enter {
93         struct trace_entry      ent;
94         int                     nr;
95         unsigned long           args[];
96 };
97
98 struct syscall_trace_exit {
99         struct trace_entry      ent;
100         int                     nr;
101         unsigned long           ret;
102 };
103
104 /*
105  * trace_flag_type is an enumeration that holds different
106  * states when a trace occurs. These are:
107  *  IRQS_OFF            - interrupts were disabled
108  *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
109  *  NEED_RESCHED        - reschedule is requested
110  *  HARDIRQ             - inside an interrupt handler
111  *  SOFTIRQ             - inside a softirq handler
112  */
113 enum trace_flag_type {
114         TRACE_FLAG_IRQS_OFF             = 0x01,
115         TRACE_FLAG_IRQS_NOSUPPORT       = 0x02,
116         TRACE_FLAG_NEED_RESCHED         = 0x04,
117         TRACE_FLAG_HARDIRQ              = 0x08,
118         TRACE_FLAG_SOFTIRQ              = 0x10,
119 };
120
121 #define TRACE_BUF_SIZE          1024
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  */
128 struct trace_array_cpu {
129         atomic_t                disabled;
130         void                    *buffer_page;   /* ring buffer spare */
131
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;
139         unsigned long           skipped_entries;
140         cycle_t                 preempt_timestamp;
141         pid_t                   pid;
142         uid_t                   uid;
143         char                    comm[TASK_COMM_LEN];
144 };
145
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  */
151 struct trace_array {
152         struct ring_buffer      *buffer;
153         unsigned long           entries;
154         int                     cpu;
155         cycle_t                 time_start;
156         struct task_struct      *waiter;
157         struct trace_array_cpu  *data[NR_CPUS];
158 };
159
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. */
172 extern 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);        \
191                 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK);   \
192                 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
193                 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT);   \
194                 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
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);                              \
200                 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
201                 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
202                 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
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);             \
207                 IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
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);     \
212                 __ftrace_bad_type();                                    \
213         } while (0)
214
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  */
220 struct tracer_opt {
221         const char      *name; /* Will appear on the trace_options file */
222         u32             bit; /* Mask assigned in val field in tracer_flags */
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  */
229 struct tracer_flags {
230         u32                     val;
231         struct tracer_opt       *opts;
232 };
233
234 /* Makes more easy to define a tracer opt */
235 #define TRACER_OPT(s, b)        .name = #s, .bit = b
236
237
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
256  */
257 struct tracer {
258         const char              *name;
259         int                     (*init)(struct trace_array *tr);
260         void                    (*reset)(struct trace_array *tr);
261         void                    (*start)(struct trace_array *tr);
262         void                    (*stop)(struct trace_array *tr);
263         void                    (*open)(struct trace_iterator *iter);
264         void                    (*pipe_open)(struct trace_iterator *iter);
265         void                    (*wait_pipe)(struct trace_iterator *iter);
266         void                    (*close)(struct trace_iterator *iter);
267         ssize_t                 (*read)(struct trace_iterator *iter,
268                                         struct file *filp, char __user *ubuf,
269                                         size_t cnt, loff_t *ppos);
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);
276 #ifdef CONFIG_FTRACE_STARTUP_TEST
277         int                     (*selftest)(struct tracer *trace,
278                                             struct trace_array *tr);
279 #endif
280         void                    (*print_header)(struct seq_file *m);
281         enum print_line_t       (*print_line)(struct trace_iterator *iter);
282         /* If you handled the flag setting, return 0 */
283         int                     (*set_flag)(u32 old_flags, u32 bit, int set);
284         struct tracer           *next;
285         int                     print_max;
286         struct tracer_flags     *flags;
287 };
288
289
290 #define TRACE_PIPE_ALL_CPU      -1
291
292 int tracer_init(struct tracer *t, struct trace_array *tr);
293 int tracing_is_enabled(void);
294 void trace_wake_up(void);
295 void tracing_reset(struct trace_array *tr, int cpu);
296 void tracing_reset_online_cpus(struct trace_array *tr);
297 void tracing_reset_current(int cpu);
298 void tracing_reset_current_online_cpus(void);
299 int tracing_open_generic(struct inode *inode, struct file *filp);
300 struct 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
306 struct dentry *tracing_init_dentry(void);
307 void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
308
309 struct ring_buffer_event;
310
311 struct ring_buffer_event *
312 trace_buffer_lock_reserve(struct ring_buffer *buffer,
313                           int type,
314                           unsigned long len,
315                           unsigned long flags,
316                           int pc);
317 void trace_buffer_unlock_commit(struct ring_buffer *buffer,
318                                 struct ring_buffer_event *event,
319                                 unsigned long flags, int pc);
320
321 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
322                                                 struct trace_array_cpu *data);
323
324 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
325                                           int *ent_cpu, u64 *ent_ts);
326
327 void default_wait_pipe(struct trace_iterator *iter);
328 void poll_wait_pipe(struct trace_iterator *iter);
329
330 void ftrace(struct trace_array *tr,
331                             struct trace_array_cpu *data,
332                             unsigned long ip,
333                             unsigned long parent_ip,
334                             unsigned long flags, int pc);
335 void tracing_sched_switch_trace(struct trace_array *tr,
336                                 struct task_struct *prev,
337                                 struct task_struct *next,
338                                 unsigned long flags, int pc);
339
340 void tracing_sched_wakeup_trace(struct trace_array *tr,
341                                 struct task_struct *wakee,
342                                 struct task_struct *cur,
343                                 unsigned long flags, int pc);
344 void trace_special(struct trace_array *tr,
345                    struct trace_array_cpu *data,
346                    unsigned long arg1,
347                    unsigned long arg2,
348                    unsigned long arg3, int pc);
349 void trace_function(struct trace_array *tr,
350                     unsigned long ip,
351                     unsigned long parent_ip,
352                     unsigned long flags, int pc);
353
354 void trace_graph_return(struct ftrace_graph_ret *trace);
355 int trace_graph_entry(struct ftrace_graph_ent *trace);
356 void set_graph_array(struct trace_array *tr);
357
358 void tracing_start_cmdline_record(void);
359 void tracing_stop_cmdline_record(void);
360 void tracing_sched_switch_assign_trace(struct trace_array *tr);
361 void tracing_stop_sched_switch_record(void);
362 void tracing_start_sched_switch_record(void);
363 int register_tracer(struct tracer *type);
364 void unregister_tracer(struct tracer *type);
365 int is_tracing_stopped(void);
366
367 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
368
369 #ifdef CONFIG_TRACER_MAX_TRACE
370 extern unsigned long tracing_max_latency;
371 extern unsigned long tracing_thresh;
372
373 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
374 void update_max_tr_single(struct trace_array *tr,
375                           struct task_struct *tsk, int cpu);
376 #endif /* CONFIG_TRACER_MAX_TRACE */
377
378 #ifdef CONFIG_STACKTRACE
379 void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
380                         int skip, int pc);
381
382 void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
383                             int pc);
384
385 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
386                    int pc);
387 #else
388 static inline void ftrace_trace_stack(struct trace_array *tr,
389                                       unsigned long flags, int skip, int pc)
390 {
391 }
392
393 static inline void ftrace_trace_userstack(struct trace_array *tr,
394                                           unsigned long flags, int pc)
395 {
396 }
397
398 static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
399                                  int skip, int pc)
400 {
401 }
402 #endif /* CONFIG_STACKTRACE */
403
404 extern cycle_t ftrace_now(int cpu);
405
406 extern void trace_find_cmdline(int pid, char comm[]);
407
408 #ifdef CONFIG_DYNAMIC_FTRACE
409 extern unsigned long ftrace_update_tot_cnt;
410 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
411 extern int DYN_FTRACE_TEST_NAME(void);
412 #endif
413
414 extern int ring_buffer_expanded;
415 extern bool tracing_selftest_disabled;
416 DECLARE_PER_CPU(local_t, ftrace_cpu_disabled);
417
418 #ifdef CONFIG_FTRACE_STARTUP_TEST
419 extern int trace_selftest_startup_function(struct tracer *trace,
420                                            struct trace_array *tr);
421 extern int trace_selftest_startup_function_graph(struct tracer *trace,
422                                                  struct trace_array *tr);
423 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
424                                           struct trace_array *tr);
425 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
426                                              struct trace_array *tr);
427 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
428                                                  struct trace_array *tr);
429 extern int trace_selftest_startup_wakeup(struct tracer *trace,
430                                          struct trace_array *tr);
431 extern int trace_selftest_startup_nop(struct tracer *trace,
432                                          struct trace_array *tr);
433 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
434                                                struct trace_array *tr);
435 extern int trace_selftest_startup_sysprof(struct tracer *trace,
436                                                struct trace_array *tr);
437 extern int trace_selftest_startup_branch(struct tracer *trace,
438                                          struct trace_array *tr);
439 extern int trace_selftest_startup_hw_branches(struct tracer *trace,
440                                               struct trace_array *tr);
441 #endif /* CONFIG_FTRACE_STARTUP_TEST */
442
443 extern void *head_page(struct trace_array_cpu *data);
444 extern unsigned long long ns2usecs(cycle_t nsec);
445 extern int
446 trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
447 extern int
448 trace_vprintk(unsigned long ip, const char *fmt, va_list args);
449 extern int
450 trace_array_vprintk(struct trace_array *tr,
451                     unsigned long ip, const char *fmt, va_list args);
452 int trace_array_printk(struct trace_array *tr,
453                        unsigned long ip, const char *fmt, ...);
454
455 extern unsigned long trace_flags;
456
457 extern int trace_clock_id;
458
459 /* Standard output formatting function used for function return traces */
460 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
461 extern enum print_line_t print_graph_function(struct trace_iterator *iter);
462 extern enum print_line_t
463 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
464
465 #ifdef CONFIG_DYNAMIC_FTRACE
466 /* TODO: make this variable */
467 #define FTRACE_GRAPH_MAX_FUNCS          32
468 extern int ftrace_graph_count;
469 extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
470
471 static 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 }
485 #else
486 static inline int ftrace_graph_addr(unsigned long addr)
487 {
488         return 1;
489 }
490 #endif /* CONFIG_DYNAMIC_FTRACE */
491 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
492 static inline enum print_line_t
493 print_graph_function(struct trace_iterator *iter)
494 {
495         return TRACE_TYPE_UNHANDLED;
496 }
497 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
498
499 extern struct list_head ftrace_pids;
500
501 #ifdef CONFIG_FUNCTION_TRACER
502 static inline int ftrace_trace_task(struct task_struct *task)
503 {
504         if (list_empty(&ftrace_pids))
505                 return 1;
506
507         return test_tsk_trace_trace(task);
508 }
509 #else
510 static inline int ftrace_trace_task(struct task_struct *task)
511 {
512         return 1;
513 }
514 #endif
515
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  */
523 struct trace_parser {
524         bool            cont;
525         char            *buffer;
526         unsigned        idx;
527         unsigned        size;
528 };
529
530 static inline bool trace_parser_loaded(struct trace_parser *parser)
531 {
532         return (parser->idx != 0);
533 }
534
535 static inline bool trace_parser_cont(struct trace_parser *parser)
536 {
537         return parser->cont;
538 }
539
540 static inline void trace_parser_clear(struct trace_parser *parser)
541 {
542         parser->cont = false;
543         parser->idx = 0;
544 }
545
546 extern int trace_parser_get_init(struct trace_parser *parser, int size);
547 extern void trace_parser_put(struct trace_parser *parser);
548 extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
549         size_t cnt, loff_t *ppos);
550
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  */
558 enum 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,
568         TRACE_ITER_SCHED_TREE           = 0x200,
569         TRACE_ITER_PRINTK               = 0x400,
570         TRACE_ITER_PREEMPTONLY          = 0x800,
571         TRACE_ITER_BRANCH               = 0x1000,
572         TRACE_ITER_ANNOTATE             = 0x2000,
573         TRACE_ITER_USERSTACKTRACE       = 0x4000,
574         TRACE_ITER_SYM_USEROBJ          = 0x8000,
575         TRACE_ITER_PRINTK_MSGONLY       = 0x10000,
576         TRACE_ITER_CONTEXT_INFO         = 0x20000, /* Print pid/cpu/time */
577         TRACE_ITER_LATENCY_FMT          = 0x40000,
578         TRACE_ITER_SLEEP_TIME           = 0x80000,
579         TRACE_ITER_GRAPH_TIME           = 0x100000,
580 };
581
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
589 extern struct tracer nop_trace;
590
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  *
600  * To prevent this, we read the need_resched flag before
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  *
605  * The rational for doing the above is that if need_resched is set
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  */
610 static 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.
626  * If resched is set, then we are either inside an atomic or
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  */
631 static 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
639 #ifdef CONFIG_BRANCH_TRACER
640 extern int enable_branch_tracing(struct trace_array *tr);
641 extern void disable_branch_tracing(void);
642 static inline int trace_branch_enable(struct trace_array *tr)
643 {
644         if (trace_flags & TRACE_ITER_BRANCH)
645                 return enable_branch_tracing(tr);
646         return 0;
647 }
648 static inline void trace_branch_disable(void)
649 {
650         /* due to races, always disable */
651         disable_branch_tracing();
652 }
653 #else
654 static inline int trace_branch_enable(struct trace_array *tr)
655 {
656         return 0;
657 }
658 static inline void trace_branch_disable(void)
659 {
660 }
661 #endif /* CONFIG_BRANCH_TRACER */
662
663 /* set ring buffers to default size if not already done so */
664 int tracing_update_buffers(void);
665
666 /* trace event type bit fields, not numeric */
667 enum {
668         TRACE_EVENT_TYPE_PRINTF         = 1,
669         TRACE_EVENT_TYPE_RAW            = 2,
670 };
671
672 struct ftrace_event_field {
673         struct list_head        link;
674         char                    *name;
675         char                    *type;
676         int                     filter_type;
677         int                     offset;
678         int                     size;
679         int                     is_signed;
680 };
681
682 struct event_filter {
683         int                     n_preds;
684         struct filter_pred      **preds;
685         char                    *filter_string;
686 };
687
688 struct event_subsystem {
689         struct list_head        list;
690         const char              *name;
691         struct dentry           *entry;
692         struct event_filter     *filter;
693         int                     nr_events;
694 };
695
696 struct filter_pred;
697 struct regex;
698
699 typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
700                                  int val1, int val2);
701
702 typedef int (*regex_match_func)(char *str, struct regex *r, int len);
703
704 enum regex_type {
705         MATCH_FULL,
706         MATCH_FRONT_ONLY,
707         MATCH_MIDDLE_ONLY,
708         MATCH_END_ONLY,
709 };
710
711 struct regex {
712         char                    pattern[MAX_FILTER_STR_VAL];
713         int                     len;
714         int                     field_len;
715         regex_match_func        match;
716 };
717
718 struct filter_pred {
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;
727 };
728
729 extern enum regex_type
730 filter_parse_regex(char *buff, int len, char **search, int *not);
731 extern void print_event_filter(struct ftrace_event_call *call,
732                                struct trace_seq *s);
733 extern int apply_event_filter(struct ftrace_event_call *call,
734                               char *filter_string);
735 extern int apply_subsystem_event_filter(struct event_subsystem *system,
736                                         char *filter_string);
737 extern void print_subsystem_event_filter(struct event_subsystem *system,
738                                          struct trace_seq *s);
739 extern int filter_assign_type(const char *type);
740
741 static inline int
742 filter_check_discard(struct ftrace_event_call *call, void *rec,
743                      struct ring_buffer *buffer,
744                      struct ring_buffer_event *event)
745 {
746         if (unlikely(call->filter_active) && !filter_match_preds(call, rec)) {
747                 ring_buffer_discard_commit(buffer, event);
748                 return 1;
749         }
750
751         return 0;
752 }
753
754 extern struct mutex event_mutex;
755 extern struct list_head ftrace_events;
756
757 extern const char *__start___trace_bprintk_fmt[];
758 extern const char *__stop___trace_bprintk_fmt[];
759
760 #undef FTRACE_ENTRY
761 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print)             \
762         extern struct ftrace_event_call event_##call;
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"
767
768 #endif /* _LINUX_KERNEL_TRACE_H */