From 523949c628bf755ab344cc2208f15ab5fac6812b Mon Sep 17 00:00:00 2001 From: jimmyshiu Date: Thu, 18 Jul 2024 20:16:00 +0530 Subject: [PATCH] sm6375-common: power-libperfmgr: ADPF: optimize the wakeup performance and fix unstable boost. Optimize boost: A more efficient way is to trigger the wakeup boost through mTidSessionListMap, so the time complexity reduce from O(n^3) to O(n^2). The original code path: PSM:wakeSessions() contains a loop that is O(n), inside the loop, it calls to PHS::wakeup() which call to PSM::setUclampMinLocked(), and PSM::setUclampMinLocked() contains two loops O(n^2) The new code path: PSM::wakeSessions() directly checks all the ADPF tasks O(n) and get the wakeup boost value O(n), then directly set the uclamp.min The time complexity lower to O(n^2). Fix unstable boost: The original flow is to find max boost and wake it up from stale state one by one. But the previous woken ones would not be counted when the later ones finding their max boost value. The new flow boost all the tasks first, then wake up all those sessions. Bug: 235510337 Test: Manually playing UIBench -> Transitions -> ActivityTransition Change-Id: I995673b74401e198eb72188134ba1ebc134f971c --- power-libperfmgr/PowerHintSession.cpp | 7 +++---- power-libperfmgr/PowerSessionManager.cpp | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/power-libperfmgr/PowerHintSession.cpp b/power-libperfmgr/PowerHintSession.cpp index 0ac0b4a..2dbb464 100644 --- a/power-libperfmgr/PowerHintSession.cpp +++ b/power-libperfmgr/PowerHintSession.cpp @@ -426,14 +426,13 @@ void PowerHintSession::wakeup() { ATRACE_NAME(tag.c_str()); } std::shared_ptr adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); - int min = std::max(mDescriptor->current_min, static_cast(adpfConfig->mUclampMinInit)); - mDescriptor->current_min = min; - PowerSessionManager::getInstance()->setUclampMinLocked(this, min); + mDescriptor->current_min = + std::max(mDescriptor->current_min, static_cast(adpfConfig->mUclampMinInit)); if (ATRACE_ENABLED()) { const std::string idstr = getIdString(); std::string sz = StringPrintf("adpf.%s-min", idstr.c_str()); - ATRACE_INT(sz.c_str(), min); + ATRACE_INT(sz.c_str(), mDescriptor->current_min); } } diff --git a/power-libperfmgr/PowerSessionManager.cpp b/power-libperfmgr/PowerSessionManager.cpp index 516942a..947208b 100644 --- a/power-libperfmgr/PowerSessionManager.cpp +++ b/power-libperfmgr/PowerSessionManager.cpp @@ -33,6 +33,7 @@ namespace power { namespace impl { namespace pixel { +using ::android::perfmgr::AdpfConfig; using ::android::perfmgr::HintManager; namespace { @@ -103,7 +104,28 @@ void PowerSessionManager::updateHintBoost(const std::string &boost, int32_t dura void PowerSessionManager::wakeSessions() { std::lock_guard guard(mLock); - for (PowerHintSession *s : mSessions) { + std::shared_ptr adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); + std::unordered_set wakeupList; + const int wakeupBoostValue = static_cast(adpfConfig->mUclampMinInit); + for (auto &it : mTidSessionListMap) { + int tid = it.first; + int maxboost = -1; + // Find the max boost value among all the sessions that include the same TID. + for (PowerHintSession *s : it.second) { + if (!s->isActive()) + continue; + // all active sessions need to be awakened. + wakeupList.insert(s); + if (s->isTimeout()) { + maxboost = std::max(maxboost, s->getUclampMin()); + } + } + // Found the max boost and actally set to the task. + if (maxboost != -1) { + set_uclamp_min(tid, std::max(maxboost, wakeupBoostValue)); + } + } + for (PowerHintSession *s : wakeupList) { s->wakeup(); } }