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