public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Paasch <christoph.paasch@uclouvain.be>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, Neal Cardwell <ncardwell@google.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Doug Leith <doug.leith@nuim.ie>
Subject: Re: [PATCH v2 net] tcp: Fix integer-overflows in TCP vegas
Date: Sun, 27 Jul 2014 11:48:49 +0200	[thread overview]
Message-ID: <20140727094849.GC5965@cpaasch-mac> (raw)
In-Reply-To: <1406368497.12728.16.camel@edumazet-glaptop2.roam.corp.google.com>

On 26/07/14 - 11:54:57, Eric Dumazet wrote:
> On Sat, 2014-07-26 at 10:59 +0200, Christoph Paasch wrote:
> 
> > do you mean, using "do_div"?
> > 
> > David suggested to avoid using do_div in tcp_vegas.
> 
> My understanding is the following :
> 
> On 64bit arches, used on most servers that really care of TCP
> performance these days, do_div() is the fastest thing : No extra
> conditional.
> 
> # define do_div(n,base) ({                                      \
>         uint32_t __base = (base);                               \
>         uint32_t __rem;                                         \
>         __rem = ((uint64_t)(n)) % __base;                       \
>         (n) = ((uint64_t)(n)) / __base;                         \
>         __rem;                                                  \
>  })
> 
> 
> Then on 32bit, do_div(target_cwnd, Y) will perform a single divide
> if target_cwnd is < 2^32, which is very likely the case :
> 
> 
> # define do_div(n,base) ({                              \
>         uint32_t __base = (base);                       \
>         uint32_t __rem;                                 \
>         (void)(((typeof((n)) *)0) == ((uint64_t *)0));  \
>         if (likely(((n) >> 32) == 0)) {                 \
>                 __rem = (uint32_t)(n) % __base;         \
>                 (n) = (uint32_t)(n) / __base;           \
>         } else                                          \
>                 __rem = __div64_32(&(n), __base);       \
>         __rem;                                          \
>  })
> 
> 
> 
> (In both cases, compiler will remove the modulo operation, as we do not use it)

I am very fine with using do_div. Indeed, cwnd and rtt must be quite high to
fall into the case of 64-bit divides.

I will wait a bit for other feedback and then send a new version with do_div.


Thanks,
Christoph

  reply	other threads:[~2014-07-27  9:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-25 11:52 [PATCH v2 net] tcp: Fix integer-overflows in TCP vegas Christoph Paasch
2014-07-25 18:14 ` Stephen Hemminger
2014-07-26  8:59   ` Christoph Paasch
2014-07-26  9:54     ` Eric Dumazet
2014-07-27  9:48       ` Christoph Paasch [this message]
2014-07-29  0:26 ` David Miller
2014-07-29  9:52   ` Christoph Paasch

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=20140727094849.GC5965@cpaasch-mac \
    --to=christoph.paasch@uclouvain.be \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=doug.leith@nuim.ie \
    --cc=eric.dumazet@gmail.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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