Skip to content

Commit 0bfbedb

Browse files
Eric Dumazetdavem330
authored andcommitted
tunnels: Optimize tx path
We currently dirty a cache line to update tunnel device stats (tx_packets/tx_bytes). We better use the txq->tx_bytes/tx_packets counters that already are present in cpu cache, in the cache line shared with txq->_xmit_lock This patch extends IPTUNNEL_XMIT() macro to use txq pointer provided by the caller. Also &tunnel->dev->stats can be replaced by &dev->stats Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 16c6cf8 commit 0bfbedb

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

include/net/ipip.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ struct ip_tunnel_prl_entry
4242
ip_select_ident(iph, &rt->u.dst, NULL); \
4343
\
4444
err = ip_local_out(skb); \
45-
if (net_xmit_eval(err) == 0) { \
46-
stats->tx_bytes += pkt_len; \
47-
stats->tx_packets++; \
45+
if (likely(net_xmit_eval(err) == 0)) { \
46+
txq->tx_bytes += pkt_len; \
47+
txq->tx_packets++; \
4848
} else { \
4949
stats->tx_errors++; \
5050
stats->tx_aborted_errors++; \

net/ipv4/ip_gre.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ static int ipgre_rcv(struct sk_buff *skb)
662662
static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
663663
{
664664
struct ip_tunnel *tunnel = netdev_priv(dev);
665-
struct net_device_stats *stats = &tunnel->dev->stats;
665+
struct net_device_stats *stats = &dev->stats;
666+
struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
666667
struct iphdr *old_iph = ip_hdr(skb);
667668
struct iphdr *tiph;
668669
u8 tos;
@@ -810,7 +811,7 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev
810811
struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
811812
if (!new_skb) {
812813
ip_rt_put(rt);
813-
stats->tx_dropped++;
814+
txq->tx_dropped++;
814815
dev_kfree_skb(skb);
815816
return NETDEV_TX_OK;
816817
}

net/ipv4/ipip.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ static int ipip_rcv(struct sk_buff *skb)
390390
static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
391391
{
392392
struct ip_tunnel *tunnel = netdev_priv(dev);
393-
struct net_device_stats *stats = &tunnel->dev->stats;
393+
struct net_device_stats *stats = &dev->stats;
394+
struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
394395
struct iphdr *tiph = &tunnel->parms.iph;
395396
u8 tos = tunnel->parms.iph.tos;
396397
__be16 df = tiph->frag_off;
@@ -478,7 +479,7 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
478479
struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
479480
if (!new_skb) {
480481
ip_rt_put(rt);
481-
stats->tx_dropped++;
482+
txq->tx_dropped++;
482483
dev_kfree_skb(skb);
483484
return NETDEV_TX_OK;
484485
}

net/ipv6/sit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
555555
struct net_device *dev)
556556
{
557557
struct ip_tunnel *tunnel = netdev_priv(dev);
558-
struct net_device_stats *stats = &tunnel->dev->stats;
558+
struct net_device_stats *stats = &dev->stats;
559+
struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
559560
struct iphdr *tiph = &tunnel->parms.iph;
560561
struct ipv6hdr *iph6 = ipv6_hdr(skb);
561562
u8 tos = tunnel->parms.iph.tos;
@@ -688,7 +689,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
688689
struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
689690
if (!new_skb) {
690691
ip_rt_put(rt);
691-
stats->tx_dropped++;
692+
txq->tx_dropped++;
692693
dev_kfree_skb(skb);
693694
return NETDEV_TX_OK;
694695
}

0 commit comments

Comments
 (0)