From owner-svn-src-all@FreeBSD.ORG Thu Mar 19 08:34:04 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6DEEC106564A; Thu, 19 Mar 2009 08:34:04 +0000 (UTC) (envelope-from rnoland@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5C1138FC12; Thu, 19 Mar 2009 08:34:04 +0000 (UTC) (envelope-from rnoland@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2J8Y4QK053565; Thu, 19 Mar 2009 08:34:04 GMT (envelope-from rnoland@svn.freebsd.org) Received: (from rnoland@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2J8Y4lV053564; Thu, 19 Mar 2009 08:34:04 GMT (envelope-from rnoland@svn.freebsd.org) Message-Id: <200903190834.n2J8Y4lV053564@svn.freebsd.org> From: Robert Noland Date: Thu, 19 Mar 2009 08:34:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190022 - head/sys/dev/drm X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2009 08:34:05 -0000 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;