summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2023-05-17 07:45:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-05-17 07:45:37 +0000
commit3f1dc04d2a026a7e82b91a443b644723344a7e1e (patch)
tree2645ed910ee109ca86bbe884565579d8441e6de6
parent4cbdf1780aa821d0ce179f80c1d38fc0d183590e (diff)
parentfcafca141939f9dcfd200523c11e141d7fbab76b (diff)
Merge "Revert "Add slow frame detection to PowerHAL"" into udc-dev
-rw-r--r--power-libperfmgr/aidl/PowerHintSession.cpp64
-rw-r--r--power-libperfmgr/aidl/PowerHintSession.h35
2 files changed, 15 insertions, 84 deletions
diff --git a/power-libperfmgr/aidl/PowerHintSession.cpp b/power-libperfmgr/aidl/PowerHintSession.cpp
index 12f3104..eadc4cf 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 6475fea..e1c2523 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