[PATCH] test/gem_gtt_speed: Add a baseline test for the performance of a CPU mmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When looking at the pwrite/pread/wc performance, it is useful to judge
that against the performance of an ordinary CPU mmap.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/drmtest.c         |   15 ++++++++++-
 lib/drmtest.h         |    6 ++++-
 tests/gem_gtt_speed.c |   72 +++++++++++++++++++++++++++++++++++++++++++------
 tests/gem_mmap.c      |   22 +++++++--------
 4 files changed, 94 insertions(+), 21 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index f9f10e1..cdf46aa 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -311,7 +311,7 @@ uint32_t gem_create(int fd, int size)
 	return create.handle;
 }
 
-void *gem_mmap(int fd, uint32_t handle, int size, int prot)
+void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot)
 {
 	struct drm_i915_gem_mmap_gtt mmap_arg;
 	void *ptr;
@@ -327,6 +327,19 @@ void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 	return ptr;
 }
 
+void *gem_mmap__cpu(int fd, uint32_t handle, int size, int prot)
+{
+	struct drm_i915_gem_mmap mmap_arg;
+
+	mmap_arg.handle = handle;
+	mmap_arg.offset = 0;
+	mmap_arg.size = size;
+	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
+		return NULL;
+
+	return (void *)(uintptr_t)mmap_arg.addr_ptr;
+}
+
 uint64_t gem_aperture_size(int fd)
 {
 	struct drm_i915_gem_get_aperture aperture;
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 9f27e2c..4021104 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -52,7 +52,11 @@ 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);
 uint32_t gem_create(int fd, int size);
-void *gem_mmap(int fd, uint32_t handle, int size, int prot);
+
+void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot);
+void *gem_mmap__cpu(int fd, uint32_t handle, int size, int prot);
+#define gem_mmap gem_mmap__gtt
+
 uint64_t gem_aperture_size(int fd);
 uint64_t gem_mappable_aperture_size(void);
 int gem_madvise(int fd, uint32_t handle, int state);
diff --git a/tests/gem_gtt_speed.c b/tests/gem_gtt_speed.c
index 69cd1ff..73a3c6d 100644
--- a/tests/gem_gtt_speed.c
+++ b/tests/gem_gtt_speed.c
@@ -83,6 +83,58 @@ int main(int argc, char **argv)
 		}
 
 		if (tiling == I915_TILING_NONE) {
+			gem_set_domain(fd, handle,
+				       I915_GEM_DOMAIN_CPU,
+				       I915_GEM_DOMAIN_CPU);
+
+			{
+				uint32_t *base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
+				volatile uint32_t *ptr = base;
+				int x = 0;
+
+				for (i = 0; i < size/sizeof(*ptr); i++)
+					x += ptr[i];
+
+				/* force overtly clever gcc to actually compute x */
+				ptr[0] = x;
+
+				munmap(base, size);
+
+				/* mmap read */
+				gettimeofday(&start, NULL);
+				for (loop = 0; loop < 1000; loop++) {
+					base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
+					ptr = base;
+					x = 0;
+
+					for (i = 0; i < size/sizeof(*ptr); i++)
+						x += ptr[i];
+
+					/* force overtly clever gcc to actually compute x */
+					ptr[0] = x;
+
+					munmap(base, size);
+				}
+				gettimeofday(&end, NULL);
+				printf("Time to read %dk through a CPU map:		%7.3f?s\n",
+				       size/1024, elapsed(&start, &end, loop));
+
+				/* mmap write */
+				gettimeofday(&start, NULL);
+				for (loop = 0; loop < 1000; loop++) {
+					base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE);
+					ptr = base;
+
+					for (i = 0; i < size/sizeof(*ptr); i++)
+						ptr[i] = i;
+
+					munmap(base, size);
+				}
+				gettimeofday(&end, NULL);
+				printf("Time to write %dk through a CPU map:		%7.3f?s\n",
+				       size/1024, elapsed(&start, &end, loop));
+			}
+
 			/* CPU pwrite */
 			gettimeofday(&start, NULL);
 			for (loop = 0; loop < 1000; loop++)
@@ -102,7 +154,8 @@ int main(int argc, char **argv)
 
 		/* prefault into gtt */
 		{
-			uint32_t *ptr = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			volatile uint32_t *ptr = base;
 			int x = 0;
 
 			for (i = 0; i < size/sizeof(*ptr); i++)
@@ -111,12 +164,13 @@ int main(int argc, char **argv)
 			/* force overtly clever gcc to actually compute x */
 			ptr[0] = x;
 
-			munmap(ptr, size);
+			munmap(base, size);
 		}
 		/* mmap read */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
-			uint32_t *ptr = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			volatile uint32_t *ptr = base;
 			int x = 0;
 
 			for (i = 0; i < size/sizeof(*ptr); i++)
@@ -125,7 +179,7 @@ int main(int argc, char **argv)
 			/* force overtly clever gcc to actually compute x */
 			ptr[0] = x;
 
-			munmap(ptr, size);
+			munmap(base, size);
 		}
 		gettimeofday(&end, NULL);
 		printf("Time to read %dk through a GTT map:		%7.3f?s\n",
@@ -134,12 +188,13 @@ int main(int argc, char **argv)
 		/* mmap write */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
-			uint32_t *ptr = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			volatile uint32_t *ptr = base;
 
 			for (i = 0; i < size/sizeof(*ptr); i++)
 				ptr[i] = i;
 
-			munmap(ptr, size);
+			munmap(base, size);
 		}
 		gettimeofday(&end, NULL);
 		printf("Time to write %dk through a GTT map:		%7.3f?s\n",
@@ -148,7 +203,8 @@ int main(int argc, char **argv)
 		/* mmap read */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
-			uint32_t *ptr = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
+			volatile uint32_t *ptr = base;
 			int x = 0;
 
 			for (i = 0; i < size/sizeof(*ptr); i++)
@@ -157,7 +213,7 @@ int main(int argc, char **argv)
 			/* force overtly clever gcc to actually compute x */
 			ptr[0] = x;
 
-			munmap(ptr, size);
+			munmap(base, size);
 		}
 		gettimeofday(&end, NULL);
 		printf("Time to read %dk (again) through a GTT map:	%7.3f?s\n",
diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c
index 6ba6e3b..f9369f4 100644
--- a/tests/gem_mmap.c
+++ b/tests/gem_mmap.c
@@ -45,7 +45,7 @@
 int main(int argc, char **argv)
 {
 	int fd;
-	struct drm_i915_gem_mmap gem_mmap;
+	struct drm_i915_gem_mmap arg;
 	uint8_t expected[OBJECT_SIZE];
 	uint8_t buf[OBJECT_SIZE];
 	uint8_t *addr;
@@ -54,23 +54,23 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	memset(&gem_mmap, 0, sizeof(gem_mmap));
-	gem_mmap.handle = 0x10101010;
-	gem_mmap.offset = 0;
-	gem_mmap.size = 4096;
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = 0x10101010;
+	arg.offset = 0;
+	arg.size = 4096;
 	printf("Testing mmaping of bad object.\n");
-	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &gem_mmap);
+	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
 	assert(ret == -1 && errno == ENOENT);
 
 	handle = gem_create(fd, OBJECT_SIZE);
 
 	printf("Testing mmaping of newly created object.\n");
-	gem_mmap.handle = handle;
-	gem_mmap.offset = 0;
-	gem_mmap.size = OBJECT_SIZE;
-	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &gem_mmap);
+	arg.handle = handle;
+	arg.offset = 0;
+	arg.size = OBJECT_SIZE;
+	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
 	assert(ret == 0);
-	addr = (uint8_t *)(uintptr_t)gem_mmap.addr_ptr;
+	addr = (uint8_t *)(uintptr_t)arg.addr_ptr;
 
 	printf("Testing contents of newly created object.\n");
 	memset(expected, 0, sizeof(expected));
-- 
1.7.10



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux