Merge "Create hint session asynchronously" into udc-dev am: 5c406a3cad am: e570abbeff

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22951911

Change-Id: I8325e452da0a0ce1cae6b91c28670bcbd6e9d2cc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Matt Buckley
2023-05-05 00:24:51 +00:00
committed by Automerger Merge Worker
2 changed files with 32 additions and 12 deletions

View File

@@ -20,11 +20,14 @@
#include <private/performance_hint_private.h> #include <private/performance_hint_private.h>
#include <utils/Log.h> #include <utils/Log.h>
#include <chrono>
#include <vector> #include <vector>
#include "../Properties.h" #include "../Properties.h"
#include "thread/CommonPool.h" #include "thread/CommonPool.h"
using namespace std::chrono_literals;
namespace android { namespace android {
namespace uirenderer { namespace uirenderer {
namespace renderthread { namespace renderthread {
@@ -96,10 +99,25 @@ HintSessionWrapper::~HintSessionWrapper() {
} }
bool HintSessionWrapper::init() { bool HintSessionWrapper::init() {
// If it already exists, broke last time we tried this, shouldn't be running, or if (mHintSession != nullptr) return true;
// If we're waiting for the session
if (mHintSessionFuture.valid()) {
// If the session is here
if (mHintSessionFuture.wait_for(0s) == std::future_status::ready) {
mHintSession = mHintSessionFuture.get();
if (mHintSession != nullptr) {
mSessionValid = true;
return true;
}
}
return false;
}
// If it broke last time we tried this, shouldn't be running, or
// has bad argument values, don't even bother // has bad argument values, don't even bother
if (mHintSession != nullptr || !mSessionValid || !Properties::useHintManager || if (!mSessionValid || !Properties::useHintManager || !Properties::isDrawingEnabled() ||
!Properties::isDrawingEnabled() || mUiThreadId < 0 || mRenderThreadId < 0) { mUiThreadId < 0 || mRenderThreadId < 0) {
return false; return false;
} }
@@ -118,15 +136,14 @@ bool HintSessionWrapper::init() {
// Use a placeholder target value to initialize, // Use a placeholder target value to initialize,
// this will always be replaced elsewhere before it gets used // this will always be replaced elsewhere before it gets used
int64_t defaultTargetDurationNanos = 16666667; int64_t defaultTargetDurationNanos = 16666667;
mHintSession = mHintSessionFuture = CommonPool::async([=, tids = std::move(tids)] {
gAPH_createSessionFn(manager, tids.data(), tids.size(), defaultTargetDurationNanos); return gAPH_createSessionFn(manager, tids.data(), tids.size(), defaultTargetDurationNanos);
});
mSessionValid = !!mHintSession; return false;
return mSessionValid;
} }
void HintSessionWrapper::updateTargetWorkDuration(long targetWorkDurationNanos) { void HintSessionWrapper::updateTargetWorkDuration(long targetWorkDurationNanos) {
if (mHintSession == nullptr) return; if (!init()) return;
targetWorkDurationNanos = targetWorkDurationNanos * Properties::targetCpuTimePercentage / 100; targetWorkDurationNanos = targetWorkDurationNanos * Properties::targetCpuTimePercentage / 100;
if (targetWorkDurationNanos != mLastTargetWorkDuration && if (targetWorkDurationNanos != mLastTargetWorkDuration &&
targetWorkDurationNanos > kSanityCheckLowerBound && targetWorkDurationNanos > kSanityCheckLowerBound &&
@@ -138,7 +155,7 @@ void HintSessionWrapper::updateTargetWorkDuration(long targetWorkDurationNanos)
} }
void HintSessionWrapper::reportActualWorkDuration(long actualDurationNanos) { void HintSessionWrapper::reportActualWorkDuration(long actualDurationNanos) {
if (mHintSession == nullptr) return; if (!init()) return;
if (actualDurationNanos > kSanityCheckLowerBound && if (actualDurationNanos > kSanityCheckLowerBound &&
actualDurationNanos < kSanityCheckUpperBound) { actualDurationNanos < kSanityCheckUpperBound) {
gAPH_reportActualWorkDurationFn(mHintSession, actualDurationNanos); gAPH_reportActualWorkDurationFn(mHintSession, actualDurationNanos);
@@ -146,7 +163,7 @@ void HintSessionWrapper::reportActualWorkDuration(long actualDurationNanos) {
} }
void HintSessionWrapper::sendLoadResetHint() { void HintSessionWrapper::sendLoadResetHint() {
if (mHintSession == nullptr) return; if (!init()) return;
nsecs_t now = systemTime(); nsecs_t now = systemTime();
if (now - mLastFrameNotification > kResetHintTimeout) { if (now - mLastFrameNotification > kResetHintTimeout) {
gAPH_sendHintFn(mHintSession, static_cast<int>(SessionHint::CPU_LOAD_RESET)); gAPH_sendHintFn(mHintSession, static_cast<int>(SessionHint::CPU_LOAD_RESET));
@@ -155,7 +172,7 @@ void HintSessionWrapper::sendLoadResetHint() {
} }
void HintSessionWrapper::sendLoadIncreaseHint() { void HintSessionWrapper::sendLoadIncreaseHint() {
if (mHintSession == nullptr) return; if (!init()) return;
gAPH_sendHintFn(mHintSession, static_cast<int>(SessionHint::CPU_LOAD_UP)); gAPH_sendHintFn(mHintSession, static_cast<int>(SessionHint::CPU_LOAD_UP));
} }

View File

@@ -18,6 +18,8 @@
#include <android/performance_hint.h> #include <android/performance_hint.h>
#include <future>
#include "utils/TimeUtils.h" #include "utils/TimeUtils.h"
namespace android { namespace android {
@@ -38,6 +40,7 @@ public:
private: private:
APerformanceHintSession* mHintSession = nullptr; APerformanceHintSession* mHintSession = nullptr;
std::future<APerformanceHintSession*> mHintSessionFuture;
nsecs_t mLastFrameNotification = 0; nsecs_t mLastFrameNotification = 0;
nsecs_t mLastTargetWorkDuration = 0; nsecs_t mLastTargetWorkDuration = 0;