netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [TCP] Avoid two divides in __tcp_grow_window()
@ 2007-12-21 14:05 Eric Dumazet
  2007-12-21 14:08 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2007-12-21 14:05 UTC (permalink / raw)
  To: David Miller; +Cc: netdev@vger.kernel.org

tcp_win_from_space() being signed, compiler might emit an integer divide
to compute tcp_win_from_space()/2 .

Using right shifts is OK here and less expensive.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 6931946..145b51a 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -289,8 +289,8 @@ static int __tcp_grow_window(const struct sock *sk, const struct sk_buff *skb)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	/* Optimize this! */
-	int truesize = tcp_win_from_space(skb->truesize)/2;
-	int window = tcp_win_from_space(sysctl_tcp_rmem[2])/2;
+	int truesize = tcp_win_from_space(skb->truesize) >> 1;
+	int window = tcp_win_from_space(sysctl_tcp_rmem[2]) >> 1;
 
 	while (tp->rcv_ssthresh <= window) {
 		if (truesize <= skb->len)

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

* Re: [TCP] Avoid two divides in __tcp_grow_window()
  2007-12-21 14:05 [TCP] Avoid two divides in __tcp_grow_window() Eric Dumazet
@ 2007-12-21 14:08 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-12-21 14:08 UTC (permalink / raw)
  To: dada1; +Cc: netdev

From: Eric Dumazet <dada1@cosmosbay.com>
Date: Fri, 21 Dec 2007 15:05:51 +0100

> tcp_win_from_space() being signed, compiler might emit an integer divide
> to compute tcp_win_from_space()/2 .
> 
> Using right shifts is OK here and less expensive.
> 
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>

Applied, thanks Eric.

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

end of thread, other threads:[~2007-12-21 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-21 14:05 [TCP] Avoid two divides in __tcp_grow_window() Eric Dumazet
2007-12-21 14:08 ` 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).