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