[igt-dev] [PATCH i-g-t v14 26/33] lib/ioctl_wrappers: Add gem_has_relocations() check

Chris Wilson chris at chris-wilson.co.uk
Thu Jan 14 15:21:46 UTC 2021


Quoting Zbigniew Kempczyński (2021-01-14 12:22:26)
> Add check which probes kernel relocation or not for i915 device.
> 
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: Petri Latvala <petri.latvala at intel.com>
> ---
>  lib/ioctl_wrappers.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  lib/ioctl_wrappers.h |  1 +
>  2 files changed, 44 insertions(+)
> 
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index 45415621b..1b4ca85da 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -868,6 +868,49 @@ uint64_t gem_total_stolen_size(int fd)
>         return aperture.stolen_total_size;
>  }
>  
> +/**
> + * gem_has_relocations:
> + * @fd: opened i915 drm file descriptor
> + *
> + * Feature test macro to query whether kernel allows for generation to
> + * use relocations.
> + *
> + * Returns: true if we can use relocations, otherwise false
> + */
> +bool gem_has_relocations(int fd)
> +{
> +       struct drm_i915_gem_relocation_entry reloc;
> +       struct drm_i915_gem_exec_object2 obj;
> +       struct drm_i915_gem_execbuffer2 execbuf;
> +       const uint32_t bbe = mi_batch_buffer_end;
> +       unsigned int reloc_offset = 0x10;
> +       int ret;
> +
> +       memset(&obj, 0, sizeof(obj));
> +       obj.handle = gem_create(fd, 4096);
> +       obj.relocs_ptr = to_user_pointer(&reloc);
> +       obj.relocation_count = 1;
> +       obj.offset = 1;
> +       gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
> +
> +       memset(&execbuf, 0, sizeof(execbuf));
> +       execbuf.buffers_ptr = to_user_pointer(&obj);
> +       execbuf.buffer_count = 1;
> +       memset(&reloc, 0, sizeof(reloc));
> +       reloc.offset = reloc_offset;
> +       reloc.target_handle = obj.handle;
> +       reloc.read_domains = i915_gem_domain_instruction;
> +       reloc.presumed_offset = -1;
> +
> +       ret = __gem_execbuf(fd, &execbuf);
> +       gem_close(fd, obj.handle);

I would expect

bool gem_has_relocations(int i915)
{
	struct drm_i915_gem_relocation_entry reloc = {};
	struct drm_i915_gem_exec_object2 obj = {
		.handle = gem_create(i915, 4096),
		.relocs_ptr = to_user_pointer(&reloc),
		.relocation_count = 1,
	};
	struct drm_i915_gem_execbuffer2 execbuf = {
		.buffers_ptr = to_user_pointer(&obj),
		.buffer_count = 1,
	};
	bool has_relocs;

	has_relocs = __gem_execbuf(i915, &execbuf) == -ENOENT;
	gem_close(i915, obj.handle);

	return has_relocs;
}

so we probe without execution (albeit cannot avoid the gem_create).

Not that I think this is relevant.
-Chris


More information about the igt-dev mailing list