From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astuC-00048x-2u for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1astu8-0006t4-3Q for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:19:04 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:35815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astu7-0006sr-S9 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:19:00 -0400 Received: by mail-qk0-x244.google.com with SMTP id k126so2207949qke.2 for ; Wed, 20 Apr 2016 08:18:59 -0700 (PDT) Sender: Richard Henderson References: <1461107270-19234-1-git-send-email-cota@braap.org> <1461107270-19234-6-git-send-email-cota@braap.org> From: Richard Henderson Message-ID: <57179DE0.5080701@twiddle.net> Date: Wed, 20 Apr 2016 08:18:56 -0700 MIME-Version: 1.0 In-Reply-To: <1461107270-19234-6-git-send-email-cota@braap.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 05/11] qemu-thread: add simple test-and-set spinlock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , QEMU Developers , MTTCG Devel Cc: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Paolo Bonzini , Peter Crosthwaite , Peter Maydell , Sergey Fedorov On 04/19/2016 04:07 PM, Emilio G. Cota wrote: > From: Guillaume Delbergue > > Signed-off-by: Guillaume Delbergue > [Rewritten. - Paolo] > Signed-off-by: Paolo Bonzini > [Emilio's additions: call cpu_relax() while spinning; optimize for > uncontended locks by acquiring the lock with xchg+test instead of > test+xchg+test.] > Signed-off-by: Emilio G. Cota > --- It probably doesn't matter for any real hosts, but do note that there are compiler primitives for test-and-set that (can be) simpler for a cpu to implement than xchg. This likely affects only ancient hosts like sparcv7, or tiny hosts like SH. We don't have to change anything here, but it does seem more natural to use a test-and-set primitive. > +static inline int qemu_spin_trylock(QemuSpin *spin) > +{ > + if (atomic_read(&spin->value) || atomic_xchg(&spin->value, true)) { > + return -EBUSY; I think there's no point in the extra read here. r~