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