From 962551000b46a47e640ca0e7b719c66b721233ae Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 19 May 2020 15:57:06 -0700 Subject: [PATCH] adb: only submit USB writes on the worker thread. After USB disconnection, io_submit will block until the endpoint comes back up. We handle this in the worker thread by sending it a signal to break it out of io_submit when we notice that USB has gone down, but opportunistic writes from the main thread can get stuck in this scenario as well. Submitting the writes only on the worker thread doesn't have a measurable impact on performance, so avert this scenario by only submitting writes from the worker thread. Bug: http://b/157078255 Test: test_device.py Change-Id: I1118f2e2a70d13f15592eb996e7084033ed5cb9d --- adb/daemon/usb.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index 7fff05af1..a66387193 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -231,7 +231,14 @@ struct UsbFfsConnection : public Connection { offset += write_size; } } - SubmitWrites(); + + // Wake up the worker thread to submit writes. + uint64_t notify = 1; + ssize_t rc = adb_write(worker_event_fd_.get(), ¬ify, sizeof(notify)); + if (rc < 0) { + PLOG(FATAL) << "failed to notify worker eventfd to submit writes"; + } + return true; } @@ -443,6 +450,9 @@ struct UsbFfsConnection : public Connection { } ReadEvents(); + + std::lock_guard lock(write_mutex_); + SubmitWrites(); } }); } @@ -626,8 +636,6 @@ struct UsbFfsConnection : public Connection { write_requests_.erase(it); size_t outstanding_writes = --writes_submitted_; LOG(DEBUG) << "USB write: reaped, down to " << outstanding_writes; - - SubmitWrites(); } IoWriteBlock CreateWriteBlock(std::shared_ptr payload, size_t offset, size_t len,