netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: edumazet@google.com, davem@davemloft.net
Cc: netdev@vger.kernel.org, inux-kernel@vger.kernel.org,
	Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH net-next 2/2] ipv6: replace ip_hdr() with skb->data for optimization
Date: Tue,  5 Jun 2018 08:04:22 -0400	[thread overview]
Message-ID: <1528200262-11834-2-git-send-email-laoar.shao@gmail.com> (raw)
In-Reply-To: <1528200262-11834-1-git-send-email-laoar.shao@gmail.com>

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 <laoar.shao@gmail.com>
---
 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

  reply	other threads:[~2018-06-05 12:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 12:04 [PATCH net-next 1/2] ipv4: replace ip_hdr() with skb->data for optimization Yafang Shao
2018-06-05 12:04 ` Yafang Shao [this message]
2018-06-05 12:20 ` Paolo Abeni
2018-06-05 12:29   ` Yafang Shao
2018-06-05 15:08     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528200262-11834-2-git-send-email-laoar.shao@gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=inux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).