Skip to content

Commit 418b3be

Browse files
Melody HsuAndroid (Google) Code Review
authored andcommitted
Merge "Prune logic from buffer stuffing recovery using UIDs" into main
2 parents 969e7ea + 2e90a1e commit 418b3be

File tree

10 files changed

+0
-170
lines changed

10 files changed

+0
-170
lines changed

services/surfaceflinger/FrameTimeline/FrameTimeline.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <cinttypes>
3030
#include <numeric>
3131
#include <unordered_set>
32-
#include <vector>
3332

3433
#include "../Jank/JankTracker.h"
3534

@@ -1005,11 +1004,6 @@ void FrameTimeline::setSfPresent(nsecs_t sfPresentTime,
10051004
finalizeCurrentDisplayFrame();
10061005
}
10071006

1008-
const std::vector<std::shared_ptr<frametimeline::SurfaceFrame>>& FrameTimeline::getPresentFrames()
1009-
const {
1010-
return mPresentFrames;
1011-
}
1012-
10131007
void FrameTimeline::onCommitNotComposited() {
10141008
SFTRACE_CALL();
10151009
std::scoped_lock lock(mMutex);
@@ -1530,7 +1524,6 @@ void FrameTimeline::flushPendingPresentFences() {
15301524
mPendingPresentFences.erase(mPendingPresentFences.begin());
15311525
}
15321526

1533-
mPresentFrames.clear();
15341527
for (size_t i = 0; i < mPendingPresentFences.size(); i++) {
15351528
const auto& pendingPresentFence = mPendingPresentFences[i];
15361529
nsecs_t signalTime = Fence::SIGNAL_TIME_INVALID;
@@ -1544,12 +1537,6 @@ void FrameTimeline::flushPendingPresentFences() {
15441537
auto& displayFrame = pendingPresentFence.second;
15451538
displayFrame->onPresent(signalTime, mPreviousActualPresentTime);
15461539

1547-
// Surface frames have been jank classified and can be provided to caller
1548-
// to detect if buffer stuffing is occurring.
1549-
for (const auto& frame : displayFrame->getSurfaceFrames()) {
1550-
mPresentFrames.push_back(frame);
1551-
}
1552-
15531540
mPreviousPredictionPresentTime =
15541541
displayFrame->trace(mSurfaceFlingerPid, monoBootOffset,
15551542
mPreviousPredictionPresentTime, mFilterFramesBeforeTraceStarts);

services/surfaceflinger/FrameTimeline/FrameTimeline.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,6 @@ class FrameTimeline {
331331
virtual void setSfPresent(nsecs_t sfPresentTime, const std::shared_ptr<FenceTime>& presentFence,
332332
const std::shared_ptr<FenceTime>& gpuFence) = 0;
333333

334-
// Provides surface frames that have already been jank classified in the most recent
335-
// flush of pending present fences. This allows buffer stuffing detection from SF.
336-
virtual const std::vector<std::shared_ptr<frametimeline::SurfaceFrame>>& getPresentFrames()
337-
const = 0;
338-
339334
// Tells FrameTimeline that a frame was committed but not composited. This is used to flush
340335
// all the associated surface frames.
341336
virtual void onCommitNotComposited() = 0;
@@ -513,8 +508,6 @@ class FrameTimeline : public android::frametimeline::FrameTimeline {
513508
void setSfWakeUp(int64_t token, nsecs_t wakeupTime, Fps refreshRate, Fps renderRate) override;
514509
void setSfPresent(nsecs_t sfPresentTime, const std::shared_ptr<FenceTime>& presentFence,
515510
const std::shared_ptr<FenceTime>& gpuFence = FenceTime::NO_FENCE) override;
516-
const std::vector<std::shared_ptr<frametimeline::SurfaceFrame>>& getPresentFrames()
517-
const override;
518511
void onCommitNotComposited() override;
519512
void parseArgs(const Vector<String16>& args, std::string& result) override;
520513
void setMaxDisplayFrames(uint32_t size) override;
@@ -562,9 +555,6 @@ class FrameTimeline : public android::frametimeline::FrameTimeline {
562555
// display frame, this is a good starting size for the vector so that we can avoid the
563556
// internal vector resizing that happens with push_back.
564557
static constexpr uint32_t kNumSurfaceFramesInitial = 10;
565-
// Presented surface frames that have been jank classified and can
566-
// indicate of potential buffer stuffing.
567-
std::vector<std::shared_ptr<frametimeline::SurfaceFrame>> mPresentFrames;
568558
};
569559

570560
} // namespace impl

services/surfaceflinger/Scheduler/EventThread.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,6 @@ void EventThread::onModeRejected(PhysicalDisplayId displayId, DisplayModeId mode
512512
mCondition.notify_all();
513513
}
514514

515-
// Merge lists of buffer stuffed Uids
516-
void EventThread::addBufferStuffedUids(BufferStuffingMap bufferStuffedUids) {
517-
std::lock_guard<std::mutex> lock(mMutex);
518-
for (auto& [uid, count] : bufferStuffedUids) {
519-
mBufferStuffedUids.emplace_or_replace(uid, count);
520-
}
521-
}
522-
523515
void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
524516
DisplayEventConsumers consumers;
525517

@@ -761,10 +753,6 @@ void EventThread::generateFrameTimeline(VsyncEventData& outVsyncEventData, nsecs
761753

762754
void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event,
763755
const DisplayEventConsumers& consumers) {
764-
// List of Uids that have been sent vsync data with queued buffer count.
765-
// Used to keep track of which Uids can be removed from the map of
766-
// buffer stuffed clients.
767-
ftl::SmallVector<uid_t, 10> uidsPostedQueuedBuffers;
768756
for (const auto& consumer : consumers) {
769757
DisplayEventReceiver::Event copy = event;
770758
if (event.header.type == DisplayEventType::DISPLAY_EVENT_VSYNC) {
@@ -774,13 +762,6 @@ void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event,
774762
event.vsync.vsyncData.preferredExpectedPresentationTime(),
775763
event.vsync.vsyncData.preferredDeadlineTimestamp());
776764
}
777-
auto it = mBufferStuffedUids.find(consumer->mOwnerUid);
778-
if (it != mBufferStuffedUids.end()) {
779-
copy.vsync.vsyncData.numberQueuedBuffers = it->second;
780-
uidsPostedQueuedBuffers.emplace_back(consumer->mOwnerUid);
781-
} else {
782-
copy.vsync.vsyncData.numberQueuedBuffers = 0;
783-
}
784765
switch (consumer->postEvent(copy)) {
785766
case NO_ERROR:
786767
break;
@@ -796,12 +777,6 @@ void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event,
796777
removeDisplayEventConnectionLocked(consumer);
797778
}
798779
}
799-
// The clients that have already received the queued buffer count
800-
// can be removed from the buffer stuffed Uid list to avoid
801-
// being sent duplicate messages.
802-
for (auto uid : uidsPostedQueuedBuffers) {
803-
mBufferStuffedUids.erase(uid);
804-
}
805780
if (event.header.type == DisplayEventType::DISPLAY_EVENT_VSYNC &&
806781
FlagManager::getInstance().vrr_config()) {
807782
mLastCommittedVsyncTime =

services/surfaceflinger/Scheduler/EventThread.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ using gui::VsyncEventData;
5656
// ---------------------------------------------------------------------------
5757

5858
using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
59-
using BufferStuffingMap = ftl::SmallMap<uid_t, uint32_t, 10>;
6059

6160
enum class VSyncRequest {
6261
None = -2,
@@ -141,10 +140,6 @@ class EventThread {
141140

142141
virtual void onHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel,
143142
int32_t maxLevel) = 0;
144-
145-
// An elevated number of queued buffers in the server is detected. This propagates a
146-
// flag to Choreographer indicating that buffer stuffing recovery should begin.
147-
virtual void addBufferStuffedUids(BufferStuffingMap bufferStuffedUids) = 0;
148143
};
149144

150145
struct IEventThreadCallback {
@@ -199,8 +194,6 @@ class EventThread : public android::EventThread {
199194
void onHdcpLevelsChanged(PhysicalDisplayId displayId, int32_t connectedLevel,
200195
int32_t maxLevel) override;
201196

202-
void addBufferStuffedUids(BufferStuffingMap bufferStuffedUids) override;
203-
204197
private:
205198
friend EventThreadTest;
206199

@@ -241,10 +234,6 @@ class EventThread : public android::EventThread {
241234
scheduler::VSyncCallbackRegistration mVsyncRegistration GUARDED_BY(mMutex);
242235
frametimeline::TokenManager* const mTokenManager;
243236

244-
// All consumers that need to recover from buffer stuffing and the number
245-
// of their queued buffers.
246-
BufferStuffingMap mBufferStuffedUids GUARDED_BY(mMutex);
247-
248237
IEventThreadCallback& mCallback;
249238

250239
std::thread mThread;

services/surfaceflinger/Scheduler/Scheduler.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,6 @@ bool Scheduler::updateFrameRateOverridesLocked(GlobalSignals consideredSignals,
960960
return mFrameRateOverrideMappings.updateFrameRateOverridesByContent(frameRateOverrides);
961961
}
962962

963-
void Scheduler::addBufferStuffedUids(BufferStuffingMap bufferStuffedUids) {
964-
if (!mRenderEventThread) return;
965-
mRenderEventThread->addBufferStuffedUids(std::move(bufferStuffedUids));
966-
}
967-
968963
void Scheduler::promotePacesetterDisplay(PhysicalDisplayId pacesetterId, PromotionParams params) {
969964
std::shared_ptr<VsyncSchedule> pacesetterVsyncSchedule;
970965
{

services/surfaceflinger/Scheduler/Scheduler.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,6 @@ class Scheduler : public IEventThreadCallback, android::impl::MessageQueue {
337337
mPacesetterFrameDurationFractionToSkip = frameDurationFraction;
338338
}
339339

340-
// Propagates a flag to the EventThread indicating that buffer stuffing
341-
// recovery should begin.
342-
void addBufferStuffedUids(BufferStuffingMap bufferStuffedUids);
343-
344340
void setDebugPresentDelay(TimePoint delay) { mDebugPresentDelay = delay; }
345341

346342
private:

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@
6666
#include <ftl/concat.h>
6767
#include <ftl/fake_guard.h>
6868
#include <ftl/future.h>
69-
#include <ftl/small_map.h>
7069
#include <ftl/unit.h>
7170
#include <gui/AidlUtil.h>
7271
#include <gui/BufferQueue.h>
7372
#include <gui/DebugEGLImageTracker.h>
7473
#include <gui/IProducerListener.h>
75-
#include <gui/JankInfo.h>
7674
#include <gui/LayerMetadata.h>
7775
#include <gui/LayerState.h>
7876
#include <gui/Surface.h>
@@ -3315,40 +3313,12 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
33153313

33163314
const TimePoint presentTime = TimePoint::now();
33173315

3318-
// The Uids of layer owners that are in buffer stuffing mode, and their elevated
3319-
// buffer counts. Messages to start recovery are sent exclusively to these Uids.
3320-
BufferStuffingMap bufferStuffedUids;
3321-
33223316
// Set presentation information before calling Layer::releasePendingBuffer, such that jank
33233317
// information from previous' frame classification is already available when sending jank info
33243318
// to clients, so they get jank classification as early as possible.
33253319
mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime,
33263320
pacesetterGpuCompositionDoneFenceTime);
33273321

3328-
// Find and register any layers that are in buffer stuffing mode
3329-
const auto& presentFrames = mFrameTimeline->getPresentFrames();
3330-
3331-
for (const auto& frame : presentFrames) {
3332-
const auto& layer = mLayerLifecycleManager.getLayerFromId(frame->getLayerId());
3333-
if (!layer) continue;
3334-
uint32_t numberQueuedBuffers = layer->pendingBuffers ? layer->pendingBuffers->load() : 0;
3335-
int32_t jankType = frame->getJankType().value_or(JankType::None);
3336-
if (jankType & JankType::BufferStuffing &&
3337-
layer->flags & layer_state_t::eRecoverableFromBufferStuffing) {
3338-
auto [it, wasEmplaced] =
3339-
bufferStuffedUids.try_emplace(layer->ownerUid.val(), numberQueuedBuffers);
3340-
// Update with maximum number of queued buffers, allows clients drawing
3341-
// multiple windows to account for the most severely stuffed window
3342-
if (!wasEmplaced && it->second < numberQueuedBuffers) {
3343-
it->second = numberQueuedBuffers;
3344-
}
3345-
}
3346-
}
3347-
3348-
if (!bufferStuffedUids.empty()) {
3349-
mScheduler->addBufferStuffedUids(std::move(bufferStuffedUids));
3350-
}
3351-
33523322
// We use the CompositionEngine::getLastFrameRefreshTimestamp() which might
33533323
// be sampled a little later than when we started doing work for this frame,
33543324
// but that should be okay since CompositorTiming has snapping logic.

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,6 @@ class SurfaceFlinger : public BnSurfaceComposer,
14591459
// Flag used to set override desired display mode from backdoor
14601460
bool mDebugDisplayModeSetByBackdoor = false;
14611461

1462-
// Tracks the number of maximum queued buffers by layer owner Uid.
1463-
using BufferStuffingMap = ftl::SmallMap<uid_t, uint32_t, 10>;
14641462
BufferCountTracker mBufferCountTracker;
14651463

14661464
std::unordered_map<DisplayId, sp<HdrLayerInfoReporter>> mHdrLayerInfoListeners

services/surfaceflinger/tests/unittests/EventThreadTest.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include <gmock/gmock.h>
2525
#include <gtest/gtest.h>
26-
#include <gui/DisplayEventReceiver.h>
2726
#include <log/log.h>
2827
#include <scheduler/VsyncConfig.h>
2928
#include <utils/Errors.h>
@@ -112,8 +111,6 @@ class EventThreadTest : public testing::Test, public IEventThreadCallback {
112111
void expectOnExpectedPresentTimePosted(nsecs_t expectedPresentTime);
113112
void expectUidFrameRateMappingEventReceivedByConnection(PhysicalDisplayId expectedDisplayId,
114113
std::vector<FrameRateOverride>);
115-
void expectQueuedBufferCountReceivedByConnection(
116-
ConnectionEventRecorder& connectionEventRecorder, uint32_t expectedBufferCount);
117114

118115
void onVSyncEvent(nsecs_t timestamp, nsecs_t expectedPresentationTime,
119116
nsecs_t deadlineTimestamp) {
@@ -147,7 +144,6 @@ class EventThreadTest : public testing::Test, public IEventThreadCallback {
147144
sp<MockEventThreadConnection> mConnection;
148145
sp<MockEventThreadConnection> mThrottledConnection;
149146
std::unique_ptr<frametimeline::impl::TokenManager> mTokenManager;
150-
std::vector<ConnectionEventRecorder*> mBufferStuffedConnectionRecorders;
151147

152148
std::chrono::nanoseconds mVsyncPeriod;
153149

@@ -380,14 +376,6 @@ void EventThreadTest::expectUidFrameRateMappingEventReceivedByConnection(
380376
EXPECT_EQ(expectedDisplayId, event.header.displayId);
381377
}
382378

383-
void EventThreadTest::expectQueuedBufferCountReceivedByConnection(
384-
ConnectionEventRecorder& connectionEventRecorder, uint32_t expectedBufferCount) {
385-
auto args = connectionEventRecorder.waitForCall();
386-
ASSERT_TRUE(args.has_value());
387-
const auto& event = std::get<0>(args.value());
388-
EXPECT_EQ(expectedBufferCount, event.vsync.vsyncData.numberQueuedBuffers);
389-
}
390-
391379
namespace {
392380

393381
using namespace testing;
@@ -880,63 +868,6 @@ TEST_F(EventThreadTest, postHcpLevelsChanged) {
880868
EXPECT_EQ(HDCP_V2, event.hdcpLevelsChange.maxLevel);
881869
}
882870

883-
TEST_F(EventThreadTest, connectionReceivesBufferStuffing) {
884-
setupEventThread();
885-
886-
// Create a connection that will experience buffer stuffing.
887-
ConnectionEventRecorder stuffedConnectionEventRecorder{0};
888-
sp<MockEventThreadConnection> stuffedConnection =
889-
createConnection(stuffedConnectionEventRecorder,
890-
gui::ISurfaceComposer::EventRegistration::modeChanged |
891-
gui::ISurfaceComposer::EventRegistration::frameRateOverride,
892-
111);
893-
894-
// Add a connection and buffer count to the list of stuffed Uids that will receive
895-
// data in the next vsync event.
896-
BufferStuffingMap bufferStuffedUids;
897-
bufferStuffedUids.try_emplace(stuffedConnection->mOwnerUid, 3);
898-
mThread->addBufferStuffedUids(bufferStuffedUids);
899-
mBufferStuffedConnectionRecorders.emplace_back(&stuffedConnectionEventRecorder);
900-
901-
// Signal that we want the next vsync event to be posted to two connections.
902-
mThread->requestNextVsync(mConnection);
903-
mThread->requestNextVsync(stuffedConnection);
904-
onVSyncEvent(123, 456, 789);
905-
906-
// Vsync event data contains number of queued buffers.
907-
expectQueuedBufferCountReceivedByConnection(mConnectionEventCallRecorder, 0);
908-
expectQueuedBufferCountReceivedByConnection(stuffedConnectionEventRecorder, 3);
909-
}
910-
911-
TEST_F(EventThreadTest, connectionsWithSameUidReceiveBufferStuffing) {
912-
setupEventThread();
913-
914-
// Create a connection with the same Uid as another connection.
915-
ConnectionEventRecorder secondConnectionEventRecorder{0};
916-
sp<MockEventThreadConnection> secondConnection =
917-
createConnection(secondConnectionEventRecorder,
918-
gui::ISurfaceComposer::EventRegistration::modeChanged |
919-
gui::ISurfaceComposer::EventRegistration::frameRateOverride,
920-
mConnectionUid);
921-
922-
// Add connection Uid and buffer count to the list of stuffed Uids that will receive
923-
// data in the next vsync event.
924-
BufferStuffingMap bufferStuffedUids;
925-
bufferStuffedUids.try_emplace(mConnectionUid, 3);
926-
mThread->addBufferStuffedUids(bufferStuffedUids);
927-
mBufferStuffedConnectionRecorders.emplace_back(&mConnectionEventCallRecorder);
928-
mBufferStuffedConnectionRecorders.emplace_back(&secondConnectionEventRecorder);
929-
930-
// Signal that we want the next vsync event to be posted to two connections.
931-
mThread->requestNextVsync(mConnection);
932-
mThread->requestNextVsync(secondConnection);
933-
onVSyncEvent(123, 456, 789);
934-
935-
// Vsync event data contains number of queued buffers.
936-
expectQueuedBufferCountReceivedByConnection(mConnectionEventCallRecorder, 3);
937-
expectQueuedBufferCountReceivedByConnection(secondConnectionEventRecorder, 3);
938-
}
939-
940871
} // namespace
941872
} // namespace android
942873

services/surfaceflinger/tests/unittests/mock/MockEventThread.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class EventThread : public android::EventThread {
5555
MOCK_METHOD(void, onHdcpLevelsChanged,
5656
(PhysicalDisplayId displayId, int32_t connectedLevel, int32_t maxLevel),
5757
(override));
58-
MOCK_METHOD(void, addBufferStuffedUids, (BufferStuffingMap), (override));
5958
};
6059

6160
} // namespace android::mock

0 commit comments

Comments
 (0)