blob: f05c8fb48f39db34716c9b2ff8e8ab657b38a8df [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#ifndef _LINUX_KERNEL_TRACE_H
2#define _LINUX_KERNEL_TRACE_H
3
4#include <linux/fs.h>
5#include <linux/atomic.h>
6#include <linux/sched.h>
7#include <linux/clocksource.h>
8#include <linux/ring_buffer.h>
9#include <linux/mmiotrace.h>
10#include <linux/tracepoint.h>
11#include <linux/ftrace.h>
12#include <linux/hw_breakpoint.h>
13#include <linux/trace_seq.h>
14#include <linux/ftrace_event.h>
15
16enum trace_type {
17 __TRACE_FIRST_TYPE = 0,
18
19 TRACE_FN,
20 TRACE_CTX,
21 TRACE_WAKE,
22 TRACE_STACK,
23 TRACE_PRINT,
24 TRACE_BPRINT,
25 TRACE_MMIO_RW,
26 TRACE_MMIO_MAP,
27 TRACE_BRANCH,
28 TRACE_GRAPH_RET,
29 TRACE_GRAPH_ENT,
30 TRACE_USER_STACK,
31 TRACE_BLK,
32
33 __TRACE_LAST_TYPE,
34};
35
36
37#undef __field
38#define __field(type, item) type item;
39
40#undef __field_struct
41#define __field_struct(type, item) __field(type, item)
42
43#undef __field_desc
44#define __field_desc(type, container, item)
45
46#undef __array
47#define __array(type, item, size) type item[size];
48
49#undef __array_desc
50#define __array_desc(type, container, item, size)
51
52#undef __dynamic_array
53#define __dynamic_array(type, item) type item[];
54
55#undef F_STRUCT
56#define F_STRUCT(args...) args
57
58#undef FTRACE_ENTRY
59#define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
60 struct struct_name { \
61 struct trace_entry ent; \
62 tstruct \
63 }
64
65#undef TP_ARGS
66#define TP_ARGS(args...) args
67
68#undef FTRACE_ENTRY_DUP
69#define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter)
70
71#undef FTRACE_ENTRY_REG
72#define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
73 filter, regfn) \
74 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
75 filter)
76
77#include "trace_entries.h"
78
79/*
80 * syscalls are special, and need special handling, this is why
81 * they are not included in trace_entries.h
82 */
83struct syscall_trace_enter {
84 struct trace_entry ent;
85 int nr;
86 unsigned long args[];
87};
88
89struct syscall_trace_exit {
90 struct trace_entry ent;
91 int nr;
92 long ret;
93};
94
95struct kprobe_trace_entry_head {
96 struct trace_entry ent;
97 unsigned long ip;
98};
99
100struct kretprobe_trace_entry_head {
101 struct trace_entry ent;
102 unsigned long func;
103 unsigned long ret_ip;
104};
105
106/*
107 * trace_flag_type is an enumeration that holds different
108 * states when a trace occurs. These are:
109 * IRQS_OFF - interrupts were disabled
110 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
111 * NEED_RESCHED - reschedule is requested
112 * HARDIRQ - inside an interrupt handler
113 * SOFTIRQ - inside a softirq handler
114 */
115enum trace_flag_type {
116 TRACE_FLAG_IRQS_OFF = 0x01,
117 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
118 TRACE_FLAG_NEED_RESCHED = 0x04,
119 TRACE_FLAG_HARDIRQ = 0x08,
120 TRACE_FLAG_SOFTIRQ = 0x10,
121};
122
123#define TRACE_BUF_SIZE 1024
124
125/*
126 * The CPU trace array - it consists of thousands of trace entries
127 * plus some other descriptor data: (for example which task started
128 * the trace, etc.)
129 */
130struct trace_array_cpu {
131 atomic_t disabled;
132 void *buffer_page; /* ring buffer spare */
133
134 unsigned long saved_latency;
135 unsigned long critical_start;
136 unsigned long critical_end;
137 unsigned long critical_sequence;
138 unsigned long nice;
139 unsigned long policy;
140 unsigned long rt_priority;
141 unsigned long skipped_entries;
142 cycle_t preempt_timestamp;
143 pid_t pid;
144 uid_t uid;
145 char comm[TASK_COMM_LEN];
146};
147
148/*
149 * The trace array - an array of per-CPU trace arrays. This is the
150 * highest level data structure that individual tracers deal with.
151 * They have on/off state as well:
152 */
153struct trace_array {
154 struct ring_buffer *buffer;
155 unsigned long entries;
156 int cpu;
157 int buffer_disabled;
158 cycle_t time_start;
159 struct task_struct *waiter;
160 struct trace_array_cpu *data[NR_CPUS];
161};
162
163#define FTRACE_CMP_TYPE(var, type) \
164 __builtin_types_compatible_p(typeof(var), type *)
165
166#undef IF_ASSIGN
167#define IF_ASSIGN(var, entry, etype, id) \
168 if (FTRACE_CMP_TYPE(var, etype)) { \
169 var = (typeof(var))(entry); \
170 WARN_ON(id && (entry)->type != id); \
171 break; \
172 }
173
174/* Will cause compile errors if type is not found. */
175extern void __ftrace_bad_type(void);
176
177/*
178 * The trace_assign_type is a verifier that the entry type is
179 * the same as the type being assigned. To add new types simply
180 * add a line with the following format:
181 *
182 * IF_ASSIGN(var, ent, type, id);
183 *
184 * Where "type" is the trace type that includes the trace_entry
185 * as the "ent" item. And "id" is the trace identifier that is
186 * used in the trace_type enum.
187 *
188 * If the type can have more than one id, then use zero.
189 */
190#define trace_assign_type(var, ent) \
191 do { \
192 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
193 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
194 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
195 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
196 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
197 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
198 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
199 TRACE_MMIO_RW); \
200 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
201 TRACE_MMIO_MAP); \
202 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
203 IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
204 TRACE_GRAPH_ENT); \
205 IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
206 TRACE_GRAPH_RET); \
207 __ftrace_bad_type(); \
208 } while (0)
209
210/*
211 * An option specific to a tracer. This is a boolean value.
212 * The bit is the bit index that sets its value on the
213 * flags value in struct tracer_flags.
214 */
215struct tracer_opt {
216 const char *name; /* Will appear on the trace_options file */
217 u32 bit; /* Mask assigned in val field in tracer_flags */
218};
219
220/*
221 * The set of specific options for a tracer. Your tracer
222 * have to set the initial value of the flags val.
223 */
224struct tracer_flags {
225 u32 val;
226 struct tracer_opt *opts;
227};
228
229/* Makes more easy to define a tracer opt */
230#define TRACER_OPT(s, b) .name = #s, .bit = b
231
232
233/**
234 * struct tracer - a specific tracer and its callbacks to interact with debugfs
235 * @name: the name chosen to select it on the available_tracers file
236 * @init: called when one switches to this tracer (echo name > current_tracer)
237 * @reset: called when one switches to another tracer
238 * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
239 * @stop: called when tracing is paused (echo 0 > tracing_enabled)
240 * @open: called when the trace file is opened
241 * @pipe_open: called when the trace_pipe file is opened
242 * @wait_pipe: override how the user waits for traces on trace_pipe
243 * @close: called when the trace file is released
244 * @pipe_close: called when the trace_pipe file is released
245 * @read: override the default read callback on trace_pipe
246 * @splice_read: override the default splice_read callback on trace_pipe
247 * @selftest: selftest to run on boot (see trace_selftest.c)
248 * @print_headers: override the first lines that describe your columns
249 * @print_line: callback that prints a trace
250 * @set_flag: signals one of your private flags changed (trace_options file)
251 * @flags: your private flags
252 */
253struct tracer {
254 const char *name;
255 int (*init)(struct trace_array *tr);
256 void (*reset)(struct trace_array *tr);
257 void (*start)(struct trace_array *tr);
258 void (*stop)(struct trace_array *tr);
259 void (*open)(struct trace_iterator *iter);
260 void (*pipe_open)(struct trace_iterator *iter);
261 void (*wait_pipe)(struct trace_iterator *iter);
262 void (*close)(struct trace_iterator *iter);
263 void (*pipe_close)(struct trace_iterator *iter);
264 ssize_t (*read)(struct trace_iterator *iter,
265 struct file *filp, char __user *ubuf,
266 size_t cnt, loff_t *ppos);
267 ssize_t (*splice_read)(struct trace_iterator *iter,
268 struct file *filp,
269 loff_t *ppos,
270 struct pipe_inode_info *pipe,
271 size_t len,
272 unsigned int flags);
273#ifdef CONFIG_FTRACE_STARTUP_TEST
274 int (*selftest)(struct tracer *trace,
275 struct trace_array *tr);
276#endif
277 void (*print_header)(struct seq_file *m);
278 enum print_line_t (*print_line)(struct trace_iterator *iter);
279 /* If you handled the flag setting, return 0 */
280 int (*set_flag)(u32 old_flags, u32 bit, int set);
281 /* Return 0 if OK with change, else return non-zero */
282 int (*flag_changed)(struct tracer *tracer,
283 u32 mask, int set);
284 struct tracer *next;
285 struct tracer_flags *flags;
286 int print_max;
287 int use_max_tr;
288 bool enabled;
289};
290
291
292/* Only current can touch trace_recursion */
293#define trace_recursion_inc() do { (current)->trace_recursion++; } while (0)
294#define trace_recursion_dec() do { (current)->trace_recursion--; } while (0)
295
296/* Ring buffer has the 10 LSB bits to count */
297#define trace_recursion_buffer() ((current)->trace_recursion & 0x3ff)
298
299/* for function tracing recursion */
300#define TRACE_INTERNAL_BIT (1<<11)
301#define TRACE_GLOBAL_BIT (1<<12)
302#define TRACE_CONTROL_BIT (1<<13)
303
304/*
305 * Abuse of the trace_recursion.
306 * As we need a way to maintain state if we are tracing the function
307 * graph in irq because we want to trace a particular function that
308 * was called in irq context but we have irq tracing off. Since this
309 * can only be modified by current, we can reuse trace_recursion.
310 */
311#define TRACE_IRQ_BIT (1<<13)
312
313#define trace_recursion_set(bit) do { (current)->trace_recursion |= (bit); } while (0)
314#define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(bit); } while (0)
315#define trace_recursion_test(bit) ((current)->trace_recursion & (bit))
316
317#define TRACE_PIPE_ALL_CPU -1
318
319int tracer_init(struct tracer *t, struct trace_array *tr);
320int tracing_is_enabled(void);
321void trace_wake_up(void);
322void tracing_reset(struct trace_array *tr, int cpu);
323void tracing_reset_online_cpus(struct trace_array *tr);
324void tracing_reset_current(int cpu);
325void tracing_reset_current_online_cpus(void);
326int tracing_open_generic(struct inode *inode, struct file *filp);
327struct dentry *trace_create_file(const char *name,
328 umode_t mode,
329 struct dentry *parent,
330 void *data,
331 const struct file_operations *fops);
332
333struct dentry *tracing_init_dentry(void);
334
335struct ring_buffer_event;
336
337struct ring_buffer_event *
338trace_buffer_lock_reserve(struct ring_buffer *buffer,
339 int type,
340 unsigned long len,
341 unsigned long flags,
342 int pc);
343void trace_buffer_unlock_commit(struct ring_buffer *buffer,
344 struct ring_buffer_event *event,
345 unsigned long flags, int pc);
346
347struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
348 struct trace_array_cpu *data);
349
350struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
351 int *ent_cpu, u64 *ent_ts);
352
353int trace_empty(struct trace_iterator *iter);
354
355void *trace_find_next_entry_inc(struct trace_iterator *iter);
356
357void trace_init_global_iter(struct trace_iterator *iter);
358
359void tracing_iter_reset(struct trace_iterator *iter, int cpu);
360
361void poll_wait_pipe(struct trace_iterator *iter);
362
363void ftrace(struct trace_array *tr,
364 struct trace_array_cpu *data,
365 unsigned long ip,
366 unsigned long parent_ip,
367 unsigned long flags, int pc);
368void tracing_sched_switch_trace(struct trace_array *tr,
369 struct task_struct *prev,
370 struct task_struct *next,
371 unsigned long flags, int pc);
372
373void tracing_sched_wakeup_trace(struct trace_array *tr,
374 struct task_struct *wakee,
375 struct task_struct *cur,
376 unsigned long flags, int pc);
377void trace_function(struct trace_array *tr,
378 unsigned long ip,
379 unsigned long parent_ip,
380 unsigned long flags, int pc);
381void trace_graph_function(struct trace_array *tr,
382 unsigned long ip,
383 unsigned long parent_ip,
384 unsigned long flags, int pc);
385void trace_latency_header(struct seq_file *m);
386void trace_default_header(struct seq_file *m);
387void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
388int trace_empty(struct trace_iterator *iter);
389
390void trace_graph_return(struct ftrace_graph_ret *trace);
391int trace_graph_entry(struct ftrace_graph_ent *trace);
392void set_graph_array(struct trace_array *tr);
393
394void tracing_start_cmdline_record(void);
395void tracing_stop_cmdline_record(void);
396void tracing_sched_switch_assign_trace(struct trace_array *tr);
397void tracing_stop_sched_switch_record(void);
398void tracing_start_sched_switch_record(void);
399int register_tracer(struct tracer *type);
400void unregister_tracer(struct tracer *type);
401int is_tracing_stopped(void);
402enum trace_file_type {
403 TRACE_FILE_LAT_FMT = 1,
404 TRACE_FILE_ANNOTATE = 2,
405};
406
407extern cpumask_var_t __read_mostly tracing_buffer_mask;
408
409#define for_each_tracing_cpu(cpu) \
410 for_each_cpu(cpu, tracing_buffer_mask)
411
412extern unsigned long nsecs_to_usecs(unsigned long nsecs);
413
414extern unsigned long tracing_thresh;
415
416#ifdef CONFIG_TRACER_MAX_TRACE
417extern unsigned long tracing_max_latency;
418
419void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
420void update_max_tr_single(struct trace_array *tr,
421 struct task_struct *tsk, int cpu);
422#endif /* CONFIG_TRACER_MAX_TRACE */
423
424#ifdef CONFIG_STACKTRACE
425void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
426 int skip, int pc);
427
428void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
429 int skip, int pc, struct pt_regs *regs);
430
431void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
432 int pc);
433
434void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
435 int pc);
436#else
437static inline void ftrace_trace_stack(struct ring_buffer *buffer,
438 unsigned long flags, int skip, int pc)
439{
440}
441
442static inline void ftrace_trace_stack_regs(struct ring_buffer *buffer,
443 unsigned long flags, int skip,
444 int pc, struct pt_regs *regs)
445{
446}
447
448static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
449 unsigned long flags, int pc)
450{
451}
452
453static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
454 int skip, int pc)
455{
456}
457#endif /* CONFIG_STACKTRACE */
458
459extern cycle_t ftrace_now(int cpu);
460
461extern void trace_find_cmdline(int pid, char comm[]);
462
463#ifdef CONFIG_DYNAMIC_FTRACE
464extern unsigned long ftrace_update_tot_cnt;
465#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
466extern int DYN_FTRACE_TEST_NAME(void);
467#define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
468extern int DYN_FTRACE_TEST_NAME2(void);
469#endif
470
471extern int ring_buffer_expanded;
472extern bool tracing_selftest_disabled;
473DECLARE_PER_CPU(int, ftrace_cpu_disabled);
474
475#ifdef CONFIG_FTRACE_STARTUP_TEST
476extern int trace_selftest_startup_function(struct tracer *trace,
477 struct trace_array *tr);
478extern int trace_selftest_startup_function_graph(struct tracer *trace,
479 struct trace_array *tr);
480extern int trace_selftest_startup_irqsoff(struct tracer *trace,
481 struct trace_array *tr);
482extern int trace_selftest_startup_preemptoff(struct tracer *trace,
483 struct trace_array *tr);
484extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
485 struct trace_array *tr);
486extern int trace_selftest_startup_wakeup(struct tracer *trace,
487 struct trace_array *tr);
488extern int trace_selftest_startup_nop(struct tracer *trace,
489 struct trace_array *tr);
490extern int trace_selftest_startup_sched_switch(struct tracer *trace,
491 struct trace_array *tr);
492extern int trace_selftest_startup_branch(struct tracer *trace,
493 struct trace_array *tr);
494#endif /* CONFIG_FTRACE_STARTUP_TEST */
495
496extern void *head_page(struct trace_array_cpu *data);
497extern unsigned long long ns2usecs(cycle_t nsec);
498extern int
499trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
500extern int
501trace_vprintk(unsigned long ip, const char *fmt, va_list args);
502extern int
503trace_array_vprintk(struct trace_array *tr,
504 unsigned long ip, const char *fmt, va_list args);
505int trace_array_printk(struct trace_array *tr,
506 unsigned long ip, const char *fmt, ...);
507void trace_printk_seq(struct trace_seq *s);
508enum print_line_t print_trace_line(struct trace_iterator *iter);
509
510extern unsigned long trace_flags;
511
512extern int trace_clock_id;
513
514/* Standard output formatting function used for function return traces */
515#ifdef CONFIG_FUNCTION_GRAPH_TRACER
516
517/* Flag options */
518#define TRACE_GRAPH_PRINT_OVERRUN 0x1
519#define TRACE_GRAPH_PRINT_CPU 0x2
520#define TRACE_GRAPH_PRINT_OVERHEAD 0x4
521#define TRACE_GRAPH_PRINT_PROC 0x8
522#define TRACE_GRAPH_PRINT_DURATION 0x10
523#define TRACE_GRAPH_PRINT_ABS_TIME 0x20
524
525extern enum print_line_t
526print_graph_function_flags(struct trace_iterator *iter, u32 flags);
527extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
528extern enum print_line_t
529trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
530extern void graph_trace_open(struct trace_iterator *iter);
531extern void graph_trace_close(struct trace_iterator *iter);
532extern int __trace_graph_entry(struct trace_array *tr,
533 struct ftrace_graph_ent *trace,
534 unsigned long flags, int pc);
535extern void __trace_graph_return(struct trace_array *tr,
536 struct ftrace_graph_ret *trace,
537 unsigned long flags, int pc);
538
539
540#ifdef CONFIG_DYNAMIC_FTRACE
541/* TODO: make this variable */
542#define FTRACE_GRAPH_MAX_FUNCS 32
543extern int ftrace_graph_filter_enabled;
544extern int ftrace_graph_count;
545extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
546
547static inline int ftrace_graph_addr(unsigned long addr)
548{
549 int i;
550
551 if (!ftrace_graph_filter_enabled)
552 return 1;
553
554 for (i = 0; i < ftrace_graph_count; i++) {
555 if (addr == ftrace_graph_funcs[i]) {
556 /*
557 * If no irqs are to be traced, but a set_graph_function
558 * is set, and called by an interrupt handler, we still
559 * want to trace it.
560 */
561 if (in_irq())
562 trace_recursion_set(TRACE_IRQ_BIT);
563 else
564 trace_recursion_clear(TRACE_IRQ_BIT);
565 return 1;
566 }
567 }
568
569 return 0;
570}
571#else
572static inline int ftrace_graph_addr(unsigned long addr)
573{
574 return 1;
575}
576#endif /* CONFIG_DYNAMIC_FTRACE */
577#else /* CONFIG_FUNCTION_GRAPH_TRACER */
578static inline enum print_line_t
579print_graph_function_flags(struct trace_iterator *iter, u32 flags)
580{
581 return TRACE_TYPE_UNHANDLED;
582}
583#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
584
585extern struct list_head ftrace_pids;
586
587#ifdef CONFIG_FUNCTION_TRACER
588static inline int ftrace_trace_task(struct task_struct *task)
589{
590 if (list_empty(&ftrace_pids))
591 return 1;
592
593 return test_tsk_trace_trace(task);
594}
595extern int ftrace_is_dead(void);
596#else
597static inline int ftrace_trace_task(struct task_struct *task)
598{
599 return 1;
600}
601static inline int ftrace_is_dead(void) { return 0; }
602#endif
603
604int ftrace_event_is_function(struct ftrace_event_call *call);
605
606/*
607 * struct trace_parser - servers for reading the user input separated by spaces
608 * @cont: set if the input is not complete - no final space char was found
609 * @buffer: holds the parsed user input
610 * @idx: user input length
611 * @size: buffer size
612 */
613struct trace_parser {
614 bool cont;
615 char *buffer;
616 unsigned idx;
617 unsigned size;
618};
619
620static inline bool trace_parser_loaded(struct trace_parser *parser)
621{
622 return (parser->idx != 0);
623}
624
625static inline bool trace_parser_cont(struct trace_parser *parser)
626{
627 return parser->cont;
628}
629
630static inline void trace_parser_clear(struct trace_parser *parser)
631{
632 parser->cont = false;
633 parser->idx = 0;
634}
635
636extern int trace_parser_get_init(struct trace_parser *parser, int size);
637extern void trace_parser_put(struct trace_parser *parser);
638extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
639 size_t cnt, loff_t *ppos);
640
641/*
642 * trace_iterator_flags is an enumeration that defines bit
643 * positions into trace_flags that controls the output.
644 *
645 * NOTE: These bits must match the trace_options array in
646 * trace.c.
647 */
648enum trace_iterator_flags {
649 TRACE_ITER_PRINT_PARENT = 0x01,
650 TRACE_ITER_SYM_OFFSET = 0x02,
651 TRACE_ITER_SYM_ADDR = 0x04,
652 TRACE_ITER_VERBOSE = 0x08,
653 TRACE_ITER_RAW = 0x10,
654 TRACE_ITER_HEX = 0x20,
655 TRACE_ITER_BIN = 0x40,
656 TRACE_ITER_BLOCK = 0x80,
657 TRACE_ITER_STACKTRACE = 0x100,
658 TRACE_ITER_PRINTK = 0x200,
659 TRACE_ITER_PREEMPTONLY = 0x400,
660 TRACE_ITER_BRANCH = 0x800,
661 TRACE_ITER_ANNOTATE = 0x1000,
662 TRACE_ITER_USERSTACKTRACE = 0x2000,
663 TRACE_ITER_SYM_USEROBJ = 0x4000,
664 TRACE_ITER_PRINTK_MSGONLY = 0x8000,
665 TRACE_ITER_CONTEXT_INFO = 0x10000, /* Print pid/cpu/time */
666 TRACE_ITER_LATENCY_FMT = 0x20000,
667 TRACE_ITER_SLEEP_TIME = 0x40000,
668 TRACE_ITER_GRAPH_TIME = 0x80000,
669 TRACE_ITER_RECORD_CMD = 0x100000,
670 TRACE_ITER_OVERWRITE = 0x200000,
671 TRACE_ITER_STOP_ON_FREE = 0x400000,
672 TRACE_ITER_IRQ_INFO = 0x800000,
673};
674
675/*
676 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
677 * control the output of kernel symbols.
678 */
679#define TRACE_ITER_SYM_MASK \
680 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
681
682extern struct tracer nop_trace;
683
684#ifdef CONFIG_BRANCH_TRACER
685extern int enable_branch_tracing(struct trace_array *tr);
686extern void disable_branch_tracing(void);
687static inline int trace_branch_enable(struct trace_array *tr)
688{
689 if (trace_flags & TRACE_ITER_BRANCH)
690 return enable_branch_tracing(tr);
691 return 0;
692}
693static inline void trace_branch_disable(void)
694{
695 /* due to races, always disable */
696 disable_branch_tracing();
697}
698#else
699static inline int trace_branch_enable(struct trace_array *tr)
700{
701 return 0;
702}
703static inline void trace_branch_disable(void)
704{
705}
706#endif /* CONFIG_BRANCH_TRACER */
707
708/* set ring buffers to default size if not already done so */
709int tracing_update_buffers(void);
710
711/* trace event type bit fields, not numeric */
712enum {
713 TRACE_EVENT_TYPE_PRINTF = 1,
714 TRACE_EVENT_TYPE_RAW = 2,
715};
716
717struct ftrace_event_field {
718 struct list_head link;
719 char *name;
720 char *type;
721 int filter_type;
722 int offset;
723 int size;
724 int is_signed;
725};
726
727struct event_filter {
728 int n_preds; /* Number assigned */
729 int a_preds; /* allocated */
730 struct filter_pred *preds;
731 struct filter_pred *root;
732 char *filter_string;
733};
734
735struct event_subsystem {
736 struct list_head list;
737 const char *name;
738 struct dentry *entry;
739 struct event_filter *filter;
740 int nr_events;
741 int ref_count;
742};
743
744#define FILTER_PRED_INVALID ((unsigned short)-1)
745#define FILTER_PRED_IS_RIGHT (1 << 15)
746#define FILTER_PRED_FOLD (1 << 15)
747
748/*
749 * The max preds is the size of unsigned short with
750 * two flags at the MSBs. One bit is used for both the IS_RIGHT
751 * and FOLD flags. The other is reserved.
752 *
753 * 2^14 preds is way more than enough.
754 */
755#define MAX_FILTER_PRED 16384
756
757struct filter_pred;
758struct regex;
759
760typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
761
762typedef int (*regex_match_func)(char *str, struct regex *r, int len);
763
764enum regex_type {
765 MATCH_FULL = 0,
766 MATCH_FRONT_ONLY,
767 MATCH_MIDDLE_ONLY,
768 MATCH_END_ONLY,
769};
770
771struct regex {
772 char pattern[MAX_FILTER_STR_VAL];
773 int len;
774 int field_len;
775 regex_match_func match;
776};
777
778struct filter_pred {
779 filter_pred_fn_t fn;
780 u64 val;
781 struct regex regex;
782 unsigned short *ops;
783 struct ftrace_event_field *field;
784 int offset;
785 int not;
786 int op;
787 unsigned short index;
788 unsigned short parent;
789 unsigned short left;
790 unsigned short right;
791};
792
793extern struct list_head ftrace_common_fields;
794
795extern enum regex_type
796filter_parse_regex(char *buff, int len, char **search, int *not);
797extern void print_event_filter(struct ftrace_event_call *call,
798 struct trace_seq *s);
799extern int apply_event_filter(struct ftrace_event_call *call,
800 char *filter_string);
801extern int apply_subsystem_event_filter(struct event_subsystem *system,
802 char *filter_string);
803extern void print_subsystem_event_filter(struct event_subsystem *system,
804 struct trace_seq *s);
805extern int filter_assign_type(const char *type);
806
807struct list_head *
808trace_get_fields(struct ftrace_event_call *event_call);
809
810static inline int
811filter_check_discard(struct ftrace_event_call *call, void *rec,
812 struct ring_buffer *buffer,
813 struct ring_buffer_event *event)
814{
815 if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
816 !filter_match_preds(call->filter, rec)) {
817 ring_buffer_discard_commit(buffer, event);
818 return 1;
819 }
820
821 return 0;
822}
823
824extern void trace_event_enable_cmd_record(bool enable);
825
826extern struct mutex event_mutex;
827extern struct list_head ftrace_events;
828
829extern const char *__start___trace_bprintk_fmt[];
830extern const char *__stop___trace_bprintk_fmt[];
831
832int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
833int set_tracer_flag(unsigned int mask, int enabled);
834
835#undef FTRACE_ENTRY
836#define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
837 extern struct ftrace_event_call \
838 __attribute__((__aligned__(4))) event_##call;
839#undef FTRACE_ENTRY_DUP
840#define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
841 FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
842 filter)
843#include "trace_entries.h"
844
845#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
846int perf_ftrace_event_register(struct ftrace_event_call *call,
847 enum trace_reg type, void *data);
848#else
849#define perf_ftrace_event_register NULL
850#endif
851
852#endif /* _LINUX_KERNEL_TRACE_H */