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