Skip to content

Commit 70d1ace

Browse files
gurchetansinghdigetx
authored andcommitted
drm/virtio: Conditionally allocate virtio_gpu_fence
We don't want to create a fence for every command submission. It's only necessary when userspace provides a waitable token for submission. This could be: 1) bo_handles, to be used with VIRTGPU_WAIT 2) out_fence_fd, to be used with dma_fence apis 3) a ring_idx provided with VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK + DRM event API 4) syncobjs in the future The use case for just submitting a command to the host, and expecting no response. For example, gfxstream has GFXSTREAM_CONTEXT_PING that just wakes up the host side worker threads. There's also CROSS_DOMAIN_CMD_SEND which just sends data to the Wayland server. This prevents the need to signal the automatically created virtio_gpu_fence. In addition, VIRTGPU_EXECBUF_RING_IDX is checked when creating a DRM event object. VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK is already defined in terms of per-context rings. It was theoretically possible to create a DRM event on the global timeline (ring_idx == 0), if the context enabled DRM event polling. However, that wouldn't work and userspace (Sommelier). Explicitly disallow it for clarity. Signed-off-by: Gurchetan Singh <[email protected]> Reviewed-by: Dmitry Osipenko <[email protected]> Tested-by: Dmitry Osipenko <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> # edited coding style Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 8d1077c commit 70d1ace

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

drivers/gpu/drm/virtio/virtgpu_submit.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,9 @@ static int virtio_gpu_fence_event_create(struct drm_device *dev,
6464
struct virtio_gpu_fence *fence,
6565
u32 ring_idx)
6666
{
67-
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
6867
struct virtio_gpu_fence_event *e = NULL;
6968
int ret;
7069

71-
if (!(vfpriv->ring_idx_mask & BIT_ULL(ring_idx)))
72-
return 0;
73-
7470
e = kzalloc(sizeof(*e), GFP_KERNEL);
7571
if (!e)
7672
return -ENOMEM;
@@ -164,18 +160,30 @@ static int virtio_gpu_init_submit(struct virtio_gpu_submit *submit,
164160
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
165161
struct virtio_gpu_device *vgdev = dev->dev_private;
166162
struct virtio_gpu_fence *out_fence;
163+
bool drm_fence_event;
167164
int err;
168165

169166
memset(submit, 0, sizeof(*submit));
170167

171-
out_fence = virtio_gpu_fence_alloc(vgdev, fence_ctx, ring_idx);
172-
if (!out_fence)
173-
return -ENOMEM;
174-
175-
err = virtio_gpu_fence_event_create(dev, file, out_fence, ring_idx);
176-
if (err) {
177-
dma_fence_put(&out_fence->f);
178-
return err;
168+
if ((exbuf->flags & VIRTGPU_EXECBUF_RING_IDX) &&
169+
(vfpriv->ring_idx_mask & BIT_ULL(ring_idx)))
170+
drm_fence_event = true;
171+
else
172+
drm_fence_event = false;
173+
174+
if ((exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) ||
175+
exbuf->num_bo_handles ||
176+
drm_fence_event)
177+
out_fence = virtio_gpu_fence_alloc(vgdev, fence_ctx, ring_idx);
178+
else
179+
out_fence = NULL;
180+
181+
if (drm_fence_event) {
182+
err = virtio_gpu_fence_event_create(dev, file, out_fence, ring_idx);
183+
if (err) {
184+
dma_fence_put(&out_fence->f);
185+
return err;
186+
}
179187
}
180188

181189
submit->out_fence = out_fence;

0 commit comments

Comments
 (0)