aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c484
1 files changed, 263 insertions, 221 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55773f1..3c13e46d7d24 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * Based on code from the latency_tracer, that is: 10 * Based on code from the latency_tracer, that is:
11 * Copyright (C) 2004-2006 Ingo Molnar 11 * Copyright (C) 2004-2006 Ingo Molnar
12 * Copyright (C) 2004 William Lee Irwin III 12 * Copyright (C) 2004 Nadia Yvette Chambers
13 */ 13 */
14#include <linux/ring_buffer.h> 14#include <linux/ring_buffer.h>
15#include <generated/utsrelease.h> 15#include <generated/utsrelease.h>
@@ -19,6 +19,7 @@
19#include <linux/seq_file.h> 19#include <linux/seq_file.h>
20#include <linux/notifier.h> 20#include <linux/notifier.h>
21#include <linux/irqflags.h> 21#include <linux/irqflags.h>
22#include <linux/irq_work.h>
22#include <linux/debugfs.h> 23#include <linux/debugfs.h>
23#include <linux/pagemap.h> 24#include <linux/pagemap.h>
24#include <linux/hardirq.h> 25#include <linux/hardirq.h>
@@ -78,6 +79,21 @@ static int dummy_set_flag(u32 old_flags, u32 bit, int set)
78} 79}
79 80
80/* 81/*
82 * To prevent the comm cache from being overwritten when no
83 * tracing is active, only save the comm when a trace event
84 * occurred.
85 */
86static DEFINE_PER_CPU(bool, trace_cmdline_save);
87
88/*
89 * When a reader is waiting for data, then this variable is
90 * set to true.
91 */
92static bool trace_wakeup_needed;
93
94static struct irq_work trace_work_wakeup;
95
96/*
81 * Kill all tracing for good (never come back). 97 * Kill all tracing for good (never come back).
82 * It is initialized to 1 but will turn to zero if the initialization 98 * It is initialized to 1 but will turn to zero if the initialization
83 * of the tracer is successful. But that is the only place that sets 99 * of the tracer is successful. But that is the only place that sets
@@ -139,6 +155,18 @@ static int __init set_ftrace_dump_on_oops(char *str)
139} 155}
140__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); 156__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
141 157
158
159static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
160static char *trace_boot_options __initdata;
161
162static int __init set_trace_boot_options(char *str)
163{
164 strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
165 trace_boot_options = trace_boot_options_buf;
166 return 0;
167}
168__setup("trace_options=", set_trace_boot_options);
169
142unsigned long long ns2usecs(cycle_t nsec) 170unsigned long long ns2usecs(cycle_t nsec)
143{ 171{
144 nsec += 500; 172 nsec += 500;
@@ -198,20 +226,9 @@ static struct trace_array max_tr;
198 226
199static DEFINE_PER_CPU(struct trace_array_cpu, max_tr_data); 227static DEFINE_PER_CPU(struct trace_array_cpu, max_tr_data);
200 228
201/* tracer_enabled is used to toggle activation of a tracer */
202static int tracer_enabled = 1;
203
204/**
205 * tracing_is_enabled - return tracer_enabled status
206 *
207 * This function is used by other tracers to know the status
208 * of the tracer_enabled flag. Tracers may use this function
209 * to know if it should enable their features when starting
210 * up. See irqsoff tracer for an example (start_irqsoff_tracer).
211 */
212int tracing_is_enabled(void) 229int tracing_is_enabled(void)
213{ 230{
214 return tracer_enabled; 231 return tracing_is_on();
215} 232}
216 233
217/* 234/*
@@ -333,12 +350,18 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
333static int trace_stop_count; 350static int trace_stop_count;
334static DEFINE_RAW_SPINLOCK(tracing_start_lock); 351static DEFINE_RAW_SPINLOCK(tracing_start_lock);
335 352
336static void wakeup_work_handler(struct work_struct *work) 353/**
354 * trace_wake_up - wake up tasks waiting for trace input
355 *
356 * Schedules a delayed work to wake up any task that is blocked on the
357 * trace_wait queue. These is used with trace_poll for tasks polling the
358 * trace.
359 */
360static void trace_wake_up(struct irq_work *work)
337{ 361{
338 wake_up(&trace_wait); 362 wake_up_all(&trace_wait);
339}
340 363
341static DECLARE_DELAYED_WORK(wakeup_work, wakeup_work_handler); 364}
342 365
343/** 366/**
344 * tracing_on - enable tracing buffers 367 * tracing_on - enable tracing buffers
@@ -393,22 +416,6 @@ int tracing_is_on(void)
393} 416}
394EXPORT_SYMBOL_GPL(tracing_is_on); 417EXPORT_SYMBOL_GPL(tracing_is_on);
395 418
396/**
397 * trace_wake_up - wake up tasks waiting for trace input
398 *
399 * Schedules a delayed work to wake up any task that is blocked on the
400 * trace_wait queue. These is used with trace_poll for tasks polling the
401 * trace.
402 */
403void trace_wake_up(void)
404{
405 const unsigned long delay = msecs_to_jiffies(2);
406
407 if (trace_flags & TRACE_ITER_BLOCK)
408 return;
409 schedule_delayed_work(&wakeup_work, delay);
410}
411
412static int __init set_buf_size(char *str) 419static int __init set_buf_size(char *str)
413{ 420{
414 unsigned long buf_size; 421 unsigned long buf_size;
@@ -431,7 +438,7 @@ static int __init set_tracing_thresh(char *str)
431 438
432 if (!str) 439 if (!str)
433 return 0; 440 return 0;
434 ret = strict_strtoul(str, 0, &threshold); 441 ret = kstrtoul(str, 0, &threshold);
435 if (ret < 0) 442 if (ret < 0)
436 return 0; 443 return 0;
437 tracing_thresh = threshold * 1000; 444 tracing_thresh = threshold * 1000;
@@ -477,10 +484,12 @@ static const char *trace_options[] = {
477static struct { 484static struct {
478 u64 (*func)(void); 485 u64 (*func)(void);
479 const char *name; 486 const char *name;
487 int in_ns; /* is this clock in nanoseconds? */
480} trace_clocks[] = { 488} trace_clocks[] = {
481 { trace_clock_local, "local" }, 489 { trace_clock_local, "local", 1 },
482 { trace_clock_global, "global" }, 490 { trace_clock_global, "global", 1 },
483 { trace_clock_counter, "counter" }, 491 { trace_clock_counter, "counter", 0 },
492 ARCH_TRACE_CLOCKS
484}; 493};
485 494
486int trace_clock_id; 495int trace_clock_id;
@@ -757,6 +766,40 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
757} 766}
758#endif /* CONFIG_TRACER_MAX_TRACE */ 767#endif /* CONFIG_TRACER_MAX_TRACE */
759 768
769static void default_wait_pipe(struct trace_iterator *iter)
770{
771 DEFINE_WAIT(wait);
772
773 prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE);
774
775 /*
776 * The events can happen in critical sections where
777 * checking a work queue can cause deadlocks.
778 * After adding a task to the queue, this flag is set
779 * only to notify events to try to wake up the queue
780 * using irq_work.
781 *
782 * We don't clear it even if the buffer is no longer
783 * empty. The flag only causes the next event to run
784 * irq_work to do the work queue wake up. The worse
785 * that can happen if we race with !trace_empty() is that
786 * an event will cause an irq_work to try to wake up
787 * an empty queue.
788 *
789 * There's no reason to protect this flag either, as
790 * the work queue and irq_work logic will do the necessary
791 * synchronization for the wake ups. The only thing
792 * that is necessary is that the wake up happens after
793 * a task has been queued. It's OK for spurious wake ups.
794 */
795 trace_wakeup_needed = true;
796
797 if (trace_empty(iter))
798 schedule();
799
800 finish_wait(&trace_wait, &wait);
801}
802
760/** 803/**
761 * register_tracer - register a tracer with the ftrace system. 804 * register_tracer - register a tracer with the ftrace system.
762 * @type - the plugin for the tracer 805 * @type - the plugin for the tracer
@@ -875,32 +918,6 @@ int register_tracer(struct tracer *type)
875 return ret; 918 return ret;
876} 919}
877 920
878void unregister_tracer(struct tracer *type)
879{
880 struct tracer **t;
881
882 mutex_lock(&trace_types_lock);
883 for (t = &trace_types; *t; t = &(*t)->next) {
884 if (*t == type)
885 goto found;
886 }
887 pr_info("Tracer %s not registered\n", type->name);
888 goto out;
889
890 found:
891 *t = (*t)->next;
892
893 if (type == current_trace && tracer_enabled) {
894 tracer_enabled = 0;
895 tracing_stop();
896 if (current_trace->stop)
897 current_trace->stop(&global_trace);
898 current_trace = &nop_trace;
899 }
900out:
901 mutex_unlock(&trace_types_lock);
902}
903
904void tracing_reset(struct trace_array *tr, int cpu) 921void tracing_reset(struct trace_array *tr, int cpu)
905{ 922{
906 struct ring_buffer *buffer = tr->buffer; 923 struct ring_buffer *buffer = tr->buffer;
@@ -1131,10 +1148,14 @@ void trace_find_cmdline(int pid, char comm[])
1131 1148
1132void tracing_record_cmdline(struct task_struct *tsk) 1149void tracing_record_cmdline(struct task_struct *tsk)
1133{ 1150{
1134 if (atomic_read(&trace_record_cmdline_disabled) || !tracer_enabled || 1151 if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on())
1135 !tracing_is_on()) 1152 return;
1153
1154 if (!__this_cpu_read(trace_cmdline_save))
1136 return; 1155 return;
1137 1156
1157 __this_cpu_write(trace_cmdline_save, false);
1158
1138 trace_save_cmdline(tsk); 1159 trace_save_cmdline(tsk);
1139} 1160}
1140 1161
@@ -1178,27 +1199,36 @@ trace_buffer_lock_reserve(struct ring_buffer *buffer,
1178 return event; 1199 return event;
1179} 1200}
1180 1201
1202void
1203__buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event)
1204{
1205 __this_cpu_write(trace_cmdline_save, true);
1206 if (trace_wakeup_needed) {
1207 trace_wakeup_needed = false;
1208 /* irq_work_queue() supplies it's own memory barriers */
1209 irq_work_queue(&trace_work_wakeup);
1210 }
1211 ring_buffer_unlock_commit(buffer, event);
1212}
1213
1181static inline void 1214static inline void
1182__trace_buffer_unlock_commit(struct ring_buffer *buffer, 1215__trace_buffer_unlock_commit(struct ring_buffer *buffer,
1183 struct ring_buffer_event *event, 1216 struct ring_buffer_event *event,
1184 unsigned long flags, int pc, 1217 unsigned long flags, int pc)
1185 int wake)
1186{ 1218{
1187 ring_buffer_unlock_commit(buffer, event); 1219 __buffer_unlock_commit(buffer, event);
1188 1220
1189 ftrace_trace_stack(buffer, flags, 6, pc); 1221 ftrace_trace_stack(buffer, flags, 6, pc);
1190 ftrace_trace_userstack(buffer, flags, pc); 1222 ftrace_trace_userstack(buffer, flags, pc);
1191
1192 if (wake)
1193 trace_wake_up();
1194} 1223}
1195 1224
1196void trace_buffer_unlock_commit(struct ring_buffer *buffer, 1225void trace_buffer_unlock_commit(struct ring_buffer *buffer,
1197 struct ring_buffer_event *event, 1226 struct ring_buffer_event *event,
1198 unsigned long flags, int pc) 1227 unsigned long flags, int pc)
1199{ 1228{
1200 __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); 1229 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1201} 1230}
1231EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit);
1202 1232
1203struct ring_buffer_event * 1233struct ring_buffer_event *
1204trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, 1234trace_current_buffer_lock_reserve(struct ring_buffer **current_rb,
@@ -1215,29 +1245,21 @@ void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
1215 struct ring_buffer_event *event, 1245 struct ring_buffer_event *event,
1216 unsigned long flags, int pc) 1246 unsigned long flags, int pc)
1217{ 1247{
1218 __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); 1248 __trace_buffer_unlock_commit(buffer, event, flags, pc);
1219} 1249}
1220EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); 1250EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit);
1221 1251
1222void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer, 1252void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
1223 struct ring_buffer_event *event, 1253 struct ring_buffer_event *event,
1224 unsigned long flags, int pc) 1254 unsigned long flags, int pc,
1225{ 1255 struct pt_regs *regs)
1226 __trace_buffer_unlock_commit(buffer, event, flags, pc, 0);
1227}
1228EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit);
1229
1230void trace_nowake_buffer_unlock_commit_regs(struct ring_buffer *buffer,
1231 struct ring_buffer_event *event,
1232 unsigned long flags, int pc,
1233 struct pt_regs *regs)
1234{ 1256{
1235 ring_buffer_unlock_commit(buffer, event); 1257 __buffer_unlock_commit(buffer, event);
1236 1258
1237 ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); 1259 ftrace_trace_stack_regs(buffer, flags, 0, pc, regs);
1238 ftrace_trace_userstack(buffer, flags, pc); 1260 ftrace_trace_userstack(buffer, flags, pc);
1239} 1261}
1240EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit_regs); 1262EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs);
1241 1263
1242void trace_current_buffer_discard_commit(struct ring_buffer *buffer, 1264void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
1243 struct ring_buffer_event *event) 1265 struct ring_buffer_event *event)
@@ -1269,7 +1291,7 @@ trace_function(struct trace_array *tr,
1269 entry->parent_ip = parent_ip; 1291 entry->parent_ip = parent_ip;
1270 1292
1271 if (!filter_check_discard(call, entry, buffer, event)) 1293 if (!filter_check_discard(call, entry, buffer, event))
1272 ring_buffer_unlock_commit(buffer, event); 1294 __buffer_unlock_commit(buffer, event);
1273} 1295}
1274 1296
1275void 1297void
@@ -1362,7 +1384,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
1362 entry->size = trace.nr_entries; 1384 entry->size = trace.nr_entries;
1363 1385
1364 if (!filter_check_discard(call, entry, buffer, event)) 1386 if (!filter_check_discard(call, entry, buffer, event))
1365 ring_buffer_unlock_commit(buffer, event); 1387 __buffer_unlock_commit(buffer, event);
1366 1388
1367 out: 1389 out:
1368 /* Again, don't let gcc optimize things here */ 1390 /* Again, don't let gcc optimize things here */
@@ -1458,7 +1480,7 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
1458 1480
1459 save_stack_trace_user(&trace); 1481 save_stack_trace_user(&trace);
1460 if (!filter_check_discard(call, entry, buffer, event)) 1482 if (!filter_check_discard(call, entry, buffer, event))
1461 ring_buffer_unlock_commit(buffer, event); 1483 __buffer_unlock_commit(buffer, event);
1462 1484
1463 out_drop_count: 1485 out_drop_count:
1464 __this_cpu_dec(user_stack_count); 1486 __this_cpu_dec(user_stack_count);
@@ -1559,10 +1581,10 @@ static int alloc_percpu_trace_buffer(void)
1559 return -ENOMEM; 1581 return -ENOMEM;
1560} 1582}
1561 1583
1584static int buffers_allocated;
1585
1562void trace_printk_init_buffers(void) 1586void trace_printk_init_buffers(void)
1563{ 1587{
1564 static int buffers_allocated;
1565
1566 if (buffers_allocated) 1588 if (buffers_allocated)
1567 return; 1589 return;
1568 1590
@@ -1571,7 +1593,38 @@ void trace_printk_init_buffers(void)
1571 1593
1572 pr_info("ftrace: Allocated trace_printk buffers\n"); 1594 pr_info("ftrace: Allocated trace_printk buffers\n");
1573 1595
1596 /* Expand the buffers to set size */
1597 tracing_update_buffers();
1598
1574 buffers_allocated = 1; 1599 buffers_allocated = 1;
1600
1601 /*
1602 * trace_printk_init_buffers() can be called by modules.
1603 * If that happens, then we need to start cmdline recording
1604 * directly here. If the global_trace.buffer is already
1605 * allocated here, then this was called by module code.
1606 */
1607 if (global_trace.buffer)
1608 tracing_start_cmdline_record();
1609}
1610
1611void trace_printk_start_comm(void)
1612{
1613 /* Start tracing comms if trace printk is set */
1614 if (!buffers_allocated)
1615 return;
1616 tracing_start_cmdline_record();
1617}
1618
1619static void trace_printk_start_stop_comm(int enabled)
1620{
1621 if (!buffers_allocated)
1622 return;
1623
1624 if (enabled)
1625 tracing_start_cmdline_record();
1626 else
1627 tracing_stop_cmdline_record();
1575} 1628}
1576 1629
1577/** 1630/**
@@ -1622,7 +1675,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
1622 1675
1623 memcpy(entry->buf, tbuffer, sizeof(u32) * len); 1676 memcpy(entry->buf, tbuffer, sizeof(u32) * len);
1624 if (!filter_check_discard(call, entry, buffer, event)) { 1677 if (!filter_check_discard(call, entry, buffer, event)) {
1625 ring_buffer_unlock_commit(buffer, event); 1678 __buffer_unlock_commit(buffer, event);
1626 ftrace_trace_stack(buffer, flags, 6, pc); 1679 ftrace_trace_stack(buffer, flags, 6, pc);
1627 } 1680 }
1628 1681
@@ -1693,7 +1746,7 @@ int trace_array_vprintk(struct trace_array *tr,
1693 memcpy(&entry->buf, tbuffer, len); 1746 memcpy(&entry->buf, tbuffer, len);
1694 entry->buf[len] = '\0'; 1747 entry->buf[len] = '\0';
1695 if (!filter_check_discard(call, entry, buffer, event)) { 1748 if (!filter_check_discard(call, entry, buffer, event)) {
1696 ring_buffer_unlock_commit(buffer, event); 1749 __buffer_unlock_commit(buffer, event);
1697 ftrace_trace_stack(buffer, flags, 6, pc); 1750 ftrace_trace_stack(buffer, flags, 6, pc);
1698 } 1751 }
1699 out: 1752 out:
@@ -2426,6 +2479,10 @@ __tracing_open(struct inode *inode, struct file *file)
2426 if (ring_buffer_overruns(iter->tr->buffer)) 2479 if (ring_buffer_overruns(iter->tr->buffer))
2427 iter->iter_flags |= TRACE_FILE_ANNOTATE; 2480 iter->iter_flags |= TRACE_FILE_ANNOTATE;
2428 2481
2482 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
2483 if (trace_clocks[trace_clock_id].in_ns)
2484 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
2485
2429 /* stop the trace while dumping */ 2486 /* stop the trace while dumping */
2430 tracing_stop(); 2487 tracing_stop();
2431 2488
@@ -2794,26 +2851,19 @@ static void set_tracer_flags(unsigned int mask, int enabled)
2794 2851
2795 if (mask == TRACE_ITER_OVERWRITE) 2852 if (mask == TRACE_ITER_OVERWRITE)
2796 ring_buffer_change_overwrite(global_trace.buffer, enabled); 2853 ring_buffer_change_overwrite(global_trace.buffer, enabled);
2854
2855 if (mask == TRACE_ITER_PRINTK)
2856 trace_printk_start_stop_comm(enabled);
2797} 2857}
2798 2858
2799static ssize_t 2859static int trace_set_options(char *option)
2800tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2801 size_t cnt, loff_t *ppos)
2802{ 2860{
2803 char buf[64];
2804 char *cmp; 2861 char *cmp;
2805 int neg = 0; 2862 int neg = 0;
2806 int ret; 2863 int ret = 0;
2807 int i; 2864 int i;
2808 2865
2809 if (cnt >= sizeof(buf)) 2866 cmp = strstrip(option);
2810 return -EINVAL;
2811
2812 if (copy_from_user(&buf, ubuf, cnt))
2813 return -EFAULT;
2814
2815 buf[cnt] = 0;
2816 cmp = strstrip(buf);
2817 2867
2818 if (strncmp(cmp, "no", 2) == 0) { 2868 if (strncmp(cmp, "no", 2) == 0) {
2819 neg = 1; 2869 neg = 1;
@@ -2832,10 +2882,27 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2832 mutex_lock(&trace_types_lock); 2882 mutex_lock(&trace_types_lock);
2833 ret = set_tracer_option(current_trace, cmp, neg); 2883 ret = set_tracer_option(current_trace, cmp, neg);
2834 mutex_unlock(&trace_types_lock); 2884 mutex_unlock(&trace_types_lock);
2835 if (ret)
2836 return ret;
2837 } 2885 }
2838 2886
2887 return ret;
2888}
2889
2890static ssize_t
2891tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2892 size_t cnt, loff_t *ppos)
2893{
2894 char buf[64];
2895
2896 if (cnt >= sizeof(buf))
2897 return -EINVAL;
2898
2899 if (copy_from_user(&buf, ubuf, cnt))
2900 return -EFAULT;
2901
2902 buf[cnt] = 0;
2903
2904 trace_set_options(buf);
2905
2839 *ppos += cnt; 2906 *ppos += cnt;
2840 2907
2841 return cnt; 2908 return cnt;
@@ -2940,56 +3007,6 @@ static const struct file_operations tracing_saved_cmdlines_fops = {
2940}; 3007};
2941 3008
2942static ssize_t 3009static ssize_t
2943tracing_ctrl_read(struct file *filp, char __user *ubuf,
2944 size_t cnt, loff_t *ppos)
2945{
2946 char buf[64];
2947 int r;
2948
2949 r = sprintf(buf, "%u\n", tracer_enabled);
2950 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
2951}
2952
2953static ssize_t
2954tracing_ctrl_write(struct file *filp, const char __user *ubuf,
2955 size_t cnt, loff_t *ppos)
2956{
2957 struct trace_array *tr = filp->private_data;
2958 unsigned long val;
2959 int ret;
2960
2961 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
2962 if (ret)
2963 return ret;
2964
2965 val = !!val;
2966
2967 mutex_lock(&trace_types_lock);
2968 if (tracer_enabled ^ val) {
2969
2970 /* Only need to warn if this is used to change the state */
2971 WARN_ONCE(1, "tracing_enabled is deprecated. Use tracing_on");
2972
2973 if (val) {
2974 tracer_enabled = 1;
2975 if (current_trace->start)
2976 current_trace->start(tr);
2977 tracing_start();
2978 } else {
2979 tracer_enabled = 0;
2980 tracing_stop();
2981 if (current_trace->stop)
2982 current_trace->stop(tr);
2983 }
2984 }
2985 mutex_unlock(&trace_types_lock);
2986
2987 *ppos += cnt;
2988
2989 return cnt;
2990}
2991
2992static ssize_t
2993tracing_set_trace_read(struct file *filp, char __user *ubuf, 3010tracing_set_trace_read(struct file *filp, char __user *ubuf,
2994 size_t cnt, loff_t *ppos) 3011 size_t cnt, loff_t *ppos)
2995{ 3012{
@@ -3019,6 +3036,31 @@ static void set_buffer_entries(struct trace_array *tr, unsigned long val)
3019 tr->data[cpu]->entries = val; 3036 tr->data[cpu]->entries = val;
3020} 3037}
3021 3038
3039/* resize @tr's buffer to the size of @size_tr's entries */
3040static int resize_buffer_duplicate_size(struct trace_array *tr,
3041 struct trace_array *size_tr, int cpu_id)
3042{
3043 int cpu, ret = 0;
3044
3045 if (cpu_id == RING_BUFFER_ALL_CPUS) {
3046 for_each_tracing_cpu(cpu) {
3047 ret = ring_buffer_resize(tr->buffer,
3048 size_tr->data[cpu]->entries, cpu);
3049 if (ret < 0)
3050 break;
3051 tr->data[cpu]->entries = size_tr->data[cpu]->entries;
3052 }
3053 } else {
3054 ret = ring_buffer_resize(tr->buffer,
3055 size_tr->data[cpu_id]->entries, cpu_id);
3056 if (ret == 0)
3057 tr->data[cpu_id]->entries =
3058 size_tr->data[cpu_id]->entries;
3059 }
3060
3061 return ret;
3062}
3063
3022static int __tracing_resize_ring_buffer(unsigned long size, int cpu) 3064static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
3023{ 3065{
3024 int ret; 3066 int ret;
@@ -3030,6 +3072,10 @@ static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
3030 */ 3072 */
3031 ring_buffer_expanded = 1; 3073 ring_buffer_expanded = 1;
3032 3074
3075 /* May be called before buffers are initialized */
3076 if (!global_trace.buffer)
3077 return 0;
3078
3033 ret = ring_buffer_resize(global_trace.buffer, size, cpu); 3079 ret = ring_buffer_resize(global_trace.buffer, size, cpu);
3034 if (ret < 0) 3080 if (ret < 0)
3035 return ret; 3081 return ret;
@@ -3039,23 +3085,8 @@ static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
3039 3085
3040 ret = ring_buffer_resize(max_tr.buffer, size, cpu); 3086 ret = ring_buffer_resize(max_tr.buffer, size, cpu);
3041 if (ret < 0) { 3087 if (ret < 0) {
3042 int r = 0; 3088 int r = resize_buffer_duplicate_size(&global_trace,
3043 3089 &global_trace, cpu);
3044 if (cpu == RING_BUFFER_ALL_CPUS) {
3045 int i;
3046 for_each_tracing_cpu(i) {
3047 r = ring_buffer_resize(global_trace.buffer,
3048 global_trace.data[i]->entries,
3049 i);
3050 if (r < 0)
3051 break;
3052 }
3053 } else {
3054 r = ring_buffer_resize(global_trace.buffer,
3055 global_trace.data[cpu]->entries,
3056 cpu);
3057 }
3058
3059 if (r < 0) { 3090 if (r < 0) {
3060 /* 3091 /*
3061 * AARGH! We are left with different 3092 * AARGH! We are left with different
@@ -3193,17 +3224,11 @@ static int tracing_set_tracer(const char *buf)
3193 3224
3194 topts = create_trace_option_files(t); 3225 topts = create_trace_option_files(t);
3195 if (t->use_max_tr) { 3226 if (t->use_max_tr) {
3196 int cpu;
3197 /* we need to make per cpu buffer sizes equivalent */ 3227 /* we need to make per cpu buffer sizes equivalent */
3198 for_each_tracing_cpu(cpu) { 3228 ret = resize_buffer_duplicate_size(&max_tr, &global_trace,
3199 ret = ring_buffer_resize(max_tr.buffer, 3229 RING_BUFFER_ALL_CPUS);
3200 global_trace.data[cpu]->entries, 3230 if (ret < 0)
3201 cpu); 3231 goto out;
3202 if (ret < 0)
3203 goto out;
3204 max_tr.data[cpu]->entries =
3205 global_trace.data[cpu]->entries;
3206 }
3207 } 3232 }
3208 3233
3209 if (t->init) { 3234 if (t->init) {
@@ -3325,6 +3350,10 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
3325 if (trace_flags & TRACE_ITER_LATENCY_FMT) 3350 if (trace_flags & TRACE_ITER_LATENCY_FMT)
3326 iter->iter_flags |= TRACE_FILE_LAT_FMT; 3351 iter->iter_flags |= TRACE_FILE_LAT_FMT;
3327 3352
3353 /* Output in nanoseconds only if we are using a clock in nanoseconds. */
3354 if (trace_clocks[trace_clock_id].in_ns)
3355 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
3356
3328 iter->cpu_file = cpu_file; 3357 iter->cpu_file = cpu_file;
3329 iter->tr = &global_trace; 3358 iter->tr = &global_trace;
3330 mutex_init(&iter->mutex); 3359 mutex_init(&iter->mutex);
@@ -3385,19 +3414,6 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table)
3385 } 3414 }
3386} 3415}
3387 3416
3388
3389void default_wait_pipe(struct trace_iterator *iter)
3390{
3391 DEFINE_WAIT(wait);
3392
3393 prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE);
3394
3395 if (trace_empty(iter))
3396 schedule();
3397
3398 finish_wait(&trace_wait, &wait);
3399}
3400
3401/* 3417/*
3402 * This is a make-shift waitqueue. 3418 * This is a make-shift waitqueue.
3403 * A tracer might use this callback on some rare cases: 3419 * A tracer might use this callback on some rare cases:
@@ -3446,7 +3462,7 @@ static int tracing_wait_pipe(struct file *filp)
3446 * 3462 *
3447 * iter->pos will be 0 if we haven't read anything. 3463 * iter->pos will be 0 if we haven't read anything.
3448 */ 3464 */
3449 if (!tracer_enabled && iter->pos) 3465 if (!tracing_is_enabled() && iter->pos)
3450 break; 3466 break;
3451 } 3467 }
3452 3468
@@ -3955,7 +3971,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
3955 } else 3971 } else
3956 entry->buf[cnt] = '\0'; 3972 entry->buf[cnt] = '\0';
3957 3973
3958 ring_buffer_unlock_commit(buffer, event); 3974 __buffer_unlock_commit(buffer, event);
3959 3975
3960 written = cnt; 3976 written = cnt;
3961 3977
@@ -4016,6 +4032,14 @@ static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf,
4016 if (max_tr.buffer) 4032 if (max_tr.buffer)
4017 ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func); 4033 ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func);
4018 4034
4035 /*
4036 * New clock may not be consistent with the previous clock.
4037 * Reset the buffer so that it doesn't have incomparable timestamps.
4038 */
4039 tracing_reset_online_cpus(&global_trace);
4040 if (max_tr.buffer)
4041 tracing_reset_online_cpus(&max_tr);
4042
4019 mutex_unlock(&trace_types_lock); 4043 mutex_unlock(&trace_types_lock);
4020 4044
4021 *fpos += cnt; 4045 *fpos += cnt;
@@ -4037,13 +4061,6 @@ static const struct file_operations tracing_max_lat_fops = {
4037 .llseek = generic_file_llseek, 4061 .llseek = generic_file_llseek,
4038}; 4062};
4039 4063
4040static const struct file_operations tracing_ctrl_fops = {
4041 .open = tracing_open_generic,
4042 .read = tracing_ctrl_read,
4043 .write = tracing_ctrl_write,
4044 .llseek = generic_file_llseek,
4045};
4046
4047static const struct file_operations set_tracer_fops = { 4064static const struct file_operations set_tracer_fops = {
4048 .open = tracing_open_generic, 4065 .open = tracing_open_generic,
4049 .read = tracing_set_trace_read, 4066 .read = tracing_set_trace_read,
@@ -4260,13 +4277,11 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
4260 return -ENOMEM; 4277 return -ENOMEM;
4261 4278
4262 if (*ppos & (PAGE_SIZE - 1)) { 4279 if (*ppos & (PAGE_SIZE - 1)) {
4263 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
4264 ret = -EINVAL; 4280 ret = -EINVAL;
4265 goto out; 4281 goto out;
4266 } 4282 }
4267 4283
4268 if (len & (PAGE_SIZE - 1)) { 4284 if (len & (PAGE_SIZE - 1)) {
4269 WARN_ONCE(1, "Ftrace: splice_read should page-align\n");
4270 if (len < PAGE_SIZE) { 4285 if (len < PAGE_SIZE) {
4271 ret = -EINVAL; 4286 ret = -EINVAL;
4272 goto out; 4287 goto out;
@@ -4377,13 +4392,27 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
4377 cnt = ring_buffer_bytes_cpu(tr->buffer, cpu); 4392 cnt = ring_buffer_bytes_cpu(tr->buffer, cpu);
4378 trace_seq_printf(s, "bytes: %ld\n", cnt); 4393 trace_seq_printf(s, "bytes: %ld\n", cnt);
4379 4394
4380 t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu)); 4395 if (trace_clocks[trace_clock_id].in_ns) {
4381 usec_rem = do_div(t, USEC_PER_SEC); 4396 /* local or global for trace_clock */
4382 trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", t, usec_rem); 4397 t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu));
4398 usec_rem = do_div(t, USEC_PER_SEC);
4399 trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n",
4400 t, usec_rem);
4401
4402 t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu));
4403 usec_rem = do_div(t, USEC_PER_SEC);
4404 trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
4405 } else {
4406 /* counter or tsc mode for trace_clock */
4407 trace_seq_printf(s, "oldest event ts: %llu\n",
4408 ring_buffer_oldest_event_ts(tr->buffer, cpu));
4409
4410 trace_seq_printf(s, "now ts: %llu\n",
4411 ring_buffer_time_stamp(tr->buffer, cpu));
4412 }
4383 4413
4384 t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu)); 4414 cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu);
4385 usec_rem = do_div(t, USEC_PER_SEC); 4415 trace_seq_printf(s, "dropped events: %ld\n", cnt);
4386 trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
4387 4416
4388 count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); 4417 count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
4389 4418
@@ -4788,10 +4817,17 @@ rb_simple_write(struct file *filp, const char __user *ubuf,
4788 return ret; 4817 return ret;
4789 4818
4790 if (buffer) { 4819 if (buffer) {
4791 if (val) 4820 mutex_lock(&trace_types_lock);
4821 if (val) {
4792 ring_buffer_record_on(buffer); 4822 ring_buffer_record_on(buffer);
4793 else 4823 if (current_trace->start)
4824 current_trace->start(tr);
4825 } else {
4794 ring_buffer_record_off(buffer); 4826 ring_buffer_record_off(buffer);
4827 if (current_trace->stop)
4828 current_trace->stop(tr);
4829 }
4830 mutex_unlock(&trace_types_lock);
4795 } 4831 }
4796 4832
4797 (*ppos)++; 4833 (*ppos)++;
@@ -4815,9 +4851,6 @@ static __init int tracer_init_debugfs(void)
4815 4851
4816 d_tracer = tracing_init_dentry(); 4852 d_tracer = tracing_init_dentry();
4817 4853
4818 trace_create_file("tracing_enabled", 0644, d_tracer,
4819 &global_trace, &tracing_ctrl_fops);
4820
4821 trace_create_file("trace_options", 0644, d_tracer, 4854 trace_create_file("trace_options", 0644, d_tracer,
4822 NULL, &tracing_iter_fops); 4855 NULL, &tracing_iter_fops);
4823 4856
@@ -5089,6 +5122,7 @@ __init static int tracer_alloc_buffers(void)
5089 5122
5090 /* Only allocate trace_printk buffers if a trace_printk exists */ 5123 /* Only allocate trace_printk buffers if a trace_printk exists */
5091 if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) 5124 if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
5125 /* Must be called before global_trace.buffer is allocated */
5092 trace_printk_init_buffers(); 5126 trace_printk_init_buffers();
5093 5127
5094 /* To save memory, keep the ring buffer size to its minimum */ 5128 /* To save memory, keep the ring buffer size to its minimum */
@@ -5136,6 +5170,7 @@ __init static int tracer_alloc_buffers(void)
5136#endif 5170#endif
5137 5171
5138 trace_init_cmdlines(); 5172 trace_init_cmdlines();
5173 init_irq_work(&trace_work_wakeup, trace_wake_up);
5139 5174
5140 register_tracer(&nop_trace); 5175 register_tracer(&nop_trace);
5141 current_trace = &nop_trace; 5176 current_trace = &nop_trace;
@@ -5147,6 +5182,13 @@ __init static int tracer_alloc_buffers(void)
5147 5182
5148 register_die_notifier(&trace_die_notifier); 5183 register_die_notifier(&trace_die_notifier);
5149 5184
5185 while (trace_boot_options) {
5186 char *option;
5187
5188 option = strsep(&trace_boot_options, ",");
5189 trace_set_options(option);
5190 }
5191
5150 return 0; 5192 return 0;
5151 5193
5152out_free_cpumask: 5194out_free_cpumask: