All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about memory barriers
@ 2006-02-02 21:12 Alan Stern
  2006-02-02 21:32 ` linux-os (Dick Johnson)
  2006-02-02 21:37 ` Roland Dreier
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Stern @ 2006-02-02 21:12 UTC (permalink / raw)
  To: Kernel development list

The kernel's documentation about memory barriers is rather skimpy.  I 
gather that rmb() guarantees that all preceding reads will have completed 
before any following reads are made, and wmb() guarantees that all 
preceding writes will have completed before any following writes are made.  
I also gather that mb() is essentially the same as rmb() and wmb() put 
together.

But suppose I need to prevent a read from being moved past a write?  It 
doesn't look like either rmb() or wmb() will do this.  And if mb() is the 
same as "rmb(); wmb();" then it won't either.  So what's the right thing 
to do?

Alan Stern


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

* Re: Question about memory barriers
  2006-02-02 21:12 Question about memory barriers Alan Stern
@ 2006-02-02 21:32 ` linux-os (Dick Johnson)
  2006-02-02 21:37 ` Roland Dreier
  1 sibling, 0 replies; 5+ messages in thread
From: linux-os (Dick Johnson) @ 2006-02-02 21:32 UTC (permalink / raw)
  To: Alan Stern; +Cc: Kernel development list


On Thu, 2 Feb 2006, Alan Stern wrote:

> The kernel's documentation about memory barriers is rather skimpy.  I
> gather that rmb() guarantees that all preceding reads will have completed
> before any following reads are made, and wmb() guarantees that all
> preceding writes will have completed before any following writes are made.
> I also gather that mb() is essentially the same as rmb() and wmb() put
> together.
>
> But suppose I need to prevent a read from being moved past a write?  It
> doesn't look like either rmb() or wmb() will do this.  And if mb() is the
> same as "rmb(); wmb();" then it won't either.  So what's the right thing
> to do?
>
> Alan Stern

If you use the correct macros for device I/O (in other words
the operations are upon volatile objects), there can never
be any re-ordering of any associated code.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.66 BogoMips).
Warning : 98.36% of all statistics are fiction.
_
To unsubscribe


****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

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

* Re: Question about memory barriers
  2006-02-02 21:12 Question about memory barriers Alan Stern
  2006-02-02 21:32 ` linux-os (Dick Johnson)
@ 2006-02-02 21:37 ` Roland Dreier
  2006-02-02 21:49   ` Alan Stern
  1 sibling, 1 reply; 5+ messages in thread
From: Roland Dreier @ 2006-02-02 21:37 UTC (permalink / raw)
  To: Alan Stern; +Cc: Kernel development list

>>>>> "Alan" == Alan Stern <stern@rowland.harvard.edu> writes:

    Alan> The kernel's documentation about memory barriers is rather
    Alan> skimpy.  I gather that rmb() guarantees that all preceding
    Alan> reads will have completed before any following reads are
    Alan> made, and wmb() guarantees that all preceding writes will
    Alan> have completed before any following writes are made.  I also
    Alan> gather that mb() is essentially the same as rmb() and wmb()
    Alan> put together.

Most of this is correct, except that mb() is stronger than just rmb()
and wmb() put together.  All memory operations before the mb() will
complete before any operations after the mb().  A better way to
understand this is to look at the sparc64 definition:

#define mb()    \
        membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")

    Alan> But suppose I need to prevent a read from being moved past a
    Alan> write?  It doesn't look like either rmb() or wmb() will do
    Alan> this.  And if mb() is the same as "rmb(); wmb();" then it
    Alan> won't either.  So what's the right thing to do?

As described above, mb() will work in this case.  It actually
guarantees more than you need, so you could conceivably define a new
primitive, but the current barriers are hard enough for people to
figure out ;)

 - R.

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

* Re: Question about memory barriers
  2006-02-02 21:37 ` Roland Dreier
@ 2006-02-02 21:49   ` Alan Stern
  2006-02-02 21:52     ` Randy.Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2006-02-02 21:49 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Kernel development list

On Thu, 2 Feb 2006, Roland Dreier wrote:

> Most of this is correct, except that mb() is stronger than just rmb()
> and wmb() put together.  All memory operations before the mb() will
> complete before any operations after the mb().  A better way to
> understand this is to look at the sparc64 definition:
> 
> #define mb()    \
>         membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")

Thanks for the explanation.  Is there any appropriate place, say in 
Documentation/, where these things could be spelled out more completely?

Alan Stern


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

* Re: Question about memory barriers
  2006-02-02 21:49   ` Alan Stern
@ 2006-02-02 21:52     ` Randy.Dunlap
  0 siblings, 0 replies; 5+ messages in thread
From: Randy.Dunlap @ 2006-02-02 21:52 UTC (permalink / raw)
  To: Alan Stern; +Cc: Roland Dreier, Kernel development list

On Thu, 2 Feb 2006, Alan Stern wrote:

> On Thu, 2 Feb 2006, Roland Dreier wrote:
>
> > Most of this is correct, except that mb() is stronger than just rmb()
> > and wmb() put together.  All memory operations before the mb() will
> > complete before any operations after the mb().  A better way to
> > understand this is to look at the sparc64 definition:
> >
> > #define mb()    \
> >         membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")
>
> Thanks for the explanation.  Is there any appropriate place, say in
> Documentation/, where these things could be spelled out more completely?

Info could be added to Documentation/DocBook/kernel-locking.tmpl
which already has some barrier info.

-- 
~Randy

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

end of thread, other threads:[~2006-02-02 21:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-02 21:12 Question about memory barriers Alan Stern
2006-02-02 21:32 ` linux-os (Dick Johnson)
2006-02-02 21:37 ` Roland Dreier
2006-02-02 21:49   ` Alan Stern
2006-02-02 21:52     ` Randy.Dunlap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.