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