[PATCH 28/72] drm/i915: Avoid memset() into the ringbuffer

Chris Wilson chris at chris-wilson.co.uk
Tue Feb 6 20:57:28 UTC 2018


As the ringbuffer may exist inside stolen memory, our access to it may
be via the GTT iomap. This implies we may only have WC access for which
the conventional memset() subsitution of rep stos performs very badly,
so open-code it with a qword write.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index e2085820b586..89d5a4fa2ee4 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1700,14 +1700,20 @@ u32 *intel_ring_begin(struct drm_i915_gem_request *req,
 	}
 
 	if (unlikely(need_wrap)) {
+		u64 *tail = ring->vaddr + ring->emit;
+
 		need_wrap &= ~1;
 		GEM_BUG_ON(need_wrap > ring->space);
 		GEM_BUG_ON(ring->emit + need_wrap > ring->size);
+		GEM_BUG_ON(!IS_ALIGNED(need_wrap, sizeof(*tail)));
 
-		/* Fill the tail with MI_NOOP */
-		memset(ring->vaddr + ring->emit, 0, need_wrap);
-		ring->emit = 0;
+		/* Fill the tail with MI_NOOP, avoiding memset into our iomap */
 		ring->space -= need_wrap;
+		while (need_wrap) {
+			*tail++ = MI_NOOP;
+			need_wrap -= sizeof(*tail);
+		}
+		ring->emit = 0;
 	}
 
 	GEM_BUG_ON(ring->emit > ring->size - bytes);
-- 
2.16.1



More information about the Intel-gfx-trybot mailing list