[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <28447.1568728295@warthog.procyon.org.uk>
Date: Tue, 17 Sep 2019 14:51:35 +0100
From: David Howells <dhowells@...hat.com>
To: Will Deacon <will@...nel.org>
Cc: dhowells@...hat.com, torvalds@...uxfoundation.org,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
peterz@...radead.org
Subject: Re: [RFC][PATCH] pipe: Convert ring to head/tail
Will Deacon <will@...nel.org> wrote:
> > + /* Barrier: head belongs to the write side, so order reading
> > + * the data after reading the head pointer.
> > + */
> > + unsigned int head = READ_ONCE(pipe->head);
>
> Hmm, I don't understand this. Since READ_ONCE() doesn't imply a barrier,
> how are you enforcing the read-read ordering in the CPU?
It does imply a barrier: smp_read_barrier_depends(). I believe that's
> What is the purpose of saying "This may need to insert a barrier"? Can this
> function be overridden or something?
I mean it's arch-dependent whether READ_ONCE() inserts a barrier or not.
> Saying that "This inserts a barrier" feels misleading, because READ_ONCE()
> doesn't do that.
Yes it does - on the Alpha:
[arch/alpha/include/asm/barrier.h]
#define read_barrier_depends() __asm__ __volatile__("mb": : :"memory")
[include/asm-generic/barrier.h]
#ifndef __smp_read_barrier_depends
#define __smp_read_barrier_depends() read_barrier_depends()
#endif
...
#ifndef smp_read_barrier_depends
#define smp_read_barrier_depends() __smp_read_barrier_depends()
#endif
[include/linux/compiler.h]
#define __READ_ONCE(x, check) \
({ \
union { typeof(x) __val; char __c[1]; } __u; \
if (check) \
__read_once_size(&(x), __u.__c, sizeof(x)); \
else \
__read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \
smp_read_barrier_depends(); /* Enforce dependency ordering from x */ \
__u.__val; \
})
#define READ_ONCE(x) __READ_ONCE(x, 1)
See:
commit 76ebbe78f7390aee075a7f3768af197ded1bdfbb
Author: Will Deacon <will.deacon@....com>
Date: Tue Oct 24 11:22:47 2017 +0100
locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE()
David
Powered by blists - more mailing lists