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