SF: region sampling scheduling optimization
Schedule the region sampling thread more wisely by estimating when
the next invalidate is going to happen. This makes the region sampling
to be scheduled often at times where the main thread is idle, without
eating the budget in an invalidate message.
Bug: 181983990
Test: SF unit tests
Test: observe systrace
Change-Id: I1faca3aa7f882ed7c69e77e6a0877c10d57f0f1c
diff --git a/services/surfaceflinger/Scheduler/MessageQueue.h b/services/surfaceflinger/Scheduler/MessageQueue.h
index 2934af0..58ce9b9 100644
--- a/services/surfaceflinger/Scheduler/MessageQueue.h
+++ b/services/surfaceflinger/Scheduler/MessageQueue.h
@@ -72,6 +72,7 @@
virtual void postMessage(sp<MessageHandler>&&) = 0;
virtual void invalidate() = 0;
virtual void refresh() = 0;
+ virtual std::optional<std::chrono::steady_clock::time_point> nextExpectedInvalidate() = 0;
};
// ---------------------------------------------------------------------------
@@ -81,9 +82,13 @@
class MessageQueue : public android::MessageQueue {
protected:
class Handler : public MessageHandler {
- enum { eventMaskInvalidate = 0x1, eventMaskRefresh = 0x2, eventMaskTransaction = 0x4 };
+ enum : uint32_t {
+ eventMaskInvalidate = 0x1,
+ eventMaskRefresh = 0x2,
+ eventMaskTransaction = 0x4
+ };
MessageQueue& mQueue;
- int32_t mEventMask;
+ std::atomic<uint32_t> mEventMask;
std::atomic<int64_t> mVsyncId;
std::atomic<nsecs_t> mExpectedVSyncTime;
@@ -92,6 +97,7 @@
void handleMessage(const Message& message) override;
virtual void dispatchRefresh();
virtual void dispatchInvalidate(int64_t vsyncId, nsecs_t expectedVSyncTimestamp);
+ virtual bool invalidatePending();
};
friend class Handler;
@@ -107,7 +113,8 @@
TracedOrdinal<std::chrono::nanoseconds> workDuration
GUARDED_BY(mutex) = {"VsyncWorkDuration-sf", std::chrono::nanoseconds(0)};
std::chrono::nanoseconds lastCallbackTime GUARDED_BY(mutex) = std::chrono::nanoseconds{0};
- bool mScheduled GUARDED_BY(mutex) = false;
+ bool scheduled GUARDED_BY(mutex) = false;
+ std::optional<nsecs_t> expectedWakeupTime GUARDED_BY(mutex);
TracedOrdinal<int> value = {"VSYNC-sf", 0};
};
@@ -141,6 +148,8 @@
// sends REFRESH message at next VSYNC
void refresh() override;
+
+ std::optional<std::chrono::steady_clock::time_point> nextExpectedInvalidate() override;
};
} // namespace impl