[igt-dev] [RFC v2 19/43] tests/i915/gem_exec_fence: use the gem_engine_topology library

Ramalingam C
2019-06-21T10:01:32Z

tests/i915/gem_exec_fence.c | 112 +++++++++++++++++++-----------------
1 file changed, 58 insertions(+), 54 deletions(-)

diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c
index 0befb54f8d02..1f4f3bd91142 100644
--- a/tests/i915/gem_exec_fence.c
+++ b/tests/i915/gem_exec_fence.c
@@ -57,7 +57,8 @@ struct sync_merge_data {
#define SYNC_IOC_MERGE _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
#endif

-static void store(int fd, unsigned ring, int fence, uint32_t target, unsigned offset_value)
+static void store(int fd, const struct intel_execution_engine2 *e, int fence,
+ uint32_t target, unsigned offset_value)
{
const int SCRATCH = 0;
const int BATCH = 1;
@@ -71,7 +72,7 @@ static void store(int fd, unsigned ring, int fence, uint32_t target, unsigned of
memset(&execbuf, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.buffer_count = 2;
- execbuf.flags = ring | LOCAL_EXEC_FENCE_IN;
+ execbuf.flags = e->flags | LOCAL_EXEC_FENCE_IN;
execbuf.rsvd2 = fence;
if (gen < 6)
execbuf.flags |= I915_EXEC_SECURE;
@@ -119,7 +120,8 @@ static bool fence_busy(int fence)
#define NONBLOCK 0x2
#define WAIT 0x4

-static void test_fence_busy(int fd, unsigned ring, unsigned flags)
+static void test_fence_busy(int fd, const struct intel_execution_engine2 *e,
+ unsigned flags)
{
const int gen = intel_gen(intel_get_drm_devid(fd));
struct drm_i915_gem_exec_object2 obj;
@@ -134,7 +136,7 @@ static void test_fence_busy(int fd, unsigned ring, unsigned flags)
memset(&execbuf, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(&obj);
execbuf.buffer_count = 1;
- execbuf.flags = ring | LOCAL_EXEC_FENCE_OUT;
+ execbuf.flags = e->flags | LOCAL_EXEC_FENCE_OUT;

memset(&obj, 0, sizeof(obj));
obj.handle = gem_create(fd, 4096);
@@ -216,7 +218,7 @@ static void test_fence_busy_all(int fd, unsigned flags)
struct drm_i915_gem_execbuffer2 execbuf;
struct timespec tv;
uint32_t *batch;
- unsigned int engine;
+ const struct intel_execution_engine2 *e;
int all, i, timeout;

gem_quiescent_gpu(fd);
@@ -263,10 +265,10 @@ static void test_fence_busy_all(int fd, unsigned flags)
i++;

all = -1;
- for_each_engine(fd, engine) {
+ __for_each_static_engine(e) {
int fence, new;

- execbuf.flags = engine | LOCAL_EXEC_FENCE_OUT;
+ execbuf.flags = e->flags | LOCAL_EXEC_FENCE_OUT;
execbuf.rsvd2 = -1;
gem_execbuf_wr(fd, &execbuf);
fence = execbuf.rsvd2 >> 32;
@@ -315,11 +317,12 @@ static void test_fence_busy_all(int fd, unsigned flags)
gem_quiescent_gpu(fd);
}

-static void test_fence_await(int fd, unsigned ring, unsigned flags)
+static void test_fence_await(int fd, const struct intel_execution_engine2 *e,
+ unsigned flags)
{
uint32_t scratch = gem_create(fd, 4096);
igt_spin_t *spin;
- unsigned engine;
+ const struct intel_execution_engine2 *other;
uint32_t *out;
int i;

@@ -330,20 +333,20 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);

spin = igt_spin_new(fd,
- .engine = ring,
+ .engine = e->flags,
.flags = IGT_SPIN_FENCE_OUT);
igt_assert(spin->out_fence != -1);

i = 0;
- for_each_physical_engine(fd, engine) {
- if (!gem_can_store_dword(fd, engine))
+ __for_each_physical_engine(fd, other) {
+ if (!gem_class_can_store_dword(fd, other->class))
continue;

if (flags & NONBLOCK) {
- store(fd, engine, spin->out_fence, scratch, i);
+ store(fd, other, spin->out_fence, scratch, i);
} else {
igt_fork(child, 1)
- store(fd, engine, spin->out_fence, scratch, i);
+ store(fd, other, spin->out_fence, scratch, i);
}

i++;
@@ -370,13 +373,14 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
gem_close(fd, scratch);
}

-static void resubmit(int fd, uint32_t handle, unsigned int ring, int count)
+static void resubmit(int fd, uint32_t handle,
+ const struct intel_execution_engine2 *e, int count)
{
struct drm_i915_gem_exec_object2 obj = { .handle = handle };
struct drm_i915_gem_execbuffer2 execbuf = {
.buffers_ptr = to_user_pointer(&obj),
.buffer_count = 1,
- .flags = ring,
+ .flags = e->flags,
};
while (count--)
gem_execbuf(fd, &execbuf);
@@ -398,7 +402,7 @@ static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
return err;
}

-static void test_parallel(int fd, unsigned int master)
+static void test_parallel(int fd, const struct intel_execution_engine2 *e)
{
const int SCRATCH = 0;
const int BATCH = 1;
@@ -411,7 +415,7 @@ static void test_parallel(int fd, unsigned int master)
uint32_t handle[16];
uint32_t batch[16];
igt_spin_t *spin;
- unsigned engine;
+ const struct intel_execution_engine2 *other;
IGT_CORK_HANDLE(c);
uint32_t plug;
int i, x = 0;
@@ -421,14 +425,14 @@ static void test_parallel(int fd, unsigned int master)
/* Fill the queue with many requests so that the next one has to
* wait before it can be executed by the hardware.
*/
- spin = igt_spin_new(fd, .engine = master, .dependency = plug);
- resubmit(fd, spin->handle, master, 16);
+ spin = igt_spin_new(fd, .engine = e->flags, .dependency = plug);
+ resubmit(fd, spin->handle, e, 16);

/* Now queue the master request and its secondaries */
memset(&execbuf, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.buffer_count = 2;
- execbuf.flags = master | LOCAL_EXEC_FENCE_OUT;
+ execbuf.flags = e->flags | LOCAL_EXEC_FENCE_OUT;
if (gen < 6)
execbuf.flags |= I915_EXEC_SECURE;

@@ -497,11 +501,11 @@ static void test_parallel(int fd, unsigned int master)
obj[BATCH].relocation_count = 1;

/* Queue all secondaries */
- for_each_physical_engine(fd, engine) {
- if (engine == master)
+ __for_each_physical_engine(fd, other) {
+ if (other == e)
continue;

- execbuf.flags = engine | LOCAL_EXEC_FENCE_SUBMIT;
+ execbuf.flags = other->flags | LOCAL_EXEC_FENCE_SUBMIT;
if (gen < 6)
execbuf.flags |= I915_EXEC_SECURE;

@@ -588,7 +592,8 @@ static inline uint32_t upper_32_bits(uint64_t x)
return x >> 32;
}

-static void test_keep_in_fence(int fd, unsigned int engine, unsigned int flags)
+static void test_keep_in_fence(int fd, const struct intel_execution_engine2 *e,
+ unsigned int flags)
{
struct sigaction sa = { .sa_handler = alarm_handler };
struct drm_i915_gem_exec_object2 obj = {
@@ -597,14 +602,14 @@ static void test_keep_in_fence(int fd, unsigned int engine, unsigned int flags)
struct drm_i915_gem_execbuffer2 execbuf = {
.buffers_ptr = to_user_pointer(&obj),
.buffer_count = 1,
- .flags = engine | LOCAL_EXEC_FENCE_OUT,
+ .flags = e->flags | LOCAL_EXEC_FENCE_OUT,
};
unsigned long count, last;
struct itimerval itv;
igt_spin_t *spin;
int fence;

- spin = igt_spin_new(fd, .engine = engine);
+ spin = igt_spin_new(fd, .engine = e->flags);

gem_execbuf_wr(fd, &execbuf);
fence = upper_32_bits(execbuf.rsvd2);
@@ -662,7 +667,8 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
const uint32_t bbe = MI_BATCH_BUFFER_END;
struct drm_i915_gem_exec_object2 obj[2];
struct drm_i915_gem_execbuffer2 execbuf;
- unsigned int engines[16], engine;
+ unsigned int engines[16];
+ const struct intel_execution_engine2 *e;
unsigned int nengine, n, s;
unsigned long limit;
int all_fences;
@@ -673,8 +679,8 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
limit = ring_size / 3;

nengine = 0;
- for_each_physical_engine(fd, engine)
- engines[nengine++] = engine;
+ __for_each_physical_engine(fd, e)
+ engines[nengine++] = e->flags;
igt_require(nengine);

gem_quiescent_gpu(fd);
@@ -1155,7 +1161,7 @@ static void test_syncobj_wait(int fd)
.handle = syncobj_create(fd),
};
igt_spin_t *spin;
- unsigned engine;
+ const struct intel_execution_engine2 *e;
unsigned handle[16];
int n;

@@ -1188,13 +1194,13 @@ static void test_syncobj_wait(int fd)
gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));

n = 0;
- for_each_engine(fd, engine) {
+ __for_each_static_engine(e) {
obj.handle = gem_create(fd, 4096);
gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));

/* No inter-engine synchronisation, will complete */
- if (engine == I915_EXEC_BLT) {
- execbuf.flags = engine;
+ if (e->class == I915_ENGINE_CLASS_COPY) {
+ execbuf.flags = e->flags;
execbuf.cliprects_ptr = 0;
execbuf.num_cliprects = 0;
gem_execbuf(fd, &execbuf);
@@ -1204,7 +1210,7 @@ static void test_syncobj_wait(int fd)
igt_assert(gem_bo_busy(fd, spin->handle));

/* Now wait upon the blocked engine */
- execbuf.flags = LOCAL_EXEC_FENCE_ARRAY | engine;
+ execbuf.flags = LOCAL_EXEC_FENCE_ARRAY | e->flags;
execbuf.cliprects_ptr = to_user_pointer(&fence);
execbuf.num_cliprects = 1;
fence.flags = LOCAL_EXEC_FENCE_WAIT;
@@ -1513,7 +1519,7 @@ static void test_syncobj_channel(int fd)

igt_main
{
- const struct intel_execution_engine *e;
+ const struct intel_execution_engine2 *e;
int i915 = -1;

igt_fixture {
@@ -1545,11 +1551,10 @@ igt_main
test_fence_busy_all(i915, WAIT | HANG);
}

- for (e = intel_execution_engines; e->name; e++) {
+ __for_each_physical_engine(i915, e) {
igt_subtest_group {
igt_fixture {
- igt_require(gem_has_ring(i915, e->exec_id | e->flags));
- igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+ igt_require(gem_class_can_store_dword(i915, e->class));
}

igt_subtest_group {
@@ -1558,29 +1563,28 @@ igt_main
}

igt_subtest_f("%sbusy-%s",
- e->exec_id == 0 ? "basic-" : "",
+ e->class == I915_ENGINE_CLASS_RENDER ? "basic-" : "",
e->name)
- test_fence_busy(i915, e->exec_id | e->flags, 0);
+ test_fence_busy(i915, e, 0);
igt_subtest_f("%swait-%s",
- e->exec_id == 0 ? "basic-" : "",
+ e->class == I915_ENGINE_CLASS_RENDER ? "basic-" : "",
e->name)
- test_fence_busy(i915, e->exec_id | e->flags, WAIT);
+ test_fence_busy(i915, e, WAIT);
igt_subtest_f("%sawait-%s",
- e->exec_id == 0 ? "basic-" : "",
+ e->class == I915_ENGINE_CLASS_RENDER ? "basic-" : "",
e->name)
- test_fence_await(i915, e->exec_id | e->flags, 0);
+ test_fence_await(i915, e, 0);
igt_subtest_f("nb-await-%s", e->name)
- test_fence_await(i915, e->exec_id | e->flags, NONBLOCK);
+ test_fence_await(i915, e, NONBLOCK);

igt_subtest_f("keep-in-fence-%s", e->name)
- test_keep_in_fence(i915, e->exec_id | e->flags, 0);
+ test_keep_in_fence(i915, e, 0);

- if (e->exec_id &&
- !(e->exec_id == I915_EXEC_BSD && !e->flags)) {
+ if (!(e->class == I915_ENGINE_CLASS_VIDEO && !e->flags)) {
igt_subtest_f("parallel-%s", e->name) {
igt_require(has_submit_fence(i915));
igt_until_timeout(2)
- test_parallel(i915, e->exec_id | e->flags);
+ test_parallel(i915, e);
}
}

@@ -1599,13 +1603,13 @@ igt_main
}

igt_subtest_f("busy-hang-%s", e->name)
- test_fence_busy(i915, e->exec_id | e->flags, HANG);
+ test_fence_busy(i915, e, HANG);
igt_subtest_f("wait-hang-%s", e->name)
- test_fence_busy(i915, e->exec_id | e->flags, HANG | WAIT);
+ test_fence_busy(i915, e, HANG | WAIT);
igt_subtest_f("await-hang-%s", e->name)
- test_fence_await(i915, e->exec_id | e->flags, HANG);
+ test_fence_await(i915, e, HANG);
igt_subtest_f("nb-await-hang-%s", e->name)
- test_fence_await(i915, e->exec_id | e->flags, NONBLOCK | HANG);
+ test_fence_await(i915, e, NONBLOCK | HANG);
igt_fixture {
igt_disallow_hang(i915, hang);