lkml.org 
[lkml]   [2015]   [Apr]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 05/10] seqlock: Better document raw_write_seqcount_latch()
On Mon, Apr 13, 2015 at 05:08:19PM +0000, Mathieu Desnoyers wrote:
> ----- Original Message -----
> >
> > * Peter Zijlstra <peterz@infradead.org> wrote:
> >
> [...]
> > > + * The query will have a form like:
> > > + *
> > > + * struct entry *latch_query(struct latch_struct *latch, ...)
> > > + * {
> > > + * struct entry *entry;
> > > + * unsigned seq, idx;
> > > + *
> > > + * do {
> > > + * seq = latch->seq;
> > > + * smp_rmb();
> > > + *
> > > + * idx = seq & 0x01;
> > > + * entry = data_query(latch->data[idx], ...);
> > > + *
> > > + * smp_rmb();
> > > + * } while (seq != latch->seq);
> >
> > Btw., I realize this is just a sample, but couldn't this be written
> > more optimally as:
> >
> > do {
> > seq = READ_ONCE(latch->seq);
> > smp_read_barrier_depends();
> >
> > idx = seq & 0x01;
> > entry = data_query(latch->data[idx], ...);
> >
> > smp_rmb();
> > } while (seq != latch->seq);
> >
> > Note that there's just a single smp_rmb() barrier: the READ_ONCE() is
> > there to make sure GCC doesn't calculate 'idx' from two separate
> > reads, but otherwise there's a direct data dependency on latch->seq so
> > no smp_rmb() is needed, only a data dependency barrier when doing the
> > first lookup AFAICS?
> >
> > (This doesn't matter on x86 where smp_rmb() is barrier().)
>
> The latch evolved from seqlock.h, where there was no
> data dependency between the sequence counter and the
> data read, hence the smp_rmb(). Indeed, there is a
> data dependency in the case of the latch, so I think
> your approach of READ_ONCE + smp_read_barrier_depends()
> is appropriate.

A shorthand for READ_ONCE + smp_read_barrier_depends() is the shiny
new lockless_dereference(). This helps readability, as it is often
non-trivial to work out which accesses smp_read_barrier_depends() is
helping to order.

Thanx, Paul



\
 
 \ /
  Last update: 2015-04-13 20:21    [W:0.100 / U:28.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site