From patchwork Thu Aug 18 18:27:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9289141 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 9AA70600CB for ; Fri, 19 Aug 2016 02:03:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B1029185 for ; Fri, 19 Aug 2016 02:03:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D24C291AB; Fri, 19 Aug 2016 02:03:30 +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 C78B629185 for ; Fri, 19 Aug 2016 02:03:29 +0000 (UTC) Received: from localhost ([::1]:55002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baZ9a-0000kP-D3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Aug 2016 22:03:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baZ9K-0000f4-4U for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:03:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baZ9E-000332-2v for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:03:09 -0400 Received: from mail-ve1eur01on0116.outbound.protection.outlook.com ([104.47.1.116]:13120 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baZ9D-00032w-JG for qemu-devel@nongnu.org; Thu, 18 Aug 2016 22:03:04 -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=dGZsDP4y8RHDNPh/i94NXaUR4yD3HCa4lxTC3Kj/6E8=; b=BX0elwxMJhQtm67Xq3/0+6VsvSYcZn3RgJWSsN/piycJEQNdqRAJxcWe9DFaFWtueYcuNhuA52L249I7iX626+Vx2gRnecQorbkYL8+Y3mtYDu/OBvOi5ISBAFJ/fxifEip9Y/OVM6YLHf/lonviHVxWGcjTeTE5OpC2+EYNA2k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.10) by HE1PR0802MB2476.eurprd08.prod.outlook.com (10.175.34.149) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 18 Aug 2016 18:28:42 +0000 From: Roman Kagan To: Date: Thu, 18 Aug 2016 21:27:54 +0300 Message-ID: <1471544874-26996-5-git-send-email-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471544874-26996-1-git-send-email-rkagan@virtuozzo.com> References: <1471544874-26996-1-git-send-email-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: VI1PR07CA0121.eurprd07.prod.outlook.com (10.165.229.175) To HE1PR0802MB2476.eurprd08.prod.outlook.com (10.175.34.149) X-MS-Office365-Filtering-Correlation-Id: 28282c92-58ae-4e3e-295c-08d3c7957bac X-Microsoft-Exchange-Diagnostics: 1; HE1P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XYaMteGXHPO3WcTgddNKGYdzwA=; 4:c6Myrai+uR9jDAfaYV4LjjNo0Vb+u7psZ9BmSO1TQSLGhny1naPvBjHoX5U0owDBq3OTPfKABtwxvIeMVAisZCAhhh9fTAQRegg3KyeMfX2Kn6FOxlBmQXo4XM4upipx9n7ip1oR28GZBw1zDIVyjhBaWyVgHb32Y4989q8gU8AFl4ECdKdD1fl98Gii+gUu3aMLQlkCgMImPg6C5fjI7onKSJNL/lMgSHwsETzxXlknDRSlzTTrsL5RCa/cMrstPA8zWa/wJrWHrOM+SOBorVC9OO9Fbj+I5Y8B+ORn0rpQZ1BGHVHPMNl96RgaRfcbYzeVWrNnxHqCHhQdTmf3NhJvWXPpRTX6B48EJvSnqO04V6ghjN6zGXCrvawnaG7Qvx7oslhAYs0dp4dBO/ecqI6uVwAllbtQGDXfK779MgQ= 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)(10201501046)(3002001)(6043046)(6042046); SRVR:HE1PR0802MB2476; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0802MB2476; X-Forefront-PRVS: 0038DE95A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(43544003)(189002)(76176999)(19580405001)(7846002)(7736002)(50466002)(229853001)(50226002)(6116002)(2351001)(33646002)(4326007)(305945005)(47776003)(3846002)(2906002)(586003)(81156014)(8676002)(66066001)(101416001)(42186005)(86362001)(77096005)(81166006)(50986999)(53416004)(68736007)(97736004)(105586002)(5003940100001)(92566002)(189998001)(19580395003)(110136002)(48376002)(69596002)(106356001)(2950100001)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0802MB2476; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; HE1PR0802MB2476; 23:GREF4z6TEtjSI7z7H7Z224KIiyyf5je2vR2L/tV?= =?us-ascii?Q?XhKT12L2qDVh9/PyK+YhBNgLdLxpxM1ijZEsc/c0gPOxRGsmwnjrxkxCF5yv?= =?us-ascii?Q?5DKjtD/e6Dgw9xtbkOe+tcA1Y2frV/w4JxA9XwijCc4qBvkmA1dG+E51C4jd?= =?us-ascii?Q?yGBiY/C/KJJGzph69oUfoALIp1cZ3XdsoHcGMXGrIvXWMCG9kL/bZCv/04xs?= =?us-ascii?Q?zYjfnx7qNROmTWH0SLcmoaGWX7JHPFLleDv7J+O4XdA2iB657YF2CyFHqkyh?= =?us-ascii?Q?0K/7kKel9RZDBU+G3Hahwibku6vMKB0dpQQ0kkGDNzY6MCSP88ZfcyUyioj+?= =?us-ascii?Q?QcAJoxRmkEyyXKOAGknsL6qKuNy63Y/j8WZC67dznwSh8jEakJCvRHjTF1O0?= =?us-ascii?Q?gi3G1rvzrfBiSju7BJrf+EeUKZUe24LaP5CRBsotYnR5SF3/pXT2A3QhPdYO?= =?us-ascii?Q?LD6NjmfJUch9WB54tB1zkEu7ELzYjz2e9AsVs8Lym3YfxApSTu71TesgoHM3?= =?us-ascii?Q?bEExZb6F43VFN3TdfgZ2rjPObmV5vGfJUYQajncNx+7yRAKo9SLXOW7aMRfV?= =?us-ascii?Q?bxuod7cdcKjgznWeSzM9AeMCHz49xhk/gPXfVEyAZECb7ADmBAOFmOtGwpiA?= =?us-ascii?Q?477EobA4N+ByislypNDqS4o87TiYZ9mPjRByQSz7T8zDETPEVtfUlbDYhN3l?= =?us-ascii?Q?DBREQ6htrkDoJ15px6HSLHKFsRCtSYx5TkF5YIfiZC7qKoXvd/tm3OyZo9vw?= =?us-ascii?Q?Bse5QQjXaZtnLsJVi/k4FDb9IfiXZxrjoanoTvxRYB+UWvY7WvSdHVQjJRNQ?= =?us-ascii?Q?DaWLx0/QPuIOeENQe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g0vhHSpfaCGZnyjJF1wFDFaZXd/Vjl//IrV90fMW7yWE3sm+sEUe4RzBcy3pVX25oUk8fdjRN9Qo6VdvO6pLqLt2h8ltkkQkxw3W7CLb9R8/Rz/+ILlItrhnKV3qnYSRLKAqBz19vjHqRqTsGC8/lC728UQ6yanX4HZi7rfN5aYXHOQFhiqTh30UK+f3egVG3OCKn SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2476; 20:qweS0FpZKAZsCh/MRa0Xxzb4RTbrxHjW8q2xstsiJSDVytYdzzArUMRQv6Hh+XJyzPIlqUb+QbIyDn4G+bqVklc7wx/Xn6FlKMgI9pvT1JFh9CIGAIzrM7+zp9X3MqdntZVSByWA8Vhs2aQAeYjvgVhtBulL3aClqbhng/p7LFk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2016 18:28:42.2021 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2476 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.116 Subject: [Qemu-devel] [PATCH 4/4] 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" , Roman Kagan , "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" --- 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 b56fecd..66a926a 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, @@ -411,6 +417,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); @@ -433,6 +448,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); } @@ -441,6 +457,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