From patchwork Wed Nov 23 10:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9442961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B41F6075F for ; Wed, 23 Nov 2016 11:00:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29CB6203B9 for ; Wed, 23 Nov 2016 11:00:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E7B92236A; Wed, 23 Nov 2016 11:00:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 44F4D203B9 for ; Wed, 23 Nov 2016 11:00:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0017E6E7F2; Wed, 23 Nov 2016 11:00:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A90216E7EF for ; Wed, 23 Nov 2016 10:59:54 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP; 23 Nov 2016 02:59:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,537,1473145200"; d="scan'208";a="8374884" Received: from abdiel-macbookpro.fi.intel.com ([10.237.66.47]) by orsmga002.jf.intel.com with ESMTP; 23 Nov 2016 02:59:50 -0800 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Nov 2016 12:59:41 +0200 Message-Id: <20161123105943.5157-4-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161123105943.5157-1-abdiel.janulgue@linux.intel.com> References: <20161123105943.5157-1-abdiel.janulgue@linux.intel.com> Cc: Daniel Vetter Subject: [Intel-gfx] [i-g-t PATCH v10 3/5] igt/gem_wait: Use new igt_spin_batch X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP v7: Adapt to api rename v8: Restore sanitycheck wait on the recursive batch and avoid using C99 locals (Chris Wilson) v9: Explicitly quit the batch instead of timing out right away v10: Adapt to api rename Cc: Chris Wilson Cc: Daniel Vetter Reviewed-by: Tomeu Vizoso Signed-off-by: Abdiel Janulgue --- tests/gem_wait.c | 124 +++---------------------------------------------------- 1 file changed, 6 insertions(+), 118 deletions(-) diff --git a/tests/gem_wait.c b/tests/gem_wait.c index b4127de..ebcaec2 100644 --- a/tests/gem_wait.c +++ b/tests/gem_wait.c @@ -27,18 +27,6 @@ #include "igt.h" -#include -#include -#include - -#define gettid() syscall(__NR_gettid) -#define sigev_notify_thread_id _sigev_un._tid - -#define LOCAL_I915_EXEC_BSD_SHIFT (13) -#define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) - -#define ENGINE_MASK (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) - static int __gem_wait(int fd, struct drm_i915_gem_wait *w) { int err; @@ -75,98 +63,24 @@ static void invalid_buf(int fd) igt_assert_eq(__gem_wait(fd, &wait), -ENOENT); } -static uint32_t *batch; - -static void sigiter(int sig, siginfo_t *info, void *arg) -{ - *batch = MI_BATCH_BUFFER_END; - __sync_synchronize(); -} - -#define MSEC_PER_SEC (1000) -#define USEC_PER_SEC (1000 * MSEC_PER_SEC) -#define NSEC_PER_SEC (1000 * USEC_PER_SEC) - #define BUSY 1 #define HANG 2 static void basic(int fd, unsigned engine, unsigned flags) { - const int gen = intel_gen(intel_get_drm_devid(fd)); - struct drm_i915_gem_exec_object2 obj; - struct drm_i915_gem_relocation_entry reloc; - struct drm_i915_gem_execbuffer2 execbuf; struct drm_i915_gem_wait wait; - unsigned engines[16]; - unsigned nengine; - int i, timeout; - - nengine = 0; - if (engine == -1) { - for_each_engine(fd, engine) - if (engine) engines[nengine++] = engine; - } else { - igt_require(gem_has_ring(fd, engine)); - engines[nengine++] = engine; - } - igt_require(nengine); - - memset(&execbuf, 0, sizeof(execbuf)); - execbuf.buffers_ptr = (uintptr_t)&obj; - execbuf.buffer_count = 1; - - memset(&obj, 0, sizeof(obj)); - obj.handle = gem_create(fd, 4096); - - obj.relocs_ptr = (uintptr_t)&reloc; - obj.relocation_count = 1; - memset(&reloc, 0, sizeof(reloc)); - - batch = gem_mmap__gtt(fd, obj.handle, 4096, PROT_WRITE); - gem_set_domain(fd, obj.handle, - I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); - - reloc.target_handle = obj.handle; /* recurse */ - reloc.presumed_offset = 0; - reloc.offset = sizeof(uint32_t); - reloc.delta = 0; - reloc.read_domains = I915_GEM_DOMAIN_COMMAND; - reloc.write_domain = 0; - - i = 0; - batch[i] = MI_BATCH_BUFFER_START; - if (gen >= 8) { - batch[i] |= 1 << 8 | 1; - batch[++i] = 0; - batch[++i] = 0; - } else if (gen >= 6) { - batch[i] |= 1 << 8; - batch[++i] = 0; - } else { - batch[i] |= 2 << 6; - batch[++i] = 0; - if (gen < 4) { - batch[i] |= 1; - reloc.delta = 1; - } - } - - for (i = 0; i < nengine; i++) { - execbuf.flags &= ~ENGINE_MASK; - execbuf.flags |= engines[i]; - gem_execbuf(fd, &execbuf); - } + igt_spin_t *spin = igt_spin_batch_new(fd, engine, NULL); memset(&wait, 0, sizeof(wait)); - wait.bo_handle = obj.handle; + wait.bo_handle = spin->handle; igt_assert_eq(__gem_wait(fd, &wait), -ETIME); if (flags & BUSY) { + int timeout; struct timespec tv; timeout = 120; if ((flags & HANG) == 0) { - *batch = MI_BATCH_BUFFER_END; - __sync_synchronize(); + igt_spin_batch_end(spin); timeout = 1; } @@ -174,29 +88,7 @@ static void basic(int fd, unsigned engine, unsigned flags) while (__gem_wait(fd, &wait) == -ETIME) igt_assert(igt_seconds_elapsed(&tv) < timeout); } else { - timer_t timer; - - if ((flags & HANG) == 0) { - struct sigevent sev; - struct sigaction act; - struct itimerspec its; - - memset(&sev, 0, sizeof(sev)); - sev.sigev_notify = SIGEV_SIGNAL | SIGEV_THREAD_ID; - sev.sigev_notify_thread_id = gettid(); - sev.sigev_signo = SIGRTMIN + 1; - igt_assert(timer_create(CLOCK_MONOTONIC, &sev, &timer) == 0); - - memset(&act, 0, sizeof(act)); - act.sa_sigaction = sigiter; - act.sa_flags = SA_SIGINFO; - igt_assert(sigaction(SIGRTMIN + 1, &act, NULL) == 0); - - memset(&its, 0, sizeof(its)); - its.it_value.tv_nsec = 0; - its.it_value.tv_sec = 1; - igt_assert(timer_settime(timer, 0, &its, NULL) == 0); - } + igt_spin_batch_set_timeout(spin, NSEC_PER_SEC); wait.timeout_ns = NSEC_PER_SEC / 2; /* 0.5s */ igt_assert_eq(__gem_wait(fd, &wait), -ETIME); @@ -215,13 +107,9 @@ static void basic(int fd, unsigned engine, unsigned flags) wait.timeout_ns = 0; igt_assert_eq(__gem_wait(fd, &wait), 0); igt_assert(wait.timeout_ns == 0); - - if ((flags & HANG) == 0) - timer_delete(timer); } - gem_close(fd, obj.handle); - munmap(batch, 4096); + igt_spin_batch_free(fd, spin); } igt_main