From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
stable@dpdk.org,
Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>,
Jakub Grajciar <jgrajcia@cisco.com>,
Ferruh Yigit <ferruh.yigit@amd.com>
Subject: [PATCH 2/7] net/memif: fix issues in statistics
Date: Tue, 22 Sep 2026 12:40:53 -0700 [thread overview]
Message-ID: <20260922194138.508919-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20260922194138.508919-1-stephen@networkplumber.org>
The statistics structure is already cleared in ethdev before
calling PMD.
Statistics from all queues should be counted against overall
packets; the constant RTE_ETHDEV_QUEUE_STAT_CNTRS is upper
bound on the array of queue stats.
The counters were also keyed off the negotiated ring counts in
pmd->run, which memif_disconnect() clears, so every counter read
back as zero once the peer went away. Iterate over the configured
queue counts instead, in both stats_get and stats_reset, so the
totals survive a disconnect.
Fixes: 09c7e63a71f9 ("net/memif: introduce memory interface PMD")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/memif/rte_eth_memif.c | 44 +++++++++++--------------------
1 file changed, 15 insertions(+), 29 deletions(-)
diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c
index 5d153c3a5a..89796d3ed5 100644
--- a/drivers/net/memif/rte_eth_memif.c
+++ b/drivers/net/memif/rte_eth_memif.c
@@ -1595,25 +1595,18 @@ static int
memif_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
struct eth_queue_stats *qstats)
{
- struct pmd_internals *pmd = dev->data->dev_private;
struct memif_queue *mq;
- int i;
- uint8_t tmp, nq;
-
- stats->ipackets = 0;
- stats->ibytes = 0;
- stats->opackets = 0;
- stats->obytes = 0;
+ unsigned int i;
- tmp = (pmd->role == MEMIF_ROLE_CLIENT) ? pmd->run.num_s2c_rings :
- pmd->run.num_c2s_rings;
- nq = (tmp < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? tmp :
- RTE_ETHDEV_QUEUE_STAT_CNTRS;
+ /*
+ * Use the configured queue counts, not pmd->run, which memif_disconnect()
+ * clears; otherwise all counters would read zero once the peer is gone.
+ */
/* RX stats */
- for (i = 0; i < nq; i++) {
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
mq = dev->data->rx_queues[i];
- if (qstats != NULL) {
+ if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
qstats->q_ipackets[i] = mq->n_pkts;
qstats->q_ibytes[i] = mq->n_bytes;
}
@@ -1622,15 +1615,10 @@ memif_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
stats->ierrors += mq->n_err;
}
- tmp = (pmd->role == MEMIF_ROLE_CLIENT) ? pmd->run.num_c2s_rings :
- pmd->run.num_s2c_rings;
- nq = (tmp < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? tmp :
- RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
/* TX stats */
- for (i = 0; i < nq; i++) {
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
mq = dev->data->tx_queues[i];
- if (qstats != NULL) {
+ if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
qstats->q_opackets[i] = mq->n_pkts;
qstats->q_obytes[i] = mq->n_bytes;
}
@@ -1643,20 +1631,18 @@ memif_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
static int
memif_stats_reset(struct rte_eth_dev *dev)
{
- struct pmd_internals *pmd = dev->data->dev_private;
- int i;
struct memif_queue *mq;
+ unsigned int i;
- for (i = 0; i < pmd->run.num_c2s_rings; i++) {
- mq = (pmd->role == MEMIF_ROLE_CLIENT) ? dev->data->tx_queues[i] :
- dev->data->rx_queues[i];
+ /* Same as memif_stats_get(), pmd->run is cleared on disconnect. */
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ mq = dev->data->rx_queues[i];
mq->n_pkts = 0;
mq->n_bytes = 0;
mq->n_err = 0;
}
- for (i = 0; i < pmd->run.num_s2c_rings; i++) {
- mq = (pmd->role == MEMIF_ROLE_CLIENT) ? dev->data->rx_queues[i] :
- dev->data->tx_queues[i];
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ mq = dev->data->tx_queues[i];
mq->n_pkts = 0;
mq->n_bytes = 0;
mq->n_err = 0;
--
2.53.0
next prev parent reply other threads:[~2026-09-22 19:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 19:40 [PATCH 0/7] net/memif: validate input from connecting peer Stephen Hemminger
2026-09-22 19:40 ` [PATCH 1/7] maintainers: update for memif driver Stephen Hemminger
2026-09-22 19:40 ` Stephen Hemminger [this message]
2026-09-22 19:40 ` [PATCH 3/7] net/memif: validate peer descriptors Stephen Hemminger
2026-09-22 19:40 ` [PATCH 4/7] net/memif: validate control channel requests Stephen Hemminger
2026-09-22 19:40 ` [PATCH 5/7] net/memif: validate descriptor length in zero-copy mode Stephen Hemminger
2026-09-22 19:40 ` [PATCH 6/7] net/memif: add server/client connectivity test Stephen Hemminger
2026-09-22 19:40 ` [PATCH 7/7] doc: clarify memif secret is not access control Stephen Hemminger
2026-09-24 15:44 ` Stephen Hemminger
2026-09-28 17:56 ` Stephen Hemminger
2026-09-24 11:24 ` [PATCH 0/7] net/memif: validate input from connecting peer Sriram Yagnaraman
2026-09-29 15:42 ` Stephen Hemminger
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=20260922194138.508919-3-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=jgrajcia@cisco.com \
--cc=sriram.yagnaraman@ericsson.com \
--cc=stable@dpdk.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox