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