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