From nobody Sat Nov 15 16:37:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1750135143; cv=none; d=zohomail.com; s=zohoarc; b=ZtChdQkODxzjsnRzq2KzZFbpxIcp0Ze6YGNkPt0yq+druKmQlSzMYsWSA/IsCVCScH2mZZLFG8+S6xd68lszoAVbfAC8SjZ8xri728qNfdN5cSKMcCZuyFHfl8MZjywPuEzZjIUUec+ArQaK4duLp45TUbiK/8urCPxfhkcxOvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750135143; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GbC/LVG75ypwNQd/4beWvIKh0qoF4zIaJrxYJqmbJvA=; b=LsYHdqJKpFpBP5YwJHEsqDO/a4FiGfiiVa72iIqateNPGf52AYfPMRUn3dmogQlBbZp5qb9wFQgziZFXr/EO2KlaEhwTamuT/vUGv+z5Lfgw3D1UVbHADi2P5SCbMS/mWnzWBlDQiaX9Ad34GkJHcuzJM/9t4dOr+reyG6+Wyds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750135143391885.6204630119526; Mon, 16 Jun 2025 21:39:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uRO5h-0002rF-Ty; Tue, 17 Jun 2025 00:38:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uRO5g-0002qF-4y for qemu-devel@nongnu.org; Tue, 17 Jun 2025 00:38:32 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uRO5e-0007jV-2E for qemu-devel@nongnu.org; Tue, 17 Jun 2025 00:38:31 -0400 Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2025 21:38:25 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2025 21:38:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750135111; x=1781671111; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GSS9b1nGxtqsZ74PUq0QmxMmFYUyYN4NIY8CJ8re9Zo=; b=AHn67MgV6RWL/mGB6GDqQUZAKBpE+3QKH9D+9qEdmS9U6zalYZkehv07 UndTS09EeYJj8KmSIE0NjYfe/82y+WYN7FoGFjkQ8CgAomCD8gQI8vp55 Y5L79O0tX2S6pEphMJAPUI6ALcOABlbLmLKi4DvZBYkEJaQayP2lPWXWr Y/47GeZEcyK8VmX4lEwEskz2IpK5Cmdhmw0SWyxWq2AazZRUHaUyTuGV9 qy6btoYAVbAeuZefTc8/TUAGY1dHfAt/Nh64j2ioUgKO5FvwoYsPARQck sAQp7dfAbWVnDqYBPptLiQvchXJeuQdLr0TgTrgbngN7Vei9HM3QNLTOI Q==; X-CSE-ConnectionGUID: FpUtpV4QTIeWK2cM8FpTmg== X-CSE-MsgGUID: 3OGfpT+MS6acJ6rOvL7U9g== X-IronPort-AV: E=McAfee;i="6800,10657,11465"; a="52432305" X-IronPort-AV: E=Sophos;i="6.16,242,1744095600"; d="scan'208";a="52432305" X-CSE-ConnectionGUID: ER4iffJ0QcG3dPyZI8UoCA== X-CSE-MsgGUID: G6lKIXGtRpulP2UB3kAqMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,242,1744095600"; d="scan'208";a="149551048" From: Vivek Kasireddy To: qemu-devel@nongnu.org Cc: Vivek Kasireddy , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Dmitry Osipenko , Frediano Ziglio , Dongwon Kim , Michael Scherle Subject: [PATCH v6 4/7] ui/spice: Add an option to submit gl_draw requests at fixed rate Date: Mon, 16 Jun 2025 21:32:28 -0700 Message-ID: <20250617043546.1022779-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617043546.1022779-1-vivek.kasireddy@intel.com> References: <20250617043546.1022779-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -62 X-Spam_score: -6.3 X-Spam_bar: ------ X-Spam_report: (-6.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.892, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1750135145218116600 In the specific case where the display layer (virtio-gpu) is using dmabuf, and if remote clients are enabled (-spice gl=3Don,port=3Dxxxx), it makes sense to limit the maximum (streaming) rate (refresh rate) to a fixed value using the GUI refresh timer. Otherwise, the updates or gl_draw requests would be sent as soon as the Guest submits a new frame which is not optimal as it would lead to increased network traffic and wastage of GPU cycles if the frames get dropped. Cc: Gerd Hoffmann Cc: Marc-Andr=C3=A9 Lureau Cc: Dmitry Osipenko Cc: Frediano Ziglio Cc: Dongwon Kim Cc: Michael Scherle Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Vivek Kasireddy --- include/ui/spice-display.h | 1 + qemu-options.hx | 5 +++ ui/spice-core.c | 12 ++++++++ ui/spice-display.c | 62 ++++++++++++++++++++++++++++++++------ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h index 6c55f38c8b..9bdde78266 100644 --- a/include/ui/spice-display.h +++ b/include/ui/spice-display.h @@ -152,6 +152,7 @@ struct SimpleSpiceCursor { =20 extern bool spice_opengl; extern bool spice_remote_client; +extern int spice_max_refresh_rate; =20 int qemu_spice_rect_is_empty(const QXLRect* r); void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r); diff --git a/qemu-options.hx b/qemu-options.hx index 124c87311c..e06fa67b89 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2282,6 +2282,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice, " [,disable-agent-file-xfer=3Don|off][,agent-mouse=3D[on|off]]\n" " [,playback-compression=3D[on|off]][,seamless-migration=3D[on|o= ff]]\n" " [,video-codec=3D\n" + " [,max-refresh-rate=3Drate\n" " [,gl=3D[on|off]][,rendernode=3D]\n" " enable spice\n" " at least one of {port, tls-port} is mandatory\n", @@ -2377,6 +2378,10 @@ SRST would be used as default. And, for the case where gl=3Doff, the default codec to be used is determined by the Spice server. =20 + ``max-refresh-rate=3Drate`` + Provide the maximum refresh rate (or FPS) at which the encoding + requests should be sent to the Spice server. Default would be 30. + ``gl=3D[on|off]`` Enable/disable OpenGL context. Default is off. =20 diff --git a/ui/spice-core.c b/ui/spice-core.c index 5e585ed958..5477950a5e 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -56,6 +56,8 @@ struct SpiceTimer { QEMUTimer *timer; }; =20 +#define DEFAULT_MAX_REFRESH_RATE 30 + static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque) { SpiceTimer *timer; @@ -491,6 +493,9 @@ static QemuOptsList qemu_spice_opts =3D { },{ .name =3D "video-codec", .type =3D QEMU_OPT_STRING, + },{ + .name =3D "max-refresh-rate", + .type =3D QEMU_OPT_NUMBER, },{ .name =3D "agent-mouse", .type =3D QEMU_OPT_BOOL, @@ -806,6 +811,13 @@ static void qemu_spice_init(void) spice_server_set_streaming_video(spice_server, SPICE_STREAM_VIDEO_= OFF); } =20 + spice_max_refresh_rate =3D qemu_opt_get_number(opts, "max-refresh-rate= ", + DEFAULT_MAX_REFRESH_RATE); + if (spice_max_refresh_rate <=3D 0) { + error_report("max refresh rate/fps is invalid"); + exit(1); + } + spice_server_set_agent_mouse (spice_server, qemu_opt_get_bool(opts, "agent-mouse", 1)); spice_server_set_playback_compression diff --git a/ui/spice-display.c b/ui/spice-display.c index 0fb72f6d6f..e409b6bdb2 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -32,6 +32,7 @@ =20 bool spice_opengl; bool spice_remote_client; +int spice_max_refresh_rate; =20 int qemu_spice_rect_is_empty(const QXLRect* r) { @@ -844,12 +845,32 @@ static void qemu_spice_gl_block_timer(void *opaque) warn_report("spice: no gl-draw-done within one second"); } =20 +static void spice_gl_draw(SimpleSpiceDisplay *ssd, + uint32_t x, uint32_t y, uint32_t w, uint32_t h) +{ + uint64_t cookie; + + cookie =3D (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_GL_DRAW_DONE, 0); + spice_qxl_gl_draw_async(&ssd->qxl, x, y, w, h, cookie); +} + static void spice_gl_refresh(DisplayChangeListener *dcl) { SimpleSpiceDisplay *ssd =3D container_of(dcl, SimpleSpiceDisplay, dcl); - uint64_t cookie; =20 - if (!ssd->ds || qemu_console_is_gl_blocked(ssd->dcl.con)) { + if (!ssd->ds) { + return; + } + + if (qemu_console_is_gl_blocked(ssd->dcl.con)) { + if (spice_remote_client && ssd->gl_updates && ssd->have_scanout) { + glFlush(); + spice_gl_draw(ssd, 0, 0, + surface_width(ssd->ds), surface_height(ssd->ds)); + ssd->gl_updates =3D 0; + /* E.g, to achieve 60 FPS, update_interval needs to be ~16.66 = ms */ + dcl->update_interval =3D 1000 / spice_max_refresh_rate; + } return; } =20 @@ -857,11 +878,8 @@ static void spice_gl_refresh(DisplayChangeListener *dc= l) if (ssd->gl_updates && ssd->have_surface) { qemu_spice_gl_block(ssd, true); glFlush(); - cookie =3D (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_GL_DRAW_DONE,= 0); - spice_qxl_gl_draw_async(&ssd->qxl, 0, 0, - surface_width(ssd->ds), - surface_height(ssd->ds), - cookie); + spice_gl_draw(ssd, 0, 0, + surface_width(ssd->ds), surface_height(ssd->ds)); ssd->gl_updates =3D 0; } } @@ -954,6 +972,20 @@ static void qemu_spice_gl_scanout_disable(DisplayChang= eListener *dcl) SimpleSpiceDisplay *ssd =3D container_of(dcl, SimpleSpiceDisplay, dcl); =20 trace_qemu_spice_gl_scanout_disable(ssd->qxl.id); + + /* + * We need to check for the case of "lost" updates, where a gl_draw + * was not submitted because the timer did not get a chance to run. + * One case where this happens is when the Guest VM is getting + * rebooted. If the console is blocked in this situation, we need + * to unblock it. Otherwise, newer updates would not take effect. + */ + if (qemu_console_is_gl_blocked(ssd->dcl.con)) { + if (spice_remote_client && ssd->gl_updates && ssd->have_scanout) { + ssd->gl_updates =3D 0; + qemu_spice_gl_block(ssd, false); + } + } spice_server_gl_scanout(&ssd->qxl, NULL, 0, 0, NULL, NULL, 0, DRM_FORM= AT_INVALID, DRM_FORMAT_MOD_INVALID, false); qemu_spice_gl_monitor_config(ssd, 0, 0, 0, 0); @@ -1061,7 +1093,6 @@ static void qemu_spice_gl_update(DisplayChangeListene= r *dcl, EGLint fourcc =3D 0; bool render_cursor =3D false; bool y_0_top =3D false; /* FIXME */ - uint64_t cookie; uint32_t width, height, texture; =20 if (!ssd->have_scanout) { @@ -1159,8 +1190,19 @@ static void qemu_spice_gl_update(DisplayChangeListen= er *dcl, trace_qemu_spice_gl_update(ssd->qxl.id, w, h, x, y); qemu_spice_gl_block(ssd, true); glFlush(); - cookie =3D (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_GL_DRAW_DONE, 0); - spice_qxl_gl_draw_async(&ssd->qxl, x, y, w, h, cookie); + + /* + * In the case of remote clients, the submission of gl_draw request is + * deferred here, so that it can be submitted later (to spice server) + * from spice_gl_refresh() timer callback. This is done to ensure that + * Guest updates are submitted at a steady rate (e.g. 60 FPS) instead + * of submitting them arbitrarily. + */ + if (spice_remote_client) { + ssd->gl_updates++; + } else { + spice_gl_draw(ssd, x, y, w, h); + } } =20 static const DisplayChangeListenerOps display_listener_gl_ops =3D { --=20 2.49.0