ip -s link and ethtool -S only show device totals, so they cannot show whether traffic is spread over the queues or which queue drops. Implement netdev_stat_ops so qstats-get shows each queue: packets and bytes, and for RX alloc_fail and PHYP's no-buffer drops as hw_drops and hw_drop_overruns. This already covers today's TX queues. RX alloc_fail counts failed skb allocations both when refilling buffers and for copybreak, which then passes the frame up in its pool buffer. Nothing counted the copybreak failures before. An invalid buffer PHYP hands back carries no frame, so it is not a hw_drop; it stays in ethtool -S as rx_invalid_buffer. A frame PHYP delivered but the driver then dropped is rx_dropped, not a hw_drop. TX hw_drops is left unset, because the TX drop count includes frames rejected before they reached PHYP. Queues above the live count are reported in the base stats, so the qstats total still matches ndo_get_stats64 after the queue count goes down. Signed-off-by: Mingming Cao --- drivers/net/ethernet/ibm/ibmveth.c | 75 +++++++++++++++++++++++++++++- drivers/net/ethernet/ibm/ibmveth.h | 1 + 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 56b645ffb18c..f30d8ba23320 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "ibmveth.h" @@ -2577,8 +2578,11 @@ static void ibmveth_poll_deliver_frame(struct napi_struct *napi, } new_skb = NULL; - if (length < rx_copybreak) + if (length < rx_copybreak) { new_skb = netdev_alloc_skb(netdev, length); + if (unlikely(!new_skb)) + IBMVETH_STAT_INC(rxs->copybreak_no_mem); + } if (new_skb) { skb_copy_to_linear_data(new_skb, skb->data + offset, length); @@ -2928,6 +2932,74 @@ static void ibmveth_get_stats64(struct net_device *dev, } } +static void ibmveth_get_queue_stats_rx(struct net_device *dev, int idx, + struct netdev_queue_stats_rx *stats) +{ + struct ibmveth_adapter *adapter = netdev_priv(dev); + u64 no_buffer; + + stats->packets = READ_ONCE(adapter->rx_qstats[idx].packets); + stats->bytes = READ_ONCE(adapter->rx_qstats[idx].bytes); + /* Frames PHYP dropped for lack of a posted buffer: the last sample + * of the live page plus pages this queue already released. + */ + no_buffer = ibmveth_rx_no_buffer_total(adapter, idx); + stats->hw_drops = no_buffer; + stats->hw_drop_overruns = no_buffer; + stats->alloc_fail = + READ_ONCE(adapter->rx_qstats[idx].replenish_no_mem) + + READ_ONCE(adapter->rx_qstats[idx].copybreak_no_mem); +} + +static void ibmveth_get_queue_stats_tx(struct net_device *dev, int idx, + struct netdev_queue_stats_tx *stats) +{ + struct ibmveth_adapter *adapter = netdev_priv(dev); + + stats->packets = READ_ONCE(adapter->tx_qstats[idx].packets); + stats->bytes = READ_ONCE(adapter->tx_qstats[idx].bytes); + /* TX hw_drops left unset: dropped_packets includes + * software xmit rejects that never reached PHYP. + */ +} + +/** + * ibmveth_get_base_stats - account for traffic not on a live queue + * @dev: network device + * @rx: RX base statistics storage + * @tx: TX base statistics storage + * + * The core sums get_queue_stats_{rx,tx}() only below + * real_num_{rx,tx}_queues, while ibmveth_get_stats64() walks every + * slot. Report the slots at or above real_num here so the two agree + * after the queue count goes down. + * + * Every field the queue callbacks set must be set here too: the core + * drops a field from the device total if the base leaves it unset. + */ +static void ibmveth_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + rx->packets = 0; + rx->bytes = 0; + rx->alloc_fail = 0; + rx->hw_drops = 0; + rx->hw_drop_overruns = 0; + tx->packets = 0; + tx->bytes = 0; + + netdev_stat_queue_sum(dev, dev->real_num_rx_queues, + IBMVETH_MAX_RX_QUEUES, rx, + dev->real_num_tx_queues, IBMVETH_MAX_QUEUES, tx); +} + +static const struct netdev_stat_ops ibmveth_stat_ops = { + .get_queue_stats_rx = ibmveth_get_queue_stats_rx, + .get_queue_stats_tx = ibmveth_get_queue_stats_tx, + .get_base_stats = ibmveth_get_base_stats, +}; + static const struct net_device_ops ibmveth_netdev_ops = { .ndo_open = ibmveth_open, .ndo_stop = ibmveth_close, @@ -3032,6 +3104,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) netdev->irq = dev->irq; netdev->netdev_ops = &ibmveth_netdev_ops; netdev->ethtool_ops = &netdev_ethtool_ops; + netdev->stat_ops = &ibmveth_stat_ops; SET_NETDEV_DEV(netdev, &dev->dev); netdev->hw_features = NETIF_F_SG; if (vio_get_attribute(dev, "ibm,illan-options", NULL) != NULL) { diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index d6d28b75dd99..588209144de7 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -260,6 +260,7 @@ struct ibmveth_rx_queue_stats { u64 replenish_no_mem; u64 replenish_add_buff_failure; u64 replenish_add_buff_success; + u64 copybreak_no_mem; } ____cacheline_aligned_in_smp; /* Per-queue TX counters; serialized by the stack's per-queue TX lock. */ -- 2.50.1 (Apple Git-155)