Skip to contentSkip to conversation

virtio-gpu: fixes and spice preparation

PATCH Superseded Gerd Hoffmann 2 participants 13 messages Jan 13, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover virtio-gpu: fixes and spice preparation

Hi,

This patch series brings some minor opengl bug fixes and also some virtio-gpu preparations for spice support.

please review,
Gerd

Gerd Hoffmann (6):
zap qemu_egl_has_ext in include/ui/egl-helpers.h
console: block rendering until client is done
virtio-gpu: fix memory leak in error path
virtio-gpu: maintain command queue
virtio-gpu: add support to enable/disable command processing
virtio-gpu: block any rendering until client (ui) is done

 hw/display/virtio-gpu-3d.c     | 11 +++++--
 hw/display/virtio-gpu.c        | 71 +++++++++++++++++++++++++++++-------------
 hw/display/virtio-vga.c        | 10 ++++++
 include/hw/virtio/virtio-gpu.h |  4 +++
 include/ui/console.h           |  2 ++
 include/ui/egl-helpers.h       |  1 -
 ui/console.c                   | 10 ++++++
 7 files changed, 84 insertions(+), 25 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/6 zap qemu_egl_has_ext in include/ui/egl-helpers.h

Drop leftover prototype which sneaked in by mistake

---
 include/ui/egl-helpers.h | 1 -
 1 file changed, 1 deletion(-)
include/ui/egl-helpers.h +0 -1
index 5ad5dc3..8c84398 100644
@@ -11,6 +11,5 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);
 
 int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug);
 EGLContext qemu_egl_init_ctx(void);
-bool qemu_egl_has_ext(const char *haystack, const char *needle);
 
 #endif /* EGL_HELPERS_H */
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] zap qemu_egl_has_ext in include/ui/egl-helpers.h

Quoted 21 lines · Gerd Hoffmann

Drop leftover prototype which sneaked in by mistake

---
 include/ui/egl-helpers.h | 1 -
 1 file changed, 1 deletion(-)
include/ui/egl-helpers.h +0 -2
index 5ad5dc3..8c84398 100644
@@ -11,6 +11,5 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);
 
 int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug);
 EGLContext qemu_egl_init_ctx(void);
-bool qemu_egl_has_ext(const char *haystack, const char *needle);
 
 #endif /* EGL_HELPERS_H */
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#3 lore raw

PATCH 2/6 console: block rendering until client is done

In reply to Gerd Hoffmann

Allow gl user interfaces to block display device gl rendering. The ui code might want to do that in case it takes a little longer to bring things to screen, for example because we'll hand over a dma-buf to another process (spice will do that).

---
 include/ui/console.h |  2 ++
 ui/console.c         | 10 ++++++++++
 2 files changed, 12 insertions(+)
include/ui/console.h +2 -0
index adac36d..12ad627 100644
@@ -362,6 +362,7 @@ typedef struct GraphicHwOps {
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
     int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
+    void (*gl_block)(void *opaque, bool block);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
@@ -374,6 +375,7 @@ void graphic_console_set_hwops(QemuConsole *con,
 void graphic_hw_update(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
+void graphic_hw_gl_block(QemuConsole *con, bool block);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
ui/console.c +10 -0
index 4b65c34..f0a4bd8 100644
@@ -261,6 +261,16 @@ void graphic_hw_update(QemuConsole *con)
     }
 }
 
+void graphic_hw_gl_block(QemuConsole *con, bool block)
+{
+    if (!con) {
+        con = active_console;
+    }
+    if (con && con->hw_ops->gl_block) {
+        con->hw_ops->gl_block(con->hw, block);
+    }
+}
+
 void graphic_hw_invalidate(QemuConsole *con)
 {
     if (!con) {
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/6
#4 lore raw

Re: [Qemu-devel] [PATCH 2/6] console: block rendering until client is done

Hi

Quoted 6 lines · Gerd Hoffmann

Allow gl user interfaces to block display device gl rendering. The ui code might want to do that in case it takes a little longer to bring things to screen, for example because we'll hand over a dma-buf to another process (spice will do that).

Quoted 49 lines
---
 include/ui/console.h |  2 ++
 ui/console.c         | 10 ++++++++++
 2 files changed, 12 insertions(+)
include/ui/console.h +2 -0
index adac36d..12ad627 100644
@@ -362,6 +362,7 @@ typedef struct GraphicHwOps {
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
     int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
+    void (*gl_block)(void *opaque, bool block);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
@@ -374,6 +375,7 @@ void graphic_console_set_hwops(QemuConsole *con,
 void graphic_hw_update(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
+void graphic_hw_gl_block(QemuConsole *con, bool block);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
ui/console.c +10 -1
index 4b65c34..f0a4bd8 100644
@@ -261,6 +261,16 @@ void graphic_hw_update(QemuConsole *con)
     }
 }
 
+void graphic_hw_gl_block(QemuConsole *con, bool block)
+{
+    if (!con) {
+        con = active_console;
+    }
+    if (con && con->hw_ops->gl_block) {
+        con->hw_ops->gl_block(con->hw, block);
+    }
+}
+
 void graphic_hw_invalidate(QemuConsole *con)
 {
     if (!con) {
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#5 lore raw

PATCH 3/6 virtio-gpu: fix memory leak in error path

In reply to Gerd Hoffmann

Found by Coverity Scan, buf not freed on error.

---
 hw/display/virtio-gpu-3d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-3d.c +2 -1
index 28dccfd..d2af327 100644
@@ -197,7 +197,7 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
         qemu_log_mask(LOG_GUEST_ERROR, "%s: size mismatch (%zd/%d)",
                       __func__, s, cs.size);
         cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
-        return;
+        goto out;
     }
 
     if (virtio_gpu_stats_enabled(g->conf)) {
@@ -207,6 +207,7 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
 
     virgl_renderer_submit_cmd(buf, cs.hdr.ctx_id, cs.size / 4);
 
+out:
     g_free(buf);
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 3/6
#6 lore raw

Re: [Qemu-devel] [PATCH 3/6] virtio-gpu: fix memory leak in error path

Hi

Quoted 4 lines · Gerd Hoffmann

Found by Coverity Scan, buf not freed on error.

---

Quoted 27 lines
 hw/display/virtio-gpu-3d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-3d.c +2 -2
index 28dccfd..d2af327 100644
@@ -197,7 +197,7 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
         qemu_log_mask(LOG_GUEST_ERROR, "%s: size mismatch (%zd/%d)",
                       __func__, s, cs.size);
         cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
-        return;
+        goto out;
     }
 
     if (virtio_gpu_stats_enabled(g->conf)) {
@@ -207,6 +207,7 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
 
     virgl_renderer_submit_cmd(buf, cs.hdr.ctx_id, cs.size / 4);
 
+out:
     g_free(buf);
 }
 
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#7 lore raw

PATCH 4/6 virtio-gpu: maintain command queue

In reply to Gerd Hoffmann

We'll go take out the commands we receive out of the virt queue and put them into a linked list, to decouple virtio queue handling from actual command processing.

Also move cmd processing to new virtio_gpu_handle_ctrl func, so we can easily kick it from different places.

---
 hw/display/virtio-gpu.c        | 60 ++++++++++++++++++++++++++----------------
 include/hw/virtio/virtio-gpu.h |  1 +
 2 files changed, 39 insertions(+), 22 deletions(-)
hw/display/virtio-gpu.c +38 -22
index 7e79a9c..4433c12 100644
@@ -754,33 +754,21 @@ static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq)
     qemu_bh_schedule(g->cursor_bh);
 }
 
-static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+static void virtio_cpu_process_cmdq(VirtIOGPU *g)
 {
-    VirtIOGPU *g = VIRTIO_GPU(vdev);
     struct virtio_gpu_ctrl_command *cmd;
 
-    if (!virtio_queue_ready(vq)) {
-        return;
-    }
-
-#ifdef CONFIG_VIRGL
-    if (!g->renderer_inited && g->use_virgl_renderer) {
-        virtio_gpu_virgl_init(g);
-        g->renderer_inited = true;
-    }
-#endif
-
-    cmd = g_new(struct virtio_gpu_ctrl_command, 1);
-    while (virtqueue_pop(vq, &cmd->elem)) {
-        cmd->vq = vq;
-        cmd->error = 0;
-        cmd->finished = false;
-        if (virtio_gpu_stats_enabled(g->conf)) {
-            g->stats.requests++;
-        }
+    while (!QTAILQ_EMPTY(&g->cmdq)) {
+        cmd = QTAILQ_FIRST(&g->cmdq);
 
+        /* process command */
         VIRGL(g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd,
               g, cmd);
+        QTAILQ_REMOVE(&g->cmdq, cmd, next);
+        if (virtio_gpu_stats_enabled(g->conf)) {
+            g->stats.requests++;
+        }
+
         if (!cmd->finished) {
             QTAILQ_INSERT_TAIL(&g->fenceq, cmd, next);
             g->inflight++;
@@ -790,11 +778,38 @@ static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
                 }
                 fprintf(stderr, "inflight: %3d (+)\r", g->inflight);
             }
-            cmd = g_new(struct virtio_gpu_ctrl_command, 1);
         }
     }
+}
+
+static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    struct virtio_gpu_ctrl_command *cmd;
+
+    if (!virtio_queue_ready(vq)) {
+        return;
+    }
+
+#ifdef CONFIG_VIRGL
+    if (!g->renderer_inited && g->use_virgl_renderer) {
+        virtio_gpu_virgl_init(g);
+        g->renderer_inited = true;
+    }
+#endif
+
+    cmd = g_new0(struct virtio_gpu_ctrl_command, 1);
+    while (virtqueue_pop(vq, &cmd->elem)) {
+        cmd->vq = vq;
+        cmd->error = 0;
+        cmd->finished = false;
+        QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
+        cmd = g_new0(struct virtio_gpu_ctrl_command, 1);
+    }
     g_free(cmd);
 
+    virtio_cpu_process_cmdq(g);
+
 #ifdef CONFIG_VIRGL
     if (g->use_virgl_renderer) {
         virtio_gpu_virgl_fence_poll(g);
@@ -920,6 +935,7 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
     g->ctrl_bh = qemu_bh_new(virtio_gpu_ctrl_bh, g);
     g->cursor_bh = qemu_bh_new(virtio_gpu_cursor_bh, g);
     QTAILQ_INIT(&g->reslist);
+    QTAILQ_INIT(&g->cmdq);
     QTAILQ_INIT(&g->fenceq);
 
     g->enabled_output_bitmask = 1;
include/hw/virtio/virtio-gpu.h +1 -0
index 9b279d7..f7e7a52 100644
@@ -94,6 +94,7 @@ typedef struct VirtIOGPU {
     DeviceState *qdev;
 
     QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist;
+    QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq;
     QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
 
     struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUT];
Signature · 1 line
1.8.3.1
#8 lore raw

Re: [Qemu-devel] [PATCH 4/6] virtio-gpu: maintain command queue

Hi

Quoted 18 lines · Gerd Hoffmann

We'll go take out the commands we receive out of the virt queue and put them into a linked list, to decouple virtio queue handling from actual command processing.

Also move cmd processing to new virtio_gpu_handle_ctrl func, so we can easily kick it from different places.

---
 hw/display/virtio-gpu.c        | 60 ++++++++++++++++++++++++++----------------
 include/hw/virtio/virtio-gpu.h |  1 +
 2 files changed, 39 insertions(+), 22 deletions(-)
hw/display/virtio-gpu.c +0 -0
index 7e79a9c..4433c12 100644

hw/display/virtio-gpu.c static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq) · line 757

Quoted 5 lines
hw/display/virtio-gpu.c +1 -1
@@ -754,33 +754,21 @@ static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq)
     qemu_bh_schedule(g->cursor_bh);
 }
 
-static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+static void virtio_cpu_process_cmdq(VirtIOGPU *g)

cpu/gpu

Quoted 38 lines
hw/display/virtio-gpu.c +8 -20
 {
-    VirtIOGPU *g = VIRTIO_GPU(vdev);
     struct virtio_gpu_ctrl_command *cmd;
 
-    if (!virtio_queue_ready(vq)) {
-        return;
-    }
-
-#ifdef CONFIG_VIRGL
-    if (!g->renderer_inited && g->use_virgl_renderer) {
-        virtio_gpu_virgl_init(g);
-        g->renderer_inited = true;
-    }
-#endif
-
-    cmd = g_new(struct virtio_gpu_ctrl_command, 1);
-    while (virtqueue_pop(vq, &cmd->elem)) {
-        cmd->vq = vq;
-        cmd->error = 0;
-        cmd->finished = false;
-        if (virtio_gpu_stats_enabled(g->conf)) {
-            g->stats.requests++;
-        }
+    while (!QTAILQ_EMPTY(&g->cmdq)) {
+        cmd = QTAILQ_FIRST(&g->cmdq);
 
+        /* process command */
         VIRGL(g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd,
               g, cmd);
+        QTAILQ_REMOVE(&g->cmdq, cmd, next);
+        if (virtio_gpu_stats_enabled(g->conf)) {
+            g->stats.requests++;
+        }
+
         if (!cmd->finished) {
             QTAILQ_INSERT_TAIL(&g->fenceq, cmd, next);
             g->inflight++;

hw/display/virtio-gpu.c static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) · line 781

Quoted 5 lines
hw/display/virtio-gpu.c +0 -1
@@ -790,11 +778,38 @@ static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
                 }
                 fprintf(stderr, "inflight: %3d (+)\r", g->inflight);
             }
-            cmd = g_new(struct virtio_gpu_ctrl_command, 1);
         }

else g_free(cmd)

Quoted 10 lines
hw/display/virtio-gpu.c +9 -0
     }
+}
+
+static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOGPU *g = VIRTIO_GPU(vdev);
+    struct virtio_gpu_ctrl_command *cmd;
+
+    if (!virtio_queue_ready(vq)) {
+        return;

hw/display/virtio-gpu.c static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) · line 801

Quoted 10 lines
hw/display/virtio-gpu.c +10 -0
+    }
+
+#ifdef CONFIG_VIRGL
+    if (!g->renderer_inited && g->use_virgl_renderer) {
+        virtio_gpu_virgl_init(g);
+        g->renderer_inited = true;
+    }
+#endif
+
+    cmd = g_new0(struct virtio_gpu_ctrl_command, 1);

g_new0 is costly (the struct is big) and quite unnecessary here:

hw/display/virtio-gpu.c static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) · line 805

Quoted 4 lines
hw/display/virtio-gpu.c +4 -0
+    while (virtqueue_pop(vq, &cmd->elem)) {
+        cmd->vq = vq;
+        cmd->error = 0;
+        cmd->finished = false;

Add:
+ cmd->waiting = false;

and you can switch to g_new.

hw/display/virtio-gpu.c static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) · line 807

Quoted 2 lines
hw/display/virtio-gpu.c +2 -0
+        QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
+        cmd = g_new0(struct virtio_gpu_ctrl_command, 1);

same

Quoted 31 lines
hw/display/virtio-gpu.c +4 -0
+    }
     g_free(cmd);
 
+    virtio_cpu_process_cmdq(g);
+
 #ifdef CONFIG_VIRGL
     if (g->use_virgl_renderer) {
         virtio_gpu_virgl_fence_poll(g);
@@ -920,6 +935,7 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
     g->ctrl_bh = qemu_bh_new(virtio_gpu_ctrl_bh, g);
     g->cursor_bh = qemu_bh_new(virtio_gpu_cursor_bh, g);
     QTAILQ_INIT(&g->reslist);
+    QTAILQ_INIT(&g->cmdq);
     QTAILQ_INIT(&g->fenceq);
 
     g->enabled_output_bitmask = 1;
include/hw/virtio/virtio-gpu.h +1 -1
index 9b279d7..f7e7a52 100644
@@ -94,6 +94,7 @@ typedef struct VirtIOGPU {
     DeviceState *qdev;
 
     QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist;
+    QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq;
     QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
 
     struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUT];
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#9 lore raw

PATCH 5/6 virtio-gpu: add support to enable/disable command processing

In reply to Gerd Hoffmann

So we can stop rendering for a while in case we have to.

---
 hw/display/virtio-gpu-3d.c     | 3 ++-
 hw/display/virtio-gpu.c        | 5 ++++-
 include/hw/virtio/virtio-gpu.h | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +2 -1
index d2af327..65926b1 100644
@@ -553,7 +553,8 @@ static void virtio_gpu_fence_poll(void *opaque)
     VirtIOGPU *g = opaque;
 
     virgl_renderer_poll();
-    if (g->inflight) {
+    virtio_cpu_process_cmdq(g);
+    if (!QTAILQ_EMPTY(&g->cmdq) || !QTAILQ_EMPTY(&g->fenceq)) {
         timer_mod(g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 10);
     }
 }
hw/display/virtio-gpu.c +4 -1
index 4433c12..9087e63 100644
@@ -754,7 +754,7 @@ static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq)
     qemu_bh_schedule(g->cursor_bh);
 }
 
-static void virtio_cpu_process_cmdq(VirtIOGPU *g)
+void virtio_cpu_process_cmdq(VirtIOGPU *g)
 {
     struct virtio_gpu_ctrl_command *cmd;
 
@@ -764,6 +764,9 @@ static void virtio_cpu_process_cmdq(VirtIOGPU *g)
         /* process command */
         VIRGL(g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd,
               g, cmd);
+        if (cmd->waiting) {
+            break;
+        }
         QTAILQ_REMOVE(&g->cmdq, cmd, next);
         if (virtio_gpu_stats_enabled(g->conf)) {
             g->stats.requests++;
include/hw/virtio/virtio-gpu.h +2 -0
index f7e7a52..fdf0091 100644
@@ -76,6 +76,7 @@ struct virtio_gpu_ctrl_command {
     VirtQueue *vq;
     struct virtio_gpu_ctrl_hdr cmd_hdr;
     uint32_t error;
+    bool waiting;
     bool finished;
     QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
 };
@@ -152,6 +153,7 @@ int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
                                   struct virtio_gpu_ctrl_command *cmd,
                                   struct iovec **iov);
 void virtio_gpu_cleanup_mapping_iov(struct iovec *iov, uint32_t count);
+void virtio_cpu_process_cmdq(VirtIOGPU *g);
 
 /* virtio-gpu-3d.c */
 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
Signature · 1 line
1.8.3.1
Reviewed-by on v1 5/6
#10 lore raw

Re: [Qemu-devel] [PATCH 5/6] virtio-gpu: add support to enable/disable command processing

Hi

Quoted 3 lines · Gerd Hoffmann

So we can stop rendering for a while in case we have to.

Quoted 66 lines
---
 hw/display/virtio-gpu-3d.c     | 3 ++-
 hw/display/virtio-gpu.c        | 5 ++++-
 include/hw/virtio/virtio-gpu.h | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +2 -1
index d2af327..65926b1 100644
@@ -553,7 +553,8 @@ static void virtio_gpu_fence_poll(void *opaque)
     VirtIOGPU *g = opaque;
 
     virgl_renderer_poll();
-    if (g->inflight) {
+    virtio_cpu_process_cmdq(g);
+    if (!QTAILQ_EMPTY(&g->cmdq) || !QTAILQ_EMPTY(&g->fenceq)) {
         timer_mod(g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 10);
     }
 }
hw/display/virtio-gpu.c +4 -1
index 4433c12..9087e63 100644
@@ -754,7 +754,7 @@ static void virtio_gpu_handle_cursor_cb(VirtIODevice *vdev, VirtQueue *vq)
     qemu_bh_schedule(g->cursor_bh);
 }
 
-static void virtio_cpu_process_cmdq(VirtIOGPU *g)
+void virtio_cpu_process_cmdq(VirtIOGPU *g)
 {
     struct virtio_gpu_ctrl_command *cmd;
 
@@ -764,6 +764,9 @@ static void virtio_cpu_process_cmdq(VirtIOGPU *g)
         /* process command */
         VIRGL(g, virtio_gpu_virgl_process_cmd, virtio_gpu_simple_process_cmd,
               g, cmd);
+        if (cmd->waiting) {
+            break;
+        }
         QTAILQ_REMOVE(&g->cmdq, cmd, next);
         if (virtio_gpu_stats_enabled(g->conf)) {
             g->stats.requests++;
include/hw/virtio/virtio-gpu.h +2 -1
index f7e7a52..fdf0091 100644
@@ -76,6 +76,7 @@ struct virtio_gpu_ctrl_command {
     VirtQueue *vq;
     struct virtio_gpu_ctrl_hdr cmd_hdr;
     uint32_t error;
+    bool waiting;
     bool finished;
     QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
 };
@@ -152,6 +153,7 @@ int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
                                   struct virtio_gpu_ctrl_command *cmd,
                                   struct iovec **iov);
 void virtio_gpu_cleanup_mapping_iov(struct iovec *iov, uint32_t count);
+void virtio_cpu_process_cmdq(VirtIOGPU *g);
 
 /* virtio-gpu-3d.c */
 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#11 lore raw

PATCH 6/6 virtio-gpu: block any rendering until client (ui) is done

In reply to Gerd Hoffmann

Wire up gl_block callback, so ui code can request to stop virtio-gpu rendering.

---
 hw/display/virtio-gpu-3d.c     |  5 +++++
 hw/display/virtio-gpu.c        |  8 ++++++++
 hw/display/virtio-vga.c        | 10 ++++++++++
 include/hw/virtio/virtio-gpu.h |  1 +
 4 files changed, 24 insertions(+)
hw/display/virtio-gpu-3d.c +5 -0
index 65926b1..321a959 100644
@@ -382,6 +382,11 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
 {
     VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr);
 
+    cmd->waiting = g->renderer_blocked;
+    if (cmd->waiting) {
+        return;
+    }
+
     virgl_renderer_force_ctx_0();
     switch (cmd->cmd_hdr.type) {
     case VIRTIO_GPU_CMD_CTX_CREATE:
hw/display/virtio-gpu.c +8 -0
index 9087e63..09936c9 100644
@@ -893,11 +893,19 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
     return 0;
 }
 
+static void virtio_gpu_gl_block(void *opaque, bool block)
+{
+    VirtIOGPU *g = opaque;
+
+    g->renderer_blocked = block;
+}
+
 const GraphicHwOps virtio_gpu_ops = {
     .invalidate = virtio_gpu_invalidate_display,
     .gfx_update = virtio_gpu_update_display,
     .text_update = virtio_gpu_text_update,
     .ui_info = virtio_gpu_ui_info,
+    .gl_block = virtio_gpu_gl_block,
 };
 
 static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
hw/display/virtio-vga.c +10 -0
index f7e539f..255d419 100644
@@ -65,11 +65,21 @@ static int virtio_vga_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
     return -1;
 }
 
+static void virtio_vga_gl_block(void *opaque, bool block)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (virtio_gpu_ops.gl_block) {
+        virtio_gpu_ops.gl_block(&vvga->vdev, block);
+    }
+}
+
 static const GraphicHwOps virtio_vga_ops = {
     .invalidate = virtio_vga_invalidate_display,
     .gfx_update = virtio_vga_update_display,
     .text_update = virtio_vga_text_update,
     .ui_info = virtio_vga_ui_info,
+    .gl_block = virtio_vga_gl_block,
 };
 
 /* VGA device wrapper around PCI device around virtio GPU */
include/hw/virtio/virtio-gpu.h +1 -0
index fdf0091..7249fcd 100644
@@ -107,6 +107,7 @@ typedef struct VirtIOGPU {
 
     bool use_virgl_renderer;
     bool renderer_inited;
+    bool renderer_blocked;
     QEMUTimer *fence_poll;
     QEMUTimer *print_stats;
 
Signature · 1 line
1.8.3.1
#12 lore raw

Re: [Qemu-devel] [PATCH 6/6] virtio-gpu: block any rendering until client (ui) is done

Hi

Quoted 32 lines · Gerd Hoffmann

Wire up gl_block callback, so ui code can request to stop virtio-gpu rendering.

---
 hw/display/virtio-gpu-3d.c     |  5 +++++
 hw/display/virtio-gpu.c        |  8 ++++++++
 hw/display/virtio-vga.c        | 10 ++++++++++
 include/hw/virtio/virtio-gpu.h |  1 +
 4 files changed, 24 insertions(+)
hw/display/virtio-gpu-3d.c +5 -0
index 65926b1..321a959 100644
@@ -382,6 +382,11 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
 {
     VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr);
 
+    cmd->waiting = g->renderer_blocked;
+    if (cmd->waiting) {
+        return;
+    }
+
     virgl_renderer_force_ctx_0();
     switch (cmd->cmd_hdr.type) {
     case VIRTIO_GPU_CMD_CTX_CREATE:
hw/display/virtio-gpu.c +0 -0
index 9087e63..09936c9 100644

hw/display/virtio-gpu.c static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info) · line 901

Quoted 9 lines
hw/display/virtio-gpu.c +6 -0
@@ -893,11 +893,19 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
     return 0;
 }
 
+static void virtio_gpu_gl_block(void *opaque, bool block)
+{
+    VirtIOGPU *g = opaque;
+
+    g->renderer_blocked = block;
+}

Why not add here?:

+ if (!block) {
+ virtio_cpu_process_cmdq(g);
+ }

Quoted 51 lines
hw/display/virtio-gpu.c +2 -0
+
 const GraphicHwOps virtio_gpu_ops = {
     .invalidate = virtio_gpu_invalidate_display,
     .gfx_update = virtio_gpu_update_display,
     .text_update = virtio_gpu_text_update,
     .ui_info = virtio_gpu_ui_info,
+    .gl_block = virtio_gpu_gl_block,
 };
 
 static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
hw/display/virtio-vga.c +10 -0
index f7e539f..255d419 100644
@@ -65,11 +65,21 @@ static int virtio_vga_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
     return -1;
 }
 
+static void virtio_vga_gl_block(void *opaque, bool block)
+{
+    VirtIOVGA *vvga = opaque;
+
+    if (virtio_gpu_ops.gl_block) {
+        virtio_gpu_ops.gl_block(&vvga->vdev, block);
+    }
+}
+
 static const GraphicHwOps virtio_vga_ops = {
     .invalidate = virtio_vga_invalidate_display,
     .gfx_update = virtio_vga_update_display,
     .text_update = virtio_vga_text_update,
     .ui_info = virtio_vga_ui_info,
+    .gl_block = virtio_vga_gl_block,
 };
 
 /* VGA device wrapper around PCI device around virtio GPU */
include/hw/virtio/virtio-gpu.h +1 -1
index fdf0091..7249fcd 100644
@@ -107,6 +107,7 @@ typedef struct VirtIOGPU {
 
     bool use_virgl_renderer;
     bool renderer_inited;
+    bool renderer_blocked;
     QEMUTimer *fence_poll;
     QEMUTimer *print_stats;
 
--

1.8.3.1

Signature · 1 line
Marc-André Lureau