[PATCH i-g-t] lib/i915: Use explicit iterator names in for_each_engine()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Provide the iterator name as an explicit macro parameter so that it is
known to the caller, and allows for them to properly nest loops over all
engines.

Fixes:
../tests/i915/gem_exec_schedule.c: In function ‘semaphore_noskip’:
../lib/igt_gt.h:84:44: warning: declaration of ‘e__’ shadows a previous local [-Wshadow]
  for (const struct intel_execution_engine *e__ = intel_execution_engines;\
                                            ^~~
../tests/i915/gem_exec_schedule.c:653:2: note: in expansion of macro ‘for_each_physical_engine’
  for_each_physical_engine(i915, other) {
  ^~~~~~~~~~~~~~~~~~~~~~~~
../lib/igt_gt.h:84:44: note: shadowed declaration is here
  for (const struct intel_execution_engine *e__ = intel_execution_engines;\
                                            ^~~
../tests/i915/gem_exec_schedule.c:652:2: note: in expansion of macro ‘for_each_physical_engine’
  for_each_physical_engine(i915, engine) {
  ^~~~~~~~~~~~~~~~~~~~~~~~
../tests/i915/gem_exec_schedule.c: In function ‘measure_semaphore_power’:
../lib/igt_gt.h:84:44: warning: declaration of ‘e__’ shadows a previous local [-Wshadow]
  for (const struct intel_execution_engine *e__ = intel_execution_engines;\
                                            ^~~
../tests/i915/gem_exec_schedule.c:1740:3: note: in expansion of macro ‘for_each_physical_engine’
   for_each_physical_engine(i915, engine) {
   ^~~~~~~~~~~~~~~~~~~~~~~~
../lib/igt_gt.h:84:44: note: shadowed declaration is here
  for (const struct intel_execution_engine *e__ = intel_execution_engines;\
                                            ^~~
../tests/i915/gem_exec_schedule.c:1719:2: note: in expansion of macro ‘for_each_physical_engine’
  for_each_physical_engine(i915, signaler) {
  ^~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
Cc: Andi Shyti <andi.shyti@xxxxxxxxx>
---
 benchmarks/gem_syslatency.c     |  16 +--
 lib/i915/gem_ring.c             |   4 +-
 lib/igt_gt.h                    |  24 +++--
 tests/amdgpu/amd_prime.c        |   6 +-
 tests/i915/gem_bad_reloc.c      |   4 +-
 tests/i915/gem_busy.c           |   4 +-
 tests/i915/gem_concurrent_all.c |   7 +-
 tests/i915/gem_cs_prefetch.c    |   2 +-
 tests/i915/gem_ctx_create.c     |  12 +--
 tests/i915/gem_ctx_shared.c     |  43 ++++----
 tests/i915/gem_ctx_switch.c     |   2 +-
 tests/i915/gem_ctx_thrash.c     |  14 ++-
 tests/i915/gem_eio.c            |  29 +++---
 tests/i915/gem_exec_async.c     |  13 ++-
 tests/i915/gem_exec_await.c     |   7 +-
 tests/i915/gem_exec_capture.c   |   6 +-
 tests/i915/gem_exec_create.c    |   8 +-
 tests/i915/gem_exec_fence.c     |  61 ++++++-----
 tests/i915/gem_exec_flush.c     |   2 +-
 tests/i915/gem_exec_gttfill.c   |  11 +-
 tests/i915/gem_exec_latency.c   |  33 +++---
 tests/i915/gem_exec_nop.c       |  44 ++++----
 tests/i915/gem_exec_params.c    |  14 +--
 tests/i915/gem_exec_reloc.c     |   8 +-
 tests/i915/gem_exec_reuse.c     |   6 +-
 tests/i915/gem_exec_schedule.c  | 172 +++++++++++++++-----------------
 tests/i915/gem_exec_suspend.c   |  20 ++--
 tests/i915/gem_exec_whisper.c   |   8 +-
 tests/i915/gem_mocs_settings.c  |   6 +-
 tests/i915/gem_reset_stats.c    |  10 +-
 tests/i915/gem_ring_sync_loop.c |   5 +-
 tests/i915/gem_ringfill.c       |   3 +-
 tests/i915/gem_shrink.c         |   5 +-
 tests/i915/gem_spin_batch.c     |   2 +-
 tests/i915/gem_storedw_loop.c   |   2 +-
 tests/i915/gem_sync.c           |  99 +++++++++---------
 tests/i915/gem_userptr_blits.c  |   7 +-
 tests/i915/i915_module_load.c   |  22 ++--
 tests/kms_busy.c                |  30 +++---
 tests/prime_busy.c              |   8 +-
 tests/prime_vgem.c              |  16 +--
 41 files changed, 368 insertions(+), 427 deletions(-)

diff --git a/benchmarks/gem_syslatency.c b/benchmarks/gem_syslatency.c
index d7cf0ed49..402306300 100644
--- a/benchmarks/gem_syslatency.c
+++ b/benchmarks/gem_syslatency.c
@@ -79,17 +79,6 @@ static void force_low_latency(void)
 
 #define ENGINE_FLAGS  (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK)
 
-static bool ignore_engine(int fd, unsigned engine)
-{
-	if (engine == 0)
-		return true;
-
-	if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD)
-		return true;
-
-	return false;
-}
-
 static void *gem_busyspin(void *arg)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -100,14 +89,13 @@ static void *gem_busyspin(void *arg)
 		bs->sz ? bs->sz + sizeof(bbe) : bs->leak ? 16 << 20 : 4 << 10;
 	unsigned engines[16];
 	unsigned nengine;
-	unsigned engine;
 	int fd;
 
 	fd = drm_open_driver(DRIVER_INTEL);
 
 	nengine = 0;
-	for_each_engine(fd, engine)
-		if (!ignore_engine(fd, engine)) engines[nengine++] = engine;
+	for_each_physical_engine(e, fd)
+		engines[nengine++] = eb_ring(e);
 
 	memset(obj, 0, sizeof(obj));
 	obj[0].handle = gem_create(fd, 4096);
diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
index 5ca2a728b..99f4741cb 100644
--- a/lib/i915/gem_ring.c
+++ b/lib/i915/gem_ring.c
@@ -153,9 +153,9 @@ gem_measure_ring_inflight(int fd, unsigned int engine, enum measure_ring_flags f
 	fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_NONBLOCK);
 
 	if (engine == ALL_ENGINES) {
-		for_each_physical_engine(fd, engine) {
+		for_each_physical_engine(e, fd) {
 			unsigned int count =
-				__gem_measure_ring_inflight(fd, engine, flags);
+				__gem_measure_ring_inflight(fd, eb_ring(e), flags);
 
 			if (count < min)
 				min = count;
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index 73b5002a0..66088d391 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -72,19 +72,21 @@ extern const struct intel_execution_engine {
 	unsigned flags;
 } intel_execution_engines[];
 
+#define eb_ring(e) ((e)->exec_id | (e)->flags)
+
 #define for_if(expr__) if (!(expr__)) {} else
 
-#define for_each_engine(fd__, flags__) \
-	for (const struct intel_execution_engine *e__ = intel_execution_engines;\
-	     e__->name; \
-	     e__++) \
-		for_if (gem_has_ring(fd__, flags__ = e__->exec_id | e__->flags))
-
-#define for_each_physical_engine(fd__, flags__) \
-	for (const struct intel_execution_engine *e__ = intel_execution_engines;\
-	     e__->name; \
-	     e__++) \
-		for_if (gem_ring_has_physical_engine(fd__, flags__ = e__->exec_id | e__->flags))
+#define for_each_engine(it__, fd__) \
+	for (const struct intel_execution_engine *it__ = intel_execution_engines;\
+	     it__->name; \
+	     it__++) \
+		for_if (gem_has_ring(fd__, eb_ring(it__)))
+
+#define for_each_physical_engine(it__, fd__) \
+	for (const struct intel_execution_engine *it__ = intel_execution_engines;\
+	     it__->name; \
+	     it__++) \
+		for_if (gem_ring_has_physical_engine(fd__, eb_ring(it__)))
 
 bool gem_ring_is_physical_engine(int fd, unsigned int ring);
 bool gem_ring_has_physical_engine(int fd, unsigned int ring);
diff --git a/tests/amdgpu/amd_prime.c b/tests/amdgpu/amd_prime.c
index dc71ac70c..fdb8a0283 100644
--- a/tests/amdgpu/amd_prime.c
+++ b/tests/amdgpu/amd_prime.c
@@ -173,14 +173,14 @@ static void i915_to_amd(int i915, int amd, amdgpu_device_handle device)
 	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];
 	unsigned int nengine;
 	unsigned long count;
 	struct cork c;
 
 	nengine = 0;
-	for_each_physical_engine(i915, engine)
-		engines[nengine++] = engine;
+	for_each_physical_engine(e, i915)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	memset(obj, 0, sizeof(obj));
diff --git a/tests/i915/gem_bad_reloc.c b/tests/i915/gem_bad_reloc.c
index c03e5beb3..96c9babe6 100644
--- a/tests/i915/gem_bad_reloc.c
+++ b/tests/i915/gem_bad_reloc.c
@@ -196,10 +196,10 @@ igt_main
 
 	for (e = intel_execution_engines; e->name; e++) {
 		igt_subtest_f("negative-reloc-%s", e->name)
-			negative_reloc(fd, e->exec_id | e->flags, 0);
+			negative_reloc(fd, eb_ring(e), 0);
 
 		igt_subtest_f("negative-reloc-lut-%s", e->name)
-			negative_reloc(fd, e->exec_id | e->flags, USE_LUT);
+			negative_reloc(fd, eb_ring(e), USE_LUT);
 	}
 
 	igt_subtest("negative-reloc-bltcopy")
diff --git a/tests/i915/gem_busy.c b/tests/i915/gem_busy.c
index a55358708..a8388149b 100644
--- a/tests/i915/gem_busy.c
+++ b/tests/i915/gem_busy.c
@@ -319,8 +319,8 @@ static void close_race(int fd)
 	 */
 
 	nengine = 0;
-	for_each_engine(fd, i)
-		engines[nengine++] = i;
+	for_each_engine(e, fd)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
diff --git a/tests/i915/gem_concurrent_all.c b/tests/i915/gem_concurrent_all.c
index 266995d14..992bea62e 100644
--- a/tests/i915/gem_concurrent_all.c
+++ b/tests/i915/gem_concurrent_all.c
@@ -949,15 +949,14 @@ static igt_hang_t rcs_hang(void)
 static igt_hang_t all_hang(void)
 {
 	igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
-	unsigned engine;
 
-	for_each_physical_engine(fd, engine) {
+	for_each_physical_engine(e, fd) {
 		struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf;
 
-		if (engine == I915_EXEC_RENDER)
+		eb.flags = eb_ring(e);
+		if (eb.flags == I915_EXEC_RENDER)
 			continue;
 
-		eb.flags = engine;
 		__gem_execbuf(fd, &eb);
 	}
 
diff --git a/tests/i915/gem_cs_prefetch.c b/tests/i915/gem_cs_prefetch.c
index 2b8653687..171908576 100644
--- a/tests/i915/gem_cs_prefetch.c
+++ b/tests/i915/gem_cs_prefetch.c
@@ -145,5 +145,5 @@ igt_main
 
 	for (e = intel_execution_engines; e->name; e++)
 		igt_subtest_f("%s", e->name)
-			test_ring(e->exec_id | e->flags);
+			test_ring(eb_ring(e));
 }
diff --git a/tests/i915/gem_ctx_create.c b/tests/i915/gem_ctx_create.c
index 1e2c40c4f..83da05690 100644
--- a/tests/i915/gem_ctx_create.c
+++ b/tests/i915/gem_ctx_create.c
@@ -527,14 +527,12 @@ igt_main
 	int fd = -1;
 
 	igt_fixture {
-		unsigned engine;
-
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
 		gem_require_contexts(fd);
 
-		for_each_physical_engine(fd, engine)
-			all_engines[all_nengine++] = engine;
+		for_each_physical_engine(e, fd)
+			all_engines[all_nengine++] = eb_ring(e);
 		igt_require(all_nengine);
 
 		if (gem_uses_full_ppgtt(fd)) {
@@ -582,12 +580,12 @@ igt_main
 	for (const struct intel_execution_engine *e = intel_execution_engines;
 	     e->name; e++) {
 		igt_subtest_f("active-%s", e->name)
-			active(fd, e->exec_id | e->flags, 20, 1);
+			active(fd, eb_ring(e), 20, 1);
 		igt_subtest_f("forked-active-%s", e->name)
-			active(fd, e->exec_id | e->flags, 20, ncpus);
+			active(fd, eb_ring(e), 20, ncpus);
 		if (e->exec_id) {
 			igt_subtest_f("hog-%s", e->name)
-				active(fd, e->exec_id | e->flags, 20, -1);
+				active(fd, eb_ring(e), 20, -1);
 		}
 	}
 
diff --git a/tests/i915/gem_ctx_shared.c b/tests/i915/gem_ctx_shared.c
index f78524822..6d8cbcce2 100644
--- a/tests/i915/gem_ctx_shared.c
+++ b/tests/i915/gem_ctx_shared.c
@@ -326,7 +326,6 @@ static void single_timeline(int i915)
 	struct sync_file_info sync_file_info = {
 		.num_fences = 1,
 	};
-	unsigned int engine;
 	int n;
 
 	igt_require(has_single_timeline(i915));
@@ -347,7 +346,7 @@ static void single_timeline(int i915)
 				  I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE);
 	execbuf.flags = I915_EXEC_FENCE_OUT;
 	n = 0;
-	for_each_engine(i915, engine) {
+	for_each_engine(e, i915) {
 		gem_execbuf_wr(i915, &execbuf);
 		sync_file_info.sync_fence_info = to_user_pointer(&rings[n]);
 		do_ioctl(execbuf.rsvd2 >> 32, SYNC_IOC_FILE_INFO, &sync_file_info);
@@ -368,7 +367,6 @@ static void single_timeline(int i915)
 
 static void exec_single_timeline(int i915, unsigned int engine)
 {
-	unsigned int other;
 	igt_spin_t *spin;
 	uint32_t ctx;
 
@@ -381,17 +379,17 @@ static void exec_single_timeline(int i915, unsigned int engine)
 	 */
 	ctx = 0;
 	spin = NULL;
-	for_each_physical_engine(i915, other) {
-		if (other == engine)
+	for_each_physical_engine(e, i915) {
+		if (eb_ring(e) == engine)
 			continue;
 
 		if (spin == NULL) {
-			spin = __igt_spin_new(i915, .ctx = ctx, .engine = other);
+			spin = __igt_spin_new(i915, .ctx = ctx, .engine = eb_ring(e));
 		} else {
 			struct drm_i915_gem_execbuffer2 execbuf = {
 				.buffers_ptr = spin->execbuf.buffers_ptr,
 				.buffer_count = spin->execbuf.buffer_count,
-				.flags = other,
+				.flags = eb_ring(e),
 				.rsvd1 = ctx,
 			};
 			gem_execbuf(i915, &execbuf);
@@ -409,17 +407,17 @@ static void exec_single_timeline(int i915, unsigned int engine)
 	ctx = gem_context_clone(i915, 0, 0,
 				I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE);
 	spin = NULL;
-	for_each_physical_engine(i915, other) {
-		if (other == engine)
+	for_each_physical_engine(e, i915) {
+		if (eb_ring(e) == engine)
 			continue;
 
 		if (spin == NULL) {
-			spin = __igt_spin_new(i915, .ctx = ctx, .engine = other);
+			spin = __igt_spin_new(i915, .ctx = ctx, .engine = eb_ring(e));
 		} else {
 			struct drm_i915_gem_execbuffer2 execbuf = {
 				.buffers_ptr = spin->execbuf.buffers_ptr,
 				.buffer_count = spin->execbuf.buffer_count,
-				.flags = other,
+				.flags = eb_ring(e),
 				.rsvd1 = ctx,
 			};
 			gem_execbuf(i915, &execbuf);
@@ -742,8 +740,8 @@ static void smoketest(int i915, unsigned ring, unsigned timeout)
 	uint32_t *ptr;
 
 	nengine = 0;
-	for_each_physical_engine(i915, engine)
-		engines[nengine++] = engine;
+	for_each_physical_engine(e, i915)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	scratch = gem_create(i915, 4096);
@@ -827,11 +825,10 @@ igt_main
 
 		for (e = intel_execution_engines; e->name; e++) {
 			igt_subtest_f("exec-shared-gtt-%s", e->name)
-				exec_shared_gtt(i915, e->exec_id | e->flags);
+				exec_shared_gtt(i915, eb_ring(e));
 
 			igt_subtest_f("exec-single-timeline-%s", e->name)
-				exec_single_timeline(i915,
-						     e->exec_id | e->flags);
+				exec_single_timeline(i915, eb_ring(e));
 
 			/*
 			 * Check that the shared contexts operate independently,
@@ -842,26 +839,26 @@ igt_main
 			 */
 			igt_subtest_group {
 				igt_fixture {
-					gem_require_ring(i915, e->exec_id | e->flags);
-					igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+					gem_require_ring(i915, eb_ring(e));
+					igt_require(gem_can_store_dword(i915, eb_ring(e)));
 					igt_require(gem_scheduler_enabled(i915));
 					igt_require(gem_scheduler_has_ctx_priority(i915));
 				}
 
 				igt_subtest_f("Q-independent-%s", e->name)
-					independent(i915, e->exec_id | e->flags, 0);
+					independent(i915, eb_ring(e), 0);
 
 				igt_subtest_f("Q-in-order-%s", e->name)
-					reorder(i915, e->exec_id | e->flags, EQUAL);
+					reorder(i915, eb_ring(e), EQUAL);
 
 				igt_subtest_f("Q-out-order-%s", e->name)
-					reorder(i915, e->exec_id | e->flags, 0);
+					reorder(i915, eb_ring(e), 0);
 
 				igt_subtest_f("Q-promotion-%s", e->name)
-					promotion(i915, e->exec_id | e->flags);
+					promotion(i915, eb_ring(e));
 
 				igt_subtest_f("Q-smoketest-%s", e->name)
-					smoketest(i915, e->exec_id | e->flags, 5);
+					smoketest(i915, eb_ring(e), 5);
 			}
 		}
 
diff --git a/tests/i915/gem_ctx_switch.c b/tests/i915/gem_ctx_switch.c
index c071def78..36ecd5376 100644
--- a/tests/i915/gem_ctx_switch.c
+++ b/tests/i915/gem_ctx_switch.c
@@ -349,7 +349,7 @@ igt_main
 	for (e = intel_execution_engines; e->name; e++) {
 		struct intel_execution_engine2 e2__;
 
-		e2__ = gem_eb_flags_to_engine(e->exec_id | e->flags);
+		e2__ = gem_eb_flags_to_engine(eb_ring(e));
 		if (e2__.flags == -1)
 			continue; /* I915_EXEC_BSD with no ring selectors */
 
diff --git a/tests/i915/gem_ctx_thrash.c b/tests/i915/gem_ctx_thrash.c
index b25f95f13..62c26e9a0 100644
--- a/tests/i915/gem_ctx_thrash.c
+++ b/tests/i915/gem_ctx_thrash.c
@@ -103,13 +103,11 @@ static void single(const char *name, bool all_engines)
 
 	num_engines = 0;
 	if (all_engines) {
-		unsigned engine;
-
-		for_each_physical_engine(fd, engine) {
-			if (!gem_can_store_dword(fd, engine))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			engines[num_engines++] = engine;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -220,7 +218,7 @@ static void single(const char *name, bool all_engines)
 
 static void processes(void)
 {
-	unsigned engines[16], engine;
+	unsigned engines[16];
 	int num_engines;
 	struct rlimit rlim;
 	unsigned num_ctx;
@@ -230,8 +228,8 @@ static void processes(void)
 	fd = drm_open_driver(DRIVER_INTEL);
 
 	num_engines = 0;
-	for_each_physical_engine(fd, engine) {
-		engines[num_engines++] = engine;
+	for_each_physical_engine(e, fd) {
+		engines[num_engines++] = eb_ring(e);
 		if (num_engines == ARRAY_SIZE(engines))
 			break;
 	}
diff --git a/tests/i915/gem_eio.c b/tests/i915/gem_eio.c
index 892f3657c..8d6cb9760 100644
--- a/tests/i915/gem_eio.c
+++ b/tests/i915/gem_eio.c
@@ -427,7 +427,6 @@ static void test_suspend(int fd, int state)
 static void test_inflight(int fd, unsigned int wait)
 {
 	int parent_fd = fd;
-	unsigned int engine;
 	int fence[64]; /* mostly conservative estimate of ring size */
 	int max;
 
@@ -439,7 +438,7 @@ static void test_inflight(int fd, unsigned int wait)
 	max = min(max - 1, ARRAY_SIZE(fence));
 	igt_debug("Using %d inflight batches\n", max);
 
-	for_each_engine(parent_fd, engine) {
+	for_each_engine(e, parent_fd) {
 		const uint32_t bbe = MI_BATCH_BUFFER_END;
 		struct drm_i915_gem_exec_object2 obj[2];
 		struct drm_i915_gem_execbuffer2 execbuf;
@@ -454,16 +453,16 @@ static void test_inflight(int fd, unsigned int wait)
 		gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
 
 		gem_quiescent_gpu(fd);
-		igt_debug("Starting %s on engine '%s'\n", __func__, e__->name);
+		igt_debug("Starting %s on engine '%s'\n", __func__, e->name);
 		igt_require(i915_reset_control(false));
 
-		hang = spin_sync(fd, 0, engine);
+		hang = spin_sync(fd, 0, eb_ring(e));
 		obj[0].handle = hang->handle;
 
 		memset(&execbuf, 0, sizeof(execbuf));
 		execbuf.buffers_ptr = to_user_pointer(obj);
 		execbuf.buffer_count = 2;
-		execbuf.flags = engine | I915_EXEC_FENCE_OUT;
+		execbuf.flags = eb_ring(e) | I915_EXEC_FENCE_OUT;
 
 		for (unsigned int n = 0; n < max; n++) {
 			gem_execbuf_wr(fd, &execbuf);
@@ -563,13 +562,12 @@ static uint32_t context_create_safe(int i915)
 static void test_inflight_contexts(int fd, unsigned int wait)
 {
 	int parent_fd = fd;
-	unsigned int engine;
 
 	igt_require_gem(fd);
 	igt_require(gem_has_exec_fence(fd));
 	gem_require_contexts(fd);
 
-	for_each_engine(parent_fd, engine) {
+	for_each_engine(e, parent_fd) {
 		const uint32_t bbe = MI_BATCH_BUFFER_END;
 		struct drm_i915_gem_exec_object2 obj[2];
 		struct drm_i915_gem_execbuffer2 execbuf;
@@ -586,7 +584,7 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 
 		gem_quiescent_gpu(fd);
 
-		igt_debug("Starting %s on engine '%s'\n", __func__, e__->name);
+		igt_debug("Starting %s on engine '%s'\n", __func__, e->name);
 		igt_require(i915_reset_control(false));
 
 		memset(obj, 0, sizeof(obj));
@@ -594,13 +592,13 @@ static void test_inflight_contexts(int fd, unsigned int wait)
 		obj[1].handle = gem_create(fd, 4096);
 		gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
 
-		hang = spin_sync(fd, 0, engine);
+		hang = spin_sync(fd, 0, eb_ring(e));
 		obj[0].handle = hang->handle;
 
 		memset(&execbuf, 0, sizeof(execbuf));
 		execbuf.buffers_ptr = to_user_pointer(obj);
 		execbuf.buffer_count = 2;
-		execbuf.flags = engine | I915_EXEC_FENCE_OUT;
+		execbuf.flags = eb_ring(e) | I915_EXEC_FENCE_OUT;
 
 		count = 0;
 		for (unsigned int n = 0; n < ARRAY_SIZE(fence); n++) {
@@ -691,7 +689,7 @@ static void test_inflight_internal(int fd, unsigned int wait)
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 obj[2];
 	uint32_t bbe = MI_BATCH_BUFFER_END;
-	unsigned engine, nfence = 0;
+	unsigned nfence = 0;
 	int fences[16];
 	igt_spin_t *hang;
 
@@ -712,8 +710,8 @@ static void test_inflight_internal(int fd, unsigned int wait)
 	memset(&execbuf, 0, sizeof(execbuf));
 	execbuf.buffers_ptr = to_user_pointer(obj);
 	execbuf.buffer_count = 2;
-	for_each_engine(fd, engine) {
-		execbuf.flags = engine | I915_EXEC_FENCE_OUT;
+	for_each_engine(e, fd) {
+		execbuf.flags = eb_ring(e) | I915_EXEC_FENCE_OUT;
 
 		gem_execbuf_wr(fd, &execbuf);
 
@@ -822,10 +820,9 @@ static void reset_stress(int fd, uint32_t ctx0,
 static void test_reset_stress(int fd, unsigned int flags)
 {
 	uint32_t ctx0 = context_create_safe(fd);
-	unsigned int engine;
 
-	for_each_engine(fd, engine)
-		reset_stress(fd, ctx0, e__->name, engine, flags);
+	for_each_engine(e, fd)
+		reset_stress(fd, ctx0, e->name, eb_ring(e), flags);
 
 	gem_context_destroy(fd, ctx0);
 }
diff --git a/tests/i915/gem_exec_async.c b/tests/i915/gem_exec_async.c
index 9a06af7e2..d83e9f6db 100644
--- a/tests/i915/gem_exec_async.c
+++ b/tests/i915/gem_exec_async.c
@@ -88,7 +88,6 @@ static void one(int fd, unsigned ring, uint32_t flags)
 #define BATCH 1
 	struct drm_i915_gem_relocation_entry reloc;
 	struct drm_i915_gem_execbuffer2 execbuf;
-	unsigned int other;
 	uint32_t *batch;
 	int i;
 
@@ -143,14 +142,14 @@ static void one(int fd, unsigned ring, uint32_t flags)
 	gem_close(fd, obj[BATCH].handle);
 
 	i = 0;
-	for_each_physical_engine(fd, other) {
-		if (other == ring)
+	for_each_physical_engine(e, fd) {
+		if (eb_ring(e) == ring)
 			continue;
 
-		if (!gem_can_store_dword(fd, other))
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
-		store_dword(fd, other, obj[SCRATCH].handle, 4*i, i);
+		store_dword(fd, eb_ring(e), obj[SCRATCH].handle, 4*i, i);
 		i++;
 	}
 
@@ -205,8 +204,8 @@ igt_main
 			continue;
 
 		igt_subtest_f("concurrent-writes-%s", e->name) {
-			igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
-			igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
+			igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
+			igt_require(gem_can_store_dword(fd, eb_ring(e)));
 			one(fd, e->exec_id, e->flags);
 		}
 	}
diff --git a/tests/i915/gem_exec_await.c b/tests/i915/gem_exec_await.c
index 5cfeb8ec8..33e2ee45e 100644
--- a/tests/i915/gem_exec_await.c
+++ b/tests/i915/gem_exec_await.c
@@ -73,14 +73,13 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags)
 	} *exec;
 	struct drm_i915_gem_exec_object2 *obj;
 	struct drm_i915_gem_execbuffer2 execbuf;
-	unsigned engines[16];
-	unsigned nengine, engine;
+	unsigned engines[16], nengine;
 	unsigned long count;
 	double time;
 
 	nengine = 0;
-	for_each_physical_engine(fd, engine)
-		engines[nengine++] = engine;
+	for_each_physical_engine(e, fd)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	exec = calloc(nengine, sizeof(*exec));
diff --git a/tests/i915/gem_exec_capture.c b/tests/i915/gem_exec_capture.c
index 4457496d6..54da57aca 100644
--- a/tests/i915/gem_exec_capture.c
+++ b/tests/i915/gem_exec_capture.c
@@ -558,9 +558,9 @@ igt_main
 			continue;
 
 		igt_subtest_f("capture-%s", e->name) {
-			igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
-			igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
-			capture(fd, dir, e->exec_id | e->flags);
+			igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
+			igt_require(gem_can_store_dword(fd, eb_ring(e)));
+			capture(fd, dir, eb_ring(e));
 		}
 	}
 
diff --git a/tests/i915/gem_exec_create.c b/tests/i915/gem_exec_create.c
index 54a2429e4..88c5ddfd9 100644
--- a/tests/i915/gem_exec_create.c
+++ b/tests/i915/gem_exec_create.c
@@ -61,13 +61,11 @@ static void all(int fd, unsigned flags, int timeout, int ncpus)
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 obj;
-	unsigned engines[16];
-	unsigned nengine;
-	unsigned engine;
+	unsigned engines[16], nengine;
 
 	nengine = 0;
-	for_each_physical_engine(fd, engine)
-		engines[nengine++] = engine;
+	for_each_physical_engine(e, fd)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	memset(&obj, 0, sizeof(obj));
diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c
index 2f04d7af4..3657c4b27 100644
--- a/tests/i915/gem_exec_fence.c
+++ b/tests/i915/gem_exec_fence.c
@@ -216,7 +216,6 @@ 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;
 	int all, i, timeout;
 
 	gem_quiescent_gpu(fd);
@@ -263,10 +262,10 @@ static void test_fence_busy_all(int fd, unsigned flags)
 	i++;
 
 	all = -1;
-	for_each_engine(fd, engine) {
+	for_each_engine(e, fd) {
 		int fence, new;
 
-		execbuf.flags = engine | LOCAL_EXEC_FENCE_OUT;
+		execbuf.flags = eb_ring(e) | LOCAL_EXEC_FENCE_OUT;
 		execbuf.rsvd2 = -1;
 		gem_execbuf_wr(fd, &execbuf);
 		fence = execbuf.rsvd2 >> 32;
@@ -319,7 +318,6 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
 {
 	uint32_t scratch = gem_create(fd, 4096);
 	igt_spin_t *spin;
-	unsigned engine;
 	uint32_t *out;
 	int i;
 
@@ -336,15 +334,15 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
 	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(e, fd) {
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
 		if (flags & NONBLOCK) {
-			store(fd, engine, spin->out_fence, scratch, i);
+			store(fd, eb_ring(e), spin->out_fence, scratch, i);
 		} else {
 			igt_fork(child, 1)
-				store(fd, engine, spin->out_fence, scratch, i);
+				store(fd, eb_ring(e), spin->out_fence, scratch, i);
 		}
 
 		i++;
@@ -412,7 +410,6 @@ static void test_parallel(int fd, unsigned int master)
 	uint32_t handle[16];
 	uint32_t batch[16];
 	igt_spin_t *spin;
-	unsigned engine;
 	IGT_CORK_HANDLE(c);
 	uint32_t plug;
 	int i, x = 0;
@@ -498,11 +495,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(e, fd) {
+		if (eb_ring(e) == master)
 			continue;
 
-		execbuf.flags = engine | LOCAL_EXEC_FENCE_SUBMIT;
+		execbuf.flags = eb_ring(e) | LOCAL_EXEC_FENCE_SUBMIT;
 		if (gen < 6)
 			execbuf.flags |= I915_EXEC_SECURE;
 
@@ -663,8 +660,7 @@ 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 nengine, n, s;
+	unsigned int engines[16], nengine, n, s;
 	unsigned long limit;
 	int all_fences;
 	IGT_CORK_HANDLE(c);
@@ -674,8 +670,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(e, fd)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	gem_quiescent_gpu(fd);
@@ -1156,7 +1152,6 @@ static void test_syncobj_wait(int fd)
 		.handle = syncobj_create(fd),
 	};
 	igt_spin_t *spin;
-	unsigned engine;
 	unsigned handle[16];
 	int n;
 
@@ -1189,13 +1184,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_engine(e, fd) {
 		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 (eb_ring(e) == I915_EXEC_BLT) {
+			execbuf.flags = eb_ring(e);
 			execbuf.cliprects_ptr = 0;
 			execbuf.num_cliprects = 0;
 			gem_execbuf(fd, &execbuf);
@@ -1205,7 +1200,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 | eb_ring(e);
 		execbuf.cliprects_ptr = to_user_pointer(&fence);
 		execbuf.num_cliprects = 1;
 		fence.flags = LOCAL_EXEC_FENCE_WAIT;
@@ -1549,8 +1544,8 @@ igt_main
 	for (e = intel_execution_engines; e->name; 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_has_ring(i915, eb_ring(e)));
+				igt_require(gem_can_store_dword(i915, eb_ring(e)));
 			}
 
 			igt_subtest_group {
@@ -1561,27 +1556,27 @@ igt_main
 				igt_subtest_f("%sbusy-%s",
 						e->exec_id == 0 ? "basic-" : "",
 						e->name)
-					test_fence_busy(i915, e->exec_id | e->flags, 0);
+					test_fence_busy(i915, eb_ring(e), 0);
 				igt_subtest_f("%swait-%s",
 						e->exec_id == 0 ? "basic-" : "",
 						e->name)
-					test_fence_busy(i915, e->exec_id | e->flags, WAIT);
+					test_fence_busy(i915, eb_ring(e), WAIT);
 				igt_subtest_f("%sawait-%s",
 						e->exec_id == 0 ? "basic-" : "",
 						e->name)
-					test_fence_await(i915, e->exec_id | e->flags, 0);
+					test_fence_await(i915, eb_ring(e), 0);
 				igt_subtest_f("nb-await-%s", e->name)
-					test_fence_await(i915, e->exec_id | e->flags, NONBLOCK);
+					test_fence_await(i915, eb_ring(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, eb_ring(e), 0);
 
 				if (e->exec_id &&
 				    !(e->exec_id == I915_EXEC_BSD && !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, eb_ring(e));
 					}
 				}
 
@@ -1600,13 +1595,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, eb_ring(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, eb_ring(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, eb_ring(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, eb_ring(e), NONBLOCK | HANG);
 				igt_fixture {
 					igt_disallow_hang(i915, hang);
 				}
diff --git a/tests/i915/gem_exec_flush.c b/tests/i915/gem_exec_flush.c
index f820b2a8d..28708460b 100644
--- a/tests/i915/gem_exec_flush.c
+++ b/tests/i915/gem_exec_flush.c
@@ -600,7 +600,7 @@ igt_main
 	}
 
 	for (e = intel_execution_engines; e->name; e++) igt_subtest_group {
-		unsigned ring = e->exec_id | e->flags;
+		unsigned ring = eb_ring(e);
 		unsigned timeout = 5 + 120*!!e->exec_id;
 
 		igt_fixture {
diff --git a/tests/i915/gem_exec_gttfill.c b/tests/i915/gem_exec_gttfill.c
index efd612bb6..fa9161b4e 100644
--- a/tests/i915/gem_exec_gttfill.c
+++ b/tests/i915/gem_exec_gttfill.c
@@ -113,20 +113,19 @@ static void fillgtt(int fd, unsigned ring, int timeout)
 	struct batch *batches;
 	unsigned engines[16];
 	unsigned nengine;
-	unsigned engine;
-	uint64_t size;
 	unsigned count;
+	uint64_t size;
 
 	shared = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(shared != MAP_FAILED);
 
 	nengine = 0;
 	if (ring == 0) {
-		for_each_physical_engine(fd, engine) {
-			if (!gem_can_store_dword(fd, engine))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			engines[nengine++] = engine;
+			engines[nengine++] = eb_ring(e);
 		}
 	} else {
 		gem_require_ring(fd, ring);
@@ -224,7 +223,7 @@ igt_main
 
 	for (e = intel_execution_engines; e->name; e++)
 		igt_subtest_f("%s", e->name)
-			fillgtt(device, e->exec_id | e->flags, 20);
+			fillgtt(device, eb_ring(e), 20);
 
 	igt_subtest("all")
 		fillgtt(device, 0, 150);
diff --git a/tests/i915/gem_exec_latency.c b/tests/i915/gem_exec_latency.c
index 9ddb348c0..3d99182a0 100644
--- a/tests/i915/gem_exec_latency.c
+++ b/tests/i915/gem_exec_latency.c
@@ -267,7 +267,6 @@ static void latency_from_ring(int fd,
 	struct drm_i915_gem_relocation_entry reloc;
 	struct drm_i915_gem_execbuffer2 execbuf;
 	const unsigned int repeats = ring_size / 2;
-	unsigned int other;
 	uint32_t *map, *results;
 	uint32_t ctx[2] = {};
 	int i, j;
@@ -313,7 +312,7 @@ static void latency_from_ring(int fd,
 	reloc.presumed_offset = obj[1].offset;
 	reloc.target_handle = flags & CORK ? 1 : 0;
 
-	for_each_physical_engine(fd, other) {
+	for_each_physical_engine(e, fd) {
 		igt_spin_t *spin = NULL;
 		IGT_CORK_HANDLE(c);
 
@@ -361,7 +360,7 @@ static void latency_from_ring(int fd,
 			gem_execbuf(fd, &execbuf);
 
 			execbuf.flags &= ~ENGINE_FLAGS;
-			execbuf.flags |= other;
+			execbuf.flags |= eb_ring(e);
 
 			execbuf.batch_start_offset = 64 * (j + repeats);
 			reloc.offset =
@@ -394,7 +393,7 @@ static void latency_from_ring(int fd,
 		igt_spin_free(fd, spin);
 
 		igt_info("%s-%s delay: %.2fns\n",
-			 name, e__->name,
+			 name, e->name,
 			 (results[2*repeats-1] - results[0]) / (double)repeats * rcs_clock);
 	}
 
@@ -475,12 +474,12 @@ rthog_latency_on_ring(int fd, unsigned int engine, const char *name, unsigned in
 
 	nengine = 0;
 	if (engine == ALL_ENGINES) {
-		for_each_physical_engine(fd, engine) {
-			if (!gem_can_store_dword(fd, engine))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			engines[nengine] = engine;
-			names[nengine] = e__->name;
+			engines[nengine] = eb_ring(e);
+			names[nengine] = e->name;
 			nengine++;
 		}
 		igt_require(nengine > 1);
@@ -692,22 +691,22 @@ igt_main
 
 			igt_subtest_group {
 				igt_fixture {
-					igt_require(gem_ring_has_physical_engine(device, e->exec_id | e->flags));
+					igt_require(gem_ring_has_physical_engine(device, eb_ring(e)));
 				}
 
 				igt_subtest_f("%s-dispatch", e->name)
 					latency_on_ring(device,
-							e->exec_id | e->flags,
+							eb_ring(e),
 							e->name, 0);
 
 				igt_subtest_f("%s-live-dispatch", e->name)
 					latency_on_ring(device,
-							e->exec_id | e->flags,
+							eb_ring(e),
 							e->name, LIVE);
 
 				igt_subtest_f("%s-poll", e->name)
 					poll_ring(device,
-						  e->exec_id | e->flags,
+						  eb_ring(e),
 						  e->name);
 
 				igt_subtest_f("%s-rtidle-submit", e->name)
@@ -726,21 +725,21 @@ igt_main
 
 				igt_subtest_f("%s-live-dispatch-queued", e->name)
 					latency_on_ring(device,
-							e->exec_id | e->flags,
+							eb_ring(e),
 							e->name, LIVE | CORK);
 				igt_subtest_f("%s-dispatch-queued", e->name)
 					latency_on_ring(device,
-							e->exec_id | e->flags,
+							eb_ring(e),
 							e->name, CORK);
 
 				igt_subtest_f("%s-synchronisation", e->name)
 					latency_from_ring(device,
-							  e->exec_id | e->flags,
+							  eb_ring(e),
 							  e->name, 0);
 
 				igt_subtest_f("%s-synchronisation-queued", e->name)
 					latency_from_ring(device,
-							  e->exec_id | e->flags,
+							  eb_ring(e),
 							  e->name, CORK);
 
 				igt_subtest_group {
@@ -751,7 +750,7 @@ igt_main
 
 					igt_subtest_f("%s-preemption", e->name)
 						latency_from_ring(device,
-								  e->exec_id | e->flags,
+								  eb_ring(e),
 								  e->name, PREEMPT);
 				}
 			}
diff --git a/tests/i915/gem_exec_nop.c b/tests/i915/gem_exec_nop.c
index 8922685af..1a6906f30 100644
--- a/tests/i915/gem_exec_nop.c
+++ b/tests/i915/gem_exec_nop.c
@@ -222,7 +222,7 @@ static void poll_sequential(int fd, const char *name, int timeout)
 	struct drm_i915_gem_exec_object2 obj[2];
 	struct drm_i915_gem_relocation_entry reloc[4], *r;
 	uint32_t *bbe[2], *state, *batch;
-	unsigned engines[16], nengine, engine, flags;
+	unsigned engines[16], nengine, flags;
 	struct timespec tv = {};
 	unsigned long cycles;
 	uint64_t elapsed;
@@ -233,11 +233,11 @@ static void poll_sequential(int fd, const char *name, int timeout)
 		flags |= I915_EXEC_SECURE;
 
 	nengine = 0;
-	for_each_physical_engine(fd, engine) {
-		if (!gem_can_store_dword(fd, engine))
+	for_each_physical_engine(e, fd) {
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
-		engines[nengine++] = engine;
+		engines[nengine++] = eb_ring(e);
 	}
 	igt_require(nengine);
 
@@ -438,14 +438,14 @@ static void parallel(int fd, uint32_t handle, int timeout)
 
 	sum = 0;
 	nengine = 0;
-	for_each_physical_engine(fd, engine) {
-		engines[nengine] = engine;
-		names[nengine] = e__->name;
+	for_each_physical_engine(e, fd) {
+		engines[nengine] = eb_ring(e);
+		names[nengine] = e->name;
 		nengine++;
 
 		time = nop_on_ring(fd, handle, engine, 1, &count) / count;
 		sum += time;
-		igt_debug("%s: %.3fus\n", e__->name, 1e6*time);
+		igt_debug("%s: %.3fus\n", e->name, 1e6*time);
 	}
 	igt_require(nengine);
 	igt_info("average (individually): %.3fus\n", sum/nengine*1e6);
@@ -494,22 +494,21 @@ static void series(int fd, uint32_t handle, int timeout)
 	struct timespec start, now, sync;
 	unsigned engines[16];
 	unsigned nengine;
-	unsigned engine;
 	unsigned long count;
 	double time, max = 0, min = HUGE_VAL, sum = 0;
 	const char *name;
 
 	nengine = 0;
-	for_each_physical_engine(fd, engine) {
-		time = nop_on_ring(fd, handle, engine, 1, &count) / count;
+	for_each_physical_engine(e, fd) {
+		time = nop_on_ring(fd, handle, eb_ring(e), 1, &count) / count;
 		if (time > max) {
-			name = e__->name;
+			name = e->name;
 			max = time;
 		}
 		if (time < min)
 			min = time;
 		sum += time;
-		engines[nengine++] = engine;
+		engines[nengine++] = eb_ring(e);
 	}
 	igt_require(nengine);
 	igt_info("Maximum execution latency on %s, %.3fus, min %.3fus, total %.3fus per cycle, average %.3fus\n",
@@ -595,14 +594,14 @@ static void sequential(int fd, uint32_t handle, unsigned flags, int timeout)
 
 	nengine = 0;
 	sum = 0;
-	for_each_physical_engine(fd, n) {
+	for_each_physical_engine(e, fd) {
 		unsigned long count;
 
 		time = nop_on_ring(fd, handle, n, 1, &count) / count;
 		sum += time;
-		igt_debug("%s: %.3fus\n", e__->name, 1e6*time);
+		igt_debug("%s: %.3fus\n", e->name, 1e6*time);
 
-		engines[nengine++] = n;
+		engines[nengine++] = eb_ring(e);
 	}
 	igt_require(nengine);
 	igt_info("Total (individual) execution latency %.3fus per cycle\n",
@@ -726,8 +725,8 @@ static void fence_signal(int fd, uint32_t handle,
 
 	nengine = 0;
 	if (ring_id == ALL_ENGINES) {
-		for_each_physical_engine(fd, n)
-			engines[nengine++] = n;
+		for_each_physical_engine(e, fd)
+			engines[nengine++] = eb_ring(e);
 	} else {
 		gem_require_ring(fd, ring_id);
 		engines[nengine++] = ring_id;
@@ -875,9 +874,9 @@ igt_main
 
 	for (e = intel_execution_engines; e->name; e++) {
 		igt_subtest_f("%s", e->name)
-			single(device, handle, e->exec_id | e->flags, e->name);
+			single(device, handle, eb_ring(e), e->name);
 		igt_subtest_f("signal-%s", e->name)
-			fence_signal(device, handle, e->exec_id | e->flags, e->name, 5);
+			fence_signal(device, handle, eb_ring(e), e->name, 5);
 	}
 
 	igt_subtest("signal-all")
@@ -910,7 +909,7 @@ igt_main
 
 		for (e = intel_execution_engines; e->name; e++) {
 			igt_subtest_f("preempt-%s", e->name)
-				preempt(device, handle, e->exec_id | e->flags, e->name);
+				preempt(device, handle, eb_ring(e), e->name);
 		}
 	}
 
@@ -922,8 +921,7 @@ igt_main
 		for (e = intel_execution_engines; e->name; e++) {
 			/* Requires master for STORE_DWORD on gen4/5 */
 			igt_subtest_f("poll-%s", e->name)
-				poll_ring(device,
-					  e->exec_id | e->flags, e->name, 20);
+				poll_ring(device, eb_ring(e), e->name, 20);
 		}
 
 		igt_subtest("poll-sequential")
diff --git a/tests/i915/gem_exec_params.c b/tests/i915/gem_exec_params.c
index 49c56a8d7..8f15e6454 100644
--- a/tests/i915/gem_exec_params.c
+++ b/tests/i915/gem_exec_params.c
@@ -236,8 +236,8 @@ igt_main
 
 	igt_subtest("control") {
 		for (e = intel_execution_engines; e->name; e++) {
-			if (has_ring(fd, e->exec_id | e->flags)) {
-				execbuf.flags = e->exec_id | e->flags;
+			if (has_ring(fd, eb_ring(e))) {
+				execbuf.flags = eb_ring(e);
 				gem_execbuf(fd, &execbuf);
 			}
 		}
@@ -387,14 +387,16 @@ igt_main
 
 	igt_subtest("rs-invalid") {
 		bool has_rs = has_resource_streamer(fd);
-		unsigned int engine;
 
-		for_each_engine(fd, engine) {
+		for_each_engine(it, fd) {
 			int expect = -EINVAL;
-			if (has_rs && (engine == 0 || engine == I915_EXEC_RENDER))
+			if (has_rs &&
+			    (eb_ring(it) == 0 ||
+			     eb_ring(it) == I915_EXEC_RENDER))
 				expect = 0;
 
-			execbuf.flags = engine | LOCAL_I915_EXEC_RESOURCE_STREAMER;
+			execbuf.flags =
+				eb_ring(it) | LOCAL_I915_EXEC_RESOURCE_STREAMER;
 			igt_assert_eq(__gem_execbuf(fd, &execbuf), expect);
 		}
 	}
diff --git a/tests/i915/gem_exec_reloc.c b/tests/i915/gem_exec_reloc.c
index fdd9661d1..5f59fe99f 100644
--- a/tests/i915/gem_exec_reloc.c
+++ b/tests/i915/gem_exec_reloc.c
@@ -258,9 +258,9 @@ static void active(int fd, unsigned engine)
 
 	nengine = 0;
 	if (engine == ALL_ENGINES) {
-		for_each_physical_engine(fd, engine) {
-			if (gem_can_store_dword(fd, engine))
-				engines[nengine++] = engine;
+		for_each_physical_engine(e, fd) {
+			if (gem_can_store_dword(fd, eb_ring(e)))
+				engines[nengine++] = eb_ring(e);
 		}
 	} else {
 		igt_require(gem_has_ring(fd, engine));
@@ -754,7 +754,7 @@ igt_main
 	for (const struct intel_execution_engine *e = intel_execution_engines;
 	     e->name; e++) {
 		igt_subtest_f("active-%s", e->name)
-			active(fd, e->exec_id | e->flags);
+			active(fd, eb_ring(e));
 	}
 	igt_fixture
 		close(fd);
diff --git a/tests/i915/gem_exec_reuse.c b/tests/i915/gem_exec_reuse.c
index 935bfa9ac..971eb4137 100644
--- a/tests/i915/gem_exec_reuse.c
+++ b/tests/i915/gem_exec_reuse.c
@@ -89,7 +89,6 @@ igt_main
 	igt_fixture {
 		uint64_t gtt_size, max;
 		uint32_t bbe = MI_BATCH_BUFFER_END;
-		unsigned engine;
 
 		igt_allow_unlimited_files();
 
@@ -118,9 +117,8 @@ igt_main
 		no.obj = malloc(sizeof(struct drm_i915_gem_exec_object2) * (no.max_age + 1));
 
 		nengine = 0;
-		for_each_engine(no.fd, engine)
-			if (engine)
-				engines[nengine++] = engine;
+		for_each_physical_engine(e, no.fd)
+			engines[nengine++] = eb_ring(e);
 		igt_require(nengine);
 
 		no.batch = gem_create(no.fd, 4096);
diff --git a/tests/i915/gem_exec_schedule.c b/tests/i915/gem_exec_schedule.c
index 8695cbe9d..47f614eec 100644
--- a/tests/i915/gem_exec_schedule.c
+++ b/tests/i915/gem_exec_schedule.c
@@ -240,7 +240,6 @@ static void independent(int fd, unsigned int engine)
 	IGT_CORK_FENCE(cork);
 	igt_spin_t *spin = NULL;
 	uint32_t scratch, batch;
-	unsigned int other;
 	uint32_t *ptr;
 	int fence;
 
@@ -253,25 +252,25 @@ static void independent(int fd, unsigned int engine)
 	fence = igt_cork_plug(&cork, fd);
 
 	/* Check that we can submit to engine while all others are blocked */
-	for_each_physical_engine(fd, other) {
-		if (other == engine)
+	for_each_physical_engine(e, fd) {
+		if (eb_ring(e) == engine)
 			continue;
 
-		if (!gem_can_store_dword(fd, other))
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
 		if (spin == NULL) {
-			spin = __igt_spin_new(fd, .engine = other);
+			spin = __igt_spin_new(fd, .engine = eb_ring(e));
 		} else {
 			struct drm_i915_gem_execbuffer2 eb = {
 				.buffer_count = 1,
 				.buffers_ptr = to_user_pointer(&spin->obj[IGT_SPIN_BATCH]),
-				.flags = other,
+				.flags = eb_ring(e),
 			};
 			gem_execbuf(fd, &eb);
 		}
 
-		store_dword_fenced(fd, 0, other, scratch, 0, other, fence, 0);
+		store_dword_fenced(fd, 0, eb_ring(e), scratch, 0, eb_ring(e), fence, 0);
 	}
 	igt_require(spin);
 
@@ -312,9 +311,9 @@ static void smoketest(int fd, unsigned ring, unsigned timeout)
 
 	nengine = 0;
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, engine)
-			if (gem_can_store_dword(fd, engine))
-				engines[nengine++] = engine;
+		for_each_physical_engine(e, fd)
+			if (gem_can_store_dword(fd, eb_ring(e)))
+				engines[nengine++] = eb_ring(e);
 	} else {
 		if (gem_can_store_dword(fd, ring))
 			engines[nengine++] = ring;
@@ -385,7 +384,6 @@ static void semaphore_userlock(int i915)
 		.handle = batch_create(i915),
 	};
 	igt_spin_t *spin = NULL;
-	unsigned int engine;
 	uint32_t scratch;
 
 	igt_require(gem_scheduler_has_semaphores(i915));
@@ -398,16 +396,16 @@ static void semaphore_userlock(int i915)
 	 */
 
 	scratch = gem_create(i915, 4096);
-	for_each_physical_engine(i915, engine) {
+	for_each_physical_engine(e, i915) {
 		if (!spin) {
 			spin = igt_spin_new(i915,
 					    .dependency = scratch,
-					    .engine = engine);
+					    .engine = eb_ring(e));
 		} else {
 			uint64_t saved = spin->execbuf.flags;
 
 			spin->execbuf.flags &= ~ENGINE_MASK;
-			spin->execbuf.flags |= engine;
+			spin->execbuf.flags |= eb_ring(e);
 
 			gem_execbuf(i915, &spin->execbuf);
 
@@ -423,15 +421,15 @@ static void semaphore_userlock(int i915)
 	 * taking precedence.
 	 */
 	scratch = gem_context_create(i915);
-	for_each_physical_engine(i915, engine) {
+	for_each_physical_engine(e, i915) {
 		struct drm_i915_gem_execbuffer2 execbuf = {
 			.buffers_ptr = to_user_pointer(&obj),
 			.buffer_count = 1,
-			.flags = engine,
+			.flags = eb_ring(e),
 			.rsvd1 = scratch,
 		};
 
-		if (engine == (spin->execbuf.flags & ENGINE_MASK))
+		if (eb_ring(e) == (spin->execbuf.flags & ENGINE_MASK))
 			continue;
 
 		gem_execbuf(i915, &execbuf);
@@ -448,7 +446,6 @@ static void semaphore_codependency(int i915)
 	struct {
 		igt_spin_t *xcs, *rcs;
 	} task[2];
-	unsigned int engine;
 	int i;
 
 	/*
@@ -462,13 +459,13 @@ static void semaphore_codependency(int i915)
 	 */
 
 	i = 0;
-	for_each_physical_engine(i915, engine) {
+	for_each_physical_engine(e, i915) {
 		uint32_t ctx;
 
-		if (engine == I915_EXEC_RENDER)
+		if (eb_ring(e) == I915_EXEC_RENDER)
 			continue;
 
-		if (!gem_can_store_dword(i915, engine))
+		if (!gem_can_store_dword(i915, eb_ring(e)))
 			continue;
 
 		ctx = gem_context_create(i915);
@@ -476,7 +473,7 @@ static void semaphore_codependency(int i915)
 		task[i].xcs =
 			__igt_spin_new(i915,
 				       .ctx = ctx,
-				       .engine = engine,
+				       .engine = eb_ring(e),
 				       .flags = IGT_SPIN_POLL_RUN);
 		igt_spin_busywait_until_started(task[i].xcs);
 
@@ -514,7 +511,6 @@ static void semaphore_resolve(int i915)
 {
 	const uint32_t SEMAPHORE_ADDR = 64 << 10;
 	uint32_t semaphore, outer, inner, *sema;
-	unsigned int engine;
 
 	/*
 	 * Userspace may submit batches that wait upon unresolved
@@ -534,7 +530,7 @@ static void semaphore_resolve(int i915)
 	semaphore = gem_create(i915, 4096);
 	sema = gem_mmap__wc(i915, semaphore, 0, 4096, PROT_WRITE);
 
-	for_each_physical_engine(i915, engine) {
+	for_each_physical_engine(e, i915) {
 		struct drm_i915_gem_exec_object2 obj[3];
 		struct drm_i915_gem_execbuffer2 eb;
 		uint32_t handle, cancel;
@@ -542,10 +538,10 @@ static void semaphore_resolve(int i915)
 		igt_spin_t *spin;
 		int64_t poke = 1;
 
-		if (!gem_can_store_dword(i915, engine))
+		if (!gem_can_store_dword(i915, eb_ring(e)))
 			continue;
 
-		spin = __igt_spin_new(i915, .engine = engine);
+		spin = __igt_spin_new(i915, .engine = eb_ring(e));
 		igt_spin_end(spin); /* we just want its address for later */
 		gem_sync(i915, spin->handle);
 		igt_spin_reset(spin);
@@ -642,26 +638,27 @@ static void semaphore_resolve(int i915)
 static void semaphore_noskip(int i915)
 {
 	const int gen = intel_gen(intel_get_drm_devid(i915));
-	unsigned int engine, other;
+	unsigned int other;
 	uint32_t ctx;
 
 	igt_require(gen >= 6); /* MI_STORE_DWORD_IMM convenience */
 
 	ctx = gem_context_create(i915);
 
-	for_each_physical_engine(i915, engine) {
-	for_each_physical_engine(i915, other) {
+	for_each_physical_engine(outer, i915) {
+	for_each_physical_engine(inner, i915) {
 		struct drm_i915_gem_exec_object2 obj[3];
 		struct drm_i915_gem_execbuffer2 eb;
 		uint32_t handle, *cs, *map;
 		igt_spin_t *chain, *spin;
 
-		if (other == engine || !gem_can_store_dword(i915, other))
+		if (eb_ring(inner) == eb_ring(outer) ||
+		    !gem_can_store_dword(i915, eb_ring(inner)))
 			continue;
 
-		chain = __igt_spin_new(i915, .engine = engine);
+		chain = __igt_spin_new(i915, .engine = eb_ring(outer));
 
-		spin = __igt_spin_new(i915, .engine = other);
+		spin = __igt_spin_new(i915, .engine = eb_ring(inner));
 		igt_spin_end(spin); /* we just want its address for later */
 		gem_sync(i915, spin->handle);
 		igt_spin_reset(spin);
@@ -867,21 +864,19 @@ static void preempt(int fd, unsigned ring, unsigned flags)
 
 static igt_spin_t *__noise(int fd, uint32_t ctx, int prio, igt_spin_t *spin)
 {
-	unsigned other;
-
 	gem_context_set_priority(fd, ctx, prio);
 
-	for_each_physical_engine(fd, other) {
+	for_each_physical_engine(e, fd) {
 		if (spin == NULL) {
 			spin = __igt_spin_new(fd,
 					      .ctx = ctx,
-					      .engine = other);
+					      .engine = eb_ring(e));
 		} else {
 			struct drm_i915_gem_execbuffer2 eb = {
 				.buffer_count = 1,
 				.buffers_ptr = to_user_pointer(&spin->obj[IGT_SPIN_BATCH]),
 				.rsvd1 = ctx,
-				.flags = other,
+				.flags = eb_ring(e),
 			};
 			gem_execbuf(fd, &eb);
 		}
@@ -897,7 +892,7 @@ static void __preempt_other(int fd,
 {
 	uint32_t result = gem_create(fd, 4096);
 	uint32_t result_read[4096 / sizeof(uint32_t)];
-	unsigned int n, i, other;
+	unsigned int n, i;
 
 	n = 0;
 	store_dword(fd, ctx[LO], primary,
@@ -906,8 +901,8 @@ static void __preempt_other(int fd,
 	n++;
 
 	if (flags & CHAIN) {
-		for_each_physical_engine(fd, other) {
-			store_dword(fd, ctx[LO], other,
+		for_each_physical_engine(e, fd) {
+			store_dword(fd, ctx[LO], eb_ring(e),
 				    result, (n + 1)*sizeof(uint32_t), n + 1,
 				    I915_GEM_DOMAIN_RENDER);
 			n++;
@@ -932,7 +927,6 @@ static void __preempt_other(int fd,
 
 static void preempt_other(int fd, unsigned ring, unsigned int flags)
 {
-	unsigned int primary;
 	igt_spin_t *spin = NULL;
 	uint32_t ctx[3];
 
@@ -955,9 +949,9 @@ static void preempt_other(int fd, unsigned ring, unsigned int flags)
 	ctx[HI] = gem_context_create(fd);
 	gem_context_set_priority(fd, ctx[HI], MAX_PRIO);
 
-	for_each_physical_engine(fd, primary) {
-		igt_debug("Primary engine: %s\n", e__->name);
-		__preempt_other(fd, ctx, ring, primary, flags);
+	for_each_physical_engine(e, fd) {
+		igt_debug("Primary engine: %s\n", e->name);
+		__preempt_other(fd, ctx, ring, eb_ring(e), flags);
 
 	}
 
@@ -976,13 +970,13 @@ static void __preempt_queue(int fd,
 	uint32_t result = gem_create(fd, 4096);
 	uint32_t result_read[4096 / sizeof(uint32_t)];
 	igt_spin_t *above = NULL, *below = NULL;
-	unsigned int other, n, i;
-	int prio = MAX_PRIO;
 	uint32_t ctx[3] = {
 		gem_context_create(fd),
 		gem_context_create(fd),
 		gem_context_create(fd),
 	};
+	int prio = MAX_PRIO;
+	unsigned int n, i;
 
 	for (n = 0; n < depth; n++) {
 		if (flags & CONTEXTS) {
@@ -1011,8 +1005,8 @@ static void __preempt_queue(int fd,
 	n++;
 
 	if (flags & CHAIN) {
-		for_each_physical_engine(fd, other) {
-			store_dword(fd, ctx[LO], other,
+		for_each_physical_engine(e, fd) {
+			store_dword(fd, ctx[LO], eb_ring(e),
 				    result, (n + 1)*sizeof(uint32_t), n + 1,
 				    I915_GEM_DOMAIN_RENDER);
 			n++;
@@ -1052,11 +1046,9 @@ static void __preempt_queue(int fd,
 
 static void preempt_queue(int fd, unsigned ring, unsigned int flags)
 {
-	unsigned other;
-
-	for_each_physical_engine(fd, other) {
+	for_each_physical_engine(e, fd) {
 		for (unsigned depth = 0; depth <= MAX_ELSP_QLEN; depth++)
-			__preempt_queue(fd, ring, other, depth, flags);
+			__preempt_queue(fd, ring, eb_ring(e), depth, flags);
 	}
 }
 
@@ -1065,7 +1057,6 @@ static void preempt_self(int fd, unsigned ring)
 	uint32_t result = gem_create(fd, 4096);
 	uint32_t result_read[4096 / sizeof(uint32_t)];
 	igt_spin_t *spin[MAX_ELSP_QLEN];
-	unsigned int other;
 	unsigned int n, i;
 	uint32_t ctx[3];
 
@@ -1083,11 +1074,11 @@ static void preempt_self(int fd, unsigned ring)
 
 	n = 0;
 	gem_context_set_priority(fd, ctx[HI], MIN_PRIO);
-	for_each_physical_engine(fd, other) {
+	for_each_physical_engine(e, fd) {
 		spin[n] = __igt_spin_new(fd,
 					 .ctx = ctx[NOISE],
-					 .engine = other);
-		store_dword(fd, ctx[HI], other,
+					 .engine = eb_ring(e));
+		store_dword(fd, ctx[HI], eb_ring(e),
 			    result, (n + 1)*sizeof(uint32_t), n + 1,
 			    I915_GEM_DOMAIN_RENDER);
 		n++;
@@ -1608,13 +1599,12 @@ static void test_pi_ringfull(int fd, unsigned int engine)
 
 static void measure_semaphore_power(int i915)
 {
-	unsigned int engine, signaler;
 	struct rapl gpu, pkg;
 
 	igt_require(gpu_power_open(&gpu) == 0);
 	pkg_power_open(&pkg);
 
-	for_each_physical_engine(i915, signaler) {
+	for_each_physical_engine(signaler, i915) {
 		struct {
 			struct power_sample pkg, gpu;
 		} s_spin[2], s_sema[2];
@@ -1623,7 +1613,7 @@ static void measure_semaphore_power(int i915)
 		igt_spin_t *spin;
 
 		spin = __igt_spin_new(i915,
-				      .engine = signaler,
+				      .engine = eb_ring(signaler),
 				      .flags = IGT_SPIN_POLL_RUN);
 		gem_wait(i915, spin->handle, &jiffie); /* waitboost */
 		igt_spin_busywait_until_started(spin);
@@ -1635,14 +1625,14 @@ static void measure_semaphore_power(int i915)
 		rapl_read(&pkg, &s_spin[1].pkg);
 
 		/* Add a waiter to each engine */
-		for_each_physical_engine(i915, engine) {
+		for_each_physical_engine(e, i915) {
 			igt_spin_t *sema;
 
-			if (engine == signaler)
+			if (eb_ring(e) == eb_ring(signaler))
 				continue;
 
 			sema = __igt_spin_new(i915,
-					      .engine = engine,
+					      .engine = eb_ring(e),
 					      .dependency = spin->handle);
 
 			igt_spin_free(i915, sema);
@@ -1660,7 +1650,7 @@ static void measure_semaphore_power(int i915)
 		baseline = power_W(&gpu, &s_spin[0].gpu, &s_spin[1].gpu);
 		total = power_W(&gpu, &s_sema[0].gpu, &s_sema[1].gpu);
 		igt_info("%s: %.1fmW + %.1fmW (total %1.fmW)\n",
-			 e__->name,
+			 signaler->name,
 			 1e3 * baseline,
 			 1e3 * (total - baseline),
 			 1e3 * total);
@@ -1707,15 +1697,15 @@ igt_main
 				continue;
 
 			igt_subtest_f("fifo-%s", e->name) {
-				igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
-				igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
-				fifo(fd, e->exec_id | e->flags);
+				igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
+				igt_require(gem_can_store_dword(fd, eb_ring(e)));
+				fifo(fd, eb_ring(e));
 			}
 
 			igt_subtest_f("independent-%s", e->name) {
-				igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
-				igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
-				independent(fd, e->exec_id | e->flags);
+				igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
+				igt_require(gem_can_store_dword(fd, eb_ring(e)));
+				independent(fd, eb_ring(e));
 			}
 		}
 	}
@@ -1744,18 +1734,18 @@ igt_main
 
 			igt_subtest_group {
 				igt_fixture {
-					igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
-					igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
+					igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
+					igt_require(gem_can_store_dword(fd, eb_ring(e)));
 				}
 
 				igt_subtest_f("in-order-%s", e->name)
-					reorder(fd, e->exec_id | e->flags, EQUAL);
+					reorder(fd, eb_ring(e), EQUAL);
 
 				igt_subtest_f("out-order-%s", e->name)
-					reorder(fd, e->exec_id | e->flags, 0);
+					reorder(fd, eb_ring(e), 0);
 
 				igt_subtest_f("promotion-%s", e->name)
-					promotion(fd, e->exec_id | e->flags);
+					promotion(fd, eb_ring(e));
 
 				igt_subtest_group {
 					igt_fixture {
@@ -1763,30 +1753,30 @@ igt_main
 					}
 
 					igt_subtest_f("preempt-%s", e->name)
-						preempt(fd, e->exec_id | e->flags, 0);
+						preempt(fd, eb_ring(e), 0);
 
 					igt_subtest_f("preempt-contexts-%s", e->name)
-						preempt(fd, e->exec_id | e->flags, NEW_CTX);
+						preempt(fd, eb_ring(e), NEW_CTX);
 
 					igt_subtest_f("preempt-self-%s", e->name)
-						preempt_self(fd, e->exec_id | e->flags);
+						preempt_self(fd, eb_ring(e));
 
 					igt_subtest_f("preempt-other-%s", e->name)
-						preempt_other(fd, e->exec_id | e->flags, 0);
+						preempt_other(fd, eb_ring(e), 0);
 
 					igt_subtest_f("preempt-other-chain-%s", e->name)
-						preempt_other(fd, e->exec_id | e->flags, CHAIN);
+						preempt_other(fd, eb_ring(e), CHAIN);
 
 					igt_subtest_f("preempt-queue-%s", e->name)
-						preempt_queue(fd, e->exec_id | e->flags, 0);
+						preempt_queue(fd, eb_ring(e), 0);
 
 					igt_subtest_f("preempt-queue-chain-%s", e->name)
-						preempt_queue(fd, e->exec_id | e->flags, CHAIN);
+						preempt_queue(fd, eb_ring(e), CHAIN);
 					igt_subtest_f("preempt-queue-contexts-%s", e->name)
-						preempt_queue(fd, e->exec_id | e->flags, CONTEXTS);
+						preempt_queue(fd, eb_ring(e), CONTEXTS);
 
 					igt_subtest_f("preempt-queue-contexts-chain-%s", e->name)
-						preempt_queue(fd, e->exec_id | e->flags, CONTEXTS | CHAIN);
+						preempt_queue(fd, eb_ring(e), CONTEXTS | CHAIN);
 
 					igt_subtest_group {
 						igt_hang_t hang;
@@ -1797,11 +1787,11 @@ igt_main
 						}
 
 						igt_subtest_f("preempt-hang-%s", e->name) {
-							preempt(fd, e->exec_id | e->flags, NEW_CTX | HANG_LP);
+							preempt(fd, eb_ring(e), NEW_CTX | HANG_LP);
 						}
 
 						igt_subtest_f("preemptive-hang-%s", e->name)
-							preemptive_hang(fd, e->exec_id | e->flags);
+							preemptive_hang(fd, eb_ring(e));
 
 						igt_fixture {
 							igt_disallow_hang(fd, hang);
@@ -1811,16 +1801,16 @@ igt_main
 				}
 
 				igt_subtest_f("deep-%s", e->name)
-					deep(fd, e->exec_id | e->flags);
+					deep(fd, eb_ring(e));
 
 				igt_subtest_f("wide-%s", e->name)
-					wide(fd, e->exec_id | e->flags);
+					wide(fd, eb_ring(e));
 
 				igt_subtest_f("reorder-wide-%s", e->name)
-					reorder_wide(fd, e->exec_id | e->flags);
+					reorder_wide(fd, eb_ring(e));
 
 				igt_subtest_f("smoketest-%s", e->name)
-					smoketest(fd, e->exec_id | e->flags, 5);
+					smoketest(fd, eb_ring(e), 5);
 			}
 		}
 	}
@@ -1837,12 +1827,12 @@ igt_main
 
 			igt_subtest_group {
 				igt_fixture {
-					igt_require(gem_ring_has_physical_engine(fd, e->exec_id | e->flags));
+					igt_require(gem_ring_has_physical_engine(fd, eb_ring(e)));
 					igt_require(gem_scheduler_has_preemption(fd));
 				}
 
 				igt_subtest_f("pi-ringfull-%s", e->name)
-					test_pi_ringfull(fd, e->exec_id | e->flags);
+					test_pi_ringfull(fd, eb_ring(e));
 			}
 		}
 	}
diff --git a/tests/i915/gem_exec_suspend.c b/tests/i915/gem_exec_suspend.c
index e43a16e9e..561a10a4b 100644
--- a/tests/i915/gem_exec_suspend.c
+++ b/tests/i915/gem_exec_suspend.c
@@ -64,11 +64,9 @@ static void check_bo(int fd, uint32_t handle)
 
 static void test_all(int fd, unsigned flags)
 {
-	unsigned engine;
-
-	for_each_physical_engine(fd, engine)
-		if (gem_can_store_dword(fd, engine))
-			run_test(fd, engine, flags & ~0xff);
+	for_each_physical_engine(e, fd)
+		if (gem_can_store_dword(fd, eb_ring(e)))
+			run_test(fd, eb_ring(e), flags & ~0xff);
 }
 
 static bool has_semaphores(int fd)
@@ -106,9 +104,9 @@ static void run_test(int fd, unsigned engine, unsigned flags)
 		 * GPU is then unlikely to be active!)
 		 */
 		if (has_semaphores(fd)) {
-			for_each_physical_engine(fd, engine) {
-				if (gem_can_store_dword(fd, engine))
-					engines[nengine++] = engine;
+			for_each_physical_engine(e, fd) {
+				if (gem_can_store_dword(fd, eb_ring(e)))
+					engines[nengine++] = eb_ring(e);
 			}
 		} else {
 			igt_require(gem_has_ring(fd, 0));
@@ -267,11 +265,9 @@ igt_main
 	for (e = intel_execution_engines; e->name; e++) {
 		for (m = modes; m->suffix; m++) {
 			igt_subtest_f("%s-uncached%s", e->name, m->suffix)
-				run_test(fd, e->exec_id | e->flags,
-					 m->mode | UNCACHED);
+				run_test(fd, eb_ring(e), m->mode | UNCACHED);
 			igt_subtest_f("%s-cached%s", e->name, m->suffix)
-				run_test(fd, e->exec_id | e->flags,
-					 m->mode | CACHED);
+				run_test(fd, eb_ring(e), m->mode | CACHED);
 		}
 	}
 
diff --git a/tests/i915/gem_exec_whisper.c b/tests/i915/gem_exec_whisper.c
index 1135c6497..a33847608 100644
--- a/tests/i915/gem_exec_whisper.c
+++ b/tests/i915/gem_exec_whisper.c
@@ -203,9 +203,9 @@ static void whisper(int fd, unsigned engine, unsigned flags)
 
 	nengine = 0;
 	if (engine == ALL_ENGINES) {
-		for_each_physical_engine(fd, engine) {
-			if (gem_can_store_dword(fd, engine))
-				engines[nengine++] = engine;
+		for_each_physical_engine(e, fd) {
+			if (gem_can_store_dword(fd, eb_ring(e)))
+				engines[nengine++] = eb_ring(e);
 		}
 	} else {
 		igt_assert(!(flags & ALL));
@@ -578,7 +578,7 @@ igt_main
 				continue;
 
 			igt_subtest_f("%s-%s", e->name, m->name)
-				whisper(fd, e->exec_id | e->flags, m->flags);
+				whisper(fd, eb_ring(e), m->flags);
 		}
 	}
 
diff --git a/tests/i915/gem_mocs_settings.c b/tests/i915/gem_mocs_settings.c
index 3ad941491..fc2ccb216 100644
--- a/tests/i915/gem_mocs_settings.c
+++ b/tests/i915/gem_mocs_settings.c
@@ -605,7 +605,7 @@ igt_main
 						if (flags & (MOCS_NON_DEFAULT_CTX | MOCS_DIRTY_VALUES))
 							gem_require_contexts(fd);
 
-						run_test(fd, e->exec_id | e->flags, flags, mode);
+						run_test(fd, eb_ring(e), flags, mode);
 					}
 				}
 
@@ -617,10 +617,10 @@ igt_main
 		}
 
 		igt_subtest_f("mocs-isolation-%s", e->name) {
-			gem_require_ring(fd, e->exec_id | e->flags);
+			gem_require_ring(fd, eb_ring(e));
 			gem_require_contexts(fd);
 
-			isolation_test(fd, e->exec_id | e->flags);
+			isolation_test(fd, eb_ring(e));
 		}
 	}
 
diff --git a/tests/i915/gem_reset_stats.c b/tests/i915/gem_reset_stats.c
index ac9af23f2..0931641a7 100644
--- a/tests/i915/gem_reset_stats.c
+++ b/tests/i915/gem_reset_stats.c
@@ -88,7 +88,7 @@ static int noop(int fd, uint32_t ctx, const struct intel_execution_engine *e)
 	memset(&eb, 0, sizeof(eb));
 	eb.buffers_ptr = to_user_pointer(&exec);
 	eb.buffer_count = 1;
-	eb.flags = e->exec_id | e->flags;
+	eb.flags = eb_ring(e);
 	i915_execbuffer2_set_context_id(eb, ctx);
 
 	ret = __gem_execbuf(fd, &eb);
@@ -164,7 +164,7 @@ static void inject_hang(int fd, uint32_t ctx,
 
 	clock_gettime(CLOCK_MONOTONIC, &ts_injected);
 
-	hang = igt_hang_ctx(fd, ctx, e->exec_id | e->flags, flags & BAN);
+	hang = igt_hang_ctx(fd, ctx, eb_ring(e), flags & BAN);
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -523,12 +523,12 @@ static void noop_on_each_ring(int fd, const bool reverse)
 		for (e = intel_execution_engines; e->name; e++)
 			;
 		while (--e >= intel_execution_engines) {
-			eb.flags = e->exec_id | e->flags;
+			eb.flags = eb_ring(e);
 			__gem_execbuf(fd, &eb);
 		}
 	} else {
 		for (e = intel_execution_engines; e->name; e++) {
-			eb.flags = e->exec_id | e->flags;
+			eb.flags = eb_ring(e);
 			__gem_execbuf(fd, &eb);
 		}
 	}
@@ -546,7 +546,7 @@ static void test_close_pending_fork(const struct intel_execution_engine *e,
 
 	assert_reset_status(fd, fd, 0, RS_NO_ERROR);
 
-	hang = igt_hang_ctx(fd, 0, e->exec_id | e->flags, 0);
+	hang = igt_hang_ctx(fd, 0, eb_ring(e), 0);
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/i915/gem_ring_sync_loop.c b/tests/i915/gem_ring_sync_loop.c
index 118f3638a..32b936373 100644
--- a/tests/i915/gem_ring_sync_loop.c
+++ b/tests/i915/gem_ring_sync_loop.c
@@ -44,12 +44,11 @@ sync_loop(int fd)
 	struct drm_i915_gem_relocation_entry reloc[1];
 	unsigned engines[16];
 	unsigned nengine;
-	unsigned engine;
 	int i;
 
 	nengine = 0;
-	for_each_physical_engine(fd, engine)
-		engines[nengine++] = engine;
+	for_each_physical_engine(e, fd)
+		engines[nengine++] = eb_ring(e);
 	igt_require(nengine);
 
 	memset(object, 0, sizeof(object));
diff --git a/tests/i915/gem_ringfill.c b/tests/i915/gem_ringfill.c
index c728e1cd3..af66d0012 100644
--- a/tests/i915/gem_ringfill.c
+++ b/tests/i915/gem_ringfill.c
@@ -288,8 +288,7 @@ igt_main
 				igt_skip_on(m->flags & NEWFD && master);
 				if (m->flags & (HANG|SUSPEND|HIBERNATE))
 					igt_skip_on_simulation();
-				run_test(fd, e->exec_id | e->flags,
-					 m->flags, m->timeout);
+				run_test(fd, eb_ring(e), m->flags, m->timeout);
 			}
 		}
 	}
diff --git a/tests/i915/gem_shrink.c b/tests/i915/gem_shrink.c
index 3db754f55..d2ea2ed84 100644
--- a/tests/i915/gem_shrink.c
+++ b/tests/i915/gem_shrink.c
@@ -428,7 +428,6 @@ igt_main
 
 	igt_fixture {
 		uint64_t mem_size = intel_get_total_ram_mb();
-		unsigned int engine;
 		int fd;
 
 		fd = drm_open_driver(DRIVER_INTEL);
@@ -451,8 +450,8 @@ igt_main
 				     CHECK_SWAP | CHECK_RAM);
 
 		nengine = 0;
-		for_each_engine(fd, engine)
-			engines[nengine++] = engine;
+		for_each_engine(e, fd)
+			engines[nengine++] = eb_ring(e);
 		igt_require(nengine);
 
 		close(fd);
diff --git a/tests/i915/gem_spin_batch.c b/tests/i915/gem_spin_batch.c
index e0623f4c9..df59512a5 100644
--- a/tests/i915/gem_spin_batch.c
+++ b/tests/i915/gem_spin_batch.c
@@ -152,7 +152,7 @@ igt_main
 	}
 
 	for (e = intel_execution_engines; e->name; e++) {
-		e2__ = gem_eb_flags_to_engine(e->exec_id | e->flags);
+		e2__ = gem_eb_flags_to_engine(eb_ring(e));
 		if (e2__.flags == -1)
 			continue;
 		e2 = &e2__;
diff --git a/tests/i915/gem_storedw_loop.c b/tests/i915/gem_storedw_loop.c
index b00555e0c..bbd640431 100644
--- a/tests/i915/gem_storedw_loop.c
+++ b/tests/i915/gem_storedw_loop.c
@@ -186,7 +186,7 @@ igt_main
 	for (e = intel_execution_engines; e->name; e++) {
 		igt_subtest_f("store-%s", e->name) {
 			check_test_requirements(fd, e->exec_id);
-			store_test(fd, e->exec_id | e->flags);
+			store_test(fd, eb_ring(e));
 		}
 	}
 
diff --git a/tests/i915/gem_sync.c b/tests/i915/gem_sync.c
index 8c5aaa144..9ffca4155 100644
--- a/tests/i915/gem_sync.c
+++ b/tests/i915/gem_sync.c
@@ -86,9 +86,9 @@ sync_ring(int fd, unsigned ring, int num_children, int timeout)
 	int num_engines = 0;
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+		for_each_physical_engine(e, fd) {
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -185,12 +185,12 @@ wakeup_ring(int fd, unsigned ring, int timeout, int wlen)
 	int num_engines = 0;
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -297,12 +297,12 @@ static void active_ring(int fd, unsigned ring, int timeout)
 	int num_engines = 0;
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -364,12 +364,12 @@ active_wakeup_ring(int fd, unsigned ring, int timeout, int wlen)
 	int num_engines = 0;
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -499,12 +499,12 @@ store_ring(int fd, unsigned ring, int num_children, int timeout)
 	int num_engines = 0;
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -616,12 +616,12 @@ switch_ring(int fd, unsigned ring, int num_children, int timeout)
 	gem_require_contexts(fd);
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -943,17 +943,17 @@ store_many(int fd, unsigned ring, int timeout)
 	intel_detect_and_clear_missed_interrupts(fd);
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			if (!gem_can_store_dword(fd, ring))
+		for_each_physical_engine(e, fd) {
+			if (!gem_can_store_dword(fd, eb_ring(e)))
 				continue;
 
 			igt_fork(child, 1)
 				__store_many(fd,
-					     ring,
+					     eb_ring(e),
 					     timeout,
 					     &shared[n]);
 
-			names[n++] = e__->name;
+			names[n++] = e->name;
 		}
 		igt_waitchildren();
 	} else {
@@ -974,11 +974,11 @@ store_many(int fd, unsigned ring, int timeout)
 static void
 sync_all(int fd, int num_children, int timeout)
 {
-	unsigned engines[16], engine;
+	unsigned engines[16];
 	int num_engines = 0;
 
-	for_each_physical_engine(fd, engine) {
-		engines[num_engines++] = engine;
+	for_each_physical_engine(e, fd) {
+		engines[num_engines++] = eb_ring(e);
 		if (num_engines == ARRAY_SIZE(engines))
 			break;
 	}
@@ -1028,13 +1028,12 @@ store_all(int fd, int num_children, int timeout)
 	const int gen = intel_gen(intel_get_drm_devid(fd));
 	unsigned engines[16];
 	int num_engines = 0;
-	unsigned int ring;
 
-	for_each_physical_engine(fd, ring) {
-		if (!gem_can_store_dword(fd, ring))
+	for_each_physical_engine(e, fd) {
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
-		engines[num_engines++] = ring;
+		engines[num_engines++] = eb_ring(e);
 		if (num_engines == ARRAY_SIZE(engines))
 			break;
 	}
@@ -1139,9 +1138,9 @@ preempt(int fd, unsigned ring, int num_children, int timeout)
 	uint32_t ctx[2];
 
 	if (ring == ALL_ENGINES) {
-		for_each_physical_engine(fd, ring) {
-			names[num_engines] = e__->name;
-			engines[num_engines++] = ring;
+		for_each_physical_engine(e, fd) {
+			names[num_engines] = e->name;
+			engines[num_engines++] = eb_ring(e);
 			if (num_engines == ARRAY_SIZE(engines))
 				break;
 		}
@@ -1227,29 +1226,29 @@ igt_main
 
 	for (e = intel_execution_engines; e->name; e++) {
 		igt_subtest_f("%s", e->name)
-			sync_ring(fd, e->exec_id | e->flags, 1, 150);
+			sync_ring(fd, eb_ring(e), 1, 150);
 		igt_subtest_f("idle-%s", e->name)
-			idle_ring(fd, e->exec_id | e->flags, 150);
+			idle_ring(fd, eb_ring(e), 150);
 		igt_subtest_f("active-%s", e->name)
-			active_ring(fd, e->exec_id | e->flags, 150);
+			active_ring(fd, eb_ring(e), 150);
 		igt_subtest_f("wakeup-%s", e->name)
-			wakeup_ring(fd, e->exec_id | e->flags, 150, 1);
+			wakeup_ring(fd, eb_ring(e), 150, 1);
 		igt_subtest_f("active-wakeup-%s", e->name)
-			active_wakeup_ring(fd, e->exec_id | e->flags, 150, 1);
+			active_wakeup_ring(fd, eb_ring(e), 150, 1);
 		igt_subtest_f("double-wakeup-%s", e->name)
-			wakeup_ring(fd, e->exec_id | e->flags, 150, 2);
+			wakeup_ring(fd, eb_ring(e), 150, 2);
 		igt_subtest_f("store-%s", e->name)
-			store_ring(fd, e->exec_id | e->flags, 1, 150);
+			store_ring(fd, eb_ring(e), 1, 150);
 		igt_subtest_f("switch-%s", e->name)
-			switch_ring(fd, e->exec_id | e->flags, 1, 150);
+			switch_ring(fd, eb_ring(e), 1, 150);
 		igt_subtest_f("forked-switch-%s", e->name)
-			switch_ring(fd, e->exec_id | e->flags, ncpus, 150);
+			switch_ring(fd, eb_ring(e), ncpus, 150);
 		igt_subtest_f("many-%s", e->name)
-			store_many(fd, e->exec_id | e->flags, 150);
+			store_many(fd, eb_ring(e), 150);
 		igt_subtest_f("forked-%s", e->name)
-			sync_ring(fd, e->exec_id | e->flags, ncpus, 150);
+			sync_ring(fd, eb_ring(e), ncpus, 150);
 		igt_subtest_f("forked-store-%s", e->name)
-			store_ring(fd, e->exec_id | e->flags, ncpus, 150);
+			store_ring(fd, eb_ring(e), ncpus, 150);
 	}
 
 	igt_subtest("basic-each")
@@ -1301,7 +1300,7 @@ igt_main
 
 		for (e = intel_execution_engines; e->name; e++) {
 			igt_subtest_f("preempt-%s", e->name)
-				preempt(fd, e->exec_id | e->flags, ncpus, 150);
+				preempt(fd, eb_ring(e), ncpus, 150);
 		}
 	}
 
diff --git a/tests/i915/gem_userptr_blits.c b/tests/i915/gem_userptr_blits.c
index 18e806fed..11d6f4a1c 100644
--- a/tests/i915/gem_userptr_blits.c
+++ b/tests/i915/gem_userptr_blits.c
@@ -1165,18 +1165,17 @@ static void test_readonly(int i915)
 	igt_assert(mprotect(space, total, PROT_READ) == 0);
 
 	igt_fork(child, 1) {
-		unsigned int engine;
 		char *orig;
 
 		orig = g_compute_checksum_for_data(G_CHECKSUM_SHA1, pages, sz);
 
 		gem_userptr(i915, space, total, true, userptr_flags, &rhandle);
 
-		for_each_engine(i915, engine) {
+		for_each_engine(e, i915) {
 			char *ref, *result;
 
 			/* First tweak the backing store through the write */
-			store_dword_rand(i915, engine, whandle, sz, 1024);
+			store_dword_rand(i915, eb_ring(e), whandle, sz, 1024);
 			gem_sync(i915, whandle);
 			ref = g_compute_checksum_for_data(G_CHECKSUM_SHA1,
 							  pages, sz);
@@ -1185,7 +1184,7 @@ static void test_readonly(int i915)
 			igt_assert(strcmp(ref, orig));
 
 			/* Now try the same through the read-only handle */
-			store_dword_rand(i915, engine, rhandle, total, 1024);
+			store_dword_rand(i915, eb_ring(e), rhandle, total, 1024);
 			gem_sync(i915, rhandle);
 			result = g_compute_checksum_for_data(G_CHECKSUM_SHA1,
 							     pages, sz);
diff --git a/tests/i915/i915_module_load.c b/tests/i915/i915_module_load.c
index 7fe835207..f42083f53 100644
--- a/tests/i915/i915_module_load.c
+++ b/tests/i915/i915_module_load.c
@@ -51,10 +51,10 @@ static void store_dword(int fd, unsigned ring)
 	uint32_t batch[16];
 	int i;
 
-	if (!gem_can_store_dword(fd, ring))
+	if (!gem_has_ring(fd, ring))
 		return;
 
-	if (!gem_has_ring(fd, ring))
+	if (!gem_can_store_dword(fd, ring))
 		return;
 
 	intel_detect_and_clear_missed_interrupts(fd);
@@ -113,7 +113,7 @@ static void store_all(int fd)
 	unsigned engines[16], permuted[16];
 	uint32_t batch[16];
 	uint64_t offset;
-	unsigned engine, nengine;
+	unsigned nengine;
 	int value;
 	int i, j;
 
@@ -151,14 +151,14 @@ static void store_all(int fd)
 
 	nengine = 0;
 	intel_detect_and_clear_missed_interrupts(fd);
-	for_each_engine(fd, engine) {
-		if (!gem_can_store_dword(fd, engine))
+	for_each_engine(e, fd) {
+		if (!gem_can_store_dword(fd, eb_ring(e)))
 			continue;
 
-		igt_assert(2*(nengine+1)*sizeof(batch) <= 4096);
+		igt_assert(2 * (nengine + 1) * sizeof(batch) <= 4096);
 
 		execbuf.flags &= ~ENGINE_MASK;
-		execbuf.flags |= engine;
+		execbuf.flags |= eb_ring(e);
 
 		j = 2*nengine;
 		reloc[j].target_handle = obj[0].handle;
@@ -190,7 +190,7 @@ static void store_all(int fd)
 		execbuf.batch_start_offset = j*sizeof(batch);
 		gem_execbuf(fd, &execbuf);
 
-		engines[nengine++] = engine;
+		engines[nengine++] = eb_ring(e);
 	}
 	gem_sync(fd, obj[1].handle);
 
@@ -286,10 +286,8 @@ gem_exec_store(void)
 	fd = __drm_open_driver(DRIVER_INTEL);
 	igt_fork_hang_detector(fd);
 
-	for (e = intel_execution_engines; e->name; e++) {
-		if (gem_can_store_dword(fd, e->exec_id | e->flags))
-			store_dword(fd, e->exec_id | e->flags);
-	}
+	for (e = intel_execution_engines; e->name; e++)
+		store_dword(fd, eb_ring(e));
 
 	store_all(fd);
 
diff --git a/tests/kms_busy.c b/tests/kms_busy.c
index 5ff2b8460..faad73092 100644
--- a/tests/kms_busy.c
+++ b/tests/kms_busy.c
@@ -315,32 +315,28 @@ igt_main
 
 		igt_subtest_f("basic-flip-%s",
 			kmstest_pipe_name(n)) {
-			igt_require(gem_has_ring(display.drm_fd,
-						e->exec_id | e->flags));
+			igt_require(gem_has_ring(display.drm_fd, eb_ring(e)));
 
-			test_flip(&display, e->exec_id | e->flags, n, false);
+			test_flip(&display, eb_ring(e), n, false);
 		}
 		igt_subtest_f("basic-modeset-%s",
 			kmstest_pipe_name(n)) {
-			igt_require(gem_has_ring(display.drm_fd,
-						e->exec_id | e->flags));
+			igt_require(gem_has_ring(display.drm_fd, eb_ring(e)));
 
-			test_flip(&display, e->exec_id | e->flags, n, true);
+			test_flip(&display, eb_ring(e), n, true);
 		}
 
 		igt_fixture {
-			igt_require(gem_has_ring(display.drm_fd,
-						e->exec_id | e->flags));
+			igt_require(gem_has_ring(display.drm_fd, eb_ring(e)));
 
 			hang = igt_allow_hang(display.drm_fd, 0, 0);
 		}
 
 		igt_subtest_f("extended-pageflip-modeset-hang-oldfb-%s-%s",
 				e->name, kmstest_pipe_name(n)) {
-			igt_require(gem_has_ring(display.drm_fd,
-						e->exec_id | e->flags));
+			igt_require(gem_has_ring(display.drm_fd, eb_ring(e)));
 
-			test_pageflip_modeset_hang(&display, e->exec_id | e->flags, n);
+			test_pageflip_modeset_hang(&display, eb_ring(e), n);
 		}
 
 		igt_fixture
@@ -348,25 +344,25 @@ igt_main
 
 		igt_subtest_f("extended-pageflip-hang-oldfb-%s-%s",
 				e->name, kmstest_pipe_name(n))
-			test_hang(&display, e->exec_id | e->flags, n, false, false);
+			test_hang(&display, eb_ring(e), n, false, false);
 
 		igt_subtest_f("extended-pageflip-hang-newfb-%s-%s",
 				e->name, kmstest_pipe_name(n))
-			test_hang(&display, e->exec_id | e->flags, n, false, true);
+			test_hang(&display, eb_ring(e), n, false, true);
 
 		igt_subtest_f("extended-modeset-hang-oldfb-%s-%s",
 				e->name, kmstest_pipe_name(n))
-			test_hang(&display, e->exec_id | e->flags, n, true, false);
+			test_hang(&display, eb_ring(e), n, true, false);
 
 		igt_subtest_f("extended-modeset-hang-newfb-%s-%s",
 				e->name, kmstest_pipe_name(n))
-			test_hang(&display, e->exec_id | e->flags, n, true, true);
+			test_hang(&display, eb_ring(e), n, true, true);
 
 		igt_subtest_f("extended-modeset-hang-oldfb-with-reset-%s-%s",
 				e->name, kmstest_pipe_name(n)) {
 			igt_set_module_param_int("force_reset_modeset_test", 1);
 
-			test_hang(&display, e->exec_id | e->flags, n, true, false);
+			test_hang(&display, eb_ring(e), n, true, false);
 
 			igt_set_module_param_int("force_reset_modeset_test", 0);
 		}
@@ -375,7 +371,7 @@ igt_main
 				e->name, kmstest_pipe_name(n)) {
 			igt_set_module_param_int("force_reset_modeset_test", 1);
 
-			test_hang(&display, e->exec_id | e->flags, n, true, true);
+			test_hang(&display, eb_ring(e), n, true, true);
 
 			igt_set_module_param_int("force_reset_modeset_test", 0);
 		}
diff --git a/tests/prime_busy.c b/tests/prime_busy.c
index 4f237f68f..8ee23bb3f 100644
--- a/tests/prime_busy.c
+++ b/tests/prime_busy.c
@@ -192,8 +192,8 @@ static void test_engine_mode(int fd,
 
 	igt_subtest_group {
 		igt_fixture {
-			gem_require_ring(fd, e->exec_id | e->flags);
-			igt_require(gem_can_store_dword(fd, e->exec_id | e->flags));
+			gem_require_ring(fd, eb_ring(e));
+			igt_require(gem_can_store_dword(fd, eb_ring(e)));
 
 			if ((flags & HANG) == 0)
 			{
@@ -209,12 +209,12 @@ static void test_engine_mode(int fd,
 		igt_subtest_f("%s%s-%s",
 			      !e->exec_id && !(flags & HANG) ? "basic-" : "",
 			      name, e->name)
-			busy(fd, e->exec_id | e->flags, flags);
+			busy(fd, eb_ring(e), flags);
 
 		igt_subtest_f("%swait-%s-%s",
 			      !e->exec_id && !(flags & HANG) ? "basic-" : "",
 			      name, e->name)
-			busy(fd, e->exec_id | e->flags, flags | POLL);
+			busy(fd, eb_ring(e), flags | POLL);
 
 		igt_fixture {
 			if ((flags & HANG) == 0)
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index bebf9edc6..2b21ff414 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -848,8 +848,8 @@ igt_main
 		igt_subtest_f("%ssync-%s",
 			      e->exec_id == 0 ? "basic-" : "",
 			      e->name) {
-			gem_require_ring(i915, e->exec_id | e->flags);
-			igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+			gem_require_ring(i915, eb_ring(e));
+			igt_require(gem_can_store_dword(i915, eb_ring(e)));
 
 			gem_quiescent_gpu(i915);
 			test_sync(i915, vgem, e->exec_id, e->flags);
@@ -860,8 +860,8 @@ igt_main
 		igt_subtest_f("%sbusy-%s",
 			      e->exec_id == 0 ? "basic-" : "",
 			      e->name) {
-			gem_require_ring(i915, e->exec_id | e->flags);
-			igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+			gem_require_ring(i915, eb_ring(e));
+			igt_require(gem_can_store_dword(i915, eb_ring(e)));
 
 			gem_quiescent_gpu(i915);
 			test_busy(i915, vgem, e->exec_id, e->flags);
@@ -872,8 +872,8 @@ igt_main
 		igt_subtest_f("%swait-%s",
 			      e->exec_id == 0 ? "basic-" : "",
 			      e->name) {
-			gem_require_ring(i915, e->exec_id | e->flags);
-			igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+			gem_require_ring(i915, eb_ring(e));
+			igt_require(gem_can_store_dword(i915, eb_ring(e)));
 
 			gem_quiescent_gpu(i915);
 			test_wait(i915, vgem, e->exec_id, e->flags);
@@ -895,8 +895,8 @@ igt_main
 			igt_subtest_f("%sfence-wait-%s",
 					e->exec_id == 0 ? "basic-" : "",
 					e->name) {
-				gem_require_ring(i915, e->exec_id | e->flags);
-				igt_require(gem_can_store_dword(i915, e->exec_id | e->flags));
+				gem_require_ring(i915, eb_ring(e));
+				igt_require(gem_can_store_dword(i915, eb_ring(e)));
 
 				gem_quiescent_gpu(i915);
 				test_fence_wait(i915, vgem, e->exec_id, e->flags);
-- 
2.24.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx





[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux