All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 5/8] drm/i915: Align start for memcpy_from_wc
Date: Sat,  7 Dec 2019 17:01:07 +0000	[thread overview]
Message-ID: <20191207170110.2200142-5-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20191207170110.2200142-1-chris@chris-wilson.co.uk>

The movntqda requires 16-byte alignment for the source pointer. Avoid
falling back to clflush if the source pointer is misaligned by doing the
doing a small uncached memcpy to fixup the alignments.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_cmd_parser.c | 30 +++++++++++++++++---------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index 6cf4e336461b..2977316d64ae 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -1132,8 +1132,8 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
 {
 	unsigned int src_needs_clflush;
 	unsigned int dst_needs_clflush;
-	void *dst, *src;
-	int ret;
+	void *dst, *src, *ptr;
+	int ret, len;
 
 	ret = i915_gem_object_prepare_write(dst_obj, &dst_needs_clflush);
 	if (ret)
@@ -1150,19 +1150,30 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
 		return ERR_PTR(ret);
 	}
 
+	ptr = dst;
 	src = ERR_PTR(-ENODEV);
-	if (src_needs_clflush &&
-	    i915_can_memcpy_from_wc(NULL, offset, 0)) {
+	if (src_needs_clflush && i915_has_memcpy_from_wc()) {
 		src = i915_gem_object_pin_map(src_obj, I915_MAP_WC);
 		if (!IS_ERR(src)) {
-			i915_memcpy_from_wc(dst,
-					    src + offset,
-					    ALIGN(length, 16));
+			src += offset;
+
+			if (!IS_ALIGNED(offset, 16)) {
+				len = min(ALIGN(offset, 16) - offset, length);
+
+				memcpy(ptr, src, len);
+
+				offset += len;
+				length -= len;
+				ptr += len;
+				src += len;
+			}
+			GEM_BUG_ON(!IS_ALIGNED((unsigned long)src, 16));
+
+			i915_memcpy_from_wc(ptr, src, ALIGN(length, 16));
 			i915_gem_object_unpin_map(src_obj);
 		}
 	}
 	if (IS_ERR(src)) {
-		void *ptr;
 		int x, n;
 
 		/*
@@ -1177,10 +1188,9 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
 			length = round_up(length,
 					  boot_cpu_data.x86_clflush_size);
 
-		ptr = dst;
 		x = offset_in_page(offset);
 		for (n = offset >> PAGE_SHIFT; length; n++) {
-			int len = min_t(int, length, PAGE_SIZE - x);
+			len = min_t(int, length, PAGE_SIZE - x);
 
 			src = kmap_atomic(i915_gem_object_get_page(src_obj, n));
 			if (src_needs_clflush)
-- 
2.24.0

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

  parent reply	other threads:[~2019-12-07 17:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07 17:01 [Intel-gfx] [PATCH 1/8] drm/i915: Fix cmdparser drm.debug Chris Wilson
2019-12-07 17:01 ` [Intel-gfx] [PATCH 2/8] drm/i915: Remove redundant parameters from intel_engine_cmd_parser Chris Wilson
2019-12-11  9:41   ` Joonas Lahtinen
2019-12-07 17:01 ` [Intel-gfx] [PATCH 3/8] drm/i915: Simplify error escape from cmdparser Chris Wilson
2019-12-11  9:44   ` Joonas Lahtinen
2019-12-07 17:01 ` [Intel-gfx] [PATCH 4/8] drm/i915/gem: Tidy up error handling for eb_parse() Chris Wilson
2019-12-11  9:51   ` Joonas Lahtinen
2019-12-07 17:01 ` Chris Wilson [this message]
2019-12-11 10:03   ` [Intel-gfx] [PATCH 5/8] drm/i915: Align start for memcpy_from_wc Joonas Lahtinen
2019-12-07 17:01 ` [Intel-gfx] [PATCH 6/8] drm/i915: Prepare gen7 cmdparser for async execution Chris Wilson
2019-12-11 11:27   ` Joonas Lahtinen
2019-12-11 11:46     ` Chris Wilson
2019-12-07 17:01 ` [Intel-gfx] [PATCH 7/8] drm/i915: Asynchronous cmdparser Chris Wilson
2019-12-07 17:17   ` Chris Wilson
2019-12-07 17:18     ` Chris Wilson
2019-12-11 13:16   ` Joonas Lahtinen
2019-12-07 17:01 ` [Intel-gfx] [PATCH 8/8] HAX: Use aliasing-ppgtt for gen7 Chris Wilson
2019-12-07 17:36 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/8] drm/i915: Fix cmdparser drm.debug Patchwork
2019-12-07 17:54 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2019-12-07 20:12 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2019-12-11  9:25 ` [Intel-gfx] [PATCH 1/8] " Joonas Lahtinen
2020-01-02  9:56 ` Jani Nikula
2020-01-02 10:53   ` Chris Wilson
2020-01-02 12:26     ` Jani Nikula
2020-01-02 10:54   ` Chris Wilson

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=20191207170110.2200142-5-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --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.