On Wed, 2015-03-04 at 18:30 -0800, Andrew Fish wrote:
> > On Mar 4, 2015, at 5:34 PM, Chen Fan <chen.fan.f...@cn.fujitsu.com> wrote:
> > 
> > Hi Jeff,
> > 
> > Thanks for your explanation, I didn't encounter any issue if leaving it 
> > there.
> > 
> > I just think if use Volatile qualifier may cause the problem of 
> > performance. because
> > access the value need to copy the address value  from main memory to cpu 
> > cache
> > each time and not use the cache.
> > and IIRC, in a shared memory multiprocessor system, the cache coherence may
> > keep the consistency of shared resource data in each processor local 
> > caches.
> > if the value is updated by one processor in local cache, the copy of 
> > memory data in
> > other processor caches will be marked as invalid. and then other 
> > processors read the
> > value will access from the main memory.
> > if I misunderstand, please correct me. :)
> > 
> 
> Correction! 
> 
> Volatile in C has nothing to do with hardware and caching. It has to
> do with the abstract memory model for the compiler as defined by the C
> standard. The more aggressive the compiler optimizes the code the more
> you are exposed to potential issues. If the compiler knows about all
> the code in the program that accesses a variable it can assume that
> memory location will only be changed by the compiler, and make
> optimizations (like storing a pointer in a register). 

Just to say this in a stronger way: using a volatile keyword on data
usually indicates a mistake in the program.  The reason is that all
locking primitives are memory barriers (a memory barrier to a compiler
means that all externally stored variables that are being housed in
temporary storage are placed in stable storage on crossing a memory
barrier).  The only reason you would need a volatile primitive in SMP
code is if the variable is being accessed without locking, so the first
question should be "where's the lock that protects this data?".

James



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to