From nobody Wed Nov 5 09:21:27 2025 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499707046440890.4062738638969; Mon, 10 Jul 2017 10:17:26 -0700 (PDT) Received: from localhost ([::1]:42205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUcJJ-0001uY-7M for importer@patchew.org; Mon, 10 Jul 2017 13:17:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUcD6-0004wT-0j for qemu-devel@nongnu.org; Mon, 10 Jul 2017 13:11:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUcD3-0008TS-Ch for qemu-devel@nongnu.org; Mon, 10 Jul 2017 13:10:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUcD3-0008RG-3R for qemu-devel@nongnu.org; Mon, 10 Jul 2017 13:10:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27CFD49003 for ; Mon, 10 Jul 2017 17:10:56 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-116-231.ams2.redhat.com [10.36.116.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14FC317114; Mon, 10 Jul 2017 17:10:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27CFD49003 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dgilbert@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27CFD49003 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 18:10:39 +0100 Message-Id: <20170710171040.21021-9-dgilbert@redhat.com> In-Reply-To: <20170710171040.21021-1-dgilbert@redhat.com> References: <20170710171040.21021-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 17:10:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/9] migration: Convert ram to use new load_setup()/load_cleanup() 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: lvivier@redhat.com, peterx@redhat.com, quintela@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" From: Juan Quintela Once there, I rename ram_migration_cleanup() to ram_save_cleanup(). Notice that this is the first pass, and I only passed XBZRLE to the new scheme. Moved decoded_buf to inside XBZRLE struct. As a bonus, I don't have to export xbzrle functions from ram.c. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- loaded_data pointer was needed because called can change it (dave) spell loaded correctly in comment (dave) Message-Id: <20170628095228.4661-5-quintela@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 3 --- migration/ram.c | 49 ++++++++++++++++++++++++++++++++++++-----------= -- migration/ram.h | 1 - 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index beea01ce63..7e5dbd9b92 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -352,9 +352,6 @@ static void process_incoming_migration_co(void *opaque) migrate_decompress_threads_join(); exit(EXIT_FAILURE); } - - free_xbzrle_decoded_buf(); - mis->bh =3D qemu_bh_new(process_incoming_migration_bh, mis); qemu_bh_schedule(mis->bh); } diff --git a/migration/ram.c b/migration/ram.c index 649f76cb52..73aec34161 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -85,11 +85,10 @@ static struct { QemuMutex lock; /* it will store a page full of zeros */ uint8_t *zero_target_page; + /* buffer used for XBZRLE decoding */ + uint8_t *decoded_buf; } XBZRLE; =20 -/* buffer used for XBZRLE decoding */ -static uint8_t *xbzrle_decoded_buf; - static void XBZRLE_cache_lock(void) { if (migrate_use_xbzrle()) @@ -1350,13 +1349,18 @@ uint64_t ram_bytes_total(void) return total; } =20 -void free_xbzrle_decoded_buf(void) +static void xbzrle_load_setup(void) { - g_free(xbzrle_decoded_buf); - xbzrle_decoded_buf =3D NULL; + XBZRLE.decoded_buf =3D g_malloc(TARGET_PAGE_SIZE); } =20 -static void ram_migration_cleanup(void *opaque) +static void xbzrle_load_cleanup(void) +{ + g_free(XBZRLE.decoded_buf); + XBZRLE.decoded_buf =3D NULL; +} + +static void ram_save_cleanup(void *opaque) { RAMState **rsp =3D opaque; RAMBlock *block; @@ -2078,11 +2082,6 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr,= void *host) int xh_flags; uint8_t *loaded_data; =20 - if (!xbzrle_decoded_buf) { - xbzrle_decoded_buf =3D g_malloc(TARGET_PAGE_SIZE); - } - loaded_data =3D xbzrle_decoded_buf; - /* extract RLE header */ xh_flags =3D qemu_get_byte(f); xh_len =3D qemu_get_be16(f); @@ -2096,7 +2095,9 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, = void *host) error_report("Failed to load XBZRLE page - len overflow!"); return -1; } + loaded_data =3D XBZRLE.decoded_buf; /* load data and decode */ + /* it can change loaded_data to point to an internal buffer */ qemu_get_buffer_in_place(f, &loaded_data, xh_len); =20 /* decode RLE */ @@ -2310,6 +2311,26 @@ static void decompress_data_with_multi_threads(QEMUF= ile *f, } =20 /** + * ram_load_setup: Setup RAM for migration incoming side + * + * Returns zero to indicate success and negative for error + * + * @f: QEMUFile where to receive the data + * @opaque: RAMState pointer + */ +static int ram_load_setup(QEMUFile *f, void *opaque) +{ + xbzrle_load_setup(); + return 0; +} + +static int ram_load_cleanup(void *opaque) +{ + xbzrle_load_cleanup(); + return 0; +} + +/** * ram_postcopy_incoming_init: allocate postcopy data structures * * Returns 0 for success and negative if there was one error @@ -2629,7 +2650,9 @@ static SaveVMHandlers savevm_ram_handlers =3D { .save_live_complete_precopy =3D ram_save_complete, .save_live_pending =3D ram_save_pending, .load_state =3D ram_load, - .save_cleanup =3D ram_migration_cleanup, + .save_cleanup =3D ram_save_cleanup, + .load_setup =3D ram_load_setup, + .load_cleanup =3D ram_load_cleanup, }; =20 void ram_mig_init(void) diff --git a/migration/ram.h b/migration/ram.h index 6272eb0007..a8b79a4d4c 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -47,7 +47,6 @@ void migrate_decompress_threads_join(void); uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); void acct_update_position(QEMUFile *f, size_t size, bool zero); -void free_xbzrle_decoded_buf(void); void ram_debug_dump_bitmap(unsigned long *todump, bool expected, unsigned long pages); void ram_postcopy_migrated_memory_release(MigrationState *ms); --=20 2.13.0