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