From 773630adc88c423468d800c63173c3db3bad155d Mon Sep 17 00:00:00 2001 From: Jimmy Shiu Date: Fri, 28 Oct 2022 11:38:28 +0800 Subject: [PATCH] ADPF: remove unused EarlyBoostHandler Bug: 256515601 Test: build Change-Id: I9b63c6ee3decaa4c70f38bcc66a0e9e1de464ad6 --- aidl/power-libperfmgr/PowerHintSession.cpp | 103 --------------------- aidl/power-libperfmgr/PowerHintSession.h | 25 ----- 2 files changed, 128 deletions(-) diff --git a/aidl/power-libperfmgr/PowerHintSession.cpp b/aidl/power-libperfmgr/PowerHintSession.cpp index bce149c..4294f17 100644 --- a/aidl/power-libperfmgr/PowerHintSession.cpp +++ b/aidl/power-libperfmgr/PowerHintSession.cpp @@ -126,15 +126,8 @@ PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector< mDescriptor = new AppHintDesc(tgid, uid, threadIds); mDescriptor->duration = std::chrono::nanoseconds(durationNanos); mStaleTimerHandler = sp(new StaleTimerHandler(this)); - mEarlyBoostHandler = sp(new EarlyBoostHandler(this)); mPowerManagerHandler = PowerSessionManager::getInstance(); mLastUpdatedTime.store(std::chrono::steady_clock::now()); - mLastStartedTimeNs = - std::chrono::duration_cast( - (std::chrono::steady_clock::now() - mDescriptor->duration).time_since_epoch()) - .count(); - mLastDurationNs = durationNanos; - mWorkPeriodNs = durationNanos; if (ATRACE_ENABLED()) { const std::string idstr = getIdString(); @@ -272,7 +265,6 @@ ndk::ScopedAStatus PowerHintSession::close() { } // Remove the session from PowerSessionManager first to avoid racing. PowerSessionManager::getInstance()->removePowerSession(this); - mEarlyBoostHandler->setSessionDead(); mStaleTimerHandler->setSessionDead(); setSessionUclampMin(0); mDescriptor->is_active.store(false); @@ -361,10 +353,6 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration( next_min = std::max(static_cast(adpfConfig->mUclampMinLow), next_min); setSessionUclampMin(next_min); mStaleTimerHandler->updateTimer(getStaleTime()); - if (HintManager::GetInstance()->GetAdpfProfile()->mEarlyBoostOn) { - updateWorkPeriod(actualDurations); - mEarlyBoostHandler->updateTimer(getEarlyBoostTime()); - } return ndk::ScopedAStatus::ok(); } @@ -444,38 +432,6 @@ void PowerHintSession::wakeup() { } } -void PowerHintSession::updateWorkPeriod(const std::vector &actualDurations) { - if (actualDurations.size() == 0) - return; - if (actualDurations.size() >= 2) { - const WorkDuration &last = actualDurations[actualDurations.size() - 2]; - mLastStartedTimeNs = last.timeStampNanos - last.durationNanos; - } - const WorkDuration ¤t = actualDurations.back(); - int64_t curr_start = current.timeStampNanos - current.durationNanos; - int64_t period = curr_start - mLastStartedTimeNs; - if (period > 0 && period < mDescriptor->duration.count() * 2) { - // Accounting workload period with moving average for the last 10 workload. - mWorkPeriodNs = 0.9 * mWorkPeriodNs + 0.1 * period; - if (ATRACE_ENABLED()) { - const std::string idstr = getIdString(); - std::string sz = StringPrintf("adpf.%s-timer.period", idstr.c_str()); - ATRACE_INT(sz.c_str(), mWorkPeriodNs); - } - } - mLastStartedTimeNs = curr_start; - mLastDurationNs = current.durationNanos; -} - -time_point PowerHintSession::getEarlyBoostTime() { - std::shared_ptr adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); - int64_t earlyBoostTimeoutNs = - (int64_t)mDescriptor->duration.count() * adpfConfig->mEarlyBoostTimeFactor; - time_point nextStartTime = - mLastUpdatedTime.load() + nanoseconds(mWorkPeriodNs - mLastDurationNs); - return nextStartTime + nanoseconds(earlyBoostTimeoutNs); -} - time_point PowerHintSession::getStaleTime() { return mLastUpdatedTime.load() + nanoseconds(static_cast( @@ -525,11 +481,6 @@ void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) { } else { mSession->setStale(); mIsMonitoring.store(false); - if (ATRACE_ENABLED()) { - const std::string idstr = mSession->getIdString(); - std::string sz = StringPrintf("adpf.%s-timer.earlyboost", idstr.c_str()); - ATRACE_INT(sz.c_str(), 0); - } } if (ATRACE_ENABLED()) { const std::string idstr = mSession->getIdString(); @@ -544,60 +495,6 @@ void PowerHintSession::StaleTimerHandler::setSessionDead() { PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler); } -void PowerHintSession::EarlyBoostHandler::updateTimer(time_point boostTime) { - mBoostTime.store(boostTime); - { - std::lock_guard guard(mMessageLock); - PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mEarlyBoostHandler); - PowerHintMonitor::getInstance()->getLooper()->sendMessage(mSession->mEarlyBoostHandler, - NULL); - } - mIsMonitoring.store(true); - if (ATRACE_ENABLED()) { - const std::string idstr = mSession->getIdString(); - std::string sz = StringPrintf("adpf.%s-timer.earlyboost", idstr.c_str()); - ATRACE_INT(sz.c_str(), 1); - } -} - -void PowerHintSession::EarlyBoostHandler::handleMessage(const Message &) { - std::lock_guard guard(mBoostLock); - if (mIsSessionDead) { - return; - } - auto now = std::chrono::steady_clock::now(); - int64_t next = - static_cast(duration_cast(mBoostTime.load() - now).count()); - if (next > 0) { - if (ATRACE_ENABLED()) { - const std::string idstr = mSession->getIdString(); - std::string sz = StringPrintf("adpf.%s-timer.earlyboost", idstr.c_str()); - ATRACE_INT(sz.c_str(), 1); - } - std::lock_guard guard(mMessageLock); - PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mEarlyBoostHandler); - PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed( - next, mSession->mEarlyBoostHandler, NULL); - } else { - std::shared_ptr adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); - PowerSessionManager::getInstance()->setUclampMin(mSession, adpfConfig->mUclampMinHigh); - mIsMonitoring.store(false); - if (ATRACE_ENABLED()) { - const std::string idstr = mSession->getIdString(); - std::string sz = StringPrintf("adpf.%s-min", idstr.c_str()); - ATRACE_INT(sz.c_str(), adpfConfig->mUclampMinHigh); - sz = StringPrintf("adpf.%s-timer.earlyboost", idstr.c_str()); - ATRACE_INT(sz.c_str(), 2); - } - } -} - -void PowerHintSession::EarlyBoostHandler::setSessionDead() { - std::lock_guard guard(mBoostLock); - mIsSessionDead = true; - PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mEarlyBoostHandler); -} - } // namespace pixel } // namespace impl } // namespace power diff --git a/aidl/power-libperfmgr/PowerHintSession.h b/aidl/power-libperfmgr/PowerHintSession.h index 9b32f9f..1b3e218 100644 --- a/aidl/power-libperfmgr/PowerHintSession.h +++ b/aidl/power-libperfmgr/PowerHintSession.h @@ -87,8 +87,6 @@ class PowerHintSession : public BnPowerHintSession { int getUclampMin(); void dumpToStream(std::ostream &stream); - void updateWorkPeriod(const std::vector &actualDurations); - time_point getEarlyBoostTime(); time_point getStaleTime(); private: @@ -110,23 +108,6 @@ class PowerHintSession : public BnPowerHintSession { bool mIsSessionDead; }; - class EarlyBoostHandler : public MessageHandler { - public: - EarlyBoostHandler(PowerHintSession *session) - : mSession(session), mIsMonitoring(false), mIsSessionDead(false) {} - void updateTimer(time_point boostTime); - void handleMessage(const Message &message) override; - void setSessionDead(); - - private: - PowerHintSession *mSession; - std::mutex mBoostLock; - std::mutex mMessageLock; - std::atomic> mBoostTime; - std::atomic mIsMonitoring; - bool mIsSessionDead; - }; - private: void updateUniveralBoostMode(); int setSessionUclampMin(int32_t min); @@ -134,16 +115,10 @@ class PowerHintSession : public BnPowerHintSession { std::string getIdString() const; AppHintDesc *mDescriptor = nullptr; sp mStaleTimerHandler; - sp mEarlyBoostHandler; std::atomic> mLastUpdatedTime; sp mPowerManagerHandler; std::mutex mSessionLock; std::atomic mSessionClosed = false; - // These 3 variables are for earlyboost work period estimation. - int64_t mLastStartedTimeNs; - int64_t mLastDurationNs; - int64_t mWorkPeriodNs; - // To cache the status of whether ADPF hints are supported. std::unordered_map> mSupportedHints; };