diff options
| author | 2021-10-12 19:30:12 +0000 | |
|---|---|---|
| committer | 2022-01-05 22:34:59 +0000 | |
| commit | ef51fbaf55a7f85bda1be264d6a20852bb3367a9 (patch) | |
| tree | 88bd5db303193ad443bbe69a6e748e6df50a4c01 /services/surfaceflinger/SurfaceFlinger.cpp | |
| parent | f60ade6b4c52b1f41975ed9506df1dc0b28e8857 (diff) | |
Send power hints from surfaceflinger using the PowerAdvisor
Have SurfaceFlinger send timing hints to the PowerHAL to help meet the frame deadline and dynamically scale clock frequency for different workloads.
This patch additionally refactors a few closely related parts of the PowerAdvisor, and expands the logging there for this feature.
To enable the power hint session, use:
adb shell device_config put surface_flinger_native_boot AdpfFeature__adpf_cpu_hint true
Bug: b/195990840
Test: manual
Change-Id: Ib3eca9d08e0fb5e446ea7075630f741b48940f84
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.cpp')
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 5b783142f0..2ce84062cb 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -707,7 +707,6 @@ void SurfaceFlinger::bootFinished() { ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); mFlagManager = std::make_unique<android::FlagManager>(); - mPowerAdvisor.enablePowerHint(mFlagManager->use_adpf_cpu_hint()); mFrameTracer->initialize(); mFrameTimeline->onBootFinished(); @@ -737,7 +736,18 @@ void SurfaceFlinger::bootFinished() { } readPersistentProperties(); + std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); + std::vector<int32_t> tidList; + tidList.emplace_back(gettid()); + if (renderEngineTid.has_value()) { + tidList.emplace_back(*renderEngineTid); + } mPowerAdvisor.onBootFinished(); + mPowerAdvisor.enablePowerHint(mFlagManager->use_adpf_cpu_hint()); + if (mPowerAdvisor.usePowerHintSession()) { + mPowerAdvisor.startPowerHintSession(tidList); + } + mBootStage = BootStage::FINISHED; if (property_get_bool("sf.debug.show_refresh_rate_overlay", false)) { @@ -1909,6 +1919,13 @@ nsecs_t SurfaceFlinger::calculateExpectedPresentTime(DisplayStatInfo stats) cons } bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expectedVsyncTime) { + MainThreadScopedGuard mainThreadGuard(SF_MAIN_THREAD); + // we set this once at the beginning of commit to ensure consistency throughout the whole frame + mPowerHintSessionData.sessionEnabled = mPowerAdvisor.usePowerHintSession(); + if (mPowerHintSessionData.sessionEnabled) { + mPowerHintSessionData.commitStart = systemTime(); + } + // calculate the expected present time once and use the cached // value throughout this frame to make sure all layers are // seeing this same value. @@ -1922,6 +1939,10 @@ bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expected const nsecs_t lastScheduledPresentTime = mScheduledPresentTime; mScheduledPresentTime = expectedVsyncTime; + if (mPowerHintSessionData.sessionEnabled) { + mPowerAdvisor.setTargetWorkDuration(mExpectedPresentTime - + mPowerHintSessionData.commitStart); + } const auto vsyncIn = [&] { if (!ATRACE_ENABLED()) return 0.f; return (mExpectedPresentTime - systemTime()) / 1e6f; @@ -2061,6 +2082,10 @@ bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expected void SurfaceFlinger::composite(nsecs_t frameTime) { ATRACE_CALL(); + MainThreadScopedGuard mainThreadGuard(SF_MAIN_THREAD); + if (mPowerHintSessionData.sessionEnabled) { + mPowerHintSessionData.compositeStart = systemTime(); + } compositionengine::CompositionRefreshArgs refreshArgs; const auto& displays = ON_MAIN_THREAD(mDisplays); @@ -2114,6 +2139,11 @@ void SurfaceFlinger::composite(nsecs_t frameTime) { const auto presentTime = systemTime(); mCompositionEngine->present(refreshArgs); + + if (mPowerHintSessionData.sessionEnabled) { + mPowerHintSessionData.presentEnd = systemTime(); + } + mTimeStats->recordFrameDuration(frameTime, systemTime()); mScheduler->onPostComposition(presentTime); @@ -2161,6 +2191,13 @@ void SurfaceFlinger::composite(nsecs_t frameTime) { if (mCompositionEngine->needsAnotherUpdate()) { scheduleCommit(FrameHint::kNone); } + + // calculate total render time for performance hinting if adpf cpu hint is enabled, + if (mPowerHintSessionData.sessionEnabled) { + const nsecs_t flingerDuration = + (mPowerHintSessionData.presentEnd - mPowerHintSessionData.commitStart); + mPowerAdvisor.sendActualWorkDuration(flingerDuration, mPowerHintSessionData.presentEnd); + } } void SurfaceFlinger::updateLayerGeometry() { |