Skip to content
Snippets Groups Projects

modesetting: Fix inaccurate PresentCompleteNotify timing for TearFree

Merged Sultan Alsawaf requested to merge kerneltoast/xserver:tearfree-present-fixes into master
5 unresolved threads

TearFree with the modesetting driver suffers from inaccurate PresentCompleteNotify event timing, which leads to A/V de-synchronization with clients utilizing Present, among other problems.

This turns out to be caused by the faulty assumption in Present that a TearFree flip always completes at the next MSC, relative to the reference CRTC's MSC at the time that Present happens to read it.

This series fixes the inaccurate PresentCompleteNotify timing for TearFree by introducing a way for Present to tack on a presentation's completion notification to the completion of said presentation's corresponding TearFree flip. This ensures that the PresentCompleteNotify timing is always accurate when TearFree is used.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
165 165 {
166 166 ScreenPtr screen = crtc->pScreen;
167 167 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
168 #ifdef GLAMOR_HAS_GBM
169 xf86CrtcPtr xf86_crtc = crtc->devPrivate;
170
171 /* Check if this is a fake flip routed through TearFree and abort it */
172 if (ms_tearfree_dri_abort(xf86_crtc, ms_present_event_match, &event_id))
173 return;
174 #endif
  • It would be good to remind people that no flips may have been queued if GLAMOR_HAS_GBM is undefined, but I can't seem to find a good way to do so :s

    Here is the best I could come up with:

    Suggested change
    174 #endif
    174 #endif /* No tearfree flips can be present with GLAMOR_HAS_GBM undefined */
  • The trend for GLAMOR_HAS_GBM ifdefs that I've observed is that it's only used for dodging compile errors. In this case, ms_tearfree_dri_abort() isn't defined without GLAMOR_HAS_GBM, hence the ifdef. I think the ifdef is sufficiently clear on its own.

  • Please register or sign in to reply
  • Martin Roukala
  • Martin Roukala
  • Martin Roukala
    Martin Roukala @mupuf started a thread on commit cbeee438
  • 668 vblank->exec_msc = vblank->target_msc;
    669 vblank->queued = TRUE;
    670 }
    671 default:
    672 break;
    680
    681 /* Try the fake flip first and then fall back to a vblank event */
    682 if (present_flip(vblank->crtc, vblank->event_id, 0, NULL, TRUE) ||
    683 Success == screen_priv->queue_vblank(screen,
    684 window,
    685 vblank->crtc,
    686 vblank->event_id,
    687 completion_msc)) {
    688 /* Ensure present_execute_post() runs at the next execution */
    689 vblank->exec_msc = vblank->target_msc;
    690 vblank->queued = TRUE;
    • Comment on lines +682 to +690

      Isn't this gonna always queue a vblank event, even if present_flip succeeds? Shouldn't it have been the following?

      Suggested change
      682 if (present_flip(vblank->crtc, vblank->event_id, 0, NULL, TRUE) ||
      683 Success == screen_priv->queue_vblank(screen,
      684 window,
      685 vblank->crtc,
      686 vblank->event_id,
      687 completion_msc)) {
      688 /* Ensure present_execute_post() runs at the next execution */
      689 vblank->exec_msc = vblank->target_msc;
      690 vblank->queued = TRUE;
      682 if (!present_flip(vblank->crtc, vblank->event_id, 0, NULL, TRUE) {
      683 /* We failed to queue a fake flip, fallback to creating a vblank event */
      684 if (Success == screen_priv->queue_vblank(screen,
      685 window,
      686 vblank->crtc,
      687 vblank->event_id,
      688 completion_msc)) {
      689 /* Ensure present_execute_post() runs at the next execution */
      690 vblank->exec_msc = vblank->target_msc;
      691 vblank->queued = TRUE;
      692 }
    • No. "Queuing a vblank event" refers to screen_priv->queue_vblank(), not vblank->queued = TRUE;.

      Those 2 lines in the if-body are required when present_flip() succeeds.

    • Ha ha, this is confusing :D Anyway, this just proves my point that I have no clue about the timing infrastructure :D

    • Please register or sign in to reply
    • @kerneltoast: Damn, this is some quality commit messages and comments you wrote! You really took the be a great collaborator to heart! Thanks a lot for that, and coming back to fix the presentation timings, I really appreciate it :smile:

      Anyway, the following commits are Reviewed-by: Martin Roukala <martin.roukala@mupuf.org>:

      The last 3 commits are not something I feel comfortable reviewing right now. If someone with more knowledge of the timing infrastructure could have a look, it would be appreciated. If noone has the time, I'll try to dedicate some time for this during the week.

    • Thanks for the review! The A/V desync in video players and stutters when watching YouTube in Firefox were getting to me, so I was compelled to come back and fix presentation timings :wink:

      The last 3 commits are not something I feel comfortable reviewing right now.

      FWIW, the trick for the last 3 commits is that the TearFree timing just mimics what PageFlip does, since PageFlip's timing was always correct. What started out as being conceptually quite simple ended up requiring a lot of code though :sweat_smile:

    • @mupuf I've pushed a new version with your feedback implemented. Please let me know how it looks. Thank you!

    • Thank you @kerneltoast! I will check one commit a day starting from tomorrow, so we should be able to merge by the end of the week if all goes well!

    • @mupuf Had a chance to grok any of the remaining commits?

    • Damn, of course, sorry!

    • Please register or sign in to reply
  • Sultan Alsawaf added 32 commits

    added 32 commits

    • cbeee438...098fcedf - 21 commits from branch xorg:master
    • 37bc2840 - modesetting: Remove redundant GLAMOR_HAS_GBM #ifdef from ms_do_pageflip
    • 141da9d6 - modesetting: Pass reference CRTC pointer to ms_do_pageflip
    • c8280689 - modesetting: Pass CRTC pointer to TearFree flip handlers
    • 04ee87d8 - modesetting: Fix memory leak on ms_do_pageflip error
    • 9237538b - modesetting: Improve TearFree state check in ms_present_check_flip
    • 51c0486a - modesetting: Introduce ms_tearfree_is_active_on_crtc helper
    • d16be083 - modesetting: Ensure vblank events always run in sequential order
    • 7c244a5b - modesetting: Support accurate DRI presentation timing with TearFree
    • 413db007 - present: Prevent double vblank enqueue on error when TearFree is used
    • f279e1f8 - present: Fix inaccurate PresentCompleteNotify timing for TearFree
    • 82975044 - present: Document the TearFree flip reasons in PresentFlipReason

    Compare with previous version

  • Sultan Alsawaf added 12 commits

    added 12 commits

    • 462b0603 - 1 commit from branch xorg:master
    • 12ebdafc - modesetting: Remove redundant GLAMOR_HAS_GBM #ifdef from ms_do_pageflip
    • d7802903 - modesetting: Pass reference CRTC pointer to ms_do_pageflip
    • c2a0490c - modesetting: Pass CRTC pointer to TearFree flip handlers
    • 33f3f302 - modesetting: Fix memory leak on ms_do_pageflip error
    • a2fe24d0 - modesetting: Improve TearFree state check in ms_present_check_flip
    • 4b26d1d1 - modesetting: Introduce ms_tearfree_is_active_on_crtc helper
    • 9168f455 - modesetting: Ensure vblank events always run in sequential order
    • 81b12161 - modesetting: Support accurate DRI presentation timing with TearFree
    • 623a31df - present: Prevent double vblank enqueue on error when TearFree is used
    • fdc5af9e - present: Fix inaccurate PresentCompleteNotify timing for TearFree
    • 456bb21c - present: Document the TearFree flip reasons in PresentFlipReason

    Compare with previous version

    • 81b12161: The commit message is cut. Once fixed, you can add my Acked-by: Martin Roukala <martin.roukala@mupuf.org>
    • 623a31df: Acked-by: Martin Roukala <martin.roukala@mupuf.org>
    • fdc5af9e: Acked-by: Martin Roukala <martin.roukala@mupuf.org>

    I am still not hyper confident about these last three commits. Have you tested that this does not regress the tearfree-disabled mode? In the end, this is all I am concerned for, as the tearfree path is well documented :)

  • 81b12161: The commit message is cut.

    That's a weird GitLab bug; the commit message isn't actually cut. The raw view shows the full message: kerneltoast/xserver@81b12161 (patch)

    Have you tested that this does not regress the tearfree-disabled mode?

    Yep, everything still works fine for me with TearFree disabled, and the presentation changes are neatly scoped under a TearFree check so I think that aspect is good.

    Thanks for the acks! I'll upload a rebased version with them.

  • Sultan Alsawaf added 15 commits

    added 15 commits

    • 456bb21c...7ce57e17 - 4 commits from branch xorg:master
    • e40acc4f - modesetting: Remove redundant GLAMOR_HAS_GBM #ifdef from ms_do_pageflip
    • 5288e92e - modesetting: Pass reference CRTC pointer to ms_do_pageflip
    • aec8148d - modesetting: Pass CRTC pointer to TearFree flip handlers
    • 53a4e420 - modesetting: Fix memory leak on ms_do_pageflip error
    • 8bc302d0 - modesetting: Improve TearFree state check in ms_present_check_flip
    • 284478e6 - modesetting: Introduce ms_tearfree_is_active_on_crtc helper
    • 968cf3af - modesetting: Ensure vblank events always run in sequential order
    • 12eea378 - modesetting: Support accurate DRI presentation timing with TearFree
    • 9655d9f4 - present: Prevent double vblank enqueue on error when TearFree is used
    • 41b509ff - present: Fix inaccurate PresentCompleteNotify timing for TearFree
    • 31af0122 - present: Document the TearFree flip reasons in PresentFlipReason

    Compare with previous version

  • @mupuf updated!

  • @daenzer, @ofourdan, @vsyrjala: As far as I am concerned, this series is ready for merging. I'll press the button in a week, unless any of you guys want to have a look.

  • Sultan Alsawaf added 13 commits

    added 13 commits

    • 31af0122...d6b20f5e - 2 commits from branch xorg:master
    • 7288b4d1 - modesetting: Remove redundant GLAMOR_HAS_GBM #ifdef from ms_do_pageflip
    • 1fd9d79a - modesetting: Pass reference CRTC pointer to ms_do_pageflip
    • be864d8e - modesetting: Pass CRTC pointer to TearFree flip handlers
    • 35975d90 - modesetting: Fix memory leak on ms_do_pageflip error
    • 8b5fd556 - modesetting: Improve TearFree state check in ms_present_check_flip
    • 18b14ea1 - modesetting: Introduce ms_tearfree_is_active_on_crtc helper
    • 9d1997f7 - modesetting: Ensure vblank events always run in sequential order
    • 53b02054 - modesetting: Support accurate DRI presentation timing with TearFree
    • d4bd39f1 - present: Prevent double vblank enqueue on error when TearFree is used
    • 1fab978a - present: Fix inaccurate PresentCompleteNotify timing for TearFree
    • f490622f - present: Document the TearFree flip reasons in PresentFlipReason

    Compare with previous version

  • Evgeny Grin mentioned in issue #928

    mentioned in issue #928

  • Please register or sign in to reply
    Loading