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