ice: Accumulate HW and Netdev statistics over reset
authorBenjamin Mikailenko <benjamin.mikailenko@intel.com>
Fri, 18 Nov 2022 21:20:01 +0000 (16:20 -0500)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Wed, 23 Nov 2022 16:59:43 +0000 (08:59 -0800)
Resets happen with or without user interaction. For example, incidents
such as TX hang or a reconfiguration of parameters will result in a reset.
During reset, hardware and software statistics were set to zero. This
created an issue for the user where a reset happens in the background,
statistics set to zero, and the user checks statistics expecting them to
be populated.

To ensure this doesn't happen, keep accumulating stats over reset.

1. Remove function calls which reset hardware and netdev statistics.
2. Do not rollover statistics in ice_stat_update40 during reset.

Signed-off-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice.h
drivers/net/ethernet/intel/ice/ice_dcb_lib.c
drivers/net/ethernet/intel/ice/ice_lib.c
drivers/net/ethernet/intel/ice/ice_main.c

index f88ee05..74d40a7 100644 (file)
@@ -373,6 +373,7 @@ struct ice_vsi {
 
        /* VSI stats */
        struct rtnl_link_stats64 net_stats;
+       struct rtnl_link_stats64 net_stats_prev;
        struct ice_eth_stats eth_stats;
        struct ice_eth_stats eth_stats_prev;
 
index 9defb9d..4f24d44 100644 (file)
@@ -881,6 +881,9 @@ void ice_update_dcb_stats(struct ice_pf *pf)
        prev_ps = &pf->stats_prev;
        cur_ps = &pf->stats;
 
+       if (ice_is_reset_in_progress(pf->state))
+               pf->stat_prev_loaded = false;
+
        for (i = 0; i < 8; i++) {
                ice_stat_update32(hw, GLPRT_PXOFFRXC(port, i),
                                  pf->stat_prev_loaded,
index a2cfa0c..ffb455e 100644 (file)
@@ -1795,11 +1795,15 @@ void ice_update_eth_stats(struct ice_vsi *vsi)
 {
        struct ice_eth_stats *prev_es, *cur_es;
        struct ice_hw *hw = &vsi->back->hw;
+       struct ice_pf *pf = vsi->back;
        u16 vsi_num = vsi->vsi_num;    /* HW absolute index of a VSI */
 
        prev_es = &vsi->eth_stats_prev;
        cur_es = &vsi->eth_stats;
 
+       if (ice_is_reset_in_progress(pf->state))
+               vsi->stat_offsets_loaded = false;
+
        ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
                          &prev_es->rx_bytes, &cur_es->rx_bytes);
 
@@ -3304,6 +3308,8 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
                        goto err_vectors;
 
                ice_vsi_map_rings_to_vectors(vsi);
+
+               vsi->stat_offsets_loaded = false;
                if (ice_is_xdp_ena_vsi(vsi)) {
                        ret = ice_vsi_determine_xdp_res(vsi);
                        if (ret)
@@ -3340,6 +3346,7 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
                if (ret)
                        goto err_vectors;
 
+               vsi->stat_offsets_loaded = false;
                break;
        case ICE_VSI_CHNL:
                if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
index d6f460f..aa80e2b 100644 (file)
@@ -6397,6 +6397,7 @@ ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
  */
 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
 {
+       struct rtnl_link_stats64 *net_stats, *stats_prev;
        struct rtnl_link_stats64 *vsi_stats;
        u64 pkts, bytes;
        int i;
@@ -6436,10 +6437,28 @@ static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
 
        rcu_read_unlock();
 
-       vsi->net_stats.tx_packets = vsi_stats->tx_packets;
-       vsi->net_stats.tx_bytes = vsi_stats->tx_bytes;
-       vsi->net_stats.rx_packets = vsi_stats->rx_packets;
-       vsi->net_stats.rx_bytes = vsi_stats->rx_bytes;
+       net_stats = &vsi->net_stats;
+       stats_prev = &vsi->net_stats_prev;
+
+       /* clear prev counters after reset */
+       if (vsi_stats->tx_packets < stats_prev->tx_packets ||
+           vsi_stats->rx_packets < stats_prev->rx_packets) {
+               stats_prev->tx_packets = 0;
+               stats_prev->tx_bytes = 0;
+               stats_prev->rx_packets = 0;
+               stats_prev->rx_bytes = 0;
+       }
+
+       /* update netdev counters */
+       net_stats->tx_packets += vsi_stats->tx_packets - stats_prev->tx_packets;
+       net_stats->tx_bytes += vsi_stats->tx_bytes - stats_prev->tx_bytes;
+       net_stats->rx_packets += vsi_stats->rx_packets - stats_prev->rx_packets;
+       net_stats->rx_bytes += vsi_stats->rx_bytes - stats_prev->rx_bytes;
+
+       stats_prev->tx_packets = vsi_stats->tx_packets;
+       stats_prev->tx_bytes = vsi_stats->tx_bytes;
+       stats_prev->rx_packets = vsi_stats->rx_packets;
+       stats_prev->rx_bytes = vsi_stats->rx_bytes;
 
        kfree(vsi_stats);
 }
@@ -6501,6 +6520,9 @@ void ice_update_pf_stats(struct ice_pf *pf)
        prev_ps = &pf->stats_prev;
        cur_ps = &pf->stats;
 
+       if (ice_is_reset_in_progress(pf->state))
+               pf->stat_prev_loaded = false;
+
        ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
                          &prev_ps->eth.rx_bytes,
                          &cur_ps->eth.rx_bytes);