Cake - FQ_codel the next generation
 help / color / mirror / Atom feed
From: Dave Taht <dave.taht@gmail.com>
To: cake@lists.bufferbloat.net
Subject: [Cake] [RFC PATCH 3/5] tc: support conversions to or from 64 bit nanosecond-based time
Date: Fri, 17 Nov 2017 13:19:26 -0800	[thread overview]
Message-ID: <1510953568-11797-4-git-send-email-dave.taht@gmail.com> (raw)
In-Reply-To: <1510953568-11797-1-git-send-email-dave.taht@gmail.com>

Using a 32 bit field to represent time in nanoseconds results in a
maximum value of about 4.3 seconds, which is well below many observed
delays in WiFi and LTE, and barely in the ballpark for a trip past the
Earth's moon, Luna.

Using 64 bit time fields in nanoseconds allows us to simulate
network diameters of several hundred light-years. However, only
conversions to and from ns, us, ms, and seconds are provided.
---
 tc/tc_util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tc/tc_util.h |  3 +++
 2 files changed, 63 insertions(+)

diff --git a/tc/tc_util.c b/tc/tc_util.c
index 472fc5d..ab344c8 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -322,6 +322,66 @@ char *sprint_ticks(__u32 ticks, char *buf)
 	return sprint_time(tc_core_tick2time(ticks), buf);
 }
 
+/* 64 bit times are represented internally in nanoseconds */
+
+#define USEC_PER_SEC 1000
+#define MSEC_PER_SEC (1000 * 1000)
+#define NSEC_PER_SEC (MSEC_PER_SEC * 1000)
+
+int get_time64(__u64 *time, const char *str)
+{
+	double t;
+	char *p;
+
+	t = strtod(str, &p);
+	if (p == str)
+		return -1;
+
+	if (*p) {
+		if (strcasecmp(p, "s") == 0 ||
+		    strcasecmp(p, "sec") == 0 ||
+		    strcasecmp(p, "secs") == 0)
+			t *= NSEC_PER_SEC;
+		else if (strcasecmp(p, "ms") == 0 ||
+			 strcasecmp(p, "msec") == 0 ||
+			 strcasecmp(p, "msecs") == 0)
+			t *= MSEC_PER_SEC;
+		else if (strcasecmp(p, "us") == 0 ||
+			 strcasecmp(p, "usec") == 0 ||
+			 strcasecmp(p, "usecs") == 0)
+			t *= USEC_PER_SEC;
+		else if (strcasecmp(p, "ns") == 0 ||
+			 strcasecmp(p, "nsec") == 0 ||
+			 strcasecmp(p, "nsecs") == 0)
+			t *= 1;
+		else
+			return -1;
+	}
+
+	*time = t;
+	return 0;
+}
+
+void print_time64(char *buf, int len, __u64 time)
+{
+	double tmp = time;
+
+	if (time >= NSEC_PER_SEC)
+		snprintf(buf, len, "%.3fs", tmp/NSEC_PER_SEC);
+	else if (time >= MSEC_PER_SEC)
+		snprintf(buf, len, "%.3fms", tmp/MSEC_PER_SEC);
+	else if (time >= USEC_PER_SEC)
+		snprintf(buf, len, "%.3fus", tmp/USEC_PER_SEC);
+	else
+		snprintf(buf, len, "%lldns", time);
+}
+
+char *sprint_time64(__u64 time, char *buf)
+{
+	print_time64(buf, SPRINT_BSIZE-1, time);
+	return buf;
+}
+
 int get_size(unsigned int *size, const char *str)
 {
 	double sz;
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 583a21a..3d87e8d 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -72,12 +72,14 @@ int get_rate64(__u64 *rate, const char *str);
 int get_size(unsigned int *size, const char *str);
 int get_size_and_cell(unsigned int *size, int *cell_log, char *str);
 int get_time(unsigned int *time, const char *str);
+int get_time64(__u64 *time, const char *str);
 int get_linklayer(unsigned int *val, const char *arg);
 
 void print_rate(char *buf, int len, __u64 rate);
 void print_size(char *buf, int len, __u32 size);
 void print_qdisc_handle(char *buf, int len, __u32 h);
 void print_time(char *buf, int len, __u32 time);
+void print_time64(char *buf, int len, __u64 time);
 void print_linklayer(char *buf, int len, unsigned int linklayer);
 
 char *sprint_rate(__u64 rate, char *buf);
@@ -85,6 +87,7 @@ char *sprint_size(__u32 size, char *buf);
 char *sprint_qdisc_handle(__u32 h, char *buf);
 char *sprint_tc_classid(__u32 h, char *buf);
 char *sprint_time(__u32 time, char *buf);
+char *sprint_time64(__u64 time, char *buf);
 char *sprint_ticks(__u32 ticks, char *buf);
 char *sprint_linklayer(unsigned int linklayer, char *buf);
 
-- 
2.7.4


  parent reply	other threads:[~2017-11-17 21:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-17 21:19 [Cake] [RFC PATCH 0/5] patches for iproute2-net-next for netem slotting and cake Dave Taht
2017-11-17 21:19 ` [Cake] [RFC PATCH 1/5] Update to the actual net-next Dave Taht
2017-11-17 21:26   ` Stephen Hemminger
2017-11-17 21:34     ` Dave Taht
2017-11-17 21:19 ` [Cake] [RFC PATCH 2/5] Add cake pkt_sched.h Dave Taht
2017-11-17 21:19 ` Dave Taht [this message]
2017-11-17 21:19 ` [Cake] [RFC PATCH 4/5] q_netem: support delivering packets in delayed time slots Dave Taht
2017-11-17 21:19 ` [Cake] [RFC PATCH 5/5] netem: add documentation for the new slotting feature Dave Taht

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

  List information: https://lists.bufferbloat.net/postorius/lists/cake.lists.bufferbloat.net/

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

  git send-email \
    --in-reply-to=1510953568-11797-4-git-send-email-dave.taht@gmail.com \
    --to=dave.taht@gmail.com \
    --cc=cake@lists.bufferbloat.net \
    /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