lkml.org 
[lkml]   [2006]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Memory barriers and spin_unlock safety


On Fri, 3 Mar 2006, Linus Torvalds wrote:
>
> I suspect you have some bug in your implementation. I think Dekker's
> algorithm depends on the reads and writes being ordered, and you don't
> seem to do that.

IOW, I think you need a full memory barrier after the
"lock->turn = cpu ^ 1;"
and you should have a "smp_rmb()" in between your reads of
"lock->flags[cpu ^ 1]"
and
"lock->turn"
to give the ordering that Dekker (or Peterson) expects.

IOW, the code should be something like

lock->flags[other] = 1;
smp_wmb();
lock->turn = other
smp_mb();
while (lock->turn == cpu) {
smp_rmb();
if (!lock->flags[other])
break;
}

where the wmb's are no-ops on x86, but the rmb's certainly are not.

I _suspect_ that the fact that it starts working with an 'sfence' in there
somewhere is just because the sfence ends up being "serializing enough"
that it just happens to work, but that it has nothing to do with the
current kernel wmb() being wrong.

Linus
-
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: 2009-11-18 23:46    [W:0.040 / U:1.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site