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 C8122430BE; Mon, 21 Aug 2023 11:29:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4EB56427E9; Mon, 21 Aug 2023 11:29:23 +0200 (CEST) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id 58C3A40A7D for ; Mon, 21 Aug 2023 11:29:21 +0200 (CEST) Received: from frapeml100007.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RTnGg2pYvz6HJmL; Mon, 21 Aug 2023 17:28:43 +0800 (CST) Received: from frapeml500007.china.huawei.com (7.182.85.172) by frapeml100007.china.huawei.com (7.182.85.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 21 Aug 2023 11:29:19 +0200 Received: from frapeml500007.china.huawei.com ([7.182.85.172]) by frapeml500007.china.huawei.com ([7.182.85.172]) with mapi id 15.01.2507.031; Mon, 21 Aug 2023 11:29:19 +0200 From: Konstantin Ananyev To: Bruce Richardson , =?iso-8859-1?Q?Morten_Br=F8rup?= CC: "honnappa.nagarahalli@arm.com" , "konstantin.v.ananyev@yandex.ru" , "jerinj@marvell.com" , "dev@dpdk.org" Subject: RE: Bug in non-power-of-2 rings? Thread-Topic: Bug in non-power-of-2 rings? Thread-Index: AdnTRcFJLofpPgUJQi2nwmJrDMr1dgAtIR+AAAVbEBA= Date: Mon, 21 Aug 2023 09:29:19 +0000 Message-ID: References: <98CBD80474FA8B44BF855DF32C47DC35D87B20@smartserver.smartshare.dk> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.195.247.142] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected 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 Hi everyone, > On Sun, Aug 20, 2023 at 11:07:33AM +0200, Morten Br=F8rup wrote: > > Bruce, Honnappa, Konstantin, > > > > Back in 2017, Bruce added support for non-power-of-2 rings with this pa= tch [1]. > > > > [1]: https://git.dpdk.org/dpdk/commit/lib/librte_ring/rte_ring.h?id=3Db= 74461155543430f5253e96ad6d413ebcad36693 > > > > I think that the calculation of "entries" in __rte_ring_move_cons_head(= ) [2][3] is incorrect when the ring capacity is not power-of-2, > because it is missing the capacity comparison you added to rte_ring_count= () [4]. Please review if I'm mistaken. > > > > [2]: https://elixir.bootlin.com/dpdk/v23.07/source/lib/ring/rte_ring_c1= 1_pvt.h#L159 > > [3]: https://elixir.bootlin.com/dpdk/v23.07/source/lib/ring/rte_ring_ge= neric_pvt.h#L150 > > [4]: https://elixir.bootlin.com/dpdk/v23.07/source/lib/ring/rte_ring.h#= L502 Just to confirm you suggest something like that: - *entries =3D (r->prod.tail - *old_head); + count =3D (r->prod.tail - *old_head); + entries =3D (count > r->capacity) ? r->capacity : count; right? > > > thanks for flagging this inconsistency, but I think we are ok. >=20 > For consumer, I think this is correct, because we are only ever reducing > the number of entries in the ring, and the calculation of the number of > entries is made in the usual way using modulo arithmetic. We should never > have more than capacity entries in the ring so the check in ring count I > believe is superflous. [The exception would be if someone bypassed the > inline functions and accessed the ring directly themselves - at which poi= nt > "all bets are off", to use the English phrase] >=20 > The producer code (__rte_ring_move_prod_head) does do a capacity check, > which is where one is required to ensure we never exceed capacity. I also can't come up with the case, when current code will cause an issue.. In properly operating ring, I think we should never have more then r->capa= city=20 entries populated, so this extra check can be skipped. Unless you do have some particular case in mind? Konstantin =20