linux-msm / qdl

BSD 3-Clause "New" or "Revised" License
225 stars 79 forks source link

usb: Allow overriding bulk write size and increase default #73

Closed quic-bjorande closed 5 months ago

quic-bjorande commented 5 months ago

Since commit 760b3dffb03d ("qdl: Rework qdl_write to limit write sizes to out_maxpktsize") outgoing transfers has been chunked into blocks of wMaxPacketSize.

As reported by Wiktor Drewniak, Maksim Paimushkin, and Luca Weiss in [1] there's huge benefits to be found in reverting this change, but out of caution the limit was untouched.

With the transition to libusb, the throughput dropped another ~15% on my machine. The numbers for HighSpeed and SuperSpeed are also in the same ballpark.

With SuperSpeed, benchmarking of different chunk sizes in the megabyte range shows improvement over these numbers in the range of 15-20x on the same machine/board combination.

The bug report related to the reduction in size describes a host machine running out of swiotlb, from the fact that we requested 1MB physically contiguous memory. It's unclear if attempts was made to correct the kernel's behavior. libusb does inquiry the capabilities of the kernel and will split the buffer and submitting multiple URBs at once, as needed. While no definitive guidance has been found, multiple sources seems to recommend passing 1-2MB of buffer to libusb at a time. So, let's move the default chunk size back up to 1MB and hope that libusb resolves the reported problem.

Additionally, introduce a new option --out-chunk-size, which allow the user to override the chunk size. This would allow any user to reduce the size if needed, but also allow the value to be increased as needed.

[1] https://github.com/linux-msm/qdl/pull/39

Reported-by: Wiktor Drewniak Reported-by: Maksim Paimushkin Reported-by: Luca Weiss