Subject: Re: USB stack needs early review (Re: Someone should fix our USB
To: Michael van Elst <mlelstv@serpens.de>
From: Johnny Billquist <bqt@softjar.se>
List: tech-kern
Date: 03/22/2007 19:01:39
Michael van Elst wrote:
> On Thu, Mar 22, 2007 at 05:27:03PM +0100, Jachym Holecek wrote:
>
>>Nope, AFAIU "volatile" tells the compiler the value shouldn't get cached
>>in a register (ie. should be refetched on each use) because it's expected
>>to be updated asynchronously (by another bus-master or from interrupt/signal
>>handler).
>
> Right. 'volatile' must stay. We had several problems caused by missing
> volatile declarations when we upgraded to gcc4 which cached values in
> registers more aggressively.
It's not just a question of caching values in registers.
If a variable for instance is actually pointing to a hardware register.
And you trigger the hardware to operatate by just reading that register
but don't care about the value, a compiler could optimize the read away
if it wasn't used, and the variable wasn't declared volatile.
From the compiler point of view, it's meaningless code. It don't know
about side effects. And having memory barriers, even as functions, will
not help. volatiles are important, and can't be substituted with
anything else.
Johnny