Only expose the counters currently available (bytes, packets); add account for base stats to deal with ring clear. Signed-off-by: Paolo Abeni --- drivers/net/ethernet/intel/i40e/i40e.h | 7 ++ drivers/net/ethernet/intel/i40e/i40e_main.c | 133 ++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index dcb50c2e1aa2..fe642c464e9c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -836,16 +836,23 @@ struct i40e_vsi { struct i40e_eth_stats eth_stats; struct i40e_eth_stats eth_stats_offsets; u64 tx_restart; + u64 tx_restart_base; u64 tx_busy; + u64 tx_busy_base; u64 tx_linearize; u64 tx_force_wb; u64 tx_stopped; + u64 tx_stopped_base; + u64 tx_bytes; + u64 tx_packets; u64 rx_buf_failed; u64 rx_page_failed; u64 rx_page_reuse; u64 rx_page_alloc; u64 rx_page_waive; u64 rx_page_busy; + u64 rx_bytes; + u64 rx_packets; /* These are containers of ring pointers, allocated at run-time */ struct i40e_ring **rx_rings; diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 926d001b2150..0d0b3619ec56 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -11686,6 +11687,26 @@ static int i40e_vsi_clear(struct i40e_vsi *vsi) return 0; } +static void i40e_vsi_aggregate_tx_counters(struct i40e_vsi *vsi, + struct i40e_ring *tx_ring) +{ + if (!tx_ring) + return; + + vsi->tx_bytes += tx_ring->stats.bytes; + vsi->tx_packets += tx_ring->stats.packets; +} + +static void i40e_vsi_aggregate_rx_counters(struct i40e_vsi *vsi, + struct i40e_ring *rx_ring) +{ + if (!rx_ring) + return; + + vsi->rx_bytes += rx_ring->stats.bytes; + vsi->rx_packets += rx_ring->stats.packets; +} + /** * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI * @vsi: the VSI being cleaned @@ -11696,6 +11717,13 @@ static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) if (vsi->tx_rings && vsi->tx_rings[0]) { for (i = 0; i < vsi->alloc_queue_pairs; i++) { + struct i40e_ring *xdp_ring = vsi->xdp_rings ? + vsi->xdp_rings[i] : NULL; + + i40e_vsi_aggregate_tx_counters(vsi, vsi->tx_rings[i]); + i40e_vsi_aggregate_tx_counters(vsi, xdp_ring); + i40e_vsi_aggregate_rx_counters(vsi, vsi->rx_rings[i]); + kfree_rcu(vsi->tx_rings[i], rcu); WRITE_ONCE(vsi->tx_rings[i], NULL); WRITE_ONCE(vsi->rx_rings[i], NULL); @@ -13625,6 +13653,110 @@ static const struct net_device_ops i40e_netdev_ops = { .ndo_hwtstamp_set = i40e_ptp_hwtstamp_set, }; +static void i40e_get_queue_stats_rx(struct net_device *dev, int idx, + struct netdev_queue_stats_rx *rx) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct i40e_vsi *vsi = np->vsi; + struct i40e_ring *rx_ring; + unsigned int start; + u64 bytes, packets; + + rcu_read_lock(); + rx_ring = READ_ONCE(vsi->rx_rings[idx]); + if (!rx_ring) + goto unlock; + + do { + start = u64_stats_fetch_begin(&rx_ring->syncp); + bytes = rx_ring->stats.bytes; + packets = rx_ring->stats.packets; + } while (u64_stats_fetch_retry(&rx_ring->syncp, start)); + + rx->bytes = bytes; + rx->packets = packets; + +unlock: + rcu_read_unlock(); +} + +static void i40e_zero_tx_ring_stats(struct netdev_queue_stats_tx *tx) +{ + tx->bytes = 0; + tx->packets = 0; + tx->stop = 0; + tx->wake = 0; + tx->hw_drops = 0; +} + +static void i40e_add_tx_ring_stats(struct i40e_ring *tx_ring, + struct netdev_queue_stats_tx *tx) +{ + u64 bytes, packets; + unsigned int start; + + do { + start = u64_stats_fetch_begin(&tx_ring->syncp); + bytes = tx_ring->stats.bytes; + packets = tx_ring->stats.packets; + } while (u64_stats_fetch_retry(&tx_ring->syncp, start)); + + tx->bytes += bytes; + tx->packets += packets; + + tx->stop += tx_ring->tx_stats.tx_stopped; + tx->wake += tx_ring->tx_stats.restart_queue; + tx->hw_drops += tx_ring->tx_stats.tx_busy; +} + +static void i40e_get_queue_stats_tx(struct net_device *dev, int idx, + struct netdev_queue_stats_tx *tx) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct i40e_vsi *vsi = np->vsi; + struct i40e_ring *tx_ring; + + rcu_read_lock(); + tx_ring = READ_ONCE(vsi->tx_rings[idx]); + if (!tx_ring) + goto out; + + i40e_zero_tx_ring_stats(tx); + i40e_add_tx_ring_stats(tx_ring, tx); + + if (i40e_enabled_xdp_vsi(vsi)) { + tx_ring = READ_ONCE(vsi->xdp_rings[idx]); + if (tx_ring) + i40e_add_tx_ring_stats(tx_ring, tx); + } + +out: + rcu_read_unlock(); +} + +static void i40e_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct i40e_vsi *vsi = np->vsi; + + tx->bytes = vsi->tx_bytes; + tx->packets = vsi->tx_packets; + tx->wake = vsi->tx_restart_base; + tx->stop = vsi->tx_stopped_base; + tx->hw_drops = vsi->tx_busy_base; + + rx->bytes = vsi->rx_bytes; + rx->packets = vsi->rx_packets; +} + +static const struct netdev_stat_ops i40e_stat_ops = { + .get_queue_stats_rx = i40e_get_queue_stats_rx, + .get_queue_stats_tx = i40e_get_queue_stats_tx, + .get_base_stats = i40e_get_base_stats, +}; + /** * i40e_config_netdev - Setup the netdev flags * @vsi: the VSI being configured @@ -13787,6 +13919,7 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) /* Setup netdev TC information */ i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); + netdev->stat_ops = &i40e_stat_ops; netdev->netdev_ops = &i40e_netdev_ops; netdev->watchdog_timeo = 5 * HZ; i40e_set_ethtool_ops(netdev); -- 2.53.0 Track the number of GSO and wire packets transmitted and expose the counters via the queue stats. Signed-off-by: Paolo Abeni --- drivers/net/ethernet/intel/i40e/i40e.h | 2 ++ drivers/net/ethernet/intel/i40e/i40e_main.c | 13 ++++++++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 8 +++++++- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 2 ++ drivers/net/ethernet/intel/i40e/i40e_txrx_common.h | 6 +++++- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 2 +- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index fe642c464e9c..4a88c7d69f61 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -845,6 +845,8 @@ struct i40e_vsi { u64 tx_stopped_base; u64 tx_bytes; u64 tx_packets; + u64 tx_gso_packets; + u64 tx_gso_wire_packets; u64 rx_buf_failed; u64 rx_page_failed; u64 rx_page_reuse; diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 0d0b3619ec56..7c2af738ccc5 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -11695,6 +11695,8 @@ static void i40e_vsi_aggregate_tx_counters(struct i40e_vsi *vsi, vsi->tx_bytes += tx_ring->stats.bytes; vsi->tx_packets += tx_ring->stats.packets; + vsi->tx_gso_packets += tx_ring->tx_stats.tx_gso_packets; + vsi->tx_gso_wire_packets += tx_ring->tx_stats.tx_gso_wire_packets; } static void i40e_vsi_aggregate_rx_counters(struct i40e_vsi *vsi, @@ -13684,6 +13686,8 @@ static void i40e_zero_tx_ring_stats(struct netdev_queue_stats_tx *tx) { tx->bytes = 0; tx->packets = 0; + tx->hw_gso_packets = 0; + tx->hw_gso_wire_packets = 0; tx->stop = 0; tx->wake = 0; tx->hw_drops = 0; @@ -13692,17 +13696,21 @@ static void i40e_zero_tx_ring_stats(struct netdev_queue_stats_tx *tx) static void i40e_add_tx_ring_stats(struct i40e_ring *tx_ring, struct netdev_queue_stats_tx *tx) { - u64 bytes, packets; + u64 bytes, packets, gso_packets, gso_wire_packets; unsigned int start; do { start = u64_stats_fetch_begin(&tx_ring->syncp); bytes = tx_ring->stats.bytes; packets = tx_ring->stats.packets; + gso_packets = tx_ring->tx_stats.tx_gso_packets; + gso_wire_packets = tx_ring->tx_stats.tx_gso_wire_packets; } while (u64_stats_fetch_retry(&tx_ring->syncp, start)); tx->bytes += bytes; tx->packets += packets; + tx->hw_gso_packets += gso_packets; + tx->hw_gso_wire_packets += gso_wire_packets; tx->stop += tx_ring->tx_stats.tx_stopped; tx->wake += tx_ring->tx_stats.restart_queue; @@ -13743,6 +13751,9 @@ static void i40e_get_base_stats(struct net_device *dev, tx->bytes = vsi->tx_bytes; tx->packets = vsi->tx_packets; + tx->hw_gso_packets = vsi->tx_gso_packets; + tx->hw_gso_wire_packets = vsi->tx_gso_wire_packets; + tx->wake = vsi->tx_restart_base; tx->stop = vsi->tx_stopped_base; tx->hw_drops = vsi->tx_busy_base; diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index 894f2d06d39d..ec61cc43ae39 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -928,6 +928,7 @@ static bool i40e_clean_tx_irq(struct i40e_vsi *vsi, struct i40e_ring *tx_ring, int napi_budget, unsigned int *tx_cleaned) { + unsigned int total_gso_packets = 0, total_gso_wire_packets = 0; int i = tx_ring->next_to_clean; struct i40e_tx_buffer *tx_buf; struct i40e_tx_desc *tx_head; @@ -959,6 +960,10 @@ static bool i40e_clean_tx_irq(struct i40e_vsi *vsi, /* update the statistics for this packet */ total_bytes += tx_buf->bytecount; total_packets += tx_buf->gso_segs; + if (tx_buf->gso_segs > 1) { + total_gso_packets++; + total_gso_wire_packets += tx_buf->gso_segs; + } /* free the skb/XDP data */ if (ring_is_xdp(tx_ring)) @@ -1018,7 +1023,8 @@ static bool i40e_clean_tx_irq(struct i40e_vsi *vsi, i += tx_ring->count; tx_ring->next_to_clean = i; - i40e_update_tx_stats(tx_ring, total_packets, total_bytes); + i40e_update_tx_stats(tx_ring, total_packets, total_bytes, + total_gso_packets, total_gso_wire_packets); i40e_arm_wb(tx_ring, vsi, budget); if (ring_is_xdp(tx_ring)) diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h index 1e5fd63d47f4..15c608378467 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h @@ -295,6 +295,8 @@ struct i40e_tx_queue_stats { u64 tx_linearize; u64 tx_force_wb; u64 tx_stopped; + u64 tx_gso_packets; + u64 tx_gso_wire_packets; int prev_pkt_ctr; }; diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx_common.h b/drivers/net/ethernet/intel/i40e/i40e_txrx_common.h index e26807fd2123..24220594ff1a 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx_common.h +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx_common.h @@ -45,11 +45,15 @@ static inline __le64 build_ctob(u32 td_cmd, u32 td_offset, unsigned int size, **/ static inline void i40e_update_tx_stats(struct i40e_ring *tx_ring, unsigned int total_packets, - unsigned int total_bytes) + unsigned int total_bytes, + unsigned int total_gso, + unsigned int total_gso_wire) { u64_stats_update_begin(&tx_ring->syncp); tx_ring->stats.bytes += total_bytes; tx_ring->stats.packets += total_packets; + tx_ring->tx_stats.tx_gso_packets += total_gso; + tx_ring->tx_stats.tx_gso_wire_packets += total_gso_wire; u64_stats_update_end(&tx_ring->syncp); tx_ring->q_vector->tx.total_bytes += total_bytes; tx_ring->q_vector->tx.total_packets += total_packets; diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 9f47388eaba5..c2a465416a33 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -599,7 +599,7 @@ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget) i40e_set_rs_bit(xdp_ring); i40e_xdp_ring_update_tail(xdp_ring); - i40e_update_tx_stats(xdp_ring, nb_pkts, total_bytes); + i40e_update_tx_stats(xdp_ring, nb_pkts, total_bytes, 0, 0); return nb_pkts < budget; } -- 2.53.0