drm/i915: Reduce the time we hold struct mutex in sprite update_plane code
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 1 Oct 2013 15:02:12 +0000 (18:02 +0300)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 10 Oct 2013 10:46:59 +0000 (12:46 +0200)
We used to call the entire intel specific update_plane hook while
holding struct_mutex. Actually we only need to hold struct_mutex while
pinning/unpinning the obj. The plane state itself is protected by the
kms locks, and as the object is pinned we can dig out the offset and
tiling information from it without fearing that it would change
underneath us.

So now we don't need to drop and reacquire the lock around the
wait_for_vblank. Also we will need another wait_for_vblank in the IVB
specific update_plane hook, and this way we don't need to worry about
struct_mutex there either.

Also move the intel_plane->obj=NULL assignment outside strut_mutex in
disable_plane to make it clear that it's not protected by struct_mutex.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/intel_sprite.c

index 9161a1db8dffe6b5cd08c624b4cd68576a41c1a8..b859f944b53bdd2319c35e12b21cc7dd9fea9c7c 100644 (file)
@@ -525,7 +525,10 @@ intel_enable_primary(struct drm_crtc *crtc)
                return;
 
        intel_crtc->primary_disabled = false;
+
+       mutex_lock(&dev->struct_mutex);
        intel_update_fbc(dev);
+       mutex_unlock(&dev->struct_mutex);
 
        I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
 }
@@ -544,7 +547,10 @@ intel_disable_primary(struct drm_crtc *crtc)
        I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
 
        intel_crtc->primary_disabled = true;
+
+       mutex_lock(&dev->struct_mutex);
        intel_update_fbc(dev);
+       mutex_unlock(&dev->struct_mutex);
 }
 
 static int
@@ -810,8 +816,11 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
         * the sprite planes only require 128KiB alignment and 32 PTE padding.
         */
        ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
+
+       mutex_unlock(&dev->struct_mutex);
+
        if (ret)
-               goto out_unlock;
+               return ret;
 
        intel_plane->obj = obj;
 
@@ -842,18 +851,15 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
                 * wait for vblank to avoid ugliness, we only need to
                 * do the pin & ref bookkeeping.
                 */
-               if (old_obj != obj) {
-                       mutex_unlock(&dev->struct_mutex);
-                       if (intel_crtc->active)
-                               intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
-                       mutex_lock(&dev->struct_mutex);
-               }
+               if (old_obj != obj && intel_crtc->active)
+                       intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
+
+               mutex_lock(&dev->struct_mutex);
                intel_unpin_fb_obj(old_obj);
+               mutex_unlock(&dev->struct_mutex);
        }
 
-out_unlock:
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
+       return 0;
 }
 
 static int
@@ -885,8 +891,9 @@ intel_disable_plane(struct drm_plane *plane)
 
        mutex_lock(&dev->struct_mutex);
        intel_unpin_fb_obj(intel_plane->obj);
-       intel_plane->obj = NULL;
        mutex_unlock(&dev->struct_mutex);
+
+       intel_plane->obj = NULL;
 out:
 
        return ret;