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