From nobody Thu May 2 01:44:08 2024 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 1507114136387621.662225698624; Wed, 4 Oct 2017 03:48:56 -0700 (PDT) Received: from localhost ([::1]:34282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhEP-000627-Lz for importer@patchew.org; Wed, 04 Oct 2017 06:48:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCQ-0004oN-5M for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCO-0002nF-Qk for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCO-0002mp-K3 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C13F882FF for ; Wed, 4 Oct 2017 10:46:43 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE9085D9CB; Wed, 4 Oct 2017 10:46:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9C13F882FF Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:25 +0200 Message-Id: <20171004104636.7963-2-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Oct 2017 10:46:43 +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 v9 01/12] qapi: Fix grammar in x-multifd-page-count descriptions 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, dgilbert@redhat.com, peterx@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" Reported-by: Eric Blake Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- qapi/migration.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index f8b365e3f5..d94d6c0e46 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -471,7 +471,7 @@ # number of sockets used for migration. The # default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 @@ -542,7 +542,7 @@ # number of sockets used for migration. The # default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 @@ -638,7 +638,7 @@ # number of sockets used for migration. # The default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114376237208.81946131522318; Wed, 4 Oct 2017 03:52:56 -0700 (PDT) Received: from localhost ([::1]:34298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhII-00011G-ES for importer@patchew.org; Wed, 04 Oct 2017 06:52:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCR-0004pz-Q2 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCQ-0002oF-NQ for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53404) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCQ-0002ng-El for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 748C45D5EB for ; Wed, 4 Oct 2017 10:46:45 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF2715D9CB; Wed, 4 Oct 2017 10:46:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 748C45D5EB Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:26 +0200 Message-Id: <20171004104636.7963-3-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 04 Oct 2017 10:46:45 +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 v9 02/12] migration: Improve migration thread error handling 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, dgilbert@redhat.com, peterx@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" We now report errors also when we finish migration, not only on info migrate. We plan to use this error from several places, and we want the first error to happen to win, so we add an mutex to order it. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 19 ++++++++++++++++--- migration/migration.h | 7 ++++++- migration/tls.c | 1 - 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 98429dc843..468f51cfa7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1071,19 +1071,30 @@ static void migrate_fd_cleanup(void *opaque) MIGRATION_STATUS_CANCELLED); } =20 + if (s->error) { + /* It is used on info migrate. We can't free it */ + error_report_err(error_copy(s->error)); + } notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); } =20 +void migrate_set_error(MigrationState *s, const Error *error) +{ + qemu_mutex_lock(&s->error_mutex); + if (!s->error) { + s->error =3D error_copy(error); + } + qemu_mutex_unlock(&s->error_mutex); +} + void migrate_fd_error(MigrationState *s, const Error *error) { trace_migrate_fd_error(error_get_pretty(error)); assert(s->to_dst_file =3D=3D NULL); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); - if (!s->error) { - s->error =3D error_copy(error); - } + migrate_set_error(s, error); notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); } @@ -2355,6 +2366,7 @@ static void migration_instance_finalize(Object *obj) MigrationState *ms =3D MIGRATION_OBJ(obj); MigrationParameters *params =3D &ms->parameters; =20 + qemu_mutex_destroy(&ms->error_mutex); g_free(params->tls_hostname); g_free(params->tls_creds); } @@ -2367,6 +2379,7 @@ static void migration_instance_init(Object *obj) ms->state =3D MIGRATION_STATUS_NONE; ms->xbzrle_cache_size =3D DEFAULT_MIGRATE_CACHE_SIZE; ms->mbps =3D -1; + qemu_mutex_init(&ms->error_mutex); =20 params->tls_hostname =3D g_strdup(""); params->tls_creds =3D g_strdup(""); diff --git a/migration/migration.h b/migration/migration.h index b83cceadc4..51c0ac2e71 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -129,8 +129,12 @@ struct MigrationState int64_t colo_checkpoint_time; QEMUTimer *colo_delay_timer; =20 - /* The last error that occurred */ + /* The first error that has occurred. + We used the mutex to be able to return the 1st error message */ Error *error; + /* mutex to protect errp */ + QemuMutex error_mutex; + /* Do we have to clean up -b/-i from old migrate parameters */ /* This feature is deprecated and will be removed */ bool must_remove_block_options; @@ -159,6 +163,7 @@ bool migration_has_all_channels(void); =20 uint64_t migrate_max_downtime(void); =20 +void migrate_set_error(MigrationState *s, const Error *error); void migrate_fd_error(MigrationState *s, const Error *error); =20 void migrate_fd_connect(MigrationState *s); diff --git a/migration/tls.c b/migration/tls.c index 596e8790bd..026a008667 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -119,7 +119,6 @@ static void migration_tls_outgoing_handshake(QIOTask *t= ask, if (qio_task_propagate_error(task, &err)) { trace_migration_tls_outgoing_handshake_error(error_get_pretty(err)= ); migrate_fd_error(s, err); - error_free(err); } else { trace_migration_tls_outgoing_handshake_complete(); migration_channel_connect(s, ioc, NULL); --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114135682116.69919859183187; Wed, 4 Oct 2017 03:48:55 -0700 (PDT) Received: from localhost ([::1]:34283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhER-00064Y-VE for importer@patchew.org; Wed, 04 Oct 2017 06:48:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCT-0004r0-En for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCS-0002oy-FH for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40638) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCS-0002oW-77 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 362D7780CB for ; Wed, 4 Oct 2017 10:46:47 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDAE15D9CB; Wed, 4 Oct 2017 10:46:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 362D7780CB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:27 +0200 Message-Id: <20171004104636.7963-4-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 04 Oct 2017 10:46:47 +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 v9 03/12] migration: Make migrate_fd_error() the owner of the Error 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, dgilbert@redhat.com, peterx@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" So far, we had to free the error after each caller, so just do it here. Once there, tls.c was leaking the error. Signed-off-by: Juan Quintela --- migration/channel.c | 1 - migration/migration.c | 10 ++++------ migration/migration.h | 4 ++-- migration/socket.c | 1 - 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 70ec7ea3b7..1dd2ae1530 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -71,7 +71,6 @@ void migration_channel_connect(MigrationState *s, migration_tls_channel_connect(s, ioc, hostname, &local_err); if (local_err) { migrate_fd_error(s, local_err); - error_free(local_err); } } else { QEMUFile *f =3D qemu_fopen_channel_output(ioc); diff --git a/migration/migration.c b/migration/migration.c index 468f51cfa7..61b7e7105a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1079,16 +1079,14 @@ static void migrate_fd_cleanup(void *opaque) block_cleanup_parameters(s); } =20 -void migrate_set_error(MigrationState *s, const Error *error) +void migrate_set_error(MigrationState *s, Error *error) { qemu_mutex_lock(&s->error_mutex); - if (!s->error) { - s->error =3D error_copy(error); - } + error_propagate(&s->error, error); qemu_mutex_unlock(&s->error_mutex); } =20 -void migrate_fd_error(MigrationState *s, const Error *error) +void migrate_fd_error(MigrationState *s, Error *error) { trace_migrate_fd_error(error_get_pretty(error)); assert(s->to_dst_file =3D=3D NULL); @@ -1362,7 +1360,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool = blk, } =20 if (local_err) { - migrate_fd_error(s, local_err); + migrate_fd_error(s, error_copy(local_err)); error_propagate(errp, local_err); return; } diff --git a/migration/migration.h b/migration/migration.h index 51c0ac2e71..cc196cc87f 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -163,8 +163,8 @@ bool migration_has_all_channels(void); =20 uint64_t migrate_max_downtime(void); =20 -void migrate_set_error(MigrationState *s, const Error *error); -void migrate_fd_error(MigrationState *s, const Error *error); +void migrate_set_error(MigrationState *s, Error *error); +void migrate_fd_error(MigrationState *s, Error *error); =20 void migrate_fd_connect(MigrationState *s); =20 diff --git a/migration/socket.c b/migration/socket.c index dee869044a..2d70747a1a 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -80,7 +80,6 @@ static void socket_outgoing_migration(QIOTask *task, if (qio_task_propagate_error(task, &err)) { trace_migration_socket_outgoing_error(error_get_pretty(err)); migrate_fd_error(data->s, err); - error_free(err); } else { trace_migration_socket_outgoing_connected(data->hostname); migration_channel_connect(data->s, sioc, data->hostname); --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114138597391.89406598785024; Wed, 4 Oct 2017 03:48:58 -0700 (PDT) Received: from localhost ([::1]:34284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhEX-00068F-Ir for importer@patchew.org; Wed, 04 Oct 2017 06:48:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCW-0004tM-9K for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCU-0002qi-Bq for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCU-0002po-1x for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F85A80090 for ; Wed, 4 Oct 2017 10:46:49 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FDDF5D9CB; Wed, 4 Oct 2017 10:46:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F85A80090 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:28 +0200 Message-Id: <20171004104636.7963-5-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Oct 2017 10:46:49 +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 v9 04/12] migration: Start of multiple fd work 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, dgilbert@redhat.com, peterx@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" We create new channels for each new thread created. We send through them a string containing multifd so we are sure that we connect the right channels in both sides. Signed-off-by: Juan Quintela -- Split SocketArgs into incoming and outgoing args Use UUID's on the initial message, so we are sure we are connecting to the right channel. Remove init semaphore. Now that we use uuids on the init message, we know that this is our channel. Fix recv socket destwroy, we were destroying send channels. This was very interesting, because we were using an unreferred object without problems. Move to struct of pointers init channel sooner. split recv thread creation. listen on main thread We count the number of created threads to know when we need to stop listeni= ng Use g_strdup_printf report channel id on errors Add name parameter Use local_err Add Error * parameter to socket_send_channel_create() Use qio_channel_*_all Use asynchronous connect Use an struct to send all fields Use default uuid --- migration/migration.c | 5 ++ migration/ram.c | 128 +++++++++++++++++++++++++++++++++++++++++++---= ---- migration/ram.h | 3 ++ migration/socket.c | 34 +++++++++++++- migration/socket.h | 10 ++++ 5 files changed, 162 insertions(+), 18 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 61b7e7105a..ee98c50d8c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -419,6 +419,11 @@ void migration_ioc_process_incoming(QIOChannel *ioc) */ bool migration_has_all_channels(void) { + if (migrate_use_multifd()) { + int thread_count =3D migrate_multifd_channels(); + + return thread_count =3D=3D multifd_created_channels(); + } return true; } =20 diff --git a/migration/ram.c b/migration/ram.c index b83f8977c5..b57006594b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -36,6 +36,7 @@ #include "xbzrle.h" #include "ram.h" #include "migration.h" +#include "socket.h" #include "migration/register.h" #include "migration/misc.h" #include "qemu-file.h" @@ -47,6 +48,8 @@ #include "qemu/rcu_queue.h" #include "migration/colo.h" #include "migration/block.h" +#include "sysemu/sysemu.h" +#include "qemu/uuid.h" =20 /***********************************************************/ /* ram save/restore */ @@ -363,6 +366,7 @@ struct MultiFDSendParams { uint8_t id; char *name; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool quit; @@ -379,6 +383,12 @@ static void terminate_multifd_send_threads(Error *errp) { int i; =20 + if (errp) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, errp); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + } for (i =3D 0; i < multifd_send_state->count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -404,6 +414,7 @@ int multifd_save_cleanup(Error **errp) qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + socket_send_channel_destroy(p->c); g_free(p->name); p->name =3D NULL; } @@ -414,9 +425,27 @@ int multifd_save_cleanup(Error **errp) return ret; } =20 +typedef struct { + uint32_t version; + uint8_t id; + char uuid[UUID_FMT_LEN]; +} MigrateMultiFDInit_t; + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; + MigrateMultiFDInit_t msg; + Error *local_err =3D NULL; + size_t ret; + + msg.version =3D 1; + msg.id =3D p->id; + qemu_uuid_unparse(&qemu_uuid, (char *)&msg.uuid); + ret =3D qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), &local_= err); + if (ret !=3D 0) { + terminate_multifd_send_threads(local_err); + return NULL; + } =20 while (true) { qemu_mutex_lock(&p->mutex); @@ -431,6 +460,27 @@ static void *multifd_send_thread(void *opaque) return NULL; } =20 +static void multifd_new_channel_async(QIOTask *task, gpointer opaque) +{ + MultiFDSendParams *p =3D opaque; + QIOChannel *sioc =3D QIO_CHANNEL(qio_task_get_source(task)); + Error *local_err; + + if (qio_task_propagate_error(task, &local_err)) { + if (multifd_save_cleanup(&local_err) !=3D 0) { + migrate_set_error(migrate_get_current(), local_err); + } + } else { + p->c =3D QIO_CHANNEL(sioc); + qio_channel_set_delay(p->c, false); + + qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, + QEMU_THREAD_JOINABLE); + + multifd_send_state->count++; + } +} + int multifd_save_setup(void) { int thread_count; @@ -451,10 +501,7 @@ int multifd_save_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdsend_%d", i); - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); - - multifd_send_state->count++; + socket_send_channel_create(multifd_new_channel_async, p); } return 0; } @@ -463,6 +510,7 @@ struct MultiFDRecvParams { uint8_t id; char *name; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool quit; @@ -473,12 +521,22 @@ struct { MultiFDRecvParams *params; /* number of created threads */ int count; + /* Should we finish */ + bool quit; } *multifd_recv_state; =20 static void terminate_multifd_recv_threads(Error *errp) { int i; =20 + if (errp) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, errp); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + } + multifd_recv_state->quit =3D true; + for (i =3D 0; i < multifd_recv_state->count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 @@ -504,6 +562,7 @@ int multifd_load_cleanup(Error **errp) qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + socket_recv_channel_destroy(p->c); g_free(p->name); p->name =3D NULL; } @@ -532,10 +591,51 @@ static void *multifd_recv_thread(void *opaque) return NULL; } =20 +void multifd_new_channel(QIOChannel *ioc) +{ + MultiFDRecvParams *p; + MigrateMultiFDInit_t msg; + Error *local_err =3D NULL; + char *uuid; + size_t ret; + + ret =3D qio_channel_read_all(ioc, (char *)&msg, sizeof(msg), &local_er= r); + if (ret !=3D 0) { + terminate_multifd_recv_threads(local_err); + return; + } + + uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); + + if (strcmp(msg.uuid, uuid)) { + g_free(uuid); + error_setg(&local_err, "multifd: received uuid '%s' and expected " + "uuid '%s' for channel %hhd", msg.uuid, uuid, msg.id); + terminate_multifd_recv_threads(local_err); + return; + } + g_free(uuid); + + p =3D &multifd_recv_state->params[msg.id]; + if (p->id !=3D 0) { + error_setg(&local_err, "multifd: received id '%d' already setup'",= msg.id); + terminate_multifd_recv_threads(local_err); + return; + } + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D msg.id; + p->c =3D ioc; + multifd_recv_state->count++; + p->name =3D g_strdup_printf("multifdrecv_%d", msg.id); + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); +} + int multifd_load_setup(void) { int thread_count; - uint8_t i; =20 if (!migrate_use_multifd()) { return 0; @@ -544,21 +644,15 @@ int multifd_load_setup(void) multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); multifd_recv_state->count =3D 0; - for (i =3D 0; i < thread_count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem, 0); - p->quit =3D false; - p->id =3D i; - p->name =3D g_strdup_printf("multifdrecv_%d", i); - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); - multifd_recv_state->count++; - } + multifd_recv_state->quit =3D false; return 0; } =20 +int multifd_created_channels(void) +{ + return multifd_recv_state->count; +} + /** * save_page_header: write page header to wire * diff --git a/migration/ram.h b/migration/ram.h index 4a72d66503..5221bc9beb 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -31,6 +31,7 @@ =20 #include "qemu-common.h" #include "exec/cpu-common.h" +#include "io/channel.h" =20 extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; @@ -43,6 +44,8 @@ int multifd_save_setup(void); int multifd_save_cleanup(Error **errp); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); +void multifd_new_channel(QIOChannel *ioc); +int multifd_created_channels(void); =20 uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); diff --git a/migration/socket.c b/migration/socket.c index 2d70747a1a..22fb05edc8 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -26,6 +26,34 @@ #include "io/channel-socket.h" #include "trace.h" =20 +int socket_recv_channel_destroy(QIOChannel *recv) +{ + /* Remove channel */ + object_unref(OBJECT(recv)); + return 0; +} + +struct SocketOutgoingArgs { + SocketAddress *saddr; +} outgoing_args; + +void socket_send_channel_create(void (*f)(QIOTask *, gpointer), void *data) +{ + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + qio_channel_socket_connect_async(sioc, outgoing_args.saddr, + f, data, NULL); +} + +int socket_send_channel_destroy(QIOChannel *send) +{ + /* Remove channel */ + object_unref(OBJECT(send)); + if (outgoing_args.saddr) { + qapi_free_SocketAddress(outgoing_args.saddr); + outgoing_args.saddr =3D NULL; + } + return 0; +} =20 static SocketAddress *tcp_build_address(const char *host_port, Error **err= p) { @@ -95,6 +123,11 @@ static void socket_start_outgoing_migration(MigrationSt= ate *s, struct SocketConnectData *data =3D g_new0(struct SocketConnectData, 1); =20 data->s =3D s; + + /* in case previous migration leaked it */ + qapi_free_SocketAddress(outgoing_args.saddr); + outgoing_args.saddr =3D saddr; + if (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET) { data->hostname =3D g_strdup(saddr->u.inet.host); } @@ -105,7 +138,6 @@ static void socket_start_outgoing_migration(MigrationSt= ate *s, socket_outgoing_migration, data, socket_connect_data_free); - qapi_free_SocketAddress(saddr); } =20 void tcp_start_outgoing_migration(MigrationState *s, diff --git a/migration/socket.h b/migration/socket.h index 6b91e9db38..afb0ff0f51 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -16,6 +16,16 @@ =20 #ifndef QEMU_MIGRATION_SOCKET_H #define QEMU_MIGRATION_SOCKET_H + +#include "io/channel.h" +#include "io/task.h" + +QIOChannel *socket_recv_channel_create(void); +int socket_recv_channel_destroy(QIOChannel *recv); + +void socket_send_channel_create(void (*f)(QIOTask *, gpointer), void *data= ); +int socket_send_channel_destroy(QIOChannel *send); + void tcp_start_incoming_migration(const char *host_port, Error **errp); =20 void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 15071143086481003.6880454376192; Wed, 4 Oct 2017 03:51:48 -0700 (PDT) Received: from localhost ([::1]:34295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhH6-0008PI-8f for importer@patchew.org; Wed, 04 Oct 2017 06:51:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCZ-0004vs-4d for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCW-0002rc-0L for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCV-0002rH-OI for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7CBE780C9 for ; Wed, 4 Oct 2017 10:46:50 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 690595D9CB; Wed, 4 Oct 2017 10:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C7CBE780C9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:29 +0200 Message-Id: <20171004104636.7963-6-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 04 Oct 2017 10:46:50 +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 v9 05/12] migration: Create ram_multifd_page 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, dgilbert@redhat.com, peterx@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" The function still don't use multifd, but we have simplified ram_save_page, xbzrle and RDMA stuff is gone. We have added a new counter and a new flag for this type of pages. Signed-off-by: Juan Quintela -- Add last_page parameter Add commets for done and address Remove multifd field, it is the same than normal pages Merge next patch, now we send multiple pages at a time Remove counter for multifd pages, it is identical to normal pages Use iovec's instead of creating the equivalent. Clear memory used by pages (dave) Use g_new0(danp) define MULTIFD_CONTINUE --- migration/ram.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index b57006594b..c0af538f5f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -50,6 +50,7 @@ #include "migration/block.h" #include "sysemu/sysemu.h" #include "qemu/uuid.h" +#include "qemu/iov.h" =20 /***********************************************************/ /* ram save/restore */ @@ -69,6 +70,7 @@ #define RAM_SAVE_FLAG_XBZRLE 0x40 /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 +#define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 =20 static inline bool is_zero_range(uint8_t *p, uint64_t size) { @@ -362,14 +364,29 @@ static void compress_threads_save_setup(void) =20 /* Multiple fd's */ =20 +/* used to continue on the same multifd group */ +#define MULTIFD_CONTINUE UINT16_MAX + +typedef struct { + int num; + size_t size; + struct iovec *iov; +} multifd_pages_t; + struct MultiFDSendParams { + /* not changed */ uint8_t id; char *name; QemuThread thread; QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; + /* protected by param mutex */ bool quit; + multifd_pages_t pages; + /* protected by multifd mutex */ + /* has the thread finish the last submitted job */ + bool done; }; typedef struct MultiFDSendParams MultiFDSendParams; =20 @@ -377,8 +394,26 @@ struct { MultiFDSendParams *params; /* number of created threads */ int count; + QemuMutex mutex; + QemuSemaphore sem; + multifd_pages_t pages; } *multifd_send_state; =20 +static void multifd_init_pages(multifd_pages_t *pages) +{ + pages->num =3D 0; + pages->size =3D migrate_multifd_page_count(); + pages->iov =3D g_new0(struct iovec, pages->size); +} + +static void multifd_clear_pages(multifd_pages_t *pages) +{ + pages->num =3D 0; + pages->size =3D 0; + g_free(pages->iov); + pages->iov =3D NULL; +} + static void terminate_multifd_send_threads(Error *errp) { int i; @@ -417,9 +452,11 @@ int multifd_save_cleanup(Error **errp) socket_send_channel_destroy(p->c); g_free(p->name); p->name =3D NULL; + multifd_clear_pages(&p->pages); } g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; + multifd_clear_pages(&multifd_send_state->pages); g_free(multifd_send_state); multifd_send_state =3D NULL; return ret; @@ -446,6 +483,7 @@ static void *multifd_send_thread(void *opaque) terminate_multifd_send_threads(local_err); return NULL; } + qemu_sem_post(&multifd_send_state->sem); =20 while (true) { qemu_mutex_lock(&p->mutex); @@ -453,6 +491,15 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); break; } + if (p->pages.num) { + p->pages.num =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_mutex_lock(&multifd_send_state->mutex); + p->done =3D true; + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_sem_post(&multifd_send_state->sem); + continue; + } qemu_mutex_unlock(&p->mutex); qemu_sem_wait(&p->sem); } @@ -493,6 +540,9 @@ int multifd_save_setup(void) multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); multifd_send_state->count =3D 0; + qemu_mutex_init(&multifd_send_state->mutex); + qemu_sem_init(&multifd_send_state->sem, 0); + multifd_init_pages(&multifd_send_state->pages); for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -500,12 +550,52 @@ int multifd_save_setup(void) qemu_sem_init(&p->sem, 0); p->quit =3D false; p->id =3D i; + p->done =3D true; + multifd_init_pages(&p->pages); p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_channel_async, p); } return 0; } =20 +static uint16_t multifd_send_page(uint8_t *address, bool last_page) +{ + int i; + MultiFDSendParams *p =3D NULL; /* make happy gcc */ + multifd_pages_t *pages =3D &multifd_send_state->pages; + + pages->iov[pages->num].iov_base =3D address; + pages->iov[pages->num].iov_len =3D TARGET_PAGE_SIZE; + pages->num++; + + if (!last_page) { + if (pages->num < (pages->size - 1)) { + return MULTIFD_CONTINUE; + } + } + + qemu_sem_wait(&multifd_send_state->sem); + qemu_mutex_lock(&multifd_send_state->mutex); + for (i =3D 0; i < multifd_send_state->count; i++) { + p =3D &multifd_send_state->params[i]; + + if (p->done) { + p->done =3D false; + break; + } + } + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_mutex_lock(&p->mutex); + p->pages.num =3D pages->num; + iov_copy(p->pages.iov, pages->num, pages->iov, pages->num, 0, + iov_size(pages->iov, pages->num)); + pages->num =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + + return 0; +} + struct MultiFDRecvParams { uint8_t id; char *name; @@ -1086,6 +1176,31 @@ static int ram_save_page(RAMState *rs, PageSearchSta= tus *pss, bool last_stage) return pages; } =20 +static int ram_multifd_page(RAMState *rs, PageSearchStatus *pss, + bool last_stage) +{ + int pages; + uint8_t *p; + RAMBlock *block =3D pss->block; + ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; + + p =3D block->host + offset; + + pages =3D save_zero_page(rs, block, offset, p); + if (pages =3D=3D -1) { + ram_counters.transferred +=3D + save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_MULTIFD_PAGE); + qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); + multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + pages =3D 1; + ram_counters.normal++; + } + + return pages; +} + static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) { @@ -1514,6 +1629,8 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss, if (migrate_use_compression() && (rs->ram_bulk_stage || !migrate_use_xbzrle())) { res =3D ram_save_compressed_page(rs, pss, last_stage); + } else if (migrate_use_multifd()) { + res =3D ram_multifd_page(rs, pss, last_stage); } else { res =3D ram_save_page(rs, pss, last_stage); } @@ -2810,6 +2927,10 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) if (!migrate_use_compression()) { invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } + + if (!migrate_use_multifd()) { + invalid_flags |=3D RAM_SAVE_FLAG_MULTIFD_PAGE; + } /* This RCU critical section can be very long running. * When RCU reclaims in the code start to become numerous, * it will be necessary to reduce the granularity of this @@ -2834,13 +2955,17 @@ static int ram_load(QEMUFile *f, void *opaque, int = version_id) if (flags & invalid_flags & RAM_SAVE_FLAG_COMPRESS_PAGE) { error_report("Received an unexpected compressed page"); } + if (flags & invalid_flags & RAM_SAVE_FLAG_MULTIFD_PAGE) { + error_report("Received an unexpected multifd page"); + } =20 ret =3D -EINVAL; break; } =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | - RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { + RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE | + RAM_SAVE_FLAG_MULTIFD_PAGE)) { RAMBlock *block =3D ram_block_from_stream(f, flags); =20 host =3D host_from_ram_block_offset(block, addr); @@ -2928,6 +3053,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; } break; + + case RAM_SAVE_FLAG_MULTIFD_PAGE: + qemu_get_buffer(f, host, TARGET_PAGE_SIZE); + break; + case RAM_SAVE_FLAG_EOS: /* normal exit */ break; --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114308654678.3052493677634; Wed, 4 Oct 2017 03:51:48 -0700 (PDT) Received: from localhost ([::1]:34297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhHA-0008V6-Sh for importer@patchew.org; Wed, 04 Oct 2017 06:51:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCZ-0004vt-4d for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCX-0002us-M2 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37648) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCX-0002sm-G1 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FA25552D1 for ; Wed, 4 Oct 2017 10:46:52 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DDFF5D9CB; Wed, 4 Oct 2017 10:46:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8FA25552D1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:30 +0200 Message-Id: <20171004104636.7963-7-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 04 Oct 2017 10:46:52 +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 v9 06/12] migration: Send the fd number which we are going to use for this page 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, dgilbert@redhat.com, peterx@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" We are still sending the page through the main channel, that would change later in the series Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c0af538f5f..288201e360 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -593,7 +593,7 @@ static uint16_t multifd_send_page(uint8_t *address, boo= l last_page) qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 - return 0; + return i; } =20 struct MultiFDRecvParams { @@ -1180,6 +1180,7 @@ static int ram_multifd_page(RAMState *rs, PageSearchS= tatus *pss, bool last_stage) { int pages; + uint16_t fd_num; uint8_t *p; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; @@ -1191,8 +1192,10 @@ static int ram_multifd_page(RAMState *rs, PageSearch= Status *pss, ram_counters.transferred +=3D save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE); + fd_num =3D multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1= ); + qemu_put_be16(rs->f, fd_num); + ram_counters.transferred +=3D 2; /* size of fd_num */ qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); - multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1); ram_counters.transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; ram_counters.normal++; @@ -2945,6 +2948,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) while (!postcopy_running && !ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr, total_ram_bytes; void *host =3D NULL; + uint16_t fd_num; uint8_t ch; =20 addr =3D qemu_get_be64(f); @@ -3055,6 +3059,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; =20 case RAM_SAVE_FLAG_MULTIFD_PAGE: + fd_num =3D qemu_get_be16(f); + if (fd_num !=3D 0) { + /* this is yet an unused variable, changed later */ + fd_num =3D fd_num; + } qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1507114546480537.5931289597283; Wed, 4 Oct 2017 03:55:46 -0700 (PDT) Received: from localhost ([::1]:34311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhKm-0003Ag-RR for importer@patchew.org; Wed, 04 Oct 2017 06:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCa-0004xG-O1 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCZ-0002xg-KP for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33297) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCZ-0002wU-CO for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59C87820E5 for ; Wed, 4 Oct 2017 10:46:54 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id E744E5D9CB; Wed, 4 Oct 2017 10:46:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 59C87820E5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:31 +0200 Message-Id: <20171004104636.7963-8-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 04 Oct 2017 10:46:54 +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 v9 07/12] migration: Create thread infrastructure for multifd recv side 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, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We make the locking and the transfer of information specific, even if we are still receiving things through the main thread. Signed-off-by: Juan Quintela -- We split when we create the main channel and where we start the main migration thread, so we wait for the creation of the other threads. Use multifd_clear_pages(). Don't remove object_unref() We use correctly the channel numbres --- migration/migration.c | 7 +++--- migration/migration.h | 1 + migration/ram.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++= ---- migration/socket.c | 3 +++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ee98c50d8c..1e7c537954 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -388,7 +388,7 @@ static void migration_incoming_setup(QEMUFile *f) qemu_file_set_blocking(f, false); } =20 -static void migration_incoming_process(void) +void migration_incoming_process(void) { Coroutine *co =3D qemu_coroutine_create(process_incoming_migration_co,= NULL); qemu_coroutine_enter(co); @@ -406,9 +406,10 @@ void migration_ioc_process_incoming(QIOChannel *ioc) =20 if (!mis->from_src_file) { QEMUFile *f =3D qemu_fopen_channel_input(ioc); - migration_fd_process_incoming(f); + migration_incoming_setup(f); + return; } - /* We still only have a single channel. Nothing to do here yet */ + multifd_new_channel(ioc); } =20 /** diff --git a/migration/migration.h b/migration/migration.h index cc196cc87f..a3db60a2a1 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -158,6 +158,7 @@ void migrate_set_state(int *state, int old_state, int n= ew_state); =20 void migration_fd_process_incoming(QEMUFile *f); void migration_ioc_process_incoming(QIOChannel *ioc); +void migration_incoming_process(void); =20 bool migration_has_all_channels(void); =20 diff --git a/migration/ram.c b/migration/ram.c index 288201e360..745da2971d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -597,13 +597,18 @@ static uint16_t multifd_send_page(uint8_t *address, b= ool last_page) } =20 struct MultiFDRecvParams { + /* not changed */ uint8_t id; char *name; QemuThread thread; QIOChannel *c; + QemuSemaphore ready; QemuSemaphore sem; QemuMutex mutex; + /* proteced by param mutex */ bool quit; + multifd_pages_t pages; + bool done; }; typedef struct MultiFDRecvParams MultiFDRecvParams; =20 @@ -613,6 +618,7 @@ struct { int count; /* Should we finish */ bool quit; + multifd_pages_t pages; } *multifd_recv_state; =20 static void terminate_multifd_recv_threads(Error *errp) @@ -634,6 +640,7 @@ static void terminate_multifd_recv_threads(Error *errp) p->quit =3D true; qemu_sem_post(&p->sem); qemu_mutex_unlock(&p->mutex); + multifd_clear_pages(&p->pages); } } =20 @@ -658,6 +665,7 @@ int multifd_load_cleanup(Error **errp) } g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; + multifd_clear_pages(&multifd_recv_state->pages); g_free(multifd_recv_state); multifd_recv_state =3D NULL; =20 @@ -668,12 +676,20 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 + qemu_sem_post(&p->ready); while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } + if (p->pages.num) { + p->pages.num =3D 0; + p->done =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->ready); + continue; + } qemu_mutex_unlock(&p->mutex); qemu_sem_wait(&p->sem); } @@ -714,13 +730,21 @@ void multifd_new_channel(QIOChannel *ioc) } qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); + qemu_sem_init(&p->ready, 0); p->quit =3D false; p->id =3D msg.id; + p->done =3D false; + multifd_init_pages(&p->pages); p->c =3D ioc; multifd_recv_state->count++; p->name =3D g_strdup_printf("multifdrecv_%d", msg.id); + object_ref(OBJECT(ioc)); + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); + if (multifd_recv_state->count =3D=3D migrate_multifd_channels()) { + migration_incoming_process(); + } } =20 int multifd_load_setup(void) @@ -735,6 +759,7 @@ int multifd_load_setup(void) multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); multifd_recv_state->count =3D 0; multifd_recv_state->quit =3D false; + multifd_init_pages(&multifd_recv_state->pages); return 0; } =20 @@ -743,6 +768,36 @@ int multifd_created_channels(void) return multifd_recv_state->count; } =20 +static void multifd_recv_page(uint8_t *address, uint16_t fd_num) +{ + int thread_count; + MultiFDRecvParams *p; + multifd_pages_t *pages =3D &multifd_recv_state->pages; + + pages->iov[pages->num].iov_base =3D address; + pages->iov[pages->num].iov_len =3D TARGET_PAGE_SIZE; + pages->num++; + + if (fd_num =3D=3D MULTIFD_CONTINUE) { + return; + } + + thread_count =3D migrate_multifd_channels(); + assert(fd_num < thread_count); + p =3D &multifd_recv_state->params[fd_num]; + + qemu_sem_wait(&p->ready); + + qemu_mutex_lock(&p->mutex); + p->done =3D false; + iov_copy(p->pages.iov, pages->num, pages->iov, pages->num, 0, + iov_size(pages->iov, pages->num)); + p->pages.num =3D pages->num; + pages->num =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); +} + /** * save_page_header: write page header to wire * @@ -3060,10 +3115,7 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) =20 case RAM_SAVE_FLAG_MULTIFD_PAGE: fd_num =3D qemu_get_be16(f); - if (fd_num !=3D 0) { - /* this is yet an unused variable, changed later */ - fd_num =3D fd_num; - } + multifd_recv_page(host, fd_num); qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 diff --git a/migration/socket.c b/migration/socket.c index 22fb05edc8..debe972ee8 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -186,6 +186,9 @@ out: if (migration_has_all_channels()) { /* Close listening socket as its no longer needed */ qio_channel_close(ioc, NULL); + if (!migrate_use_multifd()) { + migration_incoming_process(); + } return G_SOURCE_REMOVE; } else { return G_SOURCE_CONTINUE; --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114308646699.3820064474701; Wed, 4 Oct 2017 03:51:48 -0700 (PDT) Received: from localhost ([::1]:34296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhH7-0008Qf-1H for importer@patchew.org; Wed, 04 Oct 2017 06:51:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCc-0004yx-BT for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCb-000306-Hm for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCb-0002z4-9S for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 414D7C058EAA for ; Wed, 4 Oct 2017 10:46:56 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id B464C5D9CB; Wed, 4 Oct 2017 10:46:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 414D7C058EAA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:32 +0200 Message-Id: <20171004104636.7963-9-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 04 Oct 2017 10:46: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] [PATCH v9 08/12] migration: Test new fd infrastructure 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, dgilbert@redhat.com, peterx@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" We just send the address through the alternate channels and test that it is ok. Signed-off-by: Juan Quintela -- Use qio_channel_*all functions --- migration/ram.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 745da2971d..4c16d0775b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -492,8 +492,24 @@ static void *multifd_send_thread(void *opaque) break; } if (p->pages.num) { + Error *local_err =3D NULL; + size_t ret; + int i; + int num; + + num =3D p->pages.num; p->pages.num =3D 0; qemu_mutex_unlock(&p->mutex); + + for (i =3D 0; i < num; i++) { + ret =3D qio_channel_write_all(p->c, + (const char *)&p->pages.iov[i].iov_base, + sizeof(uint8_t *), &local_err); + if (ret !=3D 0) { + terminate_multifd_send_threads(local_err); + return NULL; + } + } qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; qemu_mutex_unlock(&multifd_send_state->mutex); @@ -675,6 +691,7 @@ int multifd_load_cleanup(Error **errp) static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; + uint8_t *recv_address; =20 qemu_sem_post(&p->ready); while (true) { @@ -684,7 +701,29 @@ static void *multifd_recv_thread(void *opaque) break; } if (p->pages.num) { + Error *local_err =3D NULL; + size_t ret; + int i; + int num; + + num =3D p->pages.num; p->pages.num =3D 0; + + for (i =3D 0; i < num; i++) { + ret =3D qio_channel_read_all(p->c, (char *)&recv_address, + sizeof(uint8_t *), &local_err); + if (ret !=3D 0) { + terminate_multifd_recv_threads(local_err); + return NULL; + } + if (recv_address !=3D p->pages.iov[i].iov_base) { + error_setg(&local_err, "received %p and expecting %p (= %d)", + recv_address, p->pages.iov[i].iov_base, i); + terminate_multifd_recv_threads(local_err); + return NULL; + } + } + p->done =3D true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 15071145164421023.140643499733; Wed, 4 Oct 2017 03:55:16 -0700 (PDT) Received: from localhost ([::1]:34310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhKY-00031E-Oy for importer@patchew.org; Wed, 04 Oct 2017 06:55:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCi-00054K-S1 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCf-00034q-Pt for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCf-00033Z-Kn for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A9FAC04AC74 for ; Wed, 4 Oct 2017 10:47:00 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DF7D5D9CB; Wed, 4 Oct 2017 10:46:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A9FAC04AC74 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:33 +0200 Message-Id: <20171004104636.7963-10-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 04 Oct 2017 10:47: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 v9 09/12] migration: Rename initial_bytes 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, dgilbert@redhat.com, peterx@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" Now it is called qemu_file_bytes that reflects better what it does, and we create qemu_file_bytes_now to not have to call qemu_ftell() twice. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 1e7c537954..54ef095d82 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2078,13 +2078,13 @@ static void *migration_thread(void *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; + int64_t qemu_file_bytes =3D 0; int64_t start_time =3D initial_time; int64_t end_time; bool old_vm_running =3D false; @@ -2172,8 +2172,9 @@ static void *migration_thread(void *opaque) } 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 qemu_file_bytes_now =3D qemu_ftell(s->to_dst_file); + uint64_t transferred_bytes =3D + qemu_file_bytes_now - qemu_file_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; @@ -2192,7 +2193,7 @@ static void *migration_thread(void *opaque) =20 qemu_file_reset_rate_limit(s->to_dst_file); initial_time =3D current_time; - initial_bytes =3D qemu_ftell(s->to_dst_file); + qemu_file_bytes =3D qemu_file_bytes_now; } if (qemu_file_rate_limit(s->to_dst_file)) { /* usleep expects microseconds */ --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114795690878.0650939464452; Wed, 4 Oct 2017 03:59:55 -0700 (PDT) Received: from localhost ([::1]:34333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhP0-00078H-VG for importer@patchew.org; Wed, 04 Oct 2017 06:59:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCi-00054I-RK for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCh-00036I-NU for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34536) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCh-00035r-Et for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A8F880E73 for ; Wed, 4 Oct 2017 10:47:02 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEAF85D9CB; Wed, 4 Oct 2017 10:47:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7A8F880E73 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:34 +0200 Message-Id: <20171004104636.7963-11-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 04 Oct 2017 10:47:02 +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 v9 10/12] migration: Transfer pages over new channels 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, dgilbert@redhat.com, peterx@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" We switch for sending the page number to send real pages. Signed-off-by: Juan Quintela -- Remove the HACK bit, now we have the function that calculates the size of a page exported. Rename multifd_pages{_now}, to sent pages Remove multifd pages field, it is the same than normal pages --- migration/migration.c | 7 ++++++- migration/ram.c | 39 +++++++++++---------------------------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 54ef095d82..1bd87a4e44 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2085,6 +2085,7 @@ static void *migration_thread(void *opaque) */ int64_t threshold_size =3D 0; int64_t qemu_file_bytes =3D 0; + int64_t sent_pages =3D 0; int64_t start_time =3D initial_time; int64_t end_time; bool old_vm_running =3D false; @@ -2173,8 +2174,11 @@ static void *migration_thread(void *opaque) current_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); if (current_time >=3D initial_time + BUFFER_DELAY) { uint64_t qemu_file_bytes_now =3D qemu_ftell(s->to_dst_file); + uint64_t sent_pages_now =3D ram_counters.normal; uint64_t transferred_bytes =3D - qemu_file_bytes_now - qemu_file_bytes; + (qemu_file_bytes_now - qemu_file_bytes) + + (sent_pages_now - sent_pages) * + qemu_target_page_size(); 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; @@ -2194,6 +2198,7 @@ static void *migration_thread(void *opaque) qemu_file_reset_rate_limit(s->to_dst_file); initial_time =3D current_time; qemu_file_bytes =3D qemu_file_bytes_now; + sent_pages =3D sent_pages_now; } if (qemu_file_rate_limit(s->to_dst_file)) { /* usleep expects microseconds */ diff --git a/migration/ram.c b/migration/ram.c index 4c16d0775b..981f345294 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -494,21 +494,15 @@ static void *multifd_send_thread(void *opaque) if (p->pages.num) { Error *local_err =3D NULL; size_t ret; - int i; int num; =20 num =3D p->pages.num; p->pages.num =3D 0; qemu_mutex_unlock(&p->mutex); - - for (i =3D 0; i < num; i++) { - ret =3D qio_channel_write_all(p->c, - (const char *)&p->pages.iov[i].iov_base, - sizeof(uint8_t *), &local_err); - if (ret !=3D 0) { - terminate_multifd_send_threads(local_err); - return NULL; - } + ret =3D qio_channel_writev_all(p->c, p->pages.iov, num, &local= _err); + if (ret !=3D 0) { + terminate_multifd_send_threads(local_err); + return NULL; } qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; @@ -691,7 +685,6 @@ int multifd_load_cleanup(Error **errp) static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; - uint8_t *recv_address; =20 qemu_sem_post(&p->ready); while (true) { @@ -703,27 +696,16 @@ static void *multifd_recv_thread(void *opaque) if (p->pages.num) { Error *local_err =3D NULL; size_t ret; - int i; int num; =20 num =3D p->pages.num; p->pages.num =3D 0; =20 - for (i =3D 0; i < num; i++) { - ret =3D qio_channel_read_all(p->c, (char *)&recv_address, - sizeof(uint8_t *), &local_err); - if (ret !=3D 0) { - terminate_multifd_recv_threads(local_err); - return NULL; - } - if (recv_address !=3D p->pages.iov[i].iov_base) { - error_setg(&local_err, "received %p and expecting %p (= %d)", - recv_address, p->pages.iov[i].iov_base, i); - terminate_multifd_recv_threads(local_err); - return NULL; - } + ret =3D qio_channel_readv_all(p->c, p->pages.iov, num, &local_= err); + if (ret !=3D 0) { + terminate_multifd_recv_threads(local_err); + return NULL; } - p->done =3D true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); @@ -1288,8 +1270,10 @@ static int ram_multifd_page(RAMState *rs, PageSearch= Status *pss, offset | RAM_SAVE_FLAG_MULTIFD_PAGE); fd_num =3D multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1= ); qemu_put_be16(rs->f, fd_num); + if (fd_num !=3D MULTIFD_CONTINUE) { + qemu_fflush(rs->f); + } ram_counters.transferred +=3D 2; /* size of fd_num */ - qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); ram_counters.transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; ram_counters.normal++; @@ -3155,7 +3139,6 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) case RAM_SAVE_FLAG_MULTIFD_PAGE: fd_num =3D qemu_get_be16(f); multifd_recv_page(host, fd_num); - qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 case RAM_SAVE_FLAG_EOS: --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114677145393.91351657421785; Wed, 4 Oct 2017 03:57:57 -0700 (PDT) Received: from localhost ([::1]:34325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhN0-0005Lf-6K for importer@patchew.org; Wed, 04 Oct 2017 06:57:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCk-000568-T7 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCj-00037C-Gy for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCj-00036i-7P for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 446D2C2D0D47 for ; Wed, 4 Oct 2017 10:47:04 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id D462C5D9CB; Wed, 4 Oct 2017 10:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 446D2C2D0D47 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:35 +0200 Message-Id: <20171004104636.7963-12-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 04 Oct 2017 10:47:04 +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 v9 11/12] migration: Flush receive queue 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, dgilbert@redhat.com, peterx@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" Each time that we sync the bitmap, it is a possiblity that we receive a page that is being processed by a different thread. We fix this problem just making sure that we wait for all receiving threads to finish its work before we procedeed with the next stage. We are low on page flags, so we use a combination that is not valid to emit that message: MULTIFD_PAGE and COMPRESSED. I tried to make a migration command for it, but it don't work because we sync the bitmap sometimes when we have already sent the beggining of the section, so I just added a new page flag. Signed-off-by: Juan Quintela -- Create RAM_SAVE_FLAG_MULTIFD_SYNC (dave suggestion) Move the set of need_flush to inside the bitmap_sync code (peter suggestion) --- migration/ram.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++= ++ 1 file changed, 55 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 981f345294..d717776f32 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -72,6 +72,14 @@ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 #define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 =20 +/* We are getting low on pages flags, so we start using combinations + When we need to flush a page, we sent it as + RAM_SAVE_FLAG_MULTIFD_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE + We don't allow that combination +*/ +#define RAM_SAVE_FLAG_MULTIFD_SYNC \ + (RAM_SAVE_FLAG_MULTIFD_PAGE | RAM_SAVE_FLAG_ZERO) + static inline bool is_zero_range(uint8_t *p, uint64_t size) { return buffer_is_zero(p, size); @@ -194,6 +202,9 @@ struct RAMState { uint64_t iterations_prev; /* Iterations since start */ uint64_t iterations; + /* Indicates if we have synced the bitmap and we need to assure that + target has processeed all previous pages */ + bool multifd_needs_flush; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; /* protects modification of the bitmap */ @@ -614,9 +625,11 @@ struct MultiFDRecvParams { QIOChannel *c; QemuSemaphore ready; QemuSemaphore sem; + QemuCond cond_sync; QemuMutex mutex; /* proteced by param mutex */ bool quit; + bool sync; multifd_pages_t pages; bool done; }; @@ -669,6 +682,7 @@ int multifd_load_cleanup(Error **errp) qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + qemu_cond_destroy(&p->cond_sync); socket_recv_channel_destroy(p->c); g_free(p->name); p->name =3D NULL; @@ -707,6 +721,10 @@ static void *multifd_recv_thread(void *opaque) return NULL; } p->done =3D true; + if (p->sync) { + qemu_cond_signal(&p->cond_sync); + p->sync =3D false; + } qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); continue; @@ -752,9 +770,11 @@ void multifd_new_channel(QIOChannel *ioc) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->ready, 0); + qemu_cond_init(&p->cond_sync); p->quit =3D false; p->id =3D msg.id; p->done =3D false; + p->sync =3D false; multifd_init_pages(&p->pages); p->c =3D ioc; multifd_recv_state->count++; @@ -819,6 +839,27 @@ static void multifd_recv_page(uint8_t *address, uint16= _t fd_num) qemu_sem_post(&p->sem); } =20 +static int multifd_flush(void) +{ + int i, thread_count; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_channels(); + for (i =3D 0; i < thread_count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + while (!p->done) { + p->sync =3D true; + qemu_cond_wait(&p->cond_sync, &p->mutex); + } + qemu_mutex_unlock(&p->mutex); + } + return 0; +} + /** * save_page_header: write page header to wire * @@ -836,6 +877,12 @@ static size_t save_page_header(RAMState *rs, QEMUFile = *f, RAMBlock *block, { size_t size, len; =20 + if (rs->multifd_needs_flush && + (offset & RAM_SAVE_FLAG_MULTIFD_PAGE)) { + offset |=3D RAM_SAVE_FLAG_ZERO; + rs->multifd_needs_flush =3D false; + } + if (block =3D=3D rs->last_sent_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; } @@ -1124,6 +1171,9 @@ static void migration_bitmap_sync(RAMState *rs) if (migrate_use_events()) { qapi_event_send_migration_pass(ram_counters.dirty_sync_count, NULL= ); } + if (!rs->ram_bulk_stage && migrate_use_multifd()) { + rs->multifd_needs_flush =3D true; + } } =20 /** @@ -3045,6 +3095,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; } =20 + if ((flags & RAM_SAVE_FLAG_MULTIFD_SYNC) + =3D=3D RAM_SAVE_FLAG_MULTIFD_SYNC) { + multifd_flush(); + flags =3D flags & ~RAM_SAVE_FLAG_ZERO; + } if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE | RAM_SAVE_FLAG_MULTIFD_PAGE)) { --=20 2.13.5 From nobody Thu May 2 01:44:08 2024 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 1507114457947822.2316264009713; Wed, 4 Oct 2017 03:54:17 -0700 (PDT) Received: from localhost ([::1]:34306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhJf-0002Cz-1t for importer@patchew.org; Wed, 04 Oct 2017 06:54:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCo-00059v-3s for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCl-000380-FZ for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48894) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCl-00037c-6G for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:47:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36F068B11B for ; Wed, 4 Oct 2017 10:47:06 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D7A65D9CB; Wed, 4 Oct 2017 10:47:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 36F068B11B Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:36 +0200 Message-Id: <20171004104636.7963-13-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Oct 2017 10:47:06 +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 v9 12/12] migration: Add multifd test 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, dgilbert@redhat.com, peterx@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" We set the x-multifd-page-count and x-multifd-channels. Signed-off-by: Juan Quintela --- tests/Makefile.include | 3 + tests/multifd-test.c | 511 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 514 insertions(+) create mode 100644 tests/multifd-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index d23ca1ed1c..69e3fd143d 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -289,6 +289,7 @@ check-qtest-i386-$(CONFIG_POSIX) +=3D tests/test-filter= -mirror$(EXESUF) check-qtest-i386-$(CONFIG_POSIX) +=3D tests/test-filter-redirector$(EXESUF) check-qtest-i386-y +=3D tests/migration-test$(EXESUF) check-qtest-i386-y +=3D tests/postcopy-test$(EXESUF) +check-qtest-i386-y +=3D tests/multifd-test$(EXESUF) check-qtest-i386-y +=3D tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y +=3D tests/numa-test$(EXESUF) check-qtest-x86_64-y +=3D $(check-qtest-i386-y) @@ -318,6 +319,7 @@ check-qtest-ppc64-y +=3D tests/pnv-xscom-test$(EXESUF) check-qtest-ppc64-y +=3D tests/drive_del-test$(EXESUF) check-qtest-ppc64-y +=3D tests/postcopy-test$(EXESUF) check-qtest-ppc64-y +=3D tests/migration-test$(EXESUF) +check-qtest-ppc64-y +=3D tests/multifd-test$(EXESUF) check-qtest-ppc64-y +=3D tests/boot-serial-test$(EXESUF) check-qtest-ppc64-y +=3D tests/rtas-test$(EXESUF) check-qtest-ppc64-$(CONFIG_SLIRP) +=3D tests/pxe-test$(EXESUF) @@ -785,6 +787,7 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-te= st.o $(libqos-usb-obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/postcopy-test$(EXESUF): tests/postcopy-test.o tests/migration-test$(EXESUF): tests/migration-test.o +tests/multifd-test$(EXESUF): tests/multifd-test.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y)= \ $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y)= \ $(chardev-obj-y) diff --git a/tests/multifd-test.c b/tests/multifd-test.c new file mode 100644 index 0000000000..2b90f8f7bd --- /dev/null +++ b/tests/multifd-test.c @@ -0,0 +1,511 @@ +/* + * QTest testcase for multifd + * + * Copyright (c) 2017 Red Hat, Inc. and/or its affiliates + * based on the postcopy-test.c which is based + * based on the vhost-user-test.c that is: + * Copyright (c) 2014 Virtual Open Systems Sarl. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "libqtest.h" +#include "qemu/option.h" +#include "qemu/range.h" +#include "qemu/sockets.h" +#include "chardev/char.h" +#include "sysemu/sysemu.h" +#include "hw/nvram/chrp_nvram.h" + +#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ + +const unsigned start_address =3D 1024 * 1024; +const unsigned end_address =3D 100 * 1024 * 1024; +bool got_stop; + +#if defined(__linux__) +#include +#include +#endif + +static const char *tmpfs; + +/* A simple PC boot sector that modifies memory (1-100MB) quickly + * outputing a 'B' every so often if it's still running. + */ +unsigned char bootsect[] =3D { + 0xfa, 0x0f, 0x01, 0x16, 0x74, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00, + 0x0f, 0x22, 0xc0, 0x66, 0xea, 0x20, 0x7c, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x92, 0x0c, 0x02, + 0xe6, 0x92, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x8e, 0xd8, 0x66, 0xb8, 0x41, + 0x00, 0x66, 0xba, 0xf8, 0x03, 0xee, 0xb3, 0x00, 0xb8, 0x00, 0x00, 0x10, + 0x00, 0xfe, 0x00, 0x05, 0x00, 0x10, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x40, + 0x06, 0x7c, 0xf2, 0xfe, 0xc3, 0x75, 0xe9, 0x66, 0xb8, 0x42, 0x00, 0x66, + 0xba, 0xf8, 0x03, 0xee, 0xeb, 0xde, 0x66, 0x90, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00, 0x27, 0x00, 0x5c, 0x7c, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa +}; + +static void init_bootfile_x86(const char *bootpath) +{ + FILE *bootfile =3D fopen(bootpath, "wb"); + + g_assert_cmpint(fwrite(bootsect, 512, 1, bootfile), =3D=3D, 1); + fclose(bootfile); +} + +static void init_bootfile_ppc(const char *bootpath) +{ + FILE *bootfile; + char buf[MIN_NVRAM_SIZE]; + ChrpNvramPartHdr *header =3D (ChrpNvramPartHdr *)buf; + + memset(buf, 0, MIN_NVRAM_SIZE); + + /* Create a "common" partition in nvram to store boot-command property= */ + + header->signature =3D CHRP_NVPART_SYSTEM; + memcpy(header->name, "common", 6); + chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE); + + /* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB, + * so let's modify memory between 1MB and 100MB + * to do like PC bootsector + */ + + sprintf(buf + 16, + "boot-command=3Dhex .\" _\" begin %x %x do i c@ 1 + i c! 1000 = +loop " + ".\" B\" 0 until", end_address, start_address); + + /* Write partition to the NVRAM file */ + + bootfile =3D fopen(bootpath, "wb"); + g_assert_cmpint(fwrite(buf, MIN_NVRAM_SIZE, 1, bootfile), =3D=3D, 1); + fclose(bootfile); +} + +/* + * Wait for some output in the serial output file, + * we get an 'A' followed by an endless string of 'B's + * but on the destination we won't have the A. + */ +static void wait_for_serial(const char *side) +{ + char *serialpath =3D g_strdup_printf("%s/%s", tmpfs, side); + FILE *serialfile =3D fopen(serialpath, "r"); + const char *arch =3D qtest_get_arch(); + int started =3D (strcmp(side, "src_serial") =3D=3D 0 && + strcmp(arch, "ppc64") =3D=3D 0) ? 0 : 1; + + g_free(serialpath); + do { + int readvalue =3D fgetc(serialfile); + + if (!started) { + /* SLOF prints its banner before starting test, + * to ignore it, mark the start of the test with '_', + * ignore all characters until this marker + */ + switch (readvalue) { + case '_': + started =3D 1; + break; + case EOF: + fseek(serialfile, 0, SEEK_SET); + usleep(1000); + break; + } + continue; + } + switch (readvalue) { + case 'A': + /* Fine */ + break; + + case 'B': + /* It's alive! */ + fclose(serialfile); + return; + + case EOF: + started =3D (strcmp(side, "src_serial") =3D=3D 0 && + strcmp(arch, "ppc64") =3D=3D 0) ? 0 : 1; + fseek(serialfile, 0, SEEK_SET); + usleep(1000); + break; + + default: + fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, sid= e); + g_assert_not_reached(); + } + } while (true); +} + +/* + * Events can get in the way of responses we are actually waiting for. + */ +static QDict *return_or_event(QDict *response) +{ + const char *event_string; + if (!qdict_haskey(response, "event")) { + return response; + } + + /* OK, it was an event */ + event_string =3D qdict_get_str(response, "event"); + if (!strcmp(event_string, "STOP")) { + got_stop =3D true; + } + QDECREF(response); + return return_or_event(qtest_qmp_receive(global_qtest)); +} + + +/* + * It's tricky to use qemu's migration event capability with qtest, + * events suddenly appearing confuse the qmp()/hmp() responses. + * so wait for a couple of passes to have happened before + * going postcopy. + */ + +static uint64_t get_migration_pass(void) +{ + QDict *rsp, *rsp_return, *rsp_ram; + uint64_t result; + + rsp =3D return_or_event(qmp("{ 'execute': 'query-migrate' }")); + rsp_return =3D qdict_get_qdict(rsp, "return"); + if (!qdict_haskey(rsp_return, "ram")) { + /* Still in setup */ + result =3D 0; + } else { + rsp_ram =3D qdict_get_qdict(rsp_return, "ram"); + result =3D qdict_get_try_int(rsp_ram, "dirty-sync-count", 0); + } + QDECREF(rsp); + return result; +} + +static void wait_for_migration_complete(void) +{ + QDict *rsp, *rsp_return; + bool completed; + + do { + const char *status; + + rsp =3D return_or_event(qmp("{ 'execute': 'query-migrate' }")); + rsp_return =3D qdict_get_qdict(rsp, "return"); + status =3D qdict_get_str(rsp_return, "status"); + completed =3D strcmp(status, "completed") =3D=3D 0; + g_assert_cmpstr(status, !=3D, "failed"); + QDECREF(rsp); + usleep(1000 * 100); + } while (!completed); +} + +static void wait_for_migration_pass(void) +{ + uint64_t initial_pass =3D get_migration_pass(); + uint64_t pass; + + /* Wait for the 1st sync */ + do { + initial_pass =3D get_migration_pass(); + if (got_stop || initial_pass) { + break; + } + usleep(1000 * 100); + } while (true); + + do { + usleep(1000 * 100); + pass =3D get_migration_pass(); + } while (pass =3D=3D initial_pass && !got_stop); +} + +static void check_guests_ram(void) +{ + /* Our ASM test will have been incrementing one byte from each page fr= om + * 1MB to <100MB in order. + * This gives us a constraint that any page's byte should be equal or = less + * than the previous pages byte (mod 256); and they should all be equal + * except for one transition at the point where we meet the incremente= r. + * (We're running this with the guest stopped). + */ + unsigned address; + uint8_t first_byte; + uint8_t last_byte; + bool hit_edge =3D false; + bool bad =3D false; + + qtest_memread(global_qtest, start_address, &first_byte, 1); + last_byte =3D first_byte; + + for (address =3D start_address + 4096; address < end_address; address = +=3D 4096) + { + uint8_t b; + qtest_memread(global_qtest, address, &b, 1); + if (b !=3D last_byte) { + if (((b + 1) % 256) =3D=3D last_byte && !hit_edge) { + /* This is OK, the guest stopped at the point of + * incrementing the previous page but didn't get + * to us yet. + */ + hit_edge =3D true; + } else { + fprintf(stderr, "Memory content inconsistency at %x" + " first_byte =3D %x last_byte =3D %x curre= nt =3D %x" + " hit_edge =3D %x\n", + address, first_byte, last_byte, b, hit_edg= e); + bad =3D true; + } + } + last_byte =3D b; + } + g_assert_false(bad); +} + +static void cleanup(const char *filename) +{ + char *path =3D g_strdup_printf("%s/%s", tmpfs, filename); + + unlink(path); + g_free(path); +} + +static void test_migrate(void) +{ + char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *global =3D global_qtest, *from, *to; + unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; + gchar *cmd, *cmd_src, *cmd_dst; + QDict *rsp; + + char *bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); + const char *arch =3D qtest_get_arch(); + + got_stop =3D false; + + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { + init_bootfile_x86(bootpath); + cmd_src =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" + " -name pcsource,debug-threads=3Don" + " -serial file:%s/src_serial" + " -drive file=3D%s,format=3Draw", + tmpfs, bootpath); + cmd_dst =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" + " -name pcdest,debug-threads=3Don" + " -serial file:%s/dest_serial" + " -drive file=3D%s,format=3Draw" + " -incoming %s", + tmpfs, bootpath, uri); + } else if (strcmp(arch, "ppc64") =3D=3D 0) { + const char *accel; + + /* On ppc64, the test only works with kvm-hv, but not with kvm-pr = */ + accel =3D access("/sys/module/kvm_hv", F_OK) ? "tcg" : "kvm:tcg"; + init_bootfile_ppc(bootpath); + cmd_src =3D g_strdup_printf("-machine accel=3D%s -m 256M" + " -name pcsource,debug-threads=3Don" + " -serial file:%s/src_serial" + " -drive file=3D%s,if=3Dpflash,format=3D= raw", + accel, tmpfs, bootpath); + cmd_dst =3D g_strdup_printf("-machine accel=3D%s -m 256M" + " -name pcdest,debug-threads=3Don" + " -serial file:%s/dest_serial" + " -incoming %s", + accel, tmpfs, uri); + } else { + g_assert_not_reached(); + } + + g_free(bootpath); + + from =3D qtest_start(cmd_src); + g_free(cmd_src); + + to =3D qtest_init(cmd_dst); + g_free(cmd_dst); + + global_qtest =3D from; + rsp =3D qmp("{ 'execute': 'migrate-set-capabilities'," + "'arguments': { " + "'capabilities': [ {" + "'capability': 'x-multifd'," + "'state': true } ] } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + global_qtest =3D to; + rsp =3D qmp("{ 'execute': 'migrate-set-capabilities'," + "'arguments': { " + "'capabilities': [ {" + "'capability': 'x-multifd'," + "'state': true } ] } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + /* We want to pick a speed slow enough that the test completes + * quickly, but that it doesn't complete precopy even on a slow + * machine, so also set the downtime. + */ + global_qtest =3D from; + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'max-bandwidth': 100000000 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + /* 200ms downtime */ + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'downtime-limit': 300 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + /* set 4 channels */ + global_qtest =3D to; + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'x-multifd-channels': 4 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'x-multifd-page-count': 64 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + /* set 4 channels */ + global_qtest =3D from; + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'x-multifd-channels': 4 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + rsp =3D qmp("{ 'execute': 'migrate-set-parameters'," + "'arguments': { 'x-multifd-page-count': 64 } }"); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + + /* Wait for the first serial output from the source */ + wait_for_serial("src_serial"); + + cmd =3D g_strdup_printf("{ 'execute': 'migrate'," + "'arguments': { 'uri': '%s' } }", + uri); + rsp =3D qmp(cmd); + g_free(cmd); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + wait_for_migration_pass(); + + if (!got_stop) { + qmp_eventwait("STOP"); + } + + global_qtest =3D to; + qmp_eventwait("RESUME"); + + wait_for_serial("dest_serial"); + global_qtest =3D from; + wait_for_migration_complete(); + + qtest_quit(from); + + global_qtest =3D to; + + qtest_memread(to, start_address, &dest_byte_a, 1); + + /* Destination still running, wait for a byte to change */ + do { + qtest_memread(to, start_address, &dest_byte_b, 1); + usleep(10 * 1000); + } while (dest_byte_a =3D=3D dest_byte_b); + + qmp_discard_response("{ 'execute' : 'stop'}"); + /* With it stopped, check nothing changes */ + qtest_memread(to, start_address, &dest_byte_c, 1); + sleep(1); + qtest_memread(to, start_address, &dest_byte_d, 1); + g_assert_cmpint(dest_byte_c, =3D=3D, dest_byte_d); + + check_guests_ram(); + + qtest_quit(to); + g_free(uri); + + global_qtest =3D global; + + cleanup("bootsect"); + cleanup("migsocket"); + cleanup("src_serial"); + cleanup("dest_serial"); +} + +int main(int argc, char **argv) +{ + char template[] =3D "/tmp/multifd-test-XXXXXX"; + int ret; + + g_test_init(&argc, &argv, NULL); + + tmpfs =3D mkdtemp(template); + if (!tmpfs) { + g_test_message("mkdtemp on path (%s): %s\n", template, strerror(er= rno)); + } + g_assert(tmpfs); + + module_call_init(MODULE_INIT_QOM); + + qtest_add_func("/multifd", test_migrate); + + ret =3D g_test_run(); + + g_assert_cmpint(ret, =3D=3D, 0); + + ret =3D rmdir(tmpfs); + if (ret !=3D 0) { + g_test_message("unable to rmdir: path (%s): %s\n", + tmpfs, strerror(errno)); + } + + return ret; +} --=20 2.13.5