netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Taht <dave.taht@gmail.com>
To: netdev@vger.kernel.org
Cc: Dave Taht <dave.taht@gmail.com>
Subject: [PATCH net-next 2/3] netem: add uapi to express delay and jitter in nanosec
Date: Tue,  7 Nov 2017 12:59:35 -0800	[thread overview]
Message-ID: <1510088376-5527-3-git-send-email-dave.taht@gmail.com> (raw)
In-Reply-To: <1510088376-5527-1-git-send-email-dave.taht@gmail.com>

netem userspace has long relied on a horrible /proc/net/psched hack to
translate the current notion of "ticks" to nanoseconds.

Expressing latency and jitter instead, in well defined nanoseconds,
increases the dynamic range of emulated delays and jitter in netem.

It will also ease a transition where reducing a tick to nsec equivalence
would constrain the max delay in prior versions of netem to only 4.3
seconds.

Signed-off-by: Dave Taht <dave.taht@gmail.com>
---
 include/uapi/linux/pkt_sched.h |  2 ++
 net/sched/sch_netem.c          | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
index 5002562..20cfd64 100644
--- a/include/uapi/linux/pkt_sched.h
+++ b/include/uapi/linux/pkt_sched.h
@@ -536,6 +536,8 @@ enum {
 	TCA_NETEM_ECN,
 	TCA_NETEM_RATE64,
 	TCA_NETEM_PAD,
+	TCA_NETEM_LATENCY64,
+	TCA_NETEM_JITTER64,
 	__TCA_NETEM_MAX,
 };
 
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 443a75d..16c4813 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -819,6 +819,8 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
 	[TCA_NETEM_LOSS]	= { .type = NLA_NESTED },
 	[TCA_NETEM_ECN]		= { .type = NLA_U32 },
 	[TCA_NETEM_RATE64]	= { .type = NLA_U64 },
+	[TCA_NETEM_LATENCY64]	= { .type = NLA_S64 },
+	[TCA_NETEM_JITTER64]	= { .type = NLA_S64 },
 };
 
 static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
@@ -916,6 +918,12 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
 		q->rate = max_t(u64, q->rate,
 				nla_get_u64(tb[TCA_NETEM_RATE64]));
 
+	if (tb[TCA_NETEM_LATENCY64])
+		q->latency = nla_get_s64(tb[TCA_NETEM_LATENCY64]);
+
+	if (tb[TCA_NETEM_JITTER64])
+		q->jitter = nla_get_s64(tb[TCA_NETEM_JITTER64]);
+
 	if (tb[TCA_NETEM_ECN])
 		q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]);
 
@@ -1020,6 +1028,14 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
 	if (nla_put(skb, TCA_OPTIONS, sizeof(qopt), &qopt))
 		goto nla_put_failure;
 
+	if (PSCHED_TICKS2NS(qopt.latency) != q->latency)
+		if (nla_put(skb, TCA_NETEM_LATENCY64, sizeof(q->latency),
+			    &q->latency))
+			goto nla_put_failure;
+	if (PSCHED_TICKS2NS(qopt.jitter) != q->jitter)
+		if (nla_put(skb, TCA_NETEM_JITTER64, sizeof(q->jitter),
+			    &q->jitter))
+			goto nla_put_failure;
 	cor.delay_corr = q->delay_cor.rho;
 	cor.loss_corr = q->loss_cor.rho;
 	cor.dup_corr = q->dup_cor.rho;
-- 
2.7.4

  parent reply	other threads:[~2017-11-07 20:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 20:59 [PATCH net-next 0/3] netem: add nsec scheduling and slot feature Dave Taht
2017-11-07 20:59 ` [PATCH net-next 1/3] netem: convert to qdisc_watchdog_schedule_ns Dave Taht
2017-11-14 21:11   ` [net-next,1/3] " James Hogan
2017-11-14 21:43     ` James Hogan
2017-11-14 22:49     ` Stephen Hemminger
2017-11-07 20:59 ` Dave Taht [this message]
2017-11-07 20:59 ` [PATCH net-next 3/3] netem: support delivering packets in delayed time slots Dave Taht
2017-11-08  0:26 ` [PATCH net-next 0/3] netem: add nsec scheduling and slot feature Stephen Hemminger
2017-11-08 21:45   ` 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

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

  git send-email \
    --in-reply-to=1510088376-5527-3-git-send-email-dave.taht@gmail.com \
    --to=dave.taht@gmail.com \
    --cc=netdev@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).