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