Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ring buffer based function tracer |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> |
| 6 | * |
| 7 | * Originally taken from the RT patch by: |
| 8 | * Arnaldo Carvalho de Melo <acme@redhat.com> |
| 9 | * |
| 10 | * Based on code from the latency_tracer, that is: |
| 11 | * Copyright (C) 2004-2006 Ingo Molnar |
| 12 | * Copyright (C) 2004 William Lee Irwin III |
| 13 | */ |
| 14 | #include <linux/utsrelease.h> |
| 15 | #include <linux/kallsyms.h> |
| 16 | #include <linux/seq_file.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 17 | #include <linux/notifier.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 18 | #include <linux/debugfs.h> |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 19 | #include <linux/pagemap.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 20 | #include <linux/hardirq.h> |
| 21 | #include <linux/linkage.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <linux/ftrace.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/percpu.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 26 | #include <linux/kdebug.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 27 | #include <linux/ctype.h> |
| 28 | #include <linux/init.h> |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 29 | #include <linux/poll.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 30 | #include <linux/gfp.h> |
| 31 | #include <linux/fs.h> |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 32 | #include <linux/kprobes.h> |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 33 | #include <linux/writeback.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 34 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 35 | #include <linux/stacktrace.h> |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 36 | #include <linux/ring_buffer.h> |
Frederic Weisbecker | 21798a8 | 2008-10-28 09:43:26 +0100 | [diff] [blame] | 37 | #include <linux/irqflags.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 38 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 39 | #include "trace.h" |
| 40 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 41 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
| 42 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX; |
| 44 | unsigned long __read_mostly tracing_thresh; |
| 45 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 46 | /* For tracers that don't implement custom flags */ |
| 47 | static struct tracer_opt dummy_tracer_opt[] = { |
| 48 | { } |
| 49 | }; |
| 50 | |
| 51 | static struct tracer_flags dummy_tracer_flags = { |
| 52 | .val = 0, |
| 53 | .opts = dummy_tracer_opt |
| 54 | }; |
| 55 | |
| 56 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * Kill all tracing for good (never come back). |
| 63 | * It is initialized to 1 but will turn to zero if the initialization |
| 64 | * of the tracer is successful. But that is the only place that sets |
| 65 | * this back to zero. |
| 66 | */ |
| 67 | int tracing_disabled = 1; |
| 68 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 69 | static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); |
| 70 | |
| 71 | static inline void ftrace_disable_cpu(void) |
| 72 | { |
| 73 | preempt_disable(); |
| 74 | local_inc(&__get_cpu_var(ftrace_cpu_disabled)); |
| 75 | } |
| 76 | |
| 77 | static inline void ftrace_enable_cpu(void) |
| 78 | { |
| 79 | local_dec(&__get_cpu_var(ftrace_cpu_disabled)); |
| 80 | preempt_enable(); |
| 81 | } |
| 82 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 83 | static cpumask_t __read_mostly tracing_buffer_mask; |
| 84 | |
| 85 | #define for_each_tracing_cpu(cpu) \ |
| 86 | for_each_cpu_mask(cpu, tracing_buffer_mask) |
| 87 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 88 | /* |
| 89 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 90 | * |
| 91 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 92 | * is set, then ftrace_dump is called. This will output the contents |
| 93 | * of the ftrace buffers to the console. This is very useful for |
| 94 | * capturing traces that lead to crashes and outputing it to a |
| 95 | * serial console. |
| 96 | * |
| 97 | * It is default off, but you can enable it with either specifying |
| 98 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
| 99 | * /proc/sys/kernel/ftrace_dump_on_oops to true. |
| 100 | */ |
| 101 | int ftrace_dump_on_oops; |
| 102 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 103 | static int tracing_set_tracer(char *buf); |
| 104 | |
| 105 | static int __init set_ftrace(char *str) |
| 106 | { |
| 107 | tracing_set_tracer(str); |
| 108 | return 1; |
| 109 | } |
| 110 | __setup("ftrace", set_ftrace); |
| 111 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 112 | static int __init set_ftrace_dump_on_oops(char *str) |
| 113 | { |
| 114 | ftrace_dump_on_oops = 1; |
| 115 | return 1; |
| 116 | } |
| 117 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
| 118 | |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 119 | long |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 120 | ns2usecs(cycle_t nsec) |
| 121 | { |
| 122 | nsec += 500; |
| 123 | do_div(nsec, 1000); |
| 124 | return nsec; |
| 125 | } |
| 126 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 127 | cycle_t ftrace_now(int cpu) |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 128 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 129 | u64 ts = ring_buffer_time_stamp(cpu); |
| 130 | ring_buffer_normalize_time_stamp(cpu, &ts); |
| 131 | return ts; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 134 | /* |
| 135 | * The global_trace is the descriptor that holds the tracing |
| 136 | * buffers for the live tracing. For each CPU, it contains |
| 137 | * a link list of pages that will store trace entries. The |
| 138 | * page descriptor of the pages in the memory is used to hold |
| 139 | * the link list by linking the lru item in the page descriptor |
| 140 | * to each of the pages in the buffer per CPU. |
| 141 | * |
| 142 | * For each active CPU there is a data field that holds the |
| 143 | * pages for the buffer for that CPU. Each CPU has the same number |
| 144 | * of pages allocated for its buffer. |
| 145 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 146 | static struct trace_array global_trace; |
| 147 | |
| 148 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
| 149 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 150 | /* |
| 151 | * The max_tr is used to snapshot the global_trace when a maximum |
| 152 | * latency is reached. Some tracers will use this to store a maximum |
| 153 | * trace while it continues examining live traces. |
| 154 | * |
| 155 | * The buffers for the max_tr are set up the same as the global_trace. |
| 156 | * When a snapshot is taken, the link list of the max_tr is swapped |
| 157 | * with the link list of the global_trace and the buffers are reset for |
| 158 | * the global_trace so the tracing can continue. |
| 159 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 160 | static struct trace_array max_tr; |
| 161 | |
| 162 | static DEFINE_PER_CPU(struct trace_array_cpu, max_data); |
| 163 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 164 | /* tracer_enabled is used to toggle activation of a tracer */ |
Steven Rostedt | 26994ea | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 165 | static int tracer_enabled = 1; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 166 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 167 | /** |
| 168 | * tracing_is_enabled - return tracer_enabled status |
| 169 | * |
| 170 | * This function is used by other tracers to know the status |
| 171 | * of the tracer_enabled flag. Tracers may use this function |
| 172 | * to know if it should enable their features when starting |
| 173 | * up. See irqsoff tracer for an example (start_irqsoff_tracer). |
| 174 | */ |
| 175 | int tracing_is_enabled(void) |
| 176 | { |
| 177 | return tracer_enabled; |
| 178 | } |
| 179 | |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 180 | /* function tracing enabled */ |
| 181 | int ftrace_function_enabled; |
| 182 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 183 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 184 | * trace_buf_size is the size in bytes that is allocated |
| 185 | * for a buffer. Note, the number of bytes is always rounded |
| 186 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 187 | * |
| 188 | * This number is purposely set to a low number of 16384. |
| 189 | * If the dump on oops happens, it will be much appreciated |
| 190 | * to not have to wait for all that output. Anyway this can be |
| 191 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 192 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 193 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 194 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 195 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 196 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 197 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 198 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 199 | |
| 200 | /* current_trace points to the tracer that is currently active */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 201 | static struct tracer *current_trace __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * max_tracer_type_len is used to simplify the allocating of |
| 205 | * buffers to read userspace tracer names. We keep track of |
| 206 | * the longest tracer name registered. |
| 207 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 208 | static int max_tracer_type_len; |
| 209 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 210 | /* |
| 211 | * trace_types_lock is used to protect the trace_types list. |
| 212 | * This lock is also used to keep user access serialized. |
| 213 | * Accesses from userspace will grab this lock while userspace |
| 214 | * activities happen inside the kernel. |
| 215 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 216 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 217 | |
| 218 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 219 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
| 220 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 221 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 222 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
| 223 | TRACE_ITER_ANNOTATE; |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 224 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 225 | /** |
| 226 | * trace_wake_up - wake up tasks waiting for trace input |
| 227 | * |
| 228 | * Simply wakes up any task that is blocked on the trace_wait |
| 229 | * queue. These is used with trace_poll for tasks polling the trace. |
| 230 | */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 231 | void trace_wake_up(void) |
| 232 | { |
Ingo Molnar | 017730c | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 233 | /* |
| 234 | * The runqueue_is_locked() can fail, but this is the best we |
| 235 | * have for now: |
| 236 | */ |
| 237 | if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked()) |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 238 | wake_up(&trace_wait); |
| 239 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 240 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 241 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 242 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 243 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 244 | int ret; |
| 245 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 246 | if (!str) |
| 247 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 248 | ret = strict_strtoul(str, 0, &buf_size); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 249 | /* nr_entries can not be zero */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 250 | if (ret < 0 || buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 251 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 252 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 253 | return 1; |
| 254 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 255 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 256 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 257 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 258 | { |
| 259 | return nsecs / 1000; |
| 260 | } |
| 261 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 262 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 263 | static const char *trace_options[] = { |
| 264 | "print-parent", |
| 265 | "sym-offset", |
| 266 | "sym-addr", |
| 267 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 268 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 269 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 270 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 271 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 272 | "stacktrace", |
Ingo Molnar | 4ac3ba4 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 273 | "sched-tree", |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 274 | "ftrace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 275 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 276 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 277 | "annotate", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 278 | NULL |
| 279 | }; |
| 280 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 281 | /* |
| 282 | * ftrace_max_lock is used to protect the swapping of buffers |
| 283 | * when taking a max snapshot. The buffers themselves are |
| 284 | * protected by per_cpu spinlocks. But the action of the swap |
| 285 | * needs its own lock. |
| 286 | * |
| 287 | * This is defined as a raw_spinlock_t in order to help |
| 288 | * with performance when lockdep debugging is enabled. |
| 289 | */ |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 290 | static raw_spinlock_t ftrace_max_lock = |
| 291 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Copy the new maximum trace into the separate maximum-trace |
| 295 | * structure. (this way the maximum trace is permanently saved, |
| 296 | * for later retrieval via /debugfs/tracing/latency_trace) |
| 297 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 298 | static void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 299 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 300 | { |
| 301 | struct trace_array_cpu *data = tr->data[cpu]; |
| 302 | |
| 303 | max_tr.cpu = cpu; |
| 304 | max_tr.time_start = data->preempt_timestamp; |
| 305 | |
| 306 | data = max_tr.data[cpu]; |
| 307 | data->saved_latency = tracing_max_latency; |
| 308 | |
| 309 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); |
| 310 | data->pid = tsk->pid; |
| 311 | data->uid = tsk->uid; |
| 312 | data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 313 | data->policy = tsk->policy; |
| 314 | data->rt_priority = tsk->rt_priority; |
| 315 | |
| 316 | /* record this tasks comm */ |
| 317 | tracing_record_cmdline(current); |
| 318 | } |
| 319 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 320 | /** |
| 321 | * trace_seq_printf - sequence printing of trace information |
| 322 | * @s: trace sequence descriptor |
| 323 | * @fmt: printf format string |
| 324 | * |
| 325 | * The tracer may use either sequence operations or its own |
| 326 | * copy to user routines. To simplify formating of a trace |
| 327 | * trace_seq_printf is used to store strings into a special |
| 328 | * buffer (@s). Then the output may be either used by |
| 329 | * the sequencer or pulled into another buffer. |
| 330 | */ |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 331 | int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 332 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) |
| 333 | { |
| 334 | int len = (PAGE_SIZE - 1) - s->len; |
| 335 | va_list ap; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 336 | int ret; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 337 | |
| 338 | if (!len) |
| 339 | return 0; |
| 340 | |
| 341 | va_start(ap, fmt); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 342 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 343 | va_end(ap); |
| 344 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 345 | /* If we can't write it all, don't bother writing anything */ |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 346 | if (ret >= len) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 347 | return 0; |
| 348 | |
| 349 | s->len += ret; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 350 | |
| 351 | return len; |
| 352 | } |
| 353 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 354 | /** |
| 355 | * trace_seq_puts - trace sequence printing of simple string |
| 356 | * @s: trace sequence descriptor |
| 357 | * @str: simple string to record |
| 358 | * |
| 359 | * The tracer may use either the sequence operations or its own |
| 360 | * copy to user routines. This function records a simple string |
| 361 | * into a special buffer (@s) for later retrieval by a sequencer |
| 362 | * or other mechanism. |
| 363 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 364 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 365 | trace_seq_puts(struct trace_seq *s, const char *str) |
| 366 | { |
| 367 | int len = strlen(str); |
| 368 | |
| 369 | if (len > ((PAGE_SIZE - 1) - s->len)) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 370 | return 0; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 371 | |
| 372 | memcpy(s->buffer + s->len, str, len); |
| 373 | s->len += len; |
| 374 | |
| 375 | return len; |
| 376 | } |
| 377 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 378 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 379 | trace_seq_putc(struct trace_seq *s, unsigned char c) |
| 380 | { |
| 381 | if (s->len >= (PAGE_SIZE - 1)) |
| 382 | return 0; |
| 383 | |
| 384 | s->buffer[s->len++] = c; |
| 385 | |
| 386 | return 1; |
| 387 | } |
| 388 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 389 | static int |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 390 | trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) |
| 391 | { |
| 392 | if (len > ((PAGE_SIZE - 1) - s->len)) |
| 393 | return 0; |
| 394 | |
| 395 | memcpy(s->buffer + s->len, mem, len); |
| 396 | s->len += len; |
| 397 | |
| 398 | return len; |
| 399 | } |
| 400 | |
Harvey Harrison | ad0a3b6 | 2008-10-08 17:44:55 -0700 | [diff] [blame] | 401 | #define MAX_MEMHEX_BYTES 8 |
| 402 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 403 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 404 | static int |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 405 | trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) |
| 406 | { |
| 407 | unsigned char hex[HEX_CHARS]; |
Thomas Gleixner | 93dcc6e | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 408 | unsigned char *data = mem; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 409 | int i, j; |
| 410 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 411 | #ifdef __BIG_ENDIAN |
| 412 | for (i = 0, j = 0; i < len; i++) { |
| 413 | #else |
| 414 | for (i = len-1, j = 0; i >= 0; i--) { |
| 415 | #endif |
Harvey Harrison | 2fbc474 | 2008-10-08 16:51:49 -0700 | [diff] [blame] | 416 | hex[j++] = hex_asc_hi(data[i]); |
| 417 | hex[j++] = hex_asc_lo(data[i]); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 418 | } |
Thomas Gleixner | 93dcc6e | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 419 | hex[j++] = ' '; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 420 | |
| 421 | return trace_seq_putmem(s, hex, j); |
| 422 | } |
| 423 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 424 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 425 | trace_seq_reset(struct trace_seq *s) |
| 426 | { |
| 427 | s->len = 0; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 428 | s->readpos = 0; |
| 429 | } |
| 430 | |
| 431 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 432 | { |
| 433 | int len; |
| 434 | int ret; |
| 435 | |
| 436 | if (s->len <= s->readpos) |
| 437 | return -EBUSY; |
| 438 | |
| 439 | len = s->len - s->readpos; |
| 440 | if (cnt > len) |
| 441 | cnt = len; |
| 442 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
| 443 | if (ret) |
| 444 | return -EFAULT; |
| 445 | |
| 446 | s->readpos += len; |
| 447 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 448 | } |
| 449 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 450 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 451 | trace_print_seq(struct seq_file *m, struct trace_seq *s) |
| 452 | { |
| 453 | int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len; |
| 454 | |
| 455 | s->buffer[len] = 0; |
| 456 | seq_puts(m, s->buffer); |
| 457 | |
| 458 | trace_seq_reset(s); |
| 459 | } |
| 460 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 461 | /** |
| 462 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 463 | * @tr: tracer |
| 464 | * @tsk: the task with the latency |
| 465 | * @cpu: The cpu that initiated the trace. |
| 466 | * |
| 467 | * Flip the buffers between the @tr and the max_tr and record information |
| 468 | * about which task was the cause of this latency. |
| 469 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 470 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 471 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 472 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 473 | struct ring_buffer *buf = tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 474 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 475 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 476 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 477 | |
| 478 | tr->buffer = max_tr.buffer; |
| 479 | max_tr.buffer = buf; |
| 480 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 481 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 482 | ring_buffer_reset(tr->buffer); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 483 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 484 | |
| 485 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 486 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
| 490 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 491 | * @tr - tracer |
| 492 | * @tsk - task with the latency |
| 493 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 494 | * |
| 495 | * Flip the trace of a single CPU buffer between the @tr and the max_tr. |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 496 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 497 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 498 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 499 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 500 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 501 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 502 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 503 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 504 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 505 | ftrace_disable_cpu(); |
| 506 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 507 | ring_buffer_reset(max_tr.buffer); |
| 508 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
| 509 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 510 | ftrace_enable_cpu(); |
| 511 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 512 | WARN_ON_ONCE(ret); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 513 | |
| 514 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 515 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 518 | /** |
| 519 | * register_tracer - register a tracer with the ftrace system. |
| 520 | * @type - the plugin for the tracer |
| 521 | * |
| 522 | * Register a new plugin tracer. |
| 523 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 524 | int register_tracer(struct tracer *type) |
| 525 | { |
| 526 | struct tracer *t; |
| 527 | int len; |
| 528 | int ret = 0; |
| 529 | |
| 530 | if (!type->name) { |
| 531 | pr_info("Tracer must have a name\n"); |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | mutex_lock(&trace_types_lock); |
| 536 | for (t = trace_types; t; t = t->next) { |
| 537 | if (strcmp(type->name, t->name) == 0) { |
| 538 | /* already found */ |
| 539 | pr_info("Trace %s already registered\n", |
| 540 | type->name); |
| 541 | ret = -1; |
| 542 | goto out; |
| 543 | } |
| 544 | } |
| 545 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 546 | if (!type->set_flag) |
| 547 | type->set_flag = &dummy_set_flag; |
| 548 | if (!type->flags) |
| 549 | type->flags = &dummy_tracer_flags; |
| 550 | else |
| 551 | if (!type->flags->opts) |
| 552 | type->flags->opts = dummy_tracer_opt; |
| 553 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 554 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 555 | if (type->selftest) { |
| 556 | struct tracer *saved_tracer = current_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 557 | struct trace_array *tr = &global_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 558 | int i; |
| 559 | /* |
| 560 | * Run a selftest on this tracer. |
| 561 | * Here we reset the trace buffer, and set the current |
| 562 | * tracer to be this tracer. The tracer can then run some |
| 563 | * internal tracing to verify that everything is in order. |
| 564 | * If we fail, we do not register this tracer. |
| 565 | */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 566 | for_each_tracing_cpu(i) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 567 | tracing_reset(tr, i); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 568 | } |
| 569 | current_trace = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 570 | /* the test is responsible for initializing and enabling */ |
| 571 | pr_info("Testing tracer %s: ", type->name); |
| 572 | ret = type->selftest(type, tr); |
| 573 | /* the test is responsible for resetting too */ |
| 574 | current_trace = saved_tracer; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 575 | if (ret) { |
| 576 | printk(KERN_CONT "FAILED!\n"); |
| 577 | goto out; |
| 578 | } |
Steven Rostedt | 1d4db00 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 579 | /* Only reset on passing, to avoid touching corrupted buffers */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 580 | for_each_tracing_cpu(i) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 581 | tracing_reset(tr, i); |
Steven Rostedt | 1d4db00 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 582 | } |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 583 | printk(KERN_CONT "PASSED\n"); |
| 584 | } |
| 585 | #endif |
| 586 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 587 | type->next = trace_types; |
| 588 | trace_types = type; |
| 589 | len = strlen(type->name); |
| 590 | if (len > max_tracer_type_len) |
| 591 | max_tracer_type_len = len; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 592 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 593 | out: |
| 594 | mutex_unlock(&trace_types_lock); |
| 595 | |
| 596 | return ret; |
| 597 | } |
| 598 | |
| 599 | void unregister_tracer(struct tracer *type) |
| 600 | { |
| 601 | struct tracer **t; |
| 602 | int len; |
| 603 | |
| 604 | mutex_lock(&trace_types_lock); |
| 605 | for (t = &trace_types; *t; t = &(*t)->next) { |
| 606 | if (*t == type) |
| 607 | goto found; |
| 608 | } |
| 609 | pr_info("Trace %s not registered\n", type->name); |
| 610 | goto out; |
| 611 | |
| 612 | found: |
| 613 | *t = (*t)->next; |
| 614 | if (strlen(type->name) != max_tracer_type_len) |
| 615 | goto out; |
| 616 | |
| 617 | max_tracer_type_len = 0; |
| 618 | for (t = &trace_types; *t; t = &(*t)->next) { |
| 619 | len = strlen((*t)->name); |
| 620 | if (len > max_tracer_type_len) |
| 621 | max_tracer_type_len = len; |
| 622 | } |
| 623 | out: |
| 624 | mutex_unlock(&trace_types_lock); |
| 625 | } |
| 626 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 627 | void tracing_reset(struct trace_array *tr, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 628 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 629 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 630 | ring_buffer_reset_cpu(tr->buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 631 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 632 | } |
| 633 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 634 | #define SAVED_CMDLINES 128 |
| 635 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 636 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 637 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 638 | static int cmdline_idx; |
| 639 | static DEFINE_SPINLOCK(trace_cmdline_lock); |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 640 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 641 | /* temporary disable recording */ |
| 642 | atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 643 | |
| 644 | static void trace_init_cmdlines(void) |
| 645 | { |
| 646 | memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline)); |
| 647 | memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid)); |
| 648 | cmdline_idx = 0; |
| 649 | } |
| 650 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 651 | static int trace_stop_count; |
| 652 | static DEFINE_SPINLOCK(tracing_start_lock); |
| 653 | |
| 654 | /** |
| 655 | * tracing_start - quick start of the tracer |
| 656 | * |
| 657 | * If tracing is enabled but was stopped by tracing_stop, |
| 658 | * this will start the tracer back up. |
| 659 | */ |
| 660 | void tracing_start(void) |
| 661 | { |
| 662 | struct ring_buffer *buffer; |
| 663 | unsigned long flags; |
| 664 | |
| 665 | if (tracing_disabled) |
| 666 | return; |
| 667 | |
| 668 | spin_lock_irqsave(&tracing_start_lock, flags); |
| 669 | if (--trace_stop_count) |
| 670 | goto out; |
| 671 | |
| 672 | if (trace_stop_count < 0) { |
| 673 | /* Someone screwed up their debugging */ |
| 674 | WARN_ON_ONCE(1); |
| 675 | trace_stop_count = 0; |
| 676 | goto out; |
| 677 | } |
| 678 | |
| 679 | |
| 680 | buffer = global_trace.buffer; |
| 681 | if (buffer) |
| 682 | ring_buffer_record_enable(buffer); |
| 683 | |
| 684 | buffer = max_tr.buffer; |
| 685 | if (buffer) |
| 686 | ring_buffer_record_enable(buffer); |
| 687 | |
| 688 | ftrace_start(); |
| 689 | out: |
| 690 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * tracing_stop - quick stop of the tracer |
| 695 | * |
| 696 | * Light weight way to stop tracing. Use in conjunction with |
| 697 | * tracing_start. |
| 698 | */ |
| 699 | void tracing_stop(void) |
| 700 | { |
| 701 | struct ring_buffer *buffer; |
| 702 | unsigned long flags; |
| 703 | |
| 704 | ftrace_stop(); |
| 705 | spin_lock_irqsave(&tracing_start_lock, flags); |
| 706 | if (trace_stop_count++) |
| 707 | goto out; |
| 708 | |
| 709 | buffer = global_trace.buffer; |
| 710 | if (buffer) |
| 711 | ring_buffer_record_disable(buffer); |
| 712 | |
| 713 | buffer = max_tr.buffer; |
| 714 | if (buffer) |
| 715 | ring_buffer_record_disable(buffer); |
| 716 | |
| 717 | out: |
| 718 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 719 | } |
| 720 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 721 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 722 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 723 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 724 | { |
| 725 | unsigned map; |
| 726 | unsigned idx; |
| 727 | |
| 728 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 729 | return; |
| 730 | |
| 731 | /* |
| 732 | * It's not the end of the world if we don't get |
| 733 | * the lock, but we also don't want to spin |
| 734 | * nor do we want to disable interrupts, |
| 735 | * so if we miss here, then better luck next time. |
| 736 | */ |
| 737 | if (!spin_trylock(&trace_cmdline_lock)) |
| 738 | return; |
| 739 | |
| 740 | idx = map_pid_to_cmdline[tsk->pid]; |
| 741 | if (idx >= SAVED_CMDLINES) { |
| 742 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 743 | |
| 744 | map = map_cmdline_to_pid[idx]; |
| 745 | if (map <= PID_MAX_DEFAULT) |
| 746 | map_pid_to_cmdline[map] = (unsigned)-1; |
| 747 | |
| 748 | map_pid_to_cmdline[tsk->pid] = idx; |
| 749 | |
| 750 | cmdline_idx = idx; |
| 751 | } |
| 752 | |
| 753 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 754 | |
| 755 | spin_unlock(&trace_cmdline_lock); |
| 756 | } |
| 757 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 758 | static char *trace_find_cmdline(int pid) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 759 | { |
| 760 | char *cmdline = "<...>"; |
| 761 | unsigned map; |
| 762 | |
| 763 | if (!pid) |
| 764 | return "<idle>"; |
| 765 | |
| 766 | if (pid > PID_MAX_DEFAULT) |
| 767 | goto out; |
| 768 | |
| 769 | map = map_pid_to_cmdline[pid]; |
| 770 | if (map >= SAVED_CMDLINES) |
| 771 | goto out; |
| 772 | |
| 773 | cmdline = saved_cmdlines[map]; |
| 774 | |
| 775 | out: |
| 776 | return cmdline; |
| 777 | } |
| 778 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 779 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 780 | { |
| 781 | if (atomic_read(&trace_record_cmdline_disabled)) |
| 782 | return; |
| 783 | |
| 784 | trace_save_cmdline(tsk); |
| 785 | } |
| 786 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 787 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 788 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 789 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 790 | { |
| 791 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 792 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 793 | entry->preempt_count = pc & 0xff; |
| 794 | entry->pid = (tsk) ? tsk->pid : 0; |
| 795 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 796 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 797 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 798 | #else |
| 799 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 800 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 801 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 802 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 803 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 804 | } |
| 805 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 806 | void |
Steven Rostedt | 6fb44b7 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 807 | trace_function(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 808 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 809 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 810 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 811 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 812 | struct ftrace_entry *entry; |
Ingo Molnar | dcb6308 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 813 | unsigned long irq_flags; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 814 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 815 | /* If we are reading the ring buffer, don't trace */ |
| 816 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
| 817 | return; |
| 818 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 819 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 820 | &irq_flags); |
| 821 | if (!event) |
| 822 | return; |
| 823 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 824 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 825 | entry->ent.type = TRACE_FN; |
| 826 | entry->ip = ip; |
| 827 | entry->parent_ip = parent_ip; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 828 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 831 | #ifdef CONFIG_FUNCTION_RET_TRACER |
| 832 | static void __trace_function_return(struct trace_array *tr, |
| 833 | struct trace_array_cpu *data, |
| 834 | struct ftrace_retfunc *trace, |
| 835 | unsigned long flags, |
| 836 | int pc) |
| 837 | { |
| 838 | struct ring_buffer_event *event; |
| 839 | struct ftrace_ret_entry *entry; |
| 840 | unsigned long irq_flags; |
| 841 | |
| 842 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
| 843 | return; |
| 844 | |
| 845 | event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), |
| 846 | &irq_flags); |
| 847 | if (!event) |
| 848 | return; |
| 849 | entry = ring_buffer_event_data(event); |
| 850 | tracing_generic_entry_update(&entry->ent, flags, pc); |
| 851 | entry->ent.type = TRACE_FN_RET; |
| 852 | entry->ip = trace->func; |
| 853 | entry->parent_ip = trace->ret; |
| 854 | entry->rettime = trace->rettime; |
| 855 | entry->calltime = trace->calltime; |
Frederic Weisbecker | 0231022 | 2008-11-17 03:22:41 +0100 | [diff] [blame^] | 856 | entry->overrun = trace->overrun; |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 857 | ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); |
| 858 | } |
| 859 | #endif |
| 860 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 861 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 862 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 863 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 864 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 865 | { |
| 866 | if (likely(!atomic_read(&data->disabled))) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 867 | trace_function(tr, data, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 870 | static void ftrace_trace_stack(struct trace_array *tr, |
| 871 | struct trace_array_cpu *data, |
| 872 | unsigned long flags, |
| 873 | int skip, int pc) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 874 | { |
Al Viro | c2c8052 | 2008-10-31 19:50:41 +0000 | [diff] [blame] | 875 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 876 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 877 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 878 | struct stack_trace trace; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 879 | unsigned long irq_flags; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 880 | |
| 881 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 882 | return; |
| 883 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 884 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 885 | &irq_flags); |
| 886 | if (!event) |
| 887 | return; |
| 888 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 889 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 890 | entry->ent.type = TRACE_STACK; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 891 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 892 | memset(&entry->caller, 0, sizeof(entry->caller)); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 893 | |
| 894 | trace.nr_entries = 0; |
| 895 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 896 | trace.skip = skip; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 897 | trace.entries = entry->caller; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 898 | |
| 899 | save_stack_trace(&trace); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 900 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Al Viro | c2c8052 | 2008-10-31 19:50:41 +0000 | [diff] [blame] | 901 | #endif |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 902 | } |
| 903 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 904 | void __trace_stack(struct trace_array *tr, |
| 905 | struct trace_array_cpu *data, |
| 906 | unsigned long flags, |
| 907 | int skip) |
| 908 | { |
| 909 | ftrace_trace_stack(tr, data, flags, skip, preempt_count()); |
| 910 | } |
| 911 | |
| 912 | static void |
| 913 | ftrace_trace_special(void *__tr, void *__data, |
| 914 | unsigned long arg1, unsigned long arg2, unsigned long arg3, |
| 915 | int pc) |
Ingo Molnar | a4feb83 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 916 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 917 | struct ring_buffer_event *event; |
Ingo Molnar | a4feb83 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 918 | struct trace_array_cpu *data = __data; |
| 919 | struct trace_array *tr = __tr; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 920 | struct special_entry *entry; |
Ingo Molnar | a4feb83 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 921 | unsigned long irq_flags; |
| 922 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 923 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 924 | &irq_flags); |
| 925 | if (!event) |
| 926 | return; |
| 927 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 928 | tracing_generic_entry_update(&entry->ent, 0, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 929 | entry->ent.type = TRACE_SPECIAL; |
| 930 | entry->arg1 = arg1; |
| 931 | entry->arg2 = arg2; |
| 932 | entry->arg3 = arg3; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 933 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 934 | ftrace_trace_stack(tr, data, irq_flags, 4, pc); |
Ingo Molnar | a4feb83 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 935 | |
| 936 | trace_wake_up(); |
| 937 | } |
| 938 | |
| 939 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 940 | __trace_special(void *__tr, void *__data, |
| 941 | unsigned long arg1, unsigned long arg2, unsigned long arg3) |
| 942 | { |
| 943 | ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count()); |
| 944 | } |
| 945 | |
| 946 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 947 | tracing_sched_switch_trace(struct trace_array *tr, |
| 948 | struct trace_array_cpu *data, |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 949 | struct task_struct *prev, |
| 950 | struct task_struct *next, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 951 | unsigned long flags, int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 952 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 953 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 954 | struct ctx_switch_entry *entry; |
Ingo Molnar | dcb6308 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 955 | unsigned long irq_flags; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 956 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 957 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 958 | &irq_flags); |
| 959 | if (!event) |
| 960 | return; |
| 961 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 962 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 963 | entry->ent.type = TRACE_CTX; |
| 964 | entry->prev_pid = prev->pid; |
| 965 | entry->prev_prio = prev->prio; |
| 966 | entry->prev_state = prev->state; |
| 967 | entry->next_pid = next->pid; |
| 968 | entry->next_prio = next->prio; |
| 969 | entry->next_state = next->state; |
| 970 | entry->next_cpu = task_cpu(next); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 971 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 972 | ftrace_trace_stack(tr, data, flags, 5, pc); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 973 | } |
| 974 | |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 975 | void |
| 976 | tracing_sched_wakeup_trace(struct trace_array *tr, |
| 977 | struct trace_array_cpu *data, |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 978 | struct task_struct *wakee, |
| 979 | struct task_struct *curr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 980 | unsigned long flags, int pc) |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 981 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 982 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 983 | struct ctx_switch_entry *entry; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 984 | unsigned long irq_flags; |
| 985 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 986 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 987 | &irq_flags); |
| 988 | if (!event) |
| 989 | return; |
| 990 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 991 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 992 | entry->ent.type = TRACE_WAKE; |
| 993 | entry->prev_pid = curr->pid; |
| 994 | entry->prev_prio = curr->prio; |
| 995 | entry->prev_state = curr->state; |
| 996 | entry->next_pid = wakee->pid; |
| 997 | entry->next_prio = wakee->prio; |
| 998 | entry->next_state = wakee->state; |
| 999 | entry->next_cpu = task_cpu(wakee); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1000 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1001 | ftrace_trace_stack(tr, data, flags, 6, pc); |
Ingo Molnar | 017730c | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 1002 | |
| 1003 | trace_wake_up(); |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1004 | } |
| 1005 | |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1006 | void |
| 1007 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) |
| 1008 | { |
| 1009 | struct trace_array *tr = &global_trace; |
| 1010 | struct trace_array_cpu *data; |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1011 | unsigned long flags; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1012 | int cpu; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1013 | int pc; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1014 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1015 | if (tracing_disabled) |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1016 | return; |
| 1017 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1018 | pc = preempt_count(); |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1019 | local_irq_save(flags); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1020 | cpu = raw_smp_processor_id(); |
| 1021 | data = tr->data[cpu]; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1022 | |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1023 | if (likely(atomic_inc_return(&data->disabled) == 1)) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1024 | ftrace_trace_special(tr, data, arg1, arg2, arg3, pc); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1025 | |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1026 | atomic_dec(&data->disabled); |
| 1027 | local_irq_restore(flags); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 1030 | #ifdef CONFIG_FUNCTION_TRACER |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1031 | static void |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1032 | function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1033 | { |
| 1034 | struct trace_array *tr = &global_trace; |
| 1035 | struct trace_array_cpu *data; |
| 1036 | unsigned long flags; |
| 1037 | long disabled; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1038 | int cpu, resched; |
| 1039 | int pc; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1040 | |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1041 | if (unlikely(!ftrace_function_enabled)) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1042 | return; |
| 1043 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1044 | pc = preempt_count(); |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 1045 | resched = ftrace_preempt_disable(); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1046 | local_save_flags(flags); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1047 | cpu = raw_smp_processor_id(); |
| 1048 | data = tr->data[cpu]; |
| 1049 | disabled = atomic_inc_return(&data->disabled); |
| 1050 | |
| 1051 | if (likely(disabled == 1)) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1052 | trace_function(tr, data, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1053 | |
| 1054 | atomic_dec(&data->disabled); |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 1055 | ftrace_preempt_enable(resched); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1058 | static void |
| 1059 | function_trace_call(unsigned long ip, unsigned long parent_ip) |
| 1060 | { |
| 1061 | struct trace_array *tr = &global_trace; |
| 1062 | struct trace_array_cpu *data; |
| 1063 | unsigned long flags; |
| 1064 | long disabled; |
| 1065 | int cpu; |
| 1066 | int pc; |
| 1067 | |
| 1068 | if (unlikely(!ftrace_function_enabled)) |
| 1069 | return; |
| 1070 | |
| 1071 | /* |
| 1072 | * Need to use raw, since this must be called before the |
| 1073 | * recursive protection is performed. |
| 1074 | */ |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 1075 | local_irq_save(flags); |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1076 | cpu = raw_smp_processor_id(); |
| 1077 | data = tr->data[cpu]; |
| 1078 | disabled = atomic_inc_return(&data->disabled); |
| 1079 | |
| 1080 | if (likely(disabled == 1)) { |
| 1081 | pc = preempt_count(); |
| 1082 | trace_function(tr, data, ip, parent_ip, flags, pc); |
| 1083 | } |
| 1084 | |
| 1085 | atomic_dec(&data->disabled); |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 1086 | local_irq_restore(flags); |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1087 | } |
| 1088 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1089 | #ifdef CONFIG_FUNCTION_RET_TRACER |
| 1090 | void trace_function_return(struct ftrace_retfunc *trace) |
| 1091 | { |
| 1092 | struct trace_array *tr = &global_trace; |
| 1093 | struct trace_array_cpu *data; |
| 1094 | unsigned long flags; |
| 1095 | long disabled; |
| 1096 | int cpu; |
| 1097 | int pc; |
| 1098 | |
| 1099 | raw_local_irq_save(flags); |
| 1100 | cpu = raw_smp_processor_id(); |
| 1101 | data = tr->data[cpu]; |
| 1102 | disabled = atomic_inc_return(&data->disabled); |
| 1103 | if (likely(disabled == 1)) { |
| 1104 | pc = preempt_count(); |
| 1105 | __trace_function_return(tr, data, trace, flags, pc); |
| 1106 | } |
| 1107 | atomic_dec(&data->disabled); |
| 1108 | raw_local_irq_restore(flags); |
| 1109 | } |
| 1110 | #endif /* CONFIG_FUNCTION_RET_TRACER */ |
| 1111 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1112 | static struct ftrace_ops trace_ops __read_mostly = |
| 1113 | { |
| 1114 | .func = function_trace_call, |
| 1115 | }; |
| 1116 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1117 | void tracing_start_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1118 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1119 | ftrace_function_enabled = 0; |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1120 | |
| 1121 | if (trace_flags & TRACE_ITER_PREEMPTONLY) |
| 1122 | trace_ops.func = function_trace_call_preempt_only; |
| 1123 | else |
| 1124 | trace_ops.func = function_trace_call; |
| 1125 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1126 | register_ftrace_function(&trace_ops); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1127 | ftrace_function_enabled = 1; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1130 | void tracing_stop_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1131 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1132 | ftrace_function_enabled = 0; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1133 | unregister_ftrace_function(&trace_ops); |
| 1134 | } |
| 1135 | #endif |
| 1136 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1137 | enum trace_file_type { |
| 1138 | TRACE_FILE_LAT_FMT = 1, |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1139 | TRACE_FILE_ANNOTATE = 2, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1140 | }; |
| 1141 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1142 | static void trace_iterator_increment(struct trace_iterator *iter, int cpu) |
| 1143 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1144 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1145 | ftrace_disable_cpu(); |
| 1146 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1147 | iter->idx++; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1148 | if (iter->buffer_iter[iter->cpu]) |
| 1149 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1150 | |
| 1151 | ftrace_enable_cpu(); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1152 | } |
| 1153 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1154 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1155 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1156 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1157 | struct ring_buffer_event *event; |
| 1158 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1159 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1160 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1161 | ftrace_disable_cpu(); |
| 1162 | |
| 1163 | if (buf_iter) |
| 1164 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 1165 | else |
| 1166 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); |
| 1167 | |
| 1168 | ftrace_enable_cpu(); |
| 1169 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1170 | return event ? ring_buffer_event_data(event) : NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1171 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1172 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1173 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1174 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1175 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1176 | struct ring_buffer *buffer = iter->tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1177 | struct trace_entry *ent, *next = NULL; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1178 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1179 | int next_cpu = -1; |
| 1180 | int cpu; |
| 1181 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1182 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1183 | |
| 1184 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1185 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1186 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1187 | ent = peek_next_entry(iter, cpu, &ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1188 | |
Ingo Molnar | cdd31cd | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1189 | /* |
| 1190 | * Pick the entry with the smallest timestamp: |
| 1191 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1192 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1193 | next = ent; |
| 1194 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1195 | next_ts = ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | if (ent_cpu) |
| 1200 | *ent_cpu = next_cpu; |
| 1201 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1202 | if (ent_ts) |
| 1203 | *ent_ts = next_ts; |
| 1204 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1205 | return next; |
| 1206 | } |
| 1207 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1208 | /* Find the next real entry, without updating the iterator itself */ |
| 1209 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1210 | find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1211 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1212 | return __find_next_entry(iter, ent_cpu, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1213 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1214 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1215 | /* Find the next real entry, and increment the iterator to the next entry */ |
| 1216 | static void *find_next_entry_inc(struct trace_iterator *iter) |
| 1217 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1218 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1219 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1220 | if (iter->ent) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1221 | trace_iterator_increment(iter, iter->cpu); |
| 1222 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1223 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1224 | } |
| 1225 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1226 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1227 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1228 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1229 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1230 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1231 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1234 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1235 | { |
| 1236 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1237 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1238 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1239 | |
| 1240 | (*pos)++; |
| 1241 | |
| 1242 | /* can't go backwards */ |
| 1243 | if (iter->idx > i) |
| 1244 | return NULL; |
| 1245 | |
| 1246 | if (iter->idx < 0) |
| 1247 | ent = find_next_entry_inc(iter); |
| 1248 | else |
| 1249 | ent = iter; |
| 1250 | |
| 1251 | while (ent && iter->idx < i) |
| 1252 | ent = find_next_entry_inc(iter); |
| 1253 | |
| 1254 | iter->pos = *pos; |
| 1255 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1256 | return ent; |
| 1257 | } |
| 1258 | |
| 1259 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 1260 | { |
| 1261 | struct trace_iterator *iter = m->private; |
| 1262 | void *p = NULL; |
| 1263 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1264 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1265 | |
| 1266 | mutex_lock(&trace_types_lock); |
| 1267 | |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1268 | if (!current_trace || current_trace != iter->trace) { |
| 1269 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1270 | return NULL; |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1271 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1272 | |
| 1273 | atomic_inc(&trace_record_cmdline_disabled); |
| 1274 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1275 | if (*pos != iter->pos) { |
| 1276 | iter->ent = NULL; |
| 1277 | iter->cpu = 0; |
| 1278 | iter->idx = -1; |
| 1279 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1280 | ftrace_disable_cpu(); |
| 1281 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1282 | for_each_tracing_cpu(cpu) { |
| 1283 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1284 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1285 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1286 | ftrace_enable_cpu(); |
| 1287 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1288 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 1289 | ; |
| 1290 | |
| 1291 | } else { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1292 | l = *pos - 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1293 | p = s_next(m, p, &l); |
| 1294 | } |
| 1295 | |
| 1296 | return p; |
| 1297 | } |
| 1298 | |
| 1299 | static void s_stop(struct seq_file *m, void *p) |
| 1300 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1301 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1302 | mutex_unlock(&trace_types_lock); |
| 1303 | } |
| 1304 | |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1305 | #ifdef CONFIG_KRETPROBES |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1306 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1307 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1308 | static const char tramp_name[] = "kretprobe_trampoline"; |
| 1309 | int size = sizeof(tramp_name); |
| 1310 | |
| 1311 | if (strncmp(tramp_name, name, size) == 0) |
| 1312 | return "[unknown/kretprobe'd]"; |
| 1313 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1314 | } |
| 1315 | #else |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1316 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1317 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1318 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1319 | } |
| 1320 | #endif /* CONFIG_KRETPROBES */ |
| 1321 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1322 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1323 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1324 | { |
| 1325 | #ifdef CONFIG_KALLSYMS |
| 1326 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1327 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1328 | |
| 1329 | kallsyms_lookup(address, NULL, NULL, NULL, str); |
| 1330 | |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1331 | name = kretprobed(str); |
| 1332 | |
| 1333 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1334 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1335 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1336 | } |
| 1337 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1338 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1339 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, |
| 1340 | unsigned long address) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1341 | { |
| 1342 | #ifdef CONFIG_KALLSYMS |
| 1343 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1344 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1345 | |
| 1346 | sprint_symbol(str, address); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1347 | name = kretprobed(str); |
| 1348 | |
| 1349 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1350 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1351 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | #ifndef CONFIG_64BIT |
| 1355 | # define IP_FMT "%08lx" |
| 1356 | #else |
| 1357 | # define IP_FMT "%016lx" |
| 1358 | #endif |
| 1359 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1360 | int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1361 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1362 | { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1363 | int ret; |
| 1364 | |
| 1365 | if (!ip) |
| 1366 | return trace_seq_printf(s, "0"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1367 | |
| 1368 | if (sym_flags & TRACE_ITER_SYM_OFFSET) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1369 | ret = seq_print_sym_offset(s, "%s", ip); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1370 | else |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1371 | ret = seq_print_sym_short(s, "%s", ip); |
| 1372 | |
| 1373 | if (!ret) |
| 1374 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1375 | |
| 1376 | if (sym_flags & TRACE_ITER_SYM_ADDR) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1377 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 1378 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1381 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1382 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1383 | seq_puts(m, "# _------=> CPU# \n"); |
| 1384 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 1385 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 1386 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 1387 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
| 1388 | seq_puts(m, "# |||| / \n"); |
| 1389 | seq_puts(m, "# ||||| delay \n"); |
| 1390 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 1391 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1394 | static void print_func_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1395 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1396 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
| 1397 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1401 | static void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1402 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 1403 | { |
| 1404 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1405 | struct trace_array *tr = iter->tr; |
| 1406 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
| 1407 | struct tracer *type = current_trace; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1408 | unsigned long total; |
| 1409 | unsigned long entries; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1410 | const char *name = "preemption"; |
| 1411 | |
| 1412 | if (type) |
| 1413 | name = type->name; |
| 1414 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1415 | entries = ring_buffer_entries(iter->tr->buffer); |
| 1416 | total = entries + |
| 1417 | ring_buffer_overruns(iter->tr->buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1418 | |
| 1419 | seq_printf(m, "%s latency trace v1.1.5 on %s\n", |
| 1420 | name, UTS_RELEASE); |
| 1421 | seq_puts(m, "-----------------------------------" |
| 1422 | "---------------------------------\n"); |
| 1423 | seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |" |
| 1424 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1425 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1426 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1427 | total, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1428 | tr->cpu, |
| 1429 | #if defined(CONFIG_PREEMPT_NONE) |
| 1430 | "server", |
| 1431 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 1432 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 1433 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1434 | "preempt", |
| 1435 | #else |
| 1436 | "unknown", |
| 1437 | #endif |
| 1438 | /* These are reserved for later use */ |
| 1439 | 0, 0, 0, 0); |
| 1440 | #ifdef CONFIG_SMP |
| 1441 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 1442 | #else |
| 1443 | seq_puts(m, ")\n"); |
| 1444 | #endif |
| 1445 | seq_puts(m, " -----------------\n"); |
| 1446 | seq_printf(m, " | task: %.16s-%d " |
| 1447 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
| 1448 | data->comm, data->pid, data->uid, data->nice, |
| 1449 | data->policy, data->rt_priority); |
| 1450 | seq_puts(m, " -----------------\n"); |
| 1451 | |
| 1452 | if (data->critical_start) { |
| 1453 | seq_puts(m, " => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1454 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 1455 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1456 | seq_puts(m, "\n => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1457 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 1458 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1459 | seq_puts(m, "\n"); |
| 1460 | } |
| 1461 | |
| 1462 | seq_puts(m, "\n"); |
| 1463 | } |
| 1464 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1465 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1466 | lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1467 | { |
| 1468 | int hardirq, softirq; |
| 1469 | char *comm; |
| 1470 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1471 | comm = trace_find_cmdline(entry->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1472 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1473 | trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1474 | trace_seq_printf(s, "%3d", cpu); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1475 | trace_seq_printf(s, "%c%c", |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1476 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 1477 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.', |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1478 | ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.')); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1479 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1480 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; |
| 1481 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1482 | if (hardirq && softirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1483 | trace_seq_putc(s, 'H'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1484 | } else { |
| 1485 | if (hardirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1486 | trace_seq_putc(s, 'h'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1487 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1488 | if (softirq) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1489 | trace_seq_putc(s, 's'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1490 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1491 | trace_seq_putc(s, '.'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1495 | if (entry->preempt_count) |
| 1496 | trace_seq_printf(s, "%x", entry->preempt_count); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1497 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1498 | trace_seq_puts(s, "."); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | unsigned long preempt_mark_thresh = 100; |
| 1502 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1503 | static void |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1504 | lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1505 | unsigned long rel_usecs) |
| 1506 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1507 | trace_seq_printf(s, " %4lldus", abs_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1508 | if (rel_usecs > preempt_mark_thresh) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1509 | trace_seq_puts(s, "!: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1510 | else if (rel_usecs > 1) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1511 | trace_seq_puts(s, "+: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1512 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1513 | trace_seq_puts(s, " : "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; |
| 1517 | |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1518 | /* |
| 1519 | * The message is supposed to contain an ending newline. |
| 1520 | * If the printing stops prematurely, try to add a newline of our own. |
| 1521 | */ |
| 1522 | void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1523 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1524 | struct trace_entry *ent; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1525 | struct trace_field_cont *cont; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1526 | bool ok = true; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1527 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1528 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1529 | if (!ent || ent->type != TRACE_CONT) { |
| 1530 | trace_seq_putc(s, '\n'); |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | do { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1535 | cont = (struct trace_field_cont *)ent; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1536 | if (ok) |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1537 | ok = (trace_seq_printf(s, "%s", cont->buf) > 0); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1538 | |
| 1539 | ftrace_disable_cpu(); |
| 1540 | |
| 1541 | if (iter->buffer_iter[iter->cpu]) |
| 1542 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1543 | else |
| 1544 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); |
| 1545 | |
| 1546 | ftrace_enable_cpu(); |
| 1547 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1548 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1549 | } while (ent && ent->type == TRACE_CONT); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1550 | |
| 1551 | if (!ok) |
| 1552 | trace_seq_putc(s, '\n'); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1555 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 1556 | { |
| 1557 | struct trace_seq *s = &iter->seq; |
| 1558 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1559 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 1560 | return; |
| 1561 | |
| 1562 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 1563 | return; |
| 1564 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1565 | if (cpu_isset(iter->cpu, iter->started)) |
| 1566 | return; |
| 1567 | |
| 1568 | cpu_set(iter->cpu, iter->started); |
| 1569 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); |
| 1570 | } |
| 1571 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1572 | static enum print_line_t |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1573 | print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1574 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1575 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1576 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1577 | struct trace_entry *next_entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1578 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); |
| 1579 | struct trace_entry *entry = iter->ent; |
| 1580 | unsigned long abs_usecs; |
| 1581 | unsigned long rel_usecs; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1582 | u64 next_ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1583 | char *comm; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1584 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1585 | int i; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1586 | unsigned state; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1587 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1588 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1589 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1590 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1591 | test_cpu_buff_start(iter); |
| 1592 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1593 | next_entry = find_next_entry(iter, NULL, &next_ts); |
| 1594 | if (!next_entry) |
| 1595 | next_ts = iter->ts; |
| 1596 | rel_usecs = ns2usecs(next_ts - iter->ts); |
| 1597 | abs_usecs = ns2usecs(iter->ts - iter->tr->time_start); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1598 | |
| 1599 | if (verbose) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1600 | comm = trace_find_cmdline(entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1601 | trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]" |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1602 | " %ld.%03ldms (+%ld.%03ldms): ", |
| 1603 | comm, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1604 | entry->pid, cpu, entry->flags, |
| 1605 | entry->preempt_count, trace_idx, |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1606 | ns2usecs(iter->ts), |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1607 | abs_usecs/1000, |
| 1608 | abs_usecs % 1000, rel_usecs/1000, |
| 1609 | rel_usecs % 1000); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1610 | } else { |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1611 | lat_print_generic(s, entry, cpu); |
| 1612 | lat_print_timestamp(s, abs_usecs, rel_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1613 | } |
| 1614 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1615 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1616 | struct ftrace_entry *field; |
| 1617 | |
| 1618 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1619 | |
| 1620 | seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1621 | trace_seq_puts(s, " ("); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1622 | seq_print_ip_sym(s, field->parent_ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1623 | trace_seq_puts(s, ")\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1624 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1625 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1626 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1627 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1628 | struct ctx_switch_entry *field; |
| 1629 | |
| 1630 | trace_assign_type(field, entry); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1631 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1632 | T = field->next_state < sizeof(state_to_char) ? |
| 1633 | state_to_char[field->next_state] : 'X'; |
| 1634 | |
| 1635 | state = field->prev_state ? |
| 1636 | __ffs(field->prev_state) + 1 : 0; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1637 | S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1638 | comm = trace_find_cmdline(field->next_pid); |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1639 | trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1640 | field->prev_pid, |
| 1641 | field->prev_prio, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1642 | S, entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1643 | field->next_cpu, |
| 1644 | field->next_pid, |
| 1645 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1646 | T, comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1647 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1648 | } |
| 1649 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1650 | struct special_entry *field; |
| 1651 | |
| 1652 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1653 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1654 | trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1655 | field->arg1, |
| 1656 | field->arg2, |
| 1657 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1658 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1659 | } |
| 1660 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1661 | struct stack_entry *field; |
| 1662 | |
| 1663 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1664 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1665 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1666 | if (i) |
| 1667 | trace_seq_puts(s, " <= "); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1668 | seq_print_ip_sym(s, field->caller[i], sym_flags); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1669 | } |
| 1670 | trace_seq_puts(s, "\n"); |
| 1671 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1672 | } |
| 1673 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1674 | struct print_entry *field; |
| 1675 | |
| 1676 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1677 | |
| 1678 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 1679 | trace_seq_printf(s, ": %s", field->buf); |
| 1680 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1681 | trace_seq_print_cont(s, iter); |
| 1682 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1683 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 1684 | case TRACE_BRANCH: { |
| 1685 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1686 | |
| 1687 | trace_assign_type(field, entry); |
| 1688 | |
| 1689 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 1690 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1691 | field->func, |
| 1692 | field->file, |
| 1693 | field->line); |
| 1694 | break; |
| 1695 | } |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1696 | default: |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1697 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1698 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1699 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1700 | } |
| 1701 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1702 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1703 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1704 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1705 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1706 | struct trace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1707 | unsigned long usec_rem; |
| 1708 | unsigned long long t; |
| 1709 | unsigned long secs; |
| 1710 | char *comm; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1711 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1712 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1713 | int i; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1714 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1715 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1716 | |
| 1717 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1718 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1719 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1720 | test_cpu_buff_start(iter); |
| 1721 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1722 | comm = trace_find_cmdline(iter->ent->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1723 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1724 | t = ns2usecs(iter->ts); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1725 | usec_rem = do_div(t, 1000000ULL); |
| 1726 | secs = (unsigned long)t; |
| 1727 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1728 | ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1729 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1730 | return TRACE_TYPE_PARTIAL_LINE; |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1731 | ret = trace_seq_printf(s, "[%03d] ", iter->cpu); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1732 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1733 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1734 | ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem); |
| 1735 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1736 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1737 | |
| 1738 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1739 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1740 | struct ftrace_entry *field; |
| 1741 | |
| 1742 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1743 | |
| 1744 | ret = seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1745 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1746 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1747 | if ((sym_flags & TRACE_ITER_PRINT_PARENT) && |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1748 | field->parent_ip) { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1749 | ret = trace_seq_printf(s, " <-"); |
| 1750 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1751 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1752 | ret = seq_print_ip_sym(s, |
| 1753 | field->parent_ip, |
| 1754 | sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1755 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1756 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1757 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1758 | ret = trace_seq_printf(s, "\n"); |
| 1759 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1760 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1761 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1762 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1763 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1764 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1765 | struct ctx_switch_entry *field; |
| 1766 | |
| 1767 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1768 | |
| 1769 | S = field->prev_state < sizeof(state_to_char) ? |
| 1770 | state_to_char[field->prev_state] : 'X'; |
| 1771 | T = field->next_state < sizeof(state_to_char) ? |
| 1772 | state_to_char[field->next_state] : 'X'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1773 | ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1774 | field->prev_pid, |
| 1775 | field->prev_prio, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1776 | S, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1777 | entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1778 | field->next_cpu, |
| 1779 | field->next_pid, |
| 1780 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1781 | T); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1782 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1783 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1784 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1785 | } |
| 1786 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1787 | struct special_entry *field; |
| 1788 | |
| 1789 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1790 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1791 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1792 | field->arg1, |
| 1793 | field->arg2, |
| 1794 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1795 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1796 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1797 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1798 | } |
| 1799 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1800 | struct stack_entry *field; |
| 1801 | |
| 1802 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1803 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1804 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1805 | if (i) { |
| 1806 | ret = trace_seq_puts(s, " <= "); |
| 1807 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1808 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1809 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1810 | ret = seq_print_ip_sym(s, field->caller[i], |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1811 | sym_flags); |
| 1812 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1813 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1814 | } |
| 1815 | ret = trace_seq_puts(s, "\n"); |
| 1816 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1817 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1818 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1819 | } |
| 1820 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1821 | struct print_entry *field; |
| 1822 | |
| 1823 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1824 | |
| 1825 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 1826 | trace_seq_printf(s, ": %s", field->buf); |
| 1827 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1828 | trace_seq_print_cont(s, iter); |
| 1829 | break; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1830 | } |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1831 | case TRACE_FN_RET: { |
| 1832 | return print_return_function(iter); |
| 1833 | break; |
| 1834 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 1835 | case TRACE_BRANCH: { |
| 1836 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1837 | |
| 1838 | trace_assign_type(field, entry); |
| 1839 | |
| 1840 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 1841 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1842 | field->func, |
| 1843 | field->file, |
| 1844 | field->line); |
| 1845 | break; |
| 1846 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1847 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1848 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1849 | } |
| 1850 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1851 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1852 | { |
| 1853 | struct trace_seq *s = &iter->seq; |
| 1854 | struct trace_entry *entry; |
| 1855 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1856 | int S, T; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1857 | |
| 1858 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1859 | |
| 1860 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1861 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1862 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1863 | ret = trace_seq_printf(s, "%d %d %llu ", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1864 | entry->pid, iter->cpu, iter->ts); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1865 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1866 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1867 | |
| 1868 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1869 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1870 | struct ftrace_entry *field; |
| 1871 | |
| 1872 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1873 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1874 | ret = trace_seq_printf(s, "%x %x\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1875 | field->ip, |
| 1876 | field->parent_ip); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1877 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1878 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1879 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1880 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1881 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1882 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1883 | struct ctx_switch_entry *field; |
| 1884 | |
| 1885 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1886 | |
| 1887 | S = field->prev_state < sizeof(state_to_char) ? |
| 1888 | state_to_char[field->prev_state] : 'X'; |
| 1889 | T = field->next_state < sizeof(state_to_char) ? |
| 1890 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1891 | if (entry->type == TRACE_WAKE) |
| 1892 | S = '+'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1893 | ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1894 | field->prev_pid, |
| 1895 | field->prev_prio, |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1896 | S, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1897 | field->next_cpu, |
| 1898 | field->next_pid, |
| 1899 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1900 | T); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1901 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1902 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1903 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1904 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1905 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1906 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1907 | struct special_entry *field; |
| 1908 | |
| 1909 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1910 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1911 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1912 | field->arg1, |
| 1913 | field->arg2, |
| 1914 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1915 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1916 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1917 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1918 | } |
| 1919 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1920 | struct print_entry *field; |
| 1921 | |
| 1922 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1923 | |
| 1924 | trace_seq_printf(s, "# %lx %s", field->ip, field->buf); |
| 1925 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1926 | trace_seq_print_cont(s, iter); |
| 1927 | break; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1928 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1929 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1930 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1931 | } |
| 1932 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1933 | #define SEQ_PUT_FIELD_RET(s, x) \ |
| 1934 | do { \ |
| 1935 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ |
| 1936 | return 0; \ |
| 1937 | } while (0) |
| 1938 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1939 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ |
| 1940 | do { \ |
Harvey Harrison | ad0a3b6 | 2008-10-08 17:44:55 -0700 | [diff] [blame] | 1941 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1942 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ |
| 1943 | return 0; \ |
| 1944 | } while (0) |
| 1945 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1946 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1947 | { |
| 1948 | struct trace_seq *s = &iter->seq; |
| 1949 | unsigned char newline = '\n'; |
| 1950 | struct trace_entry *entry; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1951 | int S, T; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1952 | |
| 1953 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1954 | |
| 1955 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1956 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1957 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1958 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1959 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1960 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1961 | |
| 1962 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1963 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1964 | struct ftrace_entry *field; |
| 1965 | |
| 1966 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1967 | |
| 1968 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); |
| 1969 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1970 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1971 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1972 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1973 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1974 | struct ctx_switch_entry *field; |
| 1975 | |
| 1976 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1977 | |
| 1978 | S = field->prev_state < sizeof(state_to_char) ? |
| 1979 | state_to_char[field->prev_state] : 'X'; |
| 1980 | T = field->next_state < sizeof(state_to_char) ? |
| 1981 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1982 | if (entry->type == TRACE_WAKE) |
| 1983 | S = '+'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1984 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); |
| 1985 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1986 | SEQ_PUT_HEX_FIELD_RET(s, S); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1987 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); |
| 1988 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); |
| 1989 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1990 | SEQ_PUT_HEX_FIELD_RET(s, T); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1991 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1992 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1993 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1994 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1995 | struct special_entry *field; |
| 1996 | |
| 1997 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1998 | |
| 1999 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); |
| 2000 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); |
| 2001 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2002 | break; |
| 2003 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2004 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2005 | SEQ_PUT_FIELD_RET(s, newline); |
| 2006 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2007 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2010 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2011 | { |
| 2012 | struct trace_seq *s = &iter->seq; |
| 2013 | struct trace_entry *entry; |
| 2014 | |
| 2015 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2016 | |
| 2017 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2018 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2019 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2020 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Eric Anholt | 072ba49 | 2008-10-26 15:26:57 -0700 | [diff] [blame] | 2021 | SEQ_PUT_FIELD_RET(s, entry->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2022 | SEQ_PUT_FIELD_RET(s, iter->ts); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2023 | |
| 2024 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2025 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2026 | struct ftrace_entry *field; |
| 2027 | |
| 2028 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2029 | |
| 2030 | SEQ_PUT_FIELD_RET(s, field->ip); |
| 2031 | SEQ_PUT_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2032 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2033 | } |
| 2034 | case TRACE_CTX: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2035 | struct ctx_switch_entry *field; |
| 2036 | |
| 2037 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2038 | |
| 2039 | SEQ_PUT_FIELD_RET(s, field->prev_pid); |
| 2040 | SEQ_PUT_FIELD_RET(s, field->prev_prio); |
| 2041 | SEQ_PUT_FIELD_RET(s, field->prev_state); |
| 2042 | SEQ_PUT_FIELD_RET(s, field->next_pid); |
| 2043 | SEQ_PUT_FIELD_RET(s, field->next_prio); |
| 2044 | SEQ_PUT_FIELD_RET(s, field->next_state); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2045 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2046 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2047 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2048 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2049 | struct special_entry *field; |
| 2050 | |
| 2051 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2052 | |
| 2053 | SEQ_PUT_FIELD_RET(s, field->arg1); |
| 2054 | SEQ_PUT_FIELD_RET(s, field->arg2); |
| 2055 | SEQ_PUT_FIELD_RET(s, field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2056 | break; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2057 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2058 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2059 | return 1; |
| 2060 | } |
| 2061 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2062 | static int trace_empty(struct trace_iterator *iter) |
| 2063 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2064 | int cpu; |
| 2065 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2066 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2067 | if (iter->buffer_iter[cpu]) { |
| 2068 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) |
| 2069 | return 0; |
| 2070 | } else { |
| 2071 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) |
| 2072 | return 0; |
| 2073 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2074 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2075 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2076 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2077 | } |
| 2078 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2079 | static enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2080 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2081 | enum print_line_t ret; |
| 2082 | |
| 2083 | if (iter->trace && iter->trace->print_line) { |
| 2084 | ret = iter->trace->print_line(iter); |
| 2085 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2086 | return ret; |
| 2087 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2088 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2089 | if (trace_flags & TRACE_ITER_BIN) |
| 2090 | return print_bin_fmt(iter); |
| 2091 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2092 | if (trace_flags & TRACE_ITER_HEX) |
| 2093 | return print_hex_fmt(iter); |
| 2094 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2095 | if (trace_flags & TRACE_ITER_RAW) |
| 2096 | return print_raw_fmt(iter); |
| 2097 | |
| 2098 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2099 | return print_lat_fmt(iter, iter->idx, iter->cpu); |
| 2100 | |
| 2101 | return print_trace_fmt(iter); |
| 2102 | } |
| 2103 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2104 | static int s_show(struct seq_file *m, void *v) |
| 2105 | { |
| 2106 | struct trace_iterator *iter = v; |
| 2107 | |
| 2108 | if (iter->ent == NULL) { |
| 2109 | if (iter->tr) { |
| 2110 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2111 | seq_puts(m, "#\n"); |
| 2112 | } |
| 2113 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2114 | /* print nothing if the buffers are empty */ |
| 2115 | if (trace_empty(iter)) |
| 2116 | return 0; |
| 2117 | print_trace_header(m, iter); |
| 2118 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2119 | print_lat_help_header(m); |
| 2120 | } else { |
| 2121 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2122 | print_func_help_header(m); |
| 2123 | } |
| 2124 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2125 | print_trace_line(iter); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2126 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
| 2132 | static struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2133 | .start = s_start, |
| 2134 | .next = s_next, |
| 2135 | .stop = s_stop, |
| 2136 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2137 | }; |
| 2138 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2139 | static struct trace_iterator * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2140 | __tracing_open(struct inode *inode, struct file *file, int *ret) |
| 2141 | { |
| 2142 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2143 | struct seq_file *m; |
| 2144 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2145 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2146 | if (tracing_disabled) { |
| 2147 | *ret = -ENODEV; |
| 2148 | return NULL; |
| 2149 | } |
| 2150 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2151 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 2152 | if (!iter) { |
| 2153 | *ret = -ENOMEM; |
| 2154 | goto out; |
| 2155 | } |
| 2156 | |
| 2157 | mutex_lock(&trace_types_lock); |
| 2158 | if (current_trace && current_trace->print_max) |
| 2159 | iter->tr = &max_tr; |
| 2160 | else |
| 2161 | iter->tr = inode->i_private; |
| 2162 | iter->trace = current_trace; |
| 2163 | iter->pos = -1; |
| 2164 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2165 | /* Annotate start of buffers if we had overruns */ |
| 2166 | if (ring_buffer_overruns(iter->tr->buffer)) |
| 2167 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2168 | |
| 2169 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2170 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2171 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2172 | iter->buffer_iter[cpu] = |
| 2173 | ring_buffer_read_start(iter->tr->buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2174 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2175 | if (!iter->buffer_iter[cpu]) |
| 2176 | goto fail_buffer; |
| 2177 | } |
| 2178 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2179 | /* TODO stop tracer */ |
| 2180 | *ret = seq_open(file, &tracer_seq_ops); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2181 | if (*ret) |
| 2182 | goto fail_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2183 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2184 | m = file->private_data; |
| 2185 | m->private = iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2186 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2187 | /* stop the trace while dumping */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2188 | tracing_stop(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2189 | |
| 2190 | if (iter->trace && iter->trace->open) |
| 2191 | iter->trace->open(iter); |
| 2192 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2193 | mutex_unlock(&trace_types_lock); |
| 2194 | |
| 2195 | out: |
| 2196 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2197 | |
| 2198 | fail_buffer: |
| 2199 | for_each_tracing_cpu(cpu) { |
| 2200 | if (iter->buffer_iter[cpu]) |
| 2201 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2202 | } |
| 2203 | mutex_unlock(&trace_types_lock); |
| 2204 | |
| 2205 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2209 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2210 | if (tracing_disabled) |
| 2211 | return -ENODEV; |
| 2212 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2213 | filp->private_data = inode->i_private; |
| 2214 | return 0; |
| 2215 | } |
| 2216 | |
| 2217 | int tracing_release(struct inode *inode, struct file *file) |
| 2218 | { |
| 2219 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 2220 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2221 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2222 | |
| 2223 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2224 | for_each_tracing_cpu(cpu) { |
| 2225 | if (iter->buffer_iter[cpu]) |
| 2226 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2227 | } |
| 2228 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2229 | if (iter->trace && iter->trace->close) |
| 2230 | iter->trace->close(iter); |
| 2231 | |
| 2232 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2233 | tracing_start(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2234 | mutex_unlock(&trace_types_lock); |
| 2235 | |
| 2236 | seq_release(inode, file); |
| 2237 | kfree(iter); |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
| 2241 | static int tracing_open(struct inode *inode, struct file *file) |
| 2242 | { |
| 2243 | int ret; |
| 2244 | |
| 2245 | __tracing_open(inode, file, &ret); |
| 2246 | |
| 2247 | return ret; |
| 2248 | } |
| 2249 | |
| 2250 | static int tracing_lt_open(struct inode *inode, struct file *file) |
| 2251 | { |
| 2252 | struct trace_iterator *iter; |
| 2253 | int ret; |
| 2254 | |
| 2255 | iter = __tracing_open(inode, file, &ret); |
| 2256 | |
| 2257 | if (!ret) |
| 2258 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2259 | |
| 2260 | return ret; |
| 2261 | } |
| 2262 | |
| 2263 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2264 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2265 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2266 | { |
| 2267 | struct tracer *t = m->private; |
| 2268 | |
| 2269 | (*pos)++; |
| 2270 | |
| 2271 | if (t) |
| 2272 | t = t->next; |
| 2273 | |
| 2274 | m->private = t; |
| 2275 | |
| 2276 | return t; |
| 2277 | } |
| 2278 | |
| 2279 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2280 | { |
| 2281 | struct tracer *t = m->private; |
| 2282 | loff_t l = 0; |
| 2283 | |
| 2284 | mutex_lock(&trace_types_lock); |
| 2285 | for (; t && l < *pos; t = t_next(m, t, &l)) |
| 2286 | ; |
| 2287 | |
| 2288 | return t; |
| 2289 | } |
| 2290 | |
| 2291 | static void t_stop(struct seq_file *m, void *p) |
| 2292 | { |
| 2293 | mutex_unlock(&trace_types_lock); |
| 2294 | } |
| 2295 | |
| 2296 | static int t_show(struct seq_file *m, void *v) |
| 2297 | { |
| 2298 | struct tracer *t = v; |
| 2299 | |
| 2300 | if (!t) |
| 2301 | return 0; |
| 2302 | |
| 2303 | seq_printf(m, "%s", t->name); |
| 2304 | if (t->next) |
| 2305 | seq_putc(m, ' '); |
| 2306 | else |
| 2307 | seq_putc(m, '\n'); |
| 2308 | |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | static struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2313 | .start = t_start, |
| 2314 | .next = t_next, |
| 2315 | .stop = t_stop, |
| 2316 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2317 | }; |
| 2318 | |
| 2319 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2320 | { |
| 2321 | int ret; |
| 2322 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2323 | if (tracing_disabled) |
| 2324 | return -ENODEV; |
| 2325 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2326 | ret = seq_open(file, &show_traces_seq_ops); |
| 2327 | if (!ret) { |
| 2328 | struct seq_file *m = file->private_data; |
| 2329 | m->private = trace_types; |
| 2330 | } |
| 2331 | |
| 2332 | return ret; |
| 2333 | } |
| 2334 | |
| 2335 | static struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2336 | .open = tracing_open, |
| 2337 | .read = seq_read, |
| 2338 | .llseek = seq_lseek, |
| 2339 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2340 | }; |
| 2341 | |
| 2342 | static struct file_operations tracing_lt_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2343 | .open = tracing_lt_open, |
| 2344 | .read = seq_read, |
| 2345 | .llseek = seq_lseek, |
| 2346 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2347 | }; |
| 2348 | |
| 2349 | static struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2350 | .open = show_traces_open, |
| 2351 | .read = seq_read, |
| 2352 | .release = seq_release, |
| 2353 | }; |
| 2354 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2355 | /* |
| 2356 | * Only trace on a CPU if the bitmask is set: |
| 2357 | */ |
| 2358 | static cpumask_t tracing_cpumask = CPU_MASK_ALL; |
| 2359 | |
| 2360 | /* |
| 2361 | * When tracing/tracing_cpu_mask is modified then this holds |
| 2362 | * the new bitmask we are about to install: |
| 2363 | */ |
| 2364 | static cpumask_t tracing_cpumask_new; |
| 2365 | |
| 2366 | /* |
| 2367 | * The tracer itself will not take this lock, but still we want |
| 2368 | * to provide a consistent cpumask to user-space: |
| 2369 | */ |
| 2370 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2371 | |
| 2372 | /* |
| 2373 | * Temporary storage for the character representation of the |
| 2374 | * CPU bitmask (and one more byte for the newline): |
| 2375 | */ |
| 2376 | static char mask_str[NR_CPUS + 1]; |
| 2377 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2378 | static ssize_t |
| 2379 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 2380 | size_t count, loff_t *ppos) |
| 2381 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2382 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2383 | |
| 2384 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2385 | |
| 2386 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
| 2387 | if (count - len < 2) { |
| 2388 | count = -EINVAL; |
| 2389 | goto out_err; |
| 2390 | } |
| 2391 | len += sprintf(mask_str + len, "\n"); |
| 2392 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 2393 | |
| 2394 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2395 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2396 | |
| 2397 | return count; |
| 2398 | } |
| 2399 | |
| 2400 | static ssize_t |
| 2401 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 2402 | size_t count, loff_t *ppos) |
| 2403 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2404 | int err, cpu; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2405 | |
| 2406 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2407 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
| 2408 | if (err) |
| 2409 | goto err_unlock; |
| 2410 | |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2411 | raw_local_irq_disable(); |
| 2412 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2413 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2414 | /* |
| 2415 | * Increase/decrease the disabled counter if we are |
| 2416 | * about to flip a bit in the cpumask: |
| 2417 | */ |
| 2418 | if (cpu_isset(cpu, tracing_cpumask) && |
| 2419 | !cpu_isset(cpu, tracing_cpumask_new)) { |
| 2420 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2421 | } |
| 2422 | if (!cpu_isset(cpu, tracing_cpumask) && |
| 2423 | cpu_isset(cpu, tracing_cpumask_new)) { |
| 2424 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 2425 | } |
| 2426 | } |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2427 | __raw_spin_unlock(&ftrace_max_lock); |
| 2428 | raw_local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2429 | |
| 2430 | tracing_cpumask = tracing_cpumask_new; |
| 2431 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2432 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2433 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2434 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2435 | |
| 2436 | err_unlock: |
| 2437 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2438 | |
| 2439 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static struct file_operations tracing_cpumask_fops = { |
| 2443 | .open = tracing_open_generic, |
| 2444 | .read = tracing_cpumask_read, |
| 2445 | .write = tracing_cpumask_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2446 | }; |
| 2447 | |
| 2448 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2449 | tracing_trace_options_read(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2450 | size_t cnt, loff_t *ppos) |
| 2451 | { |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2452 | int i; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2453 | char *buf; |
| 2454 | int r = 0; |
| 2455 | int len = 0; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2456 | u32 tracer_flags = current_trace->flags->val; |
| 2457 | struct tracer_opt *trace_opts = current_trace->flags->opts; |
| 2458 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2459 | |
| 2460 | /* calulate max size */ |
| 2461 | for (i = 0; trace_options[i]; i++) { |
| 2462 | len += strlen(trace_options[i]); |
| 2463 | len += 3; /* "no" and space */ |
| 2464 | } |
| 2465 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2466 | /* |
| 2467 | * Increase the size with names of options specific |
| 2468 | * of the current tracer. |
| 2469 | */ |
| 2470 | for (i = 0; trace_opts[i].name; i++) { |
| 2471 | len += strlen(trace_opts[i].name); |
| 2472 | len += 3; /* "no" and space */ |
| 2473 | } |
| 2474 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2475 | /* +2 for \n and \0 */ |
| 2476 | buf = kmalloc(len + 2, GFP_KERNEL); |
| 2477 | if (!buf) |
| 2478 | return -ENOMEM; |
| 2479 | |
| 2480 | for (i = 0; trace_options[i]; i++) { |
| 2481 | if (trace_flags & (1 << i)) |
| 2482 | r += sprintf(buf + r, "%s ", trace_options[i]); |
| 2483 | else |
| 2484 | r += sprintf(buf + r, "no%s ", trace_options[i]); |
| 2485 | } |
| 2486 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2487 | for (i = 0; trace_opts[i].name; i++) { |
| 2488 | if (tracer_flags & trace_opts[i].bit) |
| 2489 | r += sprintf(buf + r, "%s ", |
| 2490 | trace_opts[i].name); |
| 2491 | else |
| 2492 | r += sprintf(buf + r, "no%s ", |
| 2493 | trace_opts[i].name); |
| 2494 | } |
| 2495 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2496 | r += sprintf(buf + r, "\n"); |
| 2497 | WARN_ON(r >= len + 2); |
| 2498 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2499 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2500 | |
| 2501 | kfree(buf); |
| 2502 | |
| 2503 | return r; |
| 2504 | } |
| 2505 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2506 | /* Try to assign a tracer specific option */ |
| 2507 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 2508 | { |
| 2509 | struct tracer_flags *trace_flags = trace->flags; |
| 2510 | struct tracer_opt *opts = NULL; |
| 2511 | int ret = 0, i = 0; |
| 2512 | int len; |
| 2513 | |
| 2514 | for (i = 0; trace_flags->opts[i].name; i++) { |
| 2515 | opts = &trace_flags->opts[i]; |
| 2516 | len = strlen(opts->name); |
| 2517 | |
| 2518 | if (strncmp(cmp, opts->name, len) == 0) { |
| 2519 | ret = trace->set_flag(trace_flags->val, |
| 2520 | opts->bit, !neg); |
| 2521 | break; |
| 2522 | } |
| 2523 | } |
| 2524 | /* Not found */ |
| 2525 | if (!trace_flags->opts[i].name) |
| 2526 | return -EINVAL; |
| 2527 | |
| 2528 | /* Refused to handle */ |
| 2529 | if (ret) |
| 2530 | return ret; |
| 2531 | |
| 2532 | if (neg) |
| 2533 | trace_flags->val &= ~opts->bit; |
| 2534 | else |
| 2535 | trace_flags->val |= opts->bit; |
| 2536 | |
| 2537 | return 0; |
| 2538 | } |
| 2539 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2540 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2541 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2542 | size_t cnt, loff_t *ppos) |
| 2543 | { |
| 2544 | char buf[64]; |
| 2545 | char *cmp = buf; |
| 2546 | int neg = 0; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2547 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2548 | int i; |
| 2549 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2550 | if (cnt >= sizeof(buf)) |
| 2551 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2552 | |
| 2553 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2554 | return -EFAULT; |
| 2555 | |
| 2556 | buf[cnt] = 0; |
| 2557 | |
| 2558 | if (strncmp(buf, "no", 2) == 0) { |
| 2559 | neg = 1; |
| 2560 | cmp += 2; |
| 2561 | } |
| 2562 | |
| 2563 | for (i = 0; trace_options[i]; i++) { |
| 2564 | int len = strlen(trace_options[i]); |
| 2565 | |
| 2566 | if (strncmp(cmp, trace_options[i], len) == 0) { |
| 2567 | if (neg) |
| 2568 | trace_flags &= ~(1 << i); |
| 2569 | else |
| 2570 | trace_flags |= (1 << i); |
| 2571 | break; |
| 2572 | } |
| 2573 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2574 | |
| 2575 | /* If no option could be set, test the specific tracer options */ |
| 2576 | if (!trace_options[i]) { |
| 2577 | ret = set_tracer_option(current_trace, cmp, neg); |
| 2578 | if (ret) |
| 2579 | return ret; |
| 2580 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2581 | |
| 2582 | filp->f_pos += cnt; |
| 2583 | |
| 2584 | return cnt; |
| 2585 | } |
| 2586 | |
| 2587 | static struct file_operations tracing_iter_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2588 | .open = tracing_open_generic, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2589 | .read = tracing_trace_options_read, |
| 2590 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2591 | }; |
| 2592 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2593 | static const char readme_msg[] = |
| 2594 | "tracing mini-HOWTO:\n\n" |
| 2595 | "# mkdir /debug\n" |
| 2596 | "# mount -t debugfs nodev /debug\n\n" |
| 2597 | "# cat /debug/tracing/available_tracers\n" |
| 2598 | "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n" |
| 2599 | "# cat /debug/tracing/current_tracer\n" |
| 2600 | "none\n" |
| 2601 | "# echo sched_switch > /debug/tracing/current_tracer\n" |
| 2602 | "# cat /debug/tracing/current_tracer\n" |
| 2603 | "sched_switch\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2604 | "# cat /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2605 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2606 | "# echo print-parent > /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2607 | "# echo 1 > /debug/tracing/tracing_enabled\n" |
| 2608 | "# cat /debug/tracing/trace > /tmp/trace.txt\n" |
| 2609 | "echo 0 > /debug/tracing/tracing_enabled\n" |
| 2610 | ; |
| 2611 | |
| 2612 | static ssize_t |
| 2613 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 2614 | size_t cnt, loff_t *ppos) |
| 2615 | { |
| 2616 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 2617 | readme_msg, strlen(readme_msg)); |
| 2618 | } |
| 2619 | |
| 2620 | static struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2621 | .open = tracing_open_generic, |
| 2622 | .read = tracing_readme_read, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2623 | }; |
| 2624 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2625 | static ssize_t |
| 2626 | tracing_ctrl_read(struct file *filp, char __user *ubuf, |
| 2627 | size_t cnt, loff_t *ppos) |
| 2628 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2629 | char buf[64]; |
| 2630 | int r; |
| 2631 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2632 | r = sprintf(buf, "%u\n", tracer_enabled); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2633 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | static ssize_t |
| 2637 | tracing_ctrl_write(struct file *filp, const char __user *ubuf, |
| 2638 | size_t cnt, loff_t *ppos) |
| 2639 | { |
| 2640 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2641 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2642 | long val; |
| 2643 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2644 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2645 | if (cnt >= sizeof(buf)) |
| 2646 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2647 | |
| 2648 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2649 | return -EFAULT; |
| 2650 | |
| 2651 | buf[cnt] = 0; |
| 2652 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2653 | ret = strict_strtoul(buf, 10, &val); |
| 2654 | if (ret < 0) |
| 2655 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2656 | |
| 2657 | val = !!val; |
| 2658 | |
| 2659 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2660 | if (tracer_enabled ^ val) { |
| 2661 | if (val) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2662 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2663 | if (current_trace->start) |
| 2664 | current_trace->start(tr); |
| 2665 | tracing_start(); |
| 2666 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2667 | tracer_enabled = 0; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2668 | tracing_stop(); |
| 2669 | if (current_trace->stop) |
| 2670 | current_trace->stop(tr); |
| 2671 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2672 | } |
| 2673 | mutex_unlock(&trace_types_lock); |
| 2674 | |
| 2675 | filp->f_pos += cnt; |
| 2676 | |
| 2677 | return cnt; |
| 2678 | } |
| 2679 | |
| 2680 | static ssize_t |
| 2681 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 2682 | size_t cnt, loff_t *ppos) |
| 2683 | { |
| 2684 | char buf[max_tracer_type_len+2]; |
| 2685 | int r; |
| 2686 | |
| 2687 | mutex_lock(&trace_types_lock); |
| 2688 | if (current_trace) |
| 2689 | r = sprintf(buf, "%s\n", current_trace->name); |
| 2690 | else |
| 2691 | r = sprintf(buf, "\n"); |
| 2692 | mutex_unlock(&trace_types_lock); |
| 2693 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2694 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2695 | } |
| 2696 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2697 | static int tracing_set_tracer(char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2698 | { |
| 2699 | struct trace_array *tr = &global_trace; |
| 2700 | struct tracer *t; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2701 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2702 | |
| 2703 | mutex_lock(&trace_types_lock); |
| 2704 | for (t = trace_types; t; t = t->next) { |
| 2705 | if (strcmp(t->name, buf) == 0) |
| 2706 | break; |
| 2707 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2708 | if (!t) { |
| 2709 | ret = -EINVAL; |
| 2710 | goto out; |
| 2711 | } |
| 2712 | if (t == current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2713 | goto out; |
| 2714 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2715 | trace_branch_disable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2716 | if (current_trace && current_trace->reset) |
| 2717 | current_trace->reset(tr); |
| 2718 | |
| 2719 | current_trace = t; |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 2720 | if (t->init) { |
| 2721 | ret = t->init(tr); |
| 2722 | if (ret) |
| 2723 | goto out; |
| 2724 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2725 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2726 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2727 | out: |
| 2728 | mutex_unlock(&trace_types_lock); |
| 2729 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2730 | return ret; |
| 2731 | } |
| 2732 | |
| 2733 | static ssize_t |
| 2734 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 2735 | size_t cnt, loff_t *ppos) |
| 2736 | { |
| 2737 | char buf[max_tracer_type_len+1]; |
| 2738 | int i; |
| 2739 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2740 | int err; |
| 2741 | |
| 2742 | ret = cnt; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2743 | |
| 2744 | if (cnt > max_tracer_type_len) |
| 2745 | cnt = max_tracer_type_len; |
| 2746 | |
| 2747 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2748 | return -EFAULT; |
| 2749 | |
| 2750 | buf[cnt] = 0; |
| 2751 | |
| 2752 | /* strip ending whitespace. */ |
| 2753 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 2754 | buf[i] = 0; |
| 2755 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2756 | err = tracing_set_tracer(buf); |
| 2757 | if (err) |
| 2758 | return err; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2759 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2760 | filp->f_pos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2761 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2762 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | static ssize_t |
| 2766 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 2767 | size_t cnt, loff_t *ppos) |
| 2768 | { |
| 2769 | unsigned long *ptr = filp->private_data; |
| 2770 | char buf[64]; |
| 2771 | int r; |
| 2772 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2773 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2774 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2775 | if (r > sizeof(buf)) |
| 2776 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2777 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | static ssize_t |
| 2781 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 2782 | size_t cnt, loff_t *ppos) |
| 2783 | { |
| 2784 | long *ptr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2785 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2786 | long val; |
| 2787 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2788 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2789 | if (cnt >= sizeof(buf)) |
| 2790 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2791 | |
| 2792 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2793 | return -EFAULT; |
| 2794 | |
| 2795 | buf[cnt] = 0; |
| 2796 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2797 | ret = strict_strtoul(buf, 10, &val); |
| 2798 | if (ret < 0) |
| 2799 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2800 | |
| 2801 | *ptr = val * 1000; |
| 2802 | |
| 2803 | return cnt; |
| 2804 | } |
| 2805 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2806 | static atomic_t tracing_reader; |
| 2807 | |
| 2808 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 2809 | { |
| 2810 | struct trace_iterator *iter; |
| 2811 | |
| 2812 | if (tracing_disabled) |
| 2813 | return -ENODEV; |
| 2814 | |
| 2815 | /* We only allow for reader of the pipe */ |
| 2816 | if (atomic_inc_return(&tracing_reader) != 1) { |
| 2817 | atomic_dec(&tracing_reader); |
| 2818 | return -EBUSY; |
| 2819 | } |
| 2820 | |
| 2821 | /* create a buffer to store the information to pass to userspace */ |
| 2822 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 2823 | if (!iter) |
| 2824 | return -ENOMEM; |
| 2825 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2826 | mutex_lock(&trace_types_lock); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2827 | |
| 2828 | /* trace pipe does not show start of buffer */ |
| 2829 | cpus_setall(iter->started); |
| 2830 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2831 | iter->tr = &global_trace; |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2832 | iter->trace = current_trace; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2833 | filp->private_data = iter; |
| 2834 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2835 | if (iter->trace->pipe_open) |
| 2836 | iter->trace->pipe_open(iter); |
| 2837 | mutex_unlock(&trace_types_lock); |
| 2838 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2839 | return 0; |
| 2840 | } |
| 2841 | |
| 2842 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 2843 | { |
| 2844 | struct trace_iterator *iter = file->private_data; |
| 2845 | |
| 2846 | kfree(iter); |
| 2847 | atomic_dec(&tracing_reader); |
| 2848 | |
| 2849 | return 0; |
| 2850 | } |
| 2851 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2852 | static unsigned int |
| 2853 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 2854 | { |
| 2855 | struct trace_iterator *iter = filp->private_data; |
| 2856 | |
| 2857 | if (trace_flags & TRACE_ITER_BLOCK) { |
| 2858 | /* |
| 2859 | * Always select as readable when in blocking mode |
| 2860 | */ |
| 2861 | return POLLIN | POLLRDNORM; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2862 | } else { |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2863 | if (!trace_empty(iter)) |
| 2864 | return POLLIN | POLLRDNORM; |
| 2865 | poll_wait(filp, &trace_wait, poll_table); |
| 2866 | if (!trace_empty(iter)) |
| 2867 | return POLLIN | POLLRDNORM; |
| 2868 | |
| 2869 | return 0; |
| 2870 | } |
| 2871 | } |
| 2872 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2873 | /* |
| 2874 | * Consumer reader. |
| 2875 | */ |
| 2876 | static ssize_t |
| 2877 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 2878 | size_t cnt, loff_t *ppos) |
| 2879 | { |
| 2880 | struct trace_iterator *iter = filp->private_data; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2881 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2882 | |
| 2883 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2884 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 2885 | if (sret != -EBUSY) |
| 2886 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2887 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2888 | trace_seq_reset(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2889 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2890 | mutex_lock(&trace_types_lock); |
| 2891 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2892 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 2893 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2894 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2895 | } |
| 2896 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2897 | waitagain: |
| 2898 | sret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2899 | while (trace_empty(iter)) { |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2900 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2901 | if ((filp->f_flags & O_NONBLOCK)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2902 | sret = -EAGAIN; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2903 | goto out; |
| 2904 | } |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2905 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2906 | /* |
| 2907 | * This is a make-shift waitqueue. The reason we don't use |
| 2908 | * an actual wait queue is because: |
| 2909 | * 1) we only ever have one waiter |
| 2910 | * 2) the tracing, traces all functions, we don't want |
| 2911 | * the overhead of calling wake_up and friends |
| 2912 | * (and tracing them too) |
| 2913 | * Anyway, this is really very primitive wakeup. |
| 2914 | */ |
| 2915 | set_current_state(TASK_INTERRUPTIBLE); |
| 2916 | iter->tr->waiter = current; |
| 2917 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2918 | mutex_unlock(&trace_types_lock); |
| 2919 | |
Ingo Molnar | 9fe068e | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2920 | /* sleep for 100 msecs, and try again. */ |
| 2921 | schedule_timeout(HZ/10); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2922 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2923 | mutex_lock(&trace_types_lock); |
| 2924 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2925 | iter->tr->waiter = NULL; |
| 2926 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2927 | if (signal_pending(current)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2928 | sret = -EINTR; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2929 | goto out; |
| 2930 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2931 | |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2932 | if (iter->trace != current_trace) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2933 | goto out; |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2934 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2935 | /* |
| 2936 | * We block until we read something and tracing is disabled. |
| 2937 | * We still block if tracing is disabled, but we have never |
| 2938 | * read anything. This allows a user to cat this file, and |
| 2939 | * then enable tracing. But after we have read something, |
| 2940 | * we give an EOF when tracing is again disabled. |
| 2941 | * |
| 2942 | * iter->pos will be 0 if we haven't read anything. |
| 2943 | */ |
| 2944 | if (!tracer_enabled && iter->pos) |
| 2945 | break; |
| 2946 | |
| 2947 | continue; |
| 2948 | } |
| 2949 | |
| 2950 | /* stop when tracing is finished */ |
| 2951 | if (trace_empty(iter)) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2952 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2953 | |
| 2954 | if (cnt >= PAGE_SIZE) |
| 2955 | cnt = PAGE_SIZE - 1; |
| 2956 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2957 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2958 | memset(&iter->seq, 0, |
| 2959 | sizeof(struct trace_iterator) - |
| 2960 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2961 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2962 | |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2963 | while (find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2964 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2965 | int len = iter->seq.len; |
| 2966 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2967 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2968 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2969 | /* don't print partial lines */ |
| 2970 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2971 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2972 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2973 | |
| 2974 | trace_consume(iter); |
| 2975 | |
| 2976 | if (iter->seq.len >= cnt) |
| 2977 | break; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2978 | } |
| 2979 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2980 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2981 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 2982 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2983 | trace_seq_reset(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2984 | |
| 2985 | /* |
| 2986 | * If there was nothing to send to user, inspite of consuming trace |
| 2987 | * entries, go back to wait for more entries. |
| 2988 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2989 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2990 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2991 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2992 | out: |
| 2993 | mutex_unlock(&trace_types_lock); |
| 2994 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2995 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2996 | } |
| 2997 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2998 | static ssize_t |
| 2999 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 3000 | size_t cnt, loff_t *ppos) |
| 3001 | { |
| 3002 | struct trace_array *tr = filp->private_data; |
| 3003 | char buf[64]; |
| 3004 | int r; |
| 3005 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3006 | r = sprintf(buf, "%lu\n", tr->entries >> 10); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3007 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3008 | } |
| 3009 | |
| 3010 | static ssize_t |
| 3011 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 3012 | size_t cnt, loff_t *ppos) |
| 3013 | { |
| 3014 | unsigned long val; |
| 3015 | char buf[64]; |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3016 | int ret, cpu; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3017 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3018 | if (cnt >= sizeof(buf)) |
| 3019 | return -EINVAL; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3020 | |
| 3021 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3022 | return -EFAULT; |
| 3023 | |
| 3024 | buf[cnt] = 0; |
| 3025 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3026 | ret = strict_strtoul(buf, 10, &val); |
| 3027 | if (ret < 0) |
| 3028 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3029 | |
| 3030 | /* must have at least 1 entry */ |
| 3031 | if (!val) |
| 3032 | return -EINVAL; |
| 3033 | |
| 3034 | mutex_lock(&trace_types_lock); |
| 3035 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3036 | tracing_stop(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3037 | |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3038 | /* disable all cpu buffers */ |
| 3039 | for_each_tracing_cpu(cpu) { |
| 3040 | if (global_trace.data[cpu]) |
| 3041 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 3042 | if (max_tr.data[cpu]) |
| 3043 | atomic_inc(&max_tr.data[cpu]->disabled); |
| 3044 | } |
| 3045 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3046 | /* value is in KB */ |
| 3047 | val <<= 10; |
| 3048 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3049 | if (val != global_trace.entries) { |
| 3050 | ret = ring_buffer_resize(global_trace.buffer, val); |
| 3051 | if (ret < 0) { |
| 3052 | cnt = ret; |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 3053 | goto out; |
| 3054 | } |
| 3055 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3056 | ret = ring_buffer_resize(max_tr.buffer, val); |
| 3057 | if (ret < 0) { |
| 3058 | int r; |
| 3059 | cnt = ret; |
| 3060 | r = ring_buffer_resize(global_trace.buffer, |
| 3061 | global_trace.entries); |
| 3062 | if (r < 0) { |
| 3063 | /* AARGH! We are left with different |
| 3064 | * size max buffer!!!! */ |
| 3065 | WARN_ON(1); |
| 3066 | tracing_disabled = 1; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3067 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3068 | goto out; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3069 | } |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 3070 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3071 | global_trace.entries = val; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | filp->f_pos += cnt; |
| 3075 | |
Steven Rostedt | 19384c0 | 2008-05-22 00:22:16 -0400 | [diff] [blame] | 3076 | /* If check pages failed, return ENOMEM */ |
| 3077 | if (tracing_disabled) |
| 3078 | cnt = -ENOMEM; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3079 | out: |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3080 | for_each_tracing_cpu(cpu) { |
| 3081 | if (global_trace.data[cpu]) |
| 3082 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 3083 | if (max_tr.data[cpu]) |
| 3084 | atomic_dec(&max_tr.data[cpu]->disabled); |
| 3085 | } |
| 3086 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3087 | tracing_start(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3088 | max_tr.entries = global_trace.entries; |
| 3089 | mutex_unlock(&trace_types_lock); |
| 3090 | |
| 3091 | return cnt; |
| 3092 | } |
| 3093 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3094 | static int mark_printk(const char *fmt, ...) |
| 3095 | { |
| 3096 | int ret; |
| 3097 | va_list args; |
| 3098 | va_start(args, fmt); |
| 3099 | ret = trace_vprintk(0, fmt, args); |
| 3100 | va_end(args); |
| 3101 | return ret; |
| 3102 | } |
| 3103 | |
| 3104 | static ssize_t |
| 3105 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 3106 | size_t cnt, loff_t *fpos) |
| 3107 | { |
| 3108 | char *buf; |
| 3109 | char *end; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3110 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3111 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3112 | return -EINVAL; |
| 3113 | |
| 3114 | if (cnt > TRACE_BUF_SIZE) |
| 3115 | cnt = TRACE_BUF_SIZE; |
| 3116 | |
| 3117 | buf = kmalloc(cnt + 1, GFP_KERNEL); |
| 3118 | if (buf == NULL) |
| 3119 | return -ENOMEM; |
| 3120 | |
| 3121 | if (copy_from_user(buf, ubuf, cnt)) { |
| 3122 | kfree(buf); |
| 3123 | return -EFAULT; |
| 3124 | } |
| 3125 | |
| 3126 | /* Cut from the first nil or newline. */ |
| 3127 | buf[cnt] = '\0'; |
| 3128 | end = strchr(buf, '\n'); |
| 3129 | if (end) |
| 3130 | *end = '\0'; |
| 3131 | |
| 3132 | cnt = mark_printk("%s\n", buf); |
| 3133 | kfree(buf); |
| 3134 | *fpos += cnt; |
| 3135 | |
| 3136 | return cnt; |
| 3137 | } |
| 3138 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3139 | static struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3140 | .open = tracing_open_generic, |
| 3141 | .read = tracing_max_lat_read, |
| 3142 | .write = tracing_max_lat_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3143 | }; |
| 3144 | |
| 3145 | static struct file_operations tracing_ctrl_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3146 | .open = tracing_open_generic, |
| 3147 | .read = tracing_ctrl_read, |
| 3148 | .write = tracing_ctrl_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3149 | }; |
| 3150 | |
| 3151 | static struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3152 | .open = tracing_open_generic, |
| 3153 | .read = tracing_set_trace_read, |
| 3154 | .write = tracing_set_trace_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3155 | }; |
| 3156 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3157 | static struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3158 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3159 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3160 | .read = tracing_read_pipe, |
| 3161 | .release = tracing_release_pipe, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3162 | }; |
| 3163 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3164 | static struct file_operations tracing_entries_fops = { |
| 3165 | .open = tracing_open_generic, |
| 3166 | .read = tracing_entries_read, |
| 3167 | .write = tracing_entries_write, |
| 3168 | }; |
| 3169 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3170 | static struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3171 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3172 | .write = tracing_mark_write, |
| 3173 | }; |
| 3174 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3175 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3176 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3177 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3178 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3179 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3180 | } |
| 3181 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3182 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3183 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3184 | size_t cnt, loff_t *ppos) |
| 3185 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3186 | static char ftrace_dyn_info_buffer[1024]; |
| 3187 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3188 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3189 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3190 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3191 | int r; |
| 3192 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3193 | mutex_lock(&dyn_info_mutex); |
| 3194 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3195 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3196 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3197 | buf[r++] = '\n'; |
| 3198 | |
| 3199 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3200 | |
| 3201 | mutex_unlock(&dyn_info_mutex); |
| 3202 | |
| 3203 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3204 | } |
| 3205 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3206 | static struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3207 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3208 | .read = tracing_read_dyn_info, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3209 | }; |
| 3210 | #endif |
| 3211 | |
| 3212 | static struct dentry *d_tracer; |
| 3213 | |
| 3214 | struct dentry *tracing_init_dentry(void) |
| 3215 | { |
| 3216 | static int once; |
| 3217 | |
| 3218 | if (d_tracer) |
| 3219 | return d_tracer; |
| 3220 | |
| 3221 | d_tracer = debugfs_create_dir("tracing", NULL); |
| 3222 | |
| 3223 | if (!d_tracer && !once) { |
| 3224 | once = 1; |
| 3225 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 3226 | return NULL; |
| 3227 | } |
| 3228 | |
| 3229 | return d_tracer; |
| 3230 | } |
| 3231 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3232 | #ifdef CONFIG_FTRACE_SELFTEST |
| 3233 | /* Let selftest have access to static functions in this file */ |
| 3234 | #include "trace_selftest.c" |
| 3235 | #endif |
| 3236 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3237 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3238 | { |
| 3239 | struct dentry *d_tracer; |
| 3240 | struct dentry *entry; |
| 3241 | |
| 3242 | d_tracer = tracing_init_dentry(); |
| 3243 | |
| 3244 | entry = debugfs_create_file("tracing_enabled", 0644, d_tracer, |
| 3245 | &global_trace, &tracing_ctrl_fops); |
| 3246 | if (!entry) |
| 3247 | pr_warning("Could not create debugfs 'tracing_enabled' entry\n"); |
| 3248 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3249 | entry = debugfs_create_file("trace_options", 0644, d_tracer, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3250 | NULL, &tracing_iter_fops); |
| 3251 | if (!entry) |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3252 | pr_warning("Could not create debugfs 'trace_options' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3253 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3254 | entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, |
| 3255 | NULL, &tracing_cpumask_fops); |
| 3256 | if (!entry) |
| 3257 | pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); |
| 3258 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3259 | entry = debugfs_create_file("latency_trace", 0444, d_tracer, |
| 3260 | &global_trace, &tracing_lt_fops); |
| 3261 | if (!entry) |
| 3262 | pr_warning("Could not create debugfs 'latency_trace' entry\n"); |
| 3263 | |
| 3264 | entry = debugfs_create_file("trace", 0444, d_tracer, |
| 3265 | &global_trace, &tracing_fops); |
| 3266 | if (!entry) |
| 3267 | pr_warning("Could not create debugfs 'trace' entry\n"); |
| 3268 | |
| 3269 | entry = debugfs_create_file("available_tracers", 0444, d_tracer, |
| 3270 | &global_trace, &show_traces_fops); |
| 3271 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3272 | pr_warning("Could not create debugfs 'available_tracers' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3273 | |
| 3274 | entry = debugfs_create_file("current_tracer", 0444, d_tracer, |
| 3275 | &global_trace, &set_tracer_fops); |
| 3276 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3277 | pr_warning("Could not create debugfs 'current_tracer' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3278 | |
| 3279 | entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer, |
| 3280 | &tracing_max_latency, |
| 3281 | &tracing_max_lat_fops); |
| 3282 | if (!entry) |
| 3283 | pr_warning("Could not create debugfs " |
| 3284 | "'tracing_max_latency' entry\n"); |
| 3285 | |
| 3286 | entry = debugfs_create_file("tracing_thresh", 0644, d_tracer, |
| 3287 | &tracing_thresh, &tracing_max_lat_fops); |
| 3288 | if (!entry) |
| 3289 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3290 | "'tracing_thresh' entry\n"); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3291 | entry = debugfs_create_file("README", 0644, d_tracer, |
| 3292 | NULL, &tracing_readme_fops); |
| 3293 | if (!entry) |
| 3294 | pr_warning("Could not create debugfs 'README' entry\n"); |
| 3295 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3296 | entry = debugfs_create_file("trace_pipe", 0644, d_tracer, |
| 3297 | NULL, &tracing_pipe_fops); |
| 3298 | if (!entry) |
| 3299 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3300 | "'trace_pipe' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3301 | |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3302 | entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3303 | &global_trace, &tracing_entries_fops); |
| 3304 | if (!entry) |
| 3305 | pr_warning("Could not create debugfs " |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3306 | "'buffer_size_kb' entry\n"); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3307 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3308 | entry = debugfs_create_file("trace_marker", 0220, d_tracer, |
| 3309 | NULL, &tracing_mark_fops); |
| 3310 | if (!entry) |
| 3311 | pr_warning("Could not create debugfs " |
| 3312 | "'trace_marker' entry\n"); |
| 3313 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3314 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3315 | entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 3316 | &ftrace_update_tot_cnt, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3317 | &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3318 | if (!entry) |
| 3319 | pr_warning("Could not create debugfs " |
| 3320 | "'dyn_ftrace_total_info' entry\n"); |
| 3321 | #endif |
Ingo Molnar | d618b3e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3322 | #ifdef CONFIG_SYSPROF_TRACER |
| 3323 | init_tracer_sysprof_debugfs(d_tracer); |
| 3324 | #endif |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3325 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3326 | } |
| 3327 | |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3328 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3329 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3330 | static DEFINE_SPINLOCK(trace_buf_lock); |
| 3331 | static char trace_buf[TRACE_BUF_SIZE]; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3332 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3333 | struct ring_buffer_event *event; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3334 | struct trace_array *tr = &global_trace; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3335 | struct trace_array_cpu *data; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3336 | struct print_entry *entry; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3337 | unsigned long flags, irq_flags; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3338 | int cpu, len = 0, size, pc; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3339 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3340 | if (tracing_disabled) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3341 | return 0; |
| 3342 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3343 | pc = preempt_count(); |
| 3344 | preempt_disable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3345 | cpu = raw_smp_processor_id(); |
| 3346 | data = tr->data[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3347 | |
Steven Rostedt | 3ea2e6d | 2008-10-04 02:01:00 -0400 | [diff] [blame] | 3348 | if (unlikely(atomic_read(&data->disabled))) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3349 | goto out; |
| 3350 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3351 | spin_lock_irqsave(&trace_buf_lock, flags); |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3352 | len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3353 | |
| 3354 | len = min(len, TRACE_BUF_SIZE-1); |
| 3355 | trace_buf[len] = 0; |
| 3356 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3357 | size = sizeof(*entry) + len + 1; |
| 3358 | event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3359 | if (!event) |
| 3360 | goto out_unlock; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3361 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3362 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3363 | entry->ent.type = TRACE_PRINT; |
| 3364 | entry->ip = ip; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3365 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3366 | memcpy(&entry->buf, trace_buf, len); |
| 3367 | entry->buf[len] = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3368 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3369 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3370 | out_unlock: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3371 | spin_unlock_irqrestore(&trace_buf_lock, flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3372 | |
| 3373 | out: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3374 | preempt_enable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3375 | |
| 3376 | return len; |
| 3377 | } |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3378 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 3379 | |
| 3380 | int __ftrace_printk(unsigned long ip, const char *fmt, ...) |
| 3381 | { |
| 3382 | int ret; |
| 3383 | va_list ap; |
| 3384 | |
| 3385 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 3386 | return 0; |
| 3387 | |
| 3388 | va_start(ap, fmt); |
| 3389 | ret = trace_vprintk(ip, fmt, ap); |
| 3390 | va_end(ap); |
| 3391 | return ret; |
| 3392 | } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3393 | EXPORT_SYMBOL_GPL(__ftrace_printk); |
| 3394 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3395 | static int trace_panic_handler(struct notifier_block *this, |
| 3396 | unsigned long event, void *unused) |
| 3397 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3398 | if (ftrace_dump_on_oops) |
| 3399 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3400 | return NOTIFY_OK; |
| 3401 | } |
| 3402 | |
| 3403 | static struct notifier_block trace_panic_notifier = { |
| 3404 | .notifier_call = trace_panic_handler, |
| 3405 | .next = NULL, |
| 3406 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 3407 | }; |
| 3408 | |
| 3409 | static int trace_die_handler(struct notifier_block *self, |
| 3410 | unsigned long val, |
| 3411 | void *data) |
| 3412 | { |
| 3413 | switch (val) { |
| 3414 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3415 | if (ftrace_dump_on_oops) |
| 3416 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3417 | break; |
| 3418 | default: |
| 3419 | break; |
| 3420 | } |
| 3421 | return NOTIFY_OK; |
| 3422 | } |
| 3423 | |
| 3424 | static struct notifier_block trace_die_notifier = { |
| 3425 | .notifier_call = trace_die_handler, |
| 3426 | .priority = 200 |
| 3427 | }; |
| 3428 | |
| 3429 | /* |
| 3430 | * printk is set to max of 1024, we really don't need it that big. |
| 3431 | * Nothing should be printing 1000 characters anyway. |
| 3432 | */ |
| 3433 | #define TRACE_MAX_PRINT 1000 |
| 3434 | |
| 3435 | /* |
| 3436 | * Define here KERN_TRACE so that we have one place to modify |
| 3437 | * it if we decide to change what log level the ftrace dump |
| 3438 | * should be at. |
| 3439 | */ |
| 3440 | #define KERN_TRACE KERN_INFO |
| 3441 | |
| 3442 | static void |
| 3443 | trace_printk_seq(struct trace_seq *s) |
| 3444 | { |
| 3445 | /* Probably should print a warning here. */ |
| 3446 | if (s->len >= 1000) |
| 3447 | s->len = 1000; |
| 3448 | |
| 3449 | /* should be zero ended, but we are paranoid. */ |
| 3450 | s->buffer[s->len] = 0; |
| 3451 | |
| 3452 | printk(KERN_TRACE "%s", s->buffer); |
| 3453 | |
| 3454 | trace_seq_reset(s); |
| 3455 | } |
| 3456 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3457 | void ftrace_dump(void) |
| 3458 | { |
| 3459 | static DEFINE_SPINLOCK(ftrace_dump_lock); |
| 3460 | /* use static because iter can be a bit big for the stack */ |
| 3461 | static struct trace_iterator iter; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3462 | static cpumask_t mask; |
| 3463 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3464 | unsigned long flags; |
| 3465 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3466 | |
| 3467 | /* only one dump */ |
| 3468 | spin_lock_irqsave(&ftrace_dump_lock, flags); |
| 3469 | if (dump_ran) |
| 3470 | goto out; |
| 3471 | |
| 3472 | dump_ran = 1; |
| 3473 | |
| 3474 | /* No turning back! */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 3475 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3476 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3477 | for_each_tracing_cpu(cpu) { |
| 3478 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 3479 | } |
| 3480 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3481 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
| 3482 | |
| 3483 | iter.tr = &global_trace; |
| 3484 | iter.trace = current_trace; |
| 3485 | |
| 3486 | /* |
| 3487 | * We need to stop all tracing on all CPUS to read the |
| 3488 | * the next buffer. This is a bit expensive, but is |
| 3489 | * not done often. We fill all what we can read, |
| 3490 | * and then release the locks again. |
| 3491 | */ |
| 3492 | |
| 3493 | cpus_clear(mask); |
| 3494 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3495 | while (!trace_empty(&iter)) { |
| 3496 | |
| 3497 | if (!cnt) |
| 3498 | printk(KERN_TRACE "---------------------------------\n"); |
| 3499 | |
| 3500 | cnt++; |
| 3501 | |
| 3502 | /* reset all but tr, trace, and overruns */ |
| 3503 | memset(&iter.seq, 0, |
| 3504 | sizeof(struct trace_iterator) - |
| 3505 | offsetof(struct trace_iterator, seq)); |
| 3506 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 3507 | iter.pos = -1; |
| 3508 | |
| 3509 | if (find_next_entry_inc(&iter) != NULL) { |
| 3510 | print_trace_line(&iter); |
| 3511 | trace_consume(&iter); |
| 3512 | } |
| 3513 | |
| 3514 | trace_printk_seq(&iter.seq); |
| 3515 | } |
| 3516 | |
| 3517 | if (!cnt) |
| 3518 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 3519 | else |
| 3520 | printk(KERN_TRACE "---------------------------------\n"); |
| 3521 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3522 | out: |
| 3523 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); |
| 3524 | } |
| 3525 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3526 | __init static int tracer_alloc_buffers(void) |
| 3527 | { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3528 | struct trace_array_cpu *data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3529 | int i; |
| 3530 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3531 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3532 | tracing_buffer_mask = cpu_possible_map; |
| 3533 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3534 | global_trace.buffer = ring_buffer_alloc(trace_buf_size, |
| 3535 | TRACE_BUFFER_FLAGS); |
| 3536 | if (!global_trace.buffer) { |
| 3537 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 3538 | WARN_ON(1); |
| 3539 | return 0; |
| 3540 | } |
| 3541 | global_trace.entries = ring_buffer_size(global_trace.buffer); |
| 3542 | |
| 3543 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3544 | max_tr.buffer = ring_buffer_alloc(trace_buf_size, |
| 3545 | TRACE_BUFFER_FLAGS); |
| 3546 | if (!max_tr.buffer) { |
| 3547 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); |
| 3548 | WARN_ON(1); |
| 3549 | ring_buffer_free(global_trace.buffer); |
| 3550 | return 0; |
| 3551 | } |
| 3552 | max_tr.entries = ring_buffer_size(max_tr.buffer); |
| 3553 | WARN_ON(max_tr.entries != global_trace.entries); |
| 3554 | #endif |
| 3555 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3556 | /* Allocate the first page for all buffers */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3557 | for_each_tracing_cpu(i) { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3558 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3559 | max_tr.data[i] = &per_cpu(max_data, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3560 | } |
| 3561 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3562 | trace_init_cmdlines(); |
| 3563 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3564 | register_tracer(&nop_trace); |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3565 | #ifdef CONFIG_BOOT_TRACER |
| 3566 | register_tracer(&boot_tracer); |
| 3567 | current_trace = &boot_tracer; |
| 3568 | current_trace->init(&global_trace); |
| 3569 | #else |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3570 | current_trace = &nop_trace; |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3571 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3572 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3573 | /* All seems OK, enable tracing */ |
| 3574 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3575 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3576 | atomic_notifier_chain_register(&panic_notifier_list, |
| 3577 | &trace_panic_notifier); |
| 3578 | |
| 3579 | register_die_notifier(&trace_die_notifier); |
| 3580 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3581 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3582 | } |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3583 | early_initcall(tracer_alloc_buffers); |
| 3584 | fs_initcall(tracer_init_debugfs); |