[Mesa-dev] [PATCH v4 10/10] anv: Do relocations in userspace before execbuf ioctl
Chris Wilson
chris at chris-wilson.co.uk
Tue Nov 8 10:27:00 UTC 2016
On Mon, Nov 07, 2016 at 02:27:54PM -0800, Jason Ekstrand wrote:
> From: Kristian Høgsberg Kristensen <kristian.h.kristensen at intel.com>
>
> Since our surface state buffer is shared by all batches, the kernel does a
> full stall and sync with the CPU between batches every time we call
> execbuf2 because it refuses to do relocations on an active buffer. Doing
> them in userspace and passing the NO_RELOC flag to the kernel allows us to
> perform the relocations without stalling.
>
> This improves the performance of Dota 2 by around 30% on a Sky Lake GT2.
>
> v2 (Jason Ekstrand):
> - Better comments (Chris Wilson)
> - Fixed write_reloc for correct canonical form (Chris Wilson)
>
> v3 (Jason Ekstrand):
> - Skip relocations which aren't needed
> - Provide an environment variable to always use the kernel
> - More comments about correctness (Chris Wilson)
>
> v4 (Jason Ekstrand):
> - More comments (Chris Wilson)
>
> v5 (Jason Ekstrand):
> - Rebase on top of moving execbuf2 setup go QueueSubmit
>
> Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
> ---
> @@ -1134,14 +1238,48 @@ anv_cmd_buffer_execbuf(struct anv_device *device,
> .rsvd2 = 0,
> };
>
> - /* Since surface states are shared between command buffers and we don't
> - * know what order they will be submitted to the kernel, we don't know what
> - * address is actually written in the surface state object at any given
> - * time. The only option is to set a bogus presumed offset and let
> - * relocations do their job.
> - */
> - for (size_t i = 0; i < cmd_buffer->surface_relocs.num_relocs; i++)
> - cmd_buffer->surface_relocs.relocs[i].presumed_offset = -1;
> + if (relocate_cmd_buffer(cmd_buffer, &execbuf)) {
> + /* If we were able to successfully relocate everything, tell the kernel
> + * that it can skip doing relocations. The requirement for using
> + * NO_RELOC is:
> + *
> + * 1) The addresses written in the objects must match the corresponding
> + * reloc.presumed_offset which in turn must match the corresponding
> + * execobject.offset.
> + *
> + * 2) To avoid stalling, execobject.offset should match the current
> + * address of that object within the active context.
> + *
> + * In order to satisfy all of the invariants that make userspace
> + * relocations to be safe (see relocate_cmd_buffer()), we need to
> + * further ensure that the addresses we use match those used by the
> + * kernel for the most recent execbuf2.
> + *
> + * If we were able to successfully relocate everything, tell the kernel
> + * that it can skip doing relocations.
Duplicate (with opening) sentence.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
More information about the mesa-dev
mailing list