Skip to contentSkip to conversation

force absolute timestamp trace option

PATCH New Korben Rusek 1 participant 3 messages Jun 18, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover force absolute timestamp trace option

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.

This follows from a discussion between [email protected] and Steven Rostedt found here:

https://lkml.org/lkml/2019/5/24/710

Korben Rusek (2):
Add force-abs-timestamp trace option.
tests for absolute timestamp

 Documentation/trace/ftrace.rst                |   5 +
 kernel/trace/trace.c                          |   4 +
 kernel/trace/trace.h                          |   1 +
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/timestamp/Makefile    |  25 +++
 tools/testing/selftests/timestamp/abs-test.sh | 156 ++++++++++++++
 .../selftests/timestamp/abs-timestamp.c       | 198 ++++++++++++++++++
 7 files changed, 390 insertions(+)
 create mode 100644 tools/testing/selftests/timestamp/Makefile
 create mode 100644 tools/testing/selftests/timestamp/abs-test.sh
 create mode 100644 tools/testing/selftests/timestamp/abs-timestamp.c
Signature · 1 line
2.27.0.290.gba653c62da-goog
#1 lore raw

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

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.

---
 Documentation/trace/ftrace.rst | 5 +++++
 kernel/trace/trace.c           | 4 ++++
 kernel/trace/trace.h           | 1 +
 3 files changed, 10 insertions(+)
Documentation/trace/ftrace.rst +5 -0
index 430a16283103..704264164ffd 100644
@@ -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
kernel/trace/trace.c +6 -0
index ec44b0e2a19c..8b5c4e998895 100644
@@ -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;
 }
 
kernel/trace/trace.h +1 -0
index def769df5bf1..cb1ecc540494 100644
@@ -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					\
Signature · 1 line
2.27.0.290.gba653c62da-goog
#2 lore raw

PATCH 2/2 tests for absolute timestamp

In reply to Korben Rusek

Tested:
kselftest output:

Found regular timestamps when force-abs-timestamp flag is off - [PASS] Found absolute timestamps when force-abs-timestamp flag is on - [PASS]

---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/timestamp/Makefile    |  25 +++
 tools/testing/selftests/timestamp/abs-test.sh | 156 ++++++++++++++
 .../selftests/timestamp/abs-timestamp.c       | 198 ++++++++++++++++++
 4 files changed, 380 insertions(+)
 create mode 100644 tools/testing/selftests/timestamp/Makefile
 create mode 100644 tools/testing/selftests/timestamp/abs-test.sh
 create mode 100644 tools/testing/selftests/timestamp/abs-timestamp.c
tools/testing/selftests/Makefile +1 -0
index 1195bd85af38..bda1cd0a608f 100644
@@ -58,6 +58,7 @@ TARGETS += timens
 ifneq (1, $(quicktest))
 TARGETS += timers
 endif
+TARGETS += timestamp
 TARGETS += tmpfs
 TARGETS += tpm2
 TARGETS += user
tools/testing/selftests/timestamp/Makefile new file +25 -0
new file mode 100644
index 000000000000..a8aa3b7278cf
@@ -0,0 +1,25 @@
+TEST_PROGS := abs-test.sh
+
+.PHONY: all clean
+
+include ../lib.mk
+
+override define RUN_TESTS
+	@cd $(OUTPUT); ./abs-test.sh
+endef
+
+override define INSTALL_RULE
+	mkdir -p $(INSTALL_PATH)
+	$(CC) -o $(INSTALL_PATH)/abs-timestamp abs-timestamp.c -static
+	echo $(INSTALL_PATH)
+	cp abs-test.sh $(INSTALL_PATH)/abs-test.sh
+	chmod u+x $(INSTALL_PATH)/abs-test.sh
+endef
+
+override define CLEAN
+	rm -f abs-timestamp
+endef
+
+override define EMIT_TESTS
+	echo "./abs-test.sh"
+endef
tools/testing/selftests/timestamp/abs-test.sh new file +156 -0

156 lines not on this page · raw message

tools/testing/selftests/timestamp/abs-timestamp.c new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
2.27.0.290.gba653c62da-goog