2020-01-20 10:06:41

by Wen Yang

[permalink] [raw]
Subject: [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()

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 <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Alexey Kuznetsov <[email protected]>
Cc: Hideaki YOSHIFUJI <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
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


2020-01-20 17:59:33

by Eric Dumazet

[permalink] [raw]
Subject: Re: [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()



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 <[email protected]>

Thanks !

2020-01-21 09:47:46

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] tcp_bbr: improve arithmetic division in bbr_update_bw()

From: Wen Yang <[email protected]>
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 <[email protected]>

Applied, thank you.