Skip to content

Commit 81fe5d6

Browse files
author
Mamatha Inamdar
committed
ibmvnic: Use ndo_get_stats64 to fix inaccurate SAR reporting
JIRA: https://issues.redhat.com/browse/RHEL-104319 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 ede83c7 commit 81fe5d6

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
@@ -2308,8 +2308,6 @@ static void ibmvnic_tx_scrq_clean_buffer(struct ibmvnic_adapter *adapter,
23082308
tx_pool->num_buffers - 1 :
23092309
tx_pool->consumer_index - 1;
23102310
tx_buff = &tx_pool->tx_buff[index];
2311-
adapter->netdev->stats.tx_packets--;
2312-
adapter->netdev->stats.tx_bytes -= tx_buff->skb->len;
23132311
adapter->tx_stats_buffers[queue_num].batched_packets--;
23142312
adapter->tx_stats_buffers[queue_num].bytes -=
23152313
tx_buff->skb->len;
@@ -2642,9 +2640,6 @@ static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
26422640
}
26432641
out:
26442642
rcu_read_unlock();
2645-
netdev->stats.tx_dropped += tx_dropped;
2646-
netdev->stats.tx_bytes += tx_bytes;
2647-
netdev->stats.tx_packets += tx_bpackets + tx_dpackets;
26482643
adapter->tx_send_failed += tx_send_failed;
26492644
adapter->tx_map_failed += tx_map_failed;
26502645
adapter->tx_stats_buffers[queue_num].batched_packets += tx_bpackets;
@@ -3447,6 +3442,25 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
34473442
return -ret;
34483443
}
34493444

3445+
static void ibmvnic_get_stats64(struct net_device *netdev,
3446+
struct rtnl_link_stats64 *stats)
3447+
{
3448+
struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3449+
int i;
3450+
3451+
for (i = 0; i < adapter->req_rx_queues; i++) {
3452+
stats->rx_packets += adapter->rx_stats_buffers[i].packets;
3453+
stats->rx_bytes += adapter->rx_stats_buffers[i].bytes;
3454+
}
3455+
3456+
for (i = 0; i < adapter->req_tx_queues; i++) {
3457+
stats->tx_packets += adapter->tx_stats_buffers[i].batched_packets;
3458+
stats->tx_packets += adapter->tx_stats_buffers[i].direct_packets;
3459+
stats->tx_bytes += adapter->tx_stats_buffers[i].bytes;
3460+
stats->tx_dropped += adapter->tx_stats_buffers[i].dropped_packets;
3461+
}
3462+
}
3463+
34503464
static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue)
34513465
{
34523466
struct ibmvnic_adapter *adapter = netdev_priv(dev);
@@ -3562,8 +3576,6 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
35623576

35633577
length = skb->len;
35643578
napi_gro_receive(napi, skb); /* send it up */
3565-
netdev->stats.rx_packets++;
3566-
netdev->stats.rx_bytes += length;
35673579
adapter->rx_stats_buffers[scrq_num].packets++;
35683580
adapter->rx_stats_buffers[scrq_num].bytes += length;
35693581
frames_processed++;
@@ -3673,6 +3685,7 @@ static const struct net_device_ops ibmvnic_netdev_ops = {
36733685
.ndo_set_rx_mode = ibmvnic_set_multi,
36743686
.ndo_set_mac_address = ibmvnic_set_mac,
36753687
.ndo_validate_addr = eth_validate_addr,
3688+
.ndo_get_stats64 = ibmvnic_get_stats64,
36763689
.ndo_tx_timeout = ibmvnic_tx_timeout,
36773690
.ndo_change_mtu = ibmvnic_change_mtu,
36783691
.ndo_features_check = ibmvnic_features_check,

0 commit comments

Comments
 (0)