svn commit: r190022 - head/sys/dev/drm

Robert Noland rnoland at FreeBSD.org
Thu Mar 19 01:34:05 PDT 2009


Author: rnoland
Date: Thu Mar 19 08:34:04 2009
New Revision: 190022
URL: http://svn.freebsd.org/changeset/base/190022

Log:
  Rework vblank handling to try to resolve some reports of "slow" windows
  after vt switch or suspend.  I can't really test this on Intel right now
  but I think I've heard reports of it on radeon as well.  I can't break
  it on the radeon here.
  
  MFC after:	3 days

Modified:
  head/sys/dev/drm/drm_irq.c

Modified: head/sys/dev/drm/drm_irq.c
==============================================================================
--- head/sys/dev/drm/drm_irq.c	Thu Mar 19 08:28:36 2009	(r190021)
+++ head/sys/dev/drm/drm_irq.c	Thu Mar 19 08:34:04 2009	(r190022)
@@ -98,15 +98,13 @@ static void vblank_disable_fn(void *arg)
 
 void drm_vblank_cleanup(struct drm_device *dev)
 {
-	unsigned long irqflags;
-
 	/* Bail if the driver didn't call drm_vblank_init() */
 	if (dev->num_crtcs == 0)
 		return;
 
-	DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
+	DRM_SPINLOCK(&dev->vbl_lock);
 	callout_stop(&dev->vblank_disable_timer);
-	DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
+	DRM_SPINUNLOCK(&dev->vbl_lock);
 
 	callout_drain(&dev->vblank_disable_timer);
 
@@ -200,11 +198,25 @@ err:
 
 int drm_irq_uninstall(struct drm_device *dev)
 {
+	int crtc;
+
 	if (!dev->irq_enabled)
 		return EINVAL;
 
 	dev->irq_enabled = 0;
 
+	/*
+	* Wake up any waiters so they don't hang.
+	*/
+	DRM_SPINLOCK(&dev->vbl_lock);
+	for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
+		DRM_WAKEUP(&dev->vblank[crtc].queue);
+		dev->vblank[crtc].enabled = 0;
+		dev->vblank[crtc].last =
+		    dev->driver->get_vblank_counter(dev, crtc);
+	}
+	DRM_SPINUNLOCK(&dev->vbl_lock);
+
 	DRM_DEBUG("irq=%d\n", dev->irq);
 
 	dev->driver->irq_uninstall(dev);
@@ -277,16 +289,15 @@ static void drm_update_vblank_count(stru
 
 int drm_vblank_get(struct drm_device *dev, int crtc)
 {
-	unsigned long irqflags;
 	int ret = 0;
 
-	DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
+	DRM_SPINLOCK(&dev->vbl_lock);
 	/* Going from 0->1 means we have to enable interrupts again */
 	atomic_add_acq_int(&dev->vblank[crtc].refcount, 1);
-	DRM_DEBUG("vblank refcount = %d\n", dev->vblank[crtc].refcount);
 	if (dev->vblank[crtc].refcount == 1 &&
 	    !dev->vblank[crtc].enabled) {
 		ret = dev->driver->enable_vblank(dev, crtc);
+		DRM_DEBUG("enabling vblank on crtc %d, ret: %d\n", crtc, ret);
 		if (ret)
 			atomic_dec(&dev->vblank[crtc].refcount);
 		else {
@@ -294,30 +305,28 @@ int drm_vblank_get(struct drm_device *de
 			drm_update_vblank_count(dev, crtc);
 		}
 	}
-	DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
+	DRM_SPINUNLOCK(&dev->vbl_lock);
 
 	return ret;
 }
 
 void drm_vblank_put(struct drm_device *dev, int crtc)
 {
-	unsigned long irqflags;
+	KASSERT(atomic_read(&dev->vblank[crtc].refcount) > 0,
+	    ("invalid refcount"));
 
-	DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
 	/* Last user schedules interrupt disable */
 	atomic_subtract_acq_int(&dev->vblank[crtc].refcount, 1);
-	DRM_DEBUG("vblank refcount = %d\n", dev->vblank[crtc].refcount);
+
 	if (dev->vblank[crtc].refcount == 0)
 	    callout_reset(&dev->vblank_disable_timer, 5 * DRM_HZ,
 		(timeout_t *)vblank_disable_fn, (void *)dev);
-	DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
 }
 
 int drm_modeset_ctl(struct drm_device *dev, void *data,
 		    struct drm_file *file_priv)
 {
 	struct drm_modeset_ctl *modeset = data;
-	unsigned long irqflags;
 	int crtc, ret = 0;
 
 	DRM_DEBUG("num_crtcs=%d\n", dev->num_crtcs);
@@ -343,18 +352,22 @@ int drm_modeset_ctl(struct drm_device *d
 	case _DRM_PRE_MODESET:
 		DRM_DEBUG("pre-modeset\n");
 		if (!dev->vblank[crtc].inmodeset) {
-			dev->vblank[crtc].inmodeset = 1;
-			drm_vblank_get(dev, crtc);
+			dev->vblank[crtc].inmodeset = 0x1;
+			if (drm_vblank_get(dev, crtc) == 0)
+				dev->vblank[crtc].inmodeset |= 0x2;
 		}
 		break;
 	case _DRM_POST_MODESET:
 		DRM_DEBUG("post-modeset\n");
 		if (dev->vblank[crtc].inmodeset) {
-			DRM_SPINLOCK_IRQSAVE(&dev->vbl_lock, irqflags);
+			DRM_SPINLOCK(&dev->vbl_lock);
 			dev->vblank_disable_allowed = 1;
+			DRM_SPINUNLOCK(&dev->vbl_lock);
+
+			if (dev->vblank[crtc].inmodeset & 0x2)
+				drm_vblank_put(dev, crtc);
+
 			dev->vblank[crtc].inmodeset = 0;
-			DRM_SPINUNLOCK_IRQRESTORE(&dev->vbl_lock, irqflags);
-			drm_vblank_put(dev, crtc);
 		}
 		break;
 	default:
@@ -445,7 +458,11 @@ int drm_wait_vblank(struct drm_device *d
 			mtx_unlock(&dev->irq_lock);
 		}
 
-		DRM_DEBUG("return = %d\n", ret);
+		if (ret == ERESTART) {
+			DRM_DEBUG("restarting syscall\n");
+			return ret;
+		}
+
 		if (ret != EINTR) {
 			struct timeval now;
 


More information about the svn-src-head mailing list