From nobody Sun Oct 26 01:41:55 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514958180341855.2689298219109; Tue, 2 Jan 2018 21:43:00 -0800 (PST) Received: from localhost ([::1]:40577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbpA-00045g-49 for importer@patchew.org; Wed, 03 Jan 2018 00:42:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnJ-0002ug-VD for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnI-0000pU-BD for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnI-0000ok-5V for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5904CC057FA1 for ; Wed, 3 Jan 2018 05:40:51 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9815F6199F; Wed, 3 Jan 2018 05:40:49 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:33 +0800 Message-Id: <20180103054043.25719-2-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 03 Jan 2018 05:40:51 +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 01/11] migration: assert colo instead of check 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" When reaching here if we are still "active" it means we must be in colo state. Assert it instead of check it in if condition. Finally I want to use "switch" here rather than lots of complicated if clauses. Signed-off-by: Peter Xu --- migration/migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 4de3b551fe..0ee4b4c27c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2309,7 +2309,8 @@ static void *migration_thread(void *opaque) } runstate_set(RUN_STATE_POSTMIGRATE); } else { - if (s->state =3D=3D MIGRATION_STATUS_ACTIVE && enable_colo) { + if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + assert(enable_colo); migrate_start_colo_process(s); qemu_savevm_state_cleanup(); /* --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958310900599.0513392426171; Tue, 2 Jan 2018 21:45:10 -0800 (PST) Received: from localhost ([::1]:40614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbrS-0006iW-3s for importer@patchew.org; Wed, 03 Jan 2018 00:45:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnL-0002v6-Jv for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnK-0000r7-O4 for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59830) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnK-0000qX-Ht for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93BA8368E6 for ; Wed, 3 Jan 2018 05:40:53 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF84F6198E; Wed, 3 Jan 2018 05:40:51 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:34 +0800 Message-Id: <20180103054043.25719-3-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 03 Jan 2018 05:40:53 +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 02/11] migration: qemu_savevm_state_cleanup() in 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" Moving existing callers all into migrate_fd_cleanup(). It simplifies migration_thread() a bit. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 0ee4b4c27c..edbda43246 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1077,6 +1077,8 @@ static void migrate_fd_cleanup(void *opaque) qemu_bh_delete(s->cleanup_bh); s->cleanup_bh =3D NULL; =20 + qemu_savevm_state_cleanup(); + if (s->to_dst_file) { Error *local_err =3D NULL; =20 @@ -2290,13 +2292,6 @@ static void *migration_thread(void *opaque) end_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); =20 qemu_mutex_lock_iothread(); - /* - * The resource has been allocated by migration will be reused in COLO - * process, so don't release them. - */ - if (!enable_colo) { - qemu_savevm_state_cleanup(); - } if (s->state =3D=3D MIGRATION_STATUS_COMPLETED) { uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file); s->total_time =3D end_time - s->total_time; @@ -2312,7 +2307,6 @@ static void *migration_thread(void *opaque) if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { assert(enable_colo); migrate_start_colo_process(s); - qemu_savevm_state_cleanup(); /* * Fixme: we will run VM in COLO no matter its old running stat= e. * After exited COLO, we will keep running. --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151495818337247.38726195582262; Tue, 2 Jan 2018 21:43:03 -0800 (PST) Received: from localhost ([::1]:40579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbpG-0004B0-Ds for importer@patchew.org; Wed, 03 Jan 2018 00:42:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnN-0002yB-IP for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnM-0000su-Sj for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnM-0000sI-MM for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD0EFC0587FD for ; Wed, 3 Jan 2018 05:40:55 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14F7360C9B; Wed, 3 Jan 2018 05:40:53 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:35 +0800 Message-Id: <20180103054043.25719-4-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 03 Jan 2018 05:40:55 +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 03/11] migration: remove "enable_colo" var 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" It's only used once, clean it up a bit. Signed-off-by: Peter Xu --- migration/migration.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index edbda43246..20f7565527 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2177,7 +2177,6 @@ static void *migration_thread(void *opaque) bool entered_postcopy =3D false; /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ enum MigrationStatus current_active_state =3D MIGRATION_STATUS_ACTIVE; - bool enable_colo =3D migrate_colo_enabled(); =20 rcu_register_thread(); =20 @@ -2305,7 +2304,7 @@ static void *migration_thread(void *opaque) runstate_set(RUN_STATE_POSTMIGRATE); } else { if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - assert(enable_colo); + assert(migrate_colo_enabled()); migrate_start_colo_process(s); /* * Fixme: we will run VM in COLO no matter its old running stat= e. --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 15149581919431004.2801610787493; Tue, 2 Jan 2018 21:43:11 -0800 (PST) Received: from localhost ([::1]:40580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbpN-0004JH-O1 for importer@patchew.org; Wed, 03 Jan 2018 00:43:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnS-00033A-CI for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnP-0000ut-4l for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnO-0000uE-Sr for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:40:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C6D67E423 for ; Wed, 3 Jan 2018 05:40:58 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49B4F6198E; Wed, 3 Jan 2018 05:40:56 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:36 +0800 Message-Id: <20180103054043.25719-5-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 03 Jan 2018 05:40:58 +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 04/11] migration: split use of MigrationState.total_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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" It was used either to: 1. store initial timestamp of migration start, and 2. store total time used by last migration Let's provide two parameters for each of them. Mix use of the two is slightly misleading. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 13 +++++++------ migration/migration.h | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 20f7565527..b684c2005d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -613,7 +613,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->has_status =3D true; info->has_total_time =3D true; info->total_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - - s->total_time; + - s->mig_start_time; info->has_expected_downtime =3D true; info->expected_downtime =3D s->expected_downtime; info->has_setup_time =3D true; @@ -629,7 +629,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) case MIGRATION_STATUS_COMPLETED: info->has_status =3D true; info->has_total_time =3D true; - info->total_time =3D s->total_time; + info->total_time =3D s->mig_total_time; info->has_downtime =3D true; info->downtime =3D s->downtime; info->has_setup_time =3D true; @@ -1270,7 +1270,8 @@ MigrationState *migrate_init(void) =20 migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_S= ETUP); =20 - s->total_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + s->mig_start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + s->mig_total_time =3D 0; return s; } =20 @@ -2293,13 +2294,13 @@ static void *migration_thread(void *opaque) qemu_mutex_lock_iothread(); if (s->state =3D=3D MIGRATION_STATUS_COMPLETED) { uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file); - s->total_time =3D end_time - s->total_time; + s->mig_total_time =3D end_time - s->mig_start_time; if (!entered_postcopy) { s->downtime =3D end_time - start_time; } - if (s->total_time) { + if (s->mig_total_time) { s->mbps =3D (((double) transferred_bytes * 8.0) / - ((double) s->total_time)) / 1000; + ((double) s->mig_total_time)) / 1000; } runstate_set(RUN_STATE_POSTMIGRATE); } else { diff --git a/migration/migration.h b/migration/migration.h index 663415fe48..ac74a12713 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -103,7 +103,10 @@ struct MigrationState } rp_state; =20 double mbps; - int64_t total_time; + /* Timestamp when recent migration starts (ms) */ + int64_t mig_start_time; + /* Total time used by latest migration (ms) */ + int64_t mig_total_time; int64_t downtime; int64_t expected_downtime; bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958315282392.8025488479541; Tue, 2 Jan 2018 21:45:15 -0800 (PST) Received: from localhost ([::1]:40616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbrW-0006m4-FI for importer@patchew.org; Wed, 03 Jan 2018 00:45:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnS-00033G-Ge for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnR-0000wd-Du for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnR-0000w4-5n for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 549305AFED for ; Wed, 3 Jan 2018 05:41:00 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C2DC6198E; Wed, 3 Jan 2018 05:40:58 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:37 +0800 Message-Id: <20180103054043.25719-6-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 03 Jan 2018 05:41: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 05/11] migration: move vm_old_running into global state 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" Firstly, it was passed around. Let's just move it into MigrationState just like many other variables as state of migration. One thing to mention is that for postcopy, we actually don't need this knowledge at all since postcopy can't resume a VM even if it fails (we can see that from the old code too: when we try to resume we also check against "entered_postcopy" variable). So further we do this: - in postcopy_start(), we don't update vm_old_running since useless - in migration_thread(), we don't need to check entered_postcopy when resume, since it's only used for precopy. Comment this out too for that variable definition. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 17 +++++++---------- migration/migration.h | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b684c2005d..62b3766852 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1272,6 +1272,7 @@ MigrationState *migrate_init(void) =20 s->mig_start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); s->mig_total_time =3D 0; + s->old_vm_running =3D false; return s; } =20 @@ -1846,7 +1847,7 @@ static int await_return_path_close_on_source(Migratio= nState *ms) * Switch from normal iteration to postcopy * Returns non-0 on error */ -static int postcopy_start(MigrationState *ms, bool *old_vm_running) +static int postcopy_start(MigrationState *ms) { int ret; QIOChannelBuffer *bioc; @@ -1864,7 +1865,6 @@ static int postcopy_start(MigrationState *ms, bool *o= ld_vm_running) trace_postcopy_start_set_run(); =20 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); - *old_vm_running =3D runstate_is_running(); global_state_store(); ret =3D vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); if (ret < 0) { @@ -2055,11 +2055,9 @@ static int migration_maybe_pause(MigrationState *s, * * @s: Current migration state * @current_active_state: The migration state we expect to be in - * @*old_vm_running: Pointer to old_vm_running flag * @*start_time: Pointer to time to update */ static void migration_completion(MigrationState *s, int current_active_sta= te, - bool *old_vm_running, int64_t *start_time) { int ret; @@ -2068,7 +2066,7 @@ static void migration_completion(MigrationState *s, i= nt current_active_state, qemu_mutex_lock_iothread(); *start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); - *old_vm_running =3D runstate_is_running(); + s->old_vm_running =3D runstate_is_running(); ret =3D global_state_store(); =20 if (!ret) { @@ -2174,7 +2172,6 @@ static void *migration_thread(void *opaque) int64_t threshold_size =3D 0; int64_t start_time =3D initial_time; int64_t end_time; - bool old_vm_running =3D false; bool entered_postcopy =3D false; /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ enum MigrationStatus current_active_state =3D MIGRATION_STATUS_ACTIVE; @@ -2233,7 +2230,7 @@ static void *migration_thread(void *opaque) pend_nonpost <=3D threshold_size && atomic_read(&s->start_postcopy)) { =20 - if (!postcopy_start(s, &old_vm_running)) { + if (!postcopy_start(s)) { current_active_state =3D MIGRATION_STATUS_POSTCOPY= _ACTIVE; entered_postcopy =3D true; } @@ -2245,7 +2242,7 @@ static void *migration_thread(void *opaque) } else { trace_migration_thread_low_pending(pending_size); migration_completion(s, current_active_state, - &old_vm_running, &start_time); + &start_time); break; } } @@ -2311,9 +2308,9 @@ static void *migration_thread(void *opaque) * Fixme: we will run VM in COLO no matter its old running stat= e. * After exited COLO, we will keep running. */ - old_vm_running =3D true; + s->old_vm_running =3D true; } - if (old_vm_running && !entered_postcopy) { + if (s->old_vm_running) { vm_start(); } else { if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { diff --git a/migration/migration.h b/migration/migration.h index ac74a12713..0f5df2367c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -111,6 +111,12 @@ struct MigrationState int64_t expected_downtime; bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; int64_t setup_time; + /* + * Whether the old VM is running for the last migration. This is + * used to resume the VM when precopy failed or cancelled somehow. + * It's never used for postcopy. + */ + bool old_vm_running; =20 /* Flag set once the migration has been asked to enter postcopy */ bool start_postcopy; --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958308653364.6298869611618; Tue, 2 Jan 2018 21:45:08 -0800 (PST) Received: from localhost ([::1]:40613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbrP-0006hT-QJ for importer@patchew.org; Wed, 03 Jan 2018 00:45:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnV-00035s-1q for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnU-00010h-2m for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnT-0000yv-Ql for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0002E81DE9 for ; Wed, 3 Jan 2018 05:41:02 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C61A760C9B; Wed, 3 Jan 2018 05:41:00 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:38 +0800 Message-Id: <20180103054043.25719-7-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 03 Jan 2018 05:41:03 +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 06/11] migration: introduce vm_down_start_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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" Introduce MigrationState.vm_down_start_time to replace the local variable "start_time" in migration_thread to avoid passing things around. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 12 ++++-------- migration/migration.h | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 62b3766852..2d8b47197e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2055,16 +2055,14 @@ static int migration_maybe_pause(MigrationState *s, * * @s: Current migration state * @current_active_state: The migration state we expect to be in - * @*start_time: Pointer to time to update */ -static void migration_completion(MigrationState *s, int current_active_sta= te, - int64_t *start_time) +static void migration_completion(MigrationState *s, int current_active_sta= te) { int ret; =20 if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { qemu_mutex_lock_iothread(); - *start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + s->vm_down_start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); s->old_vm_running =3D runstate_is_running(); ret =3D global_state_store(); @@ -2170,7 +2168,6 @@ static void *migration_thread(void *opaque) * measured bandwidth */ int64_t threshold_size =3D 0; - int64_t start_time =3D initial_time; int64_t end_time; bool entered_postcopy =3D false; /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ @@ -2241,8 +2238,7 @@ static void *migration_thread(void *opaque) qemu_savevm_state_iterate(s->to_dst_file, entered_postcopy= ); } else { trace_migration_thread_low_pending(pending_size); - migration_completion(s, current_active_state, - &start_time); + migration_completion(s, current_active_state); break; } } @@ -2293,7 +2289,7 @@ static void *migration_thread(void *opaque) uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file); s->mig_total_time =3D end_time - s->mig_start_time; if (!entered_postcopy) { - s->downtime =3D end_time - start_time; + s->downtime =3D end_time - s->vm_down_start_time; } if (s->mig_total_time) { s->mbps =3D (((double) transferred_bytes * 8.0) / diff --git a/migration/migration.h b/migration/migration.h index 0f5df2367c..3ab5506233 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -107,6 +107,8 @@ struct MigrationState int64_t mig_start_time; /* Total time used by latest migration (ms) */ int64_t mig_total_time; + /* Timestamp when VM is down (ms) to migrate the last stuff */ + int64_t vm_down_start_time; int64_t downtime; int64_t expected_downtime; bool enabled_capabilities[MIGRATION_CAPABILITY__MAX]; --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958452871795.9805397227803; Tue, 2 Jan 2018 21:47:32 -0800 (PST) Received: from localhost ([::1]:40651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbtk-0000Dw-1w for importer@patchew.org; Wed, 03 Jan 2018 00:47:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnc-0003DI-Bz for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnZ-00015X-4A for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnY-00014o-UF for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C75F37E6E for ; Wed, 3 Jan 2018 05:41:08 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B0FD619A3; Wed, 3 Jan 2018 05:41:03 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:39 +0800 Message-Id: <20180103054043.25719-8-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 03 Jan 2018 05:41:08 +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 07/11] migration: introduce migrate_calculate_complete 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" Generalize the calculation part when migration complete into a function to simplify migration_thread(). Signed-off-by: Peter Xu --- migration/migration.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2d8b47197e..acef54748b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2151,6 +2151,19 @@ bool migrate_colo_enabled(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_X_COLO]; } =20 +static void migration_calculate_complete(MigrationState *s) +{ + uint64_t bytes =3D qemu_ftell(s->to_dst_file); + int64_t end_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + + s->mig_total_time =3D end_time - s->mig_start_time; + s->downtime =3D end_time - s->vm_down_start_time; + + if (s->mig_total_time) { + s->mbps =3D ((double) bytes * 8.0) / s->mig_total_time / 1000; + } +} + /* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -2168,7 +2181,6 @@ static void *migration_thread(void *opaque) * measured bandwidth */ int64_t threshold_size =3D 0; - int64_t end_time; bool entered_postcopy =3D false; /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ enum MigrationStatus current_active_state =3D MIGRATION_STATUS_ACTIVE; @@ -2282,19 +2294,10 @@ static void *migration_thread(void *opaque) trace_migration_thread_after_loop(); /* If we enabled cpu throttling for auto-converge, turn it off. */ cpu_throttle_stop(); - end_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); =20 qemu_mutex_lock_iothread(); if (s->state =3D=3D MIGRATION_STATUS_COMPLETED) { - uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file); - s->mig_total_time =3D end_time - s->mig_start_time; - if (!entered_postcopy) { - s->downtime =3D end_time - s->vm_down_start_time; - } - if (s->mig_total_time) { - s->mbps =3D (((double) transferred_bytes * 8.0) / - ((double) s->mig_total_time)) / 1000; - } + migration_calculate_complete(s); runstate_set(RUN_STATE_POSTMIGRATE); } else { if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958454914746.4003105495734; Tue, 2 Jan 2018 21:47:34 -0800 (PST) Received: from localhost ([::1]:40653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbtm-0000G1-4h for importer@patchew.org; Wed, 03 Jan 2018 00:47:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnc-0003DG-B7 for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbnb-00016W-BM for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnb-000163-53 for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48D5681DF3 for ; Wed, 3 Jan 2018 05:41:10 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DA946198E; Wed, 3 Jan 2018 05:41:08 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:40 +0800 Message-Id: <20180103054043.25719-9-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 03 Jan 2018 05:41:10 +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 08/11] migration: use switch at the end of migration 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" It converts the old if clauses into switch, explicitly mentions the possible migration states. The old nested "if"s are not clear on what we do on different states. Signed-off-by: Peter Xu --- migration/migration.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index acef54748b..bfcba24caa 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2296,19 +2296,23 @@ static void *migration_thread(void *opaque) cpu_throttle_stop(); =20 qemu_mutex_lock_iothread(); - if (s->state =3D=3D MIGRATION_STATUS_COMPLETED) { + switch (s->state) { + case MIGRATION_STATUS_COMPLETED: migration_calculate_complete(s); runstate_set(RUN_STATE_POSTMIGRATE); - } else { - if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - assert(migrate_colo_enabled()); - migrate_start_colo_process(s); - /* - * Fixme: we will run VM in COLO no matter its old running stat= e. - * After exited COLO, we will keep running. - */ - s->old_vm_running =3D true; - } + break; + + case MIGRATION_STATUS_ACTIVE: + assert(migrate_colo_enabled()); + migrate_start_colo_process(s); + /* + * Fixme: we will run VM in COLO no matter its old running state. + * After exited COLO, we will keep running. + */ + s->old_vm_running =3D true; + /* Fallthrough */ + case MIGRATION_STATUS_FAILED: + case MIGRATION_STATUS_CANCELLED: if (s->old_vm_running) { vm_start(); } else { @@ -2316,6 +2320,12 @@ static void *migration_thread(void *opaque) runstate_set(RUN_STATE_POSTMIGRATE); } } + break; + + default: + /* Should not reach here, but if so, forgive the VM. */ + error_report("%s: Unknown ending state %d", __func__, s->state); + break; } qemu_bh_schedule(s->cleanup_bh); qemu_mutex_unlock_iothread(); --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 1514958461797950.4012734195478; Tue, 2 Jan 2018 21:47:41 -0800 (PST) Received: from localhost ([::1]:40654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbts-0000Jy-T3 for importer@patchew.org; Wed, 03 Jan 2018 00:47:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnf-0003FE-8y for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbne-00018Y-40 for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbnd-00017t-Qv for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03A475F7AC for ; Wed, 3 Jan 2018 05:41:13 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id B54716199F; Wed, 3 Jan 2018 05:41:10 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:41 +0800 Message-Id: <20180103054043.25719-10-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 03 Jan 2018 05:41:13 +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 09/11] migration: cleanup stats update into function 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" We have quite a few lines in migration_thread() that calculates some statistics for the migration interations. Isolate it into a single function to improve readability. Signed-off-by: Peter Xu --- migration/migration.c | 82 +++++++++++++++++++++++++++++------------------= ---- migration/migration.h | 13 ++++++++ 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bfcba24caa..2629f907e9 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1273,6 +1273,8 @@ MigrationState *migrate_init(void) s->mig_start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); s->mig_total_time =3D 0; s->old_vm_running =3D false; + s->initial_bytes =3D 0; + s->threshold_size =3D 0; return s; } =20 @@ -2164,6 +2166,39 @@ static void migration_calculate_complete(MigrationSt= ate *s) } } =20 +static void migration_update_statistics(MigrationState *s, + int64_t current_time) +{ + uint64_t transferred =3D qemu_ftell(s->to_dst_file) - s->initial_bytes; + uint64_t time_spent =3D current_time - s->initial_time; + double bandwidth =3D (double)transferred / time_spent; + int64_t threshold_size =3D bandwidth * s->parameters.downtime_limit; + + if (current_time < s->initial_time + BUFFER_DELAY) { + return; + } + + s->mbps =3D (((double) transferred * 8.0) / + ((double) time_spent / 1000.0)) / 1000.0 / 1000.0; + + /* + * if we haven't sent anything, we don't want to + * recalculate. 10000 is a small enough number for our purposes + */ + if (ram_counters.dirty_pages_rate && transferred > 10000) { + s->expected_downtime =3D ram_counters.dirty_pages_rate * + qemu_target_page_size() / bandwidth; + } + + qemu_file_reset_rate_limit(s->to_dst_file); + + s->initial_time =3D current_time; + s->initial_bytes =3D qemu_ftell(s->to_dst_file); + + trace_migrate_transferred(transferred, time_spent, + bandwidth, threshold_size); +} + /* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -2171,22 +2206,15 @@ static void migration_calculate_complete(MigrationS= tate *s) static void *migration_thread(void *opaque) { MigrationState *s =3D opaque; - /* Used by the bandwidth calcs, updated later */ - int64_t initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); int64_t setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); - int64_t initial_bytes =3D 0; - /* - * The final stage happens when the remaining data is smaller than - * this threshold; it's calculated from the requested downtime and - * measured bandwidth - */ - int64_t threshold_size =3D 0; bool entered_postcopy =3D false; /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ enum MigrationStatus current_active_state =3D MIGRATION_STATUS_ACTIVE; =20 rcu_register_thread(); =20 + s->initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + qemu_savevm_state_header(s->to_dst_file); =20 /* @@ -2226,17 +2254,17 @@ static void *migration_thread(void *opaque) if (!qemu_file_rate_limit(s->to_dst_file)) { uint64_t pend_post, pend_nonpost; =20 - qemu_savevm_state_pending(s->to_dst_file, threshold_size, + qemu_savevm_state_pending(s->to_dst_file, s->threshold_size, &pend_nonpost, &pend_post); pending_size =3D pend_nonpost + pend_post; - trace_migrate_pending(pending_size, threshold_size, + trace_migrate_pending(pending_size, s->threshold_size, pend_post, pend_nonpost); - if (pending_size && pending_size >=3D threshold_size) { + if (pending_size && pending_size >=3D s->threshold_size) { /* Still a significant amount to transfer */ =20 if (migrate_postcopy() && s->state !=3D MIGRATION_STATUS_POSTCOPY_ACTIVE && - pend_nonpost <=3D threshold_size && + pend_nonpost <=3D s->threshold_size && atomic_read(&s->start_postcopy)) { =20 if (!postcopy_start(s)) { @@ -2261,33 +2289,15 @@ static void *migration_thread(void *opaque) trace_migration_thread_file_err(); break; } + current_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); - if (current_time >=3D initial_time + BUFFER_DELAY) { - uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file) - - initial_bytes; - uint64_t time_spent =3D current_time - initial_time; - double bandwidth =3D (double)transferred_bytes / time_spent; - threshold_size =3D bandwidth * s->parameters.downtime_limit; - - s->mbps =3D (((double) transferred_bytes * 8.0) / - ((double) time_spent / 1000.0)) / 1000.0 / 1000.0; - - trace_migrate_transferred(transferred_bytes, time_spent, - bandwidth, threshold_size); - /* if we haven't sent anything, we don't want to recalculate - 10000 is a small enough number for our purposes */ - if (ram_counters.dirty_pages_rate && transferred_bytes > 10000= ) { - s->expected_downtime =3D ram_counters.dirty_pages_rate * - qemu_target_page_size() / bandwidth; - } =20 - qemu_file_reset_rate_limit(s->to_dst_file); - initial_time =3D current_time; - initial_bytes =3D qemu_ftell(s->to_dst_file); - } + /* Conditionally update statistics */ + migration_update_statistics(s, current_time); + if (qemu_file_rate_limit(s->to_dst_file)) { /* usleep expects microseconds */ - g_usleep((initial_time + BUFFER_DELAY - current_time)*1000); + g_usleep((s->initial_time + BUFFER_DELAY - current_time) * 100= 0); } } =20 diff --git a/migration/migration.h b/migration/migration.h index 3ab5506233..248f7d9a5c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -90,6 +90,19 @@ struct MigrationState QEMUBH *cleanup_bh; QEMUFile *to_dst_file; =20 + /* + * Migration thread statistic variables, mostly used in + * migration_thread() iterations only. + */ + uint64_t initial_bytes; + int64_t initial_time; + /* + * The final stage happens when the remaining data is smaller than + * this threshold; it's calculated from the requested downtime and + * measured bandwidth + */ + int64_t threshold_size; + /* params from 'migrate-set-parameters' */ MigrationParameters parameters; =20 --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514958590371778.2605554489902; Tue, 2 Jan 2018 21:49:50 -0800 (PST) Received: from localhost ([::1]:40726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbvu-0002Ua-0D for importer@patchew.org; Wed, 03 Jan 2018 00:49:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnh-0003I0-Lb for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbng-0001AW-Lq for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbng-00019z-Ci for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:16 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82DAF80472 for ; Wed, 3 Jan 2018 05:41:15 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CB8C6199F; Wed, 3 Jan 2018 05:41:13 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:42 +0800 Message-Id: <20180103054043.25719-11-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 03 Jan 2018 05:41:15 +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 10/11] migration: major cleanup for migrate iterations 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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" The major work for migration iterations are to move RAM/block/... data via qemu_savevm_state_iterate(). Generalize those part into a single function. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 90 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2629f907e9..c6c39738d2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2056,11 +2056,11 @@ static int migration_maybe_pause(MigrationState *s, * The caller 'breaks' the loop when this returns. * * @s: Current migration state - * @current_active_state: The migration state we expect to be in */ -static void migration_completion(MigrationState *s, int current_active_sta= te) +static void migration_completion(MigrationState *s) { int ret; + int current_active_state =3D s->state; =20 if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { qemu_mutex_lock_iothread(); @@ -2199,6 +2199,51 @@ static void migration_update_statistics(MigrationSta= te *s, bandwidth, threshold_size); } =20 +/* Migration thread iteration status */ +typedef enum { + MIG_ITERATE_RESUME, /* Resume current iteration */ + MIG_ITERATE_SKIP, /* Skip current iteration */ + MIG_ITERATE_BREAK, /* Break the loop */ +} MigIterateState; + +/* + * Return true if continue to the next iteration directly, false + * otherwise. + */ +static MigIterateState migration_iteration_run(MigrationState *s) +{ + uint64_t pending_size, pend_post, pend_nonpost; + bool in_postcopy =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE; + + qemu_savevm_state_pending(s->to_dst_file, s->threshold_size, + &pend_nonpost, &pend_post); + pending_size =3D pend_nonpost + pend_post; + + trace_migrate_pending(pending_size, s->threshold_size, + pend_post, pend_nonpost); + + if (pending_size && pending_size >=3D s->threshold_size) { + /* Still a significant amount to transfer */ + if (migrate_postcopy() && !in_postcopy && + pend_nonpost <=3D s->threshold_size && + atomic_read(&s->start_postcopy)) { + if (postcopy_start(s)) { + error_report("%s: postcopy failed to start", __func__); + } + return MIG_ITERATE_SKIP; + } + /* Just another iteration step */ + qemu_savevm_state_iterate(s->to_dst_file, + s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); + } else { + trace_migration_thread_low_pending(pending_size); + migration_completion(s); + return MIG_ITERATE_BREAK; + } + + return MIG_ITERATE_RESUME; +} + /* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -2207,9 +2252,6 @@ static void *migration_thread(void *opaque) { MigrationState *s =3D opaque; int64_t setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); - bool entered_postcopy =3D false; - /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */ - enum MigrationStatus current_active_state =3D MIGRATION_STATUS_ACTIVE; =20 rcu_register_thread(); =20 @@ -2249,43 +2291,21 @@ static void *migration_thread(void *opaque) while (s->state =3D=3D MIGRATION_STATUS_ACTIVE || s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE) { int64_t current_time; - uint64_t pending_size; =20 if (!qemu_file_rate_limit(s->to_dst_file)) { - uint64_t pend_post, pend_nonpost; - - qemu_savevm_state_pending(s->to_dst_file, s->threshold_size, - &pend_nonpost, &pend_post); - pending_size =3D pend_nonpost + pend_post; - trace_migrate_pending(pending_size, s->threshold_size, - pend_post, pend_nonpost); - if (pending_size && pending_size >=3D s->threshold_size) { - /* Still a significant amount to transfer */ - - if (migrate_postcopy() && - s->state !=3D MIGRATION_STATUS_POSTCOPY_ACTIVE && - pend_nonpost <=3D s->threshold_size && - atomic_read(&s->start_postcopy)) { - - if (!postcopy_start(s)) { - current_active_state =3D MIGRATION_STATUS_POSTCOPY= _ACTIVE; - entered_postcopy =3D true; - } - - continue; - } - /* Just another iteration step */ - qemu_savevm_state_iterate(s->to_dst_file, entered_postcopy= ); - } else { - trace_migration_thread_low_pending(pending_size); - migration_completion(s, current_active_state); + MigIterateState iter_state =3D migration_iteration_run(s); + if (iter_state =3D=3D MIG_ITERATE_SKIP) { + continue; + } else if (iter_state =3D=3D MIG_ITERATE_BREAK) { break; } } =20 if (qemu_file_get_error(s->to_dst_file)) { - migrate_set_state(&s->state, current_active_state, - MIGRATION_STATUS_FAILED); + if (migration_is_setup_or_active(s->state)) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } trace_migration_thread_file_err(); break; } --=20 2.14.3 From nobody Sun Oct 26 01:41:55 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514958589867311.15935036752774; Tue, 2 Jan 2018 21:49:49 -0800 (PST) Received: from localhost ([::1]:40725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbvo-0002RI-MR for importer@patchew.org; Wed, 03 Jan 2018 00:49:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWbnm-0003MS-2r for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWbni-0001Be-RX for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWbni-0001BG-Ig for qemu-devel@nongnu.org; Wed, 03 Jan 2018 00:41:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B988681DE9 for ; Wed, 3 Jan 2018 05:41:17 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id F412B6198E; Wed, 3 Jan 2018 05:41:15 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:40:43 +0800 Message-Id: <20180103054043.25719-12-peterx@redhat.com> In-Reply-To: <20180103054043.25719-1-peterx@redhat.com> References: <20180103054043.25719-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 03 Jan 2018 05:41:17 +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 11/11] migration: put the finish part into a new function 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: Laurent Vivier , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela 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 only moved the last part of migration_thread() into a new function migration_iteration_finish() to make it much shorter. With previous works to remove some local variables, now it's fairly easy to do that. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 80 +++++++++++++++++++++++++++--------------------= ---- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index c6c39738d2..51379bba2c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2244,6 +2244,47 @@ static MigIterateState migration_iteration_run(Migra= tionState *s) return MIG_ITERATE_RESUME; } =20 +static void migration_iteration_finish(MigrationState *s) +{ + /* If we enabled cpu throttling for auto-converge, turn it off. */ + cpu_throttle_stop(); + + qemu_mutex_lock_iothread(); + switch (s->state) { + case MIGRATION_STATUS_COMPLETED: + migration_calculate_complete(s); + runstate_set(RUN_STATE_POSTMIGRATE); + break; + + case MIGRATION_STATUS_ACTIVE: + assert(migrate_colo_enabled()); + migrate_start_colo_process(s); + /* + * Fixme: we will run VM in COLO no matter its old running state. + * After exited COLO, we will keep running. + */ + s->old_vm_running =3D true; + /* Fallthrough */ + case MIGRATION_STATUS_FAILED: + case MIGRATION_STATUS_CANCELLED: + if (s->old_vm_running) { + vm_start(); + } else { + if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { + runstate_set(RUN_STATE_POSTMIGRATE); + } + } + break; + + default: + /* Should not reach here, but if so, forgive the VM. */ + error_report("%s: Unknown ending state %d", __func__, s->state); + break; + } + qemu_bh_schedule(s->cleanup_bh); + qemu_mutex_unlock_iothread(); +} + /* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -2322,44 +2363,7 @@ static void *migration_thread(void *opaque) } =20 trace_migration_thread_after_loop(); - /* If we enabled cpu throttling for auto-converge, turn it off. */ - cpu_throttle_stop(); - - qemu_mutex_lock_iothread(); - switch (s->state) { - case MIGRATION_STATUS_COMPLETED: - migration_calculate_complete(s); - runstate_set(RUN_STATE_POSTMIGRATE); - break; - - case MIGRATION_STATUS_ACTIVE: - assert(migrate_colo_enabled()); - migrate_start_colo_process(s); - /* - * Fixme: we will run VM in COLO no matter its old running state. - * After exited COLO, we will keep running. - */ - s->old_vm_running =3D true; - /* Fallthrough */ - case MIGRATION_STATUS_FAILED: - case MIGRATION_STATUS_CANCELLED: - if (s->old_vm_running) { - vm_start(); - } else { - if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { - runstate_set(RUN_STATE_POSTMIGRATE); - } - } - break; - - default: - /* Should not reach here, but if so, forgive the VM. */ - error_report("%s: Unknown ending state %d", __func__, s->state); - break; - } - qemu_bh_schedule(s->cleanup_bh); - qemu_mutex_unlock_iothread(); - + migration_iteration_finish(s); rcu_unregister_thread(); return NULL; } --=20 2.14.3