Skip to content

Commit 5678f0a

Browse files
author
Mamatha Inamdar
committed
ibmvnic: Use ndo_get_stats64 to fix inaccurate SAR reporting
JIRA: https://issues.redhat.com/browse/RHEL-104119 commit efe2803 Author: Mingming Cao <mmc@linux.ibm.com> Date: Wed Jul 16 11:21:15 2025 -0400 ibmvnic: Use ndo_get_stats64 to fix inaccurate SAR reporting VNIC testing on multi-core Power systems showed SAR stats drift and packet rate inconsistencies under load. Implements ndo_get_stats64 to provide safe aggregation of queue-level atomic64 counters into rtnl_link_stats64 for use by tools like 'ip -s', 'ifconfig', and 'sar'. Switch to ndo_get_stats64 to align SAR reporting with the standard kernel interface for retrieving netdev stats. This removes redundant per-adapter stat updates, reduces overhead, eliminates cacheline bouncing from hot path updates, and improves the accuracy of reported packet rates. Signed-off-by: Mingming Cao <mmc@linux.ibm.com> Reviewed-by: Brian King <bjking1@linux.ibm.com> Reviewed-by: Dave Marquardt <davemarq@linux.ibm.com> Reviewed-by: Simon Horman <horms@kernel.org> ---- Changes since v3: link to v3: https://www.spinics.net/lists/netdev/msg1107999.html -- keep per queue counters as u64 (this patch) and drop off patch 1 in v3 Link: https://patch.msgid.link/20250716152115.61143-1-mmc@linux.ibm.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Mamatha Inamdar <minamdar@redhat.com>
1 parent 2ab276a commit 5678f0a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

drivers/net/ethernet/ibm/ibmvnic.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,8 +2103,6 @@ static void ibmvnic_tx_scrq_clean_buffer(struct ibmvnic_adapter *adapter,
21032103
tx_pool->num_buffers - 1 :
21042104
tx_pool->consumer_index - 1;
21052105
tx_buff = &tx_pool->tx_buff[index];
2106-
adapter->netdev->stats.tx_packets--;
2107-
adapter->netdev->stats.tx_bytes -= tx_buff->skb->len;
21082106
adapter->tx_stats_buffers[queue_num].batched_packets--;
21092107
adapter->tx_stats_buffers[queue_num].bytes -=
21102108
tx_buff->skb->len;
@@ -2435,9 +2433,6 @@ static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
24352433
}
24362434
out:
24372435
rcu_read_unlock();
2438-
netdev->stats.tx_dropped += tx_dropped;
2439-
netdev->stats.tx_bytes += tx_bytes;
2440-
netdev->stats.tx_packets += tx_bpackets + tx_dpackets;
24412436
adapter->tx_send_failed += tx_send_failed;
24422437
adapter->tx_map_failed += tx_map_failed;
24432438
adapter->tx_stats_buffers[queue_num].batched_packets += tx_bpackets;
@@ -3240,6 +3235,25 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
32403235
return -ret;
32413236
}
32423237

3238+
static void ibmvnic_get_stats64(struct net_device *netdev,
3239+
struct rtnl_link_stats64 *stats)
3240+
{
3241+
struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3242+
int i;
3243+
3244+
for (i = 0; i < adapter->req_rx_queues; i++) {
3245+
stats->rx_packets += adapter->rx_stats_buffers[i].packets;
3246+
stats->rx_bytes += adapter->rx_stats_buffers[i].bytes;
3247+
}
3248+
3249+
for (i = 0; i < adapter->req_tx_queues; i++) {
3250+
stats->tx_packets += adapter->tx_stats_buffers[i].batched_packets;
3251+
stats->tx_packets += adapter->tx_stats_buffers[i].direct_packets;
3252+
stats->tx_bytes += adapter->tx_stats_buffers[i].bytes;
3253+
stats->tx_dropped += adapter->tx_stats_buffers[i].dropped_packets;
3254+
}
3255+
}
3256+
32433257
static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue)
32443258
{
32453259
struct ibmvnic_adapter *adapter = netdev_priv(dev);
@@ -3355,8 +3369,6 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
33553369

33563370
length = skb->len;
33573371
napi_gro_receive(napi, skb); /* send it up */
3358-
netdev->stats.rx_packets++;
3359-
netdev->stats.rx_bytes += length;
33603372
adapter->rx_stats_buffers[scrq_num].packets++;
33613373
adapter->rx_stats_buffers[scrq_num].bytes += length;
33623374
frames_processed++;
@@ -3466,6 +3478,7 @@ static const struct net_device_ops ibmvnic_netdev_ops = {
34663478
.ndo_set_rx_mode = ibmvnic_set_multi,
34673479
.ndo_set_mac_address = ibmvnic_set_mac,
34683480
.ndo_validate_addr = eth_validate_addr,
3481+
.ndo_get_stats64 = ibmvnic_get_stats64,
34693482
.ndo_tx_timeout = ibmvnic_tx_timeout,
34703483
.ndo_change_mtu = ibmvnic_change_mtu,
34713484
.ndo_features_check = ibmvnic_features_check,

0 commit comments

Comments
 (0)