Netdev List
 help / color / mirror / Atom feed
From: "Tilmans, Olivier (Nokia - BE/Antwerp)"  <olivier.tilmans@nokia-bell-labs.com>
To: Eric Dumazet <eric.dumazet@gmail.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Olga Albisser <olga@albisser.org>,
	"De Schepper,
	Koen (Nokia - BE/Antwerp)" 
	<koen.de_schepper@nokia-bell-labs.com>,
	Bob Briscoe <research@bobbriscoe.net>,
	Henrik Steen <henrist@henrist.net>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next v4] sched: Add dualpi2 qdisc
Date: Wed, 21 Aug 2019 10:53:20 +0000	[thread overview]
Message-ID: <20190821103947.kxb2mixecndcelb6@nokia-bell-labs.com> (raw)
In-Reply-To: <20190821081150.31838-1-olivier.tilmans@nokia-bell-labs.com>

> +static s64 __scale_delta(s64 diff)
> +{
> +	do_div(diff, (1 << (ALPHA_BETA_GRANULARITY + 1)) - 1);
> +	return diff;
> +}
[...]
> +	delta = __scale_delta(((s64)qdelay - q->pi2.target) * q->pi2.alpha);
> +	delta += __scale_delta(((s64)qdelay - qdelay_old) * q->pi2.beta);

I just noticed that ensuring 64b divide compatibility across platforms 
using do_div() introduced this bug, as do_div() works with unsigned operands.

This will be fixed in a later v5 with the following patch:

---
 net/sched/sch_dualpi2.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/sched/sch_dualpi2.c b/net/sched/sch_dualpi2.c
index a6452aa82018..c6c851499d35 100644
--- a/net/sched/sch_dualpi2.c
+++ b/net/sched/sch_dualpi2.c
@@ -385,7 +385,7 @@ static struct sk_buff *dualpi2_qdisc_dequeue(struct Qdisc *sch)
 	return skb;
 }
 
-static s64 __scale_delta(s64 diff)
+static s64 __scale_delta(u64 diff)
 {
 	do_div(diff, (1 << (ALPHA_BETA_GRANULARITY + 1)) - 1);
 	return diff;
@@ -406,16 +406,18 @@ static u32 calculate_probability(struct Qdisc *sch)
 	/* Alpha and beta take at most 32b, i.e, the delay difference would
 	 * overflow for queueing delay differences > ~4.2sec.
 	 */
-	delta = __scale_delta(((s64)qdelay - q->pi2.target) * q->pi2.alpha);
-	delta += __scale_delta(((s64)qdelay - qdelay_old) * q->pi2.beta);
-	new_prob = delta + q->pi2.prob;
+	delta = ((s64)qdelay - q->pi2.target) * q->pi2.alpha;
+	delta += ((s64)qdelay - qdelay_old) * q->pi2.beta;
 	/* Prevent overflow */
 	if (delta > 0) {
+		new_prob = __scale_delta(delta) + q->pi2.prob;
 		if (new_prob < q->pi2.prob)
 			new_prob = MAX_PROB;
+	} else {
+		new_prob = q->pi2.prob - __scale_delta(delta * -1);
 		/* Prevent underflow */
-	} else if (new_prob > q->pi2.prob) {
-		new_prob = 0;
+		if (new_prob > q->pi2.prob)
+			new_prob = 0;
 	}
 	/* If we do not drop on overload, ensure we cap the L4S probability to
 	 * 100% to keep window fairness when overflowing.
-- 

Sorry for this.


Best,
Olivier

      reply	other threads:[~2019-08-21 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21  8:31 [PATCH net-next v4] sched: Add dualpi2 qdisc Tilmans, Olivier (Nokia - BE/Antwerp)
2019-08-21 10:53 ` Tilmans, Olivier (Nokia - BE/Antwerp) [this message]

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=20190821103947.kxb2mixecndcelb6@nokia-bell-labs.com \
    --to=olivier.tilmans@nokia-bell-labs.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=henrist@henrist.net \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=koen.de_schepper@nokia-bell-labs.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olga@albisser.org \
    --cc=research@bobbriscoe.net \
    --cc=stephen@networkplumber.org \
    --cc=xiyou.wangcong@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
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