linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()
@ 2020-01-20 10:04 Wen Yang
  2020-01-20 17:58 ` Eric Dumazet
  2020-01-21  9:46 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Wen Yang @ 2020-01-20 10:04 UTC (permalink / raw)
  To: Eric Dumazet, davem
  Cc: Wen Yang, Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev, linux-kernel

do_div() does a 64-by-32 division. Use div64_long() instead of it
if the divisor is long, to avoid truncation to 32-bit.
And as a nice side effect also cleans up the function a bit.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 net/ipv4/tcp_bbr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
index a6545ef0d27b..6c4d79baff26 100644
--- a/net/ipv4/tcp_bbr.c
+++ b/net/ipv4/tcp_bbr.c
@@ -779,8 +779,7 @@ static void bbr_update_bw(struct sock *sk, const struct rate_sample *rs)
 	 * bandwidth sample. Delivered is in packets and interval_us in uS and
 	 * ratio will be <<1 for most connections. So delivered is first scaled.
 	 */
-	bw = (u64)rs->delivered * BW_UNIT;
-	do_div(bw, rs->interval_us);
+	bw = div64_long((u64)rs->delivered * BW_UNIT, rs->interval_us);
 
 	/* If this sample is application-limited, it is likely to have a very
 	 * low delivered count that represents application behavior rather than
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()
  2020-01-20 10:04 [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw() Wen Yang
@ 2020-01-20 17:58 ` Eric Dumazet
  2020-01-21  9:46 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2020-01-20 17:58 UTC (permalink / raw)
  To: Wen Yang, Eric Dumazet, davem
  Cc: Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev, linux-kernel



On 1/20/20 2:04 AM, Wen Yang wrote:
> do_div() does a 64-by-32 division. Use div64_long() instead of it
> if the divisor is long, to avoid truncation to 32-bit.
> And as a nice side effect also cleans up the function a bit.
> 

Signed-off-by: Eric Dumazet <edumazet@google.com>

Thanks !

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()
  2020-01-20 10:04 [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw() Wen Yang
  2020-01-20 17:58 ` Eric Dumazet
@ 2020-01-21  9:46 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-01-21  9:46 UTC (permalink / raw)
  To: wenyang; +Cc: edumazet, kuznet, yoshfuji, netdev, linux-kernel

From: Wen Yang <wenyang@linux.alibaba.com>
Date: Mon, 20 Jan 2020 18:04:56 +0800

> do_div() does a 64-by-32 division. Use div64_long() instead of it
> if the divisor is long, to avoid truncation to 32-bit.
> And as a nice side effect also cleans up the function a bit.
> 
> Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>

Applied, thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-21  9:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 10:04 [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw() Wen Yang
2020-01-20 17:58 ` Eric Dumazet
2020-01-21  9:46 ` David Miller

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).