<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 3, 2019 at 3:19 AM Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks a lot for writing this :)<br>
I now have a canvas to add stuff on!<br>
<br>
Just a couple of questions below.<br>
<br>
-Lionel<br>
<br>
On 02/08/2019 20:40, Jason Ekstrand wrote:<br>
> This patch only brings the syncobj documentation up-to-date for the<br>
> original form of syncobj.  It does not contain any information about the<br>
> design of timeline syncobjs.<br>
> ---<br>
>   drivers/gpu/drm/drm_syncobj.c | 81 +++++++++++++++++++++++++++++++----<br>
>   1 file changed, 73 insertions(+), 8 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c<br>
> index 1438dcb3ebb1..03cc888744fb 100644<br>
> --- a/drivers/gpu/drm/drm_syncobj.c<br>
> +++ b/drivers/gpu/drm/drm_syncobj.c<br>
> @@ -29,17 +29,82 @@<br>
>   /**<br>
>    * DOC: Overview<br>
>    *<br>
> - * DRM synchronisation objects (syncobj, see struct &drm_syncobj) are<br>
> - * persistent objects that contain an optional fence. The fence can be updated<br>
> - * with a new fence, or be NULL.<br>
> + * DRM synchronisation objects (syncobj, see struct &drm_syncobj) provide a<br>
> + * synchronization primitive which can be used by userspace to explicitly<br>
> + * synchronize GPU commands, can be shared between userspace processes, and<br>
> + * can be shared between different DRM drivers.<br>
<br>
<br>
I've been wondering whether we should call it a container for a <br>
synchronization primitive rather than a primitive itself.<br>
<br>
Sync files are also a container, just we fewer features (no host <br>
operations).<br>
<br>
It's not really important :)<br></blockquote><div><br></div><div>That's a fun philosophical question and I think the answer entirely depends on which side of the ioctl you're on. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + * Their primary use-case is to implement Vulkan fences and semaphores.<br>
> + * The syncobj userspace API provides ioctls for several operations:<br>
>    *<br>
> - * syncobj's can be waited upon, where it will wait for the underlying<br>
> - * fence.<br>
> + *  - Creation and destruction of syncobjs<br>
> + *  - Import and export of syncobjs to/from a syncobj file descriptor<br>
> + *  - Import and export a syncobj's underlying fence to/from a sync file<br>
> + *  - Reset a syncobj (set its fence to NULL)<br>
> + *  - Signal a syncobj (set a trivially signaled fence)<br>
> + *  - Wait a syncobj's fence to be signaled<br>
>    *<br>
> - * syncobj's can be export to fd's and back, these fd's are opaque and<br>
> - * have no other use case, except passing the syncobj between processes.<br>
> + * At it's core, a syncobj simply a wrapper around a pointer to a struct<br>
> + * &dma_fence which may be NULL.<br>
> + * When GPU work which signals a syncobj is enqueued in a DRM driver,<br>
> + * the syncobj fence is replaced with a fence which will be signaled by the<br>
> + * completion of that work.<br>
> + * When GPU work which waits on a syncobj is enqueued in a DRM driver, the<br>
> + * driver retrieves syncobj's current fence at the time the work is enqueued<br>
> + * waits on that fence before submitting the work to hardware.<br>
> + * If the syncobj's fence is NULL, the enqueue operation is expected to fail.<br>
> + * All manipulation of the syncobjs's fence happens in terms of the current<br>
> + * fence at the time the ioctl is called by userspace regardless of whether<br>
> + * that operation is an immediate host-side operation (signal or reset) or<br>
> + * or an operation which is enqueued in some driver queue.<br>
>    *<br>
> - * Their primary use-case is to implement Vulkan fences and semaphores.<br>
<br>
<br>
Maybe add a line about creation (and its signaled flag)?<br></blockquote><div><br></div><div>Sure, I'll also make a comment about reset and signal.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + *<br>
> + * Host-side wait on syncobjs<br>
> + * --------------------------<br>
> + *<br>
> + * The userspace syncobj API provides an ioctl for waiting on a set of<br>
> + * syncobjs.<br>
> + * The wait ioctl takes an array of syncobj handles and a flag indicating<br>
> + * whether it should return immediately once one syncobj has been signaled<br>
> + * or if it should wait for all the syncobjs to be signaled.<br>
> + * Unlike the enqueued GPU work dependencies, the host-side wait ioctl<br>
> + * will also optionally wait for the syncobj to first receive a fence and<br>
> + * then wait on that fence.<br>
> + * Assuming the syncobj starts off with a NULL fence, this allows a client<br>
> + * to do a host wait in one thread (or process) which waits on GPU work<br>
> + * submitted in another thread (or process) without having to manually<br>
> + * synchronize between the two.<br>
> + * This requirement is inherited from the Vulkan fence API.<br>
<br>
<br>
Should we list the flags & ioctl names?<br></blockquote><div><br></div><div>I don't know.  Maybe Dave or Daniel can tell me how these things are usually done?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + *<br>
> + *<br>
> + * Import/export of syncobjs<br>
> + * -------------------------<br>
> + *<br>
> + * The userspace syncobj API provides two mechanisms for import/export of<br>
> + * syncobjs.<br>
> + *<br>
> + * The first lets the client import or export an entire syncobj to a file<br>
> + * descriptor.<br>
> + * These fd's are opaque and have no other use case, except passing the<br>
> + * syncobj between processes.<br>
> + * All syncobj handles which are created as the result of such an import<br>
> + * operation refer to the same underlying syncobj as was used for the<br>
> + * export and the syncobj can be used persistently across all the processes<br>
> + * with which it is shared.<br>
> + * Unlike dma-buf, importing a syncobj creates a new handle for every<br>
> + * import instead of de-duplicating.<br>
> + * The primary use-case of this persistent import/export is for shared<br>
> + * Vulkan fences and semaphores.<br>
> + *<br>
> + * The second import/export mechanism lets the client export the syncobj's<br>
> + * current fence to/from a &sync_file.<br>
> + * When a syncobj is exported to a sync file, that sync file wraps the<br>
> + * sycnobj's fence at the time of export and any later signal or reset<br>
> + * operations on the syncobj will not affect the exported sync file.<br>
> + * When a sync file is imported into a syncobj, the syncobj's fence is set<br>
> + * to the fence wrapped by that sync file.<br>
> + * Because sync files are immutable, resetting or signaling the syncobj<br>
> + * will not affect any sync files whose fences have been imported into the<br>
> + * syncobj.<br>
>    *<br>
<br>
<br>
This 3 lines below seem to be redundant now?<br></blockquote><div><br></div><div>Which three lines are you referring to?  The thing about krefs?  I agree that it feels a bit odd with the rest of the documentation because it's a very internal detail and the rest of what I've written is an overview.  Maybe the bit about krefs should go in the top section and the bit about the file should stay here?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Maybe rephrase with something like :<br>
<br>
<br>
"Sharing a syncobj increases its refcount. The syncobj is destroyed when <br>
a client release the last reference."<br></blockquote><div><br></div><div>I don't think we need to describe how reference counting works.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>    * syncobj have a kref reference count, but also have an optional file.<br>
>    * The file is only created once the syncobj is exported.<br>
<br>
<br>
</blockquote></div></div>