]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - kernel/trace/trace.h
net: skb ftracer - Add actual ftrace code to kernel (v3)
[karo-tx-linux.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/ftrace.h>
11 #include <trace/boot.h>
12 #include <linux/kmemtrace.h>
13 #include <trace/power.h>
14 #include <trace/events/skb.h>
15
16 #include <linux/trace_seq.h>
17 #include <linux/ftrace_event.h>
18
19 enum trace_type {
20         __TRACE_FIRST_TYPE = 0,
21
22         TRACE_FN,
23         TRACE_CTX,
24         TRACE_WAKE,
25         TRACE_STACK,
26         TRACE_PRINT,
27         TRACE_BPRINT,
28         TRACE_SPECIAL,
29         TRACE_MMIO_RW,
30         TRACE_MMIO_MAP,
31         TRACE_BRANCH,
32         TRACE_BOOT_CALL,
33         TRACE_BOOT_RET,
34         TRACE_GRAPH_RET,
35         TRACE_GRAPH_ENT,
36         TRACE_USER_STACK,
37         TRACE_HW_BRANCHES,
38         TRACE_SYSCALL_ENTER,
39         TRACE_SYSCALL_EXIT,
40         TRACE_KMEM_ALLOC,
41         TRACE_KMEM_FREE,
42         TRACE_POWER,
43         TRACE_BLK,
44         TRACE_SKB_SOURCE,
45
46         __TRACE_LAST_TYPE,
47 };
48
49 /*
50  * Function trace entry - function address and parent function addres:
51  */
52 struct ftrace_entry {
53         struct trace_entry      ent;
54         unsigned long           ip;
55         unsigned long           parent_ip;
56 };
57
58 /* Function call entry */
59 struct ftrace_graph_ent_entry {
60         struct trace_entry              ent;
61         struct ftrace_graph_ent         graph_ent;
62 };
63
64 /* Function return entry */
65 struct ftrace_graph_ret_entry {
66         struct trace_entry              ent;
67         struct ftrace_graph_ret         ret;
68 };
69 extern struct tracer boot_tracer;
70
71 /*
72  * Context switch trace entry - which task (and prio) we switched from/to:
73  */
74 struct ctx_switch_entry {
75         struct trace_entry      ent;
76         unsigned int            prev_pid;
77         unsigned char           prev_prio;
78         unsigned char           prev_state;
79         unsigned int            next_pid;
80         unsigned char           next_prio;
81         unsigned char           next_state;
82         unsigned int            next_cpu;
83 };
84
85 /*
86  * Special (free-form) trace entry:
87  */
88 struct special_entry {
89         struct trace_entry      ent;
90         unsigned long           arg1;
91         unsigned long           arg2;
92         unsigned long           arg3;
93 };
94
95 /*
96  * Stack-trace entry:
97  */
98
99 #define FTRACE_STACK_ENTRIES    8
100
101 struct stack_entry {
102         struct trace_entry      ent;
103         unsigned long           caller[FTRACE_STACK_ENTRIES];
104 };
105
106 struct userstack_entry {
107         struct trace_entry      ent;
108         unsigned long           caller[FTRACE_STACK_ENTRIES];
109 };
110
111 /*
112  * trace_printk entry:
113  */
114 struct bprint_entry {
115         struct trace_entry      ent;
116         unsigned long           ip;
117         const char              *fmt;
118         u32                     buf[];
119 };
120
121 struct print_entry {
122         struct trace_entry      ent;
123         unsigned long           ip;
124         char                    buf[];
125 };
126
127 #define TRACE_OLD_SIZE          88
128
129 struct trace_field_cont {
130         unsigned char           type;
131         /* Temporary till we get rid of this completely */
132         char                    buf[TRACE_OLD_SIZE - 1];
133 };
134
135 struct trace_mmiotrace_rw {
136         struct trace_entry      ent;
137         struct mmiotrace_rw     rw;
138 };
139
140 struct trace_mmiotrace_map {
141         struct trace_entry      ent;
142         struct mmiotrace_map    map;
143 };
144
145 struct trace_boot_call {
146         struct trace_entry      ent;
147         struct boot_trace_call boot_call;
148 };
149
150 struct trace_boot_ret {
151         struct trace_entry      ent;
152         struct boot_trace_ret boot_ret;
153 };
154
155 #define TRACE_FUNC_SIZE 30
156 #define TRACE_FILE_SIZE 20
157 struct trace_branch {
158         struct trace_entry      ent;
159         unsigned                line;
160         char                    func[TRACE_FUNC_SIZE+1];
161         char                    file[TRACE_FILE_SIZE+1];
162         char                    correct;
163 };
164
165 struct hw_branch_entry {
166         struct trace_entry      ent;
167         u64                     from;
168         u64                     to;
169 };
170
171 struct trace_power {
172         struct trace_entry      ent;
173         struct power_trace      state_data;
174 };
175
176 struct skb_record {
177         pid_t pid;              /* pid of the copying process */
178         int anid;               /* node where skb was allocated */
179         int cnid;               /* node to which skb was copied in userspace */
180         char ifname[IFNAMSIZ];  /* Name of the receiving interface */
181         int rx_queue;           /* The rx queue the skb was received on */
182         int ccpu;               /* Cpu the application got this frame from */
183         int len;                /* length of the data copied */
184 };
185
186 struct trace_skb_event {
187         struct trace_entry      ent;
188         struct skb_record       event_data;
189 };
190
191 enum kmemtrace_type_id {
192         KMEMTRACE_TYPE_KMALLOC = 0,     /* kmalloc() or kfree(). */
193         KMEMTRACE_TYPE_CACHE,           /* kmem_cache_*(). */
194         KMEMTRACE_TYPE_PAGES,           /* __get_free_pages() and friends. */
195 };
196
197 struct kmemtrace_alloc_entry {
198         struct trace_entry      ent;
199         enum kmemtrace_type_id type_id;
200         unsigned long call_site;
201         const void *ptr;
202         size_t bytes_req;
203         size_t bytes_alloc;
204         gfp_t gfp_flags;
205         int node;
206 };
207
208 struct kmemtrace_free_entry {
209         struct trace_entry      ent;
210         enum kmemtrace_type_id type_id;
211         unsigned long call_site;
212         const void *ptr;
213 };
214
215 struct syscall_trace_enter {
216         struct trace_entry      ent;
217         int                     nr;
218         unsigned long           args[];
219 };
220
221 struct syscall_trace_exit {
222         struct trace_entry      ent;
223         int                     nr;
224         unsigned long           ret;
225 };
226
227
228 /*
229  * trace_flag_type is an enumeration that holds different
230  * states when a trace occurs. These are:
231  *  IRQS_OFF            - interrupts were disabled
232  *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
233  *  NEED_RESCED         - reschedule is requested
234  *  HARDIRQ             - inside an interrupt handler
235  *  SOFTIRQ             - inside a softirq handler
236  */
237 enum trace_flag_type {
238         TRACE_FLAG_IRQS_OFF             = 0x01,
239         TRACE_FLAG_IRQS_NOSUPPORT       = 0x02,
240         TRACE_FLAG_NEED_RESCHED         = 0x04,
241         TRACE_FLAG_HARDIRQ              = 0x08,
242         TRACE_FLAG_SOFTIRQ              = 0x10,
243 };
244
245 #define TRACE_BUF_SIZE          1024
246
247 /*
248  * The CPU trace array - it consists of thousands of trace entries
249  * plus some other descriptor data: (for example which task started
250  * the trace, etc.)
251  */
252 struct trace_array_cpu {
253         atomic_t                disabled;
254         void                    *buffer_page;   /* ring buffer spare */
255
256         /* these fields get copied into max-trace: */
257         unsigned long           trace_idx;
258         unsigned long           overrun;
259         unsigned long           saved_latency;
260         unsigned long           critical_start;
261         unsigned long           critical_end;
262         unsigned long           critical_sequence;
263         unsigned long           nice;
264         unsigned long           policy;
265         unsigned long           rt_priority;
266         cycle_t                 preempt_timestamp;
267         pid_t                   pid;
268         uid_t                   uid;
269         char                    comm[TASK_COMM_LEN];
270 };
271
272 /*
273  * The trace array - an array of per-CPU trace arrays. This is the
274  * highest level data structure that individual tracers deal with.
275  * They have on/off state as well:
276  */
277 struct trace_array {
278         struct ring_buffer      *buffer;
279         unsigned long           entries;
280         int                     cpu;
281         cycle_t                 time_start;
282         struct task_struct      *waiter;
283         struct trace_array_cpu  *data[NR_CPUS];
284 };
285
286 #define FTRACE_CMP_TYPE(var, type) \
287         __builtin_types_compatible_p(typeof(var), type *)
288
289 #undef IF_ASSIGN
290 #define IF_ASSIGN(var, entry, etype, id)                \
291         if (FTRACE_CMP_TYPE(var, etype)) {              \
292                 var = (typeof(var))(entry);             \
293                 WARN_ON(id && (entry)->type != id);     \
294                 break;                                  \
295         }
296
297 /* Will cause compile errors if type is not found. */
298 extern void __ftrace_bad_type(void);
299
300 /*
301  * The trace_assign_type is a verifier that the entry type is
302  * the same as the type being assigned. To add new types simply
303  * add a line with the following format:
304  *
305  * IF_ASSIGN(var, ent, type, id);
306  *
307  *  Where "type" is the trace type that includes the trace_entry
308  *  as the "ent" item. And "id" is the trace identifier that is
309  *  used in the trace_type enum.
310  *
311  *  If the type can have more than one id, then use zero.
312  */
313 #define trace_assign_type(var, ent)                                     \
314         do {                                                            \
315                 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN);     \
316                 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0);        \
317                 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK);   \
318                 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
319                 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT);   \
320                 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
321                 IF_ASSIGN(var, ent, struct special_entry, 0);           \
322                 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw,          \
323                           TRACE_MMIO_RW);                               \
324                 IF_ASSIGN(var, ent, struct trace_mmiotrace_map,         \
325                           TRACE_MMIO_MAP);                              \
326                 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
327                 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
328                 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
329                 IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry,      \
330                           TRACE_GRAPH_ENT);             \
331                 IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,      \
332                           TRACE_GRAPH_RET);             \
333                 IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
334                 IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
335                 IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry,       \
336                           TRACE_KMEM_ALLOC);    \
337                 IF_ASSIGN(var, ent, struct kmemtrace_free_entry,        \
338                           TRACE_KMEM_FREE);     \
339                 IF_ASSIGN(var, ent, struct syscall_trace_enter,         \
340                           TRACE_SYSCALL_ENTER);                         \
341                 IF_ASSIGN(var, ent, struct syscall_trace_exit,          \
342                           TRACE_SYSCALL_EXIT);                          \
343                 IF_ASSIGN(var, ent, struct trace_skb_event,             \
344                           TRACE_SKB_SOURCE);                            \
345                 __ftrace_bad_type();                                    \
346         } while (0)
347
348 /*
349  * An option specific to a tracer. This is a boolean value.
350  * The bit is the bit index that sets its value on the
351  * flags value in struct tracer_flags.
352  */
353 struct tracer_opt {
354         const char      *name; /* Will appear on the trace_options file */
355         u32             bit; /* Mask assigned in val field in tracer_flags */
356 };
357
358 /*
359  * The set of specific options for a tracer. Your tracer
360  * have to set the initial value of the flags val.
361  */
362 struct tracer_flags {
363         u32                     val;
364         struct tracer_opt       *opts;
365 };
366
367 /* Makes more easy to define a tracer opt */
368 #define TRACER_OPT(s, b)        .name = #s, .bit = b
369
370
371 /**
372  * struct tracer - a specific tracer and its callbacks to interact with debugfs
373  * @name: the name chosen to select it on the available_tracers file
374  * @init: called when one switches to this tracer (echo name > current_tracer)
375  * @reset: called when one switches to another tracer
376  * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
377  * @stop: called when tracing is paused (echo 0 > tracing_enabled)
378  * @open: called when the trace file is opened
379  * @pipe_open: called when the trace_pipe file is opened
380  * @wait_pipe: override how the user waits for traces on trace_pipe
381  * @close: called when the trace file is released
382  * @read: override the default read callback on trace_pipe
383  * @splice_read: override the default splice_read callback on trace_pipe
384  * @selftest: selftest to run on boot (see trace_selftest.c)
385  * @print_headers: override the first lines that describe your columns
386  * @print_line: callback that prints a trace
387  * @set_flag: signals one of your private flags changed (trace_options file)
388  * @flags: your private flags
389  */
390 struct tracer {
391         const char              *name;
392         int                     (*init)(struct trace_array *tr);
393         void                    (*reset)(struct trace_array *tr);
394         void                    (*start)(struct trace_array *tr);
395         void                    (*stop)(struct trace_array *tr);
396         void                    (*open)(struct trace_iterator *iter);
397         void                    (*pipe_open)(struct trace_iterator *iter);
398         void                    (*wait_pipe)(struct trace_iterator *iter);
399         void                    (*close)(struct trace_iterator *iter);
400         ssize_t                 (*read)(struct trace_iterator *iter,
401                                         struct file *filp, char __user *ubuf,
402                                         size_t cnt, loff_t *ppos);
403         ssize_t                 (*splice_read)(struct trace_iterator *iter,
404                                                struct file *filp,
405                                                loff_t *ppos,
406                                                struct pipe_inode_info *pipe,
407                                                size_t len,
408                                                unsigned int flags);
409 #ifdef CONFIG_FTRACE_STARTUP_TEST
410         int                     (*selftest)(struct tracer *trace,
411                                             struct trace_array *tr);
412 #endif
413         void                    (*print_header)(struct seq_file *m);
414         enum print_line_t       (*print_line)(struct trace_iterator *iter);
415         /* If you handled the flag setting, return 0 */
416         int                     (*set_flag)(u32 old_flags, u32 bit, int set);
417         struct tracer           *next;
418         int                     print_max;
419         struct tracer_flags     *flags;
420         struct tracer_stat      *stats;
421 };
422
423
424 #define TRACE_PIPE_ALL_CPU      -1
425
426 int tracer_init(struct tracer *t, struct trace_array *tr);
427 int tracing_is_enabled(void);
428 void trace_wake_up(void);
429 void tracing_reset(struct trace_array *tr, int cpu);
430 void tracing_reset_online_cpus(struct trace_array *tr);
431 void tracing_reset_current(int cpu);
432 void tracing_reset_current_online_cpus(void);
433 int tracing_open_generic(struct inode *inode, struct file *filp);
434 struct dentry *trace_create_file(const char *name,
435                                  mode_t mode,
436                                  struct dentry *parent,
437                                  void *data,
438                                  const struct file_operations *fops);
439
440 struct dentry *tracing_init_dentry(void);
441 void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
442
443 struct ring_buffer_event;
444
445 struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
446                                                     int type,
447                                                     unsigned long len,
448                                                     unsigned long flags,
449                                                     int pc);
450 void trace_buffer_unlock_commit(struct trace_array *tr,
451                                 struct ring_buffer_event *event,
452                                 unsigned long flags, int pc);
453
454 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
455                                                 struct trace_array_cpu *data);
456
457 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
458                                           int *ent_cpu, u64 *ent_ts);
459
460 void default_wait_pipe(struct trace_iterator *iter);
461 void poll_wait_pipe(struct trace_iterator *iter);
462
463 void ftrace(struct trace_array *tr,
464                             struct trace_array_cpu *data,
465                             unsigned long ip,
466                             unsigned long parent_ip,
467                             unsigned long flags, int pc);
468 void tracing_sched_switch_trace(struct trace_array *tr,
469                                 struct task_struct *prev,
470                                 struct task_struct *next,
471                                 unsigned long flags, int pc);
472
473 void tracing_sched_wakeup_trace(struct trace_array *tr,
474                                 struct task_struct *wakee,
475                                 struct task_struct *cur,
476                                 unsigned long flags, int pc);
477 void trace_special(struct trace_array *tr,
478                    struct trace_array_cpu *data,
479                    unsigned long arg1,
480                    unsigned long arg2,
481                    unsigned long arg3, int pc);
482 void trace_function(struct trace_array *tr,
483                     unsigned long ip,
484                     unsigned long parent_ip,
485                     unsigned long flags, int pc);
486
487 void trace_graph_return(struct ftrace_graph_ret *trace);
488 int trace_graph_entry(struct ftrace_graph_ent *trace);
489
490 void tracing_start_cmdline_record(void);
491 void tracing_stop_cmdline_record(void);
492 void tracing_sched_switch_assign_trace(struct trace_array *tr);
493 void tracing_stop_sched_switch_record(void);
494 void tracing_start_sched_switch_record(void);
495 int register_tracer(struct tracer *type);
496 void unregister_tracer(struct tracer *type);
497
498 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
499
500 extern unsigned long tracing_max_latency;
501 extern unsigned long tracing_thresh;
502
503 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
504 void update_max_tr_single(struct trace_array *tr,
505                           struct task_struct *tsk, int cpu);
506
507 void __trace_stack(struct trace_array *tr,
508                    unsigned long flags,
509                    int skip, int pc);
510
511 extern cycle_t ftrace_now(int cpu);
512
513 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
514 typedef void
515 (*tracer_switch_func_t)(void *private,
516                         void *__rq,
517                         struct task_struct *prev,
518                         struct task_struct *next);
519
520 struct tracer_switch_ops {
521         tracer_switch_func_t            func;
522         void                            *private;
523         struct tracer_switch_ops        *next;
524 };
525 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
526
527 extern void trace_find_cmdline(int pid, char comm[]);
528
529 #ifdef CONFIG_DYNAMIC_FTRACE
530 extern unsigned long ftrace_update_tot_cnt;
531 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
532 extern int DYN_FTRACE_TEST_NAME(void);
533 #endif
534
535 #ifdef CONFIG_FTRACE_STARTUP_TEST
536 extern int trace_selftest_startup_function(struct tracer *trace,
537                                            struct trace_array *tr);
538 extern int trace_selftest_startup_function_graph(struct tracer *trace,
539                                                  struct trace_array *tr);
540 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
541                                           struct trace_array *tr);
542 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
543                                              struct trace_array *tr);
544 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
545                                                  struct trace_array *tr);
546 extern int trace_selftest_startup_wakeup(struct tracer *trace,
547                                          struct trace_array *tr);
548 extern int trace_selftest_startup_nop(struct tracer *trace,
549                                          struct trace_array *tr);
550 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
551                                                struct trace_array *tr);
552 extern int trace_selftest_startup_sysprof(struct tracer *trace,
553                                                struct trace_array *tr);
554 extern int trace_selftest_startup_branch(struct tracer *trace,
555                                          struct trace_array *tr);
556 extern int trace_selftest_startup_hw_branches(struct tracer *trace,
557                                               struct trace_array *tr);
558 #endif /* CONFIG_FTRACE_STARTUP_TEST */
559
560 extern void *head_page(struct trace_array_cpu *data);
561 extern unsigned long long ns2usecs(cycle_t nsec);
562 extern int
563 trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
564 extern int
565 trace_vprintk(unsigned long ip, const char *fmt, va_list args);
566
567 extern unsigned long trace_flags;
568
569 /* Standard output formatting function used for function return traces */
570 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
571 extern enum print_line_t print_graph_function(struct trace_iterator *iter);
572 extern enum print_line_t
573 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
574
575 #ifdef CONFIG_DYNAMIC_FTRACE
576 /* TODO: make this variable */
577 #define FTRACE_GRAPH_MAX_FUNCS          32
578 extern int ftrace_graph_count;
579 extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
580
581 static inline int ftrace_graph_addr(unsigned long addr)
582 {
583         int i;
584
585         if (!ftrace_graph_count || test_tsk_trace_graph(current))
586                 return 1;
587
588         for (i = 0; i < ftrace_graph_count; i++) {
589                 if (addr == ftrace_graph_funcs[i])
590                         return 1;
591         }
592
593         return 0;
594 }
595 #else
596 static inline int ftrace_trace_addr(unsigned long addr)
597 {
598         return 1;
599 }
600 static inline int ftrace_graph_addr(unsigned long addr)
601 {
602         return 1;
603 }
604 #endif /* CONFIG_DYNAMIC_FTRACE */
605 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
606 static inline enum print_line_t
607 print_graph_function(struct trace_iterator *iter)
608 {
609         return TRACE_TYPE_UNHANDLED;
610 }
611 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
612
613 extern struct pid *ftrace_pid_trace;
614
615 #ifdef CONFIG_FUNCTION_TRACER
616 static inline int ftrace_trace_task(struct task_struct *task)
617 {
618         if (!ftrace_pid_trace)
619                 return 1;
620
621         return test_tsk_trace_trace(task);
622 }
623 #else
624 static inline int ftrace_trace_task(struct task_struct *task)
625 {
626         return 1;
627 }
628 #endif
629
630 /*
631  * trace_iterator_flags is an enumeration that defines bit
632  * positions into trace_flags that controls the output.
633  *
634  * NOTE: These bits must match the trace_options array in
635  *       trace.c.
636  */
637 enum trace_iterator_flags {
638         TRACE_ITER_PRINT_PARENT         = 0x01,
639         TRACE_ITER_SYM_OFFSET           = 0x02,
640         TRACE_ITER_SYM_ADDR             = 0x04,
641         TRACE_ITER_VERBOSE              = 0x08,
642         TRACE_ITER_RAW                  = 0x10,
643         TRACE_ITER_HEX                  = 0x20,
644         TRACE_ITER_BIN                  = 0x40,
645         TRACE_ITER_BLOCK                = 0x80,
646         TRACE_ITER_STACKTRACE           = 0x100,
647         TRACE_ITER_SCHED_TREE           = 0x200,
648         TRACE_ITER_PRINTK               = 0x400,
649         TRACE_ITER_PREEMPTONLY          = 0x800,
650         TRACE_ITER_BRANCH               = 0x1000,
651         TRACE_ITER_ANNOTATE             = 0x2000,
652         TRACE_ITER_USERSTACKTRACE       = 0x4000,
653         TRACE_ITER_SYM_USEROBJ          = 0x8000,
654         TRACE_ITER_PRINTK_MSGONLY       = 0x10000,
655         TRACE_ITER_CONTEXT_INFO         = 0x20000, /* Print pid/cpu/time */
656         TRACE_ITER_LATENCY_FMT          = 0x40000,
657         TRACE_ITER_GLOBAL_CLK           = 0x80000,
658         TRACE_ITER_SLEEP_TIME           = 0x100000,
659         TRACE_ITER_GRAPH_TIME           = 0x200000,
660 };
661
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
669 extern struct tracer nop_trace;
670
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  *
680  * To prevent this, we read the need_resched flag before
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  *
685  * The rational for doing the above is that if need_resched is set
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.
706  * If resched is set, then we are either inside an atomic or
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
719 #ifdef CONFIG_BRANCH_TRACER
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)
723 {
724         if (trace_flags & TRACE_ITER_BRANCH)
725                 return enable_branch_tracing(tr);
726         return 0;
727 }
728 static inline void trace_branch_disable(void)
729 {
730         /* due to races, always disable */
731         disable_branch_tracing();
732 }
733 #else
734 static inline int trace_branch_enable(struct trace_array *tr)
735 {
736         return 0;
737 }
738 static inline void trace_branch_disable(void)
739 {
740 }
741 #endif /* CONFIG_BRANCH_TRACER */
742
743 /* set ring buffers to default size if not already done so */
744 int tracing_update_buffers(void);
745
746 /* trace event type bit fields, not numeric */
747 enum {
748         TRACE_EVENT_TYPE_PRINTF         = 1,
749         TRACE_EVENT_TYPE_RAW            = 2,
750 };
751
752 struct ftrace_event_field {
753         struct list_head        link;
754         char                    *name;
755         char                    *type;
756         int                     offset;
757         int                     size;
758         int                     is_signed;
759 };
760
761 struct event_filter {
762         int                     n_preds;
763         struct filter_pred      **preds;
764         char                    *filter_string;
765 };
766
767 struct event_subsystem {
768         struct list_head        list;
769         const char              *name;
770         struct dentry           *entry;
771         void                    *filter;
772 };
773
774 struct filter_pred;
775
776 typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
777                                  int val1, int val2);
778
779 struct filter_pred {
780         filter_pred_fn_t fn;
781         u64 val;
782         char str_val[MAX_FILTER_STR_VAL];
783         int str_len;
784         char *field_name;
785         int offset;
786         int not;
787         int op;
788         int pop_n;
789 };
790
791 extern void print_event_filter(struct ftrace_event_call *call,
792                                struct trace_seq *s);
793 extern int apply_event_filter(struct ftrace_event_call *call,
794                               char *filter_string);
795 extern int apply_subsystem_event_filter(struct event_subsystem *system,
796                                         char *filter_string);
797 extern void print_subsystem_event_filter(struct event_subsystem *system,
798                                          struct trace_seq *s);
799
800 static inline int
801 filter_check_discard(struct ftrace_event_call *call, void *rec,
802                      struct ring_buffer *buffer,
803                      struct ring_buffer_event *event)
804 {
805         if (unlikely(call->filter_active) && !filter_match_preds(call, rec)) {
806                 ring_buffer_discard_commit(buffer, event);
807                 return 1;
808         }
809
810         return 0;
811 }
812
813 #define DEFINE_COMPARISON_PRED(type)                                    \
814 static int filter_pred_##type(struct filter_pred *pred, void *event,    \
815                               int val1, int val2)                       \
816 {                                                                       \
817         type *addr = (type *)(event + pred->offset);                    \
818         type val = (type)pred->val;                                     \
819         int match = 0;                                                  \
820                                                                         \
821         switch (pred->op) {                                             \
822         case OP_LT:                                                     \
823                 match = (*addr < val);                                  \
824                 break;                                                  \
825         case OP_LE:                                                     \
826                 match = (*addr <= val);                                 \
827                 break;                                                  \
828         case OP_GT:                                                     \
829                 match = (*addr > val);                                  \
830                 break;                                                  \
831         case OP_GE:                                                     \
832                 match = (*addr >= val);                                 \
833                 break;                                                  \
834         default:                                                        \
835                 break;                                                  \
836         }                                                               \
837                                                                         \
838         return match;                                                   \
839 }
840
841 #define DEFINE_EQUALITY_PRED(size)                                      \
842 static int filter_pred_##size(struct filter_pred *pred, void *event,    \
843                               int val1, int val2)                       \
844 {                                                                       \
845         u##size *addr = (u##size *)(event + pred->offset);              \
846         u##size val = (u##size)pred->val;                               \
847         int match;                                                      \
848                                                                         \
849         match = (val == *addr) ^ pred->not;                             \
850                                                                         \
851         return match;                                                   \
852 }
853
854 extern struct mutex event_mutex;
855 extern struct list_head ftrace_events;
856
857 extern const char *__start___trace_bprintk_fmt[];
858 extern const char *__stop___trace_bprintk_fmt[];
859
860 #undef TRACE_EVENT_FORMAT
861 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt)      \
862         extern struct ftrace_event_call event_##call;
863 #undef TRACE_EVENT_FORMAT_NOFILTER
864 #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt)
865 #include "trace_event_types.h"
866
867 #endif /* _LINUX_KERNEL_TRACE_H */