From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A084843F39; Sun, 28 Apr 2024 17:42:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2250E40265; Sun, 28 Apr 2024 17:42:23 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 2898340263 for ; Sun, 28 Apr 2024 17:42:22 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id D16471E2C3 for ; Sun, 28 Apr 2024 17:42:21 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id C43E61E412; Sun, 28 Apr 2024 17:42:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.3 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id F415E1E390; Sun, 28 Apr 2024 17:42:18 +0200 (CEST) Message-ID: Date: Sun, 28 Apr 2024 17:42:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] net/af_packet: make stats reset reliable To: =?UTF-8?Q?Morten_Br=C3=B8rup?= , Ferruh Yigit , "John W. Linville" Cc: Thomas Monjalon , dev@dpdk.org, =?UTF-8?Q?Mattias_R=C3=B6nnblom?= , Stephen Hemminger References: <20240425174617.2126159-1-ferruh.yigit@amd.com> <98CBD80474FA8B44BF855DF32C47DC35E9F3F4@smartserver.smartshare.dk> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F3F4@smartserver.smartshare.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 2024-04-26 13:33, Morten Brørup wrote: >> +static uint64_t >> +stats_get_diff(uint64_t stats, uint64_t offset) >> +{ >> + if (stats >= offset) >> + return stats - offset; >> + /* unlikely wraparound case */ >> + return UINT64_MAX + stats - offset; > > The numbers are unsigned, so wrapping comes for free. > With 64-bit counters, will they ever wrap? If you constantly run 100 Gbps it'll take > 1000 years before the byte counter wrap. > Remove the comparison and always return stats - offset. > > Using uint8_t for easier explanation, if offset is 255 and stats is 0, then the diff should be 1. > Returning stats - offset: > stats - offset = 0 - 255 = 0 - 0xFF = 1. > > Returning UINT8_MAX + stats - offset is wrong: > UINT8_MAX + stats - offset = 255 - 0 - 255 = 0. > > Besides that, it looks good to me. > > > While reviewing, I came across the rx_mbuf_alloc_failed counter in the rte_eth_dev_data structure: > https://elixir.bootlin.com/dpdk/v24.03/source/lib/ethdev/rte_ethdev.c#L3145 > https://elixir.bootlin.com/dpdk/v24.03/source/lib/ethdev/ethdev_driver.h#L127 > > Doesn't it have the same problem? > > > BTW, the af_packet PMD doesn't increase the rx_mbuf_alloc_failed counter on mbuf allocation failures. But that's a separate bug. >