On Sun, 1 Jul 2007, David Brownell wrote:

> On Tuesday 26 June 2007, Alan Stern wrote:
> > On Tue, 26 Jun 2007, Greg KH wrote:
> > 
> > > On Tue, Jun 26, 2007 at 10:32:42AM -0400, Alan Stern wrote:
> > > > On Mon, 25 Jun 2007, Greg KH wrote:
> > > > 
> > > > > You mean something like the following, but also for bulk and int?  I
> > > > > like it, it reduces the number of allocations and frees we have to do 
> > > > > as
> > > > > the transfer buffer will get freed automatically with the urb, when it
> > > > > is.
> > > > > 
> > > > > What do people think?
> > > > 
> > > > > +     urb = kzalloc(sizeof(*urb) + size, mem_flags);
> > > > > +     if (!urb)
> > > > > +             return NULL;
> > > > > +     buffer = ((unsigned char *)(urb) + size);
> > > > 
> > > > This is no good.  The buffer has to be located in its own cache line; 
> > > > it can't be combined with another data structure like the URB.  They 
> > > > must be allocated separately.
> > > 
> > > Why?  I thought the only requirement be that they are from DMA-able
> > > memory.
> 
> That's the primary criterion, yes ... I don't think that snippet of
> code above is entirely wrong.  It would be best to round up the size
> of the URB part, so any buffer part always starts on a new cacheline.
> 
> What I like about that is that it hits the heap only once, not twice.
> So it's lower overhead, and has cleaner failure modes.

Yes, that's a good approach.  It could work for Iso URBs as well, since 
we can calculate the number of packet descriptors from the total 
transfer size and the endpoint maxpacket size (assuming each Iso packet 
has the maximum size -- which might not be a good assumption).

> > Another important requirement of streaming DMA-IN transfers is that the
> > CPU must not touch the buffer's cache line while it is mapped for DMA.
> 
> Almost true... the constraint applies to either DMA_DIRECTION_* value,
> and dma_sync_single_for_cpu()/dma_sync_single_for_device() are standard
> ways to loosen the constraint.

Yes, with the dma_sync routines you can reduce the window during which 
the cache line must be undisturbed.

However I don't understand the necessity for this with DMA-OUT 
transfers.  Obviously _writing_ to the buffer during the transfer is 
dangerous, but it's not apparent why _reading_ the buffer should be 
bad.

Alan Stern


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to