Skip to content

Commit eee4c9c

Browse files
author
Melody Hsu
committed
Time duration blocked on dequeueBuffer for stuffing recovery
Start buffer stuffing recovery only when severely buffer stuffed. Determined based on how long BBQ waits on buffer release. Waits shorter than this may simply be false positives for buffer stuffing recovery due to timing and should be ignored. Bug: b/294922229 Test: Manually check perfetto traces, presubmit, SysUi performance tests Flag: android.view.flags.buffer_stuffing_recovery Change-Id: Ic8c01edaebd599724fc7a9a67630069c05b567c1
1 parent e715810 commit eee4c9c

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

libs/gui/BLASTBufferQueue.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,16 +1221,12 @@ class BBQBufferQueueProducer : public BufferQueueProducer {
12211221
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
12221222
status_t waitForBufferRelease(std::unique_lock<std::mutex>& bufferQueueLock,
12231223
nsecs_t timeout) const override {
1224+
const auto startTime = std::chrono::steady_clock::now();
12241225
sp<BLASTBufferQueue> bbq = mBLASTBufferQueue.promote();
12251226
if (!bbq) {
12261227
return OK;
12271228
}
12281229

1229-
// Provide a callback for Choreographer to start buffer stuffing recovery when blocked
1230-
// on buffer release.
1231-
std::function<void()> callbackCopy = bbq->getWaitForBufferReleaseCallback();
1232-
if (callbackCopy) callbackCopy();
1233-
12341230
// BufferQueue has already checked if we have a free buffer. If there's an unread interrupt,
12351231
// we want to ignore it. This must be done before unlocking the BufferQueue lock to ensure
12361232
// we don't miss an interrupt.
@@ -1252,6 +1248,14 @@ class BBQBufferQueueProducer : public BufferQueueProducer {
12521248
}
12531249

12541250
bbq->releaseBufferCallback(id, fence, maxAcquiredBufferCount);
1251+
const nsecs_t durationNanos = std::chrono::duration_cast<std::chrono::nanoseconds>(
1252+
std::chrono::steady_clock::now() - startTime)
1253+
.count();
1254+
// Provide a callback for Choreographer to start buffer stuffing recovery when blocked
1255+
// on buffer release.
1256+
std::function<void(const nsecs_t)> callbackCopy = bbq->getWaitForBufferReleaseCallback();
1257+
if (callbackCopy) callbackCopy(durationNanos);
1258+
12551259
return OK;
12561260
}
12571261
#endif
@@ -1343,12 +1347,13 @@ void BLASTBufferQueue::setApplyToken(sp<IBinder> applyToken) {
13431347
mApplyToken = std::move(applyToken);
13441348
}
13451349

1346-
void BLASTBufferQueue::setWaitForBufferReleaseCallback(std::function<void()> callback) {
1350+
void BLASTBufferQueue::setWaitForBufferReleaseCallback(
1351+
std::function<void(const nsecs_t)> callback) {
13471352
std::lock_guard _lock{mWaitForBufferReleaseMutex};
13481353
mWaitForBufferReleaseCallback = std::move(callback);
13491354
}
13501355

1351-
std::function<void()> BLASTBufferQueue::getWaitForBufferReleaseCallback() const {
1356+
std::function<void(const nsecs_t)> BLASTBufferQueue::getWaitForBufferReleaseCallback() const {
13521357
std::lock_guard _lock{mWaitForBufferReleaseMutex};
13531358
return mWaitForBufferReleaseCallback;
13541359
}

libs/gui/include/gui/BLASTBufferQueue.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener {
143143
void setTransactionHangCallback(std::function<void(const std::string&)> callback);
144144
void setApplyToken(sp<IBinder>);
145145

146-
void setWaitForBufferReleaseCallback(std::function<void()> callback)
146+
void setWaitForBufferReleaseCallback(std::function<void(const nsecs_t)> callback)
147147
EXCLUDES(mWaitForBufferReleaseMutex);
148-
std::function<void()> getWaitForBufferReleaseCallback() const
148+
std::function<void(const nsecs_t)> getWaitForBufferReleaseCallback() const
149149
EXCLUDES(mWaitForBufferReleaseMutex);
150150

151151
virtual ~BLASTBufferQueue();
@@ -329,7 +329,8 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener {
329329

330330
std::unordered_set<uint64_t> mSyncedFrameNumbers GUARDED_BY(mMutex);
331331

332-
std::function<void()> mWaitForBufferReleaseCallback GUARDED_BY(mWaitForBufferReleaseMutex);
332+
std::function<void(const nsecs_t)> mWaitForBufferReleaseCallback
333+
GUARDED_BY(mWaitForBufferReleaseMutex);
333334
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
334335
// BufferReleaseChannel is used to communicate buffer releases from SurfaceFlinger to the
335336
// client.

0 commit comments

Comments
 (0)