Subject: Re: USB stack needs early review (Re: Someone should fix our USB stack...)
To: Jachym Holecek <freza@dspfpga.com>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 03/22/2007 09:31:28
On Mar 22, 2007, at 9:27 AM, 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).
>
> So you want both -- "volatile" to make sure your code doesn't keep  
> outdated
> value in CPU registers and bus_dmamap_sync() to make sure outdated  
> value
> gets purged from CPU cache (or any kind of bus cache along the way),  
> as you
> noted above.

Well, if bus_dmamap_sync() were actually a function call on all  
platforms (on some, it is a noop macro), then there would be an  
implied memory clobber, and the compiler would know to refetch from  
the memory location after the call.

But, until such time as the bus_dma interface is cleaned up in this  
regard, volatile is probably necessary.

>
>
>    -- Jachym

-- thorpej