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