Skip to contentSkip to conversation

Avoid two divides in __tcp_grow_window()

TCP Applied Eric Dumazet 2 participants 2 messages Dec 21, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

net/ipv4/tcp_input.c +2 -2
index 6931946..145b51a 100644
@@ -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)
maintainer Applied
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 21 Dec 2007 15:05:51 +0100

Quoted 6 lines

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.

Applied, thanks Eric.