usb: Add packet combining functions

Currently we only do pipelining for output endpoints, since to properly
support short-not-ok semantics we can only have one outstanding input
packet. Since the ehci and uhci controllers have a limited per td packet
size guests will split large input transfers to into multiple packets,
and since we don't pipeline these, this comes with a serious performance
penalty.

This patch adds helper functions to (re-)combine packets which belong to 1
transfer at the guest device-driver level into 1 large transger. This can be
used by (redirection) usb-devices to enable pipelining for input endpoints.

This patch will combine packets together until a transfer terminating packet
is encountered. A terminating packet is a packet which meets one or more of
the following conditions:
1) The packet size is *not* a multiple of the endpoint max packet size
2) The packet does *not* have its short-not-ok flag set
3) The packet has its interrupt-on-complete flag set

The short-not-ok flag of the combined packet is that of the terminating packet.
Multiple combined packets may be submitted to the device, if the combined
packets do not have their short-not-ok flag set, enabling true pipelining.

If a combined packet does have its short-not-ok flag set the queue will
wait with submitting further packets to the device until that packet has
completed.

Once enabled in the usb-redir and ehci code, this improves the speed (MB/s)
of a Linux guest reading from a USB mass storage device by a factor of
1.2 - 1.5.

And the main reason why I started working on this, when reading from a pl2303
USB<->serial converter, it combines the previous 4 packets submitted per
device-driver level read into 1 big read, reducing the number of packets / sec
by a factor 4, and it allows to have multiple reads outstanding. This allows
for much better latency tolerance without the pl2303's internal buffer
overflowing (which was happening at 115200 bps, without serial flow control).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
4 files changed
tree: 507d819855224e6983b506c4c7774d225e1eec13
  1. audio/
  2. block/
  3. bsd-user/
  4. default-configs/
  5. docs/
  6. fpu/
  7. fsdev/
  8. gdb-xml/
  9. hw/
  10. include/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. qom/
  20. roms/
  21. scripts/
  22. slirp/
  23. sysconfigs/
  24. target-alpha/
  25. target-arm/
  26. target-cris/
  27. target-i386/
  28. target-lm32/
  29. target-m68k/
  30. target-microblaze/
  31. target-mips/
  32. target-openrisc/
  33. target-ppc/
  34. target-s390x/
  35. target-sh4/
  36. target-sparc/
  37. target-unicore32/
  38. target-xtensa/
  39. tcg/
  40. tests/
  41. trace/
  42. ui/
  43. .exrc
  44. .gitignore
  45. .gitmodules
  46. .mailmap
  47. a.out.h
  48. acl.c
  49. acl.h
  50. aes.c
  51. aes.h
  52. aio.c
  53. alpha-dis.c
  54. alpha.ld
  55. arch_init.c
  56. arch_init.h
  57. arm-dis.c
  58. arm.ld
  59. async.c
  60. balloon.c
  61. balloon.h
  62. bitmap.c
  63. bitmap.h
  64. bitops.c
  65. bitops.h
  66. block-migration.c
  67. block-migration.h
  68. block.c
  69. block.h
  70. block_int.h
  71. blockdev-nbd.c
  72. blockdev.c
  73. blockdev.h
  74. blockjob.c
  75. blockjob.h
  76. bswap.h
  77. bt-host.c
  78. bt-host.h
  79. bt-vhci.c
  80. buffered_file.c
  81. buffered_file.h
  82. cache-utils.c
  83. cache-utils.h
  84. Changelog
  85. cmd.c
  86. cmd.h
  87. CODING_STYLE
  88. compatfd.c
  89. compatfd.h
  90. compiler.h
  91. config.h
  92. configure
  93. console.c
  94. console.h
  95. COPYING
  96. COPYING.LIB
  97. coroutine-gthread.c
  98. coroutine-sigaltstack.c
  99. coroutine-ucontext.c
  100. coroutine-win32.c
  101. cpu-all.h
  102. cpu-common.h
  103. cpu-defs.h
  104. cpu-exec.c
  105. cpus.c
  106. cpus.h
  107. cputlb.c
  108. cputlb.h
  109. cris-dis.c
  110. cursor.c
  111. cursor_hidden.xpm
  112. cursor_left_ptr.xpm
  113. cutils.c
  114. def-helper.h
  115. device_tree.c
  116. device_tree.h
  117. dis-asm.h
  118. disas.c
  119. disas.h
  120. dma-helpers.c
  121. dma.h
  122. dump-stub.c
  123. dump.c
  124. dump.h
  125. elf.h
  126. envlist.c
  127. envlist.h
  128. error.c
  129. error.h
  130. event_notifier.c
  131. event_notifier.h
  132. exec-all.h
  133. exec-memory.h
  134. exec.c
  135. gdbstub.c
  136. gdbstub.h
  137. gen-icount.h
  138. HACKING
  139. hmp-commands.hx
  140. hmp.c
  141. hmp.h
  142. host-utils.c
  143. host-utils.h
  144. hppa-dis.c
  145. hppa.ld
  146. hwaddr.h
  147. i386-dis.c
  148. i386.ld
  149. ia64-dis.c
  150. ia64.ld
  151. input.c
  152. int128.h
  153. iohandler.c
  154. ioport.c
  155. ioport.h
  156. iorange.h
  157. iov.c
  158. iov.h
  159. json-lexer.c
  160. json-lexer.h
  161. json-parser.c
  162. json-parser.h
  163. json-streamer.c
  164. json-streamer.h
  165. kvm-all.c
  166. kvm-stub.c
  167. kvm.h
  168. libfdt_env.h
  169. LICENSE
  170. linux-aio.c
  171. lm32-dis.c
  172. m68k-dis.c
  173. m68k.ld
  174. main-loop.c
  175. main-loop.h
  176. MAINTAINERS
  177. Makefile
  178. Makefile.dis
  179. Makefile.objs
  180. Makefile.target
  181. Makefile.user
  182. memory-internal.h
  183. memory.c
  184. memory.h
  185. memory_mapping-stub.c
  186. memory_mapping.c
  187. memory_mapping.h
  188. microblaze-dis.c
  189. migration-exec.c
  190. migration-fd.c
  191. migration-tcp.c
  192. migration-unix.c
  193. migration.c
  194. migration.h
  195. mips-dis.c
  196. mips.ld
  197. module.c
  198. module.h
  199. monitor.c
  200. monitor.h
  201. nbd.c
  202. nbd.h
  203. net.c
  204. net.h
  205. notify.c
  206. notify.h
  207. os-posix.c
  208. os-win32.c
  209. osdep.c
  210. osdep.h
  211. oslib-posix.c
  212. oslib-win32.c
  213. page_cache.c
  214. path.c
  215. pci-ids.txt
  216. pflib.c
  217. pflib.h
  218. poison.h
  219. posix-aio-compat.c
  220. ppc-dis.c
  221. ppc.ld
  222. ppc64.ld
  223. qapi-schema-guest.json
  224. qapi-schema-test.json
  225. qapi-schema.json
  226. qbool.c
  227. qbool.h
  228. qdict-test-data.txt
  229. qdict.c
  230. qdict.h
  231. qemu-aio.h
  232. qemu-barrier.h
  233. qemu-bridge-helper.c
  234. qemu-char.c
  235. qemu-char.h
  236. qemu-common.h
  237. qemu-config.c
  238. qemu-config.h
  239. qemu-coroutine-int.h
  240. qemu-coroutine-io.c
  241. qemu-coroutine-lock.c
  242. qemu-coroutine-sleep.c
  243. qemu-coroutine.c
  244. qemu-coroutine.h
  245. qemu-doc.texi
  246. qemu-error.c
  247. qemu-error.h
  248. qemu-file.h
  249. qemu-ga.c
  250. qemu-img-cmds.hx
  251. qemu-img.c
  252. qemu-img.texi
  253. qemu-io.c
  254. qemu-lock.h
  255. qemu-log.c
  256. qemu-log.h
  257. qemu-nbd.c
  258. qemu-nbd.texi
  259. qemu-objects.h
  260. qemu-option-internal.h
  261. qemu-option.c
  262. qemu-option.h
  263. qemu-options-wrapper.h
  264. qemu-options.h
  265. qemu-options.hx
  266. qemu-os-posix.h
  267. qemu-os-win32.h
  268. qemu-progress.c
  269. qemu-queue.h
  270. qemu-seccomp.c
  271. qemu-seccomp.h
  272. qemu-sockets.c
  273. qemu-tech.texi
  274. qemu-thread-posix.c
  275. qemu-thread-posix.h
  276. qemu-thread-win32.c
  277. qemu-thread-win32.h
  278. qemu-thread.h
  279. qemu-timer-common.c
  280. qemu-timer.c
  281. qemu-timer.h
  282. qemu-tls.h
  283. qemu-tool.c
  284. qemu-user.c
  285. qemu-x509.h
  286. qemu-xattr.h
  287. qemu.sasl
  288. qemu_socket.h
  289. qerror.c
  290. qerror.h
  291. qfloat.c
  292. qfloat.h
  293. qint.c
  294. qint.h
  295. qjson.c
  296. qjson.h
  297. qlist.c
  298. qlist.h
  299. qmp-commands.hx
  300. qmp.c
  301. qobject.h
  302. qstring.c
  303. qstring.h
  304. qtest.c
  305. qtest.h
  306. range.h
  307. readline.c
  308. readline.h
  309. README
  310. rules.mak
  311. s390-dis.c
  312. s390.ld
  313. savevm.c
  314. sh4-dis.c
  315. softmmu-semi.h
  316. softmmu_defs.h
  317. softmmu_exec.h
  318. softmmu_header.h
  319. softmmu_template.h
  320. sparc-dis.c
  321. sparc.ld
  322. sparc64.ld
  323. spice-qemu-char.c
  324. sysemu.h
  325. tcg-runtime.c
  326. tci-dis.c
  327. tci.c
  328. thunk.c
  329. thunk.h
  330. TODO
  331. trace-events
  332. translate-all.c
  333. uboot_image.h
  334. uri.c
  335. uri.h
  336. user-exec.c
  337. VERSION
  338. version.rc
  339. vgafont.h
  340. vl.c
  341. vmstate.h
  342. x86_64.ld
  343. xen-all.c
  344. xen-mapcache.c
  345. xen-mapcache.h
  346. xen-stub.c