From nobody Thu Nov 6 15:35:36 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.zoho.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 1489586464787194.26975338249338; Wed, 15 Mar 2017 07:01:04 -0700 (PDT) Received: from localhost ([::1]:37436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co9U2-0007Ph-SA for importer@patchew.org; Wed, 15 Mar 2017 10:00:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co9KQ-0007Z7-3l for qemu-devel@nongnu.org; Wed, 15 Mar 2017 09:51:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1co9KO-0003kX-NR for qemu-devel@nongnu.org; Wed, 15 Mar 2017 09:51:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1co9KO-0003kF-Av for qemu-devel@nongnu.org; Wed, 15 Mar 2017 09:51:00 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E7B23B731 for ; Wed, 15 Mar 2017 13:51:00 +0000 (UTC) Received: from secure.mitica (ovpn-116-230.ams2.redhat.com [10.36.116.230]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2FDoNUs002305; Wed, 15 Mar 2017 09:50:58 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E7B23B731 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4E7B23B731 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 15 Mar 2017 14:50:13 +0100 Message-Id: <20170315135021.6978-24-quintela@redhat.com> In-Reply-To: <20170315135021.6978-1-quintela@redhat.com> References: <20170315135021.6978-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 15 Mar 2017 13:51:00 +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] [PATCH 23/31] ram: Move migration_bitmap_rcu into RAMState 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: amit.shah@redhat.com, dgilbert@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" Once there, rename the type to be shorter. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 79 ++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c14293c..d39d185 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -132,6 +132,19 @@ out: return ret; } =20 +struct RAMBitmap { + struct rcu_head rcu; + /* Main migration bitmap */ + unsigned long *bmap; + /* bitmap of pages that haven't been sent even once + * only maintained and used in postcopy at the moment + * where it's used to send the dirtymap at the start + * of the postcopy phase + */ + unsigned long *unsentmap; +}; +typedef struct RAMBitmap RAMBitmap; + /* State of RAM for migration */ struct RAMState { /* Last block that we have visited searching for dirty pages */ @@ -180,6 +193,8 @@ struct RAMState { uint64_t migration_dirty_pages; /* protects modification of the bitmap */ QemuMutex bitmap_mutex; + /* Ram Bitmap protected by RCU */ + RAMBitmap *ram_bitmap; }; typedef struct RAMState RAMState; =20 @@ -236,18 +251,6 @@ struct PageSearchStatus { }; typedef struct PageSearchStatus PageSearchStatus; =20 -static struct BitmapRcu { - struct rcu_head rcu; - /* Main migration bitmap */ - unsigned long *bmap; - /* bitmap of pages that haven't been sent even once - * only maintained and used in postcopy at the moment - * where it's used to send the dirtymap at the start - * of the postcopy phase - */ - unsigned long *unsentmap; -} *migration_bitmap_rcu; - struct CompressParam { bool done; bool quit; @@ -554,7 +557,7 @@ ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RA= MBlock *rb, =20 unsigned long next; =20 - bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + bitmap =3D atomic_rcu_read(&rs->ram_bitmap)->bmap; if (rs->ram_bulk_stage && nr > base) { next =3D nr + 1; } else { @@ -569,7 +572,7 @@ static inline bool migration_bitmap_clear_dirty(RAMStat= e *rs, ram_addr_t addr) { bool ret; int nr =3D addr >> TARGET_PAGE_BITS; - unsigned long *bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + unsigned long *bitmap =3D atomic_rcu_read(&rs->ram_bitmap)->bmap; =20 ret =3D test_and_clear_bit(nr, bitmap); =20 @@ -583,7 +586,7 @@ static void migration_bitmap_sync_range(RAMState *rs, r= am_addr_t start, ram_addr_t length) { unsigned long *bitmap; - bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + bitmap =3D atomic_rcu_read(&rs->ram_bitmap)->bmap; rs-> migration_dirty_pages +=3D cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length); } @@ -1115,14 +1118,14 @@ static bool get_queued_page(RAMState *rs, Migration= State *ms, PageSearchStatus * */ if (block) { unsigned long *bitmap; - bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + bitmap =3D atomic_rcu_read(&rs->ram_bitmap)->bmap; dirty =3D test_bit(*ram_addr_abs >> TARGET_PAGE_BITS, bitmap); if (!dirty) { trace_get_queued_page_not_dirty( block->idstr, (uint64_t)offset, (uint64_t)*ram_addr_abs, test_bit(*ram_addr_abs >> TARGET_PAGE_BITS, - atomic_rcu_read(&migration_bitmap_rcu)->unsentmap= )); + atomic_rcu_read(&rs->ram_bitmap)->unsentmap)); } else { trace_get_queued_page(block->idstr, (uint64_t)offset, @@ -1276,7 +1279,7 @@ static int ram_save_target_page(RAMState *rs, Migrati= onState *ms, QEMUFile *f, if (res < 0) { return res; } - unsentmap =3D atomic_rcu_read(&migration_bitmap_rcu)->unsentmap; + unsentmap =3D atomic_rcu_read(&rs->ram_bitmap)->unsentmap; if (unsentmap) { clear_bit(dirty_ram_abs >> TARGET_PAGE_BITS, unsentmap); } @@ -1440,7 +1443,7 @@ void free_xbzrle_decoded_buf(void) xbzrle_decoded_buf =3D NULL; } =20 -static void migration_bitmap_free(struct BitmapRcu *bmap) +static void migration_bitmap_free(struct RAMBitmap *bmap) { g_free(bmap->bmap); g_free(bmap->unsentmap); @@ -1449,11 +1452,13 @@ static void migration_bitmap_free(struct BitmapRcu = *bmap) =20 static void ram_migration_cleanup(void *opaque) { + RAMState *rs =3D opaque; + /* caller have hold iothread lock or is in a bh, so there is * no writing race against this migration_bitmap */ - struct BitmapRcu *bitmap =3D migration_bitmap_rcu; - atomic_rcu_set(&migration_bitmap_rcu, NULL); + struct RAMBitmap *bitmap =3D rs->ram_bitmap; + atomic_rcu_set(&rs->ram_bitmap, NULL); if (bitmap) { memory_global_dirty_log_stop(); call_rcu(bitmap, migration_bitmap_free, rcu); @@ -1488,9 +1493,9 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr= _t new) /* called in qemu main thread, so there is * no writing race against this migration_bitmap */ - if (migration_bitmap_rcu) { - struct BitmapRcu *old_bitmap =3D migration_bitmap_rcu, *bitmap; - bitmap =3D g_new(struct BitmapRcu, 1); + if (ram_state.ram_bitmap) { + struct RAMBitmap *old_bitmap =3D ram_state.ram_bitmap, *bitmap; + bitmap =3D g_new(struct RAMBitmap, 1); bitmap->bmap =3D bitmap_new(new); =20 /* prevent migration_bitmap content from being set bit @@ -1508,7 +1513,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr= _t new) */ bitmap->unsentmap =3D NULL; =20 - atomic_rcu_set(&migration_bitmap_rcu, bitmap); + atomic_rcu_set(&ram_state.ram_bitmap, bitmap); qemu_mutex_unlock(&ram_state.bitmap_mutex); ram_state.migration_dirty_pages +=3D new - old; call_rcu(old_bitmap, migration_bitmap_free, rcu); @@ -1529,7 +1534,7 @@ void ram_debug_dump_bitmap(unsigned long *todump, boo= l expected) char linebuf[129]; =20 if (!todump) { - todump =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + todump =3D atomic_rcu_read(&ram_state.ram_bitmap)->bmap; } =20 for (cur =3D 0; cur < ram_pages; cur +=3D linelen) { @@ -1559,7 +1564,7 @@ void ram_debug_dump_bitmap(unsigned long *todump, boo= l expected) void ram_postcopy_migrated_memory_release(MigrationState *ms) { struct RAMBlock *block; - unsigned long *bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + unsigned long *bitmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->bmap; =20 QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { unsigned long first =3D block->offset >> TARGET_PAGE_BITS; @@ -1591,7 +1596,7 @@ static int postcopy_send_discard_bm_ram(MigrationStat= e *ms, unsigned long current; unsigned long *unsentmap; =20 - unsentmap =3D atomic_rcu_read(&migration_bitmap_rcu)->unsentmap; + unsentmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap; for (current =3D start; current < end; ) { unsigned long one =3D find_next_bit(unsentmap, end, current); =20 @@ -1680,8 +1685,8 @@ static void postcopy_chunk_hostpages_pass(MigrationSt= ate *ms, bool unsent_pass, return; } =20 - bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; - unsentmap =3D atomic_rcu_read(&migration_bitmap_rcu)->unsentmap; + bitmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->bmap; + unsentmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap; =20 if (unsent_pass) { /* Find a sent page */ @@ -1836,7 +1841,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *= ms) /* This should be our last sync, the src is now paused */ migration_bitmap_sync(&ram_state); =20 - unsentmap =3D atomic_rcu_read(&migration_bitmap_rcu)->unsentmap; + unsentmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->unsentmap; if (!unsentmap) { /* We don't have a safe way to resize the sentmap, so * if the bitmap was resized it will be NULL at this @@ -1857,7 +1862,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *= ms) /* * Update the unsentmap to be unsentmap =3D unsentmap | dirty */ - bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + bitmap =3D atomic_rcu_read(&ram_state.ram_bitmap)->bmap; bitmap_or(unsentmap, unsentmap, bitmap, last_ram_offset() >> TARGET_PAGE_BITS); =20 @@ -1950,16 +1955,16 @@ static int ram_state_init(RAMState *rs) bytes_transferred =3D 0; ram_state_reset(rs); =20 - migration_bitmap_rcu =3D g_new0(struct BitmapRcu, 1); + rs->ram_bitmap =3D g_new0(struct RAMBitmap, 1); /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { ram_bitmap_pages =3D last_ram_offset() >> TARGET_PAGE_BITS; - migration_bitmap_rcu->bmap =3D bitmap_new(ram_bitmap_pages); - bitmap_set(migration_bitmap_rcu->bmap, 0, ram_bitmap_pages); + rs->ram_bitmap->bmap =3D bitmap_new(ram_bitmap_pages); + bitmap_set(rs->ram_bitmap->bmap, 0, ram_bitmap_pages); =20 if (migrate_postcopy_ram()) { - migration_bitmap_rcu->unsentmap =3D bitmap_new(ram_bitmap_page= s); - bitmap_set(migration_bitmap_rcu->unsentmap, 0, ram_bitmap_page= s); + rs->ram_bitmap->unsentmap =3D bitmap_new(ram_bitmap_pages); + bitmap_set(rs->ram_bitmap->unsentmap, 0, ram_bitmap_pages); } } =20 --=20 2.9.3