sm6375-common: power-libperfmgr: ADPF: Fix updateHintBoost blocks the binder thread
post the task into a looper thread. Bug: 232992641 Test: Manually playing UIBench -> Transitions -> ActivityTransition Change-Id: Ibd241834f904b4c87a51363e766e110d2818d496
This commit is contained in:
parent
620a6da869
commit
fbcc05b19b
6 changed files with 43 additions and 16 deletions
|
@ -77,7 +77,10 @@ Power::Power()
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
||||||
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << 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) {
|
switch (type) {
|
||||||
#ifdef TAP_TO_WAKE_NODE
|
#ifdef TAP_TO_WAKE_NODE
|
||||||
case Mode::DOUBLE_TAP_TO_WAKE:
|
case Mode::DOUBLE_TAP_TO_WAKE:
|
||||||
|
@ -137,7 +140,10 @@ ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
||||||
|
|
||||||
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
||||||
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << 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) {
|
switch (type) {
|
||||||
case Boost::INTERACTION:
|
case Boost::INTERACTION:
|
||||||
if (mSustainedPerfModeOn) {
|
if (mSustainedPerfModeOn) {
|
||||||
|
|
|
@ -47,7 +47,10 @@ ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
|
||||||
} else {
|
} else {
|
||||||
HintManager::GetInstance()->EndHint(mode);
|
HintManager::GetInstance()->EndHint(mode);
|
||||||
}
|
}
|
||||||
PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
|
if (HintManager::GetInstance()->GetAdpfProfile() &&
|
||||||
|
HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
|
||||||
|
PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +64,10 @@ ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aid
|
||||||
|
|
||||||
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
|
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
|
||||||
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << 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) {
|
if (durationMs > 0) {
|
||||||
HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
|
HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
|
||||||
|
|
|
@ -145,7 +145,7 @@ PowerHintSession::PowerHintSession(int32_t tgid, int32_t uid, const std::vector<
|
||||||
}
|
}
|
||||||
PowerSessionManager::getInstance()->addPowerSession(this);
|
PowerSessionManager::getInstance()->addPowerSession(this);
|
||||||
// init boost
|
// init boost
|
||||||
wakeup();
|
setSessionUclampMin(HintManager::GetInstance()->GetAdpfProfile()->mUclampMinInit);
|
||||||
ALOGV("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
ALOGV("PowerHintSession created: %s", mDescriptor->toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,10 +161,6 @@ PowerHintSession::~PowerHintSession() {
|
||||||
sz = sz = StringPrintf("adpf.%s-active", idstr.c_str());
|
sz = sz = StringPrintf("adpf.%s-active", idstr.c_str());
|
||||||
ATRACE_INT(sz.c_str(), 0);
|
ATRACE_INT(sz.c_str(), 0);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> guard(mSessionLock);
|
|
||||||
mSessionClosed.store(true);
|
|
||||||
}
|
|
||||||
delete mDescriptor;
|
delete mDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,11 +261,16 @@ ndk::ScopedAStatus PowerHintSession::close() {
|
||||||
if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
|
if (!mSessionClosed.compare_exchange_strong(sessionClosedExpectedToBe, true)) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
}
|
}
|
||||||
|
// 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);
|
mDescriptor->is_active.store(false);
|
||||||
mEarlyBoostHandler->setSessionDead();
|
mEarlyBoostHandler->setSessionDead();
|
||||||
mStaleTimerHandler->setSessionDead();
|
mStaleTimerHandler->setSessionDead();
|
||||||
setSessionUclampMin(0);
|
|
||||||
PowerSessionManager::getInstance()->removePowerSession(this);
|
|
||||||
updateUniveralBoostMode();
|
updateUniveralBoostMode();
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
@ -439,8 +440,7 @@ void PowerHintSession::updateWorkPeriod(const std::vector<WorkDuration> &actualD
|
||||||
}
|
}
|
||||||
const WorkDuration ¤t = actualDurations.back();
|
const WorkDuration ¤t = actualDurations.back();
|
||||||
int64_t curr_start = current.timeStampNanos - current.durationNanos;
|
int64_t curr_start = current.timeStampNanos - current.durationNanos;
|
||||||
int64_t period = mDescriptor->duration.count();
|
int64_t period = curr_start - mLastStartedTimeNs;
|
||||||
period = curr_start - mLastStartedTimeNs;
|
|
||||||
if (period > 0 && period < mDescriptor->duration.count() * 2) {
|
if (period > 0 && period < mDescriptor->duration.count() * 2) {
|
||||||
// Accounting workload period with moving average for the last 10 workload.
|
// Accounting workload period with moving average for the last 10 workload.
|
||||||
mWorkPeriodNs = 0.9 * mWorkPeriodNs + 0.1 * period;
|
mWorkPeriodNs = 0.9 * mWorkPeriodNs + 0.1 * period;
|
||||||
|
|
|
@ -112,7 +112,8 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
|
|
||||||
class EarlyBoostHandler : public MessageHandler {
|
class EarlyBoostHandler : public MessageHandler {
|
||||||
public:
|
public:
|
||||||
EarlyBoostHandler(PowerHintSession *session) : mSession(session) {}
|
EarlyBoostHandler(PowerHintSession *session)
|
||||||
|
: mSession(session), mIsMonitoring(false), mIsSessionDead(false) {}
|
||||||
void updateTimer(time_point<steady_clock> boostTime);
|
void updateTimer(time_point<steady_clock> boostTime);
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void setSessionDead();
|
void setSessionDead();
|
||||||
|
|
|
@ -97,7 +97,7 @@ void PowerSessionManager::updateHintBoost(const std::string &boost, int32_t dura
|
||||||
ALOGV("PowerSessionManager::updateHintBoost: boost: %s, durationMs: %d", boost.c_str(),
|
ALOGV("PowerSessionManager::updateHintBoost: boost: %s, durationMs: %d", boost.c_str(),
|
||||||
durationMs);
|
durationMs);
|
||||||
if (boost.compare("DISPLAY_UPDATE_IMMINENT") == 0) {
|
if (boost.compare("DISPLAY_UPDATE_IMMINENT") == 0) {
|
||||||
wakeSessions();
|
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mWakeupHandler, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +201,10 @@ void PowerSessionManager::handleMessage(const Message &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PowerSessionManager::WakeupHandler::handleMessage(const Message &) {
|
||||||
|
PowerSessionManager::getInstance()->wakeSessions();
|
||||||
|
}
|
||||||
|
|
||||||
void PowerSessionManager::dumpToFd(int fd) {
|
void PowerSessionManager::dumpToFd(int fd) {
|
||||||
std::ostringstream dump_buf;
|
std::ostringstream dump_buf;
|
||||||
std::lock_guard<std::mutex> guard(mLock);
|
std::lock_guard<std::mutex> guard(mLock);
|
||||||
|
|
|
@ -61,6 +61,13 @@ class PowerSessionManager : public MessageHandler {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
class WakeupHandler : public MessageHandler {
|
||||||
|
public:
|
||||||
|
WakeupHandler() {}
|
||||||
|
void handleMessage(const Message &message) override;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void wakeSessions();
|
void wakeSessions();
|
||||||
std::optional<bool> isAnyAppSessionActive();
|
std::optional<bool> isAnyAppSessionActive();
|
||||||
|
@ -71,6 +78,7 @@ class PowerSessionManager : public MessageHandler {
|
||||||
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
|
std::unordered_set<PowerHintSession *> mSessions; // protected by mLock
|
||||||
std::unordered_map<int, int> mTidRefCountMap; // protected by mLock
|
std::unordered_map<int, int> mTidRefCountMap; // protected by mLock
|
||||||
std::unordered_map<int, std::unordered_set<PowerHintSession *>> mTidSessionListMap;
|
std::unordered_map<int, std::unordered_set<PowerHintSession *>> mTidSessionListMap;
|
||||||
|
sp<WakeupHandler> mWakeupHandler;
|
||||||
bool mActive; // protected by mLock
|
bool mActive; // protected by mLock
|
||||||
/**
|
/**
|
||||||
* mLock to pretect the above data objects opertions.
|
* mLock to pretect the above data objects opertions.
|
||||||
|
@ -82,7 +90,9 @@ class PowerSessionManager : public MessageHandler {
|
||||||
: kDisableBoostHintName(::android::base::GetProperty(kPowerHalAdpfDisableTopAppBoost,
|
: kDisableBoostHintName(::android::base::GetProperty(kPowerHalAdpfDisableTopAppBoost,
|
||||||
"ADPF_DISABLE_TA_BOOST")),
|
"ADPF_DISABLE_TA_BOOST")),
|
||||||
mActive(false),
|
mActive(false),
|
||||||
mDisplayRefreshRate(60) {}
|
mDisplayRefreshRate(60) {
|
||||||
|
mWakeupHandler = sp<WakeupHandler>(new WakeupHandler());
|
||||||
|
}
|
||||||
PowerSessionManager(PowerSessionManager const &) = delete;
|
PowerSessionManager(PowerSessionManager const &) = delete;
|
||||||
void operator=(PowerSessionManager const &) = delete;
|
void operator=(PowerSessionManager const &) = delete;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue