[igt-dev] [PATCH i-g-t v4 02/11] lib/igt_gt: add intel_measure_ring_size

Antonio Argenziano antonio.argenziano at intel.com
Wed Feb 21 23:19:38 UTC 2018


From: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>

The logic to measure the ring size is replicated almost identically in
several tests. Adding it as a common function will make the code
cleaner.

The tests are updated in follow up patches.

v2:
	- Move into a new file: 'gem_ring'. (Chris)

v3:
	- Rename ring measure function. (Chris)

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>

Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/Makefile.sources |   2 +
 lib/i915/gem_ring.c  | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/i915/gem_ring.h  |  36 ++++++++++++++++
 lib/meson.build      |   2 +
 4 files changed, 157 insertions(+)
 create mode 100644 lib/i915/gem_ring.c
 create mode 100644 lib/i915/gem_ring.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 86fbfeef..5b13ef88 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -9,6 +9,8 @@ lib_source_list =	 	\
 	i915/gem_scheduler.h	\
 	i915/gem_submission.c	\
 	i915/gem_submission.h	\
+	i915/gem_ring.h	\
+	i915/gem_ring.c	\
 	i915_3d.h		\
 	i915_reg.h		\
 	i915_pciids.h		\
diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
new file mode 100644
index 00000000..7326673a
--- /dev/null
+++ b/lib/i915/gem_ring.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2014 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 "gem_ring.h"
+
+#include <signal.h>
+#include <sys/ioctl.h>
+
+#include "intel_reg.h"
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+#include "igt_dummyload.h"
+
+static void alarm_handler(int sig)
+{
+}
+
+/**
+ * gem_measure_ring_inflight:
+ * @fd: open i915 drm file descriptor
+ * @engine: execbuf engine flag
+ * @flags: flags to affect measurement:
+ *		- MEASURE_RING_NEW_CTX: use a new context to account for the space
+ *		  used by the lrc init.
+ *
+ * This function calculates the maximum number of batches that can be inserted
+ * at the same time in the ring on the selected engine.
+ *
+ * Returns:
+ * Number of batches that fit in the ring
+ */
+unsigned int
+gem_measure_ring_inflight(int fd, unsigned int engine, enum measure_ring_flags flags)
+{
+	struct sigaction old_sa, sa = { .sa_handler = alarm_handler };
+	struct drm_i915_gem_exec_object2 obj[2];
+	struct drm_i915_gem_execbuffer2 execbuf;
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	unsigned int count, last;
+	struct itimerval itv;
+	IGT_CORK_HANDLE(cork);
+
+	memset(obj, 0, sizeof(obj));
+	obj[1].handle = gem_create(fd, 4096);
+	gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = to_user_pointer(&obj[1]);
+	execbuf.buffer_count = 1;
+	execbuf.flags = engine;
+	gem_execbuf(fd, &execbuf);
+	gem_sync(fd, obj[1].handle);
+
+	obj[0].handle = igt_cork_plug(&cork, fd);
+
+	execbuf.buffers_ptr = to_user_pointer(obj);
+	execbuf.buffer_count = 2;
+
+	if (flags & MEASURE_RING_NEW_CTX)
+		execbuf.rsvd1 = gem_context_create(fd);
+
+	sigaction(SIGALRM, &sa, &old_sa);
+	itv.it_interval.tv_sec = 0;
+	itv.it_interval.tv_usec = 100;
+	itv.it_value.tv_sec = 0;
+	itv.it_value.tv_usec = 1000;
+	setitimer(ITIMER_REAL, &itv, NULL);
+
+	last = -1;
+	count = 0;
+	do {
+		if (ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf) == 0) {
+			count++;
+			continue;
+		}
+
+		if (last == count)
+			break;
+
+		last = count;
+	} while (1);
+
+	memset(&itv, 0, sizeof(itv));
+	setitimer(ITIMER_REAL, &itv, NULL);
+	sigaction(SIGALRM, &old_sa, NULL);
+
+	igt_cork_unplug(&cork);
+	gem_close(fd, obj[0].handle);
+	gem_close(fd, obj[1].handle);
+
+	if (flags & MEASURE_RING_NEW_CTX)
+		gem_context_destroy(fd, execbuf.rsvd1);
+
+	gem_quiescent_gpu(fd);
+
+	return count;
+}
diff --git a/lib/i915/gem_ring.h b/lib/i915/gem_ring.h
new file mode 100644
index 00000000..c69adce0
--- /dev/null
+++ b/lib/i915/gem_ring.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2014 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 GEM_RING_H
+#define GEM_RING_H
+
+#include <stdbool.h>
+
+enum measure_ring_flags {
+	MEASURE_RING_NEW_CTX = 1
+};
+
+unsigned int
+gem_measure_ring_inflight(int fd, unsigned int engine, enum measure_ring_flags flags);
+
+#endif /* GEM_RING_H */
diff --git a/lib/meson.build b/lib/meson.build
index 94ea0799..6c77e407 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -5,6 +5,7 @@ lib_headers = [
 	'i915/gem_context.h',
 	'i915/gem_scheduler.h',
 	'i915/gem_submission.h',
+	'i915/gem_ring.h',
 	'i915_3d.h',
 	'i915_reg.h',
 	'i915_pciids.h',
@@ -57,6 +58,7 @@ lib_sources = [
 	'i915/gem_context.c',
 	'i915/gem_scheduler.c',
 	'i915/gem_submission.c',
+	'i915/gem_ring.c',
 	'igt_debugfs.c',
 	'igt_device.c',
 	'igt_aux.c',
-- 
2.14.2



More information about the igt-dev mailing list