mtp: import fix for cpu utilization
commit f2388b3c23754f33f9bba1f73c0b2ca57f00e546
Author: James Wei <jameswei@google.com>
Date: Tue Dec 18 17:39:58 2018 +0800
MTP: CPU usage high while under MTP mode.
poll timeout not setting well in MTP ffs handler.
This will cause MTP ffs handler not going into sleep mode.
Bug: 121171744
Test: MTP 500 Mbyte file copy throughput from / to Host (no drop)
Change-Id: I9b8a7257670b8e536bf2ea81118d297211254984
Change-Id: Ic79f6b04334074c73b62325b53112719ba29255d
diff --git a/mtp/ffs/MtpFfsHandle.cpp b/mtp/ffs/MtpFfsHandle.cpp
index 01b6f2e..19c28b3 100644
--- a/mtp/ffs/MtpFfsHandle.cpp
+++ b/mtp/ffs/MtpFfsHandle.cpp
@@ -48,6 +48,9 @@
constexpr unsigned MAX_FILE_CHUNK_SIZE = AIO_BUFS_MAX * AIO_BUF_LEN;
constexpr uint32_t MAX_MTP_FILE_SIZE = 0xFFFFFFFF;
+// Note: POLL_TIMEOUT_MS = 0 means return immediately i.e. no sleep.
+// And this will cause high CPU usage.
+constexpr int32_t POLL_TIMEOUT_MS = 500;
struct timespec ZERO_TIMEOUT = { 0, 0 };
@@ -305,7 +308,7 @@
int error = 0;
while (num_events < min_events) {
- if (poll(mPollFds, 2, 0) == -1) {
+ if (poll(mPollFds, 2, POLL_TIMEOUT_MS) == -1) {
MTPE("Mtp error during poll()\n");
return -1;
}