gre: Optimize tx path.
authorJesse Gross <jesse@nicira.com>
Tue, 2 Feb 2010 22:13:47 +0000 (17:13 -0500)
committerJesse Gross <jesse@nicira.com>
Thu, 4 Feb 2010 20:48:14 +0000 (15:48 -0500)
Ports commit 0bfbed "tunnels: Optimize tx path" from the mainline
kernel.

datapath/linux-2.6/compat-2.6/include/net/ipip.h
datapath/linux-2.6/compat-2.6/ip_gre.c

index 604ece2dcff3204a0407b0222f1df88ed43717bb..7fa0b2826a6c9c4426934fb617912ba941fa3511 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <linux/version.h>
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
+#define HAVE_NETDEV_QUEUE_STATS
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
 
 #include <linux/if_tunnel.h>
@@ -48,6 +52,16 @@ struct ip_tunnel_prl_entry
        spinlock_t                      lock;
 };
 
+#ifdef HAVE_NETDEV_QUEUE_STATS
+#define UPDATE_TX_STATS()                                              \
+       txq->tx_bytes += pkt_len;                                       \
+       txq->tx_packets++;
+#else
+#define UPDATE_TX_STATS()                                              \
+       stats->tx_bytes += pkt_len;                                     \
+       stats->tx_packets++;
+#endif
+
 #define IPTUNNEL_XMIT() do {                                           \
        int err;                                                        \
        int pkt_len = skb->len - skb_transport_offset(skb);             \
@@ -56,9 +70,8 @@ struct ip_tunnel_prl_entry
        ip_select_ident(iph, &rt->u.dst, NULL);                         \
                                                                        \
        err = ip_local_out(skb);                                        \
-       if (net_xmit_eval(err) == 0) {                                  \
-               stats->tx_bytes += pkt_len;                             \
-               stats->tx_packets++;                                    \
+       if (likely(net_xmit_eval(err) == 0)) {                          \
+               UPDATE_TX_STATS();                                      \
        } else {                                                        \
                stats->tx_errors++;                                     \
                stats->tx_aborted_errors++;                             \
index 05c6055b5b524683bd1eca4b29a04e39fa19c942..4c47b92530af17f600dca771efce05e4e0dc61ac 100644 (file)
@@ -696,6 +696,9 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
        struct net_device_stats *stats;
+#ifdef HAVE_NETDEV_QUEUE_STATS
+       struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
+#endif
        struct iphdr  *old_iph = ip_hdr(skb);
        struct iphdr  *tiph;
        u8     tos;
@@ -709,7 +712,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
        int    mtu;
 
 #ifdef HAVE_NETDEV_STATS
-       stats = &tunnel->dev->stats;
+       stats = &dev->stats;
 #else
        stats = &tunnel->stat;
 #endif
@@ -860,7 +863,11 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
                struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
                if (!new_skb) {
                        ip_rt_put(rt);
+#ifdef HAVE_NETDEV_QUEUE_STATS
+                       txq->tx_dropped++;
+#else
                        stats->tx_dropped++;
+#endif
                        dev_kfree_skb(skb);
                        return NETDEV_TX_OK;
                }