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 07:59, Dennis Ferguson wrote:
> I'm sure you are right that loads can be reordered with respect to stores,
> so I'd expect membar_enter() and membar_sync(), and maybe membar_exit(), to
> actually do something since (according to the man page) those functions
> worry about the ordering of loads against stores.
> 
> I don't need these, though.  I have one write-only guy running concurrently
> with N read-only guys, so the write-only guy only cares about the ordering
> of stores while the read-only guys only care about the ordering of loads.
> Since membar_consumer() (according to the man page) protects against
> the reordering of loads alone, and membar_producer() protects against
> the reordering of stores alone, these seem to be the functions I need
> to use.  Since load-only and store-only order are also things that Intel
> processors guarantee will happen if you don't do anything at all (other
> architectures don't guarantee that, though, which is why I might want to
> call these functions anyway), it still doesn't make sense to me why
> membar_consumer() and membar_producer() in particular would need to do
> anything at all on Intel CPUs.

Agreed, although notice that membar_enter() is aliased to
membar_consumer() in atomic.S, for amd64.

  membar_enter()
      Any store preceeding membar_enter() will reach global visibility
      before all loads and stores following it.

The lock is needed, or else the loads that could follow may get
reordered (when writing to different locations, of course), and be
visible before the store.

For the rest:

- I don't know why membar_consumer and membar_enter are aliased

- for i386, Solaris adds a lock for all memory barriers, while Linux
only does that for its rmb() (it seems to provide less membar_ops than
Solaris or NetBSD). The wmb is ~ a noop, except for x86 OOSTORE.

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/common/atomic/i386/atomic.s

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=include/asm-i386/system.h;h=d69ba937e09251769e2f00d54c0c91562a4127e8;hb=4827bbb06e4b59922c2b9bfb13ad1bf936bdebe5

- According to anandtech, P6 (and P-M) may reorder loads, via the ROB
(ReOrder Buffer):

http://www.anandtech.com/show/1998/5

Cheers,

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




Home | Main Index | Thread Index | Old Index