All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: remove loop to compute wscale
@ 2018-11-29 15:56 Eric Dumazet
  2018-11-29 16:03 ` Soheil Hassas Yeganeh
  2018-11-29 19:13 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2018-11-29 15:56 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Soheil Hassas Yeganeh, Neal Cardwell,
	Yuchung Cheng, Eric Dumazet

We can remove the loop and conditional branches
and compute wscale efficiently thanks to ilog2()

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp_output.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 3ae4a277991a3473f61b1f73acd5ee355cf6a5df..d3b691f3a9e896ce340ae081a0d24092024361c8 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -233,16 +233,14 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,
 	if (init_rcv_wnd)
 		*rcv_wnd = min(*rcv_wnd, init_rcv_wnd * mss);
 
-	(*rcv_wscale) = 0;
+	*rcv_wscale = 0;
 	if (wscale_ok) {
 		/* Set window scaling on max possible window */
 		space = max_t(u32, space, sock_net(sk)->ipv4.sysctl_tcp_rmem[2]);
 		space = max_t(u32, space, sysctl_rmem_max);
 		space = min_t(u32, space, *window_clamp);
-		while (space > U16_MAX && (*rcv_wscale) < TCP_MAX_WSCALE) {
-			space >>= 1;
-			(*rcv_wscale)++;
-		}
+		*rcv_wscale = clamp_t(int, ilog2(space) - 15,
+				      0, TCP_MAX_WSCALE);
 	}
 	/* Set the clamp no higher than max representable value */
 	(*window_clamp) = min_t(__u32, U16_MAX << (*rcv_wscale), *window_clamp);
-- 
2.20.0.rc0.387.gc7a69e6b6c-goog

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

* Re: [PATCH net-next] tcp: remove loop to compute wscale
  2018-11-29 15:56 [PATCH net-next] tcp: remove loop to compute wscale Eric Dumazet
@ 2018-11-29 16:03 ` Soheil Hassas Yeganeh
  2018-11-29 19:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Soheil Hassas Yeganeh @ 2018-11-29 16:03 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, netdev, Neal Cardwell, Yuchung Cheng, Eric Dumazet

On Thu, Nov 29, 2018 at 10:56 AM Eric Dumazet <edumazet@google.com> wrote:
>
> We can remove the loop and conditional branches
> and compute wscale efficiently thanks to ilog2()
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Acked-by: Soheil Hassas Yeganeh <soheil@google.com>

Very nice, thank you, Eric!

> ---
>  net/ipv4/tcp_output.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 3ae4a277991a3473f61b1f73acd5ee355cf6a5df..d3b691f3a9e896ce340ae081a0d24092024361c8 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -233,16 +233,14 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,
>         if (init_rcv_wnd)
>                 *rcv_wnd = min(*rcv_wnd, init_rcv_wnd * mss);
>
> -       (*rcv_wscale) = 0;
> +       *rcv_wscale = 0;
>         if (wscale_ok) {
>                 /* Set window scaling on max possible window */
>                 space = max_t(u32, space, sock_net(sk)->ipv4.sysctl_tcp_rmem[2]);
>                 space = max_t(u32, space, sysctl_rmem_max);
>                 space = min_t(u32, space, *window_clamp);
> -               while (space > U16_MAX && (*rcv_wscale) < TCP_MAX_WSCALE) {
> -                       space >>= 1;
> -                       (*rcv_wscale)++;
> -               }
> +               *rcv_wscale = clamp_t(int, ilog2(space) - 15,
> +                                     0, TCP_MAX_WSCALE);
>         }
>         /* Set the clamp no higher than max representable value */
>         (*window_clamp) = min_t(__u32, U16_MAX << (*rcv_wscale), *window_clamp);
> --
> 2.20.0.rc0.387.gc7a69e6b6c-goog
>

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

* Re: [PATCH net-next] tcp: remove loop to compute wscale
  2018-11-29 15:56 [PATCH net-next] tcp: remove loop to compute wscale Eric Dumazet
  2018-11-29 16:03 ` Soheil Hassas Yeganeh
@ 2018-11-29 19:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-11-29 19:13 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, soheil, ncardwell, ycheng, eric.dumazet

From: Eric Dumazet <edumazet@google.com>
Date: Thu, 29 Nov 2018 07:56:20 -0800

> We can remove the loop and conditional branches
> and compute wscale efficiently thanks to ilog2()
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied.

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

end of thread, other threads:[~2018-11-30  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29 15:56 [PATCH net-next] tcp: remove loop to compute wscale Eric Dumazet
2018-11-29 16:03 ` Soheil Hassas Yeganeh
2018-11-29 19:13 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.