diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-17 23:26:01 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-17 23:26:01 +0000 |
commit | b26e3628e2fca19642275f7c178733121022a4a1 (patch) | |
tree | 2645ed910ee109ca86bbe884565579d8441e6de6 | |
parent | 7a468f5701daa76d1ab9edfe1f1be337fd6d98d1 (diff) | |
parent | 3f1dc04d2a026a7e82b91a443b644723344a7e1e (diff) | |
download | pixel-b26e3628e2fca19642275f7c178733121022a4a1.tar.gz |
Snap for 10154358 from 3f1dc04d2a026a7e82b91a443b644723344a7e1e to udc-release
Change-Id: Ia7f78edfdc7f3617f169ddfb76802a359061b22a
-rw-r--r-- | power-libperfmgr/aidl/PowerHintSession.cpp | 64 | ||||
-rw-r--r-- | power-libperfmgr/aidl/PowerHintSession.h | 35 | ||||
-rw-r--r-- | thermal/utils/thermal_throttling.cpp | 28 |
3 files changed, 35 insertions, 92 deletions
diff --git a/power-libperfmgr/aidl/PowerHintSession.cpp b/power-libperfmgr/aidl/PowerHintSession.cpp index 12f31046..eadc4cf3 100644 --- a/power-libperfmgr/aidl/PowerHintSession.cpp +++ b/power-libperfmgr/aidl/PowerHintSession.cpp @@ -115,34 +115,6 @@ int64_t PowerHintSession::convertWorkDurationToBoostByPid( return output; } -bool PowerHintSession::isSlowUpdate(nanoseconds slowUpdateThreshold) { - if (!mReportingTimestamps.isFull()) { - return false; - } - // Convert timestamps to intervals between calls - std::array<nanoseconds, decltype(mReportingTimestamps)::maxSize() - 1> intervals; - for (int i = 0; i < mReportingTimestamps.size() - 1; ++i) { - intervals[i] = mReportingTimestamps[-i] - mReportingTimestamps[-i - 1]; - } - // Take the median, sort of.. if we have an even number of intervals, we just - // use the larger one instead of averaging. This makes the cutoff a little clearer. - std::sort(intervals.begin(), intervals.end()); - nanoseconds median = intervals[intervals.size() / 2]; - bool out = median > slowUpdateThreshold; - if (ATRACE_ENABLED()) { - traceSessionVal("slow_frame", out); - } - return out; -} - -std::chrono::nanoseconds PowerHintSession::getStaleTimeoutDuration( - std::shared_ptr<AdpfConfig> config) { - if (config == nullptr) { - config = HintManager::GetInstance()->GetAdpfProfile(); - } - return duration_cast<nanoseconds>(mDescriptor->duration * config->mStaleTimeFactor); -} - PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector<int32_t> &threadIds, int64_t durationNanos) : mStaleTimerHandler(sp<StaleTimerHandler>::make(this)), @@ -298,7 +270,7 @@ ndk::ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDura targetDurationNanos * HintManager::GetInstance()->GetAdpfProfile()->mTargetTimeFactor; ALOGV("update target duration: %" PRId64 " ns", targetDurationNanos); - mDescriptor->duration = nanoseconds(targetDurationNanos); + mDescriptor->duration = std::chrono::nanoseconds(targetDurationNanos); if (ATRACE_ENABLED()) { traceSessionVal("target", mDescriptor->duration.count()); } @@ -335,9 +307,8 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration( traceSessionVal("hint.overtime", actualDurations.back().durationNanos - mDescriptor->duration.count() > 0); } - const auto now = std::chrono::steady_clock::now(); - mLastUpdatedTime.store(now); + mLastUpdatedTime.store(std::chrono::steady_clock::now()); if (isFirstFrame) { if (isAppSession()) { tryToSendPowerHint("ADPF_FIRST_FRAME"); @@ -347,14 +318,6 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration( disableTemporaryBoost(); - mReportingTimestamps.append(now); - - // If the updates have usually been taking longer than the stale timeout, ignore them - if (isSlowUpdate(getStaleTimeoutDuration(adpfConfig))) { - setSessionUclampMin(0); - return ndk::ScopedAStatus::ok(); - } - if (!adpfConfig->mPidOn) { setSessionUclampMin(adpfConfig->mUclampMinHigh); return ndk::ScopedAStatus::ok(); @@ -376,17 +339,8 @@ ndk::ScopedAStatus PowerHintSession::sendHint(SessionHint hint) { ALOGE("Error: session is dead"); return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); } - if (!mDescriptor->is_active.load()) { - ALOGE("Error: shouldn't send hint during pause state."); - return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); - } disableTemporaryBoost(); std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); - nanoseconds staleTimeout = getStaleTimeoutDuration(adpfConfig); - mLastUpdatedTime.store(std::chrono::steady_clock::now()); - bool skipBoost = isSlowUpdate(staleTimeout) && hint == SessionHint::CPU_LOAD_RESET; - if (skipBoost) - return ndk::ScopedAStatus::ok(); switch (hint) { case SessionHint::CPU_LOAD_UP: mNextUclampMin.store(mDescriptor->current_min); @@ -399,7 +353,8 @@ ndk::ScopedAStatus PowerHintSession::sendHint(SessionHint hint) { case SessionHint::CPU_LOAD_RESET: mNextUclampMin.store(std::max(adpfConfig->mUclampMinInit, static_cast<uint32_t>(mDescriptor->current_min))); - mBoostTimerHandler->updateTimer(staleTimeout / 2); + mBoostTimerHandler->updateTimer(duration_cast<nanoseconds>( + mDescriptor->duration * adpfConfig->mStaleTimeFactor / 2.0)); setSessionUclampMin(adpfConfig->mUclampMinHigh); break; case SessionHint::CPU_LOAD_RESUME: @@ -410,6 +365,7 @@ ndk::ScopedAStatus PowerHintSession::sendHint(SessionHint hint) { return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } tryToSendPowerHint(toString(hint)); + mLastUpdatedTime.store(std::chrono::steady_clock::now()); if (ATRACE_ENABLED()) { mLastHintSent = static_cast<int>(hint); traceSessionVal("session_hint", static_cast<int>(hint)); @@ -463,7 +419,11 @@ bool PowerHintSession::isActive() { bool PowerHintSession::isTimeout() { auto now = std::chrono::steady_clock::now(); - time_point<steady_clock> staleTime = mLastUpdatedTime.load() + getStaleTimeoutDuration(); + time_point<steady_clock> staleTime = + mLastUpdatedTime.load() + + nanoseconds(static_cast<int64_t>( + mDescriptor->duration.count() * + HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor)); return now >= staleTime; } @@ -546,7 +506,9 @@ void PowerHintSession::SessionTimerHandler::setSessionDead() { } void PowerHintSession::StaleTimerHandler::updateTimer() { - SessionTimerHandler::updateTimer(mSession->getStaleTimeoutDuration()); + SessionTimerHandler::updateTimer(duration_cast<nanoseconds>( + mSession->mDescriptor->duration * + HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor)); } void PowerHintSession::StaleTimerHandler::onTimeout() { diff --git a/power-libperfmgr/aidl/PowerHintSession.h b/power-libperfmgr/aidl/PowerHintSession.h index 6475feae..e1c2523d 100644 --- a/power-libperfmgr/aidl/PowerHintSession.h +++ b/power-libperfmgr/aidl/PowerHintSession.h @@ -19,12 +19,9 @@ #include <aidl/android/hardware/power/BnPowerHintSession.h> #include <aidl/android/hardware/power/SessionHint.h> #include <aidl/android/hardware/power/WorkDuration.h> -#include <perfmgr/AdpfConfig.h> #include <utils/Looper.h> -#include <utils/Mutex.h> #include <utils/Thread.h> -#include <array> #include <mutex> #include <unordered_map> @@ -41,7 +38,6 @@ using aidl::android::hardware::power::WorkDuration; using ::android::Message; using ::android::MessageHandler; using ::android::sp; -using ::android::perfmgr::AdpfConfig; using std::chrono::milliseconds; using std::chrono::nanoseconds; using std::chrono::steady_clock; @@ -131,39 +127,14 @@ class PowerHintSession : public BnPowerHintSession { void onTimeout() override; }; - template <class T, size_t N> - class RingBuffer { - std::array<T, N> elements{}; - size_t mIndex = 0; - size_t numElements = 0; - - public: - void append(T item) { - mIndex = (mIndex + 1) % N; - numElements = std::min(N, numElements + 1); - elements[mIndex] = item; - } - bool isFull() const { return numElements == N; } - size_t size() const { return numElements; } - static constexpr size_t maxSize() { return N; } - // Allows access like [0] == current, [-1] = previous, etc.. - T &operator[](int offset) { - size_t positiveOffset = - static_cast<size_t>((offset % static_cast<int>(N)) + static_cast<int>(N)); - return elements[(mIndex + positiveOffset) % N]; - } - }; - private: void updateUniveralBoostMode(); int setSessionUclampMin(int32_t min, bool resetStale = true); void tryToSendPowerHint(std::string hint); int64_t convertWorkDurationToBoostByPid(const std::vector<WorkDuration> &actualDurations); void traceSessionVal(char const *identifier, int64_t val) const; - bool isSlowUpdate(nanoseconds slowUpdateThreshold); - nanoseconds getStaleTimeoutDuration(std::shared_ptr<AdpfConfig> config = nullptr); - AppHintDesc *mDescriptor GUARDED_BY(mSessionLock) = nullptr; - sp<StaleTimerHandler> mStaleTimerHandler GUARDED_BY(mSessionLock); + AppHintDesc *mDescriptor = nullptr; + sp<StaleTimerHandler> mStaleTimerHandler; sp<BoostTimerHandler> mBoostTimerHandler; std::atomic<time_point<steady_clock>> mLastUpdatedTime; sp<MessageHandler> mPowerManagerHandler; @@ -176,8 +147,6 @@ class PowerHintSession : public BnPowerHintSession { std::unordered_map<std::string, std::optional<bool>> mSupportedHints; // Last session hint sent, used for logging int mLastHintSent = -1; - // Tracks the last N reported timestamps for slow update detection - RingBuffer<time_point<steady_clock>, 4> mReportingTimestamps; }; } // namespace pixel diff --git a/thermal/utils/thermal_throttling.cpp b/thermal/utils/thermal_throttling.cpp index 8ae7de7a..26ac345b 100644 --- a/thermal/utils/thermal_throttling.cpp +++ b/thermal/utils/thermal_throttling.cpp @@ -422,25 +422,37 @@ bool ThermalThrottling::allocatePowerToCdev( cdev_power_budget = 0; } - const auto curr_state = + int max_cdev_vote; + if (!getCdevMaxRequest(binded_cdev_info_pair.first, &max_cdev_vote)) { + return false; + } + + const auto curr_cdev_vote = thermal_throttling_status_map_[temp.name].pid_cdev_request_map.at( binded_cdev_info_pair.first); if (binded_cdev_info_pair.second.max_release_step != std::numeric_limits<int>::max() && (power_data_invalid || cdev_power_adjustment > 0)) { - auto target_state = - std::max(curr_state - binded_cdev_info_pair.second.max_release_step, 0); - cdev_power_budget = - std::min(cdev_power_budget, cdev_info.state2power[target_state]); + if (curr_cdev_vote < max_cdev_vote) { + cdev_power_budget = cdev_info.state2power[curr_cdev_vote]; + LOG(VERBOSE) << temp.name << "'s " << binded_cdev_info_pair.first + << " vote: " << curr_cdev_vote + << " is lower than max cdev vote: " << max_cdev_vote; + } else { + const auto target_state = std::max( + curr_cdev_vote - binded_cdev_info_pair.second.max_release_step, 0); + cdev_power_budget = + std::min(cdev_power_budget, cdev_info.state2power[target_state]); + } } if (binded_cdev_info_pair.second.max_throttle_step != std::numeric_limits<int>::max() && (power_data_invalid || cdev_power_adjustment < 0)) { - auto target_state = - std::min(curr_state + binded_cdev_info_pair.second.max_throttle_step, - cdev_info.max_state); + const auto target_state = std::min( + curr_cdev_vote + binded_cdev_info_pair.second.max_throttle_step, + cdev_info.max_state); cdev_power_budget = std::max(cdev_power_budget, cdev_info.state2power[target_state]); } |