Subject: Re: Fwd: Located problem in pcn driver...
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/21/2003 01:07:11
> [...] logic [...] to decide if it(load/store) is meant for I/O device
> or memory and probably bypasses cache as a result for I/O operations
> without the volatile keyword being used.
The volatile keyword has nothing to do with bypassing cache in the
memory-subsystem sense; it exists to prevent the compiler from cacheing
"stored" values, optimizing it away, rearranging it with respect to
other volatile-marked stores, or suchlike.
For example, if I wrote
foo(int *vp)
{
int i;
int j;
...compute something in i and j, don't modify vp...
*vp = i;
*vp = j;
}
the compiler would be justified in optimizing the first store out of
existence (since vp cannot point to either i or j, because it had its
value before i and j existed, the first line cannot change j and thus
cannot change the value left in *vp). But "volatile int *vp" would
prevent this. This, of course, is completely orthogonal to bypassing
memory-subsystem cache (which is important in some but not all of the
cases in which volatile is necessary).
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B