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