summaryrefslogtreecommitdiff
path: root/libs/ui/FenceTime.cpp
diff options
context:
space:
mode:
author Ady Abraham <adyabr@google.com> 2021-03-31 16:56:03 -0700
committer Ady Abraham <adyabr@google.com> 2021-04-02 22:30:12 +0000
commit6c1b7aca75e3fb0d45789b15007202493de6bc3d (patch)
tree33e2216ceb207348dad96465d653082b487547ec /libs/ui/FenceTime.cpp
parentd043c248649e8e9b51c73b6d3c02257882149dcc (diff)
SF: use FenceTime when possible
Fence::getSignalTime is calling a system call everytime, where FenceTime caches the signal time. This shows reduction in simpleperf for the main thread 2.23% -> 1.25% Test: simpleperf for PIP + Notification shade expansion Bug: 184378996 Change-Id: I182db2ddfcb7fdbde758f5d87357a16e60c1bb07
Diffstat (limited to 'libs/ui/FenceTime.cpp')
-rw-r--r--libs/ui/FenceTime.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/libs/ui/FenceTime.cpp b/libs/ui/FenceTime.cpp
index bdfe04b0dd..538c1d2a42 100644
--- a/libs/ui/FenceTime.cpp
+++ b/libs/ui/FenceTime.cpp
@@ -97,6 +97,34 @@ bool FenceTime::isValid() const {
return mState != State::INVALID;
}
+status_t FenceTime::wait(int timeout) {
+ // See if we already have a cached value we can return.
+ nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed);
+ if (signalTime != Fence::SIGNAL_TIME_PENDING) {
+ return NO_ERROR;
+ }
+
+ // Hold a reference to the fence on the stack in case the class'
+ // reference is removed by another thread. This prevents the
+ // fence from being destroyed until the end of this method, where
+ // we conveniently do not have the lock held.
+ sp<Fence> fence;
+ {
+ // With the lock acquired this time, see if we have the cached
+ // value or if we need to poll the fence.
+ std::lock_guard<std::mutex> lock(mMutex);
+ if (!mFence.get()) {
+ // Another thread set the signal time just before we added the
+ // reference to mFence.
+ return NO_ERROR;
+ }
+ fence = mFence;
+ }
+
+ // Make the system call without the lock held.
+ return fence->wait(timeout);
+}
+
nsecs_t FenceTime::getSignalTime() {
// See if we already have a cached value we can return.
nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed);