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: [PATCH v2 10/38] drm/i915: Create a fake object for testing huge allocations
Date: Thu, 19 Jan 2017 11:41:30 +0000	[thread overview]
Message-ID: <20170119114158.17941-11-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20170119114158.17941-1-chris@chris-wilson.co.uk>

We would like to be able to exercise huge allocations even on memory
constrained devices. To do this we create an object that allocates only
a few pages and remaps them across its whole range - each page is reused
multiple times. We can therefore pretend we are rendering into a much
larger object.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c                  |   1 +
 drivers/gpu/drm/i915/i915_gem_object.h           |  20 ++--
 drivers/gpu/drm/i915/selftests/huge_gem_object.c | 135 +++++++++++++++++++++++
 drivers/gpu/drm/i915/selftests/huge_gem_object.h |  33 ++++++
 4 files changed, 181 insertions(+), 8 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/selftests/huge_gem_object.c
 create mode 100644 drivers/gpu/drm/i915/selftests/huge_gem_object.h

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index d93abed05631..a03eeb6d85bf 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4942,4 +4942,5 @@ i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/scatterlist.c"
 #include "selftests/mock_gem_device.c"
+#include "selftests/huge_gem_object.c"
 #endif
diff --git a/drivers/gpu/drm/i915/i915_gem_object.h b/drivers/gpu/drm/i915/i915_gem_object.h
index 290eaa7fc9eb..4114cc8a0b9b 100644
--- a/drivers/gpu/drm/i915/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/i915_gem_object.h
@@ -167,14 +167,18 @@ struct drm_i915_gem_object {
 	/** Record of address bit 17 of each page at last unbind. */
 	unsigned long *bit_17;
 
-	struct i915_gem_userptr {
-		uintptr_t ptr;
-		unsigned read_only :1;
-
-		struct i915_mm_struct *mm;
-		struct i915_mmu_object *mmu_object;
-		struct work_struct *work;
-	} userptr;
+	union {
+		struct i915_gem_userptr {
+			uintptr_t ptr;
+			unsigned read_only :1;
+
+			struct i915_mm_struct *mm;
+			struct i915_mmu_object *mmu_object;
+			struct work_struct *work;
+		} userptr;
+
+		unsigned long scratch;
+	};
 
 	/** for phys allocated objects */
 	struct drm_dma_handle *phys_handle;
diff --git a/drivers/gpu/drm/i915/selftests/huge_gem_object.c b/drivers/gpu/drm/i915/selftests/huge_gem_object.c
new file mode 100644
index 000000000000..f39294f4013f
--- /dev/null
+++ b/drivers/gpu/drm/i915/selftests/huge_gem_object.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "huge_gem_object.h"
+
+static void huge_free_pages(struct drm_i915_gem_object *obj,
+			    struct sg_table *pages)
+{
+	unsigned long nreal = obj->scratch / PAGE_SIZE;
+	struct scatterlist *sg;
+
+	for (sg = pages->sgl; sg && nreal--; sg = ____sg_next(sg))
+		__free_page(sg_page(sg));
+
+	sg_free_table(pages);
+	kfree(pages);
+}
+
+static struct sg_table *
+huge_get_pages(struct drm_i915_gem_object *obj)
+{
+#define GFP (GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY)
+	const unsigned long nreal = obj->scratch / PAGE_SIZE;
+	const unsigned long npages = obj->base.size / PAGE_SIZE;
+	struct scatterlist *sg, *src, *end;
+	struct sg_table *pages;
+	unsigned long n;
+
+	pages = kmalloc(sizeof(*pages), GFP);
+	if (!pages)
+		return ERR_PTR(-ENOMEM);
+
+	if (sg_alloc_table(pages, npages, GFP)) {
+		kfree(pages);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	sg = pages->sgl;
+	for (n = 0; n < nreal; n++) {
+		struct page *page;
+
+		page = alloc_page(GFP | __GFP_HIGHMEM);
+		if (!page) {
+			sg_mark_end(sg);
+			goto err;
+		}
+
+		sg_set_page(sg, page, PAGE_SIZE, 0);
+		sg = ____sg_next(sg);
+	}
+	if (nreal < npages) {
+		for (end = sg, src = pages->sgl; sg; sg = __sg_next(sg)) {
+			sg_set_page(sg, sg_page(src), PAGE_SIZE, 0);
+			src = ____sg_next(src);
+			if (src == end)
+				src = pages->sgl;
+		}
+	}
+
+	if (i915_gem_gtt_prepare_pages(obj, pages))
+		goto err;
+
+	return pages;
+
+err:
+	huge_free_pages(obj, pages);
+	return ERR_PTR(-ENOMEM);
+#undef GFP
+}
+
+static void huge_put_pages(struct drm_i915_gem_object *obj,
+			   struct sg_table *pages)
+{
+	i915_gem_gtt_finish_pages(obj, pages);
+	huge_free_pages(obj, pages);
+
+	obj->mm.dirty = false;
+}
+
+static const struct drm_i915_gem_object_ops huge_ops = {
+	.flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
+		 I915_GEM_OBJECT_IS_SHRINKABLE,
+	.get_pages = huge_get_pages,
+	.put_pages = huge_put_pages,
+};
+
+struct drm_i915_gem_object *
+huge_gem_object(struct drm_i915_private *i915,
+		phys_addr_t real_size,
+		phys_addr_t fake_size)
+{
+	struct drm_i915_gem_object *obj;
+
+	GEM_BUG_ON(!real_size || real_size > fake_size);
+	GEM_BUG_ON(!IS_ALIGNED(real_size, PAGE_SIZE));
+	GEM_BUG_ON(!IS_ALIGNED(fake_size, PAGE_SIZE));
+
+	if (overflows_type(fake_size, obj->base.size))
+		return ERR_PTR(-E2BIG);
+
+	obj = i915_gem_object_alloc(i915);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	drm_gem_private_object_init(&i915->drm, &obj->base, fake_size);
+	i915_gem_object_init(obj, &huge_ops);
+
+	obj->base.write_domain = I915_GEM_DOMAIN_CPU;
+	obj->base.read_domains = I915_GEM_DOMAIN_CPU;
+	obj->cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
+	obj->scratch = real_size;
+
+	return obj;
+}
diff --git a/drivers/gpu/drm/i915/selftests/huge_gem_object.h b/drivers/gpu/drm/i915/selftests/huge_gem_object.h
new file mode 100644
index 000000000000..3022a7c93844
--- /dev/null
+++ b/drivers/gpu/drm/i915/selftests/huge_gem_object.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __HUGE_GEM_OBJECT_H
+#define __HUGE_GEM_OBJECT_H
+
+struct drm_i915_gem_object *
+huge_gem_object(struct drm_i915_private *i915,
+		phys_addr_t real_size,
+		phys_addr_t fake_size);
+
+#endif /* !__HUGE_GEM_OBJECT_H */
-- 
2.11.0

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

  parent reply	other threads:[~2017-01-19 11:42 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 11:41 More selftests Chris Wilson
2017-01-19 11:41 ` [PATCH v2 01/38] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-01-25 11:12   ` Joonas Lahtinen
2017-01-25 11:16     ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 02/38] drm/i915: Provide a hook for selftests Chris Wilson
2017-01-25 11:50   ` Joonas Lahtinen
2017-02-01 13:57     ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 03/38] drm/i915: Add some selftests for sg_table manipulation Chris Wilson
2017-02-01 11:17   ` Tvrtko Ursulin
2017-02-01 11:34     ` Chris Wilson
2017-02-02 12:41       ` Tvrtko Ursulin
2017-02-02 13:38         ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 04/38] drm/i915: Add unit tests for the breadcrumb rbtree, insert/remove Chris Wilson
2017-01-19 11:41 ` [PATCH v2 05/38] drm/i915: Add unit tests for the breadcrumb rbtree, completion Chris Wilson
2017-01-19 11:41 ` [PATCH v2 06/38] drm/i915: Add unit tests for the breadcrumb rbtree, wakeups Chris Wilson
2017-02-01 11:27   ` Tvrtko Ursulin
2017-02-01 11:43     ` Chris Wilson
2017-02-01 13:19     ` [PATCH v3] " Chris Wilson
2017-02-01 16:57       ` Tvrtko Ursulin
2017-02-01 17:08         ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 07/38] drm/i915: Mock the GEM device for self-testing Chris Wilson
2017-01-19 11:41 ` [PATCH v2 08/38] drm/i915: Mock a GGTT " Chris Wilson
2017-01-19 11:41 ` [PATCH v2 09/38] drm/i915: Mock infrastructure for request emission Chris Wilson
2017-01-19 11:41 ` Chris Wilson [this message]
2017-01-19 13:09   ` [PATCH v2 10/38] drm/i915: Create a fake object for testing huge allocations Matthew Auld
2017-01-19 11:41 ` [PATCH v2 11/38] drm/i915: Add selftests for i915_gem_request Chris Wilson
2017-01-19 11:41 ` [PATCH v2 12/38] drm/i915: Add a simple request selftest for waiting Chris Wilson
2017-01-19 11:41 ` [PATCH v2 13/38] drm/i915: Add a simple fence selftest to i915_gem_request Chris Wilson
2017-01-19 11:41 ` [PATCH v2 14/38] drm/i915: Simple selftest to exercise live requests Chris Wilson
2017-02-01  8:14   ` Joonas Lahtinen
2017-02-01 10:31     ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 15/38] drm/i915: Test simultaneously submitting requests to all engines Chris Wilson
2017-02-01  8:03   ` Joonas Lahtinen
2017-02-01 10:15     ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 16/38] drm/i915: Add selftests for object allocation, phys Chris Wilson
2017-01-19 11:41 ` [PATCH v2 17/38] drm/i915: Add a live seftest for GEM objects Chris Wilson
2017-01-19 11:41 ` [PATCH v2 18/38] drm/i915: Test partial mappings Chris Wilson
2017-01-19 11:41 ` [PATCH v2 19/38] drm/i915: Test exhaustion of the mmap space Chris Wilson
2017-01-19 11:41 ` [PATCH v2 20/38] drm/i915: Test coherency of and barriers between cache domains Chris Wilson
2017-01-19 13:01   ` Matthew Auld
2017-01-19 11:41 ` [PATCH v2 21/38] drm/i915: Move uncore selfchecks to live selftest infrastructure Chris Wilson
2017-01-19 11:41 ` [PATCH v2 22/38] drm/i915: Test all fw tables during mock selftests Chris Wilson
2017-01-19 11:41 ` [PATCH v2 23/38] drm/i915: Sanity check all registers for matching fw domains Chris Wilson
2017-01-19 11:41 ` [PATCH v2 24/38] drm/i915: Add some mock tests for dmabuf interop Chris Wilson
2017-01-19 11:41 ` [PATCH v2 25/38] drm/i915: Add initial selftests for i915_gem_gtt Chris Wilson
2017-01-19 11:41 ` [PATCH v2 26/38] drm/i915: Exercise filling the top/bottom portions of the ppgtt Chris Wilson
2017-01-31 12:32   ` Joonas Lahtinen
2017-01-19 11:41 ` [PATCH v2 27/38] drm/i915: Exercise filling the top/bottom portions of the global GTT Chris Wilson
2017-01-19 11:41 ` [PATCH v2 28/38] drm/i915: Fill different pages of the GTT Chris Wilson
2017-01-19 11:41 ` [PATCH v2 29/38] drm/i915: Exercise filling and removing random ranges from the live GTT Chris Wilson
2017-01-20 10:39   ` Matthew Auld
2017-01-19 11:41 ` [PATCH v2 30/38] drm/i915: Test creation of VMA Chris Wilson
2017-01-31 10:50   ` Joonas Lahtinen
2017-02-01 14:07     ` Chris Wilson
2017-01-19 11:41 ` [PATCH v2 31/38] drm/i915: Exercise i915_vma_pin/i915_vma_insert Chris Wilson
2017-01-19 11:41 ` [PATCH v2 32/38] drm/i915: Verify page layout for rotated VMA Chris Wilson
2017-02-01 13:26   ` Matthew Auld
2017-02-01 14:33   ` Tvrtko Ursulin
2017-02-01 14:55     ` Chris Wilson
2017-02-01 15:44       ` Tvrtko Ursulin
2017-01-19 11:41 ` [PATCH v2 33/38] drm/i915: Test creation of partial VMA Chris Wilson
2017-01-31 12:03   ` Joonas Lahtinen
2017-01-19 11:41 ` [PATCH v2 34/38] drm/i915: Live testing for context execution Chris Wilson
2017-01-25 14:51   ` Joonas Lahtinen
2017-01-19 11:41 ` [PATCH v2 35/38] drm/i915: Initial selftests for exercising eviction Chris Wilson
2017-01-19 11:41 ` [PATCH v2 36/38] drm/i915: Add mock exercise for i915_gem_gtt_reserve Chris Wilson
2017-01-25 13:30   ` Joonas Lahtinen
2017-01-19 11:41 ` [PATCH v2 37/38] drm/i915: Add mock exercise for i915_gem_gtt_insert Chris Wilson
2017-01-25 13:31   ` Joonas Lahtinen
2017-01-19 11:41 ` [PATCH v2 38/38] drm/i915: Add initial selftests for hang detection and resets Chris Wilson
2017-02-01 11:43   ` Mika Kuoppala
2017-02-01 13:31     ` Chris Wilson
2017-01-19 13:54 ` ✗ Fi.CI.BAT: failure for series starting with [v2,01/38] drm: Provide a driver hook for drm_dev_release() Patchwork

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=20170119114158.17941-11-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.