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