public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-05-13 11:53 [PATCH 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
@ 2015-05-13 11:53 ` ankitprasad.r.sharma
  0 siblings, 0 replies; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-05-13 11:53 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This patch adds support to verify pread/pwrite for non-shmem backed
objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faults

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
---
 tests/gem_pread.c  | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/gem_pwrite.c |  45 ++++++++++++++++++++++++
 2 files changed, 145 insertions(+)

diff --git a/tests/gem_pread.c b/tests/gem_pread.c
index cc83948..95162d5 100644
--- a/tests/gem_pread.c
+++ b/tests/gem_pread.c
@@ -41,6 +41,10 @@
 #include "drmtest.h"
 
 #define OBJECT_SIZE 16384
+#define LARGE_OBJECT_SIZE 1024 * 1024
+#define KGRN "\x1B[32m"
+#define KRED "\x1B[31m"
+#define KNRM "\x1B[0m"
 
 static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
 {
@@ -76,11 +80,14 @@ static const char *bytes_per_sec(char *buf, double v)
 
 
 uint32_t *src, dst;
+uint32_t *dst_user, src_stolen, large_stolen;
+uint32_t *stolen_pf_user, *stolen_nopf_user;
 int fd, count;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
+	int large_obj_size = LARGE_OBJECT_SIZE;
 	uint32_t buf[20];
 	const struct {
 		int level;
@@ -90,6 +97,9 @@ int main(int argc, char **argv)
 		{ 1, "snoop" },
 		{ 2, "display" },
 		{ -1 },
+		{ -1, "stolen-uncached"},
+		{ -1, "stolen-snoop"},
+		{ -1, "stolen-display"},
 	}, *c;
 
 	igt_subtest_init(argc, argv);
@@ -106,6 +116,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		src_stolen = gem_create_stolen(fd, object_size);
+		dst_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -142,9 +154,97 @@ int main(int argc, char **argv)
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, src_stolen, dst_user, object_size, count);
+			gettimeofday(&end, NULL);
+			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
+				 object_size, count,
+				 elapsed(&start, &end, count),
+				 bytes_per_sec((char *)buf,
+				 object_size/elapsed(&start, &end, count)*1e6));
+			fflush(stdout);
+		}
+	}
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest((c + 4)->name) {
+			gem_set_caching(fd, src_stolen, c->level);
+
+			for (count = 1; count <= 1<<17; count <<= 1) {
+				struct timeval start, end;
+
+				gettimeofday(&start, NULL);
+				do_gem_read(fd, src_stolen, dst_user,
+					    object_size, count);
+				gettimeofday(&end, NULL);
+				igt_info("Time to %s pread %d bytes x %6d:      %7.3fµs, %s\n",
+					 (c + 4)->name, object_size, count,
+					 elapsed(&start, &end, count),
+					 bytes_per_sec((char *)buf,
+					 object_size/elapsed(&start, &end, count)*1e6));
+				fflush(stdout);
+			}
+		}
+	}
+
+	/* List pread times for stolen area with 1 page fault (page fault only
+	 * first time) and multiple page faults (unmapping the pages at the
+	 * end of each iteration)
+	 */
+	igt_subtest("pagefault-pread") {
+		large_stolen = gem_create_stolen(fd, large_obj_size);
+		stolen_nopf_user = (uint32_t *) mmap(NULL, large_obj_size,
+						PROT_WRITE,
+						MAP_ANONYMOUS|MAP_PRIVATE,
+						-1, 0);
+
+		for (count = 1; count <= 10; count ++) {
+			struct timeval start, end;
+			uint32_t t_elapsed = 0;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_nopf_user,
+				    large_obj_size, 1);
+			gettimeofday(&end, NULL);
+			t_elapsed = elapsed(&start, &end, 1);
+			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
+				 large_obj_size,
+				 elapsed(&start, &end, 1),
+				 bytes_per_sec((char *)buf,
+				 large_obj_size/elapsed(&start, &end, 1)*1e6));
+
+			stolen_pf_user = (uint32_t *) mmap(NULL, large_obj_size,
+						      PROT_WRITE,
+						      MAP_ANONYMOUS|MAP_PRIVATE,
+						      -1, 0);
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_pf_user,
+				    large_obj_size, 1);
+			gettimeofday(&end, NULL);
+			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
+				 large_obj_size,
+				 elapsed(&start, &end, 1),
+				 t_elapsed < elapsed(&start, &end, 1) ? KGRN : KRED,
+				 bytes_per_sec((char *)buf,
+				 large_obj_size/elapsed(&start, &end, 1)*1e6),
+				 KNRM);
+			fflush(stdout);
+			munmap(stolen_pf_user, large_obj_size);
+		}
+			munmap(stolen_nopf_user, large_obj_size);
+			gem_close(fd, large_stolen);
+	}
+
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(dst_user);
+		gem_close(fd, src_stolen);
 
 		close(fd);
 	}
diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
index 6378b0a..dd1ca95 100644
--- a/tests/gem_pwrite.c
+++ b/tests/gem_pwrite.c
@@ -82,6 +82,7 @@ static const char *bytes_per_sec(char *buf, double v)
 
 
 uint32_t *src, dst;
+uint32_t *src_user, dst_stolen;
 int fd;
 
 int main(int argc, char **argv)
@@ -97,6 +98,9 @@ int main(int argc, char **argv)
 		{ 1, "snoop" },
 		{ 2, "display" },
 		{ -1 },
+		{ -1, "stolen-uncached"},
+		{ -1, "stolen-snoop"},
+		{ -1, "stolen-display"},
 	}, *c;
 
 	igt_skip_on_simulation();
@@ -114,6 +118,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		dst_stolen = gem_create_stolen(fd, object_size);
+		src_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -150,9 +156,48 @@ int main(int argc, char **argv)
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_write(fd, dst_stolen, src_user,
+				     object_size, count);
+			gettimeofday(&end, NULL);
+			igt_info("Time to pwrite %d bytes x %6d:        %7.3fµs, %s\n",
+				 object_size, count,
+				 elapsed(&start, &end, count),
+				 bytes_per_sec((char *)buf,
+				 object_size/elapsed(&start, &end, count)*1e6));
+			fflush(stdout);
+		}
+	}
+
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest((c + 4)->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_stolen, src_user,
+					     object_size, count);
+				gettimeofday(&end, NULL);
+				igt_info("Time to %s pwrite %d bytes x %6d:     %7.3fµs, %s\n",
+					 (c + 4)->name, object_size, count,
+					 elapsed(&start, &end, count),
+					 bytes_per_sec((char *)buf,
+					 object_size/elapsed(&start, &end, count)*1e6));
+				fflush(stdout);
+			}
+		}
+	}
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(src_user);
+		gem_close(fd, dst_stolen);
 
 		close(fd);
 	}
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 0/3] Tests for verifying the old and extended GEM_CREATE ioctl
@ 2015-07-01  9:26 ankitprasad.r.sharma
  2015-07-01  9:26 ` [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl ankitprasad.r.sharma
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-07-01  9:26 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This new set of tests verifies the old and the new extended GEM_CREATE ioctl
gem_stolen tries to verify the new extended GEM_CREATE ioctl, which tries to
create an object backed by stolen memory and performs basic operations on it.
It verifies the creation as well as the purging of an object when it is no
longer needed, copying contents of a stolen backed object to another, doing
a pread/pwrite on the object and verifying its contents.

We also try to pread/pwrite a stolen backed object multiple times to get the
pread/pwrite speed, as well as pread speed when there is a page fault while
accessing userspace buffer.

There is a new test gem_create to do a sanity check for creating both
stolen/shmem backed objects with valid and invalid parameters.

v2: Rebased to the latest and added IGT_TEST_DESCRIPTION

Ankitprasad Sharma (3):
  igt/gem_stolen: Verifying extended gem_create ioctl
  igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  igt/gem_create: Test to validate parameters for GEM_CREATE ioctl

 lib/ioctl_wrappers.c   |  59 ++++++++
 lib/ioctl_wrappers.h   |  12 ++
 tests/Makefile.sources |   2 +
 tests/gem_create.c     | 181 ++++++++++++++++++++++++
 tests/gem_pread.c      | 100 ++++++++++++++
 tests/gem_pwrite.c     |  45 ++++++
 tests/gem_stolen.c     | 363 +++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 762 insertions(+)
 create mode 100644 tests/gem_create.c
 create mode 100644 tests/gem_stolen.c

-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl
  2015-07-01  9:26 [PATCH v2 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
@ 2015-07-01  9:26 ` ankitprasad.r.sharma
  2015-07-03  9:05   ` Tvrtko Ursulin
  2015-07-01  9:26 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
  2015-07-01  9:26 ` [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl ankitprasad.r.sharma
  2 siblings, 1 reply; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-07-01  9:26 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This patch adds the testcases for verifying the new extended
gem_create ioctl. By means of this extended ioctl, memory
placement of the GEM object can be specified, i.e. either
shmem or stolen memory.
These testcases include functional tests and interface tests for
testing the gem_create ioctl call for stolen memory placement

v2: Testing pread/pwrite functionality for stolen backed objects,
added local struct for extended gem_create and gem_get_aperture,
until headers catch up (Chris)

v3: Removed get_aperture related functions, extended gem_pread
to compare speeds for user pages with and without page faults,
unexposed local_gem_create struct, changed gem_create_stolen
usage (Chris)

v4: Splitting patch to remove changes from gem_pread/gem_pwrite
to another patch (Ankit)

v5: Rebased to the latest (Ankit)
    Added IGT_TEST_DESCRIPTION (Thomas Wood)

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 lib/ioctl_wrappers.c   |  59 ++++++++
 lib/ioctl_wrappers.h   |  12 ++
 tests/Makefile.sources |   1 +
 tests/gem_stolen.c     | 363 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 435 insertions(+)
 create mode 100644 tests/gem_stolen.c

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index a269d0f..0e868eb 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -389,6 +389,65 @@ void gem_sync(int fd, uint32_t handle)
 		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 }
 
+bool gem_create__has_stolen_support(int fd)
+{
+	static int has_stolen_support = -1;
+	struct drm_i915_getparam gp;
+	int val = -1;
+
+	if (has_stolen_support < 0) {
+		memset(&gp, 0, sizeof(gp));
+		gp.param = 36; /* CREATE_VERSION */
+		gp.value = &val;
+
+		/* Do we have the extended gem_create_ioctl? */
+		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+		has_stolen_support = val >= 1;
+	}
+
+	return has_stolen_support;
+}
+
+struct local_i915_gem_create_v2 {
+	uint64_t size;
+	uint32_t handle;
+	uint32_t pad;
+#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
+	uint32_t flags;
+};
+
+#define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
+/**
+ * gem_create_stolen:
+ * @fd: open i915 drm file descriptor
+ * @size: desired size of the buffer
+ * @flags: desired placement i.e. stolen or shmem
+ *
+ * This wraps the new GEM_CREATE ioctl, which allocates a
+ * new gem buffer object of @size and placement based on @flags.
+ *
+ * Returns: The file-private handle of the created buffer object
+ */
+
+uint32_t gem_create_stolen(int fd, int size)
+{
+	struct local_i915_gem_create_v2 create;
+	int ret;
+
+	memset(&create, 0, sizeof(create));
+	create.handle = 0;
+	create.size = size;
+	create.flags = I915_CREATE_PLACEMENT_STOLEN;
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+
+	if (ret < 0)
+		return 0;
+
+	errno = 0;
+	return create.handle;
+}
+
+
 uint32_t __gem_create(int fd, int size)
 {
 	struct drm_i915_gem_create create;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index bc5d4bd..bff5135 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -56,6 +56,8 @@ void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t leng
 void gem_set_domain(int fd, uint32_t handle,
 		    uint32_t read_domains, uint32_t write_domain);
 void gem_sync(int fd, uint32_t handle);
+bool gem_create__has_stolen_support(int fd);
+uint32_t gem_create_stolen(int fd, int size);
 uint32_t __gem_create(int fd, int size);
 uint32_t gem_create(int fd, uint64_t size);
 void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
@@ -67,6 +69,16 @@ bool gem_mmap__has_wc(int fd);
 void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
 
 /**
+ * gem_require_stolen_support:
+ * @fd: open i915 drm file descriptor
+ *
+ * Test macro to query whether support for allocating objects from stolen
+ * memory is available. Automatically skips through igt_require() if not.
+ */
+#define gem_require_stolen_support(fd) \
+			igt_require(gem_create__has_stolen_support(fd))
+
+/**
  * gem_require_mmap_wc:
  * @fd: open i915 drm file descriptor
  *
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index b9479cc..324cbb5 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -55,6 +55,7 @@ TESTS_progs_M = \
 	gem_reset_stats \
 	gem_ringfill \
 	gem_set_tiling_vs_blt \
+	gem_stolen \
 	gem_storedw_batches_loop \
 	gem_streaming_writes \
 	gem_tiled_blits \
diff --git a/tests/gem_stolen.c b/tests/gem_stolen.c
new file mode 100644
index 0000000..9caaefd
--- /dev/null
+++ b/tests/gem_stolen.c
@@ -0,0 +1,363 @@
+/*
+ * Copyright © 2011 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:
+ *    Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
+ *
+ */
+
+/** @file gem_create_stolen.c
+ *
+ * This is a test for the extended gem_create ioctl, that includes allocation
+ * of object from stolen memory
+ *
+ * The goal is to simply ensure the basics work, and invalid input combinations
+ * are rejected.
+ */
+
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <getopt.h>
+
+#include <drm.h>
+
+#include "ioctl_wrappers.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_io.h"
+#include "intel_chipset.h"
+#include "igt_aux.h"
+#include "drmtest.h"
+#include "drm.h"
+#include "i915_drm.h"
+
+IGT_TEST_DESCRIPTION("This test verifies the exetended gem_create ioctl,"
+		     " that includes allocation of obj from stolen region");
+#define CLEAR(s) memset(&s, 0, sizeof(s))
+#define SIZE 1024*1024
+
+static struct drm_intel_bufmgr *bufmgr;
+static struct intel_batchbuffer *batch;
+
+static void verify_copy_op(drm_intel_bo *src, drm_intel_bo *dest)
+{
+	uint32_t *virt, i, ret;
+	/* Fill the src BO with dwords */
+	ret = drm_intel_gem_bo_map_gtt(src);
+	igt_assert(!ret);
+
+	virt = src->virtual;
+	for (i = 0; i < SIZE/4; i++)
+		virt[i] = i;
+
+	intel_copy_bo(batch, dest, src, SIZE);
+
+	ret = drm_intel_gem_bo_map_gtt(dest);
+	igt_assert(!ret);
+
+	virt = dest->virtual;
+	/* verify */
+	for (i = 0; i < SIZE/4; i++) {
+		if (virt[i] != i) {
+			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
+					"at offset 0x%08x\n",
+					i, virt[i], i * 4);
+			igt_assert(virt[i] == i);
+		}
+	}
+
+	drm_intel_bo_unmap(src);
+	drm_intel_bo_unmap(dest);
+}
+
+static void stolen_pwrite(int fd)
+{
+	drm_intel_bo *bo;
+	uint32_t buf[SIZE/4];
+	uint32_t handle = 0;
+	uint32_t *virt;
+	int i, ret = 0;
+
+	for (i = 0; i < SIZE/4; i ++)
+		buf[i] = 0xdead;
+
+	gem_require_stolen_support(fd);
+
+	handle = gem_create_stolen(fd, SIZE);
+	igt_assert(handle != 0);
+
+	gem_write(fd, handle, 0, buf, SIZE);
+	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "bo", handle);
+
+	ret = drm_intel_gem_bo_map_gtt(bo);
+	igt_assert(!ret);
+
+	virt = bo->virtual;
+
+	for (i = 0; i < SIZE/4; i ++)
+		igt_assert(virt[i] == 0xdead);
+
+	drm_intel_bo_unmap(bo);
+	drm_intel_bo_unreference(bo);
+	gem_close(fd, handle);
+}
+
+static void stolen_pread(int fd)
+{
+	drm_intel_bo *bo;
+	uint32_t buf[SIZE/4];
+	uint32_t handle = 0;
+	uint32_t *virt;
+	int i, ret = 0;
+
+	CLEAR(buf);
+
+	gem_require_stolen_support(fd);
+
+	handle = gem_create_stolen(fd, SIZE);
+	igt_assert(handle != 0);
+
+	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "bo", handle);
+
+	ret = drm_intel_gem_bo_map_gtt(bo);
+	igt_assert(!ret);
+
+	virt = bo->virtual;
+
+	for (i = 0; i < SIZE/4; i ++)
+		virt[i] = 0xdead;
+
+	drm_intel_bo_unmap(bo);
+	drm_intel_bo_unreference(bo);
+
+	gem_read(fd, handle, 0, buf, SIZE);
+
+	for (i = 0; i < SIZE/4; i ++)
+		igt_assert(buf[i] == 0xdead);
+
+	gem_close(fd, handle);
+}
+
+static void copy_test(int fd)
+{
+	drm_intel_bo *src, *dest;
+	uint32_t src_handle = 0, dest_handle = 0;
+	int ret = 0;
+
+	gem_require_stolen_support(fd);
+
+	src_handle = gem_create_stolen(fd, SIZE);
+	igt_assert(src_handle != 0);
+
+	dest_handle = gem_create_stolen(fd, SIZE);
+	igt_assert(dest_handle != 0);
+
+	src = gem_handle_to_libdrm_bo(bufmgr, fd, "src_bo", src_handle);
+	dest = gem_handle_to_libdrm_bo(bufmgr, fd, "dst_bo", dest_handle);
+
+	igt_assert(src != NULL);
+	igt_assert(dest != NULL);
+
+	verify_copy_op(src, dest);
+
+	drm_intel_bo_unreference(src);
+	drm_intel_bo_unreference(dest);
+	gem_close(fd, src_handle);
+	gem_close(fd, dest_handle);
+}
+
+static void verify_object_clear(int fd)
+{
+	drm_intel_bo *bo;
+	uint32_t handle = 0;
+	uint32_t *virt;
+	int i, ret = 0;
+
+	gem_require_stolen_support(fd);
+
+	handle = gem_create_stolen(fd, SIZE);
+	igt_assert(handle != 0);
+
+	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "verify_bo", handle);
+	igt_assert(bo != NULL);
+
+	ret = drm_intel_gem_bo_map_gtt(bo);
+	igt_assert(ret == 0);
+
+	/* Verify if the BO is zeroed */
+	virt = bo->virtual;
+	for (i = 0; i < SIZE / 4; i++)
+		igt_assert(virt[i] == 0);
+
+	drm_intel_bo_unmap(bo);
+	drm_intel_bo_unreference(bo);
+	gem_close(fd, handle);
+}
+
+static void stolen_fill_purge_test(int fd)
+{
+	drm_intel_bo *bo;
+	int mret = 0, ret = 0, obj_count = 0, i = 0;
+	int _ret = 0, j = 0;
+	uint32_t handle[100] = {0};
+	uint32_t new_handle = 0;
+	uint32_t *virt;
+	int retained = 0;
+
+	gem_require_stolen_support(fd);
+
+	/* Exhaust Stolen space */
+	while(ret == 0) {
+		ret = -1;
+		handle[i] = gem_create_stolen(fd, SIZE);
+		if (handle[i] != 0) {
+			ret = 0;
+			bo = gem_handle_to_libdrm_bo(bufmgr, fd,
+						     "verify_bo", handle[i]);
+			igt_assert(bo != NULL);
+
+			_ret = drm_intel_gem_bo_map_gtt(bo);
+			igt_assert(_ret == 0);
+
+			virt = bo->virtual;
+			for (j = 0; j < SIZE / 4; j++)
+				virt[j] = 0xab;
+
+			drm_intel_bo_unmap(bo);
+			drm_intel_bo_unreference(bo);
+
+			obj_count++;
+		}
+
+		i++;
+	}
+
+	igt_assert(obj_count > 0);
+
+	/* Mark all stolen objects purgeable */
+	for (i = 0; i < obj_count; i++)
+		retained = gem_madvise(fd, handle[i], I915_MADV_DONTNEED);
+
+	/* Try to allocate one more object */
+	new_handle = gem_create_stolen(fd, SIZE);
+	igt_assert(new_handle != 0);
+
+	/* Check if the retained object's memory contents are intact */
+	for (i = 0; i < obj_count; i++) {
+		retained = gem_madvise(fd, handle[i], I915_MADV_WILLNEED);
+		if (retained) {
+			bo = gem_handle_to_libdrm_bo(bufmgr, fd,
+						     "verify_bo", handle[i]);
+			igt_assert(bo != NULL);
+
+			_ret = drm_intel_gem_bo_map_gtt(bo);
+			igt_assert(_ret == 0);
+
+			virt = bo->virtual;
+			for (j = 0; j < SIZE / 4; j++)
+				igt_assert(virt[j] == 0xab);
+
+			drm_intel_bo_unmap(bo);
+			drm_intel_bo_unreference(bo);
+		}
+	}
+
+	gem_close(fd, new_handle);
+	for (i = 0; i < obj_count; i++)
+		gem_close(fd, handle[i]);
+}
+
+static void
+stolen_no_mmap(int fd)
+{
+	void *addr;
+	uint32_t handle = 0;
+
+	gem_require_stolen_support(fd);
+
+	handle = gem_create_stolen(fd, SIZE);
+	igt_assert(handle != 0);
+
+	addr = gem_mmap__cpu(fd, handle, 0, SIZE, PROT_READ | PROT_WRITE);
+	igt_assert(addr == NULL);
+
+	gem_close(fd, handle);
+}
+
+igt_main
+{
+	int i, fd, gtt_size_total, gtt_size_mappable;
+	uint32_t devid;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		drm_intel_get_aperture_sizes(fd, (size_t*)&gtt_size_total,
+				(size_t*)&gtt_size_mappable);
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+	}
+
+	igt_subtest("stolen-clear")
+		verify_object_clear(fd);
+
+	/*
+	 * stolen mem special cases - checking for non cpu mappable
+	 */
+	igt_subtest("stolen-no-mmap")
+		stolen_no_mmap(fd);
+
+	/* checking for pread/pwrite interfaces */
+	igt_subtest("stolen-pwrite")
+		stolen_pwrite(fd);
+
+	igt_subtest("stolen-pread")
+		stolen_pread(fd);
+
+	/* Functional Test - blt copy */
+	igt_subtest("stolen-copy")
+		copy_test(fd);
+
+	/* Filling stolen completely and marking all the objects
+	 * purgeable. Then trying to add one more object, to verify
+	 * the purging logic.
+	 * Again marking all objects WILLNEED and verifying the
+	 * contents of the retained objects.
+	 */
+	igt_subtest("stolen-fill-purge")
+		stolen_fill_purge_test(fd);
+
+	igt_fixture {
+		intel_batchbuffer_free(batch);
+		drm_intel_bufmgr_destroy(bufmgr);
+	}
+}
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-01  9:26 [PATCH v2 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
  2015-07-01  9:26 ` [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl ankitprasad.r.sharma
@ 2015-07-01  9:26 ` ankitprasad.r.sharma
  2015-07-03  9:37   ` Tvrtko Ursulin
  2015-07-01  9:26 ` [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl ankitprasad.r.sharma
  2 siblings, 1 reply; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-07-01  9:26 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This patch adds support to verify pread/pwrite for non-shmem backed
objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faults

v2: Rebased to the latest (Ankit)

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 tests/gem_pread.c  | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/gem_pwrite.c |  45 ++++++++++++++++++++++++
 2 files changed, 145 insertions(+)

diff --git a/tests/gem_pread.c b/tests/gem_pread.c
index cc83948..95162d5 100644
--- a/tests/gem_pread.c
+++ b/tests/gem_pread.c
@@ -41,6 +41,10 @@
 #include "drmtest.h"
 
 #define OBJECT_SIZE 16384
+#define LARGE_OBJECT_SIZE 1024 * 1024
+#define KGRN "\x1B[32m"
+#define KRED "\x1B[31m"
+#define KNRM "\x1B[0m"
 
 static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
 {
@@ -76,11 +80,14 @@ static const char *bytes_per_sec(char *buf, double v)
 
 
 uint32_t *src, dst;
+uint32_t *dst_user, src_stolen, large_stolen;
+uint32_t *stolen_pf_user, *stolen_nopf_user;
 int fd, count;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
+	int large_obj_size = LARGE_OBJECT_SIZE;
 	uint32_t buf[20];
 	const struct {
 		int level;
@@ -90,6 +97,9 @@ int main(int argc, char **argv)
 		{ 1, "snoop" },
 		{ 2, "display" },
 		{ -1 },
+		{ -1, "stolen-uncached"},
+		{ -1, "stolen-snoop"},
+		{ -1, "stolen-display"},
 	}, *c;
 
 	igt_subtest_init(argc, argv);
@@ -106,6 +116,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		src_stolen = gem_create_stolen(fd, object_size);
+		dst_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -142,9 +154,97 @@ int main(int argc, char **argv)
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, src_stolen, dst_user, object_size, count);
+			gettimeofday(&end, NULL);
+			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
+				 object_size, count,
+				 elapsed(&start, &end, count),
+				 bytes_per_sec((char *)buf,
+				 object_size/elapsed(&start, &end, count)*1e6));
+			fflush(stdout);
+		}
+	}
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest((c + 4)->name) {
+			gem_set_caching(fd, src_stolen, c->level);
+
+			for (count = 1; count <= 1<<17; count <<= 1) {
+				struct timeval start, end;
+
+				gettimeofday(&start, NULL);
+				do_gem_read(fd, src_stolen, dst_user,
+					    object_size, count);
+				gettimeofday(&end, NULL);
+				igt_info("Time to %s pread %d bytes x %6d:      %7.3fµs, %s\n",
+					 (c + 4)->name, object_size, count,
+					 elapsed(&start, &end, count),
+					 bytes_per_sec((char *)buf,
+					 object_size/elapsed(&start, &end, count)*1e6));
+				fflush(stdout);
+			}
+		}
+	}
+
+	/* List pread times for stolen area with 1 page fault (page fault only
+	 * first time) and multiple page faults (unmapping the pages at the
+	 * end of each iteration)
+	 */
+	igt_subtest("pagefault-pread") {
+		large_stolen = gem_create_stolen(fd, large_obj_size);
+		stolen_nopf_user = (uint32_t *) mmap(NULL, large_obj_size,
+						PROT_WRITE,
+						MAP_ANONYMOUS|MAP_PRIVATE,
+						-1, 0);
+
+		for (count = 1; count <= 10; count ++) {
+			struct timeval start, end;
+			uint32_t t_elapsed = 0;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_nopf_user,
+				    large_obj_size, 1);
+			gettimeofday(&end, NULL);
+			t_elapsed = elapsed(&start, &end, 1);
+			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
+				 large_obj_size,
+				 elapsed(&start, &end, 1),
+				 bytes_per_sec((char *)buf,
+				 large_obj_size/elapsed(&start, &end, 1)*1e6));
+
+			stolen_pf_user = (uint32_t *) mmap(NULL, large_obj_size,
+						      PROT_WRITE,
+						      MAP_ANONYMOUS|MAP_PRIVATE,
+						      -1, 0);
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_pf_user,
+				    large_obj_size, 1);
+			gettimeofday(&end, NULL);
+			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
+				 large_obj_size,
+				 elapsed(&start, &end, 1),
+				 t_elapsed < elapsed(&start, &end, 1) ? KGRN : KRED,
+				 bytes_per_sec((char *)buf,
+				 large_obj_size/elapsed(&start, &end, 1)*1e6),
+				 KNRM);
+			fflush(stdout);
+			munmap(stolen_pf_user, large_obj_size);
+		}
+			munmap(stolen_nopf_user, large_obj_size);
+			gem_close(fd, large_stolen);
+	}
+
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(dst_user);
+		gem_close(fd, src_stolen);
 
 		close(fd);
 	}
diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
index 5b6a77f..c7e3edf 100644
--- a/tests/gem_pwrite.c
+++ b/tests/gem_pwrite.c
@@ -135,6 +135,7 @@ static void test_big_gtt(int fd, int scale)
 }
 
 uint32_t *src, dst;
+uint32_t *src_user, dst_stolen;
 int fd;
 
 int main(int argc, char **argv)
@@ -150,6 +151,9 @@ int main(int argc, char **argv)
 		{ 1, "snoop" },
 		{ 2, "display" },
 		{ -1 },
+		{ -1, "stolen-uncached"},
+		{ -1, "stolen-snoop"},
+		{ -1, "stolen-display"},
 	}, *c;
 
 	igt_skip_on_simulation();
@@ -167,6 +171,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		dst_stolen = gem_create_stolen(fd, object_size);
+		src_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -203,9 +209,48 @@ int main(int argc, char **argv)
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_write(fd, dst_stolen, src_user,
+				     object_size, count);
+			gettimeofday(&end, NULL);
+			igt_info("Time to pwrite %d bytes x %6d:        %7.3fµs, %s\n",
+				 object_size, count,
+				 elapsed(&start, &end, count),
+				 bytes_per_sec((char *)buf,
+				 object_size/elapsed(&start, &end, count)*1e6));
+			fflush(stdout);
+		}
+	}
+
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest((c + 4)->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_stolen, src_user,
+					     object_size, count);
+				gettimeofday(&end, NULL);
+				igt_info("Time to %s pwrite %d bytes x %6d:     %7.3fµs, %s\n",
+					 (c + 4)->name, object_size, count,
+					 elapsed(&start, &end, count),
+					 bytes_per_sec((char *)buf,
+					 object_size/elapsed(&start, &end, count)*1e6));
+				fflush(stdout);
+			}
+		}
+	}
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(src_user);
+		gem_close(fd, dst_stolen);
 	}
 
 	igt_subtest("big-cpu")
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
  2015-07-01  9:26 [PATCH v2 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
  2015-07-01  9:26 ` [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl ankitprasad.r.sharma
  2015-07-01  9:26 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
@ 2015-07-01  9:26 ` ankitprasad.r.sharma
  2015-07-03  9:52   ` Tvrtko Ursulin
  2 siblings, 1 reply; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-07-01  9:26 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This test validates the two parameters (size and flags) GEM_CREATE ioctl.

v2: Added IGT_TEST_DESCRIPTION (Thomas Wood)

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 tests/Makefile.sources |   1 +
 tests/gem_create.c     | 181 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+)
 create mode 100644 tests/gem_create.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 324cbb5..f5790df 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -15,6 +15,7 @@ TESTS_progs_M = \
 	gem_close_race \
 	gem_concurrent_blit \
 	gem_concurrent_all \
+	gem_create \
 	gem_cs_tlb \
 	gem_ctx_param_basic \
 	gem_ctx_bad_exec \
diff --git a/tests/gem_create.c b/tests/gem_create.c
new file mode 100644
index 0000000..6581035
--- /dev/null
+++ b/tests/gem_create.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright © 2011 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:
+ *    Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
+ *
+ */
+
+/** @file gem_create.c
+ *
+ * This is a test for the extended and old gem_create ioctl, that
+ * includes allocation of object from stolen memory and shmem
+ *
+ * The goal is to simply ensure that basics work and invalid input
+ * combinations are rejected.
+ */
+
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <getopt.h>
+
+#include <drm.h>
+
+#include "ioctl_wrappers.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_io.h"
+#include "intel_chipset.h"
+#include "igt_aux.h"
+#include "drmtest.h"
+#include "drm.h"
+#include "i915_drm.h"
+
+IGT_TEST_DESCRIPTION("This is a test for the extended & old gem_create ioctl,"
+		     " that includes allocation of object from stolen memory"
+		     " and shmem");
+
+#define CLEAR(s) memset(&s, 0, sizeof(s))
+#define SIZE 2048
+#define OFFSET 3072
+
+static struct drm_intel_bufmgr *bufmgr;
+static struct intel_batchbuffer *batch;
+
+static void invalid_flag_test(int fd)
+{
+	int ret = 0;
+
+struct local_i915_gem_create_v2 {
+	uint64_t size;
+	uint32_t handle;
+	uint32_t pad;
+#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
+	uint32_t flags;
+} create;
+
+#define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
+	gem_require_stolen_support(fd);
+
+	create.handle = 0;
+	create.size = SIZE;
+	create.flags = ~I915_CREATE_PLACEMENT_STOLEN;
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+
+	igt_assert(ret <= 0);
+}
+
+static void invalid_size_test(int fd)
+{
+	int handle;
+
+	handle = __gem_create(fd, 0);
+	igt_assert(handle == 0);
+}
+
+/* Creating an object with non-aligned size and trying to access offset of
+ * value (size+x) & length y, where (size+x+y) <= object's last page boundary.
+ * pwrite here must be successful.
+ */
+static void valid_nonaligned_size(int fd)
+{
+	int handle, i;
+	uint32_t buf[1024];
+
+	for (i = 0; i < 1024; i ++)
+		buf[i] = 0xdead;
+
+	handle = gem_create(fd, SIZE);
+	igt_assert(handle != 0);
+
+	gem_write(fd, handle, OFFSET, buf, 256);
+
+	gem_close(fd, handle);
+}
+
+/* Creating an object with non-aligned size and trying to access offset of
+ * value (size+x) & length y, where (size+x+y) > object's last page boundary.
+ * pwrite here must result in failure.
+ */
+static void invalid_nonaligned_size(int fd)
+{
+	int handle, i;
+	uint32_t buf[1024];
+	struct drm_i915_gem_pwrite gem_pwrite;
+
+	for (i = 0; i < 1024; i ++)
+		buf[i] = 0xdead;
+
+	handle = gem_create(fd, SIZE);
+
+	CLEAR(gem_pwrite);
+	gem_pwrite.handle = handle;
+	gem_pwrite.offset = OFFSET;
+	/* Out of bound access */
+	gem_pwrite.size = 2048;
+	gem_pwrite.data_ptr = (uintptr_t)buf;
+	igt_assert(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) != 0);
+
+	gem_close(fd, handle);
+}
+
+igt_main
+{
+	int i, fd, gtt_size_total, gtt_size_mappable;
+	uint32_t devid;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		drm_intel_get_aperture_sizes(fd, (size_t*)&gtt_size_total,
+				(size_t*)&gtt_size_mappable);
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+	}
+
+	igt_subtest("stolen-invalid-flag")
+		invalid_flag_test(fd);
+
+	igt_subtest("stolen-invalid-size")
+		invalid_size_test(fd);
+
+	igt_subtest("stolen-valid-nonaligned")
+		valid_nonaligned_size(fd);
+
+	igt_subtest("stolen-invalid-nonaligned")
+		invalid_nonaligned_size(fd);
+
+	igt_fixture {
+		intel_batchbuffer_free(batch);
+		drm_intel_bufmgr_destroy(bufmgr);
+	}
+}
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl
  2015-07-01  9:26 ` [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl ankitprasad.r.sharma
@ 2015-07-03  9:05   ` Tvrtko Ursulin
  2015-07-03  9:16     ` Chris Wilson
  0 siblings, 1 reply; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-07-03  9:05 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath


On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This patch adds the testcases for verifying the new extended
> gem_create ioctl. By means of this extended ioctl, memory
> placement of the GEM object can be specified, i.e. either
> shmem or stolen memory.
> These testcases include functional tests and interface tests for
> testing the gem_create ioctl call for stolen memory placement
>
> v2: Testing pread/pwrite functionality for stolen backed objects,
> added local struct for extended gem_create and gem_get_aperture,
> until headers catch up (Chris)
>
> v3: Removed get_aperture related functions, extended gem_pread
> to compare speeds for user pages with and without page faults,
> unexposed local_gem_create struct, changed gem_create_stolen
> usage (Chris)
>
> v4: Splitting patch to remove changes from gem_pread/gem_pwrite
> to another patch (Ankit)
>
> v5: Rebased to the latest (Ankit)
>      Added IGT_TEST_DESCRIPTION (Thomas Wood)
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
>   lib/ioctl_wrappers.c   |  59 ++++++++
>   lib/ioctl_wrappers.h   |  12 ++
>   tests/Makefile.sources |   1 +
>   tests/gem_stolen.c     | 363 +++++++++++++++++++++++++++++++++++++++++++++++++
>   4 files changed, 435 insertions(+)
>   create mode 100644 tests/gem_stolen.c
>
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index a269d0f..0e868eb 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -389,6 +389,65 @@ void gem_sync(int fd, uint32_t handle)
>   		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
>   }
>
> +bool gem_create__has_stolen_support(int fd)
> +{
> +	static int has_stolen_support = -1;
> +	struct drm_i915_getparam gp;
> +	int val = -1;
> +
> +	if (has_stolen_support < 0) {
> +		memset(&gp, 0, sizeof(gp));
> +		gp.param = 36; /* CREATE_VERSION */
> +		gp.value = &val;
> +
> +		/* Do we have the extended gem_create_ioctl? */
> +		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
> +		has_stolen_support = val >= 1;

If ioctl fails it will declare stolen support. (val remains -1)

I would also suggest "has_stolen_support = val > 1" as clearer.

> +	}
> +
> +	return has_stolen_support;
> +}
> +
> +struct local_i915_gem_create_v2 {
> +	uint64_t size;
> +	uint32_t handle;
> +	uint32_t pad;
> +#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
> +	uint32_t flags;
> +};
> +
> +#define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
> +/**
> + * gem_create_stolen:
> + * @fd: open i915 drm file descriptor
> + * @size: desired size of the buffer
> + * @flags: desired placement i.e. stolen or shmem
> + *
> + * This wraps the new GEM_CREATE ioctl, which allocates a
> + * new gem buffer object of @size and placement based on @flags.
> + *
> + * Returns: The file-private handle of the created buffer object
> + */
> +
> +uint32_t gem_create_stolen(int fd, int size)
> +{

Why int for size?

> +	struct local_i915_gem_create_v2 create;
> +	int ret;
> +
> +	memset(&create, 0, sizeof(create));
> +	create.handle = 0;
> +	create.size = size;
> +	create.flags = I915_CREATE_PLACEMENT_STOLEN;
> +	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
> +
> +	if (ret < 0)
> +		return 0;
> +
> +	errno = 0;
> +	return create.handle;
> +}
> +
> +

Interestingly gem_create_stolen copies implementation from __gem_create 
and differs from normal gem_create in handling of ioctl failure. But it 
removes the double underscore from the name. I think this creates 
unnecessary inconsistency. It should either have double underscore 
prefix or copy implementation from gem_create.

>   uint32_t __gem_create(int fd, int size)
>   {
>   	struct drm_i915_gem_create create;
> diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
> index bc5d4bd..bff5135 100644
> --- a/lib/ioctl_wrappers.h
> +++ b/lib/ioctl_wrappers.h
> @@ -56,6 +56,8 @@ void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t leng
>   void gem_set_domain(int fd, uint32_t handle,
>   		    uint32_t read_domains, uint32_t write_domain);
>   void gem_sync(int fd, uint32_t handle);
> +bool gem_create__has_stolen_support(int fd);
> +uint32_t gem_create_stolen(int fd, int size);
>   uint32_t __gem_create(int fd, int size);
>   uint32_t gem_create(int fd, uint64_t size);
>   void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
> @@ -67,6 +69,16 @@ bool gem_mmap__has_wc(int fd);
>   void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
>
>   /**
> + * gem_require_stolen_support:
> + * @fd: open i915 drm file descriptor
> + *
> + * Test macro to query whether support for allocating objects from stolen
> + * memory is available. Automatically skips through igt_require() if not.
> + */
> +#define gem_require_stolen_support(fd) \
> +			igt_require(gem_create__has_stolen_support(fd))
> +
> +/**
>    * gem_require_mmap_wc:
>    * @fd: open i915 drm file descriptor
>    *
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index b9479cc..324cbb5 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -55,6 +55,7 @@ TESTS_progs_M = \
>   	gem_reset_stats \
>   	gem_ringfill \
>   	gem_set_tiling_vs_blt \
> +	gem_stolen \
>   	gem_storedw_batches_loop \
>   	gem_streaming_writes \
>   	gem_tiled_blits \
> diff --git a/tests/gem_stolen.c b/tests/gem_stolen.c
> new file mode 100644
> index 0000000..9caaefd
> --- /dev/null
> +++ b/tests/gem_stolen.c
> @@ -0,0 +1,363 @@
> +/*
> + * Copyright © 2011 Intel Corporation

Is the year correct?

> + *
> + * 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:
> + *    Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> + *
> + */
> +
> +/** @file gem_create_stolen.c
> + *
> + * This is a test for the extended gem_create ioctl, that includes allocation
> + * of object from stolen memory

Missing full stop.

> + *
> + * The goal is to simply ensure the basics work, and invalid input combinations
> + * are rejected.
> + */
> +
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <fcntl.h>
> +#include <inttypes.h>
> +#include <errno.h>
> +#include <sys/stat.h>
> +#include <sys/time.h>
> +#include <getopt.h>
> +
> +#include <drm.h>
> +
> +#include "ioctl_wrappers.h"
> +#include "intel_bufmgr.h"
> +#include "intel_batchbuffer.h"
> +#include "intel_io.h"
> +#include "intel_chipset.h"
> +#include "igt_aux.h"
> +#include "drmtest.h"
> +#include "drm.h"
> +#include "i915_drm.h"
> +
> +IGT_TEST_DESCRIPTION("This test verifies the exetended gem_create ioctl,"
> +		     " that includes allocation of obj from stolen region");
> +#define CLEAR(s) memset(&s, 0, sizeof(s))
> +#define SIZE 1024*1024
> +
> +static struct drm_intel_bufmgr *bufmgr;
> +static struct intel_batchbuffer *batch;
> +
> +static void verify_copy_op(drm_intel_bo *src, drm_intel_bo *dest)
> +{
> +	uint32_t *virt, i, ret;
> +	/* Fill the src BO with dwords */
> +	ret = drm_intel_gem_bo_map_gtt(src);
> +	igt_assert(!ret);
> +
> +	virt = src->virtual;
> +	for (i = 0; i < SIZE/4; i++)

There is a lot of these hardcoded fours around. Maybe it would be nicer 
to use sizeof(*virt) or #define SIZE_DWORDS .. or something.

> +		virt[i] = i;
> +
> +	intel_copy_bo(batch, dest, src, SIZE);
> +
> +	ret = drm_intel_gem_bo_map_gtt(dest);
> +	igt_assert(!ret);
> +
> +	virt = dest->virtual;
> +	/* verify */
> +	for (i = 0; i < SIZE/4; i++) {
> +		if (virt[i] != i) {
> +			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
> +					"at offset 0x%08x\n",
> +					i, virt[i], i * 4);

Doesn't %x add '0x' prefix already?

But probably could just use igt_assert_eq here without the extra 
fprintf. Also in other identical places.

> +			igt_assert(virt[i] == i);
> +		}
> +	}
> +
> +	drm_intel_bo_unmap(src);
> +	drm_intel_bo_unmap(dest);
> +}
> +
> +static void stolen_pwrite(int fd)
> +{
> +	drm_intel_bo *bo;
> +	uint32_t buf[SIZE/4];
> +	uint32_t handle = 0;
> +	uint32_t *virt;
> +	int i, ret = 0;
> +
> +	for (i = 0; i < SIZE/4; i ++)

Stray space.

> +		buf[i] = 0xdead;
> +
> +	gem_require_stolen_support(fd);
> +
> +	handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(handle != 0);
> +
> +	gem_write(fd, handle, 0, buf, SIZE);
> +	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "bo", handle);
> +
> +	ret = drm_intel_gem_bo_map_gtt(bo);
> +	igt_assert(!ret);
> +
> +	virt = bo->virtual;
> +
> +	for (i = 0; i < SIZE/4; i ++)
> +		igt_assert(virt[i] == 0xdead);
> +
> +	drm_intel_bo_unmap(bo);
> +	drm_intel_bo_unreference(bo);
> +	gem_close(fd, handle);
> +}
> +
> +static void stolen_pread(int fd)
> +{
> +	drm_intel_bo *bo;
> +	uint32_t buf[SIZE/4];
> +	uint32_t handle = 0;
> +	uint32_t *virt;
> +	int i, ret = 0;
> +
> +	CLEAR(buf);
> +
> +	gem_require_stolen_support(fd);
> +
> +	handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(handle != 0);
> +
> +	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "bo", handle);
> +
> +	ret = drm_intel_gem_bo_map_gtt(bo);
> +	igt_assert(!ret);
> +
> +	virt = bo->virtual;
> +
> +	for (i = 0; i < SIZE/4; i ++)
> +		virt[i] = 0xdead;
> +
> +	drm_intel_bo_unmap(bo);
> +	drm_intel_bo_unreference(bo);
> +
> +	gem_read(fd, handle, 0, buf, SIZE);
> +
> +	for (i = 0; i < SIZE/4; i ++)
> +		igt_assert(buf[i] == 0xdead);
> +
> +	gem_close(fd, handle);
> +}
> +
> +static void copy_test(int fd)
> +{
> +	drm_intel_bo *src, *dest;
> +	uint32_t src_handle = 0, dest_handle = 0;
> +	int ret = 0;
> +
> +	gem_require_stolen_support(fd);
> +
> +	src_handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(src_handle != 0);
> +
> +	dest_handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(dest_handle != 0);
> +
> +	src = gem_handle_to_libdrm_bo(bufmgr, fd, "src_bo", src_handle);
> +	dest = gem_handle_to_libdrm_bo(bufmgr, fd, "dst_bo", dest_handle);
> +
> +	igt_assert(src != NULL);
> +	igt_assert(dest != NULL);
> +
> +	verify_copy_op(src, dest);
> +
> +	drm_intel_bo_unreference(src);
> +	drm_intel_bo_unreference(dest);
> +	gem_close(fd, src_handle);
> +	gem_close(fd, dest_handle);
> +}
> +
> +static void verify_object_clear(int fd)
> +{
> +	drm_intel_bo *bo;
> +	uint32_t handle = 0;
> +	uint32_t *virt;
> +	int i, ret = 0;
> +
> +	gem_require_stolen_support(fd);
> +
> +	handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(handle != 0);
> +
> +	bo = gem_handle_to_libdrm_bo(bufmgr, fd, "verify_bo", handle);
> +	igt_assert(bo != NULL);
> +
> +	ret = drm_intel_gem_bo_map_gtt(bo);
> +	igt_assert(ret == 0);

There are igt_assert_eq and igt_assert_neq but in uses such as here 
(NULL vs non-NULL) I am not too bothered.

> +	/* Verify if the BO is zeroed */
> +	virt = bo->virtual;
> +	for (i = 0; i < SIZE / 4; i++)
> +		igt_assert(virt[i] == 0);
> +
> +	drm_intel_bo_unmap(bo);
> +	drm_intel_bo_unreference(bo);
> +	gem_close(fd, handle);
> +}
> +
> +static void stolen_fill_purge_test(int fd)
> +{
> +	drm_intel_bo *bo;
> +	int mret = 0, ret = 0, obj_count = 0, i = 0;
> +	int _ret = 0, j = 0;
> +	uint32_t handle[100] = {0};
> +	uint32_t new_handle = 0;

These two don't need to be initialized, plus, I don't see any protection 
for overflowing the handle array below?

> +	uint32_t *virt;
> +	int retained = 0;
> +
> +	gem_require_stolen_support(fd);
> +
> +	/* Exhaust Stolen space */
> +	while(ret == 0) {
> +		ret = -1;
> +		handle[i] = gem_create_stolen(fd, SIZE);
> +		if (handle[i] != 0) {
> +			ret = 0;
> +			bo = gem_handle_to_libdrm_bo(bufmgr, fd,
> +						     "verify_bo", handle[i]);
> +			igt_assert(bo != NULL);
> +
> +			_ret = drm_intel_gem_bo_map_gtt(bo);
> +			igt_assert(_ret == 0);
> +
> +			virt = bo->virtual;
> +			for (j = 0; j < SIZE / 4; j++)
> +				virt[j] = 0xab;
> +
> +			drm_intel_bo_unmap(bo);
> +			drm_intel_bo_unreference(bo);
> +
> +			obj_count++;
> +		}

Above loop and various "ret" flavours looks like could be simplified.

I think if you convert to do-while you can avoid the "ret = -1; ... ret 
= 0;" dance.

do {

	handle[i] = gem_create_stolen()
	if (handle[i]) {
		...
		<the main part of your loop>
		...
	}

	i++;
} while (handle[i-1]);

> +		i++;
> +	}
> +
> +	igt_assert(obj_count > 0);
> +
> +	/* Mark all stolen objects purgeable */
> +	for (i = 0; i < obj_count; i++)
> +		retained = gem_madvise(fd, handle[i], I915_MADV_DONTNEED);
> +
> +	/* Try to allocate one more object */
> +	new_handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(new_handle != 0);
> +
> +	/* Check if the retained object's memory contents are intact */
> +	for (i = 0; i < obj_count; i++) {
> +		retained = gem_madvise(fd, handle[i], I915_MADV_WILLNEED);
> +		if (retained) {
> +			bo = gem_handle_to_libdrm_bo(bufmgr, fd,
> +						     "verify_bo", handle[i]);
> +			igt_assert(bo != NULL);
> +
> +			_ret = drm_intel_gem_bo_map_gtt(bo);
> +			igt_assert(_ret == 0);
> +
> +			virt = bo->virtual;
> +			for (j = 0; j < SIZE / 4; j++)
> +				igt_assert(virt[j] == 0xab);
> +
> +			drm_intel_bo_unmap(bo);
> +			drm_intel_bo_unreference(bo);
> +		}
> +	}
> +
> +	gem_close(fd, new_handle);
> +	for (i = 0; i < obj_count; i++)
> +		gem_close(fd, handle[i]);
> +}
> +
> +static void
> +stolen_no_mmap(int fd)
> +{
> +	void *addr;
> +	uint32_t handle = 0;
> +
> +	gem_require_stolen_support(fd);
> +
> +	handle = gem_create_stolen(fd, SIZE);
> +	igt_assert(handle != 0);
> +
> +	addr = gem_mmap__cpu(fd, handle, 0, SIZE, PROT_READ | PROT_WRITE);
> +	igt_assert(addr == NULL);
> +
> +	gem_close(fd, handle);
> +}
> +
> +igt_main
> +{
> +	int i, fd, gtt_size_total, gtt_size_mappable;
> +	uint32_t devid;
> +
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		fd = drm_open_any();
> +		devid = intel_get_drm_devid(fd);
> +
> +		drm_intel_get_aperture_sizes(fd, (size_t*)&gtt_size_total,
> +				(size_t*)&gtt_size_mappable);
> +		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
> +		batch = intel_batchbuffer_alloc(bufmgr, devid);
> +	}
> +
> +	igt_subtest("stolen-clear")
> +		verify_object_clear(fd);
> +
> +	/*
> +	 * stolen mem special cases - checking for non cpu mappable
> +	 */
> +	igt_subtest("stolen-no-mmap")
> +		stolen_no_mmap(fd);
> +
> +	/* checking for pread/pwrite interfaces */
> +	igt_subtest("stolen-pwrite")
> +		stolen_pwrite(fd);
> +
> +	igt_subtest("stolen-pread")
> +		stolen_pread(fd);
> +
> +	/* Functional Test - blt copy */
> +	igt_subtest("stolen-copy")
> +		copy_test(fd);
> +
> +	/* Filling stolen completely and marking all the objects
> +	 * purgeable. Then trying to add one more object, to verify
> +	 * the purging logic.
> +	 * Again marking all objects WILLNEED and verifying the
> +	 * contents of the retained objects.
> +	 */
> +	igt_subtest("stolen-fill-purge")
> +		stolen_fill_purge_test(fd);
> +
> +	igt_fixture {
> +		intel_batchbuffer_free(batch);
> +		drm_intel_bufmgr_destroy(bufmgr);
> +	}
> +}

Could also test creation of huge objects which can never be allocated 
from stolen, esp if size overflow 32-bits.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl
  2015-07-03  9:05   ` Tvrtko Ursulin
@ 2015-07-03  9:16     ` Chris Wilson
  2015-07-03  9:38       ` Tvrtko Ursulin
  0 siblings, 1 reply; 17+ messages in thread
From: Chris Wilson @ 2015-07-03  9:16 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: ankitprasad.r.sharma, intel-gfx, akash.goel, shashidhar.hiremath

On Fri, Jul 03, 2015 at 10:05:05AM +0100, Tvrtko Ursulin wrote:
> >+bool gem_create__has_stolen_support(int fd)
> >+{
> >+	static int has_stolen_support = -1;
> >+
> >+	if (has_stolen_support < 0) {
> >+	struct drm_i915_getparam gp;
> >+	int val = -1;

> >+		memset(&gp, 0, sizeof(gp));
> >+		gp.param = 36; /* CREATE_VERSION */
> >+		gp.value = &val;
> >+
> >+		/* Do we have the extended gem_create_ioctl? */
> >+		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
> >+		has_stolen_support = val >= 1;
> 
> If ioctl fails it will declare stolen support. (val remains -1)
> 
> I would also suggest "has_stolen_support = val > 1" as clearer.

Tvrtko, -ENOCOFFEE? :)

> >+	struct local_i915_gem_create_v2 create;
> >+	int ret;
> >+
> >+	memset(&create, 0, sizeof(create));
> >+	create.handle = 0;
> >+	create.size = size;
> >+	create.flags = I915_CREATE_PLACEMENT_STOLEN;
> >+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
> >+
> >+	if (ret < 0)
> >+		return 0;
> >+
> >+	errno = 0;
> >+	return create.handle;
> >+}
> >+
> >+
> 
> Interestingly gem_create_stolen copies implementation from
> __gem_create and differs from normal gem_create in handling of ioctl
> failure. But it removes the double underscore from the name. I think
> this creates unnecessary inconsistency. It should either have double
> underscore prefix or copy implementation from gem_create.

Right, I have been using gem_(*) for abort-on-failure, and __gem_*() for
propagate the error back to the caller. I would like that idiom become
more common.
-Chris


-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-01  9:26 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
@ 2015-07-03  9:37   ` Tvrtko Ursulin
  2015-07-06 14:33     ` Dave Gordon
  2015-07-21 12:38     ` Ankitprasad Sharma
  0 siblings, 2 replies; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-07-03  9:37 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath



On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This patch adds support to verify pread/pwrite for non-shmem backed
> objects. It also shows the pread/pwrite speed.
> It also tests speeds for pread with and without user side page faults
>
> v2: Rebased to the latest (Ankit)
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
>   tests/gem_pread.c  | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   tests/gem_pwrite.c |  45 ++++++++++++++++++++++++
>   2 files changed, 145 insertions(+)
>
> diff --git a/tests/gem_pread.c b/tests/gem_pread.c
> index cc83948..95162d5 100644
> --- a/tests/gem_pread.c
> +++ b/tests/gem_pread.c
> @@ -41,6 +41,10 @@
>   #include "drmtest.h"
>
>   #define OBJECT_SIZE 16384
> +#define LARGE_OBJECT_SIZE 1024 * 1024
> +#define KGRN "\x1B[32m"
> +#define KRED "\x1B[31m"
> +#define KNRM "\x1B[0m"
>
>   static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
>   {
> @@ -76,11 +80,14 @@ static const char *bytes_per_sec(char *buf, double v)
>
>
>   uint32_t *src, dst;
> +uint32_t *dst_user, src_stolen, large_stolen;
> +uint32_t *stolen_pf_user, *stolen_nopf_user;
>   int fd, count;
>
>   int main(int argc, char **argv)
>   {
>   	int object_size = 0;
> +	int large_obj_size = LARGE_OBJECT_SIZE;

Why have both a define and a variable which does not get modified for 
the same thing?

>   	uint32_t buf[20];
>   	const struct {
>   		int level;
> @@ -90,6 +97,9 @@ int main(int argc, char **argv)
>   		{ 1, "snoop" },
>   		{ 2, "display" },
>   		{ -1 },
> +		{ -1, "stolen-uncached"},
> +		{ -1, "stolen-snoop"},
> +		{ -1, "stolen-display"},

Ugh why so hacky? You only used the new three entries for their names, 
right?

What about instead of "igt_subtest((c + 4)->name)" do 
"igt_subtest_f("stolen-%s", c->name)" and then you don't need to add 
these hacky entries?

>   	}, *c;
>
>   	igt_subtest_init(argc, argv);
> @@ -106,6 +116,8 @@ int main(int argc, char **argv)
>
>   		dst = gem_create(fd, object_size);
>   		src = malloc(object_size);
> +		src_stolen = gem_create_stolen(fd, object_size);
> +		dst_user = malloc(object_size);
>   	}
>
>   	igt_subtest("normal") {
> @@ -142,9 +154,97 @@ int main(int argc, char **argv)
>   		}
>   	}
>
> +	igt_subtest("stolen-normal") {
> +		for (count = 1; count <= 1<<17; count <<= 1) {
> +			struct timeval start, end;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, src_stolen, dst_user, object_size, count);
> +			gettimeofday(&end, NULL);
> +			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
> +				 object_size, count,
> +				 elapsed(&start, &end, count),
> +				 bytes_per_sec((char *)buf,
> +				 object_size/elapsed(&start, &end, count)*1e6));

There is no checking that bytes_per_sec won't overflow buf. Which is 
also declared as unit32_t just so we can cast here. :) Suggest fixing if 
you feel like it, won't mandate it since it is existing code.

> +			fflush(stdout);
> +		}
> +	}
> +	for (c = cache; c->level != -1; c++) {
> +		igt_subtest((c + 4)->name) {
> +			gem_set_caching(fd, src_stolen, c->level);
> +
> +			for (count = 1; count <= 1<<17; count <<= 1) {
> +				struct timeval start, end;
> +
> +				gettimeofday(&start, NULL);
> +				do_gem_read(fd, src_stolen, dst_user,
> +					    object_size, count);
> +				gettimeofday(&end, NULL);
> +				igt_info("Time to %s pread %d bytes x %6d:      %7.3fµs, %s\n",
> +					 (c + 4)->name, object_size, count,
> +					 elapsed(&start, &end, count),
> +					 bytes_per_sec((char *)buf,
> +					 object_size/elapsed(&start, &end, count)*1e6));
> +				fflush(stdout);
> +			}
> +		}
> +	}
> +
> +	/* List pread times for stolen area with 1 page fault (page fault only
> +	 * first time) and multiple page faults (unmapping the pages at the
> +	 * end of each iteration)
> +	 */

Can you explain more the idea behind this test? It benchmarks minor 
faulting (well could be major as well but we can't say), but it is 
nothing in the i915 path as far as I know.

> +	igt_subtest("pagefault-pread") {
> +		large_stolen = gem_create_stolen(fd, large_obj_size);
> +		stolen_nopf_user = (uint32_t *) mmap(NULL, large_obj_size,
> +						PROT_WRITE,
> +						MAP_ANONYMOUS|MAP_PRIVATE,
> +						-1, 0);

Some asserts for object creationg and mmap?

> +
> +		for (count = 1; count <= 10; count ++) {
> +			struct timeval start, end;
> +			uint32_t t_elapsed = 0;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_nopf_user,
> +				    large_obj_size, 1);
> +			gettimeofday(&end, NULL);
> +			t_elapsed = elapsed(&start, &end, 1);
> +			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
> +				 large_obj_size,
> +				 elapsed(&start, &end, 1),
> +				 bytes_per_sec((char *)buf,
> +				 large_obj_size/elapsed(&start, &end, 1)*1e6));
> +
> +			stolen_pf_user = (uint32_t *) mmap(NULL, large_obj_size,
> +						      PROT_WRITE,
> +						      MAP_ANONYMOUS|MAP_PRIVATE,
> +						      -1, 0);
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_pf_user,
> +				    large_obj_size, 1);
> +			gettimeofday(&end, NULL);
> +			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
> +				 large_obj_size,
> +				 elapsed(&start, &end, 1),
> +				 t_elapsed < elapsed(&start, &end, 1) ? KGRN : KRED,
> +				 bytes_per_sec((char *)buf,
> +				 large_obj_size/elapsed(&start, &end, 1)*1e6),
> +				 KNRM);
> +			fflush(stdout);
> +			munmap(stolen_pf_user, large_obj_size);
> +		}
> +			munmap(stolen_nopf_user, large_obj_size);
> +			gem_close(fd, large_stolen);

Indentation is broken here.

> +	}
> +
> +
>   	igt_fixture {
>   		free(src);
>   		gem_close(fd, dst);
> +		free(dst_user);
> +		gem_close(fd, src_stolen);
>
>   		close(fd);
>   	}
> diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
> index 5b6a77f..c7e3edf 100644
> --- a/tests/gem_pwrite.c
> +++ b/tests/gem_pwrite.c
> @@ -135,6 +135,7 @@ static void test_big_gtt(int fd, int scale)
>   }
>
>   uint32_t *src, dst;
> +uint32_t *src_user, dst_stolen;
>   int fd;
>
>   int main(int argc, char **argv)
> @@ -150,6 +151,9 @@ int main(int argc, char **argv)
>   		{ 1, "snoop" },
>   		{ 2, "display" },
>   		{ -1 },
> +		{ -1, "stolen-uncached"},
> +		{ -1, "stolen-snoop"},
> +		{ -1, "stolen-display"},

Same comment as for pread.

Hm, should the page faulting benchmark go in gem_pwrite rather than 
gem_pread? Although not sure - is stolen pageable at all?

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl
  2015-07-03  9:16     ` Chris Wilson
@ 2015-07-03  9:38       ` Tvrtko Ursulin
  0 siblings, 0 replies; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-07-03  9:38 UTC (permalink / raw)
  To: Chris Wilson, ankitprasad.r.sharma, intel-gfx, akash.goel,
	shashidhar.hiremath


On 07/03/2015 10:16 AM, Chris Wilson wrote:
> On Fri, Jul 03, 2015 at 10:05:05AM +0100, Tvrtko Ursulin wrote:
>>> +bool gem_create__has_stolen_support(int fd)
>>> +{
>>> +	static int has_stolen_support = -1;
>>> +
>>> +	if (has_stolen_support < 0) {
>>> +	struct drm_i915_getparam gp;
>>> +	int val = -1;
>
>>> +		memset(&gp, 0, sizeof(gp));
>>> +		gp.param = 36; /* CREATE_VERSION */
>>> +		gp.value = &val;
>>> +
>>> +		/* Do we have the extended gem_create_ioctl? */
>>> +		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
>>> +		has_stolen_support = val >= 1;
>>
>> If ioctl fails it will declare stolen support. (val remains -1)
>>
>> I would also suggest "has_stolen_support = val > 1" as clearer.
>
> Tvrtko, -ENOCOFFEE? :)

Ooops don't know why I saw an arithmetic shift there.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
  2015-07-01  9:26 ` [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl ankitprasad.r.sharma
@ 2015-07-03  9:52   ` Tvrtko Ursulin
  2015-07-21 13:09     ` Ankitprasad Sharma
  0 siblings, 1 reply; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-07-03  9:52 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath



On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This test validates the two parameters (size and flags) GEM_CREATE ioctl.
>
> v2: Added IGT_TEST_DESCRIPTION (Thomas Wood)
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
>   tests/Makefile.sources |   1 +
>   tests/gem_create.c     | 181 +++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 182 insertions(+)
>   create mode 100644 tests/gem_create.c
>
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 324cbb5..f5790df 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -15,6 +15,7 @@ TESTS_progs_M = \
>   	gem_close_race \
>   	gem_concurrent_blit \
>   	gem_concurrent_all \
> +	gem_create \
>   	gem_cs_tlb \
>   	gem_ctx_param_basic \
>   	gem_ctx_bad_exec \
> diff --git a/tests/gem_create.c b/tests/gem_create.c
> new file mode 100644
> index 0000000..6581035
> --- /dev/null
> +++ b/tests/gem_create.c
> @@ -0,0 +1,181 @@
> +/*
> + * Copyright © 2011 Intel Corporation

Year correct?

> + *
> + * 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:
> + *    Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> + *
> + */
> +
> +/** @file gem_create.c
> + *
> + * This is a test for the extended and old gem_create ioctl, that
> + * includes allocation of object from stolen memory and shmem

Full stop.

> + *
> + * The goal is to simply ensure that basics work and invalid input
> + * combinations are rejected.
> + */
> +
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <fcntl.h>
> +#include <inttypes.h>
> +#include <errno.h>
> +#include <sys/stat.h>
> +#include <sys/time.h>
> +#include <getopt.h>
> +
> +#include <drm.h>
> +
> +#include "ioctl_wrappers.h"
> +#include "intel_bufmgr.h"
> +#include "intel_batchbuffer.h"
> +#include "intel_io.h"
> +#include "intel_chipset.h"
> +#include "igt_aux.h"
> +#include "drmtest.h"
> +#include "drm.h"
> +#include "i915_drm.h"
> +
> +IGT_TEST_DESCRIPTION("This is a test for the extended & old gem_create ioctl,"
> +		     " that includes allocation of object from stolen memory"
> +		     " and shmem");
> +
> +#define CLEAR(s) memset(&s, 0, sizeof(s))
> +#define SIZE 2048

Since PAGE_SIZE is the minimum object I think it would be better for 
default size to be that. And then have an explicit test to see if 
requests smaller than minimum are correctly rounded up.

> +#define OFFSET 3072
> +
> +static struct drm_intel_bufmgr *bufmgr;
> +static struct intel_batchbuffer *batch;

What is batchbuffer for? (Cleanup includes as well.)

> +
> +static void invalid_flag_test(int fd)
> +{
> +	int ret = 0;

Don't need to initialize.

> +
> +struct local_i915_gem_create_v2 {
> +	uint64_t size;
> +	uint32_t handle;
> +	uint32_t pad;
> +#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
> +	uint32_t flags;
> +} create;
> +
> +#define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
> +	gem_require_stolen_support(fd);
> +
> +	create.handle = 0;
> +	create.size = SIZE;
> +	create.flags = ~I915_CREATE_PLACEMENT_STOLEN;

Also ~0 should be rejected.

> +	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
> +
> +	igt_assert(ret <= 0);
> +}
> +
> +static void invalid_size_test(int fd)
> +{
> +	int handle;
> +
> +	handle = __gem_create(fd, 0);
> +	igt_assert(handle == 0);
> +}
> +/* Creating an object with non-aligned size and trying to access offset of
> + * value (size+x) & length y, where (size+x+y) <= object's last page boundary.
> + * pwrite here must be successful.
> + */
> +static void valid_nonaligned_size(int fd)
> +{
> +	int handle, i;
> +	uint32_t buf[1024];
> +
> +	for (i = 0; i < 1024; i ++)
> +		buf[i] = 0xdead;
> +
> +	handle = gem_create(fd, SIZE);
> +	igt_assert(handle != 0);
> +
> +	gem_write(fd, handle, OFFSET, buf, 256);
> +
> +	gem_close(fd, handle);
> +}

I would move this subtest to gem_pread or gem_pwrite - this one claims 
to be only about create so kind of doesn't belong here.

> +/* Creating an object with non-aligned size and trying to access offset of
> + * value (size+x) & length y, where (size+x+y) > object's last page boundary.
> + * pwrite here must result in failure.
> + */
> +static void invalid_nonaligned_size(int fd)
> +{
> +	int handle, i;
> +	uint32_t buf[1024];
> +	struct drm_i915_gem_pwrite gem_pwrite;
> +
> +	for (i = 0; i < 1024; i ++)

Suggest avoiding hardcoding.

> +		buf[i] = 0xdead;
> +
> +	handle = gem_create(fd, SIZE);
> +
> +	CLEAR(gem_pwrite);
> +	gem_pwrite.handle = handle;
> +	gem_pwrite.offset = OFFSET;
> +	/* Out of bound access */
> +	gem_pwrite.size = 2048;

Mixing up defines and hardcoding could be improved so the numbers are 
more obvious when reading this. Perhaps OFFSET should not be defined at 
all but expressed relative to SIZE at relevant places so the reader 
immediately know what is the test trying to do.

> +	gem_pwrite.data_ptr = (uintptr_t)buf;
> +	igt_assert(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) != 0);
> +
> +	gem_close(fd, handle);
> +}
> +
> +igt_main
> +{
> +	int i, fd, gtt_size_total, gtt_size_mappable;
> +	uint32_t devid;
> +
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		fd = drm_open_any();
> +		devid = intel_get_drm_devid(fd);
> +
> +		drm_intel_get_aperture_sizes(fd, (size_t*)&gtt_size_total,
> +				(size_t*)&gtt_size_mappable);

Doesn't look like the test needs to know this.

> +		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);

Or this.

> +		batch = intel_batchbuffer_alloc(bufmgr, devid);
> +	}
> +
> +	igt_subtest("stolen-invalid-flag")
> +		invalid_flag_test(fd);
> +
> +	igt_subtest("stolen-invalid-size")
> +		invalid_size_test(fd);
> +
> +	igt_subtest("stolen-valid-nonaligned")
> +		valid_nonaligned_size(fd);
> +
> +	igt_subtest("stolen-invalid-nonaligned")
> +		invalid_nonaligned_size(fd);
> +
> +	igt_fixture {
> +		intel_batchbuffer_free(batch);
> +		drm_intel_bufmgr_destroy(bufmgr);
> +	}
> +}
>

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-03  9:37   ` Tvrtko Ursulin
@ 2015-07-06 14:33     ` Dave Gordon
  2015-07-21 12:38     ` Ankitprasad Sharma
  1 sibling, 0 replies; 17+ messages in thread
From: Dave Gordon @ 2015-07-06 14:33 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath

On 03/07/15 10:37, Tvrtko Ursulin wrote:
>
>
> On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
>> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>>
>> This patch adds support to verify pread/pwrite for non-shmem backed
>> objects. It also shows the pread/pwrite speed.
>> It also tests speeds for pread with and without user side page faults
>>
>> v2: Rebased to the latest (Ankit)
>>
>> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
>> ---
>>   tests/gem_pread.c  | 100
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   tests/gem_pwrite.c |  45 ++++++++++++++++++++++++
>>   2 files changed, 145 insertions(+)

[snip]

>> @@ -142,9 +154,97 @@ int main(int argc, char **argv)
>>           }
>>       }
>>
>> +    igt_subtest("stolen-normal") {
>> +        for (count = 1; count <= 1<<17; count <<= 1) {
>> +            struct timeval start, end;
>> +
>> +            gettimeofday(&start, NULL);
>> +            do_gem_read(fd, src_stolen, dst_user, object_size, count);
>> +            gettimeofday(&end, NULL);
>> +            igt_info("Time to pread %d bytes x %6d:    %7.3fµs, %s\n",
>> +                 object_size, count,
>> +                 elapsed(&start, &end, count),
>> +                 bytes_per_sec((char *)buf,
>> +                 object_size/elapsed(&start, &end, count)*1e6));
>
> There is no checking that bytes_per_sec won't overflow buf. Which is
> also declared as unit32_t just so we can cast here. :) Suggest fixing if
> you feel like it, won't mandate it since it is existing code.

That printf format appears to have 4 %-fields but 5 parameters?
Ah, no it hasn't, but the indentation is misleading -- how about 
indenting the last line (the one beginning object_size ...) some more so 
that it's more obviously a parameter to bytes_per_sec() and not igt_info().

Also perhaps nicer to precalculate elapsed(&start, &end, count) and save 
it rather than inlining twice in the parameter list? Maybe even do the 
same with the bps value (even though it's only used once) just so the 
long printf lines don't have complicated expressions embedded?

Thus:

+        for (count = 1; count <= 1<<17; count <<= 1) {
+            struct timeval start, end;
*            double usecs;
*            char *bps;
+
+            gettimeofday(&start, NULL);
+            do_gem_read(fd, src_stolen, dst_user, object_size, count);
+            gettimeofday(&end, NULL);
*            usecs = elapsed(&start, &end, count);
*            bps = bytes_per_sec((char *)buf, 1e6*object_size/usecs);
*            igt_info("Time to pread %d bytes x %6d:    %7.3fµs, %s\n",
*                 object_size, count, time, bps);

... and obviously for all other similar code below.

.Dave.

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-03  9:37   ` Tvrtko Ursulin
  2015-07-06 14:33     ` Dave Gordon
@ 2015-07-21 12:38     ` Ankitprasad Sharma
  1 sibling, 0 replies; 17+ messages in thread
From: Ankitprasad Sharma @ 2015-07-21 12:38 UTC (permalink / raw)
  To: Tvrtko Ursulin; +Cc: intel-gfx, akash.goel, shashidhar.hiremath

On Fri, 2015-07-03 at 10:37 +0100, Tvrtko Ursulin wrote:
> 
> On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
> > From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
> >
> > This patch adds support to verify pread/pwrite for non-shmem backed
> > objects. It also shows the pread/pwrite speed.
> > It also tests speeds for pread with and without user side page faults
> >
> > v2: Rebased to the latest (Ankit)
> >
> > Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> > ---
> >   tests/gem_pread.c  | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >   tests/gem_pwrite.c |  45 ++++++++++++++++++++++++
> >   2 files changed, 145 insertions(+)
> >
> > diff --git a/tests/gem_pread.c b/tests/gem_pread.c
> > index cc83948..95162d5 100644
> > --- a/tests/gem_pread.c
> > +++ b/tests/gem_pread.c
> > @@ -41,6 +41,10 @@
> >   #include "drmtest.h"
> >
> >   #define OBJECT_SIZE 16384
> > +#define LARGE_OBJECT_SIZE 1024 * 1024
> > +#define KGRN "\x1B[32m"
> > +#define KRED "\x1B[31m"
> > +#define KNRM "\x1B[0m"
> >
> >   static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
> >   {
> > @@ -76,11 +80,14 @@ static const char *bytes_per_sec(char *buf, double v)
> >
> >
> >   uint32_t *src, dst;
> > +uint32_t *dst_user, src_stolen, large_stolen;
> > +uint32_t *stolen_pf_user, *stolen_nopf_user;
> >   int fd, count;
> >
> >   int main(int argc, char **argv)
> >   {
> >   	int object_size = 0;
> > +	int large_obj_size = LARGE_OBJECT_SIZE;
> 
> Why have both a define and a variable which does not get modified for 
> the same thing?
> 
> >   	uint32_t buf[20];
> >   	const struct {
> >   		int level;
> > @@ -90,6 +97,9 @@ int main(int argc, char **argv)
> >   		{ 1, "snoop" },
> >   		{ 2, "display" },
> >   		{ -1 },
> > +		{ -1, "stolen-uncached"},
> > +		{ -1, "stolen-snoop"},
> > +		{ -1, "stolen-display"},
> 
> Ugh why so hacky? You only used the new three entries for their names, 
> right?
> 
> What about instead of "igt_subtest((c + 4)->name)" do 
> "igt_subtest_f("stolen-%s", c->name)" and then you don't need to add 
> these hacky entries?
> 
> >   	}, *c;
> >
> >   	igt_subtest_init(argc, argv);
> > @@ -106,6 +116,8 @@ int main(int argc, char **argv)
> >
> >   		dst = gem_create(fd, object_size);
> >   		src = malloc(object_size);
> > +		src_stolen = gem_create_stolen(fd, object_size);
> > +		dst_user = malloc(object_size);
> >   	}
> >
> >   	igt_subtest("normal") {
> > @@ -142,9 +154,97 @@ int main(int argc, char **argv)
> >   		}
> >   	}
> >
> > +	igt_subtest("stolen-normal") {
> > +		for (count = 1; count <= 1<<17; count <<= 1) {
> > +			struct timeval start, end;
> > +
> > +			gettimeofday(&start, NULL);
> > +			do_gem_read(fd, src_stolen, dst_user, object_size, count);
> > +			gettimeofday(&end, NULL);
> > +			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
> > +				 object_size, count,
> > +				 elapsed(&start, &end, count),
> > +				 bytes_per_sec((char *)buf,
> > +				 object_size/elapsed(&start, &end, count)*1e6));
> 
> There is no checking that bytes_per_sec won't overflow buf. Which is 
> also declared as unit32_t just so we can cast here. :) Suggest fixing if 
> you feel like it, won't mandate it since it is existing code.
> 
> > +			fflush(stdout);
> > +		}
> > +	}
> > +	for (c = cache; c->level != -1; c++) {
> > +		igt_subtest((c + 4)->name) {
> > +			gem_set_caching(fd, src_stolen, c->level);
> > +
> > +			for (count = 1; count <= 1<<17; count <<= 1) {
> > +				struct timeval start, end;
> > +
> > +				gettimeofday(&start, NULL);
> > +				do_gem_read(fd, src_stolen, dst_user,
> > +					    object_size, count);
> > +				gettimeofday(&end, NULL);
> > +				igt_info("Time to %s pread %d bytes x %6d:      %7.3fµs, %s\n",
> > +					 (c + 4)->name, object_size, count,
> > +					 elapsed(&start, &end, count),
> > +					 bytes_per_sec((char *)buf,
> > +					 object_size/elapsed(&start, &end, count)*1e6));
> > +				fflush(stdout);
> > +			}
> > +		}
> > +	}
> > +
> > +	/* List pread times for stolen area with 1 page fault (page fault only
> > +	 * first time) and multiple page faults (unmapping the pages at the
> > +	 * end of each iteration)
> > +	 */
> 
> Can you explain more the idea behind this test? It benchmarks minor 
> faulting (well could be major as well but we can't say), but it is 
> nothing in the i915 path as far as I know.
> 
> > +	igt_subtest("pagefault-pread") {
> > +		large_stolen = gem_create_stolen(fd, large_obj_size);
> > +		stolen_nopf_user = (uint32_t *) mmap(NULL, large_obj_size,
> > +						PROT_WRITE,
> > +						MAP_ANONYMOUS|MAP_PRIVATE,
> > +						-1, 0);
> 
> Some asserts for object creationg and mmap?
> 
> > +
> > +		for (count = 1; count <= 10; count ++) {
> > +			struct timeval start, end;
> > +			uint32_t t_elapsed = 0;
> > +
> > +			gettimeofday(&start, NULL);
> > +			do_gem_read(fd, large_stolen, stolen_nopf_user,
> > +				    large_obj_size, 1);
> > +			gettimeofday(&end, NULL);
> > +			t_elapsed = elapsed(&start, &end, 1);
> > +			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
> > +				 large_obj_size,
> > +				 elapsed(&start, &end, 1),
> > +				 bytes_per_sec((char *)buf,
> > +				 large_obj_size/elapsed(&start, &end, 1)*1e6));
> > +
> > +			stolen_pf_user = (uint32_t *) mmap(NULL, large_obj_size,
> > +						      PROT_WRITE,
> > +						      MAP_ANONYMOUS|MAP_PRIVATE,
> > +						      -1, 0);
> > +
> > +			gettimeofday(&start, NULL);
> > +			do_gem_read(fd, large_stolen, stolen_pf_user,
> > +				    large_obj_size, 1);
> > +			gettimeofday(&end, NULL);
> > +			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
> > +				 large_obj_size,
> > +				 elapsed(&start, &end, 1),
> > +				 t_elapsed < elapsed(&start, &end, 1) ? KGRN : KRED,
> > +				 bytes_per_sec((char *)buf,
> > +				 large_obj_size/elapsed(&start, &end, 1)*1e6),
> > +				 KNRM);
> > +			fflush(stdout);
> > +			munmap(stolen_pf_user, large_obj_size);
> > +		}
> > +			munmap(stolen_nopf_user, large_obj_size);
> > +			gem_close(fd, large_stolen);
> 
> Indentation is broken here.
> 
> > +	}
> > +
> > +
> >   	igt_fixture {
> >   		free(src);
> >   		gem_close(fd, dst);
> > +		free(dst_user);
> > +		gem_close(fd, src_stolen);
> >
> >   		close(fd);
> >   	}
> > diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
> > index 5b6a77f..c7e3edf 100644
> > --- a/tests/gem_pwrite.c
> > +++ b/tests/gem_pwrite.c
> > @@ -135,6 +135,7 @@ static void test_big_gtt(int fd, int scale)
> >   }
> >
> >   uint32_t *src, dst;
> > +uint32_t *src_user, dst_stolen;
> >   int fd;
> >
> >   int main(int argc, char **argv)
> > @@ -150,6 +151,9 @@ int main(int argc, char **argv)
> >   		{ 1, "snoop" },
> >   		{ 2, "display" },
> >   		{ -1 },
> > +		{ -1, "stolen-uncached"},
> > +		{ -1, "stolen-snoop"},
> > +		{ -1, "stolen-display"},
> 
> Same comment as for pread.
> 
> Hm, should the page faulting benchmark go in gem_pwrite rather than 
> gem_pread? Although not sure - is stolen pageable at all?
Sorry, but I do not think it is of much use in case of pwrite, as here
we are talking about pagefaults in userspace. In case of pwrites, user
would have already filled the buffer and so a rare chance of pagefault
while doing a pwrite.
The concept of pread is reading an object to a userspace buffer, in
which pages may not be yet allocated when the kernel is trying to write
to that buffer and hence need to handle pagefaults here, resulting in
slow read. 
Hence, demonstrating here if there are multiple pagefaults, how slow
pread would be.

Thanks,
Ankit
> 


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
  2015-07-03  9:52   ` Tvrtko Ursulin
@ 2015-07-21 13:09     ` Ankitprasad Sharma
  0 siblings, 0 replies; 17+ messages in thread
From: Ankitprasad Sharma @ 2015-07-21 13:09 UTC (permalink / raw)
  To: Tvrtko Ursulin; +Cc: intel-gfx, akash.goel, shashidhar.hiremath

On Fri, 2015-07-03 at 10:52 +0100, Tvrtko Ursulin wrote:
> 
> On 07/01/2015 10:26 AM, ankitprasad.r.sharma@intel.com wrote:
> > From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
> >
> > This test validates the two parameters (size and flags) GEM_CREATE ioctl.
> >
> > v2: Added IGT_TEST_DESCRIPTION (Thomas Wood)
> >
> > Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> > ---
> >   tests/Makefile.sources |   1 +
> >   tests/gem_create.c     | 181 +++++++++++++++++++++++++++++++++++++++++++++++++
> >   2 files changed, 182 insertions(+)
> >   create mode 100644 tests/gem_create.c
> >
> > diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> > index 324cbb5..f5790df 100644
> > --- a/tests/Makefile.sources
> > +++ b/tests/Makefile.sources
> > @@ -15,6 +15,7 @@ TESTS_progs_M = \
> >   	gem_close_race \
> >   	gem_concurrent_blit \
> >   	gem_concurrent_all \
> > +	gem_create \
> >   	gem_cs_tlb \
> >   	gem_ctx_param_basic \
> >   	gem_ctx_bad_exec \
> > diff --git a/tests/gem_create.c b/tests/gem_create.c
> > new file mode 100644
> > index 0000000..6581035
> > --- /dev/null
> > +++ b/tests/gem_create.c
> > @@ -0,0 +1,181 @@
> > +/*
> > + * Copyright © 2011 Intel Corporation
> 
> Year correct?
> 
> > + *
> > + * 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:
> > + *    Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> > + *
> > + */
> > +
> > +/** @file gem_create.c
> > + *
> > + * This is a test for the extended and old gem_create ioctl, that
> > + * includes allocation of object from stolen memory and shmem
> 
> Full stop.
> 
> > + *
> > + * The goal is to simply ensure that basics work and invalid input
> > + * combinations are rejected.
> > + */
> > +
> > +#include <stdlib.h>
> > +#include <sys/ioctl.h>
> > +#include <stdio.h>
> > +#include <string.h>
> > +#include <fcntl.h>
> > +#include <inttypes.h>
> > +#include <errno.h>
> > +#include <sys/stat.h>
> > +#include <sys/time.h>
> > +#include <getopt.h>
> > +
> > +#include <drm.h>
> > +
> > +#include "ioctl_wrappers.h"
> > +#include "intel_bufmgr.h"
> > +#include "intel_batchbuffer.h"
> > +#include "intel_io.h"
> > +#include "intel_chipset.h"
> > +#include "igt_aux.h"
> > +#include "drmtest.h"
> > +#include "drm.h"
> > +#include "i915_drm.h"
> > +
> > +IGT_TEST_DESCRIPTION("This is a test for the extended & old gem_create ioctl,"
> > +		     " that includes allocation of object from stolen memory"
> > +		     " and shmem");
> > +
> > +#define CLEAR(s) memset(&s, 0, sizeof(s))
> > +#define SIZE 2048
> 
> Since PAGE_SIZE is the minimum object I think it would be better for 
> default size to be that. And then have an explicit test to see if 
> requests smaller than minimum are correctly rounded up.
> 
> > +#define OFFSET 3072
> > +
> > +static struct drm_intel_bufmgr *bufmgr;
> > +static struct intel_batchbuffer *batch;
> 
> What is batchbuffer for? (Cleanup includes as well.)
> 
> > +
> > +static void invalid_flag_test(int fd)
> > +{
> > +	int ret = 0;
> 
> Don't need to initialize.
> 
> > +
> > +struct local_i915_gem_create_v2 {
> > +	uint64_t size;
> > +	uint32_t handle;
> > +	uint32_t pad;
> > +#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
> > +	uint32_t flags;
> > +} create;
> > +
> > +#define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
> > +	gem_require_stolen_support(fd);
> > +
> > +	create.handle = 0;
> > +	create.size = SIZE;
> > +	create.flags = ~I915_CREATE_PLACEMENT_STOLEN;
> 
> Also ~0 should be rejected.
> 
> > +	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
> > +
> > +	igt_assert(ret <= 0);
> > +}
> > +
> > +static void invalid_size_test(int fd)
> > +{
> > +	int handle;
> > +
> > +	handle = __gem_create(fd, 0);
> > +	igt_assert(handle == 0);
> > +}
> > +/* Creating an object with non-aligned size and trying to access offset of
> > + * value (size+x) & length y, where (size+x+y) <= object's last page boundary.
> > + * pwrite here must be successful.
> > + */
> > +static void valid_nonaligned_size(int fd)
> > +{
> > +	int handle, i;
> > +	uint32_t buf[1024];
> > +
> > +	for (i = 0; i < 1024; i ++)
> > +		buf[i] = 0xdead;
> > +
> > +	handle = gem_create(fd, SIZE);
> > +	igt_assert(handle != 0);
> > +
> > +	gem_write(fd, handle, OFFSET, buf, 256);
> > +
> > +	gem_close(fd, handle);
> > +}
> 
> I would move this subtest to gem_pread or gem_pwrite - this one claims 
> to be only about create so kind of doesn't belong here.
This subtest is not about pwrite or pread but to check the behavior of
gem_create on passing non-page-aligned value. I might not have been able
to clarify this through my comments. Will update that. 
Just using pwrite as a mechanism here to validate gem_create.

Regards,
Ankit
> 
> > +/* Creating an object with non-aligned size and trying to access offset of
> > + * value (size+x) & length y, where (size+x+y) > object's last page boundary.
> > + * pwrite here must result in failure.
> > + */
> > +static void invalid_nonaligned_size(int fd)
> > +{
> > +	int handle, i;
> > +	uint32_t buf[1024];
> > +	struct drm_i915_gem_pwrite gem_pwrite;
> > +
> > +	for (i = 0; i < 1024; i ++)
> 
> Suggest avoiding hardcoding.
> 
> > +		buf[i] = 0xdead;
> > +
> > +	handle = gem_create(fd, SIZE);
> > +
> > +	CLEAR(gem_pwrite);
> > +	gem_pwrite.handle = handle;
> > +	gem_pwrite.offset = OFFSET;
> > +	/* Out of bound access */
> > +	gem_pwrite.size = 2048;
> 
> Mixing up defines and hardcoding could be improved so the numbers are 
> more obvious when reading this. Perhaps OFFSET should not be defined at 
> all but expressed relative to SIZE at relevant places so the reader 
> immediately know what is the test trying to do.
> 
> > +	gem_pwrite.data_ptr = (uintptr_t)buf;
> > +	igt_assert(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) != 0);
> > +
> > +	gem_close(fd, handle);
> > +}
> > +
> > +igt_main
> > +{
> > +	int i, fd, gtt_size_total, gtt_size_mappable;
> > +	uint32_t devid;
> > +
> > +	igt_skip_on_simulation();
> > +
> > +	igt_fixture {
> > +		fd = drm_open_any();
> > +		devid = intel_get_drm_devid(fd);
> > +
> > +		drm_intel_get_aperture_sizes(fd, (size_t*)&gtt_size_total,
> > +				(size_t*)&gtt_size_mappable);
> 
> Doesn't look like the test needs to know this.
> 
> > +		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
> 
> Or this.
> 
> > +		batch = intel_batchbuffer_alloc(bufmgr, devid);
> > +	}
> > +
> > +	igt_subtest("stolen-invalid-flag")
> > +		invalid_flag_test(fd);
> > +
> > +	igt_subtest("stolen-invalid-size")
> > +		invalid_size_test(fd);
> > +
> > +	igt_subtest("stolen-valid-nonaligned")
> > +		valid_nonaligned_size(fd);
> > +
> > +	igt_subtest("stolen-invalid-nonaligned")
> > +		invalid_nonaligned_size(fd);
> > +
> > +	igt_fixture {
> > +		intel_batchbuffer_free(batch);
> > +		drm_intel_bufmgr_destroy(bufmgr);
> > +	}
> > +}
> >
> 
> Regards,
> 
> Tvrtko


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-22 13:45 [PATCH v3 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
@ 2015-07-22 13:45 ` ankitprasad.r.sharma
  2015-07-22 16:14   ` Tvrtko Ursulin
  0 siblings, 1 reply; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-07-22 13:45 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This patch adds support to verify pread/pwrite for non-shmem backed
objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faults

v2: Fixed Rebase conflicts (Ankit)

v3: Precalculating values to avoid redundant function calls (Dave)
Replaced igt_subtest by igt_subtest_f, added asserts for mmap, corrected
indentation (Tvrtko)

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 tests/gem_pread.c  | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 tests/gem_pwrite.c |  54 ++++++++++++++++++++++++---
 2 files changed, 149 insertions(+), 11 deletions(-)

diff --git a/tests/gem_pread.c b/tests/gem_pread.c
index cc83948..21fccd0 100644
--- a/tests/gem_pread.c
+++ b/tests/gem_pread.c
@@ -41,6 +41,10 @@
 #include "drmtest.h"
 
 #define OBJECT_SIZE 16384
+#define LARGE_OBJECT_SIZE 1024 * 1024
+#define KGRN "\x1B[32m"
+#define KRED "\x1B[31m"
+#define KNRM "\x1B[0m"
 
 static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
 {
@@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)
 
 
 uint32_t *src, dst;
+uint32_t *dst_user, src_stolen, large_stolen;
+uint32_t *stolen_pf_user, *stolen_nopf_user;
 int fd, count;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
+	double usecs;
 	uint32_t buf[20];
+	char* bps;
 	const struct {
 		int level;
 		const char *name;
@@ -106,6 +114,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		src_stolen = gem_create_stolen(fd, object_size);
+		dst_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -115,10 +125,10 @@ int main(int argc, char **argv)
 			gettimeofday(&start, NULL);
 			do_gem_read(fd, dst, src, object_size, count);
 			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
 			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
-				 object_size, count,
-				 elapsed(&start, &end, count),
-				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+				 object_size, count, usecs, bps);
 			fflush(stdout);
 		}
 	}
@@ -133,18 +143,102 @@ int main(int argc, char **argv)
 				gettimeofday(&start, NULL);
 				do_gem_read(fd, dst, src, object_size, count);
 				gettimeofday(&end, NULL);
+				usecs = elapsed(&start, &end, count);
+				bps = bytes_per_sec((char *)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,
-					 elapsed(&start, &end, count),
-					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+					 c->name, object_size, count, usecs, bps);
 				fflush(stdout);
 			}
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, src_stolen, dst_user, object_size, count);
+			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec((char *)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);
+		}
+	}
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest_f("stolen-%s", c->name) {
+			gem_set_caching(fd, src_stolen, c->level);
+
+			for (count = 1; count <= 1<<17; count <<= 1) {
+				struct timeval start, end;
+
+				gettimeofday(&start, NULL);
+				do_gem_read(fd, src_stolen, dst_user,
+					    object_size, count);
+				gettimeofday(&end, NULL);
+				usecs = elapsed(&start, &end, count);
+				bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
+				igt_info("Time to stolen-%s pread %d bytes x %6d:      %7.3fµs, %s\n",
+					 c->name, object_size, count, usecs, bps);
+				fflush(stdout);
+			}
+		}
+	}
+
+	/* List the time taken in pread operation for stolen objects, with
+	 * and without the overhead of page fault handling on accessing the
+	 * user space buffer
+	 */
+	igt_subtest("pagefault-pread") {
+		large_stolen = gem_create_stolen(fd, LARGE_OBJECT_SIZE);
+		stolen_nopf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
+						PROT_WRITE,
+						MAP_ANONYMOUS|MAP_PRIVATE,
+						-1, 0);
+		igt_assert(stolen_nopf_user);
+
+		for (count = 1; count <= 10; count ++) {
+			struct timeval start, end;
+			double t_elapsed = 0;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_nopf_user,
+				    LARGE_OBJECT_SIZE, 1);
+			gettimeofday(&end, NULL);
+			t_elapsed = elapsed(&start, &end, 1);
+			bps = bytes_per_sec((char *)buf, object_size/t_elapsed*1e6);
+			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
+				 LARGE_OBJECT_SIZE, t_elapsed, bps);
+
+			stolen_pf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
+						      PROT_WRITE,
+						      MAP_ANONYMOUS|MAP_PRIVATE,
+						      -1, 0);
+			igt_assert(stolen_pf_user);
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_pf_user,
+				    LARGE_OBJECT_SIZE, 1);
+			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
+			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
+				 LARGE_OBJECT_SIZE, usecs,
+				 t_elapsed < usecs ? KGRN : KRED, bps, KNRM);
+			fflush(stdout);
+			munmap(stolen_pf_user, LARGE_OBJECT_SIZE);
+		}
+		munmap(stolen_nopf_user, LARGE_OBJECT_SIZE);
+		gem_close(fd, large_stolen);
+	}
+
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(dst_user);
+		gem_close(fd, src_stolen);
 
 		close(fd);
 	}
diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
index 5b6a77f..892c531 100644
--- a/tests/gem_pwrite.c
+++ b/tests/gem_pwrite.c
@@ -135,11 +135,14 @@ static void test_big_gtt(int fd, int scale)
 }
 
 uint32_t *src, dst;
+uint32_t *src_user, dst_stolen;
 int fd;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
+	double usecs;
+	char* bps;
 	uint32_t buf[20];
 	int count;
 	const struct {
@@ -150,6 +153,9 @@ int main(int argc, char **argv)
 		{ 1, "snoop" },
 		{ 2, "display" },
 		{ -1 },
+		{ -1, "stolen-uncached"},
+		{ -1, "stolen-snoop"},
+		{ -1, "stolen-display"},
 	}, *c;
 
 	igt_skip_on_simulation();
@@ -167,6 +173,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		dst_stolen = gem_create_stolen(fd, object_size);
+		src_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -176,10 +184,10 @@ int main(int argc, char **argv)
 			gettimeofday(&start, NULL);
 			do_gem_write(fd, dst, src, object_size, count);
 			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
 			igt_info("Time to pwrite %d bytes x %6d:	%7.3fµs, %s\n",
-				 object_size, count,
-				 elapsed(&start, &end, count),
-				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+				 object_size, count, usecs, bps);
 			fflush(stdout);
 		}
 	}
@@ -194,10 +202,44 @@ int main(int argc, char **argv)
 				gettimeofday(&start, NULL);
 				do_gem_write(fd, dst, src, object_size, count);
 				gettimeofday(&end, NULL);
+				usecs = elapsed(&start, &end, count);
+				bps = bytes_per_sec((char *)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("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_write(fd, dst_stolen, src_user,
+				     object_size, count);
+			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec((char *)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);
+		}
+	}
+
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest((c + 4)->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_stolen, src_user,
+					     object_size, count);
+				gettimeofday(&end, NULL);
+				igt_info("Time to stolen-%s pwrite %d bytes x %6d:     %7.3fµs, %s\n",
 					 c->name, object_size, count,
-					 elapsed(&start, &end, count),
-					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+					 usecs, bps);
 				fflush(stdout);
 			}
 		}
@@ -206,6 +248,8 @@ int main(int argc, char **argv)
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(src_user);
+		gem_close(fd, dst_stolen);
 	}
 
 	igt_subtest("big-cpu")
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-07-22 13:45 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
@ 2015-07-22 16:14   ` Tvrtko Ursulin
  0 siblings, 0 replies; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-07-22 16:14 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath


Hi,

On 07/22/2015 02:45 PM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This patch adds support to verify pread/pwrite for non-shmem backed
> objects. It also shows the pread/pwrite speed.
> It also tests speeds for pread with and without user side page faults
>
> v2: Fixed Rebase conflicts (Ankit)
>
> v3: Precalculating values to avoid redundant function calls (Dave)
> Replaced igt_subtest by igt_subtest_f, added asserts for mmap, corrected
> indentation (Tvrtko)
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
>   tests/gem_pread.c  | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++---
>   tests/gem_pwrite.c |  54 ++++++++++++++++++++++++---
>   2 files changed, 149 insertions(+), 11 deletions(-)
>
> diff --git a/tests/gem_pread.c b/tests/gem_pread.c
> index cc83948..21fccd0 100644
> --- a/tests/gem_pread.c
> +++ b/tests/gem_pread.c
> @@ -41,6 +41,10 @@
>   #include "drmtest.h"
>
>   #define OBJECT_SIZE 16384
> +#define LARGE_OBJECT_SIZE 1024 * 1024
> +#define KGRN "\x1B[32m"
> +#define KRED "\x1B[31m"
> +#define KNRM "\x1B[0m"
>
>   static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
>   {
> @@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)
>
>
>   uint32_t *src, dst;
> +uint32_t *dst_user, src_stolen, large_stolen;
> +uint32_t *stolen_pf_user, *stolen_nopf_user;
>   int fd, count;
>
>   int main(int argc, char **argv)
>   {
>   	int object_size = 0;
> +	double usecs;
>   	uint32_t buf[20];

Well you could have changed this to char buf[something big], all the 
users do (char *)buf and you have touched all (or at least a lot of) 
lines which do that...

> +	char* bps;
>   	const struct {
>   		int level;
>   		const char *name;
> @@ -106,6 +114,8 @@ int main(int argc, char **argv)
>
>   		dst = gem_create(fd, object_size);
>   		src = malloc(object_size);
> +		src_stolen = gem_create_stolen(fd, object_size);
> +		dst_user = malloc(object_size);
>   	}
>
>   	igt_subtest("normal") {
> @@ -115,10 +125,10 @@ int main(int argc, char **argv)
>   			gettimeofday(&start, NULL);
>   			do_gem_read(fd, dst, src, object_size, count);
>   			gettimeofday(&end, NULL);
> +			usecs = elapsed(&start, &end, count);
> +			bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
>   			igt_info("Time to pread %d bytes x %6d:	%7.3fµs, %s\n",
> -				 object_size, count,
> -				 elapsed(&start, &end, count),
> -				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +				 object_size, count, usecs, bps);
>   			fflush(stdout);
>   		}
>   	}
> @@ -133,18 +143,102 @@ int main(int argc, char **argv)
>   				gettimeofday(&start, NULL);
>   				do_gem_read(fd, dst, src, object_size, count);
>   				gettimeofday(&end, NULL);
> +				usecs = elapsed(&start, &end, count);
> +				bps = bytes_per_sec((char *)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,
> -					 elapsed(&start, &end, count),
> -					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +					 c->name, object_size, count, usecs, bps);
>   				fflush(stdout);
>   			}
>   		}
>   	}
>
> +	igt_subtest("stolen-normal") {
> +		for (count = 1; count <= 1<<17; count <<= 1) {
> +			struct timeval start, end;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, src_stolen, dst_user, object_size, count);
> +			gettimeofday(&end, NULL);
> +			usecs = elapsed(&start, &end, count);
> +			bps = bytes_per_sec((char *)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);
> +		}
> +	}
> +	for (c = cache; c->level != -1; c++) {
> +		igt_subtest_f("stolen-%s", c->name) {
> +			gem_set_caching(fd, src_stolen, c->level);
> +
> +			for (count = 1; count <= 1<<17; count <<= 1) {
> +				struct timeval start, end;
> +
> +				gettimeofday(&start, NULL);
> +				do_gem_read(fd, src_stolen, dst_user,
> +					    object_size, count);
> +				gettimeofday(&end, NULL);
> +				usecs = elapsed(&start, &end, count);
> +				bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
> +				igt_info("Time to stolen-%s pread %d bytes x %6d:      %7.3fµs, %s\n",
> +					 c->name, object_size, count, usecs, bps);
> +				fflush(stdout);
> +			}
> +		}
> +	}
> +
> +	/* List the time taken in pread operation for stolen objects, with
> +	 * and without the overhead of page fault handling on accessing the
> +	 * user space buffer
> +	 */
> +	igt_subtest("pagefault-pread") {
> +		large_stolen = gem_create_stolen(fd, LARGE_OBJECT_SIZE);
> +		stolen_nopf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
> +						PROT_WRITE,
> +						MAP_ANONYMOUS|MAP_PRIVATE,
> +						-1, 0);
> +		igt_assert(stolen_nopf_user);
> +
> +		for (count = 1; count <= 10; count ++) {
> +			struct timeval start, end;
> +			double t_elapsed = 0;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_nopf_user,
> +				    LARGE_OBJECT_SIZE, 1);
> +			gettimeofday(&end, NULL);
> +			t_elapsed = elapsed(&start, &end, 1);
> +			bps = bytes_per_sec((char *)buf, object_size/t_elapsed*1e6);
> +			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
> +				 LARGE_OBJECT_SIZE, t_elapsed, bps);
> +
> +			stolen_pf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
> +						      PROT_WRITE,
> +						      MAP_ANONYMOUS|MAP_PRIVATE,
> +						      -1, 0);
> +			igt_assert(stolen_pf_user);
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_pf_user,
> +				    LARGE_OBJECT_SIZE, 1);
> +			gettimeofday(&end, NULL);
> +			usecs = elapsed(&start, &end, count);
> +			bps = bytes_per_sec((char *)buf, object_size/usecs*1e6);
> +			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
> +				 LARGE_OBJECT_SIZE, usecs,
> +				 t_elapsed < usecs ? KGRN : KRED, bps, KNRM);
> +			fflush(stdout);
> +			munmap(stolen_pf_user, LARGE_OBJECT_SIZE);
> +		}
> +		munmap(stolen_nopf_user, LARGE_OBJECT_SIZE);
> +		gem_close(fd, large_stolen);
> +	}
> +
> +
>   	igt_fixture {
>   		free(src);
>   		gem_close(fd, dst);
> +		free(dst_user);
> +		gem_close(fd, src_stolen);
>
>   		close(fd);
>   	}
> diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
> index 5b6a77f..892c531 100644
> --- a/tests/gem_pwrite.c
> +++ b/tests/gem_pwrite.c
> @@ -135,11 +135,14 @@ static void test_big_gtt(int fd, int scale)
>   }
>
>   uint32_t *src, dst;
> +uint32_t *src_user, dst_stolen;
>   int fd;
>
>   int main(int argc, char **argv)
>   {
>   	int object_size = 0;
> +	double usecs;
> +	char* bps;
>   	uint32_t buf[20];
>   	int count;
>   	const struct {
> @@ -150,6 +153,9 @@ int main(int argc, char **argv)
>   		{ 1, "snoop" },
>   		{ 2, "display" },
>   		{ -1 },
> +		{ -1, "stolen-uncached"},
> +		{ -1, "stolen-snoop"},
> +		{ -1, "stolen-display"},

Oh you kept this hack and corresponding "c + 4" here. ;(

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-09-15  8:36 [PATCH v4 0/3] Tests for verifying the old and extended " ankitprasad.r.sharma
@ 2015-09-15  8:36 ` ankitprasad.r.sharma
  2015-09-15 15:35   ` Tvrtko Ursulin
  0 siblings, 1 reply; 17+ messages in thread
From: ankitprasad.r.sharma @ 2015-09-15  8:36 UTC (permalink / raw)
  To: intel-gfx; +Cc: Ankitprasad Sharma, akash.goel, shashidhar.hiremath

From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>

This patch adds support to verify pread/pwrite for non-shmem backed
objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faults

v2: Fixed Rebase conflicts (Ankit)

v3: Precalculating values to avoid redundant function calls (Dave)
Replaced igt_subtest by igt_subtest_f, added asserts for mmap, corrected
indentation (Tvrtko)

v4: Updated data types to avoid redundant type conversions (Tvrtko)
Corrected pagefault-pread time calculation (Ankit)

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 tests/gem_pread.c  | 108 +++++++++++++++++++++++++++++++++++++++++++++++++----
 tests/gem_pwrite.c |  55 ++++++++++++++++++++++++---
 2 files changed, 150 insertions(+), 13 deletions(-)

diff --git a/tests/gem_pread.c b/tests/gem_pread.c
index cc83948..41553b8 100644
--- a/tests/gem_pread.c
+++ b/tests/gem_pread.c
@@ -41,6 +41,10 @@
 #include "drmtest.h"
 
 #define OBJECT_SIZE 16384
+#define LARGE_OBJECT_SIZE 1024 * 1024
+#define KGRN "\x1B[32m"
+#define KRED "\x1B[31m"
+#define KNRM "\x1B[0m"
 
 static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
 {
@@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)
 
 
 uint32_t *src, dst;
+uint32_t *dst_user, src_stolen, large_stolen;
+uint32_t *stolen_pf_user, *stolen_nopf_user;
 int fd, count;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
-	uint32_t buf[20];
+	double usecs;
+	char buf[100];
+	char* bps;
 	const struct {
 		int level;
 		const char *name;
@@ -106,6 +114,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		src_stolen = gem_create_stolen(fd, object_size);
+		dst_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -115,10 +125,10 @@ int main(int argc, char **argv)
 			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,
-				 elapsed(&start, &end, count),
-				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+				 object_size, count, usecs, bps);
 			fflush(stdout);
 		}
 	}
@@ -133,18 +143,102 @@ int main(int argc, char **argv)
 				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,
-					 elapsed(&start, &end, count),
-					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+					 c->name, object_size, count, usecs, bps);
 				fflush(stdout);
 			}
 		}
 	}
 
+	igt_subtest("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, src_stolen, dst_user, 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);
+		}
+	}
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest_f("stolen-%s", c->name) {
+			gem_set_caching(fd, src_stolen, c->level);
+
+			for (count = 1; count <= 1<<17; count <<= 1) {
+				struct timeval start, end;
+
+				gettimeofday(&start, NULL);
+				do_gem_read(fd, src_stolen, dst_user,
+					    object_size, count);
+				gettimeofday(&end, NULL);
+				usecs = elapsed(&start, &end, count);
+				bps = bytes_per_sec(buf, object_size/usecs*1e6);
+				igt_info("Time to stolen-%s pread %d bytes x %6d:      %7.3fµs, %s\n",
+					 c->name, object_size, count, usecs, bps);
+				fflush(stdout);
+			}
+		}
+	}
+
+	/* List the time taken in pread operation for stolen objects, with
+	 * and without the overhead of page fault handling on accessing the
+	 * user space buffer
+	 */
+	igt_subtest("pagefault-pread") {
+		large_stolen = gem_create_stolen(fd, LARGE_OBJECT_SIZE);
+		stolen_nopf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
+						PROT_WRITE,
+						MAP_ANONYMOUS|MAP_PRIVATE,
+						-1, 0);
+		igt_assert(stolen_nopf_user);
+
+		for (count = 1; count <= 10; count ++) {
+			struct timeval start, end;
+			double t_elapsed = 0;
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_nopf_user,
+				    LARGE_OBJECT_SIZE, 1);
+			gettimeofday(&end, NULL);
+			t_elapsed = elapsed(&start, &end, count);
+			bps = bytes_per_sec(buf, object_size/t_elapsed*1e6);
+			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
+				 LARGE_OBJECT_SIZE, t_elapsed, bps);
+
+			stolen_pf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
+						      PROT_WRITE,
+						      MAP_ANONYMOUS|MAP_PRIVATE,
+						      -1, 0);
+			igt_assert(stolen_pf_user);
+
+			gettimeofday(&start, NULL);
+			do_gem_read(fd, large_stolen, stolen_pf_user,
+				    LARGE_OBJECT_SIZE, 1);
+			gettimeofday(&end, NULL);
+			usecs = elapsed(&start, &end, count);
+			bps = bytes_per_sec(buf, object_size/usecs*1e6);
+			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
+				 LARGE_OBJECT_SIZE, usecs,
+				 t_elapsed < usecs ? KGRN : KRED, bps, KNRM);
+			fflush(stdout);
+			munmap(stolen_pf_user, LARGE_OBJECT_SIZE);
+		}
+		munmap(stolen_nopf_user, LARGE_OBJECT_SIZE);
+		gem_close(fd, large_stolen);
+	}
+
+
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(dst_user);
+		gem_close(fd, src_stolen);
 
 		close(fd);
 	}
diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
index 5b6a77f..23509c5 100644
--- a/tests/gem_pwrite.c
+++ b/tests/gem_pwrite.c
@@ -135,12 +135,15 @@ static void test_big_gtt(int fd, int scale)
 }
 
 uint32_t *src, dst;
+uint32_t *src_user, dst_stolen;
 int fd;
 
 int main(int argc, char **argv)
 {
 	int object_size = 0;
-	uint32_t buf[20];
+	double usecs;
+	char* bps;
+	char buf[100];
 	int count;
 	const struct {
 		int level;
@@ -167,6 +170,8 @@ int main(int argc, char **argv)
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
+		dst_stolen = gem_create_stolen(fd, object_size);
+		src_user = malloc(object_size);
 	}
 
 	igt_subtest("normal") {
@@ -176,10 +181,10 @@ int main(int argc, char **argv)
 			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,
-				 elapsed(&start, &end, count),
-				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+				 object_size, count, usecs, bps);
 			fflush(stdout);
 		}
 	}
@@ -194,10 +199,46 @@ int main(int argc, char **argv)
 				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("stolen-normal") {
+		for (count = 1; count <= 1<<17; count <<= 1) {
+			struct timeval start, end;
+
+			gettimeofday(&start, NULL);
+			do_gem_write(fd, dst_stolen, src_user,
+				     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);
+		}
+	}
+
+	for (c = cache; c->level != -1; c++) {
+		igt_subtest_f("stolen-%s", 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_stolen, src_user,
+					     object_size, count);
+				gettimeofday(&end, NULL);
+				bps = bytes_per_sec(buf,
+						    object_size/usecs*1e6);
+				igt_info("Time to stolen-%s pwrite %d bytes x %6d:     %7.3fµs, %s\n",
 					 c->name, object_size, count,
-					 elapsed(&start, &end, count),
-					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+					 usecs, bps);
 				fflush(stdout);
 			}
 		}
@@ -206,6 +247,8 @@ int main(int argc, char **argv)
 	igt_fixture {
 		free(src);
 		gem_close(fd, dst);
+		free(src_user);
+		gem_close(fd, dst_stolen);
 	}
 
 	igt_subtest("big-cpu")
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
  2015-09-15  8:36 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
@ 2015-09-15 15:35   ` Tvrtko Ursulin
  0 siblings, 0 replies; 17+ messages in thread
From: Tvrtko Ursulin @ 2015-09-15 15:35 UTC (permalink / raw)
  To: ankitprasad.r.sharma, intel-gfx; +Cc: akash.goel, shashidhar.hiremath



On 09/15/2015 09:36 AM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This patch adds support to verify pread/pwrite for non-shmem backed
> objects. It also shows the pread/pwrite speed.
> It also tests speeds for pread with and without user side page faults
>
> v2: Fixed Rebase conflicts (Ankit)
>
> v3: Precalculating values to avoid redundant function calls (Dave)
> Replaced igt_subtest by igt_subtest_f, added asserts for mmap, corrected
> indentation (Tvrtko)
>
> v4: Updated data types to avoid redundant type conversions (Tvrtko)
> Corrected pagefault-pread time calculation (Ankit)
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
>   tests/gem_pread.c  | 108 +++++++++++++++++++++++++++++++++++++++++++++++++----
>   tests/gem_pwrite.c |  55 ++++++++++++++++++++++++---
>   2 files changed, 150 insertions(+), 13 deletions(-)
>
> diff --git a/tests/gem_pread.c b/tests/gem_pread.c
> index cc83948..41553b8 100644
> --- a/tests/gem_pread.c
> +++ b/tests/gem_pread.c
> @@ -41,6 +41,10 @@
>   #include "drmtest.h"
>
>   #define OBJECT_SIZE 16384
> +#define LARGE_OBJECT_SIZE 1024 * 1024
> +#define KGRN "\x1B[32m"
> +#define KRED "\x1B[31m"
> +#define KNRM "\x1B[0m"
>
>   static void do_gem_read(int fd, uint32_t handle, void *buf, int len, int loops)
>   {
> @@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)
>
>
>   uint32_t *src, dst;
> +uint32_t *dst_user, src_stolen, large_stolen;
> +uint32_t *stolen_pf_user, *stolen_nopf_user;
>   int fd, count;
>
>   int main(int argc, char **argv)
>   {
>   	int object_size = 0;
> -	uint32_t buf[20];
> +	double usecs;
> +	char buf[100];
> +	char* bps;
>   	const struct {
>   		int level;
>   		const char *name;
> @@ -106,6 +114,8 @@ int main(int argc, char **argv)
>
>   		dst = gem_create(fd, object_size);
>   		src = malloc(object_size);
> +		src_stolen = gem_create_stolen(fd, object_size);
> +		dst_user = malloc(object_size);
>   	}
>
>   	igt_subtest("normal") {
> @@ -115,10 +125,10 @@ int main(int argc, char **argv)
>   			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,
> -				 elapsed(&start, &end, count),
> -				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +				 object_size, count, usecs, bps);
>   			fflush(stdout);
>   		}
>   	}
> @@ -133,18 +143,102 @@ int main(int argc, char **argv)
>   				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,
> -					 elapsed(&start, &end, count),
> -					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +					 c->name, object_size, count, usecs, bps);
>   				fflush(stdout);
>   			}
>   		}
>   	}
>
> +	igt_subtest("stolen-normal") {
> +		for (count = 1; count <= 1<<17; count <<= 1) {
> +			struct timeval start, end;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, src_stolen, dst_user, 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);
> +		}
> +	}
> +	for (c = cache; c->level != -1; c++) {
> +		igt_subtest_f("stolen-%s", c->name) {
> +			gem_set_caching(fd, src_stolen, c->level);
> +
> +			for (count = 1; count <= 1<<17; count <<= 1) {
> +				struct timeval start, end;
> +
> +				gettimeofday(&start, NULL);
> +				do_gem_read(fd, src_stolen, dst_user,
> +					    object_size, count);
> +				gettimeofday(&end, NULL);
> +				usecs = elapsed(&start, &end, count);
> +				bps = bytes_per_sec(buf, object_size/usecs*1e6);
> +				igt_info("Time to stolen-%s pread %d bytes x %6d:      %7.3fµs, %s\n",
> +					 c->name, object_size, count, usecs, bps);
> +				fflush(stdout);
> +			}
> +		}
> +	}
> +
> +	/* List the time taken in pread operation for stolen objects, with
> +	 * and without the overhead of page fault handling on accessing the
> +	 * user space buffer
> +	 */
> +	igt_subtest("pagefault-pread") {
> +		large_stolen = gem_create_stolen(fd, LARGE_OBJECT_SIZE);
> +		stolen_nopf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
> +						PROT_WRITE,
> +						MAP_ANONYMOUS|MAP_PRIVATE,
> +						-1, 0);
> +		igt_assert(stolen_nopf_user);
> +
> +		for (count = 1; count <= 10; count ++) {
> +			struct timeval start, end;
> +			double t_elapsed = 0;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_nopf_user,
> +				    LARGE_OBJECT_SIZE, 1);
> +			gettimeofday(&end, NULL);
> +			t_elapsed = elapsed(&start, &end, count);
> +			bps = bytes_per_sec(buf, object_size/t_elapsed*1e6);
> +			igt_info("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n",
> +				 LARGE_OBJECT_SIZE, t_elapsed, bps);
> +
> +			stolen_pf_user = (uint32_t *) mmap(NULL, LARGE_OBJECT_SIZE,
> +						      PROT_WRITE,
> +						      MAP_ANONYMOUS|MAP_PRIVATE,
> +						      -1, 0);
> +			igt_assert(stolen_pf_user);
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_read(fd, large_stolen, stolen_pf_user,
> +				    LARGE_OBJECT_SIZE, 1);
> +			gettimeofday(&end, NULL);
> +			usecs = elapsed(&start, &end, count);
> +			bps = bytes_per_sec(buf, object_size/usecs*1e6);
> +			igt_info("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n",
> +				 LARGE_OBJECT_SIZE, usecs,
> +				 t_elapsed < usecs ? KGRN : KRED, bps, KNRM);
> +			fflush(stdout);
> +			munmap(stolen_pf_user, LARGE_OBJECT_SIZE);
> +		}
> +		munmap(stolen_nopf_user, LARGE_OBJECT_SIZE);
> +		gem_close(fd, large_stolen);
> +	}
> +
> +
>   	igt_fixture {
>   		free(src);
>   		gem_close(fd, dst);
> +		free(dst_user);
> +		gem_close(fd, src_stolen);
>
>   		close(fd);
>   	}
> diff --git a/tests/gem_pwrite.c b/tests/gem_pwrite.c
> index 5b6a77f..23509c5 100644
> --- a/tests/gem_pwrite.c
> +++ b/tests/gem_pwrite.c
> @@ -135,12 +135,15 @@ static void test_big_gtt(int fd, int scale)
>   }
>
>   uint32_t *src, dst;
> +uint32_t *src_user, dst_stolen;
>   int fd;
>
>   int main(int argc, char **argv)
>   {
>   	int object_size = 0;
> -	uint32_t buf[20];
> +	double usecs;
> +	char* bps;
> +	char buf[100];
>   	int count;
>   	const struct {
>   		int level;
> @@ -167,6 +170,8 @@ int main(int argc, char **argv)
>
>   		dst = gem_create(fd, object_size);
>   		src = malloc(object_size);
> +		dst_stolen = gem_create_stolen(fd, object_size);
> +		src_user = malloc(object_size);
>   	}
>
>   	igt_subtest("normal") {
> @@ -176,10 +181,10 @@ int main(int argc, char **argv)
>   			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,
> -				 elapsed(&start, &end, count),
> -				 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +				 object_size, count, usecs, bps);
>   			fflush(stdout);
>   		}
>   	}
> @@ -194,10 +199,46 @@ int main(int argc, char **argv)
>   				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("stolen-normal") {
> +		for (count = 1; count <= 1<<17; count <<= 1) {
> +			struct timeval start, end;
> +
> +			gettimeofday(&start, NULL);
> +			do_gem_write(fd, dst_stolen, src_user,
> +				     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);
> +		}
> +	}
> +
> +	for (c = cache; c->level != -1; c++) {
> +		igt_subtest_f("stolen-%s", 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_stolen, src_user,
> +					     object_size, count);
> +				gettimeofday(&end, NULL);
> +				bps = bytes_per_sec(buf,
> +						    object_size/usecs*1e6);
> +				igt_info("Time to stolen-%s pwrite %d bytes x %6d:     %7.3fµs, %s\n",
>   					 c->name, object_size, count,
> -					 elapsed(&start, &end, count),
> -					 bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
> +					 usecs, bps);
>   				fflush(stdout);
>   			}
>   		}
> @@ -206,6 +247,8 @@ int main(int argc, char **argv)
>   	igt_fixture {
>   		free(src);
>   		gem_close(fd, dst);
> +		free(src_user);
> +		gem_close(fd, dst_stolen);
>   	}
>
>   	igt_subtest("big-cpu")
>

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-09-15 15:35 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-01  9:26 [PATCH v2 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
2015-07-01  9:26 ` [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl ankitprasad.r.sharma
2015-07-03  9:05   ` Tvrtko Ursulin
2015-07-03  9:16     ` Chris Wilson
2015-07-03  9:38       ` Tvrtko Ursulin
2015-07-01  9:26 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
2015-07-03  9:37   ` Tvrtko Ursulin
2015-07-06 14:33     ` Dave Gordon
2015-07-21 12:38     ` Ankitprasad Sharma
2015-07-01  9:26 ` [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl ankitprasad.r.sharma
2015-07-03  9:52   ` Tvrtko Ursulin
2015-07-21 13:09     ` Ankitprasad Sharma
  -- strict thread matches above, loose matches on Subject: below --
2015-09-15  8:36 [PATCH v4 0/3] Tests for verifying the old and extended " ankitprasad.r.sharma
2015-09-15  8:36 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
2015-09-15 15:35   ` Tvrtko Ursulin
2015-07-22 13:45 [PATCH v3 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
2015-07-22 13:45 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma
2015-07-22 16:14   ` Tvrtko Ursulin
2015-05-13 11:53 [PATCH 0/3] Tests for verifying the old and extended GEM_CREATE ioctl ankitprasad.r.sharma
2015-05-13 11:53 ` [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj ankitprasad.r.sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox