Subject: Re: USB stack needs early review (Re: Someone should fix our USB stack...)
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/27/2007 15:49:16
>>>> How could be spl() implemented to avoid the need for volatiles?
>>> It needs to have a memory clobber + __insn_barrier().
>> How would that avoid the ned for volatile marking on stuff shared
>> between driver top half and driver bottom half?
> I don't believe we're talking about true memory-mapped device
> registers;

Neither was I.  I was talking about things like state in the softc:
stuff that's inspected and modified by both top half and bottom half.

> we're talking about RAM that the device is allowed to write to at
> specific points, between known handoffs.  Given DMA sync operations
> at those handoffs, the compiler may merrily treat the memory as
> being, in fact, memory-like.

True but irrelevant.  volatile is needed even for memory-like memory
when the memory may change asynchronously with respect to the C
abstract machine, such as memory shared between top and bottom halves
of a driver - or memory shared by the main line and a signal handler,
which is just the userland version of the same thing.

As a trivial example, consider

	while (! (sc->flags & SCF_INTERRUPTED))
		;

(Yes, it's somewhat unrealistic; top halves rarely busy-wait like that.
But that's an efficiency issue; absent volatile, there's a correctness
issue as well.)

/~\ 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