From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753591AbcALUbI (ORCPT ); Tue, 12 Jan 2016 15:31:08 -0500 Received: from mail.kernel.org ([198.145.29.136]:52646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753524AbcALUbG (ORCPT ); Tue, 12 Jan 2016 15:31:06 -0500 Subject: Re: [PATCH 3/4] x86,asm: Re-work smp_store_mb() To: Linus Torvalds , "Michael S. Tsirkin" References: <1445975631-17047-1-git-send-email-dave@stgolabs.net> <1445975631-17047-4-git-send-email-dave@stgolabs.net> <20151027223744.GB11242@worktop.amr.corp.intel.com> <20151102201535.GB1707@linux-uzut.site> <20160112150032-mutt-send-email-mst@redhat.com> Cc: Davidlohr Bueso , Davidlohr Bueso , Peter Zijlstra , the arch/x86 maintainers , Linux Kernel Mailing List , virtualization , "H. Peter Anvin" , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar From: Andy Lutomirski Message-ID: <56956276.1090705@kernel.org> Date: Tue, 12 Jan 2016 12:30:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/12/2016 09:20 AM, Linus Torvalds wrote: > On Tue, Jan 12, 2016 at 5:57 AM, Michael S. Tsirkin wrote: >> #ifdef xchgrz >> /* same as xchg but poking at gcc red zone */ >> #define barrier() do { int ret; asm volatile ("xchgl %0, -4(%%" SP ");": "=r"(ret) :: "memory", "cc"); } while (0) >> #endif > > That's not safe in general. gcc might be using its redzone, so doing > xchg into it is unsafe. > > But.. > >> Is this a good way to test it? > > .. it's fine for some basic testing. It doesn't show any subtle > interactions (ie some operations may have different dynamic behavior > when the write buffers are busy etc), but as a baseline for "how fast > can things go" the stupid raw loop is fine. And while the xchg into > the redzoen wouldn't be acceptable as a real implementation, for > timing testing it's likely fine (ie you aren't hitting the problem it > can cause). I recall reading somewhere that lock addl $0, 32(%rsp) or so (maybe even 64) was better because it avoided stomping on very-likely-to-be-hot write buffers. --Andy