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