All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH v2 09/22] drm/i915/selftests: add write-dword test for LMEM
Date: Thu,  3 Oct 2019 20:24:31 +0100	[thread overview]
Message-ID: <20191003192444.10113-10-matthew.auld@intel.com> (raw)
In-Reply-To: <20191003192444.10113-1-matthew.auld@intel.com>

Simple test writing to dwords across an object, using various engines in
a randomized order, checking that our writes land from the cpu.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 .../drm/i915/selftests/intel_memory_region.c  | 171 ++++++++++++++++++
 1 file changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/i915/selftests/intel_memory_region.c b/drivers/gpu/drm/i915/selftests/intel_memory_region.c
index 1ad755e75e57..afb248f175df 100644
--- a/drivers/gpu/drm/i915/selftests/intel_memory_region.c
+++ b/drivers/gpu/drm/i915/selftests/intel_memory_region.c
@@ -7,13 +7,16 @@
 
 #include "../i915_selftest.h"
 
+
 #include "mock_drm.h"
 #include "mock_gem_device.h"
 #include "mock_region.h"
 
+#include "gem/i915_gem_context.h"
 #include "gem/i915_gem_lmem.h"
 #include "gem/i915_gem_region.h"
 #include "gem/i915_gem_object_blt.h"
+#include "gem/selftests/igt_gem_utils.h"
 #include "gem/selftests/mock_context.h"
 #include "gt/intel_gt.h"
 #include "selftests/igt_flush_test.h"
@@ -255,6 +258,125 @@ static int igt_mock_contiguous(void *arg)
 	return err;
 }
 
+static int igt_gpu_write_dw(struct intel_context *ce,
+			    struct i915_vma *vma,
+			    u32 dword,
+			    u32 value)
+{
+	return igt_gpu_fill_dw(ce, vma, dword * sizeof(u32),
+			       vma->size >> PAGE_SHIFT, value);
+}
+
+static int igt_cpu_check(struct drm_i915_gem_object *obj, u32 dword, u32 val)
+{
+	unsigned long n;
+	int err;
+
+	i915_gem_object_lock(obj);
+	err = i915_gem_object_set_to_wc_domain(obj, false);
+	i915_gem_object_unlock(obj);
+	if (err)
+		return err;
+
+	err = i915_gem_object_pin_pages(obj);
+	if (err)
+		return err;
+
+	for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) {
+		u32 __iomem *base;
+		u32 read_val;
+
+		base = i915_gem_object_lmem_io_map_page_atomic(obj, n);
+
+		read_val = ioread32(base + dword);
+		io_mapping_unmap_atomic(base);
+		if (read_val != val) {
+			pr_err("n=%lu base[%u]=%u, val=%u\n",
+			       n, dword, read_val, val);
+			err = -EINVAL;
+			break;
+		}
+	}
+
+	i915_gem_object_unpin_pages(obj);
+	return err;
+}
+
+static int igt_gpu_write(struct i915_gem_context *ctx,
+			 struct drm_i915_gem_object *obj)
+{
+	struct drm_i915_private *i915 = ctx->i915;
+	struct i915_address_space *vm = ctx->vm ?: &i915->ggtt.vm;
+	struct i915_gem_engines *engines;
+	struct i915_gem_engines_iter it;
+	struct intel_context *ce;
+	I915_RND_STATE(prng);
+	IGT_TIMEOUT(end_time);
+	unsigned int count;
+	struct i915_vma *vma;
+	int *order;
+	int i, n;
+	int err = 0;
+
+	GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
+
+	n = 0;
+	count = 0;
+	for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
+		count++;
+		if (!intel_engine_can_store_dword(ce->engine))
+			continue;
+
+		n++;
+	}
+	i915_gem_context_unlock_engines(ctx);
+	if (!n)
+		return 0;
+
+	order = i915_random_order(count * count, &prng);
+	if (!order)
+		return -ENOMEM;
+
+	vma = i915_vma_instance(obj, vm, NULL);
+	if (IS_ERR(vma)) {
+		err = PTR_ERR(vma);
+		goto out_free;
+	}
+
+	err = i915_vma_pin(vma, 0, 0, PIN_USER);
+	if (err)
+		goto out_free;
+
+	i = 0;
+	engines = i915_gem_context_lock_engines(ctx);
+	do {
+		u32 rng = prandom_u32_state(&prng);
+		u32 dword = offset_in_page(rng) / 4;
+
+		ce = engines->engines[order[i] % engines->num_engines];
+		i = (i + 1) % (count * count);
+		if (!ce || !intel_engine_can_store_dword(ce->engine))
+			continue;
+
+		err = igt_gpu_write_dw(ce, vma, dword, rng);
+		if (err)
+			break;
+
+		err = igt_cpu_check(obj, dword, rng);
+		if (err)
+			break;
+	} while (!__igt_timeout(end_time, NULL));
+	i915_gem_context_unlock_engines(ctx);
+
+out_free:
+	kfree(order);
+
+	if (err == -ENOMEM)
+		err = 0;
+
+	return err;
+}
+
 static int igt_lmem_create(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
@@ -276,6 +398,54 @@ static int igt_lmem_create(void *arg)
 	return err;
 }
 
+static int igt_lmem_write_gpu(void *arg)
+{
+	struct drm_i915_private *i915 = arg;
+	struct drm_i915_gem_object *obj;
+	struct i915_gem_context *ctx;
+	struct drm_file *file;
+	I915_RND_STATE(prng);
+	u32 sz;
+	int err;
+
+	mutex_unlock(&i915->drm.struct_mutex);
+	file = mock_file(i915);
+	mutex_lock(&i915->drm.struct_mutex);
+	if (IS_ERR(file))
+		return PTR_ERR(file);
+
+	ctx = live_context(i915, file);
+	if (IS_ERR(ctx)) {
+		err = PTR_ERR(ctx);
+		goto out_file;
+	}
+
+	sz = round_up(prandom_u32_state(&prng) % SZ_32M, PAGE_SIZE);
+
+	obj = i915_gem_object_create_lmem(i915, sz, 0);
+	if (IS_ERR(obj)) {
+		err = PTR_ERR(obj);
+		goto out_file;
+	}
+
+	err = i915_gem_object_pin_pages(obj);
+	if (err)
+		goto out_put;
+
+	err = igt_gpu_write(ctx, obj);
+	if (err)
+		pr_err("igt_gpu_write failed(%d)\n", err);
+
+	i915_gem_object_unpin_pages(obj);
+out_put:
+	i915_gem_object_put(obj);
+out_file:
+	mutex_unlock(&i915->drm.struct_mutex);
+	mock_file_free(i915, file);
+	mutex_lock(&i915->drm.struct_mutex);
+	return err;
+}
+
 static int igt_lmem_write_cpu(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
@@ -427,6 +597,7 @@ int intel_memory_region_live_selftests(struct drm_i915_private *i915)
 	static const struct i915_subtest tests[] = {
 		SUBTEST(igt_lmem_create),
 		SUBTEST(igt_lmem_write_cpu),
+		SUBTEST(igt_lmem_write_gpu),
 	};
 	int err;
 
-- 
2.20.1

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

  parent reply	other threads:[~2019-10-03 19:25 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 19:24 [PATCH v2 00/22] LMEM basics Matthew Auld
2019-10-03 19:24 ` [PATCH v2 01/22] drm/i915/stolen: make the object creation interface consistent Matthew Auld
2019-10-03 19:29   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 02/22] drm/i915: introduce intel_memory_region Matthew Auld
2019-10-03 19:24 ` [PATCH v2 03/22] drm/i915/region: support contiguous allocations Matthew Auld
2019-10-03 19:24 ` [PATCH v2 04/22] drm/i915/region: support volatile objects Matthew Auld
2019-10-03 19:40   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 05/22] drm/i915: Add memory region information to device_info Matthew Auld
2019-10-03 19:24 ` [PATCH v2 06/22] drm/i915: support creating LMEM objects Matthew Auld
2019-10-03 19:46   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 07/22] drm/i915: setup io-mapping for LMEM Matthew Auld
2019-10-03 19:24 ` [PATCH v2 08/22] drm/i915/lmem: support kernel mapping Matthew Auld
2019-10-03 19:48   ` Chris Wilson
2019-10-03 19:24 ` Matthew Auld [this message]
2019-10-03 19:24 ` [PATCH v2 10/22] drm/i915/selftests: extend coverage to include LMEM huge-pages Matthew Auld
2019-10-03 19:24 ` [PATCH v2 11/22] drm/i915: enumerate and init each supported region Matthew Auld
2019-10-03 19:24 ` [PATCH v2 12/22] drm/i915: treat shmem as a region Matthew Auld
2019-10-03 19:24 ` [PATCH v2 13/22] drm/i915: treat stolen " Matthew Auld
2019-10-03 19:43   ` Tang, CQ
2019-10-03 19:24 ` [PATCH v2 14/22] drm/i915: define HAS_MAPPABLE_APERTURE Matthew Auld
2019-10-03 19:53   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 15/22] drm/i915: do not map aperture if it is not available Matthew Auld
2019-10-03 19:24 ` [PATCH v2 16/22] drm/i915: set num_fence_regs to 0 if there is no aperture Matthew Auld
2019-10-03 19:24 ` [PATCH v2 17/22] drm/i915: error capture with no ggtt slot Matthew Auld
2019-10-03 19:24 ` [PATCH v2 18/22] drm/i915: Don't try to place HWS in non-existing mappable region Matthew Auld
2019-10-03 19:24 ` [PATCH v2 19/22] drm/i915: don't allocate the ring in stolen if we lack aperture Matthew Auld
2019-10-03 19:37   ` Tang, CQ
2019-10-03 19:55   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 20/22] drm/i915/selftests: fallback to using the gpu to trash stolen Matthew Auld
2019-10-03 20:02   ` Chris Wilson
2019-10-03 19:24 ` [PATCH v2 21/22] drm/i915/selftests: check for missing aperture Matthew Auld
2019-10-03 19:24 ` [PATCH v2 22/22] HAX drm/i915: add the fake lmem region Matthew Auld
2019-10-03 22:11 ` ✗ Fi.CI.CHECKPATCH: warning for LMEM basics (rev2) Patchwork
2019-10-03 22:21 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-10-03 22:34 ` ✓ Fi.CI.BAT: success " Patchwork
2019-10-04 11:34 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-10-04 12:06   ` Kai Vehmanen
2019-10-04 12:08     ` 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=20191003192444.10113-10-matthew.auld@intel.com \
    --to=matthew.auld@intel.com \
    --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.