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