Skip to contentSkip to conversation

drm/i915/vlv: Use Blitter Engine to clear out contents of Stolen frame buffers

PATCH In review [email protected] 3 participants 4 messages Jan 9, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 7/7 drm/i915/vlv: Use Blitter Engine to clear out contents of Stolen frame buffers

From: Akash Goel <[email protected]>

On VLV, to clear out the contents of Frame buffers allocated from stolen area, Blitter engine is being used, to avoid the waste of CPU cycles in doing a sw based memset.

---
 drivers/gpu/drm/i915/i915_gem_stolen.c | 87 ++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem_stolen.c +84 -3
index 253a39a..10237c8 100644
@@ -371,7 +371,84 @@ i915_gem_object_create_stolen(struct drm_device *dev, u32 size)
 	return NULL;
 }
 
-static void i915_memset_stolen_obj(struct drm_i915_gem_object *obj)
+static int i915_add_clear_obj_cmd(struct drm_i915_gem_object *obj)
+{
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
+	uint32_t obj_height = (obj->base.size / obj->stride);
+	u32 offset = i915_gem_obj_ggtt_offset(obj);
+	int ret;
+
+#define	COLOR_BLIT_OP		((0x2 << 29) | (0x40 << 22) | (0x3 << 20) | 0x3)
+#define	COLOR_BLIT_OP_DW1	((0x3 << 24) | (0xF0 << 16) | (obj->stride))
+#define	COLOR_BLIT_OP_DW2	((obj_height << 16) | (obj->stride))
+#define	COLOR_BLIT_OP_DW3	(offset)
+#define	COLOR_BLIT_OP_DW4	(0x0)
+
+	ret = intel_ring_begin(ring, 6);
+	if (ret)
+		return ret;
+	intel_ring_emit(ring, COLOR_BLIT_OP);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW1);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW2);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW3);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW4);
+	intel_ring_emit(ring, MI_NOOP);
+	intel_ring_advance(ring);
+
+	return 0;
+}
+
+static int i915_memset_stolen_obj_hw(struct drm_i915_gem_object *obj)
+{
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
+	unsigned alignment = 0;
+	bool map_and_fenceable =  true;
+	bool nonblocking = false;
+	u32 seqno;
+	int ret;
+
+	ret = i915_gem_obj_ggtt_pin(obj, alignment, map_and_fenceable,
+		nonblocking);
+	if (ret) {
+		DRM_ERROR("Mapping of User FB to GTT failed\n");
+		return ret;
+	}
+
+	/* Adding commands to the blitter ring to
+	 * clear out the contents of the buffer object
+	 */
+	ret = i915_add_clear_obj_cmd(obj);
+	if (ret) {
+		DRM_ERROR("couldn't add commands in blitter ring\n");
+		i915_gem_object_ggtt_unpin(obj);
+		return ret;
+	}
+
+	seqno = intel_ring_get_seqno(ring);
+
+	/* Object now in render domain */
+	obj->base.read_domains = I915_GEM_DOMAIN_RENDER;
+	obj->base.write_domain = I915_GEM_DOMAIN_RENDER;
+
+	i915_vma_move_to_active(i915_gem_obj_to_ggtt(obj), ring);
+
+	obj->dirty = 1;
+	obj->last_write_seqno = seqno;
+
+	/* Unconditionally force add_request to emit a full flush. */
+	ring->gpu_caches_dirty = true;
+
+	/* Add a breadcrumb for the completion of the clear request */
+	(void)i915_add_request(ring, NULL);
+
+	i915_gem_object_ggtt_unpin(obj);
+
+	return 0;
+}
+
+static void i915_memset_stolen_obj_sw(struct drm_i915_gem_object *obj)
 {
 	int ret;
 	char __iomem *base;
@@ -490,9 +567,13 @@ i915_gem_object_move_to_stolen(struct drm_i915_gem_object *obj)
 	obj->cache_level = HAS_LLC(dev) ? I915_CACHE_LLC : I915_CACHE_NONE;
 
 	/* Zero-out the contents of the stolen object, otherwise we observe
-	 * corruptions in the display.
+	 * corruptions in the display. First try using the blitter engine
+	 * to clear the buffer contents
 	 */
-	i915_memset_stolen_obj(obj);
+	ret = i915_memset_stolen_obj_hw(obj);
+	/* fallback to Sw based memset if Hw memset fails */
+	if (ret)
+		i915_memset_stolen_obj_sw(obj);
 	return;
 
 cleanup:
Signature · 1 line
1.8.5.2
#1 lore raw
Quoted 16 lines · On Thu, Jan 09, 2014 at 11:01:56AM +0530, [email protected] wrote:

From: Akash Goel <[email protected]>

On VLV, to clear out the contents of Frame buffers allocated from stolen area, Blitter engine is being used, to avoid the waste of CPU cycles in doing a sw based memset.

---
 drivers/gpu/drm/i915/i915_gem_stolen.c | 87 ++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem_stolen.c +0 -0
index 253a39a..10237c8 100644

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen(struct drm_device *dev, u32 size) · line 377

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4 -1
@@ -371,7 +371,84 @@ i915_gem_object_create_stolen(struct drm_device *dev, u32 size)
 	return NULL;
 }
 
-static void i915_memset_stolen_obj(struct drm_i915_gem_object *obj)
+static int i915_add_clear_obj_cmd(struct drm_i915_gem_object *obj)
+{
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct intel_ring_buffer *ring = &dev_priv->ring[BCS];

Pre-gen6 has the blitter on the RCS ring.

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen(struct drm_device *dev, u32 size) · line 378

Quoted 1 line
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -0
+	uint32_t obj_height = (obj->base.size / obj->stride);

obj->stride is 0 for untiled buffers, so for more robustness I'd just use 4096 (page size) as stride. For even more robustness I think we should have checks here to make sure that we don't overflow blitter hw limits here.

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen(struct drm_device *dev, u32 size) · line 386

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +8 -0
+	u32 offset = i915_gem_obj_ggtt_offset(obj);
+	int ret;
+
+#define	COLOR_BLIT_OP		((0x2 << 29) | (0x40 << 22) | (0x3 << 20) | 0x3)
+#define	COLOR_BLIT_OP_DW1	((0x3 << 24) | (0xF0 << 16) | (obj->stride))
+#define	COLOR_BLIT_OP_DW2	((obj_height << 16) | (obj->stride))
+#define	COLOR_BLIT_OP_DW3	(offset)
+#define	COLOR_BLIT_OP_DW4	(0x0)

These #defines imo don't help readability, everywhere else (kernel/userspace) we construct the cmd dwords in-line in the OUT_BATCH/intel_ring_emit calls. Also please use the existing XY_ blt cmd #defines in i915_reg.h.
- Daniel

Quoted 91 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +71 -2
+
+	ret = intel_ring_begin(ring, 6);
+	if (ret)
+		return ret;
+	intel_ring_emit(ring, COLOR_BLIT_OP);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW1);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW2);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW3);
+	intel_ring_emit(ring, COLOR_BLIT_OP_DW4);
+	intel_ring_emit(ring, MI_NOOP);
+	intel_ring_advance(ring);
+
+	return 0;
+}
+
+static int i915_memset_stolen_obj_hw(struct drm_i915_gem_object *obj)
+{
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
+	unsigned alignment = 0;
+	bool map_and_fenceable =  true;
+	bool nonblocking = false;
+	u32 seqno;
+	int ret;
+
+	ret = i915_gem_obj_ggtt_pin(obj, alignment, map_and_fenceable,
+		nonblocking);
+	if (ret) {
+		DRM_ERROR("Mapping of User FB to GTT failed\n");
+		return ret;
+	}
+
+	/* Adding commands to the blitter ring to
+	 * clear out the contents of the buffer object
+	 */
+	ret = i915_add_clear_obj_cmd(obj);
+	if (ret) {
+		DRM_ERROR("couldn't add commands in blitter ring\n");
+		i915_gem_object_ggtt_unpin(obj);
+		return ret;
+	}
+
+	seqno = intel_ring_get_seqno(ring);
+
+	/* Object now in render domain */
+	obj->base.read_domains = I915_GEM_DOMAIN_RENDER;
+	obj->base.write_domain = I915_GEM_DOMAIN_RENDER;
+
+	i915_vma_move_to_active(i915_gem_obj_to_ggtt(obj), ring);
+
+	obj->dirty = 1;
+	obj->last_write_seqno = seqno;
+
+	/* Unconditionally force add_request to emit a full flush. */
+	ring->gpu_caches_dirty = true;
+
+	/* Add a breadcrumb for the completion of the clear request */
+	(void)i915_add_request(ring, NULL);
+
+	i915_gem_object_ggtt_unpin(obj);
+
+	return 0;
+}
+
+static void i915_memset_stolen_obj_sw(struct drm_i915_gem_object *obj)
 {
 	int ret;
 	char __iomem *base;
@@ -490,9 +567,13 @@ i915_gem_object_move_to_stolen(struct drm_i915_gem_object *obj)
 	obj->cache_level = HAS_LLC(dev) ? I915_CACHE_LLC : I915_CACHE_NONE;
 
 	/* Zero-out the contents of the stolen object, otherwise we observe
-	 * corruptions in the display.
+	 * corruptions in the display. First try using the blitter engine
+	 * to clear the buffer contents
 	 */
-	i915_memset_stolen_obj(obj);
+	ret = i915_memset_stolen_obj_hw(obj);
+	/* fallback to Sw based memset if Hw memset fails */
+	if (ret)
+		i915_memset_stolen_obj_sw(obj);
 	return;
 
 cleanup:
Signature · 6 lines
1.8.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw

Sorry we have never received the i915_gem_exec.c file . Please share that, we don't see it in the drm-intel-next also.

Best Regards
Akash

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Thursday, January 09, 2014 3:16 PM
To: Goel, Akash
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH 7/7] drm/i915/vlv: Use Blitter Engine to clear out contents of Stolen frame buffers

Quoted 1 line · On Thu, Jan 09, 2014 at 11:01:56AM +0530, [email protected] wrote:

From: Akash Goel <[email protected]>

Did I not ever send i915_gem_exec.c which does this correctly? -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre