Skip to contentSkip to conversation

reduced LLC caching series

PATCH In review Eric Anholt 3 participants 14 messages Mar 29, 2011 – Mar 31, 2011

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

Chris posted a big patch series incorporating the cleaned up LLC caching changes, but there were a bunch of not-ready-yet patches in there. This is a reduced series that I think is ready, with some fixes from me. From the final commit:

    Improves full-screen openarena on my laptop 20.3% +/- 4.0% (n=3)
    Improves 800x600 nexuiz on my laptop 12.3% +/- 0.1% (n=3)

Full screen, highest settings OA is now just about at refresh rate on it.

#1 lore raw

PATCH 1/6 drm/i915: Rename agp_type to cache_level

From: Chris Wilson <[email protected]>

... to clarify just how we use it inside the driver. We still need to translate through agp_type for interface into the fake AGP driver.

---
 drivers/gpu/drm/i915/i915_debugfs.c     |   11 ++++++-----
 drivers/gpu/drm/i915/i915_drv.h         |   12 +++++++++---
 drivers/gpu/drm/i915/i915_gem.c         |    2 +-
 drivers/gpu/drm/i915/i915_gem_gtt.c     |   22 ++++++++++++++++------
 drivers/gpu/drm/i915/i915_irq.c         |    2 +-
 drivers/gpu/drm/i915/intel_ringbuffer.c |    4 ++--
 6 files changed, 35 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +6 -5
index 87c8e29..993e379 100644
@@ -106,11 +106,12 @@ static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
     }
 }
 
-static const char *agp_type_str(int type)
+static const char *cache_level_str(int type)
 {
 	switch (type) {
-	case 0: return " uncached";
-	case 1: return " snooped";
+	case I915_CACHE_NONE: return " uncached";
+	case I915_CACHE_LLC: return " snooped (LLC)";
+	case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
 	default: return "";
 	}
 }
@@ -127,7 +128,7 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
 		   obj->base.write_domain,
 		   obj->last_rendering_seqno,
 		   obj->last_fenced_seqno,
-		   agp_type_str(obj->agp_type == AGP_USER_CACHED_MEMORY),
+		   cache_level_str(obj->cache_level),
 		   obj->dirty ? " dirty" : "",
 		   obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
 	if (obj->base.name)
@@ -714,7 +715,7 @@ static void print_error_buffers(struct seq_file *m,
 			   dirty_flag(err->dirty),
 			   purgeable_flag(err->purgeable),
 			   ring_str(err->ring),
-			   agp_type_str(err->agp_type));
+			   cache_level_str(err->cache_level));
 
 		if (err->name)
 			seq_printf(m, " (name: %d)", err->name);
drivers/gpu/drm/i915/i915_drv.h +9 -3
index 5004724..6d98e0e 100644
@@ -188,7 +188,7 @@ struct drm_i915_error_state {
 		u32 dirty:1;
 		u32 purgeable:1;
 		u32 ring:4;
-		u32 agp_type:1;
+		u32 cache_level:2;
 	} *active_bo, *pinned_bo;
 	u32 active_bo_count, pinned_bo_count;
 	struct intel_overlay_error_state *overlay;
@@ -705,6 +705,12 @@ typedef struct drm_i915_private {
 	struct drm_property *broadcast_rgb_property;
 } drm_i915_private_t;
 
+enum i915_cache_level {
+	I915_CACHE_NONE,
+	I915_CACHE_LLC,
+	I915_CACHE_LLC_MLC, /* gen6+ */
+};
+
 struct drm_i915_gem_object {
 	struct drm_gem_object base;
 
@@ -791,6 +797,8 @@ struct drm_i915_gem_object {
 	unsigned int pending_fenced_gpu_access:1;
 	unsigned int fenced_gpu_access:1;
 
+	unsigned int cache_level:2;
+
 	struct page **pages;
 
 	/**
@@ -827,8 +835,6 @@ struct drm_i915_gem_object {
 	/** Record of address bit 17 of each page at last unbind. */
 	unsigned long *bit_17;
 
-	/** AGP mapping type (AGP_USER_MEMORY or AGP_USER_CACHED_MEMORY */
-	uint32_t agp_type;
 
 	/**
 	 * If present, while GEM_DOMAIN_CPU is in the read domain this array
drivers/gpu/drm/i915/i915_gem.c +1 -1
index 7ce3f35..264bec8 100644
@@ -3569,7 +3569,7 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
 	obj->base.write_domain = I915_GEM_DOMAIN_CPU;
 	obj->base.read_domains = I915_GEM_DOMAIN_CPU;
 
-	obj->agp_type = AGP_USER_MEMORY;
+	obj->cache_level = I915_CACHE_NONE;
 	obj->base.driver_private = NULL;
 	obj->fence_reg = I915_FENCE_REG_NONE;
 	INIT_LIST_HEAD(&obj->mm_list);
drivers/gpu/drm/i915/i915_gem_gtt.c +16 -6
index b0abdc6..af3c0e6 100644
@@ -29,6 +29,17 @@
 #include "i915_trace.h"
 #include "intel_drv.h"
 
+/* XXX kill agp_type! */
+static uint32_t cache_level_to_agp_type(enum i915_cache_level cache_level)
+{
+	switch (cache_level) {
+	default:
+	case I915_CACHE_NONE: return AGP_USER_MEMORY;
+	case I915_CACHE_LLC: return AGP_USER_CACHED_MEMORY;
+	case I915_CACHE_LLC_MLC: return AGP_USER_CACHED_MEMORY_LLC_MLC;
+	}
+}
+
 void i915_gem_restore_gtt_mappings(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -46,15 +57,14 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
 
 			intel_gtt_insert_sg_entries(obj->sg_list,
 						    obj->num_sg,
-						    obj->gtt_space->start
-							>> PAGE_SHIFT,
-						    obj->agp_type);
+						    obj->gtt_space->start >> PAGE_SHIFT,
+						    cache_level_to_agp_type(obj->cache_level));
 		} else
 			intel_gtt_insert_pages(obj->gtt_space->start
 						   >> PAGE_SHIFT,
 					       obj->base.size >> PAGE_SHIFT,
 					       obj->pages,
-					       obj->agp_type);
+					       cache_level_to_agp_type(obj->cache_level));
 	}
 
 	intel_gtt_chipset_flush();
@@ -77,12 +87,12 @@ int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)
 		intel_gtt_insert_sg_entries(obj->sg_list,
 					    obj->num_sg,
 					    obj->gtt_space->start >> PAGE_SHIFT,
-					    obj->agp_type);
+					    cache_level_to_agp_type(obj->cache_level));
 	} else
 		intel_gtt_insert_pages(obj->gtt_space->start >> PAGE_SHIFT,
 				       obj->base.size >> PAGE_SHIFT,
 				       obj->pages,
-				       obj->agp_type);
+				       cache_level_to_agp_type(obj->cache_level));
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_irq.c +1 -1
index 188b497..5c0466e 100644
@@ -676,7 +676,7 @@ static u32 capture_bo_list(struct drm_i915_error_buffer *err,
 		err->dirty = obj->dirty;
 		err->purgeable = obj->madv != I915_MADV_WILLNEED;
 		err->ring = obj->ring ? obj->ring->id : 0;
-		err->agp_type = obj->agp_type == AGP_USER_CACHED_MEMORY;
+		err->cache_level = obj->cache_level;
 
 		if (++i == count)
 			break;
drivers/gpu/drm/i915/intel_ringbuffer.c +2 -2
index e9e6f71..bb18dfb 100644
@@ -236,7 +236,7 @@ init_pipe_control(struct intel_ring_buffer *ring)
 		ret = -ENOMEM;
 		goto err;
 	}
-	obj->agp_type = AGP_USER_CACHED_MEMORY;
+	obj->cache_level = I915_CACHE_LLC;
 
 	ret = i915_gem_object_pin(obj, 4096, true);
 	if (ret)
@@ -759,7 +759,7 @@ static int init_status_page(struct intel_ring_buffer *ring)
 		ret = -ENOMEM;
 		goto err;
 	}
-	obj->agp_type = AGP_USER_CACHED_MEMORY;
+	obj->cache_level = I915_CACHE_LLC;
 
 	ret = i915_gem_object_pin(obj, 4096, true);
 	if (ret != 0) {
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/6 drm/i915: Mark the cursor and the overlay as being part of the display planes

In reply to Eric Anholt

From: Chris Wilson <[email protected]>

---
 drivers/gpu/drm/i915/intel_display.c |    2 +-
 drivers/gpu/drm/i915/intel_overlay.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +1 -1
index 432fc04..8fdeae6 100644
@@ -5355,7 +5355,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
 			goto fail_locked;
 		}
 
-		ret = i915_gem_object_set_to_gtt_domain(obj, 0);
+		ret = i915_gem_object_set_to_display_plane(obj, NULL);
 		if (ret) {
 			DRM_ERROR("failed to move cursor bo into the GTT\n");
 			goto fail_unpin;
drivers/gpu/drm/i915/intel_overlay.c +1 -1
index a670c00..e0903c5 100644
@@ -777,7 +777,7 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
 	if (ret != 0)
 		return ret;
 
-	ret = i915_gem_object_set_to_gtt_domain(new_bo, 0);
+	ret = i915_gem_object_set_to_display_plane(new_bo, NULL);
 	if (ret != 0)
 		goto out_unpin;
 
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/6 drm/i915: Do not clflush snooped objects

In reply to Eric Anholt

From: Chris Wilson <[email protected]>

Rely on the GPU snooping into the CPU cache for appropriately bound objects on MI_FLUSH. Or perhaps one day we will have a cache-coherent CPU/GPU package...

---
 drivers/gpu/drm/i915/i915_gem.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +8 -0
index 264bec8..fa483d8 100644
@@ -2878,6 +2878,14 @@ i915_gem_clflush_object(struct drm_i915_gem_object *obj)
 	if (obj->pages == NULL)
 		return;
 
+	/* If the GPU is snooping the contents of the CPU cache,
+	 * we do not need to clear the CPU cache lines. Instead we need
+	 * to be sure to flush/invalidate the RENDER cache when the contents
+	 * must be refreshed.
+	 */
+	if (obj->cache_level != I915_CACHE_NONE)
+		return;
+
 	trace_i915_gem_object_clflush(obj);
 
 	drm_clflush_pages(obj->pages, obj->base.size / PAGE_SIZE);
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH 4/6 drm/i915: Add an interface to dynamically change the cache level

In reply to Eric Anholt

From: Chris Wilson <[email protected]>

[v2: Don't forget that when going from cached to uncached, we haven't been tracking the write domain from the CPU perspective, since we haven't needed it for GPU coherency.]

---
 drivers/gpu/drm/i915/i915_drv.h         |    6 ++++-
 drivers/gpu/drm/i915/i915_gem.c         |   35 ++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_gtt.c     |    8 ++++--
 drivers/gpu/drm/i915/intel_ringbuffer.c |    6 +++-
 4 files changed, 48 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +5 -1
index 6d98e0e..e38765d 100644
@@ -1190,9 +1190,13 @@ void i915_gem_release(struct drm_device *dev, struct drm_file *file);
 uint32_t
 i915_gem_get_unfenced_gtt_alignment(struct drm_i915_gem_object *obj);
 
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level);
+
 /* i915_gem_gtt.c */
 void i915_gem_restore_gtt_mappings(struct drm_device *dev);
-int __must_check i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj);
+int __must_check i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
+					  enum i915_cache_level cache_level);
 void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj);
 
 /* i915_gem_evict.c */
drivers/gpu/drm/i915/i915_gem.c +34 -1
index fa483d8..8389b03 100644
@@ -2831,7 +2831,7 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
 		return ret;
 	}
 
-	ret = i915_gem_gtt_bind_object(obj);
+	ret = i915_gem_gtt_bind_object(obj, obj->cache_level);
 	if (ret) {
 		i915_gem_object_put_pages_gtt(obj);
 		drm_mm_put_block(obj->gtt_space);
@@ -3002,6 +3002,39 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 	return 0;
 }
 
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level)
+{
+	int ret;
+
+	if (obj->cache_level == cache_level)
+		return 0;
+
+	if (obj->gtt_space) {
+		ret = i915_gem_object_flush_gpu(obj);
+		if (ret)
+			return ret;
+
+		ret = i915_gem_gtt_bind_object(obj, cache_level);
+		if (ret)
+			return ret;
+	}
+
+	if (cache_level == I915_CACHE_NONE) {
+		/* If we're coming frm LLC cached, then we haven't
+		 * actually been tracking whether the data is in the
+		 * CPU cache or not, since we only allow one bit set
+		 * in obj->write_domain.  Just set it to the CPU cache
+		 * for now.
+		 */
+		BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
+		obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	}
+
+	obj->cache_level = cache_level;
+	return 0;
+}
+
 /*
  * Prepare buffer for display plane. Use uninterruptible for possible flush
  * wait, as in modesetting process we're not supposed to be interrupted.
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -3
index af3c0e6..47d8bad 100644
@@ -70,10 +70,12 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
 	intel_gtt_chipset_flush();
 }
 
-int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)
+int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
+			     enum i915_cache_level cache_level)
 {
 	struct drm_device *dev = obj->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	uint32_t agp_type = cache_level_to_agp_type(cache_level);
 	int ret;
 
 	if (dev_priv->mm.gtt->needs_dmar) {
@@ -87,12 +89,12 @@ int i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj)
 		intel_gtt_insert_sg_entries(obj->sg_list,
 					    obj->num_sg,
 					    obj->gtt_space->start >> PAGE_SHIFT,
-					    cache_level_to_agp_type(obj->cache_level));
+					    agp_type);
 	} else
 		intel_gtt_insert_pages(obj->gtt_space->start >> PAGE_SHIFT,
 				       obj->base.size >> PAGE_SHIFT,
 				       obj->pages,
-				       cache_level_to_agp_type(obj->cache_level));
+				       agp_type);
 
 	return 0;
 }
drivers/gpu/drm/i915/intel_ringbuffer.c +4 -2
index bb18dfb..6d25e79 100644
@@ -236,7 +236,8 @@ init_pipe_control(struct intel_ring_buffer *ring)
 		ret = -ENOMEM;
 		goto err;
 	}
-	obj->cache_level = I915_CACHE_LLC;
+
+	i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
 
 	ret = i915_gem_object_pin(obj, 4096, true);
 	if (ret)
@@ -759,7 +760,8 @@ static int init_status_page(struct intel_ring_buffer *ring)
 		ret = -ENOMEM;
 		goto err;
 	}
-	obj->cache_level = I915_CACHE_LLC;
+
+	i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
 
 	ret = i915_gem_object_pin(obj, 4096, true);
 	if (ret != 0) {
Signature · 1 line
1.7.4.1
#5 lore raw

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

The series looks really good, only one quibble below.

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 3032

Quoted 12 lines · Eric Anholt
drivers/gpu/drm/i915/i915_gem.c +12 -0
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level)
+	if (cache_level == I915_CACHE_NONE) {
+		/* If we're coming frm LLC cached, then we haven't
+		 * actually been tracking whether the data is in the
+		 * CPU cache or not, since we only allow one bit set
+		 * in obj->write_domain.  Just set it to the CPU cache
+		 * for now.
+		 */
+		BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
+		obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	}

[We can rearrange the code to convert the BUG_ON into a
if (WARN_ON()) return -EBUSY;.]

I think this is overkill, at least by my interpretation of the old BLT docs which imply that cache line invalidation (both CPU and GPU) is done for snooped PTEs on MI_FLUSH.

LLC -> UC transitions will be rare, only for new buffers (and on the first page flip) after a modeset, but it's the principle! ;-)

Until we expose cache control through an ioctl we will never be able to experiment...
-Chris

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

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

Quoted 19 lines · Chris Wilson

The series looks really good, only one quibble below.

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 3032

Quoted 12 lines · Eric Anholt
drivers/gpu/drm/i915/i915_gem.c +12 -0
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level)
+	if (cache_level == I915_CACHE_NONE) {
+		/* If we're coming frm LLC cached, then we haven't
+		 * actually been tracking whether the data is in the
+		 * CPU cache or not, since we only allow one bit set
+		 * in obj->write_domain.  Just set it to the CPU cache
+		 * for now.
+		 */
+		BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
+		obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	}

[We can rearrange the code to convert the BUG_ON into a
if (WARN_ON()) return -EBUSY;.]

Quoted 3 lines

I think this is overkill, at least by my interpretation of the old BLT docs which imply that cache line invalidation (both CPU and GPU) is done for snooped PTEs on MI_FLUSH.

And what about a CPU write through the GTT? Or the CPU writes to the pages before we turned them into a BO and cleared their CPU write domain flag without actually clflushing them?

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

#7 lore raw

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

Quoted 20 lines · Eric Anholt
Quoted 19 lines · Chris Wilson

The series looks really good, only one quibble below.

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 3032

Quoted 12 lines · Eric Anholt
drivers/gpu/drm/i915/i915_gem.c +12 -0
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level)
+	if (cache_level == I915_CACHE_NONE) {
+		/* If we're coming frm LLC cached, then we haven't
+		 * actually been tracking whether the data is in the
+		 * CPU cache or not, since we only allow one bit set
+		 * in obj->write_domain.  Just set it to the CPU cache
+		 * for now.
+		 */
+		BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
+		obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	}

[We can rearrange the code to convert the BUG_ON into a
if (WARN_ON()) return -EBUSY;.]

Quoted 5 lines
Quoted 3 lines

I think this is overkill, at least by my interpretation of the old BLT docs which imply that cache line invalidation (both CPU and GPU) is done for snooped PTEs on MI_FLUSH.

And what about a CPU write through the GTT?

Even on SNB these are still UC. And we should try hard not to, as the specs give dire warnings about writing to snooped PTEs through the GTT. (Since we will bypass the caches with the write, aiui, and cause confusion.)

Quoted 3 lines

Or the CPU writes to the
pages before we turned them into a BO and cleared their CPU write domain flag without actually clflushing them?

That's a valid argument. Just frustrated by the necessity. -Chris

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

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

Quoted 25 lines · Chris Wilson
Quoted 24 lines · Eric Anholt
Quoted 22 lines · Chris Wilson

The series looks really good, only one quibble below.

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 3032

Quoted 12 lines · Eric Anholt
drivers/gpu/drm/i915/i915_gem.c +12 -0
+int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
+				    enum i915_cache_level cache_level)
+	if (cache_level == I915_CACHE_NONE) {
+		/* If we're coming frm LLC cached, then we haven't
+		 * actually been tracking whether the data is in the
+		 * CPU cache or not, since we only allow one bit set
+		 * in obj->write_domain.  Just set it to the CPU cache
+		 * for now.
+		 */
+		BUG_ON(obj->base.write_domain & I915_GEM_GPU_DOMAINS);
+		obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	}

[We can rearrange the code to convert the BUG_ON into a
if (WARN_ON()) return -EBUSY;.]

I think this is overkill, at least by my interpretation of the old BLT docs which imply that cache line invalidation (both CPU and GPU) is done for snooped PTEs on MI_FLUSH.

Quoted 6 lines
Quoted 1 line

And what about a CPU write through the GTT?

Even on SNB these are still UC. And we should try hard not to, as the specs give dire warnings about writing to snooped PTEs through the GTT. (Since we will bypass the caches with the write, aiui, and cause confusion.)

Oh, wow. That's really bad. Reject this series if so.

If true, then we need to be accurately tracking the CPU write domain. Mapping for GTT would need to actually clflush, and we'd need to clflush to read GTT-written data.

On the other hand, I'm surprised things survived the testing I've done if that's true, given that we're surely GTT pwriting the batchbuffer data in, and then reading them through LLC. I would expect to pull in a bunch of zeroes in place of actual commands. Were you perhaps referring to pre-gen6 chipsets?

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

#9 lore raw

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

Quoted 10 lines · Eric Anholt
Quoted 7 lines · Chris Wilson
Quoted 1 line · Eric Anholt

And what about a CPU write through the GTT?

Even on SNB these are still UC. And we should try hard not to, as the specs give dire warnings about writing to snooped PTEs through the GTT. (Since we will bypass the caches with the write, aiui, and cause confusion.)

Oh, wow. That's really bad. Reject this series if so.

I plucked that tidbit out of the specs for the BLT engine, which has not been rigorously updated since gen2... Though don't we also encounter a few subtleties with movnta (__copy_from_user_nocache_nozero from pwrite) and data in cachelines?

But it is something that I worry about given my desire to start mapping user pages and using the BLT engine for C to UC transfers. -Chris

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

Re: [PATCH 4/6] drm/i915: Add an interface to dynamically change the cache level

Quoted 10 lines · Chris Wilson
Quoted 9 lines · Eric Anholt
Quoted 7 lines · Chris Wilson
Quoted 1 line · Eric Anholt

And what about a CPU write through the GTT?

Even on SNB these are still UC. And we should try hard not to, as the specs give dire warnings about writing to snooped PTEs through the GTT. (Since we will bypass the caches with the write, aiui, and cause confusion.)

Quoted 6 lines
Quoted 1 line

Oh, wow. That's really bad. Reject this series if so.

I plucked that tidbit out of the specs for the BLT engine, which has not been rigorously updated since gen2... Though don't we also encounter a few subtleties with movnta (__copy_from_user_nocache_nozero from pwrite) and data in cachelines?

The only tricky correctness bit for those was how to flush the little tiny movnt cache when you're done, which is "mfence". As far as other interesting notes about movnt, it doesn't mean that the destination is not in cache after the instruction -- if it was already in cache, it will likely be in cache afterwards. I don't think that has any impact on how we do our code.

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

#11 lore raw

PATCH 5/6 drm/i915: Use the uncached domain for the display planes v2

In reply to Eric Anholt

The simplest and common method for ensuring scanout coherency on all chipsets is to mark the scanout buffers as uncached (and for userspace to remember to flush the render cache every so often).

We can improve upon this for later generations by marking scanout objects as GFDT and only flush those cachelines when required. However, we start simple.

[v2: Move the set to uncached above the clflush. Otherwise, we'd skip the clflush and try to scan out data that was still sitting in the cache.]

---
 drivers/gpu/drm/i915/i915_gem.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +13 -0
index 8389b03..de9a446 100644
@@ -3062,6 +3062,19 @@ i915_gem_object_set_to_display_plane(struct drm_i915_gem_object *obj,
 			return ret;
 	}
 
+	/* The display engine is not coherent with the LLC cache on gen6.  As
+	 * a result, we make sure that the pinning that is about to occur is
+	 * done with uncached PTEs. This is lowest common denominator for all
+	 * chipsets.
+	 *
+	 * However for gen6+, we could do better by using the GFDT bit instead
+	 * of uncaching, which would allow us to flush all the LLC-cached data
+	 * with that bit in the PTE to main memory with just one PIPE_CONTROL.
+	 */
+	ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+	if (ret)
+		return ret;
+
 	i915_gem_object_flush_cpu_write_domain(obj);
 
 	old_read_domains = obj->base.read_domains;
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH 6/6 drm/i915: Use the LLC mode on gen6 for everything but display.

In reply to Eric Anholt

Improves full-screen openarena on my laptop 20.3% +/- 4.0% (n=3) Improves 800x600 nexuiz on my laptop 12.3% +/- 0.1% (n=3)

We have more room to improve with doing LLC caching for display using GFDT, and in doing LLC+MLC caching, but this was an easy performance win and incremental improvement toward those two.

---
 drivers/gpu/drm/i915/i915_gem.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +17 -1
index de9a446..87d4e17 100644
@@ -3623,7 +3623,23 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
 	obj->base.write_domain = I915_GEM_DOMAIN_CPU;
 	obj->base.read_domains = I915_GEM_DOMAIN_CPU;
 
-	obj->cache_level = I915_CACHE_NONE;
+	if (IS_GEN6(dev)) {
+		/* On Gen6, we can have the GPU use the LLC (the CPU
+		 * cache) for about a 10% performance improvement
+		 * compared to uncached.  Graphics requests other than
+		 * display scanout are coherent with the CPU in
+		 * accessing this cache.  This means in this mode we
+		 * don't need to clflush on the CPU side, and on the
+		 * GPU side we only need to flush internal caches to
+		 * get data visible to the CPU.
+		 *
+		 * However, we maintain the display planes as UC, and so
+		 * need to rebind when first used as such.
+		 */
+		obj->cache_level = I915_CACHE_LLC;
+	} else
+		obj->cache_level = I915_CACHE_NONE;
+
 	obj->base.driver_private = NULL;
 	obj->fence_reg = I915_FENCE_REG_NONE;
 	INIT_LIST_HEAD(&obj->mm_list);
Signature · 1 line
1.7.4.1