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 7E7034409D; Wed, 22 May 2024 21:01:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 10F214026B; Wed, 22 May 2024 21:01:14 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 345F1400D6 for ; Wed, 22 May 2024 21:01:13 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 3326120B915A; Wed, 22 May 2024 12:01:12 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3326120B915A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1716404472; bh=sEeRpMGnFxG5wGgzco3obLQXb+z2Z+K+tJ0bG2WbchU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rS5Ib38oOkEWh7HK52f1xiyY3zOxUGTFR3BZcfsOCQM2buR63kAZ75+ym/W1Pg9kF CYSzpVTYXZqeQ2YE2mScUBt4ojtMIEHbWutmoSPCVO9hmwQl9WrYA9Hhf/40xjIsMk u2O7qOY1+dwA1ET+WvACrGg/mFQF+sj7eASLNpBc= Date: Wed, 22 May 2024 12:01:12 -0700 From: Tyler Retzlaff To: Morten =?iso-8859-1?Q?Br=F8rup?= Cc: Stephen Hemminger , dev@dpdk.org Subject: Re: [PATCH v9 1/8] eal: generic 64 bit counter Message-ID: <20240522190112.GA19947@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20240510050507.14381-1-stephen@networkplumber.org> <20240521201801.126886-1-stephen@networkplumber.org> <20240521201801.126886-2-stephen@networkplumber.org> <98CBD80474FA8B44BF855DF32C47DC35E9F488@smartserver.smartshare.dk> <20240522083741.64078d7e@hermes.local> <98CBD80474FA8B44BF855DF32C47DC35E9F48C@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F48C@smartserver.smartshare.dk> User-Agent: Mutt/1.5.21 (2010-09-15) 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 Wed, May 22, 2024 at 07:57:01PM +0200, Morten Brørup wrote: > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > Sent: Wednesday, 22 May 2024 17.38 > > > > On Wed, 22 May 2024 10:31:39 +0200 > > Morten Brørup wrote: > > > > > > +/* On 32 bit platform, need to use atomic to avoid load/store > > tearing */ > > > > +typedef RTE_ATOMIC(uint64_t) rte_counter64_t; > > > > > > As shown by Godbolt experiments discussed in a previous thread [2], > > non-tearing 64 bit counters can be implemented without using atomic > > instructions on all 32 bit architectures supported by DPDK. So we should > > use the counter/offset design pattern for RTE_ARCH_32 too. > > > > > > [2]: > > https://inbox.dpdk.org/dev/98CBD80474FA8B44BF855DF32C47DC35E9F433@smarts > > erver.smartshare.dk/ > > > > > > This code built with -O3 and -m32 on godbolt shows split problem. > > > > #include > > > > typedef uint64_t rte_counter64_t; > > > > void > > rte_counter64_add(rte_counter64_t *counter, uint32_t val) > > { > > *counter += val; > > } > > … *counter = val; > > } > > > > rte_counter64_add: > > push ebx > > mov eax, DWORD PTR [esp+8] > > xor ebx, ebx > > mov ecx, DWORD PTR [esp+12] > > add DWORD PTR [eax], ecx > > adc DWORD PTR [eax+4], ebx > > pop ebx > > ret > > > > rte_counter64_read: > > mov eax, DWORD PTR [esp+4] > > mov edx, DWORD PTR [eax+4] > > mov eax, DWORD PTR [eax] > > ret > > rte_counter64_set: > > movq xmm0, QWORD PTR [esp+8] > > mov eax, DWORD PTR [esp+4] > > movq QWORD PTR [eax], xmm0 > > ret > > Sure, atomic might be required on some 32 bit architectures and/or with some compilers. in theory i think you should be able to use generic atomics and depending on the target you get codegen that works. it might be something more expensive on 32-bit and nothing on 64-bit etc.. what's the damage if we just use atomic generic and relaxed ordering? is the codegen not optimal? > I envision a variety of 32 bit implementations, optimized for certain architectures/compilers. > > Some of them can provide non-tearing 64 bit load/store, so we should also use the counter/offset design pattern for those. >