linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v24 06/10] trace-cmd: Add role parameter to timestamp synchronization plugins
Date: Fri,  9 Oct 2020 17:03:34 +0300	[thread overview]
Message-ID: <20201009140338.25260-7-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20201009140338.25260-1-tz.stoyanov@gmail.com>

Defined HOST and GUEST roles in timestamp synchronization context.
Some timestamp synchronization plugins may not support running in both
host and guest roles. This could happen in nested virtualization use
case, where the same plugin can be used as a host and as a guest.
Added logic to timestamp synchronization plugins to declare what roles
they support. Added logic to select plugin depending on supported roles
and currently requested role.

clocks. Added logic to timestamp synchronization plugins to declare what
ftace clocks they support. Added logic to select plugin depending on the
ftrace clock used in the current trace session and supported clocks.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h             | 10 ++++++++--
 lib/trace-cmd/include/trace-tsync-local.h | 10 +++++-----
 lib/trace-cmd/trace-timesync-ptp.c        |  2 ++
 lib/trace-cmd/trace-timesync.c            | 16 ++++++++++++----
 tracecmd/trace-record.c                   |  3 ++-
 tracecmd/trace-tsync.c                    |  3 ++-
 6 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 66b5d02b..f1068c49 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -442,6 +442,11 @@ enum{
 	TRACECMD_TIME_SYNC_CMD_STOP	= 2,
 };
 
+enum tracecmd_time_sync_role {
+	TRACECMD_TIME_SYNC_ROLE_HOST	= 0x01,
+	TRACECMD_TIME_SYNC_ROLE_GUEST	= 0x02
+};
+
 #define TRACECMD_TIME_SYNC_PROTO_PTP_WEIGHT	10
 
 struct tracecmd_time_sync {
@@ -455,8 +460,9 @@ struct tracecmd_time_sync {
 };
 
 void tracecmd_tsync_init(void);
-int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock);
-unsigned int tracecmd_tsync_proto_select(char *proto_mask, int words, char *clock);
+int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock, int role);
+unsigned int tracecmd_tsync_proto_select(char *proto_mask, int words, char *clock,
+					 enum tracecmd_time_sync_role role);
 bool tsync_proto_is_supported(unsigned int proto_id);
 void tracecmd_tsync_with_host(struct tracecmd_time_sync *tsync);
 void tracecmd_tsync_with_guest(struct tracecmd_time_sync *tsync);
diff --git a/lib/trace-cmd/include/trace-tsync-local.h b/lib/trace-cmd/include/trace-tsync-local.h
index 37c3597b..b79b102c 100644
--- a/lib/trace-cmd/include/trace-tsync-local.h
+++ b/lib/trace-cmd/include/trace-tsync-local.h
@@ -26,12 +26,12 @@ struct clock_sync_context {
 	unsigned int			remote_port;
 };
 
-int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
+int tracecmd_tsync_proto_register(unsigned int proto_id, int weight, int roles,
 				  int supported_clocks,
-				int (*init)(struct tracecmd_time_sync *),
-				int (*free)(struct tracecmd_time_sync *),
-				int (*calc)(struct tracecmd_time_sync *,
-					    long long *, long long *));
+				  int (*init)(struct tracecmd_time_sync *),
+				  int (*free)(struct tracecmd_time_sync *),
+				  int (*calc)(struct tracecmd_time_sync *,
+					      long long *, long long *));
 int tracecmd_tsync_proto_unregister(unsigned int proto_id);
 
 int ptp_clock_sync_register(void);
diff --git a/lib/trace-cmd/trace-timesync-ptp.c b/lib/trace-cmd/trace-timesync-ptp.c
index 51f17bca..07ce3b6e 100644
--- a/lib/trace-cmd/trace-timesync-ptp.c
+++ b/lib/trace-cmd/trace-timesync-ptp.c
@@ -678,6 +678,8 @@ int ptp_clock_sync_register(void)
 {
 	return tracecmd_tsync_proto_register(TRACECMD_TIME_SYNC_PROTO_PTP,
 					     TRACECMD_TIME_SYNC_PROTO_PTP_WEIGHT,
+					     TRACECMD_TIME_SYNC_ROLE_GUEST |
+					     TRACECMD_TIME_SYNC_ROLE_HOST,
 					     0,
 					     ptp_clock_sync_init,
 					     ptp_clock_sync_free,
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 47d34e2a..807fb6f5 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -25,6 +25,7 @@
 struct tsync_proto {
 	struct tsync_proto *next;
 	unsigned int proto_id;
+	enum tracecmd_time_sync_role roles;
 	int	weight;
 	int supported_clocks;
 
@@ -55,7 +56,7 @@ void tracecmd_tsync_init(void)
 	ptp_clock_sync_register();
 }
 
-int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
+int tracecmd_tsync_proto_register(unsigned int proto_id, int weight, int roles,
 				int supported_clocks,
 				int (*init)(struct tracecmd_time_sync *),
 				int (*free)(struct tracecmd_time_sync *),
@@ -71,6 +72,7 @@ int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
 		return -1;
 	proto->proto_id = proto_id;
 	proto->weight = weight;
+	proto->roles = roles;
 	proto->supported_clocks = supported_clocks;
 	proto->clock_sync_init = init;
 	proto->clock_sync_free = free;
@@ -142,12 +144,13 @@ int tracecmd_tsync_get_offsets(struct tracecmd_time_sync *tsync,
  *
  * @proto_mask: bitmask array of time sync protocols, supported by the peer
  * @length: size of the @protos array
- * @clock: selected trace clock
+ * @role : local time sync role
  *
  * Retuns Id of a time sync protocol, that can be used with the peer, or 0
  *	  in case there is no match with supported protocols
  */
-unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length, char *clock)
+unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length, char *clock,
+					 enum tracecmd_time_sync_role role)
 {
 	struct tsync_proto *selected = NULL;
 	struct tsync_proto *proto;
@@ -159,6 +162,8 @@ unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length, char *clo
 		clock_id = tracecmd_clock_str2id(clock);
 	for (word = 0; word < length; word++) {
 		for (proto = tsync_proto_list; proto; proto = proto->next) {
+			if (!(proto->roles & role))
+				continue;
 			if (proto->supported_clocks && clock_id &&
 			    !(proto->supported_clocks & clock_id))
 				continue;
@@ -192,12 +197,13 @@ unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length, char *clo
  *	       supported by the peer. Must be freed by free()
  * @words: return, allocated size of the @protobits array
  * @clock: selected trace clock
+ * @role: supported protocol role
  *
  * If completed successfully 0 is returned and allocated array in @proto_mask of
  * size @words. In case of an error, -1 is returned.
  * @proto_mask must be freed with free()
  */
-int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock)
+int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock, int role)
 {
 	struct tsync_proto *proto;
 	int proto_max = 0;
@@ -219,6 +225,8 @@ int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock
 	for (proto = tsync_proto_list; proto; proto = proto->next) {
 		if ((proto->proto_id / PROTO_MASK_SIZE) >= count)
 			continue;
+		if (!(proto->roles & role))
+			continue;
 		if (proto->supported_clocks && clock_id &&
 		    !(proto->supported_clocks & clock_id))
 			continue;
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 08bbc0e0..ff70df43 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3677,7 +3677,8 @@ static void connect_to_agent(struct buffer_instance *instance)
 		die("Failed to allocate message handle");
 
 	if (instance->tsync.loop_interval >= 0)
-		tracecmd_tsync_proto_getall(&protos, &protos_count, instance->clock);
+		tracecmd_tsync_proto_getall(&protos, &protos_count, instance->clock,
+					    TRACECMD_TIME_SYNC_ROLE_HOST);
 
 	ret = tracecmd_msg_send_trace_req(msg_handle, instance->argc,
 					  instance->argv, use_fifos,
diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c
index 832b70c3..051b1003 100644
--- a/tracecmd/trace-tsync.c
+++ b/tracecmd/trace-tsync.c
@@ -220,7 +220,8 @@ unsigned int tracecmd_guest_tsync(char *tsync_protos,
 	int fd;
 
 	fd = -1;
-	proto = tracecmd_tsync_proto_select(tsync_protos, tsync_protos_size, clock);
+	proto = tracecmd_tsync_proto_select(tsync_protos, tsync_protos_size,
+					    clock, TRACECMD_TIME_SYNC_ROLE_GUEST);
 	if (!proto)
 		return 0;
 #ifdef VSOCK
-- 
2.26.2


  parent reply	other threads:[~2020-10-09 14:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 14:03 [PATCH v24 00/10] Timestamp synchronization of host - guest tracing session Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 01/10] trace-cmd: [POC] PTP-like algorithm for host - guest timestamp synchronization Tzvetomir Stoyanov (VMware)
2020-10-15 21:24   ` Steven Rostedt
2020-10-26  7:38     ` Tzvetomir Stoyanov
2020-10-09 14:03 ` [PATCH v24 02/10] trace-cmd: Debug scripts for " Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 03/10] trace-cmd: Add trace-cmd library APIs for ftrace clock name Tzvetomir Stoyanov (VMware)
2020-10-22  1:26   ` Steven Rostedt
2020-10-22  1:31     ` Steven Rostedt
2020-10-09 14:03 ` [PATCH v24 04/10] trace-cmd: Move VM related logic in a separate file Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 05/10] trace-cmd: Add clock parameter to timestamp synchronization plugins Tzvetomir Stoyanov (VMware)
2020-10-22  1:39   ` Steven Rostedt
2020-10-09 14:03 ` Tzvetomir Stoyanov (VMware) [this message]
2020-10-09 14:03 ` [PATCH v24 07/10] trace-cmd: Add host / guest role in timestamp synchronization context Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 08/10] trace-cmd: Add guest CPU count PID in tracecmd_time_sync struct Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 09/10] trace-cmd: Fixed bitmask logic tracecmd_tsync_proto_getall() Tzvetomir Stoyanov (VMware)
2020-10-09 14:03 ` [PATCH v24 10/10] trace-cmd [POC]: Add KVM timestamp synchronization plugin Tzvetomir Stoyanov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201009140338.25260-7-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).