summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2018-06-22 19:06:38 -0500
committerGerrit Code Review2018-06-22 19:06:38 -0500
commitb8f4f1422f94c455a9a8013453ddaf9cde839184 (patch)
tree367a8d176592a6538318c9696b992b3876109c29
parenta67b00a322015a165228d212462b19974b02d9e5 (diff)
parent04b9ca8c31e789db68858641a21424f99c02578c (diff)
downloadplatform-system-core-b8f4f1422f94c455a9a8013453ddaf9cde839184.tar.gz
platform-system-core-b8f4f1422f94c455a9a8013453ddaf9cde839184.tar.xz
platform-system-core-b8f4f1422f94c455a9a8013453ddaf9cde839184.zip
Merge "Revert "adb: detect some spin loops and abort.""
-rw-r--r--adb/fdevent.cpp49
-rw-r--r--adb/services.cpp25
2 files changed, 0 insertions, 74 deletions
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index f98c11a2f..098a39dc1 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -35,7 +35,6 @@
35#include <unordered_map> 35#include <unordered_map>
36#include <vector> 36#include <vector>
37 37
38#include <android-base/file.h>
39#include <android-base/logging.h> 38#include <android-base/logging.h>
40#include <android-base/stringprintf.h> 39#include <android-base/stringprintf.h>
41#include <android-base/thread_annotations.h> 40#include <android-base/thread_annotations.h>
@@ -358,56 +357,10 @@ void fdevent_run_on_main_thread(std::function<void()> fn) {
358 } 357 }
359} 358}
360 359
361static void fdevent_check_spin(uint64_t cycle) {
362 // Check to see if we're spinning because we forgot about an fdevent
363 // by keeping track of how long fdevents have been continuously pending.
364 struct SpinCheck {
365 fdevent* fde;
366 std::chrono::steady_clock::time_point timestamp;
367 uint64_t cycle;
368 };
369 static auto& g_continuously_pending = *new std::unordered_map<uint64_t, SpinCheck>();
370
371 auto now = std::chrono::steady_clock::now();
372 for (auto* fde : g_pending_list) {
373 auto it = g_continuously_pending.find(fde->id);
374 if (it == g_continuously_pending.end()) {
375 g_continuously_pending[fde->id] =
376 SpinCheck{.fde = fde, .timestamp = now, .cycle = cycle};
377 } else {
378 it->second.cycle = cycle;
379 }
380 }
381
382 for (auto it = g_continuously_pending.begin(); it != g_continuously_pending.end();) {
383 if (it->second.cycle != cycle) {
384 it = g_continuously_pending.erase(it);
385 } else {
386 // Use an absurdly long window, since all we really care about is
387 // getting a bugreport eventually.
388 if (now - it->second.timestamp > std::chrono::minutes(5)) {
389 LOG(FATAL_WITHOUT_ABORT) << "detected spin in fdevent: " << dump_fde(it->second.fde);
390#if defined(__linux__)
391 int fd = it->second.fde->fd.get();
392 std::string fd_path = android::base::StringPrintf("/proc/self/fd/%d", fd);
393 std::string path;
394 if (!android::base::Readlink(fd_path, &path)) {
395 PLOG(FATAL_WITHOUT_ABORT) << "readlink of fd " << fd << " failed";
396 }
397 LOG(FATAL_WITHOUT_ABORT) << "fd " << fd << " = " << path;
398#endif
399 abort();
400 }
401 ++it;
402 }
403 }
404}
405
406void fdevent_loop() { 360void fdevent_loop() {
407 set_main_thread(); 361 set_main_thread();
408 fdevent_run_setup(); 362 fdevent_run_setup();
409 363
410 uint64_t cycle = 0;
411 while (true) { 364 while (true) {
412 if (terminate_loop) { 365 if (terminate_loop) {
413 return; 366 return;
@@ -417,8 +370,6 @@ void fdevent_loop() {
417 370
418 fdevent_process(); 371 fdevent_process();
419 372
420 fdevent_check_spin(cycle++);
421
422 while (!g_pending_list.empty()) { 373 while (!g_pending_list.empty()) {
423 fdevent* fde = g_pending_list.front(); 374 fdevent* fde = g_pending_list.front();
424 g_pending_list.pop_front(); 375 g_pending_list.pop_front();
diff --git a/adb/services.cpp b/adb/services.cpp
index b613d8312..a757d9066 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -181,29 +181,6 @@ static void reconnect_service(int fd, void* arg) {
181 kick_transport(t); 181 kick_transport(t);
182} 182}
183 183
184static void spin_service(int fd, void*) {
185 unique_fd sfd(fd);
186
187 if (!__android_log_is_debuggable()) {
188 WriteFdExactly(sfd.get(), "refusing to spin on non-debuggable build\n");
189 return;
190 }
191
192 // A service that creates an fdevent that's always pending, and then ignores it.
193 unique_fd pipe_read, pipe_write;
194 if (!Pipe(&pipe_read, &pipe_write)) {
195 WriteFdExactly(sfd.get(), "failed to create pipe\n");
196 return;
197 }
198
199 fdevent_run_on_main_thread([fd = pipe_read.release()]() {
200 fdevent* fde = fdevent_create(fd, [](int, unsigned, void*) {}, nullptr);
201 fdevent_add(fde, FDE_READ);
202 });
203
204 WriteFdExactly(sfd.get(), "spinning\n");
205}
206
207int reverse_service(const char* command, atransport* transport) { 184int reverse_service(const char* command, atransport* transport) {
208 int s[2]; 185 int s[2];
209 if (adb_socketpair(s)) { 186 if (adb_socketpair(s)) {
@@ -351,8 +328,6 @@ int service_to_fd(const char* name, atransport* transport) {
351 reinterpret_cast<void*>(1)); 328 reinterpret_cast<void*>(1));
352 } else if (!strcmp(name, "reconnect")) { 329 } else if (!strcmp(name, "reconnect")) {
353 ret = create_service_thread("reconnect", reconnect_service, transport); 330 ret = create_service_thread("reconnect", reconnect_service, transport);
354 } else if (!strcmp(name, "spin")) {
355 ret = create_service_thread("spin", spin_service, nullptr);
356#endif 331#endif
357 } 332 }
358 if (ret >= 0) { 333 if (ret >= 0) {