Reland "Create a VsyncSchedule per display"
In order to determine the vsync offsets between displays, keep track of
a VsyncSchedule for each display.
Store the VsyncSchedules in a SmallMap. Update getVsyncSchedule with a
parameter to choose the display. The default parameter uses the leader's
display, which is what many current callers want.
Update VsyncDispatches when the leader changes, so that they are always
listening to the leader.
Enable and disable vsync callbacks per display. Earlier attempts to turn
them on and off together could leave a secondary display on a bad
schedule. Add a method for resyncing all displays at once.
Use std::shared_ptrs for VsyncDispatches. This prevents lifetime issues
if a VsyncSchedule gets removed while its VsyncDispatch is still in use.
Same for VsyncTracker, which is referenced by VsyncDispatch.
When the leader VsyncSchedule changes, call cancel on
VsyncCallbackRegistrations and replace them with new ones using the new
VsyncDispatches. If a callback was scheduled, schedule a new one.
Update VsyncSchedule's members' traces so that there is a separate track
for each display.
For refresh rate changes, modulate vsync config based on the leader
display. When switching leaders, force a period transition to ensure
that a potential refresh rate change is completed.
This reverts commit db16a2be4054d0dd7d940f4fa0a2ced0575fd2e7 aka
I0757a7df540fad316b2db42e4c77f1c73bc49420, which reverted the original
CL, If60218e85292c786b9fa70ecb33ee374d3a385e0. Notable differences from
the original CL:
- Logical pieces have been separated and landed in the following CLs:
- I21be76e20776d8a3f49e5bd295a0042de9e2dde9
- I062002245db8fd817e145a3aaf197bb874b00636
- I54a1304a3428968134cc707b24d5b325927c31df
- Remove IEventThreadCallback changes. These are ultimately orthogonal
to the motivation of this CL.
- Store the ID instead of the name and use ftl::Concat, as tracked in
b/266817103.
- Rename MessageQueue::updateVsyncRegistration to onNewVsyncSchedule, to
match the name in EventThread. These methods do essentially the same
thing, so use the same name.
- Crucially, I54a1304a3428968134cc707b24d5b325927c31df restores the
pending HWC Vsync state, which was originally removed in
If60218e85292c786b9fa70ecb33ee374d3a385e0. The removal seems to have
been responsible for b/267562341.
Bug: 255601557
Bug: 256196556
Bug: 241285473
Bug: 241286146
Bug: 268366385
Fixes: 266817103
Test: libsurfaceflinger_unittest
Test: manual (look at perfetto traces)
Change-Id: Icdb80253436b4d0034fc20fcae8583efb7c30292
diff --git a/services/surfaceflinger/Scheduler/VsyncSchedule.cpp b/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
index 5245556..62e37db 100644
--- a/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
+++ b/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
@@ -42,8 +42,8 @@
}
public:
- explicit PredictedVsyncTracer(VsyncDispatch& dispatch)
- : mRegistration(dispatch, makeVsyncCallback(), __func__) {
+ explicit PredictedVsyncTracer(std::shared_ptr<VsyncDispatch> dispatch)
+ : mRegistration(std::move(dispatch), makeVsyncCallback(), __func__) {
schedule();
}
@@ -54,16 +54,19 @@
VSyncCallbackRegistration mRegistration;
};
-VsyncSchedule::VsyncSchedule(FeatureFlags features)
- : mTracker(createTracker()),
- mDispatch(createDispatch(*mTracker)),
- mController(createController(*mTracker, features)),
+VsyncSchedule::VsyncSchedule(PhysicalDisplayId id, FeatureFlags features)
+ : mId(id),
+ mTracker(createTracker(id)),
+ mDispatch(createDispatch(mTracker)),
+ mController(createController(id, *mTracker, features)),
mTracer(features.test(Feature::kTracePredictedVsync)
- ? std::make_unique<PredictedVsyncTracer>(*mDispatch)
+ ? std::make_unique<PredictedVsyncTracer>(mDispatch)
: nullptr) {}
-VsyncSchedule::VsyncSchedule(TrackerPtr tracker, DispatchPtr dispatch, ControllerPtr controller)
- : mTracker(std::move(tracker)),
+VsyncSchedule::VsyncSchedule(PhysicalDisplayId id, TrackerPtr tracker, DispatchPtr dispatch,
+ ControllerPtr controller)
+ : mId(id),
+ mTracker(std::move(tracker)),
mDispatch(std::move(dispatch)),
mController(std::move(controller)) {}
@@ -95,45 +98,46 @@
mDispatch->dump(out);
}
-VsyncSchedule::TrackerPtr VsyncSchedule::createTracker() {
+VsyncSchedule::TrackerPtr VsyncSchedule::createTracker(PhysicalDisplayId id) {
// TODO(b/144707443): Tune constants.
constexpr nsecs_t kInitialPeriod = (60_Hz).getPeriodNsecs();
constexpr size_t kHistorySize = 20;
constexpr size_t kMinSamplesForPrediction = 6;
constexpr uint32_t kDiscardOutlierPercent = 20;
- return std::make_unique<VSyncPredictor>(kInitialPeriod, kHistorySize, kMinSamplesForPrediction,
- kDiscardOutlierPercent);
+ return std::make_unique<VSyncPredictor>(id, kInitialPeriod, kHistorySize,
+ kMinSamplesForPrediction, kDiscardOutlierPercent);
}
-VsyncSchedule::DispatchPtr VsyncSchedule::createDispatch(VsyncTracker& tracker) {
+VsyncSchedule::DispatchPtr VsyncSchedule::createDispatch(TrackerPtr tracker) {
using namespace std::chrono_literals;
// TODO(b/144707443): Tune constants.
constexpr std::chrono::nanoseconds kGroupDispatchWithin = 500us;
constexpr std::chrono::nanoseconds kSnapToSameVsyncWithin = 3ms;
- return std::make_unique<VSyncDispatchTimerQueue>(std::make_unique<Timer>(), tracker,
+ return std::make_unique<VSyncDispatchTimerQueue>(std::make_unique<Timer>(), std::move(tracker),
kGroupDispatchWithin.count(),
kSnapToSameVsyncWithin.count());
}
-VsyncSchedule::ControllerPtr VsyncSchedule::createController(VsyncTracker& tracker,
+VsyncSchedule::ControllerPtr VsyncSchedule::createController(PhysicalDisplayId id,
+ VsyncTracker& tracker,
FeatureFlags features) {
// TODO(b/144707443): Tune constants.
constexpr size_t kMaxPendingFences = 20;
const bool hasKernelIdleTimer = features.test(Feature::kKernelIdleTimer);
- auto reactor = std::make_unique<VSyncReactor>(std::make_unique<SystemClock>(), tracker,
+ auto reactor = std::make_unique<VSyncReactor>(id, std::make_unique<SystemClock>(), tracker,
kMaxPendingFences, hasKernelIdleTimer);
reactor->setIgnorePresentFences(!features.test(Feature::kPresentFences));
return reactor;
}
-void VsyncSchedule::startPeriodTransition(ISchedulerCallback& callback, Period period) {
+void VsyncSchedule::startPeriodTransition(ISchedulerCallback& callback, Period period, bool force) {
std::lock_guard<std::mutex> lock(mHwVsyncLock);
- mController->startPeriodTransition(period.ns());
+ mController->startPeriodTransition(period.ns(), force);
enableHardwareVsyncLocked(callback);
}
@@ -165,7 +169,7 @@
void VsyncSchedule::enableHardwareVsyncLocked(ISchedulerCallback& callback) {
if (mHwVsyncState == HwVsyncState::Disabled) {
getTracker().resetModel();
- callback.setVsyncEnabled(true);
+ callback.setVsyncEnabled(mId, true);
mHwVsyncState = HwVsyncState::Enabled;
}
}
@@ -173,7 +177,7 @@
void VsyncSchedule::disableHardwareVsync(ISchedulerCallback& callback, bool disallow) {
std::lock_guard<std::mutex> lock(mHwVsyncLock);
if (mHwVsyncState == HwVsyncState::Enabled) {
- callback.setVsyncEnabled(false);
+ callback.setVsyncEnabled(mId, false);
}
mHwVsyncState = disallow ? HwVsyncState::Disallowed : HwVsyncState::Disabled;
}