DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Dimon" <dimon.zhao@nebula-matrix.com>
To: "Stephen Hemminger" <stephen@networkplumber.org>
Cc: "dev" <dev@dpdk.org>, "Kyo Liu" <kyo.liu@nebula-matrix.com>,
	"Leon" <leon.yu@nebula-matrix.com>,
	"Sam" <sam.chen@nebula-matrix.com>
Subject: 回复:[PATCH v1 1/1] net/nbl: fix Rx/Tx stats concurrency
Date: Thu, 27 Nov 2025 16:12:35 +0800	[thread overview]
Message-ID: <b54b8e60-831f-4363-93c9-798258d56719.dimon.zhao@nebula-matrix.com> (raw)
In-Reply-To: <20251126160713.3943bcef@phoenix.local>

[-- Attachment #1: Type: text/plain, Size: 2471 bytes --]

Hi Stephen,
Thank you for the feedback.
The main issue I wanted to address is the race condition when the flow stops.
With the old memset code, if a reset happens during a stats read/modify/write cycle (even with +0 modification), the zeroing can be completely lost.
My new code handles this case better under no-traffic conditions.
We do not need fully reliable statistics, so we don't need to use atomic operations.
This seems like a reasonable compromise for our use case.
------------------------------------------------------------------
发件人:Stephen Hemminger <stephen@networkplumber.org>
发送时间:2025年11月27日(周四) 08:07
收件人:Dimon<dimon.zhao@nebula-matrix.com>
抄 送:dev<dev@dpdk.org>; Kyo Liu<kyo.liu@nebula-matrix.com>; Leon<leon.yu@nebula-matrix.com>; Sam<sam.chen@nebula-matrix.com>
主 题:Re: [PATCH v1 1/1] net/nbl: fix Rx/Tx stats concurrency
On Tue, 25 Nov 2025 18:54:36 -0800
Dimon Zhao <dimon.zhao@nebula-matrix.com> wrote:
> Queue statistics are being continuously updated in Rx/Tx burst
> routines while handling traffic. In addition to that, statistics
> can be reset (written with zeroes) on statistics reset in other
> threads, causing a race condition, which in turn could result in
> wrong stats.
> 
> The patch provides an approach with reference values, allowing
> the actual counters to be writable within Rx/Tx burst threads
> only, and updating reference values on stats reset.
> 
> Fixes: 661c0ccf2512 ("net/nbl: support statistics")
> 
> Signed-off-by: Dimon Zhao <dimon.zhao@nebula-matrix.com>
First off, many drivers do the same thing as the current code.
I think virtio is the most commonly used driver with same memset.
They just zero an accumulated buffer.
The SW counters are not meant to super exact (not a good idea to bill
customers based on packet counts).
Your new method using a stashed old copy, still has races.
The old code would race the zero with read/modify/write of the increment.
If the race happened the zero might happen in the middle of the modify
causing the value not to be zeroed.
The new code is less of a problem but assignment is not atomic on
many platforms, especially for structure size objects. Therefore it
could happen to get read of stale data.
If you really want to have reliable statistics in SW, you
would have to use atomic operations, and pay the penalty of the
additional locked operations in the fast path.
PS: FreeBSD has the same problem in many drivers.

[-- Attachment #2: Type: text/html, Size: 6293 bytes --]

      reply	other threads:[~2025-11-27  8:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26  2:54 [PATCH v1 0/1] fix NBL issues in DPDK 25.11-rc4 Dimon Zhao
2025-11-26  2:54 ` [PATCH v1 1/1] net/nbl: fix Rx/Tx stats concurrency Dimon Zhao
2025-11-27  0:07   ` Stephen Hemminger
2025-11-27  8:12     ` Dimon [this message]

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=b54b8e60-831f-4363-93c9-798258d56719.dimon.zhao@nebula-matrix.com \
    --to=dimon.zhao@nebula-matrix.com \
    --cc=dev@dpdk.org \
    --cc=kyo.liu@nebula-matrix.com \
    --cc=leon.yu@nebula-matrix.com \
    --cc=sam.chen@nebula-matrix.com \
    --cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).