Re: Infrastructure for zerocopy I/O

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 8 Dec 2015, Steinar H. Gunderson wrote:

> On Tue, Dec 08, 2015 at 03:26:28PM -0500, Alan Stern wrote:
> > I just noticed this -- usbm->memlist needs to be initialized before
> > dec_usb_memory_use_count() can be called.  INIT_LIST_HEAD before the
> > "if" statement will fix the problem.
> 
> Done.
> 
> > The patch could use one more ingredient.  In
> > include/uapi/linux/usbdevicefs_h, add a #define for USBDEVFS_CAP_MMAP
> > and fix up proc_get_capabilities() to report the new capability.  In
> > theory, user programs could just try an mmap() call and see if it
> > works, but this seems cleaner.
> 
> Done.
> 
> /* Steinar */
> 
> From 03318604cc6ad9def451784da407e6fcd6af4705 Mon Sep 17 00:00:00 2001
> From: "Steinar H. Gunderson" <sesse@xxxxxxxxxx>
> Date: Thu, 26 Nov 2015 01:19:13 +0100
> Subject: [PATCH] Add support for usbfs zerocopy.
> 
> Add a new interface for userspace to preallocate memory that can be
> used with usbfs. This gives two primary benefits:
> 
>  - Zerocopy; data no longer needs to be copied between the userspace
>    and the kernel, but can instead be read directly by the driver from
>    userspace's buffers. This works for all kinds of transfers (even if
>    nonsensical for control and interrupt transfers); isochronous also
>    no longer need to memset() the buffer to zero to avoid leaking kernel data.
> 
>  - Once the buffers are allocated, USB transfers can no longer fail due to
>    memory fragmentation; previously, long-running programs could run into
>    problems finding a large enough contiguous memory chunk, especially on
>    embedded systems or at high rates.
> 
> Memory is allocated by using mmap() against the usbfs file descriptor,
> and similarly deallocated by munmap(). Once memory has been allocated,
> using it as pointers to a bulk or isochronous operation means you will
> automatically get zerocopy behavior. Note that this also means you cannot
> modify outgoing data until the transfer is complete. The same holds for
> data on the same cache lines as incoming data; DMA modifying them at the
> same time could lead to your changes being overwritten.
> 
> There's a new capability USBDEVFS_CAP_MMAP that userspace can query to see
> if the running kernel supports this functionality, if just trying mmap() is
> not acceptable.
> 
> Largely based on a patch by Markus Rechberger with some updates. The original
> patch can be found at:
> 
>   http://sundtek.de/support/devio_mmap_v0.4.diff
> 
> Signed-off-by: Steinar H. Gunderson <sesse@xxxxxxxxxx>
> Signed-off-by: Markus Rechberger <mrechberger@xxxxxxxxx>

I don't see anything else to change.  You can submit this to Greg KH 
and add:

Acked-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux