From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] trace-cmd/timesync: Remove double check of finding the protocol
Date: Wed, 17 Feb 2021 15:50:34 -0500 [thread overview]
Message-ID: <20210217155034.04f6891f@gandalf.local.home> (raw)
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
In the two locations that call clock_context_init(), the protocol is
searched for via tsync_proto_find() to test if it has clock_sync_calc set.
clock_context_init() then does another tsync_proto_find(). Instead of having
this duplicate search, have clock_context_init() do the search and check if
clock_sync_calc is set, and return the protocol back to the caller on
success.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-timesync.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 9cbed775..8d01c0bc 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -327,7 +327,8 @@ clock_synch_delete_instance(struct tracefs_instance *inst)
tracefs_instance_free(inst);
}
-static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
+static int clock_context_init(struct tracecmd_time_sync *tsync,
+ struct tsync_proto **proto, bool guest)
{
struct clock_sync_context *clock = NULL;
struct tsync_proto *protocol;
@@ -336,7 +337,7 @@ static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
return 0;
protocol = tsync_proto_find(tsync->proto_name);
- if (!protocol)
+ if (!protocol || !protocol->clock_sync_calc)
return -1;
clock = calloc(1, sizeof(struct clock_sync_context));
@@ -359,6 +360,8 @@ static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
if (protocol->clock_sync_init && protocol->clock_sync_init(tsync) < 0)
goto error;
+ *proto = protocol;
+
return 0;
error:
tsync->context = NULL;
@@ -432,11 +435,7 @@ void tracecmd_tsync_with_host(struct tracecmd_time_sync *tsync)
unsigned int command;
int ret;
- proto = tsync_proto_find(tsync->proto_name);
- if (!proto || !proto->clock_sync_calc)
- return;
-
- clock_context_init(tsync, true);
+ clock_context_init(tsync, &proto, true);
if (!tsync->context)
return;
@@ -534,11 +533,7 @@ void tracecmd_tsync_with_guest(struct tracecmd_time_sync *tsync)
bool end = false;
int ret;
- proto = tsync_proto_find(tsync->proto_name);
- if (!proto || !proto->clock_sync_calc)
- return;
-
- clock_context_init(tsync, false);
+ clock_context_init(tsync, &proto, false);
if (!tsync->context)
return;
--
2.25.4
reply other threads:[~2021-02-17 20:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210217155034.04f6891f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.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).