18ceab59a5bae9e23d6acce3c5622b930e2b69f8
[platform/kernel/linux-starfive.git] / kernel / trace / trace.h
1 // SPDX-License-Identifier: GPL-2.0
2
3 #ifndef _LINUX_KERNEL_TRACE_H
4 #define _LINUX_KERNEL_TRACE_H
5
6 #include <linux/fs.h>
7 #include <linux/atomic.h>
8 #include <linux/sched.h>
9 #include <linux/clocksource.h>
10 #include <linux/ring_buffer.h>
11 #include <linux/mmiotrace.h>
12 #include <linux/tracepoint.h>
13 #include <linux/ftrace.h>
14 #include <linux/trace.h>
15 #include <linux/hw_breakpoint.h>
16 #include <linux/trace_seq.h>
17 #include <linux/trace_events.h>
18 #include <linux/compiler.h>
19 #include <linux/glob.h>
20 #include <linux/irq_work.h>
21 #include <linux/workqueue.h>
22
23 #ifdef CONFIG_FTRACE_SYSCALLS
24 #include <asm/unistd.h>         /* For NR_SYSCALLS           */
25 #include <asm/syscall.h>        /* some archs define it here */
26 #endif
27
28 enum trace_type {
29         __TRACE_FIRST_TYPE = 0,
30
31         TRACE_FN,
32         TRACE_CTX,
33         TRACE_WAKE,
34         TRACE_STACK,
35         TRACE_PRINT,
36         TRACE_BPRINT,
37         TRACE_MMIO_RW,
38         TRACE_MMIO_MAP,
39         TRACE_BRANCH,
40         TRACE_GRAPH_RET,
41         TRACE_GRAPH_ENT,
42         TRACE_USER_STACK,
43         TRACE_BLK,
44         TRACE_BPUTS,
45         TRACE_HWLAT,
46         TRACE_RAW_DATA,
47
48         __TRACE_LAST_TYPE,
49 };
50
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, filter)     \
75         struct struct_name {                                            \
76                 struct trace_entry      ent;                            \
77                 tstruct                                                 \
78         }
79
80 #undef FTRACE_ENTRY_DUP
81 #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter)
82
83 #undef FTRACE_ENTRY_REG
84 #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
85                          filter, regfn) \
86         FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
87                      filter)
88
89 #undef FTRACE_ENTRY_PACKED
90 #define FTRACE_ENTRY_PACKED(name, struct_name, id, tstruct, print,      \
91                             filter)                                     \
92         FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
93                      filter) __packed
94
95 #include "trace_entries.h"
96
97 /* Use this for memory failure errors */
98 #define MEM_FAIL(condition, fmt, ...) ({                        \
99         static bool __section(.data.once) __warned;             \
100         int __ret_warn_once = !!(condition);                    \
101                                                                 \
102         if (unlikely(__ret_warn_once && !__warned)) {           \
103                 __warned = true;                                \
104                 pr_err("ERROR: " fmt, ##__VA_ARGS__);           \
105         }                                                       \
106         unlikely(__ret_warn_once);                              \
107 })
108
109 /*
110  * syscalls are special, and need special handling, this is why
111  * they are not included in trace_entries.h
112  */
113 struct syscall_trace_enter {
114         struct trace_entry      ent;
115         int                     nr;
116         unsigned long           args[];
117 };
118
119 struct syscall_trace_exit {
120         struct trace_entry      ent;
121         int                     nr;
122         long                    ret;
123 };
124
125 struct kprobe_trace_entry_head {
126         struct trace_entry      ent;
127         unsigned long           ip;
128 };
129
130 struct kretprobe_trace_entry_head {
131         struct trace_entry      ent;
132         unsigned long           func;
133         unsigned long           ret_ip;
134 };
135
136 /*
137  * trace_flag_type is an enumeration that holds different
138  * states when a trace occurs. These are:
139  *  IRQS_OFF            - interrupts were disabled
140  *  IRQS_NOSUPPORT      - arch does not support irqs_disabled_flags
141  *  NEED_RESCHED        - reschedule is requested
142  *  HARDIRQ             - inside an interrupt handler
143  *  SOFTIRQ             - inside a softirq handler
144  */
145 enum trace_flag_type {
146         TRACE_FLAG_IRQS_OFF             = 0x01,
147         TRACE_FLAG_IRQS_NOSUPPORT       = 0x02,
148         TRACE_FLAG_NEED_RESCHED         = 0x04,
149         TRACE_FLAG_HARDIRQ              = 0x08,
150         TRACE_FLAG_SOFTIRQ              = 0x10,
151         TRACE_FLAG_PREEMPT_RESCHED      = 0x20,
152         TRACE_FLAG_NMI                  = 0x40,
153 };
154
155 #define TRACE_BUF_SIZE          1024
156
157 struct trace_array;
158
159 /*
160  * The CPU trace array - it consists of thousands of trace entries
161  * plus some other descriptor data: (for example which task started
162  * the trace, etc.)
163  */
164 struct trace_array_cpu {
165         atomic_t                disabled;
166         void                    *buffer_page;   /* ring buffer spare */
167
168         unsigned long           entries;
169         unsigned long           saved_latency;
170         unsigned long           critical_start;
171         unsigned long           critical_end;
172         unsigned long           critical_sequence;
173         unsigned long           nice;
174         unsigned long           policy;
175         unsigned long           rt_priority;
176         unsigned long           skipped_entries;
177         u64                     preempt_timestamp;
178         pid_t                   pid;
179         kuid_t                  uid;
180         char                    comm[TASK_COMM_LEN];
181
182         bool                    ignore_pid;
183 #ifdef CONFIG_FUNCTION_TRACER
184         bool                    ftrace_ignore_pid;
185 #endif
186 };
187
188 struct tracer;
189 struct trace_option_dentry;
190
191 struct array_buffer {
192         struct trace_array              *tr;
193         struct trace_buffer             *buffer;
194         struct trace_array_cpu __percpu *data;
195         u64                             time_start;
196         int                             cpu;
197 };
198
199 #define TRACE_FLAGS_MAX_SIZE            32
200
201 struct trace_options {
202         struct tracer                   *tracer;
203         struct trace_option_dentry      *topts;
204 };
205
206 struct trace_pid_list {
207         int                             pid_max;
208         unsigned long                   *pids;
209 };
210
211 typedef bool (*cond_update_fn_t)(struct trace_array *tr, void *cond_data);
212
213 /**
214  * struct cond_snapshot - conditional snapshot data and callback
215  *
216  * The cond_snapshot structure encapsulates a callback function and
217  * data associated with the snapshot for a given tracing instance.
218  *
219  * When a snapshot is taken conditionally, by invoking
220  * tracing_snapshot_cond(tr, cond_data), the cond_data passed in is
221  * passed in turn to the cond_snapshot.update() function.  That data
222  * can be compared by the update() implementation with the cond_data
223  * contained wihin the struct cond_snapshot instance associated with
224  * the trace_array.  Because the tr->max_lock is held throughout the
225  * update() call, the update() function can directly retrieve the
226  * cond_snapshot and cond_data associated with the per-instance
227  * snapshot associated with the trace_array.
228  *
229  * The cond_snapshot.update() implementation can save data to be
230  * associated with the snapshot if it decides to, and returns 'true'
231  * in that case, or it returns 'false' if the conditional snapshot
232  * shouldn't be taken.
233  *
234  * The cond_snapshot instance is created and associated with the
235  * user-defined cond_data by tracing_cond_snapshot_enable().
236  * Likewise, the cond_snapshot instance is destroyed and is no longer
237  * associated with the trace instance by
238  * tracing_cond_snapshot_disable().
239  *
240  * The method below is required.
241  *
242  * @update: When a conditional snapshot is invoked, the update()
243  *      callback function is invoked with the tr->max_lock held.  The
244  *      update() implementation signals whether or not to actually
245  *      take the snapshot, by returning 'true' if so, 'false' if no
246  *      snapshot should be taken.  Because the max_lock is held for
247  *      the duration of update(), the implementation is safe to
248  *      directly retrieven and save any implementation data it needs
249  *      to in association with the snapshot.
250  */
251 struct cond_snapshot {
252         void                            *cond_data;
253         cond_update_fn_t                update;
254 };
255
256 /*
257  * The trace array - an array of per-CPU trace arrays. This is the
258  * highest level data structure that individual tracers deal with.
259  * They have on/off state as well:
260  */
261 struct trace_array {
262         struct list_head        list;
263         char                    *name;
264         struct array_buffer     array_buffer;
265 #ifdef CONFIG_TRACER_MAX_TRACE
266         /*
267          * The max_buffer is used to snapshot the trace when a maximum
268          * latency is reached, or when the user initiates a snapshot.
269          * Some tracers will use this to store a maximum trace while
270          * it continues examining live traces.
271          *
272          * The buffers for the max_buffer are set up the same as the array_buffer
273          * When a snapshot is taken, the buffer of the max_buffer is swapped
274          * with the buffer of the array_buffer and the buffers are reset for
275          * the array_buffer so the tracing can continue.
276          */
277         struct array_buffer     max_buffer;
278         bool                    allocated_snapshot;
279 #endif
280 #if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
281         unsigned long           max_latency;
282 #ifdef CONFIG_FSNOTIFY
283         struct dentry           *d_max_latency;
284         struct work_struct      fsnotify_work;
285         struct irq_work         fsnotify_irqwork;
286 #endif
287 #endif
288         struct trace_pid_list   __rcu *filtered_pids;
289         /*
290          * max_lock is used to protect the swapping of buffers
291          * when taking a max snapshot. The buffers themselves are
292          * protected by per_cpu spinlocks. But the action of the swap
293          * needs its own lock.
294          *
295          * This is defined as a arch_spinlock_t in order to help
296          * with performance when lockdep debugging is enabled.
297          *
298          * It is also used in other places outside the update_max_tr
299          * so it needs to be defined outside of the
300          * CONFIG_TRACER_MAX_TRACE.
301          */
302         arch_spinlock_t         max_lock;
303         int                     buffer_disabled;
304 #ifdef CONFIG_FTRACE_SYSCALLS
305         int                     sys_refcount_enter;
306         int                     sys_refcount_exit;
307         struct trace_event_file __rcu *enter_syscall_files[NR_syscalls];
308         struct trace_event_file __rcu *exit_syscall_files[NR_syscalls];
309 #endif
310         int                     stop_count;
311         int                     clock_id;
312         int                     nr_topts;
313         bool                    clear_trace;
314         int                     buffer_percent;
315         unsigned int            n_err_log_entries;
316         struct tracer           *current_trace;
317         unsigned int            trace_flags;
318         unsigned char           trace_flags_index[TRACE_FLAGS_MAX_SIZE];
319         unsigned int            flags;
320         raw_spinlock_t          start_lock;
321         struct list_head        err_log;
322         struct dentry           *dir;
323         struct dentry           *options;
324         struct dentry           *percpu_dir;
325         struct dentry           *event_dir;
326         struct trace_options    *topts;
327         struct list_head        systems;
328         struct list_head        events;
329         struct trace_event_file *trace_marker_file;
330         cpumask_var_t           tracing_cpumask; /* only trace on set CPUs */
331         int                     ref;
332 #ifdef CONFIG_FUNCTION_TRACER
333         struct ftrace_ops       *ops;
334         struct trace_pid_list   __rcu *function_pids;
335 #ifdef CONFIG_DYNAMIC_FTRACE
336         /* All of these are protected by the ftrace_lock */
337         struct list_head        func_probes;
338         struct list_head        mod_trace;
339         struct list_head        mod_notrace;
340 #endif
341         /* function tracing enabled */
342         int                     function_enabled;
343 #endif
344         int                     time_stamp_abs_ref;
345         struct list_head        hist_vars;
346 #ifdef CONFIG_TRACER_SNAPSHOT
347         struct cond_snapshot    *cond_snapshot;
348 #endif
349 };
350
351 enum {
352         TRACE_ARRAY_FL_GLOBAL   = (1 << 0)
353 };
354
355 extern struct list_head ftrace_trace_arrays;
356
357 extern struct mutex trace_types_lock;
358
359 extern int trace_array_get(struct trace_array *tr);
360 extern int tracing_check_open_get_tr(struct trace_array *tr);
361 extern struct trace_array *trace_array_find(const char *instance);
362 extern struct trace_array *trace_array_find_get(const char *instance);
363
364 extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs);
365 extern int tracing_set_clock(struct trace_array *tr, const char *clockstr);
366
367 extern bool trace_clock_in_ns(struct trace_array *tr);
368
369 /*
370  * The global tracer (top) should be the first trace array added,
371  * but we check the flag anyway.
372  */
373 static inline struct trace_array *top_trace_array(void)
374 {
375         struct trace_array *tr;
376
377         if (list_empty(&ftrace_trace_arrays))
378                 return NULL;
379
380         tr = list_entry(ftrace_trace_arrays.prev,
381                         typeof(*tr), list);
382         WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
383         return tr;
384 }
385
386 #define FTRACE_CMP_TYPE(var, type) \
387         __builtin_types_compatible_p(typeof(var), type *)
388
389 #undef IF_ASSIGN
390 #define IF_ASSIGN(var, entry, etype, id)                        \
391         if (FTRACE_CMP_TYPE(var, etype)) {                      \
392                 var = (typeof(var))(entry);                     \
393                 WARN_ON(id != 0 && (entry)->type != id);        \
394                 break;                                          \
395         }
396
397 /* Will cause compile errors if type is not found. */
398 extern void __ftrace_bad_type(void);
399
400 /*
401  * The trace_assign_type is a verifier that the entry type is
402  * the same as the type being assigned. To add new types simply
403  * add a line with the following format:
404  *
405  * IF_ASSIGN(var, ent, type, id);
406  *
407  *  Where "type" is the trace type that includes the trace_entry
408  *  as the "ent" item. And "id" is the trace identifier that is
409  *  used in the trace_type enum.
410  *
411  *  If the type can have more than one id, then use zero.
412  */
413 #define trace_assign_type(var, ent)                                     \
414         do {                                                            \
415                 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN);     \
416                 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0);        \
417                 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK);   \
418                 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
419                 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT);   \
420                 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
421                 IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS);   \
422                 IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT);   \
423                 IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
424                 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw,          \
425                           TRACE_MMIO_RW);                               \
426                 IF_ASSIGN(var, ent, struct trace_mmiotrace_map,         \
427                           TRACE_MMIO_MAP);                              \
428                 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
429                 IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry,      \
430                           TRACE_GRAPH_ENT);             \
431                 IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,      \
432                           TRACE_GRAPH_RET);             \
433                 __ftrace_bad_type();                                    \
434         } while (0)
435
436 /*
437  * An option specific to a tracer. This is a boolean value.
438  * The bit is the bit index that sets its value on the
439  * flags value in struct tracer_flags.
440  */
441 struct tracer_opt {
442         const char      *name; /* Will appear on the trace_options file */
443         u32             bit; /* Mask assigned in val field in tracer_flags */
444 };
445
446 /*
447  * The set of specific options for a tracer. Your tracer
448  * have to set the initial value of the flags val.
449  */
450 struct tracer_flags {
451         u32                     val;
452         struct tracer_opt       *opts;
453         struct tracer           *trace;
454 };
455
456 /* Makes more easy to define a tracer opt */
457 #define TRACER_OPT(s, b)        .name = #s, .bit = b
458
459
460 struct trace_option_dentry {
461         struct tracer_opt               *opt;
462         struct tracer_flags             *flags;
463         struct trace_array              *tr;
464         struct dentry                   *entry;
465 };
466
467 /**
468  * struct tracer - a specific tracer and its callbacks to interact with tracefs
469  * @name: the name chosen to select it on the available_tracers file
470  * @init: called when one switches to this tracer (echo name > current_tracer)
471  * @reset: called when one switches to another tracer
472  * @start: called when tracing is unpaused (echo 1 > tracing_on)
473  * @stop: called when tracing is paused (echo 0 > tracing_on)
474  * @update_thresh: called when tracing_thresh is updated
475  * @open: called when the trace file is opened
476  * @pipe_open: called when the trace_pipe file is opened
477  * @close: called when the trace file is released
478  * @pipe_close: called when the trace_pipe file is released
479  * @read: override the default read callback on trace_pipe
480  * @splice_read: override the default splice_read callback on trace_pipe
481  * @selftest: selftest to run on boot (see trace_selftest.c)
482  * @print_headers: override the first lines that describe your columns
483  * @print_line: callback that prints a trace
484  * @set_flag: signals one of your private flags changed (trace_options file)
485  * @flags: your private flags
486  */
487 struct tracer {
488         const char              *name;
489         int                     (*init)(struct trace_array *tr);
490         void                    (*reset)(struct trace_array *tr);
491         void                    (*start)(struct trace_array *tr);
492         void                    (*stop)(struct trace_array *tr);
493         int                     (*update_thresh)(struct trace_array *tr);
494         void                    (*open)(struct trace_iterator *iter);
495         void                    (*pipe_open)(struct trace_iterator *iter);
496         void                    (*close)(struct trace_iterator *iter);
497         void                    (*pipe_close)(struct trace_iterator *iter);
498         ssize_t                 (*read)(struct trace_iterator *iter,
499                                         struct file *filp, char __user *ubuf,
500                                         size_t cnt, loff_t *ppos);
501         ssize_t                 (*splice_read)(struct trace_iterator *iter,
502                                                struct file *filp,
503                                                loff_t *ppos,
504                                                struct pipe_inode_info *pipe,
505                                                size_t len,
506                                                unsigned int flags);
507 #ifdef CONFIG_FTRACE_STARTUP_TEST
508         int                     (*selftest)(struct tracer *trace,
509                                             struct trace_array *tr);
510 #endif
511         void                    (*print_header)(struct seq_file *m);
512         enum print_line_t       (*print_line)(struct trace_iterator *iter);
513         /* If you handled the flag setting, return 0 */
514         int                     (*set_flag)(struct trace_array *tr,
515                                             u32 old_flags, u32 bit, int set);
516         /* Return 0 if OK with change, else return non-zero */
517         int                     (*flag_changed)(struct trace_array *tr,
518                                                 u32 mask, int set);
519         struct tracer           *next;
520         struct tracer_flags     *flags;
521         int                     enabled;
522         int                     ref;
523         bool                    print_max;
524         bool                    allow_instances;
525 #ifdef CONFIG_TRACER_MAX_TRACE
526         bool                    use_max_tr;
527 #endif
528         /* True if tracer cannot be enabled in kernel param */
529         bool                    noboot;
530 };
531
532
533 /* Only current can touch trace_recursion */
534
535 /*
536  * For function tracing recursion:
537  *  The order of these bits are important.
538  *
539  *  When function tracing occurs, the following steps are made:
540  *   If arch does not support a ftrace feature:
541  *    call internal function (uses INTERNAL bits) which calls...
542  *   If callback is registered to the "global" list, the list
543  *    function is called and recursion checks the GLOBAL bits.
544  *    then this function calls...
545  *   The function callback, which can use the FTRACE bits to
546  *    check for recursion.
547  *
548  * Now if the arch does not suppport a feature, and it calls
549  * the global list function which calls the ftrace callback
550  * all three of these steps will do a recursion protection.
551  * There's no reason to do one if the previous caller already
552  * did. The recursion that we are protecting against will
553  * go through the same steps again.
554  *
555  * To prevent the multiple recursion checks, if a recursion
556  * bit is set that is higher than the MAX bit of the current
557  * check, then we know that the check was made by the previous
558  * caller, and we can skip the current check.
559  */
560 enum {
561         TRACE_BUFFER_BIT,
562         TRACE_BUFFER_NMI_BIT,
563         TRACE_BUFFER_IRQ_BIT,
564         TRACE_BUFFER_SIRQ_BIT,
565
566         /* Start of function recursion bits */
567         TRACE_FTRACE_BIT,
568         TRACE_FTRACE_NMI_BIT,
569         TRACE_FTRACE_IRQ_BIT,
570         TRACE_FTRACE_SIRQ_BIT,
571
572         /* INTERNAL_BITs must be greater than FTRACE_BITs */
573         TRACE_INTERNAL_BIT,
574         TRACE_INTERNAL_NMI_BIT,
575         TRACE_INTERNAL_IRQ_BIT,
576         TRACE_INTERNAL_SIRQ_BIT,
577
578         TRACE_BRANCH_BIT,
579 /*
580  * Abuse of the trace_recursion.
581  * As we need a way to maintain state if we are tracing the function
582  * graph in irq because we want to trace a particular function that
583  * was called in irq context but we have irq tracing off. Since this
584  * can only be modified by current, we can reuse trace_recursion.
585  */
586         TRACE_IRQ_BIT,
587
588         /* Set if the function is in the set_graph_function file */
589         TRACE_GRAPH_BIT,
590
591         /*
592          * In the very unlikely case that an interrupt came in
593          * at a start of graph tracing, and we want to trace
594          * the function in that interrupt, the depth can be greater
595          * than zero, because of the preempted start of a previous
596          * trace. In an even more unlikely case, depth could be 2
597          * if a softirq interrupted the start of graph tracing,
598          * followed by an interrupt preempting a start of graph
599          * tracing in the softirq, and depth can even be 3
600          * if an NMI came in at the start of an interrupt function
601          * that preempted a softirq start of a function that
602          * preempted normal context!!!! Luckily, it can't be
603          * greater than 3, so the next two bits are a mask
604          * of what the depth is when we set TRACE_GRAPH_BIT
605          */
606
607         TRACE_GRAPH_DEPTH_START_BIT,
608         TRACE_GRAPH_DEPTH_END_BIT,
609
610         /*
611          * To implement set_graph_notrace, if this bit is set, we ignore
612          * function graph tracing of called functions, until the return
613          * function is called to clear it.
614          */
615         TRACE_GRAPH_NOTRACE_BIT,
616 };
617
618 #define trace_recursion_set(bit)        do { (current)->trace_recursion |= (1<<(bit)); } while (0)
619 #define trace_recursion_clear(bit)      do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
620 #define trace_recursion_test(bit)       ((current)->trace_recursion & (1<<(bit)))
621
622 #define trace_recursion_depth() \
623         (((current)->trace_recursion >> TRACE_GRAPH_DEPTH_START_BIT) & 3)
624 #define trace_recursion_set_depth(depth) \
625         do {                                                            \
626                 current->trace_recursion &=                             \
627                         ~(3 << TRACE_GRAPH_DEPTH_START_BIT);            \
628                 current->trace_recursion |=                             \
629                         ((depth) & 3) << TRACE_GRAPH_DEPTH_START_BIT;   \
630         } while (0)
631
632 #define TRACE_CONTEXT_BITS      4
633
634 #define TRACE_FTRACE_START      TRACE_FTRACE_BIT
635 #define TRACE_FTRACE_MAX        ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
636
637 #define TRACE_LIST_START        TRACE_INTERNAL_BIT
638 #define TRACE_LIST_MAX          ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
639
640 #define TRACE_CONTEXT_MASK      TRACE_LIST_MAX
641
642 static __always_inline int trace_get_context_bit(void)
643 {
644         int bit;
645
646         if (in_interrupt()) {
647                 if (in_nmi())
648                         bit = 0;
649
650                 else if (in_irq())
651                         bit = 1;
652                 else
653                         bit = 2;
654         } else
655                 bit = 3;
656
657         return bit;
658 }
659
660 static __always_inline int trace_test_and_set_recursion(int start, int max)
661 {
662         unsigned int val = current->trace_recursion;
663         int bit;
664
665         /* A previous recursion check was made */
666         if ((val & TRACE_CONTEXT_MASK) > max)
667                 return 0;
668
669         bit = trace_get_context_bit() + start;
670         if (unlikely(val & (1 << bit)))
671                 return -1;
672
673         val |= 1 << bit;
674         current->trace_recursion = val;
675         barrier();
676
677         return bit;
678 }
679
680 static __always_inline void trace_clear_recursion(int bit)
681 {
682         unsigned int val = current->trace_recursion;
683
684         if (!bit)
685                 return;
686
687         bit = 1 << bit;
688         val &= ~bit;
689
690         barrier();
691         current->trace_recursion = val;
692 }
693
694 static inline struct ring_buffer_iter *
695 trace_buffer_iter(struct trace_iterator *iter, int cpu)
696 {
697         return iter->buffer_iter ? iter->buffer_iter[cpu] : NULL;
698 }
699
700 int tracer_init(struct tracer *t, struct trace_array *tr);
701 int tracing_is_enabled(void);
702 void tracing_reset_online_cpus(struct array_buffer *buf);
703 void tracing_reset_current(int cpu);
704 void tracing_reset_all_online_cpus(void);
705 int tracing_open_generic(struct inode *inode, struct file *filp);
706 int tracing_open_generic_tr(struct inode *inode, struct file *filp);
707 bool tracing_is_disabled(void);
708 bool tracer_tracing_is_on(struct trace_array *tr);
709 void tracer_tracing_on(struct trace_array *tr);
710 void tracer_tracing_off(struct trace_array *tr);
711 struct dentry *trace_create_file(const char *name,
712                                  umode_t mode,
713                                  struct dentry *parent,
714                                  void *data,
715                                  const struct file_operations *fops);
716
717 struct dentry *tracing_init_dentry(void);
718
719 struct ring_buffer_event;
720
721 struct ring_buffer_event *
722 trace_buffer_lock_reserve(struct trace_buffer *buffer,
723                           int type,
724                           unsigned long len,
725                           unsigned long flags,
726                           int pc);
727
728 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
729                                                 struct trace_array_cpu *data);
730
731 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
732                                           int *ent_cpu, u64 *ent_ts);
733
734 void trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
735                                         struct ring_buffer_event *event);
736
737 int trace_empty(struct trace_iterator *iter);
738
739 void *trace_find_next_entry_inc(struct trace_iterator *iter);
740
741 void trace_init_global_iter(struct trace_iterator *iter);
742
743 void tracing_iter_reset(struct trace_iterator *iter, int cpu);
744
745 unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu);
746 unsigned long trace_total_entries(struct trace_array *tr);
747
748 void trace_function(struct trace_array *tr,
749                     unsigned long ip,
750                     unsigned long parent_ip,
751                     unsigned long flags, int pc);
752 void trace_graph_function(struct trace_array *tr,
753                     unsigned long ip,
754                     unsigned long parent_ip,
755                     unsigned long flags, int pc);
756 void trace_latency_header(struct seq_file *m);
757 void trace_default_header(struct seq_file *m);
758 void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
759 int trace_empty(struct trace_iterator *iter);
760
761 void trace_graph_return(struct ftrace_graph_ret *trace);
762 int trace_graph_entry(struct ftrace_graph_ent *trace);
763 void set_graph_array(struct trace_array *tr);
764
765 void tracing_start_cmdline_record(void);
766 void tracing_stop_cmdline_record(void);
767 void tracing_start_tgid_record(void);
768 void tracing_stop_tgid_record(void);
769
770 int register_tracer(struct tracer *type);
771 int is_tracing_stopped(void);
772
773 loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
774
775 extern cpumask_var_t __read_mostly tracing_buffer_mask;
776
777 #define for_each_tracing_cpu(cpu)       \
778         for_each_cpu(cpu, tracing_buffer_mask)
779
780 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
781
782 extern unsigned long tracing_thresh;
783
784 /* PID filtering */
785
786 extern int pid_max;
787
788 bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
789                              pid_t search_pid);
790 bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
791                             struct task_struct *task);
792 void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
793                                   struct task_struct *self,
794                                   struct task_struct *task);
795 void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
796 void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
797 int trace_pid_show(struct seq_file *m, void *v);
798 void trace_free_pid_list(struct trace_pid_list *pid_list);
799 int trace_pid_write(struct trace_pid_list *filtered_pids,
800                     struct trace_pid_list **new_pid_list,
801                     const char __user *ubuf, size_t cnt);
802
803 #ifdef CONFIG_TRACER_MAX_TRACE
804 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
805                    void *cond_data);
806 void update_max_tr_single(struct trace_array *tr,
807                           struct task_struct *tsk, int cpu);
808 #endif /* CONFIG_TRACER_MAX_TRACE */
809
810 #if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
811         defined(CONFIG_FSNOTIFY)
812
813 void latency_fsnotify(struct trace_array *tr);
814
815 #else
816
817 static inline void latency_fsnotify(struct trace_array *tr) { }
818
819 #endif
820
821 #ifdef CONFIG_STACKTRACE
822 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
823                    int pc);
824 #else
825 static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
826                                  int skip, int pc)
827 {
828 }
829 #endif /* CONFIG_STACKTRACE */
830
831 extern u64 ftrace_now(int cpu);
832
833 extern void trace_find_cmdline(int pid, char comm[]);
834 extern int trace_find_tgid(int pid);
835 extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
836
837 #ifdef CONFIG_DYNAMIC_FTRACE
838 extern unsigned long ftrace_update_tot_cnt;
839 extern unsigned long ftrace_number_of_pages;
840 extern unsigned long ftrace_number_of_groups;
841 void ftrace_init_trace_array(struct trace_array *tr);
842 #else
843 static inline void ftrace_init_trace_array(struct trace_array *tr) { }
844 #endif
845 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
846 extern int DYN_FTRACE_TEST_NAME(void);
847 #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
848 extern int DYN_FTRACE_TEST_NAME2(void);
849
850 extern bool ring_buffer_expanded;
851 extern bool tracing_selftest_disabled;
852
853 #ifdef CONFIG_FTRACE_STARTUP_TEST
854 extern int trace_selftest_startup_function(struct tracer *trace,
855                                            struct trace_array *tr);
856 extern int trace_selftest_startup_function_graph(struct tracer *trace,
857                                                  struct trace_array *tr);
858 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
859                                           struct trace_array *tr);
860 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
861                                              struct trace_array *tr);
862 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
863                                                  struct trace_array *tr);
864 extern int trace_selftest_startup_wakeup(struct tracer *trace,
865                                          struct trace_array *tr);
866 extern int trace_selftest_startup_nop(struct tracer *trace,
867                                          struct trace_array *tr);
868 extern int trace_selftest_startup_branch(struct tracer *trace,
869                                          struct trace_array *tr);
870 /*
871  * Tracer data references selftest functions that only occur
872  * on boot up. These can be __init functions. Thus, when selftests
873  * are enabled, then the tracers need to reference __init functions.
874  */
875 #define __tracer_data           __refdata
876 #else
877 /* Tracers are seldom changed. Optimize when selftests are disabled. */
878 #define __tracer_data           __read_mostly
879 #endif /* CONFIG_FTRACE_STARTUP_TEST */
880
881 extern void *head_page(struct trace_array_cpu *data);
882 extern unsigned long long ns2usecs(u64 nsec);
883 extern int
884 trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
885 extern int
886 trace_vprintk(unsigned long ip, const char *fmt, va_list args);
887 extern int
888 trace_array_vprintk(struct trace_array *tr,
889                     unsigned long ip, const char *fmt, va_list args);
890 int trace_array_printk_buf(struct trace_buffer *buffer,
891                            unsigned long ip, const char *fmt, ...);
892 void trace_printk_seq(struct trace_seq *s);
893 enum print_line_t print_trace_line(struct trace_iterator *iter);
894
895 extern char trace_find_mark(unsigned long long duration);
896
897 struct ftrace_hash;
898
899 struct ftrace_mod_load {
900         struct list_head        list;
901         char                    *func;
902         char                    *module;
903         int                      enable;
904 };
905
906 enum {
907         FTRACE_HASH_FL_MOD      = (1 << 0),
908 };
909
910 struct ftrace_hash {
911         unsigned long           size_bits;
912         struct hlist_head       *buckets;
913         unsigned long           count;
914         unsigned long           flags;
915         struct rcu_head         rcu;
916 };
917
918 struct ftrace_func_entry *
919 ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
920
921 static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
922 {
923         return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
924 }
925
926 /* Standard output formatting function used for function return traces */
927 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
928
929 /* Flag options */
930 #define TRACE_GRAPH_PRINT_OVERRUN       0x1
931 #define TRACE_GRAPH_PRINT_CPU           0x2
932 #define TRACE_GRAPH_PRINT_OVERHEAD      0x4
933 #define TRACE_GRAPH_PRINT_PROC          0x8
934 #define TRACE_GRAPH_PRINT_DURATION      0x10
935 #define TRACE_GRAPH_PRINT_ABS_TIME      0x20
936 #define TRACE_GRAPH_PRINT_REL_TIME      0x40
937 #define TRACE_GRAPH_PRINT_IRQS          0x80
938 #define TRACE_GRAPH_PRINT_TAIL          0x100
939 #define TRACE_GRAPH_SLEEP_TIME          0x200
940 #define TRACE_GRAPH_GRAPH_TIME          0x400
941 #define TRACE_GRAPH_PRINT_FILL_SHIFT    28
942 #define TRACE_GRAPH_PRINT_FILL_MASK     (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
943
944 extern void ftrace_graph_sleep_time_control(bool enable);
945
946 #ifdef CONFIG_FUNCTION_PROFILER
947 extern void ftrace_graph_graph_time_control(bool enable);
948 #else
949 static inline void ftrace_graph_graph_time_control(bool enable) { }
950 #endif
951
952 extern enum print_line_t
953 print_graph_function_flags(struct trace_iterator *iter, u32 flags);
954 extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
955 extern void
956 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
957 extern void graph_trace_open(struct trace_iterator *iter);
958 extern void graph_trace_close(struct trace_iterator *iter);
959 extern int __trace_graph_entry(struct trace_array *tr,
960                                struct ftrace_graph_ent *trace,
961                                unsigned long flags, int pc);
962 extern void __trace_graph_return(struct trace_array *tr,
963                                  struct ftrace_graph_ret *trace,
964                                  unsigned long flags, int pc);
965
966 #ifdef CONFIG_DYNAMIC_FTRACE
967 extern struct ftrace_hash __rcu *ftrace_graph_hash;
968 extern struct ftrace_hash *ftrace_graph_notrace_hash;
969
970 static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
971 {
972         unsigned long addr = trace->func;
973         int ret = 0;
974         struct ftrace_hash *hash;
975
976         preempt_disable_notrace();
977
978         hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
979
980         if (ftrace_hash_empty(hash)) {
981                 ret = 1;
982                 goto out;
983         }
984
985         if (ftrace_lookup_ip(hash, addr)) {
986
987                 /*
988                  * This needs to be cleared on the return functions
989                  * when the depth is zero.
990                  */
991                 trace_recursion_set(TRACE_GRAPH_BIT);
992                 trace_recursion_set_depth(trace->depth);
993
994                 /*
995                  * If no irqs are to be traced, but a set_graph_function
996                  * is set, and called by an interrupt handler, we still
997                  * want to trace it.
998                  */
999                 if (in_irq())
1000                         trace_recursion_set(TRACE_IRQ_BIT);
1001                 else
1002                         trace_recursion_clear(TRACE_IRQ_BIT);
1003                 ret = 1;
1004         }
1005
1006 out:
1007         preempt_enable_notrace();
1008         return ret;
1009 }
1010
1011 static inline void ftrace_graph_addr_finish(struct ftrace_graph_ret *trace)
1012 {
1013         if (trace_recursion_test(TRACE_GRAPH_BIT) &&
1014             trace->depth == trace_recursion_depth())
1015                 trace_recursion_clear(TRACE_GRAPH_BIT);
1016 }
1017
1018 static inline int ftrace_graph_notrace_addr(unsigned long addr)
1019 {
1020         int ret = 0;
1021
1022         preempt_disable_notrace();
1023
1024         if (ftrace_lookup_ip(ftrace_graph_notrace_hash, addr))
1025                 ret = 1;
1026
1027         preempt_enable_notrace();
1028         return ret;
1029 }
1030 #else
1031 static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
1032 {
1033         return 1;
1034 }
1035
1036 static inline int ftrace_graph_notrace_addr(unsigned long addr)
1037 {
1038         return 0;
1039 }
1040 static inline void ftrace_graph_addr_finish(struct ftrace_graph_ret *trace)
1041 { }
1042 #endif /* CONFIG_DYNAMIC_FTRACE */
1043
1044 extern unsigned int fgraph_max_depth;
1045
1046 static inline bool ftrace_graph_ignore_func(struct ftrace_graph_ent *trace)
1047 {
1048         /* trace it when it is-nested-in or is a function enabled. */
1049         return !(trace_recursion_test(TRACE_GRAPH_BIT) ||
1050                  ftrace_graph_addr(trace)) ||
1051                 (trace->depth < 0) ||
1052                 (fgraph_max_depth && trace->depth >= fgraph_max_depth);
1053 }
1054
1055 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
1056 static inline enum print_line_t
1057 print_graph_function_flags(struct trace_iterator *iter, u32 flags)
1058 {
1059         return TRACE_TYPE_UNHANDLED;
1060 }
1061 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1062
1063 extern struct list_head ftrace_pids;
1064
1065 #ifdef CONFIG_FUNCTION_TRACER
1066 struct ftrace_func_command {
1067         struct list_head        list;
1068         char                    *name;
1069         int                     (*func)(struct trace_array *tr,
1070                                         struct ftrace_hash *hash,
1071                                         char *func, char *cmd,
1072                                         char *params, int enable);
1073 };
1074 extern bool ftrace_filter_param __initdata;
1075 static inline int ftrace_trace_task(struct trace_array *tr)
1076 {
1077         return !this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid);
1078 }
1079 extern int ftrace_is_dead(void);
1080 int ftrace_create_function_files(struct trace_array *tr,
1081                                  struct dentry *parent);
1082 void ftrace_destroy_function_files(struct trace_array *tr);
1083 void ftrace_init_global_array_ops(struct trace_array *tr);
1084 void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
1085 void ftrace_reset_array_ops(struct trace_array *tr);
1086 void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
1087 void ftrace_init_tracefs_toplevel(struct trace_array *tr,
1088                                   struct dentry *d_tracer);
1089 void ftrace_clear_pids(struct trace_array *tr);
1090 int init_function_trace(void);
1091 void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
1092 #else
1093 static inline int ftrace_trace_task(struct trace_array *tr)
1094 {
1095         return 1;
1096 }
1097 static inline int ftrace_is_dead(void) { return 0; }
1098 static inline int
1099 ftrace_create_function_files(struct trace_array *tr,
1100                              struct dentry *parent)
1101 {
1102         return 0;
1103 }
1104 static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
1105 static inline __init void
1106 ftrace_init_global_array_ops(struct trace_array *tr) { }
1107 static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
1108 static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
1109 static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
1110 static inline void ftrace_clear_pids(struct trace_array *tr) { }
1111 static inline int init_function_trace(void) { return 0; }
1112 static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
1113 /* ftace_func_t type is not defined, use macro instead of static inline */
1114 #define ftrace_init_array_ops(tr, func) do { } while (0)
1115 #endif /* CONFIG_FUNCTION_TRACER */
1116
1117 #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
1118
1119 struct ftrace_probe_ops {
1120         void                    (*func)(unsigned long ip,
1121                                         unsigned long parent_ip,
1122                                         struct trace_array *tr,
1123                                         struct ftrace_probe_ops *ops,
1124                                         void *data);
1125         int                     (*init)(struct ftrace_probe_ops *ops,
1126                                         struct trace_array *tr,
1127                                         unsigned long ip, void *init_data,
1128                                         void **data);
1129         void                    (*free)(struct ftrace_probe_ops *ops,
1130                                         struct trace_array *tr,
1131                                         unsigned long ip, void *data);
1132         int                     (*print)(struct seq_file *m,
1133                                          unsigned long ip,
1134                                          struct ftrace_probe_ops *ops,
1135                                          void *data);
1136 };
1137
1138 struct ftrace_func_mapper;
1139 typedef int (*ftrace_mapper_func)(void *data);
1140
1141 struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
1142 void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
1143                                            unsigned long ip);
1144 int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
1145                                unsigned long ip, void *data);
1146 void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
1147                                    unsigned long ip);
1148 void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
1149                              ftrace_mapper_func free_func);
1150
1151 extern int
1152 register_ftrace_function_probe(char *glob, struct trace_array *tr,
1153                                struct ftrace_probe_ops *ops, void *data);
1154 extern int
1155 unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
1156                                       struct ftrace_probe_ops *ops);
1157 extern void clear_ftrace_function_probes(struct trace_array *tr);
1158
1159 int register_ftrace_command(struct ftrace_func_command *cmd);
1160 int unregister_ftrace_command(struct ftrace_func_command *cmd);
1161
1162 void ftrace_create_filter_files(struct ftrace_ops *ops,
1163                                 struct dentry *parent);
1164 void ftrace_destroy_filter_files(struct ftrace_ops *ops);
1165
1166 extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
1167                              int len, int reset);
1168 extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
1169                               int len, int reset);
1170 #else
1171 struct ftrace_func_command;
1172
1173 static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
1174 {
1175         return -EINVAL;
1176 }
1177 static inline __init int unregister_ftrace_command(char *cmd_name)
1178 {
1179         return -EINVAL;
1180 }
1181 static inline void clear_ftrace_function_probes(struct trace_array *tr)
1182 {
1183 }
1184
1185 /*
1186  * The ops parameter passed in is usually undefined.
1187  * This must be a macro.
1188  */
1189 #define ftrace_create_filter_files(ops, parent) do { } while (0)
1190 #define ftrace_destroy_filter_files(ops) do { } while (0)
1191 #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
1192
1193 bool ftrace_event_is_function(struct trace_event_call *call);
1194
1195 /*
1196  * struct trace_parser - servers for reading the user input separated by spaces
1197  * @cont: set if the input is not complete - no final space char was found
1198  * @buffer: holds the parsed user input
1199  * @idx: user input length
1200  * @size: buffer size
1201  */
1202 struct trace_parser {
1203         bool            cont;
1204         char            *buffer;
1205         unsigned        idx;
1206         unsigned        size;
1207 };
1208
1209 static inline bool trace_parser_loaded(struct trace_parser *parser)
1210 {
1211         return (parser->idx != 0);
1212 }
1213
1214 static inline bool trace_parser_cont(struct trace_parser *parser)
1215 {
1216         return parser->cont;
1217 }
1218
1219 static inline void trace_parser_clear(struct trace_parser *parser)
1220 {
1221         parser->cont = false;
1222         parser->idx = 0;
1223 }
1224
1225 extern int trace_parser_get_init(struct trace_parser *parser, int size);
1226 extern void trace_parser_put(struct trace_parser *parser);
1227 extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
1228         size_t cnt, loff_t *ppos);
1229
1230 /*
1231  * Only create function graph options if function graph is configured.
1232  */
1233 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1234 # define FGRAPH_FLAGS                                           \
1235                 C(DISPLAY_GRAPH,        "display-graph"),
1236 #else
1237 # define FGRAPH_FLAGS
1238 #endif
1239
1240 #ifdef CONFIG_BRANCH_TRACER
1241 # define BRANCH_FLAGS                                   \
1242                 C(BRANCH,               "branch"),
1243 #else
1244 # define BRANCH_FLAGS
1245 #endif
1246
1247 #ifdef CONFIG_FUNCTION_TRACER
1248 # define FUNCTION_FLAGS                                         \
1249                 C(FUNCTION,             "function-trace"),      \
1250                 C(FUNC_FORK,            "function-fork"),
1251 # define FUNCTION_DEFAULT_FLAGS         TRACE_ITER_FUNCTION
1252 #else
1253 # define FUNCTION_FLAGS
1254 # define FUNCTION_DEFAULT_FLAGS         0UL
1255 # define TRACE_ITER_FUNC_FORK           0UL
1256 #endif
1257
1258 #ifdef CONFIG_STACKTRACE
1259 # define STACK_FLAGS                            \
1260                 C(STACKTRACE,           "stacktrace"),
1261 #else
1262 # define STACK_FLAGS
1263 #endif
1264
1265 /*
1266  * trace_iterator_flags is an enumeration that defines bit
1267  * positions into trace_flags that controls the output.
1268  *
1269  * NOTE: These bits must match the trace_options array in
1270  *       trace.c (this macro guarantees it).
1271  */
1272 #define TRACE_FLAGS                                             \
1273                 C(PRINT_PARENT,         "print-parent"),        \
1274                 C(SYM_OFFSET,           "sym-offset"),          \
1275                 C(SYM_ADDR,             "sym-addr"),            \
1276                 C(VERBOSE,              "verbose"),             \
1277                 C(RAW,                  "raw"),                 \
1278                 C(HEX,                  "hex"),                 \
1279                 C(BIN,                  "bin"),                 \
1280                 C(BLOCK,                "block"),               \
1281                 C(PRINTK,               "trace_printk"),        \
1282                 C(ANNOTATE,             "annotate"),            \
1283                 C(USERSTACKTRACE,       "userstacktrace"),      \
1284                 C(SYM_USEROBJ,          "sym-userobj"),         \
1285                 C(PRINTK_MSGONLY,       "printk-msg-only"),     \
1286                 C(CONTEXT_INFO,         "context-info"),   /* Print pid/cpu/time */ \
1287                 C(LATENCY_FMT,          "latency-format"),      \
1288                 C(RECORD_CMD,           "record-cmd"),          \
1289                 C(RECORD_TGID,          "record-tgid"),         \
1290                 C(OVERWRITE,            "overwrite"),           \
1291                 C(STOP_ON_FREE,         "disable_on_free"),     \
1292                 C(IRQ_INFO,             "irq-info"),            \
1293                 C(MARKERS,              "markers"),             \
1294                 C(EVENT_FORK,           "event-fork"),          \
1295                 FUNCTION_FLAGS                                  \
1296                 FGRAPH_FLAGS                                    \
1297                 STACK_FLAGS                                     \
1298                 BRANCH_FLAGS
1299
1300 /*
1301  * By defining C, we can make TRACE_FLAGS a list of bit names
1302  * that will define the bits for the flag masks.
1303  */
1304 #undef C
1305 #define C(a, b) TRACE_ITER_##a##_BIT
1306
1307 enum trace_iterator_bits {
1308         TRACE_FLAGS
1309         /* Make sure we don't go more than we have bits for */
1310         TRACE_ITER_LAST_BIT
1311 };
1312
1313 /*
1314  * By redefining C, we can make TRACE_FLAGS a list of masks that
1315  * use the bits as defined above.
1316  */
1317 #undef C
1318 #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
1319
1320 enum trace_iterator_flags { TRACE_FLAGS };
1321
1322 /*
1323  * TRACE_ITER_SYM_MASK masks the options in trace_flags that
1324  * control the output of kernel symbols.
1325  */
1326 #define TRACE_ITER_SYM_MASK \
1327         (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
1328
1329 extern struct tracer nop_trace;
1330
1331 #ifdef CONFIG_BRANCH_TRACER
1332 extern int enable_branch_tracing(struct trace_array *tr);
1333 extern void disable_branch_tracing(void);
1334 static inline int trace_branch_enable(struct trace_array *tr)
1335 {
1336         if (tr->trace_flags & TRACE_ITER_BRANCH)
1337                 return enable_branch_tracing(tr);
1338         return 0;
1339 }
1340 static inline void trace_branch_disable(void)
1341 {
1342         /* due to races, always disable */
1343         disable_branch_tracing();
1344 }
1345 #else
1346 static inline int trace_branch_enable(struct trace_array *tr)
1347 {
1348         return 0;
1349 }
1350 static inline void trace_branch_disable(void)
1351 {
1352 }
1353 #endif /* CONFIG_BRANCH_TRACER */
1354
1355 /* set ring buffers to default size if not already done so */
1356 int tracing_update_buffers(void);
1357
1358 struct ftrace_event_field {
1359         struct list_head        link;
1360         const char              *name;
1361         const char              *type;
1362         int                     filter_type;
1363         int                     offset;
1364         int                     size;
1365         int                     is_signed;
1366 };
1367
1368 struct prog_entry;
1369
1370 struct event_filter {
1371         struct prog_entry __rcu *prog;
1372         char                    *filter_string;
1373 };
1374
1375 struct event_subsystem {
1376         struct list_head        list;
1377         const char              *name;
1378         struct event_filter     *filter;
1379         int                     ref_count;
1380 };
1381
1382 struct trace_subsystem_dir {
1383         struct list_head                list;
1384         struct event_subsystem          *subsystem;
1385         struct trace_array              *tr;
1386         struct dentry                   *entry;
1387         int                             ref_count;
1388         int                             nr_events;
1389 };
1390
1391 extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
1392                                      struct trace_buffer *buffer,
1393                                      struct ring_buffer_event *event);
1394
1395 void trace_buffer_unlock_commit_regs(struct trace_array *tr,
1396                                      struct trace_buffer *buffer,
1397                                      struct ring_buffer_event *event,
1398                                      unsigned long flags, int pc,
1399                                      struct pt_regs *regs);
1400
1401 static inline void trace_buffer_unlock_commit(struct trace_array *tr,
1402                                               struct trace_buffer *buffer,
1403                                               struct ring_buffer_event *event,
1404                                               unsigned long flags, int pc)
1405 {
1406         trace_buffer_unlock_commit_regs(tr, buffer, event, flags, pc, NULL);
1407 }
1408
1409 DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
1410 DECLARE_PER_CPU(int, trace_buffered_event_cnt);
1411 void trace_buffered_event_disable(void);
1412 void trace_buffered_event_enable(void);
1413
1414 static inline void
1415 __trace_event_discard_commit(struct trace_buffer *buffer,
1416                              struct ring_buffer_event *event)
1417 {
1418         if (this_cpu_read(trace_buffered_event) == event) {
1419                 /* Simply release the temp buffer */
1420                 this_cpu_dec(trace_buffered_event_cnt);
1421                 return;
1422         }
1423         ring_buffer_discard_commit(buffer, event);
1424 }
1425
1426 /*
1427  * Helper function for event_trigger_unlock_commit{_regs}().
1428  * If there are event triggers attached to this event that requires
1429  * filtering against its fields, then they wil be called as the
1430  * entry already holds the field information of the current event.
1431  *
1432  * It also checks if the event should be discarded or not.
1433  * It is to be discarded if the event is soft disabled and the
1434  * event was only recorded to process triggers, or if the event
1435  * filter is active and this event did not match the filters.
1436  *
1437  * Returns true if the event is discarded, false otherwise.
1438  */
1439 static inline bool
1440 __event_trigger_test_discard(struct trace_event_file *file,
1441                              struct trace_buffer *buffer,
1442                              struct ring_buffer_event *event,
1443                              void *entry,
1444                              enum event_trigger_type *tt)
1445 {
1446         unsigned long eflags = file->flags;
1447
1448         if (eflags & EVENT_FILE_FL_TRIGGER_COND)
1449                 *tt = event_triggers_call(file, entry, event);
1450
1451         if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
1452             (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
1453              !filter_match_preds(file->filter, entry))) {
1454                 __trace_event_discard_commit(buffer, event);
1455                 return true;
1456         }
1457
1458         return false;
1459 }
1460
1461 /**
1462  * event_trigger_unlock_commit - handle triggers and finish event commit
1463  * @file: The file pointer assoctiated to the event
1464  * @buffer: The ring buffer that the event is being written to
1465  * @event: The event meta data in the ring buffer
1466  * @entry: The event itself
1467  * @irq_flags: The state of the interrupts at the start of the event
1468  * @pc: The state of the preempt count at the start of the event.
1469  *
1470  * This is a helper function to handle triggers that require data
1471  * from the event itself. It also tests the event against filters and
1472  * if the event is soft disabled and should be discarded.
1473  */
1474 static inline void
1475 event_trigger_unlock_commit(struct trace_event_file *file,
1476                             struct trace_buffer *buffer,
1477                             struct ring_buffer_event *event,
1478                             void *entry, unsigned long irq_flags, int pc)
1479 {
1480         enum event_trigger_type tt = ETT_NONE;
1481
1482         if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
1483                 trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
1484
1485         if (tt)
1486                 event_triggers_post_call(file, tt);
1487 }
1488
1489 /**
1490  * event_trigger_unlock_commit_regs - handle triggers and finish event commit
1491  * @file: The file pointer assoctiated to the event
1492  * @buffer: The ring buffer that the event is being written to
1493  * @event: The event meta data in the ring buffer
1494  * @entry: The event itself
1495  * @irq_flags: The state of the interrupts at the start of the event
1496  * @pc: The state of the preempt count at the start of the event.
1497  *
1498  * This is a helper function to handle triggers that require data
1499  * from the event itself. It also tests the event against filters and
1500  * if the event is soft disabled and should be discarded.
1501  *
1502  * Same as event_trigger_unlock_commit() but calls
1503  * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
1504  */
1505 static inline void
1506 event_trigger_unlock_commit_regs(struct trace_event_file *file,
1507                                  struct trace_buffer *buffer,
1508                                  struct ring_buffer_event *event,
1509                                  void *entry, unsigned long irq_flags, int pc,
1510                                  struct pt_regs *regs)
1511 {
1512         enum event_trigger_type tt = ETT_NONE;
1513
1514         if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
1515                 trace_buffer_unlock_commit_regs(file->tr, buffer, event,
1516                                                 irq_flags, pc, regs);
1517
1518         if (tt)
1519                 event_triggers_post_call(file, tt);
1520 }
1521
1522 #define FILTER_PRED_INVALID     ((unsigned short)-1)
1523 #define FILTER_PRED_IS_RIGHT    (1 << 15)
1524 #define FILTER_PRED_FOLD        (1 << 15)
1525
1526 /*
1527  * The max preds is the size of unsigned short with
1528  * two flags at the MSBs. One bit is used for both the IS_RIGHT
1529  * and FOLD flags. The other is reserved.
1530  *
1531  * 2^14 preds is way more than enough.
1532  */
1533 #define MAX_FILTER_PRED         16384
1534
1535 struct filter_pred;
1536 struct regex;
1537
1538 typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
1539
1540 typedef int (*regex_match_func)(char *str, struct regex *r, int len);
1541
1542 enum regex_type {
1543         MATCH_FULL = 0,
1544         MATCH_FRONT_ONLY,
1545         MATCH_MIDDLE_ONLY,
1546         MATCH_END_ONLY,
1547         MATCH_GLOB,
1548         MATCH_INDEX,
1549 };
1550
1551 struct regex {
1552         char                    pattern[MAX_FILTER_STR_VAL];
1553         int                     len;
1554         int                     field_len;
1555         regex_match_func        match;
1556 };
1557
1558 struct filter_pred {
1559         filter_pred_fn_t        fn;
1560         u64                     val;
1561         struct regex            regex;
1562         unsigned short          *ops;
1563         struct ftrace_event_field *field;
1564         int                     offset;
1565         int                     not;
1566         int                     op;
1567 };
1568
1569 static inline bool is_string_field(struct ftrace_event_field *field)
1570 {
1571         return field->filter_type == FILTER_DYN_STRING ||
1572                field->filter_type == FILTER_STATIC_STRING ||
1573                field->filter_type == FILTER_PTR_STRING ||
1574                field->filter_type == FILTER_COMM;
1575 }
1576
1577 static inline bool is_function_field(struct ftrace_event_field *field)
1578 {
1579         return field->filter_type == FILTER_TRACE_FN;
1580 }
1581
1582 extern enum regex_type
1583 filter_parse_regex(char *buff, int len, char **search, int *not);
1584 extern void print_event_filter(struct trace_event_file *file,
1585                                struct trace_seq *s);
1586 extern int apply_event_filter(struct trace_event_file *file,
1587                               char *filter_string);
1588 extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
1589                                         char *filter_string);
1590 extern void print_subsystem_event_filter(struct event_subsystem *system,
1591                                          struct trace_seq *s);
1592 extern int filter_assign_type(const char *type);
1593 extern int create_event_filter(struct trace_array *tr,
1594                                struct trace_event_call *call,
1595                                char *filter_str, bool set_str,
1596                                struct event_filter **filterp);
1597 extern void free_event_filter(struct event_filter *filter);
1598
1599 struct ftrace_event_field *
1600 trace_find_event_field(struct trace_event_call *call, char *name);
1601
1602 extern void trace_event_enable_cmd_record(bool enable);
1603 extern void trace_event_enable_tgid_record(bool enable);
1604
1605 extern int event_trace_init(void);
1606 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
1607 extern int event_trace_del_tracer(struct trace_array *tr);
1608
1609 extern struct trace_event_file *__find_event_file(struct trace_array *tr,
1610                                                   const char *system,
1611                                                   const char *event);
1612 extern struct trace_event_file *find_event_file(struct trace_array *tr,
1613                                                 const char *system,
1614                                                 const char *event);
1615
1616 static inline void *event_file_data(struct file *filp)
1617 {
1618         return READ_ONCE(file_inode(filp)->i_private);
1619 }
1620
1621 extern struct mutex event_mutex;
1622 extern struct list_head ftrace_events;
1623
1624 extern const struct file_operations event_trigger_fops;
1625 extern const struct file_operations event_hist_fops;
1626 extern const struct file_operations event_inject_fops;
1627
1628 #ifdef CONFIG_HIST_TRIGGERS
1629 extern int register_trigger_hist_cmd(void);
1630 extern int register_trigger_hist_enable_disable_cmds(void);
1631 #else
1632 static inline int register_trigger_hist_cmd(void) { return 0; }
1633 static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
1634 #endif
1635
1636 extern int register_trigger_cmds(void);
1637 extern void clear_event_triggers(struct trace_array *tr);
1638
1639 struct event_trigger_data {
1640         unsigned long                   count;
1641         int                             ref;
1642         struct event_trigger_ops        *ops;
1643         struct event_command            *cmd_ops;
1644         struct event_filter __rcu       *filter;
1645         char                            *filter_str;
1646         void                            *private_data;
1647         bool                            paused;
1648         bool                            paused_tmp;
1649         struct list_head                list;
1650         char                            *name;
1651         struct list_head                named_list;
1652         struct event_trigger_data       *named_data;
1653 };
1654
1655 /* Avoid typos */
1656 #define ENABLE_EVENT_STR        "enable_event"
1657 #define DISABLE_EVENT_STR       "disable_event"
1658 #define ENABLE_HIST_STR         "enable_hist"
1659 #define DISABLE_HIST_STR        "disable_hist"
1660
1661 struct enable_trigger_data {
1662         struct trace_event_file         *file;
1663         bool                            enable;
1664         bool                            hist;
1665 };
1666
1667 extern int event_enable_trigger_print(struct seq_file *m,
1668                                       struct event_trigger_ops *ops,
1669                                       struct event_trigger_data *data);
1670 extern void event_enable_trigger_free(struct event_trigger_ops *ops,
1671                                       struct event_trigger_data *data);
1672 extern int event_enable_trigger_func(struct event_command *cmd_ops,
1673                                      struct trace_event_file *file,
1674                                      char *glob, char *cmd, char *param);
1675 extern int event_enable_register_trigger(char *glob,
1676                                          struct event_trigger_ops *ops,
1677                                          struct event_trigger_data *data,
1678                                          struct trace_event_file *file);
1679 extern void event_enable_unregister_trigger(char *glob,
1680                                             struct event_trigger_ops *ops,
1681                                             struct event_trigger_data *test,
1682                                             struct trace_event_file *file);
1683 extern void trigger_data_free(struct event_trigger_data *data);
1684 extern int event_trigger_init(struct event_trigger_ops *ops,
1685                               struct event_trigger_data *data);
1686 extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
1687                                               int trigger_enable);
1688 extern void update_cond_flag(struct trace_event_file *file);
1689 extern int set_trigger_filter(char *filter_str,
1690                               struct event_trigger_data *trigger_data,
1691                               struct trace_event_file *file);
1692 extern struct event_trigger_data *find_named_trigger(const char *name);
1693 extern bool is_named_trigger(struct event_trigger_data *test);
1694 extern int save_named_trigger(const char *name,
1695                               struct event_trigger_data *data);
1696 extern void del_named_trigger(struct event_trigger_data *data);
1697 extern void pause_named_trigger(struct event_trigger_data *data);
1698 extern void unpause_named_trigger(struct event_trigger_data *data);
1699 extern void set_named_trigger_data(struct event_trigger_data *data,
1700                                    struct event_trigger_data *named_data);
1701 extern struct event_trigger_data *
1702 get_named_trigger_data(struct event_trigger_data *data);
1703 extern int register_event_command(struct event_command *cmd);
1704 extern int unregister_event_command(struct event_command *cmd);
1705 extern int register_trigger_hist_enable_disable_cmds(void);
1706
1707 /**
1708  * struct event_trigger_ops - callbacks for trace event triggers
1709  *
1710  * The methods in this structure provide per-event trigger hooks for
1711  * various trigger operations.
1712  *
1713  * All the methods below, except for @init() and @free(), must be
1714  * implemented.
1715  *
1716  * @func: The trigger 'probe' function called when the triggering
1717  *      event occurs.  The data passed into this callback is the data
1718  *      that was supplied to the event_command @reg() function that
1719  *      registered the trigger (see struct event_command) along with
1720  *      the trace record, rec.
1721  *
1722  * @init: An optional initialization function called for the trigger
1723  *      when the trigger is registered (via the event_command reg()
1724  *      function).  This can be used to perform per-trigger
1725  *      initialization such as incrementing a per-trigger reference
1726  *      count, for instance.  This is usually implemented by the
1727  *      generic utility function @event_trigger_init() (see
1728  *      trace_event_triggers.c).
1729  *
1730  * @free: An optional de-initialization function called for the
1731  *      trigger when the trigger is unregistered (via the
1732  *      event_command @reg() function).  This can be used to perform
1733  *      per-trigger de-initialization such as decrementing a
1734  *      per-trigger reference count and freeing corresponding trigger
1735  *      data, for instance.  This is usually implemented by the
1736  *      generic utility function @event_trigger_free() (see
1737  *      trace_event_triggers.c).
1738  *
1739  * @print: The callback function invoked to have the trigger print
1740  *      itself.  This is usually implemented by a wrapper function
1741  *      that calls the generic utility function @event_trigger_print()
1742  *      (see trace_event_triggers.c).
1743  */
1744 struct event_trigger_ops {
1745         void                    (*func)(struct event_trigger_data *data,
1746                                         void *rec,
1747                                         struct ring_buffer_event *rbe);
1748         int                     (*init)(struct event_trigger_ops *ops,
1749                                         struct event_trigger_data *data);
1750         void                    (*free)(struct event_trigger_ops *ops,
1751                                         struct event_trigger_data *data);
1752         int                     (*print)(struct seq_file *m,
1753                                          struct event_trigger_ops *ops,
1754                                          struct event_trigger_data *data);
1755 };
1756
1757 /**
1758  * struct event_command - callbacks and data members for event commands
1759  *
1760  * Event commands are invoked by users by writing the command name
1761  * into the 'trigger' file associated with a trace event.  The
1762  * parameters associated with a specific invocation of an event
1763  * command are used to create an event trigger instance, which is
1764  * added to the list of trigger instances associated with that trace
1765  * event.  When the event is hit, the set of triggers associated with
1766  * that event is invoked.
1767  *
1768  * The data members in this structure provide per-event command data
1769  * for various event commands.
1770  *
1771  * All the data members below, except for @post_trigger, must be set
1772  * for each event command.
1773  *
1774  * @name: The unique name that identifies the event command.  This is
1775  *      the name used when setting triggers via trigger files.
1776  *
1777  * @trigger_type: A unique id that identifies the event command
1778  *      'type'.  This value has two purposes, the first to ensure that
1779  *      only one trigger of the same type can be set at a given time
1780  *      for a particular event e.g. it doesn't make sense to have both
1781  *      a traceon and traceoff trigger attached to a single event at
1782  *      the same time, so traceon and traceoff have the same type
1783  *      though they have different names.  The @trigger_type value is
1784  *      also used as a bit value for deferring the actual trigger
1785  *      action until after the current event is finished.  Some
1786  *      commands need to do this if they themselves log to the trace
1787  *      buffer (see the @post_trigger() member below).  @trigger_type
1788  *      values are defined by adding new values to the trigger_type
1789  *      enum in include/linux/trace_events.h.
1790  *
1791  * @flags: See the enum event_command_flags below.
1792  *
1793  * All the methods below, except for @set_filter() and @unreg_all(),
1794  * must be implemented.
1795  *
1796  * @func: The callback function responsible for parsing and
1797  *      registering the trigger written to the 'trigger' file by the
1798  *      user.  It allocates the trigger instance and registers it with
1799  *      the appropriate trace event.  It makes use of the other
1800  *      event_command callback functions to orchestrate this, and is
1801  *      usually implemented by the generic utility function
1802  *      @event_trigger_callback() (see trace_event_triggers.c).
1803  *
1804  * @reg: Adds the trigger to the list of triggers associated with the
1805  *      event, and enables the event trigger itself, after
1806  *      initializing it (via the event_trigger_ops @init() function).
1807  *      This is also where commands can use the @trigger_type value to
1808  *      make the decision as to whether or not multiple instances of
1809  *      the trigger should be allowed.  This is usually implemented by
1810  *      the generic utility function @register_trigger() (see
1811  *      trace_event_triggers.c).
1812  *
1813  * @unreg: Removes the trigger from the list of triggers associated
1814  *      with the event, and disables the event trigger itself, after
1815  *      initializing it (via the event_trigger_ops @free() function).
1816  *      This is usually implemented by the generic utility function
1817  *      @unregister_trigger() (see trace_event_triggers.c).
1818  *
1819  * @unreg_all: An optional function called to remove all the triggers
1820  *      from the list of triggers associated with the event.  Called
1821  *      when a trigger file is opened in truncate mode.
1822  *
1823  * @set_filter: An optional function called to parse and set a filter
1824  *      for the trigger.  If no @set_filter() method is set for the
1825  *      event command, filters set by the user for the command will be
1826  *      ignored.  This is usually implemented by the generic utility
1827  *      function @set_trigger_filter() (see trace_event_triggers.c).
1828  *
1829  * @get_trigger_ops: The callback function invoked to retrieve the
1830  *      event_trigger_ops implementation associated with the command.
1831  */
1832 struct event_command {
1833         struct list_head        list;
1834         char                    *name;
1835         enum event_trigger_type trigger_type;
1836         int                     flags;
1837         int                     (*func)(struct event_command *cmd_ops,
1838                                         struct trace_event_file *file,
1839                                         char *glob, char *cmd, char *params);
1840         int                     (*reg)(char *glob,
1841                                        struct event_trigger_ops *ops,
1842                                        struct event_trigger_data *data,
1843                                        struct trace_event_file *file);
1844         void                    (*unreg)(char *glob,
1845                                          struct event_trigger_ops *ops,
1846                                          struct event_trigger_data *data,
1847                                          struct trace_event_file *file);
1848         void                    (*unreg_all)(struct trace_event_file *file);
1849         int                     (*set_filter)(char *filter_str,
1850                                               struct event_trigger_data *data,
1851                                               struct trace_event_file *file);
1852         struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
1853 };
1854
1855 /**
1856  * enum event_command_flags - flags for struct event_command
1857  *
1858  * @POST_TRIGGER: A flag that says whether or not this command needs
1859  *      to have its action delayed until after the current event has
1860  *      been closed.  Some triggers need to avoid being invoked while
1861  *      an event is currently in the process of being logged, since
1862  *      the trigger may itself log data into the trace buffer.  Thus
1863  *      we make sure the current event is committed before invoking
1864  *      those triggers.  To do that, the trigger invocation is split
1865  *      in two - the first part checks the filter using the current
1866  *      trace record; if a command has the @post_trigger flag set, it
1867  *      sets a bit for itself in the return value, otherwise it
1868  *      directly invokes the trigger.  Once all commands have been
1869  *      either invoked or set their return flag, the current record is
1870  *      either committed or discarded.  At that point, if any commands
1871  *      have deferred their triggers, those commands are finally
1872  *      invoked following the close of the current event.  In other
1873  *      words, if the event_trigger_ops @func() probe implementation
1874  *      itself logs to the trace buffer, this flag should be set,
1875  *      otherwise it can be left unspecified.
1876  *
1877  * @NEEDS_REC: A flag that says whether or not this command needs
1878  *      access to the trace record in order to perform its function,
1879  *      regardless of whether or not it has a filter associated with
1880  *      it (filters make a trigger require access to the trace record
1881  *      but are not always present).
1882  */
1883 enum event_command_flags {
1884         EVENT_CMD_FL_POST_TRIGGER       = 1,
1885         EVENT_CMD_FL_NEEDS_REC          = 2,
1886 };
1887
1888 static inline bool event_command_post_trigger(struct event_command *cmd_ops)
1889 {
1890         return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
1891 }
1892
1893 static inline bool event_command_needs_rec(struct event_command *cmd_ops)
1894 {
1895         return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
1896 }
1897
1898 extern int trace_event_enable_disable(struct trace_event_file *file,
1899                                       int enable, int soft_disable);
1900 extern int tracing_alloc_snapshot(void);
1901 extern void tracing_snapshot_cond(struct trace_array *tr, void *cond_data);
1902 extern int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update);
1903
1904 extern int tracing_snapshot_cond_disable(struct trace_array *tr);
1905 extern void *tracing_cond_snapshot_data(struct trace_array *tr);
1906
1907 extern const char *__start___trace_bprintk_fmt[];
1908 extern const char *__stop___trace_bprintk_fmt[];
1909
1910 extern const char *__start___tracepoint_str[];
1911 extern const char *__stop___tracepoint_str[];
1912
1913 void trace_printk_control(bool enabled);
1914 void trace_printk_start_comm(void);
1915 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
1916 int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
1917
1918 /* Used from boot time tracer */
1919 extern int trace_set_options(struct trace_array *tr, char *option);
1920 extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
1921 extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
1922                                           unsigned long size, int cpu_id);
1923 extern int tracing_set_cpumask(struct trace_array *tr,
1924                                 cpumask_var_t tracing_cpumask_new);
1925
1926
1927 #define MAX_EVENT_NAME_LEN      64
1928
1929 extern int trace_run_command(const char *buf, int (*createfn)(int, char**));
1930 extern ssize_t trace_parse_run_command(struct file *file,
1931                 const char __user *buffer, size_t count, loff_t *ppos,
1932                 int (*createfn)(int, char**));
1933
1934 extern unsigned int err_pos(char *cmd, const char *str);
1935 extern void tracing_log_err(struct trace_array *tr,
1936                             const char *loc, const char *cmd,
1937                             const char **errs, u8 type, u8 pos);
1938
1939 /*
1940  * Normal trace_printk() and friends allocates special buffers
1941  * to do the manipulation, as well as saves the print formats
1942  * into sections to display. But the trace infrastructure wants
1943  * to use these without the added overhead at the price of being
1944  * a bit slower (used mainly for warnings, where we don't care
1945  * about performance). The internal_trace_puts() is for such
1946  * a purpose.
1947  */
1948 #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
1949
1950 #undef FTRACE_ENTRY
1951 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter)     \
1952         extern struct trace_event_call                                  \
1953         __aligned(4) event_##call;
1954 #undef FTRACE_ENTRY_DUP
1955 #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
1956         FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
1957                      filter)
1958 #undef FTRACE_ENTRY_PACKED
1959 #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print, filter) \
1960         FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
1961                      filter)
1962
1963 #include "trace_entries.h"
1964
1965 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
1966 int perf_ftrace_event_register(struct trace_event_call *call,
1967                                enum trace_reg type, void *data);
1968 #else
1969 #define perf_ftrace_event_register NULL
1970 #endif
1971
1972 #ifdef CONFIG_FTRACE_SYSCALLS
1973 void init_ftrace_syscalls(void);
1974 const char *get_syscall_name(int syscall);
1975 #else
1976 static inline void init_ftrace_syscalls(void) { }
1977 static inline const char *get_syscall_name(int syscall)
1978 {
1979         return NULL;
1980 }
1981 #endif
1982
1983 #ifdef CONFIG_EVENT_TRACING
1984 void trace_event_init(void);
1985 void trace_event_eval_update(struct trace_eval_map **map, int len);
1986 /* Used from boot time tracer */
1987 extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
1988 extern int trigger_process_regex(struct trace_event_file *file, char *buff);
1989 #else
1990 static inline void __init trace_event_init(void) { }
1991 static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
1992 #endif
1993
1994 #ifdef CONFIG_TRACER_SNAPSHOT
1995 void tracing_snapshot_instance(struct trace_array *tr);
1996 int tracing_alloc_snapshot_instance(struct trace_array *tr);
1997 #else
1998 static inline void tracing_snapshot_instance(struct trace_array *tr) { }
1999 static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
2000 {
2001         return 0;
2002 }
2003 #endif
2004
2005 #ifdef CONFIG_PREEMPT_TRACER
2006 void tracer_preempt_on(unsigned long a0, unsigned long a1);
2007 void tracer_preempt_off(unsigned long a0, unsigned long a1);
2008 #else
2009 static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
2010 static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
2011 #endif
2012 #ifdef CONFIG_IRQSOFF_TRACER
2013 void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
2014 void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
2015 #else
2016 static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
2017 static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
2018 #endif
2019
2020 extern struct trace_iterator *tracepoint_print_iter;
2021
2022 /*
2023  * Reset the state of the trace_iterator so that it can read consumed data.
2024  * Normally, the trace_iterator is used for reading the data when it is not
2025  * consumed, and must retain state.
2026  */
2027 static __always_inline void trace_iterator_reset(struct trace_iterator *iter)
2028 {
2029         const size_t offset = offsetof(struct trace_iterator, seq);
2030
2031         /*
2032          * Keep gcc from complaining about overwriting more than just one
2033          * member in the structure.
2034          */
2035         memset((char *)iter + offset, 0, sizeof(struct trace_iterator) - offset);
2036
2037         iter->pos = -1;
2038 }
2039
2040 #endif /* _LINUX_KERNEL_TRACE_H */