All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [RFC PATCH i-g-t v3 2/4] lib: Add GEM minimum page size helper
Date: Mon, 28 Oct 2019 16:53:16 +0100	[thread overview]
Message-ID: <20191028155318.23416-3-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com>

Some tests assume 4kB page size while using softpin.  That assumption
may be wrong on future GEM backends with possibly larger minimum page
sizes.  As a result, those tests may either fail on softpin at offsets
which are incorrectly aligned, may silently skip such incorrectly
aligned addresses assuming them occupied by other users, or may always
succeed when examining invalid use patterns.

Provide a helper function that detects minimum page size and returns
the size order.  Tests may use it to calculate softpin offsets suitable
for actually used backing store.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Stuart Summers <stuart.summers@intel.com>
---
 lib/ioctl_wrappers.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
 lib/ioctl_wrappers.h |  1 +
 2 files changed, 83 insertions(+)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 280fdd62..a4313832 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -54,6 +54,7 @@
 #include "intel_io.h"
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
+#include "igt_x86.h"
 #include "config.h"
 
 #ifdef HAVE_VALGRIND
@@ -1157,6 +1158,87 @@ bool gem_has_softpin(int fd)
 	return has_softpin;
 }
 
+static int __min_page_size_order(int fd, struct drm_i915_gem_exec_object2 *obj,
+				 struct drm_i915_gem_execbuffer2 *eb,
+				 uint64_t offset, int min_order, int max_order)
+{
+	static const uint32_t bbe = MI_BATCH_BUFFER_END;
+	uint64_t page_size = 1ull << max_order;
+	int order;
+
+	if (max_order > min_order) {
+		/* explore upper half of the max_order@offset area */
+		order = __min_page_size_order(fd, obj, eb, offset, min_order,
+					      max_order - 1);
+		if (order < max_order)
+			return order;
+	}
+
+	obj->offset = gen8_canonical_addr(offset - page_size);
+	gem_write(fd, obj->handle, 0, &bbe, sizeof(bbe));
+	if (!__gem_execbuf(fd, eb)) {
+		/* upper half not occupied, must be the minimum */
+		igt_debug("found min page size=%#llx, size order=%d\n",
+			  (long long)page_size, max_order);
+		return max_order;
+	}
+
+	if (max_order > min_order) {
+		/* explore lower half of in case the upper half was occupied */
+		page_size >>= 1;
+		order = __min_page_size_order(fd, obj, eb, offset - page_size,
+					      min_order, max_order - 1);
+		if (order < max_order)
+			return order;
+	}
+
+	return max_order + 1;
+}
+
+/**
+ * gem_min_page_size_order:
+ * @fd: open i915 drm file descriptor
+ *
+ * This function detects the minimum size of a gem object allocated from
+ * a default backing store.  It is useful for calculating correctly aligned
+ * softpin offsets.
+ * Since size order to size conversion (size = 1 << order) is less trivial
+ * than the opposite, the function returns the size order as more handy.
+ *
+ * Returns:
+ * Size order of the minimum page size
+ */
+int gem_min_page_size_order(int fd)
+{
+	struct drm_i915_gem_exec_object2 obj;
+	struct drm_i915_gem_execbuffer2 eb;
+	uint64_t gtt_size = gem_aperture_size(fd);
+	int min_order = 12;	/* current I915_GTT_PAGE_SIZE equivalent */
+	uint64_t page_size = 1ull << min_order;
+	int max_order = 21;	/* current I915_GTT_MAX_PAGE_SIZE equivalent */
+
+	/* no softpin => 4kB page size */
+	if (!gem_has_softpin(fd))
+		return min_order;
+
+	memset(&obj, 0, sizeof(obj));
+	memset(&eb, 0, sizeof(eb));
+
+	obj.handle = gem_create(fd, page_size);
+	obj.flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+	eb.buffers_ptr = to_user_pointer(&obj);
+	eb.buffer_count = 1;
+
+	min_order = __min_page_size_order(fd, &obj, &eb, gtt_size, min_order,
+					  max_order);
+
+	gem_close(fd, obj.handle);
+
+	igt_require(min_order <= max_order);
+
+	return min_order;
+}
+
 /**
  * gem_has_exec_fence:
  * @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 03211c97..91690847 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -138,6 +138,7 @@ uint64_t gem_aperture_size(int fd);
 uint64_t gem_global_aperture_size(int fd);
 uint64_t gem_mappable_aperture_size(void);
 bool gem_has_softpin(int fd);
+int gem_min_page_size_order(int fd);
 bool gem_has_exec_fence(int fd);
 
 /* check functions which auto-skip tests by calling igt_skip() */
-- 
2.21.0

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

WARNING: multiple messages have this Message-ID (diff)
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC PATCH i-g-t v3 2/4] lib: Add GEM minimum page size helper
Date: Mon, 28 Oct 2019 16:53:16 +0100	[thread overview]
Message-ID: <20191028155318.23416-3-janusz.krzysztofik@linux.intel.com> (raw)
Message-ID: <20191028155316.OsftPrrT-I7Zn-B76GYmSwK-AP8ksJm4Akg2fRuW6Qs@z> (raw)
In-Reply-To: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com>

Some tests assume 4kB page size while using softpin.  That assumption
may be wrong on future GEM backends with possibly larger minimum page
sizes.  As a result, those tests may either fail on softpin at offsets
which are incorrectly aligned, may silently skip such incorrectly
aligned addresses assuming them occupied by other users, or may always
succeed when examining invalid use patterns.

Provide a helper function that detects minimum page size and returns
the size order.  Tests may use it to calculate softpin offsets suitable
for actually used backing store.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Stuart Summers <stuart.summers@intel.com>
---
 lib/ioctl_wrappers.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
 lib/ioctl_wrappers.h |  1 +
 2 files changed, 83 insertions(+)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 280fdd62..a4313832 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -54,6 +54,7 @@
 #include "intel_io.h"
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
+#include "igt_x86.h"
 #include "config.h"
 
 #ifdef HAVE_VALGRIND
@@ -1157,6 +1158,87 @@ bool gem_has_softpin(int fd)
 	return has_softpin;
 }
 
+static int __min_page_size_order(int fd, struct drm_i915_gem_exec_object2 *obj,
+				 struct drm_i915_gem_execbuffer2 *eb,
+				 uint64_t offset, int min_order, int max_order)
+{
+	static const uint32_t bbe = MI_BATCH_BUFFER_END;
+	uint64_t page_size = 1ull << max_order;
+	int order;
+
+	if (max_order > min_order) {
+		/* explore upper half of the max_order@offset area */
+		order = __min_page_size_order(fd, obj, eb, offset, min_order,
+					      max_order - 1);
+		if (order < max_order)
+			return order;
+	}
+
+	obj->offset = gen8_canonical_addr(offset - page_size);
+	gem_write(fd, obj->handle, 0, &bbe, sizeof(bbe));
+	if (!__gem_execbuf(fd, eb)) {
+		/* upper half not occupied, must be the minimum */
+		igt_debug("found min page size=%#llx, size order=%d\n",
+			  (long long)page_size, max_order);
+		return max_order;
+	}
+
+	if (max_order > min_order) {
+		/* explore lower half of in case the upper half was occupied */
+		page_size >>= 1;
+		order = __min_page_size_order(fd, obj, eb, offset - page_size,
+					      min_order, max_order - 1);
+		if (order < max_order)
+			return order;
+	}
+
+	return max_order + 1;
+}
+
+/**
+ * gem_min_page_size_order:
+ * @fd: open i915 drm file descriptor
+ *
+ * This function detects the minimum size of a gem object allocated from
+ * a default backing store.  It is useful for calculating correctly aligned
+ * softpin offsets.
+ * Since size order to size conversion (size = 1 << order) is less trivial
+ * than the opposite, the function returns the size order as more handy.
+ *
+ * Returns:
+ * Size order of the minimum page size
+ */
+int gem_min_page_size_order(int fd)
+{
+	struct drm_i915_gem_exec_object2 obj;
+	struct drm_i915_gem_execbuffer2 eb;
+	uint64_t gtt_size = gem_aperture_size(fd);
+	int min_order = 12;	/* current I915_GTT_PAGE_SIZE equivalent */
+	uint64_t page_size = 1ull << min_order;
+	int max_order = 21;	/* current I915_GTT_MAX_PAGE_SIZE equivalent */
+
+	/* no softpin => 4kB page size */
+	if (!gem_has_softpin(fd))
+		return min_order;
+
+	memset(&obj, 0, sizeof(obj));
+	memset(&eb, 0, sizeof(eb));
+
+	obj.handle = gem_create(fd, page_size);
+	obj.flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+	eb.buffers_ptr = to_user_pointer(&obj);
+	eb.buffer_count = 1;
+
+	min_order = __min_page_size_order(fd, &obj, &eb, gtt_size, min_order,
+					  max_order);
+
+	gem_close(fd, obj.handle);
+
+	igt_require(min_order <= max_order);
+
+	return min_order;
+}
+
 /**
  * gem_has_exec_fence:
  * @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 03211c97..91690847 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -138,6 +138,7 @@ uint64_t gem_aperture_size(int fd);
 uint64_t gem_global_aperture_size(int fd);
 uint64_t gem_mappable_aperture_size(void);
 bool gem_has_softpin(int fd);
+int gem_min_page_size_order(int fd);
 bool gem_has_exec_fence(int fd);
 
 /* check functions which auto-skip tests by calling igt_skip() */
-- 
2.21.0

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

  parent reply	other threads:[~2019-10-28 15:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 15:53 [RFC PATCH i-g-t v3 0/4] Calculate softpin offsets from actual page size Janusz Krzysztofik
2019-10-28 15:53 ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/ Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` Janusz Krzysztofik [this message]
2019-10-28 15:53   ` [Intel-gfx] [RFC PATCH i-g-t v3 2/4] lib: Add GEM minimum page size helper Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 3/4] tests/gem_exec_reloc: Calculate softpin offsets from actual page size Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 15:53 ` [RFC PATCH i-g-t v3 4/4] tests/gem_ctx_shared: Calculate object attributs " Janusz Krzysztofik
2019-10-28 15:53   ` [Intel-gfx] " Janusz Krzysztofik
2019-10-28 17:20 ` [igt-dev] ✗ Fi.CI.BAT: failure for Calculate softpin offsets " 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=20191028155318.23416-3-janusz.krzysztofik@linux.intel.com \
    --to=janusz.krzysztofik@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --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.