adb: fdevent: add fdevent_context_epoll.
Implement an epoll-backed fdevent_context, that reduces overhead when
we're polling many file descriptors. FdeventTest.smoke goes from ~5.2s
to ~3.3s when run on the host (after this patch's modification to change
it from chaining 10 file descriptors together to 512).
Test: adb_test on host
Test: adbd_test on blueline
Test: test_adb.py
Test: test_device.py
Change-Id: Iacf0093aa7bebea31e447c2cb012af72d8c3297e
diff --git a/adb/fdevent/fdevent.cpp b/adb/fdevent/fdevent.cpp
index d215217..562f587 100644
--- a/adb/fdevent/fdevent.cpp
+++ b/adb/fdevent/fdevent.cpp
@@ -26,6 +26,7 @@
#include "adb_utils.h"
#include "fdevent.h"
+#include "fdevent_epoll.h"
#include "fdevent_poll.h"
using namespace std::chrono_literals;
@@ -185,8 +186,16 @@
Interrupt();
}
+static std::unique_ptr<fdevent_context> fdevent_create_context() {
+#if defined(__linux__)
+ return std::make_unique<fdevent_context_epoll>();
+#else
+ return std::make_unique<fdevent_context_poll>();
+#endif
+}
+
static auto& g_ambient_fdevent_context =
- *new std::unique_ptr<fdevent_context>(new fdevent_context_poll());
+ *new std::unique_ptr<fdevent_context>(fdevent_create_context());
static fdevent_context* fdevent_get_ambient() {
return g_ambient_fdevent_context.get();
@@ -247,5 +256,5 @@
}
void fdevent_reset() {
- g_ambient_fdevent_context.reset(new fdevent_context_poll());
+ g_ambient_fdevent_context = fdevent_create_context();
}