From c7401648354d935c19495bc232168f057e466906 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 21 Oct 2020 12:15:30 -0700 Subject: [PATCH] Power: add support for devices without display idle signals To workaround b/141025174, adding support for devices without display idle signals. Also added a property to override idle display function. Besides the idle signal support, this CL also makes touch boost duration tunable through several new vendor properties. It also named display idle monitor thread and cleans out the obsolete HIDL Power HAL implementation. Bug: 168080943 Bug: 169065024 Bug: 171494137 Test: Boot and trace Change-Id: I76067d10958654d539624ec4cac8f346103e67bc --- aidl/power-libperfmgr/InteractionHandler.cpp | 86 ++++++++++++++------ aidl/power-libperfmgr/InteractionHandler.h | 30 +++---- aidl/power-libperfmgr/Power.h | 1 - 3 files changed, 76 insertions(+), 41 deletions(-) diff --git a/aidl/power-libperfmgr/InteractionHandler.cpp b/aidl/power-libperfmgr/InteractionHandler.cpp index 9ca52a64..f73e6da8 100644 --- a/aidl/power-libperfmgr/InteractionHandler.cpp +++ b/aidl/power-libperfmgr/InteractionHandler.cpp @@ -17,30 +17,59 @@ #define LOG_TAG "android.hardware.power@-service.samsung-libperfmgr" #define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) +#include +#include + #include #include #include #include #include + +#include #include #include -#include #include "InteractionHandler.h" #define MAX_LENGTH 64 #define MSINSEC 1000L -#define USINMS 1000000L +#define NSINMS 1000000L + +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + +namespace { + +static const bool kDisplayIdleSupport = + ::android::base::GetBoolProperty("vendor.powerhal.disp.idle_support", true); +static const std::array kDispIdlePath = {"/sys/class/drm/card0/device/idle_state", + "/sys/class/graphics/fb0/idle_state"}; +static const uint32_t kWaitMs = + ::android::base::GetUintProperty("vendor.powerhal.disp.idle_wait", /*default*/ 100U); +static const uint32_t kMinDurationMs = + ::android::base::GetUintProperty("vendor.powerhal.interaction.min", /*default*/ 1400U); +static const uint32_t kMaxDurationMs = + ::android::base::GetUintProperty("vendor.powerhal.interaction.max", /*default*/ 5650U); +static const uint32_t kDurationOffsetMs = + ::android::base::GetUintProperty("vendor.powerhal.interaction.offset", /*default*/ 650U); + +static size_t CalcTimespecDiffMs(struct timespec start, struct timespec end) { + size_t diff_in_ms = 0; + diff_in_ms += (end.tv_sec - start.tv_sec) * MSINSEC; + diff_in_ms += (end.tv_nsec - start.tv_nsec) / NSINMS; + return diff_in_ms; +} -static const std::vector fb_idle_patch = {"/sys/class/drm/card0/device/idle_state", - "/sys/class/graphics/fb0/idle_state"}; +} // namespace InteractionHandler::InteractionHandler(std::shared_ptr const &hint_manager) : mState(INTERACTION_STATE_UNINITIALIZED), - mWaitMs(100), - mMinDurationMs(1400), - mMaxDurationMs(5650), mDurationMs(0), mHintManager(hint_manager) {} @@ -50,8 +79,8 @@ InteractionHandler::~InteractionHandler() { static int fb_idle_open(void) { int fd; - for (auto &path : fb_idle_patch) { - fd = open(path.c_str(), O_RDONLY); + for (const auto &path : kDispIdlePath) { + fd = open(path, O_RDONLY); if (fd >= 0) return fd; } @@ -115,30 +144,27 @@ void InteractionHandler::PerfRel() { ATRACE_INT("interaction_lock", 0); } -size_t InteractionHandler::CalcTimespecDiffMs(struct timespec start, struct timespec end) { - size_t diff_in_us = 0; - diff_in_us += (end.tv_sec - start.tv_sec) * MSINSEC; - diff_in_us += (end.tv_nsec - start.tv_nsec) / USINMS; - return diff_in_us; -} - void InteractionHandler::Acquire(int32_t duration) { ATRACE_CALL(); std::lock_guard lk(mLock); - if (mState == INTERACTION_STATE_UNINITIALIZED) { - ALOGW("%s: called while uninitialized", __func__); - return; - } - int inputDuration = duration + 650; + int inputDuration = duration + kDurationOffsetMs; int finalDuration; - if (inputDuration > mMaxDurationMs) - finalDuration = mMaxDurationMs; - else if (inputDuration > mMinDurationMs) + if (inputDuration > kMaxDurationMs) + finalDuration = kMaxDurationMs; + else if (inputDuration > kMinDurationMs) finalDuration = inputDuration; else - finalDuration = mMinDurationMs; + finalDuration = kMinDurationMs; + + // Fallback to do boost directly + // 1) override property is set OR + // 2) InteractionHandler not initialized + if (!kDisplayIdleSupport || mState == INTERACTION_STATE_UNINITIALIZED) { + mHintManager->DoHint("INTERACTION", std::chrono::milliseconds(finalDuration)); + return; + } struct timespec cur_timespec; clock_gettime(CLOCK_MONOTONIC, &cur_timespec); @@ -235,6 +261,7 @@ void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) { } void InteractionHandler::Routine() { + pthread_setname_np(pthread_self(), "DisplayIdleMonitor"); std::unique_lock lk(mLock, std::defer_lock); while (true) { @@ -245,7 +272,14 @@ void InteractionHandler::Routine() { mState = INTERACTION_STATE_WAITING; lk.unlock(); - WaitForIdle(mWaitMs, mDurationMs); + WaitForIdle(kWaitMs, mDurationMs); Release(); } } + +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/aidl/power-libperfmgr/InteractionHandler.h b/aidl/power-libperfmgr/InteractionHandler.h index ba767f14..77ade883 100644 --- a/aidl/power-libperfmgr/InteractionHandler.h +++ b/aidl/power-libperfmgr/InteractionHandler.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef POWER_LIBPERFMGR_INTERACTIONHANDLER_H_ -#define POWER_LIBPERFMGR_INTERACTIONHANDLER_H_ +#pragma once #include #include @@ -25,9 +24,16 @@ #include +namespace aidl { +namespace google { +namespace hardware { +namespace power { +namespace impl { +namespace pixel { + using ::android::perfmgr::HintManager; -enum interaction_state { +enum InteractionState { INTERACTION_STATE_UNINITIALIZED, INTERACTION_STATE_IDLE, INTERACTION_STATE_INTERACTION, @@ -51,24 +57,20 @@ class InteractionHandler { void PerfLock(); void PerfRel(); - size_t CalcTimespecDiffMs(struct timespec start, struct timespec end); - - enum interaction_state mState; - + enum InteractionState mState; int mIdleFd; int mEventFd; - - int32_t mWaitMs; - int32_t mMinDurationMs; - int32_t mMaxDurationMs; int32_t mDurationMs; - struct timespec mLastTimespec; - std::unique_ptr mThread; std::mutex mLock; std::condition_variable mCond; std::shared_ptr mHintManager; }; -#endif // POWER_LIBPERFMGR_INTERACTIONHANDLER_H_ +} // namespace pixel +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace google +} // namespace aidl diff --git a/aidl/power-libperfmgr/Power.h b/aidl/power-libperfmgr/Power.h index ab4e142d..3d76fa71 100644 --- a/aidl/power-libperfmgr/Power.h +++ b/aidl/power-libperfmgr/Power.h @@ -32,7 +32,6 @@ namespace power { namespace impl { namespace pixel { -using ::InteractionHandler; using ::aidl::android::hardware::power::Boost; using ::aidl::android::hardware::power::Mode; using ::android::perfmgr::HintManager;