From nobody Sat Nov 15 20:34:36 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=1748495816; cv=none; d=zohomail.com; s=zohoarc; b=ZtmqOCf0lCKaP296A6aZuRLt/5qn3Bqcol+ND18I5tdd85QxSCii0LUxZ56U1qSrWV+HRfGBEFG+XkJOiyc4TWcc7teHiKOU2J/IZcBKZo4dNEr/P2UlvYdO/CseO+TSrqSRE8Eg6qrE7Nz04NyafXUAXbLSf8VES3g9gyw7Ra4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748495816; 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=nhTSwK4uuPGNZXGux8Gv4mSyrajPACjTPsXbHcBW6Qw=; b=S02MLoL0+zNoOx4DTwDNjZQdgH+8XL9RC/lbOKC5icn/kRf7d1JeemTjCeZyKrUvtGir1P8DkT0OFWvWFXEGWBYao72h5r2vWW33uKpG6oTZWTabruX9O2dCqet/PLig8yRpmfRUGreEvyJBY94y8avHWPQumRoVty60oLYPOoU= 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 1748495816284234.34575847639474; Wed, 28 May 2025 22:16:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKVcr-0007ym-20; Thu, 29 May 2025 01:16:21 -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 1uKVcg-0007wv-D5 for qemu-devel@nongnu.org; Thu, 29 May 2025 01:16:13 -0400 Received: from mgamail.intel.com ([198.175.65.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uKVca-0008GJ-Pz for qemu-devel@nongnu.org; Thu, 29 May 2025 01:16:10 -0400 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2025 22:15:26 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2025 22:15:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1748495765; x=1780031765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cT3Vr4u3LFYtemGbo8vgKnjPHY2jUHGA9ai8u8i8k0s=; b=Fx+yoVw2byopd1/pHyi76PX2T1bmiQ/As0NimAHIY25ZYWF2TWbtYqua +aIwPZW8yPlv/gsrl8bVpBn9RBsYfNUojed3pTbDmjnxSohX+2ymB+FgL P8PjySWb7Zz379zxc3xR99uKaxIxxq2LE3vGDPzLR1PxWu/R45f1SR4SC nHtslPYLUncKqdHCXE5LjIAtvLCleHMEh2gsSbdMyrvhqnxPmgat1rgm8 h0mMqiIw9d4jLsa2aVCwM1Bk3tpmixhMUslG6L/L91oaZ1EUgwYrLWH5T lQ8KI1jZoOsc0+Fh/9GJMeHK9L78sc/nF8l9zmNXwhBbc4GDpOc7+MLTv A==; X-CSE-ConnectionGUID: gYH0UoCDTGC4WAeyxKFSfA== X-CSE-MsgGUID: Lj6Lf7jaQUCMnTVM681OlQ== X-IronPort-AV: E=McAfee;i="6700,10204,11447"; a="50241898" X-IronPort-AV: E=Sophos;i="6.15,323,1739865600"; d="scan'208";a="50241898" X-CSE-ConnectionGUID: Q++Bj9mbQOmYB0eyGLfh1w== X-CSE-MsgGUID: Q3Ra1WtlS5CMq0idtxhp3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,323,1739865600"; d="scan'208";a="174455344" 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 v5 4/7] ui/spice: Add an option to submit gl_draw requests at fixed rate Date: Wed, 28 May 2025 22:11:15 -0700 Message-ID: <20250529051352.1409904-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250529051352.1409904-1-vivek.kasireddy@intel.com> References: <20250529051352.1409904-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.20; envelope-from=vivek.kasireddy@intel.com; helo=mgamail.intel.com X-Spam_score_int: -72 X-Spam_score: -7.3 X-Spam_bar: ------- X-Spam_report: (-7.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.904, 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1748495818170116600 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 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 fcddb583c9..98af43953d 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-codecs=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", @@ -2374,6 +2375,10 @@ SRST Provide the preferred codec the Spice server should use. Default would be spice:mjpeg. =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 f92dd55392..6576bfd20d 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-codecs", .type =3D QEMU_OPT_STRING, + },{ + .name =3D "max-refresh-rate", + .type =3D QEMU_OPT_NUMBER, },{ .name =3D "agent-mouse", .type =3D QEMU_OPT_BOOL, @@ -813,6 +818,13 @@ static void qemu_spice_init(void) } } =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