Port-amd64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Why does membar_consumer() do anything on x86_64?



On 11.07.2010 05:19, Dennis Ferguson wrote:
> Hello,
> 
> Unless I'm truly confused, here's what membar_consumer() and membar_producer()
> do on an x86_64 processor:
> 
>     ENTRY(_membar_consumer)
>             LOCK(25)
>             addq    $0, -8(%rsp)
>             ret
>     ENDLABEL(membar_consumer_end)
> 
>     ENTRY(_membar_producer)
>             /* A store is enough */
>             movq    $0, -8(%rsp)
>             ret
>     ENDLABEL(membar_producer_end)
> 
> I'm trying to figure out why membar_consumer() does that, since the useless
> read-modify-write is measurably quite expensive.  I'm also curious why
> membar_producer() is implemented as the useless write.

On amd64, IIRC, there is one exception regarding ordering; a quick
search in the spec says that "Loads may be reordered with older stores
to different locations."

lock instructions have total order (loads and store are not reordered
with lock instructions). As memory barriers always go by 2 (one
consumer/reader, one producer/writer), the lock avoids load/store
reordering to different locations; see 8.2.3.4, "Loads May Be Reordered
with Earlier Stores to Different Locations."

http://www.intel.com/Assets/PDF/manual/253668.pdf

I could get it wrong though, anyway, it seems plausible to me...

Cheers,

-- 
Jean-Yves Migeon
jeanyves.migeon%free.fr@localhost




Home | Main Index | Thread Index | Old Index