lkml.org 
[lkml]   [2003]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: frlock and barrier discussion
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/

\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.059 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site