arch: barrier cleanup + barriers for virt
Subsystems (16)
Michael S. Tsirkin
maintainerv3 cover arch: barrier cleanup + barriers for virt
Changes since v2:
- extended checkpatch tests for barriers, and added patches teaching it to warn about incorrect usage of barriers (__smp_xxx barriers are for use by asm-generic code only), should help prevent misuse by arch code
to address comments by Russell King
- patched more instances of xen to use virt_ barriers
as suggested by Stefano Stabellini
- implemented a 2 byte xchg on sh instead of hacking around it as suggested by Peter Zijlstra and Rich Felker
- added a patch to drop some s390 arch-specific smp_xxx barriers - generic versions are more efficient
as suggested by Peter Zijlstra and Martin Schwidefsky
- added a patch to replace before/after atomic barriers with barrier() on s390 as suggested by Peter Zijlstra and Martin Schwidefsky
- included acks from multiple arch maintainers
thanks a lot for the review!
Changes since v1:
- replaced an asm-generic patch with an equivalent patch already in tip
- add wrappers with virt_ prefix for better code annotation, as suggested by David Miller
- dropped XXX in patch names as this makes vger choke, Cc all relevant mailing lists on all patches (not personal email, as the list becomes too long then)
I parked this in vhost tree for now, though the inclusion of patch 1 from tip creates a merge conflict - but one that is trivial to resolve.
So I intend to just merge it all through my tree, including the duplicate patch, and assume conflict will be resolved.
I would really appreciate some feedback on arch bits (especially the x86 bits), and acks for merging this through the vhost tree.
Thanks!
What really started me off is trying to cleanup some virt code, as suggested by Peter, who said
Quoted 2 lines
You could of course go fix that instead of mutilating things into sort-of functional state.
This work is needed for virtio, so it's probably easiest to merge it through my tree - is this fine by everyone?
Note to arch maintainers: please don't cherry-pick patches out of this patchset as it's been structured in this order to avoid breaking bisect. Please send acks instead!
=====
Sometimes, virtualization is weird. For example, virtio does this (conceptually):
#ifdef CONFIG_SMP
smp_mb();
#else
mb();#endif
Similarly, Xen calls mb() when it's not doing any MMIO at all.
Of course it's wrong in the sense that it's suboptimal. What we would really like is to have, on UP, exactly the same barrier as on SMP. This is because a UP guest can run on an SMP host.
But Linux doesn't provide this ability: if CONFIG_SMP is not defined is optimizes most barriers out to a compiler barrier.
Consider for example x86: what we want is xchg (NOT mfence - there's no real IO going on here - just switching out of the VM - more like a function call really) but if built without CONFIG_SMP smp_store_mb does not include this.
Virt in general is probably the only use-case, because this really is an artifact of interfacing with an SMP host while running an UP kernel, but since we have (at least) two users, it seems to make sense to put these APIs in a central place.
In fact, smp_ barriers are stubs on !SMP, so they can be defined as follows:
arch/XXX/include/asm/barrier.h:
#define __smp_mb() DOSOMETHING
include/asm-generic/barrier.h:
#ifdef CONFIG_SMP
#define smp_mb() __smp_mb()
#else
#define smp_mb() barrier()
#endif
This has the benefit of cleaning out a bunch of duplicated ifdefs on a bunch of architectures - this patchset brings about a net reduction in LOC, more than compensated for later by performance enhancements, extra documentation and tools :)
Then virt can use __smp_XXX when talking to an SMP host. To make those users explicit, this patchset adds virt_xxx wrappers for them.
Touching all archs is a tad tedious, but its fairly straight forward.
The patchset is structured as follows:
-. Patch 1 fixes a bug in asm-generic.
It is already in tip, included here for completeness.
-. Patches 2-12 make sure barrier.h on all remaining
architectures includes asm-generic/barrier.h:
after the change in Patch 1, code there matches asm-generic/barrier.h almost verbatim.
Minor code tweaks were required in a couple of places. Macros duplicated from asm-generic/barrier.h are dropped in the process.
After all that preparatory work, we are getting to the actual change.
-. Patch 13 adds generic smp_XXX wrappers in asm-generic:
these select __smp_XXX or barrier() depending on CONFIG_SMP
-. Patches 14-27 change all architectures to
define __smp_XXX macros; the generic code in asm-generic/barrier.h then defines smp_XXX macros
I compiled the affected arches before and after the changes, dumped the .text section (using objdump -O binary) and made sure that the object code is exactly identical before and after the change.
Note: the changes were intentionally done in a way that avoids generated code changes.
When I got feedback from arch maintainers that the barriers can be improved, I made this in a separate patch on top, to allow this testing by binary comparisons.
Unfortunately, I don't have a metag cross-build toolset ready. Hoping for some acks on this architecture.
Next, the following patches put the __smp_xxx APIs to work for virt:
-. Patch 28 adds virt_ wrappers for __smp_, and documents them.
After all this work, this requires very few lines of code in the generic header.
-. Patches 29,30 convert virtio drivers to use the virt_xxx APIs
tested on x86
-. Patches 31-33 teach virtio to use virt_store_mb
sh architecture was missing a 2-byte xchg, needed for 2 byte smp_store_mb,
so I had to add this support for sh
-. Patches 34-36 teach checkpatch to warn about
misuse of the new barriers
-. Patches 37-39 convert xen drivers to use the virt_xxx APIs
compiled only (by intel 0-day infrastructure)
-. Patch 40 makes some smp barriers on s390 more efficient
included here to avoid merge conflicts, at maintainer's request
tested on x86
Davidlohr Bueso (1):
lcoking/barriers, arch: Use smp barriers in smp_store_release()
Michael S. Tsirkin (40):
asm-generic: guard smp_store_release/load_acquire
ia64: rename nop->iosapic_nop
ia64: reuse asm-generic/barrier.h
powerpc: reuse asm-generic/barrier.h
s390: reuse asm-generic/barrier.h
sparc: reuse asm-generic/barrier.h
arm: reuse asm-generic/barrier.h
arm64: reuse asm-generic/barrier.h
metag: reuse asm-generic/barrier.h
mips: reuse asm-generic/barrier.h
x86/um: reuse asm-generic/barrier.h
x86: reuse asm-generic/barrier.h
asm-generic: add __smp_xxx wrappers
powerpc: define __smp_xxx
arm64: define __smp_xxx
arm: define __smp_xxx
blackfin: define __smp_xxx
ia64: define __smp_xxx
metag: define __smp_xxx
mips: define __smp_xxx
s390: define __smp_xxx
sh: define __smp_xxx, fix smp_store_mb for !SMP
sparc: define __smp_xxx
tile: define __smp_xxx
xtensa: define __smp_xxx
x86: define __smp_xxx
asm-generic: implement virt_xxx memory barriers Revert "virtio_ring: Update weak barriers to use dma_wmb/rmb"
virtio_ring: update weak barriers to use virt_xxx
sh: support 1 and 2 byte xchg
sh: move xchg_cmpxchg to a header by itself
virtio_ring: use virt_store_mb
checkpatch.pl: add missing memory barriers
checkpatch: check for __smp outside barrier.h
checkpatch: add virt barriers
xenbus: use virt_xxx barriers
xen/io: use virt_xxx barriers
xen/events: use virt_xxx barriers
s390: use generic memory barriers
s390: more efficient smp barriers
arch/arm/include/asm/barrier.h | 35 ++---------- arch/arm64/include/asm/barrier.h | 19 ++----- arch/blackfin/include/asm/barrier.h | 4 +- arch/ia64/include/asm/barrier.h | 24 +++----- arch/metag/include/asm/barrier.h | 55 ++++++------------- arch/mips/include/asm/barrier.h | 51 ++++++----------- arch/powerpc/include/asm/barrier.h | 33 ++++------- arch/s390/include/asm/barrier.h | 23 ++++---- arch/sh/include/asm/barrier.h | 3 +- arch/sh/include/asm/cmpxchg-grb.h | 22 ++++++++ arch/sh/include/asm/cmpxchg-irq.h | 11 ++++ arch/sh/include/asm/cmpxchg-llsc.h | 25 +-------- arch/sh/include/asm/cmpxchg-xchg.h | 51 +++++++++++++++++ arch/sh/include/asm/cmpxchg.h | 3 + arch/sparc/include/asm/barrier_32.h | 1 - arch/sparc/include/asm/barrier_64.h | 29 ++-------- arch/sparc/include/asm/processor.h | 3 - arch/tile/include/asm/barrier.h | 9 +-- arch/x86/include/asm/barrier.h | 36 +++++------- arch/x86/um/asm/barrier.h | 9 +-- arch/xtensa/include/asm/barrier.h | 4 +- include/asm-generic/barrier.h | 106 +++++++++++++++++++++++++++++++++--- include/linux/virtio_ring.h | 21 +++++-- include/xen/interface/io/ring.h | 16 +++--- arch/ia64/kernel/iosapic.c | 6 +- drivers/virtio/virtio_ring.c | 15 +++-- drivers/xen/events/events_fifo.c | 3 +- drivers/xen/xenbus/xenbus_comms.c | 8 +-- Documentation/memory-barriers.txt | 28 ++++++++-- scripts/checkpatch.pl | 31 ++++++++++- 30 files changed, 382 insertions(+), 302 deletions(-) create mode 100644 arch/sh/include/asm/cmpxchg-xchg.h
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 1/41 lcoking/barriers, arch: Use smp barriers in smp_store_release()
From: Davidlohr Bueso <[email protected]>
With commit b92b8b35a2e ("locking/arch: Rename set_mb() to smp_store_mb()") it was made clear that the context of this call (and thus set_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant of mb(), respecting the semantics and saving a mandatory barrier on UP.
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
arch/ia64/include/asm/barrier.h +1 -1
@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure
arch/powerpc/include/asm/barrier.h +1 -1
@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC
arch/s390/include/asm/barrier.h +1 -1
@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \
include/asm-generic/barrier.h +1 -1
@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomic
Signature · 1 line
MST
Re: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
Quoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.
Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Aside from a need for s/lcoking/locking/ in the subject line:
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
Quoted 24 lines · Paul E. McKenney
Quoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Cc dave at stgolabs.netLink http://lkml.kernel.org/r/1445975631-17047-3-git-send-email-dave at stgolabs.netSigned-off-by Ingo Molnar <[email protected]>
Quoted 3 lines
Aside from a need for s/lcoking/locking/ in the subject line:
Reviewed-by Paul E. McKenney <[email protected]>
Thanks!
Though Ingo already put this in tip tree like this, and I need a copy in my tree to avoid breaking bisect, so I will probably keep it exactly the same to avoid confusion.
Quoted 62 lines
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
In reply to Paul E. McKenneyQuoted 24 lines · Paul E. McKenney
Quoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Quoted 3 lines
Aside from a need for s/lcoking/locking/ in the subject line:
Reviewed-by Paul E. McKenney <[email protected]>
Thanks!
Though Ingo already put this in tip tree like this, and I need a copy in my tree to avoid breaking bisect, so I will probably keep it exactly the same to avoid confusion.
Quoted 62 lines
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
In reply to Paul E. McKenneyQuoted 24 lines · Paul E. McKenney
Quoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Quoted 3 lines
Aside from a need for s/lcoking/locking/ in the subject line:
Reviewed-by Paul E. McKenney <[email protected]>
Thanks!
Though Ingo already put this in tip tree like this, and I need a copy in my tree to avoid breaking bisect, so I will probably keep it exactly the same to avoid confusion.
Quoted 62 lines
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Re: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
In reply to Michael S. TsirkinQuoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.
Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Aside from a need for s/lcoking/locking/ in the subject line:
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Re: [PATCH v3 01/41] lcoking/barriers, arch: Use smp barriers in smp_store_release()
In reply to Michael S. TsirkinQuoted 8 lines · Michael S. Tsirkin
From: Davidlohr Bueso <[email protected]>
With commit
b92b8b35a2e("locking/arch: Renameset_mb()tosmp_store_mb()") it was made clear that the context of this call (and thusset_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant ofmb(), respecting the semantics and saving a mandatory barrier on UP.
Quoted 14 lines
Signed-off-by Davidlohr Bueso <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Cc <[email protected]>Cc Andrew Morton <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Heiko Carstens <[email protected]>Cc Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Aside from a need for s/lcoking/locking/ in the subject line:
Quoted 62 lines
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)arch/ia64/include/asm/barrier.h +1
-1@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure arch/powerpc/include/asm/barrier.h +1
-1@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNCarch/s390/include/asm/barrier.h +1
-1@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \include/asm-generic/barrier.h +1
-1@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomicSignature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 1/41 lcoking/barriers, arch: Use smp barriers in smp_store_release()
In reply to Michael S. TsirkinFrom: Davidlohr Bueso <[email protected]>
With commit b92b8b35a2e ("locking/arch: Rename set_mb() to smp_store_mb()") it was made clear that the context of this call (and thus set_mb) is strictly for CPU ordering, as opposed to IO. As such all archs should use the smp variant of mb(), respecting the semantics and saving a mandatory barrier on UP.
--- arch/ia64/include/asm/barrier.h | 2 +- arch/powerpc/include/asm/barrier.h | 2 +- arch/s390/include/asm/barrier.h | 2 +- include/asm-generic/barrier.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
arch/ia64/include/asm/barrier.h +1 -1
@@ -77,7 +77,7 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)/* * The group barrier in front of the rsm & ssm are necessary to ensure
arch/powerpc/include/asm/barrier.h +1 -1
@@ -34,7 +34,7 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC
arch/s390/include/asm/barrier.h +1 -1
@@ -36,7 +36,7 @@#define smp_mb__before_atomic () smp_mb()#define smp_mb__after_atomic () smp_mb() -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#define smp_store_release (p, v) \ do { \
include/asm-generic/barrier.h +1 -1
@@ -93,7 +93,7 @@#endif /* CONFIG_SMP */ #ifndef smp_store_mb -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); mb(); } while (0) +#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)#endif #ifndef smp_mb__before_atomic
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 2/41 asm-generic: guard smp_store_release/load_acquire
In reply to Michael S. TsirkinAllow architectures to override smp_store_release and smp_load_acquire by guarding the defines in asm-generic/barrier.h with ifndef directives.
This is in preparation to reusing asm-generic/barrier.h on architectures which have their own definition of these macros.
--- include/asm-generic/barrier.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/barrier.h +4 -0
@@ -104,13 +104,16 @@#define smp_mb__after_atomic () smp_mb()#endif +#ifndef smp_store_release#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \ smp_mb(); \ WRITE_ONCE(*p, v); \ } while (0) +#endif +#ifndef smp_load_acquire#define smp_load_acquire (p) \ ({ \ typeof(*p) ___p1 = READ_ONCE(*p); \
@@ -118,6 +121,7 @@ do { \smp_mb (); \ ___p1; \ }) +#endif #endif /* !__ASSEMBLY__ */ #endif /* __ASM_GENERIC_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 2/41 asm-generic: guard smp_store_release/load_acquire
In reply to Michael S. TsirkinAllow architectures to override smp_store_release and smp_load_acquire by guarding the defines in asm-generic/barrier.h with ifndef directives.
This is in preparation to reusing asm-generic/barrier.h on architectures which have their own definition of these macros.
--- include/asm-generic/barrier.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/barrier.h +4 -0
@@ -104,13 +104,16 @@#define smp_mb__after_atomic () smp_mb()#endif +#ifndef smp_store_release#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \ smp_mb(); \ WRITE_ONCE(*p, v); \ } while (0) +#endif +#ifndef smp_load_acquire#define smp_load_acquire (p) \ ({ \ typeof(*p) ___p1 = READ_ONCE(*p); \
@@ -118,6 +121,7 @@ do { \smp_mb (); \ ___p1; \ }) +#endif #endif /* !__ASSEMBLY__ */ #endif /* __ASM_GENERIC_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 2/41 asm-generic: guard smp_store_release/load_acquire
In reply to Michael S. TsirkinAllow architectures to override smp_store_release and smp_load_acquire by guarding the defines in asm-generic/barrier.h with ifndef directives.
This is in preparation to reusing asm-generic/barrier.h on architectures which have their own definition of these macros.
--- include/asm-generic/barrier.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/barrier.h +4 -0
@@ -104,13 +104,16 @@#define smp_mb__after_atomic () smp_mb()#endif +#ifndef smp_store_release#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \ smp_mb(); \ WRITE_ONCE(*p, v); \ } while (0) +#endif +#ifndef smp_load_acquire#define smp_load_acquire (p) \ ({ \ typeof(*p) ___p1 = READ_ONCE(*p); \
@@ -118,6 +121,7 @@ do { \smp_mb (); \ ___p1; \ }) +#endif #endif /* !__ASSEMBLY__ */ #endif /* __ASM_GENERIC_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 3/41 ia64: rename nop->iosapic_nop
In reply to Michael S. Tsirkinasm-generic/barrier.h defines a nop() macro. To be able to use this header on ia64, we shouldn't call local functions/variables nop().
There's one instance where this breaks on ia64:
rename the function to iosapic_nop to avoid the conflict.
--- arch/ia64/kernel/iosapic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/ia64/kernel/iosapic.c +3 -3
@@ -256,7 +256,7 @@ set_rte (unsigned int gsi, unsigned int irq, unsigned int dest, int mask) }static void -nop (struct irq_data *data) +iosapic_nop (struct irq_data *data) {/* do nothing... */ }
@@ -415,7 +415,7 @@ iosapic_unmask_level_irq (struct irq_data *data)#define iosapic_shutdown_level_irq mask_irq#define iosapic_enable_level_irq unmask_irq#define iosapic_disable_level_irq mask_irq -#define iosapic_ack_level_irq nop +#define iosapic_ack_level_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_level = { .name ="IO-SAPIC-level" ,
@@ -453,7 +453,7 @@ iosapic_ack_edge_irq (struct irq_data *data) }#define iosapic_enable_edge_irq unmask_irq -#define iosapic_disable_edge_irq nop +#define iosapic_disable_edge_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_edge = { .name ="IO-SAPIC-edge" ,
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 3/41 ia64: rename nop->iosapic_nop
In reply to Michael S. Tsirkinasm-generic/barrier.h defines a nop() macro. To be able to use this header on ia64, we shouldn't call local functions/variables nop().
There's one instance where this breaks on ia64:
rename the function to iosapic_nop to avoid the conflict.
--- arch/ia64/kernel/iosapic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/ia64/kernel/iosapic.c +3 -3
@@ -256,7 +256,7 @@ set_rte (unsigned int gsi, unsigned int irq, unsigned int dest, int mask) }static void -nop (struct irq_data *data) +iosapic_nop (struct irq_data *data) {/* do nothing... */ }
@@ -415,7 +415,7 @@ iosapic_unmask_level_irq (struct irq_data *data)#define iosapic_shutdown_level_irq mask_irq#define iosapic_enable_level_irq unmask_irq#define iosapic_disable_level_irq mask_irq -#define iosapic_ack_level_irq nop +#define iosapic_ack_level_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_level = { .name ="IO-SAPIC-level" ,
@@ -453,7 +453,7 @@ iosapic_ack_edge_irq (struct irq_data *data) }#define iosapic_enable_edge_irq unmask_irq -#define iosapic_disable_edge_irq nop +#define iosapic_disable_edge_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_edge = { .name ="IO-SAPIC-edge" ,
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 3/41 ia64: rename nop->iosapic_nop
In reply to Michael S. Tsirkinasm-generic/barrier.h defines a nop() macro. To be able to use this header on ia64, we shouldn't call local functions/variables nop().
There's one instance where this breaks on ia64:
rename the function to iosapic_nop to avoid the conflict.
--- arch/ia64/kernel/iosapic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/ia64/kernel/iosapic.c +3 -3
@@ -256,7 +256,7 @@ set_rte (unsigned int gsi, unsigned int irq, unsigned int dest, int mask) }static void -nop (struct irq_data *data) +iosapic_nop (struct irq_data *data) {/* do nothing... */ }
@@ -415,7 +415,7 @@ iosapic_unmask_level_irq (struct irq_data *data)#define iosapic_shutdown_level_irq mask_irq#define iosapic_enable_level_irq unmask_irq#define iosapic_disable_level_irq mask_irq -#define iosapic_ack_level_irq nop +#define iosapic_ack_level_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_level = { .name ="IO-SAPIC-level" ,
@@ -453,7 +453,7 @@ iosapic_ack_edge_irq (struct irq_data *data) }#define iosapic_enable_edge_irq unmask_irq -#define iosapic_disable_edge_irq nop +#define iosapic_disable_edge_irq iosapic_nopstatic struct irq_chip irq_type_iosapic_edge = { .name ="IO-SAPIC-edge" ,
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 4/41 ia64: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn ia64 smp_rmb, smp_wmb, read_barrier_depends, smp_read_barrier_depends and smp_store_mb() match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/ia64/include/asm/barrier.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/ia64/include/asm/barrier.h +2 -8
@@ -48,12 +48,6 @@# define smp_mb () barrier()#endif -#define smp_rmb () smp_mb() -#define smp_wmb () smp_mb() - -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier()
@@ -77,12 +71,12 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -/* * The group barrier in front of the rsm & ssm are necessary to ensure * that none of the previous instructions in the same group are * affected by the rsm/ssm. */ +#include <asm-generic/barrier.h> +#endif /* _ASM_IA64_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 4/41 ia64: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn ia64 smp_rmb, smp_wmb, read_barrier_depends, smp_read_barrier_depends and smp_store_mb() match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/ia64/include/asm/barrier.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/ia64/include/asm/barrier.h +2 -8
@@ -48,12 +48,6 @@# define smp_mb () barrier()#endif -#define smp_rmb () smp_mb() -#define smp_wmb () smp_mb() - -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier()
@@ -77,12 +71,12 @@ do { \ ___p1; \ }) -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -/* * The group barrier in front of the rsm & ssm are necessary to ensure * that none of the previous instructions in the same group are * affected by the rsm/ssm. */ +#include <asm-generic/barrier.h> +#endif /* _ASM_IA64_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 5/41 powerpc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn powerpc read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/powerpc/include/asm/barrier.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/barrier.h +2 -7
@@ -34,8 +34,6 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC#else
@@ -60,9 +58,6 @@#define smp_wmb () barrier()#endif /* CONFIG_SMP */ -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -/* * This is a barrier which prevents following instructions from being * started until the value of the argument x is known. For example, if
@@ -87,8 +82,8 @@ do { \ ___p1; \ }) -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb()#define smp_mb__before_spinlock () smp_mb() +#include <asm-generic/barrier.h> +#endif /* _ASM_POWERPC_BARRIER_H */
Signature · 1 line
MST
Re: [PATCH v3 05/41] powerpc: reuse asm-generic/barrier.h
Quoted 9 lines · Michael S. Tsirkin
On powerpc
read_barrier_depends,smp_read_barrier_dependssmp_store_mb(),smp_mb__before_atomicandsmp_mb__after_atomicmatch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.This is in preparation to refactoring this code area.
Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Arnd Bergmann <[email protected]>
Looks sane to me.
Quoted 41 lines
--- arch/powerpc/include/asm/barrier.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)arch/powerpc/include/asm/barrier.h +2
-7@@ -34,8 +34,6 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC#else @@ -60,9 +58,6 @@#define smp_wmb () barrier()#endif /* CONFIG_SMP */ -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -/* * This is a barrier which prevents following instructions from being * started until the value of the argument x is known. For example, if @@ -87,8 +82,8 @@ do { \ ___p1; \ }) -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb()#define smp_mb__before_spinlock () smp_mb() +#include <asm-generic/barrier.h> +#endif /* _ASM_POWERPC_BARRIER_H */ Signature · 1 line
MST
Re: [PATCH v3 05/41] powerpc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinQuoted 9 lines · Michael S. Tsirkin
On powerpc
read_barrier_depends,smp_read_barrier_dependssmp_store_mb(),smp_mb__before_atomicandsmp_mb__after_atomicmatch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.This is in preparation to refactoring this code area.
Signed-off-by Michael S. Tsirkin <[email protected]>Acked-by Arnd Bergmann <[email protected]>
Looks sane to me.
Quoted 41 lines
--- arch/powerpc/include/asm/barrier.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)arch/powerpc/include/asm/barrier.h +2
-7@@ -34,8 +34,6 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC#else @@ -60,9 +58,6 @@#define smp_wmb () barrier()#endif /* CONFIG_SMP */ -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -/* * This is a barrier which prevents following instructions from being * started until the value of the argument x is known. For example, if @@ -87,8 +82,8 @@ do { \ ___p1; \ }) -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb()#define smp_mb__before_spinlock () smp_mb() +#include <asm-generic/barrier.h> +#endif /* _ASM_POWERPC_BARRIER_H */ Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 5/41 powerpc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn powerpc read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/powerpc/include/asm/barrier.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/barrier.h +2 -7
@@ -34,8 +34,6 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC#else
@@ -60,9 +58,6 @@#define smp_wmb () barrier()#endif /* CONFIG_SMP */ -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -/* * This is a barrier which prevents following instructions from being * started until the value of the argument x is known. For example, if
@@ -87,8 +82,8 @@ do { \ ___p1; \ }) -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb()#define smp_mb__before_spinlock () smp_mb() +#include <asm-generic/barrier.h> +#endif /* _ASM_POWERPC_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 5/41 powerpc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn powerpc read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/powerpc/include/asm/barrier.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/barrier.h +2 -7
@@ -34,8 +34,6 @@#define rmb () __asm__ __volatile__ ("sync" : : : "memory")#define wmb () __asm__ __volatile__ ("sync" : : : "memory") -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#ifdef __SUBARCH_HAS_LWSYNC# define SMPWMB LWSYNC#else
@@ -60,9 +58,6 @@#define smp_wmb () barrier()#endif /* CONFIG_SMP */ -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -/* * This is a barrier which prevents following instructions from being * started until the value of the argument x is known. For example, if
@@ -87,8 +82,8 @@ do { \ ___p1; \ }) -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb()#define smp_mb__before_spinlock () smp_mb() +#include <asm-generic/barrier.h> +#endif /* _ASM_POWERPC_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 6/41 s390: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn s390 read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/s390/include/asm/barrier.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/s390/include/asm/barrier.h +2 -8
@@ -30,14 +30,6 @@#define smp_rmb () rmb()#define smp_wmb () wmb() -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -53,4 +45,6 @@ do { \ ___p1; \ }) +#include <asm-generic/barrier.h> +#endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 6/41 s390: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn s390 read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/s390/include/asm/barrier.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/s390/include/asm/barrier.h +2 -8
@@ -30,14 +30,6 @@#define smp_rmb () rmb()#define smp_wmb () wmb() -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -53,4 +45,6 @@ do { \ ___p1; \ }) +#include <asm-generic/barrier.h> +#endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 6/41 s390: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn s390 read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/s390/include/asm/barrier.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/s390/include/asm/barrier.h +2 -8
@@ -30,14 +30,6 @@#define smp_rmb () rmb()#define smp_wmb () wmb() -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -53,4 +45,6 @@ do { \ ___p1; \ }) +#include <asm-generic/barrier.h> +#endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 7/41 sparc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn sparc 64 bit dma_rmb, dma_wmb, smp_store_mb, smp_mb, smp_rmb, smp_wmb, read_barrier_depends and smp_read_barrier_depends match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
nop uses __asm__ __volatile but is otherwise identical to the generic version, drop that as well.
This is in preparation to refactoring this code area.
Note: nop() was in processor.h and not in barrier.h as on other architectures. Nothing seems to depend on it being there though.
--- arch/sparc/include/asm/barrier_32.h | 1 - arch/sparc/include/asm/barrier_64.h | 21 ++------------------- arch/sparc/include/asm/processor.h | 3 --- 3 files changed, 2 insertions(+), 23 deletions(-)
arch/sparc/include/asm/barrier_32.h +0 -1
@@ -1,7 +1,6 @@#ifndef __SPARC_BARRIER_H#define __SPARC_BARRIER_H -#include <asm/processor.h> /* for nop() */ #include <asm-generic/barrier.h> #endif /* !(__SPARC_BARRIER_H) */
arch/sparc/include/asm/barrier_64.h +2 -19
@@ -37,25 +37,6 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \#define rmb () __asm__ __volatile__("":::"memory")#define wmb () __asm__ __volatile__("":::"memory") -#define dma_rmb () rmb() -#define dma_wmb () wmb() - -#define smp_store_mb (__var, __value) \ - do { WRITE_ONCE(__var, __value); membar_safe("#StoreLoad"); } while(0) - -#ifdef CONFIG_SMP -#define smp_mb () mb() -#define smp_rmb () rmb() -#define smp_wmb () wmb() -#else -#define smp_mb () __asm__ __volatile__("":::"memory") -#define smp_rmb () __asm__ __volatile__("":::"memory") -#define smp_wmb () __asm__ __volatile__("":::"memory") -#endif - -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -74,4 +55,6 @@ do { \#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* !(__SPARC64_BARRIER_H) */
arch/sparc/include/asm/processor.h +0 -3
@@ -5,7 +5,4 @@#else #include <asm/processor_32.h> #endif - -#define nop () __asm__ __volatile__ ("nop") -#endif
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 7/41 sparc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn sparc 64 bit dma_rmb, dma_wmb, smp_store_mb, smp_mb, smp_rmb, smp_wmb, read_barrier_depends and smp_read_barrier_depends match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
nop uses __asm__ __volatile but is otherwise identical to the generic version, drop that as well.
This is in preparation to refactoring this code area.
Note: nop() was in processor.h and not in barrier.h as on other architectures. Nothing seems to depend on it being there though.
--- arch/sparc/include/asm/barrier_32.h | 1 - arch/sparc/include/asm/barrier_64.h | 21 ++------------------- arch/sparc/include/asm/processor.h | 3 --- 3 files changed, 2 insertions(+), 23 deletions(-)
arch/sparc/include/asm/barrier_32.h +0 -1
@@ -1,7 +1,6 @@#ifndef __SPARC_BARRIER_H#define __SPARC_BARRIER_H -#include <asm/processor.h> /* for nop() */ #include <asm-generic/barrier.h> #endif /* !(__SPARC_BARRIER_H) */
arch/sparc/include/asm/barrier_64.h +2 -19
@@ -37,25 +37,6 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \#define rmb () __asm__ __volatile__("":::"memory")#define wmb () __asm__ __volatile__("":::"memory") -#define dma_rmb () rmb() -#define dma_wmb () wmb() - -#define smp_store_mb (__var, __value) \ - do { WRITE_ONCE(__var, __value); membar_safe("#StoreLoad"); } while(0) - -#ifdef CONFIG_SMP -#define smp_mb () mb() -#define smp_rmb () rmb() -#define smp_wmb () wmb() -#else -#define smp_mb () __asm__ __volatile__("":::"memory") -#define smp_rmb () __asm__ __volatile__("":::"memory") -#define smp_wmb () __asm__ __volatile__("":::"memory") -#endif - -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -74,4 +55,6 @@ do { \#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* !(__SPARC64_BARRIER_H) */
arch/sparc/include/asm/processor.h +0 -3
@@ -5,7 +5,4 @@#else #include <asm/processor_32.h> #endif - -#define nop () __asm__ __volatile__ ("nop") -#endif
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 7/41 sparc: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn sparc 64 bit dma_rmb, dma_wmb, smp_store_mb, smp_mb, smp_rmb, smp_wmb, read_barrier_depends and smp_read_barrier_depends match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
nop uses __asm__ __volatile but is otherwise identical to the generic version, drop that as well.
This is in preparation to refactoring this code area.
Note: nop() was in processor.h and not in barrier.h as on other architectures. Nothing seems to depend on it being there though.
--- arch/sparc/include/asm/barrier_32.h | 1 - arch/sparc/include/asm/barrier_64.h | 21 ++------------------- arch/sparc/include/asm/processor.h | 3 --- 3 files changed, 2 insertions(+), 23 deletions(-)
arch/sparc/include/asm/barrier_32.h +0 -1
@@ -1,7 +1,6 @@#ifndef __SPARC_BARRIER_H#define __SPARC_BARRIER_H -#include <asm/processor.h> /* for nop() */ #include <asm-generic/barrier.h> #endif /* !(__SPARC_BARRIER_H) */
arch/sparc/include/asm/barrier_64.h +2 -19
@@ -37,25 +37,6 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \#define rmb () __asm__ __volatile__("":::"memory")#define wmb () __asm__ __volatile__("":::"memory") -#define dma_rmb () rmb() -#define dma_wmb () wmb() - -#define smp_store_mb (__var, __value) \ - do { WRITE_ONCE(__var, __value); membar_safe("#StoreLoad"); } while(0) - -#ifdef CONFIG_SMP -#define smp_mb () mb() -#define smp_rmb () rmb() -#define smp_wmb () wmb() -#else -#define smp_mb () __asm__ __volatile__("":::"memory") -#define smp_rmb () __asm__ __volatile__("":::"memory") -#define smp_wmb () __asm__ __volatile__("":::"memory") -#endif - -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) -#define smp_store_release (p, v) \ do { \ compiletime_assert_atomic_type(*p); \
@@ -74,4 +55,6 @@ do { \#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* !(__SPARC64_BARRIER_H) */
arch/sparc/include/asm/processor.h +0 -3
@@ -5,7 +5,4 @@#else #include <asm/processor_32.h> #endif - -#define nop () __asm__ __volatile__ ("nop") -#endif
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 8/41 arm: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release, smp_load_acquire, smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm/include/asm/barrier.h | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
arch/arm/include/asm/barrier.h +1 -22
@@ -70,28 +70,7 @@ extern void arm_heavy_mb(void);#define smp_wmb () dmb(ishst)#endif -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) - -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* !__ASSEMBLY__ */ #endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 8/41 arm: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release, smp_load_acquire, smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm/include/asm/barrier.h | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
arch/arm/include/asm/barrier.h +1 -22
@@ -70,28 +70,7 @@ extern void arm_heavy_mb(void);#define smp_wmb () dmb(ishst)#endif -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) - -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* !__ASSEMBLY__ */ #endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 8/41 arm: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release, smp_load_acquire, smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm/include/asm/barrier.h | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
arch/arm/include/asm/barrier.h +1 -22
@@ -70,28 +70,7 @@ extern void arm_heavy_mb(void);#define smp_wmb () dmb(ishst)#endif -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) - -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* !__ASSEMBLY__ */ #endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 9/41 arm64: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm64 nop, read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm64/include/asm/barrier.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm64/include/asm/barrier.h +1 -8
@@ -91,14 +91,7 @@ do { \ __u.__val; \ }) -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define nop () asm volatile("nop"); - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* __ASSEMBLY__ */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 9/41 arm64: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm64 nop, read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm64/include/asm/barrier.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm64/include/asm/barrier.h +1 -8
@@ -91,14 +91,7 @@ do { \ __u.__val; \ }) -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define nop () asm volatile("nop"); - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* __ASSEMBLY__ */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 9/41 arm64: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn arm64 nop, read_barrier_depends, smp_read_barrier_depends smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/arm64/include/asm/barrier.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm64/include/asm/barrier.h +1 -8
@@ -91,14 +91,7 @@ do { \ __u.__val; \ }) -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define nop () asm volatile("nop"); - -#define smp_mb__before_atomic () smp_mb() -#define smp_mb__after_atomic () smp_mb() +#include <asm-generic/barrier.h> #endif /* __ASSEMBLY__ */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 10/41 metag: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn metag dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release and smp_load_acquire match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/metag/include/asm/barrier.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
arch/metag/include/asm/barrier.h +2 -23
@@ -44,9 +44,6 @@ static inline void wr_fence(void)#define rmb () barrier()#define wmb () mb() -#define dma_rmb () rmb() -#define dma_wmb () wmb() -#ifndef CONFIG_SMP #define fence () do { } while (0)#define smp_mb () barrier()
@@ -81,27 +78,9 @@ static inline void fence(void)#endif #endif -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) -#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* _ASM_METAG_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 10/41 metag: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn metag dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release and smp_load_acquire match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/metag/include/asm/barrier.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
arch/metag/include/asm/barrier.h +2 -23
@@ -44,9 +44,6 @@ static inline void wr_fence(void)#define rmb () barrier()#define wmb () mb() -#define dma_rmb () rmb() -#define dma_wmb () wmb() -#ifndef CONFIG_SMP #define fence () do { } while (0)#define smp_mb () barrier()
@@ -81,27 +78,9 @@ static inline void fence(void)#endif #endif -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) -#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* _ASM_METAG_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 10/41 metag: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn metag dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release and smp_load_acquire match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/metag/include/asm/barrier.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
arch/metag/include/asm/barrier.h +2 -23
@@ -44,9 +44,6 @@ static inline void wr_fence(void)#define rmb () barrier()#define wmb () mb() -#define dma_rmb () rmb() -#define dma_wmb () wmb() -#ifndef CONFIG_SMP #define fence () do { } while (0)#define smp_mb () barrier()
@@ -81,27 +78,9 @@ static inline void fence(void)#endif #endif -#define read_barrier_depends () do { } while (0) -#define smp_read_barrier_depends () do { } while (0) - -#define smp_store_mb (var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) - -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) -#define smp_mb__before_atomic () barrier()#define smp_mb__after_atomic () barrier() +#include <asm-generic/barrier.h> +#endif /* _ASM_METAG_BARRIER_H */
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH v3 11/41 mips: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinOn mips dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends, smp_read_barrier_depends, smp_store_release and smp_load_acquire match the asm-generic variants exactly. Drop the local definitions and pull in asm-generic/barrier.h instead.
This is in preparation to refactoring this code area.
--- arch/mips/include/asm/barrier.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
arch/mips/include/asm/barrier.h +2 -23
@@ -10,9 +10,6 @@#include <asm/addrspace.h> -#define read_barrier_depends () do { } while(0) -#define smp_read_barrier_depends () do { } while(0) -#ifdef CONFIG_CPU_HAS_SYNC #define __sync () \ __asm__ __volatile__( \
@@ -87,8 +84,6 @@#define wmb () fast_wmb()#define rmb () fast_rmb() -#define dma_wmb () fast_wmb() -#define dma_rmb () fast_rmb()#if defined(CONFIG_WEAK_ORDERING ) && defined(CONFIG_SMP )# ifdef CONFIG_CPU_CAVIUM_OCTEON
@@ -112,9 +107,6 @@#define __WEAK_LLSC_MB " \n"#endif -#define smp_store_mb (var, value) \ - do { WRITE_ONCE(var, value); smp_mb(); } while (0) -#define smp_llsc_mb () __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory")#ifdef CONFIG_CPU_CAVIUM_OCTEON
@@ -129,22 +121,9 @@#define nudge_writes () mb()#endif -#define smp_store_release (p, v) \ -do { \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - WRITE_ONCE(*p, v); \ -} while (0) - -#define smp_load_acquire (p) \ -({ \ - typeof(*p) ___p1 = READ_ONCE(*p); \ - compiletime_assert_atomic_type(*p); \ - smp_mb(); \ - ___p1; \ -}) -#define smp_mb__before_atomic () smp_mb__before_llsc()#define smp_mb__after_atomic () smp_llsc_mb() +#include <asm-generic/barrier.h> +#endif /* __ASM_BARRIER_H */
Signature · 1 line
MST
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.
This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for smp_store_release and smp_load_acquire, look into
http://patchwork.linux-mips.org/patch/10506/
- Leonid.
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 6 lines · Leonid Yegoshin
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.
Quoted 7 lines
This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look intohttp://patchwork.linux-mips.org/patch/10506/- Leonid.
Fine, but it matches what current code is doing. Since that MIPS_LIGHTWEIGHT_SYNC patch didn't go into linux-next yet, do you see a problem reworking it on top of this patchset?
Signature · 1 line
MST
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Leonid Yegoshin
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look into
Quoted 7 lines
Quoted 3 lines
http://patchwork.linux-mips.org/patch/10506/- Leonid.
Fine, but it matches what current code is doing. Since that
MIPS_LIGHTWEIGHT_SYNCpatch didn't go into linux-next yet, do you see a problem reworking it on top of this patchset?
That patch is a complete doorstop atm. It needs a lot more work before it can go anywhere. Don't worry about it.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Michael S. TsirkinQuoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Leonid Yegoshin
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look into
Quoted 7 lines
Quoted 3 lines
http://patchwork.linux-mips.org/patch/10506/- Leonid.
Fine, but it matches what current code is doing. Since that
MIPS_LIGHTWEIGHT_SYNCpatch didn't go into linux-next yet, do you see a problem reworking it on top of this patchset?
That patch is a complete doorstop atm. It needs a lot more work before it can go anywhere. Don't worry about it.
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 6 lines · Leonid Yegoshin
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.
Quoted 7 lines
This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look intohttp://patchwork.linux-mips.org/patch/10506/- Leonid.
Fine, but it matches what current code is doing. Since that MIPS_LIGHTWEIGHT_SYNC patch didn't go into linux-next yet, do you see a problem reworking it on top of this patchset?
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 6 lines · Leonid Yegoshin
Quoted 5 lines · Michael S. Tsirkin
On mips
dma_rmb,dma_wmb,smp_store_mb,read_barrier_depends,smp_read_barrier_depends,smp_store_releaseandsmp_load_acquirematch the asm-generic variants exactly. Drop the local definitions and pull inasm-generic/barrier.hinstead.
Quoted 7 lines
This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look intohttp://patchwork.linux-mips.org/patch/10506/- Leonid.
Fine, but it matches what current code is doing. Since that MIPS_LIGHTWEIGHT_SYNC patch didn't go into linux-next yet, do you see a problem reworking it on top of this patchset?
Signature · 1 line
MST
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
This statement doesn't fit MIPS barriers variations. Moreover, there is a reason to extend that even more specific, at least for
smp_store_releaseandsmp_load_acquire, look intohttp://patchwork.linux-mips.org/patch/10506/
Dude, that's one horrible patch.
1) you do not make such things selectable; either the hardware needs them or it doesn't. If it does you _must_ use them, however unlikely.
2) the changelog _completely_ fails to explain the sync 0x11 and sync 0x12 semantics nor does it provide a publicly accessible link to documentation that does.
3) it really should have explained what you did with smp_llsc_mb/smp_mb__before_llsc() in _detail_.
And I agree that ideally it should be split into parts.
Seriously, this is _NOT_ OK.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 3 lines · Peter Zijlstra
2) the changelog _completely_ fails to explain the sync
0x11and sync0x12semantics nor does it provide a publicly accessible link to documentation that does.
Ralf pointed me at: https://imgtec.com/mips/architectures/mips64/
Quoted 2 lines
3) it really should have explained what you did with smp_llsc_mb/smp_mb__before_llsc() in _detail_.
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12 are _NOT_ transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.
That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers. They need not be globally performed.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra
2) the changelog _completely_ fails to explain the sync
0x11and sync0x12semantics nor does it provide a publicly accessible link to documentation that does.Ralf pointed me at: https://imgtec.com/mips/architectures/mips64/
Quoted 2 lines
3) it really should have explained what you did with smp_llsc_mb/smp_mb__before_llsc() in _detail_.
Quoted 6 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12 are _NOT_ transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.
That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers. They need not be globally performed.
Which if true; and I know Will has some questions here; would also mean that you 'cannot' use the ACQUIRE/RELEASE barriers for your locks as was recently suggested by David Daney.
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra
2) the changelog _completely_ fails to explain the sync
0x11and sync0x12semantics nor does it provide a publicly accessible link to documentation that does.Ralf pointed me at: https://imgtec.com/mips/architectures/mips64/
Quoted 2 lines
3) it really should have explained what you did with smp_llsc_mb/smp_mb__before_llsc() in _detail_.
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12 are _NOT_ transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.
Quoted 6 lines
Quoted 2 lines
That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers. They need not be globally performed.
Which if true; and I know Will has some questions here; would also mean that you 'cannot' use the ACQUIRE/RELEASE barriers for your locks as was recently suggested by David Daney.
The issue I have with the SYNC description in the text above is that it describes the single CPU (program order) and the dual-CPU (confusingly named global order) cases, but then doesn't generalise any further. That means we can't sensibly reason about transitivity properties when a third agent is involved. For example, the WRC+sync+addr test:
P0:
Wx = 1
P1:
Rx == 1
SYNC
Wy = 1
P2:
Ry == 1
<address dep>
Rx = 0
I can't find anything to forbid that, given the text. The main problem is having the SYNC on P1 affect the write by P0.
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
I think it's much worse than RCpc, given my interpretation of the wording.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
(I try to answer on multiple mails in one)
First of all, it seems like some generic notes should be given here:
1. Generic MIPS "SYNC" (aka "SYNC 0") instruction is a very heavy in some CPUs. On that CPUs it basically kills pipelines in each CPU, can do a special memory/IO bus transaction (similar to "fence") and hold a system until all R/W is completed. It is like Big Kernel Lock but worse. So, the move to SMP_* kind of barriers is needed to improve performance, especially on newest CPUs with long pipelines.
2. MIPS Arch document may be misleading because words "ordering" and "completion" means different from Linux, the SYNC instruction description is written for HW engineers. I wrote that in a separate patch of the same patchset -
http://patchwork.linux-mips.org/patch/10505/ "MIPS: R6: Use lightweight SYNC instruction in smp_* memory barriers":
Quoted 5 lines
This instructions were specifically designed to work for smp_*() sort of memory barriers in MIPS R2/R3/R5 and R6.
Unfortunately, it's description is very cryptic and is done in HW engineering style which prevents use of it by SW.
3. I bother MIPS Arch team long time until I completely understood that MIPS SYNC_WMB, SYNC_MB, SYNC_RMB, SYNC_RELEASE and SYNC_ACQUIRE do an exactly that is required in Documentation/memory-barriers.txt
In Peter Zijlstra mail:
Quoted 2 lines
1) you do not make such things selectable; either the hardware needs them or it doesn't. If it does
you_must_use them, however unlikely.
It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
Quoted 6 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
In Will Deacon mail:
Quoted 15 lines
The issue I have with the SYNC description in the text above is that it describes the single CPU (program order) and the dual-CPU (confusingly named global order) cases, but then doesn't generalise any further. That means we can't sensibly reason about transitivity properties when a third agent is involved. For example, the WRC+sync+addr test:
P0:
Wx = 1P1:
Rx == 1
SYNC
Wy = 1
Quoted 8 lines
P2:
Ry == 1
<address dep>
Rx = 0I can't find anything to forbid that, given the text. The main problem is having the SYNC on P1 affect the write by P0.
As I understand that test, the visibility of P0: W[x] = 1 is identical to P1 and P2 here. If P1 got X before SYNC and write to Y after SYNC then instruction source register dependency tracking in P2 prevents a speculative load of X before P2 obtains Y from the same place as P0/P1 and calculate address of X. If some load of X in P2 happens before address dependency calculation it's result is discarded.
Yes, you can't find that in MIPS SYNC instruction description, it is more likely in CM (Coherence Manager) area. I just pointed our arch team member responsible for documents and he will think how to explain that.
- Leonid.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 10 lines · Leonid Yegoshin
(I try to answer on multiple mails in one)
First of all, it seems like some generic notes should be given here:
1. Generic MIPS "SYNC" (aka "SYNC 0") instruction is a very heavy in some CPUs. On that CPUs it basically kills pipelines in each CPU, can do a special memory/IO bus transaction (similar to "fence") and hold a system until all R/W is completed. It is like Big Kernel Lock but worse. So, the move to SMP_* kind of barriers is needed to improve performance, especially on newest CPUs with long pipelines.
The MIPS SYNC isn't any worse than the PPC SYNC, x86 MFENCE or arm DSB SY, yes they're heavy, so what.
Quoted 5 lines
2. MIPS Arch document may be misleading because words "ordering" and "completion" means different from Linux, the SYNC instruction description is written for HW engineers. I wrote that in a separate patch of the same patchset - http://patchwork.linux-mips.org/patch/10505/ "MIPS: R6: Use lightweight SYNC instruction in smp_* memory barriers":
Did you actually say anything here?
Quoted 9 lines
Quoted 5 lines
This instructions were specifically designed to work for smp_*() sort of memory barriers in MIPS R2/R3/R5 and R6.
Unfortunately, it's description is very cryptic and is done in HW engineering style which prevents use of it by SW.
3. I bother MIPS Arch team long time until I completely understood that MIPS
SYNC_WMB,SYNC_MB,SYNC_RMB,SYNC_RELEASEandSYNC_ACQUIREdo an exactly that is required inDocumentation/memory-barriers.txt
Ha! and you think that document covers all the really fun details?
In particular we're very much all 'confused' about the various notions of transitivity and what barriers imply how much of it.
Quoted 11 lines
In Peter Zijlstra mail:
Quoted 2 lines
1) you do not make such things selectable; either the hardware needs them or it doesn't. If it does
you_must_use them, however unlikely.It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
Quoted 8 lines
Quoted 6 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 9 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
As it stands, RCU is the only _known_ codebase where this matters, but we did in fact write code for a fair number of years 'assuming' RELEASE
+ ACQUIRE was a full barrier, so who knows what else is out there.
RCsc - release consistency sequential consistency
RCpc - release consistency processor consistency
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines
It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
It was my guess to explain - why barriers was not included originally. You can check with Ralf, he knows more about that time MIPS Linux code.
I bother with this more than 2 years and I just try to solve that issue - in recent CPUs the load after LL/SC synchronization instruction loop can get ahead of SC for sure, it was tested.
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
Peter Zijlstra recently wrote: "In particular we're very much all 'confused' about the various notions of transitivity". I am actually confused too and need some examples here.
Quoted 10 lines
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 6 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
Quoted 7 lines
Quoted 2 lines
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
MIPS Arch starting from R2 requires that. If some CPU can't, it should execute a full "SYNC 0" instead, which is a full memory barrier.
Quoted 4 lines
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
Yes, it was a goal for SYNC_ACQUIRE and SYNC_RELEASE.
Caveats:
- "Full memory barrier" on MIPS means - full barrier for any device
in coherent domain. In MIPS Tech/Imagination Tech MIPS-based CPU it is "for any device connected to CM or IOCU + directly connected memory".
- It is not applied to instruction fetch. However, I-Cache flushes
and SYNCI are consistent with that. There is also hazard barrier instructions to clear CPU pipeline to some extent - to help with this limitation.
I don't think that these caveats prevent a correct Acquire/Release semantic.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 7 lines
It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
It was my guess to explain - why barriers was not included originally. You can check with Ralf, he knows more about that time MIPS Linux code.
I bother with this more than 2 years and I just try to solve that issue - in recent CPUs the load after LL/SC synchronization instruction loop can get ahead of SC for sure, it was tested.
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
Peter Zijlstra recently wrote: "In particular we're very much all 'confused' about the various notions of transitivity". I am actually confused too and need some examples here.
Quoted 10 lines
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 6 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
Quoted 7 lines
Quoted 2 lines
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
MIPS Arch starting from R2 requires that. If some CPU can't, it should execute a full "SYNC 0" instead, which is a full memory barrier.
Quoted 4 lines
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
Yes, it was a goal for SYNC_ACQUIRE and SYNC_RELEASE.
Caveats:
- "Full memory barrier" on MIPS means - full barrier for any device
in coherent domain. In MIPS Tech/Imagination Tech MIPS-based CPU it is "for any device connected to CM or IOCU + directly connected memory".
- It is not applied to instruction fetch. However, I-Cache flushes
and SYNCI are consistent with that. There is also hazard barrier instructions to clear CPU pipeline to some extent - to help with this limitation.
I don't think that these caveats prevent a correct Acquire/Release semantic.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 7 lines
It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
It was my guess to explain - why barriers was not included originally. You can check with Ralf, he knows more about that time MIPS Linux code.
I bother with this more than 2 years and I just try to solve that issue - in recent CPUs the load after LL/SC synchronization instruction loop can get ahead of SC for sure, it was tested.
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
Peter Zijlstra recently wrote: "In particular we're very much all 'confused' about the various notions of transitivity". I am actually confused too and need some examples here.
Quoted 10 lines
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 6 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
Quoted 7 lines
Quoted 2 lines
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
MIPS Arch starting from R2 requires that. If some CPU can't, it should execute a full "SYNC 0" instead, which is a full memory barrier.
Quoted 4 lines
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
Yes, it was a goal for SYNC_ACQUIRE and SYNC_RELEASE.
Caveats:
- "Full memory barrier" on MIPS means - full barrier for any device
in coherent domain. In MIPS Tech/Imagination Tech MIPS-based CPU it is "for any device connected to CM or IOCU + directly connected memory".
- It is not applied to instruction fetch. However, I-Cache flushes
and SYNCI are consistent with that. There is also hazard barrier instructions to clear CPU pipeline to some extent - to help with this limitation.
I don't think that these caveats prevent a correct Acquire/Release semantic.
- Leonid.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 10 lines · Leonid Yegoshin
(I try to answer on multiple mails in one)
First of all, it seems like some generic notes should be given here:
1. Generic MIPS "SYNC" (aka "SYNC 0") instruction is a very heavy in some CPUs. On that CPUs it basically kills pipelines in each CPU, can do a special memory/IO bus transaction (similar to "fence") and hold a system until all R/W is completed. It is like Big Kernel Lock but worse. So, the move to SMP_* kind of barriers is needed to improve performance, especially on newest CPUs with long pipelines.
The MIPS SYNC isn't any worse than the PPC SYNC, x86 MFENCE or arm DSB SY, yes they're heavy, so what.
Quoted 5 lines
2. MIPS Arch document may be misleading because words "ordering" and "completion" means different from Linux, the SYNC instruction description is written for HW engineers. I wrote that in a separate patch of the same patchset - http://patchwork.linux-mips.org/patch/10505/ "MIPS: R6: Use lightweight SYNC instruction in smp_* memory barriers":
Did you actually say anything here?
Quoted 9 lines
Quoted 5 lines
This instructions were specifically designed to work for smp_*() sort of memory barriers in MIPS R2/R3/R5 and R6.
Unfortunately, it's description is very cryptic and is done in HW engineering style which prevents use of it by SW.
3. I bother MIPS Arch team long time until I completely understood that MIPS
SYNC_WMB,SYNC_MB,SYNC_RMB,SYNC_RELEASEandSYNC_ACQUIREdo an exactly that is required inDocumentation/memory-barriers.txt
Ha! and you think that document covers all the really fun details?
In particular we're very much all 'confused' about the various notions of transitivity and what barriers imply how much of it.
Quoted 11 lines
In Peter Zijlstra mail:
Quoted 2 lines
1) you do not make such things selectable; either the hardware needs them or it doesn't. If it does
you_must_use them, however unlikely.It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
Quoted 8 lines
Quoted 6 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 9 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
As it stands, RCU is the only _known_ codebase where this matters, but we did in fact write code for a fair number of years 'assuming' RELEASE
+ ACQUIRE was a full barrier, so who knows what else is out there.
RCsc - release consistency sequential consistency
RCpc - release consistency processor consistency
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 10 lines · Leonid Yegoshin
(I try to answer on multiple mails in one)
First of all, it seems like some generic notes should be given here:
1. Generic MIPS "SYNC" (aka "SYNC 0") instruction is a very heavy in some CPUs. On that CPUs it basically kills pipelines in each CPU, can do a special memory/IO bus transaction (similar to "fence") and hold a system until all R/W is completed. It is like Big Kernel Lock but worse. So, the move to SMP_* kind of barriers is needed to improve performance, especially on newest CPUs with long pipelines.
The MIPS SYNC isn't any worse than the PPC SYNC, x86 MFENCE or arm DSB SY, yes they're heavy, so what.
Quoted 5 lines
2. MIPS Arch document may be misleading because words "ordering" and "completion" means different from Linux, the SYNC instruction description is written for HW engineers. I wrote that in a separate patch of the same patchset - http://patchwork.linux-mips.org/patch/10505/ "MIPS: R6: Use lightweight SYNC instruction in smp_* memory barriers":
Did you actually say anything here?
Quoted 9 lines
Quoted 5 lines
This instructions were specifically designed to work for smp_*() sort of memory barriers in MIPS R2/R3/R5 and R6.
Unfortunately, it's description is very cryptic and is done in HW engineering style which prevents use of it by SW.
3. I bother MIPS Arch team long time until I completely understood that MIPS
SYNC_WMB,SYNC_MB,SYNC_RMB,SYNC_RELEASEandSYNC_ACQUIREdo an exactly that is required inDocumentation/memory-barriers.txt
Ha! and you think that document covers all the really fun details?
In particular we're very much all 'confused' about the various notions of transitivity and what barriers imply how much of it.
Quoted 11 lines
In Peter Zijlstra mail:
Quoted 2 lines
1) you do not make such things selectable; either the hardware needs them or it doesn't. If it does
you_must_use them, however unlikely.It is selectable only for MIPS R2 but not MIPS R6. The reason is - most of MIPS R2 CPUs have short pipeline and that SYNC is just waste of CPU resource, especially taking into account that "lightweight syncs" are converted to a heavy "SYNC 0" in many of that CPUs. However the latest MIPS/Imagination CPU have a pipeline long enough to hit a problem - absence of SYNC at LL/SC inside atomics, barriers etc.
What ?! Are you saying that because R2 has short pipelines its unlikely to hit the reordering issues and we can omit barriers?
Quoted 8 lines
Quoted 6 lines
And reading the MIPS64 v6.04 instruction set manual, I think 0x11/0x12
are_NOT_transitive and therefore cannot be used to implement the smp_mb__{before,after} stuff.That is, in MIPS speak, those SYNC types are Ordering Barriers, not Completion Barriers.
Please see above, point 2.
That did not in fact enlighten things. Are they transitive/multi-copy atomic or not?
(and here Will will go into great detail on the differences between the two and make our collective brains explode :-)
Quoted 9 lines
Quoted 6 lines
That is, currently all architectures -- with exception of PPC -- have RCsc locks, but using these non-transitive things will get you RCpc locks.
So yes, MIPS can go RCpc for its locks and share the burden of pain with PPC, but that needs to be a very concious decision.
I don't understand that - I tried hard but I can't find any word like "RCsc", "RCpc" in Documents/ directory. Web search goes nowhere, of course.
From: lkml.kernel.org/r/[email protected]
Yes, the difference between RCpc and RCsc is in the meaning of RELEASE + ACQUIRE. With RCsc that implies a full memory barrier, with RCpc it does not.
Currently PowerPC is the only arch that (can, and) does RCpc and gives a weaker RELEASE + ACQUIRE. Only the CPU who did the ACQUIRE is guaranteed to see the stores of the CPU which did the RELEASE in order.
As it stands, RCU is the only _known_ codebase where this matters, but we did in fact write code for a fair number of years 'assuming' RELEASE
+ ACQUIRE was a full barrier, so who knows what else is out there.
RCsc - release consistency sequential consistency
RCpc - release consistency processor consistency
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 24 lines · Leonid Yegoshin
Quoted 15 lines
The issue I have with the SYNC description in the text above is that it describes the single CPU (program order) and the dual-CPU (confusingly named global order) cases, but then doesn't generalise any further. That means we can't sensibly reason about transitivity properties when a third agent is involved. For example, the WRC+sync+addr test:
P0:
Wx = 1P1:
Rx == 1
SYNC
Wy = 1Quoted 8 lines
P2:
Ry == 1
<address dep>
Rx = 0I can't find anything to forbid that, given the text. The main problem is having the SYNC on P1 affect the write by P0.
Quoted 6 lines
As I understand that test, the visibility of P0: W[x] = 1 is identical to P1 and P2 here. If P1 got X before SYNC and write to Y after SYNC then instruction source register dependency tracking in P2 prevents a speculative load of X before P2 obtains Y from the same place as P0/P1 and calculate address of X. If some load of X in P2 happens before address dependency calculation it's result is discarded.
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1
P1:
Rx == 1
<address dep>
Wy = 1
P2:
Ry == 1
<address dep>
Rx = 0
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
Quoted 3 lines
Yes, you can't find that in MIPS SYNC instruction description, it is more likely in CM (Coherence Manager) area. I just pointed our arch team member responsible for documents and he will think how to explain that.
I tried grepping the linked documents for "coherence manager" but couldn't find anything. Is the description you refer to available anywhere?
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 20 lines · Will Deacon
Quoted 1 line · Leonid Yegoshin
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1P1:
Rx == 1
<address dep>
Wy = 1P2:
Ry == 1
<address dep>
Rx = 0
Quoted 4 lines
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (SYNC_WMB etc)? You use any barrier or do not use it and I just voice an intention to use a more efficient instruction instead of bold hummer (SYNC instruction). If you don't use any barrier here then it is a different issue.
May be it has sense to return back to original issue?
- Leonid
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
This barrier business is hard enough as it is, but magic unexplained hardware makes it impossible.
Rest assured, you (MIPS) isn't the first (nor likely the last) to go through all this. We've had these discussions (and to a certain extend are still having them) for x86, PPC, Alpha, ARM, etc..
Any every time new barriers instructions get introduced we had better have a full and comprehensive explanation to go along with them.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 8 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?
Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
The reason we (Peter and I) care about this isn't because we enjoy being obstructive. It's because there is a whole load of core (i.e. portable) kernel code that is written to the *kernel* memory model. For example, the scheduler, RCU, mutex implementations, perf, drivers, you name it.
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g. smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes. You could turn around and say "but if MIPS gets it wrong, then that's MIPS's problem", but actually not having a general understanding of the ordering guarantees provided by each architecture makes it very difficult for us to extend the kernel memory model in such a way that it can be implemented efficiently across the board *and* relied upon by core code.
The virtio patch at the start of the thread doesn't particularly concern me. It's the other patches you linked to that implement acquire/release that have me worried.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 20 lines · Will Deacon
Quoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
The reason we (Peter and I) care about this isn't because we enjoy being obstructive. It's because there is a whole load of core (i.e. portable) kernel code that is written to the *kernel* memory model. For example, the scheduler, RCU, mutex implementations, perf, drivers, you name it.
Quoted 9 lines
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes. You could turn around and say "but if MIPS gets it wrong, then that's MIPS's problem", but actually not having a general understanding of the ordering guarantees provided by each architecture makes it very difficult for us to extend the kernel memory model in such a way that it can be implemented efficiently across the board *and* relied upon by core code.
What Will said!
Yes, you can cut corners within MIPS architecture-specific code, but primitives that are used in the core kernel really do need to work as expected.
Thanx, Paul
Quoted 6 lines
The virtio patch at the start of the thread doesn't particularly concern me. It's the other patches you linked to that implement acquire/release that have me worried.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 15 lines · Paul E. McKenney
Quoted 6 lines · Will Deacon
Quoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
Quoted 9 lines
What Will said!
Yes, you can cut corners within MIPS architecture-specific code, but primitives that are used in the core kernel really do need to work as expected.
Thanx, Paul
Absolutelly! Please use SYNC - right now it is not.
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of Documentation/memory-barriers.txt
It is easy - just use smp_acquire instead of plain smp_mb insmp_load_acquire, at least for MIPS.
- Leonid.
- Leonid.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txt
That's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
There is work in progress on a specification, but please don't hold your breath. And I am not as optimistic as I might be about any formal specification keeping up with the Linux kernel or with the hardware that it supports. But it seems worth a good try.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
Please!
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
There is work in progress on a specification, but please don't hold your breath. And I am not as optimistic as I might be about any formal specification keeping up with the Linux kernel or with the hardware that it supports. But it seems worth a good try.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
Please!
Thanx, Paul
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
That is, if you'd managed to read that file at the right point in time, you might have through we'd be OK with requiring a barrier for control dependencies.
We got rid of that mistake. It was based on a flawed reading of the Alpha docs. See: 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()")
Similarly, while the document goes to great length to explain the read_barrier_depends thing, nobody actually thinks its a brilliant idea to have. Ideally we'd kill the thing the moment we drop Alpha support.
Again, memory-barriers.txt is _NOT_, I repeat, _NOT_ a hardware spec, it is not even a recommendation. It are our best effort (but flawed) scribbles of what we think is makes sense given the huge amount of actual hardware we have to run on.
As to the ACQUIRE/RELEASE semantics, ARM64 actually has multi-copy-atomic acquire/release (as does ia64, although in reality it doesn't actually have acquire/release). PPC otoh does _NOT_ have this, and is currently the only arch to suffer RCpc locks.
Now for a long long time we assumed our locks were RCsc, and we've written code assuming UNLOCK x + LOCK y was in fact a full barrier with transitiviy. Then we figured out PPC didn't actually match that. RCU is the only piece of code we _know_ relied on that, but there might be more out there...
So we document, for new code, that UNLOCK+LOCK isn't a MB, while at the same time we lobby PPC to stick a full barrier in and get rid of this stuff.
Nobody really likes RCpc locks, esp. given the history we have of assuming RCsc.
The current document allowing for RCpc is not an endorsement thereof. Ideally we'd _NOT_ have to worry about that. We can do without these head-aches.
So again, stop referring to our document as a spec. Also please don't make MIPS push the limits of weak memory models, we really can do without the pain.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
That is, if you'd managed to read that file at the right point in time, you might have through we'd be OK with requiring a barrier for control dependencies.
We got rid of that mistake. It was based on a flawed reading of the Alpha docs. See: 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()")
Similarly, while the document goes to great length to explain the read_barrier_depends thing, nobody actually thinks its a brilliant idea to have. Ideally we'd kill the thing the moment we drop Alpha support.
Again, memory-barriers.txt is _NOT_, I repeat, _NOT_ a hardware spec, it is not even a recommendation. It are our best effort (but flawed) scribbles of what we think is makes sense given the huge amount of actual hardware we have to run on.
As to the ACQUIRE/RELEASE semantics, ARM64 actually has multi-copy-atomic acquire/release (as does ia64, although in reality it doesn't actually have acquire/release). PPC otoh does _NOT_ have this, and is currently the only arch to suffer RCpc locks.
Now for a long long time we assumed our locks were RCsc, and we've written code assuming UNLOCK x + LOCK y was in fact a full barrier with transitiviy. Then we figured out PPC didn't actually match that. RCU is the only piece of code we _know_ relied on that, but there might be more out there...
So we document, for new code, that UNLOCK+LOCK isn't a MB, while at the same time we lobby PPC to stick a full barrier in and get rid of this stuff.
Nobody really likes RCpc locks, esp. given the history we have of assuming RCsc.
The current document allowing for RCpc is not an endorsement thereof. Ideally we'd _NOT_ have to worry about that. We can do without these head-aches.
So again, stop referring to our document as a spec. Also please don't make MIPS push the limits of weak memory models, we really can do without the pain.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
That is, if you'd managed to read that file at the right point in time, you might have through we'd be OK with requiring a barrier for control dependencies.
We got rid of that mistake. It was based on a flawed reading of the Alpha docs. See: 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()")
Similarly, while the document goes to great length to explain the read_barrier_depends thing, nobody actually thinks its a brilliant idea to have. Ideally we'd kill the thing the moment we drop Alpha support.
Again, memory-barriers.txt is _NOT_, I repeat, _NOT_ a hardware spec, it is not even a recommendation. It are our best effort (but flawed) scribbles of what we think is makes sense given the huge amount of actual hardware we have to run on.
As to the ACQUIRE/RELEASE semantics, ARM64 actually has multi-copy-atomic acquire/release (as does ia64, although in reality it doesn't actually have acquire/release). PPC otoh does _NOT_ have this, and is currently the only arch to suffer RCpc locks.
Now for a long long time we assumed our locks were RCsc, and we've written code assuming UNLOCK x + LOCK y was in fact a full barrier with transitiviy. Then we figured out PPC didn't actually match that. RCU is the only piece of code we _know_ relied on that, but there might be more out there...
So we document, for new code, that UNLOCK+LOCK isn't a MB, while at the same time we lobby PPC to stick a full barrier in and get rid of this stuff.
Nobody really likes RCpc locks, esp. given the history we have of assuming RCsc.
The current document allowing for RCpc is not an endorsement thereof. Ideally we'd _NOT_ have to worry about that. We can do without these head-aches.
So again, stop referring to our document as a spec. Also please don't make MIPS push the limits of weak memory models, we really can do without the pain.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for smp_acquire etc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.
If you have something else in mind, you can ask me. But I prefer to do not deviate too much from Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet smp_read_barrier_depends() and smp_rmb() should be used instead.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 33 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
Quoted 4 lines
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.
Is SYNC_ACQUIRE a memory-barrier instruction that orders prior loads against later loads and stores? If so, and if MIPS does not do ordering based on address and data dependencies, I suggest making read_barrier_depends() be a SYNC_ACQUIRE rather than SYNC_RMB.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 33 lines · Paul E. McKenney
Quoted 32 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
Quoted 6 lines
Quoted 4 lines
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.Is
SYNC_ACQUIREa memory-barrier instruction that orders prior loads against later loads and stores?
Yes, it is in MD00087 (table 6.6 of document Ver 6.04) - https://imgtec.com/?do-download=4302
Quoted 3 lines
If so, and if MIPS does not do
ordering based on address and data dependencies, I suggest makingread_barrier_depends()be aSYNC_ACQUIRErather thanSYNC_RMB.
I understood that, after I see the example of using it.
Please consider to add that into Documentation/memory-barriers.txt (it is not easy to find that this barrier is used for shared WRITE basing on shared pointer), it would be helpful.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 39 lines · Leonid Yegoshin
Quoted 37 lines · Paul E. McKenney
Quoted 36 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.
Quoted 5 lines
Quoted 2 lines
Is
SYNC_ACQUIREa memory-barrier instruction that orders prior loads against later loads and stores?Yes, it is in MD00087 (table 6.6 of document Ver 6.04) -
https://imgtec.com/?do-download=4302
OK, it does look like it should work. Of course, if you can rely on straight address/data dependencies, that would be even better.
Quoted 8 lines
Quoted 3 lines
If so, and if MIPS does not do
ordering based on address and data dependencies, I suggest makingread_barrier_depends()be aSYNC_ACQUIRErather thanSYNC_RMB.I understood that, after I see the example of using it. Please consider to add that into
Documentation/memory-barriers.txt(it is not easy to find that this barrier is used for shared WRITE basing on shared pointer), it would be helpful.
Actually, the Linux kernel doesn't have an acquire barrier, just an smp_load_acquire(). Or did someone sneak one in while I wasn't looking? ;-)
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 1 line · Paul E. McKenney
Actually, the Linux kernel doesn't have an acquire barrier, just an
smp_load_acquire(). Or did someone sneak one in while I wasn't looking?
That was an exactly starting point for this discussion. This patch just pulls out from MIPS files smp_load_acquire() and smp_store_release(). However, I put into LMO half year ago the patch http://patchwork.linux-mips.org/patch/10506/ which replaces a generic smp_mb with MIPS specific smp_release/acquire in that functions. This patch also fixes use of SYNCs barriers in spin_locks/atomics/bitops for Imagination MIPS CPUs too - it is just absent now for any Imagination MIPS CPUs!
Michael later pointed me that it can be returned back with his series of patches but discussion was already here.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 1 line · Paul E. McKenney
Actually, the Linux kernel doesn't have an acquire barrier, just an
smp_load_acquire(). Or did someone sneak one in while I wasn't looking?
That was an exactly starting point for this discussion. This patch just pulls out from MIPS files smp_load_acquire() and smp_store_release(). However, I put into LMO half year ago the patch http://patchwork.linux-mips.org/patch/10506/ which replaces a generic smp_mb with MIPS specific smp_release/acquire in that functions. This patch also fixes use of SYNCs barriers in spin_locks/atomics/bitops for Imagination MIPS CPUs too - it is just absent now for any Imagination MIPS CPUs!
Michael later pointed me that it can be returned back with his series of patches but discussion was already here.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 39 lines · Leonid Yegoshin
Quoted 37 lines · Paul E. McKenney
Quoted 36 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.
Quoted 5 lines
Quoted 2 lines
Is
SYNC_ACQUIREa memory-barrier instruction that orders prior loads against later loads and stores?Yes, it is in MD00087 (table 6.6 of document Ver 6.04) -
https://imgtec.com/?do-download=4302
OK, it does look like it should work. Of course, if you can rely on straight address/data dependencies, that would be even better.
Quoted 8 lines
Quoted 3 lines
If so, and if MIPS does not do
ordering based on address and data dependencies, I suggest makingread_barrier_depends()be aSYNC_ACQUIRErather thanSYNC_RMB.I understood that, after I see the example of using it. Please consider to add that into
Documentation/memory-barriers.txt(it is not easy to find that this barrier is used for shared WRITE basing on shared pointer), it would be helpful.
Actually, the Linux kernel doesn't have an acquire barrier, just an smp_load_acquire(). Or did someone sneak one in while I wasn't looking? ;-)
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 33 lines · Paul E. McKenney
Quoted 32 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
Quoted 6 lines
Quoted 4 lines
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.Is
SYNC_ACQUIREa memory-barrier instruction that orders prior loads against later loads and stores?
Yes, it is in MD00087 (table 6.6 of document Ver 6.04) - https://imgtec.com/?do-download=4302
Quoted 3 lines
If so, and if MIPS does not do
ordering based on address and data dependencies, I suggest makingread_barrier_depends()be aSYNC_ACQUIRErather thanSYNC_RMB.
I understood that, after I see the example of using it.
Please consider to add that into Documentation/memory-barriers.txt (it is not easy to find that this barrier is used for shared WRITE basing on shared pointer), it would be helpful.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 33 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
Quoted 4 lines
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.
Is SYNC_ACQUIRE a memory-barrier instruction that orders prior loads against later loads and stores? If so, and if MIPS does not do ordering based on address and data dependencies, I suggest making read_barrier_depends() be a SYNC_ACQUIRE rather than SYNC_RMB.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 33 lines · Leonid Yegoshin
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for
smp_acquireetc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.If you have something else in mind, you can ask me. But I prefer to do not deviate too much from
Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
Quoted 4 lines
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet
smp_read_barrier_depends()andsmp_rmb()should be used instead.
Is SYNC_ACQUIRE a memory-barrier instruction that orders prior loads against later loads and stores? If so, and if MIPS does not do ordering based on address and data dependencies, I suggest making read_barrier_depends() be a SYNC_ACQUIRE rather than SYNC_RMB.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Quoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txtThat's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
Quoted 8 lines
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
I am afraid I can't help you here. It is very complicated stuff and a model is actually doesn't fit your assumptions about CPUs well without some simplifications which are based on what you want to have.
I say that SYNC_ACQUIRE/etc follows what you expect for smp_acquire etc (basing on that document). And at least two CPU models were tested with my patches (see it in LMO) for that last year and that instructions are implemented now in engineering kernel.
If you have something else in mind, you can ask me. But I prefer to do not deviate too much from Documentation/memory-barriers.txt, for exam - if it asks to have memory barrier somewhere, then I assume the code should have it, and please - don't ask me a test which violates the current version of document recommendations.
For a moment I don't see a significant changes in this document for MIPS Arch at least 1.5 year, and the only significant point is that MIPS CPU Arch doesn't have yet smp_read_barrier_depends() and smp_rmb() should be used instead.
- Leonid.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txt
That's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 3 lines · Leonid Yegoshin
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of
Documentation/memory-barriers.txt
That's madness. That document changes from version to version as to what we _think_ the actual hardware does. It is _NOT_ a specification.
You cannot design hardware from that. Its incomplete and fails to specify a bunch of things. It not a mathematically sound definition of a memory model.
Please stop referring to that document for what a particular barrier _should_ do. Explain what MIPS does, so we can attempt to integrate this knowledge with our knowledge of PPC/ARM/Alpha/x86/etc. and improve upon our understanding of hardware and improve the Linux memory model.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 15 lines · Paul E. McKenney
Quoted 6 lines · Will Deacon
Quoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
Quoted 9 lines
What Will said!
Yes, you can cut corners within MIPS architecture-specific code, but primitives that are used in the core kernel really do need to work as expected.
Thanx, Paul
Absolutelly! Please use SYNC - right now it is not.
An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of Documentation/memory-barriers.txt
It is easy - just use smp_acquire instead of plain smp_mb insmp_load_acquire, at least for MIPS.
- Leonid.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 20 lines · Will Deacon
Quoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
The reason we (Peter and I) care about this isn't because we enjoy being obstructive. It's because there is a whole load of core (i.e. portable) kernel code that is written to the *kernel* memory model. For example, the scheduler, RCU, mutex implementations, perf, drivers, you name it.
Quoted 9 lines
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes. You could turn around and say "but if MIPS gets it wrong, then that's MIPS's problem", but actually not having a general understanding of the ordering guarantees provided by each architecture makes it very difficult for us to extend the kernel memory model in such a way that it can be implemented efficiently across the board *and* relied upon by core code.
What Will said!
Yes, you can cut corners within MIPS architecture-specific code, but primitives that are used in the core kernel really do need to work as expected.
Thanx, Paul
Quoted 6 lines
The virtio patch at the start of the thread doesn't particularly concern me. It's the other patches you linked to that implement acquire/release that have me worried.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 1 line · Will Deacon
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes.
It seems you don't listen me. I said multiple times - MIPS implementation of SYNC_RMB/SYNC_WMB/SYNC_MB/SYNC_ACQUIRE/SYNC_RELEASE instructions matches the description of smp_rmb/smp_wmb/smp_mb/sync_acquire/sync_release from Documentation/memory-barriers.txt file.
What else do you want from me - RTL or microArch design for that?
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 7 lines · Leonid Yegoshin
Quoted 5 lines · Will Deacon
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes.
Quoted 8 lines
It seems you don't listen me. I said multiple times - MIPS implementation of SYNC_RMB/SYNC_WMB/SYNC_MB/SYNC_ACQUIRE/SYNC_RELEASE instructions matches the description of smp_rmb/smp_wmb/smp_mb/sync_acquire/sync_release from
Documentation/memory-barriers.txtfile.What else do you want from me - RTL or microArch design for that?
I suspect that it is more likely that we are talking past each other. This stuff is subtle and although we have better ways of talking about it than (say) ten years ago, it is subtle. Two ways of talking about it are herd and ppcmem.
The overview of ppcmem (AKA armmem and cppmem) is here:
https://www.cl.cam.ac.uk/~pes20/ppcmem/help.html
The intro to herd is here: http://arxiv.org/pdf/1308.6810v5.pdf
It may be downloaded here: http://diy.inria.fr/herd/
As a very rough rule of thumb, herd is faster and easier to use and ppcmem is more precise.
So SYNC_RMB is intended to implement smp_rmb(), correct?
You could use SYNC_ACQUIRE() to implement read_barrier_depends() and smp_read_barrier_depends(), but SYNC_RMB probably does not suffice. The reason for this is that smp_read_barrier_depends() must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:
p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */
In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Again, if your hardware maintains local ordering for address and data dependencies, you can have read_barrier_depends() and smp_read_barrier_depends() be no-ops like they are for most architectures.
Does that help?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?
Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.
If smp_read_barrier_depends() is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famous Documentation/memory-barriers.txt and had no chance to know what you use it in this way too.
Quoted 3 lines
The reason for this is that
smp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer.
I can't see that requirement anywhere in Documents directory. I mean - the words "write through a dereference of that pointer" or similar for smp_read_barrier_depends.
Quoted 16 lines
For example: p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Quoted 4 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example smp_read_barrier_depends() but in discussion it comes out that it may not. Because without smp_read_barrier_depends() your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.
Well, Documentation/memory-barriers.txt was intended as a guide for Linux kernel hackers, and not for hardware architects. The need for something more precise has become clear over the past year or two, and I am working on it with some heavy-duty memory-model folks. But all previous memory models have been for a specific CPU architecture, so doing one for the intersection of several is offering up some complications. I therefore cannot yet provide a completion date.
That said, I still suggest use of SYNC_ACQUIRE for read_barrier_depends().
Quoted 7 lines
Quoted 3 lines
The reason for this is that
smp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer.I can't see that requirement anywhere in Documents directory. I mean
- the words "write through a dereference of that pointer" or similar forsmp_read_barrier_depends.
No worries, I will add one. Please see the end of this message for an initial patch.
Please understand that Documentation/memory-barriers.txt is a living document:
v4.4: Two changes
v4.3: Three changes
v4.2: Six changes
v4.1: Three changes
v4.0: Two changes
It tends to change as we locate corner cases either in hardware or in software use cases/APIs.
Quoted 21 lines
Quoted 16 lines
For example:
p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Quoted 4 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
Quoted 8 lines
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example
smp_read_barrier_depends()but in discussion it comes out that it may not. Because withoutsmp_read_barrier_depends()your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
As noted in another email in this thread, I do not believe that WRC+addr+addr needs to be prohibited. Sounds like Will and I need to get our story straight, though.
Will?
Thanx, Paul
------------------------------------------------------------------------
commit 955720966e216b00613fcf60188d507c103f0e80
Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800
documentation: Subsequent writes ordered by rcu_dereference()
The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare, but when it happens, we need that write -not- to be clobbered by the initialization. This commit therefore adds an example showing a data dependency ordering a later data-dependent write.
Documentation/memory-barriers.txt +24 -0
@@ -555,6 +555,30 @@ between the address load and the data load: This enforces the occurrence of one of the two implications, and prevents the third possibility from arising. +A data-dependency barrier must also order against dependent writes: + + CPU 1 CPU 2 + =============== =============== + { A == 1, B == 2, C = 3, P == &A, Q == &C } + B = 4; + <write barrier> + WRITE_ONCE(P, &B); + Q = READ_ONCE(P); + <data dependency barrier> + *Q = 5; + +The data-dependency barrier must order the read into Q with the store +into *Q. This prohibits this outcome: + + (Q == B) && (B == 4) + +Please note that this pattern should be rare. After all, the whole point +of dependency ordering is to -prevent- writes to the data structure, along +with the expensive cache misses associated with those writes. This pattern +can be used to record rare error conditions and the like, and the ordering +prevents such records from being lost. + + [!] Note that this extremely counterintuitive situation arises most easily on machines with split caches, so that, for example, one cache bank processes even-numbered cache lines and the other bank processes odd-numbered cache
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Paul,
Quoted 10 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example
smp_read_barrier_depends()but in discussion it comes out that it may not. Because withoutsmp_read_barrier_depends()your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
Quoted 3 lines
As noted in another email in this thread, I do not believe that WRC+addr+addr needs to be prohibited. Sounds like Will and I need to get our story straight, though.
I think you figured this out while I was sleeping, but just to confirm:
1. The MIPS64 ISA doc [1] talks about SYNC in a way that applies only to memory accesses appearing in *program-order* before the SYNC
2. We need WRC+sync+addr to work, which means that the SYNC in P1 must also capture the store in P0 as being "before" the barrier. Leonid reckons it works, but his explanation [2] focussed on the address dependency in P2 as to why this works. If that is the case (i.e. address dependency provides global transitivity), then WRC+addr+addr should also work (even though its not required).
3. It seems that WRC+addr+addr doesn't work, so I'm still suspicious about WRC+sync+addr, because neither the architecture document or Leonid's explanation tell me that it should be forbidden.
Will
[1] https://imgtec.com/?do-download=4302
[2] http://lkml.kernel.org/r/[email protected] (scroll to the end)
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 8 lines · Will Deacon
Paul,
I think you figured this out while I was sleeping, but just to confirm:
1. The MIPS64 ISA doc [1] talks about SYNC in a way that applies only to memory accesses appearing in *program-order* before the SYNC
Quoted 6 lines
2. We need WRC+sync+addr to work, which means that the SYNC in P1 must also capture the store in P0 as being "before" the barrier. Leonid reckons it works, but his explanation [2] focussed on the address dependency in P2 as to why this works. If that is the case (i.e. address dependency provides global transitivity), then WRC+addr+addr should also work (even though its not required).
No, it is not correct. There is one old design which provides access to core (thread0 + thread1) write-buffers for threads load in advance of it is visible to other cores. It means, that WRC+sync+addr passes because of SYNC in write thread and register dependency inside other thread but WRC+addr+addr may fail because other core may get a stale data.
Quoted 9 lines
3. It seems that WRC+addr+addr doesn't work, so I'm still suspicious about WRC+sync+addr, because neither the architecture document or Leonid's explanation tell me that it should be forbidden.
Will
[1] https://imgtec.com/?do-download=4302
[2] http://lkml.kernel.org/r/[email protected] (scroll to the end)
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 8 lines · Will Deacon
Paul,
I think you figured this out while I was sleeping, but just to confirm:
1. The MIPS64 ISA doc [1] talks about SYNC in a way that applies only to memory accesses appearing in *program-order* before the SYNC
Quoted 6 lines
2. We need WRC+sync+addr to work, which means that the SYNC in P1 must also capture the store in P0 as being "before" the barrier. Leonid reckons it works, but his explanation [2] focussed on the address dependency in P2 as to why this works. If that is the case (i.e. address dependency provides global transitivity), then WRC+addr+addr should also work (even though its not required).
No, it is not correct. There is one old design which provides access to core (thread0 + thread1) write-buffers for threads load in advance of it is visible to other cores. It means, that WRC+sync+addr passes because of SYNC in write thread and register dependency inside other thread but WRC+addr+addr may fail because other core may get a stale data.
Quoted 9 lines
3. It seems that WRC+addr+addr doesn't work, so I'm still suspicious about WRC+sync+addr, because neither the architecture document or Leonid's explanation tell me that it should be forbidden.
Will
[1] https://imgtec.com/?do-download=4302
[2] http://lkml.kernel.org/r/[email protected] (scroll to the end)
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyPaul,
Quoted 10 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example
smp_read_barrier_depends()but in discussion it comes out that it may not. Because withoutsmp_read_barrier_depends()your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
Quoted 3 lines
As noted in another email in this thread, I do not believe that WRC+addr+addr needs to be prohibited. Sounds like Will and I need to get our story straight, though.
I think you figured this out while I was sleeping, but just to confirm:
1. The MIPS64 ISA doc [1] talks about SYNC in a way that applies only to memory accesses appearing in *program-order* before the SYNC
2. We need WRC+sync+addr to work, which means that the SYNC in P1 must also capture the store in P0 as being "before" the barrier. Leonid reckons it works, but his explanation [2] focussed on the address dependency in P2 as to why this works. If that is the case (i.e. address dependency provides global transitivity), then WRC+addr+addr should also work (even though its not required).
3. It seems that WRC+addr+addr doesn't work, so I'm still suspicious about WRC+sync+addr, because neither the architecture document or Leonid's explanation tell me that it should be forbidden.
Will
[1] https://imgtec.com/?do-download=4302
[2] http://lkml.kernel.org/r/[email protected] (scroll to the end)
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 9 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.
Quoted 8 lines
Quoted 5 lines
If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.Well,
Documentation/memory-barriers.txtwas intended as a guide for Linux kernel hackers, and not for hardware architects.
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Quoted 10 lines
------------------------------------------------------------------------
commit
955720966e216b00613fcf60188d507c103f0e80Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800documentation: Subsequent writes ordered by
rcu_dereference()The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare,
How are these rare? Isn't:
rcu_read_lock() obj = rcu_dereference(ptr); if (!atomic_inc_not_zero(&obj->ref)) obj = NULL; rcu_read_unlock();
a _very_ common thing to do?
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Documentation/memory-barriers.txt +17 -0
@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================
@@ -5,6 +6,22 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware. + +===== +INDEX +===== + Contents: (*) Abstract memory access model.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 22 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/memory-barriers.txt +1
-0@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================@@ -5,6 +6,22 @@ By: David Howells <[email protected]>
Documentation/memory-barriers.txt line 16
Quoted 10 lines
Documentation/memory-barriers.txt +8
-0Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask.
It might be worth adding you and me to the top of the file, to save Paul Cc'ing us on questions (get_maintainer.pl points at poor old Corbet for this file).
But yes, it seems that something like this is required.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 7 lines · Will Deacon
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
Seems likely to me. ;-)
Quoted 30 lines
Quoted 15 lines
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/memory-barriers.txt +1
-0@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================@@ -5,6 +6,22 @@ By: David Howells <[email protected]>Documentation/memory-barriers.txt line 16
Quoted 10 lines
Documentation/memory-barriers.txt +8
-0Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask.It might be worth adding you and me to the top of the file, to save Paul Cc'ing us on questions (get_maintainer.pl points at poor old Corbet for this file).
Quoted 1 line
But yes, it seems that something like this is required.
So Peter, would you like to update your patch to include yourself and Will as authors?
Thanx, Paul
Peter Zijlstra
maintainerPATCH 1/1 documentation: Add disclaimer
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimer
It appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Documentation/memory-barriers.txt +17 -1
@@ -4,8 +4,24 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> + Will Deacon <[email protected]> + Peter Zijlstra <[email protected]> -Contents: +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware. + +======== +CONTENTS +======== (*) Abstract memory access model.
Re: [PATCH] documentation: Add disclaimer
Quoted 25 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimerIt appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
Quoted 4 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Will
Re: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraQuoted 25 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimerIt appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
Quoted 4 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Will
Re: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraQuoted 25 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimerIt appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
Quoted 4 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Will
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraDocumentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.
The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
Re: [PATCH] documentation: Add disclaimer
Quoted 25 lines · David Howells
Documentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Quoted 13 lines
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Quoted 5 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
Good point! Would you be willing to add a Signed-off-by so I can take the combined change, assuming Peter and Will are good with it?
Thanx, Paul
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
Quoted 3 lines · Paul E. McKenney
Good point! Would you be willing to add a Signed-off-by so I can take the combined change, assuming Peter and Will are good with it?
Sure!
David
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
In reply to Paul E. McKenneyQuoted 3 lines · Paul E. McKenney
Good point! Would you be willing to add a Signed-off-by so I can take the combined change, assuming Peter and Will are good with it?
Sure!
David
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
In reply to Paul E. McKenneyQuoted 3 lines · Paul E. McKenney
Good point! Would you be willing to add a Signed-off-by so I can take the combined change, assuming Peter and Will are good with it?
Sure!
David
Re: [PATCH] documentation: Add disclaimer
In reply to David HowellsQuoted 25 lines · David Howells
Documentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Quoted 13 lines
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Quoted 5 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
Good point! Would you be willing to add a Signed-off-by so I can take the combined change, assuming Peter and Will are good with it?
Thanx, Paul
Re: [PATCH] documentation: Add disclaimer
In reply to David HowellsQuoted 25 lines · David Howells
Documentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Quoted 7 lines
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Done as part of your patch. Again, apologies for the delay.
Thanx, Paul
Quoted 9 lines
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH] documentation: Add disclaimer
In reply to David HowellsQuoted 25 lines · David Howells
Documentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Quoted 7 lines
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Done as part of your patch. Again, apologies for the delay.
Thanx, Paul
Quoted 9 lines
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
Re: [PATCH] documentation: Add disclaimer
In reply to David HowellsQuoted 25 lines · David Howells
Documentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Quoted 7 lines
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Done as part of your patch. Again, apologies for the delay.
Thanx, Paul
Quoted 9 lines
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraDocumentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.
The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
David Howells
maintainerRe: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraDocumentation/memory-barriers.txt line 20
Quoted 11 lines · Peter Zijlstra
+==========
Documentation/memory-barriers.txt +10
-0+DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware.
The purpose of this document is twofold:
(1) to specify the minimum functionality that one can rely on for any particular barrier, and
(2) to provide a guide as to how to use the barriers that are available.
Note that an architecture can provide more than the minimum requirement for any particular barrier, but if the barrier provides less than that, it is incorrect.
Note also that it is possible that a barrier may be a no-op for an architecture because the way that arch works renders an explicit barrier unnecessary in that case.
Quoted 1 line
+
Can you bung an extra blank line in here if you have to redo this at all?
Quoted 6 lines
+========
+CONTENTS
+========(*) Abstract memory access model.
David
Re: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraQuoted 20 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimerIt appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Quoted 6 lines
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Rather belatedly queued and pushed to -rcu, apologies for the delay. One minor edit noted below.
Thanx, Paul
Quoted 16 lines
--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)Documentation/memory-barriers.txt +2
-1@@ -4,8 +4,24 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> + Will Deacon <[email protected]> + Peter Zijlstra <[email protected]> -Contents:
Documentation/memory-barriers.txt line 19
Quoted 10 lines
Documentation/memory-barriers.txt +10
-0+========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from
s/I/To/ because there is more than one author.
Quoted 9 lines
Documentation/memory-barriers.txt +5
-0+hardware. + +======== +CONTENTS +======== (*) Abstract memory access model.
Re: [PATCH] documentation: Add disclaimer
In reply to Peter ZijlstraQuoted 20 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimerIt appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Quoted 6 lines
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Rather belatedly queued and pushed to -rcu, apologies for the delay. One minor edit noted below.
Thanx, Paul
Quoted 16 lines
--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)Documentation/memory-barriers.txt +2
-1@@ -4,8 +4,24 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> + Will Deacon <[email protected]> + Peter Zijlstra <[email protected]> -Contents:
Documentation/memory-barriers.txt line 19
Quoted 10 lines
Documentation/memory-barriers.txt +10
-0+========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from
s/I/To/ because there is more than one author.
Documentation/memory-barriers.txt
Quoted 9 lines
Documentation/memory-barriers.txt +5
-0+hardware. + +======== +CONTENTS +======== (*) Abstract memory access model.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Peter Zijlstra
maintainerPATCH 1/1 documentation: Add disclaimer
In reply to Paul E. McKenneyQuoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimer
It appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Documentation/memory-barriers.txt +17 -1
@@ -4,8 +4,24 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> + Will Deacon <[email protected]> + Peter Zijlstra <[email protected]> -Contents: +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware. + +======== +CONTENTS +======== (*) Abstract memory access model.
Peter Zijlstra
maintainerPATCH 1/1 documentation: Add disclaimer
In reply to Paul E. McKenneyQuoted 2 lines · Paul E. McKenney
So Peter, would you like to update your patch to include yourself and Will as authors?
Sure, here goes.
---
Subject: documentation: Add disclaimer
It appears people are reading this document as a requirements list for building hardware. This is not the intent of this document. Nor is it particularly suited for this purpose.
The primary purpose of this document is our collective attempt to define a set of primitives that (hopefully) allow us to write correct code on the myriad of SMP platforms Linux supports.
Its a definite work in progress as our understanding of these platforms, and memory ordering in general, progresses.
Nor does being mentioned in this document mean we think its a particularly good idea; the data dependency barrier required by Alpha being a prime example. Yes we have it, no you're insane to require it when building new hardware.
--- Documentation/memory-barriers.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Documentation/memory-barriers.txt +17 -1
@@ -4,8 +4,24 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> + Will Deacon <[email protected]> + Peter Zijlstra <[email protected]> -Contents: +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware. + +======== +CONTENTS +======== (*) Abstract memory access model.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 7 lines · Will Deacon
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
Seems likely to me. ;-)
Quoted 30 lines
Quoted 15 lines
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/memory-barriers.txt +1
-0@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================@@ -5,6 +6,22 @@ By: David Howells <[email protected]>Documentation/memory-barriers.txt line 16
Quoted 10 lines
Documentation/memory-barriers.txt +8
-0Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask.It might be worth adding you and me to the top of the file, to save Paul Cc'ing us on questions (get_maintainer.pl points at poor old Corbet for this file).
Quoted 1 line
But yes, it seems that something like this is required.
So Peter, would you like to update your patch to include yourself and Will as authors?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 22 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/memory-barriers.txt +1
-0@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================@@ -5,6 +6,22 @@ By: David Howells <[email protected]>
Documentation/memory-barriers.txt line 16
Quoted 10 lines
Documentation/memory-barriers.txt +8
-0Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask.
It might be worth adding you and me to the top of the file, to save Paul Cc'ing us on questions (get_maintainer.pl points at poor old Corbet for this file).
But yes, it seems that something like this is required.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 22 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/memory-barriers.txt +1
-0@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================@@ -5,6 +6,22 @@ By: David Howells <[email protected]>
Documentation/memory-barriers.txt line 16
Quoted 10 lines
Documentation/memory-barriers.txt +8
-0Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask.
It might be worth adding you and me to the top of the file, to save Paul Cc'ing us on questions (get_maintainer.pl points at poor old Corbet for this file).
But yes, it seems that something like this is required.
Will
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Do we want this ?
--- Documentation/memory-barriers.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Documentation/memory-barriers.txt +17 -0
@@ -1,3 +1,4 @@ + ============================ LINUX KERNEL MEMORY BARRIERS ============================
@@ -5,6 +6,22 @@ By: David Howells <[email protected]> Paul E. McKenney <[email protected]> +========== +DISCLAIMER +========== + +This document is not a specification; it is intentionally (for the sake of +brevity) and unintentionally (due to being human) incomplete. This document is +meant as a guide to using the various memory barriers provided by Linux, but +in case of any doubt (and there are many) please ask. + +I repeat, this document is not a specification of what Linux expects from +hardware. + +===== +INDEX +===== + Contents: (*) Abstract memory access model.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 35 lines · Peter Zijlstra
Quoted 9 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.Quoted 8 lines
Quoted 5 lines
If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.Well,
Documentation/memory-barriers.txtwas intended as a guide for Linux kernel hackers, and not for hardware architects.Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Quoted 10 lines
------------------------------------------------------------------------
commit
955720966e216b00613fcf60188d507c103f0e80Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800documentation: Subsequent writes ordered by
rcu_dereference()The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare,
How are these rare? Isn't:
Quoted 7 lines
rcu_read_lock() obj = rcu_dereference(ptr); if (!atomic_inc_not_zero(&obj->ref)) obj = NULL; rcu_read_unlock();a _very_ common thing to do?
It is, but it provides its own barriers, so does not need to rely on dependency ordering.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 35 lines · Peter Zijlstra
Quoted 9 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.Quoted 8 lines
Quoted 5 lines
If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.Well,
Documentation/memory-barriers.txtwas intended as a guide for Linux kernel hackers, and not for hardware architects.Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Quoted 10 lines
------------------------------------------------------------------------
commit
955720966e216b00613fcf60188d507c103f0e80Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800documentation: Subsequent writes ordered by
rcu_dereference()The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare,
How are these rare? Isn't:
Quoted 7 lines
rcu_read_lock() obj = rcu_dereference(ptr); if (!atomic_inc_not_zero(&obj->ref)) obj = NULL; rcu_read_unlock();a _very_ common thing to do?
It is, but it provides its own barriers, so does not need to rely on dependency ordering.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 35 lines · Peter Zijlstra
Quoted 9 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.Quoted 8 lines
Quoted 5 lines
If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.Well,
Documentation/memory-barriers.txtwas intended as a guide for Linux kernel hackers, and not for hardware architects.Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Quoted 10 lines
------------------------------------------------------------------------
commit
955720966e216b00613fcf60188d507c103f0e80Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800documentation: Subsequent writes ordered by
rcu_dereference()The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare,
How are these rare? Isn't:
Quoted 7 lines
rcu_read_lock() obj = rcu_dereference(ptr); if (!atomic_inc_not_zero(&obj->ref)) obj = NULL; rcu_read_unlock();a _very_ common thing to do?
It is, but it provides its own barriers, so does not need to rely on dependency ordering.
Thanx, Paul
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 9 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.
Quoted 8 lines
Quoted 5 lines
If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.Well,
Documentation/memory-barriers.txtwas intended as a guide for Linux kernel hackers, and not for hardware architects.
Yeah, this goes under the header: memory-barriers.txt is _NOT_ a specification (I seem to keep repeating this).
Quoted 10 lines
------------------------------------------------------------------------
commit
955720966e216b00613fcf60188d507c103f0e80Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800documentation: Subsequent writes ordered by
rcu_dereference()The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare,
How are these rare? Isn't:
rcu_read_lock() obj = rcu_dereference(ptr); if (!atomic_inc_not_zero(&obj->ref)) obj = NULL; rcu_read_unlock();
a _very_ common thing to do?
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.
Well, Documentation/memory-barriers.txt was intended as a guide for Linux kernel hackers, and not for hardware architects. The need for something more precise has become clear over the past year or two, and I am working on it with some heavy-duty memory-model folks. But all previous memory models have been for a specific CPU architecture, so doing one for the intersection of several is offering up some complications. I therefore cannot yet provide a completion date.
That said, I still suggest use of SYNC_ACQUIRE for read_barrier_depends().
Quoted 7 lines
Quoted 3 lines
The reason for this is that
smp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer.I can't see that requirement anywhere in Documents directory. I mean
- the words "write through a dereference of that pointer" or similar forsmp_read_barrier_depends.
No worries, I will add one. Please see the end of this message for an initial patch.
Please understand that Documentation/memory-barriers.txt is a living document:
v4.4: Two changes
v4.3: Three changes
v4.2: Six changes
v4.1: Three changes
v4.0: Two changes
It tends to change as we locate corner cases either in hardware or in software use cases/APIs.
Quoted 21 lines
Quoted 16 lines
For example:
p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Quoted 4 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
Quoted 8 lines
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example
smp_read_barrier_depends()but in discussion it comes out that it may not. Because withoutsmp_read_barrier_depends()your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
As noted in another email in this thread, I do not believe that WRC+addr+addr needs to be prohibited. Sounds like Will and I need to get our story straight, though.
Will?
Thanx, Paul
------------------------------------------------------------------------
commit 955720966e216b00613fcf60188d507c103f0e80
Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800
documentation: Subsequent writes ordered by rcu_dereference()
The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare, but when it happens, we need that write -not- to be clobbered by the initialization. This commit therefore adds an example showing a data dependency ordering a later data-dependent write.
Documentation/memory-barriers.txt +24 -0
@@ -555,6 +555,30 @@ between the address load and the data load: This enforces the occurrence of one of the two implications, and prevents the third possibility from arising. +A data-dependency barrier must also order against dependent writes: + + CPU 1 CPU 2 + =============== =============== + { A == 1, B == 2, C = 3, P == &A, Q == &C } + B = 4; + <write barrier> + WRITE_ONCE(P, &B); + Q = READ_ONCE(P); + <data dependency barrier> + *Q = 5; + +The data-dependency barrier must order the read into Q with the store +into *Q. This prohibits this outcome: + + (Q == B) && (B == 4) + +Please note that this pattern should be rare. After all, the whole point +of dependency ordering is to -prevent- writes to the data structure, along +with the expensive cache misses associated with those writes. This pattern +can be used to record rare error conditions and the like, and the ordering +prevents such records from being lost. + + [!] Note that this extremely counterintuitive situation arises most easily on machines with split caches, so that, for example, one cache bank processes even-numbered cache lines and the other bank processes odd-numbered cache
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?Yes.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.If
smp_read_barrier_depends()is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famousDocumentation/memory-barriers.txtand had no chance to know what you use it in this way too.
Well, Documentation/memory-barriers.txt was intended as a guide for Linux kernel hackers, and not for hardware architects. The need for something more precise has become clear over the past year or two, and I am working on it with some heavy-duty memory-model folks. But all previous memory models have been for a specific CPU architecture, so doing one for the intersection of several is offering up some complications. I therefore cannot yet provide a completion date.
That said, I still suggest use of SYNC_ACQUIRE for read_barrier_depends().
Quoted 7 lines
Quoted 3 lines
The reason for this is that
smp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer.I can't see that requirement anywhere in Documents directory. I mean
- the words "write through a dereference of that pointer" or similar forsmp_read_barrier_depends.
No worries, I will add one. Please see the end of this message for an initial patch.
Please understand that Documentation/memory-barriers.txt is a living document:
v4.4: Two changes
v4.3: Three changes
v4.2: Six changes
v4.1: Three changes
v4.0: Two changes
It tends to change as we locate corner cases either in hardware or in software use cases/APIs.
Quoted 21 lines
Quoted 16 lines
For example:
p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Quoted 4 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
Quoted 8 lines
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example
smp_read_barrier_depends()but in discussion it comes out that it may not. Because withoutsmp_read_barrier_depends()your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
As noted in another email in this thread, I do not believe that WRC+addr+addr needs to be prohibited. Sounds like Will and I need to get our story straight, though.
Will?
Thanx, Paul
------------------------------------------------------------------------
commit 955720966e216b00613fcf60188d507c103f0e80
Author: Paul E. McKenney <[email protected]> Date: Thu Jan 14 14:17:04 2016 -0800
documentation: Subsequent writes ordered by rcu_dereference()
The current memory-barriers.txt does not address the possibility of a write to a dereferenced pointer. This should be rare, but when it happens, we need that write -not- to be clobbered by the initialization. This commit therefore adds an example showing a data dependency ordering a later data-dependent write.
Documentation/memory-barriers.txt +24 -0
@@ -555,6 +555,30 @@ between the address load and the data load: This enforces the occurrence of one of the two implications, and prevents the third possibility from arising. +A data-dependency barrier must also order against dependent writes: + + CPU 1 CPU 2 + =============== =============== + { A == 1, B == 2, C = 3, P == &A, Q == &C } + B = 4; + <write barrier> + WRITE_ONCE(P, &B); + Q = READ_ONCE(P); + <data dependency barrier> + *Q = 5; + +The data-dependency barrier must order the read into Q with the store +into *Q. This prohibits this outcome: + + (Q == B) && (B == 4) + +Please note that this pattern should be rare. After all, the whole point +of dependency ordering is to -prevent- writes to the data structure, along +with the expensive cache misses associated with those writes. This pattern +can be used to record rare error conditions and the like, and the ordering +prevents such records from being lost. + + [!] Note that this extremely counterintuitive situation arises most easily on machines with split caches, so that, for example, one cache bank processes even-numbered cache lines and the other bank processes odd-numbered cache
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 2 lines · Paul E. McKenney
So
SYNC_RMBis intended to implementsmp_rmb(), correct?
Yes.
Quoted 3 lines
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice.
If smp_read_barrier_depends() is used to separate not only two reads but read pointer and WRITE basing on that pointer (example below) - yes. I just doesn't see any example of this in famous Documentation/memory-barriers.txt and had no chance to know what you use it in this way too.
Quoted 3 lines
The reason for this is that
smp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer.
I can't see that requirement anywhere in Documents directory. I mean - the words "write through a dereference of that pointer" or similar for smp_read_barrier_depends.
Quoted 16 lines
For example: p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Quoted 4 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
It is not so simple, I mean "local ordering for address and data dependencies". Local ordering is NOT enough. It happens that current MIPS R6 doesn't require in your example smp_read_barrier_depends() but in discussion it comes out that it may not. Because without smp_read_barrier_depends() your example can be a part of Will's WRC+addr+addr and we found some design which easily can bump into this test. And that design actually performs "local ordering for address and data dependencies" too.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 21 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Quoted 6 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Does that help?
This is crazy! smp_rmb started out being strictly stronger than smp_read_barrier_depends, when did this stop being the case?
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for smp_read_barrier_depends(), especially in its rcu_dereference*() form, is smp_load_acquire().
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Hi Paul,
Quoted 33 lines · Paul E. McKenney
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?
Quoted 9 lines
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for
smp_read_barrier_depends(), especially in its rcu_dereference*() form, issmp_load_acquire().
Confused..
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for read->write with data dependency is unnecessary:
http://article.gmane.org/gmane.linux.kernel/2077661
And in an earlier mail of that thread, Linus made his point that smp_read_barrier_depends() should only be used to order read->read.
So right now, are we going to extend the semantics of smp_read_barrier_depends()? Can we just make smp_read_barrier_depends() still only work for read->read, and assume all the architectures won't reorder read->write with data dependency, so that the code above having a smp_rmb() also works?
Regards,
Boqun
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Boqun Feng
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for
read->writewith data dependency is unnecessary:
Quoted 8 lines
And in an earlier mail of that thread, Linus made his point that
smp_read_barrier_depends()should only be used to orderread->read.So right now, are we going to extend the semantics of
smp_read_barrier_depends()? Can we just makesmp_read_barrier_depends()still only work forread->read, and assume all the architectures won't reorderread->writewith data dependency, so that the code above having asmp_rmb()also works?
That discussions was about control dependencies. So writes that _depend_ on a prior read having an explicit value.
So something like:
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends() if (x->val == 5) x->bar = 5;
In that case, the load of x->val must be complete and its value determined _before_ the store to x->bar can happen.
This is distinct from:
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;
And its the second case where smp_read_barrier_depends() read->write order matters.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr);
smp_read_barrier_depends();
x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
It's called "smp_READ_barrier_depends()" for a reason.
Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.
So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy smp_read_barrier_depends(). But it's the only reason.
This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:
? u determines the execution of v, the location accessed by v, or
the value written by v.
? u determines the execution or address or value of another
memory access z that precedes
v or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).
Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
So no, "smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.
So if you _ever_ see a "smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);
because a "rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 7 lines
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;
Or am I missing your point?
Quoted 39 lines
It's called "
smp_READ_barrier_depends()" for a reason.Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called
smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy
smp_read_barrier_depends(). But it's the only reason.This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:• u determines the execution of v, the location accessed by v, or
the value written by v.
• u determines the execution or address or value of another
memory access z that precedesv or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the
READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
Quoted 5 lines
So no, "
smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.So if you _ever_ see a "
smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
And the smp_read_barrier_depends() in both rcu_dereference() and in lockless_dereference() is ordering the read-to-read case and the underlying hardware is ordering the read-to-write case on weakly ordered hardware.
Or, again, am I missing your point?
Thanx, Paul
Quoted 11 lines
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);because a "
rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 16 lines · Paul E. McKenney
Quoted 8 lines · Linus Torvalds
Quoted 4 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Quoted 6 lines
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;Or am I missing your point?
You are entirely missing the point.
You might as well just write it as
struct foo x = READ_ONCE(*ptr);
x->bar = 5;because that "smp_read_barrier_depends()" does NOTHING wrt the second write.
So what I am saying is simple: anybody who writes that "smp_read_barrier_depends()" in there is just ttoally and completely WRONG, and the fact that Peter wrote it out after I removed several instances of that bloody f*cking idiocy is disturbing.
Don't do it. It's BS. It's wrong. Don't make excuses for it.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 7 lines · Linus Torvalds
You might as well just write it as
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.
Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
So if anybody believes that the "smp_read_barrier_depends()" does something, they are *wrong*.
And if anybody sends out an email with that smp_read_barrier_depends() in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.
So stop perpetuating the myth that smp_read_barrier_depends() does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.
I had to remove this crap once from the kernel already, see commit 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()").
I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
but I sincerely hope that we'll never find that kind of broken architecture.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no smp_read_barrier_depends() needed. That said, I believe that we should encourage rcu_dereference*() or lockless_dereference() instead of READ_ONCE() for documentation reasons, though.
Quoted 5 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.
The other problem with smp_read_barrier_depends() is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() and lockless_dereference().
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.
It looks like I should add words to memory-barriers.txt de-emphasizing smp_read_barrier_depends(). I will take a look at that.
Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
Agreed. We can worry about whether or not we replace the current smp_read_barrier_depends() with that new barrier when and if such hardware appears.
Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Paul E. McKenney
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.
I agree that that is likely the right thing to do in pretty much all situations.
In theory, there might be performance situations where we'd want to actively avoid the smp_read_barrier_depends() inherent in those, but considering that it's only a performance issue on alpha, and we probably have all of two or three people using Linux on alpha, it's a pretty theoretical performance worry.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 8 lines · Linus Torvalds
Quoted 5 lines · Paul E. McKenney
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.
Quoted 7 lines
I agree that that is likely the right thing to do in pretty much all situations.
In theory, there might be performance situations where we'd want to actively avoid the
smp_read_barrier_depends()inherent in those, but considering that it's only a performance issue on alpha, and we probably have all of two or three people using Linux on alpha, it's a pretty theoretical performance worry.
Agreed!
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
Quoted 5 lines · Paul E. McKenney
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.
Quoted 7 lines
I agree that that is likely the right thing to do in pretty much all situations.
In theory, there might be performance situations where we'd want to actively avoid the
smp_read_barrier_depends()inherent in those, but considering that it's only a performance issue on alpha, and we probably have all of two or three people using Linux on alpha, it's a pretty theoretical performance worry.
Agreed!
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 5 lines · Paul E. McKenney
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.
I agree that that is likely the right thing to do in pretty much all situations.
In theory, there might be performance situations where we'd want to actively avoid the smp_read_barrier_depends() inherent in those, but considering that it's only a performance issue on alpha, and we probably have all of two or three people using Linux on alpha, it's a pretty theoretical performance worry.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 5 lines · Paul E. McKenney
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.
I agree that that is likely the right thing to do in pretty much all situations.
In theory, there might be performance situations where we'd want to actively avoid the smp_read_barrier_depends() inherent in those, but considering that it's only a performance issue on alpha, and we probably have all of two or three people using Linux on alpha, it's a pretty theoretical performance worry.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().
Because semantically speaking, rcu_derefence*() and lockless_dereference() are CONSUME(i.e. data/address dependent read->read and read->write pairs are ordered), whereas smp_read_barrier_depends() only guarantees read->read pairs with data dependency are ordered, right?
If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +2 -2
@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load. This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, for
Regards,
Boqun
Quoted 49 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 44 lines · Boqun Feng
Quoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().Because semantically speaking, rcu_derefence*() and
lockless_dereference()are CONSUME(i.e. data/address dependentread->readandread->writepairs are ordered), whereassmp_read_barrier_depends()only guaranteesread->readpairs with data dependency are ordered, right?If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +0
-0
Documentation/memory-barriers.txt There are some more advanced barrier functions: · line 1707
Quoted 7 lines
Documentation/memory-barriers.txt +2
-2@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load.
This is a good start, but more is needed to warn people off of smp_read_barrier_depends(). But yes, better explanation would be good.
Thanx, Paul
Quoted 56 lines
Documentation/memory-barriers.txt +0
-0This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, forRegards,
BoqunQuoted 49 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Boqun FengQuoted 44 lines · Boqun Feng
Quoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().Because semantically speaking, rcu_derefence*() and
lockless_dereference()are CONSUME(i.e. data/address dependentread->readandread->writepairs are ordered), whereassmp_read_barrier_depends()only guaranteesread->readpairs with data dependency are ordered, right?If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +0
-0
Documentation/memory-barriers.txt There are some more advanced barrier functions: · line 1707
Quoted 7 lines
Documentation/memory-barriers.txt +2
-2@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load.
This is a good start, but more is needed to warn people off of smp_read_barrier_depends(). But yes, better explanation would be good.
Thanx, Paul
Quoted 56 lines
Documentation/memory-barriers.txt +0
-0This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, forRegards,
BoqunQuoted 49 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Boqun FengQuoted 44 lines · Boqun Feng
Quoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().Because semantically speaking, rcu_derefence*() and
lockless_dereference()are CONSUME(i.e. data/address dependentread->readandread->writepairs are ordered), whereassmp_read_barrier_depends()only guaranteesread->readpairs with data dependency are ordered, right?If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +0
-0
Documentation/memory-barriers.txt There are some more advanced barrier functions: · line 1707
Quoted 7 lines
Documentation/memory-barriers.txt +2
-2@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load.
This is a good start, but more is needed to warn people off of smp_read_barrier_depends(). But yes, better explanation would be good.
Thanx, Paul
Quoted 56 lines
Documentation/memory-barriers.txt +0
-0This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, forRegards,
BoqunQuoted 49 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().
Because semantically speaking, rcu_derefence*() and lockless_dereference() are CONSUME(i.e. data/address dependent read->read and read->write pairs are ordered), whereas smp_read_barrier_depends() only guarantees read->read pairs with data dependency are ordered, right?
If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +2 -2
@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load. This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, for
Regards,
Boqun
Quoted 40 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
Quoted 9 lines
;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 22 lines · Paul E. McKenney
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no
smp_read_barrier_depends()needed. That said, I believe that we should encourage rcu_dereference*() orlockless_dereference()instead ofREAD_ONCE()for documentation reasons, though.Quoted 3 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
Quoted 7 lines
Quoted 2 lines
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.The other problem with
smp_read_barrier_depends()is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() andlockless_dereference().
Because semantically speaking, rcu_derefence*() and lockless_dereference() are CONSUME(i.e. data/address dependent read->read and read->write pairs are ordered), whereas smp_read_barrier_depends() only guarantees read->read pairs with data dependency are ordered, right?
If so, maybe we need to call it out in memory-barriers.txt, for example:
Documentation/memory-barriers.txt +2 -2
@@ -1703,8 +1703,8 @@ There are some more advanced barrier functions: (*) lockless_dereference(); - This can be thought of as a pointer-fetch wrapper around the - smp_read_barrier_depends() data-dependency barrier. + This is a load, and any load or store that has a data dependency on the + value returned by this load won't be reordered before this load. This is also similar to rcu_dereference(), but in cases where object lifetime is handled by some mechanism other than RCU, for
Regards,
Boqun
Quoted 40 lines
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.It looks like I should add words to memory-barriers.txt de-emphasizing
smp_read_barrier_depends(). I will take a look at that.Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.Agreed. We can worry about whether or not we replace the current
smp_read_barrier_depends()with that new barrier when and if such hardware appears.Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
Quoted 9 lines
;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 5 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds
You might as well just write it as
Quoted 7 lines
Quoted 4 lines
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
No trailing data-dependent read, so agreed, no smp_read_barrier_depends() needed. That said, I believe that we should encourage rcu_dereference*() or lockless_dereference() instead of READ_ONCE() for documentation reasons, though.
Quoted 5 lines
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
So if anybody believes that the "
smp_read_barrier_depends()" does something, they are *wrong*.
The other problem with smp_read_barrier_depends() is that it is often a pain figuring out which prior load it is supposed to apply to. Hence my preference for rcu_dereference*() and lockless_dereference().
Quoted 7 lines
And if anybody sends out an email with that
smp_read_barrier_depends()in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.So stop perpetuating the myth that
smp_read_barrier_depends()does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.
It looks like I should add words to memory-barriers.txt de-emphasizing smp_read_barrier_depends(). I will take a look at that.
Quoted 7 lines
I had to remove this crap once from the kernel already, see commit
105ff3cbf225("atomic: remove all traces ofREAD_ONCE_CTRL()and atomic*_read_ctrl()").I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
Well, if it makes you feel better, that was control dependencies and this was data dependencies. So it was not -exactly- the same. ;-)
(Sorry, couldn't resist...)
Quoted 7 lines
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
Agreed. We can worry about whether or not we replace the current smp_read_barrier_depends() with that new barrier when and if such hardware appears.
Quoted 3 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
;-) ;-) ;-)
Quoted 1 line
but I sincerely hope that we'll never find that kind of broken architecture.
Apparently at least some hardware vendors are reading memory-barriers.txt, so perhaps the odds of that kind of breakage have reduced.
Thanx, Paul
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
Quoted 5 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.but I sincerely hope that we'll never find that kind of broken architecture.
So for a moment it looked like MIPS wanted to equal or surpass Alpha in this respect.
And Paul made the point that smp_read_barrier_depends() really should be smp_aquire_barrier_depends() in that we rely on both dependent reads and writes to be ordered against the initial pointer load.
Now, as you've made abundantly clear, Alpha does this, although it needs the little extra help in the dependent read department.
The 'problem' is that someone seemed to have used our Documentation/memory-barriers.txt as a specification for what hardware is permitted and we require. And in that light Paul noted that read_barrier_depends really should be considered an acquire_barrier_depends and order both dependent reads and writes against the (prior) read (if nothing else already does).
Now clearly, any sane architecture doesn't need anything like this, but again our document doesn't seem to judge. That is, from reading the document one can get the impression is a perfectly fine thing to do. Nowhere does our disdain for this thing show.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 3 lines · Peter Zijlstra
So for a moment it looked like MIPS wanted to equal or surpass Alpha in this respect.
If there is an architecture that I'd expect to try to take the "sucks more" crown, MIPS would be it. They've already done the "worst cache award" thing, and are proud members of the "stupid branch delay slot" crowd. MIPS historically even did the "delayed load slot".
The only mistake they've never done, AFAIK, is to have a rotating register file.
At the same time, the "load-to-dependent-store" thing you really have to *work* at doing wrong. It's not enough to just have bad taste and incompetent architects. You really have to spend real effort to screw up that badly. It's really hard to do by mistake.
So I suspect that even MIPS can't get it wrong.
Linus
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 3 lines · Peter Zijlstra
So for a moment it looked like MIPS wanted to equal or surpass Alpha in this respect.
If there is an architecture that I'd expect to try to take the "sucks more" crown, MIPS would be it. They've already done the "worst cache award" thing, and are proud members of the "stupid branch delay slot" crowd. MIPS historically even did the "delayed load slot".
The only mistake they've never done, AFAIK, is to have a rotating register file.
At the same time, the "load-to-dependent-store" thing you really have to *work* at doing wrong. It's not enough to just have bad taste and incompetent architects. You really have to spend real effort to screw up that badly. It's really hard to do by mistake.
So I suspect that even MIPS can't get it wrong.
Linus
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
Quoted 5 lines
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.but I sincerely hope that we'll never find that kind of broken architecture.
So for a moment it looked like MIPS wanted to equal or surpass Alpha in this respect.
And Paul made the point that smp_read_barrier_depends() really should be smp_aquire_barrier_depends() in that we rely on both dependent reads and writes to be ordered against the initial pointer load.
Now, as you've made abundantly clear, Alpha does this, although it needs the little extra help in the dependent read department.
The 'problem' is that someone seemed to have used our Documentation/memory-barriers.txt as a specification for what hardware is permitted and we require. And in that light Paul noted that read_barrier_depends really should be considered an acquire_barrier_depends and order both dependent reads and writes against the (prior) read (if nothing else already does).
Now clearly, any sane architecture doesn't need anything like this, but again our document doesn't seem to judge. That is, from reading the document one can get the impression is a perfectly fine thing to do. Nowhere does our disdain for this thing show.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds
You might as well just write it as
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.
Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
So if anybody believes that the "smp_read_barrier_depends()" does something, they are *wrong*.
And if anybody sends out an email with that smp_read_barrier_depends() in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.
So stop perpetuating the myth that smp_read_barrier_depends() does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.
I had to remove this crap once from the kernel already, see commit 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()").
I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
but I sincerely hope that we'll never find that kind of broken architecture.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds
You might as well just write it as
struct foo x = READ_ONCE(*ptr); x->bar = 5;because that "
smp_read_barrier_depends()" does NOTHING wrt the second write.
Just to clarify: on alpha it adds a memory barrier, but that memory barrier is useless.
On non-alpha, it is a no-op, and obviously does nothing simply because it generates no code.
So if anybody believes that the "smp_read_barrier_depends()" does something, they are *wrong*.
And if anybody sends out an email with that smp_read_barrier_depends() in an example, they are actively just confusing other people, which is even worse than just being wrong. Which is why I jumped in.
So stop perpetuating the myth that smp_read_barrier_depends() does something here. It does not. It's a bug, and it has become this "mind virus" for some people that seem to believe that it does something.
I had to remove this crap once from the kernel already, see commit 105ff3cbf225 ("atomic: remove all traces of READ_ONCE_CTRL() and atomic*_read_ctrl()").
I don't want to ever see that broken construct again. And I want to make sure that everybody is educated about how broken it was. I'm extremely unhappy that it came up again.
If it turns out that some architecture does actually need a barrier between a read and a dependent write, then that will mean that
(a) we'll have to make up a _new_ barrier, because
"smp_read_barrier_depends()" is not that barrier. We'll presumably then have to make that new barrier part of "rcu_derefence()" and friends.
(b) we will have found an architecture with even worse memory
ordering semantics than alpha, and we'll have to stop castigating alpha for being the worst memory ordering ever.
but I sincerely hope that we'll never find that kind of broken architecture.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 16 lines · Paul E. McKenney
Quoted 8 lines · Linus Torvalds
Quoted 4 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Quoted 6 lines
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;Or am I missing your point?
You are entirely missing the point.
You might as well just write it as
struct foo x = READ_ONCE(*ptr);
x->bar = 5;because that "smp_read_barrier_depends()" does NOTHING wrt the second write.
So what I am saying is simple: anybody who writes that "smp_read_barrier_depends()" in there is just ttoally and completely WRONG, and the fact that Peter wrote it out after I removed several instances of that bloody f*cking idiocy is disturbing.
Don't do it. It's BS. It's wrong. Don't make excuses for it.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 16 lines · Paul E. McKenney
Quoted 8 lines · Linus Torvalds
Quoted 4 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Quoted 6 lines
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;Or am I missing your point?
You are entirely missing the point.
You might as well just write it as
struct foo x = READ_ONCE(*ptr);
x->bar = 5;because that "smp_read_barrier_depends()" does NOTHING wrt the second write.
So what I am saying is simple: anybody who writes that "smp_read_barrier_depends()" in there is just ttoally and completely WRONG, and the fact that Peter wrote it out after I removed several instances of that bloody f*cking idiocy is disturbing.
Don't do it. It's BS. It's wrong. Don't make excuses for it.
Linus
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 6 lines · Linus Torvalds
Quoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 7 lines
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;
Or am I missing your point?
Quoted 39 lines
It's called "
smp_READ_barrier_depends()" for a reason.Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called
smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy
smp_read_barrier_depends(). But it's the only reason.This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:• u determines the execution of v, the location accessed by v, or
the value written by v.
• u determines the execution or address or value of another
memory access z that precedesv or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the
READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
Quoted 5 lines
So no, "
smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.So if you _ever_ see a "
smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
And the smp_read_barrier_depends() in both rcu_dereference() and in lockless_dereference() is ordering the read-to-read case and the underlying hardware is ordering the read-to-write case on weakly ordered hardware.
Or, again, am I missing your point?
Thanx, Paul
Quoted 11 lines
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);because a "
rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.Linus
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Linus TorvaldsQuoted 6 lines · Linus Torvalds
Quoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 7 lines
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
If I understand your objection correctly, you want the above pattern expressed either like this:
struct foo *x = rcu_dereference(*ptr); x->bar = 5;
Or like this:
struct foo *x = lockless_dereference(*ptr); x->bar = 5;
Or am I missing your point?
Quoted 39 lines
It's called "
smp_READ_barrier_depends()" for a reason.Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called
smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy
smp_read_barrier_depends(). But it's the only reason.This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:• u determines the execution of v, the location accessed by v, or
the value written by v.
• u determines the execution or address or value of another
memory access z that precedesv or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the
READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
Quoted 5 lines
So no, "
smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.So if you _ever_ see a "
smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
And the smp_read_barrier_depends() in both rcu_dereference() and in lockless_dereference() is ordering the read-to-read case and the underlying hardware is ordering the read-to-write case on weakly ordered hardware.
Or, again, am I missing your point?
Thanx, Paul
Quoted 11 lines
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);because a "
rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.Linus
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr);
smp_read_barrier_depends();
x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
It's called "smp_READ_barrier_depends()" for a reason.
Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.
So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy smp_read_barrier_depends(). But it's the only reason.
This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:
• u determines the execution of v, the location accessed by v, or
the value written by v.
• u determines the execution or address or value of another
memory access z that precedes
v or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).
Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
So no, "smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.
So if you _ever_ see a "smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);
because a "rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.
Linus
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 2 lines · Peter Zijlstra
This is distinct from:
That may be distinct, but:
Quoted 3 lines
struct foo *x = READ_ONCE(*ptr);
smp_read_barrier_depends();
x->bar = 5;This case is complete BS. Stop perpetuating it. I already removed a number of bogus cases of it, and I removed the incorrect documentation that had this crap.
It's called "smp_READ_barrier_depends()" for a reason.
Alpha is the only one that needs it, and alpha needs it only for dependent READS.
It's not called smp_read_write_barrier_depends(). It's not called "smp_mb_depends()". It's a weaker form of "smp_rmb()", nothing else.
So alpha does have an implied dependency chain from a read to a subsequent dependent write, and does not need any extra barriers.
Alpha does *not* have a dependency chain from a read to a subsequent read, which is why we need that horrible crappy smp_read_barrier_depends(). But it's the only reason.
This is the alpha reference manual wrt read-to-write dependency:
5.6.1.7 Definition of Dependence Constraint
The depends relation (DP) is defined as follows. Given u and v
issued by processor Pi, where u
is a read or an instruction fetch and v is a write, u precedes v
in DP order (written u DP v, that
is, v depends on u) in either of the following situations:
• u determines the execution of v, the location accessed by v, or
the value written by v.
• u determines the execution or address or value of another
memory access z that precedes
v or might precede v (that is, would precede v in some execution
path depending
on the value read by u) by processor issue constraint (see Section 5.6.1.3).
Note that the dependence barrier honors not only control flow, but address and data values too. This is a different syntax than we use, but 'u' is the READ_ONCE, and 'v' is the write. Any data, address or conditional dependency between the two implies an ordering.
So no, "smp_read_barrier_depends()" is *ONLY* about two reads, where the second read is data-dependent on the first. Nothing else.
So if you _ever_ see a "smp_read_barrier_depends()" that isn't about a barrier between two reads, then that is a bug.
The above code is crap. It's exactly as much crap as
a = READ_ONCE(x); smp_rmb(); WRITE_ONCE(b, y);
because a "rmb()" simply doesn't have anything to do with read-vs-subsequent-write ordering.
Linus
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Boqun FengQuoted 5 lines · Boqun Feng
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for
read->writewith data dependency is unnecessary:
Quoted 8 lines
And in an earlier mail of that thread, Linus made his point that
smp_read_barrier_depends()should only be used to orderread->read.So right now, are we going to extend the semantics of
smp_read_barrier_depends()? Can we just makesmp_read_barrier_depends()still only work forread->read, and assume all the architectures won't reorderread->writewith data dependency, so that the code above having asmp_rmb()also works?
That discussions was about control dependencies. So writes that _depend_ on a prior read having an explicit value.
So something like:
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends() if (x->val == 5) x->bar = 5;
In that case, the load of x->val must be complete and its value determined _before_ the store to x->bar can happen.
This is distinct from:
struct foo *x = READ_ONCE(*ptr); smp_read_barrier_depends(); x->bar = 5;
And its the second case where smp_read_barrier_depends() read->write order matters.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Boqun FengQuoted 47 lines · Boqun Feng
Hi Paul,
Quoted 33 lines · Paul E. McKenney
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?Quoted 8 lines
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for
smp_read_barrier_depends(), especially in its rcu_dereference*() form, issmp_load_acquire().Confused..
Quoted 7 lines
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for
read->writewith data dependency is unnecessary:http://article.gmane.org/gmane.linux.kernel/2077661
And in an earlier mail of that thread, Linus made his point that
smp_read_barrier_depends()should only be used to orderread->read.
Those examples involved read-to-write with conditionals, as in:
if (READ_ONCE(a)) WRITE_ONCE(b, 1);
Without the "if", no ordering is guaranteed on weakly ordered CPUs. (The volatile accesses keep ordering within the compiler for once...
Quoted 5 lines
So right now, are we going to extend the semantics of
smp_read_barrier_depends()? Can we just makesmp_read_barrier_depends()still only work forread->read, and assume all the architectures won't reorderread->writewith data dependency, so that the code above having asmp_rmb()also works?
The semantics of smp_read_barrier_depends() has been both read-to-write and read-to-read for some time now, this patch just catches the documentation up with reality.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Boqun FengQuoted 47 lines · Boqun Feng
Hi Paul,
Quoted 33 lines · Paul E. McKenney
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?Quoted 8 lines
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for
smp_read_barrier_depends(), especially in its rcu_dereference*() form, issmp_load_acquire().Confused..
Quoted 7 lines
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for
read->writewith data dependency is unnecessary:http://article.gmane.org/gmane.linux.kernel/2077661
And in an earlier mail of that thread, Linus made his point that
smp_read_barrier_depends()should only be used to orderread->read.
Those examples involved read-to-write with conditionals, as in:
if (READ_ONCE(a)) WRITE_ONCE(b, 1);
Without the "if", no ordering is guaranteed on weakly ordered CPUs. (The volatile accesses keep ordering within the compiler for once...
Quoted 5 lines
So right now, are we going to extend the semantics of
smp_read_barrier_depends()? Can we just makesmp_read_barrier_depends()still only work forread->read, and assume all the architectures won't reorderread->writewith data dependency, so that the code above having asmp_rmb()also works?
The semantics of smp_read_barrier_depends() has been both read-to-write and read-to-read for some time now, this patch just catches the documentation up with reality.
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyHi Paul,
Quoted 33 lines · Paul E. McKenney
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?
Quoted 9 lines
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for
smp_read_barrier_depends(), especially in its rcu_dereference*() form, issmp_load_acquire().
Confused..
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for read->write with data dependency is unnecessary:
http://article.gmane.org/gmane.linux.kernel/2077661
And in an earlier mail of that thread, Linus made his point that smp_read_barrier_depends() should only be used to order read->read.
So right now, are we going to extend the semantics of smp_read_barrier_depends()? Can we just make smp_read_barrier_depends() still only work for read->read, and assume all the architectures won't reorder read->write with data dependency, so that the code above having a smp_rmb() also works?
Regards,
Boqun
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyHi Paul,
Quoted 33 lines · Paul E. McKenney
Quoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?
Quoted 9 lines
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for
smp_read_barrier_depends(), especially in its rcu_dereference*() form, issmp_load_acquire().
Confused..
I recall that last time you and Linus came into a conclusion that even on Alpha, a barrier for read->write with data dependency is unnecessary:
http://article.gmane.org/gmane.linux.kernel/2077661
And in an earlier mail of that thread, Linus made his point that smp_read_barrier_depends() should only be used to order read->read.
So right now, are we going to extend the semantics of smp_read_barrier_depends()? Can we just make smp_read_barrier_depends() still only work for read->read, and assume all the architectures won't reorder read->write with data dependency, so that the code above having a smp_rmb() also works?
Regards,
Boqun
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Herbert XuQuoted 27 lines · Herbert Xu
Quoted 26 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.
Quoted 4 lines
Quoted 1 line
Does that help?
This is crazy!
smp_rmbstarted out being strictly stronger thansmp_read_barrier_depends, when did this stop being the case?
Hello, Herbert!
It is true that most Linux kernel code relies only on the read-read properties of dependencies, but the read-write properties are useful. Admittedly relatively rarely, but useful.
The better comparison for smp_read_barrier_depends(), especially in its rcu_dereference*() form, is smp_load_acquire().
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 21 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Quoted 6 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Does that help?
This is crazy! smp_rmb started out being strictly stronger than smp_read_barrier_depends, when did this stop being the case?
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 21 lines · Paul E. McKenney
You could use
SYNC_ACQUIRE()to implementread_barrier_depends()andsmp_read_barrier_depends(), butSYNC_RMBprobably does not suffice. The reason for this is thatsmp_read_barrier_depends()must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Quoted 6 lines
Again, if your hardware maintains local ordering for address and data dependencies, you can have
read_barrier_depends()andsmp_read_barrier_depends()be no-ops like they are for most architectures.Does that help?
This is crazy! smp_rmb started out being strictly stronger than smp_read_barrier_depends, when did this stop being the case?
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 7 lines · Leonid Yegoshin
Quoted 5 lines · Will Deacon
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes.
Quoted 8 lines
It seems you don't listen me. I said multiple times - MIPS implementation of SYNC_RMB/SYNC_WMB/SYNC_MB/SYNC_ACQUIRE/SYNC_RELEASE instructions matches the description of smp_rmb/smp_wmb/smp_mb/sync_acquire/sync_release from
Documentation/memory-barriers.txtfile.What else do you want from me - RTL or microArch design for that?
I suspect that it is more likely that we are talking past each other. This stuff is subtle and although we have better ways of talking about it than (say) ten years ago, it is subtle. Two ways of talking about it are herd and ppcmem.
The overview of ppcmem (AKA armmem and cppmem) is here:
https://www.cl.cam.ac.uk/~pes20/ppcmem/help.html
The intro to herd is here: http://arxiv.org/pdf/1308.6810v5.pdf
It may be downloaded here: http://diy.inria.fr/herd/
As a very rough rule of thumb, herd is faster and easier to use and ppcmem is more precise.
So SYNC_RMB is intended to implement smp_rmb(), correct?
You could use SYNC_ACQUIRE() to implement read_barrier_depends() and smp_read_barrier_depends(), but SYNC_RMB probably does not suffice. The reason for this is that smp_read_barrier_depends() must order the pointer load against any subsequent read or write through a dereference of that pointer. For example:
p = READ_ONCE(gp); smp_rmb(); r1 = p->a; /* ordered by smp_rmb(). */ p->b = 42; /* NOT ordered by smp_rmb(), BUG!!! */ r2 = x; /* ordered by smp_rmb(), but doesn't need to be. */
In contrast:
p = READ_ONCE(gp); smp_read_barrier_depends(); r1 = p->a; /* ordered by smp_read_barrier_depends(). */ p->b = 42; /* ordered by smp_read_barrier_depends(). */ r2 = x; /* not ordered by smp_read_barrier_depends(), which is OK. */
Again, if your hardware maintains local ordering for address and data dependencies, you can have read_barrier_depends() and smp_read_barrier_depends() be no-ops like they are for most architectures.
Does that help?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 1 line · Will Deacon
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes.
It seems you don't listen me. I said multiple times - MIPS implementation of SYNC_RMB/SYNC_WMB/SYNC_MB/SYNC_ACQUIRE/SYNC_RELEASE instructions matches the description of smp_rmb/smp_wmb/smp_mb/sync_acquire/sync_release from Documentation/memory-barriers.txt file.
What else do you want from me - RTL or microArch design for that?
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 1 line · Will Deacon
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g.
smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes.
It seems you don't listen me. I said multiple times - MIPS implementation of SYNC_RMB/SYNC_WMB/SYNC_MB/SYNC_ACQUIRE/SYNC_RELEASE instructions matches the description of smp_rmb/smp_wmb/smp_mb/sync_acquire/sync_release from Documentation/memory-barriers.txt file.
What else do you want from me - RTL or microArch design for that?
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?
Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
The reason we (Peter and I) care about this isn't because we enjoy being obstructive. It's because there is a whole load of core (i.e. portable) kernel code that is written to the *kernel* memory model. For example, the scheduler, RCU, mutex implementations, perf, drivers, you name it.
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g. smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes. You could turn around and say "but if MIPS gets it wrong, then that's MIPS's problem", but actually not having a general understanding of the ordering guarantees provided by each architecture makes it very difficult for us to extend the kernel memory model in such a way that it can be implemented efficiently across the board *and* relied upon by core code.
The virtio patch at the start of the thread doesn't particularly concern me. It's the other patches you linked to that implement acquire/release that have me worried.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?
Quoted 8 lines
Quoted 4 lines
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
The reason we (Peter and I) care about this isn't because we enjoy being obstructive. It's because there is a whole load of core (i.e. portable) kernel code that is written to the *kernel* memory model. For example, the scheduler, RCU, mutex implementations, perf, drivers, you name it.
Consequently, it's important that the architecture back-ends implement these portable primitives (e.g. smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for synchronisation purposes. You could turn around and say "but if MIPS gets it wrong, then that's MIPS's problem", but actually not having a general understanding of the ordering guarantees provided by each architecture makes it very difficult for us to extend the kernel memory model in such a way that it can be implemented efficiently across the board *and* relied upon by core code.
The virtio patch at the start of the thread doesn't particularly concern me. It's the other patches you linked to that implement acquire/release that have me worried.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
You missed a point - it is a question about replacement of SYNC with lightweight primitives. It is NOT a question about multithread system behavior without any SYNC. The answer on a latest Will's question lies in different area.
- Leonid.
Peter Zijlstra
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 2 lines · Leonid Yegoshin
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (
SYNC_WMBetc)?
Of course. If you cannot explain the semantics of the primitives you introduce, how can we judge the patch.
This barrier business is hard enough as it is, but magic unexplained hardware makes it impossible.
Rest assured, you (MIPS) isn't the first (nor likely the last) to go through all this. We've had these discussions (and to a certain extend are still having them) for x86, PPC, Alpha, ARM, etc..
Any every time new barriers instructions get introduced we had better have a full and comprehensive explanation to go along with them.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 20 lines · Will Deacon
Quoted 1 line · Leonid Yegoshin
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1P1:
Rx == 1
<address dep>
Wy = 1P2:
Ry == 1
<address dep>
Rx = 0
Quoted 4 lines
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (SYNC_WMB etc)? You use any barrier or do not use it and I just voice an intention to use a more efficient instruction instead of bold hummer (SYNC instruction). If you don't use any barrier here then it is a different issue.
May be it has sense to return back to original issue?
- Leonid
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 20 lines · Will Deacon
Quoted 1 line · Leonid Yegoshin
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1P1:
Rx == 1
<address dep>
Wy = 1P2:
Ry == 1
<address dep>
Rx = 0
Quoted 4 lines
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
I ask HW team about it but I have a question - has it any relationship with replacing MIPS SYNC with lightweight SYNCs (SYNC_WMB etc)? You use any barrier or do not use it and I just voice an intention to use a more efficient instruction instead of bold hummer (SYNC instruction). If you don't use any barrier here then it is a different issue.
May be it has sense to return back to original issue?
- Leonid
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 19 lines · Will Deacon
Quoted 1 line
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1P1:
Rx == 1
<address dep>
Wy = 1P2:
Ry == 1
<address dep>
Rx = 0
Quoted 3 lines
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
OK, I collected answers and it is:
In MIPS R6 this test passes OK, I mean - P2: Rx = 1 if Ry is read
as 1. By design.
However, it is unclear that happens in MIPS R2 1004K.
Moreover, there are voices against guarantee that it will be in
future and that voices point me to Documentation/memory-barriers.txt section "DATA DEPENDENCY BARRIERS" examples which require SYNC_RMB between loading address/index and using that for loading data based on that address or index for shared data (look on CPU2 pseudo-code):
Quoted 13 lines
To deal with this, a data dependency barrier or better must be inserted between the address load and the data load:
CPU 1 CPU 2 =============== =============== { A == 1, B == 2, C = 3, P == &A, Q == &C } B = 4; <write barrier> WRITE_ONCE(P, &B); Q = READ_ONCE(P); <data dependency barrier> <----------- SYNC_RMB is here D = *Q;
...
Quoted 4 lines
Another example of where data dependency barriers might be required is where a number is read from memory and then used to calculate the index for an array access:
Quoted 10 lines
CPU 1 CPU 2
=============== ===============
{ M[0] == 1, M[1] == 2, M[3] = 3, P == 0, Q == 3 }
M[1] = 4;
<write barrier>
WRITE_ONCE(P, 1);
Q = READ_ONCE(P);
<data dependency barrier> <------------
SYNC_RMB is here
D = M[Q];That voices say that there is a legitimate reason to relax HW here for performance if SYNC_RMB is needed anyway to work with this sequence of shared data.
And all that is out-of-topic here in my mind. I just want to be sure that this patchset still provides a use of a specific lightweight SYNCs on MIPS vs bold and heavy generalized "SYNC 0" in any case.
- Leonid.
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Leonid Yegoshin
And all that is out-of-topic here in my mind. I just want to be sure that this patchset still provides a use of a specific lightweight SYNCs on MIPS vs bold and heavy generalized "SYNC 0" in any case.
- Leonid.
Of course it does. All this patchset does is rename smp_mb/rmb/wmb to __smp_mb()/__smp_rmb()/__smp_wmb()
and then asm-generic does #define smp_mb __smp_mb
or #define smp_mb barrier depending on CONFIG_SMP.
Why is that needed? So we can implement
[PATCH v3 28/41] asm-generic: implement virt_xxx memory barriers
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
And all that is out-of-topic here in my mind. I just want to be sure that this patchset still provides a use of a specific lightweight SYNCs on MIPS vs bold and heavy generalized "SYNC 0" in any case.
- Leonid.
Of course it does. All this patchset does is rename smp_mb/rmb/wmb to __smp_mb()/__smp_rmb()/__smp_wmb()
and then asm-generic does #define smp_mb __smp_mb
or #define smp_mb barrier depending on CONFIG_SMP.
Why is that needed? So we can implement
[PATCH v3 28/41] asm-generic: implement virt_xxx memory barriers
Signature · 1 line
MST
Michael S. Tsirkin
maintainerRe: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 5 lines · Leonid Yegoshin
And all that is out-of-topic here in my mind. I just want to be sure that this patchset still provides a use of a specific lightweight SYNCs on MIPS vs bold and heavy generalized "SYNC 0" in any case.
- Leonid.
Of course it does. All this patchset does is rename smp_mb/rmb/wmb to __smp_mb()/__smp_rmb()/__smp_wmb()
and then asm-generic does #define smp_mb __smp_mb
or #define smp_mb barrier depending on CONFIG_SMP.
Why is that needed? So we can implement
[PATCH v3 28/41] asm-generic: implement virt_xxx memory barriers
Signature · 1 line
MST
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 24 lines · Leonid Yegoshin
Quoted 19 lines · Will Deacon
Quoted 1 line
I don't think the address dependency is enough on its own. By that reasoning, the following variant (WRC+addr+addr) would work too:
P0:
Wx = 1P1:
Rx == 1
<address dep>
Wy = 1P2:
Ry == 1
<address dep>
Rx = 0Quoted 3 lines
So are you saying that this is also forbidden?
Imagine that P0 and P1 are two threads that share a store buffer. What then?
Quoted 6 lines
OK, I collected answers and it is:
In MIPS R6 this test passes OK, I mean - P2: Rx = 1 if Ry is read as 1.
By design.However, it is unclear that happens in MIPS R2 1004K.
How can it be unclear? If, for example, the outcome is permitted on that CPU, then your original reasoning for the WRC+sync+addr doesn't apply there and SYNC is not transitive. That's what I'm trying to get to the bottom of.
Does the MIPS kernel target a particular CPU at compile time?
Quoted 36 lines
Moreover, there are voices against guarantee that it will be in future
and that voices point me toDocumentation/memory-barriers.txtsection "DATA DEPENDENCY BARRIERS" examples which requireSYNC_RMBbetween loading address/index and using that for loading data based on that address or index for shared data (look on CPU2 pseudo-code):Quoted 13 lines
To deal with this, a data dependency barrier or better must be inserted between the address load and the data load:
CPU 1 CPU 2 =============== =============== { A == 1, B == 2, C = 3, P == &A, Q == &C } B = 4; <write barrier> WRITE_ONCE(P, &B); Q = READ_ONCE(P); <data dependency barrier> <----------- SYNC_RMB is here D = *Q;...
Quoted 6 lines
Another example of where data dependency barriers might be required is where a
number is read from memory and then used to calculate the index for an array
access:Quoted 10 lines
CPU 1 CPU 2 =============== =============== { M[0] == 1, M[1] == 2, M[3] = 3, P == 0, Q == 3 } M[1] = 4; <write barrier> WRITE_ONCE(P, 1); Q = READ_ONCE(P); <data dependency barrier> <------------ SYNC_RMB is here D = M[Q];
Quoted 3 lines
That voices say that there is a legitimate reason to relax HW here for performance if
SYNC_RMBis needed anyway to work with this sequence of shared data.
Are you saying that MIPS needs to implement [smp_]read_barrier_depends?
Quoted 3 lines
And all that is out-of-topic here in my mind. I just want to be sure that this patchset still provides a use of a specific lightweight SYNCs on MIPS vs bold and heavy generalized "SYNC 0" in any case.
We may be highjacking the thread slightly, but there are much bigger issues at play here if you want to start using lightweight barriers to implement relaxed kernel primitives such as smp_load_acquire and smp_store_release.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 37 lines · Will Deacon
Quoted 35 lines · Leonid Yegoshin
Moreover, there are voices against guarantee that it will be in future
and that voices point me toDocumentation/memory-barriers.txtsection "DATA DEPENDENCY BARRIERS" examples which requireSYNC_RMBbetween loading address/index and using that for loading data based on that address or index for shared data (look on CPU2 pseudo-code):Quoted 13 lines
To deal with this, a data dependency barrier or better must be inserted between the address load and the data load:
CPU 1 CPU 2 =============== =============== { A == 1, B == 2, C = 3, P == &A, Q == &C } B = 4; <write barrier> WRITE_ONCE(P, &B); Q = READ_ONCE(P); <data dependency barrier> <----------- SYNC_RMB is here D = *Q;...
Quoted 16 lines
Another example of where data dependency barriers might be required is where a
number is read from memory and then used to calculate the index for an array
access:CPU 1 CPU 2 =============== =============== { M[0] == 1, M[1] == 2, M[3] = 3, P == 0, Q == 3 } M[1] = 4; <write barrier> WRITE_ONCE(P, 1); Q = READ_ONCE(P); <data dependency barrier> <------------ SYNC_RMB is here D = M[Q];
Quoted 4 lines
Quoted 3 lines
That voices say that there is a legitimate reason to relax HW here for performance if
SYNC_RMBis needed anyway to work with this sequence of shared data.Are you saying that MIPS needs to implement [smp_]read_barrier_depends?
It is not me, it is Documentation/memory-barriers.txt from kernel sources.
HW team can't work on voice statements, it should do a work on written documents. If that is written (see above the lines which I marked by "SYNC_RMB") then anybody should use it and never mind how many CPUs/Threads are in play. This examples explicitly requires to insert "data dependency barrier" between reading a shared pointer/index and using it to fetch a shared data. So, your WRC+addr+addr test is a violation of that recommendation.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 45 lines · Leonid Yegoshin
Quoted 37 lines · Will Deacon
Quoted 35 lines · Leonid Yegoshin
Moreover, there are voices against guarantee that it will be in future
and that voices point me toDocumentation/memory-barriers.txtsection "DATA DEPENDENCY BARRIERS" examples which requireSYNC_RMBbetween loading address/index and using that for loading data based on that address or index for shared data (look on CPU2 pseudo-code):Quoted 13 lines
To deal with this, a data dependency barrier or better must be inserted between the address load and the data load:
CPU 1 CPU 2 =============== =============== { A == 1, B == 2, C = 3, P == &A, Q == &C } B = 4; <write barrier> WRITE_ONCE(P, &B); Q = READ_ONCE(P); <data dependency barrier> <----------- SYNC_RMB is here D = *Q;...
Quoted 16 lines
Another example of where data dependency barriers might be required is where a
number is read from memory and then used to calculate the index for an array
access:CPU 1 CPU 2 =============== =============== { M[0] == 1, M[1] == 2, M[3] = 3, P == 0, Q == 3 } M[1] = 4; <write barrier> WRITE_ONCE(P, 1); Q = READ_ONCE(P); <data dependency barrier> <------------ SYNC_RMB is here D = M[Q];Quoted 4 lines
Quoted 3 lines
That voices say that there is a legitimate reason to relax HW here for performance if
SYNC_RMBis needed anyway to work with this sequence of shared data.Are you saying that MIPS needs to implement [smp_]read_barrier_depends?
It is not me, it is
Documentation/memory-barriers.txtfrom kernel sources.
Quoted 7 lines
HW team can't work on voice statements, it should do a work on written documents. If that is written (see above the lines which I marked by "
SYNC_RMB") then anybody should use it and never mind how many CPUs/Threads are in play. This examples explicitly requires to insert "data dependency barrier" between reading a shared pointer/index and using it to fetch a shared data. So, your WRC+addr+addr test is a violation of that recommendation.
Perhaps Documentation/memory-barriers.txt needs additional clarification. It would not be the first time.
If your CPU implicitly maintains ordering based on address and data dependencies, then you don't need any instructions for <data dependency barrier>.
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier. Transitivity is instead supplied by smp_mb() and by smp_store_release()-smp_load_acquire() chains. Here is the Linux kernel code for WRC+addr+addr, give or take (and no, I have no idea why anyone would want to write code like this):
struct foo {
struct foo **a;
};
struct foo b;
struct foo c;
struct foo d;
struct foo e;
struct foo f = { &d };
struct foo g = { &e };
struct foo *x = &b;
void cpu0(void)
{
WRITE_ONCE(x, &f);
}
void cpu1(void)
{
struct foo *p;
p = lockless_dereference(x);
WRITE_ONCE(p->a, &x);
}
void cpu2(void)
{
r1 = lockless_dereference(f.a);
WRITE_ONCE(*r1, &c);
}It is legal to end the run with x==&f and r1==&x. To prevent this outcome, we do the following:
struct foo {
struct foo **a;
};
struct foo b;
struct foo c;
struct foo d;
struct foo e;
struct foo f = { &d };
struct foo g = { &e };
struct foo *x = &b;
void cpu0(void)
{
WRITE_ONCE(x, &f);
}
void cpu1(void)
{
struct foo *p;
p = lockless_dereference(x);
smp_store_release(&p->a, &x); /* Additional ordering. */
}
void cpu2(void)
{
r1 = lockless_dereference(f.a);
WRITE_ONCE(*r1, &c);
}And I still don't know why anyone would need this sort of code. ;-)
Alternatively, we pull cpu2() into cpu1():
struct foo {
struct foo **a;
};
struct foo b;
struct foo c;
struct foo d;
struct foo e;
struct foo f = { &d };
struct foo g = { &e };
struct foo *x = &b;
void cpu0(void)
{
WRITE_ONCE(x, &f);
}
void cpu1(void)
{
struct foo *p;
p = lockless_dereference(x);
WRITE_ONCE(p->a, &x);
r1 = lockless_dereference(f.a);
WRITE_ONCE(*r1, &c);
}The ordering is now enforced by being within a single thread. In fact, the second lockless_dereference() can be READ_ONCE().
So, does MIPS maintain ordering within a given CPU based on address and data dependencies? If so, you don't need to emit memory-barrier instructions for read_barrier_depends().
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
I need some time to understand your test examples. However,
Quoted 5 lines · Paul E. McKenney
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
Quoted 1 line
Transitivity is
Peter Zijlstra recently wrote: "In particular we're very much all 'confused' about the various notions of transitivity". I am confused too, so - please use some more simple way to explain your words. Sorry, but we need a common ground first.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 1 line · Leonid Yegoshin
I need some time to understand your test examples. However,
Understood.
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that lockless_dereference() contains an smp_read_barrier_depends():
#define lockless_dereference(p) \
({ \
typeof(p) _________p1 = READ_ONCE(p); \
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
(_________p1); \
})Or am I missing your point?
Quoted 6 lines
Quoted 1 line
Transitivity is
Peter Zijlstra recently wrote: "In particular we're very much all 'confused' about the various notions of transitivity". I am confused too, so - please use some more simple way to explain your words. Sorry, but we need a common ground first.
OK, how about an example? (Z6.3 in the ppcmem naming scheme.)
int x, y, z;
void cpu0(void)
{
WRITE_ONCE(x, 1);
smp_wmb();
WRITE_ONCE(y, 1);
}
void cpu1(void)
{
WRITE_ONCE(y, 2);
smp_wmb();
WRITE_ONCE(z, 1);
}
void cpu2(void)
{
r1 = READ_ONCE(z);
smp_rmb();
r2 = read_once(x);
}If smp_rmb() and smp_wmb() provided transitive ordering, then cpu2() would see cpu0()'s ordering. But they do not, so the ordering is visible at best to the adjacent CPU. This means that the final value of y can be 2, while at the same time r1==1 && r2==0.
Now the full barrier, smp_mb(), does provide transitive ordering, so if the three barriers in the above example are replaced with smp_mb() the y==2 && r1==1 && r2==0 outcome will be prohibited.
So smp_mb() provides transitivity, as do pairs of smp_store_release() and smp_read_acquire(), as do RCU grace periods. The exact interactions between transitive and non-transitive ordering is a work in progress. That said, if a series of transitive segments ends in a write, which connects to a single non-transitive segment starting with a read, you should be good. And in fact in the example above, you can replace the smp_wmb()s with smp_mb() and leave the smp_rmb() and still prohibit the "cyclic" outcome.
If you want a more formal definition, I must refer you back to the ppcmem and herd references.
Does that help?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 18 lines · Paul E. McKenney
Quoted 6 lines · Paul E. McKenney
Quoted 4 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that
lockless_dereference()contains ansmp_read_barrier_depends():
Quoted 8 lines
#define
lockless_dereference(p)\({ \ typeof(p) _________p1 = READ_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ })Or am I missing your point?
WRC+addr+addr has no any barrier. lockless_dereference() has a barrier. I don't see a common points between this and that in your answer, sorry.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 26 lines · Leonid Yegoshin
Quoted 25 lines · Paul E. McKenney
Quoted 6 lines · Paul E. McKenney
Quoted 4 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that
lockless_dereference()contains ansmp_read_barrier_depends():#define
lockless_dereference(p)\({ \ typeof(p) _________p1 = READ_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ })
Quoted 5 lines
Quoted 1 line
Or am I missing your point?
WRC+addr+addr has no any barrier.
lockless_dereference()has a barrier. I don't see a common points between this and that in your answer, sorry.
Me, I am wondering what WRC+addr+addr has to do with anything at all.
<Going back through earlier email>
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr. This would drop an smp_mb() into cpu2() in my earlier example, which needs to provide ordering.
I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time. This leads me to believe that your smp_mb() needs to use SYNC rather than SYNC_MB, as was the subject of earlier spirited discussion in this thread.
Suppose you have something like this:
void cpu0(void)
{
WRITE_ONCE(a, 1);
SYNC_MB();
r0 = READ_ONCE(b);
}
void cpu1(void)
{
WRITE_ONCE(b, 1);
SYNC_MB();
r1 = READ_ONCE(c);
}
void cpu2(void)
{
WRITE_ONCE(c, 1);
SYNC_MB();
r2 = READ_ONCE(d);
}
void cpu3(void)
{
WRITE_ONCE(d, 1);
SYNC_MB();
r3 = READ_ONCE(a);
}Does your hardware guarantee that it is not possible for all of r0, r1, r2, and r3 to be equal to zero at the end of the test, assuming that a, b, c, and d are all initially zero, and the four functions above run concurrently? There are many similar litmus tests for other combinations of reads and writes, but this is perhaps the nastiest from a hardware viewpoint. Does SYNC_MB() provide sufficient ordering for this sort of situation?
Another (more academic) case is this one, with x and y initially zero:
void cpu0(void)
{
WRITE_ONCE(x, 1);
}
void cpu1(void)
{
WRITE_ONCE(y, 1);
}
void cpu2(void)
{
r1 = READ_ONCE(x, 1);
SYNC_MB();
r2 = READ_ONCE(y, 1);
}
void cpu3(void)
{
r3 = READ_ONCE(y, 1);
SYNC_MB();
r4 = READ_ONCE(x, 1);
}Does SYNC_MB() prohibit r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0?
Now, I don't know of any specific use cases for this pattern, but it is greatly beloved of some of the old-school concurrency community, so it is likely to crop up at some point, despite my best efforts. :-/
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Paul E. McKenney
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr.
(He actually asked twice about this and that too but skip this)
Quoted 6 lines
I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time. This leads me to believe that your
smp_mb()needs to use SYNC rather thanSYNC_MB, as was the subject of earlier spirited discussion in this thread.
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume that SYNC_MB is absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).
Quoted 7 lines
Suppose you have something like this:
...
Does your hardware guarantee that it is not possible for all of r0, r1, r2, and r3 to be equal to zero at the end of the test, assuming that a, b, c, and d are all initially zero, and the four functions above run concurrently?
It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Quoted 4 lines
Another (more academic) case is this one, with x and y initially zero:
...
DoesSYNC_MB()prohibit r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0?
It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 4 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr.
(He actually asked twice about this and that too but skip this)
Fair enough! ;-)
Quoted 7 lines
Quoted 6 lines
I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time. This leads me to believe that your
smp_mb()needs to use SYNC rather thanSYNC_MB, as was the subject of earlier spirited discussion in this thread.
Quoted 8 lines
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume thatSYNC_MBis absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).
So smp_mb() can be SYNC_MB. However, mb() needs to be SYNC for MMIO purposes, correct?
Quoted 9 lines
Quoted 6 lines
Suppose you have something like this:
...
Does your hardware guarantee that it is not possible for all of r0, r1, r2, and r3 to be equal to zero at the end of the test, assuming that a, b, c, and d are all initially zero, and the four functions above run concurrently?It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Indeed!
Quoted 7 lines
Quoted 4 lines
Another (more academic) case is this one, with x and y initially zero:
...
DoesSYNC_MB()prohibit r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0?It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Looks to me like smp_mb() can be SYNC_MB, then.
Quoted 11 lines
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 11 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume thatSYNC_MBis absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).So
smp_mb()can beSYNC_MB. However,mb()needs to be SYNC for MMIO purposes, correct?
Absolutely. For MIPS R2 which is not Octeon.
Quoted 9 lines
Quoted 9 lines
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
Quoted 4 lines
Quoted 2 lines
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that: no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 7 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.
I don't recall being asked; mind that I might not get to messages I have
not been cc-ed in a timely manner and I may miss some altogether. With the amount of mailing list traffic that passes by me my scanner may fail to trigger. Sorry if this causes anybody trouble, but such is life.
Coincidentally, I have just posted some notes on SYNC in a different
thread, see <http://lkml.iu.edu/hypermail/linux/kernel/1601.3/03080.html>.
There's a reference to an older message of mine there too. I hope this answers your questions.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 7 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.
I don't recall being asked; mind that I might not get to messages I have
not been cc-ed in a timely manner and I may miss some altogether. With the amount of mailing list traffic that passes by me my scanner may fail to trigger. Sorry if this causes anybody trouble, but such is life.
Coincidentally, I have just posted some notes on SYNC in a different
thread, see <http://lkml.iu.edu/hypermail/linux/kernel/1601.3/03080.html>.
There's a reference to an older message of mine there too. I hope this answers your questions.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 9 lines · Maciej W. Rozycki
Quoted 6 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.I don't recall being asked;
In http://patchwork.linux-mips.org/patch/10505/ the very last mesg exchange is:
Maciej,
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
...
Ralf
Maciej W. Rozycki <http://patchwork.linux-mips.org/project/linux-mips/list/?submitter=79> - June 5, 2015, 9:18 p.m.
Quoted 2 lines · Ralf Baechle
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
I should be able to check R4400 (that is virtually the same as R4000)
next week or so. As to SiByte -- not before next month I'm afraid. I don't have access to any of the other processors you named. You may want to find a better person if you want to accept this change soon.
Maciej
... and that stops forever...
- Leonid.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 2 lines · Leonid Yegoshin
In http://patchwork.linux-mips.org/patch/10505/ the very last mesg exchange is:
[...]
Quoted 1 line
... and that stops forever...
Thanks for the reminder -- last June was very hectic, I travelled a lot
and I lost the discussion from my radar. Apologies for that. I replied in that thread now with my results. I hope this helps.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 2 lines · Leonid Yegoshin
In http://patchwork.linux-mips.org/patch/10505/ the very last mesg exchange is:
[...]
Quoted 1 line
... and that stops forever...
Thanks for the reminder -- last June was very hectic, I travelled a lot
and I lost the discussion from my radar. Apologies for that. I replied in that thread now with my results. I hope this helps.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 2 lines · Leonid Yegoshin
In http://patchwork.linux-mips.org/patch/10505/ the very last mesg exchange is:
[...]
Quoted 1 line
... and that stops forever...
Thanks for the reminder -- last June was very hectic, I travelled a lot
and I lost the discussion from my radar. Apologies for that. I replied in that thread now with my results. I hope this helps.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Maciej W. RozyckiQuoted 9 lines · Maciej W. Rozycki
Quoted 6 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.I don't recall being asked;
In http://patchwork.linux-mips.org/patch/10505/ the very last mesg exchange is:
Maciej,
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
...
Ralf
Maciej W. Rozycki <http://patchwork.linux-mips.org/project/linux-mips/list/?submitter=79> - June 5, 2015, 9:18 p.m.
Quoted 2 lines · Ralf Baechle
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
I should be able to check R4400 (that is virtually the same as R4000)
next week or so. As to SiByte -- not before next month I'm afraid. I don't have access to any of the other processors you named. You may want to find a better person if you want to accept this change soon.
Maciej
... and that stops forever...
- Leonid.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Maciej W. RozyckiQuoted 13 lines · Maciej W. Rozycki
Quoted 6 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.I don't recall being asked; mind that I might not get to messages I have
not been cc-ed in a timely manner and I may miss some altogether. With the amount of mailing list traffic that passes by me my scanner may fail to trigger. Sorry if this causes anybody trouble, but such is life.
Quoted 6 lines
Coincidentally, I have just posted some notes on SYNC in a different
thread, see <http://lkml.iu.edu/hypermail/linux/kernel/1601.3/03080.html>.
There's a reference to an older message of mine there too. I hope this answers your questions.Maciej
In http://patchwork.linux-mips.org/patch/10505/the very last mesg exchange is:
Maciej,
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
...
Ralf
Maciej W. Rozycki- June 5, 2015, 9:18 p.m.
Quoted 2 lines · Ralf Baechle
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
I should be able to check R4400 (that is virtually the same as R4000)
next week or so. As to SiByte -- not before next month I'm afraid. I don't have access to any of the other processors you named. You may want to find a better person if you want to accept this change soon.
Maciej
... and that stops forever...
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Maciej W. RozyckiQuoted 13 lines · Maciej W. Rozycki
Quoted 6 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.I don't recall being asked; mind that I might not get to messages I have
not been cc-ed in a timely manner and I may miss some altogether. With the amount of mailing list traffic that passes by me my scanner may fail to trigger. Sorry if this causes anybody trouble, but such is life.
Quoted 6 lines
Coincidentally, I have just posted some notes on SYNC in a different
thread, see <http://lkml.iu.edu/hypermail/linux/kernel/1601.3/03080.html>.
There's a reference to an older message of mine there too. I hope this answers your questions.Maciej
In http://patchwork.linux-mips.org/patch/10505/the very last mesg exchange is:
Maciej,
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
...
Ralf
Maciej W. Rozycki- June 5, 2015, 9:18 p.m.
Quoted 2 lines · Ralf Baechle
do you have an R4000 / R4600 / R5000 / R7000 / SiByte system at hand to test this?
I should be able to check R4400 (that is virtually the same as R4000)
next week or so. As to SiByte -- not before next month I'm afraid. I don't have access to any of the other processors you named. You may want to find a better person if you want to accept this change soon.
Maciej
... and that stops forever...
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 7 lines · Leonid Yegoshin
Quoted 2 lines
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that:
no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.
I don't recall being asked; mind that I might not get to messages I have
not been cc-ed in a timely manner and I may miss some altogether. With the amount of mailing list traffic that passes by me my scanner may fail to trigger. Sorry if this causes anybody trouble, but such is life.
Coincidentally, I have just posted some notes on SYNC in a different
thread, see <http://lkml.iu.edu/hypermail/linux/kernel/1601.3/03080.html>.
There's a reference to an older message of mine there too. I hope this answers your questions.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 11 lines · Paul E. McKenney
Quoted 8 lines · Leonid Yegoshin
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume thatSYNC_MBis absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).So
smp_mb()can beSYNC_MB. However,mb()needs to be SYNC for MMIO purposes, correct?
Absolutely. For MIPS R2 which is not Octeon.
Quoted 9 lines
Quoted 9 lines
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
Quoted 4 lines
Quoted 2 lines
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
I don't know. I would like to have responses. Ralf asked Maciej about old systems and that came nowhere. Even rewrite - don't know what to do with that: no lightweight SYNC or no SYNC at all - yes, it is still possible that SYNC on some systems can be too heavy or even harmful, nobody tested that.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 1 line · Paul E. McKenney
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Quoted 1 line
Or do you do boot-time rewriting, like a number of other arches do?
We don't rewrite the code (as in the .text of the vmlinux binary) but we do runtime code generation for a few highly performance sensitive area of the kernel code such as copy_page() or TLB exception handlers. This allows more flexibility than just inserting templates into the kernel code. Downside - it means we have some of the complexity of as and ld in the kernel.
Ralf
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 8 lines · Ralf Baechle
Quoted 1 line
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Matt (cc-ed) has recently posted patches to add support for a relocatable
kernel, implemented without the usual overhead of PIC code. It works by retaining relocations in a fully-linked binary and then simply replaying the work the static linker does when assigning addresses, as the image loaded is copied to its intended destination at an early bootstrap stage. See:
<http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=1449137297-30464-1-git-send-email-matt.redfearn%40imgtec.com>
for details.
I think this framework can be reused by carefully choosing instructions
used in early bootstrap code, up to the relocation stage, so that it is runnable anywhere (not the same as PIC!) like early ld.so initialisation and then loading the whole attached image starting from an address where RAM does exist on target hardware.
Endianness is a different matter, obviously we can't build a single image
for both, although for distributions' sake an approach similar to one used with bi-endian firmware (for hardware which has an easy way to switch the endianness, e.g. a physical jumper or a configuration bit stored in flash memory; not to be confused with the reverse user endianness mode) might be feasible, by glueing two kernel images together and then selecting the right one early in bootstrap, perhaps again reusing Matt's framework. I'm not sure if this is worth the effort though, I suspect the usage level of this feature would be minimal.
All in all I think making a generic MIPS kernel just might be feasible,
but with the diversity of options available the effort required would be enormous. NetBSD for example I believe supports building a kernel that correctly runs on both R3000 (MIPS I, 32-bit) and R4000 (MIPS III, 64-bit) DEC hardware (as did DEC Ultrix, the vendor OS for these systems). These processors are different enough from each other that you cannot use the same code for cache, memory and exception management in an OS kernel -- backward compatibility is only provided for user software. That proves the concept, however in a very limited way only, not even covering SMP, and their R4000 kernel does not support 64-bit userland I believe. They still have completely separate ports for other MIPS hardware, such as for Broadcom SiByte SB-1 (MIPS64r1) processors.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Ralf BaechleQuoted 8 lines · Ralf Baechle
Quoted 1 line
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Matt (cc-ed) has recently posted patches to add support for a relocatable
kernel, implemented without the usual overhead of PIC code. It works by retaining relocations in a fully-linked binary and then simply replaying the work the static linker does when assigning addresses, as the image loaded is copied to its intended destination at an early bootstrap stage. See:
<http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=1449137297-30464-1-git-send-email-matt.redfearn%40imgtec.com>
for details.
I think this framework can be reused by carefully choosing instructions
used in early bootstrap code, up to the relocation stage, so that it is runnable anywhere (not the same as PIC!) like early ld.so initialisation and then loading the whole attached image starting from an address where RAM does exist on target hardware.
Endianness is a different matter, obviously we can't build a single image
for both, although for distributions' sake an approach similar to one used with bi-endian firmware (for hardware which has an easy way to switch the endianness, e.g. a physical jumper or a configuration bit stored in flash memory; not to be confused with the reverse user endianness mode) might be feasible, by glueing two kernel images together and then selecting the right one early in bootstrap, perhaps again reusing Matt's framework. I'm not sure if this is worth the effort though, I suspect the usage level of this feature would be minimal.
All in all I think making a generic MIPS kernel just might be feasible,
but with the diversity of options available the effort required would be enormous. NetBSD for example I believe supports building a kernel that correctly runs on both R3000 (MIPS I, 32-bit) and R4000 (MIPS III, 64-bit) DEC hardware (as did DEC Ultrix, the vendor OS for these systems). These processors are different enough from each other that you cannot use the same code for cache, memory and exception management in an OS kernel -- backward compatibility is only provided for user software. That proves the concept, however in a very limited way only, not even covering SMP, and their R4000 kernel does not support 64-bit userland I believe. They still have completely separate ports for other MIPS hardware, such as for Broadcom SiByte SB-1 (MIPS64r1) processors.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Ralf BaechleQuoted 8 lines · Ralf Baechle
Quoted 1 line
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Matt (cc-ed) has recently posted patches to add support for a relocatable
kernel, implemented without the usual overhead of PIC code. It works by retaining relocations in a fully-linked binary and then simply replaying the work the static linker does when assigning addresses, as the image loaded is copied to its intended destination at an early bootstrap stage. See:
<http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=1449137297-30464-1-git-send-email-matt.redfearn%40imgtec.com>
for details.
I think this framework can be reused by carefully choosing instructions
used in early bootstrap code, up to the relocation stage, so that it is runnable anywhere (not the same as PIC!) like early ld.so initialisation and then loading the whole attached image starting from an address where RAM does exist on target hardware.
Endianness is a different matter, obviously we can't build a single image
for both, although for distributions' sake an approach similar to one used with bi-endian firmware (for hardware which has an easy way to switch the endianness, e.g. a physical jumper or a configuration bit stored in flash memory; not to be confused with the reverse user endianness mode) might be feasible, by glueing two kernel images together and then selecting the right one early in bootstrap, perhaps again reusing Matt's framework. I'm not sure if this is worth the effort though, I suspect the usage level of this feature would be minimal.
All in all I think making a generic MIPS kernel just might be feasible,
but with the diversity of options available the effort required would be enormous. NetBSD for example I believe supports building a kernel that correctly runs on both R3000 (MIPS I, 32-bit) and R4000 (MIPS III, 64-bit) DEC hardware (as did DEC Ultrix, the vendor OS for these systems). These processors are different enough from each other that you cannot use the same code for cache, memory and exception management in an OS kernel -- backward compatibility is only provided for user software. That proves the concept, however in a very limited way only, not even covering SMP, and their R4000 kernel does not support 64-bit userland I believe. They still have completely separate ports for other MIPS hardware, such as for Broadcom SiByte SB-1 (MIPS64r1) processors.
Maciej
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 1 line · Paul E. McKenney
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Quoted 1 line
Or do you do boot-time rewriting, like a number of other arches do?
We don't rewrite the code (as in the .text of the vmlinux binary) but we do runtime code generation for a few highly performance sensitive area of the kernel code such as copy_page() or TLB exception handlers. This allows more flexibility than just inserting templates into the kernel code. Downside - it means we have some of the complexity of as and ld in the kernel.
Ralf
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 1 line · Paul E. McKenney
So you need to build a different kernel for some types of MIPS systems?
Yes. We can't really do without. Classic MIPS code is not relocatable without the complexity of PIC code as used by ELF DSOs - and their performanc penalty. Plus we have a number of architecture revisions ovr the decades, big and little endian, 32 and 64 bit as the major stumbling stones. There however are groups of similar systems that can share kernel binaries.
Quoted 1 line
Or do you do boot-time rewriting, like a number of other arches do?
We don't rewrite the code (as in the .text of the vmlinux binary) but we do runtime code generation for a few highly performance sensitive area of the kernel code such as copy_page() or TLB exception handlers. This allows more flexibility than just inserting templates into the kernel code. Downside - it means we have some of the complexity of as and ld in the kernel.
Ralf
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Leonid YegoshinQuoted 4 lines · Leonid Yegoshin
Quoted 2 lines · Paul E. McKenney
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr.
(He actually asked twice about this and that too but skip this)
Fair enough! ;-)
Quoted 7 lines
Quoted 6 lines
I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time. This leads me to believe that your
smp_mb()needs to use SYNC rather thanSYNC_MB, as was the subject of earlier spirited discussion in this thread.
Quoted 8 lines
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume thatSYNC_MBis absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).
So smp_mb() can be SYNC_MB. However, mb() needs to be SYNC for MMIO purposes, correct?
Quoted 9 lines
Quoted 6 lines
Suppose you have something like this:
...
Does your hardware guarantee that it is not possible for all of r0, r1, r2, and r3 to be equal to zero at the end of the test, assuming that a, b, c, and d are all initially zero, and the four functions above run concurrently?It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Indeed!
Quoted 7 lines
Quoted 4 lines
Another (more academic) case is this one, with x and y initially zero:
...
DoesSYNC_MB()prohibit r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0?It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Looks to me like smp_mb() can be SYNC_MB, then.
Quoted 11 lines
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
So you need to build a different kernel for some types of MIPS systems? Or do you do boot-time rewriting, like a number of other arches do?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 2 lines · Paul E. McKenney
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr.
(He actually asked twice about this and that too but skip this)
Quoted 6 lines
I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time. This leads me to believe that your
smp_mb()needs to use SYNC rather thanSYNC_MB, as was the subject of earlier spirited discussion in this thread.
Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly.
Just assume that SYNC_MB is absolutely the same as SYNC for any CPU and coherent device (besides performance). The difference can be in non-coherent devices because SYNC actually tries to make a barrier for them too. In some SoCs it is just the same because there is no need to barrier a non-coherent device (device register access usually strictly ordered... if there is no bridge in between).
Quoted 7 lines
Suppose you have something like this:
...
Does your hardware guarantee that it is not possible for all of r0, r1, r2, and r3 to be equal to zero at the end of the test, assuming that a, b, c, and d are all initially zero, and the four functions above run concurrently?
It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Quoted 4 lines
Another (more academic) case is this one, with x and y initially zero:
...
DoesSYNC_MB()prohibit r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0?
It is assumed to be so from Arch point of view. HW bugs are possible, of course.
Note: I am not sure about ANY past MIPS R2 CPU because that stuff is implemented some time but nobody made it in Linux kernel (it was used by some vendor for non-Linux system). For that reason my patch for lightweight SYNCs has an option - implement it or implement a generic SYNC. It is possible that some vendor did it in different way but nobody knows or test it. But as a minimum - SYNC must be implemented in spinlocks/atomics/bitops, in recent P5600 it is proven that read can pass write in atomics.
MIPS R6 is a different story, I verified lightweight SYNCs from the beginning and it also should use SYNCs.
- Leonid.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 27 lines · Paul E. McKenney
Quoted 26 lines · Leonid Yegoshin
Quoted 25 lines · Paul E. McKenney
Quoted 6 lines · Paul E. McKenney
Quoted 4 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that
lockless_dereference()contains ansmp_read_barrier_depends():#define
lockless_dereference(p)\({ \ typeof(p) _________p1 = READ_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ })
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Or am I missing your point?
WRC+addr+addr has no any barrier.
lockless_dereference()has a barrier. I don't see a common points between this and that in your answer, sorry.Me, I am wondering what WRC+addr+addr has to do with anything at all.
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
Quoted 10 lines
<Going back through earlier email>
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr. This would drop an
smp_mb()intocpu2()in my earlier example, which needs to provide ordering.I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time.
I couldn't make that leap. In particular, the manual's "Detailed Description" sections explicitly refer to program-order:
Every synchronizable specified memory instruction (loads or stores or both) that occurs in the instruction stream before the SYNC instruction must reach a stage in the load/store datapath after which no instruction re-ordering is possible before any synchronizable specified memory instruction which occurs after the SYNC instruction in the instruction stream reaches the same stage in the load/store datapath.
Will
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/399765.html
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 30 lines · Will Deacon
Quoted 29 lines · Paul E. McKenney
Quoted 28 lines · Leonid Yegoshin
Quoted 26 lines · Paul E. McKenney
Quoted 6 lines · Paul E. McKenney
Quoted 4 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that
lockless_dereference()contains ansmp_read_barrier_depends():#define
lockless_dereference(p)\({ \ typeof(p) _________p1 = READ_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ })Or am I missing your point?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
WRC+addr+addr has no any barrier.
lockless_dereference()has a barrier. I don't see a common points between this and that in your answer, sorry.Me, I am wondering what WRC+addr+addr has to do with anything at all.
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 22 lines
Quoted 10 lines
<Going back through earlier email>
OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr. This would drop an
smp_mb()intocpu2()in my earlier example, which needs to provide ordering.I am guessing that the manual's "Older instructions which must be globally performed when the SYNC instruction completes" provides the equivalent of ARM/Power A-cumulativity, which can be thought of as transitivity backwards in time.
I couldn't make that leap. In particular, the manual's "Detailed Description" sections explicitly refer to program-order:
Every synchronizable specified memory instruction (loads or stores or both) that occurs in the instruction stream before the SYNC instruction must reach a stage in the load/store datapath after which no instruction re-ordering is possible before any synchronizable specified memory instruction which occurs after the SYNC instruction in the instruction stream reaches the same stage in the load/store datapath.
Quoted 3 lines
Will
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-January/399765.html
All good points. I think we all agree that the MIPS documentation could use significant help. And given that I work for the company that produced the analogous documentation for PowerPC, that is saying something. ;-)
We simply can't know if MIPS's memory ordering is sufficient for the Linux kernel given its current implementation of the ordering primitives and its current documentation.
I feel a bit better than I did earlier due to Leonid's response to my earlier litmus-test examples. But I do recommend some serious stress testing of MIPS on a good set of litmus tests. Much nicer finding issues that way than as random irreproducible strange behavior!
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · Will Deacon
Quoted 33 lines · Paul E. McKenney
Quoted 31 lines · Leonid Yegoshin
Quoted 18 lines · Paul E. McKenney
Quoted 6 lines · Paul E. McKenney
Quoted 4 lines
The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an explicit memory barrier.
Quoted 9 lines
I don't see any reliable way to fit WRC+addr+addr into "DATA DEPENDENCY BARRIERS" section recommendation to have data dependency barrier between read of a shared pointer/index and read the shared data based on that pointer. If you have this two reads, it doesn't matter the rest of scenario, you should put the dependency barrier in code anyway. If you don't do it in WRC+addr+addr scenario then after years it can be easily changed to different scenario which fits some of scenario in "DATA DEPENDENCY BARRIERS" section and fails.
The trick is that
lockless_dereference()contains ansmp_read_barrier_depends():Quoted 8 lines
#define
lockless_dereference(p)\({ \ typeof(p) _________p1 = READ_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ })Or am I missing your point?
WRC+addr+addr has no any barrier.
lockless_dereference()has a barrier. I don't see a common points between this and that in your answer, sorry.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Me, I am wondering what WRC+addr+addr has to do with anything at all.
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
struct foo {
struct foo *next;
};
struct foo a;
struct foo b;
struct foo c = { &a };
struct foo d = { &b };
struct foo x = { &c };
struct foo y = { &d };
struct foo *r1, *r2, *r3;
void cpu0(void)
{
WRITE_ONCE(x.next, &y);
}
void cpu1(void)
{
r1 = lockless_dereference(x.next);
WRITE_ONCE(r1->next, &x);
}
void cpu2(void)
{
r2 = lockless_dereference(y.next);
r3 = READ_ONCE(r2->next);
}In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &c
Please see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
Thanx, Paul
PS. And yes, working through this does help me understand the
benefits of fake dependencies. Why do you ask? ;-)
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
P0 | P1 | P2 ;
stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ;
| stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 5 lines · Paul E. McKenney
Quoted 4 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
Quoted 7 lines
Quoted 3 lines
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
Quoted 28 lines
struct foo {
struct foo *next;
};
struct foo a;
struct foo b;
struct foo c = { &a };
struct foo d = { &b };
struct foo x = { &c };
struct foo y = { &d };
struct foo *r1, *r2, *r3;
void cpu0(void)
{
WRITE_ONCE(x.next, &y);
}
void cpu1(void)
{
r1 = lockless_dereference(x.next);
WRITE_ONCE(r1->next, &x);
}
void cpu2(void)
{
r2 = lockless_dereference(y.next);
r3 = READ_ONCE(r2->next);
}Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 8 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Seems to be missing the address dependency on P1.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 8 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
Thanx, Paul
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
P0 | P1 | P2 ;
stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ;
| stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 72 lines · Paul E. McKenney
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 13 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 3 lines
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
I think that's it!
Quoted 14 lines
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Agreed.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 99 lines · Will Deacon
Quoted 72 lines · Paul E. McKenney
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 13 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)Quoted 3 lines
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
I think that's it!
Quoted 14 lines
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 1 line
Agreed.
OK, thank you! Would you agree that it would be good to replace the current xor-based fake-dependency litmus tests with tests having real dependencies?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Will Deacon
Quoted 13 lines · Paul E. McKenney
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 5 lines
Quoted 1 line
Agreed.
OK, thank you! Would you agree that it would be good to replace the current xor-based fake-dependency litmus tests with tests having real dependencies?
Yes, because it would look a lot more like real (kernel) code.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 16 lines · Paul E. McKenney
Quoted 15 lines · Will Deacon
Quoted 13 lines · Paul E. McKenney
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 5 lines
Quoted 1 line
Agreed.
OK, thank you! Would you agree that it would be good to replace the current xor-based fake-dependency litmus tests with tests having real dependencies?
Yes, because it would look a lot more like real (kernel) code.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 16 lines · Paul E. McKenney
Quoted 15 lines · Will Deacon
Quoted 13 lines · Paul E. McKenney
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 5 lines
Quoted 1 line
Agreed.
OK, thank you! Would you agree that it would be good to replace the current xor-based fake-dependency litmus tests with tests having real dependencies?
Yes, because it would look a lot more like real (kernel) code.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 99 lines · Will Deacon
Quoted 72 lines · Paul E. McKenney
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 13 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)Quoted 3 lines
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
I think that's it!
Quoted 14 lines
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 1 line
Agreed.
OK, thank you! Would you agree that it would be good to replace the current xor-based fake-dependency litmus tests with tests having real dependencies?
Thanx, Paul
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 72 lines · Paul E. McKenney
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 13 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 3 lines
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
I think that's it!
Quoted 14 lines
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Agreed.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Paul E. McKenneyQuoted 72 lines · Paul E. McKenney
Quoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 13 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 3 lines
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
I think that's it!
Quoted 14 lines
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Agreed.
Will
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 8 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
Thanx, Paul
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
P0 | P1 | P2 ;
stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ;
| stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Re: [v3,11/41] mips: reuse asm-generic/barrier.h
In reply to Will DeaconQuoted 10 lines · Will Deacon
Quoted 9 lines · Paul E. McKenney
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Will Deacon
See my earlier reply [1] (but also, your WRC Linux example looks more like a variant on WWC and I couldn't really follow it).
I will revisit my WRC Linux example. And yes, creating litmus tests that use non-fake dependencies is still a bit of an undertaking. :-/ I am sure that it will seem more natural with time and experience...
Quoted 5 lines
Quoted 3 lines
Hmmm... You are quite right, I did do WWC. I need to change cpu2()'s last access from a store to a load to get WRC. Plus the levels of indirection definitely didn't match up, did they?
Nope, it was pretty baffling!
"It is a service that I provide." ;-)
Quoted 53 lines
Quoted 28 lines
struct foo { struct foo *next; }; struct foo a; struct foo b; struct foo c = { &a }; struct foo d = { &b }; struct foo x = { &c }; struct foo y = { &d }; struct foo *r1, *r2, *r3; void cpu0(void) { WRITE_ONCE(x.next, &y); } void cpu1(void) { r1 = lockless_dereference(x.next); WRITE_ONCE(r1->next, &x); } void cpu2(void) { r2 = lockless_dereference(y.next); r3 = READ_ONCE(r2->next); }Quoted 7 lines
In this case, it is legal to end the run with:
r1 == &y && r2 == &x && r3 == &cPlease see below for a ppcmem litmus test.
So, did I get it right this time? ;-)
The code above looks correct to me (in that it matches WRC+addrs), but your litmus test:
Quoted 8 lines
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}Quoted 5 lines
P0 | P1 | P2 ; stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ; | stw r2,0(r3) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Quoted 1 line
Seems to be missing the address dependency on P1.
You are quite correct! How about the following?
As before, both herd and ppcmem say that the cycle is allowed, as expected, given non-transitive ordering. To prohibit the cycle, P1 needs a suitable memory-barrier instruction.
Thanx, Paul
------------------------------------------------------------------------
PPC WRCnf+addrs
""
{
0:r2=x; 0:r3=y;
1:r2=x; 1:r3=y;
2:r2=x; 2:r3=y;
c=a; d=b; x=c; y=d;
}
P0 | P1 | P2 ;
stw r3,0(r2) | lwz r8,0(r2) | lwz r8,0(r3) ;
| stw r2,0(r8) | lwz r9,0(r8) ;exists
(1:r8=y /\ 2:r8=x /\ 2:r9=c)
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.