From: Mingming Cao <mmc@linux.ibm.com>
To: netdev@vger.kernel.org
Cc: bjking1@linux.ibm.com, haren@linux.ibm.com,
ricklind@linux.ibm.com, mmc@linux.ibm.com
Subject: [PATCH net-next 3/4] ibmvnic: Use ndo_get_stats64 to fix inaccurate SAR reporting
Date: Mon, 30 Jun 2025 16:48:05 -0700 [thread overview]
Message-ID: <20250630234806.10885-4-mmc@linux.ibm.com> (raw)
In-Reply-To: <20250630234806.10885-1-mmc@linux.ibm.com>
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>
---
drivers/net/ethernet/ibm/ibmvnic.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 7b2be8eeb5..8c959d5db2 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -2313,13 +2313,11 @@ static void ibmvnic_tx_scrq_clean_buffer(struct ibmvnic_adapter *adapter,
tx_pool->num_buffers - 1 :
tx_pool->consumer_index - 1;
tx_buff = &tx_pool->tx_buff[index];
- adapter->netdev->stats.tx_packets--;
- adapter->netdev->stats.tx_bytes -= tx_buff->skb->len;
atomic64_dec(&adapter->tx_stats_buffers[queue_num].batched_packets);
atomic64_sub(tx_buff->skb->len, &adapter->tx_stats_buffers[queue_num].bytes);
+ atomic64_inc(&adapter->tx_stats_buffers[queue_num].dropped_packets);
dev_kfree_skb_any(tx_buff->skb);
tx_buff->skb = NULL;
- adapter->netdev->stats.tx_dropped++;
}
ind_bufp->index = 0;
@@ -2647,9 +2645,6 @@ tx_err:
}
out:
rcu_read_unlock();
- netdev->stats.tx_dropped += tx_dropped;
- netdev->stats.tx_bytes += tx_bytes;
- netdev->stats.tx_packets += tx_bpackets + tx_dpackets;
adapter->tx_send_failed += tx_send_failed;
adapter->tx_map_failed += tx_map_failed;
atomic64_add(tx_bpackets, &adapter->tx_stats_buffers[queue_num].batched_packets);
@@ -3452,6 +3447,25 @@ err:
return -ret;
}
+static void ibmvnic_get_stats64(struct net_device *netdev,
+ struct rtnl_link_stats64 *stats)
+{
+ struct ibmvnic_adapter *adapter = netdev_priv(netdev);
+ int i;
+
+ for (i = 0; i < adapter->req_rx_queues; i++) {
+ stats->rx_packets += atomic64_read(&adapter->rx_stats_buffers[i].packets);
+ stats->rx_bytes += atomic64_read(&adapter->rx_stats_buffers[i].bytes);
+ }
+
+ for (i = 0; i < adapter->req_tx_queues; i++) {
+ stats->tx_packets += atomic64_read(&adapter->tx_stats_buffers[i].batched_packets);
+ stats->tx_packets += atomic64_read(&adapter->tx_stats_buffers[i].direct_packets);
+ stats->tx_bytes += atomic64_read(&adapter->tx_stats_buffers[i].bytes);
+ stats->tx_dropped += atomic64_read(&adapter->tx_stats_buffers[i].dropped_packets);
+ }
+}
+
static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue)
{
struct ibmvnic_adapter *adapter = netdev_priv(dev);
@@ -3567,8 +3581,6 @@ restart_poll:
length = skb->len;
napi_gro_receive(napi, skb); /* send it up */
- netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += length;
atomic64_inc(&adapter->rx_stats_buffers[scrq_num].packets);
atomic64_add(length, &adapter->rx_stats_buffers[scrq_num].bytes);
frames_processed++;
@@ -3678,6 +3690,7 @@ static const struct net_device_ops ibmvnic_netdev_ops = {
.ndo_set_rx_mode = ibmvnic_set_multi,
.ndo_set_mac_address = ibmvnic_set_mac,
.ndo_validate_addr = eth_validate_addr,
+ .ndo_get_stats64 = ibmvnic_get_stats64,
.ndo_tx_timeout = ibmvnic_tx_timeout,
.ndo_change_mtu = ibmvnic_change_mtu,
.ndo_features_check = ibmvnic_features_check,
--
2.39.3 (Apple Git-146)
next prev parent reply other threads:[~2025-06-30 23:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 23:48 [PATCH net-next 0/4] ibmvnic: Improve queue stats and subcrq indirect handling Mingming Cao
2025-06-30 23:48 ` [PATCH net-next 1/4] ibmvnic: Derive NUM_RX_STATS/NUM_TX_STATS dynamically Mingming Cao
2025-07-02 1:30 ` Jakub Kicinski
2025-06-30 23:48 ` [PATCH net-next 2/4] ibmvnic: Use atomic64_t for queue stats Mingming Cao
2025-07-03 2:58 ` kernel test robot
2025-06-30 23:48 ` Mingming Cao [this message]
2025-06-30 23:48 ` [PATCH net-next 4/4] ibmvnic: Make max subcrq indirect entries tunable via module param Mingming Cao
2025-07-02 1:31 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250630234806.10885-4-mmc@linux.ibm.com \
--to=mmc@linux.ibm.com \
--cc=bjking1@linux.ibm.com \
--cc=haren@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=ricklind@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.