diff options
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 1075 |
1 files changed, 151 insertions, 924 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 17bb88d86ac2..fd51cf0b94c7 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/irqflags.h> | 37 | #include <linux/irqflags.h> |
38 | 38 | ||
39 | #include "trace.h" | 39 | #include "trace.h" |
40 | #include "trace_output.h" | ||
40 | 41 | ||
41 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) | 42 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
42 | 43 | ||
@@ -52,6 +53,11 @@ unsigned long __read_mostly tracing_thresh; | |||
52 | */ | 53 | */ |
53 | static bool __read_mostly tracing_selftest_running; | 54 | static bool __read_mostly tracing_selftest_running; |
54 | 55 | ||
56 | /* | ||
57 | * If a tracer is running, we do not want to run SELFTEST. | ||
58 | */ | ||
59 | static bool __read_mostly tracing_selftest_disabled; | ||
60 | |||
55 | /* For tracers that don't implement custom flags */ | 61 | /* For tracers that don't implement custom flags */ |
56 | static struct tracer_opt dummy_tracer_opt[] = { | 62 | static struct tracer_opt dummy_tracer_opt[] = { |
57 | { } | 63 | { } |
@@ -109,14 +115,19 @@ static cpumask_var_t __read_mostly tracing_buffer_mask; | |||
109 | */ | 115 | */ |
110 | int ftrace_dump_on_oops; | 116 | int ftrace_dump_on_oops; |
111 | 117 | ||
112 | static int tracing_set_tracer(char *buf); | 118 | static int tracing_set_tracer(const char *buf); |
119 | |||
120 | #define BOOTUP_TRACER_SIZE 100 | ||
121 | static char bootup_tracer_buf[BOOTUP_TRACER_SIZE] __initdata; | ||
122 | static char *default_bootup_tracer; | ||
113 | 123 | ||
114 | static int __init set_ftrace(char *str) | 124 | static int __init set_ftrace(char *str) |
115 | { | 125 | { |
116 | tracing_set_tracer(str); | 126 | strncpy(bootup_tracer_buf, str, BOOTUP_TRACER_SIZE); |
127 | default_bootup_tracer = bootup_tracer_buf; | ||
117 | return 1; | 128 | return 1; |
118 | } | 129 | } |
119 | __setup("ftrace", set_ftrace); | 130 | __setup("ftrace=", set_ftrace); |
120 | 131 | ||
121 | static int __init set_ftrace_dump_on_oops(char *str) | 132 | static int __init set_ftrace_dump_on_oops(char *str) |
122 | { | 133 | { |
@@ -186,9 +197,6 @@ int tracing_is_enabled(void) | |||
186 | return tracer_enabled; | 197 | return tracer_enabled; |
187 | } | 198 | } |
188 | 199 | ||
189 | /* function tracing enabled */ | ||
190 | int ftrace_function_enabled; | ||
191 | |||
192 | /* | 200 | /* |
193 | * trace_buf_size is the size in bytes that is allocated | 201 | * trace_buf_size is the size in bytes that is allocated |
194 | * for a buffer. Note, the number of bytes is always rounded | 202 | * for a buffer. Note, the number of bytes is always rounded |
@@ -229,7 +237,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait); | |||
229 | 237 | ||
230 | /* trace_flags holds trace_options default values */ | 238 | /* trace_flags holds trace_options default values */ |
231 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | | 239 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
232 | TRACE_ITER_ANNOTATE; | 240 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO; |
233 | 241 | ||
234 | /** | 242 | /** |
235 | * trace_wake_up - wake up tasks waiting for trace input | 243 | * trace_wake_up - wake up tasks waiting for trace input |
@@ -287,6 +295,7 @@ static const char *trace_options[] = { | |||
287 | "userstacktrace", | 295 | "userstacktrace", |
288 | "sym-userobj", | 296 | "sym-userobj", |
289 | "printk-msg-only", | 297 | "printk-msg-only", |
298 | "context-info", | ||
290 | NULL | 299 | NULL |
291 | }; | 300 | }; |
292 | 301 | ||
@@ -329,132 +338,6 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
329 | tracing_record_cmdline(current); | 338 | tracing_record_cmdline(current); |
330 | } | 339 | } |
331 | 340 | ||
332 | /** | ||
333 | * trace_seq_printf - sequence printing of trace information | ||
334 | * @s: trace sequence descriptor | ||
335 | * @fmt: printf format string | ||
336 | * | ||
337 | * The tracer may use either sequence operations or its own | ||
338 | * copy to user routines. To simplify formating of a trace | ||
339 | * trace_seq_printf is used to store strings into a special | ||
340 | * buffer (@s). Then the output may be either used by | ||
341 | * the sequencer or pulled into another buffer. | ||
342 | */ | ||
343 | int | ||
344 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | ||
345 | { | ||
346 | int len = (PAGE_SIZE - 1) - s->len; | ||
347 | va_list ap; | ||
348 | int ret; | ||
349 | |||
350 | if (!len) | ||
351 | return 0; | ||
352 | |||
353 | va_start(ap, fmt); | ||
354 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); | ||
355 | va_end(ap); | ||
356 | |||
357 | /* If we can't write it all, don't bother writing anything */ | ||
358 | if (ret >= len) | ||
359 | return 0; | ||
360 | |||
361 | s->len += ret; | ||
362 | |||
363 | return len; | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * trace_seq_puts - trace sequence printing of simple string | ||
368 | * @s: trace sequence descriptor | ||
369 | * @str: simple string to record | ||
370 | * | ||
371 | * The tracer may use either the sequence operations or its own | ||
372 | * copy to user routines. This function records a simple string | ||
373 | * into a special buffer (@s) for later retrieval by a sequencer | ||
374 | * or other mechanism. | ||
375 | */ | ||
376 | static int | ||
377 | trace_seq_puts(struct trace_seq *s, const char *str) | ||
378 | { | ||
379 | int len = strlen(str); | ||
380 | |||
381 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
382 | return 0; | ||
383 | |||
384 | memcpy(s->buffer + s->len, str, len); | ||
385 | s->len += len; | ||
386 | |||
387 | return len; | ||
388 | } | ||
389 | |||
390 | static int | ||
391 | trace_seq_putc(struct trace_seq *s, unsigned char c) | ||
392 | { | ||
393 | if (s->len >= (PAGE_SIZE - 1)) | ||
394 | return 0; | ||
395 | |||
396 | s->buffer[s->len++] = c; | ||
397 | |||
398 | return 1; | ||
399 | } | ||
400 | |||
401 | static int | ||
402 | trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) | ||
403 | { | ||
404 | if (len > ((PAGE_SIZE - 1) - s->len)) | ||
405 | return 0; | ||
406 | |||
407 | memcpy(s->buffer + s->len, mem, len); | ||
408 | s->len += len; | ||
409 | |||
410 | return len; | ||
411 | } | ||
412 | |||
413 | #define MAX_MEMHEX_BYTES 8 | ||
414 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) | ||
415 | |||
416 | static int | ||
417 | trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) | ||
418 | { | ||
419 | unsigned char hex[HEX_CHARS]; | ||
420 | unsigned char *data = mem; | ||
421 | int i, j; | ||
422 | |||
423 | #ifdef __BIG_ENDIAN | ||
424 | for (i = 0, j = 0; i < len; i++) { | ||
425 | #else | ||
426 | for (i = len-1, j = 0; i >= 0; i--) { | ||
427 | #endif | ||
428 | hex[j++] = hex_asc_hi(data[i]); | ||
429 | hex[j++] = hex_asc_lo(data[i]); | ||
430 | } | ||
431 | hex[j++] = ' '; | ||
432 | |||
433 | return trace_seq_putmem(s, hex, j); | ||
434 | } | ||
435 | |||
436 | static int | ||
437 | trace_seq_path(struct trace_seq *s, struct path *path) | ||
438 | { | ||
439 | unsigned char *p; | ||
440 | |||
441 | if (s->len >= (PAGE_SIZE - 1)) | ||
442 | return 0; | ||
443 | p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); | ||
444 | if (!IS_ERR(p)) { | ||
445 | p = mangle_path(s->buffer + s->len, p, "\n"); | ||
446 | if (p) { | ||
447 | s->len = p - s->buffer; | ||
448 | return 1; | ||
449 | } | ||
450 | } else { | ||
451 | s->buffer[s->len++] = '?'; | ||
452 | return 1; | ||
453 | } | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static void | 341 | static void |
459 | trace_seq_reset(struct trace_seq *s) | 342 | trace_seq_reset(struct trace_seq *s) |
460 | { | 343 | { |
@@ -543,7 +426,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
543 | 426 | ||
544 | ftrace_enable_cpu(); | 427 | ftrace_enable_cpu(); |
545 | 428 | ||
546 | WARN_ON_ONCE(ret); | 429 | WARN_ON_ONCE(ret && ret != -EAGAIN); |
547 | 430 | ||
548 | __update_max_tr(tr, tsk, cpu); | 431 | __update_max_tr(tr, tsk, cpu); |
549 | __raw_spin_unlock(&ftrace_max_lock); | 432 | __raw_spin_unlock(&ftrace_max_lock); |
@@ -596,7 +479,7 @@ int register_tracer(struct tracer *type) | |||
596 | type->flags->opts = dummy_tracer_opt; | 479 | type->flags->opts = dummy_tracer_opt; |
597 | 480 | ||
598 | #ifdef CONFIG_FTRACE_STARTUP_TEST | 481 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
599 | if (type->selftest) { | 482 | if (type->selftest && !tracing_selftest_disabled) { |
600 | struct tracer *saved_tracer = current_trace; | 483 | struct tracer *saved_tracer = current_trace; |
601 | struct trace_array *tr = &global_trace; | 484 | struct trace_array *tr = &global_trace; |
602 | int i; | 485 | int i; |
@@ -638,8 +521,25 @@ int register_tracer(struct tracer *type) | |||
638 | out: | 521 | out: |
639 | tracing_selftest_running = false; | 522 | tracing_selftest_running = false; |
640 | mutex_unlock(&trace_types_lock); | 523 | mutex_unlock(&trace_types_lock); |
641 | lock_kernel(); | ||
642 | 524 | ||
525 | if (!ret && default_bootup_tracer) { | ||
526 | if (!strncmp(default_bootup_tracer, type->name, | ||
527 | BOOTUP_TRACER_SIZE)) { | ||
528 | printk(KERN_INFO "Starting tracer '%s'\n", | ||
529 | type->name); | ||
530 | /* Do we want this tracer to start on bootup? */ | ||
531 | tracing_set_tracer(type->name); | ||
532 | default_bootup_tracer = NULL; | ||
533 | /* disable other selftests, since this will break it. */ | ||
534 | tracing_selftest_disabled = 1; | ||
535 | #ifdef CONFIG_FTRACE_STARTUP_TEST | ||
536 | printk(KERN_INFO "Disabling FTRACE selftests due" | ||
537 | " to running tracer '%s'\n", type->name); | ||
538 | #endif | ||
539 | } | ||
540 | } | ||
541 | |||
542 | lock_kernel(); | ||
643 | return ret; | 543 | return ret; |
644 | } | 544 | } |
645 | 545 | ||
@@ -738,13 +638,12 @@ void tracing_start(void) | |||
738 | return; | 638 | return; |
739 | 639 | ||
740 | spin_lock_irqsave(&tracing_start_lock, flags); | 640 | spin_lock_irqsave(&tracing_start_lock, flags); |
741 | if (--trace_stop_count) | 641 | if (--trace_stop_count) { |
742 | goto out; | 642 | if (trace_stop_count < 0) { |
743 | 643 | /* Someone screwed up their debugging */ | |
744 | if (trace_stop_count < 0) { | 644 | WARN_ON_ONCE(1); |
745 | /* Someone screwed up their debugging */ | 645 | trace_stop_count = 0; |
746 | WARN_ON_ONCE(1); | 646 | } |
747 | trace_stop_count = 0; | ||
748 | goto out; | 647 | goto out; |
749 | } | 648 | } |
750 | 649 | ||
@@ -960,10 +859,10 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data, | |||
960 | trace_function(tr, data, ip, parent_ip, flags, pc); | 859 | trace_function(tr, data, ip, parent_ip, flags, pc); |
961 | } | 860 | } |
962 | 861 | ||
963 | static void ftrace_trace_stack(struct trace_array *tr, | 862 | static void __ftrace_trace_stack(struct trace_array *tr, |
964 | struct trace_array_cpu *data, | 863 | struct trace_array_cpu *data, |
965 | unsigned long flags, | 864 | unsigned long flags, |
966 | int skip, int pc) | 865 | int skip, int pc) |
967 | { | 866 | { |
968 | #ifdef CONFIG_STACKTRACE | 867 | #ifdef CONFIG_STACKTRACE |
969 | struct ring_buffer_event *event; | 868 | struct ring_buffer_event *event; |
@@ -971,9 +870,6 @@ static void ftrace_trace_stack(struct trace_array *tr, | |||
971 | struct stack_trace trace; | 870 | struct stack_trace trace; |
972 | unsigned long irq_flags; | 871 | unsigned long irq_flags; |
973 | 872 | ||
974 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | ||
975 | return; | ||
976 | |||
977 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), | 873 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
978 | &irq_flags); | 874 | &irq_flags); |
979 | if (!event) | 875 | if (!event) |
@@ -994,12 +890,23 @@ static void ftrace_trace_stack(struct trace_array *tr, | |||
994 | #endif | 890 | #endif |
995 | } | 891 | } |
996 | 892 | ||
893 | static void ftrace_trace_stack(struct trace_array *tr, | ||
894 | struct trace_array_cpu *data, | ||
895 | unsigned long flags, | ||
896 | int skip, int pc) | ||
897 | { | ||
898 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | ||
899 | return; | ||
900 | |||
901 | __ftrace_trace_stack(tr, data, flags, skip, pc); | ||
902 | } | ||
903 | |||
997 | void __trace_stack(struct trace_array *tr, | 904 | void __trace_stack(struct trace_array *tr, |
998 | struct trace_array_cpu *data, | 905 | struct trace_array_cpu *data, |
999 | unsigned long flags, | 906 | unsigned long flags, |
1000 | int skip) | 907 | int skip, int pc) |
1001 | { | 908 | { |
1002 | ftrace_trace_stack(tr, data, flags, skip, preempt_count()); | 909 | __ftrace_trace_stack(tr, data, flags, skip, pc); |
1003 | } | 910 | } |
1004 | 911 | ||
1005 | static void ftrace_trace_userstack(struct trace_array *tr, | 912 | static void ftrace_trace_userstack(struct trace_array *tr, |
@@ -1163,65 +1070,6 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | |||
1163 | local_irq_restore(flags); | 1070 | local_irq_restore(flags); |
1164 | } | 1071 | } |
1165 | 1072 | ||
1166 | #ifdef CONFIG_FUNCTION_TRACER | ||
1167 | static void | ||
1168 | function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) | ||
1169 | { | ||
1170 | struct trace_array *tr = &global_trace; | ||
1171 | struct trace_array_cpu *data; | ||
1172 | unsigned long flags; | ||
1173 | long disabled; | ||
1174 | int cpu, resched; | ||
1175 | int pc; | ||
1176 | |||
1177 | if (unlikely(!ftrace_function_enabled)) | ||
1178 | return; | ||
1179 | |||
1180 | pc = preempt_count(); | ||
1181 | resched = ftrace_preempt_disable(); | ||
1182 | local_save_flags(flags); | ||
1183 | cpu = raw_smp_processor_id(); | ||
1184 | data = tr->data[cpu]; | ||
1185 | disabled = atomic_inc_return(&data->disabled); | ||
1186 | |||
1187 | if (likely(disabled == 1)) | ||
1188 | trace_function(tr, data, ip, parent_ip, flags, pc); | ||
1189 | |||
1190 | atomic_dec(&data->disabled); | ||
1191 | ftrace_preempt_enable(resched); | ||
1192 | } | ||
1193 | |||
1194 | static void | ||
1195 | function_trace_call(unsigned long ip, unsigned long parent_ip) | ||
1196 | { | ||
1197 | struct trace_array *tr = &global_trace; | ||
1198 | struct trace_array_cpu *data; | ||
1199 | unsigned long flags; | ||
1200 | long disabled; | ||
1201 | int cpu; | ||
1202 | int pc; | ||
1203 | |||
1204 | if (unlikely(!ftrace_function_enabled)) | ||
1205 | return; | ||
1206 | |||
1207 | /* | ||
1208 | * Need to use raw, since this must be called before the | ||
1209 | * recursive protection is performed. | ||
1210 | */ | ||
1211 | local_irq_save(flags); | ||
1212 | cpu = raw_smp_processor_id(); | ||
1213 | data = tr->data[cpu]; | ||
1214 | disabled = atomic_inc_return(&data->disabled); | ||
1215 | |||
1216 | if (likely(disabled == 1)) { | ||
1217 | pc = preempt_count(); | ||
1218 | trace_function(tr, data, ip, parent_ip, flags, pc); | ||
1219 | } | ||
1220 | |||
1221 | atomic_dec(&data->disabled); | ||
1222 | local_irq_restore(flags); | ||
1223 | } | ||
1224 | |||
1225 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 1073 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1226 | int trace_graph_entry(struct ftrace_graph_ent *trace) | 1074 | int trace_graph_entry(struct ftrace_graph_ent *trace) |
1227 | { | 1075 | { |
@@ -1279,31 +1127,6 @@ void trace_graph_return(struct ftrace_graph_ret *trace) | |||
1279 | } | 1127 | } |
1280 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | 1128 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
1281 | 1129 | ||
1282 | static struct ftrace_ops trace_ops __read_mostly = | ||
1283 | { | ||
1284 | .func = function_trace_call, | ||
1285 | }; | ||
1286 | |||
1287 | void tracing_start_function_trace(void) | ||
1288 | { | ||
1289 | ftrace_function_enabled = 0; | ||
1290 | |||
1291 | if (trace_flags & TRACE_ITER_PREEMPTONLY) | ||
1292 | trace_ops.func = function_trace_call_preempt_only; | ||
1293 | else | ||
1294 | trace_ops.func = function_trace_call; | ||
1295 | |||
1296 | register_ftrace_function(&trace_ops); | ||
1297 | ftrace_function_enabled = 1; | ||
1298 | } | ||
1299 | |||
1300 | void tracing_stop_function_trace(void) | ||
1301 | { | ||
1302 | ftrace_function_enabled = 0; | ||
1303 | unregister_ftrace_function(&trace_ops); | ||
1304 | } | ||
1305 | #endif | ||
1306 | |||
1307 | enum trace_file_type { | 1130 | enum trace_file_type { |
1308 | TRACE_FILE_LAT_FMT = 1, | 1131 | TRACE_FILE_LAT_FMT = 1, |
1309 | TRACE_FILE_ANNOTATE = 2, | 1132 | TRACE_FILE_ANNOTATE = 2, |
@@ -1376,8 +1199,8 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1376 | } | 1199 | } |
1377 | 1200 | ||
1378 | /* Find the next real entry, without updating the iterator itself */ | 1201 | /* Find the next real entry, without updating the iterator itself */ |
1379 | static struct trace_entry * | 1202 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
1380 | find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | 1203 | int *ent_cpu, u64 *ent_ts) |
1381 | { | 1204 | { |
1382 | return __find_next_entry(iter, ent_cpu, ent_ts); | 1205 | return __find_next_entry(iter, ent_cpu, ent_ts); |
1383 | } | 1206 | } |
@@ -1472,154 +1295,6 @@ static void s_stop(struct seq_file *m, void *p) | |||
1472 | mutex_unlock(&trace_types_lock); | 1295 | mutex_unlock(&trace_types_lock); |
1473 | } | 1296 | } |
1474 | 1297 | ||
1475 | #ifdef CONFIG_KRETPROBES | ||
1476 | static inline const char *kretprobed(const char *name) | ||
1477 | { | ||
1478 | static const char tramp_name[] = "kretprobe_trampoline"; | ||
1479 | int size = sizeof(tramp_name); | ||
1480 | |||
1481 | if (strncmp(tramp_name, name, size) == 0) | ||
1482 | return "[unknown/kretprobe'd]"; | ||
1483 | return name; | ||
1484 | } | ||
1485 | #else | ||
1486 | static inline const char *kretprobed(const char *name) | ||
1487 | { | ||
1488 | return name; | ||
1489 | } | ||
1490 | #endif /* CONFIG_KRETPROBES */ | ||
1491 | |||
1492 | static int | ||
1493 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) | ||
1494 | { | ||
1495 | #ifdef CONFIG_KALLSYMS | ||
1496 | char str[KSYM_SYMBOL_LEN]; | ||
1497 | const char *name; | ||
1498 | |||
1499 | kallsyms_lookup(address, NULL, NULL, NULL, str); | ||
1500 | |||
1501 | name = kretprobed(str); | ||
1502 | |||
1503 | return trace_seq_printf(s, fmt, name); | ||
1504 | #endif | ||
1505 | return 1; | ||
1506 | } | ||
1507 | |||
1508 | static int | ||
1509 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, | ||
1510 | unsigned long address) | ||
1511 | { | ||
1512 | #ifdef CONFIG_KALLSYMS | ||
1513 | char str[KSYM_SYMBOL_LEN]; | ||
1514 | const char *name; | ||
1515 | |||
1516 | sprint_symbol(str, address); | ||
1517 | name = kretprobed(str); | ||
1518 | |||
1519 | return trace_seq_printf(s, fmt, name); | ||
1520 | #endif | ||
1521 | return 1; | ||
1522 | } | ||
1523 | |||
1524 | #ifndef CONFIG_64BIT | ||
1525 | # define IP_FMT "%08lx" | ||
1526 | #else | ||
1527 | # define IP_FMT "%016lx" | ||
1528 | #endif | ||
1529 | |||
1530 | int | ||
1531 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) | ||
1532 | { | ||
1533 | int ret; | ||
1534 | |||
1535 | if (!ip) | ||
1536 | return trace_seq_printf(s, "0"); | ||
1537 | |||
1538 | if (sym_flags & TRACE_ITER_SYM_OFFSET) | ||
1539 | ret = seq_print_sym_offset(s, "%s", ip); | ||
1540 | else | ||
1541 | ret = seq_print_sym_short(s, "%s", ip); | ||
1542 | |||
1543 | if (!ret) | ||
1544 | return 0; | ||
1545 | |||
1546 | if (sym_flags & TRACE_ITER_SYM_ADDR) | ||
1547 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
1548 | return ret; | ||
1549 | } | ||
1550 | |||
1551 | static inline int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | ||
1552 | unsigned long ip, unsigned long sym_flags) | ||
1553 | { | ||
1554 | struct file *file = NULL; | ||
1555 | unsigned long vmstart = 0; | ||
1556 | int ret = 1; | ||
1557 | |||
1558 | if (mm) { | ||
1559 | const struct vm_area_struct *vma; | ||
1560 | |||
1561 | down_read(&mm->mmap_sem); | ||
1562 | vma = find_vma(mm, ip); | ||
1563 | if (vma) { | ||
1564 | file = vma->vm_file; | ||
1565 | vmstart = vma->vm_start; | ||
1566 | } | ||
1567 | if (file) { | ||
1568 | ret = trace_seq_path(s, &file->f_path); | ||
1569 | if (ret) | ||
1570 | ret = trace_seq_printf(s, "[+0x%lx]", ip - vmstart); | ||
1571 | } | ||
1572 | up_read(&mm->mmap_sem); | ||
1573 | } | ||
1574 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) | ||
1575 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); | ||
1576 | return ret; | ||
1577 | } | ||
1578 | |||
1579 | static int | ||
1580 | seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, | ||
1581 | unsigned long sym_flags) | ||
1582 | { | ||
1583 | struct mm_struct *mm = NULL; | ||
1584 | int ret = 1; | ||
1585 | unsigned int i; | ||
1586 | |||
1587 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { | ||
1588 | struct task_struct *task; | ||
1589 | /* | ||
1590 | * we do the lookup on the thread group leader, | ||
1591 | * since individual threads might have already quit! | ||
1592 | */ | ||
1593 | rcu_read_lock(); | ||
1594 | task = find_task_by_vpid(entry->ent.tgid); | ||
1595 | if (task) | ||
1596 | mm = get_task_mm(task); | ||
1597 | rcu_read_unlock(); | ||
1598 | } | ||
1599 | |||
1600 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
1601 | unsigned long ip = entry->caller[i]; | ||
1602 | |||
1603 | if (ip == ULONG_MAX || !ret) | ||
1604 | break; | ||
1605 | if (i && ret) | ||
1606 | ret = trace_seq_puts(s, " <- "); | ||
1607 | if (!ip) { | ||
1608 | if (ret) | ||
1609 | ret = trace_seq_puts(s, "??"); | ||
1610 | continue; | ||
1611 | } | ||
1612 | if (!ret) | ||
1613 | break; | ||
1614 | if (ret) | ||
1615 | ret = seq_print_user_ip(s, mm, ip, sym_flags); | ||
1616 | } | ||
1617 | |||
1618 | if (mm) | ||
1619 | mmput(mm); | ||
1620 | return ret; | ||
1621 | } | ||
1622 | |||
1623 | static void print_lat_help_header(struct seq_file *m) | 1298 | static void print_lat_help_header(struct seq_file *m) |
1624 | { | 1299 | { |
1625 | seq_puts(m, "# _------=> CPU# \n"); | 1300 | seq_puts(m, "# _------=> CPU# \n"); |
@@ -1704,103 +1379,6 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) | |||
1704 | seq_puts(m, "\n"); | 1379 | seq_puts(m, "\n"); |
1705 | } | 1380 | } |
1706 | 1381 | ||
1707 | static void | ||
1708 | lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) | ||
1709 | { | ||
1710 | int hardirq, softirq; | ||
1711 | char *comm; | ||
1712 | |||
1713 | comm = trace_find_cmdline(entry->pid); | ||
1714 | |||
1715 | trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid); | ||
1716 | trace_seq_printf(s, "%3d", cpu); | ||
1717 | trace_seq_printf(s, "%c%c", | ||
1718 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : | ||
1719 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.', | ||
1720 | ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.')); | ||
1721 | |||
1722 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; | ||
1723 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; | ||
1724 | if (hardirq && softirq) { | ||
1725 | trace_seq_putc(s, 'H'); | ||
1726 | } else { | ||
1727 | if (hardirq) { | ||
1728 | trace_seq_putc(s, 'h'); | ||
1729 | } else { | ||
1730 | if (softirq) | ||
1731 | trace_seq_putc(s, 's'); | ||
1732 | else | ||
1733 | trace_seq_putc(s, '.'); | ||
1734 | } | ||
1735 | } | ||
1736 | |||
1737 | if (entry->preempt_count) | ||
1738 | trace_seq_printf(s, "%x", entry->preempt_count); | ||
1739 | else | ||
1740 | trace_seq_puts(s, "."); | ||
1741 | } | ||
1742 | |||
1743 | unsigned long preempt_mark_thresh = 100; | ||
1744 | |||
1745 | static void | ||
1746 | lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, | ||
1747 | unsigned long rel_usecs) | ||
1748 | { | ||
1749 | trace_seq_printf(s, " %4lldus", abs_usecs); | ||
1750 | if (rel_usecs > preempt_mark_thresh) | ||
1751 | trace_seq_puts(s, "!: "); | ||
1752 | else if (rel_usecs > 1) | ||
1753 | trace_seq_puts(s, "+: "); | ||
1754 | else | ||
1755 | trace_seq_puts(s, " : "); | ||
1756 | } | ||
1757 | |||
1758 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; | ||
1759 | |||
1760 | static int task_state_char(unsigned long state) | ||
1761 | { | ||
1762 | int bit = state ? __ffs(state) + 1 : 0; | ||
1763 | |||
1764 | return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; | ||
1765 | } | ||
1766 | |||
1767 | /* | ||
1768 | * The message is supposed to contain an ending newline. | ||
1769 | * If the printing stops prematurely, try to add a newline of our own. | ||
1770 | */ | ||
1771 | void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter) | ||
1772 | { | ||
1773 | struct trace_entry *ent; | ||
1774 | struct trace_field_cont *cont; | ||
1775 | bool ok = true; | ||
1776 | |||
1777 | ent = peek_next_entry(iter, iter->cpu, NULL); | ||
1778 | if (!ent || ent->type != TRACE_CONT) { | ||
1779 | trace_seq_putc(s, '\n'); | ||
1780 | return; | ||
1781 | } | ||
1782 | |||
1783 | do { | ||
1784 | cont = (struct trace_field_cont *)ent; | ||
1785 | if (ok) | ||
1786 | ok = (trace_seq_printf(s, "%s", cont->buf) > 0); | ||
1787 | |||
1788 | ftrace_disable_cpu(); | ||
1789 | |||
1790 | if (iter->buffer_iter[iter->cpu]) | ||
1791 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); | ||
1792 | else | ||
1793 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); | ||
1794 | |||
1795 | ftrace_enable_cpu(); | ||
1796 | |||
1797 | ent = peek_next_entry(iter, iter->cpu, NULL); | ||
1798 | } while (ent && ent->type == TRACE_CONT); | ||
1799 | |||
1800 | if (!ok) | ||
1801 | trace_seq_putc(s, '\n'); | ||
1802 | } | ||
1803 | |||
1804 | static void test_cpu_buff_start(struct trace_iterator *iter) | 1382 | static void test_cpu_buff_start(struct trace_iterator *iter) |
1805 | { | 1383 | { |
1806 | struct trace_seq *s = &iter->seq; | 1384 | struct trace_seq *s = &iter->seq; |
@@ -1818,138 +1396,31 @@ static void test_cpu_buff_start(struct trace_iterator *iter) | |||
1818 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); | 1396 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); |
1819 | } | 1397 | } |
1820 | 1398 | ||
1821 | static enum print_line_t | 1399 | static enum print_line_t print_lat_fmt(struct trace_iterator *iter) |
1822 | print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu) | ||
1823 | { | 1400 | { |
1824 | struct trace_seq *s = &iter->seq; | 1401 | struct trace_seq *s = &iter->seq; |
1825 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1402 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
1826 | struct trace_entry *next_entry; | 1403 | struct trace_event *event; |
1827 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); | ||
1828 | struct trace_entry *entry = iter->ent; | 1404 | struct trace_entry *entry = iter->ent; |
1829 | unsigned long abs_usecs; | ||
1830 | unsigned long rel_usecs; | ||
1831 | u64 next_ts; | ||
1832 | char *comm; | ||
1833 | int S, T; | ||
1834 | int i; | ||
1835 | |||
1836 | if (entry->type == TRACE_CONT) | ||
1837 | return TRACE_TYPE_HANDLED; | ||
1838 | 1405 | ||
1839 | test_cpu_buff_start(iter); | 1406 | test_cpu_buff_start(iter); |
1840 | 1407 | ||
1841 | next_entry = find_next_entry(iter, NULL, &next_ts); | 1408 | event = ftrace_find_event(entry->type); |
1842 | if (!next_entry) | ||
1843 | next_ts = iter->ts; | ||
1844 | rel_usecs = ns2usecs(next_ts - iter->ts); | ||
1845 | abs_usecs = ns2usecs(iter->ts - iter->tr->time_start); | ||
1846 | |||
1847 | if (verbose) { | ||
1848 | comm = trace_find_cmdline(entry->pid); | ||
1849 | trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]" | ||
1850 | " %ld.%03ldms (+%ld.%03ldms): ", | ||
1851 | comm, | ||
1852 | entry->pid, cpu, entry->flags, | ||
1853 | entry->preempt_count, trace_idx, | ||
1854 | ns2usecs(iter->ts), | ||
1855 | abs_usecs/1000, | ||
1856 | abs_usecs % 1000, rel_usecs/1000, | ||
1857 | rel_usecs % 1000); | ||
1858 | } else { | ||
1859 | lat_print_generic(s, entry, cpu); | ||
1860 | lat_print_timestamp(s, abs_usecs, rel_usecs); | ||
1861 | } | ||
1862 | switch (entry->type) { | ||
1863 | case TRACE_FN: { | ||
1864 | struct ftrace_entry *field; | ||
1865 | |||
1866 | trace_assign_type(field, entry); | ||
1867 | |||
1868 | seq_print_ip_sym(s, field->ip, sym_flags); | ||
1869 | trace_seq_puts(s, " ("); | ||
1870 | seq_print_ip_sym(s, field->parent_ip, sym_flags); | ||
1871 | trace_seq_puts(s, ")\n"); | ||
1872 | break; | ||
1873 | } | ||
1874 | case TRACE_CTX: | ||
1875 | case TRACE_WAKE: { | ||
1876 | struct ctx_switch_entry *field; | ||
1877 | |||
1878 | trace_assign_type(field, entry); | ||
1879 | |||
1880 | T = task_state_char(field->next_state); | ||
1881 | S = task_state_char(field->prev_state); | ||
1882 | comm = trace_find_cmdline(field->next_pid); | ||
1883 | trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", | ||
1884 | field->prev_pid, | ||
1885 | field->prev_prio, | ||
1886 | S, entry->type == TRACE_CTX ? "==>" : " +", | ||
1887 | field->next_cpu, | ||
1888 | field->next_pid, | ||
1889 | field->next_prio, | ||
1890 | T, comm); | ||
1891 | break; | ||
1892 | } | ||
1893 | case TRACE_SPECIAL: { | ||
1894 | struct special_entry *field; | ||
1895 | |||
1896 | trace_assign_type(field, entry); | ||
1897 | |||
1898 | trace_seq_printf(s, "# %ld %ld %ld\n", | ||
1899 | field->arg1, | ||
1900 | field->arg2, | ||
1901 | field->arg3); | ||
1902 | break; | ||
1903 | } | ||
1904 | case TRACE_STACK: { | ||
1905 | struct stack_entry *field; | ||
1906 | |||
1907 | trace_assign_type(field, entry); | ||
1908 | 1409 | ||
1909 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | 1410 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
1910 | if (i) | 1411 | if (!trace_print_lat_context(iter)) |
1911 | trace_seq_puts(s, " <= "); | 1412 | goto partial; |
1912 | seq_print_ip_sym(s, field->caller[i], sym_flags); | ||
1913 | } | ||
1914 | trace_seq_puts(s, "\n"); | ||
1915 | break; | ||
1916 | } | ||
1917 | case TRACE_PRINT: { | ||
1918 | struct print_entry *field; | ||
1919 | |||
1920 | trace_assign_type(field, entry); | ||
1921 | |||
1922 | seq_print_ip_sym(s, field->ip, sym_flags); | ||
1923 | trace_seq_printf(s, ": %s", field->buf); | ||
1924 | if (entry->flags & TRACE_FLAG_CONT) | ||
1925 | trace_seq_print_cont(s, iter); | ||
1926 | break; | ||
1927 | } | 1413 | } |
1928 | case TRACE_BRANCH: { | ||
1929 | struct trace_branch *field; | ||
1930 | 1414 | ||
1931 | trace_assign_type(field, entry); | 1415 | if (event && event->latency_trace) |
1416 | return event->latency_trace(iter, sym_flags); | ||
1932 | 1417 | ||
1933 | trace_seq_printf(s, "[%s] %s:%s:%d\n", | 1418 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
1934 | field->correct ? " ok " : " MISS ", | 1419 | goto partial; |
1935 | field->func, | ||
1936 | field->file, | ||
1937 | field->line); | ||
1938 | break; | ||
1939 | } | ||
1940 | case TRACE_USER_STACK: { | ||
1941 | struct userstack_entry *field; | ||
1942 | |||
1943 | trace_assign_type(field, entry); | ||
1944 | 1420 | ||
1945 | seq_print_userip_objs(field, s, sym_flags); | ||
1946 | trace_seq_putc(s, '\n'); | ||
1947 | break; | ||
1948 | } | ||
1949 | default: | ||
1950 | trace_seq_printf(s, "Unknown type %d\n", entry->type); | ||
1951 | } | ||
1952 | return TRACE_TYPE_HANDLED; | 1421 | return TRACE_TYPE_HANDLED; |
1422 | partial: | ||
1423 | return TRACE_TYPE_PARTIAL_LINE; | ||
1953 | } | 1424 | } |
1954 | 1425 | ||
1955 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | 1426 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
@@ -1957,313 +1428,78 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
1957 | struct trace_seq *s = &iter->seq; | 1428 | struct trace_seq *s = &iter->seq; |
1958 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1429 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
1959 | struct trace_entry *entry; | 1430 | struct trace_entry *entry; |
1960 | unsigned long usec_rem; | 1431 | struct trace_event *event; |
1961 | unsigned long long t; | ||
1962 | unsigned long secs; | ||
1963 | char *comm; | ||
1964 | int ret; | ||
1965 | int S, T; | ||
1966 | int i; | ||
1967 | 1432 | ||
1968 | entry = iter->ent; | 1433 | entry = iter->ent; |
1969 | 1434 | ||
1970 | if (entry->type == TRACE_CONT) | ||
1971 | return TRACE_TYPE_HANDLED; | ||
1972 | |||
1973 | test_cpu_buff_start(iter); | 1435 | test_cpu_buff_start(iter); |
1974 | 1436 | ||
1975 | comm = trace_find_cmdline(iter->ent->pid); | 1437 | event = ftrace_find_event(entry->type); |
1976 | |||
1977 | t = ns2usecs(iter->ts); | ||
1978 | usec_rem = do_div(t, 1000000ULL); | ||
1979 | secs = (unsigned long)t; | ||
1980 | |||
1981 | ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid); | ||
1982 | if (!ret) | ||
1983 | return TRACE_TYPE_PARTIAL_LINE; | ||
1984 | ret = trace_seq_printf(s, "[%03d] ", iter->cpu); | ||
1985 | if (!ret) | ||
1986 | return TRACE_TYPE_PARTIAL_LINE; | ||
1987 | ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem); | ||
1988 | if (!ret) | ||
1989 | return TRACE_TYPE_PARTIAL_LINE; | ||
1990 | 1438 | ||
1991 | switch (entry->type) { | 1439 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
1992 | case TRACE_FN: { | 1440 | if (!trace_print_context(iter)) |
1993 | struct ftrace_entry *field; | 1441 | goto partial; |
1994 | |||
1995 | trace_assign_type(field, entry); | ||
1996 | |||
1997 | ret = seq_print_ip_sym(s, field->ip, sym_flags); | ||
1998 | if (!ret) | ||
1999 | return TRACE_TYPE_PARTIAL_LINE; | ||
2000 | if ((sym_flags & TRACE_ITER_PRINT_PARENT) && | ||
2001 | field->parent_ip) { | ||
2002 | ret = trace_seq_printf(s, " <-"); | ||
2003 | if (!ret) | ||
2004 | return TRACE_TYPE_PARTIAL_LINE; | ||
2005 | ret = seq_print_ip_sym(s, | ||
2006 | field->parent_ip, | ||
2007 | sym_flags); | ||
2008 | if (!ret) | ||
2009 | return TRACE_TYPE_PARTIAL_LINE; | ||
2010 | } | ||
2011 | ret = trace_seq_printf(s, "\n"); | ||
2012 | if (!ret) | ||
2013 | return TRACE_TYPE_PARTIAL_LINE; | ||
2014 | break; | ||
2015 | } | ||
2016 | case TRACE_CTX: | ||
2017 | case TRACE_WAKE: { | ||
2018 | struct ctx_switch_entry *field; | ||
2019 | |||
2020 | trace_assign_type(field, entry); | ||
2021 | |||
2022 | T = task_state_char(field->next_state); | ||
2023 | S = task_state_char(field->prev_state); | ||
2024 | ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n", | ||
2025 | field->prev_pid, | ||
2026 | field->prev_prio, | ||
2027 | S, | ||
2028 | entry->type == TRACE_CTX ? "==>" : " +", | ||
2029 | field->next_cpu, | ||
2030 | field->next_pid, | ||
2031 | field->next_prio, | ||
2032 | T); | ||
2033 | if (!ret) | ||
2034 | return TRACE_TYPE_PARTIAL_LINE; | ||
2035 | break; | ||
2036 | } | 1442 | } |
2037 | case TRACE_SPECIAL: { | ||
2038 | struct special_entry *field; | ||
2039 | 1443 | ||
2040 | trace_assign_type(field, entry); | 1444 | if (event && event->trace) |
2041 | 1445 | return event->trace(iter, sym_flags); | |
2042 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", | ||
2043 | field->arg1, | ||
2044 | field->arg2, | ||
2045 | field->arg3); | ||
2046 | if (!ret) | ||
2047 | return TRACE_TYPE_PARTIAL_LINE; | ||
2048 | break; | ||
2049 | } | ||
2050 | case TRACE_STACK: { | ||
2051 | struct stack_entry *field; | ||
2052 | |||
2053 | trace_assign_type(field, entry); | ||
2054 | |||
2055 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | ||
2056 | if (i) { | ||
2057 | ret = trace_seq_puts(s, " <= "); | ||
2058 | if (!ret) | ||
2059 | return TRACE_TYPE_PARTIAL_LINE; | ||
2060 | } | ||
2061 | ret = seq_print_ip_sym(s, field->caller[i], | ||
2062 | sym_flags); | ||
2063 | if (!ret) | ||
2064 | return TRACE_TYPE_PARTIAL_LINE; | ||
2065 | } | ||
2066 | ret = trace_seq_puts(s, "\n"); | ||
2067 | if (!ret) | ||
2068 | return TRACE_TYPE_PARTIAL_LINE; | ||
2069 | break; | ||
2070 | } | ||
2071 | case TRACE_PRINT: { | ||
2072 | struct print_entry *field; | ||
2073 | |||
2074 | trace_assign_type(field, entry); | ||
2075 | |||
2076 | seq_print_ip_sym(s, field->ip, sym_flags); | ||
2077 | trace_seq_printf(s, ": %s", field->buf); | ||
2078 | if (entry->flags & TRACE_FLAG_CONT) | ||
2079 | trace_seq_print_cont(s, iter); | ||
2080 | break; | ||
2081 | } | ||
2082 | case TRACE_GRAPH_RET: { | ||
2083 | return print_graph_function(iter); | ||
2084 | } | ||
2085 | case TRACE_GRAPH_ENT: { | ||
2086 | return print_graph_function(iter); | ||
2087 | } | ||
2088 | case TRACE_BRANCH: { | ||
2089 | struct trace_branch *field; | ||
2090 | 1446 | ||
2091 | trace_assign_type(field, entry); | 1447 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
1448 | goto partial; | ||
2092 | 1449 | ||
2093 | trace_seq_printf(s, "[%s] %s:%s:%d\n", | ||
2094 | field->correct ? " ok " : " MISS ", | ||
2095 | field->func, | ||
2096 | field->file, | ||
2097 | field->line); | ||
2098 | break; | ||
2099 | } | ||
2100 | case TRACE_USER_STACK: { | ||
2101 | struct userstack_entry *field; | ||
2102 | |||
2103 | trace_assign_type(field, entry); | ||
2104 | |||
2105 | ret = seq_print_userip_objs(field, s, sym_flags); | ||
2106 | if (!ret) | ||
2107 | return TRACE_TYPE_PARTIAL_LINE; | ||
2108 | ret = trace_seq_putc(s, '\n'); | ||
2109 | if (!ret) | ||
2110 | return TRACE_TYPE_PARTIAL_LINE; | ||
2111 | break; | ||
2112 | } | ||
2113 | } | ||
2114 | return TRACE_TYPE_HANDLED; | 1450 | return TRACE_TYPE_HANDLED; |
1451 | partial: | ||
1452 | return TRACE_TYPE_PARTIAL_LINE; | ||
2115 | } | 1453 | } |
2116 | 1454 | ||
2117 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) | 1455 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
2118 | { | 1456 | { |
2119 | struct trace_seq *s = &iter->seq; | 1457 | struct trace_seq *s = &iter->seq; |
2120 | struct trace_entry *entry; | 1458 | struct trace_entry *entry; |
2121 | int ret; | 1459 | struct trace_event *event; |
2122 | int S, T; | ||
2123 | 1460 | ||
2124 | entry = iter->ent; | 1461 | entry = iter->ent; |
2125 | 1462 | ||
2126 | if (entry->type == TRACE_CONT) | 1463 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
2127 | return TRACE_TYPE_HANDLED; | 1464 | if (!trace_seq_printf(s, "%d %d %llu ", |
2128 | 1465 | entry->pid, iter->cpu, iter->ts)) | |
2129 | ret = trace_seq_printf(s, "%d %d %llu ", | 1466 | goto partial; |
2130 | entry->pid, iter->cpu, iter->ts); | ||
2131 | if (!ret) | ||
2132 | return TRACE_TYPE_PARTIAL_LINE; | ||
2133 | |||
2134 | switch (entry->type) { | ||
2135 | case TRACE_FN: { | ||
2136 | struct ftrace_entry *field; | ||
2137 | |||
2138 | trace_assign_type(field, entry); | ||
2139 | |||
2140 | ret = trace_seq_printf(s, "%x %x\n", | ||
2141 | field->ip, | ||
2142 | field->parent_ip); | ||
2143 | if (!ret) | ||
2144 | return TRACE_TYPE_PARTIAL_LINE; | ||
2145 | break; | ||
2146 | } | ||
2147 | case TRACE_CTX: | ||
2148 | case TRACE_WAKE: { | ||
2149 | struct ctx_switch_entry *field; | ||
2150 | |||
2151 | trace_assign_type(field, entry); | ||
2152 | |||
2153 | T = task_state_char(field->next_state); | ||
2154 | S = entry->type == TRACE_WAKE ? '+' : | ||
2155 | task_state_char(field->prev_state); | ||
2156 | ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n", | ||
2157 | field->prev_pid, | ||
2158 | field->prev_prio, | ||
2159 | S, | ||
2160 | field->next_cpu, | ||
2161 | field->next_pid, | ||
2162 | field->next_prio, | ||
2163 | T); | ||
2164 | if (!ret) | ||
2165 | return TRACE_TYPE_PARTIAL_LINE; | ||
2166 | break; | ||
2167 | } | ||
2168 | case TRACE_SPECIAL: | ||
2169 | case TRACE_USER_STACK: | ||
2170 | case TRACE_STACK: { | ||
2171 | struct special_entry *field; | ||
2172 | |||
2173 | trace_assign_type(field, entry); | ||
2174 | |||
2175 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", | ||
2176 | field->arg1, | ||
2177 | field->arg2, | ||
2178 | field->arg3); | ||
2179 | if (!ret) | ||
2180 | return TRACE_TYPE_PARTIAL_LINE; | ||
2181 | break; | ||
2182 | } | 1467 | } |
2183 | case TRACE_PRINT: { | ||
2184 | struct print_entry *field; | ||
2185 | 1468 | ||
2186 | trace_assign_type(field, entry); | 1469 | event = ftrace_find_event(entry->type); |
1470 | if (event && event->raw) | ||
1471 | return event->raw(iter, 0); | ||
1472 | |||
1473 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | ||
1474 | goto partial; | ||
2187 | 1475 | ||
2188 | trace_seq_printf(s, "# %lx %s", field->ip, field->buf); | ||
2189 | if (entry->flags & TRACE_FLAG_CONT) | ||
2190 | trace_seq_print_cont(s, iter); | ||
2191 | break; | ||
2192 | } | ||
2193 | } | ||
2194 | return TRACE_TYPE_HANDLED; | 1476 | return TRACE_TYPE_HANDLED; |
1477 | partial: | ||
1478 | return TRACE_TYPE_PARTIAL_LINE; | ||
2195 | } | 1479 | } |
2196 | 1480 | ||
2197 | #define SEQ_PUT_FIELD_RET(s, x) \ | ||
2198 | do { \ | ||
2199 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ | ||
2200 | return 0; \ | ||
2201 | } while (0) | ||
2202 | |||
2203 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ | ||
2204 | do { \ | ||
2205 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ | ||
2206 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ | ||
2207 | return 0; \ | ||
2208 | } while (0) | ||
2209 | |||
2210 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | 1481 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
2211 | { | 1482 | { |
2212 | struct trace_seq *s = &iter->seq; | 1483 | struct trace_seq *s = &iter->seq; |
2213 | unsigned char newline = '\n'; | 1484 | unsigned char newline = '\n'; |
2214 | struct trace_entry *entry; | 1485 | struct trace_entry *entry; |
2215 | int S, T; | 1486 | struct trace_event *event; |
2216 | 1487 | ||
2217 | entry = iter->ent; | 1488 | entry = iter->ent; |
2218 | 1489 | ||
2219 | if (entry->type == TRACE_CONT) | 1490 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
2220 | return TRACE_TYPE_HANDLED; | 1491 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
2221 | 1492 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); | |
2222 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); | 1493 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
2223 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); | ||
2224 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); | ||
2225 | |||
2226 | switch (entry->type) { | ||
2227 | case TRACE_FN: { | ||
2228 | struct ftrace_entry *field; | ||
2229 | |||
2230 | trace_assign_type(field, entry); | ||
2231 | |||
2232 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); | ||
2233 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); | ||
2234 | break; | ||
2235 | } | 1494 | } |
2236 | case TRACE_CTX: | ||
2237 | case TRACE_WAKE: { | ||
2238 | struct ctx_switch_entry *field; | ||
2239 | |||
2240 | trace_assign_type(field, entry); | ||
2241 | |||
2242 | T = task_state_char(field->next_state); | ||
2243 | S = entry->type == TRACE_WAKE ? '+' : | ||
2244 | task_state_char(field->prev_state); | ||
2245 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); | ||
2246 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); | ||
2247 | SEQ_PUT_HEX_FIELD_RET(s, S); | ||
2248 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); | ||
2249 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); | ||
2250 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); | ||
2251 | SEQ_PUT_HEX_FIELD_RET(s, T); | ||
2252 | break; | ||
2253 | } | ||
2254 | case TRACE_SPECIAL: | ||
2255 | case TRACE_USER_STACK: | ||
2256 | case TRACE_STACK: { | ||
2257 | struct special_entry *field; | ||
2258 | |||
2259 | trace_assign_type(field, entry); | ||
2260 | 1495 | ||
2261 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); | 1496 | event = ftrace_find_event(entry->type); |
2262 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); | 1497 | if (event && event->hex) { |
2263 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); | 1498 | enum print_line_t ret = event->hex(iter, 0); |
2264 | break; | 1499 | if (ret != TRACE_TYPE_HANDLED) |
2265 | } | 1500 | return ret; |
2266 | } | 1501 | } |
1502 | |||
2267 | SEQ_PUT_FIELD_RET(s, newline); | 1503 | SEQ_PUT_FIELD_RET(s, newline); |
2268 | 1504 | ||
2269 | return TRACE_TYPE_HANDLED; | 1505 | return TRACE_TYPE_HANDLED; |
@@ -2278,13 +1514,10 @@ static enum print_line_t print_printk_msg_only(struct trace_iterator *iter) | |||
2278 | 1514 | ||
2279 | trace_assign_type(field, entry); | 1515 | trace_assign_type(field, entry); |
2280 | 1516 | ||
2281 | ret = trace_seq_printf(s, field->buf); | 1517 | ret = trace_seq_printf(s, "%s", field->buf); |
2282 | if (!ret) | 1518 | if (!ret) |
2283 | return TRACE_TYPE_PARTIAL_LINE; | 1519 | return TRACE_TYPE_PARTIAL_LINE; |
2284 | 1520 | ||
2285 | if (entry->flags & TRACE_FLAG_CONT) | ||
2286 | trace_seq_print_cont(s, iter); | ||
2287 | |||
2288 | return TRACE_TYPE_HANDLED; | 1521 | return TRACE_TYPE_HANDLED; |
2289 | } | 1522 | } |
2290 | 1523 | ||
@@ -2292,53 +1525,21 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
2292 | { | 1525 | { |
2293 | struct trace_seq *s = &iter->seq; | 1526 | struct trace_seq *s = &iter->seq; |
2294 | struct trace_entry *entry; | 1527 | struct trace_entry *entry; |
1528 | struct trace_event *event; | ||
2295 | 1529 | ||
2296 | entry = iter->ent; | 1530 | entry = iter->ent; |
2297 | 1531 | ||
2298 | if (entry->type == TRACE_CONT) | 1532 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
2299 | return TRACE_TYPE_HANDLED; | 1533 | SEQ_PUT_FIELD_RET(s, entry->pid); |
2300 | 1534 | SEQ_PUT_FIELD_RET(s, entry->cpu); | |
2301 | SEQ_PUT_FIELD_RET(s, entry->pid); | 1535 | SEQ_PUT_FIELD_RET(s, iter->ts); |
2302 | SEQ_PUT_FIELD_RET(s, entry->cpu); | ||
2303 | SEQ_PUT_FIELD_RET(s, iter->ts); | ||
2304 | |||
2305 | switch (entry->type) { | ||
2306 | case TRACE_FN: { | ||
2307 | struct ftrace_entry *field; | ||
2308 | |||
2309 | trace_assign_type(field, entry); | ||
2310 | |||
2311 | SEQ_PUT_FIELD_RET(s, field->ip); | ||
2312 | SEQ_PUT_FIELD_RET(s, field->parent_ip); | ||
2313 | break; | ||
2314 | } | ||
2315 | case TRACE_CTX: { | ||
2316 | struct ctx_switch_entry *field; | ||
2317 | |||
2318 | trace_assign_type(field, entry); | ||
2319 | |||
2320 | SEQ_PUT_FIELD_RET(s, field->prev_pid); | ||
2321 | SEQ_PUT_FIELD_RET(s, field->prev_prio); | ||
2322 | SEQ_PUT_FIELD_RET(s, field->prev_state); | ||
2323 | SEQ_PUT_FIELD_RET(s, field->next_pid); | ||
2324 | SEQ_PUT_FIELD_RET(s, field->next_prio); | ||
2325 | SEQ_PUT_FIELD_RET(s, field->next_state); | ||
2326 | break; | ||
2327 | } | 1536 | } |
2328 | case TRACE_SPECIAL: | ||
2329 | case TRACE_USER_STACK: | ||
2330 | case TRACE_STACK: { | ||
2331 | struct special_entry *field; | ||
2332 | 1537 | ||
2333 | trace_assign_type(field, entry); | 1538 | event = ftrace_find_event(entry->type); |
1539 | if (event && event->binary) | ||
1540 | return event->binary(iter, 0); | ||
2334 | 1541 | ||
2335 | SEQ_PUT_FIELD_RET(s, field->arg1); | 1542 | return TRACE_TYPE_HANDLED; |
2336 | SEQ_PUT_FIELD_RET(s, field->arg2); | ||
2337 | SEQ_PUT_FIELD_RET(s, field->arg3); | ||
2338 | break; | ||
2339 | } | ||
2340 | } | ||
2341 | return 1; | ||
2342 | } | 1543 | } |
2343 | 1544 | ||
2344 | static int trace_empty(struct trace_iterator *iter) | 1545 | static int trace_empty(struct trace_iterator *iter) |
@@ -2383,7 +1584,7 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
2383 | return print_raw_fmt(iter); | 1584 | return print_raw_fmt(iter); |
2384 | 1585 | ||
2385 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) | 1586 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
2386 | return print_lat_fmt(iter, iter->idx, iter->cpu); | 1587 | return print_lat_fmt(iter); |
2387 | 1588 | ||
2388 | return print_trace_fmt(iter); | 1589 | return print_trace_fmt(iter); |
2389 | } | 1590 | } |
@@ -2985,7 +2186,7 @@ tracing_set_trace_read(struct file *filp, char __user *ubuf, | |||
2985 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | 2186 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
2986 | } | 2187 | } |
2987 | 2188 | ||
2988 | static int tracing_set_tracer(char *buf) | 2189 | static int tracing_set_tracer(const char *buf) |
2989 | { | 2190 | { |
2990 | struct trace_array *tr = &global_trace; | 2191 | struct trace_array *tr = &global_trace; |
2991 | struct tracer *t; | 2192 | struct tracer *t; |
@@ -3691,6 +2892,15 @@ int __ftrace_printk(unsigned long ip, const char *fmt, ...) | |||
3691 | } | 2892 | } |
3692 | EXPORT_SYMBOL_GPL(__ftrace_printk); | 2893 | EXPORT_SYMBOL_GPL(__ftrace_printk); |
3693 | 2894 | ||
2895 | int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap) | ||
2896 | { | ||
2897 | if (!(trace_flags & TRACE_ITER_PRINTK)) | ||
2898 | return 0; | ||
2899 | |||
2900 | return trace_vprintk(ip, task_curr_ret_stack(current), fmt, ap); | ||
2901 | } | ||
2902 | EXPORT_SYMBOL_GPL(__ftrace_vprintk); | ||
2903 | |||
3694 | static int trace_panic_handler(struct notifier_block *this, | 2904 | static int trace_panic_handler(struct notifier_block *this, |
3695 | unsigned long event, void *unused) | 2905 | unsigned long event, void *unused) |
3696 | { | 2906 | { |
@@ -3871,14 +3081,10 @@ __init static int tracer_alloc_buffers(void) | |||
3871 | trace_init_cmdlines(); | 3081 | trace_init_cmdlines(); |
3872 | 3082 | ||
3873 | register_tracer(&nop_trace); | 3083 | register_tracer(&nop_trace); |
3084 | current_trace = &nop_trace; | ||
3874 | #ifdef CONFIG_BOOT_TRACER | 3085 | #ifdef CONFIG_BOOT_TRACER |
3875 | register_tracer(&boot_tracer); | 3086 | register_tracer(&boot_tracer); |
3876 | current_trace = &boot_tracer; | ||
3877 | current_trace->init(&global_trace); | ||
3878 | #else | ||
3879 | current_trace = &nop_trace; | ||
3880 | #endif | 3087 | #endif |
3881 | |||
3882 | /* All seems OK, enable tracing */ | 3088 | /* All seems OK, enable tracing */ |
3883 | tracing_disabled = 0; | 3089 | tracing_disabled = 0; |
3884 | 3090 | ||
@@ -3895,5 +3101,26 @@ out_free_buffer_mask: | |||
3895 | out: | 3101 | out: |
3896 | return ret; | 3102 | return ret; |
3897 | } | 3103 | } |
3104 | |||
3105 | __init static int clear_boot_tracer(void) | ||
3106 | { | ||
3107 | /* | ||
3108 | * The default tracer at boot buffer is an init section. | ||
3109 | * This function is called in lateinit. If we did not | ||
3110 | * find the boot tracer, then clear it out, to prevent | ||
3111 | * later registration from accessing the buffer that is | ||
3112 | * about to be freed. | ||
3113 | */ | ||
3114 | if (!default_bootup_tracer) | ||
3115 | return 0; | ||
3116 | |||
3117 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", | ||
3118 | default_bootup_tracer); | ||
3119 | default_bootup_tracer = NULL; | ||
3120 | |||
3121 | return 0; | ||
3122 | } | ||
3123 | |||
3898 | early_initcall(tracer_alloc_buffers); | 3124 | early_initcall(tracer_alloc_buffers); |
3899 | fs_initcall(tracer_init_debugfs); | 3125 | fs_initcall(tracer_init_debugfs); |
3126 | late_initcall(clear_boot_tracer); | ||