From: Jian Yang <jianyang.kernel@gmail.com>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: Soheil Hassas Yeganeh <soheil@google.com>,
Willem de Bruijn <willemb@google.com>,
Jian Yang <jianyang@google.com>
Subject: [PATCH net-next 2/5] selftests: txtimestamp: allow printing latencies in nsec.
Date: Tue, 17 Mar 2020 12:25:06 -0700 [thread overview]
Message-ID: <20200317192509.150725-3-jianyang.kernel@gmail.com> (raw)
In-Reply-To: <20200317192509.150725-1-jianyang.kernel@gmail.com>
From: Jian Yang <jianyang@google.com>
Txtimestamp reports latencies in uses resolution, while nsec is needed
in cases such as measuring latencies on localhost.
Add the following new flag:
-N: print timestamps and durations in nsec (instead of usec)
Signed-off-by: Jian Yang <jianyang@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
---
.../networking/timestamping/txtimestamp.c | 56 +++++++++++++++----
1 file changed, 44 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/networking/timestamping/txtimestamp.c b/tools/testing/selftests/networking/timestamping/txtimestamp.c
index 7e386be47120..a9b8c41a3009 100644
--- a/tools/testing/selftests/networking/timestamping/txtimestamp.c
+++ b/tools/testing/selftests/networking/timestamping/txtimestamp.c
@@ -49,6 +49,10 @@
#include <time.h>
#include <unistd.h>
+#define NSEC_PER_USEC 1000L
+#define USEC_PER_SEC 1000000L
+#define NSEC_PER_SEC 1000000000LL
+
/* command line parameters */
static int cfg_proto = SOCK_STREAM;
static int cfg_ipproto = IPPROTO_TCP;
@@ -67,6 +71,7 @@ static bool cfg_use_cmsg;
static bool cfg_use_pf_packet;
static bool cfg_do_listen;
static uint16_t dest_port = 9000;
+static bool cfg_print_nsec;
static struct sockaddr_in daddr;
static struct sockaddr_in6 daddr6;
@@ -77,9 +82,14 @@ static int saved_tskey_type = -1;
static bool test_failed;
+static int64_t timespec_to_ns64(struct timespec *ts)
+{
+ return ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec;
+}
+
static int64_t timespec_to_us64(struct timespec *ts)
{
- return ts->tv_sec * 1000 * 1000 + ts->tv_nsec / 1000;
+ return ts->tv_sec * USEC_PER_SEC + ts->tv_nsec / NSEC_PER_USEC;
}
static void validate_key(int tskey, int tstype)
@@ -113,25 +123,43 @@ static void validate_timestamp(struct timespec *cur, int min_delay)
start64 = timespec_to_us64(&ts_usr);
if (cur64 < start64 + min_delay || cur64 > start64 + max_delay) {
- fprintf(stderr, "ERROR: delay %lu expected between %d and %d\n",
+ fprintf(stderr, "ERROR: %lu us expected between %d and %d\n",
cur64 - start64, min_delay, max_delay);
test_failed = true;
}
}
+static void __print_ts_delta_formatted(int64_t ts_delta)
+{
+ if (cfg_print_nsec)
+ fprintf(stderr, "%lu ns", ts_delta);
+ else
+ fprintf(stderr, "%lu us", ts_delta / NSEC_PER_USEC);
+}
+
static void __print_timestamp(const char *name, struct timespec *cur,
uint32_t key, int payload_len)
{
+ int64_t ts_delta;
+
if (!(cur->tv_sec | cur->tv_nsec))
return;
- fprintf(stderr, " %s: %lu s %lu us (seq=%u, len=%u)",
- name, cur->tv_sec, cur->tv_nsec / 1000,
- key, payload_len);
-
- if (cur != &ts_usr)
- fprintf(stderr, " (USR %+" PRId64 " us)",
- timespec_to_us64(cur) - timespec_to_us64(&ts_usr));
+ if (cfg_print_nsec)
+ fprintf(stderr, " %s: %lu s %lu ns (seq=%u, len=%u)",
+ name, cur->tv_sec, cur->tv_nsec,
+ key, payload_len);
+ else
+ fprintf(stderr, " %s: %lu s %lu us (seq=%u, len=%u)",
+ name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC,
+ key, payload_len);
+
+ if (cur != &ts_usr) {
+ ts_delta = timespec_to_ns64(cur) - timespec_to_ns64(&ts_usr);
+ fprintf(stderr, " (USR +");
+ __print_ts_delta_formatted(ts_delta);
+ fprintf(stderr, ")");
+ }
fprintf(stderr, "\n");
}
@@ -526,7 +554,7 @@ static void do_test(int family, unsigned int report_opt)
/* wait for all errors to be queued, else ACKs arrive OOO */
if (!cfg_no_delay)
- usleep(50 * 1000);
+ usleep(50 * NSEC_PER_USEC);
__poll(fd);
@@ -537,7 +565,7 @@ static void do_test(int family, unsigned int report_opt)
error(1, errno, "close");
free(buf);
- usleep(100 * 1000);
+ usleep(100 * NSEC_PER_USEC);
}
static void __attribute__((noreturn)) usage(const char *filepath)
@@ -555,6 +583,7 @@ static void __attribute__((noreturn)) usage(const char *filepath)
" -l N: send N bytes at a time\n"
" -L listen on hostname and port\n"
" -n: set no-payload option\n"
+ " -N: print timestamps and durations in nsec (instead of usec)\n"
" -p N: connect to port N\n"
" -P: use PF_PACKET\n"
" -r: use raw\n"
@@ -572,7 +601,7 @@ static void parse_opt(int argc, char **argv)
int proto_count = 0;
int c;
- while ((c = getopt(argc, argv, "46c:CDFhIl:Lnp:PrRuv:V:x")) != -1) {
+ while ((c = getopt(argc, argv, "46c:CDFhIl:LnNp:PrRuv:V:x")) != -1) {
switch (c) {
case '4':
do_ipv6 = 0;
@@ -604,6 +633,9 @@ static void parse_opt(int argc, char **argv)
case 'n':
cfg_loop_nodata = true;
break;
+ case 'N':
+ cfg_print_nsec = true;
+ break;
case 'p':
dest_port = strtoul(optarg, NULL, 10);
break;
--
2.25.1.481.gfbce0eb801-goog
next prev parent reply other threads:[~2020-03-17 19:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 19:25 [PATCH net-next 0/5] selftests: expand txtimestamp with new features Jian Yang
2020-03-17 19:25 ` [PATCH net-next 1/5] selftests: txtimestamp: allow individual txtimestamp tests Jian Yang
2020-03-17 19:25 ` Jian Yang [this message]
2020-03-17 19:25 ` [PATCH net-next 3/5] selftests: txtimestamp: add new command-line flags Jian Yang
2020-03-17 19:25 ` [PATCH net-next 4/5] selftests: txtimestamp: add support for epoll() Jian Yang
2020-03-17 19:25 ` [PATCH net-next 5/5] selftests: txtimestamp: print statistics for timestamp events Jian Yang
2020-03-17 20:33 ` [PATCH net-next 0/5] selftests: expand txtimestamp with new features Jakub Kicinski
2020-03-17 20:39 ` Willem de Bruijn
2020-03-17 21:54 ` Jakub Kicinski
2020-03-22 3:13 ` David Miller
2020-03-22 3:13 ` David Miller
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=20200317192509.150725-3-jianyang.kernel@gmail.com \
--to=jianyang.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=jianyang@google.com \
--cc=netdev@vger.kernel.org \
--cc=soheil@google.com \
--cc=willemb@google.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
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).