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