-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the linux-usb-zerocopy wiki!
This repository is meant to help bringing usb zerocopy Support to Linux mainline. There was a first post to the kernel mailing list which got some Attention, but the project paused thereafter.
The first message to the kernel mailinglist was:
The usbfs driver does not support direct data transfers from the controller to user-memory. For several use-cases (in my case USB3 Vision cameras pushing up to 360MB/s) the copy operation from kernel to user-space results in a lot of unnecessary CPU overhead especially on small embedded devices. I measured a decrease in CPU usage from 44% to 22% on a the mirabox.
This patch implements zerocopy beside the existing code paths, so it is easy to disable zerocopy at runtime and to directly compare the CPU usage. To disable zerocopy just do an echo 1 > /sys/module/usbcore/parameters/usbfs_disable_zerocopy and to reenable it echo 0 > /sys/module/usbcore/parameters/usbfs_disable_zerocopy
On modern desktop systems the change in CPU usage is quite low so this mostly affects smaller embedded devices.
Implementation details: The patch only touches drivers/usb/core/devio.c. In procy_do_submiturb(), it is checked if zerocopy is allowed. This is currently a rough check which compares the number of required pages to ps->dev->bus->sg_tablesize. I don't know if there is more to check there. Then the user memory provided inside the usbdevfs_urb structure is pinned to physical memory using get_user_pages_fast(). All the user pages are added to the scatter-gather list and the logic continues as before. In copy_urb_data_to_user() the pages are marked with set_page_dirty_lock() if the transfer was a zerocopy one. In free_async() the pinned pages are released, if the transfer was a zerocopy one.