Skip to contentSkip to conversation

ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

PATCH In review [email protected] 2 participants 10 messages May 29, 2024 – Jun 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

From: Dongwon <[email protected]>

Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to be signaled.

Cc Marc-André Lureau <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 ui/egl-helpers.c |  2 --
 ui/gtk.c         | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
ui/egl-helpers.c +0 -2
index 99b2ebbe23..dafeb36074 100644
@@ -396,8 +396,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf)
         fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display,
                                               sync);
         qemu_dmabuf_set_fence_fd(dmabuf, fence_fd);
-        eglDestroySyncKHR(qemu_egl_display, sync);
-        qemu_dmabuf_set_sync(dmabuf, NULL);
     }
 }
 
ui/gtk.c +19 -0
index 93b13b7a30..cf0dd6abed 100644
@@ -600,9 +600,12 @@ void gd_hw_gl_flushed(void *vcon)
 
     fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
     if (fence_fd >= 0) {
+        void *sync = qemu_dmabuf_get_sync(dmabuf);
         qemu_set_fd_handler(fence_fd, NULL, NULL, NULL);
         close(fence_fd);
         qemu_dmabuf_set_fence_fd(dmabuf, -1);
+        eglDestroySyncKHR(qemu_egl_display, sync);
+        qemu_dmabuf_set_sync(dmabuf, NULL);
         graphic_hw_gl_block(vc->gfx.dcl.con, false);
     }
 }
@@ -682,6 +685,22 @@ static const DisplayGLCtxOps egl_ctx_ops = {
 static void gd_change_runstate(void *opaque, bool running, RunState state)
 {
     GtkDisplayState *s = opaque;
+    QemuDmaBuf *dmabuf;
+    int i;
+
+    if (state == RUN_STATE_SAVE_VM) {
+        for (i = 0; i < s->nb_vcs; i++) {
+            VirtualConsole *vc = &s->vc[i];
+            dmabuf = vc->gfx.guest_fb.dmabuf;
+            if (dmabuf && qemu_dmabuf_get_fence_fd(dmabuf) >= 0) {
+                /* wait for the rendering to be completed */
+                eglClientWaitSync(qemu_egl_display,
+                                  qemu_dmabuf_get_sync(dmabuf),
+                                  EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
+                                  1000000000);
+            }
+        }
+    }
 
     gd_update_caption(s);
 }
Signature · 1 line
2.34.1
#1 lore raw

Hi

Quoted 6 lines · On Thu, May 30, 2024 at 2:44 AM <[email protected]> wrote:

From: Dongwon <[email protected]>

Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to be signaled.

Can you expand on what this solves?

Quoted 14 lines
Cc Marc-André Lureau <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 ui/egl-helpers.c |  2 --
 ui/gtk.c         | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
ui/egl-helpers.c +0 -0
index 99b2ebbe23..dafeb36074 100644

ui/egl-helpers.c void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) · line 399

Quoted 6 lines
ui/egl-helpers.c +0 -2
@@ -396,8 +396,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf)
         fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display,
                                               sync);
         qemu_dmabuf_set_fence_fd(dmabuf, fence_fd);
-        eglDestroySyncKHR(qemu_egl_display, sync);
-        qemu_dmabuf_set_sync(dmabuf, NULL);
 

If this function is called multiple times, it will now set a new fence_fd each time, and potentially leak older fd. Maybe it could first check if a fence_fd exists instead.

     }
Quoted 27 lines
ui/egl-helpers.c +0 -0
 }
 
ui/gtk.c +7 -0
index 93b13b7a30..cf0dd6abed 100644
@@ -600,9 +600,12 @@ void gd_hw_gl_flushed(void *vcon)
 
     fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
     if (fence_fd >= 0) {
+        void *sync = qemu_dmabuf_get_sync(dmabuf);
         qemu_set_fd_handler(fence_fd, NULL, NULL, NULL);
         close(fence_fd);
         qemu_dmabuf_set_fence_fd(dmabuf, -1);
+        eglDestroySyncKHR(qemu_egl_display, sync);
+        qemu_dmabuf_set_sync(dmabuf, NULL);
         graphic_hw_gl_block(vc->gfx.dcl.con, false);
     }
 }
@@ -682,6 +685,22 @@ static const DisplayGLCtxOps egl_ctx_ops = {
 static void gd_change_runstate(void *opaque, bool running, RunState state)
 {
     GtkDisplayState *s = opaque;
+    QemuDmaBuf *dmabuf;
+    int i;
+
+    if (state == RUN_STATE_SAVE_VM) {

ui/gtk.c static const DisplayGLCtxOps egl_ctx_ops = { · line 701

Quoted 10 lines
ui/gtk.c +9 -0
+        for (i = 0; i < s->nb_vcs; i++) {
+            VirtualConsole *vc = &s->vc[i];
+            dmabuf = vc->gfx.guest_fb.dmabuf;
+            if (dmabuf && qemu_dmabuf_get_fence_fd(dmabuf) >= 0) {
+                /* wait for the rendering to be completed */
+                eglClientWaitSync(qemu_egl_display,
+                                  qemu_dmabuf_get_sync(dmabuf),
+                                  EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
+                                  1000000000);
 

I don't think adding waiting points in the migration path is appropriate.
Perhaps once you explain the actual issue, it will be easier to help.

+ }

Quoted 10 lines
ui/gtk.c +2 -1
+        }
+    }
 
     gd_update_caption(s);
 }
--

2.34.1

Signature · 1 line
Marc-André Lureau
#2 lore raw
Quoted 4 lines · Marc-André Lureau

Hi

On Thu, May 30, 2024 at 2:44 AM <[email protected] <mailto:[email protected]>> wrote:

Quoted 8 lines

From: Dongwon <[email protected] <mailto:[email protected]>>

Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to be signaled.

Can you expand on what this solves?

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s state is saved while it is still waiting for the fence, The guest will continue to wait for the fence that was signaled while ago when it is restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

Quoted 25 lines

    Cc: Marc-André Lureau <[email protected]
    <mailto:[email protected]>>
    Cc: Vivek Kasireddy <[email protected]
    <mailto:[email protected]>>
    Signed-off-by: Dongwon Kim <[email protected]
    <mailto:[email protected]>>
    ---
      ui/egl-helpers.c |  2 --
      ui/gtk.c         | 19 +++++++++++++++++++
      2 files changed, 19 insertions(+), 2 deletions(-)

    diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
    index 99b2ebbe23..dafeb36074 100644
    --- a/ui/egl-helpers.c
    +++ b/ui/egl-helpers.c
    @@ -396,8 +396,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf)
              fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display,
                                                    sync);
              qemu_dmabuf_set_fence_fd(dmabuf, fence_fd);
    -        eglDestroySyncKHR(qemu_egl_display, sync);
    -        qemu_dmabuf_set_sync(dmabuf, NULL);
Quoted 1 line

If this function is called multiple times, it will now set a new fence_fd each time, and potentially leak older fd. Maybe it could first check if a fence_fd exists instead.

We can make that change.

Quoted 58 lines
          }
      }

    diff --git a/ui/gtk.c b/ui/gtk.c
    index 93b13b7a30..cf0dd6abed 100644
    --- a/ui/gtk.c
    +++ b/ui/gtk.c
    @@ -600,9 +600,12 @@ void gd_hw_gl_flushed(void *vcon)

          fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
          if (fence_fd >= 0) {
    +        void *sync = qemu_dmabuf_get_sync(dmabuf);
              qemu_set_fd_handler(fence_fd, NULL, NULL, NULL);
              close(fence_fd);
              qemu_dmabuf_set_fence_fd(dmabuf, -1);
    +        eglDestroySyncKHR(qemu_egl_display, sync);
    +        qemu_dmabuf_set_sync(dmabuf, NULL);
              graphic_hw_gl_block(vc->gfx.dcl.con, false);
          }
      }
    @@ -682,6 +685,22 @@ static const DisplayGLCtxOps egl_ctx_ops = {
      static void gd_change_runstate(void *opaque, bool running,
    RunState state)
      {
          GtkDisplayState *s = opaque;
    +    QemuDmaBuf *dmabuf;
    +    int i;
    +
    +    if (state == RUN_STATE_SAVE_VM) {
    +        for (i = 0; i < s->nb_vcs; i++) {
    +            VirtualConsole *vc = &s->vc[i];
    +            dmabuf = vc->gfx.guest_fb.dmabuf;
    +            if (dmabuf && qemu_dmabuf_get_fence_fd(dmabuf) >= 0) {
    +                /* wait for the rendering to be completed */
    +                eglClientWaitSync(qemu_egl_display,
    +                                  qemu_dmabuf_get_sync(dmabuf),
    +                                  EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
    +                                  1000000000);

 I don't think adding waiting points in the migration path is
appropriate. Perhaps once you explain the actual issue, it will be easier to help.

    +            }
    +        }
    +    }

          gd_update_caption(s);
      }
    -- 
    2.34.1
Signature · 1 line
Marc-André Lureau
#3 lore raw

Hi

Quoted 14 lines · Dongwon
Quoted 9 lines · Marc-André Lureau

Hi

On Thu, May 30, 2024 at 2:44 AM <[email protected] <mailto:[email protected]>> wrote:

From: Dongwon <[email protected] <mailto:[email protected]>>

Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to

be

Quoted 3 lines

signaled.

Quoted 9 lines
Quoted 1 line

Can you expand on what this solves?

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s state is saved while it is still waiting for the fence, The guest will continue to wait for the fence that was signaled while ago when it is restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

After the UI sets a fence, hw_ops->gl_block(true) gets called, which will block virtio-gpu/virgl from processing commands (until the fence is signaled and gl_block/false called again).

But this "blocking" state is not saved. So how does this affect save/restore? Please give more details, thanks

Quoted 92 lines
Quoted 25 lines

    Cc: Marc-André Lureau <[email protected]
    <mailto:[email protected]>>
    Cc: Vivek Kasireddy <[email protected]
    <mailto:[email protected]>>
    Signed-off-by: Dongwon Kim <[email protected]
    <mailto:[email protected]>>
    ---
      ui/egl-helpers.c |  2 --
      ui/gtk.c         | 19 +++++++++++++++++++
      2 files changed, 19 insertions(+), 2 deletions(-)

    diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
    index 99b2ebbe23..dafeb36074 100644
    --- a/ui/egl-helpers.c
    +++ b/ui/egl-helpers.c
    @@ -396,8 +396,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf)
              fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display,
                                                    sync);
              qemu_dmabuf_set_fence_fd(dmabuf, fence_fd);
    -        eglDestroySyncKHR(qemu_egl_display, sync);
    -        qemu_dmabuf_set_sync(dmabuf, NULL);
Quoted 3 lines

If this function is called multiple times, it will now set a new fence_fd each time, and potentially leak older fd. Maybe it could first check if a fence_fd exists instead.

We can make that change.

Quoted 59 lines
          }
      }

    diff --git a/ui/gtk.c b/ui/gtk.c
    index 93b13b7a30..cf0dd6abed 100644
    --- a/ui/gtk.c
    +++ b/ui/gtk.c
    @@ -600,9 +600,12 @@ void gd_hw_gl_flushed(void *vcon)

          fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
          if (fence_fd >= 0) {
    +        void *sync = qemu_dmabuf_get_sync(dmabuf);
              qemu_set_fd_handler(fence_fd, NULL, NULL, NULL);
              close(fence_fd);
              qemu_dmabuf_set_fence_fd(dmabuf, -1);
    +        eglDestroySyncKHR(qemu_egl_display, sync);
    +        qemu_dmabuf_set_sync(dmabuf, NULL);
              graphic_hw_gl_block(vc->gfx.dcl.con, false);
          }
      }
    @@ -682,6 +685,22 @@ static const DisplayGLCtxOps egl_ctx_ops = {
      static void gd_change_runstate(void *opaque, bool running,
    RunState state)
      {
          GtkDisplayState *s = opaque;
    +    QemuDmaBuf *dmabuf;
    +    int i;
    +
    +    if (state == RUN_STATE_SAVE_VM) {
    +        for (i = 0; i < s->nb_vcs; i++) {
    +            VirtualConsole *vc = &s->vc[i];
    +            dmabuf = vc->gfx.guest_fb.dmabuf;
    +            if (dmabuf && qemu_dmabuf_get_fence_fd(dmabuf) >= 0) {
    +                /* wait for the rendering to be completed */
    +                eglClientWaitSync(qemu_egl_display,
    +                                  qemu_dmabuf_get_sync(dmabuf),
    +                                  EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
    +                                  1000000000);

I don't think adding waiting points in the migration path is
appropriate. Perhaps once you explain the actual issue, it will be easier to help.

    +            }
    +        }
    +    }

          gd_update_caption(s);
      }
    --
    2.34.1

--
Marc-André Lureau

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

Hi,

From: Marc-André Lureau <[email protected]>
Sent: Wednesday, June 5, 2024 12:56 AM
To: Kim, Dongwon <[email protected]>
Cc: [email protected]; Peter Xu <[email protected]>
Subject: Re: [PATCH] ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

Hi

On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon <mailto:[email protected]> wrote:

Quoted 5 lines · Marc-André Lureau

Hi

On Thu, May 30, 2024 at 2:44 AM <mailto:[email protected] <mailto:mailto:[email protected]>> wrote:

Quoted 8 lines

     From: Dongwon <mailto:[email protected] <mailto:mailto:[email protected]>>

     Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to be signaled.

Can you expand on what this solves?

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s state is saved while it is still waiting for the fence, The guest will continue to  wait for the fence that was signaled while ago when it is restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

After the UI sets a fence, hw_ops->gl_block(true) gets called, which will block virtio-gpu/virgl from processing commands (until the fence is signaled and gl_block/false called again).

But this "blocking" state is not saved. So how does this affect save/restore? Please give more details, thanks

Yeah sure. "Blocking" state is not saved but guest's state is saved while it was still waiting for the response for its last resource-flush virtio msg. This virtio response, by the way is set to be sent to the guest when the pipeline is unblocked (and when the fence is signaled.). Once the guest's state is saved, current instance of guest will be continued and receives the response as usual. The problem is happening when we restore the saved guest's state again because what guest does will be waiting for the response that was sent a while ago to the original instance.

Quoted 25 lines

     Cc: Marc-André Lureau <mailto:[email protected] <mailto:mailto:[email protected]>>
     Cc: Vivek Kasireddy <mailto:[email protected] <mailto:mailto:[email protected]>>

     <mailto:mailto:[email protected]>>
     ---
       ui/egl-helpers.c |  2 --
       ui/gtk.c         | 19 +++++++++++++++++++

       2 files changed, 19 insertions(+), 2 deletions(-)

     diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
     index 99b2ebbe23..dafeb36074 100644
     --- a/ui/egl-helpers.c
     +++ b/ui/egl-helpers.c
     @@ -396,8 +396,6 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display, sync); qemu_dmabuf_set_fence_fd(dmabuf, fence_fd);
     -        eglDestroySyncKHR(qemu_egl_display, sync);
     -        qemu_dmabuf_set_sync(dmabuf, NULL);

Quoted 3 lines

If this function is called multiple times, it will now set a new fence_fd each time, and potentially leak older fd. Maybe it could first check if a fence_fd exists instead.

We can make that change.

Quoted 59 lines

           }
       }

     diff --git a/ui/gtk.c b/ui/gtk.c
     index 93b13b7a30..cf0dd6abed 100644
     --- a/ui/gtk.c
     +++ b/ui/gtk.c
     @@ -600,9 +600,12 @@ void gd_hw_gl_flushed(void *vcon)

           fence_fd = qemu_dmabuf_get_fence_fd(dmabuf);
           if (fence_fd >= 0) {
     +        void *sync = qemu_dmabuf_get_sync(dmabuf); qemu_set_fd_handler(fence_fd, NULL, NULL, NULL); close(fence_fd); qemu_dmabuf_set_fence_fd(dmabuf, -1);
     +        eglDestroySyncKHR(qemu_egl_display, sync);
     +        qemu_dmabuf_set_sync(dmabuf, NULL); graphic_hw_gl_block(vc->gfx.dcl.con, false); }
       }
     @@ -682,6 +685,22 @@ static const DisplayGLCtxOps egl_ctx_ops = { static void gd_change_runstate(void *opaque, bool running, RunState state)
       {
           GtkDisplayState *s = opaque;
     +    QemuDmaBuf *dmabuf;
     +    int i;
     +
     +    if (state == RUN_STATE_SAVE_VM) {
     +        for (i = 0; i < s->nb_vcs; i++) {
     +            VirtualConsole *vc = &s->vc[i];
     +            dmabuf = vc->gfx.guest_fb.dmabuf;
     +            if (dmabuf && qemu_dmabuf_get_fence_fd(dmabuf) >= 0) { +                /* wait for the rendering to be completed */ +                eglClientWaitSync(qemu_egl_display,
     +                                  qemu_dmabuf_get_sync(dmabuf), +                                  EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, +                                  1000000000);

   I don't think adding waiting points in the migration path is appropriate. Perhaps once you explain the actual issue, it will be easier to help.

     +            }
     +        }
     +    }

           gd_update_caption(s);
       }
     --
     2.34.1

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

Hi

Quoted 44 lines · Dongwon

Hi,

From: Marc-André Lureau <[email protected]>
Sent: Wednesday, June 5, 2024 12:56 AM
To: Kim, Dongwon <[email protected]>
Cc: [email protected]; Peter Xu <[email protected]>
Subject: Re: [PATCH] ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

Hi

On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon <mailto:[email protected]> wrote:

Quoted 6 lines · Marc-André Lureau

Hi

On Thu, May 30, 2024 at 2:44 AM <mailto:[email protected] <mailto:mailto:[email protected]>> wrote:

From: Dongwon <mailto:[email protected] <mailto:mailto:

[email protected]>>

Quoted 3 lines

Make sure rendering of the current frame is finished before switching the run state to RUN_STATE_SAVE_VM by waiting for egl-sync object to

be

Quoted 4 lines

signaled.

Can you expand on what this solves?

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s state is saved while it is still waiting for the fence, The guest will continue to wait for the fence that was signaled while ago when it is restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

After the UI sets a fence, hw_ops->gl_block(true) gets called, which will block virtio-gpu/virgl from processing commands (until the fence is signaled and gl_block/false called again).

But this "blocking" state is not saved. So how does this affect save/restore? Please give more details, thanks

Quoted 9 lines

Yeah sure. "Blocking" state is not saved but guest's state is saved while it was still waiting for the response for its last resource-flush virtio msg. This virtio response, by the way is set to be sent to the guest when the pipeline is unblocked (and when the fence is signaled.). Once the guest's state is saved, current instance of guest will be continued and receives the response as usual. The problem is happening when we restore the saved guest's state again because what guest does will be waiting for the response that was sent a while ago to the original instance.

Where is the pending response saved? Can you detail how you test this?

thanks

Signature · 1 line
Marc-André Lureau
#6 lore raw
Quoted 65 lines · Marc-André Lureau

Hi

On Wed, Jun 12, 2024 at 5:29 AM Kim, Dongwon <[email protected] <mailto:[email protected]>> wrote:

Hi,

From: Marc-André Lureau <[email protected] <mailto:[email protected]>>
Sent: Wednesday, June 5, 2024 12:56 AM
To: Kim, Dongwon <[email protected] <mailto:[email protected]>>
Cc: [email protected] <mailto:[email protected]>; Peter Xu <[email protected] <mailto:[email protected]>>
Subject: Re: [PATCH] ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

Hi

On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon <mailto:[email protected] <mailto:[email protected]>> wrote:
On 6/4/2024 4:12 AM, Marc-André Lureau wrote:
> Hi
>
> On Thu, May 30, 2024 at 2:44 AM <mailto:[email protected]
<mailto:[email protected]>
> <mailto:mailto <mailto:mailto>:[email protected]
<mailto:[email protected]>>> wrote:
>
>     From: Dongwon <mailto:[email protected]
<mailto:[email protected]> <mailto:mailto <mailto:mailto>:[email protected] <mailto:[email protected]>>>
>
>     Make sure rendering of the current frame is finished before
switching
>     the run state to RUN_STATE_SAVE_VM by waiting for egl-sync
object to be
>     signaled.
>
>
> Can you expand on what this solves?

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s state is saved while it is still waiting for the fence, The guest will continue to  wait for the fence that was signaled while ago when it is restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

After the UI sets a fence, hw_ops->gl_block(true) gets called, which will block virtio-gpu/virgl from processing commands (until the fence is signaled and gl_block/false called again).

But this "blocking" state is not saved. So how does this affect save/restore? Please give more details, thanks

Yeah sure. "Blocking" state is not saved but guest's state is saved while it was still waiting for the response for its last resource-flush virtio msg. This virtio response, by the way is set to be sent to the guest when the pipeline is unblocked (and when the fence is signaled.). Once the guest's state is saved, current instance of guest will be continued and receives the response as usual. The problem is happening when we restore the saved guest's state again because what guest does will be waiting for the response that was sent a while ago to the original instance.

Quoted 2 lines

Where is the pending response saved? Can you detail how you test this?

There is no pending response for the guest's restored point, which is a problem. The response is sent out after saving is done.

Normal cycle :

resource-flush (scanout flush) -> gl block -> render -> gl unblock (after fence is signaled) -> pending response sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

When vm state is saved in the middle :

resource-flush (scanout-flush) -> gl block -> saving vm-state -> render -> gl unblock -> pending response (resp #1) sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

Now, we restore the vm-state we saved

vm-state is restored -> guest (virtio-gpu drv) can't move on as this state is still waiting for the response (resp #1)

So we need to make sure vm-state is saved after the cycle is completed.

This situation would be only happening if you use blob=true with virtio-gpu drv as KMS on the linux guest. Do you have any similar setup?

Quoted 4 lines

thanks

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

Hi

Quoted 91 lines · Dongwon
Quoted 11 lines · Marc-André Lureau

Hi

On Wed, Jun 12, 2024 at 5:29 AM Kim, Dongwon <[email protected] <mailto:[email protected]>> wrote:

Hi,

From: Marc-André Lureau <[email protected] <mailto:[email protected]>>
Sent: Wednesday, June 5, 2024 12:56 AM
To: Kim, Dongwon <[email protected] <mailto:

[email protected]>>

Quoted 31 lines

Cc: [email protected] <mailto:[email protected]>; Peter Xu <[email protected] <mailto:[email protected]>>
Subject: Re: [PATCH] ui/gtk: Wait until the current guest frame is rendered before switching to RUN_STATE_SAVE_VM

Hi

On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon <mailto:[email protected] <mailto:[email protected]>> wrote:
On 6/4/2024 4:12 AM, Marc-André Lureau wrote:
> Hi
>
> On Thu, May 30, 2024 at 2:44 AM <mailto:[email protected]
<mailto:[email protected]>
> <mailto:mailto <mailto:mailto>:[email protected]
<mailto:[email protected]>>> wrote:
>
> From: Dongwon <mailto:[email protected]
<mailto:[email protected]> <mailto:mailto <mailto:mailto>:[email protected] <mailto:[email protected]

Quoted 1 line
Quoted 1 line

>
> Make sure rendering of the current frame is finished before
switching
> the run state to RUN_STATE_SAVE_VM by waiting for egl-sync
object to be
> signaled.
>
>
> Can you expand on what this solves?

Quoted 2 lines

In current scheme, guest waits for the fence to be signaled for each frame it submits before moving to the next frame. If the guest’s

state

Quoted 2 lines

is saved while it is still waiting for the fence, The guest will continue to wait for the fence that was signaled while ago when it

is

Quoted 21 lines

restored to the point. One way to prevent it is to get it finish the current frame before changing the state.

After the UI sets a fence, hw_ops->gl_block(true) gets called, which will block virtio-gpu/virgl from processing commands (until the fence is signaled and gl_block/false called again).

But this "blocking" state is not saved. So how does this affect save/restore? Please give more details, thanks

Yeah sure. "Blocking" state is not saved but guest's state is saved while it was still waiting for the response for its last resource-flush virtio msg. This virtio response, by the way is set to be sent to the guest when the pipeline is unblocked (and when the fence is signaled.). Once the guest's state is saved, current instance of guest will be continued and receives the response as usual. The problem is happening when we restore the saved guest's state again because what guest does will be waiting for the response that was sent a while ago to the original instance.

Quoted 2 lines

Where is the pending response saved? Can you detail how you test this?

There is no pending response for the guest's restored point, which is a problem. The response is sent out after saving is done.

Normal cycle :

resource-flush (scanout flush) -> gl block -> render -> gl unblock (after fence is signaled) -> pending response sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

When vm state is saved in the middle :

resource-flush (scanout-flush) -> gl block -> saving vm-state -> render -> gl unblock -> pending response (resp #1) sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

Quoted 5 lines

Now, we restore the vm-state we saved

vm-state is restored -> guest (virtio-gpu drv) can't move on as this state is still waiting for the response (resp #1)

Ok, so actually it's more of a device state issue than a UI/GTK. We end up not saving a state that reflects the guest state. My understanding is that the guest is waiting for a fence reply, and we don't save that. Imho, a better fix would be to either save the fenceq (but then, what else is missing to complete the operation on resume?), or have a wait to delay the migration until the fences are flushed.

Quoted 6 lines

So we need to make sure vm-state is saved after the cycle is completed.

This situation would be only happening if you use blob=true with virtio-gpu drv as KMS on the linux guest. Do you have any similar setup?

No, further details to reproduce would help. Even better would be having some automated test.

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

Hi Marc-André,

Quoted 118 lines · Marc-André Lureau

Hi

On Wed, Jun 12, 2024 at 10:50 PM Kim, Dongwon <[email protected] <mailto:[email protected]>> wrote:

On 6/11/2024 10:44 PM, Marc-André Lureau wrote:
> Hi
>
> On Wed, Jun 12, 2024 at 5:29 AM Kim, Dongwon
<[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>
>     Hi,
>
>     From: Marc-André Lureau <[email protected]
<mailto:[email protected]>
>     <mailto:[email protected]
<mailto:[email protected]>>>
>     Sent: Wednesday, June 5, 2024 12:56 AM
>     To: Kim, Dongwon <[email protected]
<mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
>     Cc: [email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>; Peter Xu
>     <[email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>>
>     Subject: Re: [PATCH] ui/gtk: Wait until the current guest
frame is
>     rendered before switching to RUN_STATE_SAVE_VM
>
>     Hi
>
>     On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon
>     <mailto:[email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>> wrote:
>     On 6/4/2024 4:12 AM, Marc-André Lureau wrote:
>      > Hi
>      >
>      > On Thu, May 30, 2024 at 2:44 AM
<mailto:[email protected] <mailto:[email protected]>
>     <mailto:[email protected] <mailto:[email protected]>> >      > <mailto:mailto <mailto:mailto> <mailto:mailto
<mailto:mailto>>:[email protected] <mailto:[email protected]>
>     <mailto:[email protected]
<mailto:[email protected]>>>> wrote:
>      >
>      >     From: Dongwon <mailto:[email protected]
<mailto:[email protected]>
>     <mailto:[email protected] <mailto:[email protected]>>
<mailto:mailto <mailto:mailto>
>     <mailto:mailto <mailto:mailto>>:[email protected]
<mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>>
>      >
>      >     Make sure rendering of the current frame is finished
before
>     switching
>      >     the run state to RUN_STATE_SAVE_VM by waiting for egl-sync >     object to be
>      >     signaled.
>      >
>      >
>      > Can you expand on what this solves?
>
>     In current scheme, guest waits for the fence to be signaled
for each
>     frame it submits before moving to the next frame. If the
guest’s state
>     is saved while it is still waiting for the fence, The guest will >     continue to  wait for the fence that was signaled while ago
when it is
>     restored to the point. One way to prevent it is to get it
finish the
>     current frame before changing the state.
>
>     After the UI sets a fence, hw_ops->gl_block(true) gets
called, which
>     will block virtio-gpu/virgl from processing commands (until the >     fence is signaled and gl_block/false called again).
>
>     But this "blocking" state is not saved. So how does this affect >     save/restore? Please give more details, thanks
>
>     Yeah sure. "Blocking" state is not saved but guest's state is
saved
>     while it was still waiting for the response for its last >     resource-flush virtio msg. This virtio response, by the way
is set
>     to be sent to the guest when the pipeline is unblocked (and
when the
>     fence is signaled.). Once the guest's state is saved, current >     instance of guest will be continued and receives the response as >     usual. The problem is happening when we restore the saved guest's >     state again because what guest does will be waiting for the
response
>     that was sent a while ago to the original instance.
>
>
> Where is the pending response saved? Can you detail how you test
this?
>

There is no pending response for the guest's restored point, which is a problem. The response is sent out after saving is done.

Normal cycle :

resource-flush (scanout flush) -> gl block -> render -> gl unblock (after fence is signaled) -> pending response sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

When vm state is saved in the middle :

resource-flush (scanout-flush) -> gl block -> saving vm-state -> render -> gl unblock -> pending response (resp #1) sent out to the guest -> guest (virtio-gpu drv) processes the next scanout frame -> (next cycle) resource-flush -> gl block ......

Quoted 7 lines

Now, we restore the vm-state we saved

vm-state is restored -> guest (virtio-gpu drv) can't move on as this state is still waiting for the response (resp #1)

Ok, so actually it's more of a device state issue than a UI/GTK. We end up not saving a state that reflects the guest state. My understanding is that the guest is waiting for a fence reply, and we don't save that. Imho, a better fix would be to either save the fenceq (but then, what else is missing to complete the operation on resume?), or have a wait to delay the migration until the fences are flushed.

The second method you are proposing here - 'have a wait'. I understand you mean delaying the start point of migration but don't you think the current patch is basically doing the similar thing? Assuming egl wait sync is what we need to use for a wait, do you have any suggestion where that should be called other than 'gd_change_runstate'?

Quoted 9 lines

So we need to make sure vm-state is saved after the cycle is completed.

This situation would be only happening if you use blob=true with virtio-gpu drv as KMS on the linux guest. Do you have any similar setup?

No, further details to reproduce would help. Even better would be having some automated test.

I will think about this. We use GPU shared via SRIOV as a GPU deviceand virtio-gpu as a display device on the guest. I think I need to find and test more general cases.

Quoted 4 lines
Signature · 2 lines
-- 
Marc-André Lureau
#9 lore raw

Hi

Quoted 150 lines · Dongwon

Hi Marc-André,

Quoted 11 lines · Marc-André Lureau

Hi

On Wed, Jun 12, 2024 at 10:50 PM Kim, Dongwon <[email protected] <mailto:[email protected]>> wrote:

    On 6/11/2024 10:44 PM, Marc-André Lureau wrote:
     > Hi
     >
     > On Wed, Jun 12, 2024 at 5:29 AM Kim, Dongwon
    <[email protected] <mailto:[email protected]>
     > <mailto:[email protected] <mailto:[email protected]>>>
Quoted 5 lines · wrote:
     >
     >     Hi,
     >
     >     From: Marc-André Lureau <[email protected]
    <mailto:[email protected]>
Quoted 8 lines
     >     <mailto:[email protected]
    <mailto:[email protected]>>>
     >     Sent: Wednesday, June 5, 2024 12:56 AM
     >     To: Kim, Dongwon <[email protected]
    <mailto:[email protected]> <mailto:[email protected]
    <mailto:[email protected]>>>
     >     Cc: [email protected] <mailto:[email protected]>
    <mailto:[email protected] <mailto:[email protected]>>;

Peter Xu

Quoted 11 lines

> <[email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>>
> Subject: Re: [PATCH] ui/gtk: Wait until the current guest
frame is
> rendered before switching to RUN_STATE_SAVE_VM
>
> Hi
>
> On Tue, Jun 4, 2024 at 9:49 PM Kim, Dongwon
> <mailto:[email protected] <mailto:[email protected]>
<mailto:[email protected] <mailto:[email protected]>>>

Quoted 9 lines · wrote:

> On 6/4/2024 4:12 AM, Marc-André Lureau wrote:
> > Hi
> >
> > On Thu, May 30, 2024 at 2:44 AM
<mailto:[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>
> > <mailto:mailto <mailto:mailto> <mailto:mailto
<mailto:mailto>>:[email protected] <mailto:[email protected]

Quoted 15 lines

> <mailto:[email protected]
<mailto:[email protected]>>>> wrote:
> >
> > From: Dongwon <mailto:[email protected]
<mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>
<mailto:mailto <mailto:mailto>
> <mailto:mailto <mailto:mailto>>:[email protected]
<mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>>
> >
> > Make sure rendering of the current frame is finished
before
> switching
> > the run state to RUN_STATE_SAVE_VM by waiting for

egl-sync

Quoted 11 lines

> object to be
> > signaled.
> >
> >
> > Can you expand on what this solves?
>
> In current scheme, guest waits for the fence to be signaled
for each
> frame it submits before moving to the next frame. If the
guest’s state
> is saved while it is still waiting for the fence, The guest

will

Quoted 9 lines

> continue to wait for the fence that was signaled while ago
when it is
> restored to the point. One way to prevent it is to get it
finish the
> current frame before changing the state.
>
> After the UI sets a fence, hw_ops->gl_block(true) gets
called, which
> will block virtio-gpu/virgl from processing commands (until

the

Quoted 3 lines

> fence is signaled and gl_block/false called again).
>
> But this "blocking" state is not saved. So how does this

affect

Quoted 11 lines

> save/restore? Please give more details, thanks
>
> Yeah sure. "Blocking" state is not saved but guest's state is
saved
> while it was still waiting for the response for its last
> resource-flush virtio msg. This virtio response, by the way
is set
> to be sent to the guest when the pipeline is unblocked (and
when the
> fence is signaled.). Once the guest's state is saved, current
> instance of guest will be continued and receives the response

as

Quoted 1 line

> usual. The problem is happening when we restore the saved

guest's

Quoted 10 lines

> state again because what guest does will be waiting for the
response
> that was sent a while ago to the original instance.
>
>
> Where is the pending response saved? Can you detail how you test
this?
>

There is no pending response for the guest's restored point, which

is a

Quoted 6 lines

problem. The response is sent out after saving is done.

Normal cycle :

resource-flush (scanout flush) -> gl block -> render -> gl unblock (after fence is signaled) -> pending response sent out to the guest

->

Quoted 1 line
    guest (virtio-gpu drv) processes the next scanout frame -> (next

cycle)

Quoted 5 lines
    resource-flush -> gl block ......

    When vm state is saved in the middle :

    resource-flush (scanout-flush) -> gl block -> saving vm-state ->

render

Quoted 2 lines
    -> gl unblock -> pending response (resp #1) sent out to the guest ->
    guest (virtio-gpu drv) processes the next scanout frame -> (next

cycle)

Quoted 8 lines

resource-flush -> gl block ......

Now, we restore the vm-state we saved

vm-state is restored -> guest (virtio-gpu drv) can't move on as this state is still waiting for the response (resp #1)

Quoted 6 lines

Ok, so actually it's more of a device state issue than a UI/GTK. We end up not saving a state that reflects the guest state. My understanding is that the guest is waiting for a fence reply, and we don't save that. Imho, a better fix would be to either save the fenceq (but then, what else is missing to complete the operation on resume?), or have a wait to delay the migration until the fences are flushed.

Quoted 6 lines

The second method you are proposing here - 'have a wait'. I understand you mean delaying the start point of migration but don't you think the current patch is basically doing the similar thing? Assuming egl wait sync is what we need to use for a wait, do you have any suggestion where that should be called other than 'gd_change_runstate'?

It should be handled at virtio-gpu side. I am not sure if runstate handler or pre_save are the right place.

Peter, what is the correct way to delay migration until the host finishes some work? (in this case we would need to wait for the rendering/UI, to signal pending fences)

thanks

Signature · 1 line
Marc-André Lureau