<div class="__aliyun_email_body_block"><div  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Hi <span  style="color: rgb(0, 0, 0); font-family: Tahoma, Arial, STHeiti, SimSun; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">Stephen,</span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >Thank you for the feedback.<br ></span></span><div  style="clear: both;"><br ></div><div  style="clear: both;">The main issue I wanted to address is the race condition when the flow stops.</div><div  style="clear: both;">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.</div><div  style="clear: both;">My new code handles this case better under no-traffic conditions.<br ></div><div ><span >We do not need fully reliable statistics, so we don't need to use atomic operations.</span></div><div ><span >This seems like a reasonable compromise for our use case.</span></div><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><blockquote  _quote="1" style="margin-right: 0px; margin-top: 0px; margin-bottom: 0px; font-family: Tahoma, Arial, STHeiti, SimSun; font-size: 14px; color: rgb(0, 0, 0);"><div  class="alimail-quote"><div  style="clear: both;">------------------------------------------------------------------</div><div  style="clear: both;">发件人:Stephen Hemminger <stephen@networkplumber.org></div><div  style="clear: both;">发送时间:2025年11月27日(周四) 08:07</div><div  style="clear: both;">收件人:Dimon<dimon.zhao@nebula-matrix.com></div><div  style="clear: both;">抄 送:dev<dev@dpdk.org>; Kyo Liu<kyo.liu@nebula-matrix.com>; Leon<leon.yu@nebula-matrix.com>; Sam<sam.chen@nebula-matrix.com></div><div  style="clear: both;">主 题:Re: [PATCH v1 1/1] net/nbl: fix Rx/Tx stats concurrency</div><div  style="clear: both;"><br ></div>On Tue, 25 Nov 2025 18:54:36 -0800<br >Dimon Zhao <dimon.zhao@nebula-matrix.com> wrote:<br ><br >> Queue statistics are being continuously updated in Rx/Tx burst<br >> routines while handling traffic. In addition to that, statistics<br >> can be reset (written with zeroes) on statistics reset in other<br >> threads, causing a race condition, which in turn could result in<br >> wrong stats.<br >> <br >> The patch provides an approach with reference values, allowing<br >> the actual counters to be writable within Rx/Tx burst threads<br >> only, and updating reference values on stats reset.<br >> <br >> Fixes: 661c0ccf2512 ("net/nbl: support statistics")<br >> <br >> Signed-off-by: Dimon Zhao <dimon.zhao@nebula-matrix.com><br ><br >First off, many drivers do the same thing as the current code.<br >I think virtio is the most commonly used driver with same memset.<br ><br >They just zero an accumulated buffer.<br >The SW counters are not meant to super exact (not a good idea to bill<br >customers based on packet counts).<br ><br >Your new method using a stashed old copy, still has races.<br >The old code would race the zero with read/modify/write of the increment.<br >If the race happened the zero might happen in the middle of the modify<br >causing the value not to be zeroed.<br ><br >The new code is less of a problem but assignment is not atomic on<br >many platforms, especially for structure size objects. Therefore it<br >could happen to get read of stale data.<br ><br >If you really want to have reliable statistics in SW, you<br >would have to use atomic operations, and pay the penalty of the<br >additional locked operations in the fast path.<br ><br >PS: FreeBSD has the same problem in many drivers.</div></blockquote><div  style="line-height: 20px; clear: both;"><br ></div></div></div>
<div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">本邮件所含信息及其任何附件为保密信息且可能属于专有信息。任何非指定接收人均无权访问本邮件。如果您不是该邮件的指定接收人,那么任何对本邮件内容进行披露,复制或使用的行为均是禁止的。如果您不是该邮件的指定接收人,请您立即通过邮件通知 compliance@nebula-matrix.com并立即删除您错误接受的邮件。</span></div><div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">The information in this message and any attachments is confidential and may be privileged.  Access to this email by anyone other than the intended recipient is not authorized.  If you are not the intended recipient, disclosure, copying or use of the contents of this email is prohibited.  If you are not the intended recipient, please notify  compliance@nebula-matrix.com immediately by email, and please destroy the email you received in error.</span></div>