[Intel-gfx] [igt-dev] [PATCH i-g-t 24/25] gem_wsim: Discover engines

Chris Wilson chris at chris-wilson.co.uk
Fri May 17 19:50:11 UTC 2019


Quoting Tvrtko Ursulin (2019-05-17 12:51:06)
> 
> On 17/05/2019 12:39, Andi Shyti wrote:
> > Hi Tvrtko,
> > 
> >> +static int
> >> +__i915_query(int i915, struct drm_i915_query *q)
> >> +{
> >> +    if (igt_ioctl(i915, DRM_IOCTL_I915_QUERY, q))
> >> +            return -errno;
> >> +    return 0;
> >> +}
> >> +
> >> +static int
> >> +__i915_query_items(int i915, struct drm_i915_query_item *items, uint32_t n_items)
> >> +{
> >> +    struct drm_i915_query q = {
> >> +            .num_items = n_items,
> >> +            .items_ptr = to_user_pointer(items),
> >> +    };
> >> +    return __i915_query(i915, &q);
> >> +}
> >> +
> >> +static void
> >> +i915_query_items(int i915, struct drm_i915_query_item *items, uint32_t n_items)
> >> +{
> >> +    igt_assert_eq(__i915_query_items(i915, items, n_items), 0);
> >> +}
> >> +
> >> +static bool has_query(int i915)
> >> +{
> >> +    struct drm_i915_query query = {};
> >> +
> >> +    return __i915_query(i915, &query) == 0;
> >> +}
> >> +
> >> +static bool has_engine_query(int i915)
> >> +{
> >> +    struct drm_i915_query_item item = {
> >> +            .query_id = DRM_I915_QUERY_ENGINE_INFO,
> >> +    };
> >> +
> >> +    return __i915_query_items(i915, &item, 1) == 0 && item.length > 0;
> >> +}
> >> +
> >> +static void query_engines(void)
> >> +{
> > 
> > [...]
> > 
> >> +            struct drm_i915_query_engine_info *engine_info;
> >> +            struct drm_i915_query_item item = {
> >> +                    .query_id = DRM_I915_QUERY_ENGINE_INFO,
> >> +            };
> >> +            const unsigned int sz = 4096;
> >> +            unsigned int i;
> >> +
> >> +            engine_info = malloc(sz);
> >> +            igt_assert(engine_info);
> >> +            memset(engine_info, 0, sz);
> >> +
> >> +            item.data_ptr = to_user_pointer(engine_info);
> >> +            item.length = sz;
> >> +
> >> +            i915_query_items(fd, &item, 1);
> >> +            igt_assert(item.length > 0);
> >> +            igt_assert(item.length <= sz);
> >> +
> >> +            num = engine_info->num_engines;
> >> +
> >> +            engines = calloc(num,
> >> +                             sizeof(struct i915_engine_class_instance));
> >> +            igt_assert(engines);
> >> +
> >> +            for (i = 0; i < num; i++) {
> >> +                    struct drm_i915_engine_info *engine =
> >> +                            (struct drm_i915_engine_info *)&engine_info->engines[i];
> >> +
> >> +                    engines[i] = engine->engine;
> >> +            }
> >> +    }
> >> +
> >> +    __engines = engines;
> >> +    __num_engines = num;
> >> +}
> > 
> > would it make sense to make a library out of all the above? e.g.
> > gem_engine_topology does similar thing (all static functions like
> > here, though).
> 
> Definitely yes, but coordinating all series seems tricky. I think best 
> would be to consolidate once everything gets merged?

The challenge is carving out the core into a separate library that
doesn't pull libigt.la in. (Tvrtko has already committed the cardinal sin
of using libigt outside of tests/.) At which point, you have just a
bunch of ioctl wrappers, and fwiw some of us may wish gem_wsim itself
was a scripting engine...
-Chris


More information about the Intel-gfx mailing list