From: Michael Ellerman <mpe@ellerman.id.au>
To: paulmck@kernel.org, Kautuk Consul <kconsul@linux.vnet.ibm.com>
Cc: Rohan McLure <rmclure@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org,
Nicholas Piggin <npiggin@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] arch/powerpc/include/asm/barrier.h: redefine rmb and wmb to lwsync
Date: Thu, 23 Feb 2023 14:51:25 +1100 [thread overview]
Message-ID: <87fsaxavk2.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <20230222174719.GA1400185@paulmck-ThinkPad-P17-Gen-1>
Hi Paul,
"Paul E. McKenney" <paulmck@kernel.org> writes:
> On Wed, Feb 22, 2023 at 02:33:44PM +0530, Kautuk Consul wrote:
>> A link from ibm.com states:
>> "Ensures that all instructions preceding the call to __lwsync
>> complete before any subsequent store instructions can be executed
>> on the processor that executed the function. Also, it ensures that
>> all load instructions preceding the call to __lwsync complete before
>> any subsequent load instructions can be executed on the processor
>> that executed the function. This allows you to synchronize between
>> multiple processors with minimal performance impact, as __lwsync
>> does not wait for confirmation from each processor."
>>
>> Thats why smp_rmb() and smp_wmb() are defined to lwsync.
>> But this same understanding applies to parallel pipeline
>> execution on each PowerPC processor.
>> So, use the lwsync instruction for rmb() and wmb() on the PPC
>> architectures that support it.
>>
>> Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
>> ---
>> arch/powerpc/include/asm/barrier.h | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
>> index b95b666f0374..e088dacc0ee8 100644
>> --- a/arch/powerpc/include/asm/barrier.h
>> +++ b/arch/powerpc/include/asm/barrier.h
>> @@ -36,8 +36,15 @@
>> * heavy-weight sync, so smp_wmb() can be a lighter-weight eieio.
>> */
>> #define __mb() __asm__ __volatile__ ("sync" : : : "memory")
>> +
>> +/* The sub-arch has lwsync. */
>> +#if defined(CONFIG_PPC64) || defined(CONFIG_PPC_E500MC)
>> +#define __rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
>> +#define __wmb() __asm__ __volatile__ ("lwsync" : : : "memory")
>
> Hmmm...
>
> Does the lwsync instruction now order both cached and uncached accesses?
No.
> Or have there been changes so that smp_rmb() and smp_wmb() get this
> definition, while rmb() and wmb() still get the sync instruction?
No.
They come from:
include/asm-generic/barrier.h:#define rmb() do { kcsan_rmb(); __rmb(); } while (0)
include/asm-generic/barrier.h:#define wmb() do { kcsan_wmb(); __wmb(); } while (0)
> (Not seeing this, but I could easily be missing something.)
You are correct, the patch is wrong because it fails to account for IO
accesses.
Kautuk, I'm not sure what motivated you to look at these barriers, was
it just the documentation you linked to?
Maybe we need some better documentation in the kernel explaining why we
use the barriers we do?
Although there's already a pretty decent comment above the definitions,
but maybe it needs further clarification:
/*
* Memory barrier.
* The sync instruction guarantees that all memory accesses initiated
* by this processor have been performed (with respect to all other
* mechanisms that access memory). The eieio instruction is a barrier
* providing an ordering (separately) for (a) cacheable stores and (b)
* loads and stores to non-cacheable memory (e.g. I/O devices).
*
* mb() prevents loads and stores being reordered across this point.
* rmb() prevents loads being reordered across this point.
* wmb() prevents stores being reordered across this point.
*
* *mb() variants without smp_ prefix must order all types of memory
* operations with one another. sync is the only instruction sufficient
* to do this.
*
* For the smp_ barriers, ordering is for cacheable memory operations
* only. We have to use the sync instruction for smp_mb(), since lwsync
* doesn't order loads with respect to previous stores. Lwsync can be
* used for smp_rmb() and smp_wmb().
cheers
next prev parent reply other threads:[~2023-02-23 3:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-22 9:03 [PATCH v2] arch/powerpc/include/asm/barrier.h: redefine rmb and wmb to lwsync Kautuk Consul
2023-02-22 9:30 ` Kautuk Consul
2023-02-22 9:44 ` Christophe Leroy
2023-02-22 9:49 ` Kautuk Consul
2023-02-22 9:43 ` Christophe Leroy
2023-02-22 9:46 ` Kautuk Consul
2023-02-22 9:51 ` Christophe Leroy
2023-02-22 9:55 ` Kautuk Consul
2023-02-22 17:47 ` Paul E. McKenney
2023-02-23 3:51 ` Michael Ellerman [this message]
2023-02-23 4:07 ` Kautuk Consul
2023-02-23 4:43 ` Kautuk Consul
2023-02-23 9:24 ` Michael Ellerman
2023-02-23 4:01 ` Kautuk Consul
2023-02-23 4:16 ` Paul E. McKenney
2023-02-23 4:22 ` Kautuk Consul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fsaxavk2.fsf@mpe.ellerman.id.au \
--to=mpe@ellerman.id.au \
--cc=kconsul@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
--cc=paulmck@kernel.org \
--cc=rmclure@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox