tun: Use netif_receive_skb instead of netif_rx

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Herbert Xu
Date: Wednesday, May 19, 2010 - 12:57 am

Hi:

tun: Use netif_receive_skb instead of netif_rx

First a bit of history as I recall, Dave can correct me where
he recalls differently :)

1) There was netif_rx and everyone had to use that.
2) Everyone had to use that, including drivers/net/tun.c.
3) NAPI brings us netif_receive_skb.
4) About the same time people noticed that tun.c can cause wild
   fluctuations in latency because of its use of netif_rx with IRQs
   enabled.
5) netif_rx_ni was added to address this.

However, netif_rx_ni was really a bit of a roundabout way of
injecting a packet if you think about it.  What ends up happening
is that we always queue the packet into the backlog, and then
immediately process it.  Which is what would happen if we simply
called netif_receive_skb directly.

So this patch just does the obvious thing and makes tun.c call
netif_receive_skb, albeit through the netif_receive_skb_ni wrapper
which does the necessary things for calling it in process context.

Now apart from potential performance gains from eliminating
unnecessary steps in the process, this has the benefit of keeping
the process context for the packet processing.  This is needed
by cgroups to shape network traffic based on the original process.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 4326520..0eed49f 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -667,7 +667,7 @@ static __inline__ ssize_t tun_get_user(struct tun_struct *tun,
 		skb_shinfo(skb)->gso_segs = 0;
 	}
 
-	netif_rx_ni(skb);
+	netif_receive_skb_ni(skb);
 
 	tun->dev->stats.rx_packets++;
 	tun->dev->stats.rx_bytes += len;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index fa8b476..34bb405 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1562,6 +1562,18 @@ extern int		netif_rx(struct sk_buff *skb);
 extern int		netif_rx_ni(struct sk_buff *skb);
 #define HAVE_NETIF_RECEIVE_SKB 1
 extern int		netif_receive_skb(struct sk_buff *skb);
+
+static inline int netif_receive_skb_ni(struct sk_buff *skb)
+{
+	int err;
+
+	local_bh_disable();
+	err = netif_receive_skb(skb);
+	local_bh_enable();
+
+	return err;
+}
+
 extern gro_result_t	dev_gro_receive(struct napi_struct *napi,
 					struct sk_buff *skb);
 extern gro_result_t	napi_skb_finish(gro_result_t ret, struct sk_buff *skb);

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 12:57 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 1:09 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 1:18 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 1:20 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 1:21 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 1:27 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 1:44 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Wed May 19, 5:05 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Wed May 19, 5:55 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 7:10 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Wed May 19, 7:31 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Wed May 19, 11:00 am)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Wed May 19, 1:14 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Wed May 19, 1:24 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Thomas Graf, (Wed May 19, 1:49 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Brian Bloniarz, (Wed May 19, 2:00 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Wed May 19, 7:55 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 7:57 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Wed May 19, 8:05 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 8:34 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 8:42 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Wed May 19, 8:46 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 9:54 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 10:01 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 10:15 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 10:20 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 10:36 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 10:46 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Eric Dumazet, (Wed May 19, 11:03 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 11:11 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 11:19 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Wed May 19, 11:52 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Thomas Graf, (Thu May 20, 1:10 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Thomas Graf, (Thu May 20, 2:40 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Thu May 20, 10:29 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Thu May 20, 4:16 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Thu May 20, 5:39 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Thu May 20, 6:02 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Thu May 20, 6:16 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Thu May 20, 10:49 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Fri May 21, 3:51 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Herbert Xu, (Fri May 21, 4:08 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Fri May 21, 5:59 am)
Re: tun: Use netif_receive_skb instead of netif_rx, Neil Horman, (Fri May 21, 9:40 am)
cls_cgroup: Store classid in struct sock, Herbert Xu, (Fri May 21, 6:49 pm)
Re: cls_cgroup: Store classid in struct sock, Neil Horman, (Sat May 22, 5:26 am)
Re: cls_cgroup: Store classid in struct sock, Herbert Xu, (Sun May 23, 10:42 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Sun May 23, 11:44 pm)
Re: tun: Use netif_receive_skb instead of netif_rx, David Miller, (Sun May 23, 11:44 pm)
Re: cls_cgroup: Store classid in struct sock, David Miller, (Sun May 23, 11:44 pm)
Re: cls_cgroup: Store classid in struct sock, David Miller, (Sun May 23, 11:55 pm)
Re: cls_cgroup: Store classid in struct sock, Herbert Xu, (Mon May 24, 12:07 am)
Re: cls_cgroup: Store classid in struct sock, David Miller, (Mon May 24, 12:14 am)
Re: cls_cgroup: Store classid in struct sock, Neil Horman, (Mon May 24, 4:09 am)
Re: cls_cgroup: Store classid in struct sock, Herbert Xu, (Mon May 24, 4:24 am)