public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Memory Barrier Definitions
@ 2002-05-07 19:07 Dave Engebretsen
  2002-05-07 19:49 ` Alan Cox
  0 siblings, 1 reply; 23+ messages in thread
From: Dave Engebretsen @ 2002-05-07 19:07 UTC (permalink / raw)
  To: linux-kernel

Hi,

I have been working through a number of issues that became significant
on Power4 based systems, and wanted to start some discussion to
understand which other platforms are impacted in a similar way.  

The fundamental issue is that Power4 is weakly consistent and the
PowerPC architecture definitions for memory reference ordering do not
necessarily mesh well with the current Linux barrier primitive use. 
Obviously, we are not the only weakc platform, but I suspect the degree
and latencies we see push things more than most systems.  What is less
clear to me is how much PPC memory barrier symantics have in common with
other systems; presumably there are some which are similar.

As a specific example, on PowerPC the following memory barriers are
defined:

eieio: Orders all I/O references & store/store to system memory, but
seperatly
lwsync: Orders load/load, store/store, and load/store, only to system
memory 
sync: Orders everything

In terms of cycles, eieio is relatively cheap, lwsync is perhaps 100's,
while sync is measured in the 1000's.  The key is that only a sync
orders both system memory and I/O space references and it is very
expensive, so it should only be used where absolutely necessary, like in
a driver.

Linux defines (more or less) the following barriers:
mb, rmb, wmb, smp_mb, smp_wmb, smp_rmb

An example of where these primitives get us into trouble is the use of
wmb() to order two stores which are only to system memory (where a
lwsync would do for ppc64) and for a store to system memory followed by
a store to I/O (many examples in drivers).  Here ppc64 requires a sync. 
Therefore we must always pay the high price and use a sync for wmb().

A solution was pointed out by Rusty Russell that we should probabily be
using smp_*mb() for system memory ordering and reserve the *mb() calls
for when ordering against I/O is also required.  There does seem to be
some limited cases where this has been done, but in general *mb() are
used in most parts of the kernel.

Any thoughts if making better use of the smp_* macros would be the right
approach?

Thanks -

Dave Engebretsen

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: Memory Barrier Definitions
@ 2002-05-09 11:33 Manfred Spraul
  2002-05-09 19:38 ` Dave Engebretsen
  0 siblings, 1 reply; 23+ messages in thread
From: Manfred Spraul @ 2002-05-09 11:33 UTC (permalink / raw)
  To: Dave Engebretsen, linux-kernel

 	
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

>
> An example of where these primitives get us into trouble is the use of
> wmb() to order two stores which are only to system memory (where a
> lwsync would do for ppc64) and for a store to system memory followed by
> a store to I/O (many examples in drivers).
>
2 questions:

1) Does that only affect memory barriers, or both memory barriers and
spinlocks?

example (from drivers/net/natsemi.c)

cpu0:
	spin_lock(&lock);
	writew(1, ioaddr+PGSEL);
	...
	writew(0, ioaddr+PGSEL);
	spin_unlock(&lock);

cpu1:
	spin_lock(&lock);
	readw(ioaddr+whatever);	// assumes that the register window is 0.

writew(1, ioaddr+PGSEL) selects a register window of the NIC. Are writew
and the spinlock synchonized on ppc64?

2) when you write "system memory", is that memory allocated with
kmalloc/gfp, or also memory allocated with pci_alloc_consistent()?

I've always assumed that
	pci_alloc_consistent_ptr->data=0;
	writew(0, ioaddr+TRIGGER);

is ordered, i.e. the memory write happens before the writew. Is that
guaranteed?

--
	Manfred

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2002-05-13 23:25 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-07 19:07 Memory Barrier Definitions Dave Engebretsen
2002-05-07 19:49 ` Alan Cox
2002-05-07 19:53   ` Dave Engebretsen
2002-05-07 20:27     ` Alan Cox
2002-05-07 21:23       ` Dave Engebretsen
2002-05-07 22:15       ` justincarlson
2002-05-08  2:49         ` Dave Engebretsen
2002-05-08 13:54           ` Justin Carlson
2002-05-08 15:27           ` Dave Engebretsen
2002-05-08 15:49             ` Andi Kleen
2002-05-08 17:07             ` David Mosberger
2002-05-09  7:36               ` Rusty Russell
2002-05-09  8:01                 ` Keith Owens
2002-05-09 15:00                 ` David Mosberger
2002-05-13  3:26                   ` Rusty Russell
2002-05-13 16:36                     ` David Mosberger
2002-05-13 16:50                       ` Linus Torvalds
2002-05-13 17:53                         ` David Mosberger
2002-05-13 23:28                         ` Rusty Russell
2002-05-07 22:57       ` Anton Blanchard
2002-05-13 18:16         ` Jesse Barnes
  -- strict thread matches above, loose matches on Subject: below --
2002-05-09 11:33 Manfred Spraul
2002-05-09 19:38 ` Dave Engebretsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox