All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 04/16] drm/i915: move clflushing into shmem_pread
Date: Sun, 25 Mar 2012 19:47:31 +0200	[thread overview]
Message-ID: <1332697663-31256-4-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1332697663-31256-1-git-send-email-daniel.vetter@ffwll.ch>

This is obviously gonna slow down pread. But for a half-way realistic
micro-benchmark, it doesn't matter: Non-broken userspace reads back
data from the gpu once before the gpu again dirties it.

So all this ranged clflush tracking is just a waste of time.

No pread performance change (neglecting the dumb benchmark of
constantly reading the same data) measured.

As an added bonus, this avoids clflush on read on coherent objects.
Which means that partial preads on snb are now roughly 4x as fast.
This will be usefull for e.g. the libva encoder - when I finally get
around to fix that up.

v2: Properly sync with the gpu on LLC machines.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 681ead9..a5545c9 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -324,12 +324,25 @@ i915_gem_shmem_pread(struct drm_device *dev,
 	int shmem_page_offset, page_length, ret = 0;
 	int obj_do_bit17_swizzling, page_do_bit17_swizzling;
 	int hit_slowpath = 0;
+	int needs_clflush = 0;
 
 	user_data = (char __user *) (uintptr_t) args->data_ptr;
 	remain = args->size;
 
 	obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
 
+	if (!(obj->base.read_domains & I915_GEM_DOMAIN_CPU)) {
+		/* If we're not in the cpu read domain, set ourself into the gtt
+		 * 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;
+		ret = i915_gem_object_set_to_gtt_domain(obj, false);
+		if (ret)
+			return ret;
+	}
+
 	offset = args->offset;
 
 	while (remain > 0) {
@@ -357,6 +370,9 @@ i915_gem_shmem_pread(struct drm_device *dev,
 
 		if (!page_do_bit17_swizzling) {
 			vaddr = kmap_atomic(page);
+			if (needs_clflush)
+				drm_clflush_virt_range(vaddr + shmem_page_offset,
+						       page_length);
 			ret = __copy_to_user_inatomic(user_data,
 						      vaddr + shmem_page_offset,
 						      page_length);
@@ -370,6 +386,10 @@ i915_gem_shmem_pread(struct drm_device *dev,
 		mutex_unlock(&dev->struct_mutex);
 
 		vaddr = kmap(page);
+		if (needs_clflush)
+			drm_clflush_virt_range(vaddr + shmem_page_offset,
+					       page_length);
+
 		if (page_do_bit17_swizzling)
 			ret = __copy_to_user_swizzled(user_data,
 						      vaddr, shmem_page_offset,
@@ -450,12 +470,6 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
 
 	trace_i915_gem_object_pread(obj, args->offset, args->size);
 
-	ret = i915_gem_object_set_cpu_read_domain_range(obj,
-							args->offset,
-							args->size);
-	if (ret)
-		goto out;
-
 	ret = i915_gem_shmem_pread(dev, obj, args, file);
 
 out:
-- 
1.7.7.6

  parent reply	other threads:[~2012-03-25 18:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 17:47 [PATCH 01/16] drm/i915: merge shmem_pwrite slow&fast-path Daniel Vetter
2012-03-25 17:47 ` [PATCH 02/16] drm/i915: merge shmem_pread slow&fast-path Daniel Vetter
2012-03-25 17:47 ` [PATCH 03/16] drm: add helper to clflush a virtual address range Daniel Vetter
2012-03-25 17:47 ` Daniel Vetter [this message]
2012-03-25 17:47 ` [PATCH 05/16] drm/i915: kill ranged cpu read domain support Daniel Vetter
2012-03-25 17:47 ` [PATCH 06/16] drm/i915: don't use gtt_pwrite on LLC cached objects Daniel Vetter
2012-03-25 17:47 ` [PATCH 07/16] drm/i915: don't call shmem_read_mapping unnecessarily Daniel Vetter
2012-03-26  9:10   ` Daniel Vetter
2012-03-25 17:47 ` [PATCH 08/16] drm/i915: drop gtt slowpath Daniel Vetter
2012-03-25 17:47 ` [PATCH 09/16] drm/i915: don't clobber userspace memory before commiting to the pread Daniel Vetter
2012-03-25 17:47 ` [PATCH 10/16] drm/i915: implement inline clflush for pwrite Daniel Vetter
2012-03-25 17:47 ` [PATCH 11/16] drm/i915: fall back to shmem pwrite when the buffer is not accessible Daniel Vetter
2012-03-25 17:47 ` [PATCH 12/16] drm/i915: use uncached writes in pwrite Daniel Vetter
2012-03-25 17:47 ` [PATCH 13/16] drm/i915: extract copy helpers from shmem_pread|pwrite Daniel Vetter
2012-03-26  9:05   ` Chris Wilson
2012-03-25 17:47 ` [PATCH 14/16] mm: extend prefault helpers to fault in more than PAGE_SIZE Daniel Vetter
2012-03-26  9:09   ` Chris Wilson
2012-03-25 17:47 ` [PATCH 15/16] drm/i915: fixup in-line clflushing on bit17 swizzled bos Daniel Vetter
2012-03-26  9:18   ` Chris Wilson
2012-03-26  9:26     ` Daniel Vetter
2012-03-26 12:50       ` Chris Wilson
2012-03-25 17:47 ` [PATCH 16/16] drm/i915: mark pwrite/pread slowpaths with unlikely Daniel Vetter
2012-03-26  9:09   ` Chris Wilson
2012-03-27 11:42     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332697663-31256-4-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.