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 | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame^] | 1212 | if (!ftrace_graph_addr(trace->func)) |
| 1213 | return 0; |
| 1214 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 1215 | local_irq_save(flags); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1216 | cpu = raw_smp_processor_id(); |
| 1217 | data = tr->data[cpu]; |
| 1218 | disabled = atomic_inc_return(&data->disabled); |
| 1219 | if (likely(disabled == 1)) { |
| 1220 | pc = preempt_count(); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1221 | __trace_graph_entry(tr, data, trace, flags, pc); |
| 1222 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame^] | 1223 | /* Only do the atomic if it is not already set */ |
| 1224 | if (!test_tsk_trace_graph(current)) |
| 1225 | set_tsk_trace_graph(current); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1226 | atomic_dec(&data->disabled); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 1227 | local_irq_restore(flags); |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 1228 | |
| 1229 | return 1; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | void trace_graph_return(struct ftrace_graph_ret *trace) |
| 1233 | { |
| 1234 | struct trace_array *tr = &global_trace; |
| 1235 | struct trace_array_cpu *data; |
| 1236 | unsigned long flags; |
| 1237 | long disabled; |
| 1238 | int cpu; |
| 1239 | int pc; |
| 1240 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 1241 | local_irq_save(flags); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1242 | cpu = raw_smp_processor_id(); |
| 1243 | data = tr->data[cpu]; |
| 1244 | disabled = atomic_inc_return(&data->disabled); |
| 1245 | if (likely(disabled == 1)) { |
| 1246 | pc = preempt_count(); |
| 1247 | __trace_graph_return(tr, data, trace, flags, pc); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1248 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame^] | 1249 | if (!trace->depth) |
| 1250 | clear_tsk_trace_graph(current); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1251 | atomic_dec(&data->disabled); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 1252 | local_irq_restore(flags); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1253 | } |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1254 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1255 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1256 | static struct ftrace_ops trace_ops __read_mostly = |
| 1257 | { |
| 1258 | .func = function_trace_call, |
| 1259 | }; |
| 1260 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1261 | void tracing_start_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1262 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1263 | ftrace_function_enabled = 0; |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1264 | |
| 1265 | if (trace_flags & TRACE_ITER_PREEMPTONLY) |
| 1266 | trace_ops.func = function_trace_call_preempt_only; |
| 1267 | else |
| 1268 | trace_ops.func = function_trace_call; |
| 1269 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1270 | register_ftrace_function(&trace_ops); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1271 | ftrace_function_enabled = 1; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1274 | void tracing_stop_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1275 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1276 | ftrace_function_enabled = 0; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1277 | unregister_ftrace_function(&trace_ops); |
| 1278 | } |
| 1279 | #endif |
| 1280 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1281 | enum trace_file_type { |
| 1282 | TRACE_FILE_LAT_FMT = 1, |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1283 | TRACE_FILE_ANNOTATE = 2, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1284 | }; |
| 1285 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1286 | static void trace_iterator_increment(struct trace_iterator *iter, int cpu) |
| 1287 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1288 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1289 | ftrace_disable_cpu(); |
| 1290 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1291 | iter->idx++; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1292 | if (iter->buffer_iter[iter->cpu]) |
| 1293 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1294 | |
| 1295 | ftrace_enable_cpu(); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1298 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1299 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1300 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1301 | struct ring_buffer_event *event; |
| 1302 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1303 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1304 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1305 | ftrace_disable_cpu(); |
| 1306 | |
| 1307 | if (buf_iter) |
| 1308 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 1309 | else |
| 1310 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); |
| 1311 | |
| 1312 | ftrace_enable_cpu(); |
| 1313 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1314 | return event ? ring_buffer_event_data(event) : NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1315 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1316 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1317 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1318 | __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] | 1319 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1320 | struct ring_buffer *buffer = iter->tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1321 | struct trace_entry *ent, *next = NULL; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1322 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1323 | int next_cpu = -1; |
| 1324 | int cpu; |
| 1325 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1326 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1327 | |
| 1328 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1329 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1330 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1331 | ent = peek_next_entry(iter, cpu, &ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1332 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1333 | /* |
| 1334 | * Pick the entry with the smallest timestamp: |
| 1335 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1336 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1337 | next = ent; |
| 1338 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1339 | next_ts = ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | if (ent_cpu) |
| 1344 | *ent_cpu = next_cpu; |
| 1345 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1346 | if (ent_ts) |
| 1347 | *ent_ts = next_ts; |
| 1348 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1349 | return next; |
| 1350 | } |
| 1351 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1352 | /* Find the next real entry, without updating the iterator itself */ |
| 1353 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1354 | 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] | 1355 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1356 | return __find_next_entry(iter, ent_cpu, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1357 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1358 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1359 | /* Find the next real entry, and increment the iterator to the next entry */ |
| 1360 | static void *find_next_entry_inc(struct trace_iterator *iter) |
| 1361 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1362 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1363 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1364 | if (iter->ent) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1365 | trace_iterator_increment(iter, iter->cpu); |
| 1366 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1367 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1370 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1371 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1372 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1373 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1374 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1375 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1378 | 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] | 1379 | { |
| 1380 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1381 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1382 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1383 | |
| 1384 | (*pos)++; |
| 1385 | |
| 1386 | /* can't go backwards */ |
| 1387 | if (iter->idx > i) |
| 1388 | return NULL; |
| 1389 | |
| 1390 | if (iter->idx < 0) |
| 1391 | ent = find_next_entry_inc(iter); |
| 1392 | else |
| 1393 | ent = iter; |
| 1394 | |
| 1395 | while (ent && iter->idx < i) |
| 1396 | ent = find_next_entry_inc(iter); |
| 1397 | |
| 1398 | iter->pos = *pos; |
| 1399 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1400 | return ent; |
| 1401 | } |
| 1402 | |
| 1403 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 1404 | { |
| 1405 | struct trace_iterator *iter = m->private; |
| 1406 | void *p = NULL; |
| 1407 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1408 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1409 | |
| 1410 | mutex_lock(&trace_types_lock); |
| 1411 | |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1412 | if (!current_trace || current_trace != iter->trace) { |
| 1413 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1414 | return NULL; |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1415 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1416 | |
| 1417 | atomic_inc(&trace_record_cmdline_disabled); |
| 1418 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1419 | if (*pos != iter->pos) { |
| 1420 | iter->ent = NULL; |
| 1421 | iter->cpu = 0; |
| 1422 | iter->idx = -1; |
| 1423 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1424 | ftrace_disable_cpu(); |
| 1425 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1426 | for_each_tracing_cpu(cpu) { |
| 1427 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1428 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1429 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1430 | ftrace_enable_cpu(); |
| 1431 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1432 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 1433 | ; |
| 1434 | |
| 1435 | } else { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1436 | l = *pos - 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1437 | p = s_next(m, p, &l); |
| 1438 | } |
| 1439 | |
| 1440 | return p; |
| 1441 | } |
| 1442 | |
| 1443 | static void s_stop(struct seq_file *m, void *p) |
| 1444 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1445 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1446 | mutex_unlock(&trace_types_lock); |
| 1447 | } |
| 1448 | |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1449 | #ifdef CONFIG_KRETPROBES |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1450 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1451 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1452 | static const char tramp_name[] = "kretprobe_trampoline"; |
| 1453 | int size = sizeof(tramp_name); |
| 1454 | |
| 1455 | if (strncmp(tramp_name, name, size) == 0) |
| 1456 | return "[unknown/kretprobe'd]"; |
| 1457 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1458 | } |
| 1459 | #else |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1460 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1461 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1462 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1463 | } |
| 1464 | #endif /* CONFIG_KRETPROBES */ |
| 1465 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1466 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1467 | 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] | 1468 | { |
| 1469 | #ifdef CONFIG_KALLSYMS |
| 1470 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1471 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1472 | |
| 1473 | kallsyms_lookup(address, NULL, NULL, NULL, str); |
| 1474 | |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1475 | name = kretprobed(str); |
| 1476 | |
| 1477 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1478 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1479 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1480 | } |
| 1481 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1482 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1483 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, |
| 1484 | unsigned long address) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1485 | { |
| 1486 | #ifdef CONFIG_KALLSYMS |
| 1487 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1488 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1489 | |
| 1490 | sprint_symbol(str, address); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1491 | name = kretprobed(str); |
| 1492 | |
| 1493 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1494 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1495 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | #ifndef CONFIG_64BIT |
| 1499 | # define IP_FMT "%08lx" |
| 1500 | #else |
| 1501 | # define IP_FMT "%016lx" |
| 1502 | #endif |
| 1503 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1504 | int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1505 | 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] | 1506 | { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1507 | int ret; |
| 1508 | |
| 1509 | if (!ip) |
| 1510 | return trace_seq_printf(s, "0"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1511 | |
| 1512 | if (sym_flags & TRACE_ITER_SYM_OFFSET) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1513 | ret = seq_print_sym_offset(s, "%s", ip); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1514 | else |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1515 | ret = seq_print_sym_short(s, "%s", ip); |
| 1516 | |
| 1517 | if (!ret) |
| 1518 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1519 | |
| 1520 | if (sym_flags & TRACE_ITER_SYM_ADDR) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1521 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 1522 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1525 | static inline int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, |
| 1526 | unsigned long ip, unsigned long sym_flags) |
| 1527 | { |
| 1528 | struct file *file = NULL; |
| 1529 | unsigned long vmstart = 0; |
| 1530 | int ret = 1; |
| 1531 | |
| 1532 | if (mm) { |
Török Edwin | cffa10a | 2008-11-23 12:39:07 +0200 | [diff] [blame] | 1533 | const struct vm_area_struct *vma; |
| 1534 | |
| 1535 | down_read(&mm->mmap_sem); |
| 1536 | vma = find_vma(mm, ip); |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1537 | if (vma) { |
| 1538 | file = vma->vm_file; |
| 1539 | vmstart = vma->vm_start; |
| 1540 | } |
Török Edwin | e38da59 | 2008-11-23 13:08:10 +0200 | [diff] [blame] | 1541 | if (file) { |
| 1542 | ret = trace_seq_path(s, &file->f_path); |
| 1543 | if (ret) |
| 1544 | ret = trace_seq_printf(s, "[+0x%lx]", ip - vmstart); |
| 1545 | } |
Török Edwin | cffa10a | 2008-11-23 12:39:07 +0200 | [diff] [blame] | 1546 | up_read(&mm->mmap_sem); |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1547 | } |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1548 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) |
| 1549 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 1550 | return ret; |
| 1551 | } |
| 1552 | |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1553 | static int |
| 1554 | 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] | 1555 | unsigned long sym_flags) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1556 | { |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1557 | struct mm_struct *mm = NULL; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1558 | int ret = 1; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1559 | unsigned int i; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1560 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1561 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { |
| 1562 | struct task_struct *task; |
| 1563 | /* |
| 1564 | * we do the lookup on the thread group leader, |
| 1565 | * since individual threads might have already quit! |
| 1566 | */ |
| 1567 | rcu_read_lock(); |
| 1568 | task = find_task_by_vpid(entry->ent.tgid); |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1569 | if (task) |
| 1570 | mm = get_task_mm(task); |
Török Edwin | cffa10a | 2008-11-23 12:39:07 +0200 | [diff] [blame] | 1571 | rcu_read_unlock(); |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1574 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1575 | unsigned long ip = entry->caller[i]; |
| 1576 | |
| 1577 | if (ip == ULONG_MAX || !ret) |
| 1578 | break; |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1579 | if (i && ret) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1580 | ret = trace_seq_puts(s, " <- "); |
| 1581 | if (!ip) { |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1582 | if (ret) |
| 1583 | ret = trace_seq_puts(s, "??"); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1584 | continue; |
| 1585 | } |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1586 | if (!ret) |
| 1587 | break; |
| 1588 | if (ret) |
| 1589 | ret = seq_print_user_ip(s, mm, ip, sym_flags); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1590 | } |
| 1591 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1592 | if (mm) |
| 1593 | mmput(mm); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1594 | return ret; |
| 1595 | } |
| 1596 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1597 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1598 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1599 | seq_puts(m, "# _------=> CPU# \n"); |
| 1600 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 1601 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 1602 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 1603 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
| 1604 | seq_puts(m, "# |||| / \n"); |
| 1605 | seq_puts(m, "# ||||| delay \n"); |
| 1606 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 1607 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1608 | } |
| 1609 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1610 | static void print_func_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1611 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1612 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
| 1613 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1617 | static void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1618 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 1619 | { |
| 1620 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1621 | struct trace_array *tr = iter->tr; |
| 1622 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
| 1623 | struct tracer *type = current_trace; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1624 | unsigned long total; |
| 1625 | unsigned long entries; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1626 | const char *name = "preemption"; |
| 1627 | |
| 1628 | if (type) |
| 1629 | name = type->name; |
| 1630 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1631 | entries = ring_buffer_entries(iter->tr->buffer); |
| 1632 | total = entries + |
| 1633 | ring_buffer_overruns(iter->tr->buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1634 | |
| 1635 | seq_printf(m, "%s latency trace v1.1.5 on %s\n", |
| 1636 | name, UTS_RELEASE); |
| 1637 | seq_puts(m, "-----------------------------------" |
| 1638 | "---------------------------------\n"); |
| 1639 | seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |" |
| 1640 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1641 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1642 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1643 | total, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1644 | tr->cpu, |
| 1645 | #if defined(CONFIG_PREEMPT_NONE) |
| 1646 | "server", |
| 1647 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 1648 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 1649 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1650 | "preempt", |
| 1651 | #else |
| 1652 | "unknown", |
| 1653 | #endif |
| 1654 | /* These are reserved for later use */ |
| 1655 | 0, 0, 0, 0); |
| 1656 | #ifdef CONFIG_SMP |
| 1657 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 1658 | #else |
| 1659 | seq_puts(m, ")\n"); |
| 1660 | #endif |
| 1661 | seq_puts(m, " -----------------\n"); |
| 1662 | seq_printf(m, " | task: %.16s-%d " |
| 1663 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
| 1664 | data->comm, data->pid, data->uid, data->nice, |
| 1665 | data->policy, data->rt_priority); |
| 1666 | seq_puts(m, " -----------------\n"); |
| 1667 | |
| 1668 | if (data->critical_start) { |
| 1669 | seq_puts(m, " => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1670 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 1671 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1672 | seq_puts(m, "\n => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1673 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 1674 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1675 | seq_puts(m, "\n"); |
| 1676 | } |
| 1677 | |
| 1678 | seq_puts(m, "\n"); |
| 1679 | } |
| 1680 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1681 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1682 | 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] | 1683 | { |
| 1684 | int hardirq, softirq; |
| 1685 | char *comm; |
| 1686 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1687 | comm = trace_find_cmdline(entry->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1688 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1689 | trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1690 | trace_seq_printf(s, "%3d", cpu); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1691 | trace_seq_printf(s, "%c%c", |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1692 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 1693 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.', |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1694 | ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.')); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1695 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1696 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; |
| 1697 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1698 | if (hardirq && softirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1699 | trace_seq_putc(s, 'H'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1700 | } else { |
| 1701 | if (hardirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1702 | trace_seq_putc(s, 'h'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1703 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1704 | if (softirq) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1705 | trace_seq_putc(s, 's'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1706 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1707 | trace_seq_putc(s, '.'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1711 | if (entry->preempt_count) |
| 1712 | trace_seq_printf(s, "%x", entry->preempt_count); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1713 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1714 | trace_seq_puts(s, "."); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | unsigned long preempt_mark_thresh = 100; |
| 1718 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1719 | static void |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1720 | lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1721 | unsigned long rel_usecs) |
| 1722 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1723 | trace_seq_printf(s, " %4lldus", abs_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1724 | if (rel_usecs > preempt_mark_thresh) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1725 | trace_seq_puts(s, "!: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1726 | else if (rel_usecs > 1) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1727 | trace_seq_puts(s, "+: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1728 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1729 | trace_seq_puts(s, " : "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; |
| 1733 | |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1734 | /* |
| 1735 | * The message is supposed to contain an ending newline. |
| 1736 | * If the printing stops prematurely, try to add a newline of our own. |
| 1737 | */ |
| 1738 | 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] | 1739 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1740 | struct trace_entry *ent; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1741 | struct trace_field_cont *cont; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1742 | bool ok = true; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1743 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1744 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1745 | if (!ent || ent->type != TRACE_CONT) { |
| 1746 | trace_seq_putc(s, '\n'); |
| 1747 | return; |
| 1748 | } |
| 1749 | |
| 1750 | do { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1751 | cont = (struct trace_field_cont *)ent; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1752 | if (ok) |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1753 | ok = (trace_seq_printf(s, "%s", cont->buf) > 0); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1754 | |
| 1755 | ftrace_disable_cpu(); |
| 1756 | |
| 1757 | if (iter->buffer_iter[iter->cpu]) |
| 1758 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1759 | else |
| 1760 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); |
| 1761 | |
| 1762 | ftrace_enable_cpu(); |
| 1763 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1764 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1765 | } while (ent && ent->type == TRACE_CONT); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1766 | |
| 1767 | if (!ok) |
| 1768 | trace_seq_putc(s, '\n'); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1769 | } |
| 1770 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1771 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 1772 | { |
| 1773 | struct trace_seq *s = &iter->seq; |
| 1774 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1775 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 1776 | return; |
| 1777 | |
| 1778 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 1779 | return; |
| 1780 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1781 | if (cpu_isset(iter->cpu, iter->started)) |
| 1782 | return; |
| 1783 | |
| 1784 | cpu_set(iter->cpu, iter->started); |
| 1785 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); |
| 1786 | } |
| 1787 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1788 | static enum print_line_t |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1789 | 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] | 1790 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1791 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1792 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1793 | struct trace_entry *next_entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1794 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); |
| 1795 | struct trace_entry *entry = iter->ent; |
| 1796 | unsigned long abs_usecs; |
| 1797 | unsigned long rel_usecs; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1798 | u64 next_ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1799 | char *comm; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1800 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1801 | int i; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1802 | unsigned state; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1803 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1804 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1805 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1806 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1807 | test_cpu_buff_start(iter); |
| 1808 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1809 | next_entry = find_next_entry(iter, NULL, &next_ts); |
| 1810 | if (!next_entry) |
| 1811 | next_ts = iter->ts; |
| 1812 | rel_usecs = ns2usecs(next_ts - iter->ts); |
| 1813 | abs_usecs = ns2usecs(iter->ts - iter->tr->time_start); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1814 | |
| 1815 | if (verbose) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1816 | comm = trace_find_cmdline(entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1817 | trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]" |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1818 | " %ld.%03ldms (+%ld.%03ldms): ", |
| 1819 | comm, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1820 | entry->pid, cpu, entry->flags, |
| 1821 | entry->preempt_count, trace_idx, |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1822 | ns2usecs(iter->ts), |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1823 | abs_usecs/1000, |
| 1824 | abs_usecs % 1000, rel_usecs/1000, |
| 1825 | rel_usecs % 1000); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1826 | } else { |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1827 | lat_print_generic(s, entry, cpu); |
| 1828 | lat_print_timestamp(s, abs_usecs, rel_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1829 | } |
| 1830 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1831 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1832 | struct ftrace_entry *field; |
| 1833 | |
| 1834 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1835 | |
| 1836 | seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1837 | trace_seq_puts(s, " ("); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1838 | seq_print_ip_sym(s, field->parent_ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1839 | trace_seq_puts(s, ")\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1840 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1841 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1842 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1843 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1844 | struct ctx_switch_entry *field; |
| 1845 | |
| 1846 | trace_assign_type(field, entry); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1847 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1848 | T = field->next_state < sizeof(state_to_char) ? |
| 1849 | state_to_char[field->next_state] : 'X'; |
| 1850 | |
| 1851 | state = field->prev_state ? |
| 1852 | __ffs(field->prev_state) + 1 : 0; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1853 | S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1854 | comm = trace_find_cmdline(field->next_pid); |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1855 | 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] | 1856 | field->prev_pid, |
| 1857 | field->prev_prio, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1858 | S, entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1859 | field->next_cpu, |
| 1860 | field->next_pid, |
| 1861 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1862 | T, comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1863 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1864 | } |
| 1865 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1866 | struct special_entry *field; |
| 1867 | |
| 1868 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1869 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1870 | trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1871 | field->arg1, |
| 1872 | field->arg2, |
| 1873 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1874 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1875 | } |
| 1876 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1877 | struct stack_entry *field; |
| 1878 | |
| 1879 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1880 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1881 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1882 | if (i) |
| 1883 | trace_seq_puts(s, " <= "); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1884 | seq_print_ip_sym(s, field->caller[i], sym_flags); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1885 | } |
| 1886 | trace_seq_puts(s, "\n"); |
| 1887 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1888 | } |
| 1889 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1890 | struct print_entry *field; |
| 1891 | |
| 1892 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1893 | |
| 1894 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 1895 | trace_seq_printf(s, ": %s", field->buf); |
| 1896 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1897 | trace_seq_print_cont(s, iter); |
| 1898 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1899 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 1900 | case TRACE_BRANCH: { |
| 1901 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1902 | |
| 1903 | trace_assign_type(field, entry); |
| 1904 | |
| 1905 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 1906 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1907 | field->func, |
| 1908 | field->file, |
| 1909 | field->line); |
| 1910 | break; |
| 1911 | } |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1912 | case TRACE_USER_STACK: { |
| 1913 | struct userstack_entry *field; |
| 1914 | |
| 1915 | trace_assign_type(field, entry); |
| 1916 | |
| 1917 | seq_print_userip_objs(field, s, sym_flags); |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 1918 | trace_seq_putc(s, '\n'); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1919 | break; |
| 1920 | } |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1921 | default: |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1922 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1923 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1924 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1927 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1928 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1929 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1930 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1931 | struct trace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1932 | unsigned long usec_rem; |
| 1933 | unsigned long long t; |
| 1934 | unsigned long secs; |
| 1935 | char *comm; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1936 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1937 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1938 | int i; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1939 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1940 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1941 | |
| 1942 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1943 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1944 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1945 | test_cpu_buff_start(iter); |
| 1946 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1947 | comm = trace_find_cmdline(iter->ent->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1948 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1949 | t = ns2usecs(iter->ts); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1950 | usec_rem = do_div(t, 1000000ULL); |
| 1951 | secs = (unsigned long)t; |
| 1952 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1953 | ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1954 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1955 | return TRACE_TYPE_PARTIAL_LINE; |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1956 | ret = trace_seq_printf(s, "[%03d] ", iter->cpu); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1957 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1958 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1959 | ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem); |
| 1960 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1961 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1962 | |
| 1963 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1964 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1965 | struct ftrace_entry *field; |
| 1966 | |
| 1967 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1968 | |
| 1969 | ret = seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1970 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1971 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1972 | if ((sym_flags & TRACE_ITER_PRINT_PARENT) && |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1973 | field->parent_ip) { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1974 | ret = trace_seq_printf(s, " <-"); |
| 1975 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1976 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1977 | ret = seq_print_ip_sym(s, |
| 1978 | field->parent_ip, |
| 1979 | sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1980 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1981 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1982 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1983 | ret = trace_seq_printf(s, "\n"); |
| 1984 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1985 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1986 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1987 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1988 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1989 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1990 | struct ctx_switch_entry *field; |
| 1991 | |
| 1992 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1993 | |
| 1994 | S = field->prev_state < sizeof(state_to_char) ? |
| 1995 | state_to_char[field->prev_state] : 'X'; |
| 1996 | T = field->next_state < sizeof(state_to_char) ? |
| 1997 | state_to_char[field->next_state] : 'X'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1998 | 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] | 1999 | field->prev_pid, |
| 2000 | field->prev_prio, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2001 | S, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2002 | entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2003 | field->next_cpu, |
| 2004 | field->next_pid, |
| 2005 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2006 | T); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2007 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2008 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2009 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2010 | } |
| 2011 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2012 | struct special_entry *field; |
| 2013 | |
| 2014 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2015 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2016 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2017 | field->arg1, |
| 2018 | field->arg2, |
| 2019 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2020 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2021 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2022 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2023 | } |
| 2024 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2025 | struct stack_entry *field; |
| 2026 | |
| 2027 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2028 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2029 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 2030 | if (i) { |
| 2031 | ret = trace_seq_puts(s, " <= "); |
| 2032 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2033 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2034 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2035 | ret = seq_print_ip_sym(s, field->caller[i], |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2036 | sym_flags); |
| 2037 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2038 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2039 | } |
| 2040 | ret = trace_seq_puts(s, "\n"); |
| 2041 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2042 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2043 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2044 | } |
| 2045 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2046 | struct print_entry *field; |
| 2047 | |
| 2048 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2049 | |
| 2050 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 2051 | trace_seq_printf(s, ": %s", field->buf); |
| 2052 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2053 | trace_seq_print_cont(s, iter); |
| 2054 | break; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2055 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2056 | case TRACE_GRAPH_RET: { |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2057 | return print_graph_function(iter); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2058 | } |
| 2059 | case TRACE_GRAPH_ENT: { |
| 2060 | return print_graph_function(iter); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2061 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2062 | case TRACE_BRANCH: { |
| 2063 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 2064 | |
| 2065 | trace_assign_type(field, entry); |
| 2066 | |
| 2067 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 2068 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 2069 | field->func, |
| 2070 | field->file, |
| 2071 | field->line); |
| 2072 | break; |
| 2073 | } |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 2074 | case TRACE_USER_STACK: { |
| 2075 | struct userstack_entry *field; |
| 2076 | |
| 2077 | trace_assign_type(field, entry); |
| 2078 | |
| 2079 | ret = seq_print_userip_objs(field, s, sym_flags); |
| 2080 | if (!ret) |
| 2081 | return TRACE_TYPE_PARTIAL_LINE; |
| 2082 | ret = trace_seq_putc(s, '\n'); |
| 2083 | if (!ret) |
| 2084 | return TRACE_TYPE_PARTIAL_LINE; |
| 2085 | break; |
| 2086 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2087 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2088 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2089 | } |
| 2090 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2091 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2092 | { |
| 2093 | struct trace_seq *s = &iter->seq; |
| 2094 | struct trace_entry *entry; |
| 2095 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2096 | int S, T; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2097 | |
| 2098 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2099 | |
| 2100 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2101 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2102 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2103 | ret = trace_seq_printf(s, "%d %d %llu ", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2104 | entry->pid, iter->cpu, iter->ts); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2105 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2106 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2107 | |
| 2108 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2109 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2110 | struct ftrace_entry *field; |
| 2111 | |
| 2112 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2113 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2114 | ret = trace_seq_printf(s, "%x %x\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2115 | field->ip, |
| 2116 | field->parent_ip); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2117 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2118 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2119 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2120 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2121 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2122 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2123 | struct ctx_switch_entry *field; |
| 2124 | |
| 2125 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2126 | |
| 2127 | S = field->prev_state < sizeof(state_to_char) ? |
| 2128 | state_to_char[field->prev_state] : 'X'; |
| 2129 | T = field->next_state < sizeof(state_to_char) ? |
| 2130 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2131 | if (entry->type == TRACE_WAKE) |
| 2132 | S = '+'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 2133 | 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] | 2134 | field->prev_pid, |
| 2135 | field->prev_prio, |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2136 | S, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2137 | field->next_cpu, |
| 2138 | field->next_pid, |
| 2139 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2140 | T); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2141 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2142 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2143 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2144 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2145 | case TRACE_SPECIAL: |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 2146 | case TRACE_USER_STACK: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2147 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2148 | struct special_entry *field; |
| 2149 | |
| 2150 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2151 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2152 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2153 | field->arg1, |
| 2154 | field->arg2, |
| 2155 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2156 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2157 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2158 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2159 | } |
| 2160 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2161 | struct print_entry *field; |
| 2162 | |
| 2163 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2164 | |
| 2165 | trace_seq_printf(s, "# %lx %s", field->ip, field->buf); |
| 2166 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2167 | trace_seq_print_cont(s, iter); |
| 2168 | break; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2169 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2170 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2171 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2174 | #define SEQ_PUT_FIELD_RET(s, x) \ |
| 2175 | do { \ |
| 2176 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ |
| 2177 | return 0; \ |
| 2178 | } while (0) |
| 2179 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2180 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ |
| 2181 | do { \ |
Harvey Harrison | ad0a3b6 | 2008-10-08 17:44:55 -0700 | [diff] [blame] | 2182 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2183 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ |
| 2184 | return 0; \ |
| 2185 | } while (0) |
| 2186 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2187 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2188 | { |
| 2189 | struct trace_seq *s = &iter->seq; |
| 2190 | unsigned char newline = '\n'; |
| 2191 | struct trace_entry *entry; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2192 | int S, T; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2193 | |
| 2194 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2195 | |
| 2196 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2197 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2198 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2199 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2200 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2201 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2202 | |
| 2203 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2204 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2205 | struct ftrace_entry *field; |
| 2206 | |
| 2207 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2208 | |
| 2209 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); |
| 2210 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2211 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2212 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2213 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2214 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2215 | struct ctx_switch_entry *field; |
| 2216 | |
| 2217 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2218 | |
| 2219 | S = field->prev_state < sizeof(state_to_char) ? |
| 2220 | state_to_char[field->prev_state] : 'X'; |
| 2221 | T = field->next_state < sizeof(state_to_char) ? |
| 2222 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2223 | if (entry->type == TRACE_WAKE) |
| 2224 | S = '+'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2225 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); |
| 2226 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2227 | SEQ_PUT_HEX_FIELD_RET(s, S); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2228 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); |
| 2229 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); |
| 2230 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2231 | SEQ_PUT_HEX_FIELD_RET(s, T); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2232 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2233 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2234 | case TRACE_SPECIAL: |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 2235 | case TRACE_USER_STACK: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2236 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2237 | struct special_entry *field; |
| 2238 | |
| 2239 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2240 | |
| 2241 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); |
| 2242 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); |
| 2243 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2244 | break; |
| 2245 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2246 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2247 | SEQ_PUT_FIELD_RET(s, newline); |
| 2248 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2249 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2250 | } |
| 2251 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2252 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2253 | { |
| 2254 | struct trace_seq *s = &iter->seq; |
| 2255 | struct trace_entry *entry; |
| 2256 | |
| 2257 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2258 | |
| 2259 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2260 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2261 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2262 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Eric Anholt | 072ba49 | 2008-10-26 15:26:57 -0700 | [diff] [blame] | 2263 | SEQ_PUT_FIELD_RET(s, entry->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2264 | SEQ_PUT_FIELD_RET(s, iter->ts); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2265 | |
| 2266 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2267 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2268 | struct ftrace_entry *field; |
| 2269 | |
| 2270 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2271 | |
| 2272 | SEQ_PUT_FIELD_RET(s, field->ip); |
| 2273 | SEQ_PUT_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2274 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2275 | } |
| 2276 | case TRACE_CTX: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2277 | struct ctx_switch_entry *field; |
| 2278 | |
| 2279 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2280 | |
| 2281 | SEQ_PUT_FIELD_RET(s, field->prev_pid); |
| 2282 | SEQ_PUT_FIELD_RET(s, field->prev_prio); |
| 2283 | SEQ_PUT_FIELD_RET(s, field->prev_state); |
| 2284 | SEQ_PUT_FIELD_RET(s, field->next_pid); |
| 2285 | SEQ_PUT_FIELD_RET(s, field->next_prio); |
| 2286 | SEQ_PUT_FIELD_RET(s, field->next_state); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2287 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2288 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2289 | case TRACE_SPECIAL: |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 2290 | case TRACE_USER_STACK: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2291 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2292 | struct special_entry *field; |
| 2293 | |
| 2294 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2295 | |
| 2296 | SEQ_PUT_FIELD_RET(s, field->arg1); |
| 2297 | SEQ_PUT_FIELD_RET(s, field->arg2); |
| 2298 | SEQ_PUT_FIELD_RET(s, field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2299 | break; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2300 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2301 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2302 | return 1; |
| 2303 | } |
| 2304 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2305 | static int trace_empty(struct trace_iterator *iter) |
| 2306 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2307 | int cpu; |
| 2308 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2309 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2310 | if (iter->buffer_iter[cpu]) { |
| 2311 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) |
| 2312 | return 0; |
| 2313 | } else { |
| 2314 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) |
| 2315 | return 0; |
| 2316 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2317 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2318 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2319 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2320 | } |
| 2321 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2322 | static enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2323 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2324 | enum print_line_t ret; |
| 2325 | |
| 2326 | if (iter->trace && iter->trace->print_line) { |
| 2327 | ret = iter->trace->print_line(iter); |
| 2328 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2329 | return ret; |
| 2330 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2331 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2332 | if (trace_flags & TRACE_ITER_BIN) |
| 2333 | return print_bin_fmt(iter); |
| 2334 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2335 | if (trace_flags & TRACE_ITER_HEX) |
| 2336 | return print_hex_fmt(iter); |
| 2337 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2338 | if (trace_flags & TRACE_ITER_RAW) |
| 2339 | return print_raw_fmt(iter); |
| 2340 | |
| 2341 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2342 | return print_lat_fmt(iter, iter->idx, iter->cpu); |
| 2343 | |
| 2344 | return print_trace_fmt(iter); |
| 2345 | } |
| 2346 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2347 | static int s_show(struct seq_file *m, void *v) |
| 2348 | { |
| 2349 | struct trace_iterator *iter = v; |
| 2350 | |
| 2351 | if (iter->ent == NULL) { |
| 2352 | if (iter->tr) { |
| 2353 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2354 | seq_puts(m, "#\n"); |
| 2355 | } |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2356 | if (iter->trace && iter->trace->print_header) |
| 2357 | iter->trace->print_header(m); |
| 2358 | else if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2359 | /* print nothing if the buffers are empty */ |
| 2360 | if (trace_empty(iter)) |
| 2361 | return 0; |
| 2362 | print_trace_header(m, iter); |
| 2363 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2364 | print_lat_help_header(m); |
| 2365 | } else { |
| 2366 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2367 | print_func_help_header(m); |
| 2368 | } |
| 2369 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2370 | print_trace_line(iter); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2371 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
| 2377 | static struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2378 | .start = s_start, |
| 2379 | .next = s_next, |
| 2380 | .stop = s_stop, |
| 2381 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2382 | }; |
| 2383 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2384 | static struct trace_iterator * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2385 | __tracing_open(struct inode *inode, struct file *file, int *ret) |
| 2386 | { |
| 2387 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2388 | struct seq_file *m; |
| 2389 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2390 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2391 | if (tracing_disabled) { |
| 2392 | *ret = -ENODEV; |
| 2393 | return NULL; |
| 2394 | } |
| 2395 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2396 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 2397 | if (!iter) { |
| 2398 | *ret = -ENOMEM; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | |
| 2402 | mutex_lock(&trace_types_lock); |
| 2403 | if (current_trace && current_trace->print_max) |
| 2404 | iter->tr = &max_tr; |
| 2405 | else |
| 2406 | iter->tr = inode->i_private; |
| 2407 | iter->trace = current_trace; |
| 2408 | iter->pos = -1; |
| 2409 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2410 | /* Notify the tracer early; before we stop tracing. */ |
| 2411 | if (iter->trace && iter->trace->open) |
| 2412 | iter->trace->open(iter); |
| 2413 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2414 | /* Annotate start of buffers if we had overruns */ |
| 2415 | if (ring_buffer_overruns(iter->tr->buffer)) |
| 2416 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2417 | |
| 2418 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2419 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2420 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2421 | iter->buffer_iter[cpu] = |
| 2422 | ring_buffer_read_start(iter->tr->buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2423 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2424 | if (!iter->buffer_iter[cpu]) |
| 2425 | goto fail_buffer; |
| 2426 | } |
| 2427 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2428 | /* TODO stop tracer */ |
| 2429 | *ret = seq_open(file, &tracer_seq_ops); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2430 | if (*ret) |
| 2431 | goto fail_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2432 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2433 | m = file->private_data; |
| 2434 | m->private = iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2435 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2436 | /* stop the trace while dumping */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2437 | tracing_stop(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2438 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2439 | mutex_unlock(&trace_types_lock); |
| 2440 | |
| 2441 | out: |
| 2442 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2443 | |
| 2444 | fail_buffer: |
| 2445 | for_each_tracing_cpu(cpu) { |
| 2446 | if (iter->buffer_iter[cpu]) |
| 2447 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2448 | } |
| 2449 | mutex_unlock(&trace_types_lock); |
Julia Lawall | 0bb943c | 2008-11-14 19:05:31 +0100 | [diff] [blame] | 2450 | kfree(iter); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2451 | |
| 2452 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2456 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2457 | if (tracing_disabled) |
| 2458 | return -ENODEV; |
| 2459 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2460 | filp->private_data = inode->i_private; |
| 2461 | return 0; |
| 2462 | } |
| 2463 | |
| 2464 | int tracing_release(struct inode *inode, struct file *file) |
| 2465 | { |
| 2466 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 2467 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2468 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2469 | |
| 2470 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2471 | for_each_tracing_cpu(cpu) { |
| 2472 | if (iter->buffer_iter[cpu]) |
| 2473 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2474 | } |
| 2475 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2476 | if (iter->trace && iter->trace->close) |
| 2477 | iter->trace->close(iter); |
| 2478 | |
| 2479 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2480 | tracing_start(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2481 | mutex_unlock(&trace_types_lock); |
| 2482 | |
| 2483 | seq_release(inode, file); |
| 2484 | kfree(iter); |
| 2485 | return 0; |
| 2486 | } |
| 2487 | |
| 2488 | static int tracing_open(struct inode *inode, struct file *file) |
| 2489 | { |
| 2490 | int ret; |
| 2491 | |
| 2492 | __tracing_open(inode, file, &ret); |
| 2493 | |
| 2494 | return ret; |
| 2495 | } |
| 2496 | |
| 2497 | static int tracing_lt_open(struct inode *inode, struct file *file) |
| 2498 | { |
| 2499 | struct trace_iterator *iter; |
| 2500 | int ret; |
| 2501 | |
| 2502 | iter = __tracing_open(inode, file, &ret); |
| 2503 | |
| 2504 | if (!ret) |
| 2505 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2506 | |
| 2507 | return ret; |
| 2508 | } |
| 2509 | |
| 2510 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2511 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2512 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2513 | { |
| 2514 | struct tracer *t = m->private; |
| 2515 | |
| 2516 | (*pos)++; |
| 2517 | |
| 2518 | if (t) |
| 2519 | t = t->next; |
| 2520 | |
| 2521 | m->private = t; |
| 2522 | |
| 2523 | return t; |
| 2524 | } |
| 2525 | |
| 2526 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2527 | { |
| 2528 | struct tracer *t = m->private; |
| 2529 | loff_t l = 0; |
| 2530 | |
| 2531 | mutex_lock(&trace_types_lock); |
| 2532 | for (; t && l < *pos; t = t_next(m, t, &l)) |
| 2533 | ; |
| 2534 | |
| 2535 | return t; |
| 2536 | } |
| 2537 | |
| 2538 | static void t_stop(struct seq_file *m, void *p) |
| 2539 | { |
| 2540 | mutex_unlock(&trace_types_lock); |
| 2541 | } |
| 2542 | |
| 2543 | static int t_show(struct seq_file *m, void *v) |
| 2544 | { |
| 2545 | struct tracer *t = v; |
| 2546 | |
| 2547 | if (!t) |
| 2548 | return 0; |
| 2549 | |
| 2550 | seq_printf(m, "%s", t->name); |
| 2551 | if (t->next) |
| 2552 | seq_putc(m, ' '); |
| 2553 | else |
| 2554 | seq_putc(m, '\n'); |
| 2555 | |
| 2556 | return 0; |
| 2557 | } |
| 2558 | |
| 2559 | static struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2560 | .start = t_start, |
| 2561 | .next = t_next, |
| 2562 | .stop = t_stop, |
| 2563 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2564 | }; |
| 2565 | |
| 2566 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2567 | { |
| 2568 | int ret; |
| 2569 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2570 | if (tracing_disabled) |
| 2571 | return -ENODEV; |
| 2572 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2573 | ret = seq_open(file, &show_traces_seq_ops); |
| 2574 | if (!ret) { |
| 2575 | struct seq_file *m = file->private_data; |
| 2576 | m->private = trace_types; |
| 2577 | } |
| 2578 | |
| 2579 | return ret; |
| 2580 | } |
| 2581 | |
| 2582 | static struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2583 | .open = tracing_open, |
| 2584 | .read = seq_read, |
| 2585 | .llseek = seq_lseek, |
| 2586 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2587 | }; |
| 2588 | |
| 2589 | static struct file_operations tracing_lt_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2590 | .open = tracing_lt_open, |
| 2591 | .read = seq_read, |
| 2592 | .llseek = seq_lseek, |
| 2593 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2594 | }; |
| 2595 | |
| 2596 | static struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2597 | .open = show_traces_open, |
| 2598 | .read = seq_read, |
| 2599 | .release = seq_release, |
| 2600 | }; |
| 2601 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2602 | /* |
| 2603 | * Only trace on a CPU if the bitmask is set: |
| 2604 | */ |
| 2605 | static cpumask_t tracing_cpumask = CPU_MASK_ALL; |
| 2606 | |
| 2607 | /* |
| 2608 | * When tracing/tracing_cpu_mask is modified then this holds |
| 2609 | * the new bitmask we are about to install: |
| 2610 | */ |
| 2611 | static cpumask_t tracing_cpumask_new; |
| 2612 | |
| 2613 | /* |
| 2614 | * The tracer itself will not take this lock, but still we want |
| 2615 | * to provide a consistent cpumask to user-space: |
| 2616 | */ |
| 2617 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2618 | |
| 2619 | /* |
| 2620 | * Temporary storage for the character representation of the |
| 2621 | * CPU bitmask (and one more byte for the newline): |
| 2622 | */ |
| 2623 | static char mask_str[NR_CPUS + 1]; |
| 2624 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2625 | static ssize_t |
| 2626 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 2627 | size_t count, loff_t *ppos) |
| 2628 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2629 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2630 | |
| 2631 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2632 | |
| 2633 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
| 2634 | if (count - len < 2) { |
| 2635 | count = -EINVAL; |
| 2636 | goto out_err; |
| 2637 | } |
| 2638 | len += sprintf(mask_str + len, "\n"); |
| 2639 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 2640 | |
| 2641 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2642 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2643 | |
| 2644 | return count; |
| 2645 | } |
| 2646 | |
| 2647 | static ssize_t |
| 2648 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 2649 | size_t count, loff_t *ppos) |
| 2650 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2651 | int err, cpu; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2652 | |
| 2653 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2654 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
| 2655 | if (err) |
| 2656 | goto err_unlock; |
| 2657 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2658 | local_irq_disable(); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2659 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2660 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2661 | /* |
| 2662 | * Increase/decrease the disabled counter if we are |
| 2663 | * about to flip a bit in the cpumask: |
| 2664 | */ |
| 2665 | if (cpu_isset(cpu, tracing_cpumask) && |
| 2666 | !cpu_isset(cpu, tracing_cpumask_new)) { |
| 2667 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2668 | } |
| 2669 | if (!cpu_isset(cpu, tracing_cpumask) && |
| 2670 | cpu_isset(cpu, tracing_cpumask_new)) { |
| 2671 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 2672 | } |
| 2673 | } |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2674 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2675 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2676 | |
| 2677 | tracing_cpumask = tracing_cpumask_new; |
| 2678 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2679 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2680 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2681 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2682 | |
| 2683 | err_unlock: |
| 2684 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2685 | |
| 2686 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | static struct file_operations tracing_cpumask_fops = { |
| 2690 | .open = tracing_open_generic, |
| 2691 | .read = tracing_cpumask_read, |
| 2692 | .write = tracing_cpumask_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2693 | }; |
| 2694 | |
| 2695 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2696 | tracing_trace_options_read(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2697 | size_t cnt, loff_t *ppos) |
| 2698 | { |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2699 | int i; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2700 | char *buf; |
| 2701 | int r = 0; |
| 2702 | int len = 0; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2703 | u32 tracer_flags = current_trace->flags->val; |
| 2704 | struct tracer_opt *trace_opts = current_trace->flags->opts; |
| 2705 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2706 | |
| 2707 | /* calulate max size */ |
| 2708 | for (i = 0; trace_options[i]; i++) { |
| 2709 | len += strlen(trace_options[i]); |
| 2710 | len += 3; /* "no" and space */ |
| 2711 | } |
| 2712 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2713 | /* |
| 2714 | * Increase the size with names of options specific |
| 2715 | * of the current tracer. |
| 2716 | */ |
| 2717 | for (i = 0; trace_opts[i].name; i++) { |
| 2718 | len += strlen(trace_opts[i].name); |
| 2719 | len += 3; /* "no" and space */ |
| 2720 | } |
| 2721 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2722 | /* +2 for \n and \0 */ |
| 2723 | buf = kmalloc(len + 2, GFP_KERNEL); |
| 2724 | if (!buf) |
| 2725 | return -ENOMEM; |
| 2726 | |
| 2727 | for (i = 0; trace_options[i]; i++) { |
| 2728 | if (trace_flags & (1 << i)) |
| 2729 | r += sprintf(buf + r, "%s ", trace_options[i]); |
| 2730 | else |
| 2731 | r += sprintf(buf + r, "no%s ", trace_options[i]); |
| 2732 | } |
| 2733 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2734 | for (i = 0; trace_opts[i].name; i++) { |
| 2735 | if (tracer_flags & trace_opts[i].bit) |
| 2736 | r += sprintf(buf + r, "%s ", |
| 2737 | trace_opts[i].name); |
| 2738 | else |
| 2739 | r += sprintf(buf + r, "no%s ", |
| 2740 | trace_opts[i].name); |
| 2741 | } |
| 2742 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2743 | r += sprintf(buf + r, "\n"); |
| 2744 | WARN_ON(r >= len + 2); |
| 2745 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2746 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2747 | |
| 2748 | kfree(buf); |
| 2749 | |
| 2750 | return r; |
| 2751 | } |
| 2752 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2753 | /* Try to assign a tracer specific option */ |
| 2754 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 2755 | { |
| 2756 | struct tracer_flags *trace_flags = trace->flags; |
| 2757 | struct tracer_opt *opts = NULL; |
| 2758 | int ret = 0, i = 0; |
| 2759 | int len; |
| 2760 | |
| 2761 | for (i = 0; trace_flags->opts[i].name; i++) { |
| 2762 | opts = &trace_flags->opts[i]; |
| 2763 | len = strlen(opts->name); |
| 2764 | |
| 2765 | if (strncmp(cmp, opts->name, len) == 0) { |
| 2766 | ret = trace->set_flag(trace_flags->val, |
| 2767 | opts->bit, !neg); |
| 2768 | break; |
| 2769 | } |
| 2770 | } |
| 2771 | /* Not found */ |
| 2772 | if (!trace_flags->opts[i].name) |
| 2773 | return -EINVAL; |
| 2774 | |
| 2775 | /* Refused to handle */ |
| 2776 | if (ret) |
| 2777 | return ret; |
| 2778 | |
| 2779 | if (neg) |
| 2780 | trace_flags->val &= ~opts->bit; |
| 2781 | else |
| 2782 | trace_flags->val |= opts->bit; |
| 2783 | |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2787 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2788 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2789 | size_t cnt, loff_t *ppos) |
| 2790 | { |
| 2791 | char buf[64]; |
| 2792 | char *cmp = buf; |
| 2793 | int neg = 0; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2794 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2795 | int i; |
| 2796 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2797 | if (cnt >= sizeof(buf)) |
| 2798 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2799 | |
| 2800 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2801 | return -EFAULT; |
| 2802 | |
| 2803 | buf[cnt] = 0; |
| 2804 | |
| 2805 | if (strncmp(buf, "no", 2) == 0) { |
| 2806 | neg = 1; |
| 2807 | cmp += 2; |
| 2808 | } |
| 2809 | |
| 2810 | for (i = 0; trace_options[i]; i++) { |
| 2811 | int len = strlen(trace_options[i]); |
| 2812 | |
| 2813 | if (strncmp(cmp, trace_options[i], len) == 0) { |
| 2814 | if (neg) |
| 2815 | trace_flags &= ~(1 << i); |
| 2816 | else |
| 2817 | trace_flags |= (1 << i); |
| 2818 | break; |
| 2819 | } |
| 2820 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2821 | |
| 2822 | /* If no option could be set, test the specific tracer options */ |
| 2823 | if (!trace_options[i]) { |
| 2824 | ret = set_tracer_option(current_trace, cmp, neg); |
| 2825 | if (ret) |
| 2826 | return ret; |
| 2827 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2828 | |
| 2829 | filp->f_pos += cnt; |
| 2830 | |
| 2831 | return cnt; |
| 2832 | } |
| 2833 | |
| 2834 | static struct file_operations tracing_iter_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2835 | .open = tracing_open_generic, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2836 | .read = tracing_trace_options_read, |
| 2837 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2838 | }; |
| 2839 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2840 | static const char readme_msg[] = |
| 2841 | "tracing mini-HOWTO:\n\n" |
| 2842 | "# mkdir /debug\n" |
| 2843 | "# mount -t debugfs nodev /debug\n\n" |
| 2844 | "# cat /debug/tracing/available_tracers\n" |
| 2845 | "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n" |
| 2846 | "# cat /debug/tracing/current_tracer\n" |
| 2847 | "none\n" |
| 2848 | "# echo sched_switch > /debug/tracing/current_tracer\n" |
| 2849 | "# cat /debug/tracing/current_tracer\n" |
| 2850 | "sched_switch\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2851 | "# cat /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2852 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2853 | "# echo print-parent > /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2854 | "# echo 1 > /debug/tracing/tracing_enabled\n" |
| 2855 | "# cat /debug/tracing/trace > /tmp/trace.txt\n" |
| 2856 | "echo 0 > /debug/tracing/tracing_enabled\n" |
| 2857 | ; |
| 2858 | |
| 2859 | static ssize_t |
| 2860 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 2861 | size_t cnt, loff_t *ppos) |
| 2862 | { |
| 2863 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 2864 | readme_msg, strlen(readme_msg)); |
| 2865 | } |
| 2866 | |
| 2867 | static struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2868 | .open = tracing_open_generic, |
| 2869 | .read = tracing_readme_read, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2870 | }; |
| 2871 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2872 | static ssize_t |
| 2873 | tracing_ctrl_read(struct file *filp, char __user *ubuf, |
| 2874 | size_t cnt, loff_t *ppos) |
| 2875 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2876 | char buf[64]; |
| 2877 | int r; |
| 2878 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2879 | r = sprintf(buf, "%u\n", tracer_enabled); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2880 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | static ssize_t |
| 2884 | tracing_ctrl_write(struct file *filp, const char __user *ubuf, |
| 2885 | size_t cnt, loff_t *ppos) |
| 2886 | { |
| 2887 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2888 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2889 | long val; |
| 2890 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2891 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2892 | if (cnt >= sizeof(buf)) |
| 2893 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2894 | |
| 2895 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2896 | return -EFAULT; |
| 2897 | |
| 2898 | buf[cnt] = 0; |
| 2899 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2900 | ret = strict_strtoul(buf, 10, &val); |
| 2901 | if (ret < 0) |
| 2902 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2903 | |
| 2904 | val = !!val; |
| 2905 | |
| 2906 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2907 | if (tracer_enabled ^ val) { |
| 2908 | if (val) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2909 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2910 | if (current_trace->start) |
| 2911 | current_trace->start(tr); |
| 2912 | tracing_start(); |
| 2913 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2914 | tracer_enabled = 0; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2915 | tracing_stop(); |
| 2916 | if (current_trace->stop) |
| 2917 | current_trace->stop(tr); |
| 2918 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2919 | } |
| 2920 | mutex_unlock(&trace_types_lock); |
| 2921 | |
| 2922 | filp->f_pos += cnt; |
| 2923 | |
| 2924 | return cnt; |
| 2925 | } |
| 2926 | |
| 2927 | static ssize_t |
| 2928 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 2929 | size_t cnt, loff_t *ppos) |
| 2930 | { |
| 2931 | char buf[max_tracer_type_len+2]; |
| 2932 | int r; |
| 2933 | |
| 2934 | mutex_lock(&trace_types_lock); |
| 2935 | if (current_trace) |
| 2936 | r = sprintf(buf, "%s\n", current_trace->name); |
| 2937 | else |
| 2938 | r = sprintf(buf, "\n"); |
| 2939 | mutex_unlock(&trace_types_lock); |
| 2940 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2941 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2942 | } |
| 2943 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2944 | static int tracing_set_tracer(char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2945 | { |
| 2946 | struct trace_array *tr = &global_trace; |
| 2947 | struct tracer *t; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2948 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2949 | |
| 2950 | mutex_lock(&trace_types_lock); |
| 2951 | for (t = trace_types; t; t = t->next) { |
| 2952 | if (strcmp(t->name, buf) == 0) |
| 2953 | break; |
| 2954 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2955 | if (!t) { |
| 2956 | ret = -EINVAL; |
| 2957 | goto out; |
| 2958 | } |
| 2959 | if (t == current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2960 | goto out; |
| 2961 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2962 | trace_branch_disable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2963 | if (current_trace && current_trace->reset) |
| 2964 | current_trace->reset(tr); |
| 2965 | |
| 2966 | current_trace = t; |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 2967 | if (t->init) { |
| 2968 | ret = t->init(tr); |
| 2969 | if (ret) |
| 2970 | goto out; |
| 2971 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2972 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2973 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2974 | out: |
| 2975 | mutex_unlock(&trace_types_lock); |
| 2976 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2977 | return ret; |
| 2978 | } |
| 2979 | |
| 2980 | static ssize_t |
| 2981 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 2982 | size_t cnt, loff_t *ppos) |
| 2983 | { |
| 2984 | char buf[max_tracer_type_len+1]; |
| 2985 | int i; |
| 2986 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2987 | int err; |
| 2988 | |
| 2989 | ret = cnt; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2990 | |
| 2991 | if (cnt > max_tracer_type_len) |
| 2992 | cnt = max_tracer_type_len; |
| 2993 | |
| 2994 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2995 | return -EFAULT; |
| 2996 | |
| 2997 | buf[cnt] = 0; |
| 2998 | |
| 2999 | /* strip ending whitespace. */ |
| 3000 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3001 | buf[i] = 0; |
| 3002 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3003 | err = tracing_set_tracer(buf); |
| 3004 | if (err) |
| 3005 | return err; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3006 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3007 | filp->f_pos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3008 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3009 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | static ssize_t |
| 3013 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3014 | size_t cnt, loff_t *ppos) |
| 3015 | { |
| 3016 | unsigned long *ptr = filp->private_data; |
| 3017 | char buf[64]; |
| 3018 | int r; |
| 3019 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3020 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3021 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3022 | if (r > sizeof(buf)) |
| 3023 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3024 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | static ssize_t |
| 3028 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3029 | size_t cnt, loff_t *ppos) |
| 3030 | { |
| 3031 | long *ptr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3032 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3033 | long val; |
| 3034 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3035 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3036 | if (cnt >= sizeof(buf)) |
| 3037 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3038 | |
| 3039 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3040 | return -EFAULT; |
| 3041 | |
| 3042 | buf[cnt] = 0; |
| 3043 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3044 | ret = strict_strtoul(buf, 10, &val); |
| 3045 | if (ret < 0) |
| 3046 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3047 | |
| 3048 | *ptr = val * 1000; |
| 3049 | |
| 3050 | return cnt; |
| 3051 | } |
| 3052 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3053 | static atomic_t tracing_reader; |
| 3054 | |
| 3055 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3056 | { |
| 3057 | struct trace_iterator *iter; |
| 3058 | |
| 3059 | if (tracing_disabled) |
| 3060 | return -ENODEV; |
| 3061 | |
| 3062 | /* We only allow for reader of the pipe */ |
| 3063 | if (atomic_inc_return(&tracing_reader) != 1) { |
| 3064 | atomic_dec(&tracing_reader); |
| 3065 | return -EBUSY; |
| 3066 | } |
| 3067 | |
| 3068 | /* create a buffer to store the information to pass to userspace */ |
| 3069 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 3070 | if (!iter) |
| 3071 | return -ENOMEM; |
| 3072 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3073 | mutex_lock(&trace_types_lock); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3074 | |
| 3075 | /* trace pipe does not show start of buffer */ |
| 3076 | cpus_setall(iter->started); |
| 3077 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3078 | iter->tr = &global_trace; |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 3079 | iter->trace = current_trace; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3080 | filp->private_data = iter; |
| 3081 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3082 | if (iter->trace->pipe_open) |
| 3083 | iter->trace->pipe_open(iter); |
| 3084 | mutex_unlock(&trace_types_lock); |
| 3085 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3086 | return 0; |
| 3087 | } |
| 3088 | |
| 3089 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3090 | { |
| 3091 | struct trace_iterator *iter = file->private_data; |
| 3092 | |
| 3093 | kfree(iter); |
| 3094 | atomic_dec(&tracing_reader); |
| 3095 | |
| 3096 | return 0; |
| 3097 | } |
| 3098 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3099 | static unsigned int |
| 3100 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3101 | { |
| 3102 | struct trace_iterator *iter = filp->private_data; |
| 3103 | |
| 3104 | if (trace_flags & TRACE_ITER_BLOCK) { |
| 3105 | /* |
| 3106 | * Always select as readable when in blocking mode |
| 3107 | */ |
| 3108 | return POLLIN | POLLRDNORM; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3109 | } else { |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3110 | if (!trace_empty(iter)) |
| 3111 | return POLLIN | POLLRDNORM; |
| 3112 | poll_wait(filp, &trace_wait, poll_table); |
| 3113 | if (!trace_empty(iter)) |
| 3114 | return POLLIN | POLLRDNORM; |
| 3115 | |
| 3116 | return 0; |
| 3117 | } |
| 3118 | } |
| 3119 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3120 | /* |
| 3121 | * Consumer reader. |
| 3122 | */ |
| 3123 | static ssize_t |
| 3124 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 3125 | size_t cnt, loff_t *ppos) |
| 3126 | { |
| 3127 | struct trace_iterator *iter = filp->private_data; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3128 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3129 | |
| 3130 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3131 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3132 | if (sret != -EBUSY) |
| 3133 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3134 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3135 | trace_seq_reset(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3136 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3137 | mutex_lock(&trace_types_lock); |
| 3138 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3139 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 3140 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3141 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3142 | } |
| 3143 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3144 | waitagain: |
| 3145 | sret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3146 | while (trace_empty(iter)) { |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 3147 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3148 | if ((filp->f_flags & O_NONBLOCK)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3149 | sret = -EAGAIN; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3150 | goto out; |
| 3151 | } |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 3152 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3153 | /* |
| 3154 | * This is a make-shift waitqueue. The reason we don't use |
| 3155 | * an actual wait queue is because: |
| 3156 | * 1) we only ever have one waiter |
| 3157 | * 2) the tracing, traces all functions, we don't want |
| 3158 | * the overhead of calling wake_up and friends |
| 3159 | * (and tracing them too) |
| 3160 | * Anyway, this is really very primitive wakeup. |
| 3161 | */ |
| 3162 | set_current_state(TASK_INTERRUPTIBLE); |
| 3163 | iter->tr->waiter = current; |
| 3164 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3165 | mutex_unlock(&trace_types_lock); |
| 3166 | |
Ingo Molnar | 9fe068e | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3167 | /* sleep for 100 msecs, and try again. */ |
| 3168 | schedule_timeout(HZ/10); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3169 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3170 | mutex_lock(&trace_types_lock); |
| 3171 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3172 | iter->tr->waiter = NULL; |
| 3173 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3174 | if (signal_pending(current)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3175 | sret = -EINTR; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3176 | goto out; |
| 3177 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3178 | |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 3179 | if (iter->trace != current_trace) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3180 | goto out; |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 3181 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3182 | /* |
| 3183 | * We block until we read something and tracing is disabled. |
| 3184 | * We still block if tracing is disabled, but we have never |
| 3185 | * read anything. This allows a user to cat this file, and |
| 3186 | * then enable tracing. But after we have read something, |
| 3187 | * we give an EOF when tracing is again disabled. |
| 3188 | * |
| 3189 | * iter->pos will be 0 if we haven't read anything. |
| 3190 | */ |
| 3191 | if (!tracer_enabled && iter->pos) |
| 3192 | break; |
| 3193 | |
| 3194 | continue; |
| 3195 | } |
| 3196 | |
| 3197 | /* stop when tracing is finished */ |
| 3198 | if (trace_empty(iter)) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3199 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3200 | |
| 3201 | if (cnt >= PAGE_SIZE) |
| 3202 | cnt = PAGE_SIZE - 1; |
| 3203 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3204 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3205 | memset(&iter->seq, 0, |
| 3206 | sizeof(struct trace_iterator) - |
| 3207 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3208 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3209 | |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3210 | while (find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3211 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3212 | int len = iter->seq.len; |
| 3213 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 3214 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3215 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3216 | /* don't print partial lines */ |
| 3217 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3218 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3219 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3220 | |
| 3221 | trace_consume(iter); |
| 3222 | |
| 3223 | if (iter->seq.len >= cnt) |
| 3224 | break; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3225 | } |
| 3226 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3227 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3228 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3229 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3230 | trace_seq_reset(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3231 | |
| 3232 | /* |
| 3233 | * If there was nothing to send to user, inspite of consuming trace |
| 3234 | * entries, go back to wait for more entries. |
| 3235 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3236 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3237 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3238 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3239 | out: |
| 3240 | mutex_unlock(&trace_types_lock); |
| 3241 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3242 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3243 | } |
| 3244 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3245 | static ssize_t |
| 3246 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 3247 | size_t cnt, loff_t *ppos) |
| 3248 | { |
| 3249 | struct trace_array *tr = filp->private_data; |
| 3250 | char buf[64]; |
| 3251 | int r; |
| 3252 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3253 | r = sprintf(buf, "%lu\n", tr->entries >> 10); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3254 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3255 | } |
| 3256 | |
| 3257 | static ssize_t |
| 3258 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 3259 | size_t cnt, loff_t *ppos) |
| 3260 | { |
| 3261 | unsigned long val; |
| 3262 | char buf[64]; |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3263 | int ret, cpu; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3264 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3265 | if (cnt >= sizeof(buf)) |
| 3266 | return -EINVAL; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3267 | |
| 3268 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3269 | return -EFAULT; |
| 3270 | |
| 3271 | buf[cnt] = 0; |
| 3272 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3273 | ret = strict_strtoul(buf, 10, &val); |
| 3274 | if (ret < 0) |
| 3275 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3276 | |
| 3277 | /* must have at least 1 entry */ |
| 3278 | if (!val) |
| 3279 | return -EINVAL; |
| 3280 | |
| 3281 | mutex_lock(&trace_types_lock); |
| 3282 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3283 | tracing_stop(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3284 | |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3285 | /* disable all cpu buffers */ |
| 3286 | for_each_tracing_cpu(cpu) { |
| 3287 | if (global_trace.data[cpu]) |
| 3288 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 3289 | if (max_tr.data[cpu]) |
| 3290 | atomic_inc(&max_tr.data[cpu]->disabled); |
| 3291 | } |
| 3292 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3293 | /* value is in KB */ |
| 3294 | val <<= 10; |
| 3295 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3296 | if (val != global_trace.entries) { |
| 3297 | ret = ring_buffer_resize(global_trace.buffer, val); |
| 3298 | if (ret < 0) { |
| 3299 | cnt = ret; |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 3300 | goto out; |
| 3301 | } |
| 3302 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3303 | ret = ring_buffer_resize(max_tr.buffer, val); |
| 3304 | if (ret < 0) { |
| 3305 | int r; |
| 3306 | cnt = ret; |
| 3307 | r = ring_buffer_resize(global_trace.buffer, |
| 3308 | global_trace.entries); |
| 3309 | if (r < 0) { |
| 3310 | /* AARGH! We are left with different |
| 3311 | * size max buffer!!!! */ |
| 3312 | WARN_ON(1); |
| 3313 | tracing_disabled = 1; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3314 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3315 | goto out; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3316 | } |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 3317 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3318 | global_trace.entries = val; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | filp->f_pos += cnt; |
| 3322 | |
Steven Rostedt | 19384c0 | 2008-05-22 00:22:16 -0400 | [diff] [blame] | 3323 | /* If check pages failed, return ENOMEM */ |
| 3324 | if (tracing_disabled) |
| 3325 | cnt = -ENOMEM; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3326 | out: |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3327 | for_each_tracing_cpu(cpu) { |
| 3328 | if (global_trace.data[cpu]) |
| 3329 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 3330 | if (max_tr.data[cpu]) |
| 3331 | atomic_dec(&max_tr.data[cpu]->disabled); |
| 3332 | } |
| 3333 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3334 | tracing_start(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3335 | max_tr.entries = global_trace.entries; |
| 3336 | mutex_unlock(&trace_types_lock); |
| 3337 | |
| 3338 | return cnt; |
| 3339 | } |
| 3340 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3341 | static int mark_printk(const char *fmt, ...) |
| 3342 | { |
| 3343 | int ret; |
| 3344 | va_list args; |
| 3345 | va_start(args, fmt); |
| 3346 | ret = trace_vprintk(0, fmt, args); |
| 3347 | va_end(args); |
| 3348 | return ret; |
| 3349 | } |
| 3350 | |
| 3351 | static ssize_t |
| 3352 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 3353 | size_t cnt, loff_t *fpos) |
| 3354 | { |
| 3355 | char *buf; |
| 3356 | char *end; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3357 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3358 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3359 | return -EINVAL; |
| 3360 | |
| 3361 | if (cnt > TRACE_BUF_SIZE) |
| 3362 | cnt = TRACE_BUF_SIZE; |
| 3363 | |
| 3364 | buf = kmalloc(cnt + 1, GFP_KERNEL); |
| 3365 | if (buf == NULL) |
| 3366 | return -ENOMEM; |
| 3367 | |
| 3368 | if (copy_from_user(buf, ubuf, cnt)) { |
| 3369 | kfree(buf); |
| 3370 | return -EFAULT; |
| 3371 | } |
| 3372 | |
| 3373 | /* Cut from the first nil or newline. */ |
| 3374 | buf[cnt] = '\0'; |
| 3375 | end = strchr(buf, '\n'); |
| 3376 | if (end) |
| 3377 | *end = '\0'; |
| 3378 | |
| 3379 | cnt = mark_printk("%s\n", buf); |
| 3380 | kfree(buf); |
| 3381 | *fpos += cnt; |
| 3382 | |
| 3383 | return cnt; |
| 3384 | } |
| 3385 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3386 | static struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3387 | .open = tracing_open_generic, |
| 3388 | .read = tracing_max_lat_read, |
| 3389 | .write = tracing_max_lat_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3390 | }; |
| 3391 | |
| 3392 | static struct file_operations tracing_ctrl_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3393 | .open = tracing_open_generic, |
| 3394 | .read = tracing_ctrl_read, |
| 3395 | .write = tracing_ctrl_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3396 | }; |
| 3397 | |
| 3398 | static struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3399 | .open = tracing_open_generic, |
| 3400 | .read = tracing_set_trace_read, |
| 3401 | .write = tracing_set_trace_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3402 | }; |
| 3403 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3404 | static struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3405 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3406 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3407 | .read = tracing_read_pipe, |
| 3408 | .release = tracing_release_pipe, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3409 | }; |
| 3410 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3411 | static struct file_operations tracing_entries_fops = { |
| 3412 | .open = tracing_open_generic, |
| 3413 | .read = tracing_entries_read, |
| 3414 | .write = tracing_entries_write, |
| 3415 | }; |
| 3416 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3417 | static struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3418 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3419 | .write = tracing_mark_write, |
| 3420 | }; |
| 3421 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3422 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3423 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3424 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3425 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3426 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3427 | } |
| 3428 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3429 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3430 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3431 | size_t cnt, loff_t *ppos) |
| 3432 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3433 | static char ftrace_dyn_info_buffer[1024]; |
| 3434 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3435 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3436 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3437 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3438 | int r; |
| 3439 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3440 | mutex_lock(&dyn_info_mutex); |
| 3441 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3442 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3443 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3444 | buf[r++] = '\n'; |
| 3445 | |
| 3446 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3447 | |
| 3448 | mutex_unlock(&dyn_info_mutex); |
| 3449 | |
| 3450 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3451 | } |
| 3452 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3453 | static struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3454 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3455 | .read = tracing_read_dyn_info, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3456 | }; |
| 3457 | #endif |
| 3458 | |
| 3459 | static struct dentry *d_tracer; |
| 3460 | |
| 3461 | struct dentry *tracing_init_dentry(void) |
| 3462 | { |
| 3463 | static int once; |
| 3464 | |
| 3465 | if (d_tracer) |
| 3466 | return d_tracer; |
| 3467 | |
| 3468 | d_tracer = debugfs_create_dir("tracing", NULL); |
| 3469 | |
| 3470 | if (!d_tracer && !once) { |
| 3471 | once = 1; |
| 3472 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 3473 | return NULL; |
| 3474 | } |
| 3475 | |
| 3476 | return d_tracer; |
| 3477 | } |
| 3478 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3479 | #ifdef CONFIG_FTRACE_SELFTEST |
| 3480 | /* Let selftest have access to static functions in this file */ |
| 3481 | #include "trace_selftest.c" |
| 3482 | #endif |
| 3483 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3484 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3485 | { |
| 3486 | struct dentry *d_tracer; |
| 3487 | struct dentry *entry; |
| 3488 | |
| 3489 | d_tracer = tracing_init_dentry(); |
| 3490 | |
| 3491 | entry = debugfs_create_file("tracing_enabled", 0644, d_tracer, |
| 3492 | &global_trace, &tracing_ctrl_fops); |
| 3493 | if (!entry) |
| 3494 | pr_warning("Could not create debugfs 'tracing_enabled' entry\n"); |
| 3495 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3496 | entry = debugfs_create_file("trace_options", 0644, d_tracer, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3497 | NULL, &tracing_iter_fops); |
| 3498 | if (!entry) |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3499 | pr_warning("Could not create debugfs 'trace_options' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3500 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3501 | entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, |
| 3502 | NULL, &tracing_cpumask_fops); |
| 3503 | if (!entry) |
| 3504 | pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); |
| 3505 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3506 | entry = debugfs_create_file("latency_trace", 0444, d_tracer, |
| 3507 | &global_trace, &tracing_lt_fops); |
| 3508 | if (!entry) |
| 3509 | pr_warning("Could not create debugfs 'latency_trace' entry\n"); |
| 3510 | |
| 3511 | entry = debugfs_create_file("trace", 0444, d_tracer, |
| 3512 | &global_trace, &tracing_fops); |
| 3513 | if (!entry) |
| 3514 | pr_warning("Could not create debugfs 'trace' entry\n"); |
| 3515 | |
| 3516 | entry = debugfs_create_file("available_tracers", 0444, d_tracer, |
| 3517 | &global_trace, &show_traces_fops); |
| 3518 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3519 | pr_warning("Could not create debugfs 'available_tracers' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3520 | |
| 3521 | entry = debugfs_create_file("current_tracer", 0444, d_tracer, |
| 3522 | &global_trace, &set_tracer_fops); |
| 3523 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3524 | pr_warning("Could not create debugfs 'current_tracer' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3525 | |
| 3526 | entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer, |
| 3527 | &tracing_max_latency, |
| 3528 | &tracing_max_lat_fops); |
| 3529 | if (!entry) |
| 3530 | pr_warning("Could not create debugfs " |
| 3531 | "'tracing_max_latency' entry\n"); |
| 3532 | |
| 3533 | entry = debugfs_create_file("tracing_thresh", 0644, d_tracer, |
| 3534 | &tracing_thresh, &tracing_max_lat_fops); |
| 3535 | if (!entry) |
| 3536 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3537 | "'tracing_thresh' entry\n"); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3538 | entry = debugfs_create_file("README", 0644, d_tracer, |
| 3539 | NULL, &tracing_readme_fops); |
| 3540 | if (!entry) |
| 3541 | pr_warning("Could not create debugfs 'README' entry\n"); |
| 3542 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3543 | entry = debugfs_create_file("trace_pipe", 0644, d_tracer, |
| 3544 | NULL, &tracing_pipe_fops); |
| 3545 | if (!entry) |
| 3546 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3547 | "'trace_pipe' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3548 | |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3549 | entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3550 | &global_trace, &tracing_entries_fops); |
| 3551 | if (!entry) |
| 3552 | pr_warning("Could not create debugfs " |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3553 | "'buffer_size_kb' entry\n"); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3554 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3555 | entry = debugfs_create_file("trace_marker", 0220, d_tracer, |
| 3556 | NULL, &tracing_mark_fops); |
| 3557 | if (!entry) |
| 3558 | pr_warning("Could not create debugfs " |
| 3559 | "'trace_marker' entry\n"); |
| 3560 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3561 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3562 | entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 3563 | &ftrace_update_tot_cnt, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3564 | &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3565 | if (!entry) |
| 3566 | pr_warning("Could not create debugfs " |
| 3567 | "'dyn_ftrace_total_info' entry\n"); |
| 3568 | #endif |
Ingo Molnar | d618b3e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3569 | #ifdef CONFIG_SYSPROF_TRACER |
| 3570 | init_tracer_sysprof_debugfs(d_tracer); |
| 3571 | #endif |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3572 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3573 | } |
| 3574 | |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3575 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3576 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3577 | static DEFINE_SPINLOCK(trace_buf_lock); |
| 3578 | static char trace_buf[TRACE_BUF_SIZE]; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3579 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3580 | struct ring_buffer_event *event; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3581 | struct trace_array *tr = &global_trace; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3582 | struct trace_array_cpu *data; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3583 | struct print_entry *entry; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3584 | unsigned long flags, irq_flags; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3585 | int cpu, len = 0, size, pc; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3586 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3587 | if (tracing_disabled) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3588 | return 0; |
| 3589 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3590 | pc = preempt_count(); |
| 3591 | preempt_disable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3592 | cpu = raw_smp_processor_id(); |
| 3593 | data = tr->data[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3594 | |
Steven Rostedt | 3ea2e6d | 2008-10-04 02:01:00 -0400 | [diff] [blame] | 3595 | if (unlikely(atomic_read(&data->disabled))) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3596 | goto out; |
| 3597 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3598 | spin_lock_irqsave(&trace_buf_lock, flags); |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3599 | len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3600 | |
| 3601 | len = min(len, TRACE_BUF_SIZE-1); |
| 3602 | trace_buf[len] = 0; |
| 3603 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3604 | size = sizeof(*entry) + len + 1; |
| 3605 | event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3606 | if (!event) |
| 3607 | goto out_unlock; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3608 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3609 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3610 | entry->ent.type = TRACE_PRINT; |
| 3611 | entry->ip = ip; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3612 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3613 | memcpy(&entry->buf, trace_buf, len); |
| 3614 | entry->buf[len] = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3615 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3616 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3617 | out_unlock: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3618 | spin_unlock_irqrestore(&trace_buf_lock, flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3619 | |
| 3620 | out: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3621 | preempt_enable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3622 | |
| 3623 | return len; |
| 3624 | } |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3625 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 3626 | |
| 3627 | int __ftrace_printk(unsigned long ip, const char *fmt, ...) |
| 3628 | { |
| 3629 | int ret; |
| 3630 | va_list ap; |
| 3631 | |
| 3632 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 3633 | return 0; |
| 3634 | |
| 3635 | va_start(ap, fmt); |
| 3636 | ret = trace_vprintk(ip, fmt, ap); |
| 3637 | va_end(ap); |
| 3638 | return ret; |
| 3639 | } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3640 | EXPORT_SYMBOL_GPL(__ftrace_printk); |
| 3641 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3642 | static int trace_panic_handler(struct notifier_block *this, |
| 3643 | unsigned long event, void *unused) |
| 3644 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3645 | if (ftrace_dump_on_oops) |
| 3646 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3647 | return NOTIFY_OK; |
| 3648 | } |
| 3649 | |
| 3650 | static struct notifier_block trace_panic_notifier = { |
| 3651 | .notifier_call = trace_panic_handler, |
| 3652 | .next = NULL, |
| 3653 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 3654 | }; |
| 3655 | |
| 3656 | static int trace_die_handler(struct notifier_block *self, |
| 3657 | unsigned long val, |
| 3658 | void *data) |
| 3659 | { |
| 3660 | switch (val) { |
| 3661 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3662 | if (ftrace_dump_on_oops) |
| 3663 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3664 | break; |
| 3665 | default: |
| 3666 | break; |
| 3667 | } |
| 3668 | return NOTIFY_OK; |
| 3669 | } |
| 3670 | |
| 3671 | static struct notifier_block trace_die_notifier = { |
| 3672 | .notifier_call = trace_die_handler, |
| 3673 | .priority = 200 |
| 3674 | }; |
| 3675 | |
| 3676 | /* |
| 3677 | * printk is set to max of 1024, we really don't need it that big. |
| 3678 | * Nothing should be printing 1000 characters anyway. |
| 3679 | */ |
| 3680 | #define TRACE_MAX_PRINT 1000 |
| 3681 | |
| 3682 | /* |
| 3683 | * Define here KERN_TRACE so that we have one place to modify |
| 3684 | * it if we decide to change what log level the ftrace dump |
| 3685 | * should be at. |
| 3686 | */ |
| 3687 | #define KERN_TRACE KERN_INFO |
| 3688 | |
| 3689 | static void |
| 3690 | trace_printk_seq(struct trace_seq *s) |
| 3691 | { |
| 3692 | /* Probably should print a warning here. */ |
| 3693 | if (s->len >= 1000) |
| 3694 | s->len = 1000; |
| 3695 | |
| 3696 | /* should be zero ended, but we are paranoid. */ |
| 3697 | s->buffer[s->len] = 0; |
| 3698 | |
| 3699 | printk(KERN_TRACE "%s", s->buffer); |
| 3700 | |
| 3701 | trace_seq_reset(s); |
| 3702 | } |
| 3703 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3704 | void ftrace_dump(void) |
| 3705 | { |
| 3706 | static DEFINE_SPINLOCK(ftrace_dump_lock); |
| 3707 | /* use static because iter can be a bit big for the stack */ |
| 3708 | static struct trace_iterator iter; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3709 | static cpumask_t mask; |
| 3710 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3711 | unsigned long flags; |
| 3712 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3713 | |
| 3714 | /* only one dump */ |
| 3715 | spin_lock_irqsave(&ftrace_dump_lock, flags); |
| 3716 | if (dump_ran) |
| 3717 | goto out; |
| 3718 | |
| 3719 | dump_ran = 1; |
| 3720 | |
| 3721 | /* No turning back! */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 3722 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3723 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3724 | for_each_tracing_cpu(cpu) { |
| 3725 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 3726 | } |
| 3727 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 3728 | /* don't look at user memory in panic mode */ |
| 3729 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 3730 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3731 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
| 3732 | |
| 3733 | iter.tr = &global_trace; |
| 3734 | iter.trace = current_trace; |
| 3735 | |
| 3736 | /* |
| 3737 | * We need to stop all tracing on all CPUS to read the |
| 3738 | * the next buffer. This is a bit expensive, but is |
| 3739 | * not done often. We fill all what we can read, |
| 3740 | * and then release the locks again. |
| 3741 | */ |
| 3742 | |
| 3743 | cpus_clear(mask); |
| 3744 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3745 | while (!trace_empty(&iter)) { |
| 3746 | |
| 3747 | if (!cnt) |
| 3748 | printk(KERN_TRACE "---------------------------------\n"); |
| 3749 | |
| 3750 | cnt++; |
| 3751 | |
| 3752 | /* reset all but tr, trace, and overruns */ |
| 3753 | memset(&iter.seq, 0, |
| 3754 | sizeof(struct trace_iterator) - |
| 3755 | offsetof(struct trace_iterator, seq)); |
| 3756 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 3757 | iter.pos = -1; |
| 3758 | |
| 3759 | if (find_next_entry_inc(&iter) != NULL) { |
| 3760 | print_trace_line(&iter); |
| 3761 | trace_consume(&iter); |
| 3762 | } |
| 3763 | |
| 3764 | trace_printk_seq(&iter.seq); |
| 3765 | } |
| 3766 | |
| 3767 | if (!cnt) |
| 3768 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 3769 | else |
| 3770 | printk(KERN_TRACE "---------------------------------\n"); |
| 3771 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3772 | out: |
| 3773 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); |
| 3774 | } |
| 3775 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3776 | __init static int tracer_alloc_buffers(void) |
| 3777 | { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3778 | struct trace_array_cpu *data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3779 | int i; |
| 3780 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3781 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3782 | tracing_buffer_mask = cpu_possible_map; |
| 3783 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3784 | global_trace.buffer = ring_buffer_alloc(trace_buf_size, |
| 3785 | TRACE_BUFFER_FLAGS); |
| 3786 | if (!global_trace.buffer) { |
| 3787 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 3788 | WARN_ON(1); |
| 3789 | return 0; |
| 3790 | } |
| 3791 | global_trace.entries = ring_buffer_size(global_trace.buffer); |
| 3792 | |
| 3793 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3794 | max_tr.buffer = ring_buffer_alloc(trace_buf_size, |
| 3795 | TRACE_BUFFER_FLAGS); |
| 3796 | if (!max_tr.buffer) { |
| 3797 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); |
| 3798 | WARN_ON(1); |
| 3799 | ring_buffer_free(global_trace.buffer); |
| 3800 | return 0; |
| 3801 | } |
| 3802 | max_tr.entries = ring_buffer_size(max_tr.buffer); |
| 3803 | WARN_ON(max_tr.entries != global_trace.entries); |
| 3804 | #endif |
| 3805 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3806 | /* Allocate the first page for all buffers */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3807 | for_each_tracing_cpu(i) { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3808 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3809 | max_tr.data[i] = &per_cpu(max_data, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3810 | } |
| 3811 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3812 | trace_init_cmdlines(); |
| 3813 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3814 | register_tracer(&nop_trace); |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3815 | #ifdef CONFIG_BOOT_TRACER |
| 3816 | register_tracer(&boot_tracer); |
| 3817 | current_trace = &boot_tracer; |
| 3818 | current_trace->init(&global_trace); |
| 3819 | #else |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3820 | current_trace = &nop_trace; |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3821 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3822 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3823 | /* All seems OK, enable tracing */ |
| 3824 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3825 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3826 | atomic_notifier_chain_register(&panic_notifier_list, |
| 3827 | &trace_panic_notifier); |
| 3828 | |
| 3829 | register_die_notifier(&trace_die_notifier); |
| 3830 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3831 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3832 | } |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3833 | early_initcall(tracer_alloc_buffers); |
| 3834 | fs_initcall(tracer_init_debugfs); |