From 394d8e4122e1682db40e75bf33943d90a53cfe33 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 17 Nov 2022 14:36:45 -0800 Subject: [PATCH] freedreno/drm/virtio: Defer flush on BO free Freeing BOs tends to be bursty (ie. when a submit is retired, or expiring entries from BO cache). Sending lots of small SET_IOVA messages to the host can quickly eat up the available virtqueue slots, resulting in (eventually) starving the guest waiting for free virtqueue space. By batching, we can avoid this and handle things more efficiently on the host (ie. in a single wakeup rather than many). Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_bo_cache.c | 5 ++++- src/freedreno/drm/virtio/virtio_bo.c | 6 ------ src/freedreno/drm/virtio/virtio_device.c | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/freedreno/drm/freedreno_bo_cache.c b/src/freedreno/drm/freedreno_bo_cache.c index 97f95618eec..b8107c31b12 100644 --- a/src/freedreno/drm/freedreno_bo_cache.c +++ b/src/freedreno/drm/freedreno_bo_cache.c @@ -107,7 +107,10 @@ fd_bo_cache_cleanup(struct fd_bo_cache *cache, time_t time) } } - if (dev) + /* Note: when called in bo_del_or_recycle() -> fd_bo_cache_free() path, + * the caller will handle bo_del_flush(). + */ + if (time && dev) bo_del_flush(dev); cache->time = time; diff --git a/src/freedreno/drm/virtio/virtio_bo.c b/src/freedreno/drm/virtio/virtio_bo.c index 52a1f016ff3..f54b8215a4d 100644 --- a/src/freedreno/drm/virtio/virtio_bo.c +++ b/src/freedreno/drm/virtio/virtio_bo.c @@ -280,12 +280,6 @@ virtio_bo_destroy(struct fd_bo *bo) set_iova(bo, 0); virtio_dev_free_iova(bo->dev, bo->iova, bo->size); - - /* Need to flush batched ccmds to ensure the host sees the iova - * release before the GEM handle is closed (ie. detach_resource() - * on the host side) - */ - virtio_execbuf_flush(bo->dev); } free(virtio_bo); diff --git a/src/freedreno/drm/virtio/virtio_device.c b/src/freedreno/drm/virtio/virtio_device.c index 333565016dd..8d2d4be5f0d 100644 --- a/src/freedreno/drm/virtio/virtio_device.c +++ b/src/freedreno/drm/virtio/virtio_device.c @@ -43,6 +43,7 @@ static const struct fd_device_funcs funcs = { .bo_new = virtio_bo_new, .bo_from_handle = virtio_bo_from_handle, .pipe_new = virtio_pipe_new, + .flush = virtio_execbuf_flush, .destroy = virtio_device_destroy, };