Skip to contentSkip to conversation

ipv4: use unlikely to optimise in ip_forward

PATCH In review [email protected] 2 participants 3 messages Mar 10, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: use unlikely to optimise in ip_forward

From: Li RongQing <[email protected]>

The condition that skb->pkt_type is not PACKET_HOST in ip_forward, should never happen, so use unlikely to optimise this check

---
 net/ipv4/ip_forward.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_forward.c +1 -1
index be8abe7..b82833a 100644
@@ -128,7 +128,7 @@ int ip_forward(struct sk_buff *skb)
 	struct ip_options *opt	= &(IPCB(skb)->opt);
 
 	/* that should never happen */
-	if (skb->pkt_type != PACKET_HOST)
+	if (unlikely(skb->pkt_type != PACKET_HOST))
 		goto drop;
 
 	if (skb_warn_if_lro(skb))
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 15 lines · On Mon, 2014-03-10 at 13:10 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

The condition that skb->pkt_type is not PACKET_HOST in ip_forward, should never happen, so use unlikely to optimise this check

---
 net/ipv4/ip_forward.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_forward.c +0 -0
index be8abe7..b82833a 100644

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 134

Quoted 8 lines
net/ipv4/ip_forward.c +1 -1
@@ -128,7 +128,7 @@ int ip_forward(struct sk_buff *skb)
 	struct ip_options *opt	= &(IPCB(skb)->opt);
 
 	/* that should never happen */
-	if (skb->pkt_type != PACKET_HOST)
+	if (unlikely(skb->pkt_type != PACKET_HOST))
 		goto drop;
 
 	if (skb_warn_if_lro(skb))

Compilers already do the right thing.

This is one of the reason you see so many goto in the kernel.

#2 lore raw

Ok, thanks

-R

Quoted 31 lines · Eric Dumazet
Quoted 15 lines · On Mon, 2014-03-10 at 13:10 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

The condition that skb->pkt_type is not PACKET_HOST in ip_forward, should never happen, so use unlikely to optimise this check

---
 net/ipv4/ip_forward.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_forward.c +0 -0
index be8abe7..b82833a 100644

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 134

Quoted 8 lines
net/ipv4/ip_forward.c +1 -1
@@ -128,7 +128,7 @@ int ip_forward(struct sk_buff *skb)
      struct ip_options *opt  = &(IPCB(skb)->opt);
 
      /* that should never happen */
-     if (skb->pkt_type != PACKET_HOST)
+     if (unlikely(skb->pkt_type != PACKET_HOST))
              goto drop;
 
      if (skb_warn_if_lro(skb))

Compilers already do the right thing.

This is one of the reason you see so many goto in the kernel.