Re: [patch] compiler: clarify ACCESS_ONCE() relies on compiler implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 4 Apr 2013, Linus Torvalds wrote:

> > I said in the previous email that you'd do this solely to rely on a
> > well-defined semantic rather than reading paragraphs of comments that
> > we're developing.
> 
> What's "well-defined" about it? It's implementation-defined in both cases.
> 
> IOW, why do you think "__builtin_access_once(x)" is fundamentally
> different from "(*(volatile type *)&(x))"? Both would be equally
> dependent on the compiler implementation, and I'd argue that it would
> be much nicer if gcc just automatically turned the existing volatile
> code internally into the builtin version (and then didn't even bother
> to expose that builtin), since if they are willing to do the built-in,
> they clearly acknowledge the need for this kind of behavior in the
> first place.
> 

Agreed, and the gcc community can do that if they choose, and even better 
if they explicitly state that they are doing this for the traditional 
meaning (yet not standard defined) of volatile.  For nothing else, it 
would give me something to cite in the comment I proposed to you.

> See what I'm arguing? If a compiler writer is acknowledging that this
> kind of "access once with good semantics through a pointer" is needed
> and useful (and in the presense of IO and threading, a compiler writer
> that doesn't acknowledge that is a moron), then _why_ would that same
> compiler writer then argue against just doing that for volatile
> pointers?
> 

Absolutely, it would be great.

This is why I wanted to clarify the comment of ACCESS_ONCE(), however, 
that states it's "preventing the compiler" and "forbidding the compiler" 
from doing certain things, because it doesn't.  That's the whole 
discussion.  For someone interested in C, one of the natural places they 
are going to look in the source is compiler.h, and especially when they 
see this magical ACCESS_ONCE() floating around which is seemingly a cheap 
memory barrier with other ACCESS_ONCE() references and I think we can do 
better, as I did in my initial reply which started this thread, to say 
this isn't in the standard and we're relying on gcc's implementation for 
this behavior.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]