From 2081cf31b36127eabf6efadeb8e58fe664b7bf77 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 22 Apr 2020 17:33:00 -0700 Subject: [PATCH 1/2] adbd: don't use libc++_static. We have dependencies that use libc++_shared, which results in ODR violation manifesting as host adbd crashing on launch in libc++ locale initialization. Bug: http://b/151056300 Test: adbd on host Change-Id: I6c039b325308fb8c36dfe5c1d090ff4ebe9e3433 (cherry picked from commit d5d5ba1644eabc64a449e73aad9fc50d186ef508) --- adb/Android.bp | 1 - 1 file changed, 1 deletion(-) diff --git a/adb/Android.bp b/adb/Android.bp index 0394bf6ff..214e20737 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -567,7 +567,6 @@ cc_library { cc_binary { name: "adbd", defaults: ["adbd_defaults", "host_adbd_supported", "libadbd_binary_dependencies"], - stl: "libc++_static", recovery_available: true, apex_available: ["com.android.adbd"], From 6da375fdc91c7d32a316bfea022f315512c6f08c Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 19 May 2020 15:57:06 -0700 Subject: [PATCH 2/2] 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 (cherry picked from commit 962551000b46a47e640ca0e7b719c66b721233ae) --- 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,