Re: spin_unlock optimization(i386)

Brian Kelly (bkelly@sulaco.com)
Thu, 25 Nov 1999 11:09:47 GMT


Linus wrote:
>HOWEVER, we have a slightly different situation here:
>
> CPU 1 CPU 2
>
> read b
> a = 0
> read a, see 0
> write b
>
>Note how both CPU's only did ONE write. That one write does not have any
>real "order", and really write ordering is not an issue AT ALL.
>
>In physics, this issue is called "causality" rather than "order", and I
>don't think the issue has really been clarified.
>
>Basically, everybody agrees on ordering of writes. Intel keeps them in
>order.
>
>What I still find to be the weak point of all the arguments both ways is
>that I still have NOT seen any real proof that CPU#1 could not see the
>"future" write of "b". In short, without a synchronizing instruction I
>don't trust causality - even though I trust order.

I think this concern is addressed (though hardly explicitly) by the
following two sections (in two different manuals!!!):

In section 7.2.2 of the System Programming manual, rule 5 states:

"5. Writes are not performed speculatively; they are only performed for
instructions that have actually been retired"

In section 2.5.5 of the Basic Architecture manual it states:

"It [the retirement unit] then retires completed micro-ops in their original
program oder, taking into account interrupts, exceptions, breakpoints and
branch mis-predictions"

So if I read this correctly, the read instruction (which includes the
actual read from memory) will have been retired before the write is
actually performed so in Linus' example, the actual read associated with
'read b' on CPU #1 can never happen after the actual write associated with
'a = 0' is performed so it can never see the "future" write of "b".

If my reading of this is correct, then it could have been covered by a
new rule (call it 2a) in section 7.2.2 of the System Programming manual:
"2a. Writes cannot pass reads"

Brian

-- 
ObAFUFAQ: F. Couple w/baby on long trip stops to switch places;
             place baby on roof; they forget it up there! Police
             cruiser pull them over and baby is rescued.  ["The
             Baby on the Roof" in TCD.]

bkelly@sulaco.com

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