android_device_motorola_sm6.../power-libperfmgr/PowerSessionManager.cpp
Matt Buckley df11f1d291
sm6375-common: power-libperfmgr: Ignore system hint sessions for universal boost
Currently PowerHAL does not distinguish between system processes and
apps when deciding whether to apply universal boost. This patch
distinguishes system sessions and app sessions and ignores system ones,
making the disabling of universal boost dependent on the presence of app
hint sessions.

Bug: b/230511824
Test: manual
Change-Id: I08dea29b3a45f2ba69ed99a9f188fa83ba143423
2024-07-18 12:56:42 +05:30

162 lines
4.8 KiB
C++

/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "powerhal-libperfmgr"
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
#include "PowerSessionManager.h"
#include <log/log.h>
#include <perfmgr/HintManager.h>
#include <processgroup/processgroup.h>
#include <utils/Trace.h>
namespace aidl {
namespace google {
namespace hardware {
namespace power {
namespace impl {
namespace pixel {
using ::android::perfmgr::HintManager;
void PowerSessionManager::updateHintMode(const std::string &mode, bool enabled) {
ALOGV("PowerSessionManager::updateHintMode: mode: %s, enabled: %d", mode.c_str(), enabled);
if (enabled && mode.compare(0, 8, "REFRESH_") == 0) {
if (mode.compare("REFRESH_120FPS") == 0) {
mDisplayRefreshRate = 120;
} else if (mode.compare("REFRESH_90FPS") == 0) {
mDisplayRefreshRate = 90;
} else if (mode.compare("REFRESH_60FPS") == 0) {
mDisplayRefreshRate = 60;
}
}
if (HintManager::GetInstance()->GetAdpfProfile()) {
HintManager::GetInstance()->SetAdpfProfile(mode);
}
}
int PowerSessionManager::getDisplayRefreshRate() {
return mDisplayRefreshRate;
}
void PowerSessionManager::addPowerSession(PowerHintSession *session) {
std::lock_guard<std::mutex> guard(mLock);
for (auto t : session->getTidList()) {
if (mTidRefCountMap.find(t) == mTidRefCountMap.end()) {
if (!SetTaskProfiles(t, {"ResetUclampGrp"})) {
ALOGW("Failed to set ResetUclampGrp task profile for tid:%d", t);
} else {
mTidRefCountMap[t] = 1;
}
continue;
}
if (mTidRefCountMap[t] <= 0) {
ALOGE("Error! Unexpected zero/negative RefCount:%d for tid:%d", mTidRefCountMap[t], t);
continue;
}
mTidRefCountMap[t]++;
}
mSessions.insert(session);
}
void PowerSessionManager::removePowerSession(PowerHintSession *session) {
std::lock_guard<std::mutex> guard(mLock);
for (auto t : session->getTidList()) {
if (mTidRefCountMap.find(t) == mTidRefCountMap.end()) {
ALOGE("Unexpected Error! Failed to look up tid:%d in TidRefCountMap", t);
continue;
}
mTidRefCountMap[t]--;
if (mTidRefCountMap[t] <= 0) {
if (!SetTaskProfiles(t, {"NoResetUclampGrp"})) {
ALOGW("Failed to set NoResetUclampGrp task profile for tid:%d", t);
}
mTidRefCountMap.erase(t);
}
}
mSessions.erase(session);
}
std::optional<bool> PowerSessionManager::isAnyAppSessionActive() {
std::lock_guard<std::mutex> guard(mLock);
bool active = false;
for (PowerHintSession *s : mSessions) {
// session active and not stale is actually active.
if (s->isActive() && !s->isStale() && s->isAppSession()) {
active = true;
break;
}
}
if (active == mActive) {
return std::nullopt;
} else {
mActive = active;
}
return active;
}
void PowerSessionManager::handleMessage(const Message &) {
auto active = isAnyAppSessionActive();
if (!active.has_value()) {
return;
}
if (active.value()) {
disableSystemTopAppBoost();
} else {
enableSystemTopAppBoost();
}
}
void PowerSessionManager::enableSystemTopAppBoost() {
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
ALOGV("PowerSessionManager::enableSystemTopAppBoost!!");
HintManager::GetInstance()->EndHint(kDisableBoostHintName);
}
}
void PowerSessionManager::disableSystemTopAppBoost() {
if (HintManager::GetInstance()->IsHintSupported(kDisableBoostHintName)) {
ALOGV("PowerSessionManager::disableSystemTopAppBoost!!");
HintManager::GetInstance()->DoHint(kDisableBoostHintName);
}
}
// =========== PowerHintMonitor implementation start from here ===========
void PowerHintMonitor::start() {
if (!isRunning()) {
run("PowerHintMonitor", ::android::PRIORITY_HIGHEST);
}
}
bool PowerHintMonitor::threadLoop() {
while (true) {
mLooper->pollOnce(-1);
}
return true;
}
sp<Looper> PowerHintMonitor::getLooper() {
return mLooper;
}
} // namespace pixel
} // namespace impl
} // namespace power
} // namespace hardware
} // namespace google
} // namespace aidl