diff options
-rw-r--r-- | services/surfaceflinger/DisplayDevice.cpp | 4 | ||||
-rw-r--r-- | services/surfaceflinger/DisplayDevice.h | 1 | ||||
-rw-r--r-- | services/surfaceflinger/Scheduler/include/scheduler/Time.h | 1 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 84 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 10 | ||||
-rw-r--r-- | services/surfaceflinger/TransactionCallbackInvoker.cpp | 4 | ||||
-rw-r--r-- | services/surfaceflinger/TransactionCallbackInvoker.h | 2 | ||||
-rw-r--r-- | services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h | 4 |
8 files changed, 46 insertions, 64 deletions
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 86809007b4..bff301edd1 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -136,10 +136,6 @@ void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) mDeviceProductInfo = std::move(info); } -uint32_t DisplayDevice::getPageFlipCount() const { - return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); -} - auto DisplayDevice::getInputInfo() const -> InputInfo { gui::DisplayInfo info; info.displayId = getLayerStack().id; diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 2161436d44..10fc0954ad 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -259,7 +259,6 @@ public: /* ------------------------------------------------------------------------ * Debugging */ - uint32_t getPageFlipCount() const; std::string getDebugName() const; void dump(std::string& result) const; diff --git a/services/surfaceflinger/Scheduler/include/scheduler/Time.h b/services/surfaceflinger/Scheduler/include/scheduler/Time.h index 2b3ad2de94..487709b610 100644 --- a/services/surfaceflinger/Scheduler/include/scheduler/Time.h +++ b/services/surfaceflinger/Scheduler/include/scheduler/Time.h @@ -32,6 +32,7 @@ static_assert(SchedulerClock::is_steady); struct Duration; struct TimePoint : scheduler::SchedulerClock::time_point { + constexpr TimePoint() = default; explicit constexpr TimePoint(const Duration&); // Implicit conversion from std::chrono counterpart. diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 1fcbdfac36..8e19c3586a 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2247,7 +2247,6 @@ void SurfaceFlinger::composite(nsecs_t frameTime, int64_t vsyncId) scheduleComposite(FrameHint::kNone); } - postFrame(); postComposition(); const bool prevFrameHadClientComposition = mHadClientComposition; @@ -2363,7 +2362,7 @@ ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, void SurfaceFlinger::postComposition() { ATRACE_CALL(); - ALOGV("postComposition"); + ALOGV(__func__); const auto* display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); @@ -2378,18 +2377,19 @@ void SurfaceFlinger::postComposition() { } mPreviousPresentFences[1] = mPreviousPresentFences[0]; - mPreviousPresentFences[0].fence = + + auto presentFence = display ? getHwComposer().getPresentFence(display->getPhysicalId()) : Fence::NO_FENCE; - mPreviousPresentFences[0].fenceTime = - std::make_shared<FenceTime>(mPreviousPresentFences[0].fence); - nsecs_t now = systemTime(); + auto presentFenceTime = std::make_shared<FenceTime>(presentFence); + mPreviousPresentFences[0] = {presentFence, presentFenceTime}; + + const TimePoint presentTime = scheduler::SchedulerClock::now(); // Set presentation information before calling Layer::releasePendingBuffer, such that jank // information from previous' frame classification is already available when sending jank info // to clients, so they get jank classification as early as possible. - mFrameTimeline->setSfPresent(/* sfPresentTime */ now, mPreviousPresentFences[0].fenceTime, - glCompositionDoneFenceTime); + mFrameTimeline->setSfPresent(presentTime.ns(), presentFenceTime, glCompositionDoneFenceTime); // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might // be sampled a little later than when we started doing work for this frame, @@ -2397,11 +2397,10 @@ void SurfaceFlinger::postComposition() { const TimePoint compositeTime = TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); const Duration presentLatency = - mPresentLatencyTracker.trackPendingFrame(compositeTime, - mPreviousPresentFences[0].fenceTime); + mPresentLatencyTracker.trackPendingFrame(compositeTime, presentFenceTime); const auto& schedule = mScheduler->getVsyncSchedule(); - const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(TimePoint::fromNs(now)); + const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(presentTime); const Period vsyncPeriod = schedule.period(); const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; @@ -2409,9 +2408,9 @@ void SurfaceFlinger::postComposition() { presentLatency.ns()); for (const auto& layer: mLayersWithQueuedFrames) { - layer->onPostComposition(display, glCompositionDoneFenceTime, - mPreviousPresentFences[0].fenceTime, compositorTiming); - layer->releasePendingBuffer(/*dequeueReadyTime*/ now); + layer->onPostComposition(display, glCompositionDoneFenceTime, presentFenceTime, + compositorTiming); + layer->releasePendingBuffer(presentTime.ns()); } std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> @@ -2468,13 +2467,16 @@ void SurfaceFlinger::postComposition() { mSomeDataspaceChanged = false; mVisibleRegionsWereDirtyThisFrame = false; - mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0].fence); + mTransactionCallbackInvoker.addPresentFence(std::move(presentFence)); mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); mTransactionCallbackInvoker.clearCompletedTransactions(); + mTimeStats->incrementTotalFrames(); + mTimeStats->setPresentFenceGlobal(presentFenceTime); + if (display && display->isInternal() && display->getPowerMode() == hal::PowerMode::ON && - mPreviousPresentFences[0].fenceTime->isValid()) { - mScheduler->addPresentFence(mPreviousPresentFences[0].fenceTime); + presentFenceTime->isValid()) { + mScheduler->addPresentFence(std::move(presentFenceTime)); } const bool isDisplayConnected = @@ -2486,9 +2488,6 @@ void SurfaceFlinger::postComposition() { } } - mTimeStats->incrementTotalFrames(); - mTimeStats->setPresentFenceGlobal(mPreviousPresentFences[0].fenceTime); - const size_t sfConnections = mScheduler->getEventThreadConnectionCount(mSfConnectionHandle); const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle); mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections); @@ -2498,20 +2497,19 @@ void SurfaceFlinger::postComposition() { return; } - nsecs_t currentTime = systemTime(); if (mHasPoweredOff) { mHasPoweredOff = false; } else { - nsecs_t elapsedTime = currentTime - getBE().mLastSwapTime; - const size_t numPeriods = static_cast<size_t>(elapsedTime / vsyncPeriod.ns()); + const Duration elapsedTime = presentTime - getBE().mLastPresentTime; + const size_t numPeriods = static_cast<size_t>(elapsedTime.ns() / vsyncPeriod.ns()); if (numPeriods < SurfaceFlingerBE::NUM_BUCKETS - 1) { - getBE().mFrameBuckets[numPeriods] += elapsedTime; + getBE().mFrameBuckets[numPeriods] += elapsedTime.ns(); } else { - getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] += elapsedTime; + getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] += elapsedTime.ns(); } - getBE().mTotalTime += elapsedTime; + getBE().mTotalTime += elapsedTime.ns(); } - getBE().mLastSwapTime = currentTime; + getBE().mLastPresentTime = presentTime; // Cleanup any outstanding resources due to rendering a prior frame. getRenderEngine().cleanupPostRender(); @@ -2539,6 +2537,8 @@ void SurfaceFlinger::postComposition() { // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); } + + logFrameStats(presentTime); } FloatRect SurfaceFlinger::getMaxDisplayBounds() { @@ -2571,16 +2571,6 @@ void SurfaceFlinger::computeLayerBounds() { } } -void SurfaceFlinger::postFrame() { - const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); - if (display && getHwComposer().isConnected(display->getPhysicalId())) { - uint32_t flipCount = display->getPageFlipCount(); - if (flipCount % LOG_FRAME_STATS_PERIOD == 0) { - logFrameStats(); - } - } -} - void SurfaceFlinger::commitTransactions() { ATRACE_CALL(); @@ -4956,7 +4946,14 @@ void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result mFrameTimeline->parseArgs(args, result); } -void SurfaceFlinger::logFrameStats() { +void SurfaceFlinger::logFrameStats(TimePoint now) { + using namespace std::chrono_literals; + + static TimePoint sTimestamp = now; + if (now - sTimestamp < 30min) return; + sTimestamp = now; + + ATRACE_CALL(); mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); } @@ -5560,15 +5557,8 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r reply->writeInt32(0); reply->writeInt32(mDebugDisableHWC); return NO_ERROR; - case 1013: { - const auto display = getDefaultDisplayDevice(); - if (!display) { - return NAME_NOT_FOUND; - } - - reply->writeInt32(display->getPageFlipCount()); - return NO_ERROR; - } + case 1013: // Unused. + return NAME_NOT_FOUND; case 1014: { Mutex::Autolock _l(mStateLock); // daltonize diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 7609241f5a..dcf13b9fb4 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -56,6 +56,7 @@ #include <compositionengine/OutputColorSetting.h> #include <scheduler/Fps.h> #include <scheduler/PresentLatencyTracker.h> +#include <scheduler/Time.h> #include "ClientCache.h" #include "DisplayDevice.h" @@ -174,7 +175,7 @@ struct SurfaceFlingerBE { static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ nsecs_t mFrameBuckets[NUM_BUCKETS] = {}; nsecs_t mTotalTime = 0; - std::atomic<nsecs_t> mLastSwapTime = 0; + TimePoint mLastPresentTime; }; class SurfaceFlinger : public BnSurfaceComposer, @@ -386,10 +387,6 @@ private: using DumpArgs = Vector<String16>; using Dumper = std::function<void(const DumpArgs&, bool asProto, std::string&)>; - // This value is specified in number of frames. Log frame stats at most - // every half hour. - enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; - class State { public: explicit State(LayerVector::StateSet set) : stateSet(set), layersSortedByZ(set) {} @@ -938,7 +935,6 @@ private: * Compositing */ void postComposition() REQUIRES(kMainThreadContext); - void postFrame() REQUIRES(kMainThreadContext); /* * Display management @@ -1038,7 +1034,7 @@ private: void clearStatsLocked(const DumpArgs& args, std::string& result); void dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const; void dumpFrameTimeline(const DumpArgs& args, std::string& result) const; - void logFrameStats() REQUIRES(kMainThreadContext); + void logFrameStats(TimePoint now) REQUIRES(kMainThreadContext); void dumpVSync(std::string& result) const REQUIRES(mStateLock); void dumpStaticScreenStats(std::string& result) const; diff --git a/services/surfaceflinger/TransactionCallbackInvoker.cpp b/services/surfaceflinger/TransactionCallbackInvoker.cpp index d2c2e29a2f..e5de7591ef 100644 --- a/services/surfaceflinger/TransactionCallbackInvoker.cpp +++ b/services/surfaceflinger/TransactionCallbackInvoker.cpp @@ -178,8 +178,8 @@ status_t TransactionCallbackInvoker::addCallbackHandle(const sp<CallbackHandle>& return NO_ERROR; } -void TransactionCallbackInvoker::addPresentFence(const sp<Fence>& presentFence) { - mPresentFence = presentFence; +void TransactionCallbackInvoker::addPresentFence(sp<Fence> presentFence) { + mPresentFence = std::move(presentFence); } void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) { diff --git a/services/surfaceflinger/TransactionCallbackInvoker.h b/services/surfaceflinger/TransactionCallbackInvoker.h index 81d79f0777..59abe3347c 100644 --- a/services/surfaceflinger/TransactionCallbackInvoker.h +++ b/services/surfaceflinger/TransactionCallbackInvoker.h @@ -70,7 +70,7 @@ public: status_t registerUnpresentedCallbackHandle(const sp<CallbackHandle>& handle); void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks); - void addPresentFence(const sp<Fence>& presentFence); + void addPresentFence(sp<Fence>); void sendCallbacks(bool onCommitOnly); void clearCompletedTransactions() { diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h index c592358566..86b7a7abdf 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h +++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h @@ -425,7 +425,8 @@ public: mFlinger->clearStatsLocked(dumpArgs, result); mFlinger->dumpTimeStats(dumpArgs, fdp->ConsumeBool(), result); - FTL_FAKE_GUARD(kMainThreadContext, mFlinger->logFrameStats()); + FTL_FAKE_GUARD(kMainThreadContext, + mFlinger->logFrameStats(TimePoint::fromNs(fdp->ConsumeIntegral<nsecs_t>()))); result = fdp->ConsumeRandomLengthString().c_str(); mFlinger->dumpFrameTimeline(dumpArgs, result); @@ -612,7 +613,6 @@ public: mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mFdp.ConsumeIntegral<uid_t>()); FTL_FAKE_GUARD(kMainThreadContext, mFlinger->postComposition()); - FTL_FAKE_GUARD(kMainThreadContext, mFlinger->postFrame()); mFlinger->calculateExpectedPresentTime({}); |