History

USB: 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

Steinar H. Gunderson committed 10 years ago

Commit f7d34b41 parent 4a6d9f82 files · +203 −25Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/usbdevice_fs.h+1−0
@@ -134,6 +134,7 @@ struct usbdevfs_hub_portinfo { · 133 unmodified lines
134134 #define USBDEVFS_CAP_NO_PACKET_SIZE_LIM 0x04
135135 #define USBDEVFS_CAP_BULK_SCATTER_GATHER 0x08
136136 #define USBDEVFS_CAP_REAP_AFTER_DISCONNECT 0x10
137+#define USBDEVFS_CAP_MMAP 0x20
137138
138139 /* USBDEVFS_DISCONNECT_CLAIM flags & struct */
139140

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t