Re: [patch] spinlocks: remove 'volatile'

Arjan van de Ven
2006-07-08T08:51:45Z

On Sat, 2006-07-08 at 11:40 +0300, Avi Kivity wrote:
> Linus Torvalds wrote:
> > On Thu, 6 Jul 2006, Mark Lord wrote:
> >
> > >
> > > I'm still browsing a copy here, but so far have only really found this:
> > >
> > > A volatile declaration may be used to describe an object corresponding
> > > to a memory-mapped input/output port or an object accessed by an
> > > aysnchronously interrupting function. Actions on objects so declared
> > > shall not be "optimized out" by an implementation or reordered except
> > > as permitted by the rules for evaluating expressions.
> >
> > Note that the "reordered" is totally pointless.
> >
> > The _hardware_ will re-order accesses. Which is the whole point.
> > "volatile" is basically never sufficient in itself.
> >
> > So the definition of "volatile" literally made sense three or four
> > decades
> > ago. It's not sensible any more.
> >
>
> It could be argued that gcc's implementation of volatile is wrong, and
> that gcc should add the appropriate serializing instructions before and
> after volatile accesses.
>
> Of course, that would make volatile even more suboptimal, but at least
> correct.

with PCI, and the PCI posting rules, there is no "one" serializing
instruction, you need to know the specifics of the device in question to
cause the flush. So at least there is no universal possible
implementation of volatile as you suggest ;-)