From patchwork Thu Oct 12 22:30:43 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: 10003049 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 013CC6028A for ; Thu, 12 Oct 2017 22:31:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E515328F19 for ; Thu, 12 Oct 2017 22:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E27C528F14; Thu, 12 Oct 2017 22:31:01 +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 D9FAB28F28 for ; Thu, 12 Oct 2017 22:31:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DCB06E99B; Thu, 12 Oct 2017 22:31:00 +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 0003E6E99A for ; Thu, 12 Oct 2017 22:30:58 +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:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,368,1503385200"; d="scan'208";a="137946045" Received: from relo-linux-1.fm.intel.com ([10.1.27.112]) by orsmga004.jf.intel.com with ESMTP; 12 Oct 2017 15:30:58 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Thu, 12 Oct 2017 15:30:43 -0700 Message-Id: <1507847444-3593-4-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 3/4] test/gem_pwrite: test writes to 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 writes to an object not backed by struct page. These reads use different paths in the kernel. Suggested-by: Chris Wilson Signed-off-by: Daniele Ceraolo Spurio Cc: Chris Wilson --- tests/gem_pwrite.c | 167 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 39 deletions(-) diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c index 1c3d23d..8e24c4b 100644 --- a/tests/gem_pwrite.c +++ b/tests/gem_pwrite.c @@ -26,6 +26,7 @@ */ #include "igt.h" +#include "igt_vgem.h" #include #include #include @@ -79,6 +80,93 @@ static const char *bytes_per_sec(char *buf, double v) return buf; } +static void do_write_loop(int fd, const char *name, uint32_t handle, + uint32_t *src, int size, int count) +{ + double usecs; + char buf[100]; + const char* bps; + struct timeval start, end; + + gettimeofday(&start, NULL); + do_gem_write(fd, handle, src, size, count); + gettimeofday(&end, NULL); + usecs = elapsed(&start, &end, count); + bps = bytes_per_sec(buf, size/usecs*1e6); + igt_info("Time to %s pwrite %d bytes x %6d:\t%7.3fµs, %s\n", + name, size, count, usecs, bps); + fflush(stdout); +} + +static void test_i915_bo(int fd, const char *name, uint32_t handle, + uint32_t *src, int size) +{ + unsigned i, count; + + for (count = 1; count <= 1<<17; count <<= 1) { + uint32_t *ptr = gem_mmap__cpu(fd, handle, 0, size, PROT_WRITE); + gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); + memset(ptr, 0, size); + munmap(ptr, size); + + do_write_loop(fd, name, handle, src, size, count); + + ptr = gem_mmap__cpu(fd, handle, 0, size, PROT_READ); + gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); + + for (i = 0; i < size / 4096; i++) + igt_assert_eq(ptr[i * 1024], i); + } +} + +struct foreign_bo { + int vgem_fd; + struct vgem_bo bo; + uint32_t handle; +}; + +static struct foreign_bo create_foreign_bo(int fd, uint32_t size) +{ + struct foreign_bo f_bo; + + f_bo.vgem_fd = drm_open_driver(DRIVER_VGEM); + + f_bo.bo.width = 1024; + f_bo.bo.height = size / 4096; + f_bo.bo.bpp = 32; + f_bo.handle = vgem_create_and_import(f_bo.vgem_fd, &f_bo.bo, fd, NULL); + igt_assert_eq(size, f_bo.bo.size); + + return f_bo; +} + +static void destroy_foreign_bo(int fd, struct foreign_bo *f_bo) +{ + gem_close(fd, f_bo->handle); + gem_close(f_bo->vgem_fd, f_bo->bo.handle); + close(f_bo->vgem_fd); +} + +static void test_foreign_bo(int fd, const char *name, struct foreign_bo *f_bo, + uint32_t *src, int size) +{ + unsigned i, count; + + for (count = 1; count <= 1<<17; count <<= 1) { + uint32_t *ptr = vgem_mmap(f_bo->vgem_fd, &f_bo->bo, PROT_WRITE); + memset(ptr, 0, size); + munmap(ptr, size); + + do_write_loop(fd, name, f_bo->handle, src, size, count); + + ptr = vgem_mmap(f_bo->vgem_fd, &f_bo->bo, PROT_READ); + gem_set_domain(fd, f_bo->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); + + for (i = 0; i < size / 4096; i++) + igt_assert_eq(ptr[i * 1024], i); + } +} + #define FORWARD 0x1 #define BACKWARD 0x2 #define RANDOM 0x4 @@ -205,16 +293,11 @@ static void test_big_gtt(int fd, int scale, unsigned flags) gem_close(fd, handle); } -uint32_t *src, dst; -int fd; - int main(int argc, char **argv) { + int fd; + uint32_t *src; int object_size = 0; - double usecs; - const char* bps; - char buf[100]; - int count; const struct { int level; const char *name; @@ -236,50 +319,56 @@ int main(int argc, char **argv) object_size = (object_size + 3) & -4; igt_fixture { + unsigned i = 0; fd = drm_open_driver(DRIVER_INTEL); - - dst = gem_create(fd, object_size); src = malloc(object_size); + igt_assert(src); + + for (i = 0; i < object_size / 4096; i++) + ((uint32_t *)src)[i * 1024] = i; } - igt_subtest("basic") { - for (count = 1; count <= 1<<17; count <<= 1) { - struct timeval start, end; - - gettimeofday(&start, NULL); - do_gem_write(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 pwrite %d bytes x %6d: %7.3fµs, %s\n", - object_size, count, usecs, bps); - fflush(stdout); + igt_subtest_group { + uint32_t handle; + igt_fixture + handle = gem_create(fd, object_size); + + igt_subtest("basic") + test_i915_bo(fd, "basic", handle, src, object_size); + + for (c = cache; c->level != -1; c++) { + igt_subtest(c->name) { + gem_set_caching(fd, handle, c->level); + test_i915_bo(fd, c->name, handle, src, object_size); + } } + + igt_fixture + gem_close(fd, handle); } - 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_write(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 pwrite %d bytes x %6d: %7.3fµs, %s\n", - c->name, object_size, count, usecs, bps); - fflush(stdout); + igt_subtest_group { + struct foreign_bo f_bo; + + igt_fixture + f_bo = create_foreign_bo(fd, object_size); + + igt_subtest("foreign-bo-basic") + test_foreign_bo(fd, "basic", &f_bo, src, object_size); + + for (c = cache; c->level != -1; c++) { + igt_subtest_f("foreign-bo-%s", c->name) { + gem_set_caching(fd, f_bo.handle, c->level); + test_foreign_bo(fd, c->name, &f_bo, src, object_size); } } + + igt_fixture + destroy_foreign_bo(fd, &f_bo); } - igt_fixture { + igt_fixture free(src); - gem_close(fd, dst); - } { const struct mode {