Merge tag 'trace-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux-2.6-block.git] / kernel / trace / trace.c
index 5071931eb94352672412967128a48e3fab4049e5..dfbcf9ee1447645594b06736e2ca9616e6cd93eb 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/nmi.h>
 #include <linux/fs.h>
 #include <linux/trace.h>
+#include <linux/sched/clock.h>
 #include <linux/sched/rt.h>
 
 #include "trace.h"
@@ -1168,6 +1169,14 @@ static struct {
        ARCH_TRACE_CLOCKS
 };
 
+bool trace_clock_in_ns(struct trace_array *tr)
+{
+       if (trace_clocks[tr->clock_id].in_ns)
+               return true;
+
+       return false;
+}
+
 /*
  * trace_parser_get_init - gets the buffer for trace parser
  */
@@ -2269,7 +2278,7 @@ trace_event_buffer_lock_reserve(struct ring_buffer **current_rb,
 
        *current_rb = trace_file->tr->trace_buffer.buffer;
 
-       if ((trace_file->flags &
+       if (!ring_buffer_time_stamp_abs(*current_rb) && (trace_file->flags &
             (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED)) &&
            (entry = this_cpu_read(trace_buffered_event))) {
                /* Try to use the per cpu buffer first */
@@ -4515,6 +4524,9 @@ static const char readme_msg[] =
 #ifdef CONFIG_X86_64
        "     x86-tsc:   TSC cycle counter\n"
 #endif
+       "\n  timestamp_mode\t-view the mode used to timestamp events\n"
+       "       delta:   Delta difference against a buffer-wide timestamp\n"
+       "    absolute:   Absolute (standalone) timestamp\n"
        "\n  trace_marker\t\t- Writes into this file writes into the kernel buffer\n"
        "\n  trace_marker_raw\t\t- Writes into this file writes binary data into the kernel buffer\n"
        "  tracing_cpumask\t- Limit which CPUs to trace\n"
@@ -4691,8 +4703,9 @@ static const char readme_msg[] =
        "\t            .sym        display an address as a symbol\n"
        "\t            .sym-offset display an address as a symbol and offset\n"
        "\t            .execname   display a common_pid as a program name\n"
-       "\t            .syscall    display a syscall id as a syscall name\n\n"
-       "\t            .log2       display log2 value rather than raw number\n\n"
+       "\t            .syscall    display a syscall id as a syscall name\n"
+       "\t            .log2       display log2 value rather than raw number\n"
+       "\t            .usecs      display a common_timestamp in microseconds\n\n"
        "\t    The 'pause' parameter can be used to pause an existing hist\n"
        "\t    trigger or to start a hist trigger but not log any events\n"
        "\t    until told to do so.  'continue' can be used to start or\n"
@@ -6202,7 +6215,7 @@ static int tracing_clock_show(struct seq_file *m, void *v)
        return 0;
 }
 
-static int tracing_set_clock(struct trace_array *tr, const char *clockstr)
+int tracing_set_clock(struct trace_array *tr, const char *clockstr)
 {
        int i;
 
@@ -6282,6 +6295,71 @@ static int tracing_clock_open(struct inode *inode, struct file *file)
        return ret;
 }
 
+static int tracing_time_stamp_mode_show(struct seq_file *m, void *v)
+{
+       struct trace_array *tr = m->private;
+
+       mutex_lock(&trace_types_lock);
+
+       if (ring_buffer_time_stamp_abs(tr->trace_buffer.buffer))
+               seq_puts(m, "delta [absolute]\n");
+       else
+               seq_puts(m, "[delta] absolute\n");
+
+       mutex_unlock(&trace_types_lock);
+
+       return 0;
+}
+
+static int tracing_time_stamp_mode_open(struct inode *inode, struct file *file)
+{
+       struct trace_array *tr = inode->i_private;
+       int ret;
+
+       if (tracing_disabled)
+               return -ENODEV;
+
+       if (trace_array_get(tr))
+               return -ENODEV;
+
+       ret = single_open(file, tracing_time_stamp_mode_show, inode->i_private);
+       if (ret < 0)
+               trace_array_put(tr);
+
+       return ret;
+}
+
+int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs)
+{
+       int ret = 0;
+
+       mutex_lock(&trace_types_lock);
+
+       if (abs && tr->time_stamp_abs_ref++)
+               goto out;
+
+       if (!abs) {
+               if (WARN_ON_ONCE(!tr->time_stamp_abs_ref)) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               if (--tr->time_stamp_abs_ref)
+                       goto out;
+       }
+
+       ring_buffer_set_time_stamp_abs(tr->trace_buffer.buffer, abs);
+
+#ifdef CONFIG_TRACER_MAX_TRACE
+       if (tr->max_buffer.buffer)
+               ring_buffer_set_time_stamp_abs(tr->max_buffer.buffer, abs);
+#endif
+ out:
+       mutex_unlock(&trace_types_lock);
+
+       return ret;
+}
+
 struct ftrace_buffer_info {
        struct trace_iterator   iter;
        void                    *spare;
@@ -6529,6 +6607,13 @@ static const struct file_operations trace_clock_fops = {
        .write          = tracing_clock_write,
 };
 
+static const struct file_operations trace_time_stamp_mode_fops = {
+       .open           = tracing_time_stamp_mode_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = tracing_single_release_tr,
+};
+
 #ifdef CONFIG_TRACER_SNAPSHOT
 static const struct file_operations snapshot_fops = {
        .open           = tracing_snapshot_open,
@@ -7699,6 +7784,7 @@ static int instance_mkdir(const char *name)
 
        INIT_LIST_HEAD(&tr->systems);
        INIT_LIST_HEAD(&tr->events);
+       INIT_LIST_HEAD(&tr->hist_vars);
 
        if (allocate_trace_buffers(tr, trace_buf_size) < 0)
                goto out_free_tr;
@@ -7851,6 +7937,9 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
        trace_create_file("tracing_on", 0644, d_tracer,
                          tr, &rb_simple_fops);
 
+       trace_create_file("timestamp_mode", 0444, d_tracer, tr,
+                         &trace_time_stamp_mode_fops);
+
        create_trace_options_dir(tr);
 
 #if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
@@ -8446,6 +8535,7 @@ __init static int tracer_alloc_buffers(void)
 
        INIT_LIST_HEAD(&global_trace.systems);
        INIT_LIST_HEAD(&global_trace.events);
+       INIT_LIST_HEAD(&global_trace.hist_vars);
        list_add(&global_trace.list, &ftrace_trace_arrays);
 
        apply_trace_boot_options();
@@ -8507,3 +8597,21 @@ __init static int clear_boot_tracer(void)
 
 fs_initcall(tracer_init_tracefs);
 late_initcall_sync(clear_boot_tracer);
+
+#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
+__init static int tracing_set_default_clock(void)
+{
+       /* sched_clock_stable() is determined in late_initcall */
+       if (!trace_boot_clock && !sched_clock_stable()) {
+               printk(KERN_WARNING
+                      "Unstable clock detected, switching default tracing clock to \"global\"\n"
+                      "If you want to keep using the local clock, then add:\n"
+                      "  \"trace_clock=local\"\n"
+                      "on the kernel command line\n");
+               tracing_set_clock(&global_trace, "global");
+       }
+
+       return 0;
+}
+late_initcall_sync(tracing_set_default_clock);
+#endif