[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150612185919.GA11558@redhat.com>
Date: Fri, 12 Jun 2015 20:59:19 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@...radead.org>, umgwanakikbuti@...il.com,
mingo@...e.hu, ktkhai@...allels.com, rostedt@...dmis.org,
tglx@...utronix.de, juri.lelli@...il.com, pang.xunlei@...aro.org,
wanpeng.li@...ux.intel.com, linux-kernel@...r.kernel.org,
Al Viro <viro@...IV.linux.org.uk>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH 11/18] seqcount: Introduce raw_write_seqcount_barrier()
On 06/11, Paul E. McKenney wrote:
>
> > > + * seqcount_t seq;
> > > + * bool X = true, Y = false;
> > > + *
> > > + * void read(void)
> > > + * {
> > > + * bool x, y;
> > > + *
> > > + * do {
> > > + * int s = read_seqcount_begin(&seq);
> > > + *
> > > + * x = X; y = Y;
> > > + *
> > > + * } while (read_seqcount_retry(&seq, s));
> > > + *
> > > + * BUG_ON(!x && !y);
> > > + * }
> > > + *
> > > + * void write(void)
> > > + * {
> > > + * Y = true;
> > > + *
> > > + * write_seqcount_begin(seq);
> > > + * write_seqcount_end(seq);
> > > + *
> > > + * X = false;
> > > + * }
> >
> > > +static inline void raw_write_seqcount_barrier(seqcount_t *s)
> > > +{
> > > + s->sequence++;
> > > + smp_wmb();
> > > + s->sequence++;
> > > +}
> > > +
> > > /*
> > > * raw_write_seqcount_latch - redirect readers to even/odd copy
> > > * @s: pointer to seqcount_t
> >
> > Looks good otherwise.
> >
> > Reviewed-by: Paul E. McKenney <paulmck@...ux.vnet.ibm.com>
>
> Color me slow and stupid. Maybe due to reviewing a patch too early in
> the morning, who knows?
>
> There is nothing above that prevents the compiler and the CPU from
> reordering the assignments to X and Y with the increment of s->sequence++.
Yes, but this doesn't matter, I think. The writer does
Y = true;
1st_increment;
wmb();
2nd_increment;
X = false;
and we do not care about reordering before or after wmnb() at all. But we
rely on the fact that 1st_increment can not be reordered with "X = false",
and that "Y = true" can not be reordered with the 2nd_increment.
And another simple "proof" is that seqcount_barrier() is equivalent to
write_seqcount_begin() + + write_seqcount_end() and thus the code above
is correct, or the ACQUIRE/RELEASE semantics of seqcount_t is broken ;)
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists