Re: [igt-dev] [RFC PATCH v9 3/5] lib/igt_gt: use for_each_engine2 to loop through engines

Chris Wilson
2019-02-14T09:50:43Z

Quoting Andi Shyti (2019-02-14 00:44:43)
> 'for_each_engine2()' defines a loop through the gpu engines.
>
> It can work with both active and pre-defined engines.
>
> In case we are looping through active engines (i.e. the running
> kernel has the query and get/setparam ioctls), the
> intel_active_engines2 points to an array that contains only the
> list engines dynamically allocated after having interrogated the
> driver.
>
> While, if we are looping through pre-defined engines,
> intel_active_engines2 points to the 'intel_execution_engines2'
> array and works exactly as for_each_engine() but using the
> new 'struct intel_execution_engine2' data type.
>
> Signed-off-by: Andi Shyti <andi.shyti@intel.com>
> ---
> lib/igt_gt.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/lib/igt_gt.h b/lib/igt_gt.h
> index f4bd6c22a81a..39e3a927191c 100644
> --- a/lib/igt_gt.h
> +++ b/lib/igt_gt.h
> @@ -30,6 +30,8 @@
>
> #include "i915_drm.h"
>
> +#include "i915/gem_query.h"
> +
> void igt_require_hang_ring(int fd, int ring);
>
> typedef struct igt_hang {
> @@ -86,6 +88,12 @@ extern const struct intel_execution_engine {
> e__++) \
> for_if (gem_ring_has_physical_engine(fd__, flags__ = e__->exec_id | e__->flags))
>
> +#define for_each_engine2(fd, ctx, e) \
> + for (__set_ctx_engine_map(fd, ctx_id), \
> + e = intel_active_engines2; e->name; e++) \

#define for_each_ctx_engine(fd, ctx, e__) \
for ((e__) = gem_context_get_engines((fd), (ctx)); (e__)->name; (e__)++)

Phrased like that, there is no need for extraneous entries in the array.
-Chris