From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yafang Shao Subject: [PATCH net-next 2/2] ipv6: replace ip_hdr() with skb->data for optimization Date: Tue, 5 Jun 2018 08:04:22 -0400 Message-ID: <1528200262-11834-2-git-send-email-laoar.shao@gmail.com> References: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com> Cc: netdev@vger.kernel.org, inux-kernel@vger.kernel.org, Yafang Shao To: edumazet@google.com, davem@davemloft.net Return-path: Received: from mail-pl0-f66.google.com ([209.85.160.66]:37676 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751598AbeFEMEq (ORCPT ); Tue, 5 Jun 2018 08:04:46 -0400 In-Reply-To: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: In ipv6 receive path, when ip header hasn't been pulled yet, ip_hdr() and skb->data are pointing to the same byte. In ipv6 output path, when ip header is just pushed, ip_hdr() and skb->data are pointing to the same byte. As ip_hdr() is more expensive than using skb->data, so replace ip_hdr() with skb->data in these situations for optimization. Signed-off-by: Yafang Shao --- net/ipv6/ip6_input.c | 4 ++-- net/ipv6/ip6_output.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index f08d344..2ff4fe8 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -113,7 +113,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt if (unlikely(!pskb_may_pull(skb, sizeof(*hdr)))) goto err; - hdr = ipv6_hdr(skb); + hdr = (const struct ipv6hdr *)skb->data; if (hdr->version != 6) goto err; @@ -189,7 +189,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); goto drop; } - hdr = ipv6_hdr(skb); + hdr = (const struct ipv6hdr *)skb->data; } if (hdr->nexthdr == NEXTHDR_HOP) { diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 021e5ae..8bb3bc1 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -235,7 +235,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); - hdr = ipv6_hdr(skb); + hdr = (struct ipv6hdr *)skb->data; /* * Fill in the IPv6 header @@ -1659,7 +1659,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); - hdr = ipv6_hdr(skb); + hdr = (struct ipv6hdr *)skb->data; ip6_flow_hdr(hdr, v6_cork->tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, -- 1.8.3.1