Re: frlock and barrier discussion

From: Andrea Arcangeli (andrea@suse.de)
Date: Wed Jan 29 2003 - 20:52:19 EST


On Wed, Jan 29, 2003 at 05:41:33PM -0800, Richard Henderson wrote:
> //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

No it's:

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

you're missing xtimensec is a write.

or this if you prefer:

        spin_lock() / now xtime can't change under us

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

        spin_unlock() / now xtime can change again

and the above is the optimal implementation of the write-side. We
definitely don't want to forbid those reoderings. if gcc or cpu thinks
it's worthwhile they must be allowed to optimize it since it's legal.

I believe wmb() is correct, and mb() is overkill.

Andrea
-
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/



This archive was generated by hypermail 2b29 : Fri Jan 31 2003 - 22:00:23 EST