From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150029920619981.03131102261602; Mon, 17 Jul 2017 06:46:46 -0700 (PDT) Received: from localhost ([::1]:50537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6MF-0007EY-QP for importer@patchew.org; Mon, 17 Jul 2017 09:46:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6IX-0003mU-UR for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6IU-0005JH-Sn for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13525) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6IU-0005J4-Jl for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 896FE61BAC for ; Mon, 17 Jul 2017 13:42:49 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 344DE5D6A2; Mon, 17 Jul 2017 13:42:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 896FE61BAC Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 896FE61BAC From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:22 +0200 Message-Id: <20170717134238.1966-2-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Jul 2017 13:42:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 01/17] migrate: Add gboolean return type to migrate_channel_process_incoming 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/channel.c | 3 ++- migration/channel.h | 2 +- migration/exec.c | 6 ++++-- migration/socket.c | 12 ++++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 3b7252f..719055d 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -19,7 +19,7 @@ #include "qapi/error.h" #include "io/channel-tls.h" =20 -void migration_channel_process_incoming(QIOChannel *ioc) +gboolean migration_channel_process_incoming(QIOChannel *ioc) { MigrationState *s =3D migrate_get_current(); =20 @@ -39,6 +39,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) QEMUFile *f =3D qemu_fopen_channel_input(ioc); migration_fd_process_incoming(f); } + return FALSE; /* unregister */ } =20 =20 diff --git a/migration/channel.h b/migration/channel.h index e4b4057..72cbc9f 100644 --- a/migration/channel.h +++ b/migration/channel.h @@ -18,7 +18,7 @@ =20 #include "io/channel.h" =20 -void migration_channel_process_incoming(QIOChannel *ioc); +gboolean migration_channel_process_incoming(QIOChannel *ioc); =20 void migration_channel_connect(MigrationState *s, QIOChannel *ioc, diff --git a/migration/exec.c b/migration/exec.c index 08b599e..2827f15 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -47,9 +47,11 @@ static gboolean exec_accept_incoming_migration(QIOChanne= l *ioc, GIOCondition condition, gpointer opaque) { - migration_channel_process_incoming(ioc); + gboolean result; + + result =3D migration_channel_process_incoming(ioc); object_unref(OBJECT(ioc)); - return FALSE; /* unregister */ + return result; } =20 void exec_start_incoming_migration(const char *command, Error **errp) diff --git a/migration/socket.c b/migration/socket.c index 757d382..6195596 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -136,25 +136,29 @@ static gboolean socket_accept_incoming_migration(QIOC= hannel *ioc, { QIOChannelSocket *sioc; Error *err =3D NULL; + gboolean result; =20 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)); + result =3D FALSE; /* unregister */ goto out; } =20 trace_migration_socket_incoming_accepted(); =20 qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-incoming"); - migration_channel_process_incoming(QIO_CHANNEL(sioc)); + result =3D migration_channel_process_incoming(QIO_CHANNEL(sioc)); object_unref(OBJECT(sioc)); =20 out: - /* Close listening socket as its no longer needed */ - qio_channel_close(ioc, NULL); - return FALSE; /* unregister */ + if (result =3D=3D FALSE) { + /* Close listening socket as its no longer needed */ + qio_channel_close(ioc, NULL); + } + return result; } =20 =20 --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299074409805.2839360728129; Mon, 17 Jul 2017 06:44:34 -0700 (PDT) Received: from localhost ([::1]:50523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6K8-0005KT-0B for importer@patchew.org; Mon, 17 Jul 2017 09:44:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6IX-0003mS-UG for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6IW-0005Jr-US for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6IW-0005Jd-LY for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BC2762647 for ; Mon, 17 Jul 2017 13:42:51 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9AE15D6A2; Mon, 17 Jul 2017 13:42:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9BC2762647 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9BC2762647 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:23 +0200 Message-Id: <20170717134238.1966-3-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Jul 2017 13:42:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 02/17] migration: Create migration_ioc_process_incoming() 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 receive the ioc to be able to implement multifd. Signed-off-by: Juan Quintela --- migration/channel.c | 3 +-- migration/migration.c | 16 +++++++++++++--- migration/migration.h | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 719055d..5b777ef 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -36,8 +36,7 @@ gboolean migration_channel_process_incoming(QIOChannel *i= oc) error_report_err(local_err); } } else { - QEMUFile *f =3D qemu_fopen_channel_input(ioc); - migration_fd_process_incoming(f); + return migration_ioc_process_incoming(ioc); } return FALSE; /* unregister */ } diff --git a/migration/migration.c b/migration/migration.c index a0db40d..c24ad03 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -299,17 +299,15 @@ static void process_incoming_migration_bh(void *opaqu= e) =20 static void process_incoming_migration_co(void *opaque) { - QEMUFile *f =3D opaque; MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyState ps; int ret; =20 - mis->from_src_file =3D f; mis->largest_page_size =3D qemu_ram_pagesize_largest(); postcopy_state_set(POSTCOPY_INCOMING_NONE); migrate_set_state(&mis->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_ACTIVE); - ret =3D qemu_loadvm_state(f); + ret =3D qemu_loadvm_state(mis->from_src_file); =20 ps =3D postcopy_state_get(); trace_process_incoming_migration_co_end(ret, ps); @@ -362,6 +360,18 @@ void migration_fd_process_incoming(QEMUFile *f) qemu_coroutine_enter(co); } =20 +gboolean migration_ioc_process_incoming(QIOChannel *ioc) +{ + MigrationIncomingState *mis =3D migration_incoming_get_current(); + + if (!mis->from_src_file) { + QEMUFile *f =3D qemu_fopen_channel_input(ioc); + mis->from_src_file =3D f; + migration_fd_process_incoming(f); + } + return FALSE; /* unregister */ +} + /* * Send a 'SHUT' message on the return channel with the given value * to indicate that we've finished with the RP. Non-0 value indicates diff --git a/migration/migration.h b/migration/migration.h index 148c9fa..5a18aea 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -20,6 +20,7 @@ #include "exec/cpu-common.h" #include "qemu/coroutine_int.h" #include "hw/qdev.h" +#include "io/channel.h" =20 /* State for the incoming migration */ struct MigrationIncomingState { @@ -152,6 +153,7 @@ struct MigrationState void migrate_set_state(int *state, int old_state, int new_state); =20 void migration_fd_process_incoming(QEMUFile *f); +gboolean migration_ioc_process_incoming(QIOChannel *ioc); =20 uint64_t migrate_max_downtime(void); =20 --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299080341898.2821308436672; Mon, 17 Jul 2017 06:44:40 -0700 (PDT) Received: from localhost ([::1]:50524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6KC-0005P8-Nj for importer@patchew.org; Mon, 17 Jul 2017 09:44:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Ia-0003o1-Gr for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6IZ-0005Kf-1J for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6IY-0005KN-OC for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA21F356D4 for ; Mon, 17 Jul 2017 13:42:53 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED6837D6B7; Mon, 17 Jul 2017 13:42:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA21F356D4 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AA21F356D4 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:24 +0200 Message-Id: <20170717134238.1966-4-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 17 Jul 2017 13:42:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 03/17] qio: Create new qio_channel_{readv, writev}_all 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 functions waits until it is able to write the full iov. Signed-off-by: Juan Quintela -- Add tests. --- include/io/channel.h | 46 +++++++++++++++++++++++++ io/channel.c | 76 ++++++++++++++++++++++++++++++++++++++= ++++ migration/qemu-file-channel.c | 29 +--------------- tests/io-channel-helpers.c | 55 ++++++++++++++++++++++++++++++ tests/io-channel-helpers.h | 4 +++ tests/test-io-channel-buffer.c | 55 ++++++++++++++++++++++++++++-- 6 files changed, 234 insertions(+), 31 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index db9bb02..bfc97e2 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -269,6 +269,52 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, Error **errp); =20 /** + * qio_channel_readv_all: + * @ioc: the channel object + * @iov: the array of memory regions to read data into + * @niov: the length of the @iov array + * @errp: pointer to a NULL-initialized error object + * + * Read data from the IO channel, storing it in the + * memory regions referenced by @iov. Each element + * in the @iov will be fully populated with data + * before the next one is used. The @niov parameter + * specifies the total number of elements in @iov. + * + * Returns: the number of bytes read, or -1 on error, + * or QIO_CHANNEL_ERR_BLOCK if no data is available + * and the channel is non-blocking + */ +ssize_t qio_channel_readv_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp); + + +/** + * qio_channel_writev_all: + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @errp: pointer to a NULL-initialized error object + * + * Write data to the IO channel, reading it from the + * memory regions referenced by @iov. Each element + * in the @iov will be fully sent, before the next + * one is used. The @niov parameter specifies the + * total number of elements in @iov. + * + * It is required for all @iov data to be fully + * sent. + * + * Returns: the number of bytes sent, or -1 on error, + */ +ssize_t qio_channel_writev_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **erp); + +/** * qio_channel_readv: * @ioc: the channel object * @iov: the array of memory regions to read data into diff --git a/io/channel.c b/io/channel.c index cdf7454..82203ef 100644 --- a/io/channel.c +++ b/io/channel.c @@ -22,6 +22,7 @@ #include "io/channel.h" #include "qapi/error.h" #include "qemu/main-loop.h" +#include "qemu/iov.h" =20 bool qio_channel_has_feature(QIOChannel *ioc, QIOChannelFeature feature) @@ -85,6 +86,81 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, } =20 =20 + +ssize_t qio_channel_readv_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + ssize_t done =3D 0; + struct iovec *local_iov =3D g_new(struct iovec, niov); + struct iovec *local_iov_head =3D local_iov; + unsigned int nlocal_iov =3D niov; + + nlocal_iov =3D iov_copy(local_iov, nlocal_iov, + iov, niov, + 0, iov_size(iov, niov)); + + while (nlocal_iov > 0) { + ssize_t len; + len =3D qio_channel_readv(ioc, local_iov, nlocal_iov, errp); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + qio_channel_wait(ioc, G_IO_OUT); + continue; + } + if (len < 0) { + error_setg_errno(errp, EIO, + "Channel was not able to read full iov"); + done =3D -1; + goto cleanup; + } + + iov_discard_front(&local_iov, &nlocal_iov, len); + done +=3D len; + } + + cleanup: + g_free(local_iov_head); + return done; +} + +ssize_t qio_channel_writev_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + ssize_t done =3D 0; + struct iovec *local_iov =3D g_new(struct iovec, niov); + struct iovec *local_iov_head =3D local_iov; + unsigned int nlocal_iov =3D niov; + + nlocal_iov =3D iov_copy(local_iov, nlocal_iov, + iov, niov, + 0, iov_size(iov, niov)); + + while (nlocal_iov > 0) { + ssize_t len; + len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, errp); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + qio_channel_wait(ioc, G_IO_OUT); + continue; + } + if (len < 0) { + error_setg_errno(errp, EIO, + "Channel was not able to write full iov"); + done =3D -1; + goto cleanup; + } + + iov_discard_front(&local_iov, &nlocal_iov, len); + done +=3D len; + } + + cleanup: + g_free(local_iov_head); + return done; +} + ssize_t qio_channel_readv(QIOChannel *ioc, const struct iovec *iov, size_t niov, diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index e202d73..457ea6c 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -36,35 +36,8 @@ static ssize_t channel_writev_buffer(void *opaque, int64_t pos) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); - ssize_t done =3D 0; - struct iovec *local_iov =3D g_new(struct iovec, iovcnt); - struct iovec *local_iov_head =3D local_iov; - unsigned int nlocal_iov =3D iovcnt; =20 - nlocal_iov =3D iov_copy(local_iov, nlocal_iov, - iov, iovcnt, - 0, iov_size(iov, iovcnt)); - - while (nlocal_iov > 0) { - ssize_t len; - len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, NULL); - if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - qio_channel_wait(ioc, G_IO_OUT); - continue; - } - if (len < 0) { - /* XXX handle Error objects */ - done =3D -EIO; - goto cleanup; - } - - iov_discard_front(&local_iov, &nlocal_iov, len); - done +=3D len; - } - - cleanup: - g_free(local_iov_head); - return done; + return qio_channel_writev_all(ioc, iov, iovcnt, NULL); } =20 =20 diff --git a/tests/io-channel-helpers.c b/tests/io-channel-helpers.c index 05e5579..3d76d95 100644 --- a/tests/io-channel-helpers.c +++ b/tests/io-channel-helpers.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "io-channel-helpers.h" #include "qapi/error.h" +#include "qemu/iov.h" =20 struct QIOChannelTest { QIOChannel *src; @@ -153,6 +154,45 @@ static gpointer test_io_thread_reader(gpointer opaque) return NULL; } =20 +static gpointer test_io_thread_writer_all(gpointer opaque) +{ + QIOChannelTest *data =3D opaque; + size_t niov =3D data->niov; + ssize_t ret; + + qio_channel_set_blocking(data->src, data->blocking, NULL); + + ret =3D qio_channel_writev_all(data->src, + data->inputv, + niov, + &data->writeerr); + if (ret !=3D iov_size(data->inputv, data->niov)) { + error_setg(&data->writeerr, "Unexpected I/O error"); + } + + return NULL; +} + +/* This thread receives all data using iovecs */ +static gpointer test_io_thread_reader_all(gpointer opaque) +{ + QIOChannelTest *data =3D opaque; + size_t niov =3D data->niov; + ssize_t ret; + + qio_channel_set_blocking(data->dst, data->blocking, NULL); + + ret =3D qio_channel_readv_all(data->dst, + data->outputv, + niov, + &data->readerr); + + if (ret !=3D iov_size(data->inputv, data->niov)) { + error_setg(&data->readerr, "Unexpected I/O error"); + } + + return NULL; +} =20 QIOChannelTest *qio_channel_test_new(void) { @@ -231,6 +271,21 @@ void qio_channel_test_run_reader(QIOChannelTest *test, test->dst =3D NULL; } =20 +void qio_channel_test_run_writer_all(QIOChannelTest *test, + QIOChannel *src) +{ + test->src =3D src; + test_io_thread_writer_all(test); + test->src =3D NULL; +} + +void qio_channel_test_run_reader_all(QIOChannelTest *test, + QIOChannel *dst) +{ + test->dst =3D dst; + test_io_thread_reader_all(test); + test->dst =3D NULL; +} =20 void qio_channel_test_validate(QIOChannelTest *test) { diff --git a/tests/io-channel-helpers.h b/tests/io-channel-helpers.h index fedc64f..17b9647 100644 --- a/tests/io-channel-helpers.h +++ b/tests/io-channel-helpers.h @@ -36,6 +36,10 @@ void qio_channel_test_run_writer(QIOChannelTest *test, QIOChannel *src); void qio_channel_test_run_reader(QIOChannelTest *test, QIOChannel *dst); +void qio_channel_test_run_writer_all(QIOChannelTest *test, + QIOChannel *src); +void qio_channel_test_run_reader_all(QIOChannelTest *test, + QIOChannel *dst); =20 void qio_channel_test_validate(QIOChannelTest *test); =20 diff --git a/tests/test-io-channel-buffer.c b/tests/test-io-channel-buffer.c index 64722a2..4bf64ae 100644 --- a/tests/test-io-channel-buffer.c +++ b/tests/test-io-channel-buffer.c @@ -22,8 +22,7 @@ #include "io/channel-buffer.h" #include "io-channel-helpers.h" =20 - -static void test_io_channel_buf(void) +static void test_io_channel_buf1(void) { QIOChannelBuffer *buf; QIOChannelTest *test; @@ -39,6 +38,53 @@ static void test_io_channel_buf(void) object_unref(OBJECT(buf)); } =20 +static void test_io_channel_buf2(void) +{ + QIOChannelBuffer *buf; + QIOChannelTest *test; + + buf =3D qio_channel_buffer_new(0); + + test =3D qio_channel_test_new(); + qio_channel_test_run_writer_all(test, QIO_CHANNEL(buf)); + buf->offset =3D 0; + qio_channel_test_run_reader(test, QIO_CHANNEL(buf)); + qio_channel_test_validate(test); + + object_unref(OBJECT(buf)); +} + +static void test_io_channel_buf3(void) +{ + QIOChannelBuffer *buf; + QIOChannelTest *test; + + buf =3D qio_channel_buffer_new(0); + + test =3D qio_channel_test_new(); + qio_channel_test_run_writer(test, QIO_CHANNEL(buf)); + buf->offset =3D 0; + qio_channel_test_run_reader_all(test, QIO_CHANNEL(buf)); + qio_channel_test_validate(test); + + object_unref(OBJECT(buf)); +} + +static void test_io_channel_buf4(void) +{ + QIOChannelBuffer *buf; + QIOChannelTest *test; + + buf =3D qio_channel_buffer_new(0); + + test =3D qio_channel_test_new(); + qio_channel_test_run_writer_all(test, QIO_CHANNEL(buf)); + buf->offset =3D 0; + qio_channel_test_run_reader_all(test, QIO_CHANNEL(buf)); + qio_channel_test_validate(test); + + object_unref(OBJECT(buf)); +} =20 int main(int argc, char **argv) { @@ -46,6 +92,9 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); =20 - g_test_add_func("/io/channel/buf", test_io_channel_buf); + g_test_add_func("/io/channel/buf1", test_io_channel_buf1); + g_test_add_func("/io/channel/buf2", test_io_channel_buf2); + g_test_add_func("/io/channel/buf3", test_io_channel_buf3); + g_test_add_func("/io/channel/buf4", test_io_channel_buf4); return g_test_run(); } --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299538923994.8782283963392; Mon, 17 Jul 2017 06:52:18 -0700 (PDT) Received: from localhost ([::1]:50563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Rb-0003Uf-Kx for importer@patchew.org; Mon, 17 Jul 2017 09:52:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Ic-0003pk-7e for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6Ib-0005MQ-9j for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45302) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6Ib-0005LK-3l for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:42:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13DFE4E047 for ; Mon, 17 Jul 2017 13:42:56 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 047385D6A2; Mon, 17 Jul 2017 13:42:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13DFE4E047 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 13DFE4E047 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:25 +0200 Message-Id: <20170717134238.1966-5-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Jul 2017 13:42:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 04/17] migration: Add multifd capability 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: Dr. David Alan Gilbert --- migration/migration.c | 9 +++++++++ migration/migration.h | 1 + qapi-schema.json | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index c24ad03..af2630b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1282,6 +1282,15 @@ bool migrate_use_events(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_use_multifd(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD]; +} + int migrate_use_xbzrle(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index 5a18aea..9da9b4e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -172,6 +172,7 @@ bool migrate_postcopy_ram(void); bool migrate_zero_blocks(void); =20 bool migrate_auto_converge(void); +bool migrate_use_multifd(void); =20 int migrate_use_xbzrle(void); int64_t migrate_xbzrle_cache_size(void); diff --git a/qapi-schema.json b/qapi-schema.json index ab438ea..2457fb0 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -902,14 +902,14 @@ # # @return-path: If enabled, migration will use the return path even # for precopy. (since 2.10) +# @x-multifd: Use more than one fd for migration (since 2.10) # # Since: 1.2 ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', - 'block', 'return-path' ] } - + 'block', 'return-path', 'x-multifd'] } ## # @MigrationCapabilityStatus: # --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299232602868.8256034323781; Mon, 17 Jul 2017 06:47:12 -0700 (PDT) Received: from localhost ([::1]:50539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Mf-0007Y4-BT for importer@patchew.org; Mon, 17 Jul 2017 09:47:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Ik-0003wR-C4 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6Ij-0005Nx-5q for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25173) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6Ii-0005Ng-Sk for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC75C7D0DB for ; Mon, 17 Jul 2017 13:43:03 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6588B5D6A2; Mon, 17 Jul 2017 13:42:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC75C7D0DB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CC75C7D0DB From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:26 +0200 Message-Id: <20170717134238.1966-6-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Jul 2017 13:43:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 05/17] migration: Create x-multifd-threads parameter 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" Indicates the number of threads that we would create. By default we create 2 threads. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- Catch inconsistent defaults (eric). Improve comment stating that number of threads is the same than number of sockets --- hmp.c | 7 +++++++ migration/migration.c | 23 +++++++++++++++++++++++ migration/migration.h | 1 + qapi-schema.json | 18 ++++++++++++++++-- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index d970ea9..92f9456 100644 --- a/hmp.c +++ b/hmp.c @@ -335,6 +335,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) monitor_printf(mon, "%s: %s\n", MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTA= L], params->block_incremental ? "on" : "off"); + monitor_printf(mon, "%s: %" PRId64 "\n", + MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREAD= S], + params->x_multifd_threads); } =20 qapi_free_MigrationParameters(params); @@ -1573,6 +1576,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) goto cleanup; } p.block_incremental =3D valuebool; + case MIGRATION_PARAMETER_X_MULTIFD_THREADS: + p.has_x_multifd_threads =3D true; + use_int_value =3D true; break; } =20 @@ -1590,6 +1596,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) p.cpu_throttle_increment =3D valueint; p.downtime_limit =3D valueint; p.x_checkpoint_delay =3D valueint; + p.x_multifd_threads =3D valueint; } =20 qmp_migrate_set_parameters(&p, &err); diff --git a/migration/migration.c b/migration/migration.c index af2630b..148edc1 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -78,6 +78,7 @@ * Note: Please change this default value to 10000 when we support hybrid = mode. */ #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY 200 +#define DEFAULT_MIGRATE_MULTIFD_THREADS 2 =20 static NotifierList migration_state_notifiers =3D NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); @@ -460,6 +461,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->x_checkpoint_delay =3D s->parameters.x_checkpoint_delay; params->has_block_incremental =3D true; params->block_incremental =3D s->parameters.block_incremental; + params->has_x_multifd_threads =3D true; + params->x_multifd_threads =3D s->parameters.x_multifd_threads; =20 return params; } @@ -712,6 +715,13 @@ void qmp_migrate_set_parameters(MigrationParameters *p= arams, Error **errp) "x_checkpoint_delay", "is invalid, it should be positive"); } + if (params->has_x_multifd_threads && + (params->x_multifd_threads < 1 || params->x_multifd_threads > 255)= ) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "multifd_threads", + "is invalid, it should be in the range of 1 to 255"); + return; + } =20 if (params->has_compress_level) { s->parameters.compress_level =3D params->compress_level; @@ -756,6 +766,9 @@ void qmp_migrate_set_parameters(MigrationParameters *pa= rams, Error **errp) if (params->has_block_incremental) { s->parameters.block_incremental =3D params->block_incremental; } + if (params->has_x_multifd_threads) { + s->parameters.x_multifd_threads =3D params->x_multifd_threads; + } } =20 =20 @@ -1291,6 +1304,15 @@ bool migrate_use_multifd(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD]; } =20 +int migrate_multifd_threads(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.x_multifd_threads; +} + int migrate_use_xbzrle(void) { MigrationState *s; @@ -2055,6 +2077,7 @@ static void migration_instance_init(Object *obj) .max_bandwidth =3D MAX_THROTTLE, .downtime_limit =3D DEFAULT_MIGRATE_SET_DOWNTIME, .x_checkpoint_delay =3D DEFAULT_MIGRATE_X_CHECKPOINT_DELAY, + .x_multifd_threads =3D DEFAULT_MIGRATE_MULTIFD_THREADS, }; ms->parameters.tls_creds =3D g_strdup(""); ms->parameters.tls_hostname =3D g_strdup(""); diff --git a/migration/migration.h b/migration/migration.h index 9da9b4e..20ea30c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -173,6 +173,7 @@ bool migrate_zero_blocks(void); =20 bool migrate_auto_converge(void); bool migrate_use_multifd(void); +int migrate_multifd_threads(void); =20 int migrate_use_xbzrle(void); int64_t migrate_xbzrle_cache_size(void); diff --git a/qapi-schema.json b/qapi-schema.json index 2457fb0..444e8f0 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -902,6 +902,7 @@ # # @return-path: If enabled, migration will use the return path even # for precopy. (since 2.10) +# # @x-multifd: Use more than one fd for migration (since 2.10) # # Since: 1.2 @@ -910,6 +911,7 @@ 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', 'block', 'return-path', 'x-multifd'] } + ## # @MigrationCapabilityStatus: # @@ -1026,13 +1028,19 @@ # migrated and the destination must already have access to the # same backing chain as was used on the source. (since 2.10) # +# @x-multifd-threads: Number of threads used to migrate data in +# parallel. This is the same number that the +# number of sockets used for migration. +# The default value is 2 (since 2.10) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', 'data': ['compress-level', 'compress-threads', 'decompress-threads', 'cpu-throttle-initial', 'cpu-throttle-increment', 'tls-creds', 'tls-hostname', 'max-bandwidth', - 'downtime-limit', 'x-checkpoint-delay', 'block-incremental' ] } + 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', + 'x-multifd-threads'] } =20 ## # @migrate-set-parameters: @@ -1106,6 +1114,11 @@ # migrated and the destination must already have access to the # same backing chain as was used on the source. (since 2.10) # +# @x-multifd-threads: Number of threads used to migrate data in +# parallel. This is the same number that the +# number of sockets used for migration. +# The default value is 2 (since 2.10) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -1119,7 +1132,8 @@ '*max-bandwidth': 'int', '*downtime-limit': 'int', '*x-checkpoint-delay': 'int', - '*block-incremental': 'bool' } } + '*block-incremental': 'bool', + '*x-multifd-threads': 'int'} } =20 ## # @query-migrate-parameters: --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299097879488.5914078762137; Mon, 17 Jul 2017 06:44:57 -0700 (PDT) Received: from localhost ([::1]:50526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6KV-0005fW-GZ for importer@patchew.org; Mon, 17 Jul 2017 09:44:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6It-00043W-Cw for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6In-0005Om-Cw for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6In-0005OY-3k for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1132F4A6EA for ; Mon, 17 Jul 2017 13:43:08 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25EE25D6A2; Mon, 17 Jul 2017 13:43:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1132F4A6EA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1132F4A6EA From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:27 +0200 Message-Id: <20170717134238.1966-7-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Jul 2017 13:43:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 06/17] migration: Create x-multifd-group parameter 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" Indicates how many pages we are going to send in each batch to a multifd thread. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert -- Be consistent with defaults and documentation --- hmp.c | 8 ++++++++ migration/migration.c | 23 +++++++++++++++++++++++ migration/migration.h | 1 + qapi-schema.json | 11 +++++++++-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index 92f9456..b01605a 100644 --- a/hmp.c +++ b/hmp.c @@ -338,6 +338,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) monitor_printf(mon, "%s: %" PRId64 "\n", MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREAD= S], params->x_multifd_threads); + monitor_printf(mon, "%s: %" PRId64 "\n", + MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_GROUP], + params->x_multifd_group); } =20 qapi_free_MigrationParameters(params); @@ -1580,6 +1583,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p.has_x_multifd_threads =3D true; use_int_value =3D true; break; + case MIGRATION_PARAMETER_X_MULTIFD_GROUP: + p.has_x_multifd_group =3D true; + use_int_value =3D true; + break; } =20 if (use_int_value) { @@ -1597,6 +1604,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) p.downtime_limit =3D valueint; p.x_checkpoint_delay =3D valueint; p.x_multifd_threads =3D valueint; + p.x_multifd_group =3D valueint; } =20 qmp_migrate_set_parameters(&p, &err); diff --git a/migration/migration.c b/migration/migration.c index 148edc1..ff3fc9d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -79,6 +79,7 @@ */ #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY 200 #define DEFAULT_MIGRATE_MULTIFD_THREADS 2 +#define DEFAULT_MIGRATE_MULTIFD_GROUP 16 =20 static NotifierList migration_state_notifiers =3D NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); @@ -463,6 +464,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->block_incremental =3D s->parameters.block_incremental; params->has_x_multifd_threads =3D true; params->x_multifd_threads =3D s->parameters.x_multifd_threads; + params->has_x_multifd_group =3D true; + params->x_multifd_group =3D s->parameters.x_multifd_group; =20 return params; } @@ -722,6 +725,13 @@ void qmp_migrate_set_parameters(MigrationParameters *p= arams, Error **errp) "is invalid, it should be in the range of 1 to 255"); return; } + if (params->has_x_multifd_group && + (params->x_multifd_group < 1 || params->x_multifd_group > 1000= 0)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "multifd_group", + "is invalid, it should be in the range of 1 to 10000"); + return; + } =20 if (params->has_compress_level) { s->parameters.compress_level =3D params->compress_level; @@ -769,6 +779,9 @@ void qmp_migrate_set_parameters(MigrationParameters *pa= rams, Error **errp) if (params->has_x_multifd_threads) { s->parameters.x_multifd_threads =3D params->x_multifd_threads; } + if (params->has_x_multifd_group) { + s->parameters.x_multifd_group =3D params->x_multifd_group; + } } =20 =20 @@ -1313,6 +1326,15 @@ int migrate_multifd_threads(void) return s->parameters.x_multifd_threads; } =20 +int migrate_multifd_group(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.x_multifd_group; +} + int migrate_use_xbzrle(void) { MigrationState *s; @@ -2078,6 +2100,7 @@ static void migration_instance_init(Object *obj) .downtime_limit =3D DEFAULT_MIGRATE_SET_DOWNTIME, .x_checkpoint_delay =3D DEFAULT_MIGRATE_X_CHECKPOINT_DELAY, .x_multifd_threads =3D DEFAULT_MIGRATE_MULTIFD_THREADS, + .x_multifd_group =3D DEFAULT_MIGRATE_MULTIFD_GROUP, }; ms->parameters.tls_creds =3D g_strdup(""); ms->parameters.tls_hostname =3D g_strdup(""); diff --git a/migration/migration.h b/migration/migration.h index 20ea30c..4aaaf9e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -174,6 +174,7 @@ bool migrate_zero_blocks(void); bool migrate_auto_converge(void); bool migrate_use_multifd(void); int migrate_multifd_threads(void); +int migrate_multifd_group(void); =20 int migrate_use_xbzrle(void); int64_t migrate_xbzrle_cache_size(void); diff --git a/qapi-schema.json b/qapi-schema.json index 444e8f0..5b3733e 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1033,6 +1033,9 @@ # number of sockets used for migration. # The default value is 2 (since 2.10) # +# @x-multifd-group: Number of pages sent together to a thread +# The default value is 16 (since 2.10) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', @@ -1040,7 +1043,7 @@ 'cpu-throttle-initial', 'cpu-throttle-increment', 'tls-creds', 'tls-hostname', 'max-bandwidth', 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', - 'x-multifd-threads'] } + 'x-multifd-threads', 'x-multifd-group'] } =20 ## # @migrate-set-parameters: @@ -1119,6 +1122,9 @@ # number of sockets used for migration. # The default value is 2 (since 2.10) # +# @x-multifd-group: Number of pages sent together to a thread +# The default value is 16 (since 2.10) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -1133,7 +1139,8 @@ '*downtime-limit': 'int', '*x-checkpoint-delay': 'int', '*block-incremental': 'bool', - '*x-multifd-threads': 'int'} } + '*x-multifd-threads': 'int', + '*x-multifd-group': 'int'} } =20 ## # @query-migrate-parameters: --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299225927433.6738624295547; Mon, 17 Jul 2017 06:47:05 -0700 (PDT) Received: from localhost ([::1]:50538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Ma-0007Ua-Lr for importer@patchew.org; Mon, 17 Jul 2017 09:47:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Iu-00044K-Cv for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6Ip-0005PF-FU for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51782) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6Ip-0005P3-6M for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B1BFC04B30E for ; Mon, 17 Jul 2017 13:43:10 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63AFF5D6A2; Mon, 17 Jul 2017 13:43:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B1BFC04B30E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2B1BFC04B30E From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:28 +0200 Message-Id: <20170717134238.1966-8-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Jul 2017 13:43:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 07/17] migration: Create multifd migration 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" Creation of the threads, nothing inside yet. Signed-off-by: Juan Quintela -- Use pointers instead of long array names Move to use semaphores instead of conditions as paolo suggestion Put all the state inside one struct. Use a counter for the number of threads created. Needed during cancellatio= n. Add error return to thread creation Add id field Rename functions to multifd_save/load_setup/cleanup Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 14 ++++ migration/ram.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ migration/ram.h | 5 ++ 3 files changed, 211 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index ff3fc9d..5a82c1c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -288,6 +288,7 @@ static void process_incoming_migration_bh(void *opaque) } else { runstate_set(global_state_get_runstate()); } + multifd_load_cleanup(); /* * This must happen after any state changes since as soon as an extern= al * observer sees this event they might start to prod at the VM assuming @@ -348,6 +349,7 @@ static void process_incoming_migration_co(void *opaque) migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); error_report("load of migration failed: %s", strerror(-ret)); + multifd_load_cleanup(); exit(EXIT_FAILURE); } mis->bh =3D qemu_bh_new(process_incoming_migration_bh, mis); @@ -358,6 +360,11 @@ void migration_fd_process_incoming(QEMUFile *f) { Coroutine *co =3D qemu_coroutine_create(process_incoming_migration_co,= f); =20 + if (multifd_load_setup() !=3D 0) { + /* We haven't been able to create multifd threads + nothing better to do */ + exit(EXIT_FAILURE); + } qemu_file_set_blocking(f, false); qemu_coroutine_enter(co); } @@ -860,6 +867,7 @@ static void migrate_fd_cleanup(void *opaque) } qemu_mutex_lock_iothread(); =20 + multifd_save_cleanup(); qemu_fclose(s->to_dst_file); s->to_dst_file =3D NULL; } @@ -2049,6 +2057,12 @@ void migrate_fd_connect(MigrationState *s) } } =20 + if (multifd_save_setup() !=3D 0) { + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); + migrate_fd_cleanup(s); + return; + } qemu_thread_create(&s->thread, "live_migration", migration_thread, s, QEMU_THREAD_JOINABLE); s->migration_thread_running =3D true; diff --git a/migration/ram.c b/migration/ram.c index 1b08296..8e87533 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -356,6 +356,198 @@ static void compress_threads_save_setup(void) } } =20 +/* Multiple fd's */ + +struct MultiFDSendParams { + uint8_t id; + QemuThread thread; + QemuSemaphore sem; + QemuMutex mutex; + bool quit; +}; +typedef struct MultiFDSendParams MultiFDSendParams; + +struct { + MultiFDSendParams *params; + /* number of created threads */ + int count; +} *multifd_send_state; + +static void terminate_multifd_send_threads(void) +{ + int i; + + for (i =3D 0; i < multifd_send_state->count; i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + qemu_sem_post(&p->sem); + qemu_mutex_unlock(&p->mutex); + } +} + +void multifd_save_cleanup(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + terminate_multifd_send_threads(); + for (i =3D 0; i < multifd_send_state->count; i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_thread_join(&p->thread); + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem); + } + g_free(multifd_send_state->params); + multifd_send_state->params =3D NULL; + g_free(multifd_send_state); + multifd_send_state =3D NULL; +} + +static void *multifd_send_thread(void *opaque) +{ + MultiFDSendParams *p =3D opaque; + + while (true) { + qemu_mutex_lock(&p->mutex); + if (p->quit) { + qemu_mutex_unlock(&p->mutex); + break; + } + qemu_mutex_unlock(&p->mutex); + qemu_sem_wait(&p->sem); + } + + return NULL; +} + +int multifd_save_setup(void) +{ + int thread_count; + uint8_t i; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_threads(); + 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; + for (i =3D 0; i < thread_count; i++) { + char thread_name[16]; + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D i; + snprintf(thread_name, sizeof(thread_name), "multifdsend_%d", i); + qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p, + QEMU_THREAD_JOINABLE); + multifd_send_state->count++; + } + return 0; +} + +struct MultiFDRecvParams { + uint8_t id; + QemuThread thread; + QemuSemaphore sem; + QemuMutex mutex; + bool quit; +}; +typedef struct MultiFDRecvParams MultiFDRecvParams; + +struct { + MultiFDRecvParams *params; + /* number of created threads */ + int count; +} *multifd_recv_state; + +static void terminate_multifd_recv_threads(void) +{ + int i; + + for (i =3D 0; i < multifd_recv_state->count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + qemu_sem_post(&p->sem); + qemu_mutex_unlock(&p->mutex); + } +} + +void multifd_load_cleanup(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + terminate_multifd_recv_threads(); + for (i =3D 0; i < multifd_recv_state->count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_thread_join(&p->thread); + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem); + } + g_free(multifd_recv_state->params); + multifd_recv_state->params =3D NULL; + g_free(multifd_recv_state); + multifd_recv_state =3D NULL; +} + +static void *multifd_recv_thread(void *opaque) +{ + MultiFDRecvParams *p =3D opaque; + + while (true) { + qemu_mutex_lock(&p->mutex); + if (p->quit) { + qemu_mutex_unlock(&p->mutex); + break; + } + qemu_mutex_unlock(&p->mutex); + qemu_sem_wait(&p->sem); + } + + return NULL; +} + +int multifd_load_setup(void) +{ + int thread_count; + uint8_t i; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_threads(); + multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); + multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); + multifd_recv_state->count =3D 0; + for (i =3D 0; i < thread_count; i++) { + char thread_name[16]; + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D i; + snprintf(thread_name, sizeof(thread_name), "multifdrecv_%d", i); + qemu_thread_create(&p->thread, thread_name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); + multifd_recv_state->count++; + } + return 0; +} + /** * save_page_header: write page header to wire * diff --git a/migration/ram.h b/migration/ram.h index c081fde..93c2bb4 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -39,6 +39,11 @@ int64_t xbzrle_cache_resize(int64_t new_size); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 +int multifd_save_setup(void); +void multifd_save_cleanup(void); +int multifd_load_setup(void); +void multifd_load_cleanup(void); + uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); void acct_update_position(QEMUFile *f, size_t size, bool zero); --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299253503621.3316983863092; Mon, 17 Jul 2017 06:47:33 -0700 (PDT) Received: from localhost ([::1]:50540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6My-0007oL-3L for importer@patchew.org; Mon, 17 Jul 2017 09:47:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Iv-00045K-Gu for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6Ir-0005Pe-R4 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6Ir-0005PY-L8 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D6D72F86E0 for ; Mon, 17 Jul 2017 13:43:12 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B08C5D6A2; Mon, 17 Jul 2017 13:43:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D6D72F86E0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8D6D72F86E0 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:29 +0200 Message-Id: <20170717134238.1966-9-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 17 Jul 2017 13:43:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 08/17] migration: Split migration_fd_process_incomming 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 that on posterior patches. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5a82c1c..b81c498 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -356,19 +356,31 @@ static void process_incoming_migration_co(void *opaqu= e) qemu_bh_schedule(mis->bh); } =20 -void migration_fd_process_incoming(QEMUFile *f) +static void migration_incoming_setup(QEMUFile *f) { - Coroutine *co =3D qemu_coroutine_create(process_incoming_migration_co,= f); + MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 if (multifd_load_setup() !=3D 0) { /* We haven't been able to create multifd threads nothing better to do */ exit(EXIT_FAILURE); } + mis->from_src_file =3D f; qemu_file_set_blocking(f, false); +} + +static void migration_incoming_process(void) +{ + Coroutine *co =3D qemu_coroutine_create(process_incoming_migration_co,= NULL); qemu_coroutine_enter(co); } =20 +void migration_fd_process_incoming(QEMUFile *f) +{ + migration_incoming_setup(f); + migration_incoming_process(); +} + gboolean migration_ioc_process_incoming(QIOChannel *ioc) { MigrationIncomingState *mis =3D migration_incoming_get_current(); --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299398466662.3950735057696; Mon, 17 Jul 2017 06:49:58 -0700 (PDT) Received: from localhost ([::1]:50550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6PJ-0001cY-Sq for importer@patchew.org; Mon, 17 Jul 2017 09:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Iw-00045w-4m for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6Iu-0005QM-CG for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6Iu-0005Q3-3Z for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AEFB7F40F for ; Mon, 17 Jul 2017 13:43:15 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD8B95D6A2; Mon, 17 Jul 2017 13:43:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AEFB7F40F Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0AEFB7F40F From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:30 +0200 Message-Id: <20170717134238.1966-10-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Jul 2017 13:43:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 09/17] migration: Start of multiple fd work X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We create new channels for each new thread created. We only send through them a character to be sure that we are creating the channels in the right order. Signed-off-by: Juan Quintela -- Split SocketArgs into incoming and outgoing args Use UUID's on the initial message, so we are sure we are connecting to the right channel. Remove init semaphore. Now that we use uuids on the init message, we know that this is our channel. Fix recv socket destwroy, we were destroying send channels. This was very interesting, because we were using an unreferred object without problems. Move to struct of pointers init channel sooner. split recv thread creation. listen on main thread --- migration/migration.c | 7 ++- migration/ram.c | 118 ++++++++++++++++++++++++++++++++++++++++++----= ---- migration/ram.h | 2 + migration/socket.c | 38 ++++++++++++++-- migration/socket.h | 10 +++++ 5 files changed, 152 insertions(+), 23 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b81c498..e1c79d5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -389,8 +389,13 @@ gboolean migration_ioc_process_incoming(QIOChannel *io= c) QEMUFile *f =3D qemu_fopen_channel_input(ioc); mis->from_src_file =3D f; migration_fd_process_incoming(f); + if (!migrate_use_multifd()) { + return FALSE; + } else { + return TRUE; + } } - return FALSE; /* unregister */ + return multifd_new_channel(ioc); } =20 /* diff --git a/migration/ram.c b/migration/ram.c index 8e87533..b80f511 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" @@ -46,6 +47,8 @@ #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" #include "migration/colo.h" +#include "sysemu/sysemu.h" +#include "qemu/uuid.h" =20 /***********************************************************/ /* ram save/restore */ @@ -361,6 +364,7 @@ static void compress_threads_save_setup(void) struct MultiFDSendParams { uint8_t id; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool quit; @@ -401,6 +405,7 @@ void multifd_save_cleanup(void) qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + socket_send_channel_destroy(p->c); } g_free(multifd_send_state->params); multifd_send_state->params =3D NULL; @@ -408,11 +413,38 @@ void multifd_save_cleanup(void) multifd_send_state =3D NULL; } =20 +/* Default uuid for multifd when qemu is not started with uuid */ +static char multifd_uuid[] =3D "5c49fd7e-af88-4a07-b6e8-091fd696ad40"; +/* strlen(multifd) + '-' + + '-' + UUID_FMT + '\0' */ +#define MULTIFD_UUID_MSG (7 + 1 + 3 + 1 + UUID_FMT_LEN + 1) + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; + char string[MULTIFD_UUID_MSG]; + char *string_uuid; + int res; + bool exit =3D false; =20 - while (true) { + if (qemu_uuid_set) { + string_uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); + } else { + string_uuid =3D g_strdup(multifd_uuid); + } + res =3D snprintf(string, MULTIFD_UUID_MSG, "%s multifd %03d", + string_uuid, p->id); + g_free(string_uuid); + + /* -1 due to the wonders of '\0' accounting */ + if (res !=3D (MULTIFD_UUID_MSG - 1)) { + error_report("Multifd UUID message '%s' is not of right length", + string); + exit =3D true; + } else { + qio_channel_write(p->c, string, MULTIFD_UUID_MSG, &error_abort); + } + + while (!exit) { qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); @@ -445,6 +477,12 @@ int multifd_save_setup(void) qemu_sem_init(&p->sem, 0); p->quit =3D false; p->id =3D i; + p->c =3D socket_send_channel_create(); + if (!p->c) { + error_report("Error creating a send channel"); + multifd_save_cleanup(); + return -1; + } snprintf(thread_name, sizeof(thread_name), "multifdsend_%d", i); qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p, QEMU_THREAD_JOINABLE); @@ -456,6 +494,7 @@ int multifd_save_setup(void) struct MultiFDRecvParams { uint8_t id; QemuThread thread; + QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; bool quit; @@ -463,7 +502,7 @@ struct MultiFDRecvParams { typedef struct MultiFDRecvParams MultiFDRecvParams; =20 struct { - MultiFDRecvParams *params; + MultiFDRecvParams **params; /* number of created threads */ int count; } *multifd_recv_state; @@ -473,7 +512,7 @@ static void terminate_multifd_recv_threads(void) int i; =20 for (i =3D 0; i < multifd_recv_state->count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + MultiFDRecvParams *p =3D multifd_recv_state->params[i]; =20 qemu_mutex_lock(&p->mutex); p->quit =3D true; @@ -491,11 +530,13 @@ void multifd_load_cleanup(void) } terminate_multifd_recv_threads(); for (i =3D 0; i < multifd_recv_state->count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + MultiFDRecvParams *p =3D multifd_recv_state->params[i]; =20 qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + socket_recv_channel_destroy(p->c); + g_free(p); } g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; @@ -520,31 +561,70 @@ static void *multifd_recv_thread(void *opaque) return NULL; } =20 +gboolean multifd_new_channel(QIOChannel *ioc) +{ + int thread_count =3D migrate_multifd_threads(); + MultiFDRecvParams *p =3D g_new0(MultiFDRecvParams, 1); + MigrationState *s =3D migrate_get_current(); + char string[MULTIFD_UUID_MSG]; + char string_uuid[UUID_FMT_LEN]; + char *uuid; + int id; + + qio_channel_read(ioc, string, sizeof(string), &error_abort); + sscanf(string, "%s multifd %03d", string_uuid, &id); + + if (qemu_uuid_set) { + uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); + } else { + uuid =3D g_strdup(multifd_uuid); + } + if (strcmp(string_uuid, uuid)) { + error_report("multifd: received uuid '%s' and expected uuid '%s'", + string_uuid, uuid); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_recv_threads(); + return FALSE; + } + g_free(uuid); + + if (multifd_recv_state->params[id] !=3D NULL) { + error_report("multifd: received id '%d' is already setup'", id); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_recv_threads(); + return FALSE; + } + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D id; + p->c =3D ioc; + atomic_set(&multifd_recv_state->params[id], p); + qemu_thread_create(&p->thread, "multifd_recv", multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); + multifd_recv_state->count++; + + /* We need to return FALSE for the last channel */ + if (multifd_recv_state->count =3D=3D thread_count) { + return FALSE; + } else { + return TRUE; + } +} + int multifd_load_setup(void) { int thread_count; - uint8_t i; =20 if (!migrate_use_multifd()) { return 0; } thread_count =3D migrate_multifd_threads(); multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); - multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); + multifd_recv_state->params =3D g_new0(MultiFDRecvParams *, thread_coun= t); multifd_recv_state->count =3D 0; - for (i =3D 0; i < thread_count; i++) { - char thread_name[16]; - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem, 0); - p->quit =3D false; - p->id =3D i; - snprintf(thread_name, sizeof(thread_name), "multifdrecv_%d", i); - qemu_thread_create(&p->thread, thread_name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); - multifd_recv_state->count++; - } return 0; } =20 diff --git a/migration/ram.h b/migration/ram.h index 93c2bb4..9413544 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -31,6 +31,7 @@ =20 #include "qemu-common.h" #include "exec/cpu-common.h" +#include "io/channel.h" =20 extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; @@ -43,6 +44,7 @@ int multifd_save_setup(void); void multifd_save_cleanup(void); int multifd_load_setup(void); void multifd_load_cleanup(void); +gboolean multifd_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); diff --git a/migration/socket.c b/migration/socket.c index 6195596..32a6b39 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -26,6 +26,38 @@ #include "io/channel-socket.h" #include "trace.h" =20 +int socket_recv_channel_destroy(QIOChannel *recv) +{ + /* Remove channel */ + object_unref(OBJECT(recv)); + return 0; +} + +struct SocketOutgoingArgs { + SocketAddress *saddr; + Error **errp; +} outgoing_args; + +QIOChannel *socket_send_channel_create(void) +{ + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + + qio_channel_socket_connect_sync(sioc, outgoing_args.saddr, + outgoing_args.errp); + qio_channel_set_delay(QIO_CHANNEL(sioc), false); + return QIO_CHANNEL(sioc); +} + +int socket_send_channel_destroy(QIOChannel *send) +{ + /* Remove channel */ + object_unref(OBJECT(send)); + if (outgoing_args.saddr) { + qapi_free_SocketAddress(outgoing_args.saddr); + outgoing_args.saddr =3D NULL; + } + return 0; +} =20 static SocketAddress *tcp_build_address(const char *host_port, Error **err= p) { @@ -96,6 +128,9 @@ static void socket_start_outgoing_migration(MigrationSta= te *s, struct SocketConnectData *data =3D g_new0(struct SocketConnectData, 1); =20 data->s =3D s; + outgoing_args.saddr =3D saddr; + outgoing_args.errp =3D errp; + if (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET) { data->hostname =3D g_strdup(saddr->u.inet.host); } @@ -106,7 +141,6 @@ static void socket_start_outgoing_migration(MigrationSt= ate *s, socket_outgoing_migration, data, socket_connect_data_free); - qapi_free_SocketAddress(saddr); } =20 void tcp_start_outgoing_migration(MigrationState *s, @@ -151,8 +185,6 @@ static gboolean socket_accept_incoming_migration(QIOCha= nnel *ioc, =20 qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-incoming"); result =3D migration_channel_process_incoming(QIO_CHANNEL(sioc)); - object_unref(OBJECT(sioc)); - out: if (result =3D=3D FALSE) { /* Close listening socket as its no longer needed */ diff --git a/migration/socket.h b/migration/socket.h index 6b91e9d..dabce0e 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -16,6 +16,16 @@ =20 #ifndef QEMU_MIGRATION_SOCKET_H #define QEMU_MIGRATION_SOCKET_H + +#include "io/channel.h" + +QIOChannel *socket_recv_channel_create(void); +int socket_recv_channel_destroy(QIOChannel *recv); + +QIOChannel *socket_send_channel_create(void); + +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.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150030009364097.16361581496858; Mon, 17 Jul 2017 07:01:33 -0700 (PDT) Received: from localhost ([::1]:50616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6aZ-0003Sm-5l for importer@patchew.org; Mon, 17 Jul 2017 10:01:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6J9-0004Hg-0P for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6J3-0005Tb-Ry for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20715) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6J3-0005TN-Jk for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 729EE7F3F4 for ; Mon, 17 Jul 2017 13:43:24 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58ABC7D6B7; Mon, 17 Jul 2017 13:43:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 729EE7F3F4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 729EE7F3F4 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:31 +0200 Message-Id: <20170717134238.1966-11-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Jul 2017 13:43:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 10/17] migration: Create ram_multifd_page X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function still don't use multifd, but we have simplified ram_save_page, xbzrle and RDMA stuff is gone. We have added a new counter and a new flag for this type of pages. Signed-off-by: Juan Quintela --- hmp.c | 2 ++ migration/migration.c | 1 + migration/ram.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++= +++- qapi-schema.json | 5 ++- 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index b01605a..eeb308b 100644 --- a/hmp.c +++ b/hmp.c @@ -234,6 +234,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", info->ram->postcopy_requests); } + monitor_printf(mon, "multifd: %" PRIu64 " pages\n", + info->ram->multifd); } =20 if (info->has_disk) { diff --git a/migration/migration.c b/migration/migration.c index e1c79d5..d9d5415 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -528,6 +528,7 @@ static void populate_ram_info(MigrationInfo *info, Migr= ationState *s) info->ram->dirty_sync_count =3D ram_counters.dirty_sync_count; info->ram->postcopy_requests =3D ram_counters.postcopy_requests; info->ram->page_size =3D qemu_target_page_size(); + info->ram->multifd =3D ram_counters.multifd; =20 if (migrate_use_xbzrle()) { info->has_xbzrle_cache =3D true; diff --git a/migration/ram.c b/migration/ram.c index b80f511..2bf3fa7 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -68,6 +68,7 @@ #define RAM_SAVE_FLAG_XBZRLE 0x40 /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 +#define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 =20 static inline bool is_zero_range(uint8_t *p, uint64_t size) { @@ -362,12 +363,17 @@ static void compress_threads_save_setup(void) /* Multiple fd's */ =20 struct MultiFDSendParams { + /* not changed */ uint8_t id; QemuThread thread; QIOChannel *c; QemuSemaphore sem; QemuMutex mutex; + /* protected by param mutex */ bool quit; + uint8_t *address; + /* protected by multifd mutex */ + bool done; }; typedef struct MultiFDSendParams MultiFDSendParams; =20 @@ -375,6 +381,8 @@ struct { MultiFDSendParams *params; /* number of created threads */ int count; + QemuMutex mutex; + QemuSemaphore sem; } *multifd_send_state; =20 static void terminate_multifd_send_threads(void) @@ -443,6 +451,7 @@ static void *multifd_send_thread(void *opaque) } else { qio_channel_write(p->c, string, MULTIFD_UUID_MSG, &error_abort); } + qemu_sem_post(&multifd_send_state->sem); =20 while (!exit) { qemu_mutex_lock(&p->mutex); @@ -450,6 +459,15 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); break; } + if (p->address) { + p->address =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_mutex_lock(&multifd_send_state->mutex); + p->done =3D true; + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_sem_post(&multifd_send_state->sem); + continue; + } qemu_mutex_unlock(&p->mutex); qemu_sem_wait(&p->sem); } @@ -469,6 +487,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); multifd_send_state->count =3D 0; + qemu_mutex_init(&multifd_send_state->mutex); + qemu_sem_init(&multifd_send_state->sem, 0); for (i =3D 0; i < thread_count; i++) { char thread_name[16]; MultiFDSendParams *p =3D &multifd_send_state->params[i]; @@ -477,6 +497,8 @@ int multifd_save_setup(void) qemu_sem_init(&p->sem, 0); p->quit =3D false; p->id =3D i; + p->done =3D true; + p->address =3D 0; p->c =3D socket_send_channel_create(); if (!p->c) { error_report("Error creating a send channel"); @@ -491,6 +513,30 @@ int multifd_save_setup(void) return 0; } =20 +static int multifd_send_page(uint8_t *address) +{ + int i; + MultiFDSendParams *p =3D NULL; /* make happy gcc */ + + qemu_sem_wait(&multifd_send_state->sem); + qemu_mutex_lock(&multifd_send_state->mutex); + for (i =3D 0; i < multifd_send_state->count; i++) { + p =3D &multifd_send_state->params[i]; + + if (p->done) { + p->done =3D false; + break; + } + } + qemu_mutex_unlock(&multifd_send_state->mutex); + qemu_mutex_lock(&p->mutex); + p->address =3D address; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + + return 0; +} + struct MultiFDRecvParams { uint8_t id; QemuThread thread; @@ -537,6 +583,7 @@ void multifd_load_cleanup(void) qemu_sem_destroy(&p->sem); socket_recv_channel_destroy(p->c); g_free(p); + multifd_recv_state->params[i] =3D NULL; } g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; @@ -1058,6 +1105,32 @@ static int ram_save_page(RAMState *rs, PageSearchSta= tus *pss, bool last_stage) return pages; } =20 +static int ram_multifd_page(RAMState *rs, PageSearchStatus *pss, + bool last_stage) +{ + int pages; + uint8_t *p; + RAMBlock *block =3D pss->block; + ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; + + p =3D block->host + offset; + + pages =3D save_zero_page(rs, block, offset, p); + if (pages =3D=3D -1) { + ram_counters.transferred +=3D + save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_MULTIFD_PAGE); + qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); + multifd_send_page(p); + ram_counters.transferred +=3D TARGET_PAGE_SIZE; + pages =3D 1; + ram_counters.normal++; + ram_counters.multifd++; + } + + return pages; +} + static int do_compress_ram_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) { @@ -1486,6 +1559,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); } @@ -2778,6 +2853,10 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) if (!migrate_use_compression()) { invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } + + if (!migrate_use_multifd()) { + invalid_flags |=3D RAM_SAVE_FLAG_MULTIFD_PAGE; + } /* This RCU critical section can be very long running. * When RCU reclaims in the code start to become numerous, * it will be necessary to reduce the granularity of this @@ -2802,13 +2881,17 @@ static int ram_load(QEMUFile *f, void *opaque, int = version_id) if (flags & invalid_flags & RAM_SAVE_FLAG_COMPRESS_PAGE) { error_report("Received an unexpected compressed page"); } + if (flags & invalid_flags & RAM_SAVE_FLAG_MULTIFD_PAGE) { + error_report("Received an unexpected multifd page"); + } =20 ret =3D -EINVAL; break; } =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | - RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { + RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE | + RAM_SAVE_FLAG_MULTIFD_PAGE)) { RAMBlock *block =3D ram_block_from_stream(f, flags); =20 host =3D host_from_ram_block_offset(block, addr); @@ -2896,6 +2979,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; } break; + + case RAM_SAVE_FLAG_MULTIFD_PAGE: + qemu_get_buffer(f, host, TARGET_PAGE_SIZE); + break; + case RAM_SAVE_FLAG_EOS: /* normal exit */ break; diff --git a/qapi-schema.json b/qapi-schema.json index 5b3733e..f708782 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -601,6 +601,8 @@ # @page-size: The number of bytes per page for the various page-based # statistics (since 2.10) # +# @multifd: number of pages sent with multifd (since 2.10) +# # Since: 0.14.0 ## { 'struct': 'MigrationStats', @@ -608,7 +610,8 @@ 'duplicate': 'int', 'skipped': 'int', 'normal': 'int', 'normal-bytes': 'int', 'dirty-pages-rate' : 'int', 'mbps' : 'number', 'dirty-sync-count' : 'int', - 'postcopy-requests' : 'int', 'page-size' : 'int' } } + 'postcopy-requests' : 'int', 'page-size' : 'int', + 'multifd' : 'int'} } =20 ## # @XBZRLECacheStats: --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299420298178.76682374045356; Mon, 17 Jul 2017 06:50:20 -0700 (PDT) Received: from localhost ([::1]:50552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Pi-0001vg-2z for importer@patchew.org; Mon, 17 Jul 2017 09:50:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JB-0004K6-1t for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JA-0005WT-0i for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6J9-0005Vv-OD for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4E6CC04B303 for ; Mon, 17 Jul 2017 13:43:30 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF6857D6B7; Mon, 17 Jul 2017 13:43:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4E6CC04B303 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B4E6CC04B303 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:32 +0200 Message-Id: <20170717134238.1966-12-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 17 Jul 2017 13:43:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 11/17] migration: Really use multiple pages at a time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now send several pages at a time each time that we wakeup a thread. Signed-off-by: Juan Quintela -- Use iovec's insead of creating the equivalent. --- migration/ram.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2bf3fa7..90e1bcb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -362,6 +362,13 @@ static void compress_threads_save_setup(void) =20 /* Multiple fd's */ =20 + +typedef struct { + int num; + int size; + struct iovec *iov; +} multifd_pages_t; + struct MultiFDSendParams { /* not changed */ uint8_t id; @@ -371,7 +378,7 @@ struct MultiFDSendParams { QemuMutex mutex; /* protected by param mutex */ bool quit; - uint8_t *address; + multifd_pages_t pages; /* protected by multifd mutex */ bool done; }; @@ -459,8 +466,8 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); break; } - if (p->address) { - p->address =3D 0; + if (p->pages.num) { + p->pages.num =3D 0; qemu_mutex_unlock(&p->mutex); qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; @@ -475,6 +482,13 @@ static void *multifd_send_thread(void *opaque) return NULL; } =20 +static void multifd_init_group(multifd_pages_t *pages) +{ + pages->num =3D 0; + pages->size =3D migrate_multifd_group(); + pages->iov =3D g_malloc0(pages->size * sizeof(struct iovec)); +} + int multifd_save_setup(void) { int thread_count; @@ -498,7 +512,7 @@ int multifd_save_setup(void) p->quit =3D false; p->id =3D i; p->done =3D true; - p->address =3D 0; + multifd_init_group(&p->pages); p->c =3D socket_send_channel_create(); if (!p->c) { error_report("Error creating a send channel"); @@ -515,8 +529,23 @@ int multifd_save_setup(void) =20 static int multifd_send_page(uint8_t *address) { - int i; + int i, j; MultiFDSendParams *p =3D NULL; /* make happy gcc */ + static multifd_pages_t pages; + static bool once; + + if (!once) { + multifd_init_group(&pages); + once =3D true; + } + + pages.iov[pages.num].iov_base =3D address; + pages.iov[pages.num].iov_len =3D TARGET_PAGE_SIZE; + pages.num++; + + if (pages.num < (pages.size - 1)) { + return UINT16_MAX; + } =20 qemu_sem_wait(&multifd_send_state->sem); qemu_mutex_lock(&multifd_send_state->mutex); @@ -530,7 +559,12 @@ static int multifd_send_page(uint8_t *address) } qemu_mutex_unlock(&multifd_send_state->mutex); qemu_mutex_lock(&p->mutex); - p->address =3D address; + p->pages.num =3D pages.num; + for (j =3D 0; j < pages.size; j++) { + p->pages.iov[j].iov_base =3D pages.iov[j].iov_base; + p->pages.iov[j].iov_len =3D pages.iov[j].iov_len; + } + pages.num =3D 0; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299588760323.5630778217726; Mon, 17 Jul 2017 06:53:08 -0700 (PDT) Received: from localhost ([::1]:50566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6SM-00043Q-ED for importer@patchew.org; Mon, 17 Jul 2017 09:53:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JC-0004Nx-Px for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JB-0005XF-VA for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35564) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JB-0005Ww-PJ for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B03497CB88 for ; Mon, 17 Jul 2017 13:43:32 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13FAA5D6A2; Mon, 17 Jul 2017 13:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B03497CB88 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B03497CB88 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:33 +0200 Message-Id: <20170717134238.1966-13-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Jul 2017 13:43:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 12/17] migration: Send the fd number which we are going to use for this page X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are still sending the page through the main channel, that would change later in the series Signed-off-by: Juan Quintela --- migration/ram.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 90e1bcb..ac0742f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -568,7 +568,7 @@ static int multifd_send_page(uint8_t *address) qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 - return 0; + return i; } =20 struct MultiFDRecvParams { @@ -1143,6 +1143,7 @@ static int ram_multifd_page(RAMState *rs, PageSearchS= tatus *pss, bool last_stage) { int pages; + uint16_t fd_num; uint8_t *p; RAMBlock *block =3D pss->block; ram_addr_t offset =3D pss->page << TARGET_PAGE_BITS; @@ -1154,8 +1155,10 @@ static int ram_multifd_page(RAMState *rs, PageSearch= Status *pss, ram_counters.transferred +=3D save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE); + fd_num =3D multifd_send_page(p); + qemu_put_be16(rs->f, fd_num); + ram_counters.transferred +=3D 2; /* size of fd_num */ qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); - multifd_send_page(p); ram_counters.transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; ram_counters.normal++; @@ -2905,6 +2908,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) while (!postcopy_running && !ret && !(flags & RAM_SAVE_FLAG_EOS)) { ram_addr_t addr, total_ram_bytes; void *host =3D NULL; + uint16_t fd_num; uint8_t ch; =20 addr =3D qemu_get_be64(f); @@ -3015,6 +3019,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; =20 case RAM_SAVE_FLAG_MULTIFD_PAGE: + fd_num =3D qemu_get_be16(f); + if (fd_num !=3D 0) { + /* this is yet an unused variable, changed later */ + fd_num =3D fd_num; + } qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500300223166291.6468808455717; Mon, 17 Jul 2017 07:03:43 -0700 (PDT) Received: from localhost ([::1]:50624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6ce-0004zy-SX for importer@patchew.org; Mon, 17 Jul 2017 10:03:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JE-0004TY-Sg for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JD-0005Xw-SQ for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JD-0005Xf-Js for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 996497CB8A for ; Mon, 17 Jul 2017 13:43:34 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B1965D6A2; Mon, 17 Jul 2017 13:43:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 996497CB8A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 996497CB8A From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:34 +0200 Message-Id: <20170717134238.1966-14-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Jul 2017 13:43:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 13/17] migration: Create thread infrastructure for multifd recv side X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We make the locking and the transfer of information specific, even if we are still receiving things through the main thread. Signed-off-by: Juan Quintela --- migration/ram.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index ac0742f..49c4880 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -49,6 +49,7 @@ #include "migration/colo.h" #include "sysemu/sysemu.h" #include "qemu/uuid.h" +#include "qemu/iov.h" =20 /***********************************************************/ /* ram save/restore */ @@ -527,7 +528,7 @@ int multifd_save_setup(void) return 0; } =20 -static int multifd_send_page(uint8_t *address) +static uint16_t multifd_send_page(uint8_t *address, bool last_page) { int i, j; MultiFDSendParams *p =3D NULL; /* make happy gcc */ @@ -543,8 +544,10 @@ static int multifd_send_page(uint8_t *address) pages.iov[pages.num].iov_len =3D TARGET_PAGE_SIZE; pages.num++; =20 - if (pages.num < (pages.size - 1)) { - return UINT16_MAX; + if (!last_page) { + if (pages.num < (pages.size - 1)) { + return UINT16_MAX; + } } =20 qemu_sem_wait(&multifd_send_state->sem); @@ -572,12 +575,17 @@ static int multifd_send_page(uint8_t *address) } =20 struct MultiFDRecvParams { + /* not changed */ uint8_t id; QemuThread thread; QIOChannel *c; + QemuSemaphore ready; QemuSemaphore sem; QemuMutex mutex; + /* proteced by param mutex */ bool quit; + multifd_pages_t pages; + bool done; }; typedef struct MultiFDRecvParams MultiFDRecvParams; =20 @@ -629,12 +637,20 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 + qemu_sem_post(&p->ready); while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } + if (p->pages.num) { + p->pages.num =3D 0; + p->done =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->ready); + continue; + } qemu_mutex_unlock(&p->mutex); qemu_sem_wait(&p->sem); } @@ -679,8 +695,11 @@ gboolean multifd_new_channel(QIOChannel *ioc) } qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); + qemu_sem_init(&p->ready, 0); p->quit =3D false; p->id =3D id; + p->done =3D false; + multifd_init_group(&p->pages); p->c =3D ioc; atomic_set(&multifd_recv_state->params[id], p); qemu_thread_create(&p->thread, "multifd_recv", multifd_recv_thread, p, @@ -709,6 +728,42 @@ int multifd_load_setup(void) return 0; } =20 +static void multifd_recv_page(uint8_t *address, uint16_t fd_num) +{ + int thread_count; + MultiFDRecvParams *p; + static multifd_pages_t pages; + static bool once; + + if (!once) { + multifd_init_group(&pages); + once =3D true; + } + + pages.iov[pages.num].iov_base =3D address; + pages.iov[pages.num].iov_len =3D TARGET_PAGE_SIZE; + pages.num++; + + if (fd_num =3D=3D UINT16_MAX) { + return; + } + + thread_count =3D migrate_multifd_threads(); + assert(fd_num < thread_count); + p =3D multifd_recv_state->params[fd_num]; + + qemu_sem_wait(&p->ready); + + qemu_mutex_lock(&p->mutex); + p->done =3D false; + iov_copy(p->pages.iov, pages.num, pages.iov, pages.num, 0, + iov_size(pages.iov, pages.num)); + p->pages.num =3D pages.num; + pages.num =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); +} + /** * save_page_header: write page header to wire * @@ -1155,7 +1210,7 @@ static int ram_multifd_page(RAMState *rs, PageSearchS= tatus *pss, ram_counters.transferred +=3D save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE); - fd_num =3D multifd_send_page(p); + fd_num =3D multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1= ); qemu_put_be16(rs->f, fd_num); ram_counters.transferred +=3D 2; /* size of fd_num */ qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); @@ -3020,10 +3075,7 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) =20 case RAM_SAVE_FLAG_MULTIFD_PAGE: fd_num =3D qemu_get_be16(f); - if (fd_num !=3D 0) { - /* this is yet an unused variable, changed later */ - fd_num =3D fd_num; - } + multifd_recv_page(host, fd_num); qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500300362719998.3708332615962; Mon, 17 Jul 2017 07:06:02 -0700 (PDT) Received: from localhost ([::1]:50638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6er-0007JI-Nl for importer@patchew.org; Mon, 17 Jul 2017 10:05:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JJ-0004ev-Tu for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JF-0005Z5-W3 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JF-0005Yj-QE for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5A854E04A for ; Mon, 17 Jul 2017 13:43:36 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED06A5D6A2; Mon, 17 Jul 2017 13:43:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5A854E04A Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C5A854E04A From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:35 +0200 Message-Id: <20170717134238.1966-15-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Jul 2017 13:43:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 14/17] migration: Delay the start of reception on main 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" When we start multifd, we will want to delay the main channel until the others are created. Signed-off-by: Juan Quintela --- migration/migration.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index d9d5415..e122684 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -358,14 +358,11 @@ static void process_incoming_migration_co(void *opaqu= e) =20 static void migration_incoming_setup(QEMUFile *f) { - MigrationIncomingState *mis =3D migration_incoming_get_current(); - if (multifd_load_setup() !=3D 0) { /* We haven't been able to create multifd threads nothing better to do */ exit(EXIT_FAILURE); } - mis->from_src_file =3D f; qemu_file_set_blocking(f, false); } =20 @@ -384,18 +381,26 @@ void migration_fd_process_incoming(QEMUFile *f) gboolean migration_ioc_process_incoming(QIOChannel *ioc) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + gboolean result =3D FALSE; =20 if (!mis->from_src_file) { QEMUFile *f =3D qemu_fopen_channel_input(ioc); mis->from_src_file =3D f; - migration_fd_process_incoming(f); - if (!migrate_use_multifd()) { - return FALSE; - } else { - return TRUE; + migration_incoming_setup(f); + if (migrate_use_multifd()) { + result =3D TRUE; } + } else { + /* we can only arrive here if multifd is on + and this is a new channel */ + result =3D multifd_new_channel(ioc); } - return multifd_new_channel(ioc); + if (result =3D=3D FALSE) { + /* called when !multifd and for last multifd channel */ + migration_incoming_process(); + } + + return result; } =20 /* --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299561843880.6339337058929; Mon, 17 Jul 2017 06:52:41 -0700 (PDT) Received: from localhost ([::1]:50564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6S0-0003nR-Go for importer@patchew.org; Mon, 17 Jul 2017 09:52:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JJ-0004eu-Tt for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JI-0005aE-2r for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JH-0005Zk-PX for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C32434E4D6 for ; Mon, 17 Jul 2017 13:43:38 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20A295D6A2; Mon, 17 Jul 2017 13:43:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C32434E4D6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C32434E4D6 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:36 +0200 Message-Id: <20170717134238.1966-16-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Jul 2017 13:43:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 15/17] migration: Test new fd infrastructure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We just send the address through the alternate channels and test that it is ok. Signed-off-by: Juan Quintela --- migration/ram.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 49c4880..b55b243 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -468,8 +468,26 @@ static void *multifd_send_thread(void *opaque) break; } if (p->pages.num) { + int i; + int num; + + num =3D p->pages.num; p->pages.num =3D 0; qemu_mutex_unlock(&p->mutex); + + for (i =3D 0; i < num; i++) { + if (qio_channel_write(p->c, + (const char *)&p->pages.iov[i].iov_b= ase, + sizeof(uint8_t *), &error_abort) + !=3D sizeof(uint8_t *)) { + MigrationState *s =3D migrate_get_current(); + + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_send_threads(); + return NULL; + } + } qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; qemu_mutex_unlock(&multifd_send_state->mutex); @@ -636,6 +654,7 @@ void multifd_load_cleanup(void) static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; + uint8_t *recv_address; =20 qemu_sem_post(&p->ready); while (true) { @@ -645,7 +664,38 @@ static void *multifd_recv_thread(void *opaque) break; } if (p->pages.num) { + int i; + int num; + + num =3D p->pages.num; p->pages.num =3D 0; + + for (i =3D 0; i < num; i++) { + if (qio_channel_read(p->c, + (char *)&recv_address, + sizeof(uint8_t *), &error_abort) + !=3D sizeof(uint8_t *)) { + MigrationState *s =3D migrate_get_current(); + + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_recv_threads(); + return NULL; + } + if (recv_address !=3D p->pages.iov[i].iov_base) { + MigrationState *s =3D migrate_get_current(); + + printf("We received %p what we were expecting %p (%d)\= n", + recv_address, + p->pages.iov[i].iov_base, i); + + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_recv_threads(); + return NULL; + } + } + p->done =3D true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15002997263991016.503805516829; Mon, 17 Jul 2017 06:55:26 -0700 (PDT) Received: from localhost ([::1]:50577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6Ue-0006F7-Oy for importer@patchew.org; Mon, 17 Jul 2017 09:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JL-0004j3-8e for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JK-0005b9-0v for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JJ-0005ai-N2 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3EC47F6A2 for ; Mon, 17 Jul 2017 13:43:40 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F0DF5D6A2; Mon, 17 Jul 2017 13:43:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3EC47F6A2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A3EC47F6A2 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:37 +0200 Message-Id: <20170717134238.1966-17-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Jul 2017 13:43:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 16/17] migration: Transfer pages over new channels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We switch for sending the page number to send real pages. Signed-off-by: Juan Quintela -- Remove the HACK bit, now we have the function that calculates the size of a page exported. --- migration/migration.c | 14 ++++++++---- migration/ram.c | 59 +++++++++++++++++------------------------------= ---- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e122684..34a34b7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1882,13 +1882,14 @@ static void *migration_thread(void *opaque) /* Used by the bandwidth calcs, updated later */ int64_t initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); int64_t setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); - int64_t initial_bytes =3D 0; /* * The final stage happens when the remaining data is smaller than * this threshold; it's calculated from the requested downtime and * measured bandwidth */ int64_t threshold_size =3D 0; + int64_t qemu_file_bytes =3D 0; + int64_t multifd_pages =3D 0; int64_t start_time =3D initial_time; int64_t end_time; bool old_vm_running =3D false; @@ -1976,9 +1977,13 @@ static void *migration_thread(void *opaque) } current_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); if (current_time >=3D initial_time + BUFFER_DELAY) { - uint64_t transferred_bytes =3D qemu_ftell(s->to_dst_file) - - initial_bytes; uint64_t time_spent =3D current_time - initial_time; + uint64_t qemu_file_bytes_now =3D qemu_ftell(s->to_dst_file); + uint64_t multifd_pages_now =3D ram_counters.multifd; + uint64_t transferred_bytes =3D + (qemu_file_bytes_now - qemu_file_bytes) + + (multifd_pages_now - multifd_pages) * + qemu_target_page_size(); double bandwidth =3D (double)transferred_bytes / time_spent; threshold_size =3D bandwidth * s->parameters.downtime_limit; =20 @@ -1996,7 +2001,8 @@ static void *migration_thread(void *opaque) =20 qemu_file_reset_rate_limit(s->to_dst_file); initial_time =3D current_time; - initial_bytes =3D qemu_ftell(s->to_dst_file); + qemu_file_bytes =3D qemu_file_bytes_now; + multifd_pages =3D multifd_pages_now; } if (qemu_file_rate_limit(s->to_dst_file)) { /* usleep expects microseconds */ diff --git a/migration/ram.c b/migration/ram.c index b55b243..c78b286 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -468,25 +468,21 @@ static void *multifd_send_thread(void *opaque) break; } if (p->pages.num) { - int i; int num; =20 num =3D p->pages.num; p->pages.num =3D 0; qemu_mutex_unlock(&p->mutex); =20 - for (i =3D 0; i < num; i++) { - if (qio_channel_write(p->c, - (const char *)&p->pages.iov[i].iov_b= ase, - sizeof(uint8_t *), &error_abort) - !=3D sizeof(uint8_t *)) { - MigrationState *s =3D migrate_get_current(); + if (qio_channel_writev_all(p->c, p->pages.iov, + num, &error_abort) + !=3D num * TARGET_PAGE_SIZE) { + MigrationState *s =3D migrate_get_current(); =20 - migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); - terminate_multifd_send_threads(); - return NULL; - } + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_send_threads(); + return NULL; } qemu_mutex_lock(&multifd_send_state->mutex); p->done =3D true; @@ -654,7 +650,6 @@ void multifd_load_cleanup(void) static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; - uint8_t *recv_address; =20 qemu_sem_post(&p->ready); while (true) { @@ -664,38 +659,21 @@ static void *multifd_recv_thread(void *opaque) break; } if (p->pages.num) { - int i; int num; =20 num =3D p->pages.num; p->pages.num =3D 0; =20 - for (i =3D 0; i < num; i++) { - if (qio_channel_read(p->c, - (char *)&recv_address, - sizeof(uint8_t *), &error_abort) - !=3D sizeof(uint8_t *)) { - MigrationState *s =3D migrate_get_current(); + if (qio_channel_readv_all(p->c, p->pages.iov, + num, &error_abort) + !=3D num * TARGET_PAGE_SIZE) { + MigrationState *s =3D migrate_get_current(); =20 - migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); - terminate_multifd_recv_threads(); - return NULL; - } - if (recv_address !=3D p->pages.iov[i].iov_base) { - MigrationState *s =3D migrate_get_current(); - - printf("We received %p what we were expecting %p (%d)\= n", - recv_address, - p->pages.iov[i].iov_base, i); - - migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); - terminate_multifd_recv_threads(); - return NULL; - } + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + terminate_multifd_recv_threads(); + return NULL; } - p->done =3D true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); @@ -1262,8 +1240,10 @@ static int ram_multifd_page(RAMState *rs, PageSearch= Status *pss, offset | RAM_SAVE_FLAG_MULTIFD_PAGE); fd_num =3D multifd_send_page(p, rs->migration_dirty_pages =3D=3D 1= ); qemu_put_be16(rs->f, fd_num); + if (fd_num !=3D UINT16_MAX) { + qemu_fflush(rs->f); + } ram_counters.transferred +=3D 2; /* size of fd_num */ - qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); ram_counters.transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; ram_counters.normal++; @@ -3126,7 +3106,6 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) case RAM_SAVE_FLAG_MULTIFD_PAGE: fd_num =3D qemu_get_be16(f); multifd_recv_page(host, fd_num); - qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 case RAM_SAVE_FLAG_EOS: --=20 2.9.4 From nobody Thu May 2 05:31:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500299661172842.038094905102; Mon, 17 Jul 2017 06:54:21 -0700 (PDT) Received: from localhost ([::1]:50571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6TZ-00054z-RO for importer@patchew.org; Mon, 17 Jul 2017 09:54:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX6JN-0004pJ-EU for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX6JM-0005cJ-71 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52286) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dX6JL-0005bh-UQ for qemu-devel@nongnu.org; Mon, 17 Jul 2017 09:43:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E063A7EBDD for ; Mon, 17 Jul 2017 13:43:42 +0000 (UTC) Received: from secure.mitica (ovpn-117-165.ams2.redhat.com [10.36.117.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 038BD5D6A2; Mon, 17 Jul 2017 13:43:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E063A7EBDD Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E063A7EBDD From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 15:42:38 +0200 Message-Id: <20170717134238.1966-18-quintela@redhat.com> In-Reply-To: <20170717134238.1966-1-quintela@redhat.com> References: <20170717134238.1966-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Jul 2017 13:43:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 17/17] migration: Flush receive queue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Each time that we sync the bitmap, it is a possiblity that we receive a page that is being processed by a different thread. We fix this problem just making sure that we wait for all receiving threads to finish its work before we procedeed with the next stage. We are low on page flags, so we use a combination that is not valid to emit that message: MULTIFD_PAGE and COMPRESSED. I tried to make a migration command for it, but it don't work because we sync the bitmap sometimes when we have already sent the beggining of the section, so I just added a new page flag. Signed-off-by: Juan Quintela --- migration/ram.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index c78b286..bffe204 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -71,6 +71,12 @@ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 #define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 =20 +/* We are getting low on pages flags, so we start using combinations + When we need to flush a page, we sent it as + RAM_SAVE_FLAG_MULTIFD_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE + We don't allow that combination +*/ + static inline bool is_zero_range(uint8_t *p, uint64_t size) { return buffer_is_zero(p, size); @@ -193,6 +199,9 @@ struct RAMState { uint64_t iterations_prev; /* Iterations since start */ uint64_t iterations; + /* Indicates if we have synced the bitmap and we need to assure that + target has processeed all previous pages */ + bool multifd_needs_flush; /* protects modification of the bitmap */ uint64_t migration_dirty_pages; /* number of dirty bits in the bitmap */ @@ -363,7 +372,6 @@ static void compress_threads_save_setup(void) =20 /* Multiple fd's */ =20 - typedef struct { int num; int size; @@ -595,9 +603,11 @@ struct MultiFDRecvParams { QIOChannel *c; QemuSemaphore ready; QemuSemaphore sem; + QemuCond cond_sync; QemuMutex mutex; /* proteced by param mutex */ bool quit; + bool sync; multifd_pages_t pages; bool done; }; @@ -637,6 +647,7 @@ void multifd_load_cleanup(void) qemu_thread_join(&p->thread); qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + qemu_cond_destroy(&p->cond_sync); socket_recv_channel_destroy(p->c); g_free(p); multifd_recv_state->params[i] =3D NULL; @@ -675,6 +686,10 @@ static void *multifd_recv_thread(void *opaque) return NULL; } p->done =3D true; + if (p->sync) { + qemu_cond_signal(&p->cond_sync); + p->sync =3D false; + } qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->ready); continue; @@ -724,9 +739,11 @@ gboolean multifd_new_channel(QIOChannel *ioc) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->ready, 0); + qemu_cond_init(&p->cond_sync); p->quit =3D false; p->id =3D id; p->done =3D false; + p->sync =3D false; multifd_init_group(&p->pages); p->c =3D ioc; atomic_set(&multifd_recv_state->params[id], p); @@ -792,6 +809,27 @@ static void multifd_recv_page(uint8_t *address, uint16= _t fd_num) qemu_sem_post(&p->sem); } =20 +static int multifd_flush(void) +{ + int i, thread_count; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_threads(); + for (i =3D 0; i < thread_count; i++) { + MultiFDRecvParams *p =3D multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + while (!p->done) { + p->sync =3D true; + qemu_cond_wait(&p->cond_sync, &p->mutex); + } + qemu_mutex_unlock(&p->mutex); + } + return 0; +} + /** * save_page_header: write page header to wire * @@ -809,6 +847,12 @@ static size_t save_page_header(RAMState *rs, QEMUFile = *f, RAMBlock *block, { size_t size, len; =20 + if (rs->multifd_needs_flush && + (offset & RAM_SAVE_FLAG_MULTIFD_PAGE)) { + offset |=3D RAM_SAVE_FLAG_ZERO; + rs->multifd_needs_flush =3D false; + } + if (block =3D=3D rs->last_sent_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; } @@ -2496,6 +2540,9 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) =20 if (!migration_in_postcopy()) { migration_bitmap_sync(rs); + if (migrate_use_multifd()) { + rs->multifd_needs_flush =3D true; + } } =20 ram_control_before_iterate(f, RAM_CONTROL_FINISH); @@ -2538,6 +2585,9 @@ static void ram_save_pending(QEMUFile *f, void *opaqu= e, uint64_t max_size, qemu_mutex_lock_iothread(); rcu_read_lock(); migration_bitmap_sync(rs); + if (migrate_use_multifd()) { + rs->multifd_needs_flush =3D true; + } rcu_read_unlock(); qemu_mutex_unlock_iothread(); remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SIZE; @@ -3012,6 +3062,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) break; } =20 + if ((flags & (RAM_SAVE_FLAG_MULTIFD_PAGE | RAM_SAVE_FLAG_ZERO)) + =3D=3D (RAM_SAVE_FLAG_MULTIFD_PAGE | RAM_SAVE_FLAG_ZERO)= ) { + multifd_flush(); + flags =3D flags & ~RAM_SAVE_FLAG_ZERO; + } if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE | RAM_SAVE_FLAG_MULTIFD_PAGE)) { --=20 2.9.4