Support passing VirtIO-GPU fences to host for waiting
Subsystems (4)
Dmitry Osipenko
maintainercover Support passing VirtIO-GPU fences to host for waiting
Today's VirtIO-GPU driver always has to wait for in-fences on the guest side, creating bottleneck for workloads that produce lots of job submissions or require lower submission latency. This bottleneck is caused by a need to do extra round trips between host and guest for the fence signalling.
The solution is to move fence signalling and waiting entierly to the host side, where it can be done more efficiently, without holding the guest side. The proposed patch introduces new "fence passing" VirtIO-GPU protocol feature, which extends VIRTIO_GPU_CMD_SUBMIT_3D with array of in-fence IDs that are passed from guest to host along with the 3D commands. Host then takes the in-fence IDs and passes them to virglrender, where the fence IDs are resolved into sync file fences and handled (waited) by a corresponding virglrender context.
The patch is RFC because we want to do more testing with crosvm and CrOS first, support fence-passing for Venus and virtio-wl. The new virglrender experimental fence-passing API already has been merged [1] and crosvm support began to pick it up [2]. Qemu patch is available at [3].
Fence passing was tested using WIP amdgpu and intel native contexts, where it proved to be useful by increasing FPS up to 3x times.
[1] https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1138
[2] https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4679609
[3] https://gitlab.freedesktop.org/digetx/qemu/-/commits/native-context-iris
Dmitry Osipenko (1):
drm/virtio: Support fence-passing feature
drivers/gpu/drm/virtio/virtgpu_drv.c | 1 + drivers/gpu/drm/virtio/virtgpu_drv.h | 11 ++- drivers/gpu/drm/virtio/virtgpu_fence.c | 15 +++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 11 ++- drivers/gpu/drm/virtio/virtgpu_kms.c | 8 +- drivers/gpu/drm/virtio/virtgpu_submit.c | 99 ++++++++++++++++++++++++- drivers/gpu/drm/virtio/virtgpu_vq.c | 7 +- include/uapi/drm/virtgpu_drm.h | 3 + include/uapi/linux/virtio_gpu.h | 11 ++- 9 files changed, 152 insertions(+), 14 deletions(-)
Signature · 1 line
2.41.0
Dmitry Osipenko
maintainerRFC PATCH 1/1 drm/virtio: Support fence-passing feature
Support extended version of VIRTIO_GPU_CMD_SUBMIT_3D command that allows passing in-fence IDs to host for waiting, removing need to do expensive host-guest roundtrips in a case of waiting for fences on a guest side.
Guest userspace must enable new VIRTGPU_CONTEXT_PARAM_FENCE_PASSING flag and host must support new VIRTIO_GPU_F_FENCE_PASSING feature in order to activate the fence passing for a given virtio-gpu context. Array of in-fence IDs is then prepended to the VIRTIO_GPU_CMD_SUBMIT_3D's data, the previously unused padding field of the command is reused for the number of in-fences.
A new VIRTGPU_EXECBUF_SHARED_FENCE flag is added to the job submission UAPI and must be set by userspace if it wants to make fence shareable with/on host. Certain jobs won't want to share fence, in particular Venus will benefit from this flag.
--- drivers/gpu/drm/virtio/virtgpu_drv.c | 1 + drivers/gpu/drm/virtio/virtgpu_drv.h | 11 ++- drivers/gpu/drm/virtio/virtgpu_fence.c | 15 +++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 11 ++- drivers/gpu/drm/virtio/virtgpu_kms.c | 8 +- drivers/gpu/drm/virtio/virtgpu_submit.c | 99 ++++++++++++++++++++++++- drivers/gpu/drm/virtio/virtgpu_vq.c | 7 +- include/uapi/drm/virtgpu_drm.h | 3 + include/uapi/linux/virtio_gpu.h | 11 ++- 9 files changed, 152 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +1 -0
@@ -148,6 +148,7 @@ static unsigned int features[] = {VIRTIO_GPU_F_RESOURCE_UUID ,VIRTIO_GPU_F_RESOURCE_BLOB ,VIRTIO_GPU_F_CONTEXT_INIT , + VIRTIO_GPU_F_FENCE_PASSING, };static struct virtio_driver virtio_gpu_driver = { .feature_table = features,
drivers/gpu/drm/virtio/virtgpu_drv.h +10 -1
@@ -149,6 +149,7 @@ struct virtio_gpu_fence {struct virtio_gpu_fence_event *e;struct virtio_gpu_fence_driver *drv;struct list_head node; +bool host_shareable; };struct virtio_gpu_vbuffer {
@@ -246,6 +247,7 @@ struct virtio_gpu_device {bool has_resource_blob;bool has_host_visible;bool has_context_init; +bool has_fence_passing;struct virtio_shm_region host_visible_region;struct drm_mm host_visible_mm;
@@ -273,6 +275,7 @@ struct virtio_gpu_fpriv {uint32_t num_rings;uint64_t base_fence_ctx;uint64_t ring_idx_mask; +bool fence_passing_enabled;struct mutex context_lock; };
@@ -367,7 +370,9 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, void *data, uint32_t data_size, uint32_t ctx_id, struct virtio_gpu_object_array *objs, - struct virtio_gpu_fence *fence); + struct virtio_gpu_fence *fence, + uint32_t cmd_size, + unsigned int num_in_fences); void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t ctx_id, uint64_t offset, uint32_t level,
@@ -420,6 +425,9 @@ virtio_gpu_cmd_set_scanout_blob(struct virtio_gpu_device *vgdev, uint32_t width, uint32_t height, uint32_t x, uint32_t y); +void virtio_gpu_cmd_in_fence (struct virtio_gpu_device *vgdev, +uint32_t ctx_id,uint64_t fence_id); +/* virtgpu_display.c */ int virtio_gpu_modeset_init (struct virtio_gpu_device *vgdev);void virtio_gpu_modeset_fini (struct virtio_gpu_device *vgdev);
@@ -439,6 +447,7 @@ void virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev, struct virtio_gpu_fence *fence);void virtio_gpu_fence_event_process (struct virtio_gpu_device *vdev,u64 fence_id); +struct virtio_gpu_fence *to_virtio_gpu_fence (struct dma_fence *dma_fence);/* virtgpu_object.c */ void virtio_gpu_cleanup_object (struct virtio_gpu_object *bo);
drivers/gpu/drm/virtio/virtgpu_fence.c +12 -3
@@ -27,9 +27,6 @@#include "virtgpu_drv.h" -#define to_virtio_gpu_fence (x) \ - container_of(x, struct virtio_gpu_fence, f) -static const char *virtio_gpu_get_driver_name (struct dma_fence *f) {return "virtio_gpu" ;
@@ -71,6 +68,14 @@ static const struct dma_fence_ops virtio_gpu_fence_ops = { .timeline_value_str = virtio_gpu_timeline_value_str, }; +struct virtio_gpu_fence *to_virtio_gpu_fence (struct dma_fence *dma_fence) +{ +if (dma_fence->ops != &virtio_gpu_fence_ops) +return NULL ; + + return container_of(dma_fence, struct virtio_gpu_fence, f); +} +struct virtio_gpu_fence *virtio_gpu_fence_alloc (struct virtio_gpu_device *vgdev,uint64_t base_fence_ctx,uint32_t ring_idx)
@@ -122,6 +127,10 @@ void virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,cpu_to_le32 (VIRTIO_GPU_FLAG_INFO_RING_IDX ); cmd_hdr->ring_idx = (u8 )fence->ring_idx; } + +if (fence->host_shareable) + cmd_hdr->flags |= +cpu_to_le32 (VIRTIO_GPU_FLAG_FENCE_SHAREABLE ); } void virtio_gpu_fence_event_process(struct virtio_gpu_device *vgdev,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +10 -1
@@ -514,7 +514,8 @@ static int virtio_gpu_resource_create_blob_ioctl(struct drm_device *dev,return PTR_ERR (buf);virtio_gpu_cmd_submit (vgdev, buf, rc_blob->cmd_size, - vfpriv->ctx_id,NULL ,NULL ); + vfpriv->ctx_id,NULL ,NULL , + rc_blob->cmd_size,0 ); }if (guest_blob)
@@ -642,6 +643,14 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev, vfpriv->ring_idx_mask = value;break ; +case VIRTGPU_CONTEXT_PARAM_FENCE_PASSING : +if (!vgdev->has_fence_passing && value) { + ret = -EINVAL ; + goto out_unlock; + } + + vfpriv->fence_passing_enabled = !!value; +break ;default : ret = -EINVAL ; goto out_unlock;
drivers/gpu/drm/virtio/virtgpu_kms.c +6 -2
@@ -197,12 +197,16 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev)if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_CONTEXT_INIT )) { vgdev->has_context_init = true; } +if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_FENCE_PASSING )) { + vgdev->has_fence_passing = true; + } -DRM_INFO ("features: %cvirgl %cedid %cresource_blob %chost_visible" , +DRM_INFO ("features: %cvirgl %cedid %cresource_blob %chost_visible %cfence_passing" , vgdev->has_virgl_3d ?'+' :'-' , vgdev->has_edid ?'+' :'-' , vgdev->has_resource_blob ?'+' :'-' , - vgdev->has_host_visible ?'+' :'-' ); + vgdev->has_host_visible ?'+' :'-' , + vgdev->has_fence_passing ?'+' :'-' );DRM_INFO ("features: %ccontext_init\n" , vgdev->has_context_init ?'+' :'-' );
drivers/gpu/drm/virtio/virtgpu_submit.c +95 -4
155 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +5 -2
@@ -1079,7 +1079,9 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, void *data, uint32_t data_size, uint32_t ctx_id, struct virtio_gpu_object_array *objs, - struct virtio_gpu_fence *fence) + struct virtio_gpu_fence *fence, + uint32_t cmd_size, + unsigned int num_in_fences) { struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -1093,7 +1095,8 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_SUBMIT_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->size =cpu_to_le32 (data_size); + cmd_p->size =cpu_to_le32 (cmd_size); + cmd_p->num_in_fences =cpu_to_le32 (num_in_fences);virtio_gpu_queue_fenced_ctrl_buffer (vgdev, vbuf, fence); }
include/uapi/drm/virtgpu_drm.h +3 -0
@@ -52,10 +52,12 @@ extern "C" {#define VIRTGPU_EXECBUF_FENCE_FD_IN 0x01#define VIRTGPU_EXECBUF_FENCE_FD_OUT 0x02#define VIRTGPU_EXECBUF_RING_IDX 0x04 +#define VIRTGPU_EXECBUF_SHARED_FENCE 0x08#define VIRTGPU_EXECBUF_FLAGS (\ VIRTGPU_EXECBUF_FENCE_FD_IN |\ VIRTGPU_EXECBUF_FENCE_FD_OUT |\ VIRTGPU_EXECBUF_RING_IDX |\ + VIRTGPU_EXECBUF_SHARED_FENCE |\ 0)struct drm_virtgpu_map {
@@ -198,6 +200,7 @@ struct drm_virtgpu_resource_create_blob {#define VIRTGPU_CONTEXT_PARAM_CAPSET_ID 0x0001#define VIRTGPU_CONTEXT_PARAM_NUM_RINGS 0x0002#define VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK 0x0003 +#define VIRTGPU_CONTEXT_PARAM_FENCE_PASSING 0x0004struct drm_virtgpu_context_set_param {__u64 param;__u64 value;
include/uapi/linux/virtio_gpu.h +10 -1
@@ -65,6 +65,11 @@*/ #define VIRTIO_GPU_F_CONTEXT_INIT 4 +/* +* VIRTIO_GPU_CMD_SUBMIT_3D +*/ +#define VIRTIO_GPU_F_FENCE_PASSING 5 +enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
@@ -133,6 +138,10 @@ enum virtio_gpu_shm_id {* of the command ring that needs to used when creating the fence */ #define VIRTIO_GPU_FLAG_INFO_RING_IDX (1 << 1) +/* +* The fence is shareable between host contexts if flag is set. +*/ +#define VIRTIO_GPU_FLAG_FENCE_SHAREABLE (1 << 2)struct virtio_gpu_ctrl_hdr {__le32 type;
@@ -304,7 +313,7 @@ struct virtio_gpu_ctx_resource {struct virtio_gpu_cmd_submit {struct virtio_gpu_ctrl_hdr hdr;__le32 size; -__le32 padding; +__le32 num_in_fences; };#define VIRTIO_GPU_CAPSET_VIRGL 1
Signature · 1 line
2.41.0
kernel test robot
build botRe: [RFC PATCH v1 1/1] drm/virtio: Support fence-passing feature
kernel test robot noticed the following build warnings:
Hi Dmitry,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.6-rc5 next-20231010] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dmitry-Osipenko/drm-virtio-Support-fence-passing-feature/20231008-035132 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20231007194747.788934-2-dmitry.osipenko%40collabora.com patch subject: [RFC PATCH v1 1/1] drm/virtio: Support fence-passing feature config: i386-randconfig-062-20231011 (https://download.01.org/0day-ci/archive/20231011/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/virtio/virtgpu_submit.c:414:30: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] @@ got restricted __le64 [usertype] @@
drivers/gpu/drm/virtio/virtgpu_submit.c:414:30: sparse: expected unsigned long long [usertype]
drivers/gpu/drm/virtio/virtgpu_submit.c:414:30: sparse: got restricted __le64 [usertype]
vim +414 drivers/gpu/drm/virtio/virtgpu_submit.c
394
395 static int virtio_gpu_attach_in_fences(struct virtio_gpu_submit *submit)
396 {
397 size_t in_fences_size = sizeof(u64) * submit->num_in_fences;
398 size_t new_data_size = submit->data_size + in_fences_size;
399 void *buf = submit->buf;
400 u64 *in_fences;
401 unsigned int i;
402
403 if (new_data_size < submit->data_size)
404 return -EINVAL;
405
406 buf = kvrealloc(buf, submit->data_size, new_data_size, GFP_KERNEL);
407 if (!buf)
408 return -ENOMEM;
409
410 memmove(buf + in_fences_size, buf, submit->data_size);
411 in_fences = buf;
412
413 for (i = 0; i < submit->num_in_fences; i++)
> 414 in_fences[i] = cpu_to_le64(submit->in_fences[i].id);
415
416 submit->data_size = new_data_size;
417 submit->buf = buf;
418
419 return 0;
420 }
421
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki