net/ena: refactor ena_get_stats64 to be atomic context safe
authorNetanel Belgazal <netanel@annapurnalabs.com>
Thu, 9 Feb 2017 13:21:32 +0000 (15:21 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 Feb 2017 03:27:06 +0000 (22:27 -0500)
ndo_get_stat64() can be called from atomic context, but the current
implementation sends an admin command to retrieve the statistics from
the device. This admin command can sleep.

This patch re-factors the implementation of ena_get_stats64() to use
the {rx,tx}bytes/count from the driver's inner counters, and to obtain
the rx drop counter from the asynchronous keep alive (heart bit)
event.

Signed-off-by: Netanel Belgazal <netanel@annapurnalabs.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amazon/ena/ena_admin_defs.h
drivers/net/ethernet/amazon/ena/ena_netdev.c
drivers/net/ethernet/amazon/ena/ena_netdev.h

index e1594d6d6789db4890eff96b710e06b2214a3884..5b6509d59716241505095f86d5b391f818ac9584 100644 (file)
@@ -873,6 +873,14 @@ struct ena_admin_aenq_link_change_desc {
        u32 flags;
 };
 
+struct ena_admin_aenq_keep_alive_desc {
+       struct ena_admin_aenq_common_desc aenq_common_desc;
+
+       u32 rx_drops_low;
+
+       u32 rx_drops_high;
+};
+
 struct ena_admin_ena_mmio_req_read_less_resp {
        u16 req_id;
 
index d1aa7b63f797a2b165ccfe216e9959427edcb7c2..54493e13dcaf8c09b19b930d2c8ccbd9d5e87543 100644 (file)
@@ -2169,28 +2169,46 @@ static void ena_get_stats64(struct net_device *netdev,
                            struct rtnl_link_stats64 *stats)
 {
        struct ena_adapter *adapter = netdev_priv(netdev);
-       struct ena_admin_basic_stats ena_stats;
-       int rc;
+       struct ena_ring *rx_ring, *tx_ring;
+       unsigned int start;
+       u64 rx_drops;
+       int i;
 
        if (!test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
                return;
 
-       rc = ena_com_get_dev_basic_stats(adapter->ena_dev, &ena_stats);
-       if (rc)
-               return;
+       for (i = 0; i < adapter->num_queues; i++) {
+               u64 bytes, packets;
+
+               tx_ring = &adapter->tx_ring[i];
 
-       stats->tx_bytes = ((u64)ena_stats.tx_bytes_high << 32) |
-               ena_stats.tx_bytes_low;
-       stats->rx_bytes = ((u64)ena_stats.rx_bytes_high << 32) |
-               ena_stats.rx_bytes_low;
+               do {
+                       start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
+                       packets = tx_ring->tx_stats.cnt;
+                       bytes = tx_ring->tx_stats.bytes;
+               } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
 
-       stats->rx_packets = ((u64)ena_stats.rx_pkts_high << 32) |
-               ena_stats.rx_pkts_low;
-       stats->tx_packets = ((u64)ena_stats.tx_pkts_high << 32) |
-               ena_stats.tx_pkts_low;
+               stats->tx_packets += packets;
+               stats->tx_bytes += bytes;
+
+               rx_ring = &adapter->rx_ring[i];
+
+               do {
+                       start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
+                       packets = rx_ring->rx_stats.cnt;
+                       bytes = rx_ring->rx_stats.bytes;
+               } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
+
+               stats->rx_packets += packets;
+               stats->rx_bytes += bytes;
+       }
+
+       do {
+               start = u64_stats_fetch_begin_irq(&adapter->syncp);
+               rx_drops = adapter->dev_stats.rx_drops;
+       } while (u64_stats_fetch_retry_irq(&adapter->syncp, start));
 
-       stats->rx_dropped = ((u64)ena_stats.rx_drops_high << 32) |
-               ena_stats.rx_drops_low;
+       stats->rx_dropped = rx_drops;
 
        stats->multicast = 0;
        stats->collisions = 0;
index 69d7e9ed5bc8583ccc675f60b7a891191568a40e..f0ddc117d9765dba11939a6f67eaa07787fe60be 100644 (file)
@@ -241,6 +241,7 @@ struct ena_stats_dev {
        u64 interface_up;
        u64 interface_down;
        u64 admin_q_pause;
+       u64 rx_drops;
 };
 
 enum ena_flags_t {