DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ciara Loftus <ciara.loftus@intel.com>
To: dev@dpdk.org
Cc: Ciara Loftus <ciara.loftus@intel.com>, stable@dpdk.org
Subject: [PATCH 1/3] net/ice: fix Rx packets statistics underflow
Date: Thu, 25 Jun 2026 09:36:17 +0000	[thread overview]
Message-ID: <20260625093619.726471-2-ciara.loftus@intel.com> (raw)
In-Reply-To: <20260625093619.726471-1-ciara.loftus@intel.com>

The number of Rx packets is computed as the sum of the unicast,
multicast and broadcast packet counters, minus the discarded packet
count:

    ipackets = rx_unicast + rx_multicast + rx_broadcast - rx_discards

The unicast, multicast and broadcast counters already include the
packets that were subsequently dropped, so subtracting rx_discards
yields only the packets delivered to the application. However, each of
these counters is read from a separate hardware register, and the reads
happen at slightly different instants. Under load, rx_discards (read
last) can momentarily exceed the sum of the unicast, multicast and
broadcast counters (read earlier). As ipackets is unsigned, the
subtraction then wraps to a huge bogus value, reported to the
application as an enormous Rx packet count and packet rate.

Read the rx_discards register before the unicast, multicast and
broadcast registers. As all of these counters only ever increase, and
the unicast, multicast and broadcast counters always include the
discarded packets, sampling rx_discards first guarantees it can never
exceed the later sum of the other three, so the subtraction can never
underflow.

Fixes: a37bde56314d ("net/ice: support statistics")
Cc: stable@dpdk.org

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
 drivers/net/intel/ice/ice_ethdev.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/intel/ice/ice_ethdev.c b/drivers/net/intel/ice/ice_ethdev.c
index ad9c49b339..94e07446be 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -6457,6 +6457,15 @@ ice_update_vsi_stats(struct ice_vsi *vsi)
 	struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
 	int idx = rte_le_to_cpu_16(vsi->vsi_id);
 
+	/*
+	 * Unicast/multicast/broadcast counters include discarded packets. Received packets is
+	 * calculated by deducting discards from unicast/multicast/broadcast. To prevent a
+	 * potential underflow, read discards first to guarantee it is smaller than
+	 * unicast/multicast/broadcast.
+	 */
+	ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
+			   &oes->rx_discards, &nes->rx_discards);
+
 	ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
 			   vsi->offset_loaded, &oes->rx_bytes,
 			   &nes->rx_bytes);
@@ -6483,8 +6492,6 @@ ice_update_vsi_stats(struct ice_vsi *vsi)
 	nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
 			  nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
 
-	ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
-			   &oes->rx_discards, &nes->rx_discards);
 	/* GLV_REPC not supported */
 	/* GLV_RMPC not supported */
 	ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
-- 
2.43.0


  reply	other threads:[~2026-06-25  9:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25  9:36 [PATCH 0/3] net/intel: fix potential rx stats underflow Ciara Loftus
2026-06-25  9:36 ` Ciara Loftus [this message]
2026-06-25 15:57   ` [PATCH 1/3] net/ice: fix Rx packets statistics underflow Bruce Richardson
2026-06-25  9:36 ` [PATCH 2/3] net/ice: fix DCF " Ciara Loftus
2026-06-25 15:57   ` Bruce Richardson
2026-06-25  9:36 ` [PATCH 3/3] net/iavf: fix " Ciara Loftus
2026-06-25 15:58   ` Bruce Richardson
2026-06-26  8:46 ` [PATCH 0/3] net/intel: fix potential rx stats underflow Bruce Richardson

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=20260625093619.726471-2-ciara.loftus@intel.com \
    --to=ciara.loftus@intel.com \
    --cc=dev@dpdk.org \
    --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