[igt-dev] [PATCH i-g-t v2 01/10] lib/igt_dummyload: add igt_cork

Chris Wilson chris at chris-wilson.co.uk
Sat Feb 10 09:26:48 UTC 2018


Quoting Antonio Argenziano (2018-02-09 23:38:56)
> From: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
> 
> The "cork" bo (imported bo with attached fence) is used in several
> tests to stall execution. Moving it to a common place makes the codebase
> cleaner.
> 
> Note that the actual test updates is done in follow up patches as it is
> simpler to do in one go after one more common function is added in the
> next patch.
> 
> v2: don't use new/free naming, don't use dynamic alloc (Chris)
> 
> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  lib/igt_dummyload.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_dummyload.h |  8 ++++++++
>  2 files changed, 66 insertions(+)
> 
> diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
> index 27eb402b..ddaa6f0c 100644
> --- a/lib/igt_dummyload.c
> +++ b/lib/igt_dummyload.c
> @@ -29,12 +29,14 @@
>  #include <i915_drm.h>
>  
>  #include "igt_core.h"
> +#include "drmtest.h"
>  #include "igt_dummyload.h"
>  #include "igt_gt.h"
>  #include "intel_chipset.h"
>  #include "intel_reg.h"
>  #include "ioctl_wrappers.h"
>  #include "sw_sync.h"
> +#include "igt_vgem.h"
>  
>  /**
>   * SECTION:igt_dummyload
> @@ -371,3 +373,59 @@ void igt_terminate_spin_batches(void)
>                 igt_spin_batch_end(iter);
>         pthread_mutex_unlock(&list_lock);
>  }
> +
> +/**
> + * igt_cork_plug:
> + * @fd: open drm file descriptor
> + * @cork: structure that will be filled with the state of the cork bo
> + *
> + * Imports a vgem bo with a fence attached to it. This bo can be used as a
> + * dependency during submission to stall execution until the fence is signaled.
> + * The parameters required to unblock the execution and to cleanup are stored in
> + * the provided cork structure.
> + *
> + * Returns:
> + * Handle of the imported BO.
> + */
> +uint32_t igt_cork_plug(int fd, struct igt_cork *cork)
> +{
> +       struct vgem_bo bo;
> +       int dmabuf;
> +       uint32_t handle;
> +
> +       igt_assert(cork);
> +
> +       cork->device = drm_open_driver(DRIVER_VGEM);
> +
> +       igt_require(vgem_has_fences(cork->device));
> +
> +       bo.width = bo.height = 1;
> +       bo.bpp = 4;
> +       vgem_create(cork->device, &bo);
> +       cork->fence = vgem_fence_attach(cork->device, &bo, VGEM_FENCE_WRITE);
> +
> +       dmabuf = prime_handle_to_fd(cork->device, bo.handle);
> +       handle = prime_fd_to_handle(fd, dmabuf);
> +       close(dmabuf);
> +
> +       return handle;
> +}
> +
> +/**
> + * igt_cork_unplug:
> + * @cork: cork state from igt_cork_plug()
> + *
> + * This function unblocks the execution by signaling the fence attached to the
> + * imported bo and does the necessary post-processing.
> + * NOTE: the imported bo handle returned by igt_cork_plug is not closed during
> + * this phase.
> + */
> +void igt_cork_unplug(struct igt_cork *cork)
> +{
> +       if (!cork || !cork->device)
> +               return;

plug does assert, but not unplug?

> +

Should have a comment here explaining that the reason we keep fence and
call vgem_fence_signal (as it would be autosignalled by close()) is so
that we catch when the fence timed-out.

Now, we could set this up with sw_sync (as used in a few other places
for corking) to avoid that timeout. Iirc, I suggested the library
routines provide both, since both are in use.

> +       vgem_fence_signal(cork->device, cork->fence);
> +       close(cork->device);
> +       cork->device = 0;

-1 for an invalid fd.
-Chris


More information about the igt-dev mailing list