public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH 1/9] drm/i915: Update rules for reading cache lines through the LLC
@ 2013-08-08 13:41 Chris Wilson
  2013-08-08 13:41 ` [PATCH 2/9] drm/i915: Track when an object is pinned for use by the display engine Chris Wilson
                   ` (8 more replies)
  0 siblings, 9 replies; 28+ messages in thread
From: Chris Wilson @ 2013-08-08 13:41 UTC (permalink / raw)
  To: intel-gfx

The LLC is a fun device. The cache is a distinct functional block within
the SA that arbitrates access from both the CPU and GPU cores. As such
all writes to memory land first in the LLC before further action is
taken. For example, an uncached write from either the CPU or GPU will
then proceed to memory and evict the cacheline from the LLC. This means that
a read from the LLC always returns the correct information even if the PTE
bit in the GPU differs from the PAT bit in the CPU. For the older
snooping architecture on non-LLC, the fundamental principle still holds
except that some coordination is required between the CPU and GPU to
explicitly perform the snooping (which is handled by our request
tracking).

The upshot of this is that we know that we can issue a read from either
LLC devices or snoopable memory and trust the contents of the cache -
i.e. we can forgo a clflush before a read in these circumstances.
Writing to memory from the CPU is a little more tricky as we have to
consider that the scanout does not read from the CPU cache at all, but
from main memory. So we have to currently treat all requests to write to
uncached memory as having to be flushed to main memory for coherency
with all consumers.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 4c420f9..7cd36c5 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -62,6 +62,12 @@ static long i915_gem_purge(struct drm_i915_private *dev_priv, long target);
 static void i915_gem_shrink_all(struct drm_i915_private *dev_priv);
 static void i915_gem_object_truncate(struct drm_i915_gem_object *obj);
 
+static bool cpu_cache_is_coherent(struct drm_device *dev,
+				  enum i915_cache_level level)
+{
+	return HAS_LLC(dev) || level != I915_CACHE_NONE;
+}
+
 static inline void i915_gem_object_fence_lost(struct drm_i915_gem_object *obj)
 {
 	if (obj->tiling_mode)
@@ -508,8 +514,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
 		 * read domain and manually flush cachelines (if required). This
 		 * optimizes for the case when the gpu will dirty the data
 		 * anyway again before the next pread happens. */
-		if (obj->cache_level == I915_CACHE_NONE)
-			needs_clflush = 1;
+		needs_clflush = !cpu_cache_is_coherent(dev, obj->cache_level);
 		if (i915_gem_obj_bound_any(obj)) {
 			ret = i915_gem_object_set_to_gtt_domain(obj, false);
 			if (ret)
@@ -833,11 +838,11 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
 				return ret;
 		}
 	}
-	/* Same trick applies for invalidate partially written cachelines before
-	 * writing.  */
-	if (!(obj->base.read_domains & I915_GEM_DOMAIN_CPU)
-	    && obj->cache_level == I915_CACHE_NONE)
-		needs_clflush_before = 1;
+	/* Same trick applies to invalidate partially written cachelines read
+	 * before writing. */
+	if ((obj->base.read_domains & I915_GEM_DOMAIN_CPU) == 0)
+		needs_clflush_before =
+			!cpu_cache_is_coherent(dev, obj->cache_level);
 
 	ret = i915_gem_object_get_pages(obj);
 	if (ret)
@@ -3679,7 +3684,8 @@ i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write)
 
 	/* Flush the CPU cache if it's still invalid. */
 	if ((obj->base.read_domains & I915_GEM_DOMAIN_CPU) == 0) {
-		i915_gem_clflush_object(obj);
+		if (!cpu_cache_is_coherent(obj->base.dev, obj->cache_level))
+			i915_gem_clflush_object(obj);
 
 		obj->base.read_domains |= I915_GEM_DOMAIN_CPU;
 	}
-- 
1.8.4.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2013-08-12 16:53 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-08 13:41 [PATCH 1/9] drm/i915: Update rules for reading cache lines through the LLC Chris Wilson
2013-08-08 13:41 ` [PATCH 2/9] drm/i915: Track when an object is pinned for use by the display engine Chris Wilson
2013-08-09 11:25   ` [PATCH] " Chris Wilson
2013-08-09 11:54     ` Ville Syrjälä
2013-08-08 13:41 ` [PATCH 3/9] drm/i915: Update rules for writing through the LLC with the cpu Chris Wilson
2013-08-08 15:27   ` Ville Syrjälä
2013-08-08 15:36     ` Chris Wilson
2013-08-08 15:51       ` Ville Syrjälä
2013-08-08 16:12         ` Chris Wilson
2013-08-09 11:26   ` [PATCH] " Chris Wilson
2013-08-09 11:56     ` Ville Syrjälä
2013-08-08 13:41 ` [PATCH 4/9] drm/i915: Allow the GPU to cache stolen memory Chris Wilson
2013-08-08 13:41 ` [PATCH 5/9] drm/i915: Allocate LLC ringbuffers from stolen Chris Wilson
2013-08-08 13:41 ` [PATCH 6/9] drm/i915: Allocate context objects " Chris Wilson
2013-08-10  9:25   ` Daniel Vetter
2013-08-10  9:34     ` Chris Wilson
2013-08-10  9:44       ` Daniel Vetter
2013-08-08 13:41 ` [PATCH 7/9] drm/i915: Only do a chipset flush after a clflush Chris Wilson
2013-08-08 13:41 ` [PATCH 8/9] drm/i915: Use Write-Through cacheing for the display plane on Iris Chris Wilson
2013-08-08 13:41 ` [PATCH 9/9] drm/i915: Allow the user to set bo into the DISPLAY cache domain Chris Wilson
2013-08-10 10:09   ` Daniel Vetter
2013-08-10 10:19     ` Chris Wilson
2013-08-10 12:54       ` [PATCH] drm/i915: reserve I915_CACHING_DISPLAY and document cache modes Daniel Vetter
2013-08-10 12:57       ` Daniel Vetter
2013-08-10 13:09         ` Chris Wilson
2013-08-10 15:54           ` Daniel Vetter
2013-08-12 16:53     ` [PATCH 9/9] drm/i915: Allow the user to set bo into the DISPLAY cache domain Daniel Vetter
2013-08-08 16:42 ` [PATCH 1/9] drm/i915: Update rules for reading cache lines through the LLC Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox