Skip to contentSkip to conversation

drm/i915: Implement CS stall workaround on Broadwell.

PATCH In review Kenneth Graunke 3 participants 9 messages Jan 27, 2014 – Jan 28, 2014

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

PATCH 1/5 drm/i915: Implement CS stall workaround on Broadwell.

According to the latest documentation, any PIPE_CONTROL with the "Command Streamer Stall" bit set must also have another bit set, with five different options. I chose "Stall at Pixel Scoreboard" since we've used it effectively in the past, but the choice is fairly arbitrary.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +8 -1
index e75d8b3..313b1bd 100644
@@ -370,7 +370,14 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
 	int ret;
 
-	flags |= PIPE_CONTROL_CS_STALL;
+	/* For CS stalls, one of the following must also be set:
+	 * - Render Target Cache Flush
+	 * - Depth Cache Flush
+	 * - Stall at Pixel Scoreboard
+	 * - Post-Sync Operation
+	 * We arbitrarily choose "Stall at Scoreboard".
+	 */
+	flags |= PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD;
 
 	if (flush_domains) {
 		flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH;
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH 2/5 drm/i915: Refactor Broadwell PIPE_CONTROL emission into a helper.

We'll want to reuse this for a workaround.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 37 ++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +22 -15
index 313b1bd..4774bfa 100644
@@ -363,12 +363,32 @@ gen7_render_ring_flush(struct intel_ring_buffer *ring,
 }
 
 static int
+gen8_emit_pipe_control(struct intel_ring_buffer *ring,
+		       u32 flags, u32 scratch_addr)
+{
+	int ret;
+
+	ret = intel_ring_begin(ring, 6);
+	if (ret)
+		return ret;
+
+	intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(6));
+	intel_ring_emit(ring, flags);
+	intel_ring_emit(ring, scratch_addr);
+	intel_ring_emit(ring, 0);
+	intel_ring_emit(ring, 0);
+	intel_ring_emit(ring, 0);
+	intel_ring_advance(ring);
+
+	return 0;
+}
+
+static int
 gen8_render_ring_flush(struct intel_ring_buffer *ring,
 		       u32 invalidate_domains, u32 flush_domains)
 {
 	u32 flags = 0;
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
-	int ret;
 
 	/* For CS stalls, one of the following must also be set:
 	 * - Render Target Cache Flush
@@ -394,20 +414,7 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 		flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
 	}
 
-	ret = intel_ring_begin(ring, 6);
-	if (ret)
-		return ret;
-
-	intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(6));
-	intel_ring_emit(ring, flags);
-	intel_ring_emit(ring, scratch_addr);
-	intel_ring_emit(ring, 0);
-	intel_ring_emit(ring, 0);
-	intel_ring_emit(ring, 0);
-	intel_ring_advance(ring);
-
-	return 0;
-
+	return gen8_emit_pipe_control(ring, flags, scratch_addr);
 }
 
 static void ring_write_tail(struct intel_ring_buffer *ring,
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH 3/5 drm/i915: Add the WaCsStallBeforeStateCacheInvalidate:bdw workaround.

In reply to Kenneth Graunke

On Broadwell, any PIPE_CONTROL with the "State Cache Invalidate" bit set must be preceded by a PIPE_CONTROL with the "CS Stall" bit set.

Documented on the BSpec 3D workarounds page.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)

The Gen7 code doesn't check ret on the state cache workaround, but it seems like we ought to.

At this point, gen7_render_ring_flush and gen8_render_ring_flush look pretty darn similar. We could probably merge them, if people are interested in that...

drivers/gpu/drm/i915/intel_ringbuffer.c +9 -0
index 4774bfa..049b019 100644
@@ -389,6 +389,7 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 {
 	u32 flags = 0;
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
+	int ret;
 
 	/* For CS stalls, one of the following must also be set:
 	 * - Render Target Cache Flush
@@ -412,6 +413,14 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 		flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE;
 		flags |= PIPE_CONTROL_QW_WRITE;
 		flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
+
+		/* WaCsStallBeforeStateCacheInvalidate:bdw */
+		ret = gen8_emit_pipe_control(ring,
+					     PIPE_CONTROL_CS_STALL |
+					     PIPE_CONTROL_STALL_AT_SCOREBOARD,
+					     0);
+		if (ret)
+			return ret;
 	}
 
 	return gen8_emit_pipe_control(ring, flags, scratch_addr);
Signature · 1 line
1.8.5.2
#3 lore raw

Re: [PATCH 3/5] drm/i915: Add the WaCsStallBeforeStateCacheInvalidate:bdw workaround.

Quoted 4 lines · Kenneth Graunke

On Broadwell, any PIPE_CONTROL with the "State Cache Invalidate" bit set must be preceded by a PIPE_CONTROL with the "CS Stall" bit set.

Documented on the BSpec 3D workarounds page.

FWIW, I am not clear this is actually needed. If it is, we need/should file a bspec bug, since it is missing there. What I am afraid happened is Windows carried it over from gen7, and that's how it ended up in the w/a db.

As I am too lazy to check the performance implications (or whether it's really needed) - I say just ship it.

Quoted 47 lines
---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)

The Gen7 code doesn't check ret on the state cache workaround, but it seems like we ought to.

At this point, gen7_render_ring_flush and gen8_render_ring_flush look pretty darn similar. We could probably merge them, if people are interested in that...

drivers/gpu/drm/i915/intel_ringbuffer.c +9 -0
index 4774bfa..049b019 100644
@@ -389,6 +389,7 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 {
 	u32 flags = 0;
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
+	int ret;
 
 	/* For CS stalls, one of the following must also be set:
 	 * - Render Target Cache Flush
@@ -412,6 +413,14 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 		flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE;
 		flags |= PIPE_CONTROL_QW_WRITE;
 		flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
+
+		/* WaCsStallBeforeStateCacheInvalidate:bdw */
+		ret = gen8_emit_pipe_control(ring,
+					     PIPE_CONTROL_CS_STALL |
+					     PIPE_CONTROL_STALL_AT_SCOREBOARD,
+					     0);
+		if (ret)
+			return ret;
 	}
 
 	return gen8_emit_pipe_control(ring, flags, scratch_addr);
Signature · 6 lines
1.8.5.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#4 lore raw

PATCH 4/5 drm/i915: Add a partial instruction shootdown workaround on Broadwell.

In reply to Kenneth Graunke

This should apply even for production hardware.

---
 drivers/gpu/drm/i915/i915_reg.h | 4 ++++
 drivers/gpu/drm/i915/intel_pm.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +4 -0
index b958e85..418e055 100644
@@ -5007,6 +5007,10 @@
 #define   GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE	(1<<10)
 #define   GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE	(1<<3)
 
+#define GEN8_ROW_CHICKEN		0xe4f0
+#define   PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE	(1<<8)
+#define   STALL_DOP_GATING_DISABLE	(1<<5)
+
 #define GEN7_ROW_CHICKEN2		0xe4f4
 #define GEN7_ROW_CHICKEN2_GT2		0xf4f4
 #define   DOP_CLOCK_GATING_DISABLE	(1<<0)
drivers/gpu/drm/i915/intel_pm.c +4 -0
index 54e99db..801d439 100644
@@ -4713,6 +4713,10 @@ static void gen8_init_clock_gating(struct drm_device *dev)
 	/* FIXME(BDW): Check all the w/a, some might only apply to
 	 * pre-production hw. */
 
+	/* WaDisablePartialInstShootdown */
+	I915_WRITE(GEN8_ROW_CHICKEN,
+	           _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE));
+
 	/*
 	 * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for
 	 * pre-production hardware
Signature · 1 line
1.8.5.2
#5 lore raw

PATCH 5/5 drm/i915: Implement more Broadwell workarounds.

In reply to Kenneth Graunke

These should only be necessary on pre-production hardware.

---
 drivers/gpu/drm/i915/i915_reg.h |  1 +
 drivers/gpu/drm/i915/intel_pm.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +1 -0
index 418e055..3ad5483 100644
@@ -5008,6 +5008,7 @@
 #define   GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE	(1<<3)
 
 #define GEN8_ROW_CHICKEN		0xe4f0
+#define   INSTRUCTION_SHOOTDOWN_DISABLE	(1<<9)
 #define   PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE	(1<<8)
 #define   STALL_DOP_GATING_DISABLE	(1<<5)
 
drivers/gpu/drm/i915/intel_pm.c +12 -0
index 801d439..3cec13f 100644
@@ -4717,6 +4717,18 @@ static void gen8_init_clock_gating(struct drm_device *dev)
 	I915_WRITE(GEN8_ROW_CHICKEN,
 	           _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE));
 
+	/* WaDisableInstructionShootdown:bdw - pre-production only */
+	I915_WRITE(GEN8_ROW_CHICKEN,
+		   _MASKED_BIT_ENABLE(INSTRUCTION_SHOOTDOWN_DISABLE));
+
+	/* WaDisableThreadStallDopClockGating:bdw - pre-production only */
+	I915_WRITE(GEN8_ROW_CHICKEN,
+		   _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE));
+
+	/* WaDisableRowChickenDopClockGating:bdw - pre-production only */
+	I915_WRITE(GEN7_ROW_CHICKEN2,
+		   _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
+
 	/*
 	 * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for
 	 * pre-production hardware
Signature · 1 line
1.8.5.2
Reviewed-by on v1 5/5
#6 lore raw

Re: [PATCH 5/5] drm/i915: Implement more Broadwell workarounds.

Quoted 25 lines · Kenneth Graunke

These should only be necessary on pre-production hardware.

---
 drivers/gpu/drm/i915/i915_reg.h |  1 +
 drivers/gpu/drm/i915/intel_pm.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +1 -0
index 418e055..3ad5483 100644
@@ -5008,6 +5008,7 @@
 #define   GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE	(1<<3)
 
 #define GEN8_ROW_CHICKEN		0xe4f0
+#define   INSTRUCTION_SHOOTDOWN_DISABLE	(1<<9)
 #define   PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE	(1<<8)
 #define   STALL_DOP_GATING_DISABLE	(1<<5)
 
drivers/gpu/drm/i915/intel_pm.c +0 -0
index 801d439..3cec13f 100644

drivers/gpu/drm/i915/intel_pm.c static void gen8_init_clock_gating(struct drm_device *dev) · line 4726

Quoted 10 lines
drivers/gpu/drm/i915/intel_pm.c +7 -0
@@ -4717,6 +4717,18 @@ static void gen8_init_clock_gating(struct drm_device *dev)
 	I915_WRITE(GEN8_ROW_CHICKEN,
 	           _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE));
 
+	/* WaDisableInstructionShootdown:bdw - pre-production only */
+	I915_WRITE(GEN8_ROW_CHICKEN,
+		   _MASKED_BIT_ENABLE(INSTRUCTION_SHOOTDOWN_DISABLE));
+
+	/* WaDisableThreadStallDopClockGating:bdw - pre-production only */
+	I915_WRITE(GEN8_ROW_CHICKEN,
+		   _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE));

bspec leads me to believe this one is not pre-production only.

drivers/gpu/drm/i915/intel_pm.c static void gen8_init_clock_gating(struct drm_device *dev) · line 4734

Quoted 8 lines
drivers/gpu/drm/i915/intel_pm.c +5 -0
+
+	/* WaDisableRowChickenDopClockGating:bdw - pre-production only */
+	I915_WRITE(GEN7_ROW_CHICKEN2,
+		   _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
+
 	/*
 	 * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for
 	 * pre-production hardware

Other than the two minor nitpicks, lgtm in patch 1, and here:

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Reviewed-by on v1 1/5
#7 lore raw
In reply to Kenneth Graunke
Quoted 21 lines · Kenneth Graunke

According to the latest documentation, any PIPE_CONTROL with the "Command Streamer Stall" bit set must also have another bit set, with five different options. I chose "Stall at Pixel Scoreboard" since we've used it effectively in the past, but the choice is fairly arbitrary.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +1 -1
index e75d8b3..313b1bd 100644
@@ -370,7 +370,14 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
 	int ret;
 
-	flags |= PIPE_CONTROL_CS_STALL;
+	/* For CS stalls, one of the following must also be set:

drivers/gpu/drm/i915/intel_ringbuffer.c gen8_render_ring_flush(struct intel_ring_buffer *ring, · line 383

Quoted 10 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +7 -0
+	 * - Render Target Cache Flush
+	 * - Depth Cache Flush
+	 * - Stall at Pixel Scoreboard
+	 * - Post-Sync Operation
+	 * We arbitrarily choose "Stall at Scoreboard".
+	 */
+	flags |= PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD;
 
 	if (flush_domains) {
 		flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH;

If I am reading the same workaround as you, we only need to do this when !flush_domains, since we satisfy the requisite in the flush_domains case.

But I can live with it whether or not you change it.

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#8 lore raw
Quoted 30 lines · Ben Widawsky
Quoted 29 lines · Kenneth Graunke

According to the latest documentation, any PIPE_CONTROL with the "Command Streamer Stall" bit set must also have another bit set, with five different options. I chose "Stall at Pixel Scoreboard" since we've used it effectively in the past, but the choice is fairly arbitrary.

---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ringbuffer.c +8 -1
index e75d8b3..313b1bd 100644
@@ -370,7 +370,14 @@ gen8_render_ring_flush(struct intel_ring_buffer *ring,
 	u32 scratch_addr = ring->scratch.gtt_offset + 128;
 	int ret;
 
-	flags |= PIPE_CONTROL_CS_STALL;
+	/* For CS stalls, one of the following must also be set:
+	 * - Render Target Cache Flush
+	 * - Depth Cache Flush
+	 * - Stall at Pixel Scoreboard
+	 * - Post-Sync Operation
+	 * We arbitrarily choose "Stall at Scoreboard".
+	 */
+	flags |= PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD;
 
Quoted 6 lines

drivers/gpu/drm/i915/intel_ringbuffer.c gen8_render_ring_flush(struct intel_ring_buffer *ring, · line 383

Quoted 2 lines
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -0
 	if (flush_domains) {
 		flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH;

If I am reading the same workaround as you, we only need to do this when !flush_domains, since we satisfy the requisite in the flush_domains case.

And we satisfy them for !flush_domains as well since we do a post-sync operation (since it must be an invalidate_domains).
-Chris

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