Increase size of the the adb packets sent over the wire
The reason behing this change is to increase the adb push/pull speed
with reduceing the number of packets sent between the host and the
device because the communication is heavily bound by packet latency.
The change maintains two way compatibility in the communication
protocol with negotiating a packet size between the target and the
host with the CONNECT packets.
After this change the push/pull speeds improved significantly
(measured from Linux-x86_64 with 100MB of data):
| Old push | Old pull || New push | New pull |
-----------------------------------------------------------
Hammerhead | 4.6 MB/s | 3.9 MB/s || 13.1 MB/s | 16.5 MB/s |
-----------------------------------------------------------
Volantis | 6.0 MB/s | 6.2 MS/s || 25.9 MB/s | 29.0 MB/s |
-----------------------------------------------------------
Fugu | 6.0 MB/s | 5.1 MB/s || 27.9 MB/s | 33.2 MB/s |
-----------------------------------------------------------
Change-Id: Id9625de31266e43394289e325c7e7e473379c5d8
diff --git a/adb/usb_linux.cpp b/adb/usb_linux.cpp
index c6f712b..439826a 100644
--- a/adb/usb_linux.cpp
+++ b/adb/usb_linux.cpp
@@ -439,36 +439,21 @@
int usb_write(usb_handle *h, const void *_data, int len)
{
- unsigned char *data = (unsigned char*) _data;
- int n;
- int need_zero = 0;
-
D("++ usb_write ++\n");
- if(h->zero_mask) {
+
+ unsigned char *data = (unsigned char*) _data;
+ int n = usb_bulk_write(h, data, len);
+ if(n != len) {
+ D("ERROR: n = %d, errno = %d (%s)\n",
+ n, errno, strerror(errno));
+ return -1;
+ }
+
+ if(h->zero_mask && !(len & h->zero_mask)) {
/* if we need 0-markers and our transfer
** is an even multiple of the packet size,
- ** we make note of it
+ ** then send the zero markers.
*/
- if(!(len & h->zero_mask)) {
- need_zero = 1;
- }
- }
-
- while(len > 0) {
- int xfer = (len > 4096) ? 4096 : len;
-
- n = usb_bulk_write(h, data, xfer);
- if(n != xfer) {
- D("ERROR: n = %d, errno = %d (%s)\n",
- n, errno, strerror(errno));
- return -1;
- }
-
- len -= xfer;
- data += xfer;
- }
-
- if(need_zero){
n = usb_bulk_write(h, _data, 0);
return n;
}
@@ -484,7 +469,7 @@
D("++ usb_read ++\n");
while(len > 0) {
- int xfer = (len > 4096) ? 4096 : len;
+ int xfer = len;
D("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
n = usb_bulk_read(h, data, xfer);