Re: [PATCH v3 net-next 2/2] tcp: minor optimization around tcp_hdr() usage in tcp receive path

From: Yafang Shao
Date: Mon May 28 2018 - 20:42:22 EST


On Tue, May 29, 2018 at 12:36 AM, Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
> On Mon, May 28, 2018 at 8:36 AM Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
>
>> This is additional to the commit ea1627c20c34 ("tcp: minor optimizations
> around tcp_hdr() usage").
>> At this point, skb->data is same with tcp_hdr() as tcp header has not
>> been pulled yet.
>
>> Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
>> Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
>> ---
>> net/ipv4/tcp_ipv4.c | 2 +-
>> net/ipv6/tcp_ipv6.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
>> index adbdb50..d179386 100644
>> --- a/net/ipv4/tcp_ipv4.c
>> +++ b/net/ipv4/tcp_ipv4.c
>> @@ -1486,7 +1486,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff
> *skb)
>> sk->sk_rx_dst = NULL;
>> }
>> }
>> - tcp_rcv_established(sk, skb, tcp_hdr(skb));
>> + tcp_rcv_established(sk, skb, (const struct tcphdr
> *)skb->data);
>> return 0;
>> }
>
>> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
>> index 7d47c2b..1c633ff 100644
>> --- a/net/ipv6/tcp_ipv6.c
>> +++ b/net/ipv6/tcp_ipv6.c
>> @@ -1322,7 +1322,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct
> sk_buff *skb)
>> }
>> }
>
>> - tcp_rcv_established(sk, skb, tcp_hdr(skb));
>> + tcp_rcv_established(sk, skb, (const struct tcphdr
> *)skb->data);
>> if (opt_skb)
>> goto ipv6_pktoptions;
>> return 0;
>> --
>> 1.8.3.1
>
>
> I would rather remove the third parameter of tcp_rcv_established() instead
> of duplicating the cast.

OK.

And what about introducing a new helper tcp_hdr_fast() ?

/* use it when tcp header has not been pulled yet */
static inline struct tcphdr *tcp_hdr_fast(const struct sk_buff *skb)

{

return (const struct tcphdr *)skb->data;

}


That could help us to use this optimized one instead of the original
one if possilbe.

Thanks
Yafang