summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-08-15 17:21:53 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-08-15 17:21:53 +0000
commit39270ccc8b5e40462ff4ffbd9b1bf7b518173f03 (patch)
tree02526e76b4e5346b387c6dfbf739df28ea42ca2f
parent91bea40df4b749f760d3414e8fbed3989deceb4d (diff)
parentc0e699319b59412a2818647b646d1a5277d0254f (diff)
downloadpixel-android13-mainline-appsearch-release.tar.gz
Snap for 8948084 from c0e699319b59412a2818647b646d1a5277d0254f to mainline-appsearch-releaseaml_ase_331311020aml_ase_331112000aml_ase_331011020android13-mainline-appsearch-release
Change-Id: Ic0700b1732e2dc57b5690eb1a5c8e1485ef2dbbb
-rw-r--r--connectivity_thermal_power_manager/connectivity_thermal_power_manager.mk3
-rw-r--r--pixelstats/BatteryEEPROMReporter.cpp8
-rw-r--r--pixelstats/include/pixelstats/BatteryEEPROMReporter.h6
-rw-r--r--power-libperfmgr/aidl/Power.cpp10
-rw-r--r--power-libperfmgr/aidl/PowerExt.cpp10
-rw-r--r--power-libperfmgr/aidl/PowerHintSession.cpp274
-rw-r--r--power-libperfmgr/aidl/PowerHintSession.h73
-rw-r--r--power-libperfmgr/aidl/PowerSessionManager.cpp13
-rw-r--r--power-libperfmgr/aidl/PowerSessionManager.h12
-rw-r--r--power-libperfmgr/libperfmgr/include/perfmgr/AdpfConfig.h2
10 files changed, 242 insertions, 169 deletions
diff --git a/connectivity_thermal_power_manager/connectivity_thermal_power_manager.mk b/connectivity_thermal_power_manager/connectivity_thermal_power_manager.mk
new file mode 100644
index 00000000..93d7f6a1
--- /dev/null
+++ b/connectivity_thermal_power_manager/connectivity_thermal_power_manager.mk
@@ -0,0 +1,3 @@
+BOARD_SEPOLICY_DIRS += hardware/google/pixel-sepolicy/connectivity_thermal_power_manager
+
+PRODUCT_PACKAGES += ConnectivityThermalPowerManager
diff --git a/pixelstats/BatteryEEPROMReporter.cpp b/pixelstats/BatteryEEPROMReporter.cpp
index 5183a1b0..d5ed720a 100644
--- a/pixelstats/BatteryEEPROMReporter.cpp
+++ b/pixelstats/BatteryEEPROMReporter.cpp
@@ -252,6 +252,14 @@ void BatteryEEPROMReporter::reportEvent(const std::shared_ptr<IStats> &stats_cli
values[BatteryEEPROM::kMinIbattFieldNumber - kVendorAtomOffset] = val;
val.set<VendorAtomValue::intValue>(hist.checksum);
values[BatteryEEPROM::kChecksumFieldNumber - kVendorAtomOffset] = val;
+ val.set<VendorAtomValue::intValue>(hist.tempco);
+ values[BatteryEEPROM::kTempcoFieldNumber - kVendorAtomOffset] = val;
+ val.set<VendorAtomValue::intValue>(hist.rcomp0);
+ values[BatteryEEPROM::kRcomp0FieldNumber - kVendorAtomOffset] = val;
+ val.set<VendorAtomValue::intValue>(hist.timer_h);
+ values[BatteryEEPROM::kTimerHFieldNumber - kVendorAtomOffset] = val;
+ val.set<VendorAtomValue::intValue>(hist.full_rep);
+ values[BatteryEEPROM::kFullRepFieldNumber - kVendorAtomOffset] = val;
VendorAtom event = {.reverseDomainName = "",
.atomId = PixelAtoms::Atom::kBatteryEeprom,
diff --git a/pixelstats/include/pixelstats/BatteryEEPROMReporter.h b/pixelstats/include/pixelstats/BatteryEEPROMReporter.h
index f7075f9a..13a203b7 100644
--- a/pixelstats/include/pixelstats/BatteryEEPROMReporter.h
+++ b/pixelstats/include/pixelstats/BatteryEEPROMReporter.h
@@ -34,9 +34,9 @@ using aidl::android::frameworks::stats::IStats;
// hence the history number is 928/28~33
#define BATT_HIST_NUM_MAX 33
-// New history layout total size is 924 or 912 byte
-// each history data size is 12 bytes: 912/12=76
-#define BATT_HIST_NUM_MAX_V2 76
+// New history layout total size is 924 or 900 byte
+// each history data size is 12 bytes: 900/12=75
+#define BATT_HIST_NUM_MAX_V2 75
/**
* A class to upload battery EEPROM metrics
diff --git a/power-libperfmgr/aidl/Power.cpp b/power-libperfmgr/aidl/Power.cpp
index 54469182..5bd18d33 100644
--- a/power-libperfmgr/aidl/Power.cpp
+++ b/power-libperfmgr/aidl/Power.cpp
@@ -88,7 +88,10 @@ Power::Power(std::shared_ptr<DisplayLowPower> dlpw, std::shared_ptr<AdaptiveCpu>
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
- PowerSessionManager::getInstance()->updateHintMode(toString(type), enabled);
+ if (HintManager::GetInstance()->GetAdpfProfile() &&
+ HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
+ PowerSessionManager::getInstance()->updateHintMode(toString(type), enabled);
+ }
switch (type) {
case Mode::LOW_POWER:
mDisplayLowPower->SetDisplayLowPower(enabled);
@@ -188,7 +191,10 @@ ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs;
- PowerSessionManager::getInstance()->updateHintBoost(toString(type), durationMs);
+ if (HintManager::GetInstance()->GetAdpfProfile() &&
+ HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
+ PowerSessionManager::getInstance()->updateHintBoost(toString(type), durationMs);
+ }
switch (type) {
case Boost::INTERACTION:
if (mVRModeOn || mSustainedPerfModeOn) {
diff --git a/power-libperfmgr/aidl/PowerExt.cpp b/power-libperfmgr/aidl/PowerExt.cpp
index 751e5e82..1d91d9b2 100644
--- a/power-libperfmgr/aidl/PowerExt.cpp
+++ b/power-libperfmgr/aidl/PowerExt.cpp
@@ -47,7 +47,10 @@ ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
} else {
HintManager::GetInstance()->EndHint(mode);
}
- PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
+ if (HintManager::GetInstance()->GetAdpfProfile() &&
+ HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
+ PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
+ }
if (mode == AdaptiveCpu::HINT_NAME) {
LOG(DEBUG) << "AdaptiveCpu intercepted hint";
@@ -66,7 +69,10 @@ ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aid
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
- PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
+ if (HintManager::GetInstance()->GetAdpfProfile() &&
+ HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
+ PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
+ }
if (durationMs > 0) {
HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
diff --git a/power-libperfmgr/aidl/PowerHintSession.cpp b/power-libperfmgr/aidl/PowerHintSession.cpp
index 5d0e2c5b..cac641a6 100644
--- a/power-libperfmgr/aidl/PowerHintSession.cpp
+++ b/power-libperfmgr/aidl/PowerHintSession.cpp
@@ -127,8 +127,16 @@ PowerHintSession::PowerHintSession(std::shared_ptr<AdaptiveCpu> adaptiveCpu, int
: mAdaptiveCpu(adaptiveCpu) {
mDescriptor = new AppHintDesc(tgid, uid, threadIds);
mDescriptor->duration = std::chrono::nanoseconds(durationNanos);
- mHintTimerHandler = sp<HintTimerHandler>(new HintTimerHandler(this));
+ mStaleTimerHandler = sp<StaleTimerHandler>(new StaleTimerHandler(this));
+ mEarlyBoostHandler = sp<EarlyBoostHandler>(new EarlyBoostHandler(this));
mPowerManagerHandler = PowerSessionManager::getInstance();
+ mLastUpdatedTime.store(std::chrono::steady_clock::now());
+ mLastStartedTimeNs =
+ std::chrono::duration_cast<std::chrono::nanoseconds>(
+ (std::chrono::steady_clock::now() - mDescriptor->duration).time_since_epoch())
+ .count();
+ mLastDurationNs = durationNanos;
+ mWorkPeriodNs = durationNanos;
if (ATRACE_ENABLED()) {
const std::string idstr = getIdString();
@@ -155,11 +163,6 @@ PowerHintSession::~PowerHintSession() {
sz = sz = StringPrintf("adpf.%s-active", idstr.c_str());
ATRACE_INT(sz.c_str(), 0);
}
- {
- std::lock_guard<std::mutex> guard(mSessionLock);
- mSessionClosed.store(true);
- }
- mHintTimerHandler->setSessionDead();
delete mDescriptor;
}
@@ -193,7 +196,11 @@ int PowerHintSession::setSessionUclampMin(int32_t min) {
std::lock_guard<std::mutex> guard(mSessionLock);
mDescriptor->current_min = min;
}
+ if (min) {
+ mStaleTimerHandler->updateTimer();
+ }
PowerSessionManager::getInstance()->setUclampMin(this, min);
+
if (ATRACE_ENABLED()) {
const std::string idstr = getIdString();
std::string sz = StringPrintf("adpf.%s-min", idstr.c_str());
@@ -207,10 +214,10 @@ int PowerHintSession::getUclampMin() {
}
void PowerHintSession::dumpToStream(std::ostream &stream) {
- stream << "ID.Min.Act.Stale(" << getIdString();
+ stream << "ID.Min.Act.Timeout(" << getIdString();
stream << ", " << mDescriptor->current_min;
stream << ", " << mDescriptor->is_active;
- stream << ", " << isStale() << ")";
+ stream << ", " << isTimeout() << ")";
}
ndk::ScopedAStatus PowerHintSession::pause() {
@@ -240,7 +247,6 @@ ndk::ScopedAStatus PowerHintSession::resume() {
if (mDescriptor->is_active.load())
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
mDescriptor->is_active.store(true);
- mHintTimerHandler->updateHintTimer(0);
// resume boost
setSessionUclampMin(mDescriptor->current_min);
if (ATRACE_ENABLED()) {
@@ -257,8 +263,16 @@ ndk::ScopedAStatus PowerHintSession::close() {
if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
}
- setSessionUclampMin(0);
+ // Remove the session from PowerSessionManager first to avoid racing.
PowerSessionManager::getInstance()->removePowerSession(this);
+ setSessionUclampMin(0);
+ {
+ std::lock_guard<std::mutex> guard(mSessionLock);
+ mSessionClosed.store(true);
+ }
+ mDescriptor->is_active.store(false);
+ mEarlyBoostHandler->setSessionDead();
+ mStaleTimerHandler->setSessionDead();
updateUniveralBoostMode();
return ndk::ScopedAStatus::ok();
}
@@ -306,6 +320,7 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
}
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
mDescriptor->update_count++;
+ bool isFirstFrame = isTimeout();
if (ATRACE_ENABLED()) {
const std::string idstr = getIdString();
std::string sz = StringPrintf("adpf.%s-batch_size", idstr.c_str());
@@ -321,7 +336,10 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
actualDurations.back().durationNanos - mDescriptor->duration.count() > 0);
}
- mHintTimerHandler->updateHintTimer(actualDurations);
+ mLastUpdatedTime.store(std::chrono::steady_clock::now());
+ if (isFirstFrame) {
+ updateUniveralBoostMode();
+ }
if (!adpfConfig->mPidOn) {
setSessionUclampMin(adpfConfig->mUclampMinHigh);
@@ -336,6 +354,11 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
mDescriptor->current_min + static_cast<int>(output));
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
setSessionUclampMin(next_min);
+ mStaleTimerHandler->updateTimer(getStaleTime());
+ if (HintManager::GetInstance()->GetAdpfProfile()->mEarlyBoostOn) {
+ updateWorkPeriod(actualDurations);
+ mEarlyBoostHandler->updateTimer(getEarlyBoostTime());
+ }
mAdaptiveCpu->ReportWorkDurations(actualDurations, mDescriptor->duration);
@@ -367,9 +390,9 @@ bool PowerHintSession::isActive() {
return mDescriptor->is_active.load();
}
-bool PowerHintSession::isStale() {
+bool PowerHintSession::isTimeout() {
auto now = std::chrono::steady_clock::now();
- return now >= mHintTimerHandler->getStaleTime();
+ return now >= getStaleTime();
}
const std::vector<int> &PowerHintSession::getTidList() const {
@@ -381,26 +404,29 @@ void PowerHintSession::setStale() {
PowerSessionManager::getInstance()->setUclampMin(this, 0);
// Deliver a task to check if all sessions are inactive.
updateUniveralBoostMode();
+ if (ATRACE_ENABLED()) {
+ const std::string idstr = getIdString();
+ std::string sz = StringPrintf("adpf.%s-min", idstr.c_str());
+ ATRACE_INT(sz.c_str(), 0);
+ }
}
void PowerHintSession::wakeup() {
std::lock_guard<std::mutex> guard(mSessionLock);
// We only wake up non-paused and stale sessions
- if (mSessionClosed || !isActive() || !isStale())
+ if (mSessionClosed || !isActive() || !isTimeout())
return;
if (ATRACE_ENABLED()) {
- std::string tag =
- StringPrintf("wakeup.%s(a:%d,s:%d)", getIdString().c_str(), isActive(), isStale());
+ std::string tag = StringPrintf("wakeup.%s(a:%d,s:%d)", getIdString().c_str(), isActive(),
+ isTimeout());
ATRACE_NAME(tag.c_str());
}
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
int min = std::max(mDescriptor->current_min, static_cast<int>(adpfConfig->mUclampMinInit));
mDescriptor->current_min = min;
PowerSessionManager::getInstance()->setUclampMinLocked(this, min);
- PowerHintMonitor::getInstance()->getLooper()->removeMessages(mHintTimerHandler);
- PowerHintMonitor::getInstance()->getLooper()->sendMessage(
- mHintTimerHandler, Message(static_cast<int>(HintTimerHandler::POKE)));
+ mStaleTimerHandler->updateTimer();
if (ATRACE_ENABLED()) {
const std::string idstr = getIdString();
@@ -409,147 +435,157 @@ void PowerHintSession::wakeup() {
}
}
-void PowerHintSession::HintTimerHandler::updateHintTimer(int64_t actualDurationNs) {
- std::lock_guard<std::mutex> guard(mStaleLock);
- PowerHintSession::HintTimerHandler::updateHintTimerLocked(actualDurationNs);
-}
-
-void PowerHintSession::HintTimerHandler::updateHintTimerLocked(int64_t actualDurationNs) {
- std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
- HintTimerState prevState = mState;
- mState = MONITORING;
- auto now = std::chrono::steady_clock::now();
- mLastUpdatedTime.store(now);
- nanoseconds nextStartDur = nanoseconds((mSession->mDescriptor->work_period
- ? mSession->mDescriptor->work_period
- : mSession->mDescriptor->duration.count()) -
- actualDurationNs);
- mNextStartTime.store(actualDurationNs <= 0 ? now : now + nextStartDur);
- if (prevState != MONITORING) {
- int64_t next =
- static_cast<int64_t>(duration_cast<nanoseconds>(getEarlyBoostTime() - now).count());
- PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mHintTimerHandler);
- PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
- next, mSession->mHintTimerHandler, NULL);
- if (prevState == STALE) {
- mSession->updateUniveralBoostMode();
- }
- }
- if (ATRACE_ENABLED()) {
- const std::string idstr = mSession->getIdString();
- std::string sz = StringPrintf("adpf.%s-timer.state", idstr.c_str());
- ATRACE_INT(sz.c_str(), mState);
- sz = StringPrintf("adpf.%s-timer.nextvsync", idstr.c_str());
- ATRACE_INT(sz.c_str(), nextStartDur.count());
- sz = StringPrintf("adpf.%s-timer.nexthint", idstr.c_str());
- ATRACE_INT(sz.c_str(),
- (int64_t)(nextStartDur.count() + mSession->mDescriptor->duration.count() *
- adpfConfig->mEarlyBoostTimeFactor));
- }
-}
-
-void PowerHintSession::HintTimerHandler::updateHintTimer(
- const std::vector<WorkDuration> &actualDurations) {
+void PowerHintSession::updateWorkPeriod(const std::vector<WorkDuration> &actualDurations) {
if (actualDurations.size() == 0)
return;
if (actualDurations.size() >= 2) {
const WorkDuration &last = actualDurations[actualDurations.size() - 2];
- mSession->mDescriptor->last_start = last.timeStampNanos - last.durationNanos;
+ mLastStartedTimeNs = last.timeStampNanos - last.durationNanos;
}
const WorkDuration &current = actualDurations.back();
int64_t curr_start = current.timeStampNanos - current.durationNanos;
- if (!mSession->mDescriptor->last_start) {
- mSession->mDescriptor->last_start = curr_start;
- updateHintTimer(current.durationNanos);
- return;
- }
- int64_t period = curr_start - mSession->mDescriptor->last_start;
- mSession->mDescriptor->last_start = curr_start;
- if (period > 0 && period < mSession->mDescriptor->duration.count() * 2) {
+ 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.
- mSession->mDescriptor->work_period =
- 0.9 * mSession->mDescriptor->work_period + 0.1 * period;
+ mWorkPeriodNs = 0.9 * mWorkPeriodNs + 0.1 * period;
if (ATRACE_ENABLED()) {
- const std::string idstr = mSession->getIdString();
+ const std::string idstr = getIdString();
std::string sz = StringPrintf("adpf.%s-timer.period", idstr.c_str());
- ATRACE_INT(sz.c_str(), period);
+ ATRACE_INT(sz.c_str(), mWorkPeriodNs);
}
}
- updateHintTimer(current.durationNanos);
+ mLastStartedTimeNs = curr_start;
+ mLastDurationNs = current.durationNanos;
}
-time_point<steady_clock> PowerHintSession::HintTimerHandler::getEarlyBoostTime() {
+time_point<steady_clock> PowerHintSession::getEarlyBoostTime() {
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
- if (!adpfConfig->mEarlyBoostOn) {
- return getStaleTime();
- }
int64_t earlyBoostTimeoutNs =
- (int64_t)mSession->mDescriptor->duration.count() * adpfConfig->mEarlyBoostTimeFactor;
- return mNextStartTime.load() + nanoseconds(earlyBoostTimeoutNs);
+ (int64_t)mDescriptor->duration.count() * adpfConfig->mEarlyBoostTimeFactor;
+ time_point<steady_clock> nextStartTime =
+ mLastUpdatedTime.load() + nanoseconds(mWorkPeriodNs - mLastDurationNs);
+ return nextStartTime + nanoseconds(earlyBoostTimeoutNs);
}
-time_point<steady_clock> PowerHintSession::HintTimerHandler::getStaleTime() {
+time_point<steady_clock> PowerHintSession::getStaleTime() {
return mLastUpdatedTime.load() +
nanoseconds(static_cast<int64_t>(
- mSession->mDescriptor->duration.count() *
+ mDescriptor->duration.count() *
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
}
-PowerHintSession::HintTimerHandler::~HintTimerHandler() {
- ATRACE_CALL();
+void PowerHintSession::StaleTimerHandler::updateTimer() {
+ time_point<steady_clock> staleTime =
+ std::chrono::steady_clock::now() +
+ nanoseconds(static_cast<int64_t>(
+ mSession->mDescriptor->duration.count() *
+ HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
+ updateTimer(staleTime);
}
-void PowerHintSession::HintTimerHandler::handleMessage(const Message &msg) {
- std::lock_guard<std::mutex> guard(mStaleLock);
- if (mIsSessionDead) {
- return;
+void PowerHintSession::StaleTimerHandler::updateTimer(time_point<steady_clock> staleTime) {
+ mStaleTime.store(staleTime);
+ {
+ std::lock_guard<std::mutex> guard(mMessageLock);
+ PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
+ PowerHintMonitor::getInstance()->getLooper()->sendMessage(mSession->mStaleTimerHandler,
+ NULL);
+ }
+ mIsMonitoring.store(true);
+ if (ATRACE_ENABLED()) {
+ const std::string idstr = mSession->getIdString();
+ std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
+ ATRACE_INT(sz.c_str(), 0);
}
- if (msg.what == POKE) {
- updateHintTimerLocked(0);
+}
+
+void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
+ if (mIsSessionDead) {
return;
}
- std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
auto now = std::chrono::steady_clock::now();
- auto staleTime = getStaleTime();
- auto earlyBoostTime = getEarlyBoostTime();
- if (adpfConfig->mEarlyBoostOn && now < earlyBoostTime) {
- int64_t next =
- static_cast<int64_t>(duration_cast<nanoseconds>(earlyBoostTime - now).count());
- mState = MONITORING;
- // Schedule for the early hint check.
- PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mHintTimerHandler);
+ int64_t next =
+ static_cast<int64_t>(duration_cast<nanoseconds>(mStaleTime.load() - now).count());
+ if (next > 0) {
+ // Schedule for the stale timeout check.
+ std::lock_guard<std::mutex> guard(mMessageLock);
+ PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
- next, mSession->mHintTimerHandler, static_cast<int>(HintTimerHandler::TIMER));
+ next, mSession->mStaleTimerHandler, NULL);
+ } else {
+ mSession->setStale();
+ mIsMonitoring.store(false);
if (ATRACE_ENABLED()) {
const std::string idstr = mSession->getIdString();
- std::string sz = StringPrintf("adpf.%s-timer.nexthint", idstr.c_str());
- ATRACE_INT(sz.c_str(), next);
+ std::string sz = StringPrintf("adpf.%s-timer.earlyboost", idstr.c_str());
+ ATRACE_INT(sz.c_str(), 0);
}
- } else if (now >= staleTime) { // Check if the session is stale.
- mSession->setStale();
- mState = STALE;
- } else { // Check if it's time to do early boost.
- if (adpfConfig->mEarlyBoostOn) {
- mState = EARLY_BOOST;
- mSession->setSessionUclampMin(adpfConfig->mUclampMinHigh);
- }
- int64_t next = static_cast<int64_t>(duration_cast<nanoseconds>(staleTime - now).count());
- // Schedule for the stale timeout check.
- PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mHintTimerHandler);
- PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
- next, mSession->mHintTimerHandler, static_cast<int>(HintTimerHandler::TIMER));
}
if (ATRACE_ENABLED()) {
const std::string idstr = mSession->getIdString();
- std::string sz = StringPrintf("adpf.%s-timer.state", idstr.c_str());
- ATRACE_INT(sz.c_str(), mState);
+ std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
+ ATRACE_INT(sz.c_str(), mIsMonitoring ? 0 : 1);
}
}
-void PowerHintSession::HintTimerHandler::setSessionDead() {
+void PowerHintSession::StaleTimerHandler::setSessionDead() {
std::lock_guard<std::mutex> guard(mStaleLock);
- PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mHintTimerHandler);
mIsSessionDead = true;
+ PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
+}
+
+void PowerHintSession::EarlyBoostHandler::updateTimer(time_point<steady_clock> boostTime) {
+ mBoostTime.store(boostTime);
+ {
+ std::lock_guard<std::mutex> 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<std::mutex> guard(mBoostLock);
+ if (mIsSessionDead) {
+ return;
+ }
+ auto now = std::chrono::steady_clock::now();
+ int64_t next =
+ static_cast<int64_t>(duration_cast<nanoseconds>(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<std::mutex> guard(mMessageLock);
+ PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mEarlyBoostHandler);
+ PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
+ next, mSession->mEarlyBoostHandler, NULL);
+ } else {
+ std::shared_ptr<AdpfConfig> 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<std::mutex> guard(mBoostLock);
+ mIsSessionDead = true;
+ PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mEarlyBoostHandler);
}
} // namespace pixel
diff --git a/power-libperfmgr/aidl/PowerHintSession.h b/power-libperfmgr/aidl/PowerHintSession.h
index 600434d4..96b445ed 100644
--- a/power-libperfmgr/aidl/PowerHintSession.h
+++ b/power-libperfmgr/aidl/PowerHintSession.h
@@ -53,9 +53,7 @@ struct AppHintDesc {
is_active(true),
update_count(0),
integral_error(0),
- previous_error(0),
- work_period(0),
- last_start(0) {}
+ previous_error(0) {}
std::string toString() const;
const int32_t tgid;
const int32_t uid;
@@ -68,9 +66,6 @@ struct AppHintDesc {
uint64_t update_count;
int64_t integral_error;
int64_t previous_error;
- // earlyhint pace
- int64_t work_period;
- int64_t last_start;
};
class PowerHintSession : public BnPowerHintSession {
@@ -85,7 +80,7 @@ class PowerHintSession : public BnPowerHintSession {
ndk::ScopedAStatus reportActualWorkDuration(
const std::vector<WorkDuration> &actualDurations) override;
bool isActive();
- bool isStale();
+ bool isTimeout();
void wakeup();
void setStale();
// Is this hint session for a user application
@@ -94,41 +89,43 @@ class PowerHintSession : public BnPowerHintSession {
int getUclampMin();
void dumpToStream(std::ostream &stream);
+ void updateWorkPeriod(const std::vector<WorkDuration> &actualDurations);
+ time_point<steady_clock> getEarlyBoostTime();
+ time_point<steady_clock> getStaleTime();
+
private:
- class HintTimerHandler : public MessageHandler {
+ class StaleTimerHandler : public MessageHandler {
public:
- enum MsgType {
- TIMER = 0,
- POKE,
- };
- enum HintTimerState {
- STALE,
- MONITORING,
- EARLY_BOOST,
- };
- HintTimerHandler(PowerHintSession *session)
- : mSession(session),
- mState(STALE),
- mLastUpdatedTime(steady_clock::now()),
- mIsSessionDead(false) {}
- ~HintTimerHandler();
+ StaleTimerHandler(PowerHintSession *session)
+ : mSession(session), mIsMonitoring(false), mIsSessionDead(false) {}
+ void updateTimer();
+ void updateTimer(time_point<steady_clock> staleTime);
void handleMessage(const Message &message) override;
- // Update HintTimer by actual work duration.
- void updateHintTimer(int64_t actualDurationNs);
- void updateHintTimerLocked(int64_t actualDurationNs);
- // Update HintTimer by a list of work durations which could be used for
- // calculating the work period.
- void updateHintTimer(const std::vector<WorkDuration> &actualDurations);
- time_point<steady_clock> getEarlyBoostTime();
- time_point<steady_clock> getStaleTime();
void setSessionDead();
private:
PowerHintSession *mSession;
- HintTimerState mState;
- std::atomic<time_point<steady_clock>> mLastUpdatedTime;
- std::atomic<time_point<steady_clock>> mNextStartTime;
std::mutex mStaleLock;
+ std::mutex mMessageLock;
+ std::atomic<time_point<steady_clock>> mStaleTime;
+ std::atomic<bool> mIsMonitoring;
+ bool mIsSessionDead;
+ };
+
+ class EarlyBoostHandler : public MessageHandler {
+ public:
+ EarlyBoostHandler(PowerHintSession *session)
+ : mSession(session), mIsMonitoring(false), mIsSessionDead(false) {}
+ void updateTimer(time_point<steady_clock> boostTime);
+ void handleMessage(const Message &message) override;
+ void setSessionDead();
+
+ private:
+ PowerHintSession *mSession;
+ std::mutex mBoostLock;
+ std::mutex mMessageLock;
+ std::atomic<time_point<steady_clock>> mBoostTime;
+ std::atomic<bool> mIsMonitoring;
bool mIsSessionDead;
};
@@ -138,10 +135,16 @@ class PowerHintSession : public BnPowerHintSession {
std::string getIdString() const;
const std::shared_ptr<AdaptiveCpu> mAdaptiveCpu;
AppHintDesc *mDescriptor = nullptr;
- sp<HintTimerHandler> mHintTimerHandler;
+ sp<StaleTimerHandler> mStaleTimerHandler;
+ sp<EarlyBoostHandler> mEarlyBoostHandler;
+ std::atomic<time_point<steady_clock>> mLastUpdatedTime;
sp<MessageHandler> mPowerManagerHandler;
std::mutex mSessionLock;
std::atomic<bool> mSessionClosed = false;
+ // These 3 variables are for earlyboost work period estimation.
+ int64_t mLastStartedTimeNs;
+ int64_t mLastDurationNs;
+ int64_t mWorkPeriodNs;
};
} // namespace pixel
diff --git a/power-libperfmgr/aidl/PowerSessionManager.cpp b/power-libperfmgr/aidl/PowerSessionManager.cpp
index 984b0d09..516942ac 100644
--- a/power-libperfmgr/aidl/PowerSessionManager.cpp
+++ b/power-libperfmgr/aidl/PowerSessionManager.cpp
@@ -97,7 +97,7 @@ void PowerSessionManager::updateHintBoost(const std::string &boost, int32_t dura
ALOGV("PowerSessionManager::updateHintBoost: boost: %s, durationMs: %d", boost.c_str(),
durationMs);
if (boost.compare("DISPLAY_UPDATE_IMMINENT") == 0) {
- wakeSessions();
+ PowerHintMonitor::getInstance()->getLooper()->sendMessage(mWakeupHandler, NULL);
}
}
@@ -162,12 +162,11 @@ void PowerSessionManager::setUclampMinLocked(PowerHintSession *session, int val)
// Get thex max uclamp.min across sessions which include the tid.
int tidMax = 0;
for (PowerHintSession *s : mTidSessionListMap[t]) {
- if (!s->isActive() || s->isStale())
+ if (!s->isActive() || s->isTimeout())
continue;
tidMax = std::max(tidMax, s->getUclampMin());
}
- val = std::max(val, tidMax);
- set_uclamp_min(t, val);
+ set_uclamp_min(t, std::max(val, tidMax));
}
}
@@ -176,7 +175,7 @@ std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
bool active = false;
for (PowerHintSession *s : mSessions) {
// session active and not stale is actually active.
- if (s->isActive() && !s->isStale() && s->isAppSession()) {
+ if (s->isActive() && !s->isTimeout() && s->isAppSession()) {
active = true;
break;
}
@@ -202,6 +201,10 @@ void PowerSessionManager::handleMessage(const Message &) {
}
}
+void PowerSessionManager::WakeupHandler::handleMessage(const Message &) {
+ PowerSessionManager::getInstance()->wakeSessions();
+}
+
void PowerSessionManager::dumpToFd(int fd) {
std::ostringstream dump_buf;
std::lock_guard<std::mutex> guard(mLock);
diff --git a/power-libperfmgr/aidl/PowerSessionManager.h b/power-libperfmgr/aidl/PowerSessionManager.h
index 90076591..6cd0886c 100644
--- a/power-libperfmgr/aidl/PowerSessionManager.h
+++ b/power-libperfmgr/aidl/PowerSessionManager.h
@@ -62,6 +62,13 @@ class PowerSessionManager : public MessageHandler {
}
private:
+ class WakeupHandler : public MessageHandler {
+ public:
+ WakeupHandler() {}
+ void handleMessage(const Message &message) override;
+ };
+
+ private:
void wakeSessions();
std::optional<bool> isAnyAppSessionActive();
void disableSystemTopAppBoost();
@@ -71,6 +78,7 @@ class PowerSessionManager : public MessageHandler {
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
std::unordered_map<int, int> mTidRefCountMap; // protected by mLock
std::unordered_map<int, std::unordered_set<PowerHintSession *>> mTidSessionListMap;
+ sp<WakeupHandler> mWakeupHandler;
bool mActive; // protected by mLock
/**
* mLock to pretect the above data objects opertions.
@@ -82,7 +90,9 @@ class PowerSessionManager : public MessageHandler {
: kDisableBoostHintName(::android::base::GetProperty(kPowerHalAdpfDisableTopAppBoost,
"ADPF_DISABLE_TA_BOOST")),
mActive(false),
- mDisplayRefreshRate(60) {}
+ mDisplayRefreshRate(60) {
+ mWakeupHandler = sp<WakeupHandler>(new WakeupHandler());
+ }
PowerSessionManager(PowerSessionManager const &) = delete;
void operator=(PowerSessionManager const &) = delete;
};
diff --git a/power-libperfmgr/libperfmgr/include/perfmgr/AdpfConfig.h b/power-libperfmgr/libperfmgr/include/perfmgr/AdpfConfig.h
index bbe4d09e..7df1bfe7 100644
--- a/power-libperfmgr/libperfmgr/include/perfmgr/AdpfConfig.h
+++ b/power-libperfmgr/libperfmgr/include/perfmgr/AdpfConfig.h
@@ -53,8 +53,6 @@ struct AdpfConfig {
int64_t getPidIInitDivI();
int64_t getPidIHighDivI();
int64_t getPidILowDivI();
- bool isEarlyBoostTimerEnabled();
- bool isStaleTimerEnabled();
void dumpToFd(int fd);
AdpfConfig(std::string name, bool pidOn, double pidPo, double pidPu, double pidI,