From db59f4c89308a2d455232d7672e3800b219184bb Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 7 Dec 2023 16:26:38 +0000 Subject: [PATCH] vblankmanager: Treat wakeup time as scheduled wakeup point for timerfd path Because we are using timerfd, ulWakeupTime should actually be the target point of the timerfd when using that, not the the current time from OnPollIn, so we can account for the scheduling quantums from the target wakeup time and other work (like we were wrt the pipe write before) --- src/vblankmanager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vblankmanager.cpp b/src/vblankmanager.cpp index 9ccb130eb1..df77bdf331 100644 --- a/src/vblankmanager.cpp +++ b/src/vblankmanager.cpp @@ -297,14 +297,21 @@ namespace gamescope if ( !m_bArmed.exchange( false ) ) return; - uint64_t ulNow = get_time_in_nanos(); m_PendingVBlank = VBlankTime { .schedule = m_TimerFDSchedule, - .ulWakeupTime = ulNow, + // One might think this should just be 'now', however consider the fact + // that the effective draw-time should also include the scheduling quantums + // and any work before we reached this poll. + // The old path used to be be on its own thread, simply awaking from sleep + // then writing to a pipe and going back to sleep, the wakeup time was before we + // did the write, so we included the quantum of pipe nudge -> wakeup. + // Doing this aims to include that, like we were before, but with timerfd. + .ulWakeupTime = m_TimerFDSchedule.ulScheduledWakeupPoint, }; #ifdef VBLANK_DEBUG + uint64_t ulNow = get_time_in_nanos(); fprintf( stderr, "wakeup: %lu\n", ulNow ); #endif