From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2qP0-0005xc-SA for qemu-devel@nongnu.org; Tue, 17 May 2016 21:36:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2oFp-0002l1-Tj for qemu-devel@nongnu.org; Tue, 17 May 2016 19:18:25 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:59180) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2oFn-0002bf-KU for qemu-devel@nongnu.org; Tue, 17 May 2016 19:18:21 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 11B0220AA4 for ; Tue, 17 May 2016 19:18:10 -0400 (EDT) Date: Tue, 17 May 2016 19:18:09 -0400 From: "Emilio G. Cota" Message-ID: <20160517231809.GA17517@flamenco> References: <1463196873-17737-1-git-send-email-cota@braap.org> <1463196873-17737-8-git-send-email-cota@braap.org> <573B5134.8060104@gmail.com> <20160517193842.GB30174@flamenco> <573B80AD.50503@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <573B80AD.50503@gmail.com> Subject: Re: [Qemu-devel] [PATCH v5 07/18] qemu-thread: add simple test-and-set spinlock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Fedorov Cc: QEMU Developers , MTTCG Devel , Alex =?iso-8859-1?Q?Benn=E9e?= , Paolo Bonzini , Peter Crosthwaite , Richard Henderson On Tue, May 17, 2016 at 23:35:57 +0300, Sergey Fedorov wrote: > On 17/05/16 22:38, Emilio G. Cota wrote: > > On Tue, May 17, 2016 at 20:13:24 +0300, Sergey Fedorov wrote: > >> On 14/05/16 06:34, Emilio G. Cota wrote: > (snip) > >>> + while (atomic_read(&spin->value)) { > >>> + cpu_relax(); > >>> + } > >>> + } > >> Looks like relaxed atomic access can be a subject to various > >> optimisations according to > >> https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync#Relaxed. > > The important thing here is that the read actually happens > > on every iteration; this is achieved with atomic_read(). > > Barriers etc. do not matter here because once we exit > > the loop, the try to acquire the lock -- and if we succeed, > > we then emit the right barrier. > > I just can't find where it is stated that an expression like > "__atomic_load(ptr, &_val, __ATOMIC_RELAXED)" has a _compiler_ barrier > or volatile access semantic. Hopefully, cpu_relax() serves as a compiler > barrier. If we rely on that, we'd better put a comment about it. I treat atomic_read/set as ACCESS_ONCE[1], i.e. volatile cast. >>From docs/atomics.txt: COMPARISON WITH LINUX KERNEL MEMORY BARRIERS ============================================ [...] - atomic_read and atomic_set in Linux give no guarantee at all; atomic_read and atomic_set in QEMU include a compiler barrier (similar to the ACCESS_ONCE macro in Linux). [1] https://lwn.net/Articles/508991/ Emilio