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

Andi Shyti andi.shyti at intel.com
Fri May 17 11:55:17 UTC 2019


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?

yes, sure! let's get everything in first :)

Andi


More information about the Intel-gfx mailing list