From patchwork Wed Oct 25 23:08:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Ceraolo Spurio X-Patchwork-Id: 10027327 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 9287360245 for ; Wed, 25 Oct 2017 23:08:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85D0C28C7C for ; Wed, 25 Oct 2017 23:08:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AF6928C7E; Wed, 25 Oct 2017 23:08:37 +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 0F55128C7D for ; Wed, 25 Oct 2017 23:08:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 480E66E713; Wed, 25 Oct 2017 23:08:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2FE446E6FE for ; Wed, 25 Oct 2017 23:08:25 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2017 16:08:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,433,1503385200"; d="scan'208";a="913793172" Received: from relo-linux-1.fm.intel.com ([10.1.27.112]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2017 16:08:23 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Wed, 25 Oct 2017 16:08:08 -0700 Message-Id: <1508972891-35322-6-git-send-email-daniele.ceraolospurio@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508972891-35322-1-git-send-email-daniele.ceraolospurio@intel.com> References: <1508972891-35322-1-git-send-email-daniele.ceraolospurio@intel.com> Subject: [Intel-gfx] [PATCH i-g-t v2 5/8] tests/gem_exec_latency: use new common functions 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 With intel_measure_ring_size and igt_cork added as common utilities we can use them instead of the local copy of those utilities Signed-off-by: Daniele Ceraolo Spurio Cc: Chris Wilson --- tests/gem_exec_latency.c | 97 ++++++------------------------------------------ 1 file changed, 11 insertions(+), 86 deletions(-) diff --git a/tests/gem_exec_latency.c b/tests/gem_exec_latency.c index e9d9344..c6c4bb2 100644 --- a/tests/gem_exec_latency.c +++ b/tests/gem_exec_latency.c @@ -54,83 +54,6 @@ static unsigned int ring_size; -struct cork { - int device; - uint32_t handle; - uint32_t fence; -}; - -static void plug(int fd, struct cork *c) -{ - struct vgem_bo bo; - int dmabuf; - - c->device = drm_open_driver(DRIVER_VGEM); - - bo.width = bo.height = 1; - bo.bpp = 4; - vgem_create(c->device, &bo); - c->fence = vgem_fence_attach(c->device, &bo, VGEM_FENCE_WRITE); - - dmabuf = prime_handle_to_fd(c->device, bo.handle); - c->handle = prime_fd_to_handle(fd, dmabuf); - close(dmabuf); -} - -static void unplug(struct cork *c) -{ - vgem_fence_signal(c->device, c->fence); - close(c->device); -} - -static void alarm_handler(int sig) -{ -} - -static void set_timeout(int seconds) -{ - struct sigaction sa = { .sa_handler = alarm_handler }; - - sigaction(SIGALRM, seconds ? &sa : NULL, NULL); - alarm(seconds); -} - -static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf) -{ - return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf); -} - -static unsigned int measure_ring_size(int fd) -{ - 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; - struct cork c; - - memset(obj, 0, sizeof(obj)); - obj[1].handle = gem_create(fd, 4096); - gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe)); - - plug(fd, &c); - obj[0].handle = c.handle; - - memset(&execbuf, 0, sizeof(execbuf)); - execbuf.buffers_ptr = to_user_pointer(obj); - execbuf.buffer_count = 2; - - count = 0; - set_timeout(1); - while (__execbuf(fd, &execbuf) == 0) - count++; - set_timeout(0); - - unplug(&c); - gem_close(fd, obj[1].handle); - - return count; -} - #define RCS_TIMESTAMP (0x2000 + 0x358) static void latency_on_ring(int fd, unsigned ring, const char *name, @@ -141,7 +64,7 @@ static void latency_on_ring(int fd, struct drm_i915_gem_exec_object2 obj[3]; struct drm_i915_gem_relocation_entry reloc; struct drm_i915_gem_execbuffer2 execbuf; - struct cork c; + struct igt_cork c; volatile uint32_t *reg; unsigned repeats = ring_size; uint32_t start, end, *map, *results; @@ -205,8 +128,7 @@ static void latency_on_ring(int fd, } if (flags & CORK) { - plug(fd, &c); - obj[0].handle = c.handle; + obj[0].handle = igt_cork_plug(fd, &c); execbuf.buffers_ptr = to_user_pointer(&obj[0]); execbuf.buffer_count = 3; } @@ -227,7 +149,7 @@ static void latency_on_ring(int fd, igt_assert(reloc.presumed_offset == obj[1].offset); if (flags & CORK) - unplug(&c); + igt_cork_unplug(&c); gem_set_domain(fd, obj[1].handle, I915_GEM_DOMAIN_GTT, 0); gpu_latency = (results[repeats-1] - results[0]) / (double)(repeats-1); @@ -268,6 +190,8 @@ static void latency_on_ring(int fd, munmap(map, 64*1024); munmap(results, 4096); + if (flags & CORK) + gem_close(fd, obj[0].handle); gem_close(fd, obj[1].handle); gem_close(fd, obj[2].handle); } @@ -319,7 +243,7 @@ static void latency_from_ring(int fd, reloc.target_handle = flags & CORK ? 1 : 0; for (e = intel_execution_engines; e->name; e++) { - struct cork c; + struct igt_cork c; if (e->exec_id == 0) continue; @@ -332,8 +256,7 @@ static void latency_from_ring(int fd, I915_GEM_DOMAIN_GTT); if (flags & CORK) { - plug(fd, &c); - obj[0].handle = c.handle; + obj[0].handle = igt_cork_plug(fd, &c); execbuf.buffers_ptr = to_user_pointer(&obj[0]); execbuf.buffer_count = 3; } @@ -391,7 +314,7 @@ static void latency_from_ring(int fd, } if (flags & CORK) - unplug(&c); + igt_cork_unplug(&c); gem_set_domain(fd, obj[1].handle, I915_GEM_DOMAIN_GTT, @@ -403,6 +326,8 @@ static void latency_from_ring(int fd, munmap(map, 64*1024); munmap(results, 4096); + if (flags & CORK) + gem_close(fd, obj[0].handle); gem_close(fd, obj[1].handle); gem_close(fd, obj[2].handle); } @@ -419,7 +344,7 @@ igt_main gem_submission_print_method(device); - ring_size = measure_ring_size(device); + ring_size = intel_measure_ring_size(device, 0, false); igt_info("Ring size: %d batches\n", ring_size); igt_require(ring_size > 8); ring_size -= 8; /* leave some spare */