All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 1/8] lib/igt_dummyload: add igt_cork
Date: Thu, 12 Oct 2017 15:27:27 -0700	[thread overview]
Message-ID: <1507847254-3289-2-git-send-email-daniele.ceraolospurio@intel.com> (raw)
In-Reply-To: <1507847254-3289-1-git-send-email-daniele.ceraolospurio@intel.com>

The "cork" bo (imported bo with attached fence) is used in several
tests to stall execution. Moving it to a common place makes the codebase
cleaner.

Note that the actual test updates is done in follow up patches as it is
simpler to do in one go after one more common function is added in the
next patch.

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_dummyload.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_dummyload.h | 11 ++++++++
 2 files changed, 86 insertions(+)

diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index bb2be55..913cc93 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -29,6 +29,7 @@
 #include <i915_drm.h>
 
 #include "igt_core.h"
+#include "drmtest.h"
 #include "igt_dummyload.h"
 #include "igt_gt.h"
 #include "intel_chipset.h"
@@ -300,3 +301,77 @@ void igt_terminate_spin_batches(void)
 	igt_list_for_each(iter, &spin_list, link)
 		igt_spin_batch_end(iter);
 }
+
+/**
+ * igt_cork_new
+ * @fd: open drm file descriptor
+ *
+ * Imports a vgem bo with a fence attached to it. This bo can be used as a
+ * dependency during submission to stall execution until the fence is signaled.
+ *
+ * Returns:
+ * Structure with the handle of the imported bo and helper internal state
+ * for igt_cork_signal() and igt_cork_free().
+ */
+igt_cork_t *igt_cork_new(int fd)
+{
+	igt_cork_t *cork;
+	struct vgem_bo bo;
+	int dmabuf;
+
+	cork = calloc(1, sizeof(igt_cork_t));
+	igt_assert(cork);
+
+	cork->device = drm_open_driver(DRIVER_VGEM);
+
+	igt_require(vgem_has_fences(cork->device));
+
+	bo.width = bo.height = 1;
+	bo.bpp = 4;
+	vgem_create(cork->device, &bo);
+	cork->fence = vgem_fence_attach(cork->device, &bo, VGEM_FENCE_WRITE);
+
+	dmabuf = prime_handle_to_fd(cork->device, bo.handle);
+	cork->handle = prime_fd_to_handle(fd, dmabuf);
+	close(dmabuf);
+
+	return cork;
+}
+
+/**
+ * igt_cork_signal:
+ * @cork: cork state from igt_cork_new()
+ *
+ * This function signals the fence attached to the imported object, thus
+ * unblocking any stalled execution.
+ */
+void igt_cork_signal(igt_cork_t *cork)
+{
+	if (!cork)
+		return;
+
+	vgem_fence_signal(cork->device, cork->fence);
+	close(cork->device);
+	cork->device = 0;
+}
+
+/**
+ * igt_cork_free:
+ * @cork: cork state from igt_cork_new()
+ * @fd: open drm file descriptor
+ *
+ * This function signals the fence attached to the imported object (if it
+ * hasn't already been signaled by igt_cork_signal) and does the necessary
+ * post-processing.
+ */
+void igt_cork_free(int fd, igt_cork_t *cork)
+{
+	if (!cork)
+		return;
+
+	if (cork->device)
+		igt_cork_signal(cork);
+
+	gem_close(fd, cork->handle);
+	free(cork);
+}
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 215425f..d20a867 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -29,6 +29,7 @@
 #include <time.h>
 
 #include "igt_aux.h"
+#include "igt_vgem.h"
 
 typedef struct igt_spin {
 	unsigned int handle;
@@ -51,4 +52,14 @@ void igt_spin_batch_free(int fd, igt_spin_t *spin);
 
 void igt_terminate_spin_batches(void);
 
+typedef struct igt_cork {
+	int device;
+	uint32_t handle;
+	uint32_t fence;
+} igt_cork_t;
+
+igt_cork_t *igt_cork_new(int fd);
+void igt_cork_signal(igt_cork_t *cork);
+void igt_cork_free(int fd, igt_cork_t *cork);
+
 #endif /* __IGT_DUMMYLOAD_H__ */
-- 
1.9.1

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

  reply	other threads:[~2017-10-12 22:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12 22:27 [PATCH i-g-t 0/8] extract cork and ring measure code Daniele Ceraolo Spurio
2017-10-12 22:27 ` Daniele Ceraolo Spurio [this message]
2017-10-12 22:48   ` [PATCH i-g-t 1/8] lib/igt_dummyload: add igt_cork Chris Wilson
2017-10-12 22:55   ` Chris Wilson
2017-10-12 22:57   ` Chris Wilson
2017-10-13  8:31     ` Chris Wilson
2017-10-13 16:37       ` Daniele Ceraolo Spurio
2017-10-18 15:49         ` Daniele Ceraolo Spurio
2017-10-18 16:04           ` Chris Wilson
2017-10-18 16:50             ` Daniele Ceraolo Spurio
2017-10-19 18:12               ` Chris Wilson
2017-10-19 20:15                 ` Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 2/8] lib/igt_gt: add intel_measure_ring_size Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 3/8] tests/gem_exec_schedule: use new common functions Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 4/8] tests/gem_exec_fence: " Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 5/8] tests/gem_exec_latency: " Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 6/8] tests/gem_wait: use igt_cork Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 7/8] tests/gem_exec_await: use intel_measure_ring_size Daniele Ceraolo Spurio
2017-10-12 22:27 ` [PATCH i-g-t 8/8] tests/gem_ringfill: " Daniele Ceraolo Spurio
2017-10-12 22:48 ` ✓ Fi.CI.BAT: success for extract cork and ring measure code Patchwork
2017-10-12 23:12 ` [PATCH i-g-t 0/8] " Chris Wilson
2017-10-13  5:32 ` ✓ Fi.CI.IGT: success for " 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=1507847254-3289-2-git-send-email-daniele.ceraolospurio@intel.com \
    --to=daniele.ceraolospurio@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.