Reduce number of Fence syscalls made.
This patch saves 6 or more Fence syscalls per frame.
* Timelines are updated just before adding a new fence
since the newly added fence is unlikely to have signaled.
* Layer::latch uses a FenceTime now, so the signal time is
automatically shared with other owners of the FenceTime.
* DispSync uses FenceTime now, only using cached values of
the signal time that have been populated by a Timeline.
Test: SurfaceFlinger boots and dumps still work.
Change-Id: Ie0cfc1af2aca143dd8d5f08f08dbe1e597376f2f
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index a6b34c2..99b39cb 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1553,6 +1553,7 @@
// |mStateLock| not needed as we are on the main thread
const sp<const DisplayDevice> hw(getDefaultDisplayDeviceLocked());
+ mGlCompositionDoneTimeline.updateSignalTimes();
std::shared_ptr<FenceTime> glCompositionDoneFenceTime;
if (mHwc->hasClientComposition(HWC_DISPLAY_PRIMARY)) {
glCompositionDoneFenceTime =
@@ -1561,12 +1562,11 @@
} else {
glCompositionDoneFenceTime = FenceTime::NO_FENCE;
}
- mGlCompositionDoneTimeline.updateSignalTimes();
+ mDisplayTimeline.updateSignalTimes();
sp<Fence> presentFence = mHwc->getPresentFence(HWC_DISPLAY_PRIMARY);
auto presentFenceTime = std::make_shared<FenceTime>(presentFence);
mDisplayTimeline.push(presentFenceTime);
- mDisplayTimeline.updateSignalTimes();
nsecs_t vsyncPhase = mPrimaryDispSync.computeNextRefresh(0);
nsecs_t vsyncInterval = mPrimaryDispSync.getPeriod();
@@ -1591,8 +1591,8 @@
}
});
- if (presentFence->isValid()) {
- if (mPrimaryDispSync.addPresentFence(presentFence)) {
+ if (presentFenceTime->isValid()) {
+ if (mPrimaryDispSync.addPresentFence(presentFenceTime)) {
enableHardwareVsync();
} else {
disableHardwareVsync(false);