net: add a core netdev->rx_dropped counter
authorEric Dumazet <eric.dumazet@gmail.com>
Thu, 30 Sep 2010 21:06:55 +0000 (21:06 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 5 Oct 2010 21:47:55 +0000 (14:47 -0700)
In various situations, a device provides a packet to our stack and we
drop it before it enters protocol stack :
- softnet backlog full (accounted in /proc/net/softnet_stat)
- bad vlan tag (not accounted)
- unknown/unregistered protocol (not accounted)

We can handle a per-device counter of such dropped frames at core level,
and automatically adds it to the device provided stats (rx_dropped), so
that standard tools can be used (ifconfig, ip link, cat /proc/net/dev)

This is a generalization of commit 8990f468a (net: rx_dropped
accounting), thus reverting it.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/loopback.c
include/linux/netdevice.h
net/8021q/vlan.h
net/8021q/vlan_core.c
net/8021q/vlan_dev.c
net/core/dev.c
net/ipv4/ip_gre.c
net/ipv4/ipip.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6mr.c
net/ipv6/sit.c

index 4b0e30b564e55fc0809a542b861747e1f354c19b..2d9663a1c54d91b3e25246f671ab35c51b606921 100644 (file)
@@ -64,7 +64,6 @@ struct pcpu_lstats {
        u64                     packets;
        u64                     bytes;
        struct u64_stats_sync   syncp;
-       unsigned long           drops;
 };
 
 /*
@@ -90,8 +89,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
                lb_stats->bytes += len;
                lb_stats->packets++;
                u64_stats_update_end(&lb_stats->syncp);
-       } else
-               lb_stats->drops++;
+       }
 
        return NETDEV_TX_OK;
 }
@@ -101,7 +99,6 @@ static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
 {
        u64 bytes = 0;
        u64 packets = 0;
-       u64 drops = 0;
        int i;
 
        for_each_possible_cpu(i) {
@@ -115,14 +112,11 @@ static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
                        tbytes = lb_stats->bytes;
                        tpackets = lb_stats->packets;
                } while (u64_stats_fetch_retry(&lb_stats->syncp, start));
-               drops   += lb_stats->drops;
                bytes   += tbytes;
                packets += tpackets;
        }
        stats->rx_packets = packets;
        stats->tx_packets = packets;
-       stats->rx_dropped = drops;
-       stats->rx_errors  = drops;
        stats->rx_bytes   = bytes;
        stats->tx_bytes   = bytes;
        return stats;
index 92d81edd58087e4ac3ef835338c1bec1b7ab627a..6abcef67b1784e2309394976ac41133c5bbd337f 100644 (file)
@@ -884,6 +884,9 @@ struct net_device {
        int                     iflink;
 
        struct net_device_stats stats;
+       atomic_long_t           rx_dropped; /* dropped packets by core network
+                                            * Do not use this in drivers.
+                                            */
 
 #ifdef CONFIG_WIRELESS_EXT
        /* List of functions to handle Wireless Extensions (instead of ioctl).
index b26ce343072c65a6a1776e1b42d35a0373f40fd6..8d9503ad01daa65729212de33f579b32aeffc1dc 100644 (file)
@@ -25,7 +25,6 @@ struct vlan_priority_tci_mapping {
  *     @rx_multicast: number of received multicast packets
  *     @syncp: synchronization point for 64bit counters
  *     @rx_errors: number of errors
- *     @rx_dropped: number of dropped packets
  */
 struct vlan_rx_stats {
        u64                     rx_packets;
@@ -33,7 +32,6 @@ struct vlan_rx_stats {
        u64                     rx_multicast;
        struct u64_stats_sync   syncp;
        unsigned long           rx_errors;
-       unsigned long           rx_dropped;
 };
 
 /**
index b6d55a9304f2bcb39a3bf9c4ee4f586412532f8e..dee727ce0291ea3cf8887a894fb08185414ba48c 100644 (file)
@@ -33,6 +33,7 @@ int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
        return polling ? netif_receive_skb(skb) : netif_rx(skb);
 
 drop:
+       atomic_long_inc(&skb->dev->rx_dropped);
        dev_kfree_skb_any(skb);
        return NET_RX_DROP;
 }
@@ -123,6 +124,7 @@ vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
        return dev_gro_receive(napi, skb);
 
 drop:
+       atomic_long_inc(&skb->dev->rx_dropped);
        return GRO_DROP;
 }
 
index f6fbcc0f1af9e8694f8c55a5f277bc79d2f86539..f54251edd40dfc09373c1d21e9eb434e19a5a064 100644 (file)
@@ -225,16 +225,15 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
                }
        }
 
-       if (unlikely(netif_rx(skb) == NET_RX_DROP)) {
-               if (rx_stats)
-                       rx_stats->rx_dropped++;
-       }
+       netif_rx(skb);
+
        rcu_read_unlock();
        return NET_RX_SUCCESS;
 
 err_unlock:
        rcu_read_unlock();
 err_free:
+       atomic_long_inc(&dev->rx_dropped);
        kfree_skb(skb);
        return NET_RX_DROP;
 }
@@ -846,15 +845,13 @@ static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev, st
                        accum.rx_packets += rxpackets;
                        accum.rx_bytes   += rxbytes;
                        accum.rx_multicast += rxmulticast;
-                       /* rx_errors, rx_dropped are ulong, not protected by syncp */
+                       /* rx_errors is ulong, not protected by syncp */
                        accum.rx_errors  += p->rx_errors;
-                       accum.rx_dropped += p->rx_dropped;
                }
                stats->rx_packets = accum.rx_packets;
                stats->rx_bytes   = accum.rx_bytes;
                stats->rx_errors  = accum.rx_errors;
                stats->multicast  = accum.rx_multicast;
-               stats->rx_dropped = accum.rx_dropped;
        }
        return stats;
 }
index ce6ad88c980b8105531916fa3aa00ced83f437bd..7d149550e8d623ee6bee8d961d91d9d4800d90dd 100644 (file)
@@ -1483,8 +1483,9 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
        skb_orphan(skb);
        nf_reset(skb);
 
-       if (!(dev->flags & IFF_UP) ||
-           (skb->len > (dev->mtu + dev->hard_header_len))) {
+       if (unlikely(!(dev->flags & IFF_UP) ||
+                    (skb->len > (dev->mtu + dev->hard_header_len)))) {
+               atomic_long_inc(&dev->rx_dropped);
                kfree_skb(skb);
                return NET_RX_DROP;
        }
@@ -2548,6 +2549,7 @@ enqueue:
 
        local_irq_restore(flags);
 
+       atomic_long_inc(&skb->dev->rx_dropped);
        kfree_skb(skb);
        return NET_RX_DROP;
 }
@@ -2995,6 +2997,7 @@ ncls:
        if (pt_prev) {
                ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
        } else {
+               atomic_long_inc(&skb->dev->rx_dropped);
                kfree_skb(skb);
                /* Jamal, now you will not able to escape explaining
                 * me how you were going to use this. :-)
@@ -5429,14 +5432,14 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
 
        if (ops->ndo_get_stats64) {
                memset(storage, 0, sizeof(*storage));
-               return ops->ndo_get_stats64(dev, storage);
-       }
-       if (ops->ndo_get_stats) {
+               ops->ndo_get_stats64(dev, storage);
+       } else if (ops->ndo_get_stats) {
                netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev));
-               return storage;
+       } else {
+               netdev_stats_to_stats64(storage, &dev->stats);
+               dev_txq_stats_fold(dev, storage);
        }
-       netdev_stats_to_stats64(storage, &dev->stats);
-       dev_txq_stats_fold(dev, storage);
+       storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
        return storage;
 }
 EXPORT_SYMBOL(dev_get_stats);
index fbe2c473a06a05ca82b0f0d2fff935924aa114e5..9d421f4cf3efbf41f52d1bd9d0a43c5b6aa2313d 100644 (file)
@@ -679,8 +679,7 @@ static int ipgre_rcv(struct sk_buff *skb)
                skb_reset_network_header(skb);
                ipgre_ecn_decapsulate(iph, skb);
 
-               if (netif_rx(skb) == NET_RX_DROP)
-                       tunnel->dev->stats.rx_dropped++;
+               netif_rx(skb);
 
                rcu_read_unlock();
                return 0;
index 6ad46c28ede210b822bf0e9585e130beaccebf05..e9b816e6cd73a681ea02e9540d6849eb924f4a8a 100644 (file)
@@ -414,8 +414,7 @@ static int ipip_rcv(struct sk_buff *skb)
 
                ipip_ecn_decapsulate(iph, skb);
 
-               if (netif_rx(skb) == NET_RX_DROP)
-                       tunnel->dev->stats.rx_dropped++;
+               netif_rx(skb);
 
                rcu_read_unlock();
                return 0;
index 8be3c452af9096e54c9736386c1c9d24b1328c36..c2c0f89397b1164bacefdb449cd2b97dbe41d66c 100644 (file)
@@ -768,8 +768,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
 
                dscp_ecn_decapsulate(t, ipv6h, skb);
 
-               if (netif_rx(skb) == NET_RX_DROP)
-                       t->dev->stats.rx_dropped++;
+               netif_rx(skb);
 
                rcu_read_unlock();
                return 0;
index 2640c9be589dd62805dab83ed910ba4cbad694d6..6f32ffce7022c198e4c78c9126c3df90026697c2 100644 (file)
@@ -666,8 +666,7 @@ static int pim6_rcv(struct sk_buff *skb)
 
        skb_tunnel_rx(skb, reg_dev);
 
-       if (netif_rx(skb) == NET_RX_DROP)
-               reg_dev->stats.rx_dropped++;
+       netif_rx(skb);
 
        dev_put(reg_dev);
        return 0;
index d7701782b6391a03bd04098d5d8b749d81fff4bb..367a6cc584ccc40bb1c5a7fc03022bd89f304d10 100644 (file)
@@ -600,8 +600,7 @@ static int ipip6_rcv(struct sk_buff *skb)
 
                ipip6_ecn_decapsulate(iph, skb);
 
-               if (netif_rx(skb) == NET_RX_DROP)
-                       tunnel->dev->stats.rx_dropped++;
+               netif_rx(skb);
 
                rcu_read_unlock();
                return 0;