Skip to contentSkip to conversation

trace-cmd [POC]: Timestamps sync using PTP-like algorithm, relying on vsock events.

PATCH Superseded Tzvetomir Stoyanov 3 participants 17 messages Jan 16, 2019 – Jan 22, 2019

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

cover trace-cmd [POC]: Timestamps sync using PTP-like algorithm, relying on vsock events.

This patch series is a POC for timestamps sync between guest and host machines. It implelents PTP-like algorithm, using vsock events for getting the current time. Best results are achieved when "boot" clock is used on both host and guest when recording the events.
The patch series depends on Slavomir's changes, introduced by the patch series "Add VM kernel tracing over vsock sockets"

Tzvetomir Stoyanov (7):
trace-cmd: Implemented new lib API: tracecmd_local_events_system()
trace-cmd: Added new option in trace.dat file for negative time
offsets
trace-cmd: Fixed logic in tracecmd_read_page_record()
trace-cmd: Added implementation of htonll() and ntohll()
trace-cmd: Added user configured clock to the record context
trace-cmd: Refactored make_instances() and tracecmd_remove_instances() trace-cmd [POC]: Implemented timestamps synch PTP-like algorithm,
using vsock events.

 include/trace-cmd/trace-cmd.h  |   7 +
 lib/trace-cmd/trace-input.c    |  19 +-
 lib/trace-cmd/trace-util.c     |  89 +++++---
 tracecmd/include/trace-local.h |   5 +
 tracecmd/include/trace-msg.h   |  10 +
 tracecmd/trace-listen.c        |   3 +
 tracecmd/trace-msg.c           | 311 ++++++++++++++++++++++++++-
 tracecmd/trace-record.c        | 380 +++++++++++++++++++++++++--------
 8 files changed, 685 insertions(+), 139 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 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 subsystem.

---
 include/trace-cmd/trace-cmd.h |  2 +
 lib/trace-cmd/trace-util.c    | 89 ++++++++++++++++++++++-------------
 2 files changed, 59 insertions(+), 32 deletions(-)
include/trace-cmd/trace-cmd.h +2 -0
index 238e16b..c79fc63 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_name);
 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 +57 -32

107 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/7] trace-cmd: Implemented new lib API: tracecmd_local_events_system()

lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven · line 1164

Quoted 12 lines · On Wed, 16 Jan 2019 21:18:32 +0200 Tzvetomir Stoyanov <[email protected]>…
lib/trace-cmd/trace-util.c +4 -1
+static int tracecmd_fill_local_events_system(const char *tracing_dir,
+					     struct tep_handle *pevent,
+					     char *sys_name)
 {
 	struct dirent *dent;
 	char *events_dir;
@@ -1189,7 +1161,8 @@ int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven
 		if (strcmp(name, ".") == 0 ||
 		    strcmp(name, "..") == 0)
 			continue;
-
+		if (sys_name && strcmp(name, sys_name))

Small nit. Please compare as: strcmp(name, sys_name) != 0

This to make it look like it is not equal. One of the flaws of the "strcmp" is that a match is false and a non match is true, which makes it likely to be done wrong :-p

If you noticed, the strcmp() in the previous if uses "== 0" as a way to say "this is true on match"

lib/trace-cmd/trace-util.c int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven · line 1195

Quoted 11 lines
lib/trace-cmd/trace-util.c +4 -0
+			continue;
 		sys = append_file(events_dir, name);
 		ret = stat(sys, &st);
 		if (ret < 0 || !S_ISDIR(st.st_mode)) {
@@ -1217,6 +1190,58 @@ int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven
 	return ret;
 }
 
+/**
+ * tracecmd_local_events_system - create a tep from the
+ * events of the specified subsystem.

Keep the above on one line, even though it breaks the 80 character limit.

-- Steve

Quoted 24 lines
lib/trace-cmd/trace-util.c +23 -0
+ *
+ * @tracing_dir: The directory that contains the events.
+ * @sys_name: Name of the subsystem, to load events from
+ *
+ * Returns a tep structure that contains the tep local to
+ * the system.
+ */
+struct tep_handle *tracecmd_local_events_system(const char *tracing_dir,
+						char *sys_name)
+{
+	struct tep_handle *tep = NULL;
+
+	tep = tep_alloc();
+	if (!tep)
+		return NULL;
+
+	if (tracecmd_fill_local_events_system(tracing_dir, tep, sys_name)) {
+		tep_free(tep);
+		tep = NULL;
+	}
+
+	return tep;
+}
 
#3 lore raw

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

In reply to Tzvetomir Stoyanov

When synchronizing timestamps between different machines, there are cases when the time offset is negative. A new option, TRACECMD_OPTION_OFFSET_N, is added in trace.dat file for such use cases. The format is the same as TRACECMD_OPTION_OFFSET, but the value is interpreted as negative integer.

---
 include/trace-cmd/trace-cmd.h |   1 +
 lib/trace-cmd/trace-input.c   |   7 +-
 tracecmd/trace-record.c       | 123 +++++++++++++++++-----------------
 3 files changed, 70 insertions(+), 61 deletions(-)
include/trace-cmd/trace-cmd.h +1 -0
index c79fc63..d0bddfc 100644
@@ -82,6 +82,7 @@ enum {
 	TRACECMD_OPTION_HOOK,
 	TRACECMD_OPTION_OFFSET,
 	TRACECMD_OPTION_CPUCOUNT,
+	TRACECMD_OPTION_OFFSET_N,
 };
 
 enum {
lib/trace-cmd/trace-input.c +6 -1
index b628570..de15d4b 100644
@@ -2151,6 +2151,7 @@ static int handle_options(struct tracecmd_input *handle)
 			handle->ts_offset += offset;
 			break;
 		case TRACECMD_OPTION_OFFSET:
+		case TRACECMD_OPTION_OFFSET_N:
 			/*
 			 * Similar to date option, but just adds an
 			 * offset to the timestamp.
@@ -2158,7 +2159,11 @@ static int handle_options(struct tracecmd_input *handle)
 			if (handle->flags & TRACECMD_FL_IGNORE_DATE)
 				break;
 			offset = strtoll(buf, NULL, 0);
-			handle->ts_offset += offset;
+			if (option == TRACECMD_OPTION_OFFSET_N) {
+				if (handle->ts_offset > offset)
+					handle->ts_offset -= offset;
+			} else
+				handle->ts_offset += offset;
 			break;
 		case TRACECMD_OPTION_CPUSTAT:
 			buf[size-1] = '\n';
tracecmd/trace-record.c +63 -60

147 lines not on this page · raw message

Signature · 1 line
2.20.1
#4 lore raw

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

Quoted 13 lines · On Wed, 16 Jan 2019 21:18:33 +0200 Tzvetomir Stoyanov <[email protected]>…
lib/trace-cmd/trace-input.c +1 -0
index b628570..de15d4b 100644
@@ -2151,6 +2151,7 @@ static int handle_options(struct tracecmd_input *handle)
 			handle->ts_offset += offset;
 			break;
 		case TRACECMD_OPTION_OFFSET:
+		case TRACECMD_OPTION_OFFSET_N:
 			/*
 			 * Similar to date option, but just adds an
 			 * offset to the timestamp.

lib/trace-cmd/trace-input.c static int handle_options(struct tracecmd_input *handle) · line 2162

Quoted 5 lines
lib/trace-cmd/trace-input.c +1 -1
@@ -2158,7 +2159,11 @@ static int handle_options(struct tracecmd_input *handle)
 			if (handle->flags & TRACECMD_FL_IGNORE_DATE)
 				break;
 			offset = strtoll(buf, NULL, 0);
-			handle->ts_offset += offset;
+			if (option == TRACECMD_OPTION_OFFSET_N) {

Instead of adding a new option, couldn't we just make option a "long long" and save a negative number in the trace.dat file? strtoll() should be able to handle it.

-- Steve

Quoted 7 lines
lib/trace-cmd/trace-input.c +4 -0
+				if (handle->ts_offset > offset)
+					handle->ts_offset -= offset;
+			} else
+				handle->ts_offset += offset;
 			break;
 		case TRACECMD_OPTION_CPUSTAT:
 			buf[size-1] = '\n';
#5 lore raw

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

Quoted 18 lines · Steven Rostedt
Quoted 14 lines · On Wed, 16 Jan 2019 21:18:33 +0200 Tzvetomir Stoyanov <[email protected]>…
lib/trace-cmd/trace-input.c +1 -0
index b628570..de15d4b 100644
@@ -2151,6 +2151,7 @@ static int handle_options(struct tracecmd_input *handle)
                      handle->ts_offset += offset;
                      break;
              case TRACECMD_OPTION_OFFSET:
+             case TRACECMD_OPTION_OFFSET_N:
                      /*
                       * Similar to date option, but just adds an
                       * offset to the timestamp.
@@ -2158,7 +2159,11 @@ static int handle_options(struct tracecmd_input *handle)
                      if (handle->flags & TRACECMD_FL_IGNORE_DATE)
Quoted 8 lines

lib/trace-cmd/trace-input.c static int handle_options(struct tracecmd_input *handle) · line 2162

Quoted 4 lines
lib/trace-cmd/trace-input.c +1 -1
                              break;
                      offset = strtoll(buf, NULL, 0);
-                     handle->ts_offset += offset;
+                     if (option == TRACECMD_OPTION_OFFSET_N) {

Instead of adding a new option, couldn't we just make option a "long long" and save a negative number in the trace.dat file? strtoll() should be able to handle it.

Yes, we can make in long long, but this will break the backward compatibility. The old versions of trace-cmd will get confused, as they will cast it to unsigned.
That's why I added a new option, in this way old trace-cmd versions will not read the
negative offset at all.

Quoted 11 lines

-- Steve

Quoted 7 lines
lib/trace-cmd/trace-input.c +4 -0
+                             if (handle->ts_offset > offset)
+                                     handle->ts_offset -= offset;
+                     } else
+                             handle->ts_offset += offset;
                      break;
              case TRACECMD_OPTION_CPUSTAT:
                      buf[size-1] = '\n';
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
#6 lore raw

PATCH 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.

---
 lib/trace-cmd/trace-input.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/trace-cmd/trace-input.c +8 -4
index de15d4b..c2b993a 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
#7 lore raw

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

Quoted 3 lines · On Wed, 16 Jan 2019 21:18:34 +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.

Please explain what you are fixing. In other words, what was wrong with the current logic?

-- Steve

Quoted 3 lines

---

#8 lore raw

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

Quoted 10 lines · Steven Rostedt
Quoted 3 lines · On Wed, 16 Jan 2019 21:18:34 +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.

Please explain what you are fixing. In other words, what was wrong with the current logic?

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. As I can understand, kbuffer_next_event() reads the event
after the one pointed by last_record. In my use case I search for a series of few events,
tracecmd_read_page_record() returns the first one (when I pass last_record=NULL), and always fails on
the second one with the error "tracecmd_read_page_record: could not find last_record". I use a gdb to figure out
what happens there.

Quoted 6 lines

-- Steve

Quoted 3 lines

---

Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
#9 lore raw

PATCH 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
#10 lore raw

PATCH 5/7 trace-cmd: Added user configured clock to the record context

In reply to Tzvetomir Stoyanov

Store the user configured clock (if any) in the record context, struct common_record_context. The clock is going to be used when synchronizing timestamps with remote tracing machine.

---
 tracecmd/trace-record.c | 2 ++
 1 file changed, 2 insertions(+)
tracecmd/trace-record.c +2 -0
index f7349eb..900d0d4 100644
@@ -227,6 +227,7 @@ struct common_record_context {
 	int topt;
 	int do_child;
 	int run_command;
+	char *clock;
 };
 
 static void add_reset_file(const char *file, const char *val, int prio)
@@ -5183,6 +5184,7 @@ static void parse_record_options(int argc,
 			break;
 		case 'C':
 			ctx->instance->clock = optarg;
+			ctx->clock = optarg;
 			break;
 		case 'v':
 			neg_event = 1;
Signature · 1 line
2.20.1
#11 lore raw

Re: [PATCH 5/7] trace-cmd: Added user configured clock to the record context

Quoted 20 lines · On Wed, 16 Jan 2019 21:18:36 +0200 Tzvetomir Stoyanov <[email protected]>…

Store the user configured clock (if any) in the record context, struct common_record_context. The clock is going to be used when synchronizing timestamps with remote tracing machine.

---
 tracecmd/trace-record.c | 2 ++
 1 file changed, 2 insertions(+)
tracecmd/trace-record.c +1 -0
index f7349eb..900d0d4 100644
@@ -227,6 +227,7 @@ struct common_record_context {
 	int topt;
 	int do_child;
 	int run_command;
+	char *clock;
 };
 
 static void add_reset_file(const char *file, const char *val, int prio)

tracecmd/trace-record.c static void parse_record_options(int argc, · line 5187

Quoted 4 lines
tracecmd/trace-record.c +1 -0
@@ -5183,6 +5184,7 @@ static void parse_record_options(int argc,
 			break;
 		case 'C':
 			ctx->instance->clock = optarg;
+			ctx->clock = optarg;

Hmm, this can cause an issue. The first thing I have to ask is, why can't we use ctx->instance->clock. I'm sure the answer is that we are adding more than one clock. But this begs the question, which clock should be use, if there are more than one clock to add?

I think this patch is not needed. In the last patch, test if ctx->instance->clock exists, and if not, we search the other instances for a clock to use. Or something else that doesn't make which clock to use ambiguous.

-- Steve

Quoted 3 lines
tracecmd/trace-record.c +0 -0
 			break;
 		case 'v':
 			neg_event = 1;
#12 lore raw

Re: [PATCH 5/7] trace-cmd: Added user configured clock to the record context

Quoted 34 lines · Steven Rostedt
Quoted 20 lines · On Wed, 16 Jan 2019 21:18:36 +0200 Tzvetomir Stoyanov <[email protected]>…

Store the user configured clock (if any) in the record context, struct common_record_context. The clock is going to be used when synchronizing timestamps with remote tracing machine.

---
 tracecmd/trace-record.c | 2 ++
 1 file changed, 2 insertions(+)
tracecmd/trace-record.c +1 -0
index f7349eb..900d0d4 100644
@@ -227,6 +227,7 @@ struct common_record_context {
      int topt;
      int do_child;
      int run_command;
+     char *clock;
 };
 
 static void add_reset_file(const char *file, const char *val, int prio)

tracecmd/trace-record.c static void parse_record_options(int argc, · line 5187

Quoted 4 lines
tracecmd/trace-record.c +1 -0
@@ -5183,6 +5184,7 @@ static void parse_record_options(int argc,
                      break;
              case 'C':
                      ctx->instance->clock = optarg;
+                     ctx->clock = optarg;

Hmm, this can cause an issue. The first thing I have to ask is, why can't we use ctx->instance->clock. I'm sure the answer is that we are adding more than one clock. But this begs the question, which clock should be use, if there are more than one clock to add?

Quoted 4 lines

I think this patch is not needed. In the last patch, test if ctx->instance->clock exists, and if not, we search the other instances for a clock to use. Or something else that doesn't make which clock to use ambiguous.

Ok, I'll remove it and will search for the first ctx->instance->clock instead. Current algorithm assumes that only one clock is used, and it is the same in both
host and guest contexts. We should think how to handle the case with multiple instances,
each one with different clock. I do not know, how instances are written in the trace.dat file,
is there a different time offset option in the file, per instance ?

Quoted 7 lines

-- Steve

Quoted 3 lines
tracecmd/trace-record.c +0 -0
                      break;
              case 'v':
                      neg_event = 1;
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
#13 lore raw

Re: [PATCH 5/7] trace-cmd: Added user configured clock to the record context

Quoted 41 lines · Tzvetomir Stoyanov
Quoted 34 lines · Steven Rostedt
Quoted 20 lines · On Wed, 16 Jan 2019 21:18:36 +0200 Tzvetomir Stoyanov <[email protected]>…

Store the user configured clock (if any) in the record context, struct common_record_context. The clock is going to be used when synchronizing timestamps with remote tracing machine.

---
 tracecmd/trace-record.c | 2 ++
 1 file changed, 2 insertions(+)
tracecmd/trace-record.c +1 -0
index f7349eb..900d0d4 100644
@@ -227,6 +227,7 @@ struct common_record_context {
      int topt;
      int do_child;
      int run_command;
+     char *clock;
 };
 
 static void add_reset_file(const char *file, const char *val, int prio)

tracecmd/trace-record.c static void parse_record_options(int argc, · line 5187

Quoted 4 lines
tracecmd/trace-record.c +1 -0
@@ -5183,6 +5184,7 @@ static void parse_record_options(int argc,
                      break;
              case 'C':
                      ctx->instance->clock = optarg;
+                     ctx->clock = optarg;

Hmm, this can cause an issue. The first thing I have to ask is, why can't we use ctx->instance->clock. I'm sure the answer is that we are adding more than one clock. But this begs the question, which clock should be use, if there are more than one clock to add?

Quoted 4 lines

I think this patch is not needed. In the last patch, test if ctx->instance->clock exists, and if not, we search the other instances for a clock to use. Or something else that doesn't make which clock to use ambiguous.

Quoted 8 lines

Ok, I'll remove it and will search for the first ctx->instance->clock instead. Current algorithm assumes that only one clock is used, and it is the same in both
host and guest contexts. We should think how to handle the case with multiple instances,
each one with different clock. I do not know, how instances are written in the trace.dat file,
is there a different time offset option in the file, per instance ?

Each instance goes into a separate file (by default "trace-$(name).dat").

For guest instances, this command

$ trace-cmd record -A guest0 -e irq -e sched -A guest1 -e irq -e sched

creates two trace files:
-rw-r--r-- 1 4.8M Jan 22 16:06 trace-guest0.dat
-rw-r--r-- 1 7.4M Jan 22 16:06 trace-guest1.dat

Cheers,

- Slavi

#14 lore raw

PATCH 6/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 900d0d4..4c3df3d 100644
@@ -4260,49 +4260,57 @@ static void clear_func_filters(void)
 	}
 }
 
-static void make_instances(void)
+static void make_one_instances(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_instances(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
#15 lore raw

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

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

Quoted 10 lines · On Wed, 16 Jan 2019 21:18:37 +0200 Tzvetomir Stoyanov <[email protected]>…
tracecmd/trace-record.c +2 -1
@@ -4260,49 +4260,57 @@ static void clear_func_filters(void)
 	}
 }
 
-static void make_instances(void)
+static void make_one_instances(struct buffer_instance *instance)
 
+static void tracecmd_remove_one_instance(struct buffer_instance *instance)

I would just make the names non plural, and call them:

make_one_instance()
tracecmd_remove_instance()

-- Steve

#16 lore raw

PATCH 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 |   5 +
 tracecmd/trace-listen.c        |   3 +
 tracecmd/trace-msg.c           | 311 +++++++++++++++++++++++++++++++--
 tracecmd/trace-record.c        | 201 ++++++++++++++++++++-
 5 files changed, 505 insertions(+), 19 deletions(-)
include/trace-cmd/trace-cmd.h +4 -0
index d0bddfc..8fb5ee9 100644
@@ -352,6 +352,10 @@ int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
 				 int *nr_cpus, int *page_size,
 				 unsigned int **ports);
 
+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 +5 -0
index 823d323..c502c70 100644
@@ -225,6 +225,11 @@ 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);
+void clock_synch_disable(int fd, struct buffer_instance *instance);
+struct tep_handle *clock_synch_get_tep(struct buffer_instance *instance);
+
 /* 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-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 +300 -11

361 lines not on this page · raw message

tracecmd/trace-record.c +193 -8

255 lines not on this page · raw message

Signature · 1 line
2.20.1