diff options
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 679 |
1 files changed, 344 insertions, 335 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8c358395d338..5c75deeefe30 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -43,14 +43,11 @@ | |||
43 | 43 | ||
44 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) | 44 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
45 | 45 | ||
46 | unsigned long __read_mostly tracing_max_latency; | ||
47 | unsigned long __read_mostly tracing_thresh; | ||
48 | |||
49 | /* | 46 | /* |
50 | * On boot up, the ring buffer is set to the minimum size, so that | 47 | * On boot up, the ring buffer is set to the minimum size, so that |
51 | * we do not waste memory on systems that are not using tracing. | 48 | * we do not waste memory on systems that are not using tracing. |
52 | */ | 49 | */ |
53 | static int ring_buffer_expanded; | 50 | int ring_buffer_expanded; |
54 | 51 | ||
55 | /* | 52 | /* |
56 | * We need to change this state when a selftest is running. | 53 | * We need to change this state when a selftest is running. |
@@ -64,7 +61,7 @@ static bool __read_mostly tracing_selftest_running; | |||
64 | /* | 61 | /* |
65 | * If a tracer is running, we do not want to run SELFTEST. | 62 | * If a tracer is running, we do not want to run SELFTEST. |
66 | */ | 63 | */ |
67 | static bool __read_mostly tracing_selftest_disabled; | 64 | bool __read_mostly tracing_selftest_disabled; |
68 | 65 | ||
69 | /* For tracers that don't implement custom flags */ | 66 | /* For tracers that don't implement custom flags */ |
70 | static struct tracer_opt dummy_tracer_opt[] = { | 67 | static struct tracer_opt dummy_tracer_opt[] = { |
@@ -89,7 +86,7 @@ static int dummy_set_flag(u32 old_flags, u32 bit, int set) | |||
89 | */ | 86 | */ |
90 | static int tracing_disabled = 1; | 87 | static int tracing_disabled = 1; |
91 | 88 | ||
92 | static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); | 89 | DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); |
93 | 90 | ||
94 | static inline void ftrace_disable_cpu(void) | 91 | static inline void ftrace_disable_cpu(void) |
95 | { | 92 | { |
@@ -172,10 +169,11 @@ static struct trace_array global_trace; | |||
172 | 169 | ||
173 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); | 170 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
174 | 171 | ||
175 | int filter_current_check_discard(struct ftrace_event_call *call, void *rec, | 172 | int filter_current_check_discard(struct ring_buffer *buffer, |
173 | struct ftrace_event_call *call, void *rec, | ||
176 | struct ring_buffer_event *event) | 174 | struct ring_buffer_event *event) |
177 | { | 175 | { |
178 | return filter_check_discard(call, rec, global_trace.buffer, event); | 176 | return filter_check_discard(call, rec, buffer, event); |
179 | } | 177 | } |
180 | EXPORT_SYMBOL_GPL(filter_current_check_discard); | 178 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
181 | 179 | ||
@@ -266,6 +264,9 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | | |||
266 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | | 264 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
267 | TRACE_ITER_GRAPH_TIME; | 265 | TRACE_ITER_GRAPH_TIME; |
268 | 266 | ||
267 | static int trace_stop_count; | ||
268 | static DEFINE_SPINLOCK(tracing_start_lock); | ||
269 | |||
269 | /** | 270 | /** |
270 | * trace_wake_up - wake up tasks waiting for trace input | 271 | * trace_wake_up - wake up tasks waiting for trace input |
271 | * | 272 | * |
@@ -323,50 +324,20 @@ static const char *trace_options[] = { | |||
323 | "printk-msg-only", | 324 | "printk-msg-only", |
324 | "context-info", | 325 | "context-info", |
325 | "latency-format", | 326 | "latency-format", |
326 | "global-clock", | ||
327 | "sleep-time", | 327 | "sleep-time", |
328 | "graph-time", | 328 | "graph-time", |
329 | NULL | 329 | NULL |
330 | }; | 330 | }; |
331 | 331 | ||
332 | /* | 332 | static struct { |
333 | * ftrace_max_lock is used to protect the swapping of buffers | 333 | u64 (*func)(void); |
334 | * when taking a max snapshot. The buffers themselves are | 334 | const char *name; |
335 | * protected by per_cpu spinlocks. But the action of the swap | 335 | } trace_clocks[] = { |
336 | * needs its own lock. | 336 | { trace_clock_local, "local" }, |
337 | * | 337 | { trace_clock_global, "global" }, |
338 | * This is defined as a raw_spinlock_t in order to help | 338 | }; |
339 | * with performance when lockdep debugging is enabled. | ||
340 | */ | ||
341 | static raw_spinlock_t ftrace_max_lock = | ||
342 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | ||
343 | |||
344 | /* | ||
345 | * Copy the new maximum trace into the separate maximum-trace | ||
346 | * structure. (this way the maximum trace is permanently saved, | ||
347 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) | ||
348 | */ | ||
349 | static void | ||
350 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | ||
351 | { | ||
352 | struct trace_array_cpu *data = tr->data[cpu]; | ||
353 | |||
354 | max_tr.cpu = cpu; | ||
355 | max_tr.time_start = data->preempt_timestamp; | ||
356 | 339 | ||
357 | data = max_tr.data[cpu]; | 340 | int trace_clock_id; |
358 | data->saved_latency = tracing_max_latency; | ||
359 | |||
360 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | ||
361 | data->pid = tsk->pid; | ||
362 | data->uid = task_uid(tsk); | ||
363 | data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | ||
364 | data->policy = tsk->policy; | ||
365 | data->rt_priority = tsk->rt_priority; | ||
366 | |||
367 | /* record this tasks comm */ | ||
368 | tracing_record_cmdline(tsk); | ||
369 | } | ||
370 | 341 | ||
371 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) | 342 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
372 | { | 343 | { |
@@ -411,6 +382,56 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) | |||
411 | return cnt; | 382 | return cnt; |
412 | } | 383 | } |
413 | 384 | ||
385 | /* | ||
386 | * ftrace_max_lock is used to protect the swapping of buffers | ||
387 | * when taking a max snapshot. The buffers themselves are | ||
388 | * protected by per_cpu spinlocks. But the action of the swap | ||
389 | * needs its own lock. | ||
390 | * | ||
391 | * This is defined as a raw_spinlock_t in order to help | ||
392 | * with performance when lockdep debugging is enabled. | ||
393 | * | ||
394 | * It is also used in other places outside the update_max_tr | ||
395 | * so it needs to be defined outside of the | ||
396 | * CONFIG_TRACER_MAX_TRACE. | ||
397 | */ | ||
398 | static raw_spinlock_t ftrace_max_lock = | ||
399 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | ||
400 | |||
401 | #ifdef CONFIG_TRACER_MAX_TRACE | ||
402 | unsigned long __read_mostly tracing_max_latency; | ||
403 | unsigned long __read_mostly tracing_thresh; | ||
404 | |||
405 | /* | ||
406 | * Copy the new maximum trace into the separate maximum-trace | ||
407 | * structure. (this way the maximum trace is permanently saved, | ||
408 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) | ||
409 | */ | ||
410 | static void | ||
411 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | ||
412 | { | ||
413 | struct trace_array_cpu *data = tr->data[cpu]; | ||
414 | struct trace_array_cpu *max_data = tr->data[cpu]; | ||
415 | |||
416 | max_tr.cpu = cpu; | ||
417 | max_tr.time_start = data->preempt_timestamp; | ||
418 | |||
419 | max_data = max_tr.data[cpu]; | ||
420 | max_data->saved_latency = tracing_max_latency; | ||
421 | max_data->critical_start = data->critical_start; | ||
422 | max_data->critical_end = data->critical_end; | ||
423 | |||
424 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | ||
425 | max_data->pid = tsk->pid; | ||
426 | max_data->uid = task_uid(tsk); | ||
427 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | ||
428 | max_data->policy = tsk->policy; | ||
429 | max_data->rt_priority = tsk->rt_priority; | ||
430 | |||
431 | /* record this tasks comm */ | ||
432 | tracing_record_cmdline(tsk); | ||
433 | } | ||
434 | |||
414 | /** | 435 | /** |
415 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr | 436 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
416 | * @tr: tracer | 437 | * @tr: tracer |
@@ -425,16 +446,15 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
425 | { | 446 | { |
426 | struct ring_buffer *buf = tr->buffer; | 447 | struct ring_buffer *buf = tr->buffer; |
427 | 448 | ||
449 | if (trace_stop_count) | ||
450 | return; | ||
451 | |||
428 | WARN_ON_ONCE(!irqs_disabled()); | 452 | WARN_ON_ONCE(!irqs_disabled()); |
429 | __raw_spin_lock(&ftrace_max_lock); | 453 | __raw_spin_lock(&ftrace_max_lock); |
430 | 454 | ||
431 | tr->buffer = max_tr.buffer; | 455 | tr->buffer = max_tr.buffer; |
432 | max_tr.buffer = buf; | 456 | max_tr.buffer = buf; |
433 | 457 | ||
434 | ftrace_disable_cpu(); | ||
435 | ring_buffer_reset(tr->buffer); | ||
436 | ftrace_enable_cpu(); | ||
437 | |||
438 | __update_max_tr(tr, tsk, cpu); | 458 | __update_max_tr(tr, tsk, cpu); |
439 | __raw_spin_unlock(&ftrace_max_lock); | 459 | __raw_spin_unlock(&ftrace_max_lock); |
440 | } | 460 | } |
@@ -452,21 +472,35 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
452 | { | 472 | { |
453 | int ret; | 473 | int ret; |
454 | 474 | ||
475 | if (trace_stop_count) | ||
476 | return; | ||
477 | |||
455 | WARN_ON_ONCE(!irqs_disabled()); | 478 | WARN_ON_ONCE(!irqs_disabled()); |
456 | __raw_spin_lock(&ftrace_max_lock); | 479 | __raw_spin_lock(&ftrace_max_lock); |
457 | 480 | ||
458 | ftrace_disable_cpu(); | 481 | ftrace_disable_cpu(); |
459 | 482 | ||
460 | ring_buffer_reset(max_tr.buffer); | ||
461 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); | 483 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
462 | 484 | ||
485 | if (ret == -EBUSY) { | ||
486 | /* | ||
487 | * We failed to swap the buffer due to a commit taking | ||
488 | * place on this CPU. We fail to record, but we reset | ||
489 | * the max trace buffer (no one writes directly to it) | ||
490 | * and flag that it failed. | ||
491 | */ | ||
492 | trace_array_printk(&max_tr, _THIS_IP_, | ||
493 | "Failed to swap buffers due to commit in progress\n"); | ||
494 | } | ||
495 | |||
463 | ftrace_enable_cpu(); | 496 | ftrace_enable_cpu(); |
464 | 497 | ||
465 | WARN_ON_ONCE(ret && ret != -EAGAIN); | 498 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
466 | 499 | ||
467 | __update_max_tr(tr, tsk, cpu); | 500 | __update_max_tr(tr, tsk, cpu); |
468 | __raw_spin_unlock(&ftrace_max_lock); | 501 | __raw_spin_unlock(&ftrace_max_lock); |
469 | } | 502 | } |
503 | #endif /* CONFIG_TRACER_MAX_TRACE */ | ||
470 | 504 | ||
471 | /** | 505 | /** |
472 | * register_tracer - register a tracer with the ftrace system. | 506 | * register_tracer - register a tracer with the ftrace system. |
@@ -523,7 +557,6 @@ __acquires(kernel_lock) | |||
523 | if (type->selftest && !tracing_selftest_disabled) { | 557 | if (type->selftest && !tracing_selftest_disabled) { |
524 | struct tracer *saved_tracer = current_trace; | 558 | struct tracer *saved_tracer = current_trace; |
525 | struct trace_array *tr = &global_trace; | 559 | struct trace_array *tr = &global_trace; |
526 | int i; | ||
527 | 560 | ||
528 | /* | 561 | /* |
529 | * Run a selftest on this tracer. | 562 | * Run a selftest on this tracer. |
@@ -532,8 +565,7 @@ __acquires(kernel_lock) | |||
532 | * internal tracing to verify that everything is in order. | 565 | * internal tracing to verify that everything is in order. |
533 | * If we fail, we do not register this tracer. | 566 | * If we fail, we do not register this tracer. |
534 | */ | 567 | */ |
535 | for_each_tracing_cpu(i) | 568 | tracing_reset_online_cpus(tr); |
536 | tracing_reset(tr, i); | ||
537 | 569 | ||
538 | current_trace = type; | 570 | current_trace = type; |
539 | /* the test is responsible for initializing and enabling */ | 571 | /* the test is responsible for initializing and enabling */ |
@@ -546,8 +578,7 @@ __acquires(kernel_lock) | |||
546 | goto out; | 578 | goto out; |
547 | } | 579 | } |
548 | /* Only reset on passing, to avoid touching corrupted buffers */ | 580 | /* Only reset on passing, to avoid touching corrupted buffers */ |
549 | for_each_tracing_cpu(i) | 581 | tracing_reset_online_cpus(tr); |
550 | tracing_reset(tr, i); | ||
551 | 582 | ||
552 | printk(KERN_CONT "PASSED\n"); | 583 | printk(KERN_CONT "PASSED\n"); |
553 | } | 584 | } |
@@ -622,21 +653,42 @@ void unregister_tracer(struct tracer *type) | |||
622 | mutex_unlock(&trace_types_lock); | 653 | mutex_unlock(&trace_types_lock); |
623 | } | 654 | } |
624 | 655 | ||
625 | void tracing_reset(struct trace_array *tr, int cpu) | 656 | static void __tracing_reset(struct trace_array *tr, int cpu) |
626 | { | 657 | { |
627 | ftrace_disable_cpu(); | 658 | ftrace_disable_cpu(); |
628 | ring_buffer_reset_cpu(tr->buffer, cpu); | 659 | ring_buffer_reset_cpu(tr->buffer, cpu); |
629 | ftrace_enable_cpu(); | 660 | ftrace_enable_cpu(); |
630 | } | 661 | } |
631 | 662 | ||
663 | void tracing_reset(struct trace_array *tr, int cpu) | ||
664 | { | ||
665 | struct ring_buffer *buffer = tr->buffer; | ||
666 | |||
667 | ring_buffer_record_disable(buffer); | ||
668 | |||
669 | /* Make sure all commits have finished */ | ||
670 | synchronize_sched(); | ||
671 | __tracing_reset(tr, cpu); | ||
672 | |||
673 | ring_buffer_record_enable(buffer); | ||
674 | } | ||
675 | |||
632 | void tracing_reset_online_cpus(struct trace_array *tr) | 676 | void tracing_reset_online_cpus(struct trace_array *tr) |
633 | { | 677 | { |
678 | struct ring_buffer *buffer = tr->buffer; | ||
634 | int cpu; | 679 | int cpu; |
635 | 680 | ||
681 | ring_buffer_record_disable(buffer); | ||
682 | |||
683 | /* Make sure all commits have finished */ | ||
684 | synchronize_sched(); | ||
685 | |||
636 | tr->time_start = ftrace_now(tr->cpu); | 686 | tr->time_start = ftrace_now(tr->cpu); |
637 | 687 | ||
638 | for_each_online_cpu(cpu) | 688 | for_each_online_cpu(cpu) |
639 | tracing_reset(tr, cpu); | 689 | __tracing_reset(tr, cpu); |
690 | |||
691 | ring_buffer_record_enable(buffer); | ||
640 | } | 692 | } |
641 | 693 | ||
642 | void tracing_reset_current(int cpu) | 694 | void tracing_reset_current(int cpu) |
@@ -667,9 +719,6 @@ static void trace_init_cmdlines(void) | |||
667 | cmdline_idx = 0; | 719 | cmdline_idx = 0; |
668 | } | 720 | } |
669 | 721 | ||
670 | static int trace_stop_count; | ||
671 | static DEFINE_SPINLOCK(tracing_start_lock); | ||
672 | |||
673 | /** | 722 | /** |
674 | * ftrace_off_permanent - disable all ftrace code permanently | 723 | * ftrace_off_permanent - disable all ftrace code permanently |
675 | * | 724 | * |
@@ -850,14 +899,15 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, | |||
850 | } | 899 | } |
851 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); | 900 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
852 | 901 | ||
853 | struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | 902 | struct ring_buffer_event * |
854 | int type, | 903 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
855 | unsigned long len, | 904 | int type, |
856 | unsigned long flags, int pc) | 905 | unsigned long len, |
906 | unsigned long flags, int pc) | ||
857 | { | 907 | { |
858 | struct ring_buffer_event *event; | 908 | struct ring_buffer_event *event; |
859 | 909 | ||
860 | event = ring_buffer_lock_reserve(tr->buffer, len); | 910 | event = ring_buffer_lock_reserve(buffer, len); |
861 | if (event != NULL) { | 911 | if (event != NULL) { |
862 | struct trace_entry *ent = ring_buffer_event_data(event); | 912 | struct trace_entry *ent = ring_buffer_event_data(event); |
863 | 913 | ||
@@ -867,58 +917,60 @@ struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | |||
867 | 917 | ||
868 | return event; | 918 | return event; |
869 | } | 919 | } |
870 | static void ftrace_trace_stack(struct trace_array *tr, | ||
871 | unsigned long flags, int skip, int pc); | ||
872 | static void ftrace_trace_userstack(struct trace_array *tr, | ||
873 | unsigned long flags, int pc); | ||
874 | 920 | ||
875 | static inline void __trace_buffer_unlock_commit(struct trace_array *tr, | 921 | static inline void |
876 | struct ring_buffer_event *event, | 922 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
877 | unsigned long flags, int pc, | 923 | struct ring_buffer_event *event, |
878 | int wake) | 924 | unsigned long flags, int pc, |
925 | int wake) | ||
879 | { | 926 | { |
880 | ring_buffer_unlock_commit(tr->buffer, event); | 927 | ring_buffer_unlock_commit(buffer, event); |
881 | 928 | ||
882 | ftrace_trace_stack(tr, flags, 6, pc); | 929 | ftrace_trace_stack(buffer, flags, 6, pc); |
883 | ftrace_trace_userstack(tr, flags, pc); | 930 | ftrace_trace_userstack(buffer, flags, pc); |
884 | 931 | ||
885 | if (wake) | 932 | if (wake) |
886 | trace_wake_up(); | 933 | trace_wake_up(); |
887 | } | 934 | } |
888 | 935 | ||
889 | void trace_buffer_unlock_commit(struct trace_array *tr, | 936 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
890 | struct ring_buffer_event *event, | 937 | struct ring_buffer_event *event, |
891 | unsigned long flags, int pc) | 938 | unsigned long flags, int pc) |
892 | { | 939 | { |
893 | __trace_buffer_unlock_commit(tr, event, flags, pc, 1); | 940 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
894 | } | 941 | } |
895 | 942 | ||
896 | struct ring_buffer_event * | 943 | struct ring_buffer_event * |
897 | trace_current_buffer_lock_reserve(int type, unsigned long len, | 944 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
945 | int type, unsigned long len, | ||
898 | unsigned long flags, int pc) | 946 | unsigned long flags, int pc) |
899 | { | 947 | { |
900 | return trace_buffer_lock_reserve(&global_trace, | 948 | *current_rb = global_trace.buffer; |
949 | return trace_buffer_lock_reserve(*current_rb, | ||
901 | type, len, flags, pc); | 950 | type, len, flags, pc); |
902 | } | 951 | } |
903 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); | 952 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
904 | 953 | ||
905 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | 954 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
955 | struct ring_buffer_event *event, | ||
906 | unsigned long flags, int pc) | 956 | unsigned long flags, int pc) |
907 | { | 957 | { |
908 | __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 1); | 958 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
909 | } | 959 | } |
910 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); | 960 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
911 | 961 | ||
912 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, | 962 | void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer, |
913 | unsigned long flags, int pc) | 963 | struct ring_buffer_event *event, |
964 | unsigned long flags, int pc) | ||
914 | { | 965 | { |
915 | __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 0); | 966 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 0); |
916 | } | 967 | } |
917 | EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit); | 968 | EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit); |
918 | 969 | ||
919 | void trace_current_buffer_discard_commit(struct ring_buffer_event *event) | 970 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
971 | struct ring_buffer_event *event) | ||
920 | { | 972 | { |
921 | ring_buffer_discard_commit(global_trace.buffer, event); | 973 | ring_buffer_discard_commit(buffer, event); |
922 | } | 974 | } |
923 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); | 975 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
924 | 976 | ||
@@ -928,6 +980,7 @@ trace_function(struct trace_array *tr, | |||
928 | int pc) | 980 | int pc) |
929 | { | 981 | { |
930 | struct ftrace_event_call *call = &event_function; | 982 | struct ftrace_event_call *call = &event_function; |
983 | struct ring_buffer *buffer = tr->buffer; | ||
931 | struct ring_buffer_event *event; | 984 | struct ring_buffer_event *event; |
932 | struct ftrace_entry *entry; | 985 | struct ftrace_entry *entry; |
933 | 986 | ||
@@ -935,7 +988,7 @@ trace_function(struct trace_array *tr, | |||
935 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | 988 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
936 | return; | 989 | return; |
937 | 990 | ||
938 | event = trace_buffer_lock_reserve(tr, TRACE_FN, sizeof(*entry), | 991 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
939 | flags, pc); | 992 | flags, pc); |
940 | if (!event) | 993 | if (!event) |
941 | return; | 994 | return; |
@@ -943,58 +996,10 @@ trace_function(struct trace_array *tr, | |||
943 | entry->ip = ip; | 996 | entry->ip = ip; |
944 | entry->parent_ip = parent_ip; | 997 | entry->parent_ip = parent_ip; |
945 | 998 | ||
946 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 999 | if (!filter_check_discard(call, entry, buffer, event)) |
947 | ring_buffer_unlock_commit(tr->buffer, event); | 1000 | ring_buffer_unlock_commit(buffer, event); |
948 | } | ||
949 | |||
950 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
951 | static int __trace_graph_entry(struct trace_array *tr, | ||
952 | struct ftrace_graph_ent *trace, | ||
953 | unsigned long flags, | ||
954 | int pc) | ||
955 | { | ||
956 | struct ftrace_event_call *call = &event_funcgraph_entry; | ||
957 | struct ring_buffer_event *event; | ||
958 | struct ftrace_graph_ent_entry *entry; | ||
959 | |||
960 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
961 | return 0; | ||
962 | |||
963 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT, | ||
964 | sizeof(*entry), flags, pc); | ||
965 | if (!event) | ||
966 | return 0; | ||
967 | entry = ring_buffer_event_data(event); | ||
968 | entry->graph_ent = *trace; | ||
969 | if (!filter_current_check_discard(call, entry, event)) | ||
970 | ring_buffer_unlock_commit(global_trace.buffer, event); | ||
971 | |||
972 | return 1; | ||
973 | } | 1001 | } |
974 | 1002 | ||
975 | static void __trace_graph_return(struct trace_array *tr, | ||
976 | struct ftrace_graph_ret *trace, | ||
977 | unsigned long flags, | ||
978 | int pc) | ||
979 | { | ||
980 | struct ftrace_event_call *call = &event_funcgraph_exit; | ||
981 | struct ring_buffer_event *event; | ||
982 | struct ftrace_graph_ret_entry *entry; | ||
983 | |||
984 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
985 | return; | ||
986 | |||
987 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_RET, | ||
988 | sizeof(*entry), flags, pc); | ||
989 | if (!event) | ||
990 | return; | ||
991 | entry = ring_buffer_event_data(event); | ||
992 | entry->ret = *trace; | ||
993 | if (!filter_current_check_discard(call, entry, event)) | ||
994 | ring_buffer_unlock_commit(global_trace.buffer, event); | ||
995 | } | ||
996 | #endif | ||
997 | |||
998 | void | 1003 | void |
999 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, | 1004 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
1000 | unsigned long ip, unsigned long parent_ip, unsigned long flags, | 1005 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
@@ -1004,17 +1009,17 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data, | |||
1004 | trace_function(tr, ip, parent_ip, flags, pc); | 1009 | trace_function(tr, ip, parent_ip, flags, pc); |
1005 | } | 1010 | } |
1006 | 1011 | ||
1007 | static void __ftrace_trace_stack(struct trace_array *tr, | 1012 | #ifdef CONFIG_STACKTRACE |
1013 | static void __ftrace_trace_stack(struct ring_buffer *buffer, | ||
1008 | unsigned long flags, | 1014 | unsigned long flags, |
1009 | int skip, int pc) | 1015 | int skip, int pc) |
1010 | { | 1016 | { |
1011 | #ifdef CONFIG_STACKTRACE | ||
1012 | struct ftrace_event_call *call = &event_kernel_stack; | 1017 | struct ftrace_event_call *call = &event_kernel_stack; |
1013 | struct ring_buffer_event *event; | 1018 | struct ring_buffer_event *event; |
1014 | struct stack_entry *entry; | 1019 | struct stack_entry *entry; |
1015 | struct stack_trace trace; | 1020 | struct stack_trace trace; |
1016 | 1021 | ||
1017 | event = trace_buffer_lock_reserve(tr, TRACE_STACK, | 1022 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
1018 | sizeof(*entry), flags, pc); | 1023 | sizeof(*entry), flags, pc); |
1019 | if (!event) | 1024 | if (!event) |
1020 | return; | 1025 | return; |
@@ -1027,32 +1032,28 @@ static void __ftrace_trace_stack(struct trace_array *tr, | |||
1027 | trace.entries = entry->caller; | 1032 | trace.entries = entry->caller; |
1028 | 1033 | ||
1029 | save_stack_trace(&trace); | 1034 | save_stack_trace(&trace); |
1030 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1035 | if (!filter_check_discard(call, entry, buffer, event)) |
1031 | ring_buffer_unlock_commit(tr->buffer, event); | 1036 | ring_buffer_unlock_commit(buffer, event); |
1032 | #endif | ||
1033 | } | 1037 | } |
1034 | 1038 | ||
1035 | static void ftrace_trace_stack(struct trace_array *tr, | 1039 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
1036 | unsigned long flags, | 1040 | int skip, int pc) |
1037 | int skip, int pc) | ||
1038 | { | 1041 | { |
1039 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | 1042 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
1040 | return; | 1043 | return; |
1041 | 1044 | ||
1042 | __ftrace_trace_stack(tr, flags, skip, pc); | 1045 | __ftrace_trace_stack(buffer, flags, skip, pc); |
1043 | } | 1046 | } |
1044 | 1047 | ||
1045 | void __trace_stack(struct trace_array *tr, | 1048 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
1046 | unsigned long flags, | 1049 | int pc) |
1047 | int skip, int pc) | ||
1048 | { | 1050 | { |
1049 | __ftrace_trace_stack(tr, flags, skip, pc); | 1051 | __ftrace_trace_stack(tr->buffer, flags, skip, pc); |
1050 | } | 1052 | } |
1051 | 1053 | ||
1052 | static void ftrace_trace_userstack(struct trace_array *tr, | 1054 | void |
1053 | unsigned long flags, int pc) | 1055 | ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) |
1054 | { | 1056 | { |
1055 | #ifdef CONFIG_STACKTRACE | ||
1056 | struct ftrace_event_call *call = &event_user_stack; | 1057 | struct ftrace_event_call *call = &event_user_stack; |
1057 | struct ring_buffer_event *event; | 1058 | struct ring_buffer_event *event; |
1058 | struct userstack_entry *entry; | 1059 | struct userstack_entry *entry; |
@@ -1061,7 +1062,7 @@ static void ftrace_trace_userstack(struct trace_array *tr, | |||
1061 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) | 1062 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
1062 | return; | 1063 | return; |
1063 | 1064 | ||
1064 | event = trace_buffer_lock_reserve(tr, TRACE_USER_STACK, | 1065 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
1065 | sizeof(*entry), flags, pc); | 1066 | sizeof(*entry), flags, pc); |
1066 | if (!event) | 1067 | if (!event) |
1067 | return; | 1068 | return; |
@@ -1075,9 +1076,8 @@ static void ftrace_trace_userstack(struct trace_array *tr, | |||
1075 | trace.entries = entry->caller; | 1076 | trace.entries = entry->caller; |
1076 | 1077 | ||
1077 | save_stack_trace_user(&trace); | 1078 | save_stack_trace_user(&trace); |
1078 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1079 | if (!filter_check_discard(call, entry, buffer, event)) |
1079 | ring_buffer_unlock_commit(tr->buffer, event); | 1080 | ring_buffer_unlock_commit(buffer, event); |
1080 | #endif | ||
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | #ifdef UNUSED | 1083 | #ifdef UNUSED |
@@ -1087,6 +1087,8 @@ static void __trace_userstack(struct trace_array *tr, unsigned long flags) | |||
1087 | } | 1087 | } |
1088 | #endif /* UNUSED */ | 1088 | #endif /* UNUSED */ |
1089 | 1089 | ||
1090 | #endif /* CONFIG_STACKTRACE */ | ||
1091 | |||
1090 | static void | 1092 | static void |
1091 | ftrace_trace_special(void *__tr, | 1093 | ftrace_trace_special(void *__tr, |
1092 | unsigned long arg1, unsigned long arg2, unsigned long arg3, | 1094 | unsigned long arg1, unsigned long arg2, unsigned long arg3, |
@@ -1094,9 +1096,10 @@ ftrace_trace_special(void *__tr, | |||
1094 | { | 1096 | { |
1095 | struct ring_buffer_event *event; | 1097 | struct ring_buffer_event *event; |
1096 | struct trace_array *tr = __tr; | 1098 | struct trace_array *tr = __tr; |
1099 | struct ring_buffer *buffer = tr->buffer; | ||
1097 | struct special_entry *entry; | 1100 | struct special_entry *entry; |
1098 | 1101 | ||
1099 | event = trace_buffer_lock_reserve(tr, TRACE_SPECIAL, | 1102 | event = trace_buffer_lock_reserve(buffer, TRACE_SPECIAL, |
1100 | sizeof(*entry), 0, pc); | 1103 | sizeof(*entry), 0, pc); |
1101 | if (!event) | 1104 | if (!event) |
1102 | return; | 1105 | return; |
@@ -1104,7 +1107,7 @@ ftrace_trace_special(void *__tr, | |||
1104 | entry->arg1 = arg1; | 1107 | entry->arg1 = arg1; |
1105 | entry->arg2 = arg2; | 1108 | entry->arg2 = arg2; |
1106 | entry->arg3 = arg3; | 1109 | entry->arg3 = arg3; |
1107 | trace_buffer_unlock_commit(tr, event, 0, pc); | 1110 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
1108 | } | 1111 | } |
1109 | 1112 | ||
1110 | void | 1113 | void |
@@ -1115,62 +1118,6 @@ __trace_special(void *__tr, void *__data, | |||
1115 | } | 1118 | } |
1116 | 1119 | ||
1117 | void | 1120 | void |
1118 | tracing_sched_switch_trace(struct trace_array *tr, | ||
1119 | struct task_struct *prev, | ||
1120 | struct task_struct *next, | ||
1121 | unsigned long flags, int pc) | ||
1122 | { | ||
1123 | struct ftrace_event_call *call = &event_context_switch; | ||
1124 | struct ring_buffer_event *event; | ||
1125 | struct ctx_switch_entry *entry; | ||
1126 | |||
1127 | event = trace_buffer_lock_reserve(tr, TRACE_CTX, | ||
1128 | sizeof(*entry), flags, pc); | ||
1129 | if (!event) | ||
1130 | return; | ||
1131 | entry = ring_buffer_event_data(event); | ||
1132 | entry->prev_pid = prev->pid; | ||
1133 | entry->prev_prio = prev->prio; | ||
1134 | entry->prev_state = prev->state; | ||
1135 | entry->next_pid = next->pid; | ||
1136 | entry->next_prio = next->prio; | ||
1137 | entry->next_state = next->state; | ||
1138 | entry->next_cpu = task_cpu(next); | ||
1139 | |||
1140 | if (!filter_check_discard(call, entry, tr->buffer, event)) | ||
1141 | trace_buffer_unlock_commit(tr, event, flags, pc); | ||
1142 | } | ||
1143 | |||
1144 | void | ||
1145 | tracing_sched_wakeup_trace(struct trace_array *tr, | ||
1146 | struct task_struct *wakee, | ||
1147 | struct task_struct *curr, | ||
1148 | unsigned long flags, int pc) | ||
1149 | { | ||
1150 | struct ftrace_event_call *call = &event_wakeup; | ||
1151 | struct ring_buffer_event *event; | ||
1152 | struct ctx_switch_entry *entry; | ||
1153 | |||
1154 | event = trace_buffer_lock_reserve(tr, TRACE_WAKE, | ||
1155 | sizeof(*entry), flags, pc); | ||
1156 | if (!event) | ||
1157 | return; | ||
1158 | entry = ring_buffer_event_data(event); | ||
1159 | entry->prev_pid = curr->pid; | ||
1160 | entry->prev_prio = curr->prio; | ||
1161 | entry->prev_state = curr->state; | ||
1162 | entry->next_pid = wakee->pid; | ||
1163 | entry->next_prio = wakee->prio; | ||
1164 | entry->next_state = wakee->state; | ||
1165 | entry->next_cpu = task_cpu(wakee); | ||
1166 | |||
1167 | if (!filter_check_discard(call, entry, tr->buffer, event)) | ||
1168 | ring_buffer_unlock_commit(tr->buffer, event); | ||
1169 | ftrace_trace_stack(tr, flags, 6, pc); | ||
1170 | ftrace_trace_userstack(tr, flags, pc); | ||
1171 | } | ||
1172 | |||
1173 | void | ||
1174 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | 1121 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) |
1175 | { | 1122 | { |
1176 | struct trace_array *tr = &global_trace; | 1123 | struct trace_array *tr = &global_trace; |
@@ -1194,68 +1141,6 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | |||
1194 | local_irq_restore(flags); | 1141 | local_irq_restore(flags); |
1195 | } | 1142 | } |
1196 | 1143 | ||
1197 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
1198 | int trace_graph_entry(struct ftrace_graph_ent *trace) | ||
1199 | { | ||
1200 | struct trace_array *tr = &global_trace; | ||
1201 | struct trace_array_cpu *data; | ||
1202 | unsigned long flags; | ||
1203 | long disabled; | ||
1204 | int ret; | ||
1205 | int cpu; | ||
1206 | int pc; | ||
1207 | |||
1208 | if (!ftrace_trace_task(current)) | ||
1209 | return 0; | ||
1210 | |||
1211 | if (!ftrace_graph_addr(trace->func)) | ||
1212 | return 0; | ||
1213 | |||
1214 | local_irq_save(flags); | ||
1215 | cpu = raw_smp_processor_id(); | ||
1216 | data = tr->data[cpu]; | ||
1217 | disabled = atomic_inc_return(&data->disabled); | ||
1218 | if (likely(disabled == 1)) { | ||
1219 | pc = preempt_count(); | ||
1220 | ret = __trace_graph_entry(tr, trace, flags, pc); | ||
1221 | } else { | ||
1222 | ret = 0; | ||
1223 | } | ||
1224 | /* Only do the atomic if it is not already set */ | ||
1225 | if (!test_tsk_trace_graph(current)) | ||
1226 | set_tsk_trace_graph(current); | ||
1227 | |||
1228 | atomic_dec(&data->disabled); | ||
1229 | local_irq_restore(flags); | ||
1230 | |||
1231 | return ret; | ||
1232 | } | ||
1233 | |||
1234 | void trace_graph_return(struct ftrace_graph_ret *trace) | ||
1235 | { | ||
1236 | struct trace_array *tr = &global_trace; | ||
1237 | struct trace_array_cpu *data; | ||
1238 | unsigned long flags; | ||
1239 | long disabled; | ||
1240 | int cpu; | ||
1241 | int pc; | ||
1242 | |||
1243 | local_irq_save(flags); | ||
1244 | cpu = raw_smp_processor_id(); | ||
1245 | data = tr->data[cpu]; | ||
1246 | disabled = atomic_inc_return(&data->disabled); | ||
1247 | if (likely(disabled == 1)) { | ||
1248 | pc = preempt_count(); | ||
1249 | __trace_graph_return(tr, trace, flags, pc); | ||
1250 | } | ||
1251 | if (!trace->depth) | ||
1252 | clear_tsk_trace_graph(current); | ||
1253 | atomic_dec(&data->disabled); | ||
1254 | local_irq_restore(flags); | ||
1255 | } | ||
1256 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
1257 | |||
1258 | |||
1259 | /** | 1144 | /** |
1260 | * trace_vbprintk - write binary msg to tracing buffer | 1145 | * trace_vbprintk - write binary msg to tracing buffer |
1261 | * | 1146 | * |
@@ -1268,6 +1153,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
1268 | 1153 | ||
1269 | struct ftrace_event_call *call = &event_bprint; | 1154 | struct ftrace_event_call *call = &event_bprint; |
1270 | struct ring_buffer_event *event; | 1155 | struct ring_buffer_event *event; |
1156 | struct ring_buffer *buffer; | ||
1271 | struct trace_array *tr = &global_trace; | 1157 | struct trace_array *tr = &global_trace; |
1272 | struct trace_array_cpu *data; | 1158 | struct trace_array_cpu *data; |
1273 | struct bprint_entry *entry; | 1159 | struct bprint_entry *entry; |
@@ -1300,7 +1186,9 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
1300 | goto out_unlock; | 1186 | goto out_unlock; |
1301 | 1187 | ||
1302 | size = sizeof(*entry) + sizeof(u32) * len; | 1188 | size = sizeof(*entry) + sizeof(u32) * len; |
1303 | event = trace_buffer_lock_reserve(tr, TRACE_BPRINT, size, flags, pc); | 1189 | buffer = tr->buffer; |
1190 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, | ||
1191 | flags, pc); | ||
1304 | if (!event) | 1192 | if (!event) |
1305 | goto out_unlock; | 1193 | goto out_unlock; |
1306 | entry = ring_buffer_event_data(event); | 1194 | entry = ring_buffer_event_data(event); |
@@ -1308,8 +1196,8 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
1308 | entry->fmt = fmt; | 1196 | entry->fmt = fmt; |
1309 | 1197 | ||
1310 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); | 1198 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); |
1311 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1199 | if (!filter_check_discard(call, entry, buffer, event)) |
1312 | ring_buffer_unlock_commit(tr->buffer, event); | 1200 | ring_buffer_unlock_commit(buffer, event); |
1313 | 1201 | ||
1314 | out_unlock: | 1202 | out_unlock: |
1315 | __raw_spin_unlock(&trace_buf_lock); | 1203 | __raw_spin_unlock(&trace_buf_lock); |
@@ -1324,14 +1212,30 @@ out: | |||
1324 | } | 1212 | } |
1325 | EXPORT_SYMBOL_GPL(trace_vbprintk); | 1213 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
1326 | 1214 | ||
1327 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | 1215 | int trace_array_printk(struct trace_array *tr, |
1216 | unsigned long ip, const char *fmt, ...) | ||
1217 | { | ||
1218 | int ret; | ||
1219 | va_list ap; | ||
1220 | |||
1221 | if (!(trace_flags & TRACE_ITER_PRINTK)) | ||
1222 | return 0; | ||
1223 | |||
1224 | va_start(ap, fmt); | ||
1225 | ret = trace_array_vprintk(tr, ip, fmt, ap); | ||
1226 | va_end(ap); | ||
1227 | return ret; | ||
1228 | } | ||
1229 | |||
1230 | int trace_array_vprintk(struct trace_array *tr, | ||
1231 | unsigned long ip, const char *fmt, va_list args) | ||
1328 | { | 1232 | { |
1329 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; | 1233 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; |
1330 | static char trace_buf[TRACE_BUF_SIZE]; | 1234 | static char trace_buf[TRACE_BUF_SIZE]; |
1331 | 1235 | ||
1332 | struct ftrace_event_call *call = &event_print; | 1236 | struct ftrace_event_call *call = &event_print; |
1333 | struct ring_buffer_event *event; | 1237 | struct ring_buffer_event *event; |
1334 | struct trace_array *tr = &global_trace; | 1238 | struct ring_buffer *buffer; |
1335 | struct trace_array_cpu *data; | 1239 | struct trace_array_cpu *data; |
1336 | int cpu, len = 0, size, pc; | 1240 | int cpu, len = 0, size, pc; |
1337 | struct print_entry *entry; | 1241 | struct print_entry *entry; |
@@ -1359,7 +1263,9 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
1359 | trace_buf[len] = 0; | 1263 | trace_buf[len] = 0; |
1360 | 1264 | ||
1361 | size = sizeof(*entry) + len + 1; | 1265 | size = sizeof(*entry) + len + 1; |
1362 | event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, irq_flags, pc); | 1266 | buffer = tr->buffer; |
1267 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, | ||
1268 | irq_flags, pc); | ||
1363 | if (!event) | 1269 | if (!event) |
1364 | goto out_unlock; | 1270 | goto out_unlock; |
1365 | entry = ring_buffer_event_data(event); | 1271 | entry = ring_buffer_event_data(event); |
@@ -1367,8 +1273,8 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
1367 | 1273 | ||
1368 | memcpy(&entry->buf, trace_buf, len); | 1274 | memcpy(&entry->buf, trace_buf, len); |
1369 | entry->buf[len] = 0; | 1275 | entry->buf[len] = 0; |
1370 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1276 | if (!filter_check_discard(call, entry, buffer, event)) |
1371 | ring_buffer_unlock_commit(tr->buffer, event); | 1277 | ring_buffer_unlock_commit(buffer, event); |
1372 | 1278 | ||
1373 | out_unlock: | 1279 | out_unlock: |
1374 | __raw_spin_unlock(&trace_buf_lock); | 1280 | __raw_spin_unlock(&trace_buf_lock); |
@@ -1380,6 +1286,11 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
1380 | 1286 | ||
1381 | return len; | 1287 | return len; |
1382 | } | 1288 | } |
1289 | |||
1290 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | ||
1291 | { | ||
1292 | return trace_array_printk(&global_trace, ip, fmt, args); | ||
1293 | } | ||
1383 | EXPORT_SYMBOL_GPL(trace_vprintk); | 1294 | EXPORT_SYMBOL_GPL(trace_vprintk); |
1384 | 1295 | ||
1385 | enum trace_file_type { | 1296 | enum trace_file_type { |
@@ -1519,6 +1430,37 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos) | |||
1519 | return ent; | 1430 | return ent; |
1520 | } | 1431 | } |
1521 | 1432 | ||
1433 | static void tracing_iter_reset(struct trace_iterator *iter, int cpu) | ||
1434 | { | ||
1435 | struct trace_array *tr = iter->tr; | ||
1436 | struct ring_buffer_event *event; | ||
1437 | struct ring_buffer_iter *buf_iter; | ||
1438 | unsigned long entries = 0; | ||
1439 | u64 ts; | ||
1440 | |||
1441 | tr->data[cpu]->skipped_entries = 0; | ||
1442 | |||
1443 | if (!iter->buffer_iter[cpu]) | ||
1444 | return; | ||
1445 | |||
1446 | buf_iter = iter->buffer_iter[cpu]; | ||
1447 | ring_buffer_iter_reset(buf_iter); | ||
1448 | |||
1449 | /* | ||
1450 | * We could have the case with the max latency tracers | ||
1451 | * that a reset never took place on a cpu. This is evident | ||
1452 | * by the timestamp being before the start of the buffer. | ||
1453 | */ | ||
1454 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { | ||
1455 | if (ts >= iter->tr->time_start) | ||
1456 | break; | ||
1457 | entries++; | ||
1458 | ring_buffer_read(buf_iter, NULL); | ||
1459 | } | ||
1460 | |||
1461 | tr->data[cpu]->skipped_entries = entries; | ||
1462 | } | ||
1463 | |||
1522 | /* | 1464 | /* |
1523 | * No necessary locking here. The worst thing which can | 1465 | * No necessary locking here. The worst thing which can |
1524 | * happen is loosing events consumed at the same time | 1466 | * happen is loosing events consumed at the same time |
@@ -1557,10 +1499,9 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
1557 | 1499 | ||
1558 | if (cpu_file == TRACE_PIPE_ALL_CPU) { | 1500 | if (cpu_file == TRACE_PIPE_ALL_CPU) { |
1559 | for_each_tracing_cpu(cpu) | 1501 | for_each_tracing_cpu(cpu) |
1560 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); | 1502 | tracing_iter_reset(iter, cpu); |
1561 | } else | 1503 | } else |
1562 | ring_buffer_iter_reset(iter->buffer_iter[cpu_file]); | 1504 | tracing_iter_reset(iter, cpu_file); |
1563 | |||
1564 | 1505 | ||
1565 | ftrace_enable_cpu(); | 1506 | ftrace_enable_cpu(); |
1566 | 1507 | ||
@@ -1609,16 +1550,32 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) | |||
1609 | struct trace_array *tr = iter->tr; | 1550 | struct trace_array *tr = iter->tr; |
1610 | struct trace_array_cpu *data = tr->data[tr->cpu]; | 1551 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
1611 | struct tracer *type = current_trace; | 1552 | struct tracer *type = current_trace; |
1612 | unsigned long total; | 1553 | unsigned long entries = 0; |
1613 | unsigned long entries; | 1554 | unsigned long total = 0; |
1555 | unsigned long count; | ||
1614 | const char *name = "preemption"; | 1556 | const char *name = "preemption"; |
1557 | int cpu; | ||
1615 | 1558 | ||
1616 | if (type) | 1559 | if (type) |
1617 | name = type->name; | 1560 | name = type->name; |
1618 | 1561 | ||
1619 | entries = ring_buffer_entries(iter->tr->buffer); | 1562 | |
1620 | total = entries + | 1563 | for_each_tracing_cpu(cpu) { |
1621 | ring_buffer_overruns(iter->tr->buffer); | 1564 | count = ring_buffer_entries_cpu(tr->buffer, cpu); |
1565 | /* | ||
1566 | * If this buffer has skipped entries, then we hold all | ||
1567 | * entries for the trace and we need to ignore the | ||
1568 | * ones before the time stamp. | ||
1569 | */ | ||
1570 | if (tr->data[cpu]->skipped_entries) { | ||
1571 | count -= tr->data[cpu]->skipped_entries; | ||
1572 | /* total is the same as the entries */ | ||
1573 | total += count; | ||
1574 | } else | ||
1575 | total += count + | ||
1576 | ring_buffer_overrun_cpu(tr->buffer, cpu); | ||
1577 | entries += count; | ||
1578 | } | ||
1622 | 1579 | ||
1623 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", | 1580 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
1624 | name, UTS_RELEASE); | 1581 | name, UTS_RELEASE); |
@@ -1660,7 +1617,7 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) | |||
1660 | seq_puts(m, "\n# => ended at: "); | 1617 | seq_puts(m, "\n# => ended at: "); |
1661 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); | 1618 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
1662 | trace_print_seq(m, &iter->seq); | 1619 | trace_print_seq(m, &iter->seq); |
1663 | seq_puts(m, "#\n"); | 1620 | seq_puts(m, "\n#\n"); |
1664 | } | 1621 | } |
1665 | 1622 | ||
1666 | seq_puts(m, "#\n"); | 1623 | seq_puts(m, "#\n"); |
@@ -1679,6 +1636,9 @@ static void test_cpu_buff_start(struct trace_iterator *iter) | |||
1679 | if (cpumask_test_cpu(iter->cpu, iter->started)) | 1636 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
1680 | return; | 1637 | return; |
1681 | 1638 | ||
1639 | if (iter->tr->data[iter->cpu]->skipped_entries) | ||
1640 | return; | ||
1641 | |||
1682 | cpumask_set_cpu(iter->cpu, iter->started); | 1642 | cpumask_set_cpu(iter->cpu, iter->started); |
1683 | 1643 | ||
1684 | /* Don't print started cpu buffer for the first entry of the trace */ | 1644 | /* Don't print started cpu buffer for the first entry of the trace */ |
@@ -1941,19 +1901,23 @@ __tracing_open(struct inode *inode, struct file *file) | |||
1941 | if (ring_buffer_overruns(iter->tr->buffer)) | 1901 | if (ring_buffer_overruns(iter->tr->buffer)) |
1942 | iter->iter_flags |= TRACE_FILE_ANNOTATE; | 1902 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
1943 | 1903 | ||
1904 | /* stop the trace while dumping */ | ||
1905 | tracing_stop(); | ||
1906 | |||
1944 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { | 1907 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
1945 | for_each_tracing_cpu(cpu) { | 1908 | for_each_tracing_cpu(cpu) { |
1946 | 1909 | ||
1947 | iter->buffer_iter[cpu] = | 1910 | iter->buffer_iter[cpu] = |
1948 | ring_buffer_read_start(iter->tr->buffer, cpu); | 1911 | ring_buffer_read_start(iter->tr->buffer, cpu); |
1912 | tracing_iter_reset(iter, cpu); | ||
1949 | } | 1913 | } |
1950 | } else { | 1914 | } else { |
1951 | cpu = iter->cpu_file; | 1915 | cpu = iter->cpu_file; |
1952 | iter->buffer_iter[cpu] = | 1916 | iter->buffer_iter[cpu] = |
1953 | ring_buffer_read_start(iter->tr->buffer, cpu); | 1917 | ring_buffer_read_start(iter->tr->buffer, cpu); |
1918 | tracing_iter_reset(iter, cpu); | ||
1954 | } | 1919 | } |
1955 | 1920 | ||
1956 | /* TODO stop tracer */ | ||
1957 | ret = seq_open(file, &tracer_seq_ops); | 1921 | ret = seq_open(file, &tracer_seq_ops); |
1958 | if (ret < 0) { | 1922 | if (ret < 0) { |
1959 | fail_ret = ERR_PTR(ret); | 1923 | fail_ret = ERR_PTR(ret); |
@@ -1963,9 +1927,6 @@ __tracing_open(struct inode *inode, struct file *file) | |||
1963 | m = file->private_data; | 1927 | m = file->private_data; |
1964 | m->private = iter; | 1928 | m->private = iter; |
1965 | 1929 | ||
1966 | /* stop the trace while dumping */ | ||
1967 | tracing_stop(); | ||
1968 | |||
1969 | mutex_unlock(&trace_types_lock); | 1930 | mutex_unlock(&trace_types_lock); |
1970 | 1931 | ||
1971 | return iter; | 1932 | return iter; |
@@ -1976,6 +1937,7 @@ __tracing_open(struct inode *inode, struct file *file) | |||
1976 | ring_buffer_read_finish(iter->buffer_iter[cpu]); | 1937 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
1977 | } | 1938 | } |
1978 | free_cpumask_var(iter->started); | 1939 | free_cpumask_var(iter->started); |
1940 | tracing_start(); | ||
1979 | fail: | 1941 | fail: |
1980 | mutex_unlock(&trace_types_lock); | 1942 | mutex_unlock(&trace_types_lock); |
1981 | kfree(iter->trace); | 1943 | kfree(iter->trace); |
@@ -2257,8 +2219,8 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
2257 | len += 3; /* "no" and newline */ | 2219 | len += 3; /* "no" and newline */ |
2258 | } | 2220 | } |
2259 | 2221 | ||
2260 | /* +2 for \n and \0 */ | 2222 | /* +1 for \0 */ |
2261 | buf = kmalloc(len + 2, GFP_KERNEL); | 2223 | buf = kmalloc(len + 1, GFP_KERNEL); |
2262 | if (!buf) { | 2224 | if (!buf) { |
2263 | mutex_unlock(&trace_types_lock); | 2225 | mutex_unlock(&trace_types_lock); |
2264 | return -ENOMEM; | 2226 | return -ENOMEM; |
@@ -2281,7 +2243,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
2281 | } | 2243 | } |
2282 | mutex_unlock(&trace_types_lock); | 2244 | mutex_unlock(&trace_types_lock); |
2283 | 2245 | ||
2284 | WARN_ON(r >= len + 2); | 2246 | WARN_ON(r >= len + 1); |
2285 | 2247 | ||
2286 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | 2248 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
2287 | 2249 | ||
@@ -2292,23 +2254,23 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
2292 | /* Try to assign a tracer specific option */ | 2254 | /* Try to assign a tracer specific option */ |
2293 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | 2255 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
2294 | { | 2256 | { |
2295 | struct tracer_flags *trace_flags = trace->flags; | 2257 | struct tracer_flags *tracer_flags = trace->flags; |
2296 | struct tracer_opt *opts = NULL; | 2258 | struct tracer_opt *opts = NULL; |
2297 | int ret = 0, i = 0; | 2259 | int ret = 0, i = 0; |
2298 | int len; | 2260 | int len; |
2299 | 2261 | ||
2300 | for (i = 0; trace_flags->opts[i].name; i++) { | 2262 | for (i = 0; tracer_flags->opts[i].name; i++) { |
2301 | opts = &trace_flags->opts[i]; | 2263 | opts = &tracer_flags->opts[i]; |
2302 | len = strlen(opts->name); | 2264 | len = strlen(opts->name); |
2303 | 2265 | ||
2304 | if (strncmp(cmp, opts->name, len) == 0) { | 2266 | if (strncmp(cmp, opts->name, len) == 0) { |
2305 | ret = trace->set_flag(trace_flags->val, | 2267 | ret = trace->set_flag(tracer_flags->val, |
2306 | opts->bit, !neg); | 2268 | opts->bit, !neg); |
2307 | break; | 2269 | break; |
2308 | } | 2270 | } |
2309 | } | 2271 | } |
2310 | /* Not found */ | 2272 | /* Not found */ |
2311 | if (!trace_flags->opts[i].name) | 2273 | if (!tracer_flags->opts[i].name) |
2312 | return -EINVAL; | 2274 | return -EINVAL; |
2313 | 2275 | ||
2314 | /* Refused to handle */ | 2276 | /* Refused to handle */ |
@@ -2316,9 +2278,9 @@ static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | |||
2316 | return ret; | 2278 | return ret; |
2317 | 2279 | ||
2318 | if (neg) | 2280 | if (neg) |
2319 | trace_flags->val &= ~opts->bit; | 2281 | tracer_flags->val &= ~opts->bit; |
2320 | else | 2282 | else |
2321 | trace_flags->val |= opts->bit; | 2283 | tracer_flags->val |= opts->bit; |
2322 | 2284 | ||
2323 | return 0; | 2285 | return 0; |
2324 | } | 2286 | } |
@@ -2333,22 +2295,6 @@ static void set_tracer_flags(unsigned int mask, int enabled) | |||
2333 | trace_flags |= mask; | 2295 | trace_flags |= mask; |
2334 | else | 2296 | else |
2335 | trace_flags &= ~mask; | 2297 | trace_flags &= ~mask; |
2336 | |||
2337 | if (mask == TRACE_ITER_GLOBAL_CLK) { | ||
2338 | u64 (*func)(void); | ||
2339 | |||
2340 | if (enabled) | ||
2341 | func = trace_clock_global; | ||
2342 | else | ||
2343 | func = trace_clock_local; | ||
2344 | |||
2345 | mutex_lock(&trace_types_lock); | ||
2346 | ring_buffer_set_clock(global_trace.buffer, func); | ||
2347 | |||
2348 | if (max_tr.buffer) | ||
2349 | ring_buffer_set_clock(max_tr.buffer, func); | ||
2350 | mutex_unlock(&trace_types_lock); | ||
2351 | } | ||
2352 | } | 2298 | } |
2353 | 2299 | ||
2354 | static ssize_t | 2300 | static ssize_t |
@@ -3316,6 +3262,62 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, | |||
3316 | return cnt; | 3262 | return cnt; |
3317 | } | 3263 | } |
3318 | 3264 | ||
3265 | static ssize_t tracing_clock_read(struct file *filp, char __user *ubuf, | ||
3266 | size_t cnt, loff_t *ppos) | ||
3267 | { | ||
3268 | char buf[64]; | ||
3269 | int bufiter = 0; | ||
3270 | int i; | ||
3271 | |||
3272 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) | ||
3273 | bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter, | ||
3274 | "%s%s%s%s", i ? " " : "", | ||
3275 | i == trace_clock_id ? "[" : "", trace_clocks[i].name, | ||
3276 | i == trace_clock_id ? "]" : ""); | ||
3277 | bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter, "\n"); | ||
3278 | |||
3279 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, bufiter); | ||
3280 | } | ||
3281 | |||
3282 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, | ||
3283 | size_t cnt, loff_t *fpos) | ||
3284 | { | ||
3285 | char buf[64]; | ||
3286 | const char *clockstr; | ||
3287 | int i; | ||
3288 | |||
3289 | if (cnt >= sizeof(buf)) | ||
3290 | return -EINVAL; | ||
3291 | |||
3292 | if (copy_from_user(&buf, ubuf, cnt)) | ||
3293 | return -EFAULT; | ||
3294 | |||
3295 | buf[cnt] = 0; | ||
3296 | |||
3297 | clockstr = strstrip(buf); | ||
3298 | |||
3299 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { | ||
3300 | if (strcmp(trace_clocks[i].name, clockstr) == 0) | ||
3301 | break; | ||
3302 | } | ||
3303 | if (i == ARRAY_SIZE(trace_clocks)) | ||
3304 | return -EINVAL; | ||
3305 | |||
3306 | trace_clock_id = i; | ||
3307 | |||
3308 | mutex_lock(&trace_types_lock); | ||
3309 | |||
3310 | ring_buffer_set_clock(global_trace.buffer, trace_clocks[i].func); | ||
3311 | if (max_tr.buffer) | ||
3312 | ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func); | ||
3313 | |||
3314 | mutex_unlock(&trace_types_lock); | ||
3315 | |||
3316 | *fpos += cnt; | ||
3317 | |||
3318 | return cnt; | ||
3319 | } | ||
3320 | |||
3319 | static const struct file_operations tracing_max_lat_fops = { | 3321 | static const struct file_operations tracing_max_lat_fops = { |
3320 | .open = tracing_open_generic, | 3322 | .open = tracing_open_generic, |
3321 | .read = tracing_max_lat_read, | 3323 | .read = tracing_max_lat_read, |
@@ -3353,6 +3355,12 @@ static const struct file_operations tracing_mark_fops = { | |||
3353 | .write = tracing_mark_write, | 3355 | .write = tracing_mark_write, |
3354 | }; | 3356 | }; |
3355 | 3357 | ||
3358 | static const struct file_operations trace_clock_fops = { | ||
3359 | .open = tracing_open_generic, | ||
3360 | .read = tracing_clock_read, | ||
3361 | .write = tracing_clock_write, | ||
3362 | }; | ||
3363 | |||
3356 | struct ftrace_buffer_info { | 3364 | struct ftrace_buffer_info { |
3357 | struct trace_array *tr; | 3365 | struct trace_array *tr; |
3358 | void *spare; | 3366 | void *spare; |
@@ -3633,9 +3641,6 @@ tracing_stats_read(struct file *filp, char __user *ubuf, | |||
3633 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); | 3641 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); |
3634 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); | 3642 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
3635 | 3643 | ||
3636 | cnt = ring_buffer_nmi_dropped_cpu(tr->buffer, cpu); | ||
3637 | trace_seq_printf(s, "nmi dropped: %ld\n", cnt); | ||
3638 | |||
3639 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); | 3644 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
3640 | 3645 | ||
3641 | kfree(s); | 3646 | kfree(s); |
@@ -4066,11 +4071,13 @@ static __init int tracer_init_debugfs(void) | |||
4066 | trace_create_file("current_tracer", 0644, d_tracer, | 4071 | trace_create_file("current_tracer", 0644, d_tracer, |
4067 | &global_trace, &set_tracer_fops); | 4072 | &global_trace, &set_tracer_fops); |
4068 | 4073 | ||
4074 | #ifdef CONFIG_TRACER_MAX_TRACE | ||
4069 | trace_create_file("tracing_max_latency", 0644, d_tracer, | 4075 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
4070 | &tracing_max_latency, &tracing_max_lat_fops); | 4076 | &tracing_max_latency, &tracing_max_lat_fops); |
4071 | 4077 | ||
4072 | trace_create_file("tracing_thresh", 0644, d_tracer, | 4078 | trace_create_file("tracing_thresh", 0644, d_tracer, |
4073 | &tracing_thresh, &tracing_max_lat_fops); | 4079 | &tracing_thresh, &tracing_max_lat_fops); |
4080 | #endif | ||
4074 | 4081 | ||
4075 | trace_create_file("README", 0444, d_tracer, | 4082 | trace_create_file("README", 0444, d_tracer, |
4076 | NULL, &tracing_readme_fops); | 4083 | NULL, &tracing_readme_fops); |
@@ -4087,6 +4094,9 @@ static __init int tracer_init_debugfs(void) | |||
4087 | trace_create_file("saved_cmdlines", 0444, d_tracer, | 4094 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
4088 | NULL, &tracing_saved_cmdlines_fops); | 4095 | NULL, &tracing_saved_cmdlines_fops); |
4089 | 4096 | ||
4097 | trace_create_file("trace_clock", 0644, d_tracer, NULL, | ||
4098 | &trace_clock_fops); | ||
4099 | |||
4090 | #ifdef CONFIG_DYNAMIC_FTRACE | 4100 | #ifdef CONFIG_DYNAMIC_FTRACE |
4091 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, | 4101 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
4092 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); | 4102 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
@@ -4265,7 +4275,6 @@ void ftrace_dump(void) | |||
4265 | 4275 | ||
4266 | __init static int tracer_alloc_buffers(void) | 4276 | __init static int tracer_alloc_buffers(void) |
4267 | { | 4277 | { |
4268 | struct trace_array_cpu *data; | ||
4269 | int ring_buf_size; | 4278 | int ring_buf_size; |
4270 | int i; | 4279 | int i; |
4271 | int ret = -ENOMEM; | 4280 | int ret = -ENOMEM; |
@@ -4315,7 +4324,7 @@ __init static int tracer_alloc_buffers(void) | |||
4315 | 4324 | ||
4316 | /* Allocate the first page for all buffers */ | 4325 | /* Allocate the first page for all buffers */ |
4317 | for_each_tracing_cpu(i) { | 4326 | for_each_tracing_cpu(i) { |
4318 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); | 4327 | global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
4319 | max_tr.data[i] = &per_cpu(max_data, i); | 4328 | max_tr.data[i] = &per_cpu(max_data, i); |
4320 | } | 4329 | } |
4321 | 4330 | ||