summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/RegionSamplingThread.h
diff options
context:
space:
mode:
author Kevin DuBois <kevindubois@google.com> 2019-05-06 16:46:45 -0700
committer Kevin DuBois <kevindubois@google.com> 2019-05-09 09:03:31 -0700
commit26afc788434bf0f120db2fbd980d557f07bd1283 (patch)
tree6f25c517e9d5350a6f8aad1b9bd90033050df9df /services/surfaceflinger/RegionSamplingThread.h
parentc81a799672f6e5a97b8229bc9fbcdecfd9c4d6d5 (diff)
sf: avoid lock on main thread during luma calc
The luma calculation operation was previously done while holding a lock that was also used to protect the request to collect the next sample. When the main thread would request the next sample, it could stall waiting on the longer luma calculation to complete. This patch refactors the sampling request locking mechanisms so sampling request signalling is protected by one lock, and the members needed during the sampling thread operations are protected by another lock. Fixes: http://b/132110951 Test: collect traces during during problematic animation (agsa initial query for info) and verify problem went away Test: visually inspect jank during agsa continued conversation Test: libgui#RegionSamplingTest Test: monkey 6000 event inject Change-Id: I291d6bcb80d0588f2e1f3689bfdd4b3434132e90
Diffstat (limited to 'services/surfaceflinger/RegionSamplingThread.h')
-rw-r--r--services/surfaceflinger/RegionSamplingThread.h23
1 files changed, 11 insertions, 12 deletions
diff --git a/services/surfaceflinger/RegionSamplingThread.h b/services/surfaceflinger/RegionSamplingThread.h
index 72b20420ef..08134e6acd 100644
--- a/services/surfaceflinger/RegionSamplingThread.h
+++ b/services/surfaceflinger/RegionSamplingThread.h
@@ -100,7 +100,7 @@ private:
void binderDied(const wp<IBinder>& who) override;
void checkForStaleLuma();
- void captureSample() REQUIRES(mMutex);
+ void captureSample();
void threadMain();
SurfaceFlinger& mFlinger;
@@ -110,19 +110,18 @@ private:
std::unique_ptr<SamplingOffsetCallback> const mPhaseCallback;
- std::mutex mThreadMutex;
- std::thread mThread GUARDED_BY(mThreadMutex);
+ std::thread mThread;
- std::mutex mMutex;
+ std::mutex mThreadControlMutex;
std::condition_variable_any mCondition;
- bool mRunning GUARDED_BY(mMutex) = true;
- bool mSampleRequested GUARDED_BY(mMutex) = false;
-
- std::unordered_map<wp<IBinder>, Descriptor, WpHash> mDescriptors GUARDED_BY(mMutex);
- std::chrono::nanoseconds lastSampleTime GUARDED_BY(mMutex);
- bool mDiscardedFrames GUARDED_BY(mMutex) = false;
-
- sp<GraphicBuffer> mCachedBuffer GUARDED_BY(mMutex) = nullptr;
+ bool mRunning GUARDED_BY(mThreadControlMutex) = true;
+ bool mSampleRequested GUARDED_BY(mThreadControlMutex) = false;
+ bool mDiscardedFrames GUARDED_BY(mThreadControlMutex) = false;
+ std::chrono::nanoseconds lastSampleTime GUARDED_BY(mThreadControlMutex);
+
+ std::mutex mSamplingMutex;
+ std::unordered_map<wp<IBinder>, Descriptor, WpHash> mDescriptors GUARDED_BY(mSamplingMutex);
+ sp<GraphicBuffer> mCachedBuffer GUARDED_BY(mSamplingMutex) = nullptr;
};
} // namespace android