Skip to contentSkip to conversation

drm/i915: Initialize hardware semaphore state on ring init

PATCH Superseded Mika Kuoppala 2 participants 13 messages Dec 17, 2012 – Dec 18, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 drm/i915: Initialize hardware semaphore state on ring init

Hardware status page needs to have proper seqno set
as our initial seqno can be arbitrary. If initial seqno is close to wrap boundary on init and i915_seqno_passed() (31bit space) refers to hw status page which contains zero, errorneous result will be returned.

References: https://bugs.freedesktop.org/show_bug.cgi?id=58230

---
 drivers/gpu/drm/i915/i915_gem.c         |    6 +++---
 drivers/gpu/drm/i915/intel_ringbuffer.c |   18 ++++++++++++++++--
 drivers/gpu/drm/i915/intel_ringbuffer.h |    3 ++-
 3 files changed, 21 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +3 -3
index d15c862..8dc5cc1 100644
@@ -1954,7 +1954,7 @@ i915_gem_handle_seqno_wrap(struct drm_device *dev)
 
 	/* Finally reset hw state */
 	for_each_ring(ring, dev_priv, i) {
-		ret = intel_ring_handle_seqno_wrap(ring);
+		ret = intel_ring_init_seqno(ring, 0);
 		if (ret)
 			return ret;
 
@@ -3933,6 +3933,8 @@ i915_gem_init_hw(struct drm_device *dev)
 
 	i915_gem_init_swizzling(dev);
 
+	dev_priv->next_seqno = dev_priv->last_seqno = (u32)~0 - 0x1000;
+
 	ret = intel_init_render_ring_buffer(dev);
 	if (ret)
 		return ret;
@@ -3949,8 +3951,6 @@ i915_gem_init_hw(struct drm_device *dev)
 			goto cleanup_bsd_ring;
 	}
 
-	dev_priv->next_seqno = (u32)-1 - 0x1000;
-
 	/*
 	 * XXX: There was some w/a described somewhere suggesting loading
 	 * contexts before PPGTT.
drivers/gpu/drm/i915/intel_ringbuffer.c +16 -2
index 69bbe7b..7e38511f 100644
@@ -1171,6 +1171,10 @@ static int intel_init_ring_buffer(struct drm_device *dev,
 	if (IS_I830(ring->dev) || IS_845G(ring->dev))
 		ring->effective_size -= 128;
 
+	ret = intel_ring_init_seqno(ring, dev_priv->last_seqno);
+	if (ret)
+		goto err_unmap;
+
 	return 0;
 
 err_unmap:
@@ -1418,7 +1422,7 @@ int intel_ring_begin(struct intel_ring_buffer *ring,
 	return __intel_ring_begin(ring, num_dwords * sizeof(uint32_t));
 }
 
-int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
+int intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno)
 {
 	int ret;
 
@@ -1427,7 +1431,7 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	if (INTEL_INFO(ring->dev)->gen < 6)
 		return 0;
 
-	ret = __intel_ring_begin(ring, 6 * sizeof(uint32_t));
+	ret = __intel_ring_begin(ring, 10 * sizeof(uint32_t));
 	if (ret)
 		return ret;
 
@@ -1435,8 +1439,18 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	 * post-wrap semaphore waits completing immediately. Clear them. */
 	update_mboxes(ring, ring->signal_mbox[0]);
 	update_mboxes(ring, ring->signal_mbox[1]);
+	intel_ring_emit(ring, MI_STORE_DWORD_INDEX);
+	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
+	intel_ring_emit(ring, seqno);
+	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
+	/* Wait until mboxes have actually cleared before pushing
+	 * anything to the rings */
+	ret = ring_wait_for_space(ring, ring->size - 8);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
drivers/gpu/drm/i915/intel_ringbuffer.h +2 -1
index b4a533e..cb5a663 100644
@@ -196,7 +196,8 @@ static inline void intel_ring_emit(struct intel_ring_buffer *ring,
 }
 void intel_ring_advance(struct intel_ring_buffer *ring);
 int __must_check intel_ring_idle(struct intel_ring_buffer *ring);
-int __must_check intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring);
+int __must_check intel_ring_init_seqno(struct intel_ring_buffer *ring,
+				       u32 seqno);
 int intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
 int intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
 
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/4 drm/i915: Always clear semaphore mboxes on seqno wrap

We need to clear the hw semaphore values explicitly. Even if sync_seqnos are zero, there might still be invalid values in the hw semaphores when we wrap.

---
 drivers/gpu/drm/i915/i915_gem.c |   12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +0 -12
index 8dc5cc1..0231fdb 100644
@@ -1932,18 +1932,6 @@ i915_gem_handle_seqno_wrap(struct drm_device *dev)
 	struct intel_ring_buffer *ring;
 	int ret, i, j;
 
-	/* The hardware uses various monotonic 32-bit counters, if we
-	 * detect that they will wraparound we need to idle the GPU
-	 * and reset those counters.
-	 */
-	ret = 0;
-	for_each_ring(ring, dev_priv, i) {
-		for (j = 0; j < ARRAY_SIZE(ring->sync_seqno); j++)
-			ret |= ring->sync_seqno[j] != 0;
-	}
-	if (ret == 0)
-		return ret;
-
 	/* Carefully retire all requests without writing to the rings */
 	for_each_ring(ring, dev_priv, i) {
 		ret = intel_ring_idle(ring);
Signature · 1 line
1.7.9.5
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] drm/i915: Always clear semaphore mboxes on seqno wrap

Quoted 3 lines · Mika Kuoppala

We need to clear the hw semaphore values explicitly. Even if sync_seqnos are zero, there might still be invalid values in the hw semaphores when we wrap.

This changelog does not make it clear why you want this patch. This is for enabling a future feature, right?

Anyway, after initial misgivings because I thought you were trying to fix a bug rather than add a feature, and provided that you improve the changelog,

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/4] drm/i915: Always clear semaphore mboxes on seqno wrap

Quoted 11 lines · Chris Wilson
Quoted 3 lines · Mika Kuoppala

We need to clear the hw semaphore values explicitly. Even if sync_seqnos are zero, there might still be invalid values in the hw semaphores when we wrap.

This changelog does not make it clear why you want this patch. This is for enabling a future feature, right?

Anyway, after initial misgivings because I thought you were trying to fix a bug rather than add a feature, and provided that you improve the changelog,

The intent is to always clear the mboxes and also set the hws page when seqno is set. Both when wrapping and setting seqno from debugfs. The hws part is needed to fix a bug where initial seqno in hws page is zero (after boot) and driver seqno is past the 2^31 boundary. I guess i could have split the mboxes and hws page setting apart saving the optimization but the gain would be little.

I think this is also issue on suspend/resume if we have passed 2^31 on suspend and we come back with driver setting initial seqno to 1.

In both cases i915_seqno_passed(ring->get_seqno(), driver_seqno) will return errorneous value.

Quoted 2 lines

-Chris

Does r-b still stand after the explanation above?

-Mika

#4 lore raw

Re: [PATCH 2/4] drm/i915: Always clear semaphore mboxes on seqno wrap

Quoted 24 lines · Mika Kuoppala
Quoted 11 lines · Chris Wilson
Quoted 3 lines · Mika Kuoppala

We need to clear the hw semaphore values explicitly. Even if sync_seqnos are zero, there might still be invalid values in the hw semaphores when we wrap.

This changelog does not make it clear why you want this patch. This is for enabling a future feature, right?

Anyway, after initial misgivings because I thought you were trying to fix a bug rather than add a feature, and provided that you improve the changelog,

The intent is to always clear the mboxes and also set the hws page when seqno is set. Both when wrapping and setting seqno from debugfs. The hws part is needed to fix a bug where initial seqno in hws page is zero (after boot) and driver seqno is past the 2^31 boundary. I guess i could have split the mboxes and hws page setting apart saving the optimization but the gain would be little.

I think this is also issue on suspend/resume if we have passed 2^31 on suspend and we come back with driver setting initial seqno to 1.

Quoted 7 lines

In both cases i915_seqno_passed(ring->get_seqno(), driver_seqno) will return errorneous value.

Quoted 2 lines

-Chris

Does r-b still stand after the explanation above?

Not really, that's an explanation for the series (setting initial seqno values was incomplete, we needed to adjust the hw side as well as our bookkeeping). But it doesn't explain why you want to change i915_gem_seqno_handle_wrap() in this patch, which as far as I can tell is because you want to reuse it later for a more general purpose. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

PATCH 3/4 drm/i915: Introduce i915_gem_seqno_init

In reply to Mika Kuoppala

i915_gem_seqno_init can set seqno to arbitrary value.

---
 drivers/gpu/drm/i915/i915_drv.h |    4 ++--
 drivers/gpu/drm/i915/i915_gem.c |    8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -2
index 514aee8..5968340 100644
@@ -1479,8 +1479,8 @@ i915_seqno_passed(uint32_t seq1, uint32_t seq2)
 	return (int32_t)(seq1 - seq2) >= 0;
 }
 
-extern int i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
-
+int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
+int __must_check i915_gem_init_seqno(struct drm_device *dev, u32 seqno);
 int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
 int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
 
drivers/gpu/drm/i915/i915_gem.c +4 -4
index 0231fdb..13d2067 100644
@@ -1925,8 +1925,8 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
 	WARN_ON(i915_verify_lists(dev));
 }
 
-static int
-i915_gem_handle_seqno_wrap(struct drm_device *dev)
+int
+i915_gem_init_seqno(struct drm_device *dev, u32 seqno)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_ring_buffer *ring;
@@ -1942,7 +1942,7 @@ i915_gem_handle_seqno_wrap(struct drm_device *dev)
 
 	/* Finally reset hw state */
 	for_each_ring(ring, dev_priv, i) {
-		ret = intel_ring_init_seqno(ring, 0);
+		ret = intel_ring_init_seqno(ring, seqno);
 		if (ret)
 			return ret;
 
@@ -1960,7 +1960,7 @@ i915_gem_get_seqno(struct drm_device *dev, u32 *seqno)
 
 	/* reserve 0 for non-seqno */
 	if (dev_priv->next_seqno == 0) {
-		int ret = i915_gem_handle_seqno_wrap(dev);
+		int ret = i915_gem_init_seqno(dev, 0);
 		if (ret)
 			return ret;
 
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 4/4 drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

In reply to Mika Kuoppala

As this debugs entry can be used to set arbitrary value to next_seqno, use i915_gem_seqno_init to set the next_seqno.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +11 -6
index 7047c4a..e669e2e 100644
@@ -903,12 +903,17 @@ i915_next_seqno_write(struct file *filp,
 	if (ret)
 		return ret;
 
-	if (i915_seqno_passed(val, dev_priv->next_seqno)) {
-		dev_priv->next_seqno = val;
-		DRM_DEBUG_DRIVER("Advancing seqno to %u\n", val);
-	} else {
-		ret = -EINVAL;
-	}
+	ret = i915_gem_init_seqno(dev, val - 1);
+	if (ret)
+		return ret;
+
+	dev_priv->next_seqno = val;
+
+	/* Carefully set the last_seqno value so that
+	 * wrap detection still works */
+	dev_priv->last_seqno = val - 1;
+	if (dev_priv->last_seqno == 0)
+		dev_priv->last_seqno--;
 
 	mutex_unlock(&dev->struct_mutex);
 
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

Quoted 43 lines · Mika Kuoppala

As this debugs entry can be used to set arbitrary value to next_seqno, use i915_gem_seqno_init to set the next_seqno.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +11 -6
index 7047c4a..e669e2e 100644
@@ -903,12 +903,17 @@ i915_next_seqno_write(struct file *filp,
 	if (ret)
 		return ret;
 
-	if (i915_seqno_passed(val, dev_priv->next_seqno)) {
-		dev_priv->next_seqno = val;
-		DRM_DEBUG_DRIVER("Advancing seqno to %u\n", val);
-	} else {
-		ret = -EINVAL;
-	}
+	ret = i915_gem_init_seqno(dev, val - 1);
+	if (ret)
+		return ret;
+
+	dev_priv->next_seqno = val;
+
+	/* Carefully set the last_seqno value so that
+	 * wrap detection still works */
+	dev_priv->last_seqno = val - 1;
+	if (dev_priv->last_seqno == 0)
+		dev_priv->last_seqno--;
 
 	mutex_unlock(&dev->struct_mutex);
 
Signature · 6 lines
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

From: Chris Wilson <[email protected]>
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/i915: Introduce i915_gem_seqno_init
To: Mika Kuoppala <[email protected]>, [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]>

Quoted 63 lines · Mika Kuoppala

i915_gem_seqno_init can set seqno to arbitrary value.

---
 drivers/gpu/drm/i915/i915_drv.h |    4 ++--
 drivers/gpu/drm/i915/i915_gem.c |    8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -2
index 514aee8..5968340 100644
@@ -1479,8 +1479,8 @@ i915_seqno_passed(uint32_t seq1, uint32_t seq2)
 	return (int32_t)(seq1 - seq2) >= 0;
 }
 
-extern int i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
-
+int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
+int __must_check i915_gem_init_seqno(struct drm_device *dev, u32 seqno);
 int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
 int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
 
drivers/gpu/drm/i915/i915_gem.c +4 -4
index 0231fdb..13d2067 100644
@@ -1925,8 +1925,8 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
 	WARN_ON(i915_verify_lists(dev));
 }
 
-static int
-i915_gem_handle_seqno_wrap(struct drm_device *dev)
+int
+i915_gem_init_seqno(struct drm_device *dev, u32 seqno)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_ring_buffer *ring;
@@ -1942,7 +1942,7 @@ i915_gem_handle_seqno_wrap(struct drm_device *dev)
 
 	/* Finally reset hw state */
 	for_each_ring(ring, dev_priv, i) {
-		ret = intel_ring_init_seqno(ring, 0);
+		ret = intel_ring_init_seqno(ring, seqno);
 		if (ret)
 			return ret;
 
@@ -1960,7 +1960,7 @@ i915_gem_get_seqno(struct drm_device *dev, u32 *seqno)
 
 	/* reserve 0 for non-seqno */
 	if (dev_priv->next_seqno == 0) {
-		int ret = i915_gem_handle_seqno_wrap(dev);
+		int ret = i915_gem_init_seqno(dev, 0);
 		if (ret)
 			return ret;
 
Signature · 6 lines
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

From: Chris Wilson <[email protected]>
Subject: Re: [Intel-gfx] [PATCH 2/4] drm/i915: Always clear semaphore mboxes on seqno wrap
To: Mika Kuoppala <[email protected]>, [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]>

Quoted 39 lines · Mika Kuoppala

We need to clear the hw semaphore values explicitly. Even if sync_seqnos are zero, there might still be invalid values in the hw semaphores when we wrap.

---
 drivers/gpu/drm/i915/i915_gem.c |   12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +0 -12
index 8dc5cc1..0231fdb 100644
@@ -1932,18 +1932,6 @@ i915_gem_handle_seqno_wrap(struct drm_device *dev)
 	struct intel_ring_buffer *ring;
 	int ret, i, j;
 
-	/* The hardware uses various monotonic 32-bit counters, if we
-	 * detect that they will wraparound we need to idle the GPU
-	 * and reset those counters.
-	 */
-	ret = 0;
-	for_each_ring(ring, dev_priv, i) {
-		for (j = 0; j < ARRAY_SIZE(ring->sync_seqno); j++)
-			ret |= ring->sync_seqno[j] != 0;
-	}
-	if (ret == 0)
-		return ret;
-
 	/* Carefully retire all requests without writing to the rings */
 	for_each_ring(ring, dev_priv, i) {
 		ret = intel_ring_idle(ring);
Signature · 6 lines
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

From: Chris Wilson <[email protected]>
Subject: Re: [Intel-gfx] [PATCH 1/4] drm/i915: Initialize hardware semaphore state on ring init
To: Mika Kuoppala <[email protected]>, [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>

Quoted 8 lines · Mika Kuoppala

Hardware status page needs to have proper seqno set
as our initial seqno can be arbitrary. If initial seqno is close to wrap boundary on init and i915_seqno_passed() (31bit space) refers to hw status page which contains zero, errorneous result will be returned.

References: https://bugs.freedesktop.org/show_bug.cgi?id=58230

Looks good baring the last chunk.

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -1435,8 +1439,18 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	 * post-wrap semaphore waits completing immediately. Clear them. */
 	update_mboxes(ring, ring->signal_mbox[0]);
 	update_mboxes(ring, ring->signal_mbox[1]);
+	intel_ring_emit(ring, MI_STORE_DWORD_INDEX);

drivers/gpu/drm/i915/i915_gem.c int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring) · line 1452

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +8 -0
+	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
+	intel_ring_emit(ring, seqno);
+	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
+	/* Wait until mboxes have actually cleared before pushing
+	 * anything to the rings */
+	ret = ring_wait_for_space(ring, ring->size - 8);
+	if (ret)
+		return ret;

I don't this is well justified. Can you clearly explain the situation where it is required?

How about if we assert that the ring is idle, and just blitz the registers and hws rather than go through the ring? -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

Quoted 23 lines · Chris Wilson
Quoted 8 lines · Mika Kuoppala

Hardware status page needs to have proper seqno set
as our initial seqno can be arbitrary. If initial seqno is close to wrap boundary on init and i915_seqno_passed() (31bit space) refers to hw status page which contains zero, errorneous result will be returned.

References: https://bugs.freedesktop.org/show_bug.cgi?id=58230

Looks good baring the last chunk.

Quoted 10 lines
(quoted diff) +4 -0
@@ -1435,8 +1439,18 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	 * post-wrap semaphore waits completing immediately. Clear them. */
 	update_mboxes(ring, ring->signal_mbox[0]);
 	update_mboxes(ring, ring->signal_mbox[1]);
+	intel_ring_emit(ring, MI_STORE_DWORD_INDEX);
+	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
+	intel_ring_emit(ring, seqno);
+	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
Quoted 8 lines

Review int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring) · line 1452

Quoted 5 lines
(quoted diff) +5 -0
+	/* Wait until mboxes have actually cleared before pushing
+	 * anything to the rings */
+	ret = ring_wait_for_space(ring, ring->size - 8);
+	if (ret)
+		return ret;

I don't this is well justified. Can you clearly explain the situation where it is required?

As the ring_add_request can it self cause seqno wrap due to intel_ring_begin, and the fact that it will update the *other* rings mboxes, we need to wait until all the rings have proceed with clearing the mboxes.

Quoted 3 lines

How about if we assert that the ring is idle, and just blitz the registers and hws rather than go through the ring? -Chris

I have tried this but failed. I think the problem is ring_add_request. It will still inject seqnos before the wrap boundary if intel_ring_begin in itself just wrapped. This is why we need to clear mboxes and set the hws page through rings.

I have a patch which allocates seqnos explicitly early in i915_gem_do_execbuffer, gets rid of outstanding_lazy_request and related i915_gem_check_olr completely thus making the wrap handling much more simpler as we don't need to be careful in ring_sync nor ring_add_request as no cross wrap boundary stuff can no longer happen. But I got the impression that you don't like this approach.

-Mika

Quoted 2 lines
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#9 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

Quoted 34 lines · Mika Kuoppala
Quoted 23 lines · Chris Wilson
Quoted 8 lines · Mika Kuoppala

Hardware status page needs to have proper seqno set
as our initial seqno can be arbitrary. If initial seqno is close to wrap boundary on init and i915_seqno_passed() (31bit space) refers to hw status page which contains zero, errorneous result will be returned.

References: https://bugs.freedesktop.org/show_bug.cgi?id=58230

Looks good baring the last chunk.

Quoted 10 lines
(quoted diff) +4 -0
@@ -1435,8 +1439,18 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	 * post-wrap semaphore waits completing immediately. Clear them. */
 	update_mboxes(ring, ring->signal_mbox[0]);
 	update_mboxes(ring, ring->signal_mbox[1]);
+	intel_ring_emit(ring, MI_STORE_DWORD_INDEX);
+	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
+	intel_ring_emit(ring, seqno);
+	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
Quoted 8 lines

Review int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring) · line 1452

Quoted 5 lines
(quoted diff) +5 -0
+	/* Wait until mboxes have actually cleared before pushing
+	 * anything to the rings */
+	ret = ring_wait_for_space(ring, ring->size - 8);
+	if (ret)
+		return ret;

I don't this is well justified. Can you clearly explain the situation where it is required?

Quoted 4 lines

As the ring_add_request can it self cause seqno wrap due to intel_ring_begin, and the fact that it will update the *other* rings mboxes, we need to wait until all the rings have proceed with clearing the mboxes.

What? What ring_add_request? The entire GPU is idle at this point.

Quoted 7 lines
Quoted 2 lines

How about if we assert that the ring is idle, and just blitz the registers and hws rather than go through the ring?

I have tried this but failed. I think the problem is ring_add_request. It will still inject seqnos before the wrap boundary if intel_ring_begin in itself just wrapped. This is why we need to clear mboxes and set the hws page through rings.

There are no outstanding requests at this point. The purpose of the loop over all the rings calling idle in i915_gem_seqno_handle_wrap() is to make sure that not only is the GPU entirely idle, but all ring->olr are reset to 0 before we then reset the hw state on each ring.

Quoted 6 lines

I have a patch which allocates seqnos explicitly early in i915_gem_do_execbuffer, gets rid of outstanding_lazy_request and related i915_gem_check_olr completely thus making the wrap handling much more simpler as we don't need to be careful in ring_sync nor ring_add_request as no cross wrap boundary stuff can no longer happen. But I got the impression that you don't like this approach.

No. Because requests need to be associated with anything that touches the ring, which may themselves not be associated with an execbuffer. The desire is to use the rings for more pipelining of state changes, not less. The request is our most basic bookkeeping element of the ring, they track how much of the ring we have used and provide for a unified wait mechanism.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#10 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

Quoted 35 lines · Chris Wilson
Quoted 34 lines · Mika Kuoppala
Quoted 31 lines · Chris Wilson
Quoted 8 lines · Mika Kuoppala

Hardware status page needs to have proper seqno set
as our initial seqno can be arbitrary. If initial seqno is close to wrap boundary on init and i915_seqno_passed() (31bit space) refers to hw status page which contains zero, errorneous result will be returned.

References: https://bugs.freedesktop.org/show_bug.cgi?id=58230

Looks good baring the last chunk.

Quoted 5 lines
(quoted diff) +1 -0
@@ -1435,8 +1439,18 @@ int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring)
 	 * post-wrap semaphore waits completing immediately. Clear them. */
 	update_mboxes(ring, ring->signal_mbox[0]);
 	update_mboxes(ring, ring->signal_mbox[1]);
+	intel_ring_emit(ring, MI_STORE_DWORD_INDEX);

Review int intel_ring_handle_seqno_wrap(struct intel_ring_buffer *ring) · line 1452

Quoted 10 lines
(quoted diff) +8 -0
+	intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
+	intel_ring_emit(ring, seqno);
+	intel_ring_emit(ring, MI_USER_INTERRUPT);
 	intel_ring_advance(ring);
 
+	/* Wait until mboxes have actually cleared before pushing
+	 * anything to the rings */
+	ret = ring_wait_for_space(ring, ring->size - 8);
+	if (ret)
+		return ret;

I don't this is well justified. Can you clearly explain the situation where it is required?

Quoted 6 lines
Quoted 4 lines

As the ring_add_request can it self cause seqno wrap due to intel_ring_begin, and the fact that it will update the *other* rings mboxes, we need to wait until all the rings have proceed with clearing the mboxes.

What? What ring_add_request? The entire GPU is idle at this point.

Yes, my explanation is bogus as intel_ring_begin can't wrap in gen6_add_request. The olr is already set before going in there.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

How about if we assert that the ring is idle, and just blitz the registers and hws rather than go through the ring?

I have tried this but failed. I think the problem is ring_add_request. It will still inject seqnos before the wrap boundary if intel_ring_begin in itself just wrapped. This is why we need to clear mboxes and set the hws page through rings.

Quoted 4 lines

There are no outstanding requests at this point. The purpose of the loop over all the rings calling idle in i915_gem_seqno_handle_wrap() is to make sure that not only is the GPU entirely idle, but all ring->olr are reset to 0 before we then reset the hw state on each ring.

My initial attempt write mboxes and hws directly had an error in it. I wrote seqno to mboxes also. Correct approach is to set mboxes to zero and set hws page value to seqno. I will retry this approach to see if the syncs will fail.

Quoted 7 lines
Quoted 6 lines

I have a patch which allocates seqnos explicitly early in i915_gem_do_execbuffer, gets rid of outstanding_lazy_request and related i915_gem_check_olr completely thus making the wrap handling much more simpler as we don't need to be careful in ring_sync nor ring_add_request as no cross wrap boundary stuff can no longer happen. But I got the impression that you don't like this approach.

Quoted 6 lines

No. Because requests need to be associated with anything that touches the ring, which may themselves not be associated with an execbuffer. The desire is to use the rings for more pipelining of state changes, not less. The request is our most basic bookkeeping element of the ring, they track how much of the ring we have used and provide for a unified wait mechanism.

Thanks for explaining the reasoning.

Quoted 4 lines

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#11 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

In reply to Mika Kuoppala
Quoted 2 lines · Mika Kuoppala

As this debugs entry can be used to set arbitrary value to next_seqno, use i915_gem_seqno_init to set the next_seqno.

I see where you are going, but I don't like the direction you took. :)

Can you try respinning and export a less fragile function from i915_gem.c to do the dirty deed?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#12 lore raw

Re: [PATCH 4/4] drm/i915: Make next_seqno debugs entry to use i915_gem_seqno_init

Quoted 8 lines · Chris Wilson
Quoted 2 lines · Mika Kuoppala

As this debugs entry can be used to set arbitrary value to next_seqno, use i915_gem_seqno_init to set the next_seqno.

I see where you are going, but I don't like the direction you took. :)

Can you try respinning and export a less fragile function from i915_gem.c to do the dirty deed?

Will do.

-Mika