From a69b8d66fb515cd55cef2fcaa626c350d761f1a9 Mon Sep 17 00:00:00 2001 From: Juraj Marcin Date: Wed, 21 May 2025 17:16:13 +0200 Subject: [PATCH 57/57] ui/vnc: Update display update interval when VM state changes to RUNNING MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Juraj Marcin RH-MergeRequest: 385: ui/vnc: Update display update interval when VM state changes to RUNNING RH-Jira: RHEL-100741 RH-Acked-by: Peter Xu RH-Acked-by: Marc-André Lureau RH-Commit: [1/1] 30dd4790a607d646465c18d621073df997e8850b (JurajMarcin/centos-src-qemu-kvm) If a virtual machine is paused for an extended period time, for example, due to an incoming migration, there are also no changes on the screen. VNC in such case increases the display update interval by VNC_REFRESH_INTERVAL_INC (50 ms). The update interval can then grow up to VNC_REFRESH_INTERVAL_MAX (3000 ms). When the machine resumes, it can then take up to 3 seconds for the first display update. Furthermore, the update interval is then halved with each display update with changes on the screen. If there are moving elements on the screen, such as a video, this can be perceived as freezing and stuttering for few seconds before the movement is smooth again. This patch resolves this issue, by adding a listener to VM state changes and changing the update interval when the VM state changes to RUNNING. The update_displaychangelistener() function updates the internal timer, and the display is refreshed immediately if the timer is expired. Signed-off-by: Juraj Marcin Reviewed-by: Marc-André Lureau Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrangé Link: https://lore.kernel.org/r/20250521151616.3951178-1-jmarcin@redhat.com Signed-off-by: Peter Xu (cherry picked from commit 0310d594d98b39f9dde79b87fd8b0ad16e7c5459) JIRA: https://issues.redhat.com/browse/RHEL-100741 Signed-off-by: Juraj Marcin --- ui/vnc.c | 12 ++++++++++++ ui/vnc.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/ui/vnc.c b/ui/vnc.c index 5057ec8680..4afc925a18 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3386,6 +3386,16 @@ static const DisplayChangeListenerOps dcl_ops = { .dpy_cursor_define = vnc_dpy_cursor_define, }; +static void vmstate_change_handler(void *opaque, bool running, RunState state) +{ + VncDisplay *vd = opaque; + + if (state != RUN_STATE_RUNNING) { + return; + } + update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE); +} + void vnc_display_init(const char *id, Error **errp) { VncDisplay *vd; @@ -3422,6 +3432,8 @@ void vnc_display_init(const char *id, Error **errp) vd->dcl.ops = &dcl_ops; register_displaychangelistener(&vd->dcl); vd->kbd = qkbd_state_init(vd->dcl.con); + vd->vmstate_handler_entry = qemu_add_vm_change_state_handler( + &vmstate_change_handler, vd); } diff --git a/ui/vnc.h b/ui/vnc.h index e5fa2efa3e..e9da707dbc 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -186,6 +186,8 @@ struct VncDisplay #endif AudioState *audio_state; + + VMChangeStateEntry *vmstate_handler_entry; }; typedef struct VncTight { -- 2.39.3