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