Commit graph

19 commits

Author SHA1 Message Date
Treehugger Robot
c0e1b607d3 Merge "fastboot: Increase maximum usbfs bulk size for writes to 256KiB" into main 2024-02-15 03:47:49 +00:00
Peter Collingbourne
ab8cc2f7f3 fastboot: Increase maximum usbfs bulk size for writes to 256KiB
With a device capable of saturating the bus at SuperSpeed+,
the next bottleneck is the fixed (size-independent) overhead of
the usbfs ioctl() system calls, which includes entering/exiting
the kernel, allocating/deallocating a contiguous buffer for DMA,
configuring/deconfiguring the IOMMU and issuing the DMA to the HC. In
order to saturate the bus from the host software perspective, we must
reach the schedule() call in reap_as() before the next interrupt from
the HC indicating the completion of the URB.

In my experimental setup, with an SS+ capable host and device
and 16 KiB URBs, we reach the schedule() call in 25us, but the
URB is serviced in an estimated 16us, so we lose roughly a third
of the bandwidth. Increasing the URB size to 64KiB there are
65us between interrupts and 55us until schedule(). This means
we usually reach schedule() in time but not always, so we lose a
bit of bandwidth. Increasing it again to 128KiB and we have 128us
between interrupts and 65us until schedule(), so we're now comfortably
saturating the bus. In order to account for differences between hosts,
this CL uses a doubled maximum of 256KiB.

With larger allocation sizes we now risk contiguous allocation
failures, so I implemented a fallback where we try smaller sizes if
a larger one fails.

With this CL download speeds on my hosts are now around 980 MB/s over
SS+ and 440 MB/s over SS.

Bug: 325128548
Change-Id: Ie5ad480c73f2f71a50ce7f75ffb4aaa93ded2f0b
2024-02-14 16:09:47 -08:00
Matt Schulte
28f4807dd3 fastboot: Remove '\n' from interface name on linux
If the device provides an interface string, we should remove the newline
from the read file that is added from by the linux kernel.

Bug: 324320178
Test: Ran the same command with my local changes vs not

```
bash$ ./fastboot devices -l
5f42ad5ad259c90cf14ea222791b6aaa fastboot usb:7-3

bash$ fastboot devices -l
5f42ad5ad259c90cf14ea222791b6aaa fastboot
 usb:7-3
```

Change-Id: Ida3316fdba8e35f0c66784f83455a4d82e90ba1c
2024-02-07 16:24:26 -08:00
Peter Collingbourne
8635c016db fastboot: Use asynchronous operations to send data
The fastboot command currently uses USBDEVFS_BULK to transfer data
(including image data) to the target. On the kernel side it looks
like this:

1. Allocate a contiguous memory region and copy the user data into
   the memory region (which may involve accessing storage).
2. Instruct the driver to start a DMA operation.
3. Wait for the DMA to finish.

This is suboptimal because it misses out on a pipelining
opportunity. We could be doing 3 for the current operation in parallel
with 1 for the next operation, so that the next DMA is ready to go
as soon as the current DMA finishes.

The kernel supports asynchronous operations on usbdevfs file
descriptors (USBDEVFS_SUBMITURB and USBDEVFS_REAPURB), so we can
implement this like so:

1. Submit URB 0
2. Submit URB 1
3. Wait for URB 0
4. Submit URB 2
5. Wait for URB 1
and so on.

That is what this CL implements. On my machine it increases transfer
speed from 125 MB/s to 160 MB/s using a USB 3.0 connection to the
target (Pixel 8).

Bug: 324107907
Change-Id: I20db7ea14af85db48f6494091c8279ef7a21033d
2024-02-06 13:10:27 -08:00
Dmitrii Merkurev
0b627d92c4 fastboot: get rid of manual transport memory management
Existing code has transport memory leaks. Use smart pointers
for transport to get rid of those cases and manual memory
management

Test: atest fastboot_test
Test: manually checked transport isn't leaking anymore
Bug: 296629925
Change-Id: Ifdf162d5084f61ae5c1d2b56a897464af58100da
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
2023-09-03 17:30:46 +01:00
David Anderson
4e058cac0d fastboot: Allow fastboot to asynchronously differentiate between fastboot and fastbootd.
It's not possible to programmatically determine which fastboot mode a
device is in, without sending a getvar:is-userspace query. Unfortunately
this is not possible asynchronously, and may interrupt other queries
being processed.

This patch changes fastbootd's USB interface name to "fastbootd". Note
that tools use the protocol number/class and not this string, so it
should be safe to extend. When using "fastboot devices", the interface
name is now listed if set. Note that currently only the Linux version of
the fastboot tool is capable of reading the interface name.

Bug: 156966319
Test: fastboot devices on Linux
Change-Id: I57ccf2bec1dda573fe3ac628a646624b76f45905
2020-05-28 17:42:00 +00:00
David Anderson
03de645aac fastbootd: Fix transport ownership.
This change moves Transport ownership back out of FastBootDriver.
Callers of set_transport must ensure that the previous transport is
destroyed. In addition, deleting a transport now ensures that it is
closed.

Bug: 78793464
Test: fastboot, fuzzy_fastboot works
Change-Id: I8f9ed2f7d5b09fd0820b2677d087a027378f26db
2018-09-04 15:01:12 -07:00
Aaron Wisner
acf78d462f Add support for fastboot transport timeouts and USB Reset() on linux
USB Reset() allows simulating unplugging and replugging device.

Test: build and run fastboot on mac 10.13.3
Test: glinux build and run fastboot
Change-Id: Id924d063e549a4cca9dda03afd8f8fe266f6d2ab
2018-07-26 11:19:44 -05:00
Tobias Thierer
ec1542f22d Revert "Add derived UsbTransport class with USB reset method"
This reverts commit ceb7cbf5fd.

Reason for revert: Broke mac builds:
system/core/fastboot/usb_osx.cpp:513:35: error: use of undeclared identifier 'USB_TRANSACTION_TIMEOUT'
USB_TRANSACTION_TIMEOUT, USB_TRANSACTION_TIMEOUT);
^

Change-Id: Ibe2f9ff2d5c63f9d33f4bd6d9ba962604cf8caeb
2018-07-25 10:41:24 +00:00
Aaron Wisner
ceb7cbf5fd Add derived UsbTransport class with USB reset method
For testing there needs to be a way to simulate unplugging and
replugging a device. This change adds support for a USB reset
method that does this.

Also add timeouts, so USB reads/writes don't block forever
on an unresponsive device.

Test: glinux, fastboot tool still works
Test: Reset confirmed working via wireshark Linux URB captures

Change-Id: I7213a2395d4ef1c0238810e4929ab966e78c8b55
2018-07-24 11:24:15 -05:00
Aaron Wisner
db511207ed Refactor libfastboot
This change creates a nice and clean API for issuing
fastboot commands without using the fastboot tool itself.

Test: fastboot tool itself (now using libfastboot2)
on sailfish, walleye, and other devices.
Test: flash bootloader bootloader.img
Test: flash radio radio.img
Test: -w update img.zip
Test: Manually getvar and reboot commands.

Bug: 111126621
Change-Id: I0022536b204ce0c5ad8329367fd522fa3c57877d
2018-07-19 15:16:47 -05:00
Elliott Hughes
290a228fdc Switch fastboot/init/libprocessgroup to std::this_thread::sleep_for.
Bug: http://b/32878766
Test: boots
Change-Id: Ie0ddfb7e60f2da5f6eefbb10c83a92e88c137ae3
2016-11-14 17:08:47 -08:00
Chih-Hung Hsieh
1c563d96f0 Fix google-explicit-constructor warnings.
Bug: 28341362
Change-Id: I4504e98a8db31e0edcbe63c23f9af43eb13e9d86
2016-04-29 15:44:04 -07:00
James Hawkins
588a2cad7f system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr.

Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
2016-02-18 14:52:46 -08:00
David Pursell
0b15663830 fastboot: create Transport object (take 2).
(Second upload of this CL; original upload had the wrong version of
usb_windows.cpp that caused a compilation error. Fixed error and
re-tested.)

This CL creates a Transport object to provide a generic interface for
various transports. Specifically this is designed to be able to add UDP
support to fastboot in an upcoming CL without changing the main program
logic.

Also includes some minor code style fixes and replaces malloc/free
in the USB implementation files with smart pointers and std::string.

Bug: http://b/22029765
Change-Id: I1175bbce08690fbd15f51e68166be9b3e9973ea0
2015-11-16 09:31:07 -08:00
David Pursell
c0504e1873 Revert "fastboot: create Transport object."
This broke some stuff, will look into it Monday.

This reverts commit 6f233a7799.

Change-Id: I155bc85d21fda3b0ba1e5e17839059797fb15509
2015-11-14 00:15:57 +00:00
David Pursell
6f233a7799 fastboot: create Transport object.
This CL creates a Transport object to provide a generic interface for
various transports. Specifically this is designed to be able to add UDP
support to fastboot in an upcoming CL without changing the main program
logic.

Also includes some minor code style fixes and replaces malloc/free
in the USB implementation files with smart pointers and std::string.

Bug: http://b/22029765
Change-Id: I68641af0da7d13db4647f5e20a18d04d67f0b327
2015-11-13 11:08:17 -08:00
Elliott Hughes
93f65faee8 Document the current MAX_USBFS_BULK_SIZE situation.
Bug: http://b/22688598
Change-Id: I8e5b92996d635f6b939f3add4dda0b9023629a8b
2015-07-28 14:18:50 -07:00
Elliott Hughes
b3748de33f Move fastboot to C++.
Minimal conversion.

Change-Id: I32cbf125be481a8757720d10fa303c38a7fd5e38
2015-06-23 20:56:01 -07:00
Renamed from fastboot/usb_linux.c (Browse further)