Permalink
Browse files

dri2: Fixes to swap scheduling.

Fix some small off-by-one errors and a mismatch
between 32 bit kernel interfaces for vblank count
and 64 bit dri2 interfaces for target_msc et al.

Return corrected target_msc to swap scheduling in
x-server.

A revised version of the patch discussed here:
http://lists.freedesktop.org/archives/nouveau/2011-September/009143.html

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information...
1 parent 5ede453 commit 919643888045b102f3e10dfdeb6210ab14b6ecab @kleinerm kleinerm committed with Feb 15, 2012
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/nouveau_dri2.c
View
@@ -387,19 +387,31 @@ nouveau_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
if (ret)
goto fail;
+ /* Truncate to match kernel interfaces; means occasional overflow
+ * misses, but that's generally not a big deal.
+ */
+ *target_msc &= 0xffffffff;
+ divisor &= 0xffffffff;
+ remainder &= 0xffffffff;
+
/* Calculate a swap target if we don't have one */
if (current_msc >= *target_msc && divisor)
*target_msc = current_msc + divisor
- (current_msc - remainder) % divisor;
+ /* Avoid underflow of unsigned value below */
+ if (*target_msc == 0)
+ *target_msc = 1;
+
/* Request a vblank event one frame before the target */
ret = nouveau_wait_vblank(draw, DRM_VBLANK_ABSOLUTE |
DRM_VBLANK_EVENT,
max(current_msc, *target_msc - 1),
&expect_msc, NULL, s);
if (ret)
goto fail;
- s->frame = (unsigned int) expect_msc & 0xffffffff;
+ s->frame = 1 + ((unsigned int) expect_msc & 0xffffffff);
+ *target_msc = 1 + expect_msc;
} else {
/* We can't/don't want to sync to vblank, just swap. */
nouveau_dri2_finish_swap(draw, 0, 0, 0, s);
@@ -420,6 +432,13 @@ nouveau_dri2_schedule_wait(ClientPtr client, DrawablePtr draw,
CARD64 current_msc;
int ret;
+ /* Truncate to match kernel interfaces; means occasional overflow
+ * misses, but that's generally not a big deal.
+ */
+ target_msc &= 0xffffffff;
+ divisor &= 0xffffffff;
+ remainder &= 0xffffffff;
+
if (!can_sync_to_vblank(draw)) {
DRI2WaitMSCComplete(client, draw, target_msc, 0, 0);
return TRUE;
@@ -439,7 +458,7 @@ nouveau_dri2_schedule_wait(ClientPtr client, DrawablePtr draw,
goto fail;
/* Calculate a wait target if we don't have one */
- if (current_msc > target_msc && divisor)
+ if (current_msc >= target_msc && divisor)
target_msc = current_msc + divisor
- (current_msc - remainder) % divisor;

0 comments on commit 9196438

Please sign in to comment.