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