From: "Michael S. Tsirkin" <mst@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Davidlohr Bueso <dbueso@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
the arch/x86 maintainers <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
virtualization <virtualization@lists.linux-foundation.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 3/4] x86,asm: Re-work smp_store_mb()
Date: Tue, 12 Jan 2016 19:45:27 +0200 [thread overview]
Message-ID: <20160112193027-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <CA+55aFwqgUQYVbVXLw1=LL6Gs=kXqhkx0tUZOdXnWbqCMdWfXg@mail.gmail.com>
On Tue, Jan 12, 2016 at 09:20:06AM -0800, Linus Torvalds wrote:
> On Tue, Jan 12, 2016 at 5:57 AM, Michael S. Tsirkin <mst@redhat.com> 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).
>
> > So mfence is more expensive than locked instructions/xchg, but sfence/lfence
> > are slightly faster, and xchg and locked instructions are very close if
> > not the same.
>
> Note that we never actually *use* lfence/sfence. They are pointless
> instructions when looking at CPU memory ordering, because for pure CPU
> memory ordering stores and loads are already ordered.
>
> The only reason to use lfence/sfence is after you've used nontemporal
> stores for IO.
By the way, the comment in barrier.h says:
/*
* Some non-Intel clones support out of order store. wmb() ceases to be
* a nop for these.
*/
and while the 1st sentence may well be true, if you have
an SMP system with out of order stores, making wmb
not a nop will not help.
Additionally as you point out, wmb is not a nop even
for regular intel CPUs because of these weird use-cases.
Drop this comment?
> That's very very rare in the kernel. So I wouldn't
> worry about those.
Right - I'll leave these alone, whoever wants to optimize this path will
have to do the necessary research.
> But yes, it does sound like mfence is just a bad idea too.
>
> > There isn't any extra magic behind mfence, is there?
>
> No.
>
> I think the only issue is that there has never been any real reason
> for CPU designers to try to make mfence go particularly fast. Nobody
> uses it, again with the exception of some odd loops that use
> nontemporal stores, and for those the cost tends to always be about
> the nontemporal accesses themselves (often to things like GPU memory
> over PCIe), and the mfence cost of a few extra cycles is negligible.
>
> The reason "lock ; add $0" has generally been the fastest we've found
> is simply that locked ops have been important for CPU designers.
>
> So I think the patch is fine, and we should likely drop the use of mfence..
>
> Linus
OK so should I repost after a bit more testing? I don't believe this
will affect the kernel build benchmark, but I'll try :)
--
MST
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>,
Davidlohr Bueso <dbueso@suse.de>,
"H. Peter Anvin" <hpa@zytor.com>,
virtualization <virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH 3/4] x86,asm: Re-work smp_store_mb()
Date: Tue, 12 Jan 2016 19:45:27 +0200 [thread overview]
Message-ID: <20160112193027-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <CA+55aFwqgUQYVbVXLw1=LL6Gs=kXqhkx0tUZOdXnWbqCMdWfXg@mail.gmail.com>
On Tue, Jan 12, 2016 at 09:20:06AM -0800, Linus Torvalds wrote:
> On Tue, Jan 12, 2016 at 5:57 AM, Michael S. Tsirkin <mst@redhat.com> 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).
>
> > So mfence is more expensive than locked instructions/xchg, but sfence/lfence
> > are slightly faster, and xchg and locked instructions are very close if
> > not the same.
>
> Note that we never actually *use* lfence/sfence. They are pointless
> instructions when looking at CPU memory ordering, because for pure CPU
> memory ordering stores and loads are already ordered.
>
> The only reason to use lfence/sfence is after you've used nontemporal
> stores for IO.
By the way, the comment in barrier.h says:
/*
* Some non-Intel clones support out of order store. wmb() ceases to be
* a nop for these.
*/
and while the 1st sentence may well be true, if you have
an SMP system with out of order stores, making wmb
not a nop will not help.
Additionally as you point out, wmb is not a nop even
for regular intel CPUs because of these weird use-cases.
Drop this comment?
> That's very very rare in the kernel. So I wouldn't
> worry about those.
Right - I'll leave these alone, whoever wants to optimize this path will
have to do the necessary research.
> But yes, it does sound like mfence is just a bad idea too.
>
> > There isn't any extra magic behind mfence, is there?
>
> No.
>
> I think the only issue is that there has never been any real reason
> for CPU designers to try to make mfence go particularly fast. Nobody
> uses it, again with the exception of some odd loops that use
> nontemporal stores, and for those the cost tends to always be about
> the nontemporal accesses themselves (often to things like GPU memory
> over PCIe), and the mfence cost of a few extra cycles is negligible.
>
> The reason "lock ; add $0" has generally been the fastest we've found
> is simply that locked ops have been important for CPU designers.
>
> So I think the patch is fine, and we should likely drop the use of mfence..
>
> Linus
OK so should I repost after a bit more testing? I don't believe this
will affect the kernel build benchmark, but I'll try :)
--
MST
next prev parent reply other threads:[~2016-01-12 17:45 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 19:53 [PATCH -tip 0/4] A few updates around smp_store_mb() Davidlohr Bueso
2015-10-27 19:53 ` [PATCH 1/4] arch,cmpxchg: Remove tas() definitions Davidlohr Bueso
2015-10-27 23:27 ` David Howells
2015-12-04 12:01 ` [tip:locking/core] locking/cmpxchg, arch: " tip-bot for Davidlohr Bueso
2015-10-27 19:53 ` [PATCH 2/4] arch,barrier: Use smp barriers in smp_store_release() Davidlohr Bueso
2015-10-27 20:03 ` Davidlohr Bueso
2015-12-04 12:01 ` [tip:locking/core] lcoking/barriers, arch: " tip-bot for Davidlohr Bueso
2015-10-27 19:53 ` [PATCH 3/4] x86,asm: Re-work smp_store_mb() Davidlohr Bueso
2015-10-27 21:33 ` Linus Torvalds
2015-10-27 22:01 ` Davidlohr Bueso
2015-10-27 22:37 ` Peter Zijlstra
2015-10-28 19:49 ` Davidlohr Bueso
2015-11-02 20:15 ` Davidlohr Bueso
2015-11-03 0:06 ` Linus Torvalds
2015-11-03 1:36 ` Davidlohr Bueso
2016-01-12 13:57 ` Michael S. Tsirkin
2016-01-12 13:57 ` Michael S. Tsirkin
2016-01-12 17:20 ` Linus Torvalds
2016-01-12 17:20 ` Linus Torvalds
2016-01-12 17:45 ` Michael S. Tsirkin [this message]
2016-01-12 17:45 ` Michael S. Tsirkin
2016-01-12 18:04 ` Linus Torvalds
2016-01-12 18:04 ` Linus Torvalds
2016-01-12 20:30 ` Andy Lutomirski
2016-01-12 20:54 ` Linus Torvalds
2016-01-12 20:54 ` Linus Torvalds
2016-01-12 20:59 ` Andy Lutomirski
2016-01-12 20:59 ` Andy Lutomirski
2016-01-12 21:37 ` Linus Torvalds
2016-01-12 21:37 ` Linus Torvalds
2016-01-12 22:14 ` Michael S. Tsirkin
2016-01-12 22:14 ` Michael S. Tsirkin
2016-01-13 16:20 ` Michael S. Tsirkin
2016-01-13 16:20 ` Michael S. Tsirkin
2016-01-12 22:21 ` Michael S. Tsirkin
2016-01-12 22:21 ` Michael S. Tsirkin
2016-01-12 22:55 ` H. Peter Anvin
2016-01-12 22:55 ` H. Peter Anvin
2016-01-12 23:24 ` Linus Torvalds
2016-01-12 23:24 ` Linus Torvalds
2016-01-13 16:17 ` Borislav Petkov
2016-01-13 16:17 ` Borislav Petkov
2016-01-13 16:25 ` Michael S. Tsirkin
2016-01-13 16:25 ` Michael S. Tsirkin
2016-01-13 16:33 ` Borislav Petkov
2016-01-13 16:33 ` Borislav Petkov
2016-01-13 16:42 ` Michael S. Tsirkin
2016-01-13 16:42 ` Michael S. Tsirkin
2016-01-13 16:53 ` Borislav Petkov
2016-01-13 16:53 ` Borislav Petkov
2016-01-13 17:00 ` Michael S. Tsirkin
2016-01-13 17:00 ` Michael S. Tsirkin
2016-01-13 18:38 ` Linus Torvalds
2016-01-13 18:38 ` Linus Torvalds
2015-10-27 19:53 ` [PATCH 4/4] doc,smp: Remove ambiguous statement in smp_store_mb() Davidlohr Bueso
2015-12-04 12:01 ` [tip:locking/core] locking/barriers, arch: Remove ambiguous statement in the smp_store_mb() documentation tip-bot for Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160112193027-mutt-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=dave@stgolabs.net \
--cc=dbueso@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.