Patchwork [net-next] tcp:elapsed variable calculated twice while keepalive working

login
register
mail settings
Submitter Tingwei Liu
Date Aug. 6, 2013, 12:38 p.m.
Message ID <1375792738-19099-1-git-send-email-tingw.liu@gmail.com>
Download mbox | patch
Permalink /patch/265050/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Tingwei Liu - Aug. 6, 2013, 12:38 p.m.
When tcp keepalive working elapsed calculated twice while the first time is not needed!

CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: Tingwei Liu <tingw.liu@gmail.com>
---
 net/ipv4/tcp_timer.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
David Miller - Aug. 9, 2013, 6:12 p.m.
From: Tingwei Liu <tingw.liu@gmail.com>
Date: Tue,  6 Aug 2013 20:38:58 +0800

> When tcp keepalive working elapsed calculated twice while the first time is not needed!
> 
> CC: Eric Dumazet <eric.dumazet@gmail.com>
> CC: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
> Signed-off-by: Tingwei Liu <tingw.liu@gmail.com>


Please put a space after "tcp:" in your Subject line prefixes, it looks
awful the way you've done it here.

> @@ -591,11 +591,11 @@ static void tcp_keepalive_timer (unsigned long data)
>  	if (!sock_flag(sk, SOCK_KEEPOPEN) || sk->sk_state == TCP_CLOSE)
>  		goto out;
>  
> -	elapsed = keepalive_time_when(tp);
> -
>  	/* It is alive without keepalive 8) */
> -	if (tp->packets_out || tcp_send_head(sk))
> +	if (tp->packets_out || tcp_send_head(sk)) {
> +		elapsed = keepalive_time_when(tp);
>  		goto resched;
> +	}
>  
>  	elapsed = keepalive_time_elapsed(tp);

This is overkill, just delete the second assignment.  Your version makes
the code look less elegant and also makes it harder to audit.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Dumazet - Aug. 9, 2013, 9:06 p.m.
On Fri, 2013-08-09 at 11:12 -0700, David Miller wrote:
> From: Tingwei Liu <tingw.liu@gmail.com>
> Date: Tue,  6 Aug 2013 20:38:58 +0800
> 
> > When tcp keepalive working elapsed calculated twice while the first time is not needed!
> > 
> > CC: Eric Dumazet <eric.dumazet@gmail.com>
> > CC: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
> > Signed-off-by: Tingwei Liu <tingw.liu@gmail.com>
> 
> 
> Please put a space after "tcp:" in your Subject line prefixes, it looks
> awful the way you've done it here.
> 
> > @@ -591,11 +591,11 @@ static void tcp_keepalive_timer (unsigned long data)
> >  	if (!sock_flag(sk, SOCK_KEEPOPEN) || sk->sk_state == TCP_CLOSE)
> >  		goto out;
> >  
> > -	elapsed = keepalive_time_when(tp);
> > -
> >  	/* It is alive without keepalive 8) */
> > -	if (tp->packets_out || tcp_send_head(sk))
> > +	if (tp->packets_out || tcp_send_head(sk)) {
> > +		elapsed = keepalive_time_when(tp);
> >  		goto resched;
> > +	}
> >  
> >  	elapsed = keepalive_time_elapsed(tp);
> 
> This is overkill, just delete the second assignment.  Your version makes
> the code look less elegant and also makes it harder to audit.
> --

As a matter of fact, 
keepalive_time_when(tp) and keepalive_time_elapsed(tp) are different ;)

This is very slow path in TCP stack, so it should not matter a lot.

 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 4b85e6f..03091d9 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -591,11 +591,11 @@  static void tcp_keepalive_timer (unsigned long data)
 	if (!sock_flag(sk, SOCK_KEEPOPEN) || sk->sk_state == TCP_CLOSE)
 		goto out;
 
-	elapsed = keepalive_time_when(tp);
-
 	/* It is alive without keepalive 8) */
-	if (tp->packets_out || tcp_send_head(sk))
+	if (tp->packets_out || tcp_send_head(sk)) {
+		elapsed = keepalive_time_when(tp);
 		goto resched;
+	}
 
 	elapsed = keepalive_time_elapsed(tp);