dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/4] drm: add explicit fencing
@ 2016-10-20 14:50 Gustavo Padovan
  2016-10-20 14:50 ` [PATCH v5 1/4] drm/fence: add in-fences support Gustavo Padovan
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: Gustavo Padovan @ 2016-10-20 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: linux-kernel, Daniel Stone, Daniel Vetter, Rob Clark,
	Greg Hackmann, John Harrison, laurent.pinchart, seanpaul, marcheu,
	m.chehab, Sumit Semwal, Maarten Lankhorst, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Hi,

Currently the Linux Kernel only have an implicit fencing mechanism, through 
reservation objects, in which the fences are attached directly to buffers
operations and userspace is unaware of what is happening. On the other hand
explicit fencing exposes fences to the userspace to handle fencing between
producer/consumer explicitely.

To support explicit fencing in the mainline kernel we de-staged the the needed
parts of the Android Sync Framework[1] to be able to send and received fences
to/from userspace. It has the concept of sync_file that exposes the driver's
fences to userspace as file descriptors.

With explicit fencing we have a global mechanism that optimizes the flow of
buffers between consumers and producers, avoiding a lot of waiting and some
potential desktop freeze. So instead of waiting for a buffer to be processed by
the GPU before sending it to DRM in an Atomic IOCTL we can get a sync_file fd
from the GPU driver at the moment we submit the buffer processing. The
compositor then passes these fds to DRM in an Atomic IOCTL, that will
not be displayed until the fences signal, i.e, the GPU finished processing the
buffer and it is ready to display. In DRM the fences we wait on before
displaying a buffer are called in-fences and they are a per-plane deal.

Vice-versa, we have out-fences to sychronize the return of buffers to GPU
(producer) to be processed again. When DRM receives an atomic request with a
the OUT_FENCE_PTR property it create a fence attach it to a per-crtc
sync_file. It then returns the sync_file fds to userspace. With the fences
available userspace can forward these fences to the GPU, where it will wait the
fence to signal before starting to process on buffer again. Out-fences are
per-crtc.

While these are out-fences in DRM (the consumer) they become in-fences once
they get to the GPU (the producer).

DRM explicit fences are opt-in, as the default will still be implicit fencing.

In-fences
---------

In the first discussions on #dri-devel on IRC we decided to hide the Sync
Framework from DRM drivers to reduce complexity, so as soon we get the fd
via IN_FENCE_FD plane property we convert the sync_file fd to a struct fence.
However a sync_file might contain more than one fence, so we created the
fence_array concept. struct fence_array is a subclass of struct
fence and stores a group of fences that needs to be waited together.

Then we just use the already in place fence waiting support to wait on those
fences. Once the producer calls fence_signal() for all fences on wait we can
proceed with the atomic commit and display the framebuffers.

Out-fences
----------

Passing a pointer to OUT_FENCE_PTR property in an atomic request enables
out-fences. The kernel then creates a fence, attach it to a sync_file and
install this file on a unused fd for each crtc. The kernel writes the fd in
the memory pointed by the out_fence_ptr provided. In case of error it writes -1.

DRM core use the already in place drm_event infrastructure to help signal
fences, we've added a fence pointer to struct drm_pending_event. We signal
signal fences when all the buffer related to that CRTC are *on* the screen.

Kernel tree
-----------

For those who want all patches on this RFC are in my tree:

https://git.kernel.org/cgit/linux/kernel/git/padovan/linux.git/log/?h=fences


v5 changes
----------

The changes from  v5 to v4 are in the patches description.


Userspace
---------

Fences support on drm_hwcomposer is currently a working in progress.

Regards,

        Gustavo

[1] https://source.android.com/devices/graphics/implement.html#vsync

---
Gustavo Padovan (4):
  drm/fence: add in-fences support
  drm/fence: release fence reference when canceling event
  drm/fence: add fence timeline to drm_crtc
  drm/fence: add out-fences support

 drivers/gpu/drm/Kconfig             |   1 +
 drivers/gpu/drm/drm_atomic.c        | 138 +++++++++++++++++++++++++++++-------
 drivers/gpu/drm/drm_atomic_helper.c |  13 ++--
 drivers/gpu/drm/drm_crtc.c          |  45 ++++++++++++
 drivers/gpu/drm/drm_fops.c          |   4 ++
 drivers/gpu/drm/drm_plane.c         |   1 +
 include/drm/drm_crtc.h              |  43 +++++++++++
 include/drm/drm_plane.h             |   4 +-
 8 files changed, 214 insertions(+), 35 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-10-21 15:44 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-20 14:50 [PATCH v5 0/4] drm: add explicit fencing Gustavo Padovan
2016-10-20 14:50 ` [PATCH v5 1/4] drm/fence: add in-fences support Gustavo Padovan
2016-10-21 12:51   ` Daniel Vetter
2016-10-20 14:50 ` [PATCH v5 2/4] drm/fence: release fence reference when canceling event Gustavo Padovan
2016-10-21 12:52   ` Daniel Vetter
2016-10-20 14:50 ` [PATCH v5 3/4] drm/fence: add fence timeline to drm_crtc Gustavo Padovan
2016-10-20 17:20   ` Brian Starkey
2016-10-20 20:12     ` Gustavo Padovan
2016-10-21 12:54   ` Daniel Vetter
2016-10-20 14:50 ` [PATCH v5 4/4] drm/fence: add out-fences support Gustavo Padovan
2016-10-20 15:35   ` Ville Syrjälä
2016-10-20 15:55     ` Gustavo Padovan
2016-10-20 16:34       ` Ville Syrjälä
2016-10-20 19:15         ` Ville Syrjälä
2016-10-21 12:57           ` Daniel Vetter
2016-10-21 13:07             ` Gustavo Padovan
2016-10-20 17:48   ` Brian Starkey
2016-10-20 20:30     ` Gustavo Padovan
2016-10-21 10:55       ` Brian Starkey
2016-10-21 13:00         ` Daniel Vetter
2016-10-21 15:44   ` Brian Starkey
2016-10-21 13:04 ` [PATCH v5 0/4] drm: add explicit fencing Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).