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