linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] trace-cmd: Fix clock setting of agent proxy
@ 2022-05-24  1:50 Steven Rostedt
  2022-05-24  1:50 ` [PATCH 1/2] trace-cmd library: Keep USECS flag if TSC multiplier is set Steven Rostedt
  2022-05-24  1:50 ` [PATCH 2/2] trace-cmd record: Set clock to TSC when connecting to a proxy with kvm Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-05-24  1:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

trace-cmd record does not set its clock to TSC if it connects to a agent
proxy, when it should. This breaks the synchronization. It works if the user
manually sets the clock to TSC before running the record, but the user
should not need to do that.

Also, if the TSC2NSEC option is set, then print the timing out in seconds
(with fractions) instead of the time stamp in nanoseconcds.

Steven Rostedt (Google) (2):
  trace-cmd library: Keep USECS flag if TSC multiplier is set
  trace-cmd record: Set clock to TSC when connecting to a proxy with kvm

 lib/trace-cmd/trace-input.c |  6 ++++++
 tracecmd/trace-record.c     | 13 +++++++++++++
 2 files changed, 19 insertions(+)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] trace-cmd library: Keep USECS flag if TSC multiplier is set
  2022-05-24  1:50 [PATCH 0/2] trace-cmd: Fix clock setting of agent proxy Steven Rostedt
@ 2022-05-24  1:50 ` Steven Rostedt
  2022-05-24  1:50 ` [PATCH 2/2] trace-cmd record: Set clock to TSC when connecting to a proxy with kvm Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-05-24  1:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the option TSC2NSECS is set, then display as microseconds like it does
with trace clock local. This is because even though the x86-tsc is not in
nanoseconds, the clock will be shifted and multiplied to be in
nanoseconds, so it makes sense to convert it to seconds.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 442b1c5a6724..e2ceff331869 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -3483,6 +3483,8 @@ static int handle_options(struct tracecmd_input *handle)
 								 buf + 4, 4);
 			handle->tsc_calc.offset = tep_read_number(handle->pevent,
 								  buf + 8, 8);
+			if (!(handle->flags & TRACECMD_FL_RAW_TS))
+				handle->flags |= TRACECMD_FL_IN_USECS;
 			break;
 		case TRACECMD_OPTION_HEADER_INFO:
 		case TRACECMD_OPTION_FTRACE_EVENTS:
@@ -3865,6 +3867,10 @@ static void extract_trace_clock(struct tracecmd_input *handle, char *line)
 	if (handle->flags & TRACECMD_FL_RAW_TS)
 		handle->flags &= ~TRACECMD_FL_IN_USECS;
 
+	/* tsc_calc is a conversion to nanoseconds */
+	if (handle->tsc_calc.mult)
+		return;
+
 	/* Clear usecs if not one of the specified clocks */
 	if (strcmp(clock, "local") && strcmp(clock, "global") &&
 	    strcmp(clock, "uptime") && strcmp(clock, "perf") &&
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] trace-cmd record: Set clock to TSC when connecting to a proxy with kvm
  2022-05-24  1:50 [PATCH 0/2] trace-cmd: Fix clock setting of agent proxy Steven Rostedt
  2022-05-24  1:50 ` [PATCH 1/2] trace-cmd library: Keep USECS flag if TSC multiplier is set Steven Rostedt
@ 2022-05-24  1:50 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-05-24  1:50 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the time synchronization protocol for the recorder to a agent proxy is
KVM, then it means that the TSC clock must be used. Force it when this is
discovered.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index ce20402af7c2..169836bd493c 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3849,16 +3849,29 @@ static int open_guest_fifos(const char *guest, int **fds)
 	return i;
 }
 
+static bool clock_is_supported(struct tracefs_instance *instance, const char *clock);
+
 static int host_tsync(struct common_record_context *ctx,
 		      struct buffer_instance *instance,
 		      unsigned int tsync_port, char *proto)
 {
+	struct buffer_instance *iter_instance;
 	int guest_id = -1;
 	int fd;
 
 	if (!proto)
 		return -1;
 
+	/* If connecting to a proxy, the clock may still need to be set */
+	if (strcmp(proto, "kvm") == 0 &&
+	    clock_is_supported(NULL, TSC_CLOCK)) {
+		ctx->clock = TSC_CLOCK;
+		for_all_instances(iter_instance) {
+			iter_instance->clock = TSC_CLOCK;
+			set_clock(ctx, iter_instance);
+		}
+	}
+
 	if (is_network(instance)) {
 		fd = connect_port(instance->name, tsync_port,
 				  instance->port_type);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-24  1:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24  1:50 [PATCH 0/2] trace-cmd: Fix clock setting of agent proxy Steven Rostedt
2022-05-24  1:50 ` [PATCH 1/2] trace-cmd library: Keep USECS flag if TSC multiplier is set Steven Rostedt
2022-05-24  1:50 ` [PATCH 2/2] trace-cmd record: Set clock to TSC when connecting to a proxy with kvm Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).