From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15815867778220.8918077325201921; Thu, 13 Feb 2020 01:39:37 -0800 (PST) Received: from localhost ([::1]:49488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ay7-0008MC-UO for importer@patchew.org; Thu, 13 Feb 2020 04:39:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45891) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Awz-0006gh-2A for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Awx-0004zK-Sn for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:24 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2769 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awx-0004qB-Gu for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:23 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id ADAF9EEDB2457C73FE05; Thu, 13 Feb 2020 17:38:15 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:08 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 01/14] migration: add the 'migrate_use_rdma_pin_all' function Date: Thu, 13 Feb 2020 17:37:42 +0800 Message-ID: <20200213093755.370-2-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng Reviewed-by: Juan Quintela --- migration/migration.c | 9 +++++++++ migration/migration.h | 1 + 2 files changed, 10 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 3a21a4686c..10a13e0c79 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2208,6 +2208,15 @@ bool migrate_use_events(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_use_rdma_pin_all(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL]; +} + bool migrate_use_multifd(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index 8473ddfc88..50fc2693c7 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -297,6 +297,7 @@ bool migrate_ignore_shared(void); bool migrate_validate_uuid(void); =20 bool migrate_auto_converge(void); +bool migrate_use_rdma_pin_all(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581586877827383.9977775295089; Thu, 13 Feb 2020 01:41:17 -0800 (PST) Received: from localhost ([::1]:49528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Azk-0003RD-ID for importer@patchew.org; Thu, 13 Feb 2020 04:41:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45893) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Awy-0006gi-W4 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Awx-0004zF-Sh for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:24 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2766 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awx-0004qA-Gp for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:23 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A33F81D81F85C3A487B6; Thu, 13 Feb 2020 17:38:15 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:08 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 02/14] migration: judge whether or not the RDMA is used for migration Date: Thu, 13 Feb 2020 17:37:43 +0800 Message-ID: <20200213093755.370-3-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/migration.c | 10 ++++++++++ migration/migration.h | 1 + 2 files changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 10a13e0c79..819089a7ea 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -107,6 +107,7 @@ static NotifierList migration_state_notifiers =3D NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); =20 static bool deferred_incoming; +static bool enabled_rdma_migration; =20 /* Messages sent on the return path from destination to source */ enum mig_rp_message_type { @@ -354,6 +355,7 @@ void migrate_add_address(SocketAddress *address) void qemu_start_incoming_migration(const char *uri, Error **errp) { const char *p; + enabled_rdma_migration =3D false; =20 qapi_event_send_migration(MIGRATION_STATUS_SETUP); if (!strcmp(uri, "defer")) { @@ -362,6 +364,7 @@ void qemu_start_incoming_migration(const char *uri, Err= or **errp) tcp_start_incoming_migration(p, errp); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { + enabled_rdma_migration =3D true; rdma_start_incoming_migration(p, errp); #endif } else if (strstart(uri, "exec:", &p)) { @@ -1982,6 +1985,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool = blk, Error *local_err =3D NULL; MigrationState *s =3D migrate_get_current(); const char *p; + enabled_rdma_migration =3D false; =20 if (!migrate_prepare(s, has_blk && blk, has_inc && inc, has_resume && resume, errp)) { @@ -1993,6 +1997,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool = blk, tcp_start_outgoing_migration(s, p, &local_err); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { + enabled_rdma_migration =3D true; rdma_start_outgoing_migration(s, p, &local_err); #endif } else if (strstart(uri, "exec:", &p)) { @@ -2208,6 +2213,11 @@ bool migrate_use_events(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_use_rdma(void) +{ + return enabled_rdma_migration; +} + bool migrate_use_rdma_pin_all(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index 50fc2693c7..9b37320d50 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -297,6 +297,7 @@ bool migrate_ignore_shared(void); bool migrate_validate_uuid(void); =20 bool migrate_auto_converge(void); +bool migrate_use_rdma(void); bool migrate_use_rdma_pin_all(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581586781055469.2618529951859; Thu, 13 Feb 2020 01:39:41 -0800 (PST) Received: from localhost ([::1]:49494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AyB-0008RF-Qb for importer@patchew.org; Thu, 13 Feb 2020 04:39:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45910) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Awz-0006gs-G2 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Awy-00050B-3r for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:25 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2768 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awx-0004q9-Gq for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:24 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A80D067201E9F3108812; Thu, 13 Feb 2020 17:38:15 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:09 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 03/14] migration/rdma: Create multiFd migration threads Date: Thu, 13 Feb 2020 17:37:44 +0800 Message-ID: <20200213093755.370-4-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Creation of the multifd send threads for RDMA migration, nothing inside yet. Signed-off-by: Zhimin Feng --- migration/multifd.c | 33 +++++++++++++--- migration/multifd.h | 2 + migration/qemu-file.c | 5 +++ migration/qemu-file.h | 1 + migration/rdma.c | 88 ++++++++++++++++++++++++++++++++++++++++++- migration/rdma.h | 3 ++ 6 files changed, 125 insertions(+), 7 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index b3e8ae9bcc..63678d7fdd 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -424,7 +424,7 @@ void multifd_send_sync_main(QEMUFile *f) { int i; =20 - if (!migrate_use_multifd()) { + if (!migrate_use_multifd() || migrate_use_rdma()) { return; } if (multifd_send_state->pages->used) { @@ -562,6 +562,20 @@ out: return NULL; } =20 +static void rdma_send_channel_create(MultiFDSendParams *p) +{ + Error *local_err =3D NULL; + + if (p->quit) { + error_setg(&local_err, "multifd: send id %d already quit", p->id); + return ; + } + p->running =3D true; + + qemu_thread_create(&p->thread, p->name, multifd_rdma_send_thread, p, + QEMU_THREAD_JOINABLE); +} + static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) { MultiFDSendParams *p =3D opaque; @@ -621,7 +635,11 @@ int multifd_save_setup(Error **errp) p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); p->name =3D g_strdup_printf("multifdsend_%d", i); - socket_send_channel_create(multifd_new_send_channel_async, p); + if (!migrate_use_rdma()) { + socket_send_channel_create(multifd_new_send_channel_async, p); + } else { + rdma_send_channel_create(p); + } } return 0; } @@ -720,7 +738,7 @@ void multifd_recv_sync_main(void) { int i; =20 - if (!migrate_use_multifd()) { + if (!migrate_use_multifd() || migrate_use_rdma()) { return; } for (i =3D 0; i < migrate_multifd_channels(); i++) { @@ -890,8 +908,13 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error *= *errp) p->num_packets =3D 1; =20 p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); + if (!migrate_use_rdma()) { + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); + } else { + qemu_thread_create(&p->thread, p->name, multifd_rdma_recv_thread, = p, + QEMU_THREAD_JOINABLE); + } atomic_inc(&multifd_recv_state->count); return atomic_read(&multifd_recv_state->count) =3D=3D migrate_multifd_channels(); diff --git a/migration/multifd.h b/migration/multifd.h index d8b0205977..c9c11ad140 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,6 +13,8 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 +#include "migration/rdma.h" + int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 1c3a358a14..f0ed8f1381 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -248,6 +248,11 @@ void qemu_fflush(QEMUFile *f) f->iovcnt =3D 0; } =20 +void *getQIOChannel(QEMUFile *f) +{ + return f->opaque; +} + void ram_control_before_iterate(QEMUFile *f, uint64_t flags) { int ret =3D 0; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index a9b6d6ccb7..fc656a3b72 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -161,6 +161,7 @@ int qemu_file_shutdown(QEMUFile *f); QEMUFile *qemu_file_get_return_path(QEMUFile *f); void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); +void *getQIOChannel(QEMUFile *f); =20 void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); diff --git a/migration/rdma.c b/migration/rdma.c index 2379b8345b..f086ab5a82 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -34,6 +34,7 @@ #include #include #include "trace.h" +#include "multifd.h" =20 /* * Print and error on both the Monitor and the Log file. @@ -3975,6 +3976,34 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, = const char *mode) return rioc->file; } =20 +static void migration_rdma_process_incoming(QEMUFile *f, Error **errp) +{ + MigrationIncomingState *mis =3D migration_incoming_get_current(); + Error *local_err =3D NULL; + QIOChannel *ioc =3D NULL; + bool start_migration; + + if (!mis->from_src_file) { + mis->from_src_file =3D f; + qemu_file_set_blocking(f, false); + + start_migration =3D migrate_use_multifd(); + } else { + ioc =3D QIO_CHANNEL(getQIOChannel(f)); + /* Multiple connections */ + assert(migrate_use_multifd()); + start_migration =3D multifd_recv_new_channel(ioc, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } + + if (start_migration) { + migration_incoming_process(); + } +} + static void rdma_accept_incoming_migration(void *opaque) { RDMAContext *rdma =3D opaque; @@ -4003,8 +4032,12 @@ static void rdma_accept_incoming_migration(void *opa= que) return; } =20 - rdma->migration_started_on_destination =3D 1; - migration_fd_process_incoming(f, errp); + if (migrate_use_multifd()) { + migration_rdma_process_incoming(f, errp); + } else { + rdma->migration_started_on_destination =3D 1; + migration_fd_process_incoming(f, errp); + } } =20 void rdma_start_incoming_migration(const char *host_port, Error **errp) @@ -4048,6 +4081,15 @@ void rdma_start_incoming_migration(const char *host_= port, Error **errp) qemu_rdma_return_path_dest_init(rdma_return_path, rdma); } =20 + if (multifd_load_setup(&local_err) !=3D 0) { + /* + * We haven't been able to create multifd threads + * nothing better to do + */ + error_report_err(local_err); + goto err; + } + qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration, NULL, (void *)(intptr_t)rdma); return; @@ -4118,3 +4160,45 @@ err: g_free(rdma); g_free(rdma_return_path); } + +void *multifd_rdma_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_sync); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + return NULL; +} + +void *multifd_rdma_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); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + return NULL; +} diff --git a/migration/rdma.h b/migration/rdma.h index de2ba09dc5..3a00573083 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -17,6 +17,9 @@ #ifndef QEMU_MIGRATION_RDMA_H #define QEMU_MIGRATION_RDMA_H =20 +void *multifd_rdma_recv_thread(void *opaque); +void *multifd_rdma_send_thread(void *opaque); + void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); =20 --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158158687821074.48165336842555; Thu, 13 Feb 2020 01:41:18 -0800 (PST) Received: from localhost ([::1]:49530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Azk-0003Wv-Rn for importer@patchew.org; Thu, 13 Feb 2020 04:41:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax3-0006j5-1V for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-00053L-F1 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2771 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awz-00050g-Rt for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B0019EFBA72BCA44EF30; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:10 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 04/14] migration/rdma: Export the RDMAContext struct Date: Thu, 13 Feb 2020 17:37:45 +0800 Message-ID: <20200213093755.370-5-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We need to use the RDMAContext in migration/multifd.c so it has to be exported. Signed-off-by: Zhimin Feng --- migration/rdma.c | 243 ---------------------------------------------- migration/rdma.h | 247 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 247 insertions(+), 243 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index f086ab5a82..a76823986e 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -19,9 +19,7 @@ #include "qemu/cutils.h" #include "rdma.h" #include "migration.h" -#include "qemu-file.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -47,34 +45,6 @@ } \ } while (0) =20 -#define RDMA_RESOLVE_TIMEOUT_MS 10000 - -/* Do not merge data if larger than this. */ -#define RDMA_MERGE_MAX (2 * 1024 * 1024) -#define RDMA_SIGNALED_SEND_MAX (RDMA_MERGE_MAX / 4096) - -#define RDMA_REG_CHUNK_SHIFT 20 /* 1 MB */ - -/* - * This is only for non-live state being migrated. - * Instead of RDMA_WRITE messages, we use RDMA_SEND - * messages for that state, which requires a different - * delivery design than main memory. - */ -#define RDMA_SEND_INCREMENT 32768 - -/* - * Maximum size infiniband SEND message - */ -#define RDMA_CONTROL_MAX_BUFFER (512 * 1024) -#define RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE 4096 - -#define RDMA_CONTROL_VERSION_CURRENT 1 -/* - * Capabilities for negotiation. - */ -#define RDMA_CAPABILITY_PIN_ALL 0x01 - /* * Add the other flags above to this list of known capabilities * as they are introduced. @@ -117,18 +87,6 @@ static uint32_t known_capabilities =3D RDMA_CAPABILITY_= PIN_ALL; =20 #define RDMA_WRID_CHUNK_MASK (~RDMA_WRID_BLOCK_MASK & ~RDMA_WRID_TYPE_MASK) =20 -/* - * RDMA migration protocol: - * 1. RDMA Writes (data messages, i.e. RAM) - * 2. IB Send/Recv (control channel messages) - */ -enum { - RDMA_WRID_NONE =3D 0, - RDMA_WRID_RDMA_WRITE =3D 1, - RDMA_WRID_SEND_CONTROL =3D 2000, - RDMA_WRID_RECV_CONTROL =3D 4000, -}; - static const char *wrid_desc[] =3D { [RDMA_WRID_NONE] =3D "NONE", [RDMA_WRID_RDMA_WRITE] =3D "WRITE RDMA", @@ -136,50 +94,6 @@ static const char *wrid_desc[] =3D { [RDMA_WRID_RECV_CONTROL] =3D "CONTROL RECV", }; =20 -/* - * Work request IDs for IB SEND messages only (not RDMA writes). - * This is used by the migration protocol to transmit - * control messages (such as device state and registration commands) - * - * We could use more WRs, but we have enough for now. - */ -enum { - RDMA_WRID_READY =3D 0, - RDMA_WRID_DATA, - RDMA_WRID_CONTROL, - RDMA_WRID_MAX, -}; - -/* - * SEND/RECV IB Control Messages. - */ -enum { - RDMA_CONTROL_NONE =3D 0, - RDMA_CONTROL_ERROR, - RDMA_CONTROL_READY, /* ready to receive */ - RDMA_CONTROL_QEMU_FILE, /* QEMUFile-transmitted bytes */ - RDMA_CONTROL_RAM_BLOCKS_REQUEST, /* RAMBlock synchronization */ - RDMA_CONTROL_RAM_BLOCKS_RESULT, /* RAMBlock synchronization */ - RDMA_CONTROL_COMPRESS, /* page contains repeat values */ - RDMA_CONTROL_REGISTER_REQUEST, /* dynamic page registration */ - RDMA_CONTROL_REGISTER_RESULT, /* key to use after registration */ - RDMA_CONTROL_REGISTER_FINISHED, /* current iteration finished */ - RDMA_CONTROL_UNREGISTER_REQUEST, /* dynamic UN-registration */ - RDMA_CONTROL_UNREGISTER_FINISHED, /* unpinning finished */ -}; - - -/* - * Memory and MR structures used to represent an IB Send/Recv work request. - * This is *not* used for RDMA writes, only IB Send/Recv. - */ -typedef struct { - uint8_t control[RDMA_CONTROL_MAX_BUFFER]; /* actual buffer to registe= r */ - struct ibv_mr *control_mr; /* registration metadata */ - size_t control_len; /* length of the message */ - uint8_t *control_curr; /* start of unconsumed byte= s */ -} RDMAWorkRequestData; - /* * Negotiate RDMA capabilities during connection-setup time. */ @@ -200,46 +114,6 @@ static void network_to_caps(RDMACapabilities *cap) cap->flags =3D ntohl(cap->flags); } =20 -/* - * Representation of a RAMBlock from an RDMA perspective. - * This is not transmitted, only local. - * This and subsequent structures cannot be linked lists - * because we're using a single IB message to transmit - * the information. It's small anyway, so a list is overkill. - */ -typedef struct RDMALocalBlock { - char *block_name; - uint8_t *local_host_addr; /* local virtual address */ - uint64_t remote_host_addr; /* remote virtual address */ - uint64_t offset; - uint64_t length; - struct ibv_mr **pmr; /* MRs for chunk-level registration */ - struct ibv_mr *mr; /* MR for non-chunk-level registration= */ - uint32_t *remote_keys; /* rkeys for chunk-level registration = */ - uint32_t remote_rkey; /* rkeys for non-chunk-level registrat= ion */ - int index; /* which block are we */ - unsigned int src_index; /* (Only used on dest) */ - bool is_ram_block; - int nb_chunks; - unsigned long *transit_bitmap; - unsigned long *unregister_bitmap; -} RDMALocalBlock; - -/* - * Also represents a RAMblock, but only on the dest. - * This gets transmitted by the dest during connection-time - * to the source VM and then is used to populate the - * corresponding RDMALocalBlock with - * the information needed to perform the actual RDMA. - */ -typedef struct QEMU_PACKED RDMADestBlock { - uint64_t remote_host_addr; - uint64_t offset; - uint64_t length; - uint32_t remote_rkey; - uint32_t padding; -} RDMADestBlock; - static const char *control_desc(unsigned int rdma_control) { static const char *strs[] =3D { @@ -294,123 +168,6 @@ static void network_to_dest_block(RDMADestBlock *db) db->remote_rkey =3D ntohl(db->remote_rkey); } =20 -/* - * Virtual address of the above structures used for transmitting - * the RAMBlock descriptions at connection-time. - * This structure is *not* transmitted. - */ -typedef struct RDMALocalBlocks { - int nb_blocks; - bool init; /* main memory init complete */ - RDMALocalBlock *block; -} RDMALocalBlocks; - -/* - * Main data structure for RDMA state. - * While there is only one copy of this structure being allocated right no= w, - * this is the place where one would start if you wanted to consider - * having more than one RDMA connection open at the same time. - */ -typedef struct RDMAContext { - char *host; - int port; - - RDMAWorkRequestData wr_data[RDMA_WRID_MAX]; - - /* - * This is used by *_exchange_send() to figure out whether or not - * the initial "READY" message has already been received or not. - * This is because other functions may potentially poll() and detect - * the READY message before send() does, in which case we need to - * know if it completed. - */ - int control_ready_expected; - - /* number of outstanding writes */ - int nb_sent; - - /* store info about current buffer so that we can - merge it with future sends */ - uint64_t current_addr; - uint64_t current_length; - /* index of ram block the current buffer belongs to */ - int current_index; - /* index of the chunk in the current ram block */ - int current_chunk; - - bool pin_all; - - /* - * infiniband-specific variables for opening the device - * and maintaining connection state and so forth. - * - * cm_id also has ibv_context, rdma_event_channel, and ibv_qp in - * cm_id->verbs, cm_id->channel, and cm_id->qp. - */ - struct rdma_cm_id *cm_id; /* connection manager ID */ - struct rdma_cm_id *listen_id; - bool connected; - - struct ibv_context *verbs; - struct rdma_event_channel *channel; - struct ibv_qp *qp; /* queue pair */ - struct ibv_comp_channel *comp_channel; /* completion channel */ - struct ibv_pd *pd; /* protection domain */ - struct ibv_cq *cq; /* completion queue */ - - /* - * If a previous write failed (perhaps because of a failed - * memory registration, then do not attempt any future work - * and remember the error state. - */ - int error_state; - int error_reported; - int received_error; - - /* - * Description of ram blocks used throughout the code. - */ - RDMALocalBlocks local_ram_blocks; - RDMADestBlock *dest_blocks; - - /* Index of the next RAMBlock received during block registration */ - unsigned int next_src_index; - - /* - * Migration on *destination* started. - * Then use coroutine yield function. - * Source runs in a thread, so we don't care. - */ - int migration_started_on_destination; - - int total_registrations; - int total_writes; - - int unregister_current, unregister_next; - uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX]; - - GHashTable *blockmap; - - /* the RDMAContext for return path */ - struct RDMAContext *return_path; - bool is_return_path; -} RDMAContext; - -#define TYPE_QIO_CHANNEL_RDMA "qio-channel-rdma" -#define QIO_CHANNEL_RDMA(obj) \ - OBJECT_CHECK(QIOChannelRDMA, (obj), TYPE_QIO_CHANNEL_RDMA) - -typedef struct QIOChannelRDMA QIOChannelRDMA; - - -struct QIOChannelRDMA { - QIOChannel parent; - RDMAContext *rdmain; - RDMAContext *rdmaout; - QEMUFile *file; - bool blocking; /* XXX we don't actually honour this yet */ -}; - /* * Main structure for IB Send/Recv control messages. * This gets prepended at the beginning of every Send/Recv. diff --git a/migration/rdma.h b/migration/rdma.h index 3a00573083..cb206c7004 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -17,6 +17,253 @@ #ifndef QEMU_MIGRATION_RDMA_H #define QEMU_MIGRATION_RDMA_H =20 +#include "qemu-file.h" +#include "qemu-file-channel.h" + +#define RDMA_RESOLVE_TIMEOUT_MS 10000 + +/* Do not merge data if larger than this. */ +#define RDMA_MERGE_MAX (2 * 1024 * 1024) +#define RDMA_SIGNALED_SEND_MAX (RDMA_MERGE_MAX / 4096) + +#define RDMA_REG_CHUNK_SHIFT 20 /* 1 MB */ + +/* + * This is only for non-live state being migrated. + * Instead of RDMA_WRITE messages, we use RDMA_SEND + * messages for that state, which requires a different + * delivery design than main memory. + */ +#define RDMA_SEND_INCREMENT 32768 + +/* + * Maximum size infiniband SEND message + */ +#define RDMA_CONTROL_MAX_BUFFER (512 * 1024) +#define RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE 4096 + +#define RDMA_CONTROL_VERSION_CURRENT 1 +/* + * Capabilities for negotiation. + */ +#define RDMA_CAPABILITY_PIN_ALL 0x01 + +/* + * RDMA migration protocol: + * 1. RDMA Writes (data messages, i.e. RAM) + * 2. IB Send/Recv (control channel messages) + */ +enum { + RDMA_WRID_NONE =3D 0, + RDMA_WRID_RDMA_WRITE =3D 1, + RDMA_WRID_SEND_CONTROL =3D 2000, + RDMA_WRID_RECV_CONTROL =3D 4000, +}; + +/* + * Work request IDs for IB SEND messages only (not RDMA writes). + * This is used by the migration protocol to transmit + * control messages (such as device state and registration commands) + * + * We could use more WRs, but we have enough for now. + */ +enum { + RDMA_WRID_READY =3D 0, + RDMA_WRID_DATA, + RDMA_WRID_CONTROL, + RDMA_WRID_MAX, +}; + +/* + * SEND/RECV IB Control Messages. + */ +enum { + RDMA_CONTROL_NONE =3D 0, + RDMA_CONTROL_ERROR, + RDMA_CONTROL_READY, /* ready to receive */ + RDMA_CONTROL_QEMU_FILE, /* QEMUFile-transmitted bytes */ + RDMA_CONTROL_RAM_BLOCKS_REQUEST, /* RAMBlock synchronization */ + RDMA_CONTROL_RAM_BLOCKS_RESULT, /* RAMBlock synchronization */ + RDMA_CONTROL_COMPRESS, /* page contains repeat values */ + RDMA_CONTROL_REGISTER_REQUEST, /* dynamic page registration */ + RDMA_CONTROL_REGISTER_RESULT, /* key to use after registration */ + RDMA_CONTROL_REGISTER_FINISHED, /* current iteration finished */ + RDMA_CONTROL_UNREGISTER_REQUEST, /* dynamic UN-registration */ + RDMA_CONTROL_UNREGISTER_FINISHED, /* unpinning finished */ +}; + + +/* + * Memory and MR structures used to represent an IB Send/Recv work request. + * This is *not* used for RDMA writes, only IB Send/Recv. + */ +typedef struct { + uint8_t control[RDMA_CONTROL_MAX_BUFFER]; /* actual buffer to registe= r */ + struct ibv_mr *control_mr; /* registration metadata */ + size_t control_len; /* length of the message */ + uint8_t *control_curr; /* start of unconsumed byte= s */ +} RDMAWorkRequestData; + +/* + * Representation of a RAMBlock from an RDMA perspective. + * This is not transmitted, only local. + * This and subsequent structures cannot be linked lists + * because we're using a single IB message to transmit + * the information. It's small anyway, so a list is overkill. + */ +typedef struct RDMALocalBlock { + char *block_name; + uint8_t *local_host_addr; /* local virtual address */ + uint64_t remote_host_addr; /* remote virtual address */ + uint64_t offset; + uint64_t length; + struct ibv_mr **pmr; /* MRs for chunk-level registration */ + struct ibv_mr *mr; /* MR for non-chunk-level registration= */ + uint32_t *remote_keys; /* rkeys for chunk-level registration = */ + uint32_t remote_rkey; /* rkeys for non-chunk-level registrat= ion */ + int index; /* which block are we */ + unsigned int src_index; /* (Only used on dest) */ + bool is_ram_block; + int nb_chunks; + unsigned long *transit_bitmap; + unsigned long *unregister_bitmap; +} RDMALocalBlock; + +/* + * Also represents a RAMblock, but only on the dest. + * This gets transmitted by the dest during connection-time + * to the source VM and then is used to populate the + * corresponding RDMALocalBlock with + * the information needed to perform the actual RDMA. + */ +typedef struct QEMU_PACKED RDMADestBlock { + uint64_t remote_host_addr; + uint64_t offset; + uint64_t length; + uint32_t remote_rkey; + uint32_t padding; +} RDMADestBlock; + +/* + * Virtual address of the above structures used for transmitting + * the RAMBlock descriptions at connection-time. + * This structure is *not* transmitted. + */ +typedef struct RDMALocalBlocks { + int nb_blocks; + bool init; /* main memory init complete */ + RDMALocalBlock *block; +} RDMALocalBlocks; + +/* + * Main data structure for RDMA state. + * While there is only one copy of this structure being allocated right no= w, + * this is the place where one would start if you wanted to consider + * having more than one RDMA connection open at the same time. + */ +typedef struct RDMAContext { + char *host; + int port; + + RDMAWorkRequestData wr_data[RDMA_WRID_MAX]; + + /* + * This is used by *_exchange_send() to figure out whether or not + * the initial "READY" message has already been received or not. + * This is because other functions may potentially poll() and detect + * the READY message before send() does, in which case we need to + * know if it completed. + */ + int control_ready_expected; + + /* number of outstanding writes */ + int nb_sent; + + /* + * store info about current buffer so that we can + * merge it with future sends + */ + uint64_t current_addr; + uint64_t current_length; + /* index of ram block the current buffer belongs to */ + int current_index; + /* index of the chunk in the current ram block */ + int current_chunk; + + bool pin_all; + + /* + * infiniband-specific variables for opening the device + * and maintaining connection state and so forth. + * + * cm_id also has ibv_context, rdma_event_channel, and ibv_qp in + * cm_id->verbs, cm_id->channel, and cm_id->qp. + */ + struct rdma_cm_id *cm_id; /* connection manager ID */ + struct rdma_cm_id *listen_id; + bool connected; + + struct ibv_context *verbs; + struct rdma_event_channel *channel; + struct ibv_qp *qp; /* queue pair */ + struct ibv_comp_channel *comp_channel; /* completion channel */ + struct ibv_pd *pd; /* protection domain */ + struct ibv_cq *cq; /* completion queue */ + + /* + * If a previous write failed (perhaps because of a failed + * memory registration, then do not attempt any future work + * and remember the error state. + */ + int error_state; + int error_reported; + int received_error; + + /* + * Description of ram blocks used throughout the code. + */ + RDMALocalBlocks local_ram_blocks; + RDMADestBlock *dest_blocks; + + /* Index of the next RAMBlock received during block registration */ + unsigned int next_src_index; + + /* + * Migration on *destination* started. + * Then use coroutine yield function. + * Source runs in a thread, so we don't care. + */ + int migration_started_on_destination; + + int total_registrations; + int total_writes; + + int unregister_current, unregister_next; + uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX]; + + GHashTable *blockmap; + + /* the RDMAContext for return path */ + struct RDMAContext *return_path; + bool is_return_path; +} RDMAContext; + +#define TYPE_QIO_CHANNEL_RDMA "qio-channel-rdma" +#define QIO_CHANNEL_RDMA(obj) \ + OBJECT_CHECK(QIOChannelRDMA, (obj), TYPE_QIO_CHANNEL_RDMA) + +typedef struct QIOChannelRDMA QIOChannelRDMA; + + +struct QIOChannelRDMA { + QIOChannel parent; + RDMAContext *rdmain; + RDMAContext *rdmaout; + QEMUFile *file; + bool blocking; /* XXX we don't actually honour this yet */ +}; + + void *multifd_rdma_recv_thread(void *opaque); void *multifd_rdma_send_thread(void *opaque); =20 --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587361111364.79403008410804; Thu, 13 Feb 2020 01:49:21 -0800 (PST) Received: from localhost ([::1]:49760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B7X-0005N2-R5 for importer@patchew.org; Thu, 13 Feb 2020 04:49:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45989) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax2-0006iv-VY for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-00053p-Qh for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2776 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Ax0-000514-8J for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C444E3313507A1336E19; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:10 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 05/14] migration/rdma: Create the multifd channels for RDMA Date: Thu, 13 Feb 2020 17:37:46 +0800 Message-ID: <20200213093755.370-6-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In both sides. We still don't transmit anything through them, and we only build the RDMA connections. Signed-off-by: Zhimin Feng --- migration/multifd.c | 103 ++++++++++++++++++++++++++++++++++++--- migration/multifd.h | 10 ++++ migration/rdma.c | 115 ++++++++++++++++++++++++++++++++------------ migration/rdma.h | 4 +- 4 files changed, 189 insertions(+), 43 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 63678d7fdd..acdfd3d5b3 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -248,6 +248,19 @@ struct { int exiting; } *multifd_send_state; =20 +int get_multifd_send_param(int id, MultiFDSendParams **param) +{ + int ret =3D 0; + + if (id < 0 || id >=3D migrate_multifd_channels()) { + ret =3D -1; + } else { + *param =3D &(multifd_send_state->params[id]); + } + + return ret; +} + /* * How we use multifd_send_state->pages and channel->pages? * @@ -410,6 +423,9 @@ void multifd_save_cleanup(void) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + if (migrate_use_rdma()) { + g_free(p->rdma); + } } qemu_sem_destroy(&multifd_send_state->channels_ready); g_free(multifd_send_state->params); @@ -464,6 +480,27 @@ void multifd_send_sync_main(QEMUFile *f) trace_multifd_send_sync_main(multifd_send_state->packet_num); } =20 +static void *multifd_rdma_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); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + return NULL; +} + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; @@ -566,6 +603,12 @@ static void rdma_send_channel_create(MultiFDSendParams= *p) { Error *local_err =3D NULL; =20 + if (multifd_channel_rdma_connect(p)) { + error_setg(&local_err, "multifd: rdma channel %d not established", + p->id); + return ; + } + if (p->quit) { error_setg(&local_err, "multifd: send id %d already quit", p->id); return ; @@ -654,6 +697,19 @@ struct { uint64_t packet_num; } *multifd_recv_state; =20 +int get_multifd_recv_param(int id, MultiFDRecvParams **param) +{ + int ret =3D 0; + + if (id < 0 || id >=3D migrate_multifd_channels()) { + ret =3D -1; + } else { + *param =3D &(multifd_recv_state->params[id]); + } + + return ret; +} + static void multifd_recv_terminate_threads(Error *err) { int i; @@ -724,6 +780,9 @@ int multifd_load_cleanup(Error **errp) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + if (migrate_use_rdma()) { + g_free(p->rdma); + } } qemu_sem_destroy(&multifd_recv_state->sem_sync); g_free(multifd_recv_state->params); @@ -761,6 +820,27 @@ void multifd_recv_sync_main(void) trace_multifd_recv_sync_main(multifd_recv_state->packet_num); } =20 +static void *multifd_rdma_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_sync); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + return NULL; +} + static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; @@ -880,18 +960,24 @@ bool multifd_recv_all_channels_created(void) bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { MultiFDRecvParams *p; + QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); Error *local_err =3D NULL; int id; =20 - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - atomic_read(&multifd_recv_state->count)); - return false; + if (migrate_use_rdma()) { + id =3D multifd_recv_state->count; + } else { + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + atomic_read(&multifd_recv_state->count)); + return false; + } } + trace_multifd_recv_new_channel(id); =20 p =3D &multifd_recv_state->params[id]; @@ -903,6 +989,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error **= errp) return false; } p->c =3D ioc; + p->file =3D rioc->file; object_ref(OBJECT(ioc)); /* initial packet */ p->num_packets =3D 1; diff --git a/migration/multifd.h b/migration/multifd.h index c9c11ad140..1eae427f8c 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -67,6 +67,10 @@ typedef struct { char *name; /* channel thread id */ QemuThread thread; + /* RDMAContext channel */ + RDMAContext *rdma; + /* communication channel */ + QEMUFile *file; /* communication channel */ QIOChannel *c; /* sem where to wait for more work */ @@ -108,6 +112,10 @@ typedef struct { char *name; /* channel thread id */ QemuThread thread; + /* RDMAContext channel */ + RDMAContext *rdma; + /* communication channel */ + QEMUFile *file; /* communication channel */ QIOChannel *c; /* this mutex protects the following parameters */ @@ -137,5 +145,7 @@ typedef struct { QemuSemaphore sem_sync; } MultiFDRecvParams; =20 +int get_multifd_send_param(int id, MultiFDSendParams **param); +int get_multifd_recv_param(int id, MultiFDRecvParams **param); #endif =20 diff --git a/migration/rdma.c b/migration/rdma.c index a76823986e..48615fcaad 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -94,6 +94,8 @@ static const char *wrid_desc[] =3D { [RDMA_WRID_RECV_CONTROL] =3D "CONTROL RECV", }; =20 +static const char *rdma_host_port; + /* * Negotiate RDMA capabilities during connection-setup time. */ @@ -3122,6 +3124,33 @@ static int qemu_rdma_accept(RDMAContext *rdma) qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migrat= ion, NULL, (void *)(intptr_t)rdma->return_path); + } else if (migrate_use_multifd()) { + int thread_count; + int i; + MultiFDRecvParams *multifd_recv_param; + RDMAContext *multifd_rdma =3D NULL; + thread_count =3D migrate_multifd_channels(); + /* create the multifd channels for RDMA */ + for (i =3D 0; i < thread_count; i++) { + if (get_multifd_recv_param(i, &multifd_recv_param) < 0) { + error_report("rdma: error getting multifd_recv_param(%d)",= i); + goto err_rdma_dest_wait; + } + + if (multifd_recv_param->rdma->cm_id =3D=3D NULL) { + multifd_rdma =3D multifd_recv_param->rdma; + break; + } + } + + if (multifd_rdma) { + qemu_set_fd_handler(rdma->channel->fd, + rdma_accept_incoming_migration, + NULL, (void *)(intptr_t)multifd_rdma); + } else { + qemu_set_fd_handler(rdma->channel->fd, rdma_cm_poll_handler, + NULL, rdma); + } } else { qemu_set_fd_handler(rdma->channel->fd, rdma_cm_poll_handler, NULL, rdma); @@ -3744,7 +3773,7 @@ static void migration_rdma_process_incoming(QEMUFile = *f, Error **errp) mis->from_src_file =3D f; qemu_file_set_blocking(f, false); =20 - start_migration =3D migrate_use_multifd(); + start_migration =3D !migrate_use_multifd(); } else { ioc =3D QIO_CHANNEL(getQIOChannel(f)); /* Multiple connections */ @@ -3847,6 +3876,30 @@ void rdma_start_incoming_migration(const char *host_= port, Error **errp) goto err; } =20 + if (migrate_use_multifd()) { + int thread_count; + int i; + int idx; + MultiFDRecvParams *multifd_recv_param; + thread_count =3D migrate_multifd_channels(); + for (i =3D 0; i < thread_count; i++) { + if (get_multifd_recv_param(i, &multifd_recv_param) < 0) { + error_report("rdma: error getting multifd_recv_param(%d)",= i); + goto err; + } + + multifd_recv_param->rdma =3D qemu_rdma_data_init(host_port, + &local_err); + for (idx =3D 0; idx < RDMA_WRID_MAX; idx++) { + multifd_recv_param->rdma->wr_data[idx].control_len =3D 0; + multifd_recv_param->rdma->wr_data[idx].control_curr =3D NU= LL; + } + /* the CM channel and CM id is shared */ + multifd_recv_param->rdma->channel =3D rdma->channel; + multifd_recv_param->rdma->listen_id =3D rdma->listen_id; + } + } + qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration, NULL, (void *)(intptr_t)rdma); return; @@ -3868,6 +3921,10 @@ void rdma_start_outgoing_migration(void *opaque, goto err; } =20 + if (migrate_use_multifd()) { + rdma_host_port =3D g_strdup(host_port); + } + ret =3D qemu_rdma_source_init(rdma, s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL], errp); =20 @@ -3918,44 +3975,38 @@ err: g_free(rdma_return_path); } =20 -void *multifd_rdma_recv_thread(void *opaque) +int multifd_channel_rdma_connect(void *opaque) { - MultiFDRecvParams *p =3D opaque; + MultiFDSendParams *p =3D opaque; + Error *local_err =3D NULL; + int ret =3D 0; =20 - 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_sync); + p->rdma =3D qemu_rdma_data_init(rdma_host_port, &local_err); + if (p->rdma =3D=3D NULL) { + goto out; } =20 - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - return NULL; -} + ret =3D qemu_rdma_source_init(p->rdma, + migrate_use_rdma_pin_all(), + &local_err); + if (ret) { + goto out; + } =20 -void *multifd_rdma_send_thread(void *opaque) -{ - MultiFDSendParams *p =3D opaque; + ret =3D qemu_rdma_connect(p->rdma, &local_err); + if (ret) { + goto out; + } =20 - 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); + p->file =3D qemu_fopen_rdma(p->rdma, "wb"); + if (p->file =3D=3D NULL) { + goto out; } =20 - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); +out: + if (local_err) { + trace_multifd_send_error(p->id); + } =20 - return NULL; + return ret; } diff --git a/migration/rdma.h b/migration/rdma.h index cb206c7004..ace6e5be90 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -263,9 +263,7 @@ struct QIOChannelRDMA { bool blocking; /* XXX we don't actually honour this yet */ }; =20 - -void *multifd_rdma_recv_thread(void *opaque); -void *multifd_rdma_send_thread(void *opaque); +int multifd_channel_rdma_connect(void *opaque); =20 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587304127915.1786015254397; Thu, 13 Feb 2020 01:48:24 -0800 (PST) Received: from localhost ([::1]:49748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B6c-0003zk-Uj for importer@patchew.org; Thu, 13 Feb 2020 04:48:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45957) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax1-0006hY-9m for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-000533-AY for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:27 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2774 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awz-00050h-RT for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BABCCDE1D4F06A777EA2; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:11 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 06/14] migration/rdma: Transmit initial packet Date: Thu, 13 Feb 2020 17:37:47 +0800 Message-ID: <20200213093755.370-7-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Transmit initial packet through the multifd RDMA channels, so that we can identify the multifd channels. Signed-off-by: Zhimin Feng --- migration/multifd.c | 33 +++++++++++++++++++++------------ migration/rdma.c | 2 ++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index acdfd3d5b3..a57d7a2eab 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -483,6 +483,13 @@ void multifd_send_sync_main(QEMUFile *f) static void *multifd_rdma_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; + Error *local_err =3D NULL; + + trace_multifd_send_thread_start(p->id); + + if (multifd_send_initial_packet(p, &local_err) < 0) { + goto out; + } =20 while (true) { qemu_mutex_lock(&p->mutex); @@ -494,6 +501,12 @@ static void *multifd_rdma_send_thread(void *opaque) qemu_sem_wait(&p->sem); } =20 +out: + if (local_err) { + trace_multifd_send_error(p->id); + multifd_send_terminate_threads(local_err); + } + qemu_mutex_lock(&p->mutex); p->running =3D false; qemu_mutex_unlock(&p->mutex); @@ -964,18 +977,14 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) Error *local_err =3D NULL; int id; =20 - if (migrate_use_rdma()) { - id =3D multifd_recv_state->count; - } else { - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - atomic_read(&multifd_recv_state->count)); - return false; - } + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + atomic_read(&multifd_recv_state->count)); + return false; } =20 trace_multifd_recv_new_channel(id); diff --git a/migration/rdma.c b/migration/rdma.c index 48615fcaad..2f1e69197f 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -4003,6 +4003,8 @@ int multifd_channel_rdma_connect(void *opaque) goto out; } =20 + p->c =3D QIO_CHANNEL(getQIOChannel(p->file)); + out: if (local_err) { trace_multifd_send_error(p->id); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581586779709705.3472100005725; Thu, 13 Feb 2020 01:39:39 -0800 (PST) Received: from localhost ([::1]:49492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AyA-0008RB-6k for importer@patchew.org; Thu, 13 Feb 2020 04:39:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax1-0006i1-QX for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-00053V-JR for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:27 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2775 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Ax0-000518-8t for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BF46E89C10EBFCAF3469; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:12 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 07/14] migration/rdma: Export the 'qemu_rdma_registration_handle' and 'qemu_rdma_exchange_send' functions Date: Thu, 13 Feb 2020 17:37:48 +0800 Message-ID: <20200213093755.370-8-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/rdma.c | 25 +++++-------------------- migration/rdma.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 2f1e69197f..23f7f525f4 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -170,17 +170,6 @@ static void network_to_dest_block(RDMADestBlock *db) db->remote_rkey =3D ntohl(db->remote_rkey); } =20 -/* - * Main structure for IB Send/Recv control messages. - * This gets prepended at the beginning of every Send/Recv. - */ -typedef struct QEMU_PACKED { - uint32_t len; /* Total length of data portion */ - uint32_t type; /* which control command to perform */ - uint32_t repeat; /* number of commands in data portion of same type */ - uint32_t padding; -} RDMAControlHeader; - static void control_to_network(RDMAControlHeader *control) { control->type =3D htonl(control->type); @@ -289,10 +278,6 @@ static void network_to_result(RDMARegisterResult *resu= lt) }; =20 const char *print_wrid(int wrid); -static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *h= ead, - uint8_t *data, RDMAControlHeader *resp, - int *resp_idx, - int (*callback)(RDMAContext *rdma)); =20 static inline uint64_t ram_chunk_index(const uint8_t *start, const uint8_t *host) @@ -1590,10 +1575,10 @@ static void qemu_rdma_move_header(RDMAContext *rdma= , int idx, * to perform an *additional* exchange of message just to provide a respon= se by * instead piggy-backing on the acknowledgement. */ -static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *h= ead, - uint8_t *data, RDMAControlHeader *resp, - int *resp_idx, - int (*callback)(RDMAContext *rdma)) +int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head, + uint8_t *data, RDMAControlHeader *resp, + int *resp_idx, + int (*callback)(RDMAContext *rdma)) { int ret =3D 0; =20 @@ -3210,7 +3195,7 @@ static int dest_ram_sort_func(const void *a, const vo= id *b) * * Keep doing this until the source tells us to stop. */ -static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) +int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) { RDMAControlHeader reg_resp =3D { .len =3D sizeof(RDMARegisterResult), .type =3D RDMA_CONTROL_REGISTER_RESULT, diff --git a/migration/rdma.h b/migration/rdma.h index ace6e5be90..8e1a6edf57 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -144,6 +144,17 @@ typedef struct QEMU_PACKED RDMADestBlock { uint32_t padding; } RDMADestBlock; =20 +/* + * Main structure for IB Send/Recv control messages. + * This gets prepended at the beginning of every Send/Recv. + */ +typedef struct QEMU_PACKED { + uint32_t len; /* Total length of data portion */ + uint32_t type; /* which control command to perform */ + uint32_t repeat; /* number of commands in data portion of same type */ + uint32_t padding; +} RDMAControlHeader; + /* * Virtual address of the above structures used for transmitting * the RAMBlock descriptions at connection-time. @@ -264,6 +275,11 @@ struct QIOChannelRDMA { }; =20 int multifd_channel_rdma_connect(void *opaque); +int qemu_rdma_registration_handle(QEMUFile *f, void *opaque); +int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head, + uint8_t *data, RDMAControlHeader *resp, + int *resp_idx, + int (*callback)(RDMAContext *rdma)); =20 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581586915472836.4659768854042; Thu, 13 Feb 2020 01:41:55 -0800 (PST) Received: from localhost ([::1]:49532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B0M-0004Wh-88 for importer@patchew.org; Thu, 13 Feb 2020 04:41:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46027) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AxB-0006zY-WD for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2AxA-0005Dj-Tm for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:37 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2777 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2AxA-00051U-I6 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:36 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CD6209BCF9EC61BBFD07; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:12 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 08/14] migration/rdma: Add the function for dynamic page registration Date: Thu, 13 Feb 2020 17:37:49 +0800 Message-ID: <20200213093755.370-9-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add the 'qemu_rdma_registration' function, multifd send threads call it to register memory. Signed-off-by: Zhimin Feng --- migration/rdma.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ migration/rdma.h | 1 + 2 files changed, 52 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index 23f7f525f4..19a238be30 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3471,6 +3471,57 @@ out: return ret; } =20 +/* + * Dynamic page registrations for multifd RDMA threads. + */ +int qemu_rdma_registration(void *opaque) +{ + RDMAContext *rdma =3D opaque; + RDMAControlHeader resp =3D {.type =3D RDMA_CONTROL_RAM_BLOCKS_RESULT }; + RDMALocalBlocks *local =3D &rdma->local_ram_blocks; + int reg_result_idx, i, nb_dest_blocks; + RDMAControlHeader head =3D { .len =3D 0, .repeat =3D 1 }; + int ret =3D 0; + + head.type =3D RDMA_CONTROL_RAM_BLOCKS_REQUEST; + + ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, &resp, + ®_result_idx, rdma->pin_all ? + qemu_rdma_reg_whole_ram_blocks : NULL); + if (ret < 0) { + goto out; + } + + nb_dest_blocks =3D resp.len / sizeof(RDMADestBlock); + + if (local->nb_blocks !=3D nb_dest_blocks) { + rdma->error_state =3D -EINVAL; + ret =3D -1; + goto out; + } + + qemu_rdma_move_header(rdma, reg_result_idx, &resp); + memcpy(rdma->dest_blocks, + rdma->wr_data[reg_result_idx].control_curr, resp.len); + + for (i =3D 0; i < nb_dest_blocks; i++) { + network_to_dest_block(&rdma->dest_blocks[i]); + + /* We require that the blocks are in the same order */ + if (rdma->dest_blocks[i].length !=3D local->block[i].length) { + rdma->error_state =3D -EINVAL; + ret =3D -1; + goto out; + } + local->block[i].remote_host_addr =3D + rdma->dest_blocks[i].remote_host_addr; + local->block[i].remote_rkey =3D rdma->dest_blocks[i].remote_rkey; + } + +out: + return ret; +} + /* Destination: * Called via a ram_control_load_hook during the initial RAM load section = which * lists the RAMBlocks by name. This lets us know the order of the RAMBlo= cks diff --git a/migration/rdma.h b/migration/rdma.h index 8e1a6edf57..86c89bdd1f 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -280,6 +280,7 @@ int qemu_rdma_exchange_send(RDMAContext *rdma, RDMACont= rolHeader *head, uint8_t *data, RDMAControlHeader *resp, int *resp_idx, int (*callback)(RDMAContext *rdma)); +int qemu_rdma_registration(void *opaque); =20 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587007788800.9401792134896; Thu, 13 Feb 2020 01:43:27 -0800 (PST) Received: from localhost ([::1]:49566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B1q-00078M-IQ for importer@patchew.org; Thu, 13 Feb 2020 04:43:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46031) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AxC-0006zl-2a for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2AxA-0005DP-QN for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:38 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2778 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2AxA-00051S-FU for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:36 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D2A28455B78695011160; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:13 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 09/14] migration/rdma: register memory for multifd RDMA channels Date: Thu, 13 Feb 2020 17:37:50 +0800 Message-ID: <20200213093755.370-10-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" register memory for multifd RDMA channels and transmit the destination the keys to source to use including the virtual addresses. Signed-off-by: Zhimin Feng --- migration/multifd.c | 34 +++++++++++++++++++++++++++++--- migration/rdma.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index a57d7a2eab..4ae25fc88f 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -388,7 +388,11 @@ static void multifd_send_terminate_threads(Error *err) =20 qemu_mutex_lock(&p->mutex); p->quit =3D true; - qemu_sem_post(&p->sem); + if (migrate_use_rdma()) { + qemu_sem_post(&p->sem_sync); + } else { + qemu_sem_post(&p->sem); + } qemu_mutex_unlock(&p->mutex); } } @@ -484,6 +488,8 @@ static void *multifd_rdma_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; + int ret =3D 0; + RDMAControlHeader head =3D { .len =3D 0, .repeat =3D 1 }; =20 trace_multifd_send_thread_start(p->id); =20 @@ -491,14 +497,28 @@ static void *multifd_rdma_send_thread(void *opaque) goto out; } =20 + /* wait for semaphore notification to register memory */ + qemu_sem_wait(&p->sem_sync); + if (qemu_rdma_registration(p->rdma) < 0) { + goto out; + } + while (true) { + qemu_sem_wait(&p->sem_sync); + qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); - qemu_sem_wait(&p->sem); + + /* Send FINISHED to the destination */ + head.type =3D RDMA_CONTROL_REGISTER_FINISHED; + ret =3D qemu_rdma_exchange_send(p->rdma, &head, NULL, NULL, NULL, = NULL); + if (ret < 0) { + return NULL; + } } =20 out: @@ -836,15 +856,23 @@ void multifd_recv_sync_main(void) static void *multifd_rdma_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; + int ret =3D 0; =20 while (true) { + qemu_sem_wait(&p->sem_sync); + qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); - qemu_sem_wait(&p->sem_sync); + + ret =3D qemu_rdma_registration_handle(p->file, p->c); + if (ret < 0) { + qemu_file_set_error(p->file, ret); + break; + } } =20 qemu_mutex_lock(&p->mutex); diff --git a/migration/rdma.c b/migration/rdma.c index 19a238be30..5de3a29712 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3570,6 +3570,19 @@ static int rdma_load_hook(QEMUFile *f, void *opaque,= uint64_t flags, void *data) return rdma_block_notification_handle(opaque, data); =20 case RAM_CONTROL_HOOK: + if (migrate_use_multifd()) { + int i; + MultiFDRecvParams *multifd_recv_param =3D NULL; + int thread_count =3D migrate_multifd_channels(); + /* Inform dest recv_thread to poll */ + for (i =3D 0; i < thread_count; i++) { + if (get_multifd_recv_param(i, &multifd_recv_param)) { + return -1; + } + qemu_sem_post(&multifd_recv_param->sem_sync); + } + } + return qemu_rdma_registration_handle(f, opaque); =20 default: @@ -3643,6 +3656,25 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, head.type =3D RDMA_CONTROL_RAM_BLOCKS_REQUEST; trace_qemu_rdma_registration_stop_ram(); =20 + if (migrate_use_multifd()) { + /* + * Inform the multifd channels to register memory + */ + int i; + int thread_count =3D migrate_multifd_channels(); + MultiFDSendParams *multifd_send_param =3D NULL; + for (i =3D 0; i < thread_count; i++) { + ret =3D get_multifd_send_param(i, &multifd_send_param); + if (ret) { + ERROR(errp, "rdma: error getting" + "multifd_send_param(%d)", i); + return ret; + } + + qemu_sem_post(&multifd_send_param->sem_sync); + } + } + /* * Make sure that we parallelize the pinning on both sides. * For very large guests, doing this serially takes a really @@ -3708,6 +3740,22 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, head.type =3D RDMA_CONTROL_REGISTER_FINISHED; ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL); =20 + if (migrate_use_multifd()) { + /* Inform src send_thread to send FINISHED signal */ + int i; + int thread_count =3D migrate_multifd_channels(); + MultiFDSendParams *multifd_send_param =3D NULL; + for (i =3D 0; i < thread_count; i++) { + ret =3D get_multifd_send_param(i, &multifd_send_param); + if (ret) { + ERROR(errp, "rdma: error getting multifd_send_param(%d)", = i); + return ret; + } + + qemu_sem_post(&multifd_send_param->sem_sync); + } + } + if (ret < 0) { goto err; } --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581586778374474.8711039367927; Thu, 13 Feb 2020 01:39:38 -0800 (PST) Received: from localhost ([::1]:49490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ay9-0008Or-0J for importer@patchew.org; Thu, 13 Feb 2020 04:39:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45953) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax1-0006hU-7x for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-00052w-9B for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:27 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2772 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awz-00050e-QQ for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AB4DFBC2EA1D7D187D71; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:13 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 10/14] migration/rdma: Wait for all multifd to complete registration Date: Thu, 13 Feb 2020 17:37:51 +0800 Message-ID: <20200213093755.370-11-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/multifd.c | 6 ++++++ migration/rdma.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/migration/multifd.c b/migration/multifd.c index 4ae25fc88f..c986d4c247 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -389,6 +389,7 @@ static void multifd_send_terminate_threads(Error *err) qemu_mutex_lock(&p->mutex); p->quit =3D true; if (migrate_use_rdma()) { + qemu_sem_post(&p->sem); qemu_sem_post(&p->sem_sync); } else { qemu_sem_post(&p->sem); @@ -502,6 +503,11 @@ static void *multifd_rdma_send_thread(void *opaque) if (qemu_rdma_registration(p->rdma) < 0) { goto out; } + /* + * Inform the main RDMA thread to run when multifd + * RDMA thread have completed registration. + */ + qemu_sem_post(&p->sem); =20 while (true) { qemu_sem_wait(&p->sem_sync); diff --git a/migration/rdma.c b/migration/rdma.c index 5de3a29712..4c48e9832c 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3733,6 +3733,23 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, rdma->dest_blocks[i].remote_host_addr; local->block[i].remote_rkey =3D rdma->dest_blocks[i].remote_rk= ey; } + + /* Wait for all multifd channels to complete registration */ + if (migrate_use_multifd()) { + int i; + int thread_count =3D migrate_multifd_channels(); + MultiFDSendParams *multifd_send_param =3D NULL; + for (i =3D 0; i < thread_count; i++) { + ret =3D get_multifd_send_param(i, &multifd_send_param); + if (ret) { + ERROR(errp, "rdma: error" + "getting multifd_send_param(%d)", i); + return ret; + } + + qemu_sem_wait(&multifd_send_param->sem); + } + } } =20 trace_qemu_rdma_registration_stop(flags); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587063646965.534045608757; Thu, 13 Feb 2020 01:44:23 -0800 (PST) Received: from localhost ([::1]:49602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B2k-00005k-CG for importer@patchew.org; Thu, 13 Feb 2020 04:44:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45917) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Awz-0006gt-N6 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Awy-00050l-BH for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:25 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2770 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awy-0004tq-09 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:24 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A5B0AE7CE3F2B8C58865; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:14 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 11/14] migration/rdma: use multifd to migrate VM for rdma-pin-all mode Date: Thu, 13 Feb 2020 17:37:52 +0800 Message-ID: <20200213093755.370-12-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/multifd.c | 15 ++++++++++++ migration/rdma.c | 58 +++++++++++++++++++++++++++++++++++++++++---- migration/rdma.h | 2 ++ 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index c986d4c247..ba5e0b11d0 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -519,12 +519,27 @@ static void *multifd_rdma_send_thread(void *opaque) } qemu_mutex_unlock(&p->mutex); =20 + /* To complete polling(CQE) */ + while (p->rdma->nb_sent) { + ret =3D qemu_rdma_block_for_wrid(p->rdma, RDMA_WRID_RDMA_WRITE= , NULL); + if (ret < 0) { + error_report("multifd RDMA migration: " + "complete polling error!"); + return NULL; + } + } + /* Send FINISHED to the destination */ head.type =3D RDMA_CONTROL_REGISTER_FINISHED; ret =3D qemu_rdma_exchange_send(p->rdma, &head, NULL, NULL, NULL, = NULL); if (ret < 0) { + error_report("multifd RDMA migration: " + "receiving remote info!"); return NULL; } + + /* sync main thread */ + qemu_sem_post(&p->sem); } =20 out: diff --git a/migration/rdma.c b/migration/rdma.c index 4c48e9832c..873c17dc03 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -96,6 +96,23 @@ static const char *wrid_desc[] =3D { =20 static const char *rdma_host_port; =20 +/* + * index of current RDMA channel for multifd + */ +static int current_RDMA_index; + +/* + * Get the multifd RDMA channel used to send data. + */ +static int get_multifd_RDMA_channel(void) +{ + int thread_count =3D migrate_multifd_channels(); + current_RDMA_index++; + current_RDMA_index %=3D thread_count; + + return current_RDMA_index; +} + /* * Negotiate RDMA capabilities during connection-setup time. */ @@ -1328,8 +1345,8 @@ static int qemu_rdma_wait_comp_channel(RDMAContext *r= dma) * completions only need to be recorded, but do not actually * need further processing. */ -static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested, - uint32_t *byte_len) +int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested, + uint32_t *byte_len) { int num_cq_events =3D 0, ret =3D 0; struct ibv_cq *cq; @@ -1731,6 +1748,20 @@ static int qemu_rdma_write_one(QEMUFile *f, RDMACont= ext *rdma, .repeat =3D 1, }; =20 + /* use multifd to send data */ + if (migrate_use_multifd() && migrate_use_rdma_pin_all()) { + int channel =3D get_multifd_RDMA_channel(); + int ret =3D 0; + MultiFDSendParams *multifd_send_param =3D NULL; + ret =3D get_multifd_send_param(channel, &multifd_send_param); + if (ret) { + error_report("rdma: error getting multifd_send_param(%d)", cha= nnel); + return -EINVAL; + } + rdma =3D multifd_send_param->rdma; + block =3D &(rdma->local_ram_blocks.block[current_index]); + } + retry: sge.addr =3D (uintptr_t)(block->local_host_addr + (current_addr - block->offset)); @@ -1948,8 +1979,21 @@ static int qemu_rdma_write_flush(QEMUFile *f, RDMACo= ntext *rdma) } =20 if (ret =3D=3D 0) { - rdma->nb_sent++; - trace_qemu_rdma_write_flush(rdma->nb_sent); + if (migrate_use_multifd() && migrate_use_rdma_pin_all()) { + /* The multifd RDMA threads send data */ + MultiFDSendParams *multifd_send_param =3D NULL; + ret =3D get_multifd_send_param(current_RDMA_index, + &multifd_send_param); + if (ret) { + error_report("rdma: error getting multifd_send_param(%d)", + current_RDMA_index); + return ret; + } + multifd_send_param->rdma->nb_sent++; + } else { + rdma->nb_sent++; + trace_qemu_rdma_write_flush(rdma->nb_sent); + } } =20 rdma->current_length =3D 0; @@ -3758,7 +3802,10 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL); =20 if (migrate_use_multifd()) { - /* Inform src send_thread to send FINISHED signal */ + /* + * Inform src send_thread to send FINISHED signal. + * Wait for multifd RDMA send threads to poll the CQE. + */ int i; int thread_count =3D migrate_multifd_channels(); MultiFDSendParams *multifd_send_param =3D NULL; @@ -3770,6 +3817,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, } =20 qemu_sem_post(&multifd_send_param->sem_sync); + qemu_sem_wait(&multifd_send_param->sem); } } =20 diff --git a/migration/rdma.h b/migration/rdma.h index 86c89bdd1f..7dc3895698 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -281,6 +281,8 @@ int qemu_rdma_exchange_send(RDMAContext *rdma, RDMACont= rolHeader *head, int *resp_idx, int (*callback)(RDMAContext *rdma)); int qemu_rdma_registration(void *opaque); +int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested, + uint32_t *byte_len); =20 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587165200213.6910764815608; Thu, 13 Feb 2020 01:46:05 -0800 (PST) Received: from localhost ([::1]:49724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B4N-00026G-3Q for importer@patchew.org; Thu, 13 Feb 2020 04:46:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45954) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Ax1-0006hV-7x for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Ax0-00052T-3m for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:27 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2773 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2Awz-00050b-PG for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:26 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B64E8B6B29421BA12035; Thu, 13 Feb 2020 17:38:20 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:14 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 12/14] migration/rdma: use multifd to migrate VM for NOT rdma-pin-all mode Date: Thu, 13 Feb 2020 17:37:53 +0800 Message-ID: <20200213093755.370-13-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 873c17dc03..eb7c2edbe7 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1749,7 +1749,7 @@ static int qemu_rdma_write_one(QEMUFile *f, RDMAConte= xt *rdma, }; =20 /* use multifd to send data */ - if (migrate_use_multifd() && migrate_use_rdma_pin_all()) { + if (migrate_use_multifd()) { int channel =3D get_multifd_RDMA_channel(); int ret =3D 0; MultiFDSendParams *multifd_send_param =3D NULL; @@ -1979,7 +1979,7 @@ static int qemu_rdma_write_flush(QEMUFile *f, RDMACon= text *rdma) } =20 if (ret =3D=3D 0) { - if (migrate_use_multifd() && migrate_use_rdma_pin_all()) { + if (migrate_use_multifd()) { /* The multifd RDMA threads send data */ MultiFDSendParams *multifd_send_param =3D NULL; ret =3D get_multifd_send_param(current_RDMA_index, --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587420806783.5132032104696; Thu, 13 Feb 2020 01:50:20 -0800 (PST) Received: from localhost ([::1]:49766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B8V-0006G4-FY for importer@patchew.org; Thu, 13 Feb 2020 04:50:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46055) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AxE-00072l-09 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2AxC-0005Ee-08 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:39 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2779 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2AxB-00052Z-Kt for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:37 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B09D99A0BA9C9E556120; Thu, 13 Feb 2020 17:38:25 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:15 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 13/14] migration/rdma: only register the memory for multifd channels Date: Thu, 13 Feb 2020 17:37:54 +0800 Message-ID: <20200213093755.370-14-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" All data is sent by multifd Channels, so we only register its for multifd channels and main channel don't register its. Signed-off-by: Zhimin Feng --- migration/rdma.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index eb7c2edbe7..b7b56c0493 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3717,6 +3717,12 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, =20 qemu_sem_post(&multifd_send_param->sem_sync); } + + /* + * Use multifd to migrate, we only register memory for + * multifd RDMA channel and main channel don't register it. + */ + goto wait_reg_complete; } =20 /* @@ -3778,6 +3784,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, local->block[i].remote_rkey =3D rdma->dest_blocks[i].remote_rk= ey; } =20 +wait_reg_complete: /* Wait for all multifd channels to complete registration */ if (migrate_use_multifd()) { int i; --=20 2.19.1 From nobody Tue Apr 23 18:28:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581587477840812.4006201907932; Thu, 13 Feb 2020 01:51:17 -0800 (PST) Received: from localhost ([::1]:49784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2B9Q-0007EJ-I4 for importer@patchew.org; Thu, 13 Feb 2020 04:51:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46058) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2AxE-000732-2S for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2AxC-0005Em-0q for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:39 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2780 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2AxB-00052d-LY for qemu-devel@nongnu.org; Thu, 13 Feb 2020 04:38:37 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B5A68D545394A53FED95; Thu, 13 Feb 2020 17:38:25 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 13 Feb 2020 17:38:16 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 14/14] migration/rdma: RDMA cleanup for multifd migration Date: Thu, 13 Feb 2020 17:37:55 +0800 Message-ID: <20200213093755.370-15-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200213093755.370-1-fengzhimin1@huawei.com> References: <20200213093755.370-1-fengzhimin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.220.198] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jemmy858585@gmail.com, Zhimin Feng , qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Zhimin Feng --- migration/multifd.c | 6 ++++++ migration/rdma.c | 5 ++--- migration/rdma.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index ba5e0b11d0..886c8e1271 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -429,6 +429,9 @@ void multifd_save_cleanup(void) g_free(p->packet); p->packet =3D NULL; if (migrate_use_rdma()) { + p->rdma->listen_id =3D NULL; + p->rdma->channel =3D NULL; + qemu_rdma_cleanup(p->rdma); g_free(p->rdma); } } @@ -835,6 +838,9 @@ int multifd_load_cleanup(Error **errp) g_free(p->packet); p->packet =3D NULL; if (migrate_use_rdma()) { + p->rdma->listen_id =3D NULL; + p->rdma->channel =3D NULL; + qemu_rdma_cleanup(p->rdma); g_free(p->rdma); } } diff --git a/migration/rdma.c b/migration/rdma.c index b7b56c0493..0a48713d03 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2096,11 +2096,11 @@ static int qemu_rdma_write(QEMUFile *f, RDMAContext= *rdma, return 0; } =20 -static void qemu_rdma_cleanup(RDMAContext *rdma) +void qemu_rdma_cleanup(RDMAContext *rdma) { int idx; =20 - if (rdma->cm_id && rdma->connected) { + if (rdma->channel && rdma->cm_id && rdma->connected) { if ((rdma->error_state || migrate_get_current()->state =3D=3D MIGRATION_STATUS_CANCELLI= NG) && !rdma->received_error) { @@ -2181,7 +2181,6 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->host =3D NULL; } =20 - static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **= errp) { int ret, idx; diff --git a/migration/rdma.h b/migration/rdma.h index 7dc3895698..b78f79ddc2 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -283,6 +283,7 @@ int qemu_rdma_exchange_send(RDMAContext *rdma, RDMACont= rolHeader *head, int qemu_rdma_registration(void *opaque); int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested, uint32_t *byte_len); +void qemu_rdma_cleanup(RDMAContext *rdma); =20 void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); --=20 2.19.1