From 5830e772d62c8be1a0731bd0f5d33505f90c97e2 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sat, 13 Jun 2020 11:52:12 +0800 Subject: [PATCH] power-libperfmgr: simply wait if idle state node is not present Change-Id: I93dd97e5437761d2d969f93a5af0cae864fd0a65 Signed-off-by: Jesse Chan --- hidl/power-libperfmgr/InteractionHandler.cpp | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/hidl/power-libperfmgr/InteractionHandler.cpp b/hidl/power-libperfmgr/InteractionHandler.cpp index 74bdd69..8cb61b3 100644 --- a/hidl/power-libperfmgr/InteractionHandler.cpp +++ b/hidl/power-libperfmgr/InteractionHandler.cpp @@ -65,15 +65,14 @@ bool InteractionHandler::Init() { if (mState != INTERACTION_STATE_UNINITIALIZED) return true; - int fd = fb_idle_open(); - if (fd < 0) - return false; - mIdleFd = fd; + mIdleFd = fb_idle_open(); mEventFd = eventfd(0, EFD_NONBLOCK); if (mEventFd < 0) { ALOGE("Unable to create event fd (%d)", errno); - close(mIdleFd); + if (mIdleFd >= 0) { + close(mIdleFd); + } return false; } @@ -96,7 +95,9 @@ void InteractionHandler::Exit() { mThread->join(); close(mEventFd); - close(mIdleFd); + if (mIdleFd >= 0) { + close(mIdleFd); + } } void InteractionHandler::PerfLock() { @@ -212,6 +213,18 @@ void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) { return; } + if (mIdleFd < 0) { + ret = poll(pfd, 1, timeout_ms); + if (ret > 0) { + ALOGV("%s: wait for duration aborted", __func__); + return; + } else if (ret < 0) { + ALOGE("%s: Error on waiting for duration (%zd)", __func__, ret); + return; + } + return; + } + ret = pread(mIdleFd, data, sizeof(data), 0); if (!ret) { ALOGE("%s: Unexpected EOF!", __func__); -- 2.20.1