From 33444e5238d2e9a686810dbfa192e64585b58040 Mon Sep 17 00:00:00 2001 From: Will McVicker Date: Thu, 18 Jul 2024 12:56:42 +0530 Subject: [PATCH] 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 --- power-libperfmgr/PowerHintSession.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/power-libperfmgr/PowerHintSession.cpp b/power-libperfmgr/PowerHintSession.cpp index 0507096..a7e5c25 100644 --- a/power-libperfmgr/PowerHintSession.cpp +++ b/power-libperfmgr/PowerHintSession.cpp @@ -153,6 +153,10 @@ PowerHintSession::~PowerHintSession() { sz = sz = StringPrintf("adpf.%s-active", idstr.c_str()); ATRACE_INT(sz.c_str(), 0); } + { + std::lock_guard guard(mSessionLock); + mSessionClosed.store(true); + } mHintTimerHandler->setSessionDead(); delete mDescriptor; } @@ -376,20 +380,19 @@ void PowerHintSession::setStale() { } void PowerHintSession::wakeup() { + std::lock_guard guard(mSessionLock); + + // We only wake up non-paused and stale sessions + if (mSessionClosed || !isActive() || !isStale()) + return; if (ATRACE_ENABLED()) { std::string tag = StringPrintf("wakeup.%s(a:%d,s:%d)", getIdString().c_str(), isActive(), isStale()); ATRACE_NAME(tag.c_str()); } - // We only wake up non-paused and stale sessions - if (!isActive() || !isStale()) - return; std::shared_ptr adpfConfig = HintManager::GetInstance()->GetAdpfProfile(); int min = std::max(mDescriptor->current_min, static_cast(adpfConfig->mUclampMinInit)); - { - std::lock_guard guard(mSessionLock); - mDescriptor->current_min = min; - } + mDescriptor->current_min = min; PowerSessionManager::getInstance()->setUclampMinLocked(this, min); PowerHintMonitor::getInstance()->getLooper()->removeMessages(mHintTimerHandler); PowerHintMonitor::getInstance()->getLooper()->sendMessage(