[igt-dev] [PATCH i-g-t v2 4/4] tests/i915/gem_exec_basic: Iterate over all memory regions

Zbigniew Kempczyński
2019-11-19T16:02:49Z

From: Lukasz Kalamarz <lukasz.kalamarz@intel.com>

As a part of local memory effort we need to make sure, that basic
scenarios are covered for every available memory region. This patch is
an attempt for this problem. If it will be accepted it will be
replicated on each test that can benefit from it.

Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz@intel.com>
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
tests/i915/gem_exec_basic.c | 109 +++++++++++++++++++++++-------------
1 file changed, 70 insertions(+), 39 deletions(-)

diff --git a/tests/i915/gem_exec_basic.c b/tests/i915/gem_exec_basic.c
index 1287860b..4a444916 100644
--- a/tests/i915/gem_exec_basic.c
+++ b/tests/i915/gem_exec_basic.c
@@ -25,12 +25,12 @@

IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");

-static uint32_t batch_create(int fd)
+static uint32_t batch_create(int fd, uint32_t batch_size, uint32_t region)
{
const uint32_t bbe = MI_BATCH_BUFFER_END;
uint32_t handle;

- handle = gem_create(fd, 4096);
+ handle = gem_create_in_memory_regions(fd, batch_size, region);
gem_write(fd, handle, 0, &bbe, sizeof(bbe));

return handle;
@@ -42,7 +42,7 @@ static void batch_fini(int fd, uint32_t handle)
gem_close(fd, handle);
}

-static void noop(int fd, uint64_t flags)
+static void noop(int fd, uint64_t flags, uint32_t batch_size, uint32_t region)
{
struct drm_i915_gem_execbuffer2 execbuf;
struct drm_i915_gem_exec_object2 exec;
@@ -50,8 +50,7 @@ static void noop(int fd, uint64_t flags)
gem_require_ring(fd, flags);

memset(&exec, 0, sizeof(exec));
-
- exec.handle = batch_create(fd);
+ exec.handle = batch_create(fd, batch_size, region);

memset(&execbuf, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(&exec);
@@ -62,7 +61,8 @@ static void noop(int fd, uint64_t flags)
batch_fini(fd, exec.handle);
}

-static void readonly(int fd, uint64_t flags)
+static void readonly(int fd, uint64_t flags, uint32_t batch_size,
+ uint32_t region)
{
struct drm_i915_gem_execbuffer2 *execbuf;
struct drm_i915_gem_exec_object2 exec;
@@ -70,39 +70,41 @@ static void readonly(int fd, uint64_t flags)
gem_require_ring(fd, flags);

memset(&exec, 0, sizeof(exec));
- exec.handle = batch_create(fd);
+ exec.handle = batch_create(fd, batch_size, region);

- execbuf = mmap(NULL, 4096, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ execbuf = mmap(NULL, batch_size, PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
igt_assert(execbuf != NULL);

execbuf->buffers_ptr = to_user_pointer(&exec);
execbuf->buffer_count = 1;
execbuf->flags = flags;
- igt_assert(mprotect(execbuf, 4096, PROT_READ) == 0);
+ igt_assert(mprotect(execbuf, batch_size, PROT_READ) == 0);

gem_execbuf(fd, execbuf);

- munmap(execbuf, 4096);
-
+ munmap(execbuf, batch_size);
batch_fini(fd, exec.handle);
}

-static void gtt(int fd, uint64_t flags)
+static void gtt(int fd, uint64_t flags, uint32_t batch_size, uint32_t region)
{
struct drm_i915_gem_execbuffer2 *execbuf;
struct drm_i915_gem_exec_object2 *exec;
uint32_t handle;

gem_require_ring(fd, flags);
+ gem_require_mappable_ggtt(fd);
+ igt_require(IS_SYSTEM_MEMORY_REGION(region));

- handle = gem_create(fd, 4096);
-
+ handle = gem_create_in_memory_regions(fd, handle, region);
gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
- execbuf = gem_mmap__gtt(fd, handle, 4096, PROT_WRITE);
+
+ execbuf = gem_mmap__gtt(fd, handle, batch_size, PROT_WRITE);
exec = (struct drm_i915_gem_exec_object2 *)(execbuf + 1);
gem_close(fd, handle);

- exec->handle = batch_create(fd);
+ exec->handle = batch_create(fd, batch_size, region);

execbuf->buffers_ptr = to_user_pointer(exec);
execbuf->buffer_count = 1;
@@ -111,36 +113,41 @@ static void gtt(int fd, uint64_t flags)
gem_execbuf(fd, execbuf);

batch_fini(fd, exec->handle);
- munmap(execbuf, 4096);
+ munmap(execbuf, batch_size);
}

-static void all(int i915)
+static void all(int i915, uint32_t batch_size, uint32_t region)
{
const struct intel_execution_engine2 *e;

__for_each_physical_engine(i915, e)
- noop(i915, e->flags);
+ noop(i915, e->flags, batch_size, region);
}

-static void readonly_all(int i915)
+static void readonly_all(int i915, uint32_t batch_size, uint32_t region)
{
const struct intel_execution_engine2 *e;

__for_each_physical_engine(i915, e)
- readonly(i915, e->flags);
+ readonly(i915, e->flags, batch_size, region);
}

-static void gtt_all(int i915)
+static void gtt_all(int i915, uint32_t batch_size, uint32_t region)
{
const struct intel_execution_engine2 *e;

__for_each_physical_engine(i915, e)
- gtt(i915, e->flags);
+ gtt(i915, e->flags, batch_size, region);
}

igt_main
{
const struct intel_execution_engine2 *e;
+ const struct intel_memory_region *mr;
+ struct local_i915_query_memory_region_info *query_info;
+ uint32_t mem_type, mem_instance;
+ uint32_t batch_size;
+ uint32_t region;
int fd = -1;

igt_fixture {
@@ -148,27 +155,51 @@ igt_main
igt_require_gem(fd);

igt_fork_hang_detector(fd);
- }
-
- igt_subtest("basic-all")
- all(fd);

- igt_subtest("readonly-all")
- readonly_all(fd);
-
- igt_subtest("gtt-all")
- gtt_all(fd);
+ query_info = gem_query_memory_regions(fd);
+ igt_assert(query_info);
+ }

- __for_each_physical_engine(fd, e) {
- igt_subtest_f("basic-%s", e->name)
- noop(fd, e->flags);
- igt_subtest_f("readonly-%s", e->name)
- readonly(fd, e->flags);
- igt_subtest_f("gtt-%s", e->name)
- gtt(fd, e->flags);
+ for (mr = intel_memory_regions; mr->region_name; mr++) {
+ mem_type = mr->memory_type;
+ mem_instance = mr->memory_instance;
+ region = INTEL_MEMORY_REGION_ID(mem_type, mem_instance);
+
+ batch_size = gem_get_batch_size(fd, region);
+
+ igt_subtest_f("basic-%s-all", mr->region_name) {
+ gem_query_require_region(query_info, region);
+ all(fd, batch_size, region);
+ }
+
+ igt_subtest_f("readonly-%s-all", mr->region_name) {
+ gem_query_require_region(query_info, region);
+ readonly_all(fd, batch_size, region);
+ }
+
+ igt_subtest_f("gtt-%s-all", mr->region_name) {
+ gem_query_require_region(query_info, region);
+ gtt_all(fd, batch_size, region);
+ }
+
+ __for_each_physical_engine(fd, e) {
+ igt_subtest_f("basic-%s-%s", mr->region_name, e->name) {
+ gem_query_require_region(query_info, region);
+ noop(fd, e->flags, batch_size, region);
+ }
+ igt_subtest_f("readonly-%s-%s", mr->region_name, e->name) {
+ gem_query_require_region(query_info, region);
+ readonly(fd, e->flags, batch_size, region);
+ }
+ igt_subtest_f("gtt-%s-%s", mr->region_name, e->name) {
+ gem_query_require_region(query_info, region);
+ gtt(fd, e->flags, batch_size, region);
+ }
+ }
}

igt_fixture {
+ free(query_info);
igt_stop_hang_detector();
close(fd);
}
--
2.23.0