Skip to contentSkip to conversation

drm/i915: Try to avoid most cache flushes on LLC platforms (WIP)

RFC PATCH In review [email protected] 2 participants 2 messages Aug 5, 2013

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

RFC PATCH 1/1 drm/i915: Try to avoid most cache flushes on LLC platforms (WIP)

From: Ville Syrjälä <[email protected]>

A bit more food for the cache discussions. My idea here is to track whether an object is part of any fb, and in case it is we assume it can be used for scanout, and thus may need some extra clflushes. But otherwise we'd try to avoid clflushes on LLC plarforms.

I also included some GFDT stuff in there just to think a bit about how it would work, but I left out the GFDT flushes themselves.

Also I didn't even boot-test this, so it may explode quite spectacularly.

---
 drivers/gpu/drm/i915/i915_drv.h            |  5 +++
 drivers/gpu/drm/i915/i915_gem.c            | 63 +++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 13 +++++-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  6 ++-
 drivers/gpu/drm/i915/intel_display.c       |  2 +
 drivers/gpu/drm/i915/intel_fb.c            |  1 +
 6 files changed, 72 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +5 -0
index 8b14e22..ec275ed 100644
@@ -451,6 +451,8 @@ enum i915_cache_level {
 	I915_CACHE_NONE = 0,
 	I915_CACHE_LLC,
 	I915_CACHE_LLC_MLC, /* gen6+, in docs at least! */
+	I915_CACHE_WT, /* hsw gt3e */
+	I915_CACHE_GFDT = 0x4, /* SNB/IVB: flag ORed w/ the cache mode */
 };
 
 typedef uint32_t gen6_gtt_pte_t;
@@ -1388,6 +1390,8 @@ struct drm_i915_gem_object {
 
 	/** for phy allocated objects */
 	struct drm_i915_gem_phys_object *phys_obj;
+
+	atomic_t fb_count;
 };
 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
 
@@ -1494,6 +1498,7 @@ struct drm_i915_file_private {
 #define HAS_VEBOX(dev)          (INTEL_INFO(dev)->has_vebox_ring)
 #define HAS_LLC(dev)            (INTEL_INFO(dev)->has_llc)
 #define I915_NEED_GFX_HWS(dev)	(INTEL_INFO(dev)->need_gfx_hws)
+#define HAS_GFDT(dev)		(0)
 
 #define HAS_HW_CONTEXTS(dev)	(INTEL_INFO(dev)->gen >= 6)
 #define HAS_ALIASING_PPGTT(dev)	(INTEL_INFO(dev)->gen >=6 && !IS_VALLEYVIEW(dev))
drivers/gpu/drm/i915/i915_gem.c +48 -15

141 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_execbuffer.c +11 -2
index 9939d2e..ceead5e 100644
@@ -702,12 +702,18 @@ err:
 	return ret;
 }
 
+static bool cpu_caches_coherent(struct drm_i915_gem_object *obj)
+{
+	return HAS_LLC(obj->base.dev) || obj->cache_level != I915_CACHE_NONE;
+}
+
 static int
 i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
 				struct list_head *objects)
 {
 	struct drm_i915_gem_object *obj;
 	uint32_t flush_domains = 0;
+	bool need_chipset_flush = false;
 	int ret;
 
 	list_for_each_entry(obj, objects, exec_list) {
@@ -715,13 +721,16 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
 		if (ret)
 			return ret;
 
-		if (obj->base.write_domain & I915_GEM_DOMAIN_CPU)
+		if (obj->base.write_domain & I915_GEM_DOMAIN_CPU &&
+		    !cpu_caches_coherent(obj)) {
 			i915_gem_clflush_object(obj);
+			need_chipset_flush = true;
+		}
 
 		flush_domains |= obj->base.write_domain;
 	}
 
-	if (flush_domains & I915_GEM_DOMAIN_CPU)
+	if (need_chipset_flush)
 		i915_gem_chipset_flush(ring->dev);
 
 	if (flush_domains & I915_GEM_DOMAIN_GTT)
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -1
index f38cc69..ea1ef86 100644
@@ -44,6 +44,7 @@
 #define HSW_PTE_UNCACHED		(0)
 #define GEN6_PTE_CACHE_LLC		(2 << 1)
 #define GEN6_PTE_CACHE_LLC_MLC		(3 << 1)
+#define GEN6_PTE_GFDT			(1 << 3)
 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
 #define HSW_PTE_ADDR_ENCODE(addr)	HSW_GTT_ADDR_ENCODE(addr)
 
@@ -62,7 +63,10 @@ static gen6_gtt_pte_t gen6_pte_encode(dma_addr_t addr,
 	gen6_gtt_pte_t pte = GEN6_PTE_VALID;
 	pte |= GEN6_PTE_ADDR_ENCODE(addr);
 
-	switch (level) {
+	if (level & I915_CACHE_GFDT)
+		pte |= GEN6_PTE_GFDT;
+
+	switch (level & ~I915_CACHE_GFDT) {
 	case I915_CACHE_LLC_MLC:
 		pte |= GEN6_PTE_CACHE_LLC_MLC;
 		break;
drivers/gpu/drm/i915/intel_display.c +2 -0
index 8afdcfe..c4c7c52 100644
@@ -9409,6 +9409,7 @@ static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
 	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
 
 	drm_framebuffer_cleanup(fb);
+	atomic_dec(&intel_fb->obj->fb_count);
 	drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
 
 	kfree(intel_fb);
@@ -9527,6 +9528,7 @@ int intel_framebuffer_init(struct drm_device *dev,
 
 	drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
 	intel_fb->obj = obj;
+	atomic_inc(&obj->fb_count);
 
 	ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
 	if (ret) {
drivers/gpu/drm/i915/intel_fb.c +1 -0
index f3c97e0..10b7c36 100644
@@ -210,6 +210,7 @@ static void intel_fbdev_destroy(struct drm_device *dev,
 	drm_framebuffer_unregister_private(&ifb->base);
 	drm_framebuffer_cleanup(&ifb->base);
 	if (ifb->obj) {
+		atomic_dec(&ifb->obj->fb_count);
 		drm_gem_object_unreference_unlocked(&ifb->obj->base);
 		ifb->obj = NULL;
 	}
Signature · 6 lines
1.8.1.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 56 lines · On Mon, Aug 05, 2013 at 11:13:24PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

A bit more food for the cache discussions. My idea here is to track whether an object is part of any fb, and in case it is we assume it can be used for scanout, and thus may need some extra clflushes. But otherwise we'd try to avoid clflushes on LLC plarforms.

I also included some GFDT stuff in there just to think a bit about how it would work, but I left out the GFDT flushes themselves.

Also I didn't even boot-test this, so it may explode quite spectacularly.

---
 drivers/gpu/drm/i915/i915_drv.h            |  5 +++
 drivers/gpu/drm/i915/i915_gem.c            | 63 +++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 13 +++++-
 drivers/gpu/drm/i915/i915_gem_gtt.c        |  6 ++-
 drivers/gpu/drm/i915/intel_display.c       |  2 +
 drivers/gpu/drm/i915/intel_fb.c            |  1 +
 6 files changed, 72 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +5 -0
index 8b14e22..ec275ed 100644
@@ -451,6 +451,8 @@ enum i915_cache_level {
 	I915_CACHE_NONE = 0,
 	I915_CACHE_LLC,
 	I915_CACHE_LLC_MLC, /* gen6+, in docs at least! */
+	I915_CACHE_WT, /* hsw gt3e */
+	I915_CACHE_GFDT = 0x4, /* SNB/IVB: flag ORed w/ the cache mode */
 };
 
 typedef uint32_t gen6_gtt_pte_t;
@@ -1388,6 +1390,8 @@ struct drm_i915_gem_object {
 
 	/** for phy allocated objects */
 	struct drm_i915_gem_phys_object *phys_obj;
+
+	atomic_t fb_count;
 };
 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
 
@@ -1494,6 +1498,7 @@ struct drm_i915_file_private {
 #define HAS_VEBOX(dev)          (INTEL_INFO(dev)->has_vebox_ring)
 #define HAS_LLC(dev)            (INTEL_INFO(dev)->has_llc)
 #define I915_NEED_GFX_HWS(dev)	(INTEL_INFO(dev)->need_gfx_hws)
+#define HAS_GFDT(dev)		(0)
 
 #define HAS_HW_CONTEXTS(dev)	(INTEL_INFO(dev)->gen >= 6)
 #define HAS_ALIASING_PPGTT(dev)	(INTEL_INFO(dev)->gen >=6 && !IS_VALLEYVIEW(dev))
drivers/gpu/drm/i915/i915_gem.c +0 -0
index bd6eb64..38d3241 100644

drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 400

Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +4 -0
@@ -394,6 +394,20 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,
 	return ret ? - EFAULT : 0;
 }
 
+static bool cpu_caches_coherent(struct drm_i915_gem_object *obj)
+{
+	return HAS_LLC(obj->base.dev) || obj->cache_level != I915_CACHE_NONE;
+}

Yes, that much better expresses what we mean.

drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 409

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +8 -0
+static bool
+scanout_needs_clflush(struct drm_i915_gem_object *obj,
+		      enum i915_cache_level cache_level)
+{
+	return cache_level != I915_CACHE_LLC &&
+		cache_level != I915_CACHE_LLC_MLC &&
+		atomic_read(&obj->fb_count) > 0;
+}

(Aside, this also a good time to change LLC_MLC to L3!)

GFDT, similarly to WT, I think is purely a bit set on the GPU side. My experience was that I could not dirty with the CPU then issue a GPU GFDT flush without seeing cache dirt on the scanout. Actually, I think I just found my issue in the SNB bspec... Apparently, I must not dirty the surface before the previous flush is complete - which is solvable by using the active render tracking. Just another little hoop to jump through for GFDT.

I think we really want to see the llc/scanout patch first so that we can give it a thorough test and debunking. Then WT as it is fairly trivial and then seeing if we can finally get GFDT right.
-Chris

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