Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v24 05/10] trace-cmd: Add clock parameter to timestamp synchronization plugins
Date: Wed, 21 Oct 2020 21:39:33 -0400
Message-ID: <20201021213933.2c69d3e5@oasis.local.home> (raw)
In-Reply-To: <20201009140338.25260-6-tz.stoyanov@gmail.com>

On Fri,  9 Oct 2020 17:03:33 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> Some timestamp synchronization plugins may not support all ftrace
> clocks. Added logic to timestamp synchronization plugins to declare what
> ftace clocks they support. Added logic to select plugin depending on the

 s/ftace/ftrace/

> 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             |  4 ++--
>  lib/trace-cmd/include/trace-tsync-local.h |  1 +
>  lib/trace-cmd/trace-timesync-ptp.c        |  1 +
>  lib/trace-cmd/trace-timesync.c            | 21 +++++++++++++++++++--
>  tracecmd/trace-record.c                   |  4 +++-
>  tracecmd/trace-tsync.c                    |  2 +-
>  6 files changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
> index 393a2e7b..66b5d02b 100644
> --- a/include/trace-cmd/trace-cmd.h
> +++ b/include/trace-cmd/trace-cmd.h
> @@ -455,8 +455,8 @@ struct tracecmd_time_sync {
>  };
>  
>  void tracecmd_tsync_init(void);
> -int tracecmd_tsync_proto_getall(char **proto_mask, int *words);
> -unsigned int tracecmd_tsync_proto_select(char *proto_mask, int words);
> +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);
>  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 1de9d5e5..37c3597b 100644
> --- a/lib/trace-cmd/include/trace-tsync-local.h
> +++ b/lib/trace-cmd/include/trace-tsync-local.h
> @@ -27,6 +27,7 @@ struct clock_sync_context {
>  };
>  
>  int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
> +				  int supported_clocks,
>  				int (*init)(struct tracecmd_time_sync *),
>  				int (*free)(struct tracecmd_time_sync *),
>  				int (*calc)(struct tracecmd_time_sync *,
> diff --git a/lib/trace-cmd/trace-timesync-ptp.c b/lib/trace-cmd/trace-timesync-ptp.c
> index 19e2f647..51f17bca 100644
> --- a/lib/trace-cmd/trace-timesync-ptp.c
> +++ b/lib/trace-cmd/trace-timesync-ptp.c
> @@ -678,6 +678,7 @@ int ptp_clock_sync_register(void)
>  {
>  	return tracecmd_tsync_proto_register(TRACECMD_TIME_SYNC_PROTO_PTP,
>  					     TRACECMD_TIME_SYNC_PROTO_PTP_WEIGHT,
> +					     0,
>  					     ptp_clock_sync_init,
>  					     ptp_clock_sync_free,
>  					     ptp_clock_sync_calc);
> diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
> index e294698b..47d34e2a 100644
> --- a/lib/trace-cmd/trace-timesync.c
> +++ b/lib/trace-cmd/trace-timesync.c
> @@ -26,6 +26,7 @@ struct tsync_proto {
>  	struct tsync_proto *next;
>  	unsigned int proto_id;
>  	int	weight;
> +	int supported_clocks;
>  
>  	int (*clock_sync_init)(struct tracecmd_time_sync *clock_context);
>  	int (*clock_sync_free)(struct tracecmd_time_sync *clock_context);
> @@ -55,6 +56,7 @@ void tracecmd_tsync_init(void)
>  }
>  
>  int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
> +				int supported_clocks,
>  				int (*init)(struct tracecmd_time_sync *),
>  				int (*free)(struct tracecmd_time_sync *),
>  				int (*calc)(struct tracecmd_time_sync *,
> @@ -69,6 +71,7 @@ int tracecmd_tsync_proto_register(unsigned int proto_id, int weight,
>  		return -1;
>  	proto->proto_id = proto_id;
>  	proto->weight = weight;
> +	proto->supported_clocks = supported_clocks;
>  	proto->clock_sync_init = init;
>  	proto->clock_sync_free = free;
>  	proto->clock_sync_calc = calc;
> @@ -139,19 +142,26 @@ 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
>   *
>   * 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)
> +unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length, char *clock)
>  {
>  	struct tsync_proto *selected = NULL;
>  	struct tsync_proto *proto;
> +	int clock_id = 0;
>  	int word;
>  	int id;
>  
> +	if (clock)
> +		clock_id = tracecmd_clock_str2id(clock);

I wonder if we should just have tracecmd_clock_str2id(NULL) return zero.

Then you don't need the 'if (clock)' check.


>  	for (word = 0; word < length; word++) {
>  		for (proto = tsync_proto_list; proto; proto = proto->next) {
> +			if (proto->supported_clocks && clock_id &&
> +			    !(proto->supported_clocks & clock_id))
> +				continue;
>  			if (proto->proto_id < word * PROTO_MASK_SIZE)
>  				continue;
>  
> @@ -181,18 +191,22 @@ unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length)
>   * @proto_mask: return, allocated bitmask array of time sync protocols,
>   *	       supported by the peer. Must be freed by free()
>   * @words: return, allocated size of the @protobits array
> + * @clock: selected trace clock
>   *
>   * 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)
> +int tracecmd_tsync_proto_getall(char **proto_mask, int *words, const char *clock)
>  {
>  	struct tsync_proto *proto;
>  	int proto_max = 0;
> +	int clock_id = 0;
>  	int count = 0;
>  	char *protos;
>  
> +	if (clock)
> +		clock_id =  tracecmd_clock_str2id(clock);
>  	for (proto = tsync_proto_list; proto; proto = proto->next)
>  		if (proto->proto_id > proto_max)
>  			proto_max = proto->proto_id;
> @@ -205,6 +219,9 @@ int tracecmd_tsync_proto_getall(char **proto_mask, int *words)
>  	for (proto = tsync_proto_list; proto; proto = proto->next) {
>  		if ((proto->proto_id / PROTO_MASK_SIZE) >= count)
>  			continue;
> +		if (proto->supported_clocks && clock_id &&
> +		    !(proto->supported_clocks & clock_id))
> +			continue;
>  		protos[proto->proto_id / PROTO_MASK_SIZE] |=
>  				(1 << (proto->proto_id % PROTO_MASK_SIZE));
>  	}
> diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
> index 9149cf76..08bbc0e0 100644
> --- a/tracecmd/trace-record.c
> +++ b/tracecmd/trace-record.c
> @@ -3677,7 +3677,7 @@ 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);
> +		tracecmd_tsync_proto_getall(&protos, &protos_count, instance->clock);
>  
>  	ret = tracecmd_msg_send_trace_req(msg_handle, instance->argc,
>  					  instance->argv, use_fifos,
> @@ -6111,6 +6111,8 @@ static void parse_record_options(int argc,
>  						 (char *)top_instance.clock,
>  						 true);
>  					add_argv(instance, "-C", true);
> +					if (!instance->clock)
> +						instance->clock = strdup((char *)top_instance.clock);

Need to check the success of the allocation.

-- Steve

>  				}
>  			}
>  			instance->tsync.loop_interval = top_instance.tsync.loop_interval;
> diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c
> index e639788d..832b70c3 100644
> --- a/tracecmd/trace-tsync.c
> +++ b/tracecmd/trace-tsync.c
> @@ -220,7 +220,7 @@ unsigned int tracecmd_guest_tsync(char *tsync_protos,
>  	int fd;
>  
>  	fd = -1;
> -	proto = tracecmd_tsync_proto_select(tsync_protos, tsync_protos_size);
> +	proto = tracecmd_tsync_proto_select(tsync_protos, tsync_protos_size, clock);
>  	if (!proto)
>  		return 0;
>  #ifdef VSOCK


  reply index

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 [this message]
2020-10-09 14:03 ` [PATCH v24 06/10] trace-cmd: Add role " Tzvetomir Stoyanov (VMware)
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=20201021213933.2c69d3e5@oasis.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /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

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git