diff mbox series

[net-next] tcp: minor optimization in tcp ack fast path processing

Message ID 1541589617-1607-2-git-send-email-laoar.shao@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series [net-next] tcp: minor optimization in tcp ack fast path processing | expand

Commit Message

Yafang Shao Nov. 7, 2018, 11:20 a.m. UTC
Bitwise operation is a little faster.
So I replace after() with (flag & FLAG_SND_UNA_ADVANCED) as this flag is
already set before.

Cc: Joe Perches <joe@perches.com>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Dumazet Nov. 7, 2018, 3:16 p.m. UTC | #1
On 11/07/2018 03:20 AM, Yafang Shao wrote:
> Bitwise operation is a little faster.


> So I replace after() with (flag & FLAG_SND_UNA_ADVANCED) as this flag is
> already set before.
> 
> Cc: Joe Perches <joe@perches.com>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  net/ipv4/tcp_input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 2868ef2..0167015 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -3610,7 +3610,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
>  	if (flag & FLAG_UPDATE_TS_RECENT)
>  		tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
>  
> -	if (!(flag & FLAG_SLOWPATH) && after(ack, prior_snd_una)) {
> +	if (!(flag & FLAG_SLOWPATH) && (flag & FLAG_SND_UNA_ADVANCED)) {
>  		/* Window is constant, pure forward advance.
>  		 * No more checks are required.
>  		 * Note, we use the fact that SND.UNA>=SND.WL2.
> 

What about reducing this to a single conditional jump ?

if ((flag & (FLAG_SLOWPATH | FLAG_SND_UNA_ADVANCED)) == FLAG_SND_UNA_ADVANCED)  {
Yafang Shao Nov. 8, 2018, 1:45 a.m. UTC | #2
On Wed, Nov 7, 2018 at 11:16 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
>
> On 11/07/2018 03:20 AM, Yafang Shao wrote:
> > Bitwise operation is a little faster.
>
>
> > So I replace after() with (flag & FLAG_SND_UNA_ADVANCED) as this flag is
> > already set before.
> >
> > Cc: Joe Perches <joe@perches.com>
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  net/ipv4/tcp_input.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> > index 2868ef2..0167015 100644
> > --- a/net/ipv4/tcp_input.c
> > +++ b/net/ipv4/tcp_input.c
> > @@ -3610,7 +3610,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
> >       if (flag & FLAG_UPDATE_TS_RECENT)
> >               tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
> >
> > -     if (!(flag & FLAG_SLOWPATH) && after(ack, prior_snd_una)) {
> > +     if (!(flag & FLAG_SLOWPATH) && (flag & FLAG_SND_UNA_ADVANCED)) {
> >               /* Window is constant, pure forward advance.
> >                * No more checks are required.
> >                * Note, we use the fact that SND.UNA>=SND.WL2.
> >
>
> What about reducing this to a single conditional jump ?
>
> if ((flag & (FLAG_SLOWPATH | FLAG_SND_UNA_ADVANCED)) == FLAG_SND_UNA_ADVANCED)  {
>

That's better.
Will change it.


Thanks
Yafang
diff mbox series

Patch

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 2868ef2..0167015 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3610,7 +3610,7 @@  static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
 	if (flag & FLAG_UPDATE_TS_RECENT)
 		tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
 
-	if (!(flag & FLAG_SLOWPATH) && after(ack, prior_snd_una)) {
+	if (!(flag & FLAG_SLOWPATH) && (flag & FLAG_SND_UNA_ADVANCED)) {
 		/* Window is constant, pure forward advance.
 		 * No more checks are required.
 		 * Note, we use the fact that SND.UNA>=SND.WL2.