* [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 1:28 ` [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier Paul E. McKenney
@ 2013-12-10 1:28 ` Paul E. McKenney
2013-12-10 1:34 ` Josh Triplett
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 1:28 UTC (permalink / raw)
To: linux-kernel
Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw,
Paul E. McKenney, Linux-Arch, Ingo Molnar, Oleg Nesterov,
Linus Torvalds
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
The Linux kernel has traditionally required that an UNLOCK+LOCK pair
act as a full memory barrier when either (1) that UNLOCK+LOCK pair
was executed by the same CPU or task, or (2) the same lock variable
was used for the UNLOCK and LOCK. It now seems likely that very few
places in the kernel rely on this full-memory-barrier semantic, and
with the advent of queued locks, providing this semantic either requires
complex reasoning, or for some architectures, added overhead.
This commit therefore adds a smp_mb__after_unlock_lock(), which may be
placed after a LOCK primitive to restore the full-memory-barrier semantic.
All definitions are currently no-ops, but will be upgraded for some
architectures when queued locks arrive.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linux-Arch <linux-arch@vger.kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
arch/arm/include/asm/barrier.h | 2 ++
arch/arm64/include/asm/barrier.h | 2 ++
arch/ia64/include/asm/barrier.h | 2 ++
arch/metag/include/asm/barrier.h | 2 ++
arch/mips/include/asm/barrier.h | 2 ++
arch/powerpc/include/asm/barrier.h | 2 ++
arch/s390/include/asm/barrier.h | 2 ++
arch/sparc/include/asm/barrier_64.h | 2 ++
arch/x86/include/asm/barrier.h | 2 ++
include/asm-generic/barrier.h | 2 ++
10 files changed, 20 insertions(+)
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
index 2f59f7443396..133aa543dfdb 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -74,6 +74,8 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#define read_barrier_depends() do { } while(0)
#define smp_read_barrier_depends() do { } while(0)
diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
index 78e20ba8806b..f97efda22e0a 100644
--- a/arch/arm64/include/asm/barrier.h
+++ b/arch/arm64/include/asm/barrier.h
@@ -91,6 +91,8 @@ do { \
#endif
+#define smp_mb__after_unlock_lock() do { } while 0
+
#define read_barrier_depends() do { } while(0)
#define smp_read_barrier_depends() do { } while(0)
diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
index bddcfe91d9c8..fb64ead98e65 100644
--- a/arch/ia64/include/asm/barrier.h
+++ b/arch/ia64/include/asm/barrier.h
@@ -101,6 +101,8 @@ do { \
})
#endif
+#define smp_mb__after_unlock_lock() do { } while (0)
+
/*
* XXX check on this ---I suspect what Linus really wants here is
* acquire vs release semantics but we can't discuss this stuff with
diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
index 5d6b4b407dda..76a3ff950607 100644
--- a/arch/metag/include/asm/barrier.h
+++ b/arch/metag/include/asm/barrier.h
@@ -97,4 +97,6 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* _ASM_METAG_BARRIER_H */
diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
index e1aa4e4c2984..6f9b586241d6 100644
--- a/arch/mips/include/asm/barrier.h
+++ b/arch/mips/include/asm/barrier.h
@@ -195,4 +195,6 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* __ASM_BARRIER_H */
diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
index f89da808ce31..abf645799991 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -84,4 +84,6 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* _ASM_POWERPC_BARRIER_H */
diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
index 578680f6207a..c8f12244aed3 100644
--- a/arch/s390/include/asm/barrier.h
+++ b/arch/s390/include/asm/barrier.h
@@ -47,4 +47,6 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* __ASM_BARRIER_H */
diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
index b5aad964558e..a2b73329f89c 100644
--- a/arch/sparc/include/asm/barrier_64.h
+++ b/arch/sparc/include/asm/barrier_64.h
@@ -68,4 +68,6 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* !(__SPARC64_BARRIER_H) */
diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index f7053f354ac3..0371fd15f7ee 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -115,6 +115,8 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
/*
* Stop RDTSC speculation. This is needed when you need to use RDTSC
* (or get_cycles or vread that possibly accesses the TSC) in a defined
diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
index 6f692f8ac664..938ecf3a7cd8 100644
--- a/include/asm-generic/barrier.h
+++ b/include/asm-generic/barrier.h
@@ -77,5 +77,7 @@ do { \
___p1; \
})
+#define smp_mb__after_unlock_lock() do { } while (0)
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_GENERIC_BARRIER_H */
--
1.8.1.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 1:28 ` [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier Paul E. McKenney
2013-12-10 1:28 ` Paul E. McKenney
@ 2013-12-10 1:34 ` Josh Triplett
2013-12-10 5:26 ` Paul E. McKenney
2013-12-10 12:37 ` Peter Zijlstra
2013-12-10 17:04 ` Oleg Nesterov
3 siblings, 1 reply; 14+ messages in thread
From: Josh Triplett @ 2013-12-10 1:34 UTC (permalink / raw)
To: Paul E. McKenney
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
niv, tglx, peterz, rostedt, dhowells, edumazet, darren, fweisbec,
sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov, Linus Torvalds
On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
>
> The Linux kernel has traditionally required that an UNLOCK+LOCK pair
> act as a full memory barrier when either (1) that UNLOCK+LOCK pair
> was executed by the same CPU or task, or (2) the same lock variable
> was used for the UNLOCK and LOCK. It now seems likely that very few
> places in the kernel rely on this full-memory-barrier semantic, and
> with the advent of queued locks, providing this semantic either requires
> complex reasoning, or for some architectures, added overhead.
>
> This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> placed after a LOCK primitive to restore the full-memory-barrier semantic.
> All definitions are currently no-ops, but will be upgraded for some
> architectures when queued locks arrive.
>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> Cc: Linux-Arch <linux-arch@vger.kernel.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
It seems quite unfortunate that this isn't in some common location, and
then only overridden by architectures that need to do so.
More importantly: you document this earlier in the patch series than you
introduce it.
- Josh Triplett
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 1:34 ` Josh Triplett
@ 2013-12-10 5:26 ` Paul E. McKenney
2013-12-10 18:53 ` Paul E. McKenney
0 siblings, 1 reply; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 5:26 UTC (permalink / raw)
To: Josh Triplett
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
niv, tglx, peterz, rostedt, dhowells, edumazet, darren, fweisbec,
sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov, Linus Torvalds
On Mon, Dec 09, 2013 at 05:34:17PM -0800, Josh Triplett wrote:
> On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> > From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> >
> > The Linux kernel has traditionally required that an UNLOCK+LOCK pair
> > act as a full memory barrier when either (1) that UNLOCK+LOCK pair
> > was executed by the same CPU or task, or (2) the same lock variable
> > was used for the UNLOCK and LOCK. It now seems likely that very few
> > places in the kernel rely on this full-memory-barrier semantic, and
> > with the advent of queued locks, providing this semantic either requires
> > complex reasoning, or for some architectures, added overhead.
> >
> > This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> > placed after a LOCK primitive to restore the full-memory-barrier semantic.
> > All definitions are currently no-ops, but will be upgraded for some
> > architectures when queued locks arrive.
> >
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > Cc: Linux-Arch <linux-arch@vger.kernel.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Linus Torvalds <torvalds@linux-foundation.org>
>
> It seems quite unfortunate that this isn't in some common location, and
> then only overridden by architectures that need to do so.
I was thinking that include/asm-generic/barrier.h was the place, but
it is all-or-nothing, used by UP architectures, from what I can see.
I figured that if there is such a common location, posting this patch
might flush it out. I am not sure that this single definition is worth
the creation of a common place -- or even this definition combined with
smp_read_barrier_depends().
> More importantly: you document this earlier in the patch series than you
> introduce it.
Fair point, I reversed the order of those two patches.
Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 5:26 ` Paul E. McKenney
@ 2013-12-10 18:53 ` Paul E. McKenney
0 siblings, 0 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 18:53 UTC (permalink / raw)
To: Josh Triplett
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
niv, tglx, peterz, rostedt, dhowells, edumazet, darren, fweisbec,
sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov, Linus Torvalds
On Mon, Dec 09, 2013 at 09:26:41PM -0800, Paul E. McKenney wrote:
> On Mon, Dec 09, 2013 at 05:34:17PM -0800, Josh Triplett wrote:
> > On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> > > From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> > >
> > > The Linux kernel has traditionally required that an UNLOCK+LOCK pair
> > > act as a full memory barrier when either (1) that UNLOCK+LOCK pair
> > > was executed by the same CPU or task, or (2) the same lock variable
> > > was used for the UNLOCK and LOCK. It now seems likely that very few
> > > places in the kernel rely on this full-memory-barrier semantic, and
> > > with the advent of queued locks, providing this semantic either requires
> > > complex reasoning, or for some architectures, added overhead.
> > >
> > > This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> > > placed after a LOCK primitive to restore the full-memory-barrier semantic.
> > > All definitions are currently no-ops, but will be upgraded for some
> > > architectures when queued locks arrive.
> > >
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > Cc: Linux-Arch <linux-arch@vger.kernel.org>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Peter Zijlstra <peterz@infradead.org>
> > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > Cc: Linus Torvalds <torvalds@linux-foundation.org>
> >
> > It seems quite unfortunate that this isn't in some common location, and
> > then only overridden by architectures that need to do so.
>
> I was thinking that include/asm-generic/barrier.h was the place, but
> it is all-or-nothing, used by UP architectures, from what I can see.
> I figured that if there is such a common location, posting this patch
> might flush it out. I am not sure that this single definition is worth
> the creation of a common place -- or even this definition combined with
> smp_read_barrier_depends().
And of course the right place to put this is include/linux/spinlock.h,
the same place where smp_mb__before_spinlock() is defined. Exceptions
then go into the corresponding arch-specific spinlock.h files.
Much better that way, thank you for calling this out!
Thanx, Paul
> > More importantly: you document this earlier in the patch series than you
> > introduce it.
>
> Fair point, I reversed the order of those two patches.
>
> Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 1:28 ` [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier Paul E. McKenney
2013-12-10 1:28 ` Paul E. McKenney
2013-12-10 1:34 ` Josh Triplett
@ 2013-12-10 12:37 ` Peter Zijlstra
2013-12-10 17:17 ` Paul E. McKenney
2013-12-10 17:45 ` Josh Triplett
2013-12-10 17:04 ` Oleg Nesterov
3 siblings, 2 replies; 14+ messages in thread
From: Peter Zijlstra @ 2013-12-10 12:37 UTC (permalink / raw)
To: Paul E. McKenney
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, rostedt, dhowells, edumazet, darren, fweisbec,
sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov, Linus Torvalds
On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
> index f89da808ce31..abf645799991 100644
> --- a/arch/powerpc/include/asm/barrier.h
> +++ b/arch/powerpc/include/asm/barrier.h
> @@ -84,4 +84,6 @@ do { \
> ___p1; \
> })
>
> +#define smp_mb__after_unlock_lock() do { } while (0)
> +
> #endif /* _ASM_POWERPC_BARRIER_H */
Didn't ben said ppc actually violates the current unlock+lock assumtion
and therefore this barrier woulnd't actually be a nop on ppc
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 12:37 ` Peter Zijlstra
@ 2013-12-10 17:17 ` Paul E. McKenney
2013-12-10 17:45 ` Josh Triplett
1 sibling, 0 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 17:17 UTC (permalink / raw)
To: Peter Zijlstra
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, rostedt, dhowells, edumazet, darren, fweisbec,
sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov, Linus Torvalds, benh
On Tue, Dec 10, 2013 at 01:37:26PM +0100, Peter Zijlstra wrote:
> On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> > diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
> > index f89da808ce31..abf645799991 100644
> > --- a/arch/powerpc/include/asm/barrier.h
> > +++ b/arch/powerpc/include/asm/barrier.h
> > @@ -84,4 +84,6 @@ do { \
> > ___p1; \
> > })
> >
> > +#define smp_mb__after_unlock_lock() do { } while (0)
> > +
> > #endif /* _ASM_POWERPC_BARRIER_H */
>
> Didn't ben said ppc actually violates the current unlock+lock assumtion
> and therefore this barrier woulnd't actually be a nop on ppc
Last I knew, I was saying that it did in theory, but wasn't able to
demonstrate it in practice. But yes, I would be more comfortable with
it being smp_mb().
Ben?
Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 12:37 ` Peter Zijlstra
2013-12-10 17:17 ` Paul E. McKenney
@ 2013-12-10 17:45 ` Josh Triplett
2013-12-10 20:11 ` Paul E. McKenney
1 sibling, 1 reply; 14+ messages in thread
From: Josh Triplett @ 2013-12-10 17:45 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Paul E. McKenney, linux-kernel, mingo, laijs, dipankar, akpm,
mathieu.desnoyers, niv, tglx, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov,
Linus Torvalds
On Tue, Dec 10, 2013 at 01:37:26PM +0100, Peter Zijlstra wrote:
> On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> > diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
> > index f89da808ce31..abf645799991 100644
> > --- a/arch/powerpc/include/asm/barrier.h
> > +++ b/arch/powerpc/include/asm/barrier.h
> > @@ -84,4 +84,6 @@ do { \
> > ___p1; \
> > })
> >
> > +#define smp_mb__after_unlock_lock() do { } while (0)
> > +
> > #endif /* _ASM_POWERPC_BARRIER_H */
>
> Didn't ben said ppc actually violates the current unlock+lock assumtion
> and therefore this barrier woulnd't actually be a nop on ppc
Or, ppc could fix its lock primitives to preserve the unlock+lock
assumption, and avoid subtle breakage across half the kernel.
- Josh Triplett
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 17:45 ` Josh Triplett
@ 2013-12-10 20:11 ` Paul E. McKenney
0 siblings, 0 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 20:11 UTC (permalink / raw)
To: Josh Triplett
Cc: Peter Zijlstra, linux-kernel, mingo, laijs, dipankar, akpm,
mathieu.desnoyers, niv, tglx, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Oleg Nesterov,
Linus Torvalds
On Tue, Dec 10, 2013 at 09:45:08AM -0800, Josh Triplett wrote:
> On Tue, Dec 10, 2013 at 01:37:26PM +0100, Peter Zijlstra wrote:
> > On Mon, Dec 09, 2013 at 05:28:02PM -0800, Paul E. McKenney wrote:
> > > diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
> > > index f89da808ce31..abf645799991 100644
> > > --- a/arch/powerpc/include/asm/barrier.h
> > > +++ b/arch/powerpc/include/asm/barrier.h
> > > @@ -84,4 +84,6 @@ do { \
> > > ___p1; \
> > > })
> > >
> > > +#define smp_mb__after_unlock_lock() do { } while (0)
> > > +
> > > #endif /* _ASM_POWERPC_BARRIER_H */
> >
> > Didn't ben said ppc actually violates the current unlock+lock assumtion
> > and therefore this barrier woulnd't actually be a nop on ppc
>
> Or, ppc could fix its lock primitives to preserve the unlock+lock
> assumption, and avoid subtle breakage across half the kernel.
Indeed. However, another motivation for this change was the difficulty
in proving that x86 really provided the equivalent of a full barrier
for the MCS lock handoff case:
http://www.spinics.net/lists/linux-mm/msg65653.html
Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 1:28 ` [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier Paul E. McKenney
` (2 preceding siblings ...)
2013-12-10 12:37 ` Peter Zijlstra
@ 2013-12-10 17:04 ` Oleg Nesterov
2013-12-10 17:18 ` Paul E. McKenney
3 siblings, 1 reply; 14+ messages in thread
From: Oleg Nesterov @ 2013-12-10 17:04 UTC (permalink / raw)
To: Paul E. McKenney
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, peterz, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Linus Torvalds
On 12/09, Paul E. McKenney wrote:
>
> This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> placed after a LOCK primitive to restore the full-memory-barrier semantic.
> All definitions are currently no-ops, but will be upgraded for some
> architectures when queued locks arrive.
I am wondering, perhaps smp_mb__after_unlock() makes more sense?
Note that it already has the potential user:
--- x/kernel/sched/wait.c
+++ x/kernel/sched/wait.c
@@ -176,8 +176,9 @@ prepare_to_wait(wait_queue_head_t *q, wa
spin_lock_irqsave(&q->lock, flags);
if (list_empty(&wait->task_list))
__add_wait_queue(q, wait);
- set_current_state(state);
+ __set_current_state(state);
spin_unlock_irqrestore(&q->lock, flags);
+ smp_mb__after_unlock();
}
EXPORT_SYMBOL(prepare_to_wait);
@@ -190,8 +191,9 @@ prepare_to_wait_exclusive(wait_queue_hea
spin_lock_irqsave(&q->lock, flags);
if (list_empty(&wait->task_list))
__add_wait_queue_tail(q, wait);
- set_current_state(state);
+ __set_current_state(state);
spin_unlock_irqrestore(&q->lock, flags);
+ smp_mb__after_unlock();
}
EXPORT_SYMBOL(prepare_to_wait_exclusive);
Assuming it can also be used "later", after another LOCK, like in
your example in 5/7.
Oleg.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 17:04 ` Oleg Nesterov
@ 2013-12-10 17:18 ` Paul E. McKenney
2013-12-10 17:18 ` Paul E. McKenney
2013-12-10 17:32 ` Oleg Nesterov
0 siblings, 2 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 17:18 UTC (permalink / raw)
To: Oleg Nesterov
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, peterz, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Linus Torvalds
On Tue, Dec 10, 2013 at 06:04:04PM +0100, Oleg Nesterov wrote:
> On 12/09, Paul E. McKenney wrote:
> >
> > This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> > placed after a LOCK primitive to restore the full-memory-barrier semantic.
> > All definitions are currently no-ops, but will be upgraded for some
> > architectures when queued locks arrive.
>
> I am wondering, perhaps smp_mb__after_unlock() makes more sense?
>
> Note that it already has the potential user:
>
> --- x/kernel/sched/wait.c
> +++ x/kernel/sched/wait.c
> @@ -176,8 +176,9 @@ prepare_to_wait(wait_queue_head_t *q, wa
> spin_lock_irqsave(&q->lock, flags);
> if (list_empty(&wait->task_list))
> __add_wait_queue(q, wait);
> - set_current_state(state);
> + __set_current_state(state);
> spin_unlock_irqrestore(&q->lock, flags);
> + smp_mb__after_unlock();
> }
> EXPORT_SYMBOL(prepare_to_wait);
>
> @@ -190,8 +191,9 @@ prepare_to_wait_exclusive(wait_queue_hea
> spin_lock_irqsave(&q->lock, flags);
> if (list_empty(&wait->task_list))
> __add_wait_queue_tail(q, wait);
> - set_current_state(state);
> + __set_current_state(state);
> spin_unlock_irqrestore(&q->lock, flags);
> + smp_mb__after_unlock();
> }
> EXPORT_SYMBOL(prepare_to_wait_exclusive);
>
>
> Assuming it can also be used "later", after another LOCK, like in
> your example in 5/7.
I am fine either way. But there was an objection to tying this to the
unlock because it costs more on many architectures than tying this to
the lock.
But if you are saying "in addition to" rather than "instead of" that
would be a different conversation.
Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 17:18 ` Paul E. McKenney
@ 2013-12-10 17:18 ` Paul E. McKenney
2013-12-10 17:32 ` Oleg Nesterov
1 sibling, 0 replies; 14+ messages in thread
From: Paul E. McKenney @ 2013-12-10 17:18 UTC (permalink / raw)
To: Oleg Nesterov
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, peterz, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Linus Torvalds
On Tue, Dec 10, 2013 at 06:04:04PM +0100, Oleg Nesterov wrote:
> On 12/09, Paul E. McKenney wrote:
> >
> > This commit therefore adds a smp_mb__after_unlock_lock(), which may be
> > placed after a LOCK primitive to restore the full-memory-barrier semantic.
> > All definitions are currently no-ops, but will be upgraded for some
> > architectures when queued locks arrive.
>
> I am wondering, perhaps smp_mb__after_unlock() makes more sense?
>
> Note that it already has the potential user:
>
> --- x/kernel/sched/wait.c
> +++ x/kernel/sched/wait.c
> @@ -176,8 +176,9 @@ prepare_to_wait(wait_queue_head_t *q, wa
> spin_lock_irqsave(&q->lock, flags);
> if (list_empty(&wait->task_list))
> __add_wait_queue(q, wait);
> - set_current_state(state);
> + __set_current_state(state);
> spin_unlock_irqrestore(&q->lock, flags);
> + smp_mb__after_unlock();
> }
> EXPORT_SYMBOL(prepare_to_wait);
>
> @@ -190,8 +191,9 @@ prepare_to_wait_exclusive(wait_queue_hea
> spin_lock_irqsave(&q->lock, flags);
> if (list_empty(&wait->task_list))
> __add_wait_queue_tail(q, wait);
> - set_current_state(state);
> + __set_current_state(state);
> spin_unlock_irqrestore(&q->lock, flags);
> + smp_mb__after_unlock();
> }
> EXPORT_SYMBOL(prepare_to_wait_exclusive);
>
>
> Assuming it can also be used "later", after another LOCK, like in
> your example in 5/7.
I am fine either way. But there was an objection to tying this to the
unlock because it costs more on many architectures than tying this to
the lock.
But if you are saying "in addition to" rather than "instead of" that
would be a different conversation.
Thanx, Paul
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v5 tip/core/locking 6/7] locking: Add an smp_mb__after_unlock_lock() for UNLOCK+LOCK barrier
2013-12-10 17:18 ` Paul E. McKenney
2013-12-10 17:18 ` Paul E. McKenney
@ 2013-12-10 17:32 ` Oleg Nesterov
1 sibling, 0 replies; 14+ messages in thread
From: Oleg Nesterov @ 2013-12-10 17:32 UTC (permalink / raw)
To: Paul E. McKenney
Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
josh, niv, tglx, peterz, rostedt, dhowells, edumazet, darren,
fweisbec, sbw, Linux-Arch, Ingo Molnar, Linus Torvalds
On 12/10, Paul E. McKenney wrote:
>
> On Tue, Dec 10, 2013 at 06:04:04PM +0100, Oleg Nesterov wrote:
> >
> > I am wondering, perhaps smp_mb__after_unlock() makes more sense?
> >
> > Note that it already has the potential user:
> >
> > --- x/kernel/sched/wait.c
> > +++ x/kernel/sched/wait.c
> > @@ -176,8 +176,9 @@ prepare_to_wait(wait_queue_head_t *q, wa
> > spin_lock_irqsave(&q->lock, flags);
> > if (list_empty(&wait->task_list))
> > __add_wait_queue(q, wait);
> > - set_current_state(state);
> > + __set_current_state(state);
> > spin_unlock_irqrestore(&q->lock, flags);
> > + smp_mb__after_unlock();
> > }
> > EXPORT_SYMBOL(prepare_to_wait);
> >
> > @@ -190,8 +191,9 @@ prepare_to_wait_exclusive(wait_queue_hea
> > spin_lock_irqsave(&q->lock, flags);
> > if (list_empty(&wait->task_list))
> > __add_wait_queue_tail(q, wait);
> > - set_current_state(state);
> > + __set_current_state(state);
> > spin_unlock_irqrestore(&q->lock, flags);
> > + smp_mb__after_unlock();
> > }
> > EXPORT_SYMBOL(prepare_to_wait_exclusive);
> >
> >
> > Assuming it can also be used "later", after another LOCK, like in
> > your example in 5/7.
>
> I am fine either way. But there was an objection to tying this to the
> unlock because it costs more on many architectures than tying this to
> the lock.
OK, I see, thanks.
> But if you are saying "in addition to" rather than "instead of" that
> would be a different conversation.
Yes, please forget for now.
Oleg.
^ permalink raw reply [flat|nested] 14+ messages in thread