sdm660-common: libperfmgr: ADPF: refine StaleTimeHandler
Bug: 256515601 Test: build Change-Id: Ia7f80c838961b837733c457b189f16c6433cf3c3
This commit is contained in:
parent
4ce650ebc9
commit
9636d797ca
2 changed files with 16 additions and 28 deletions
|
@ -346,7 +346,6 @@ ndk::ScopedAStatus PowerHintSession::reportActualWorkDuration(
|
||||||
mDescriptor->current_min + static_cast<int>(output));
|
mDescriptor->current_min + static_cast<int>(output));
|
||||||
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
|
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
|
||||||
setSessionUclampMin(next_min);
|
setSessionUclampMin(next_min);
|
||||||
mStaleTimerHandler->updateTimer(getStaleTime());
|
|
||||||
|
|
||||||
mAdaptiveCpu->ReportWorkDurations(actualDurations, mDescriptor->duration);
|
mAdaptiveCpu->ReportWorkDurations(actualDurations, mDescriptor->duration);
|
||||||
|
|
||||||
|
@ -380,7 +379,12 @@ bool PowerHintSession::isActive() {
|
||||||
|
|
||||||
bool PowerHintSession::isTimeout() {
|
bool PowerHintSession::isTimeout() {
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
return now >= getStaleTime();
|
time_point<steady_clock> staleTime =
|
||||||
|
mLastUpdatedTime.load() +
|
||||||
|
nanoseconds(static_cast<int64_t>(
|
||||||
|
mDescriptor->duration.count() *
|
||||||
|
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
||||||
|
return now >= staleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<int> &PowerHintSession::getTidList() const {
|
const std::vector<int> &PowerHintSession::getTidList() const {
|
||||||
|
@ -399,31 +403,19 @@ void PowerHintSession::setStale() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_point<steady_clock> PowerHintSession::getStaleTime() {
|
|
||||||
return mLastUpdatedTime.load() +
|
|
||||||
nanoseconds(static_cast<int64_t>(
|
|
||||||
mDescriptor->duration.count() *
|
|
||||||
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PowerHintSession::StaleTimerHandler::updateTimer() {
|
void PowerHintSession::StaleTimerHandler::updateTimer() {
|
||||||
time_point<steady_clock> staleTime =
|
auto now = std::chrono::steady_clock::now();
|
||||||
std::chrono::steady_clock::now() +
|
nanoseconds staleDuration = std::chrono::nanoseconds(
|
||||||
nanoseconds(static_cast<int64_t>(
|
static_cast<int64_t>(mSession->mDescriptor->duration.count() *
|
||||||
mSession->mDescriptor->duration.count() *
|
|
||||||
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
||||||
updateTimer(staleTime);
|
mStaleTime.store(now + staleDuration);
|
||||||
}
|
int64_t next = static_cast<int64_t>(staleDuration.count());
|
||||||
|
|
||||||
void PowerHintSession::StaleTimerHandler::updateTimer(time_point<steady_clock> staleTime) {
|
|
||||||
mStaleTime.store(staleTime);
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(mMessageLock);
|
std::lock_guard<std::mutex> guard(mMessageLock);
|
||||||
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
|
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
|
||||||
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mSession->mStaleTimerHandler,
|
PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
|
||||||
NULL);
|
next, mSession->mStaleTimerHandler, NULL);
|
||||||
}
|
}
|
||||||
mIsMonitoring.store(true);
|
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
const std::string idstr = mSession->getIdString();
|
const std::string idstr = mSession->getIdString();
|
||||||
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
|
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
|
||||||
|
@ -446,12 +438,11 @@ void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
|
||||||
next, mSession->mStaleTimerHandler, NULL);
|
next, mSession->mStaleTimerHandler, NULL);
|
||||||
} else {
|
} else {
|
||||||
mSession->setStale();
|
mSession->setStale();
|
||||||
mIsMonitoring.store(false);
|
|
||||||
}
|
}
|
||||||
if (ATRACE_ENABLED()) {
|
if (ATRACE_ENABLED()) {
|
||||||
const std::string idstr = mSession->getIdString();
|
const std::string idstr = mSession->getIdString();
|
||||||
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
|
std::string sz = StringPrintf("adpf.%s-timer.stale", idstr.c_str());
|
||||||
ATRACE_INT(sz.c_str(), mIsMonitoring ? 0 : 1);
|
ATRACE_INT(sz.c_str(), next > 0 ? 0 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,8 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
private:
|
private:
|
||||||
class StaleTimerHandler : public MessageHandler {
|
class StaleTimerHandler : public MessageHandler {
|
||||||
public:
|
public:
|
||||||
StaleTimerHandler(PowerHintSession *session)
|
StaleTimerHandler(PowerHintSession *session) : mSession(session), mIsSessionDead(false) {}
|
||||||
: mSession(session), mIsMonitoring(false), mIsSessionDead(false) {}
|
|
||||||
void updateTimer();
|
void updateTimer();
|
||||||
void updateTimer(time_point<steady_clock> staleTime);
|
|
||||||
void handleMessage(const Message &message) override;
|
void handleMessage(const Message &message) override;
|
||||||
void setSessionDead();
|
void setSessionDead();
|
||||||
|
|
||||||
|
@ -105,7 +103,6 @@ class PowerHintSession : public BnPowerHintSession {
|
||||||
std::mutex mStaleLock;
|
std::mutex mStaleLock;
|
||||||
std::mutex mMessageLock;
|
std::mutex mMessageLock;
|
||||||
std::atomic<time_point<steady_clock>> mStaleTime;
|
std::atomic<time_point<steady_clock>> mStaleTime;
|
||||||
std::atomic<bool> mIsMonitoring;
|
|
||||||
bool mIsSessionDead;
|
bool mIsSessionDead;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue