#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <sys/mman.h>
#include <sys/time.h>
#include "drm.h"
-#include "i915_drm.h"
+#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "intel_chipset.h"
#include "intel_bufmgr.h"
#include "intel_batchbuffer.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
#define OBJECT_SIZE 16384
-#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
+#define COPY_BLT_CMD (2<<29|0x53<<22)
#define BLT_WRITE_ALPHA (1<<21)
#define BLT_WRITE_RGB (1<<20)
#define BLT_SRC_TILED (1<<15)
#define BLT_DST_TILED (1<<11)
+uint32_t is_64bit;
+uint32_t exec_flags;
+
+static inline void build_batch(uint32_t *batch, int len, uint32_t *batch_len)
+{
+ unsigned int i = 0;
+
+ batch[i++] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB | (is_64bit ? 8 : 6);
+ batch[i++] = 0xcc << 16 | 1 << 25 | 1 << 24 | len;
+ batch[i++] = 0;
+ batch[i++] = 1 << 16 | (len / 4);
+ batch[i++] = 0; /* dst */
+ if (is_64bit)
+ batch[i++] = 0;
+ batch[i++] = 0;
+ batch[i++] = len;
+ batch[i++] = 0; /* src */
+ if (is_64bit)
+ batch[i++] = 0;
+ batch[i++] = MI_BATCH_BUFFER_END;
+ batch[i++] = 0;
+
+ *batch_len = i * 4;
+}
+
+#define BUILD_EXEC \
+ uint32_t batch[12]; \
+ struct drm_i915_gem_relocation_entry reloc[] = { \
+ { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER }, \
+ { src, 0, (is_64bit ? 8 : 7)*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 }, \
+ }; \
+ struct drm_i915_gem_exec_object2 exec[] = { \
+ { src }, \
+ { dst }, \
+ { gem_create(fd, 4096), 2, (uintptr_t)reloc } \
+ }; \
+ struct drm_i915_gem_execbuffer2 execbuf = { \
+ (uintptr_t)exec, 3, \
+ 0, 0, \
+ 0, 0, 0, 0, \
+ exec_flags, \
+ }; \
+ build_batch(batch, len, &execbuf.batch_len); \
+ gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+
+
static void copy(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
while (loops--) {
gem_write(fd, src, 0, buf, len);
static void as_gtt_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
uint32_t *src_ptr, *dst_ptr;
-
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
src_ptr = gem_mmap__gtt(fd, src, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__gtt(fd, dst, OBJECT_SIZE, PROT_READ);
static void as_cpu_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
uint32_t *src_ptr, *dst_ptr;
-
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ);
static void test_copy(int fd, uint32_t src, uint32_t dst, uint32_t *buf, int len)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
int i;
-
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
for (i = 0; i < len/4; i++)
buf[i] = i;
gem_close(fd, exec[2].handle);
for (i = 0; i < len/4; i++)
- assert(buf[i] == i);
+ igt_assert(buf[i] == i);
}
static void test_as_gtt_mmap(int fd, uint32_t src, uint32_t dst, int len)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
uint32_t *src_ptr, *dst_ptr;
int i;
-
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
src_ptr = gem_mmap__gtt(fd, src, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__gtt(fd, dst, OBJECT_SIZE, PROT_READ);
gem_set_domain(fd, dst, I915_GEM_DOMAIN_GTT, 0);
for (i = 0; i < len/4; i++)
- assert(dst_ptr[i] == i);
+ igt_assert(dst_ptr[i] == i);
munmap(dst_ptr, len);
munmap(src_ptr, len);
static void test_as_cpu_mmap(int fd, uint32_t src, uint32_t dst, int len)
{
- struct drm_i915_gem_relocation_entry reloc[] = {
- { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
- { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
- };
- struct drm_i915_gem_exec_object2 exec[] = {
- { src },
- { dst },
- { gem_create(fd, 4096), 2, (uintptr_t)reloc }
- };
- uint32_t batch[] = {
- COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB,
- 0xcc << 16 | 1 << 25 | 1 << 24 | len,
- 0,
- 1 << 16 | (len / 4),
- 0, /* dst */
- 0,
- len,
- 0, /* src */
- MI_BATCH_BUFFER_END,
- 0
- };
- struct drm_i915_gem_execbuffer2 execbuf = {
- (uintptr_t)exec, 3,
- 0, sizeof(batch),
- 0, 0, 0, 0,
- HAS_BLT_RING(intel_get_drm_devid(fd)) ? I915_EXEC_BLT : 0,
- };
uint32_t *src_ptr, *dst_ptr;
int i;
-
- gem_write(fd, exec[2].handle, 0, batch, sizeof(batch));
+ BUILD_EXEC;
src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ);
gem_set_domain(fd, dst, I915_GEM_DOMAIN_CPU, 0);
for (i = 0; i < len/4; i++)
- assert(dst_ptr[i] == i);
+ igt_assert(dst_ptr[i] == i);
munmap(dst_ptr, len);
munmap(src_ptr, len);
return buf;
}
+uint32_t *tmp, src, dst;
+int fd;
+
int main(int argc, char **argv)
{
int object_size = 0;
uint32_t buf[20];
- uint32_t *tmp, src, dst;
- int fd, count;
+ int count;
- drmtest_subtest_init(argc, argv);
- drmtest_skip_on_simulation();
+ igt_subtest_init(argc, argv);
+ igt_skip_on_simulation();
if (argc > 1)
object_size = atoi(argv[1]);
object_size = OBJECT_SIZE;
object_size = (object_size + 3) & -4;
- fd = drm_open_any();
+ igt_fixture {
+ uint32_t devid;
- dst = gem_create(fd, object_size);
- src = gem_create(fd, object_size);
- tmp = malloc(object_size);
+ fd = drm_open_any();
- gem_set_caching(fd, src, 0);
- gem_set_caching(fd, dst, 0);
+ dst = gem_create(fd, object_size);
+ src = gem_create(fd, object_size);
+ tmp = malloc(object_size);
- drmtest_subtest("uncached-copy-correctness")
+ gem_set_caching(fd, src, 0);
+ gem_set_caching(fd, dst, 0);
+
+ devid = intel_get_drm_devid(fd);
+ is_64bit = intel_gen(devid) >= 8;
+ exec_flags = HAS_BLT_RING(devid) ? I915_EXEC_BLT : 0;
+ }
+
+ igt_subtest("uncached-copy-correctness")
test_copy(fd, src, dst, tmp, object_size);
- drmtest_subtest("uncached-copy-performance") {
+ igt_subtest("uncached-copy-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
copy(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("Time to uncached copy %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));
+ igt_info("Time to uncached copy %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);
}
}
- drmtest_subtest("uncached-pwrite-blt-gtt_mmap-correctness")
+ igt_subtest("uncached-pwrite-blt-gtt_mmap-correctness")
test_as_gtt_mmap(fd, src, dst, object_size);
- drmtest_subtest("uncached-pwrite-blt-gtt_mmap-performance") {
+ igt_subtest("uncached-pwrite-blt-gtt_mmap-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
as_gtt_mmap(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("** mmap uncached copy %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));
+ igt_info("** mmap uncached copy %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);
}
}
- gem_set_caching(fd, src, 1);
- gem_set_caching(fd, dst, 1);
+ igt_fixture {
+ gem_set_caching(fd, src, 1);
+ gem_set_caching(fd, dst, 1);
+ }
- drmtest_subtest("snooped-copy-correctness")
+ igt_subtest("snooped-copy-correctness")
test_copy(fd, src, dst, tmp, object_size);
- drmtest_subtest("snooped-copy-performance") {
+ igt_subtest("snooped-copy-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
copy(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("Time to snooped copy %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));
+ igt_info("Time to snooped copy %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);
}
}
- drmtest_subtest("snooped-pwrite-blt-cpu_mmap-correctness")
+ igt_subtest("snooped-pwrite-blt-cpu_mmap-correctness")
test_as_cpu_mmap(fd, src, dst, object_size);
- drmtest_subtest("snooped-pwrite-blt-cpu_mmap-performance") {
+ igt_subtest("snooped-pwrite-blt-cpu_mmap-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
as_cpu_mmap(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("** mmap snooped copy %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));
+ igt_info("** mmap snooped copy %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);
}
}
- gem_set_caching(fd, src, 2);
- gem_set_caching(fd, dst, 2);
+ igt_fixture {
+ gem_set_caching(fd, src, 2);
+ gem_set_caching(fd, dst, 2);
+ }
- drmtest_subtest("display-copy-correctness")
+ igt_subtest("display-copy-correctness")
test_copy(fd, src, dst, tmp, object_size);
- drmtest_subtest("display-copy-performance") {
+ igt_subtest("display-copy-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
copy(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("Time to display copy %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));
+ igt_info("Time to display copy %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);
}
}
- drmtest_subtest("display-pwrite-blt-gtt_mmap-correctness")
+ igt_subtest("display-pwrite-blt-gtt_mmap-correctness")
test_as_gtt_mmap(fd, src, dst, object_size);
- drmtest_subtest("display-pwrite-blt-gtt_mmap-performance") {
+ igt_subtest("display-pwrite-blt-gtt_mmap-performance") {
for (count = 1; count <= 1<<17; count <<= 1) {
struct timeval start, end;
gettimeofday(&start, NULL);
as_gtt_mmap(fd, src, dst, tmp, object_size, count);
gettimeofday(&end, NULL);
- printf("** mmap display copy %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));
+ igt_info("** mmap display copy %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);
}
}
- free(tmp);
- gem_close(fd, src);
- gem_close(fd, dst);
+ igt_fixture {
+ free(tmp);
+ gem_close(fd, src);
+ gem_close(fd, dst);
- close(fd);
+ close(fd);
+ }
- return drmtest_retval();
+ igt_exit();
}