ring-buffer: Add interface for setting absolute time stamps
authorTom Zanussi <tom.zanussi@linux.intel.com>
Tue, 16 Jan 2018 02:51:39 +0000 (20:51 -0600)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Sat, 10 Mar 2018 21:05:50 +0000 (16:05 -0500)
Define a new function, tracing_set_time_stamp_abs(), which can be used
to enable or disable the use of absolute timestamps rather than time
deltas for a trace array.

Only the interface is added here; a subsequent patch will add the
underlying implementation.

Link: http://lkml.kernel.org/r/ce96119de44c7fe0ee44786d15254e9b493040d3.1516069914.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Baohong Liu <baohong.liu@intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/ring_buffer.h
kernel/trace/ring_buffer.c
kernel/trace/trace.c
kernel/trace/trace.h

index 7d9eb39fa76a89b89eb34a17d6b61b90294bfaa9..025159e17e1b627ed03409ef7f01142428d897fa 100644 (file)
@@ -178,6 +178,8 @@ void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
                                      int cpu, u64 *ts);
 void ring_buffer_set_clock(struct ring_buffer *buffer,
                           u64 (*clock)(void));
+void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs);
+bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer);
 
 size_t ring_buffer_page_len(void *page);
 
index dcf1c4dd3efe6954b7d030b986f43bd0a897f052..2a03e069bbc68e4d04461d611d460f0a41454c73 100644 (file)
@@ -488,6 +488,7 @@ struct ring_buffer {
        u64                             (*clock)(void);
 
        struct rb_irq_work              irq_work;
+       bool                            time_stamp_abs;
 };
 
 struct ring_buffer_iter {
@@ -1382,6 +1383,16 @@ void ring_buffer_set_clock(struct ring_buffer *buffer,
        buffer->clock = clock;
 }
 
+void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs)
+{
+       buffer->time_stamp_abs = abs;
+}
+
+bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer)
+{
+       return buffer->time_stamp_abs;
+}
+
 static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
 
 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
index 20a2300ae4e8671629e9b516b389c0e6c4dee2db..cba003f0362e6e8b1c1efb1e976e28455d2b094d 100644 (file)
@@ -2269,7 +2269,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 */
@@ -6282,6 +6282,37 @@ static int tracing_clock_open(struct inode *inode, struct file *file)
        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;
index 2a6d0325a76181a0a8b309eaa2b69f91b350d98a..477341710ebf74f9dc73141a9b1fd774802437c8 100644 (file)
@@ -273,6 +273,7 @@ struct trace_array {
        /* function tracing enabled */
        int                     function_enabled;
 #endif
+       int                     time_stamp_abs_ref;
 };
 
 enum {
@@ -286,6 +287,8 @@ extern struct mutex trace_types_lock;
 extern int trace_array_get(struct trace_array *tr);
 extern void trace_array_put(struct trace_array *tr);
 
+extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs);
+
 /*
  * The global tracer (top) should be the first trace array added,
  * but we check the flag anyway.