Re: frlock and barrier discussion

Richard Henderson (rth@twiddle.net)
Wed, 29 Jan 2003 17:41:33 -0800


On Wed, Jan 29, 2003 at 05:15:55PM -0800, Stephen Hemminger wrote:
> First, write_begin/end can only be safely used when there is separate
> writer synchronization such as a spin_lock or semaphore.
> As far as I know, semaphore or spin_lock guarantees a barrier.
> So xtime or anything else can not be read before the spin_lock.
>
> Using mb() is more paranoid than necessary.

If you want stuff to happen *between* the write_begin/end, or
indeed for the begin/end not to be interleaved, then mb() is
absolutely necessary. The most likely dynamic reordering of

//begin
t1 = rw->pre_sequence
t1 += 1
rw->pre_sequence = t1
wmb()

//stuff
xtimensec = xtime.tv_nsec

//end
wmb()
t2 = rw->post_sequence
t2 += 1
rw->post_sequence = t2

is

t1 = rw->pre_sequence
t2 = rw->post_sequence
xtimensec = xtime.tv_nsec
t1 += 1;
t2 += 2;
rw->pre_sequence = t1
wmb()
wmb()
rw->post_sequence = t2

Why? Because pre_sequence and post_sequence are in the same
cache line, and both reads could be satisfied in the same
cycle by the same line fill from main memory.

If you don't care about stuff happening in between the
write_begin/end, then why are you using them at all?

r~
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/