[PATCH 1/2] Add force-abs-timestamp trace option.

From: Korben Rusek
Date: Thu Jun 18 2020 - 18:16:38 EST


Normally a data event includes the delta time between itself and
the previous data event. But if a write interrupts another write
then the event cannot check the timestamp of the previous event
and so it uses a delta of 0.

Adds a new trace option: force-abs-timestamp. When this is on
each event is proceeded by an absolute timestamp event.

Reviewed-by: Peter Shier <pshier@xxxxxxxxxx>
Signed-off-by: Korben Rusek <korben@xxxxxxxxxx>
---
Documentation/trace/ftrace.rst | 5 +++++
kernel/trace/trace.c | 4 ++++
kernel/trace/trace.h | 1 +
3 files changed, 10 insertions(+)

diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst
index 430a16283103..704264164ffd 100644
--- a/Documentation/trace/ftrace.rst
+++ b/Documentation/trace/ftrace.rst
@@ -1029,6 +1029,7 @@ To see what is available, simply cat the file::
irq-info
markers
noevent-fork
+ noforce-abs-timestamp
function-trace
nofunction-fork
nodisplay-graph
@@ -1212,6 +1213,10 @@ Here are the available options:

This affects PIDs listed in set_event_notrace_pid as well.

+ force-abs-timestamp
+ When set, always use absolute timestamps rather than
+ defaulting to deltas.
+
function-trace
The latency tracers will enable function tracing
if this option is enabled (default it is). When
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ec44b0e2a19c..8b5c4e998895 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4852,6 +4852,12 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
trace_printk_control(enabled);
}

+ if (mask == TRACE_ITER_FORCE_ABS_TIMESTAMP) {
+ ring_buffer_set_time_stamp_abs(tr->array_buffer.buffer, enabled);
+#ifdef CONFIG_TRACER_MAX_TRACE
+ ring_buffer_set_time_stamp_abs(tr->max_buffer.buffer, enabled);
+#endif
+ }
return 0;
}

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index def769df5bf1..cb1ecc540494 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1330,6 +1330,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
C(MARKERS, "markers"), \
C(EVENT_FORK, "event-fork"), \
C(PAUSE_ON_TRACE, "pause-on-trace"), \
+ C(FORCE_ABS_TIMESTAMP, "force-abs-timestamp"), \
FUNCTION_FLAGS \
FGRAPH_FLAGS \
STACK_FLAGS \
--
2.27.0.290.gba653c62da-goog