From nobody Mon Feb 9 10:29:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517916848111786.2187640309394; Tue, 6 Feb 2018 03:34:08 -0800 (PST) Received: from localhost ([::1]:58760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej1Vi-0000Vb-3o for importer@patchew.org; Tue, 06 Feb 2018 06:34:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej1PH-0003Nh-Dx for qemu-devel@nongnu.org; Tue, 06 Feb 2018 06:27:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej1PF-00010L-SD for qemu-devel@nongnu.org; Tue, 06 Feb 2018 06:27:23 -0500 Received: from mga14.intel.com ([192.55.52.115]:57904) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej1PF-0000w9-Gx for qemu-devel@nongnu.org; Tue, 06 Feb 2018 06:27:21 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 03:27:21 -0800 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga001.jf.intel.com with ESMTP; 06 Feb 2018 03:27:18 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,468,1511856000"; d="scan'208";a="29184993" From: Wei Wang To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org, mst@redhat.com, quintela@redhat.com, dgilbert@redhat.com Date: Tue, 6 Feb 2018 19:08:19 +0800 Message-Id: <1517915299-15349-4-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517915299-15349-1-git-send-email-wei.w.wang@intel.com> References: <1517915299-15349-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [PATCH v2 3/3] virtio-balloon: add a timer to limit the free page report waiting time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhang.wz@gmail.com, quan.xu0@gmail.com, liliang.opensource@gmail.com, wei.w.wang@intel.com, pbonzini@redhat.com, nilal@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds a timer to limit the time that host waits for the free page hints reported by the guest. Users can specify the time in ms via "free-page-wait-time" command line option. If a user doesn't specify a time, host waits till the guest finishes reporting all the free page hints. The policy (wait for all the free page hints to be reported or use a time limit) is determined by the orchestration layer. Signed-off-by: Wei Wang CC: Michael S. Tsirkin --- hw/virtio/virtio-balloon.c | 84 ++++++++++++++++++++++++++++++++++= +++- hw/virtio/virtio-pci.c | 3 ++ include/hw/virtio/virtio-balloon.h | 4 ++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index b424d4e..9ee0de4 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -207,6 +207,65 @@ static void balloon_stats_set_poll_interval(Object *ob= j, Visitor *v, balloon_stats_change_timer(s, 0); } =20 +static void balloon_free_page_change_timer(VirtIOBalloon *s, int64_t ms) +{ + timer_mod(s->free_page_timer, + qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + ms); +} + +static void balloon_stop_free_page_report(void *opaque) +{ + VirtIOBalloon *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + + timer_del(dev->free_page_timer); + timer_free(dev->free_page_timer); + dev->free_page_timer =3D NULL; + + if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_START) { + dev->host_stop_free_page =3D true; + virtio_notify_config(vdev); + } +} + +static void balloon_free_page_get_wait_time(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + VirtIOBalloon *s =3D opaque; + + visit_type_int(v, name, &s->free_page_wait_time, errp); +} + +static void balloon_free_page_set_wait_time(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + VirtIOBalloon *s =3D opaque; + Error *local_err =3D NULL; + int64_t value; + + visit_type_int(v, name, &value, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (value < 0) { + error_setg(errp, "free page wait time must be greater than zero"); + return; + } + + if (value > UINT32_MAX) { + error_setg(errp, "free page wait time value is too big"); + return; + } + + s->free_page_wait_time =3D value; + g_assert(s->free_page_timer =3D=3D NULL); + s->free_page_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, + balloon_stop_free_page_report, s); +} + static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VirtIOBalloon *s =3D VIRTIO_BALLOON(vdev); @@ -330,6 +389,7 @@ static void virtio_balloon_poll_free_page_hints(VirtIOB= alloon *dev) if (id =3D=3D dev->free_page_report_cmd_id) { dev->free_page_report_status =3D FREE_PAGE_REPORT_S_START; } else { + dev->host_stop_free_page =3D false; dev->free_page_report_status =3D FREE_PAGE_REPORT_S_STOP; break; } @@ -385,6 +445,10 @@ static void virtio_balloon_free_page_poll(void *opaque) virtio_notify_config(vdev); s->free_page_report_status =3D FREE_PAGE_REPORT_S_REQUESTED; =20 + if (s->free_page_wait_time) { + balloon_free_page_change_timer(s, s->free_page_wait_time); + } + virtio_balloon_poll_free_page_hints(s); } =20 @@ -395,7 +459,19 @@ static void virtio_balloon_get_config(VirtIODevice *vd= ev, uint8_t *config_data) =20 config.num_pages =3D cpu_to_le32(dev->num_pages); config.actual =3D cpu_to_le32(dev->actual); - config.free_page_report_cmd_id =3D cpu_to_le32(dev->free_page_report_c= md_id); + if (dev->host_stop_free_page) { + /* + * Host is actively requesting to stop the free page reporting, se= nd + * the stop sign to the guest. This happens when the migration thr= ead + * has reached the phase to send pages to the destination while the + * guest hasn't done the reporting. + */ + config.free_page_report_cmd_id =3D + VIRTIO_BALLOON_FREE_PAGE_REPORT_STOP_I= D; + } else { + config.free_page_report_cmd_id =3D + cpu_to_le32(dev->free_page_report_cmd_= id); + } =20 trace_virtio_balloon_get_config(config.num_pages, config.actual); memcpy(config_data, &config, sizeof(struct virtio_balloon_config)); @@ -539,6 +615,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, NUL= L); s->free_page_report_status =3D FREE_PAGE_REPORT_S_STOP; s->free_page_report_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_REPORT_STO= P_ID; + s->host_stop_free_page =3D false; } reset_stats(s); } @@ -602,6 +679,11 @@ static void virtio_balloon_instance_init(Object *obj) balloon_stats_get_poll_interval, balloon_stats_set_poll_interval, NULL, s, NULL); + + object_property_add(obj, "free-page-wait-time", "int", + balloon_free_page_get_wait_time, + balloon_free_page_set_wait_time, + NULL, s, NULL); } =20 static const VMStateDescription vmstate_virtio_balloon =3D { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 6c75cca..3345104 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2250,6 +2250,9 @@ static void virtio_balloon_pci_instance_init(Object *= obj) object_property_add_alias(obj, "guest-stats-polling-interval", OBJECT(&dev->vdev), "guest-stats-polling-interval", &error_abort= ); + object_property_add_alias(obj, "free-page-wait-time", + OBJECT(&dev->vdev), + "free-page-wait-time", &error_abort); } =20 static const TypeInfo virtio_balloon_pci_info =3D { diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index 11b4e01..c16855b 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -40,6 +40,8 @@ enum virtio_balloon_free_page_report_status { typedef struct VirtIOBalloon { VirtIODevice parent_obj; VirtQueue *ivq, *dvq, *svq, *free_page_vq; + /* Host is requesting the guest to stop free page reporting */ + bool host_stop_free_page; uint32_t free_page_report_status; uint32_t num_pages; uint32_t actual; @@ -49,8 +51,10 @@ typedef struct VirtIOBalloon { VirtQueueElement *stats_vq_elem; size_t stats_vq_offset; QEMUTimer *stats_timer; + QEMUTimer *free_page_timer; int64_t stats_last_update; int64_t stats_poll_interval; + int64_t free_page_wait_time; uint32_t host_features; } VirtIOBalloon; =20 --=20 1.8.3.1