tcp: remove loop to compute wscale
Subsystems (3)
PATCH 1/1 tcp: remove loop to compute wscale
We can remove the loop and conditional branches
and compute wscale efficiently thanks to ilog2()
Signed-off-by Eric Dumazet <[email protected]>
--- net/ipv4/tcp_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv4/tcp_output.c +3 -5
@@ -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);
Signature · 1 line
2.20.0.rc0.387.gc7a69e6b6c-goog
Quoted 5 lines · Eric Dumazet
We can remove the loop and conditional branches
and compute wscale efficiently thanks toilog2()Signed-off-by Eric Dumazet <[email protected]>
Very nice, thank you, Eric!
Quoted 31 lines
--- net/ipv4/tcp_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)net/ipv4/tcp_output.c +3
-6@@ -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
From: Eric Dumazet <[email protected]>
Date: Thu, 29 Nov 2018 07:56:20 -0800
Quoted 4 lines
We can remove the loop and conditional branches
and compute wscale efficiently thanks toilog2()Signed-off-by Eric Dumazet <[email protected]>
Applied.