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