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