aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-08-06 12:30:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-06 12:30:52 -0400
commit4aed2fd8e3181fea7c09ba79cf64e7e3f4413bf9 (patch)
tree1f69733e5daab4915a76a41de0e4d1dc61e12cfb /kernel/trace/trace.c
parent3a3527b6461b1298cc53ce72f336346739297ac8 (diff)
parentfc9ea5a1e53ee54f681e226d735008e2a6f8f470 (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (162 commits) tracing/kprobes: unregister_trace_probe needs to be called under mutex perf: expose event__process function perf events: Fix mmap offset determination perf, powerpc: fsl_emb: Restore setting perf_sample_data.period perf, powerpc: Convert the FSL driver to use local64_t perf tools: Don't keep unreferenced maps when unmaps are detected perf session: Invalidate last_match when removing threads from rb_tree perf session: Free the ref_reloc_sym memory at the right place x86,mmiotrace: Add support for tracing STOS instruction perf, sched migration: Librarize task states and event headers helpers perf, sched migration: Librarize the GUI class perf, sched migration: Make the GUI class client agnostic perf, sched migration: Make it vertically scrollable perf, sched migration: Parameterize cpu height and spacing perf, sched migration: Fix key bindings perf, sched migration: Ignore unhandled task states perf, sched migration: Handle ignored migrate out events perf: New migration tool overview tracing: Drop cpparg() macro perf: Use tracepoint_synchronize_unregister() to flush any pending tracepoint call ... Fix up trivial conflicts in Makefile and drivers/cpufreq/cpufreq.c
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c127
1 files changed, 55 insertions, 72 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d6736b93dc2a..ed1032d6f81d 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -341,7 +341,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
341/* trace_flags holds trace_options default values */ 341/* trace_flags holds trace_options default values */
342unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | 342unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
343 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | 343 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
344 TRACE_ITER_GRAPH_TIME; 344 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD;
345 345
346static int trace_stop_count; 346static int trace_stop_count;
347static DEFINE_SPINLOCK(tracing_start_lock); 347static DEFINE_SPINLOCK(tracing_start_lock);
@@ -425,6 +425,7 @@ static const char *trace_options[] = {
425 "latency-format", 425 "latency-format",
426 "sleep-time", 426 "sleep-time",
427 "graph-time", 427 "graph-time",
428 "record-cmd",
428 NULL 429 NULL
429}; 430};
430 431
@@ -656,6 +657,10 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
656 return; 657 return;
657 658
658 WARN_ON_ONCE(!irqs_disabled()); 659 WARN_ON_ONCE(!irqs_disabled());
660 if (!current_trace->use_max_tr) {
661 WARN_ON_ONCE(1);
662 return;
663 }
659 arch_spin_lock(&ftrace_max_lock); 664 arch_spin_lock(&ftrace_max_lock);
660 665
661 tr->buffer = max_tr.buffer; 666 tr->buffer = max_tr.buffer;
@@ -682,6 +687,11 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
682 return; 687 return;
683 688
684 WARN_ON_ONCE(!irqs_disabled()); 689 WARN_ON_ONCE(!irqs_disabled());
690 if (!current_trace->use_max_tr) {
691 WARN_ON_ONCE(1);
692 return;
693 }
694
685 arch_spin_lock(&ftrace_max_lock); 695 arch_spin_lock(&ftrace_max_lock);
686 696
687 ftrace_disable_cpu(); 697 ftrace_disable_cpu();
@@ -726,7 +736,7 @@ __acquires(kernel_lock)
726 return -1; 736 return -1;
727 } 737 }
728 738
729 if (strlen(type->name) > MAX_TRACER_SIZE) { 739 if (strlen(type->name) >= MAX_TRACER_SIZE) {
730 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); 740 pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
731 return -1; 741 return -1;
732 } 742 }
@@ -1328,61 +1338,6 @@ static void __trace_userstack(struct trace_array *tr, unsigned long flags)
1328 1338
1329#endif /* CONFIG_STACKTRACE */ 1339#endif /* CONFIG_STACKTRACE */
1330 1340
1331static void
1332ftrace_trace_special(void *__tr,
1333 unsigned long arg1, unsigned long arg2, unsigned long arg3,
1334 int pc)
1335{
1336 struct ftrace_event_call *call = &event_special;
1337 struct ring_buffer_event *event;
1338 struct trace_array *tr = __tr;
1339 struct ring_buffer *buffer = tr->buffer;
1340 struct special_entry *entry;
1341
1342 event = trace_buffer_lock_reserve(buffer, TRACE_SPECIAL,
1343 sizeof(*entry), 0, pc);
1344 if (!event)
1345 return;
1346 entry = ring_buffer_event_data(event);
1347 entry->arg1 = arg1;
1348 entry->arg2 = arg2;
1349 entry->arg3 = arg3;
1350
1351 if (!filter_check_discard(call, entry, buffer, event))
1352 trace_buffer_unlock_commit(buffer, event, 0, pc);
1353}
1354
1355void
1356__trace_special(void *__tr, void *__data,
1357 unsigned long arg1, unsigned long arg2, unsigned long arg3)
1358{
1359 ftrace_trace_special(__tr, arg1, arg2, arg3, preempt_count());
1360}
1361
1362void
1363ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
1364{
1365 struct trace_array *tr = &global_trace;
1366 struct trace_array_cpu *data;
1367 unsigned long flags;
1368 int cpu;
1369 int pc;
1370
1371 if (tracing_disabled)
1372 return;
1373
1374 pc = preempt_count();
1375 local_irq_save(flags);
1376 cpu = raw_smp_processor_id();
1377 data = tr->data[cpu];
1378
1379 if (likely(atomic_inc_return(&data->disabled) == 1))
1380 ftrace_trace_special(tr, arg1, arg2, arg3, pc);
1381
1382 atomic_dec(&data->disabled);
1383 local_irq_restore(flags);
1384}
1385
1386/** 1341/**
1387 * trace_vbprintk - write binary msg to tracing buffer 1342 * trace_vbprintk - write binary msg to tracing buffer
1388 * 1343 *
@@ -1401,7 +1356,6 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
1401 struct bprint_entry *entry; 1356 struct bprint_entry *entry;
1402 unsigned long flags; 1357 unsigned long flags;
1403 int disable; 1358 int disable;
1404 int resched;
1405 int cpu, len = 0, size, pc; 1359 int cpu, len = 0, size, pc;
1406 1360
1407 if (unlikely(tracing_selftest_running || tracing_disabled)) 1361 if (unlikely(tracing_selftest_running || tracing_disabled))
@@ -1411,7 +1365,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
1411 pause_graph_tracing(); 1365 pause_graph_tracing();
1412 1366
1413 pc = preempt_count(); 1367 pc = preempt_count();
1414 resched = ftrace_preempt_disable(); 1368 preempt_disable_notrace();
1415 cpu = raw_smp_processor_id(); 1369 cpu = raw_smp_processor_id();
1416 data = tr->data[cpu]; 1370 data = tr->data[cpu];
1417 1371
@@ -1449,7 +1403,7 @@ out_unlock:
1449 1403
1450out: 1404out:
1451 atomic_dec_return(&data->disabled); 1405 atomic_dec_return(&data->disabled);
1452 ftrace_preempt_enable(resched); 1406 preempt_enable_notrace();
1453 unpause_graph_tracing(); 1407 unpause_graph_tracing();
1454 1408
1455 return len; 1409 return len;
@@ -2386,6 +2340,7 @@ static const struct file_operations show_traces_fops = {
2386 .open = show_traces_open, 2340 .open = show_traces_open,
2387 .read = seq_read, 2341 .read = seq_read,
2388 .release = seq_release, 2342 .release = seq_release,
2343 .llseek = seq_lseek,
2389}; 2344};
2390 2345
2391/* 2346/*
@@ -2479,6 +2434,7 @@ static const struct file_operations tracing_cpumask_fops = {
2479 .open = tracing_open_generic, 2434 .open = tracing_open_generic,
2480 .read = tracing_cpumask_read, 2435 .read = tracing_cpumask_read,
2481 .write = tracing_cpumask_write, 2436 .write = tracing_cpumask_write,
2437 .llseek = generic_file_llseek,
2482}; 2438};
2483 2439
2484static int tracing_trace_options_show(struct seq_file *m, void *v) 2440static int tracing_trace_options_show(struct seq_file *m, void *v)
@@ -2554,6 +2510,9 @@ static void set_tracer_flags(unsigned int mask, int enabled)
2554 trace_flags |= mask; 2510 trace_flags |= mask;
2555 else 2511 else
2556 trace_flags &= ~mask; 2512 trace_flags &= ~mask;
2513
2514 if (mask == TRACE_ITER_RECORD_CMD)
2515 trace_event_enable_cmd_record(enabled);
2557} 2516}
2558 2517
2559static ssize_t 2518static ssize_t
@@ -2645,6 +2604,7 @@ tracing_readme_read(struct file *filp, char __user *ubuf,
2645static const struct file_operations tracing_readme_fops = { 2604static const struct file_operations tracing_readme_fops = {
2646 .open = tracing_open_generic, 2605 .open = tracing_open_generic,
2647 .read = tracing_readme_read, 2606 .read = tracing_readme_read,
2607 .llseek = generic_file_llseek,
2648}; 2608};
2649 2609
2650static ssize_t 2610static ssize_t
@@ -2695,6 +2655,7 @@ tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
2695static const struct file_operations tracing_saved_cmdlines_fops = { 2655static const struct file_operations tracing_saved_cmdlines_fops = {
2696 .open = tracing_open_generic, 2656 .open = tracing_open_generic,
2697 .read = tracing_saved_cmdlines_read, 2657 .read = tracing_saved_cmdlines_read,
2658 .llseek = generic_file_llseek,
2698}; 2659};
2699 2660
2700static ssize_t 2661static ssize_t
@@ -2790,6 +2751,9 @@ static int tracing_resize_ring_buffer(unsigned long size)
2790 if (ret < 0) 2751 if (ret < 0)
2791 return ret; 2752 return ret;
2792 2753
2754 if (!current_trace->use_max_tr)
2755 goto out;
2756
2793 ret = ring_buffer_resize(max_tr.buffer, size); 2757 ret = ring_buffer_resize(max_tr.buffer, size);
2794 if (ret < 0) { 2758 if (ret < 0) {
2795 int r; 2759 int r;
@@ -2817,11 +2781,14 @@ static int tracing_resize_ring_buffer(unsigned long size)
2817 return ret; 2781 return ret;
2818 } 2782 }
2819 2783
2784 max_tr.entries = size;
2785 out:
2820 global_trace.entries = size; 2786 global_trace.entries = size;
2821 2787
2822 return ret; 2788 return ret;
2823} 2789}
2824 2790
2791
2825/** 2792/**
2826 * tracing_update_buffers - used by tracing facility to expand ring buffers 2793 * tracing_update_buffers - used by tracing facility to expand ring buffers
2827 * 2794 *
@@ -2882,12 +2849,26 @@ static int tracing_set_tracer(const char *buf)
2882 trace_branch_disable(); 2849 trace_branch_disable();
2883 if (current_trace && current_trace->reset) 2850 if (current_trace && current_trace->reset)
2884 current_trace->reset(tr); 2851 current_trace->reset(tr);
2885 2852 if (current_trace && current_trace->use_max_tr) {
2853 /*
2854 * We don't free the ring buffer. instead, resize it because
2855 * The max_tr ring buffer has some state (e.g. ring->clock) and
2856 * we want preserve it.
2857 */
2858 ring_buffer_resize(max_tr.buffer, 1);
2859 max_tr.entries = 1;
2860 }
2886 destroy_trace_option_files(topts); 2861 destroy_trace_option_files(topts);
2887 2862
2888 current_trace = t; 2863 current_trace = t;
2889 2864
2890 topts = create_trace_option_files(current_trace); 2865 topts = create_trace_option_files(current_trace);
2866 if (current_trace->use_max_tr) {
2867 ret = ring_buffer_resize(max_tr.buffer, global_trace.entries);
2868 if (ret < 0)
2869 goto out;
2870 max_tr.entries = global_trace.entries;
2871 }
2891 2872
2892 if (t->init) { 2873 if (t->init) {
2893 ret = tracer_init(t, tr); 2874 ret = tracer_init(t, tr);
@@ -3024,6 +3005,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
3024 if (iter->trace->pipe_open) 3005 if (iter->trace->pipe_open)
3025 iter->trace->pipe_open(iter); 3006 iter->trace->pipe_open(iter);
3026 3007
3008 nonseekable_open(inode, filp);
3027out: 3009out:
3028 mutex_unlock(&trace_types_lock); 3010 mutex_unlock(&trace_types_lock);
3029 return ret; 3011 return ret;
@@ -3469,7 +3451,6 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
3469 } 3451 }
3470 3452
3471 tracing_start(); 3453 tracing_start();
3472 max_tr.entries = global_trace.entries;
3473 mutex_unlock(&trace_types_lock); 3454 mutex_unlock(&trace_types_lock);
3474 3455
3475 return cnt; 3456 return cnt;
@@ -3582,18 +3563,21 @@ static const struct file_operations tracing_max_lat_fops = {
3582 .open = tracing_open_generic, 3563 .open = tracing_open_generic,
3583 .read = tracing_max_lat_read, 3564 .read = tracing_max_lat_read,
3584 .write = tracing_max_lat_write, 3565 .write = tracing_max_lat_write,
3566 .llseek = generic_file_llseek,
3585}; 3567};
3586 3568
3587static const struct file_operations tracing_ctrl_fops = { 3569static const struct file_operations tracing_ctrl_fops = {
3588 .open = tracing_open_generic, 3570 .open = tracing_open_generic,
3589 .read = tracing_ctrl_read, 3571 .read = tracing_ctrl_read,
3590 .write = tracing_ctrl_write, 3572 .write = tracing_ctrl_write,
3573 .llseek = generic_file_llseek,
3591}; 3574};
3592 3575
3593static const struct file_operations set_tracer_fops = { 3576static const struct file_operations set_tracer_fops = {
3594 .open = tracing_open_generic, 3577 .open = tracing_open_generic,
3595 .read = tracing_set_trace_read, 3578 .read = tracing_set_trace_read,
3596 .write = tracing_set_trace_write, 3579 .write = tracing_set_trace_write,
3580 .llseek = generic_file_llseek,
3597}; 3581};
3598 3582
3599static const struct file_operations tracing_pipe_fops = { 3583static const struct file_operations tracing_pipe_fops = {
@@ -3602,17 +3586,20 @@ static const struct file_operations tracing_pipe_fops = {
3602 .read = tracing_read_pipe, 3586 .read = tracing_read_pipe,
3603 .splice_read = tracing_splice_read_pipe, 3587 .splice_read = tracing_splice_read_pipe,
3604 .release = tracing_release_pipe, 3588 .release = tracing_release_pipe,
3589 .llseek = no_llseek,
3605}; 3590};
3606 3591
3607static const struct file_operations tracing_entries_fops = { 3592static const struct file_operations tracing_entries_fops = {
3608 .open = tracing_open_generic, 3593 .open = tracing_open_generic,
3609 .read = tracing_entries_read, 3594 .read = tracing_entries_read,
3610 .write = tracing_entries_write, 3595 .write = tracing_entries_write,
3596 .llseek = generic_file_llseek,
3611}; 3597};
3612 3598
3613static const struct file_operations tracing_mark_fops = { 3599static const struct file_operations tracing_mark_fops = {
3614 .open = tracing_open_generic, 3600 .open = tracing_open_generic,
3615 .write = tracing_mark_write, 3601 .write = tracing_mark_write,
3602 .llseek = generic_file_llseek,
3616}; 3603};
3617 3604
3618static const struct file_operations trace_clock_fops = { 3605static const struct file_operations trace_clock_fops = {
@@ -3918,6 +3905,7 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
3918static const struct file_operations tracing_stats_fops = { 3905static const struct file_operations tracing_stats_fops = {
3919 .open = tracing_open_generic, 3906 .open = tracing_open_generic,
3920 .read = tracing_stats_read, 3907 .read = tracing_stats_read,
3908 .llseek = generic_file_llseek,
3921}; 3909};
3922 3910
3923#ifdef CONFIG_DYNAMIC_FTRACE 3911#ifdef CONFIG_DYNAMIC_FTRACE
@@ -3954,6 +3942,7 @@ tracing_read_dyn_info(struct file *filp, char __user *ubuf,
3954static const struct file_operations tracing_dyn_info_fops = { 3942static const struct file_operations tracing_dyn_info_fops = {
3955 .open = tracing_open_generic, 3943 .open = tracing_open_generic,
3956 .read = tracing_read_dyn_info, 3944 .read = tracing_read_dyn_info,
3945 .llseek = generic_file_llseek,
3957}; 3946};
3958#endif 3947#endif
3959 3948
@@ -4107,6 +4096,7 @@ static const struct file_operations trace_options_fops = {
4107 .open = tracing_open_generic, 4096 .open = tracing_open_generic,
4108 .read = trace_options_read, 4097 .read = trace_options_read,
4109 .write = trace_options_write, 4098 .write = trace_options_write,
4099 .llseek = generic_file_llseek,
4110}; 4100};
4111 4101
4112static ssize_t 4102static ssize_t
@@ -4158,6 +4148,7 @@ static const struct file_operations trace_options_core_fops = {
4158 .open = tracing_open_generic, 4148 .open = tracing_open_generic,
4159 .read = trace_options_core_read, 4149 .read = trace_options_core_read,
4160 .write = trace_options_core_write, 4150 .write = trace_options_core_write,
4151 .llseek = generic_file_llseek,
4161}; 4152};
4162 4153
4163struct dentry *trace_create_file(const char *name, 4154struct dentry *trace_create_file(const char *name,
@@ -4347,9 +4338,6 @@ static __init int tracer_init_debugfs(void)
4347 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, 4338 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
4348 &ftrace_update_tot_cnt, &tracing_dyn_info_fops); 4339 &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
4349#endif 4340#endif
4350#ifdef CONFIG_SYSPROF_TRACER
4351 init_tracer_sysprof_debugfs(d_tracer);
4352#endif
4353 4341
4354 create_trace_options_dir(); 4342 create_trace_options_dir();
4355 4343
@@ -4576,16 +4564,14 @@ __init static int tracer_alloc_buffers(void)
4576 4564
4577 4565
4578#ifdef CONFIG_TRACER_MAX_TRACE 4566#ifdef CONFIG_TRACER_MAX_TRACE
4579 max_tr.buffer = ring_buffer_alloc(ring_buf_size, 4567 max_tr.buffer = ring_buffer_alloc(1, TRACE_BUFFER_FLAGS);
4580 TRACE_BUFFER_FLAGS);
4581 if (!max_tr.buffer) { 4568 if (!max_tr.buffer) {
4582 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); 4569 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
4583 WARN_ON(1); 4570 WARN_ON(1);
4584 ring_buffer_free(global_trace.buffer); 4571 ring_buffer_free(global_trace.buffer);
4585 goto out_free_cpumask; 4572 goto out_free_cpumask;
4586 } 4573 }
4587 max_tr.entries = ring_buffer_size(max_tr.buffer); 4574 max_tr.entries = 1;
4588 WARN_ON(max_tr.entries != global_trace.entries);
4589#endif 4575#endif
4590 4576
4591 /* Allocate the first page for all buffers */ 4577 /* Allocate the first page for all buffers */
@@ -4598,9 +4584,6 @@ __init static int tracer_alloc_buffers(void)
4598 4584
4599 register_tracer(&nop_trace); 4585 register_tracer(&nop_trace);
4600 current_trace = &nop_trace; 4586 current_trace = &nop_trace;
4601#ifdef CONFIG_BOOT_TRACER
4602 register_tracer(&boot_tracer);
4603#endif
4604 /* All seems OK, enable tracing */ 4587 /* All seems OK, enable tracing */
4605 tracing_disabled = 0; 4588 tracing_disabled = 0;
4606 4589