From: Ben Widawsky <ben@bwidawsk.net>
To: intel-gfx@lists.freedesktop.org
Cc: Ben Widawsky <ben@bwidawsk.net>
Subject: [PATCH] tests/wait render timeout test
Date: Fri, 11 May 2012 13:54:12 -0700 [thread overview]
Message-ID: <1336769652-11740-6-git-send-email-ben@bwidawsk.net> (raw)
In-Reply-To: <1336769652-11740-1-git-send-email-ben@bwidawsk.net>
Assures that signals interrupting the wait works properly. Because of
the scheduling around signals, interrupted waits will *seem* faster as
the GPU continues to work while all the CPU scheduling stuff happens.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
tests/Makefile.am | 3 +
tests/gem_wait_render_timeout.c | 155 +++++++++++++++++++++++++++++++++++++++
2 files changed, 158 insertions(+)
create mode 100644 tests/gem_wait_render_timeout.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 18caf78..8dcf416 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,7 @@ TESTS_progs = \
drm_vma_limiter_cached \
sysfs_rc6_residency \
flip_test \
+ gem_wait_render_timeout \
$(NULL)
# IMPORTANT: The ZZ_ tests need to be run last!
@@ -116,3 +117,5 @@ AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
gem_fence_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
gem_fence_thrash_LDADD = $(LDADD) -lpthread
+
+gem_wait_render_timeout_LDADD = $(LDADD) -lrt
diff --git a/tests/gem_wait_render_timeout.c b/tests/gem_wait_render_timeout.c
new file mode 100644
index 0000000..8edfc43
--- /dev/null
+++ b/tests/gem_wait_render_timeout.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright © 2012 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.
+ *
+ * Authors:
+ * Ben Widawsky <ben@bwidawsk.net>
+ *
+ */
+
+#include <stdio.h>
+#include <time.h>
+#include "drm.h"
+#include "rendercopy.h"
+
+#define MSEC_PER_SEC 1000L
+#define USEC_PER_MSEC 1000L
+#define NSEC_PER_USEC 1000L
+#define NSEC_PER_MSEC 1000000L
+#define USEC_PER_SEC 1000000L
+#define NSEC_PER_SEC 1000000000L
+
+#define ENOUGH_WORK_IN_SECONDS 2
+#define BUF_SIZE (8<<20)
+#define BUF_PAGES ((8<<20)>>12)
+drm_intel_bo *dst, *dst2;
+
+/* returns time diff in milliseconds */
+static int64_t
+do_time_diff(struct timespec *end, struct timespec *start)
+{
+ int64_t ret;
+ ret = (NSEC_PER_MSEC * difftime(end->tv_sec, start->tv_sec)) +
+ ((end->tv_nsec/NSEC_PER_MSEC) - (start->tv_nsec/NSEC_PER_MSEC));
+ return ret;
+}
+
+
+static void blt_color_fill(struct intel_batchbuffer *batch,
+ drm_intel_bo *buf,
+ const unsigned int pages)
+{
+ const unsigned short height = pages;
+ const unsigned short width = 4096;
+ BEGIN_BATCH(5);
+ OUT_BATCH(COLOR_BLT_CMD |
+ COLOR_BLT_WRITE_ALPHA |
+ COLOR_BLT_WRITE_RGB);
+ OUT_BATCH((3 << 24) | /* 32 Bit Color */
+ 0xF0 | /* Raster OP copy background register */
+ 0); /* Dest pitch is 0 */
+ OUT_BATCH(width << 16 |
+ height);
+ OUT_RELOC(buf, I915_GEM_DOMAIN_RENDER, 0, 0);
+ OUT_BATCH(rand()); /* random pattern */
+ ADVANCE_BATCH();
+}
+
+int main(int argc, char **argv)
+{
+ drm_intel_bufmgr *bufmgr;
+ struct intel_batchbuffer *batch;
+ uint64_t timeout = ENOUGH_WORK_IN_SECONDS * NSEC_PER_SEC;
+ int fd, ret;
+ const bool do_signals = true; /* signals will seem to make the operation
+ * use less process CPU time */
+ bool done = false;
+ int i, iter = 0x100;
+
+ fd = drm_open_any();
+
+ bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+ drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+ batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
+
+ dst = drm_intel_bo_alloc(bufmgr, "dst", BUF_SIZE, 4096);
+ dst2 = drm_intel_bo_alloc(bufmgr, "dst2", BUF_SIZE, 4096);
+
+ /* Figure out a rough number of fills required to consume 1 second of
+ * GPU work.
+ */
+ do {
+ struct timespec start, end;
+ long diff;
+
+ assert(clock_gettime(CLOCK_MONOTONIC_RAW, &start) == 0);
+ for (i = 0; i < iter; i++)
+ blt_color_fill(batch, dst, BUF_PAGES);
+ intel_batchbuffer_flush(batch);
+ drm_intel_bo_wait_rendering(dst);
+ assert(clock_gettime(CLOCK_MONOTONIC_RAW, &end) == 0);
+
+ diff = do_time_diff(&end, &start);
+ assert(diff >= 0);
+
+ if ((diff / MSEC_PER_SEC) > ENOUGH_WORK_IN_SECONDS)
+ done = true;
+ else
+ iter <<= 1;
+ } while (!done && iter < 1000000);
+
+ assert(iter < 1000000);
+
+ printf("%d iters is enough work\n", iter);
+ gem_quiescent_gpu(fd);
+ if (do_signals)
+ drmtest_fork_signal_helper();
+ /* We should be able to do half as much work in the same amount of time */
+ for (i = 0; i < iter; i++)
+ blt_color_fill(batch, dst2, BUF_PAGES);
+
+ intel_batchbuffer_flush(batch);
+
+ ret = drm_intel_gem_bo_wait(dst2, &timeout);
+ if (do_signals)
+ drmtest_stop_signal_helper();
+ if (ret) {
+ fprintf(stderr, "Timed wait failed %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ assert(timeout != 0);
+
+ if (timeout == (ENOUGH_WORK_IN_SECONDS * NSEC_PER_SEC))
+ printf("Buffer was already done!\n");
+ else {
+ printf("Finished with %lu time remaining\n", timeout);
+ }
+
+ drm_intel_bo_unreference(dst2);
+ drm_intel_bo_unreference(dst);
+ intel_batchbuffer_free(batch);
+ drm_intel_bufmgr_destroy(bufmgr);
+
+ close(fd);
+
+ return 0;
+}
--
1.7.10.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2012-05-11 20:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 20:54 [PATCH 1/4 v4] drm/i915: timeout parameter for seqno wait Ben Widawsky
2012-05-11 20:54 ` [PATCH 2/4 v3] drm/i915: improve i915_wait_request_begin trace Ben Widawsky
2012-05-11 20:54 ` [PATCH 3/4 v6] drm/i915: wait render timeout ioctl Ben Widawsky
2012-05-11 23:09 ` Eugeni Dodonov
2012-05-12 21:07 ` Ben Widawsky
2012-05-11 20:54 ` [PATCH 4/4] drm/i915: s/i915_wait_reqest/i915_wait_seqno/g Ben Widawsky
2012-05-11 22:56 ` Eugeni Dodonov
2012-05-12 21:20 ` Ben Widawsky
2012-05-11 20:54 ` [PATCH] intel: add a timed wait function Ben Widawsky
2012-05-11 20:54 ` Ben Widawsky [this message]
2012-05-11 23:09 ` [PATCH 1/4 v4] drm/i915: timeout parameter for seqno wait Eugeni Dodonov
-- strict thread matches above, loose matches on Subject: below --
2012-04-29 22:22 [PATCH 0/5 v3] timed BO wait Ben Widawsky
2012-04-29 22:22 ` [PATCH] tests/wait render timeout test Ben Widawsky
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=1336769652-11740-6-git-send-email-ben@bwidawsk.net \
--to=ben@bwidawsk.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox