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));
|
||||
next_min = std::max(static_cast<int>(adpfConfig->mUclampMinLow), next_min);
|
||||
setSessionUclampMin(next_min);
|
||||
mStaleTimerHandler->updateTimer(getStaleTime());
|
||||
|
||||
mAdaptiveCpu->ReportWorkDurations(actualDurations, mDescriptor->duration);
|
||||
|
||||
|
@ -380,7 +379,12 @@ bool PowerHintSession::isActive() {
|
|||
|
||||
bool PowerHintSession::isTimeout() {
|
||||
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 {
|
||||
|
@ -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() {
|
||||
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::StaleTimerHandler::updateTimer(time_point<steady_clock> staleTime) {
|
||||
mStaleTime.store(staleTime);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
nanoseconds staleDuration = std::chrono::nanoseconds(
|
||||
static_cast<int64_t>(mSession->mDescriptor->duration.count() *
|
||||
HintManager::GetInstance()->GetAdpfProfile()->mStaleTimeFactor));
|
||||
mStaleTime.store(now + staleDuration);
|
||||
int64_t next = static_cast<int64_t>(staleDuration.count());
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mMessageLock);
|
||||
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mSession->mStaleTimerHandler);
|
||||
PowerHintMonitor::getInstance()->getLooper()->sendMessage(mSession->mStaleTimerHandler,
|
||||
NULL);
|
||||
PowerHintMonitor::getInstance()->getLooper()->sendMessageDelayed(
|
||||
next, 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());
|
||||
|
@ -446,12 +438,11 @@ void PowerHintSession::StaleTimerHandler::handleMessage(const Message &) {
|
|||
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.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:
|
||||
class StaleTimerHandler : public MessageHandler {
|
||||
public:
|
||||
StaleTimerHandler(PowerHintSession *session)
|
||||
: mSession(session), mIsMonitoring(false), mIsSessionDead(false) {}
|
||||
StaleTimerHandler(PowerHintSession *session) : mSession(session), mIsSessionDead(false) {}
|
||||
void updateTimer();
|
||||
void updateTimer(time_point<steady_clock> staleTime);
|
||||
void handleMessage(const Message &message) override;
|
||||
void setSessionDead();
|
||||
|
||||
|
@ -105,7 +103,6 @@ class PowerHintSession : public BnPowerHintSession {
|
|||
std::mutex mStaleLock;
|
||||
std::mutex mMessageLock;
|
||||
std::atomic<time_point<steady_clock>> mStaleTime;
|
||||
std::atomic<bool> mIsMonitoring;
|
||||
bool mIsSessionDead;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue