sm6375-common: power-libperfmgr: Fix race between closing a session and receiving a boost

We need to be holding the session lock when we dereference mDescriptor
since mDescriptor is destroyed when the session is closed. This patch
takes the session lock and verifies if it's still open during wakeup.

Test: vts run -m VtsHalGraphicsComposerV2_4TargetTest
Bug: 232992641
Change-Id: I4000a85bf2932cfdcddd3006d671a3c91ed32c48
This commit is contained in:
Will McVicker 2024-07-18 20:16:00 +05:30 committed by Anand S
parent 0118a38571
commit 00036d86cc
No known key found for this signature in database
GPG key ID: 3B2983FA448B3D61

View file

@ -153,6 +153,10 @@ 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);
}
mHintTimerHandler->setSessionDead(); mHintTimerHandler->setSessionDead();
delete mDescriptor; delete mDescriptor;
} }
@ -376,20 +380,19 @@ void PowerHintSession::setStale() {
} }
void PowerHintSession::wakeup() { void PowerHintSession::wakeup() {
std::lock_guard<std::mutex> guard(mSessionLock);
// We only wake up non-paused and stale sessions
if (mSessionClosed || !isActive() || !isStale())
return;
if (ATRACE_ENABLED()) { if (ATRACE_ENABLED()) {
std::string tag = std::string tag =
StringPrintf("wakeup.%s(a:%d,s:%d)", getIdString().c_str(), isActive(), isStale()); StringPrintf("wakeup.%s(a:%d,s:%d)", getIdString().c_str(), isActive(), isStale());
ATRACE_NAME(tag.c_str()); ATRACE_NAME(tag.c_str());
} }
// We only wake up non-paused and stale sessions
if (!isActive() || !isStale())
return;
std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); std::shared_ptr<AdpfConfig> adpfConfig = HintManager::GetInstance()->GetAdpfProfile();
int min = std::max(mDescriptor->current_min, static_cast<int>(adpfConfig->mUclampMinInit)); int min = std::max(mDescriptor->current_min, static_cast<int>(adpfConfig->mUclampMinInit));
{
std::lock_guard<std::mutex> guard(mSessionLock);
mDescriptor->current_min = min; mDescriptor->current_min = min;
}
PowerSessionManager::getInstance()->setUclampMinLocked(this, min); PowerSessionManager::getInstance()->setUclampMinLocked(this, min);
PowerHintMonitor::getInstance()->getLooper()->removeMessages(mHintTimerHandler); PowerHintMonitor::getInstance()->getLooper()->removeMessages(mHintTimerHandler);
PowerHintMonitor::getInstance()->getLooper()->sendMessage( PowerHintMonitor::getInstance()->getLooper()->sendMessage(