From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201570946737.1435819318699; Fri, 16 Mar 2018 04:59:30 -0700 (PDT) Received: from localhost ([::1]:56257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo1C-00020X-25 for importer@patchew.org; Fri, 16 Mar 2018 07:59:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006ds-6t for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwA-0002Wb-59 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34966 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwA-0002W9-15 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4D204023156 for ; Fri, 16 Mar 2018 11:54:12 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7EEFC1FB3; Fri, 16 Mar 2018 11:54:11 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:49 +0100 Message-Id: <20180316115403.4148-2-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:12 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 01/15] migration: Set error state in case of 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" Signed-off-by: Juan Quintela --- migration/ram.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 7266351fd0..1b8095a358 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -414,6 +414,16 @@ static void terminate_multifd_send_threads(Error *errp) { int i; =20 + if (errp) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, errp); + if (s->state =3D=3D MIGRATION_STATUS_SETUP || + s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } + } + for (i =3D 0; i < multifd_send_state->count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -514,6 +524,16 @@ static void terminate_multifd_recv_threads(Error *errp) { int i; =20 + if (errp) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, errp); + if (s->state =3D=3D MIGRATION_STATUS_SETUP || + s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } + } + for (i =3D 0; i < multifd_recv_state->count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201569676975.4288904406125; Fri, 16 Mar 2018 04:59:29 -0700 (PDT) Received: from localhost ([::1]:56256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo1A-0001zf-SC for importer@patchew.org; Fri, 16 Mar 2018 07:59:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006dq-5q for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwA-0002WY-4u for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33544 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwA-0002W7-1B for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2ACEC401CC41 for ; Fri, 16 Mar 2018 11:54:14 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FEFDC213F; Fri, 16 Mar 2018 11:54:12 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:50 +0100 Message-Id: <20180316115403.4148-3-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:14 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 02/15] migration: In case of error just end the migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 -- As requested, just continue connection in case of error. --- migration/socket.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/migration/socket.c b/migration/socket.c index 52db0c0c09..8dda1d9a98 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -140,9 +140,7 @@ static gboolean socket_accept_incoming_migration(QIOCha= nnel *ioc, sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), &err); if (!sioc) { - error_report("could not accept migration connection (%s)", - error_get_pretty(err)); - goto out; + return G_SOURCE_CONTINUE; } =20 trace_migration_socket_incoming_accepted(); @@ -151,7 +149,6 @@ static gboolean socket_accept_incoming_migration(QIOCha= nnel *ioc, migration_channel_process_incoming(QIO_CHANNEL(sioc)); object_unref(OBJECT(sioc)); =20 -out: if (migration_has_all_channels()) { /* Close listening socket as its no longer needed */ qio_channel_close(ioc, NULL); --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201404672358.67719979065146; Fri, 16 Mar 2018 04:56:44 -0700 (PDT) Received: from localhost ([::1]:56246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnyP-0007z8-1p for importer@patchew.org; Fri, 16 Mar 2018 07:56:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006do-5n for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwA-0002Wl-5X for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52328 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwA-0002W6-16 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1E14406E96C for ; Fri, 16 Mar 2018 11:54:15 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D2C8D1EB1; Fri, 16 Mar 2018 11:54:14 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:51 +0100 Message-Id: <20180316115403.4148-4-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 03/15] migration: terminate_* can be called for other threads 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" Once there, make count field to always be accessed with atomic operations. To make blocking operations, we need to know that the thread is running, so create a bool to indicate that. Signed-off-by: Juan Quintela -- Once here, s/terminate_multifd_*-threads/multifd_*_terminate_threads/ This is consistente with every other function Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/ram.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 1b8095a358..2d51c8b94c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -400,6 +400,7 @@ struct MultiFDSendParams { QemuThread thread; QemuSemaphore sem; QemuMutex mutex; + bool running; bool quit; }; typedef struct MultiFDSendParams MultiFDSendParams; @@ -410,7 +411,7 @@ struct { int count; } *multifd_send_state; =20 -static void terminate_multifd_send_threads(Error *errp) +static void multifd_send_terminate_threads(Error *errp) { int i; =20 @@ -424,7 +425,7 @@ static void terminate_multifd_send_threads(Error *errp) } } =20 - for (i =3D 0; i < multifd_send_state->count; i++) { + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 qemu_mutex_lock(&p->mutex); @@ -442,11 +443,13 @@ int multifd_save_cleanup(Error **errp) if (!migrate_use_multifd()) { return 0; } - terminate_multifd_send_threads(NULL); - for (i =3D 0; i < multifd_send_state->count; i++) { + multifd_send_terminate_threads(NULL); + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 - qemu_thread_join(&p->thread); + if (p->running) { + qemu_thread_join(&p->thread); + } qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); g_free(p->name); @@ -466,6 +469,7 @@ static void *multifd_send_thread(void *opaque) while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { + p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } @@ -487,7 +491,7 @@ int multifd_save_setup(void) thread_count =3D migrate_multifd_channels(); 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; + atomic_set(&multifd_send_state->count, 0); for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -496,10 +500,11 @@ int multifd_save_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdsend_%d", i); + p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, QEMU_THREAD_JOINABLE); =20 - multifd_send_state->count++; + atomic_inc(&multifd_send_state->count); } return 0; } @@ -510,6 +515,7 @@ struct MultiFDRecvParams { QemuThread thread; QemuSemaphore sem; QemuMutex mutex; + bool running; bool quit; }; typedef struct MultiFDRecvParams MultiFDRecvParams; @@ -520,7 +526,7 @@ struct { int count; } *multifd_recv_state; =20 -static void terminate_multifd_recv_threads(Error *errp) +static void multifd_recv_terminate_threads(Error *errp) { int i; =20 @@ -534,7 +540,7 @@ static void terminate_multifd_recv_threads(Error *errp) } } =20 - for (i =3D 0; i < multifd_recv_state->count; i++) { + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 qemu_mutex_lock(&p->mutex); @@ -552,11 +558,13 @@ int multifd_load_cleanup(Error **errp) if (!migrate_use_multifd()) { return 0; } - terminate_multifd_recv_threads(NULL); - for (i =3D 0; i < multifd_recv_state->count; i++) { + multifd_recv_terminate_threads(NULL); + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 - qemu_thread_join(&p->thread); + if (p->running) { + qemu_thread_join(&p->thread); + } qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); g_free(p->name); @@ -577,6 +585,7 @@ static void *multifd_recv_thread(void *opaque) while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { + p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } @@ -598,7 +607,7 @@ int multifd_load_setup(void) thread_count =3D migrate_multifd_channels(); 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; + atomic_set(&multifd_recv_state->count, 0); for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 @@ -607,9 +616,10 @@ int multifd_load_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdrecv_%d", i); + p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); - multifd_recv_state->count++; + atomic_inc(&multifd_recv_state->count); } return 0; } --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201401661540.4595830409446; Fri, 16 Mar 2018 04:56:41 -0700 (PDT) Received: from localhost ([::1]:56244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnyM-0007xT-CH for importer@patchew.org; Fri, 16 Mar 2018 07:56:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006dp-5n for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwA-0002WZ-54 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33546 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwA-0002W8-1A for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B4B14036114 for ; Fri, 16 Mar 2018 11:54:17 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FB42C225F; Fri, 16 Mar 2018 11:54:15 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:52 +0100 Message-Id: <20180316115403.4148-5-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:17 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 04/15] migration: Introduce multifd_recv_new_channel() 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" Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/migration.c | 3 ++- migration/ram.c | 6 ++++++ migration/ram.h | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 3b811c213a..21c651b4ee 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -448,8 +448,9 @@ void migration_ioc_process_incoming(QIOChannel *ioc) if (!mis->from_src_file) { QEMUFile *f =3D qemu_fopen_channel_input(ioc); migration_fd_process_incoming(f); + return; } - /* We still only have a single channel. Nothing to do here yet */ + multifd_recv_new_channel(ioc); } =20 /** diff --git a/migration/ram.c b/migration/ram.c index 2d51c8b94c..f958a7aad3 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" @@ -624,6 +625,11 @@ int multifd_load_setup(void) return 0; } =20 +void multifd_recv_new_channel(QIOChannel *ioc) +{ + /* nothing to do yet */ +} + /** * save_page_header: write page header to wire * diff --git a/migration/ram.h b/migration/ram.h index 53f0021c51..a2031acf59 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -32,6 +32,7 @@ #include "qemu-common.h" #include "qapi/qapi-types-migration.h" #include "exec/cpu-common.h" +#include "io/channel.h" =20 extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; @@ -44,6 +45,7 @@ int multifd_save_setup(void); int multifd_save_cleanup(Error **errp); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); +void multifd_recv_new_channel(QIOChannel *ioc); =20 uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201404620232.60761647060792; Fri, 16 Mar 2018 04:56:44 -0700 (PDT) Received: from localhost ([::1]:56243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnyL-0007wD-5Q for importer@patchew.org; Fri, 16 Mar 2018 07:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006dr-5s for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwB-0002XC-2F for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34968 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwA-0002Ww-Uq for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79F894023156 for ; Fri, 16 Mar 2018 11:54:18 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E99FC1FB5; Fri, 16 Mar 2018 11:54:17 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:53 +0100 Message-Id: <20180316115403.4148-6-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:18 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 05/15] migration: Be sure all recv channels are created 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 need them before we start migration. Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/migration.c | 6 +++++- migration/ram.c | 11 +++++++++++ migration/ram.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 21c651b4ee..b3c6198e12 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -461,7 +461,11 @@ void migration_ioc_process_incoming(QIOChannel *ioc) */ bool migration_has_all_channels(void) { - return true; + bool all_channels; + + all_channels =3D multifd_recv_all_channels_created(); + + return all_channels; } =20 /* diff --git a/migration/ram.c b/migration/ram.c index f958a7aad3..7e60fc82a6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -625,6 +625,17 @@ int multifd_load_setup(void) return 0; } =20 +bool multifd_recv_all_channels_created(void) +{ + int thread_count =3D migrate_multifd_channels(); + + if (!migrate_use_multifd()) { + return true; + } + + return thread_count =3D=3D atomic_read(&multifd_recv_state->count); +} + void multifd_recv_new_channel(QIOChannel *ioc) { /* nothing to do yet */ diff --git a/migration/ram.h b/migration/ram.h index a2031acf59..3daf074bcc 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -45,6 +45,7 @@ int multifd_save_setup(void); int multifd_save_cleanup(Error **errp); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); +bool multifd_recv_all_channels_created(void); void multifd_recv_new_channel(QIOChannel *ioc); =20 uint64_t ram_pagesize_summary(void); --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201765314919.7158652189818; Fri, 16 Mar 2018 05:02:45 -0700 (PDT) Received: from localhost ([::1]:56277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo4B-0004Zt-M0 for importer@patchew.org; Fri, 16 Mar 2018 08:02:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006dn-59 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwC-0002Y7-EJ for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52330 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwC-0002Xt-94 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4EA1406E96C for ; Fri, 16 Mar 2018 11:54:19 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC5A1C1FB5; Fri, 16 Mar 2018 11:54:18 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:54 +0100 Message-Id: <20180316115403.4148-7-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:19 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 06/15] migration: Export functions to create send 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" Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/socket.c | 28 +++++++++++++++++++++++++++- migration/socket.h | 7 +++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/migration/socket.c b/migration/socket.c index 8dda1d9a98..7889753fab 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -28,6 +28,28 @@ #include "trace.h" =20 =20 +struct SocketOutgoingArgs { + SocketAddress *saddr; +} outgoing_args; + +void socket_send_channel_create(QIOTaskFunc f, void *data) +{ + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + qio_channel_socket_connect_async(sioc, outgoing_args.saddr, + f, data, NULL, 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; +} + static SocketAddress *tcp_build_address(const char *host_port, Error **err= p) { SocketAddress *saddr; @@ -95,6 +117,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); } @@ -106,7 +133,6 @@ static void socket_start_outgoing_migration(MigrationSt= ate *s, data, socket_connect_data_free, NULL); - qapi_free_SocketAddress(saddr); } =20 void tcp_start_outgoing_migration(MigrationState *s, diff --git a/migration/socket.h b/migration/socket.h index 6b91e9db38..528c3b0202 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -16,6 +16,13 @@ =20 #ifndef QEMU_MIGRATION_SOCKET_H #define QEMU_MIGRATION_SOCKET_H + +#include "io/channel.h" +#include "io/task.h" + +void socket_send_channel_create(QIOTaskFunc f, 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.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 152120140171818.779759560953835; Fri, 16 Mar 2018 04:56:41 -0700 (PDT) Received: from localhost ([::1]:56245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnyN-0007xv-FK for importer@patchew.org; Fri, 16 Mar 2018 07:56:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwE-0006dy-V0 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwD-0002Z9-Tj for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33548 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwD-0002Yo-NZ for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40BA7401CC41 for ; Fri, 16 Mar 2018 11:54:21 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13EF2C1FE0; Fri, 16 Mar 2018 11:54:19 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:55 +0100 Message-Id: <20180316115403.4148-8-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:21 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 07/15] migration: Synchronize send threads 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 synchronize all threads each RAM_SAVE_FLAG_EOS. Bitmap synchronizations don't happen inside a ram section, so we are safe about two channels trying to overwrite the same memory. Signed-off-by: Juan Quintela --- migration/ram.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++= +++- migration/trace-events | 3 +++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 7e60fc82a6..6aeb63f6ef 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -403,6 +403,7 @@ struct MultiFDSendParams { QemuMutex mutex; bool running; bool quit; + bool sync; }; typedef struct MultiFDSendParams MultiFDSendParams; =20 @@ -410,6 +411,8 @@ struct { MultiFDSendParams *params; /* number of created threads */ int count; + /* syncs main thread and channels */ + QemuSemaphore sem_main; } *multifd_send_state; =20 static void multifd_send_terminate_threads(Error *errp) @@ -456,6 +459,7 @@ int multifd_save_cleanup(Error **errp) g_free(p->name); p->name =3D NULL; } + qemu_sem_destroy(&multifd_send_state->sem_main); g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; g_free(multifd_send_state); @@ -463,19 +467,59 @@ int multifd_save_cleanup(Error **errp) return ret; } =20 +static void multifd_send_sync_main(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + trace_multifd_send_sync_signal(p->id, p->quit, p->running); + + qemu_mutex_lock(&p->mutex); + p->sync =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + bool wait; + + trace_multifd_send_sync_wait(p->id, p->quit, p->running); + + qemu_mutex_lock(&p->mutex); + wait =3D p->running; + qemu_mutex_unlock(&p->mutex); + + if (wait) { + qemu_sem_wait(&multifd_send_state->sem_main); + } + } + trace_multifd_send_sync_main(); +} + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; =20 while (true) { + qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); + if (p->sync) { + p->sync =3D false; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&multifd_send_state->sem_main); + continue; + } if (p->quit) { p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); - qemu_sem_wait(&p->sem); } =20 return NULL; @@ -493,6 +537,8 @@ 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); atomic_set(&multifd_send_state->count, 0); + qemu_sem_init(&multifd_send_state->sem_main, 0); + for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -507,6 +553,7 @@ int multifd_save_setup(void) =20 atomic_inc(&multifd_send_state->count); } + return 0; } =20 @@ -2283,6 +2330,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 + multifd_send_sync_main(); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); =20 return 0; @@ -2358,6 +2406,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) */ ram_control_after_iterate(f, RAM_CONTROL_ROUND); =20 + multifd_send_sync_main(); out: qemu_put_be64(f, RAM_SAVE_FLAG_EOS); ram_counters.transferred +=3D 8; @@ -2411,6 +2460,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) =20 rcu_read_unlock(); =20 + multifd_send_sync_main(); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); =20 return 0; diff --git a/migration/trace-events b/migration/trace-events index 93961dea16..845612c177 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -77,6 +77,9 @@ ram_load_postcopy_loop(uint64_t addr, int flags) "@%" PRI= x64 " %x" ram_postcopy_send_discard_bitmap(void) "" ram_save_page(const char *rbname, uint64_t offset, void *host) "%s: offset= : 0x%" PRIx64 " host: %p" ram_save_queue_pages(const char *rbname, size_t start, size_t len) "%s: st= art: 0x%zx len: 0x%zx" +multifd_send_sync_main(void) "" +multifd_send_sync_signal(uint8_t id, bool quit, bool running) "channel %d = quit %d running %d" +multifd_send_sync_wait(uint8_t id, bool quit, bool running) "channel %d qu= it %d running %d" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152120157262460.31681162370319; Fri, 16 Mar 2018 04:59:32 -0700 (PDT) Received: from localhost ([::1]:56259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo1D-00022W-Mp for importer@patchew.org; Fri, 16 Mar 2018 07:59:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwG-0006ed-A0 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwF-0002b2-56 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34970 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwF-0002a2-0o for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C7664023156 for ; Fri, 16 Mar 2018 11:54:22 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82F4EC1FE0; Fri, 16 Mar 2018 11:54:21 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:56 +0100 Message-Id: <20180316115403.4148-9-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:22 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 08/15] migration: Synchronize recv threads 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 synchronize all threads each RAM_SAVE_FLAG_EOS. Bitmap synchronizations don't happen inside a ram section, so we are safe about two channels trying to overwrite the same memory. Signed-off-by: Juan Quintela --- migration/ram.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++= ++- migration/trace-events | 3 +++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 6aeb63f6ef..4ba03cf9c9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -565,6 +565,7 @@ struct MultiFDRecvParams { QemuMutex mutex; bool running; bool quit; + bool sync; }; typedef struct MultiFDRecvParams MultiFDRecvParams; =20 @@ -572,6 +573,8 @@ struct { MultiFDRecvParams *params; /* number of created threads */ int count; + /* syncs main thread and channels */ + QemuSemaphore sem_main; } *multifd_recv_state; =20 static void multifd_recv_terminate_threads(Error *errp) @@ -618,6 +621,7 @@ int multifd_load_cleanup(Error **errp) g_free(p->name); p->name =3D NULL; } + qemu_sem_destroy(&multifd_recv_state->sem_main); g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; g_free(multifd_recv_state); @@ -626,19 +630,59 @@ int multifd_load_cleanup(Error **errp) return ret; } =20 +static void multifd_recv_sync_main(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + trace_multifd_recv_sync_signal(p->id, p->quit, p->running); + + qemu_mutex_lock(&p->mutex); + p->sync =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + bool wait; + + trace_multifd_recv_sync_wait(p->id, p->quit, p->running); + + qemu_mutex_lock(&p->mutex); + wait =3D p->running; + qemu_mutex_unlock(&p->mutex); + + if (wait) { + qemu_sem_wait(&multifd_recv_state->sem_main); + } + } + trace_multifd_recv_sync_main(); +} + static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 while (true) { + qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); + if (p->sync) { + p->sync =3D false; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&multifd_recv_state->sem_main); + continue; + } if (p->quit) { p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); - qemu_sem_wait(&p->sem); } =20 return NULL; @@ -656,6 +700,7 @@ 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); atomic_set(&multifd_recv_state->count, 0); + qemu_sem_init(&multifd_recv_state->sem_main, 0); for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 @@ -2890,6 +2935,7 @@ static int ram_load_postcopy(QEMUFile *f) break; case RAM_SAVE_FLAG_EOS: /* normal exit */ + multifd_recv_sync_main(); break; default: error_report("Unknown combination of migration flags: %#x" @@ -3075,6 +3121,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) break; case RAM_SAVE_FLAG_EOS: /* normal exit */ + multifd_recv_sync_main(); break; default: if (flags & RAM_SAVE_FLAG_HOOK) { diff --git a/migration/trace-events b/migration/trace-events index 845612c177..551d325daf 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -80,6 +80,9 @@ ram_save_queue_pages(const char *rbname, size_t start, si= ze_t len) "%s: start: 0 multifd_send_sync_main(void) "" multifd_send_sync_signal(uint8_t id, bool quit, bool running) "channel %d = quit %d running %d" multifd_send_sync_wait(uint8_t id, bool quit, bool running) "channel %d qu= it %d running %d" +multifd_recv_sync_main(void) "" +multifd_recv_sync_signal(uint8_t id, bool quit, bool running) "channel %d = quit %d running %d" +multifd_recv_sync_wait(uint8_t id, bool quit, bool running) "channel %d qu= it %d running %d" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201764828158.5544376377443; Fri, 16 Mar 2018 05:02:44 -0700 (PDT) Received: from localhost ([::1]:56278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo4E-0004ch-Q4 for importer@patchew.org; Fri, 16 Mar 2018 08:02:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwH-0006fA-Ie for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwG-0002cV-G8 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37984 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwG-0002bn-Bu for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DACA08151D47 for ; Fri, 16 Mar 2018 11:54:23 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF962C1FE0; Fri, 16 Mar 2018 11:54:22 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:57 +0100 Message-Id: <20180316115403.4148-10-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 09/15] migration: Add multifd traces for start/end thread 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-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/ram.c | 6 ++++++ migration/trace-events | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 4ba03cf9c9..7d9e363bbe 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -505,6 +505,8 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; =20 + trace_multifd_send_thread_start(p->id); + while (true) { qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); @@ -521,6 +523,7 @@ static void *multifd_send_thread(void *opaque) } qemu_mutex_unlock(&p->mutex); } + trace_multifd_send_thread_end(p->id); =20 return NULL; } @@ -668,6 +671,8 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 + trace_multifd_recv_thread_start(p->id); + while (true) { qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); @@ -685,6 +690,7 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); } =20 + trace_multifd_recv_thread_end(p->id); return NULL; } =20 diff --git a/migration/trace-events b/migration/trace-events index 551d325daf..9c92d3ec14 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -83,6 +83,10 @@ multifd_send_sync_wait(uint8_t id, bool quit, bool runni= ng) "channel %d quit %d multifd_recv_sync_main(void) "" multifd_recv_sync_signal(uint8_t id, bool quit, bool running) "channel %d = quit %d running %d" multifd_recv_sync_wait(uint8_t id, bool quit, bool running) "channel %d qu= it %d running %d" +multifd_send_thread_start(uint8_t id) "%d" +multifd_send_thread_end(uint8_t id) "%d" +multifd_recv_thread_start(uint8_t id) "%d" +multifd_recv_thread_end(uint8_t id) "%d" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521202075962648.2267066575632; Fri, 16 Mar 2018 05:07:55 -0700 (PDT) Received: from localhost ([::1]:56336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo9B-0000Oe-Df for importer@patchew.org; Fri, 16 Mar 2018 08:07:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwN-0006kP-G6 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwH-0002dp-Rc for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37988 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwH-0002dL-MB for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35DF38160F98 for ; Fri, 16 Mar 2018 11:54:25 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AEA5C1FE0; Fri, 16 Mar 2018 11:54:24 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:58 +0100 Message-Id: <20180316115403.4148-11-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 10/15] migration: Create multifd 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" In both sides. We still don't transmit anything through them. Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/ram.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7d9e363bbe..5dade41243 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -399,6 +399,7 @@ struct MultiFDSendParams { uint8_t id; char *name; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool running; @@ -454,6 +455,8 @@ int multifd_save_cleanup(Error **errp) if (p->running) { qemu_thread_join(&p->thread); } + socket_send_channel_destroy(p->c); + p->c =3D NULL; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); g_free(p->name); @@ -528,6 +531,25 @@ static void *multifd_send_thread(void *opaque) return NULL; } =20 +static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) +{ + MultiFDSendParams *p =3D opaque; + QIOChannel *sioc =3D QIO_CHANNEL(qio_task_get_source(task)); + Error *local_err =3D NULL; + + if (qio_task_propagate_error(task, &local_err)) { + multifd_send_terminate_threads(local_err); + } else { + p->c =3D QIO_CHANNEL(sioc); + qio_channel_set_delay(p->c, false); + p->running =3D true; + qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, + QEMU_THREAD_JOINABLE); + + atomic_inc(&multifd_send_state->count); + } +} + int multifd_save_setup(void) { int thread_count; @@ -550,11 +572,7 @@ int multifd_save_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdsend_%d", i); - p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); - - atomic_inc(&multifd_send_state->count); + socket_send_channel_create(multifd_new_send_channel_async, p); } =20 return 0; @@ -564,6 +582,7 @@ struct MultiFDRecvParams { uint8_t id; char *name; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool running; @@ -619,6 +638,8 @@ int multifd_load_cleanup(Error **errp) if (p->running) { qemu_thread_join(&p->thread); } + object_unref(OBJECT(p->c)); + p->c =3D NULL; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); g_free(p->name); @@ -715,10 +736,6 @@ int multifd_load_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdrecv_%d", i); - p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); - atomic_inc(&multifd_recv_state->count); } return 0; } @@ -736,7 +753,20 @@ bool multifd_recv_all_channels_created(void) =20 void multifd_recv_new_channel(QIOChannel *ioc) { - /* nothing to do yet */ + MultiFDRecvParams *p; + /* we need to invent channels id's until we transmit */ + /* we will remove this on a later patch */ + static int i; + + p =3D &multifd_recv_state->params[i]; + i++; + p->c =3D ioc; + object_ref(OBJECT(ioc)); + + p->running =3D true; + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); + atomic_inc(&multifd_recv_state->count); } =20 /** --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201921451283.5470337103163; Fri, 16 Mar 2018 05:05:21 -0700 (PDT) Received: from localhost ([::1]:56321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo6q-0006tm-Ju for importer@patchew.org; Fri, 16 Mar 2018 08:05:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwK-0006g1-3T for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwJ-0002eI-5M for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33552 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwJ-0002eC-15 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85349401CC41 for ; Fri, 16 Mar 2018 11:54:26 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79722D1EB1; Fri, 16 Mar 2018 11:54:25 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:53:59 +0100 Message-Id: <20180316115403.4148-12-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 16 Mar 2018 11:54:26 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 11/15] migration: Delay start of migration main routines 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 need to make sure that we have started all the multifd threads. Signed-off-by: Juan Quintela Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/migration.c | 4 ++-- migration/migration.h | 1 + migration/ram.c | 3 +++ migration/socket.c | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b3c6198e12..8856860c44 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -429,7 +429,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); @@ -447,7 +447,7 @@ 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; } multifd_recv_new_channel(ioc); diff --git a/migration/migration.h b/migration/migration.h index 36b9c70fd6..cef4c189c5 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -184,6 +184,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 5dade41243..55af077abc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -767,6 +767,9 @@ void multifd_recv_new_channel(QIOChannel *ioc) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); atomic_inc(&multifd_recv_state->count); + if (multifd_recv_state->count =3D=3D migrate_multifd_channels()) { + migration_incoming_process(); + } } =20 /** diff --git a/migration/socket.c b/migration/socket.c index 7889753fab..55af3b8180 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -178,6 +178,9 @@ static gboolean socket_accept_incoming_migration(QIOCha= nnel *ioc, 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.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201764887887.5462038265199; Fri, 16 Mar 2018 05:02:44 -0700 (PDT) Received: from localhost ([::1]:56279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo4F-0004dO-Na for importer@patchew.org; Fri, 16 Mar 2018 08:02:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwO-0006lG-7H for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwM-0002ht-LT for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52336 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwM-0002hj-G8 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 077D8406E8D1 for ; Fri, 16 Mar 2018 11:54:30 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7DA1C1FB5; Fri, 16 Mar 2018 11:54:26 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:54:00 +0100 Message-Id: <20180316115403.4148-13-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Mar 2018 11:54:30 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 12/15] migration: Transmit initial package through the multifd 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" Signed-off-by: Juan Quintela -- Be network agnostic. Add error checking for all values. Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/ram.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 92 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 55af077abc..dd77c78016 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -52,6 +52,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 */ @@ -395,6 +397,16 @@ static void compress_threads_save_setup(void) =20 /* Multiple fd's */ =20 +#define MULTIFD_MAGIC 0x11223344U +#define MULTIFD_VERSION 1 + +typedef struct { + uint32_t magic; + uint32_t version; + unsigned char uuid[16]; /* QemuUUID */ + uint8_t id; +} __attribute__((packed)) MultiFDInit_t; + struct MultiFDSendParams { uint8_t id; char *name; @@ -408,6 +420,65 @@ struct MultiFDSendParams { }; typedef struct MultiFDSendParams MultiFDSendParams; =20 +static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) +{ + MultiFDInit_t msg; + int ret; + + msg.magic =3D cpu_to_be32(MULTIFD_MAGIC); + msg.version =3D cpu_to_be32(MULTIFD_VERSION); + msg.id =3D p->id; + memcpy(msg.uuid, &qemu_uuid.data, sizeof(msg.uuid)); + + ret =3D qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), errp); + if (ret !=3D 0) { + return -1; + } + return 0; +} + +static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) +{ + MultiFDInit_t msg; + int ret; + + ret =3D qio_channel_read_all(c, (char *)&msg, sizeof(msg), errp); + if (ret !=3D 0) { + return -1; + } + + be32_to_cpus(&msg.magic); + be32_to_cpus(&msg.version); + + if (msg.magic !=3D MULTIFD_MAGIC) { + error_setg(errp, "multifd: recevied packet magic %d " + "expected %d", msg.magic, MULTIFD_MAGIC); + return -1; + } + + if (msg.version !=3D MULTIFD_VERSION) { + error_setg(errp, "multifd: recevied packet version %d " + "expected %d", msg.version, MULTIFD_VERSION); + return -1; + } + + if (memcmp(msg.uuid, &qemu_uuid, sizeof(qemu_uuid))) { + char *uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); + error_setg(errp, "multifd: received uuid '%s' and expected " + "uuid '%s' for channel %hhd", msg.uuid, uuid, msg.id); + g_free(uuid); + return -1; + } + + if (msg.id > migrate_multifd_channels()) { + error_setg(errp, "multifd: recevied channel version %d " + "expected %d", msg.version, MULTIFD_VERSION); + return -1; + } + + return msg.id; +} + struct { MultiFDSendParams *params; /* number of created threads */ @@ -507,9 +578,15 @@ static void multifd_send_sync_main(void) static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; + Error *local_err =3D NULL; =20 trace_multifd_send_thread_start(p->id); =20 + if (multifd_send_initial_packet(p, &local_err) < 0) { + multifd_send_terminate_threads(local_err); + return NULL; + } + while (true) { qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); @@ -754,12 +831,22 @@ bool multifd_recv_all_channels_created(void) void multifd_recv_new_channel(QIOChannel *ioc) { MultiFDRecvParams *p; - /* we need to invent channels id's until we transmit */ - /* we will remove this on a later patch */ - static int i; + Error *local_err =3D NULL; + int id; =20 - p =3D &multifd_recv_state->params[i]; - i++; + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + return; + } + + p =3D &multifd_recv_state->params[id]; + if (p->c !=3D NULL) { + error_setg(&local_err, "multifd: received id '%d' already setup'", + id); + multifd_recv_terminate_threads(local_err); + return; + } p->c =3D ioc; object_ref(OBJECT(ioc)); =20 --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201925211229.63533207804153; Fri, 16 Mar 2018 05:05:25 -0700 (PDT) Received: from localhost ([::1]:56323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo6u-0006ws-3X for importer@patchew.org; Fri, 16 Mar 2018 08:05:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwP-0006mt-PA for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwO-0002im-1I for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37990 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwN-0002iI-Rw for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 572B18151D47 for ; Fri, 16 Mar 2018 11:54:31 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A834C1FB5; Fri, 16 Mar 2018 11:54:30 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:54:01 +0100 Message-Id: <20180316115403.4148-14-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:31 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 13/15] 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. 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 now pages member is a pointer Fix off-by-one in number of pages in one packet Remove RAM_SAVE_FLAG_MULTIFD_PAGE s/multifd_pages_t/MultiFDPages_t/ --- migration/ram.c | 148 +++++++++++++++++++++++++++++++++++++++++++++= +++- migration/trace-events | 3 +- 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index dd77c78016..9919777a21 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -54,6 +54,7 @@ #include "migration/block.h" #include "sysemu/sysemu.h" #include "qemu/uuid.h" +#include "qemu/iov.h" =20 /***********************************************************/ /* ram save/restore */ @@ -407,7 +408,22 @@ typedef struct { uint8_t id; } __attribute__((packed)) MultiFDInit_t; =20 +typedef struct { + /* number of used pages */ + uint32_t used; + /* number of allocated pages */ + uint32_t allocated; + /* global number of generated multifd packets */ + uint32_t seq; + /* offset of each page */ + ram_addr_t *offset; + /* pointer to each page */ + struct iovec *iov; + RAMBlock *block; +} MultiFDPages_t; + struct MultiFDSendParams { + /* not changed */ uint8_t id; char *name; QemuThread thread; @@ -415,8 +431,15 @@ struct MultiFDSendParams { QemuSemaphore sem; QemuMutex mutex; bool running; + /* protected by param mutex */ bool quit; bool sync; + MultiFDPages_t *pages; + /* how many patches has sent this channel */ + uint32_t packets_sent; + /* protected by multifd mutex */ + /* has the thread finish the last submitted job */ + bool done; }; typedef struct MultiFDSendParams MultiFDSendParams; =20 @@ -485,8 +508,34 @@ struct { int count; /* syncs main thread and channels */ QemuSemaphore sem_main; + QemuMutex mutex; + QemuSemaphore sem; + MultiFDPages_t *pages; } *multifd_send_state; =20 +static void multifd_pages_init(MultiFDPages_t **ppages, size_t size) +{ + MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); + + pages->allocated =3D size; + pages->iov =3D g_new0(struct iovec, size); + pages->offset =3D g_new0(ram_addr_t, size); + *ppages =3D pages; +} + +static void multifd_pages_clear(MultiFDPages_t *pages) +{ + pages->used =3D 0; + pages->allocated =3D 0; + pages->seq =3D 0; + pages->block =3D NULL; + g_free(pages->iov); + pages->iov =3D NULL; + g_free(pages->offset); + pages->offset =3D NULL; + g_free(pages); +} + static void multifd_send_terminate_threads(Error *errp) { int i; @@ -532,10 +581,14 @@ int multifd_save_cleanup(Error **errp) qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; + multifd_pages_clear(p->pages); + p->pages =3D NULL; } qemu_sem_destroy(&multifd_send_state->sem_main); g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; + multifd_pages_clear(multifd_send_state->pages); + multifd_send_state->pages =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; return ret; @@ -586,6 +639,7 @@ static void *multifd_send_thread(void *opaque) multifd_send_terminate_threads(local_err); return NULL; } + qemu_sem_post(&multifd_send_state->sem); =20 while (true) { qemu_sem_wait(&p->sem); @@ -601,9 +655,23 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); break; } + if (p->pages->used) { + p->pages->used =3D 0; + qemu_mutex_unlock(&p->mutex); + + trace_multifd_send(p->id, p->pages->seq, p->pages->used); + /* ToDo: send page here */ + + qemu_mutex_lock(&multifd_send_state->mutex); + p->done =3D true; + p->packets_sent++; + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_sem_post(&multifd_send_state->sem); + continue; + } qemu_mutex_unlock(&p->mutex); } - trace_multifd_send_thread_end(p->id); + trace_multifd_send_thread_end(p->id, p->packets_sent); =20 return NULL; } @@ -630,6 +698,7 @@ static void multifd_new_send_channel_async(QIOTask *tas= k, gpointer opaque) int multifd_save_setup(void) { int thread_count; + uint32_t page_count =3D migrate_multifd_page_count(); uint8_t i; =20 if (!migrate_use_multifd()) { @@ -640,6 +709,9 @@ int multifd_save_setup(void) multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); atomic_set(&multifd_send_state->count, 0); qemu_sem_init(&multifd_send_state->sem_main, 0); + qemu_mutex_init(&multifd_send_state->mutex); + qemu_sem_init(&multifd_send_state->sem, 0); + multifd_pages_init(&multifd_send_state->pages, page_count); =20 for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; @@ -648,6 +720,8 @@ int multifd_save_setup(void) qemu_sem_init(&p->sem, 0); p->quit =3D false; p->id =3D i; + p->done =3D true; + multifd_pages_init(&p->pages, page_count); p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_send_channel_async, p); } @@ -655,6 +729,51 @@ int multifd_save_setup(void) return 0; } =20 +static void multifd_send_page(RAMBlock *block, ram_addr_t offset, + bool last_page) +{ + int i; + static int next_channel; + MultiFDSendParams *p =3D NULL; /* make happy gcc */ + MultiFDPages_t *pages =3D multifd_send_state->pages; + + if (!pages->block) { + pages->block =3D block; + } + + pages->offset[pages->used] =3D offset; + pages->iov[pages->used].iov_base =3D block->host + offset; + pages->iov[pages->used].iov_len =3D TARGET_PAGE_SIZE; + pages->used++; + + if (!last_page) { + if (pages->used < pages->allocated) { + return; + } + } + + qemu_sem_wait(&multifd_send_state->sem); + qemu_mutex_lock(&multifd_send_state->mutex); + for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { + p =3D &multifd_send_state->params[i]; + + if (p->done) { + p->done =3D false; + next_channel =3D (i + 1) % migrate_multifd_channels(); + break; + } + } + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_mutex_lock(&p->mutex); + p->pages->used =3D 0; + p->pages->seq =3D pages->seq + 1; + p->pages->block =3D NULL; + multifd_send_state->pages =3D p->pages; + p->pages =3D pages; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); +} + struct MultiFDRecvParams { uint8_t id; char *name; @@ -1291,6 +1410,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); + if (pages =3D=3D -1) { + ram_counters.transferred +=3D + save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_PAGE); + multifd_send_page(block, offset, rs->migration_dirty_pages =3D=3D = 1); + qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); + 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) { @@ -1719,6 +1863,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); } diff --git a/migration/trace-events b/migration/trace-events index 9c92d3ec14..06a9ead811 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -84,9 +84,10 @@ multifd_recv_sync_main(void) "" multifd_recv_sync_signal(uint8_t id, bool quit, bool running) "channel %d = quit %d running %d" multifd_recv_sync_wait(uint8_t id, bool quit, bool running) "channel %d qu= it %d running %d" multifd_send_thread_start(uint8_t id) "%d" -multifd_send_thread_end(uint8_t id) "%d" +multifd_send_thread_end(uint8_t id, uint32_t packets) "channel %d packets = %d" multifd_recv_thread_start(uint8_t id) "%d" multifd_recv_thread_end(uint8_t id) "%d" +multifd_send(uint8_t id, int seq, int num) "channel %d sequence %d num pag= es %d" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521201764831105.3373290781152; Fri, 16 Mar 2018 05:02:44 -0700 (PDT) Received: from localhost ([::1]:56276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo4B-0004Zd-VR for importer@patchew.org; Fri, 16 Mar 2018 08:02:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwQ-0006nI-1Z for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwP-0002jT-8Z for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34978 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwP-0002jJ-45 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A56964023156 for ; Fri, 16 Mar 2018 11:54:32 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AA3AC1FB5; Fri, 16 Mar 2018 11:54:31 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:54:02 +0100 Message-Id: <20180316115403.4148-15-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 16 Mar 2018 11:54:32 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 14/15] migration: Create pages structure for reception 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" Signed-off-by: Juan Quintela --- migration/ram.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 9919777a21..0132de6e02 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -775,6 +775,7 @@ static void multifd_send_page(RAMBlock *block, ram_addr= _t offset, } =20 struct MultiFDRecvParams { + /* not changed */ uint8_t id; char *name; QemuThread thread; @@ -782,8 +783,13 @@ struct MultiFDRecvParams { QemuSemaphore sem; QemuMutex mutex; bool running; + /* protected by param mutex */ bool quit; bool sync; + /* how many patckets has recv this channel */ + uint32_t packets_recv; + MultiFDPages_t *pages; + bool done; }; typedef struct MultiFDRecvParams MultiFDRecvParams; =20 @@ -840,6 +846,8 @@ int multifd_load_cleanup(Error **errp) qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; + multifd_pages_clear(p->pages); + p->pages =3D NULL; } qemu_sem_destroy(&multifd_recv_state->sem_main); g_free(multifd_recv_state->params); @@ -914,6 +922,7 @@ static void *multifd_recv_thread(void *opaque) int multifd_load_setup(void) { int thread_count; + uint32_t page_count =3D migrate_multifd_page_count(); uint8_t i; =20 if (!migrate_use_multifd()) { @@ -924,6 +933,7 @@ int multifd_load_setup(void) multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); atomic_set(&multifd_recv_state->count, 0); qemu_sem_init(&multifd_recv_state->sem_main, 0); + for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 @@ -932,6 +942,7 @@ int multifd_load_setup(void) p->quit =3D false; p->id =3D i; p->name =3D g_strdup_printf("multifdrecv_%d", i); + multifd_pages_init(&p->pages, page_count); } return 0; } --=20 2.14.3 From nobody Sat Oct 25 02:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521202077812184.5678460518683; Fri, 16 Mar 2018 05:07:57 -0700 (PDT) Received: from localhost ([::1]:56338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewo9F-0000Rz-JR for importer@patchew.org; Fri, 16 Mar 2018 08:07:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewnwS-0006pt-9X for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewnwQ-0002lG-Jc for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37992 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewnwQ-0002kx-E4 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 07:54:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F27CE8151D47 for ; Fri, 16 Mar 2018 11:54:33 +0000 (UTC) Received: from secure.mitica (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id E86CFC225F; Fri, 16 Mar 2018 11:54:32 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:54:03 +0100 Message-Id: <20180316115403.4148-16-quintela@redhat.com> In-Reply-To: <20180316115403.4148-1-quintela@redhat.com> References: <20180316115403.4148-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Mar 2018 11:54:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'quintela@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v11 15/15] [RFC] migration: Send pages through the multifd 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" Migration ends correctly, but there is still a race between clean up and last synchronization. Signed-off-by: Juan Quintela --- migration/ram.c | 240 ++++++++++++++++++++++++++++++++++++++++++---= ---- migration/trace-events | 3 +- 2 files changed, 211 insertions(+), 32 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 0132de6e02..d8ad456eca 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -408,6 +408,16 @@ typedef struct { uint8_t id; } __attribute__((packed)) MultiFDInit_t; =20 +typedef struct { + uint32_t magic; + uint32_t version; + uint32_t size; + uint32_t used; + uint32_t seq; + char ramblock[256]; + uint64_t offset[]; +} __attribute__((packed)) MultiFDPacket_t; + typedef struct { /* number of used pages */ uint32_t used; @@ -422,7 +432,7 @@ typedef struct { RAMBlock *block; } MultiFDPages_t; =20 -struct MultiFDSendParams { +typedef struct { /* not changed */ uint8_t id; char *name; @@ -440,8 +450,29 @@ struct MultiFDSendParams { /* protected by multifd mutex */ /* has the thread finish the last submitted job */ bool done; -}; -typedef struct MultiFDSendParams MultiFDSendParams; + uint32_t packet_len; + MultiFDPacket_t *packet; +} MultiFDSendParams; + +typedef struct { + /* not changed */ + uint8_t id; + char *name; + QemuThread thread; + QIOChannel *c; + QemuSemaphore sem; + QemuMutex mutex; + bool running; + /* protected by param mutex */ + bool quit; + bool sync; + MultiFDPages_t *pages; + /* how many patckets has recv this channel */ + uint32_t packets_recv; + bool done; + uint32_t packet_len; + MultiFDPacket_t *packet; +} MultiFDRecvParams; =20 static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) { @@ -502,6 +533,80 @@ static int multifd_recv_initial_packet(QIOChannel *c, = Error **errp) return msg.id; } =20 +static void multifd_send_fill_packet(MultiFDSendParams *p) +{ + MultiFDPacket_t *packet =3D p->packet; + int i; + + packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + packet->version =3D cpu_to_be32(MULTIFD_VERSION); + packet->size =3D cpu_to_be32(migrate_multifd_page_count()); + packet->used =3D cpu_to_be32(p->pages->used); + packet->seq =3D cpu_to_be32(p->pages->seq); + + for (i =3D 0; i < p->pages->used; i++) { + packet->offset[i] =3D cpu_to_be64(p->pages->offset[i]); + } + + strncpy(packet->ramblock, p->pages->block->idstr, 256); +} + +static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +{ + MultiFDPacket_t *packet =3D p->packet; + RAMBlock *block; + int i; + + be32_to_cpus(&packet->magic); + if (packet->magic !=3D MULTIFD_MAGIC) { + error_setg(errp, "multifd: received packet " + "version %d and expected version %d", + packet->magic, MULTIFD_VERSION); + return -1; + } + + be32_to_cpus(&packet->version); + if (packet->version !=3D MULTIFD_VERSION) { + error_setg(errp, "multifd: received packet " + "version %d and expected version %d", + packet->version, MULTIFD_VERSION); + return -1; + } + + be32_to_cpus(&packet->size); + if (packet->size > migrate_multifd_page_count()) { + error_setg(errp, "multifd: received packet " + "with size %d and expected maximum size %d", + packet->size, migrate_multifd_page_count()) ; + return -1; + } + + p->pages->used =3D be32_to_cpu(packet->used); + if (p->pages->used > packet->size) { + error_setg(errp, "multifd: received packet " + "with size %d and expected maximum size %d", + p->pages->used, packet->size) ; + return -1; + } + + be32_to_cpus(&packet->seq); + + block =3D qemu_ram_block_by_name(packet->ramblock); + if (!block) { + error_setg(errp, "multifd: unknown ram block %s", + packet->ramblock); + return -1; + } + + for (i =3D 0; i < p->pages->used; i++) { + ram_addr_t offset =3D be64_to_cpu(packet->offset[i]); + + p->pages->iov[i].iov_base =3D block->host + offset; + p->pages->iov[i].iov_len =3D TARGET_PAGE_SIZE; + } + return 0; +} + struct { MultiFDSendParams *params; /* number of created threads */ @@ -583,6 +688,9 @@ int multifd_save_cleanup(Error **errp) p->name =3D NULL; multifd_pages_clear(p->pages); p->pages =3D NULL; + p->packet_len =3D 0; + g_free(p->packet); + p->packet =3D NULL; } qemu_sem_destroy(&multifd_send_state->sem_main); g_free(multifd_send_state->params); @@ -632,12 +740,13 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + int ret; =20 trace_multifd_send_thread_start(p->id); =20 - if (multifd_send_initial_packet(p, &local_err) < 0) { - multifd_send_terminate_threads(local_err); - return NULL; + ret =3D multifd_send_initial_packet(p, &local_err); + if (ret < 0) { + goto out; } qemu_sem_post(&multifd_send_state->sem); =20 @@ -651,17 +760,28 @@ static void *multifd_send_thread(void *opaque) continue; } if (p->quit) { - p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } if (p->pages->used) { + Error *local_err =3D NULL; + uint32_t used; + + multifd_send_fill_packet(p); + used =3D p->pages->used; p->pages->used =3D 0; qemu_mutex_unlock(&p->mutex); =20 - trace_multifd_send(p->id, p->pages->seq, p->pages->used); - /* ToDo: send page here */ - + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + break; + } + trace_multifd_send(p->id, p->pages->seq, used); + ret =3D qio_channel_writev_all(p->c, p->pages->iov, used, &loc= al_err); + if (ret !=3D 0) { + break; + } qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; p->packets_sent++; @@ -671,6 +791,15 @@ static void *multifd_send_thread(void *opaque) } qemu_mutex_unlock(&p->mutex); } +out: + if (ret) { + multifd_send_terminate_threads(local_err); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + trace_multifd_send_thread_end(p->id, p->packets_sent); =20 return NULL; @@ -722,6 +851,9 @@ int multifd_save_setup(void) p->id =3D i; p->done =3D true; multifd_pages_init(&p->pages, page_count); + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(ram_addr_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_send_channel_async, p); } @@ -774,25 +906,6 @@ static void multifd_send_page(RAMBlock *block, ram_add= r_t offset, qemu_sem_post(&p->sem); } =20 -struct MultiFDRecvParams { - /* not changed */ - uint8_t id; - char *name; - QemuThread thread; - QIOChannel *c; - QemuSemaphore sem; - QemuMutex mutex; - bool running; - /* protected by param mutex */ - bool quit; - bool sync; - /* how many patckets has recv this channel */ - uint32_t packets_recv; - MultiFDPages_t *pages; - bool done; -}; -typedef struct MultiFDRecvParams MultiFDRecvParams; - struct { MultiFDRecvParams *params; /* number of created threads */ @@ -848,6 +961,9 @@ int multifd_load_cleanup(Error **errp) p->name =3D NULL; multifd_pages_clear(p->pages); p->pages =3D NULL; + p->packet_len =3D 0; + g_free(p->packet); + p->packet =3D NULL; } qemu_sem_destroy(&multifd_recv_state->sem_main); g_free(multifd_recv_state->params); @@ -892,12 +1008,34 @@ static void multifd_recv_sync_main(void) trace_multifd_recv_sync_main(); } =20 +static gboolean recv_channel_ready(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) +{ + MultiFDRecvParams *p =3D opaque; + + if (condition !=3D G_IO_IN) { + return G_SOURCE_REMOVE; + } + + qemu_mutex_lock(&p->mutex); + p->done =3D false; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + + return G_SOURCE_CONTINUE; + +} + static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 trace_multifd_recv_thread_start(p->id); =20 + qio_channel_add_watch(p->c, G_IO_IN | G_IO_HUP | G_IO_ERR, + recv_channel_ready, p, NULL); + while (true) { qemu_sem_wait(&p->sem); qemu_mutex_lock(&p->mutex); @@ -907,15 +1045,51 @@ static void *multifd_recv_thread(void *opaque) qemu_sem_post(&multifd_recv_state->sem_main); continue; } + if (!p->done) { + Error *local_err =3D NULL; + int ret; + + qemu_mutex_unlock(&p->mutex); + + ret =3D qio_channel_read_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + multifd_recv_terminate_threads(local_err); + break; + } + + ret =3D multifd_recv_unfill_packet(p, &local_err); + if (ret < 0) { + multifd_recv_terminate_threads(local_err); + break; + } + + trace_multifd_recv(p->id, p->pages->seq, p->pages->used); + ret =3D qio_channel_readv_all(p->c, p->pages->iov, + p->pages->used, &local_err); + if (ret !=3D 0) { + multifd_recv_terminate_threads(local_err); + break; + } + qemu_mutex_lock(&p->mutex); + p->done =3D true; + p->packets_recv++; + qemu_mutex_unlock(&p->mutex); + + continue; + } if (p->quit) { - p->running =3D false; qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); } =20 - trace_multifd_recv_thread_end(p->id); + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + trace_multifd_recv_thread_end(p->id, p->packets_recv); return NULL; } =20 @@ -940,9 +1114,13 @@ int multifd_load_setup(void) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); p->quit =3D false; + p->done =3D true; p->id =3D i; p->name =3D g_strdup_printf("multifdrecv_%d", i); multifd_pages_init(&p->pages, page_count); + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(ram_addr_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); } return 0; } diff --git a/migration/trace-events b/migration/trace-events index 06a9ead811..a6c1c4b20c 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -86,8 +86,9 @@ multifd_recv_sync_wait(uint8_t id, bool quit, bool runnin= g) "channel %d quit %d multifd_send_thread_start(uint8_t id) "%d" multifd_send_thread_end(uint8_t id, uint32_t packets) "channel %d packets = %d" multifd_recv_thread_start(uint8_t id) "%d" -multifd_recv_thread_end(uint8_t id) "%d" +multifd_recv_thread_end(uint8_t id, uint32_t packets) "channel %d packets = %d" multifd_send(uint8_t id, int seq, int num) "channel %d sequence %d num pag= es %d" +multifd_recv(uint8_t id, int seq, int num) "channel %d sequence %d num pag= es %d" =20 # migration/migration.c await_return_path_close_on_source_close(void) "" --=20 2.14.3