From patchwork Thu Oct 12 22:30:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniele Ceraolo Spurio X-Patchwork-Id: 10003047 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 9DBD96028A for ; Thu, 12 Oct 2017 22:31:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F34528F07 for ; Thu, 12 Oct 2017 22:31:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DEC828F1D; Thu, 12 Oct 2017 22:31:00 +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 C684728F11 for ; Thu, 12 Oct 2017 22:30:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 576C16E99A; Thu, 12 Oct 2017 22:30:59 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E1C86E99A for ; Thu, 12 Oct 2017 22:30:57 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Oct 2017 15:30:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,368,1503385200"; d="scan'208";a="137946039" Received: from relo-linux-1.fm.intel.com ([10.1.27.112]) by orsmga004.jf.intel.com with ESMTP; 12 Oct 2017 15:30:57 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Thu, 12 Oct 2017 15:30:42 -0700 Message-Id: <1507847444-3593-3-git-send-email-daniele.ceraolospurio@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507847444-3593-1-git-send-email-daniele.ceraolospurio@intel.com> References: <1507847444-3593-1-git-send-email-daniele.ceraolospurio@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 2/4] tests/gem_pread: test reads from a bo not backed by struct page 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Using an imported vgem bo we can test reads from an object not backed by struct page. These reads use different paths in the kernel. While at it, extract some common code in an helper function and fix the src vs dst naming (they are the other way around). Suggested-by: Chris Wilson Signed-off-by: Daniele Ceraolo Spurio Cc: Chris Wilson --- tests/gem_pread.c | 160 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 111 insertions(+), 49 deletions(-) diff --git a/tests/gem_pread.c b/tests/gem_pread.c index 39a46ed..89a9a5d 100644 --- a/tests/gem_pread.c +++ b/tests/gem_pread.c @@ -26,6 +26,7 @@ */ #include "igt.h" +#include "igt_vgem.h" #include #include #include @@ -73,25 +74,91 @@ static const char *bytes_per_sec(char *buf, double v) return buf; } +static void do_read_loop(int fd, const char *name, uint32_t handle, + uint32_t *dst, int size) +{ + int count; + double usecs; + char buf[100]; + const char* bps; + unsigned i; + + for (count = 1; count <= 1<<17; count <<= 1) { + struct timeval start, end; + + memset(dst, 0, size); + gettimeofday(&start, NULL); + do_gem_read(fd, handle, dst, size, count); + gettimeofday(&end, NULL); + usecs = elapsed(&start, &end, count); + bps = bytes_per_sec(buf, size/usecs*1e6); + igt_info("Time to %s pread %d bytes x %6d: %7.3fµs, %s\n", + name, size, count, usecs, bps); + fflush(stdout); + + for (i = 0; i < size / 4096; i++) + igt_assert_eq(dst[i * 1024], i); + } +} + +static uint32_t create_i915_bo(int fd, uint64_t size) +{ + uint32_t handle = gem_create(fd, size); + uint32_t *ptr; + unsigned i; + + ptr = gem_mmap__cpu(fd, handle, 0, size, PROT_WRITE); + gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); + for (i = 0; i < size / 4096; i++) + ptr[i * 1024] = i; + munmap(ptr, size); + return handle; +} + +/* + * imported BOs are not backed by struct page and therefore the preads go + * through different driver paths compared to a normal bo + */ +static uint32_t create_foreign_bo(int fd, uint64_t size) +{ + struct vgem_bo scratch; + int vgem; + uint32_t handle; + uint32_t *ptr; + unsigned i; + + vgem = drm_open_driver(DRIVER_VGEM); -uint32_t *src, dst; -int fd, count; + scratch.width = 1024; + scratch.height = size / 4096; + scratch.bpp = 32; + handle = vgem_create_and_import(vgem, &scratch, fd, NULL); + igt_assert_eq(size, scratch.size); + + ptr = vgem_mmap(vgem, &scratch, PROT_WRITE); + for (i = 0; i < size / 4096; i++) + ptr[i * 1024] = i; + munmap(ptr, scratch.size); + + close(vgem); + + return handle; +} int main(int argc, char **argv) { + int fd; + uint32_t *dst; + uint32_t handle; int object_size = 0; - double usecs; - char buf[100]; - const char* bps; const struct { - int level; - const char *name; - } cache[] = { - { 0, "uncached" }, - { 1, "snoop" }, - { 2, "display" }, - { -1 }, - }, *c; + const char *prefix; + uint32_t (*bo_create)(int fd, uint64_t size); + } modes[] = { + { "", create_i915_bo }, + { "foreign-bo-", create_foreign_bo }, + { NULL, NULL } + }, *m; igt_subtest_init(argc, argv); igt_skip_on_simulation(); @@ -104,49 +171,44 @@ int main(int argc, char **argv) igt_fixture { fd = drm_open_driver(DRIVER_INTEL); - - dst = gem_create(fd, object_size); - src = malloc(object_size); - } - - igt_subtest("basic") { - for (count = 1; count <= 1<<17; count <<= 1) { - struct timeval start, end; - - gettimeofday(&start, NULL); - do_gem_read(fd, dst, src, object_size, count); - gettimeofday(&end, NULL); - usecs = elapsed(&start, &end, count); - bps = bytes_per_sec(buf, object_size/usecs*1e6); - igt_info("Time to pread %d bytes x %6d: %7.3fµs, %s\n", - object_size, count, usecs, bps); - fflush(stdout); - } + dst = malloc(object_size); + igt_assert(dst); } - for (c = cache; c->level != -1; c++) { - igt_subtest(c->name) { - gem_set_caching(fd, dst, c->level); - - for (count = 1; count <= 1<<17; count <<= 1) { - struct timeval start, end; - - gettimeofday(&start, NULL); - do_gem_read(fd, dst, src, object_size, count); - gettimeofday(&end, NULL); - usecs = elapsed(&start, &end, count); - bps = bytes_per_sec(buf, object_size/usecs*1e6); - igt_info("Time to %s pread %d bytes x %6d: %7.3fµs, %s\n", - c->name, object_size, count, usecs, bps); - fflush(stdout); + for (m = modes; m->bo_create != NULL; m++) { + igt_subtest_group { + const struct { + int level; + const char *name; + } cache[] = { + { 0, "uncached" }, + { 1, "snoop" }, + { 2, "display" }, + { -1 }, + }, *c; + + igt_fixture + handle = m->bo_create(fd, object_size); + + igt_subtest_f("%sbasic", m->prefix) + do_read_loop(fd, "basic", handle, dst, + object_size); + + for (c = cache; c->level != -1; c++) { + igt_subtest_f("%s%s", m->prefix, c->name) { + gem_set_caching(fd, handle, c->level); + do_read_loop(fd, c->name, handle, dst, + object_size); + } } + + igt_fixture + gem_close(fd, handle); } } igt_fixture { - free(src); - gem_close(fd, dst); - + free(dst); close(fd); }