Re: why are some atomic_t's not volatile, while most are?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Chris Friesen <cfriesen@...>
Cc: Jerry Jiang <wjiang@...>, Robert P. J. Day <rpjday@...>, Linux Kernel Mailing List <linux-kernel@...>
Date: Tuesday, August 7, 2007 - 6:02 pm

Chris Friesen wrote:

That would be a compiler bug.


On most superscalar architectures, including powerpc, multiple instructions can 
be in flight simultaneously, potentially even reading and writing the same data. 
  When the compiler detects data dependencies within a thread of execution, it 
will do the right thing.  Putting the volatile keyword in here instructs the 
compiler to serialize accesses to this data even if it does not detect dependencies.

It's worth noting that all of the SMP architectures which lack the volatile 
keyword in their atomic_t definition inherit memory access semantics from ISAs 
that predate the advent of heavily-pipelined superscalar design.  i386 and 
x86_64 get theirs from at least as far back as the 8086.  I believe s390(x) 
inherits this from the s/370 ISA.  These ISAs assume strictly serialized memory 
access, and anything binary-compatible with them must enforce this in hardware, 
even at the expense of performance.  Modern ISAs that lack legacy baggage do 
away with this guarantee, putting the burden on the compiler to enforce 
serialization.  When the compiler can't detect that it's needed, we use volatile 
to inform it explicitly.

	-- Chris
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
why are some atomic_t's not volatile, while most are?, Robert P. J. Day, (Sun Jul 1, 8:49 am)
Re: why are some atomic_t's not volatile, while most are?, Chris Friesen, (Tue Aug 7, 11:51 am)
Re: why are some atomic_t's not volatile, while most are?, Chris Friesen, (Wed Aug 8, 12:50 am)
Re: why are some atomic_t's not volatile, while most are?, Robert P. J. Day, (Thu Aug 9, 8:37 am)
Re: why are some atomic_t's not volatile, while most are?, Robert P. J. Day, (Thu Aug 9, 2:02 pm)
Re: why are some atomic_t's not volatile, while most are?, Robert P. J. Day, (Thu Aug 9, 2:04 pm)
Re: why are some atomic_t's not volatile, while most are?, Jan Engelhardt, (Tue Aug 7, 6:06 pm)
Re: why are some atomic_t's not volatile, while most are?, Chris Snook, (Tue Aug 7, 6:02 pm)