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