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>
This commit is contained in:
Chris Wilson 2012-06-04 17:29:20 +01:00
parent b558877f6e
commit 77586dcdf7
4 changed files with 94 additions and 21 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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",

View File

@ -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));