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