Comment 46 for bug 320813

Revision history for this message
Timo Aaltonen (tjaalton) wrote :

Here is the final patch, and as you can see it's quite small.. This should hit upstream in the not-too-distant future.

Date: Fri, 06 Feb 2009 13:04:49 -0800
From: Jesse Barnes <email address hidden>
To: Dave Airlie <email address hidden>
Cc: DRI <email address hidden>, Timo Aaltonen <email address hidden>,
    Michel Dänzer <email address hidden>
Subject: [PATCH] capture last_vblank count at IRQ uninstall time too

In dc1336ff4fe08ae7cfe8301bfd7f0b2cfd31d20a (set vblank enable flag correctly
across IRQ uninstall), we made sure drivers that uninstall their interrupt
handler set the vblank enabled flag correctly, so that when interrupts are
re-enabled, vblank interrupts & counts work as expected. However I missed the
last_vblank field: it needs to be updated as well, otherwise, at the next
drm_update_vblank_count we'll end up comparing a current count to a stale
one (the last one captured by the disable function), which may trigger the
wraparound handling, leading to a jumpy counter and hangs in drm_wait_vblank.

The jumpy counter can prevent the DRM_WAIT_ON from returning success if the
difference between the current count and the requested count is greater than
2^23, leading to timeouts or hangs, if the ioctl is restarted in a loop (as
is the case in libdrm < 2.4.4).

Signed-off-by: Jesse Barnes <email address hidden>

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 69aa0ab..3795dbc 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -276,6 +276,7 @@ int drm_irq_uninstall(struct drm_device * dev)
        for (i = 0; i < dev->num_crtcs; i++) {
                DRM_WAKEUP(&dev->vbl_queue[i]);
                dev->vblank_enabled[i] = 0;
+ dev->last_vblank[i] = dev->driver->get_vblank_counter(dev, i);
        }
        spin_unlock_irqrestore(&dev->vbl_lock, irqflags);