Skip to contentSkip to conversation

drm/i915: pin sprite fb only if it changed

PATCH Superseded Gustavo Padovan 2 participants 2 messages Sep 9, 2014 – Sep 10, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: pin sprite fb only if it changed

From: Gustavo Padovan <[email protected]>

Optimize code avoiding helding dev mutex if old fb and current fb are the same.

---
 drivers/gpu/drm/i915/intel_sprite.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/intel_sprite.c +14 -9
index a4306cf..a301838 100644
@@ -1038,21 +1038,23 @@ intel_commit_sprite_plane(struct drm_plane *plane,
 	primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
 	WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
 
-	mutex_lock(&dev->struct_mutex);
 
 	/* Note that this will apply the VT-d workaround for scanouts,
 	 * which is more restrictive than required for sprites. (The
 	 * primary plane requires 256KiB alignment with 64 PTE padding,
 	 * the sprite planes only require 128KiB alignment and 32 PTE padding.
 	 */
-	ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
+	if (old_obj != obj) {
+		mutex_lock(&dev->struct_mutex);
+		ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
 
-	i915_gem_track_fb(old_obj, obj,
-			  INTEL_FRONTBUFFER_SPRITE(pipe));
-	mutex_unlock(&dev->struct_mutex);
+		i915_gem_track_fb(old_obj, obj,
+				  INTEL_FRONTBUFFER_SPRITE(pipe));
+		mutex_unlock(&dev->struct_mutex);
 
-	if (ret)
-		return ret;
+		if (ret)
+			return ret;
+	}
 
 	intel_plane->crtc_x = state->orig_dst.x1;
 	intel_plane->crtc_y = state->orig_dst.y1;
@@ -1098,15 +1100,18 @@ intel_commit_sprite_plane(struct drm_plane *plane,
 			intel_post_enable_primary(crtc);
 	}
 
+	if (!old_obj)
+		return 0;
+
 	/* Unpin old obj after new one is active to avoid ugliness */
-	if (old_obj) {
+	if (old_obj != obj) {
 		/*
 		 * It's fairly common to simply update the position of
 		 * an existing object.  In that case, we don't need to
 		 * wait for vblank to avoid ugliness, we only need to
 		 * do the pin & ref bookkeeping.
 		 */
-		if (old_obj != obj && intel_crtc->active)
+		if (intel_crtc->active)
 			intel_wait_for_vblank(dev, intel_crtc->pipe);
 
 		mutex_lock(&dev->struct_mutex);
Signature · 1 line
1.9.3
#1 lore raw
Quoted 15 lines · Gustavo Padovan

From: Gustavo Padovan <[email protected]>

Optimize code avoiding helding dev mutex if old fb and current fb are the same.

---
 drivers/gpu/drm/i915/intel_sprite.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/intel_sprite.c +0 -0
index a4306cf..a301838 100644

drivers/gpu/drm/i915/intel_sprite.c intel_commit_sprite_plane(struct drm_plane *plane, · line 1046

Quoted 10 lines
drivers/gpu/drm/i915/intel_sprite.c +0 -1
@@ -1038,21 +1038,23 @@ intel_commit_sprite_plane(struct drm_plane *plane,
 	primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
 	WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
 
-	mutex_lock(&dev->struct_mutex);
 
 	/* Note that this will apply the VT-d workaround for scanouts,
 	 * which is more restrictive than required for sprites. (The
 	 * primary plane requires 256KiB alignment with 64 PTE padding,
 	 * the sprite planes only require 128KiB alignment and 32 PTE padding.
 	 */

The comment should probably remain just before the intel_pin_and_fence_fb_obj() call.

drivers/gpu/drm/i915/intel_sprite.c intel_commit_sprite_plane(struct drm_plane *plane, · line 1052

Quoted 10 lines
drivers/gpu/drm/i915/intel_sprite.c +5 -4
-	ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
+	if (old_obj != obj) {
+		mutex_lock(&dev->struct_mutex);
+		ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
 
-	i915_gem_track_fb(old_obj, obj,
-			  INTEL_FRONTBUFFER_SPRITE(pipe));
-	mutex_unlock(&dev->struct_mutex);
+		i915_gem_track_fb(old_obj, obj,
+				  INTEL_FRONTBUFFER_SPRITE(pipe));

I don't think we should be calling this when things failed. This bug was already present in the code, but might as well fix it while you're at it.

Quoted 11 lines
drivers/gpu/drm/i915/intel_sprite.c +4 -2
+		mutex_unlock(&dev->struct_mutex);
 
-	if (ret)
-		return ret;
+		if (ret)
+			return ret;
+	}
 
 	intel_plane->crtc_x = state->orig_dst.x1;
 	intel_plane->crtc_y = state->orig_dst.y1;

drivers/gpu/drm/i915/intel_sprite.c intel_commit_sprite_plane(struct drm_plane *plane, · line 1107

Quoted 9 lines
drivers/gpu/drm/i915/intel_sprite.c +4 -1
@@ -1098,15 +1100,18 @@ intel_commit_sprite_plane(struct drm_plane *plane,
 			intel_post_enable_primary(crtc);
 	}
 
+	if (!old_obj)
+		return 0;
+
 	/* Unpin old obj after new one is active to avoid ugliness */
-	if (old_obj) {
+	if (old_obj != obj) {

I'd prefer
if (old_obj && old_obj != obj) {
in this case.

Quoted 18 lines
drivers/gpu/drm/i915/intel_sprite.c +1 -1
 		/*
 		 * It's fairly common to simply update the position of
 		 * an existing object.  In that case, we don't need to
 		 * wait for vblank to avoid ugliness, we only need to
 		 * do the pin & ref bookkeeping.
 		 */
-		if (old_obj != obj && intel_crtc->active)
+		if (intel_crtc->active)
 			intel_wait_for_vblank(dev, intel_crtc->pipe);
 
 		mutex_lock(&dev->struct_mutex);
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 2 lines
Ville Syrjälä
Intel OTC