virgl: fence fd support
Subsystems (3)
v2 cover virgl: fence fd support
From: Gustavo Padovan <[email protected]>
Hi,
So I finally got around to finish this work! :)
Here are the updated patchset with fixes for Rob Herring incorporated. This follow pretty much the same semantics of other drivers that implemented explicit fence support. It extends the execbuf ioctl to have an fence_fd argument that when entering the kernel carries the in-fence and when returning carries back the out-fence.
The mesa patch can be found at
https://gitlab.collabora.com/padovan/mesa
Please review!
Regards,
Gustavo
Gustavo Padovan (5):
drm/virtio: add virtio_gpu_alloc_fence()
drm/virtio: add uapi for in and out explicit fences drm/virtio: add in-fences support for explicit synchronization drm/virtio: add out-fences support for explicit synchronization drm/virtio: bump driver version after explicit synchronization
addition
drivers/gpu/drm/virtio/virtgpu_drv.h | 21 +++--- drivers/gpu/drm/virtio/virtgpu_fence.c | 41 ++++++++---- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 115 +++++++++++++++++++++++++++------ drivers/gpu/drm/virtio/virtgpu_plane.c | 46 +++++++++++-- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++--- include/uapi/drm/virtgpu_drm.h | 13 +++- 6 files changed, 197 insertions(+), 55 deletions(-)
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 1/5 drm/virtio: add virtio_gpu_alloc_fence()
From: Gustavo Padovan <[email protected]>
Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.
v2: - only alloc fence in virtio_gpu_alloc_fence(), init needs to be
all together. (Gerd Hoffman)
v3: - incorporate fence refcounting fixes from Rob Herring
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 +++++++------ drivers/gpu/drm/virtio/virtgpu_fence.c | 41 +++++++++++++++++++++--------- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 40 +++++++++++++++++++++++------ drivers/gpu/drm/virtio/virtgpu_plane.c | 46 ++++++++++++++++++++++++++++++---- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++++++------ 5 files changed, 121 insertions(+), 39 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +10 -7
@@ -128,6 +128,7 @@ struct virtio_gpu_framebuffer {int x1, y1, x2, y2;/* dirty rect */ spinlock_t dirty_lock;uint32_t hw_res_handle; +struct virtio_gpu_fence *fence; };#define to_virtio_gpu_framebuffer (x) \ container_of(x, struct virtio_gpu_framebuffer, base)
@@ -264,7 +265,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint64_t offset, __le32 width, __le32 height, __le32 x, __le32 y, - struct virtio_gpu_fence **fence); + struct virtio_gpu_fence *fence); void virtio_gpu_cmd_resource_flush(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t x, uint32_t y,
@@ -276,7 +277,7 @@ void virtio_gpu_cmd_set_scanout(struct virtio_gpu_device *vgdev,int virtio_gpu_object_attach (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *obj,uint32_t resource_id, -struct virtio_gpu_fence **fence); +struct virtio_gpu_fence *fence);int virtio_gpu_attach_status_page (struct virtio_gpu_device *vgdev);int virtio_gpu_detach_status_page (struct virtio_gpu_device *vgdev); void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
@@ -300,21 +301,21 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, uint32_t resource_id);void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence **fence); +uint32_t ctx_id,struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev,uint32_t resource_id,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, -struct virtio_gpu_fence **fence); +struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev,uint32_t resource_id,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, -struct virtio_gpu_fence **fence); +struct virtio_gpu_fence *fence);void virtio_gpu_cmd_resource_create_3d (struct virtio_gpu_device *vgdev,struct virtio_gpu_resource_create_3d *rc_3d, -struct virtio_gpu_fence **fence); +struct virtio_gpu_fence *fence);void virtio_gpu_ctrl_ack (struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);void virtio_gpu_fence_ack (struct virtqueue *vq);
@@ -342,9 +343,11 @@ void virtio_gpu_ttm_fini(struct virtio_gpu_device *vgdev);int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma);/* virtio_gpu_fence.c */ +struct virtio_gpu_fence *virtio_gpu_fence_alloc (struct virtio_gpu_device *vgdev); +void virtio_gpu_fence_cleanup (struct virtio_gpu_fence *fence);int virtio_gpu_fence_emit (struct virtio_gpu_device *vgdev,struct virtio_gpu_ctrl_hdr *cmd_hdr, -struct virtio_gpu_fence **fence); +struct virtio_gpu_fence *fence);void virtio_gpu_fence_event_process (struct virtio_gpu_device *vdev,u64 last_seq);
drivers/gpu/drm/virtio/virtgpu_fence.c +29 -12
57 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_ioctl.c +33 -7
@@ -167,15 +167,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, ret =PTR_ERR (buf); goto out_unresv; } + + fence =virtio_gpu_fence_alloc (vgdev); +if (!fence) { +kfree (buf); + ret = -ENOMEM ; + goto out_unresv; + } +virtio_gpu_cmd_submit (vgdev, buf, exbuf->size, - vfpriv->ctx_id, &fence); + vfpriv->ctx_id, fence);ttm_eu_fence_buffer_objects (&ticket, &validate_list, &fence->f);/* fence the command bo */ virtio_gpu_unref_list (&validate_list);kvfree (buflist); -dma_fence_put (&fence->f);return 0 ; out_unresv:
@@ -284,11 +291,17 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, rc_3d.nr_samples =cpu_to_le32 (rc->nr_samples); rc_3d.flags =cpu_to_le32 (rc->flags); + fence =virtio_gpu_fence_alloc (vgdev); +if (!fence) { + ret = -ENOMEM ; + goto fail_fence; + } +virtio_gpu_cmd_resource_create_3d (vgdev, &rc_3d,NULL ); - ret =virtio_gpu_object_attach (vgdev, qobj, res_id, &fence); + ret =virtio_gpu_object_attach (vgdev, qobj, res_id, fence);if (ret) { -ttm_eu_backoff_reservation (&ticket, &validate_list); - goto fail_unref; +virtio_gpu_fence_cleanup (fence); + goto fail_fence; }ttm_eu_fence_buffer_objects (&ticket, &validate_list, &fence->f); }
@@ -315,6 +328,8 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,dma_fence_put (&fence->f); }return 0 ; +fail_fence: +ttm_eu_backoff_reservation (&ticket, &validate_list); fail_unref:if (vgdev->has_virgl_3d) {virtio_gpu_unref_list (&validate_list);
@@ -379,10 +394,16 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, goto out_unres;convert_to_hw_box (&box, &args->box); + + fence =virtio_gpu_fence_alloc (vgdev); +if (!fence) { + ret = -ENOMEM ; + goto out_unres; + }virtio_gpu_cmd_transfer_from_host_3d (vgdev, qobj->hw_res_handle, vfpriv->ctx_id, offset, args->level, - &box, &fence); + &box, fence);reservation_object_add_excl_fence (qobj->tbo.resv, &fence->f);
@@ -428,10 +449,15 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, (vgdev, qobj->hw_res_handle, offset, box.w, box.h, box.x, box.y,NULL ); }else { + fence =virtio_gpu_fence_alloc (vgdev); +if (!fence) { + ret = -ENOMEM ; + goto out_unres; + }virtio_gpu_cmd_transfer_to_host_3d (vgdev, qobj->hw_res_handle, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, &fence); + args->level, &box, fence);reservation_object_add_excl_fence (qobj->tbo.resv, &fence->f);dma_fence_put (&fence->f);
drivers/gpu/drm/virtio/virtgpu_plane.c +41 -5
73 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +8 -8
@@ -317,7 +317,7 @@ static int virtio_gpu_queue_ctrl_buffer(struct virtio_gpu_device *vgdev,static int virtio_gpu_queue_fenced_ctrl_buffer (struct virtio_gpu_device *vgdev,struct virtio_gpu_vbuffer *vbuf,struct virtio_gpu_ctrl_hdr *hdr, -struct virtio_gpu_fence **fence) +struct virtio_gpu_fence *fence) {struct virtqueue *vq = vgdev->ctrlq.vq;int rc;
@@ -482,7 +482,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint64_t offset, __le32 width, __le32 height, __le32 x, __le32 y, - struct virtio_gpu_fence **fence) + struct virtio_gpu_fence *fence) { struct virtio_gpu_transfer_to_host_2d *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -506,7 +506,7 @@ virtio_gpu_cmd_resource_attach_backing(struct virtio_gpu_device *vgdev,uint32_t resource_id, struct virtio_gpu_mem_entry *ents, uint32_t nents, - struct virtio_gpu_fence **fence) + struct virtio_gpu_fence *fence) { struct virtio_gpu_resource_attach_backing *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -762,7 +762,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_resource_create_3d (struct virtio_gpu_device *vgdev,struct virtio_gpu_resource_create_3d *rc_3d, -struct virtio_gpu_fence **fence) +struct virtio_gpu_fence *fence) {struct virtio_gpu_resource_create_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -781,7 +781,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level, struct virtio_gpu_box *box, - struct virtio_gpu_fence **fence) + struct virtio_gpu_fence *fence) { struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -803,7 +803,7 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level, struct virtio_gpu_box *box, - struct virtio_gpu_fence **fence) + struct virtio_gpu_fence *fence) { struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -823,7 +823,7 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence **fence) +uint32_t ctx_id,struct virtio_gpu_fence *fence) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -844,7 +844,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,int virtio_gpu_object_attach (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *obj,uint32_t resource_id, -struct virtio_gpu_fence **fence) +struct virtio_gpu_fence *fence) {struct virtio_gpu_mem_entry *ents;struct scatterlist *sg;
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/5 drm/virtio: add uapi for in and out explicit fences
In reply to Gustavo PadovanFrom: Gustavo Padovan <[email protected]>
Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.
This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.
There are two new flags:
* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd
The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.
On error -1 should be returned in the fence_fd field.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 ++ include/uapi/drm/virtgpu_drm.h | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
@@ -115,6 +115,8 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,struct ww_acquire_ctx ticket;void *buf; + exbuf->fence_fd =-1 ; +if (vgdev->has_virgl_3d == false)return -ENOSYS ;
include/uapi/drm/virtgpu_drm.h +10 -3
@@ -47,6 +47,13 @@ extern "C" {#define DRM_VIRTGPU_WAIT 0x08#define DRM_VIRTGPU_GET_CAPS 0x09 +#define VIRTGPU_EXECBUF_FENCE_FD_IN 0x01 +#define VIRTGPU_EXECBUF_FENCE_FD_OUT 0x02 +#define VIRTGPU_EXECBUF_FLAGS (\ + VIRTGPU_EXECBUF_FENCE_FD_IN |\ + VIRTGPU_EXECBUF_FENCE_FD_OUT |\ + 0) +struct drm_virtgpu_map {__u64 offset;/* use for mmap system call */ __u32 handle;
@@ -54,12 +61,12 @@ struct drm_virtgpu_map { };struct drm_virtgpu_execbuffer { -__u32 flags;/* for future use */ +__u32 flags;__u32 size;__u64 command;/* void* */ __u64 bo_handles;__u32 num_bo_handles; -__u32 pad; +__s32 fence_fd; };#define VIRTGPU_PARAM_3D_FEATURES 1/* do we have 3D features in the hw */
@@ -136,7 +143,7 @@ struct drm_virtgpu_get_caps { DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_MAP, struct drm_virtgpu_map)#define DRM_IOCTL_VIRTGPU_EXECBUFFER \ - DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\ + DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\ struct drm_virtgpu_execbuffer)#define DRM_IOCTL_VIRTGPU_GETPARAM \
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 3/5 drm/virtio: add in-fences support for explicit synchronization
In reply to Gustavo PadovanFrom: Gustavo Padovan <[email protected]>
When the execbuf call receives an in-fence it will get the dma_fence related to that fence fd. If that fence is from a foreign context we wait on it before submitting the draw call.
v2: - incorporate fix for context check from Rob Herring
virtio-gpu: fix context check
We may have a foreign context from sw_sync, so we need to wait in that case.
If there's a match, returning an error doesn't seem right either.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +33 -9
@@ -28,6 +28,7 @@#include <drm/drmP.h> #include <drm/virtgpu_drm.h> #include <drm/ttm/ttm_execbuf_util.h> +#include <linux/sync_file.h> #include "virtgpu_drv.h"
@@ -113,6 +114,8 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,struct ttm_validate_buffer *buflist =NULL ;int i;struct ww_acquire_ctx ticket; +struct dma_fence *in_fence =NULL ; +int in_fence_fd = exbuf->fence_fd;void *buf; exbuf->fence_fd =-1 ;
@@ -120,6 +123,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,if (vgdev->has_virgl_3d == false)return -ENOSYS ; +if (exbuf->flags &VIRTGPU_EXECBUF_FENCE_FD_IN ) { + in_fence =sync_file_get_fence (in_fence_fd); +if (!in_fence) +return -EINVAL ; + +/* +* Wait if the fence is from a foreign context, or if the fence +* array contains any fence from a foreign context. +*/ +if (!dma_fence_match_context (in_fence, vgdev->fence_drv.context)) { + ret =dma_fence_wait (in_fence, true); +if (ret) +return ret; + } + } +INIT_LIST_HEAD (&validate_list);if (exbuf->num_bo_handles) {
@@ -129,26 +148,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,sizeof (struct ttm_validate_buffer ), GFP_KERNEL | __GFP_ZERO);if (!bo_handles || !buflist) { -kvfree (bo_handles); -kvfree (buflist); -return -ENOMEM ; + ret = -ENOMEM ; + goto out_in_fence; } user_bo_handles = (void __user *)(uintptr_t )exbuf->bo_handles;if (copy_from_user (bo_handles, user_bo_handles, exbuf->num_bo_handles *sizeof (uint32_t ))) { ret = -EFAULT ; -kvfree (bo_handles); -kvfree (buflist); -return ret; + goto out_in_fence; }for (i =0 ; i < exbuf->num_bo_handles; i++) { gobj =drm_gem_object_lookup (drm_file, bo_handles[i]);if (!gobj) { -kvfree (bo_handles); -kvfree (buflist); -return -ENOENT ; + ret = -ENOENT ; + goto out_in_fence; } qobj =gem_to_virtio_gpu_obj (gobj);
@@ -157,6 +172,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,list_add (&buflist[i].head, &validate_list); }kvfree (bo_handles); + bo_handles =NULL ; } ret =virtio_gpu_object_list_validate (&ticket, &validate_list);
@@ -177,6 +193,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unresv; } +if (in_fence) { +dma_fence_put (in_fence); + in_fence =NULL ; + } +virtio_gpu_cmd_submit (vgdev, buf, exbuf->size, vfpriv->ctx_id, fence);
@@ -191,7 +212,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,ttm_eu_backoff_reservation (&ticket, &validate_list); out_free:virtio_gpu_unref_list (&validate_list); +out_in_fence: +kvfree (bo_handles);kvfree (buflist); +dma_fence_put (in_fence);return ret; }
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 3/5] drm/virtio: add in-fences support for explicit synchronization
Quoted 11 lines · Gustavo Padovan
From: Gustavo Padovan <[email protected]>
When the execbuf call receives an in-fence it will get the
dma_fencerelated to that fence fd. If that fence is from a foreign context we wait on it before submitting the draw call.v2: - incorporate fix for context check from Rob Herring
Signed-off-by Gustavo Padovan <[email protected]>Signed-off-by Rob Herring <[email protected]>
Quoted 7 lines
virtio-gpu: fix context check
We may have a foreign context from
sw_sync, so we need to wait in that case.If there's a match, returning an error doesn't seem right either.
Signed-off-by Rob Herring <[email protected]>
Need to clean-up the squashed commit msg.
Rob
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 4/5 drm/virtio: add out-fences support for explicit synchronization
In reply to Gustavo PadovanFrom: Gustavo Padovan <[email protected]>
On the out-fence side we get fence returned by the submitted draw call and attach it to a sync_file and send the sync_file fd to userspace. On error -1 is returned to userspace.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 49 ++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +38 -11
@@ -105,7 +105,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;struct drm_gem_object *gobj; -struct virtio_gpu_fence *fence; +struct virtio_gpu_fence *out_fence;struct virtio_gpu_object *qobj;int ret;uint32_t *bo_handles =NULL ;
@@ -115,7 +115,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,int i;struct ww_acquire_ctx ticket;struct dma_fence *in_fence =NULL ; +struct sync_file *sync_file;int in_fence_fd = exbuf->fence_fd; +int out_fence_fd =-1 ;void *buf; exbuf->fence_fd =-1 ;
@@ -139,6 +141,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, } } +if (exbuf->flags &VIRTGPU_EXECBUF_FENCE_FD_OUT ) { + out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); +if (out_fence_fd <0 ) { + ret = out_fence_fd; + goto out_in_fence; + } + } +INIT_LIST_HEAD (&validate_list);if (exbuf->num_bo_handles) {
@@ -149,21 +159,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, GFP_KERNEL | __GFP_ZERO);if (!bo_handles || !buflist) { ret = -ENOMEM ; - goto out_in_fence; + goto out_unused_fd; } user_bo_handles = (void __user *)(uintptr_t )exbuf->bo_handles;if (copy_from_user (bo_handles, user_bo_handles, exbuf->num_bo_handles *sizeof (uint32_t ))) { ret = -EFAULT ; - goto out_in_fence; + goto out_unused_fd; }for (i =0 ; i < exbuf->num_bo_handles; i++) { gobj =drm_gem_object_lookup (drm_file, bo_handles[i]);if (!gobj) { ret = -ENOENT ; - goto out_in_fence; + goto out_unused_fd; } qobj =gem_to_virtio_gpu_obj (gobj);
@@ -186,11 +196,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unresv; } - fence =virtio_gpu_fence_alloc (vgdev); -if (!fence) { -kfree (buf); + out_fence =virtio_gpu_fence_alloc (vgdev); +if (!out_fence) { ret = -ENOMEM ; - goto out_unresv; + goto out_memdup; + } + +if (out_fence_fd >=0 ) { + sync_file =sync_file_create (&out_fence->f); +if (!sync_file) { +dma_fence_put (&out_fence->f); + ret = -ENOMEM ; + goto out_memdup; + } + + exbuf->fence_fd = out_fence_fd; +fd_install (out_fence_fd, sync_file->file); }if (in_fence) {
@@ -199,22 +220,28 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, }virtio_gpu_cmd_submit (vgdev, buf, exbuf->size, - vfpriv->ctx_id, fence); + vfpriv->ctx_id, out_fence); -ttm_eu_fence_buffer_objects (&ticket, &validate_list, &fence->f); +ttm_eu_fence_buffer_objects (&ticket, &validate_list, &out_fence->f);/* fence the command bo */ virtio_gpu_unref_list (&validate_list);kvfree (buflist);return 0 ; +out_memdup: +kfree (buf); out_unresv:ttm_eu_backoff_reservation (&ticket, &validate_list); out_free:virtio_gpu_unref_list (&validate_list); -out_in_fence: +out_unused_fd:kvfree (bo_handles);kvfree (buflist); + +if (out_fence_fd >=0 ) +put_unused_fd (out_fence_fd); +out_in_fence:dma_fence_put (in_fence);return ret; }
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 5/5 drm/virtio: bump driver version after explicit synchronization addition
In reply to Gustavo PadovanFrom: Gustavo Padovan <[email protected]>
To reflect the (backward compatible) changes in the uabi we are bumping the driver's version.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -2
@@ -46,8 +46,8 @@#define DRIVER_DATE "0"#define DRIVER_MAJOR 0 -#define DRIVER_MINOR 0 -#define DRIVER_PATCHLEVEL 1 +#define DRIVER_MINOR 1 +#define DRIVER_PATCHLEVEL 0/* virtgpu_drm_bus.c */ int drm_virtio_init (struct drm_driver *driver,struct virtio_device *vdev);
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 29 lines · Gustavo Padovan
From: Gustavo Padovan <[email protected]>
Hi,
So I finally got around to finish this work! :)
Here are the updated patchset with fixes for Rob Herring incorporated. This follow pretty much the same semantics of other drivers that implemented explicit fence support. It extends the execbuf ioctl to have anfence_fdargument that when entering the kernel carries the in-fence and when returning carries back the out-fence.The mesa patch can be found at
https://gitlab.collabora.com/padovan/mesa
Please review!
Regards,
Gustavo
Gustavo Padovan (5):
drm/virtio: addvirtio_gpu_alloc_fence()
drm/virtio: add uapi for in and out explicit fences drm/virtio: add in-fences support for explicit synchronization drm/virtio: add out-fences support for explicit synchronization drm/virtio: bump driver version after explicit synchronization
addition
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_drv.h | 21 +++--- drivers/gpu/drm/virtio/virtgpu_fence.c | 41 ++++++++---- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 115 +++++++++++++++++++++++++++------ drivers/gpu/drm/virtio/virtgpu_plane.c | 46 +++++++++++-- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++--- include/uapi/drm/virtgpu_drm.h | 13 +++- 6 files changed, 197 insertions(+), 55 deletions(-)
I tested this on Android. Without the 16ms sleep in the vsync callback to fake the timing, I get some errors about invalid fences after the splash screen and when the UI comes up.
BTW, I'm testing on a version of drm_hwcomposer with sw_sync and GL compositing removed.
At least with that one line hack/fix:
Rob
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel