From patchwork Fri Aug 19 13:39:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9290393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B07A2607FF for ; Fri, 19 Aug 2016 14:13:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D91429456 for ; Fri, 19 Aug 2016 14:13:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E42F29458; Fri, 19 Aug 2016 14:13:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A633529456 for ; Fri, 19 Aug 2016 14:13:40 +0000 (UTC) Received: from localhost ([::1]:57489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bakYE-0007Z8-RV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Aug 2016 10:13:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bakXz-0007Z1-Fv for qemu-devel@nongnu.org; Fri, 19 Aug 2016 10:13:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bakXw-0006Ns-7U for qemu-devel@nongnu.org; Fri, 19 Aug 2016 10:13:23 -0400 Received: from mail-he1eur01on0110.outbound.protection.outlook.com ([104.47.0.110]:52642 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bakXv-0006L2-7m for qemu-devel@nongnu.org; Fri, 19 Aug 2016 10:13:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=yGvxO8w0ZSEQ8xCpMowT/tE8uMrOUwiNzPmg660LsOo=; b=Yy3HVB7FEK1c89mjl8HuCjjbkbczyVrbVmS8zUKB3E1Gcz5XrMtcLfvugxIeG8dEmjhxnZMEeJ8hQgUEUXpqrKF9XNCwztwEq3YlYkx1oXGx/Xq6jnx89zTJE5CKgVVuggJkoI4189T+E4aJScdrh5H+WlLzDI10FefNdKsgF1E= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.10) by DB6PR0802MB2469.eurprd08.prod.outlook.com (10.172.251.17) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Fri, 19 Aug 2016 13:39:43 +0000 From: Roman Kagan To: Date: Fri, 19 Aug 2016 16:39:23 +0300 Message-ID: <1471613966-7267-5-git-send-email-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471613966-7267-1-git-send-email-rkagan@virtuozzo.com> References: <1471613966-7267-1-git-send-email-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM4PR01CA0021.eurprd01.prod.exchangelabs.com (10.164.74.159) To DB6PR0802MB2469.eurprd08.prod.outlook.com (10.172.251.17) X-MS-Office365-Filtering-Correlation-Id: ef7a5984-1a0a-49da-c068-08d3c8364775 X-Microsoft-Exchange-Diagnostics: 1;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ObwObas+1GKjnnG0INIbELk=; 4:PYi3A8kXzLpd5hKNMJSNdpbomOiWgaQXwTFg4juPmVy71NRWUqEzAGA0JONBgJ/h9K4PffCaXL3QTPAu0GYZx5ZDxw10VnGTMdAWl3gxE8AQN9riuH7yw6f7xF78Y/EVg8abySVQiFH9OExXVYzAuun4Osm2oTHWBrGIfxuQxIpWAeP/F70hRXp1NUoUlGhwtuLsaqGJksgMFfHLtbUAdjs7CJbodKmdLzcHmSNZeB5quGcTF29Eu9PubN/6mefIVQMMXY8swwebbCXnzu7lnhlmYD+nqRyoQ9QFSbdHIZKRqIeubsb+JSkyYtaWp13pOzy92559dcPDaFqjAGXxCX3tMk9jmzpeZTWmJy5yx0xfarZ84wcotjTfWmh3amALjqL/DLtvS+GUG++Y2tGj8QhPhgoBLynYnGrR/WGGeq4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6043046)(6042046); SRVR:DB6PR0802MB2469; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2469; X-Forefront-PRVS: 0039C6E5C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(43544003)(189002)(199003)(33646002)(229853001)(305945005)(7736002)(81156014)(92566002)(8676002)(81166006)(7846002)(48376002)(105586002)(47776003)(66066001)(50466002)(101416001)(2906002)(4326007)(586003)(36756003)(2351001)(106356001)(86362001)(50986999)(76176999)(3846002)(6116002)(77096005)(5003940100001)(19580395003)(69596002)(19580405001)(97736004)(189998001)(68736007)(2950100001)(53416004)(110136002)(42186005)(50226002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2469; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0802MB2469; 23:cGTB8OZOXR2J83+OO5dMCYyzmNWuBO/l957rcfj?= =?us-ascii?Q?YyrYyPVawSiIhKpydfcP8Ep+dY/HrXKe/vuzR7+EJ2f/qSgNNXr2oIHhUYdJ?= =?us-ascii?Q?lYoyj+Tdmk51UH/jq/txfsZTX6FiCJLlBP5DeeqvchfM1OmpmycQIu9fnbSO?= =?us-ascii?Q?408UYDPjjOfLEMrKNhao4neJhtrIzIaE7bRsYHKomT5kJp5QJ9SrJElOabm6?= =?us-ascii?Q?4lSMECWiYykDQIgrq7f4CqF0eAtMOIZ0FYHl8xQb+qinHZIokwsds39KqMQB?= =?us-ascii?Q?rDt6rCebglokzE+HPDldwNs7dyTirDf1nznSDEQ3SR1WFHYbpKxVivGO51u4?= =?us-ascii?Q?RcAUeXYHrRYA4J7q0kjeT8lozqubXBBrDBfWUMGEtB7n0J6V0ZOI2xMzl57S?= =?us-ascii?Q?Gg12aorJBTA6A+Uw3vxE0MIXFgKrYDgbT3cKEvidfYk4ZMU7FUBcCQS3dtVL?= =?us-ascii?Q?AGp2GwFmLZbtRz1wbsIYDseoWhcP77t3SU0dnpMBwdZcf9OL0SiTS0QpJyR7?= =?us-ascii?Q?fR3PlSxKeH0jYGJWJco4p88nmDZ1+LOigOyBnC2NkGZdgZtvHgSVUKJ2wO2M?= =?us-ascii?Q?FINRfZfX2MTplTpy9C9LARbkBDr24KY2H+vbewgz2OvCPzN+NPIXoALHnPRW?= =?us-ascii?Q?ETPVcq3AkBCoultfVvrn5B4yCkc8DaRj3y8mwGOy5QBtjL5p2diY6apCxUbT?= =?us-ascii?Q?l3NZ9HigPYcL9/y3w9dgQ30hpV0GRvlcJBfYitH3KVWdXWdZvE0PqrjyzoHP?= =?us-ascii?Q?lElKTeBeVE6Mum65OP7fQiXj8CC85aCEp+pXv4HoHkvn00kH/R8FGLH+uutU?= =?us-ascii?Q?vekh3iFS3IK+NYC3ZO9JAfUwiU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ZqFKFicxbeVD41ROsrgJITeOTR97+SLRzDu3YSl90nZ8X9KxzMOexXP+Uf5Uz1qSJ3UVYf4fV1RleBPpokNYeruuM51P6o7u/l7IKe2UJVjsGMqnkrORKwO6gUg+u/xX6/HUIctSkwv+AIcuutaxd1K5LopS9+5mEyRcsm1hVoR016XMU3ry3R+laZT2Jub8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2469; 20:AECDS5xzS1ViTViQ+AKp9ldllFpwDfw57OYWziJilTK+L+8dTkdjTQkc7dfYLO1M3ox8ARHVdChKbvWU3aAUCZrC6vpJ+6p+nZsriMhZuvdJJE5hBcCR1RNwkvAQfWRVNyDDlbfab0Foy9uiELV54w2VfRNBP22M9F/SM9gcqvY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2016 13:39:43.6365 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2469 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.110 Subject: [Qemu-devel] [PATCH v2 4/6] virtio-balloon: keep collecting stats on save/restore 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: "Denis V. Lunev" , Ladi Prosek , Roman Kagan , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Upon save/restore virtio-balloon stats acquisition stops. The reason is that the fact that the (only) virtqueue element is being used by QEMU is not recorded anywhere on save, so upon restore it's not released to the guest, making further progress impossible. Saving the information about the used element would introduce unjustified vmstate incompatibility. So instead just make sure the element is pushed before save, leaving the ball on the guest side. For that, add vm state change handler to virtio-ballon which would take care of pushing the element if there is one. Signed-off-by: Roman Kagan Cc: "Michael S. Tsirkin" Cc: Ladi Prosek Cc: Stefan Hajnoczi --- hw/virtio/virtio-balloon.c | 27 ++++++++++++++++++++++----- include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 6d4c57c..f00ad8e 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -88,10 +88,19 @@ static void balloon_stats_change_timer(VirtIOBalloon *s, int64_t secs) timer_mod(s->stats_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + secs * 1000); } +static void balloon_stats_push_elem(VirtIOBalloon *s) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(s); + + virtqueue_push(s->svq, s->stats_vq_elem, s->stats_vq_offset); + virtio_notify(vdev, s->svq); + g_free(s->stats_vq_elem); + s->stats_vq_elem = NULL; +} + static void balloon_stats_poll_cb(void *opaque) { VirtIOBalloon *s = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(s); if (!s->stats_vq_elem) { /* The guest hasn't sent the stats yet (either not enabled or we came @@ -100,10 +109,7 @@ static void balloon_stats_poll_cb(void *opaque) return; } - virtqueue_push(s->svq, s->stats_vq_elem, s->stats_vq_offset); - virtio_notify(vdev, s->svq); - g_free(s->stats_vq_elem); - s->stats_vq_elem = NULL; + balloon_stats_push_elem(s); } static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, @@ -414,6 +420,15 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f, return 0; } +static void balloon_vm_state_change(void *opaque, int running, RunState state) +{ + VirtIOBalloon *s = opaque; + + if (!running && s->stats_vq_elem) { + balloon_stats_push_elem(s); + } +} + static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -436,6 +451,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output); s->svq = virtio_add_queue(vdev, 1, virtio_balloon_receive_stats); + s->change = qemu_add_vm_change_state_handler(balloon_vm_state_change, s); reset_stats(s); } @@ -444,6 +460,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOBalloon *s = VIRTIO_BALLOON(dev); + qemu_del_vm_change_state_handler(s->change); balloon_stats_destroy_timer(s); qemu_remove_balloon_handler(s); virtio_cleanup(vdev); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index 1ea13bd..d72ff7f 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -43,6 +43,7 @@ typedef struct VirtIOBalloon { int64_t stats_last_update; int64_t stats_poll_interval; uint32_t host_features; + VMChangeStateEntry *change; } VirtIOBalloon; #endif