Skip to contentSkip to conversation

trace-cmd: Timetamps sync using PTP-like algorithm, relying on vsock events.

PATCH Superseded Tzvetomir Stoyanov 2 participants 13 messages Feb 8, 2019

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v3 cover trace-cmd: Timetamps sync using PTP-like algorithm, relying on vsock events.

[ V3 changes:
- Removed any magic constants, used in the PTP-like algorithm, as Slavomir Kaslev suggested.
- Implemented new algorithm, based on mapping kvm_exit events in host context to vsock_send events in guest context, suggested by Steven Rostedt.
]

This patch series is a POC for timestamps sync between guest and host machines. It implelents two algorithms:
- PTP-like algorithm, using vsock events for getting the current time.
- algorithm based on mapping kvm_exit events in host context to vsock_send events in guest context.
Both algorithms run simultaneously, so the results can be easily compared. The "#if" directive at the end of tracecmd_msg_snd_time_sync() can be used to swith between the results of the both algorithms - which one of them to be written in the trace file.

The patch series depends on Slavomir's changes, introduced by the patch series "Add VM kernel tracing over vsockets and FIFOs"

Tzvetomir Stoyanov (7):
trace-cmd: Implemented new lib API: tracecmd_local_events_system()
trace-cmd: Added support for negative time offsets in trace.dat file
trace-cmd: Fixed logic in tracecmd_read_page_record()
trace-cmd: Added implementation of htonll() and ntohll()
trace-cmd: Refactored make_instances() and tracecmd_remove_instances()
trace-cmd: Find and store pids of tasks, which run virtual CPUs of
given VM
trace-cmd [POC]: Implemented timestamps synch PTP-like algorithm,
using vsock events.

 include/trace-cmd/trace-cmd.h  |   8 +-
 lib/trace-cmd/trace-input.c    |  18 +-
 lib/trace-cmd/trace-util.c     |  99 ++++--
 tracecmd/include/trace-local.h |   9 +
 tracecmd/include/trace-msg.h   |  10 +
 tracecmd/trace-listen.c        |   3 +
 tracecmd/trace-msg.c           | 543 ++++++++++++++++++++++++++++++++-
 tracecmd/trace-read.c          |   4 +-
 tracecmd/trace-record.c        | 465 ++++++++++++++++++++++------
 9 files changed, 1020 insertions(+), 139 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/7 trace-cmd: Implemented new lib API: tracecmd_local_events_system()

The new tracecmd lib API tracecmd_local_events_system() creates a tep handler and initializes it with the events of the specified subsystems.

---
 include/trace-cmd/trace-cmd.h |  2 +
 lib/trace-cmd/trace-util.c    | 99 +++++++++++++++++++++++------------
 2 files changed, 68 insertions(+), 33 deletions(-)
include/trace-cmd/trace-cmd.h +2 -0
index 84dc95a..3d72430 100644
@@ -32,6 +32,8 @@ void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pe
 char **tracecmd_event_systems(const char *tracing_dir);
 char **tracecmd_system_events(const char *tracing_dir, const char *system);
 struct tep_handle *tracecmd_local_events(const char *tracing_dir);
+struct tep_handle *tracecmd_local_events_system(const char *tracing_dir,
+						char **sys_names);
 int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *pevent);
 char **tracecmd_local_plugins(const char *tracing_dir);
 
lib/trace-cmd/trace-util.c +66 -33

122 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH v3 2/7 trace-cmd: Added support for negative time offsets in trace.dat file

In reply to Tzvetomir Stoyanov

When synchronizing timestamps between different machines, there are cases when the time offset is negative. This patch changes the way time offset is written and read from trace.dat file - as signed decimal, instead of hex.

---
 include/trace-cmd/trace-cmd.h |   2 +-
 lib/trace-cmd/trace-input.c   |   6 +-
 tracecmd/trace-read.c         |   4 +-
 tracecmd/trace-record.c       | 120 +++++++++++++++++-----------------
 4 files changed, 66 insertions(+), 66 deletions(-)
include/trace-cmd/trace-cmd.h +1 -1
index 3d72430..b2ff6f9 100644
@@ -126,7 +126,7 @@ int tracecmd_is_buffer_instance(struct tracecmd_input *handle);
 void tracecmd_create_top_instance(char *name);
 void tracecmd_remove_instances(void);
 
-void tracecmd_set_ts_offset(struct tracecmd_input *handle, unsigned long long offset);
+void tracecmd_set_ts_offset(struct tracecmd_input *handle, long long offset);
 void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz);
 
 void tracecmd_print_events(struct tracecmd_input *handle, const char *regex);
lib/trace-cmd/trace-input.c +3 -3
index b628570..33ad7d1 100644
@@ -100,7 +100,7 @@ struct tracecmd_input {
 	bool			read_page;
 	bool			use_pipe;
 	struct cpu_data 	*cpu_data;
-	unsigned long long	ts_offset;
+	long long		ts_offset;
 	double			ts2secs;
 	char *			cpustats;
 	char *			uname;
@@ -2091,7 +2091,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu)
 }
 
 void tracecmd_set_ts_offset(struct tracecmd_input *handle,
-			    unsigned long long offset)
+			    long long offset)
 {
 	handle->ts_offset = offset;
 }
@@ -2108,7 +2108,7 @@ void tracecmd_set_ts2secs(struct tracecmd_input *handle,
 
 static int handle_options(struct tracecmd_input *handle)
 {
-	unsigned long long offset;
+	long long offset;
 	unsigned short option;
 	unsigned int size;
 	char *cpustats = NULL;
tracecmd/trace-read.c +2 -2
index 804022a..e309672 100644
@@ -58,7 +58,7 @@ static struct list_head handle_list;
 struct input_files {
 	struct list_head	list;
 	const char		*file;
-	unsigned long long	tsoffset;
+	long long		tsoffset;
 	unsigned long long	ts2secs;
 };
 static struct list_head input_files;
@@ -1413,7 +1413,7 @@ void trace_report (int argc, char **argv)
 	struct input_files *inputs;
 	struct handle_list *handles;
 	enum output_type otype;
-	unsigned long long tsoffset = 0;
+	long long tsoffset = 0;
 	unsigned long long ts2secs = 0;
 	unsigned long long ts2sc;
 	int show_stat = 0;
tracecmd/trace-record.c +60 -60

144 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH v3 2/7] trace-cmd: Added support for negative time offsets in trace.dat file

Quoted 11 lines · On Fri, 8 Feb 2019 15:49:13 +0200 Tzvetomir Stoyanov <[email protected]>…

When synchronizing timestamps between different machines, there are cases when the time offset is negative. This patch changes the way time offset is written and read from trace.dat file - as signed decimal, instead of hex.

---
 include/trace-cmd/trace-cmd.h |   2 +-
 lib/trace-cmd/trace-input.c   |   6 +-
 tracecmd/trace-read.c         |   4 +-
 tracecmd/trace-record.c       | 120 +++++++++++++++++-----------------
 4 files changed, 66 insertions(+), 66 deletions(-)

Can you break this patch into two. One that moves the code around, and the other that makes the changes. It's easier to review and see what changed that way.

Thanks!

-- Steve

Quoted 219 lines
include/trace-cmd/trace-cmd.h +1 -1
index 3d72430..b2ff6f9 100644
@@ -126,7 +126,7 @@ int tracecmd_is_buffer_instance(struct tracecmd_input *handle);
 void tracecmd_create_top_instance(char *name);
 void tracecmd_remove_instances(void);
 
-void tracecmd_set_ts_offset(struct tracecmd_input *handle, unsigned long long offset);
+void tracecmd_set_ts_offset(struct tracecmd_input *handle, long long offset);
 void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz);
 
 void tracecmd_print_events(struct tracecmd_input *handle, const char *regex);
lib/trace-cmd/trace-input.c +3 -3
index b628570..33ad7d1 100644
@@ -100,7 +100,7 @@ struct tracecmd_input {
 	bool			read_page;
 	bool			use_pipe;
 	struct cpu_data 	*cpu_data;
-	unsigned long long	ts_offset;
+	long long		ts_offset;
 	double			ts2secs;
 	char *			cpustats;
 	char *			uname;
@@ -2091,7 +2091,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu)
 }
 
 void tracecmd_set_ts_offset(struct tracecmd_input *handle,
-			    unsigned long long offset)
+			    long long offset)
 {
 	handle->ts_offset = offset;
 }
@@ -2108,7 +2108,7 @@ void tracecmd_set_ts2secs(struct tracecmd_input *handle,
 
 static int handle_options(struct tracecmd_input *handle)
 {
-	unsigned long long offset;
+	long long offset;
 	unsigned short option;
 	unsigned int size;
 	char *cpustats = NULL;
tracecmd/trace-read.c +2 -2
index 804022a..e309672 100644
@@ -58,7 +58,7 @@ static struct list_head handle_list;
 struct input_files {
 	struct list_head	list;
 	const char		*file;
-	unsigned long long	tsoffset;
+	long long		tsoffset;
 	unsigned long long	ts2secs;
 };
 static struct list_head input_files;
@@ -1413,7 +1413,7 @@ void trace_report (int argc, char **argv)
 	struct input_files *inputs;
 	struct handle_list *handles;
 	enum output_type otype;
-	unsigned long long tsoffset = 0;
+	long long tsoffset = 0;
 	unsigned long long ts2secs = 0;
 	unsigned long long ts2sc;
 	int show_stat = 0;
tracecmd/trace-record.c +60 -60
index 43d782e..01b360a 100644
@@ -203,6 +203,12 @@ enum trace_cmd {
 	CMD_record_agent,
 };
 
+enum {
+	DATA_FL_NONE		= 0,
+	DATA_FL_DATE		= 1,
+	DATA_FL_OFFSET		= 2,
+};
+
 struct common_record_context {
 	enum trace_cmd curr_cmd;
 	struct buffer_instance *instance;
@@ -3234,7 +3240,60 @@ again:
 	return msg_handle;
 }
 
-static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx);
+static void add_option_hooks(struct tracecmd_output *handle)
+{
+	struct hook_list *hook;
+	int len;
+
+	for (hook = hooks; hook; hook = hook->next) {
+		len = strlen(hook->hook);
+		tracecmd_add_option(handle, TRACECMD_OPTION_HOOK,
+				    len + 1, hook->hook);
+	}
+}
+
+static void add_uname(struct tracecmd_output *handle)
+{
+	struct utsname buf;
+	char *str;
+	int len;
+	int ret;
+
+	ret = uname(&buf);
+	/* if this fails for some reason, just ignore it */
+	if (ret < 0)
+		return;
+
+	len = strlen(buf.sysname) + strlen(buf.nodename) +
+		strlen(buf.release) + strlen(buf.machine) + 4;
+	str = malloc(len);
+	if (!str)
+		return;
+	sprintf(str, "%s %s %s %s", buf.sysname, buf.nodename, buf.release, buf.machine);
+	tracecmd_add_option(handle, TRACECMD_OPTION_UNAME, len, str);
+	free(str);
+}
+
+static void add_options(struct tracecmd_output *handle,
+			struct common_record_context *ctx)
+{
+	int type = 0;
+
+	if (ctx->date2ts) {
+		if (ctx->data_flags & DATA_FL_DATE)
+			type = TRACECMD_OPTION_DATE;
+		else if (ctx->data_flags & DATA_FL_OFFSET)
+			type = TRACECMD_OPTION_OFFSET;
+	}
+
+	if (type)
+		tracecmd_add_option(handle, type,
+				    strlen(ctx->date2ts)+1, ctx->date2ts);
+
+	tracecmd_add_option(handle, TRACECMD_OPTION_TRACECLOCK, 0, NULL);
+	add_option_hooks(handle);
+	add_uname(handle);
+}
 
 static struct tracecmd_msg_handle *
 setup_connection(struct buffer_instance *instance, struct common_record_context *ctx)
@@ -3505,40 +3564,6 @@ add_buffer_stat(struct tracecmd_output *handle, struct buffer_instance *instance
 				    instance->s_save[i].buffer);
 }
 
-static void add_option_hooks(struct tracecmd_output *handle)
-{
-	struct hook_list *hook;
-	int len;
-
-	for (hook = hooks; hook; hook = hook->next) {
-		len = strlen(hook->hook);
-		tracecmd_add_option(handle, TRACECMD_OPTION_HOOK,
-				    len + 1, hook->hook);
-	}
-}
-
-static void add_uname(struct tracecmd_output *handle)
-{
-	struct utsname buf;
-	char *str;
-	int len;
-	int ret;
-
-	ret = uname(&buf);
-	/* if this fails for some reason, just ignore it */
-	if (ret < 0)
-		return;
-
-	len = strlen(buf.sysname) + strlen(buf.nodename) +
-		strlen(buf.release) + strlen(buf.machine) + 4;
-	str = malloc(len);
-	if (!str)
-		return;
-	sprintf(str, "%s %s %s %s", buf.sysname, buf.nodename, buf.release, buf.machine);
-	tracecmd_add_option(handle, TRACECMD_OPTION_UNAME, len, str);
-	free(str);
-}
-
 static void print_stat(struct buffer_instance *instance)
 {
 	int cpu;
@@ -3553,31 +3578,6 @@ static void print_stat(struct buffer_instance *instance)
 		trace_seq_do_printf(&instance->s_print[cpu]);
 }
 
-enum {
-	DATA_FL_NONE		= 0,
-	DATA_FL_DATE		= 1,
-	DATA_FL_OFFSET		= 2,
-};
-
-static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx)
-{
-	int type = 0;
-
-	if (ctx->date2ts) {
-		if (ctx->data_flags & DATA_FL_DATE)
-			type = TRACECMD_OPTION_DATE;
-		else if (ctx->data_flags & DATA_FL_OFFSET)
-			type = TRACECMD_OPTION_OFFSET;
-	}
-
-	if (type)
-		tracecmd_add_option(handle, type, strlen(ctx->date2ts)+1, ctx->date2ts);
-
-	tracecmd_add_option(handle, TRACECMD_OPTION_TRACECLOCK, 0, NULL);
-	add_option_hooks(handle);
-	add_uname(handle);
-}
-
 static void write_guest_file(struct buffer_instance *instance)
 {
 	struct tracecmd_output *handle;
#4 lore raw

PATCH v3 3/7 trace-cmd: Fixed logic in tracecmd_read_page_record()

In reply to Tzvetomir Stoyanov

Fixed the logic in tracecmd_read_page_record() when searching for the next event in the event from the ring buffer. In the current logic, in the case when last_record is not NULL (we are searching for the second one) the check "if (ptr != last_record->data)" always fails.

---
 lib/trace-cmd/trace-input.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-input.c +8 -4
index 33ad7d1..5d64ca8 100644
@@ -1688,18 +1688,22 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size,
 			goto out_free;
 		}
 
-		do {
+		ptr = kbuffer_read_event(kbuf, &ts);
+		while (ptr < last_record->data) {
 			ptr = kbuffer_next_event(kbuf, NULL);
 			if (!ptr)
 				break;
-		} while (ptr < last_record->data);
+			if (ptr == last_record->data)
+				break;
+		}
 		if (ptr != last_record->data) {
 			warning("tracecmd_read_page_record: could not find last_record");
 			goto out_free;
 		}
-	}
+		ptr = kbuffer_next_event(kbuf, &ts);
+	} else
+		ptr = kbuffer_read_event(kbuf, &ts);
 
-	ptr = kbuffer_read_event(kbuf, &ts);
 	if (!ptr)
 		goto out_free;
 
Signature · 1 line
2.20.1
#5 lore raw

Re: [PATCH v3 3/7] trace-cmd: Fixed logic in tracecmd_read_page_record()

Quoted 6 lines · On Fri, 8 Feb 2019 15:49:14 +0200 Tzvetomir Stoyanov <[email protected]>…

Fixed the logic in tracecmd_read_page_record() when searching for the next event in the event from the ring buffer. In the current logic, in the case when last_record is not NULL (we are searching for the second one) the check "if (ptr != last_record->data)" always fails.

Nice catch.

Let's change the change log and subject:

Subject trace-cmd: Fix tracecmd_read_page_record() to read more than one event

The kbuffer_next_event() will return the next event on the sub buffer. If we pass in the last_record to tracecmd_read_page_record(), it initializes the sub buffer, and by calling kbuffer_next_event() (instead of kbuffer_read_event()), the second event on the sub buffer is returned. This causes the match of the last_record not to match if the last_record happens to be the first event on the sub buffer.

Quoted 23 lines
---
 lib/trace-cmd/trace-input.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-input.c +5 -2
index 33ad7d1..5d64ca8 100644
@@ -1688,18 +1688,22 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size,
 			goto out_free;
 		}
 
-		do {
+		ptr = kbuffer_read_event(kbuf, &ts);
+		while (ptr < last_record->data) {
 			ptr = kbuffer_next_event(kbuf, NULL);
 			if (!ptr)
 				break;
-		} while (ptr < last_record->data);
+			if (ptr == last_record->data)
+				break;
+		}

lib/trace-cmd/trace-input.c tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size, · line 1702

Quoted 10 lines
lib/trace-cmd/trace-input.c +3 -2
 		if (ptr != last_record->data) {
 			warning("tracecmd_read_page_record: could not find last_record");
 			goto out_free;
 		}
-	}
+		ptr = kbuffer_next_event(kbuf, &ts);
+	} else
+		ptr = kbuffer_read_event(kbuf, &ts);
 
-	ptr = kbuffer_read_event(kbuf, &ts);

Also, instead of the above "} else" clause, we can just move the

	ptr = kbuffer_read_event(kbuf, &ts);

before the if condition testing last_record.

-- Steve

Quoted 3 lines
lib/trace-cmd/trace-input.c +0 -0
 	if (!ptr)
 		goto out_free;
 
#6 lore raw

PATCH v3 4/7 trace-cmd: Added implementation of htonll() and ntohll()

In reply to Tzvetomir Stoyanov

Added implementation of htonll() and ntohll() as
macros, if they are not already defined.

---
 tracecmd/include/trace-msg.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tracecmd/include/trace-msg.h +10 -0
index b7fe10b..445f799 100644
@@ -15,4 +15,14 @@ extern unsigned int page_size;
 void plog(const char *fmt, ...);
 void pdie(const char *fmt, ...);
 
+#ifndef htonll
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htonll(x) __bswap_64(x)
+#define ntohll(x) __bswap_64(x)
+#else
+#define htonll(x) (x)
+#define ntohll(x) (x)
+#endif
+#endif
+
 #endif /* _TRACE_MSG_H_ */
Signature · 1 line
2.20.1
#7 lore raw

PATCH v3 5/7 trace-cmd: Refactored make_instances() and tracecmd_remove_instances()

In reply to Tzvetomir Stoyanov

In order to reuse the code which creates / deletes tracing instances, these two functions are refactotred. A new ones are implemented:
make_one_instances() and tracecmd_remove_one_instance().

---
 tracecmd/trace-record.c | 54 +++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 23 deletions(-)
tracecmd/trace-record.c +31 -23
index 01b360a..e1ad797 100644
@@ -4304,49 +4304,57 @@ static void clear_func_filters(void)
 	}
 }
 
-static void make_instances(void)
+static void make_one_instance(struct buffer_instance *instance)
 {
-	struct buffer_instance *instance;
 	struct stat st;
 	char *path;
 	int ret;
 
+	path = get_instance_dir(instance);
+	ret = stat(path, &st);
+	if (ret < 0) {
+		ret = mkdir(path, 0777);
+		if (ret < 0)
+			die("mkdir %s", path);
+	} else
+		/* Don't delete instances that already exist */
+		instance->flags |= BUFFER_FL_KEEP;
+	tracecmd_put_tracing_file(path);
+
+}
+
+static void make_instances(void)
+{
+	struct buffer_instance *instance;
+
 	for_each_instance(instance) {
 		if (instance->flags & BUFFER_FL_GUEST)
 			continue;
+		make_one_instance(instance);
+	}
+}
 
-		path = get_instance_dir(instance);
-		ret = stat(path, &st);
-		if (ret < 0) {
-			ret = mkdir(path, 0777);
-			if (ret < 0)
-				die("mkdir %s", path);
-		} else
-			/* Don't delete instances that already exist */
-			instance->flags |= BUFFER_FL_KEEP;
-		tracecmd_put_tracing_file(path);
+static void tracecmd_remove_one_instance(struct buffer_instance *instance)
+{
+	char *path;
+
+	if (instance->tracing_on_fd > 0) {
+		close(instance->tracing_on_fd);
+		instance->tracing_on_fd = 0;
 	}
+	path = get_instance_dir(instance);
+	tracecmd_put_tracing_file(path);
 }
 
 void tracecmd_remove_instances(void)
 {
 	struct buffer_instance *instance;
-	char *path;
-	int ret;
 
 	for_each_instance(instance) {
 		/* Only delete what we created */
 		if (instance->flags & (BUFFER_FL_KEEP | BUFFER_FL_GUEST))
 			continue;
-		if (instance->tracing_on_fd > 0) {
-			close(instance->tracing_on_fd);
-			instance->tracing_on_fd = 0;
-		}
-		path = get_instance_dir(instance);
-		ret = rmdir(path);
-		if (ret < 0)
-			die("rmdir %s", path);
-		tracecmd_put_tracing_file(path);
+		tracecmd_remove_one_instance(instance);
 	}
 }
 
Signature · 1 line
2.20.1
#8 lore raw

Re: [PATCH v3 5/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances()

Quoted 4 lines · On Fri, 8 Feb 2019 15:49:16 +0200 Tzvetomir Stoyanov <[email protected]>…

In order to reuse the code which creates / deletes tracing instances, these two functions are refactotred. A new ones are implemented:
make_one_instances() and tracecmd_remove_one_instance().

Note, I still prefer just dropping the "s":

make_instances() (more than one)
make_instance() (just one)

-- Steve

#9 lore raw

Re: [PATCH v3 5/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances()

In reply to Tzvetomir Stoyanov

tracecmd/trace-record.c static void clear_func_filters(void) · line 4343

Quoted 7 lines · On Fri, 8 Feb 2019 15:49:16 +0200 Tzvetomir Stoyanov <[email protected]>…
tracecmd/trace-record.c +7 -0
+static void tracecmd_remove_one_instance(struct buffer_instance *instance)
+{
+	char *path;
+
+	if (instance->tracing_on_fd > 0) {
+		close(instance->tracing_on_fd);
+		instance->tracing_on_fd = 0;

Also note that uninitialized file descriptors should be a negative number (-1), because zero is a valid descriptor value.

-- Steve

Quoted 5 lines
tracecmd/trace-record.c +2 -0
 	}
+	path = get_instance_dir(instance);
+	tracecmd_put_tracing_file(path);
 }
#10 lore raw

Re: [PATCH v3 5/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances()

Quoted 13 lines · On Fri, 8 Feb 2019 17:44:09 -0500 Steven Rostedt <[email protected]> wrote:

tracecmd/trace-record.c static void clear_func_filters(void) · line 4343

Quoted 7 lines · On Fri, 8 Feb 2019 15:49:16 +0200 Tzvetomir Stoyanov <[email protected]>…
tracecmd/trace-record.c +7 -0
+static void tracecmd_remove_one_instance(struct buffer_instance *instance)
+{
+	char *path;
+
+	if (instance->tracing_on_fd > 0) {
+		close(instance->tracing_on_fd);
+		instance->tracing_on_fd = 0;  

Also note that uninitialized file descriptors should be a negative number (-1), because zero is a valid descriptor value.

Bah, nevermind. Looks like I was a bit more lenient back in the day...

d56f30679 trace-record.c          (Steven Rostedt (Red Hat)    2013-03-06 11:31:39 -0500 1938)  /* OK, we keep zero for stdin */
d56f30679 trace-record.c          (Steven Rostedt (Red Hat)    2013-03-06 11:31:39 -0500 1939)  if (fd > 0)
6e7c1dd76 trace-record.c          (Steven Rostedt              2011-02-23 13:28:04 -0500 1940)          return fd;

;-)

-- Steve

#11 lore raw

PATCH v3 6/7 trace-cmd: Find and store pids of tasks, which run virtual CPUs of given VM

In reply to Tzvetomir Stoyanov

In order to match host and guest events, a mapping between guest VCPU and the host task, running this VCPU is needed. Extended existing struct guest to hold such mapping and added logic in read_qemu_guests() function to initialize it. Implemented a new internal API, get_guest_vcpu_pids(), to retrieve VCPU-task mapping for given VM.

---
 tracecmd/include/trace-local.h |  3 ++
 tracecmd/trace-record.c        | 57 +++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)
tracecmd/include/trace-local.h +3 -0
index 8bf7c8e..4f6e239 100644
@@ -233,6 +233,9 @@ void show_instance_file(struct buffer_instance *instance, const char *name);
 
 int count_cpus(void);
 
+#define VCPUS_MAX	256
+int *get_guest_vcpu_pids(int cid);
+
 /* No longer in event-utils.h */
 void __noreturn die(const char *fmt, ...); /* Can be overriden */
 void *malloc_or_die(unsigned int size); /* Can be overridden */
tracecmd/trace-record.c +56 -1

83 lines not on this page · raw message

Signature · 1 line
2.20.1
#12 lore raw

PATCH v3 7/7 trace-cmd [POC]: Implemented timestamps synch PTP-like algorithm, using vsock events.

In reply to Tzvetomir Stoyanov

This is a POC patch, implementing a PTP-like algorithm for syncing timestamps between host and guest machines, using vsock trace events to catch the host / guest time.

---
 include/trace-cmd/trace-cmd.h  |   4 +
 tracecmd/include/trace-local.h |   6 +
 tracecmd/trace-listen.c        |   3 +
 tracecmd/trace-msg.c           | 543 ++++++++++++++++++++++++++++++++-
 tracecmd/trace-record.c        | 234 +++++++++++++-
 5 files changed, 778 insertions(+), 12 deletions(-)
include/trace-cmd/trace-cmd.h +4 -0
index b2ff6f9..b54ff18 100644
@@ -351,6 +351,10 @@ int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
 				 int *nr_cpus, int *page_size,
 				 unsigned int **ports, bool *use_fifos);
 
+int tracecmd_msg_rcv_time_sync(struct tracecmd_msg_handle *msg_handle);
+int tracecmd_msg_snd_time_sync(struct tracecmd_msg_handle *msg_handle,
+			       char *clock_str, long long *toffset);
+
 int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle);
 
 /* --- Plugin handling --- */
tracecmd/include/trace-local.h +6 -0
index 4f6e239..424986c 100644
@@ -233,6 +233,12 @@ void show_instance_file(struct buffer_instance *instance, const char *name);
 
 int count_cpus(void);
 
+struct buffer_instance *clock_synch_enable(int fd, char *clock,
+					   int *tx_event, int *rx_event,
+					   int *kvm_exit);
+void clock_synch_disable(int fd, struct buffer_instance *instance);
+struct tep_handle *clock_synch_get_tep(struct buffer_instance *instance);
+void get_vsocket_params(int fd, int *lcid, int *lport, int *rcid, int *rport);
 #define VCPUS_MAX	256
 int *get_guest_vcpu_pids(int cid);
 
tracecmd/trace-listen.c +3 -0
index 9b50147..7783a68 100644
@@ -404,6 +404,9 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle)
 
 		msg_handle->version = V3_PROTOCOL;
 
+		/* time sync with the v3 client */
+		tracecmd_msg_rcv_time_sync(msg_handle);
+
 		/* read the CPU count, the page size, and options */
 		if ((pagesize = tracecmd_msg_initial_setting(msg_handle)) < 0)
 			goto out;
tracecmd/trace-msg.c +532 -11

593 lines not on this page · raw message

tracecmd/trace-record.c +233 -1

258 lines not on this page · raw message

Signature · 1 line
2.20.1