summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-06-04 17:29:20 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2012-06-04 17:50:51 +0100
commit77586dcdf7240aebf29d3d70313dce9d79108147 (patch)
tree4a185b10d392ff3bec898e5f8a50b79dbf53c3dd /tests
parentb558877f6e25663ece1242f1e658cf1630d7d7fe (diff)
test/gem_gtt_speed: Add a baseline test for the performance of a CPU mmap
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@chris-wilson.co.uk> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'tests')
-rw-r--r--tests/gem_gtt_speed.c72
-rw-r--r--tests/gem_mmap.c22
2 files changed, 75 insertions, 19 deletions
diff --git a/tests/gem_gtt_speed.c b/tests/gem_gtt_speed.c
index 69cd1ff3..73a3c6dc 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 6ba6e3b3..f9369f43 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));