When userspace queries the current vblank for the CRTC, we can reply
with the cached value (using atomic reads to serialise with the vblank
interrupt as necessary) without having to touch registers. In the
instant disable case, this saves us from enabling/disabling the vblank
around every query, greatly reducing the number of registers read and
written.

Signed-off-by: Chris Wilson <[email protected]>
Cc: Imre Deak <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Ville Syrjälä <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Dave Airlie <[email protected]>
---
 drivers/gpu/drm/drm_irq.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index c8a34476570a..6c4570082b65 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -1585,7 +1585,18 @@ int drm_wait_vblank(struct drm_device *dev, void *data,
        if (crtc >= dev->num_crtcs)
                return -EINVAL;
 
-       vblank = &dev->vblank[crtc];
+       /* Fast-path the query for the current value (without an event)
+        * to avoid having to enable/disable the vblank interrupts.
+        */
+       if ((vblwait->request.type & (_DRM_VBLANK_TYPES_MASK | 
_DRM_VBLANK_FLAGS_MASK)) == _DRM_VBLANK_RELATIVE &&
+           vblwait->request.sequence == 0) {
+               struct timeval now;
+
+               vblwait->reply.sequence = drm_vblank_count_and_time(dev, crtc, 
&now);
+               vblwait->reply.tval_sec = now.tv_sec;
+               vblwait->reply.tval_usec = now.tv_usec;
+               return 0;
+       }
 
        ret = drm_vblank_get(dev, crtc);
        if (ret) {
@@ -1619,6 +1630,8 @@ int drm_wait_vblank(struct drm_device *dev, void *data,
 
        DRM_DEBUG("waiting on vblank count %d, crtc %d\n",
                  vblwait->request.sequence, crtc);
+
+       vblank = &dev->vblank[crtc];
        vblank->last_wait = vblwait->request.sequence;
        DRM_WAIT_ON(ret, vblank->queue, 3 * HZ,
                    (((drm_vblank_count(dev, crtc) -
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to