[PATCH 31/31] ringbuffer

Chris Wilson chris at chris-wilson.co.uk
Sun Apr 23 12:05:33 UTC 2017


---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 16 ++++++----------
 drivers/gpu/drm/i915/intel_ringbuffer.h | 23 ++++++++++++-----------
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index ad0648cb0f80..e65d78e7b6e4 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -39,12 +39,11 @@
  */
 #define LEGACY_REQUEST_SIZE 200
 
-static int __intel_ring_space(int head, int tail, int size)
+static int __intel_ring_space(unsigned int head,
+			      unsigned int tail,
+			      unsigned int size)
 {
-	int space = head - tail;
-	if (space <= 0)
-		space += size;
-	return space - I915_RING_FREE_SPACE;
+	return (round_down(head, CACHELINE_BYTES) - tail - 8) & (size - 1);
 }
 
 void intel_ring_update_space(struct intel_ring *ring)
@@ -1617,12 +1616,9 @@ static int wait_for_space(struct drm_i915_gem_request *req, int bytes)
 	GEM_BUG_ON(!req->reserved_space);
 
 	list_for_each_entry(target, &ring->request_list, ring_link) {
-		unsigned space;
-
 		/* Would completion of this request free enough space? */
-		space = __intel_ring_space(target->postfix, ring->emit,
-					   ring->size);
-		if (space >= bytes)
+		if (bytes <= __intel_ring_space(target->postfix,
+						ring->emit, ring->size))
 			break;
 	}
 
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 11b936f9d5f4..c1be2ab889ab 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -17,17 +17,6 @@
 #define CACHELINE_BYTES 64
 #define CACHELINE_DWORDS (CACHELINE_BYTES / sizeof(uint32_t))
 
-/*
- * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
- * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
- * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
- *
- * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
- * cacheline, the Head Pointer must not be greater than the Tail
- * Pointer."
- */
-#define I915_RING_FREE_SPACE 64
-
 struct intel_hw_status_page {
 	struct i915_vma *vma;
 	u32 *page_addr;
@@ -556,6 +545,18 @@ assert_ring_tail_valid(const struct intel_ring *ring, unsigned int tail)
 	 */
 	GEM_BUG_ON(!IS_ALIGNED(tail, 8));
 	GEM_BUG_ON(tail >= ring->size);
+
+	/*
+	 * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
+	 * Gen3 BSpec "1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
+	 * Gen4+ BSpec "1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
+	 *
+	 * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
+	 * cacheline, the Head Pointer must not be greater than the Tail
+	 * Pointer."
+	 */
+	GEM_BUG_ON(round_down(tail, CACHELINE_BYTES) == round_down(ring->head, CACHELINE_BYTES) &&
+		   tail > ring->head);
 }
 
 static inline unsigned int
-- 
2.11.0



More information about the Intel-gfx-trybot mailing list