From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578563931; cv=none; d=zohomail.com; s=zohoarc; b=FKiHsgXMjChXGLSjg5gTb/U4Gfh7D/a/6hevhAkwi3GDLebOfMca3GugRDtH87/EfOrrhGaz2gLn6K2v/M+pwtkDcY/xrLlLErgvkOYUgmRjs+ynXqFZIfzszSqQOnywttabv7Qz61mY29jFHX84OE2prxKTvt+H70A0Vq+c5gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578563931; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wDLnYpWEXQoxaTpNMSYIl+3sQBW8eBhcUnaOiu8C3tA=; b=mKZGu0kmQTIV1LBsP6oUIEILXQxFLa/79aEztZjItOY1liC9+D/koQkrBID/7EfhF2PWYNk+ycv+vS+J5yn1Tvh+9V+or69ZC3qAQMI3frDz9rcjM6eLlew3nBUlgRNM1NPSwgZ4bpk6AYS4Yuhq4GVHdok96C0RHy+CQPTAscI= ARC-Authentication-Results: i=1; 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 1578563931780316.2323948832974; Thu, 9 Jan 2020 01:58:51 -0800 (PST) Received: from localhost ([::1]:57628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUaY-0003y7-2y for importer@patchew.org; Thu, 09 Jan 2020 04:58:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42141) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvC-000106-EJ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPv9-0001Im-Vm for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2288 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPv9-000172-Hz for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:47 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D95024124071CE2929B8; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:31 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 01/12] migration: Add multiRDMA capability support Date: Thu, 9 Jan 2020 12:59:11 +0800 Message-ID: <20200109045922.904-2-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Signed-off-by: fengzhimin --- migration/migration.c | 11 +++++++++++ migration/migration.h | 1 + qapi/migration.json | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 354ad072fa..e98e236ef9 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2176,6 +2176,15 @@ bool migrate_use_events(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_use_multiRDMA(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIRDMA]; +} + bool migrate_use_multifd(void) { MigrationState *s; @@ -3509,6 +3518,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), + DEFINE_PROP_MIG_CAP("x-multirdma", + MIGRATION_CAPABILITY_MULTIRDMA), =20 DEFINE_PROP_END_OF_LIST(), }; diff --git a/migration/migration.h b/migration/migration.h index 79b3dda146..bb488028a6 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -296,6 +296,7 @@ bool migrate_ignore_shared(void); bool migrate_validate_uuid(void); =20 bool migrate_auto_converge(void); +bool migrate_use_multiRDMA(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); diff --git a/qapi/migration.json b/qapi/migration.json index b7348d0c8b..c995ffdc4c 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -421,6 +421,8 @@ # @validate-uuid: Send the UUID of the source to allow the destination # to ensure it is the same. (since 4.2) # +# @multirdma: Use more than one channels for rdma migration. (since 4.2) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', @@ -428,7 +430,7 @@ 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', - 'x-ignore-shared', 'validate-uuid' ] } + 'x-ignore-shared', 'validate-uuid', 'multirdma' ] } =20 ## # @MigrationCapabilityStatus: --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578563931; cv=none; d=zohomail.com; s=zohoarc; b=DgYEceoCnfmnEFizzm5BgM2ooWRHqQ5CLBL00cGaGWeKltRpqKuSdNV9mClF0kBcLsiONeXSG8ZZciATSDGLElzeddkYvZx5gdZPl3p9LBbsfMNwXdRZXEY2v85qoRW/VxmCSjjkYN1Ma833LFji5ZMj9xLPNoRnZJXe/v/RR7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578563931; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d8Z+54LxvqxiFvkZ4cWI5RzrWsPvRp4SK9Nt050YDRQ=; b=eKQ8yO+XUr0VhRmicJ3Q94l8q8/1ySUWfUfq5KC06KB4KbFz14H+5k4IZFfChAXRGeiJW8Mjwilib3bVH+OHlEVEdmNW/GOUunWJSQ3LxLU4QAoJxSpMKIKn1D2C6BYYmp5rGszGhjnmH+XzvDL6KLphqHYa7h5ZI43Jv8G3tSM= ARC-Authentication-Results: i=1; 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 157856393178727.607602389485123; Thu, 9 Jan 2020 01:58:51 -0800 (PST) Received: from localhost ([::1]:57626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUaY-0003wU-0t for importer@patchew.org; Thu, 09 Jan 2020 04:58:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41996) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvB-000100-Kd for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPv9-0001Iu-Vp for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:49 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2289 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPv9-000175-IM for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:47 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CEC3FDBFB5913F201A51; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:32 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 02/12] migration: Export the 'migration_incoming_setup' function and add the 'migrate_use_rdma_pin_all' function Date: Thu, 9 Jan 2020 12:59:12 +0800 Message-ID: <20200109045922.904-3-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin We need to call the 'migration_incoming_setup' function in migration/rdma.c, so it has to be changed to a global function. Signed-off-by: fengzhimin Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- migration/migration.c | 11 ++++++++++- migration/migration.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index e98e236ef9..d9d73a5eac 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -518,7 +518,7 @@ fail: exit(EXIT_FAILURE); } =20 -static void migration_incoming_setup(QEMUFile *f) +void migration_incoming_setup(QEMUFile *f) { MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 @@ -2185,6 +2185,15 @@ bool migrate_use_multiRDMA(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_MULTIRDMA]; } =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 bb488028a6..0a23375b2f 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -265,6 +265,7 @@ struct MigrationState =20 void migrate_set_state(int *state, int old_state, int new_state); =20 +void migration_incoming_setup(QEMUFile *f); void migration_fd_process_incoming(QEMUFile *f); void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); void migration_incoming_process(void); @@ -297,6 +298,7 @@ bool migrate_validate_uuid(void); =20 bool migrate_auto_converge(void); bool migrate_use_multiRDMA(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 Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578563930; cv=none; d=zohomail.com; s=zohoarc; b=Y8/GMhIe70xkLlxbc5jshFKAWplJYLfRrmI0SORrMk40NLQgc759lxqcFsRlxjcusRdRxe/tqf2n+8iL98DjYc3WX86zFFqML6a79ee+7hC7kTK0I8DGCn6YvTy2ZqiqQyCLp0ZiikCMnJoHuZh+DTay0J2IvwxtakYCOzJU+PI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578563930; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z8zp2+ryIQn2JDdjsCy2qT6Tco5Jbq0bsnIDk38Exe8=; b=XmHDwn42pB6HcY73f/QftpcUqZ9grxFMjT2sUc4CwFiJwAICQSehebcLlm69luT0LNZ3wk1NE2U+Aaj+mUAzUyE4mwLivPj7l/ftawzownVf0uo3xz0O5L7cV43uVS7P1jTqehvKt5nFXsCyJXt6tlqx1dwlzVQkkG58ElY6VwA= ARC-Authentication-Results: i=1; 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 1578563930543676.3894084466367; Thu, 9 Jan 2020 01:58:50 -0800 (PST) Received: from localhost ([::1]:57623 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUaW-0003ua-IK for importer@patchew.org; Thu, 09 Jan 2020 04:58:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42269) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvD-00010D-6q for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvA-0001Jt-DL for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2292 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPv9-000173-IR for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:48 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C26DDD10DADBFCC61460; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:32 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 03/12] migration: Create the multi-rdma-channels parameter Date: Thu, 9 Jan 2020 12:59:13 +0800 Message-ID: <20200109045922.904-4-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Indicates the number of RDMA threads that we would create. By default we create 2 threads for RDMA migration. Signed-off-by: fengzhimin --- migration/migration.c | 32 ++++++++++++++++++++++++++++++++ migration/migration.h | 1 + monitor/hmp-cmds.c | 7 +++++++ qapi/migration.json | 23 +++++++++++++++++++---- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index d9d73a5eac..5756a4806e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -88,6 +88,9 @@ #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100) #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 =20 +/* Define default MultiRDMA thread number */ +#define DEFAULT_MIGRATE_MULTIRDMA_CHANNELS 2 + /* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. */ @@ -788,6 +791,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->announce_rounds =3D s->parameters.announce_rounds; params->has_announce_step =3D true; params->announce_step =3D s->parameters.announce_step; + params->has_multi_rdma_channels =3D true; + params->multi_rdma_channels =3D s->parameters.multi_rdma_channels; =20 return params; } @@ -1171,6 +1176,14 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) return false; } =20 + if (params->has_multi_rdma_channels + && (params->multi_rdma_channels < 1)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "multi_rdma_channels", + "is invalid, it should be in the range of 1 to 5"); + return false; + } + if (params->has_xbzrle_cache_size && (params->xbzrle_cache_size < qemu_target_page_size() || !is_power_of_2(params->xbzrle_cache_size))) { @@ -1302,6 +1315,9 @@ static void migrate_params_test_apply(MigrateSetParam= eters *params, if (params->has_announce_step) { dest->announce_step =3D params->announce_step; } + if (params->has_multi_rdma_channels) { + dest->multi_rdma_channels =3D params->multi_rdma_channels; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1403,6 +1419,9 @@ static void migrate_params_apply(MigrateSetParameters= *params, Error **errp) if (params->has_announce_step) { s->parameters.announce_step =3D params->announce_step; } + if (params->has_multi_rdma_channels) { + s->parameters.multi_rdma_channels =3D params->multi_rdma_channels; + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) @@ -2222,6 +2241,15 @@ int migrate_multifd_channels(void) return s->parameters.multifd_channels; } =20 +int migrate_multiRDMA_channels(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.multi_rdma_channels; +} + int migrate_use_xbzrle(void) { MigrationState *s; @@ -3513,6 +3541,9 @@ static Property migration_properties[] =3D { DEFINE_PROP_SIZE("announce-step", MigrationState, parameters.announce_step, DEFAULT_MIGRATE_ANNOUNCE_STEP), + DEFINE_PROP_UINT8("multiRDMA-channels", MigrationState, + parameters.multi_rdma_channels, + DEFAULT_MIGRATE_MULTIRDMA_CHANNELS), =20 /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -3591,6 +3622,7 @@ static void migration_instance_init(Object *obj) params->has_announce_max =3D true; params->has_announce_rounds =3D true; params->has_announce_step =3D true; + params->has_multi_rdma_channels =3D true; =20 qemu_sem_init(&ms->postcopy_pause_sem, 0); qemu_sem_init(&ms->postcopy_pause_rp_sem, 0); diff --git a/migration/migration.h b/migration/migration.h index 0a23375b2f..4192c22d8c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -271,6 +271,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp); void migration_incoming_process(void); =20 bool migration_has_all_channels(void); +int migrate_multiRDMA_channels(void); =20 uint64_t migrate_max_downtime(void); =20 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index d0e0af893a..80898c8942 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -456,6 +456,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) monitor_printf(mon, " %s: '%s'\n", MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), params->has_tls_authz ? params->tls_authz : ""); + monitor_printf(mon, "%s: %u\n", + MigrationParameter_str(MIGRATION_PARAMETER_MULTI_RDMA_CHANNELS= ), + params->multi_rdma_channels); } =20 qapi_free_MigrationParameters(params); @@ -1855,6 +1858,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_announce_step =3D true; visit_type_size(v, param, &p->announce_step, &err); break; + case MIGRATION_PARAMETER_MULTI_RDMA_CHANNELS: + p->has_multi_rdma_channels =3D true; + visit_type_int(v, param, &p->multi_rdma_channels, &err); + break; default: assert(0); } diff --git a/qapi/migration.json b/qapi/migration.json index c995ffdc4c..ab79bf0600 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -588,6 +588,10 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) # +# @multi-rdma-channels: Number of channels used to migrate data in +# parallel. This is the same number that the +# number of multiRDMA used for migration. The +# default value is 2 (since 4.2) # Since: 2.4 ## { 'enum': 'MigrationParameter', @@ -600,7 +604,8 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle' ] } + 'max-cpu-throttle', + 'multi-rdma-channels'] } =20 ## # @MigrateSetParameters: @@ -690,6 +695,10 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # The default value is 99. (Since 3.1) # +# @multi-rdma-channels: Number of channels used to migrate data in +# parallel. This is the same number that the +# number of multiRDMA used for migration. The +# default value is 2 (since 4.2) # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make @@ -715,7 +724,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multi-rdma-channels': 'int'} } =20 ## # @migrate-set-parameters: @@ -825,6 +835,10 @@ # Defaults to 99. # (Since 3.1) # +# @multi-rdma-channels: Number of channels used to migrate data in +# parallel. This is the same number that the +# number of multiRDMA used for migration. The +# default value is 2 (since 4.2) # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -847,8 +861,9 @@ '*block-incremental': 'bool' , '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', - '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle':'uint8'} } + '*max-postcopy-bandwidth': 'size', + '*max-cpu-throttle':'uint8', + '*multi-rdma-channels':'uint8'} } =20 ## # @query-migrate-parameters: --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564299; cv=none; d=zohomail.com; s=zohoarc; b=OVcpqSQun+Cm6nsIB8eYcUbrtZ2vdE5fz7mY+gwDaHz1fe3E2I6RbHHvEx9mZbl/+mx8YtrzbXm+aDC0EBe/8TN8rrpaFvGEFFYd2VgmRgsdDgQR+jYXIADmsVu0B3/jb42Fs+d+3RJyO1zFCdrM5w595PHzZL8sAEeC5BhWMMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ohN+0JTPxGzESbhP6qZkpdBP7AMSCDK3iatI599Dt3s=; b=VJmZ+2UdR7SKZH7saIQH7Lyl8NF3QiH04BrkezKz1VjPH26PnfbtN3I2AzNNeV333mEedGSVAduzgRN6I9tHsZRym1K6QcDRhIvEvYUwpKeFgR3Vl/tPGY2cLW4wyK2YSLOt7NznoEhpmkfrNh8azPOUQvr1WkuuJn3ivzQe1NE= ARC-Authentication-Results: i=1; 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 1578564299599776.1646080139778; Thu, 9 Jan 2020 02:04:59 -0800 (PST) Received: from localhost ([::1]:57704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUgT-0003ut-V5 for importer@patchew.org; Thu, 09 Jan 2020 05:04:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42224) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvC-00010A-UV for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvA-0001Ja-BT for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2290 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPv9-000171-Hi for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:48 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C8A22C74532043537580; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:33 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 04/12] migration/rdma: Create multiRDMA migration threads Date: Thu, 9 Jan 2020 12:59:14 +0800 Message-ID: <20200109045922.904-5-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Creation of the RDMA threads, nothing inside yet. Signed-off-by: fengzhimin --- migration/migration.c | 1 + migration/migration.h | 2 + migration/rdma.c | 283 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 5756a4806e..f8d4eb657e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1546,6 +1546,7 @@ static void migrate_fd_cleanup(MigrationState *s) qemu_mutex_lock_iothread(); =20 multifd_save_cleanup(); + multiRDMA_save_cleanup(); qemu_mutex_lock(&s->qemu_file_lock); tmp =3D s->to_dst_file; s->to_dst_file =3D NULL; diff --git a/migration/migration.h b/migration/migration.h index 4192c22d8c..d69a3fe4e9 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -272,6 +272,8 @@ void migration_incoming_process(void); =20 bool migration_has_all_channels(void); int migrate_multiRDMA_channels(void); +int multiRDMA_save_cleanup(void); +int multiRDMA_load_cleanup(void); =20 uint64_t migrate_max_downtime(void); =20 diff --git a/migration/rdma.c b/migration/rdma.c index e241dcb992..992e5abfed 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -395,6 +395,58 @@ typedef struct RDMAContext { bool is_return_path; } RDMAContext; =20 +typedef struct { + /* this fields are not changed once the thread is created */ + /* channel number */ + uint8_t id; + /* channel thread name */ + char *name; + /* channel thread id */ + QemuThread thread; + /* sem where to wait for more work */ + QemuSemaphore sem; + /* this mutex protects the following parameters */ + QemuMutex mutex; + /* is this channel thread running */ + bool running; + /* should this thread finish */ + bool quit; +} MultiRDMASendParams; + +struct { + MultiRDMASendParams *params; + /* number of created threads */ + int count; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; +} *multiRDMA_send_state; + +typedef struct { + /* this fields are not changed once the thread is created */ + /* channel number */ + uint8_t id; + /* channel thread name */ + char *name; + /* channel thread id */ + QemuThread thread; + /* sem where to wait for more work */ + QemuSemaphore sem; + /* this mutex protects the following parameters */ + QemuMutex mutex; + /* is this channel thread running */ + bool running; + /* should this thread finish */ + bool quit; +} MultiRDMARecvParams; + +struct { + MultiRDMARecvParams *params; + /* number of created threads */ + int count; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; +} *multiRDMA_recv_state; + #define TYPE_QIO_CHANNEL_RDMA "qio-channel-rdma" #define QIO_CHANNEL_RDMA(obj) \ OBJECT_CHECK(QIOChannelRDMA, (obj), TYPE_QIO_CHANNEL_RDMA) @@ -3018,6 +3070,7 @@ static void qio_channel_rdma_close_rcu(struct rdma_cl= ose_rcu *rcu) if (rcu->rdmaout) { qemu_rdma_cleanup(rcu->rdmaout); } + multiRDMA_load_cleanup(); =20 g_free(rcu->rdmain); g_free(rcu->rdmaout); @@ -3919,6 +3972,7 @@ static void qio_channel_rdma_finalize(Object *obj) g_free(rioc->rdmaout); rioc->rdmaout =3D NULL; } + multiRDMA_load_cleanup(); } =20 static void qio_channel_rdma_class_init(ObjectClass *klass, @@ -4007,6 +4061,59 @@ static void rdma_accept_incoming_migration(void *opa= que) migration_fd_process_incoming(f); } =20 +static void *multiRDMA_recv_thread(void *opaque) +{ + MultiRDMARecvParams *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 int multiRDMA_load_setup(const char *host_port, RDMAContext *rdma, + Error **errp) +{ + uint8_t i; + int thread_count; + + thread_count =3D migrate_multiRDMA_channels(); + if (multiRDMA_recv_state =3D=3D NULL) { + multiRDMA_recv_state =3D g_malloc0(sizeof(*multiRDMA_recv_state)); + multiRDMA_recv_state->params =3D g_new0(MultiRDMARecvParams, + thread_count); + atomic_set(&multiRDMA_recv_state->count, 0); + qemu_sem_init(&multiRDMA_recv_state->sem_sync, 0); + + for (i =3D 0; i < thread_count; i++) { + MultiRDMARecvParams *p =3D &multiRDMA_recv_state->params[i]; + + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D i; + p->running =3D true; + p->name =3D g_strdup_printf("multiRDMARecv_%d", i); + qemu_thread_create(&p->thread, p->name, multiRDMA_recv_thread, + p, QEMU_THREAD_JOINABLE); + atomic_inc(&multiRDMA_recv_state->count); + } + } + + return 0; +} + void rdma_start_incoming_migration(const char *host_port, Error **errp) { int ret; @@ -4048,6 +4155,13 @@ void rdma_start_incoming_migration(const char *host_= port, Error **errp) qemu_rdma_return_path_dest_init(rdma_return_path, rdma); } =20 + if (migrate_use_multiRDMA()) { + if (multiRDMA_load_setup(host_port, rdma, &local_err) !=3D 0) { + ERROR(errp, "init multiRDMA failure!"); + goto err; + } + } + qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration, NULL, (void *)(intptr_t)rdma); return; @@ -4055,6 +4169,167 @@ err: error_propagate(errp, local_err); g_free(rdma); g_free(rdma_return_path); + multiRDMA_load_cleanup(); +} + +static void *multiRDMA_send_thread(void *opaque) +{ + MultiRDMASendParams *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 int multiRDMA_save_setup(const char *host_port, Error **errp) +{ + int thread_count; + uint8_t i; + + thread_count =3D migrate_multiRDMA_channels(); + multiRDMA_send_state =3D g_malloc0(sizeof(*multiRDMA_send_state)); + multiRDMA_send_state->params =3D g_new0(MultiRDMASendParams, + thread_count); + atomic_set(&multiRDMA_send_state->count, 0); + qemu_sem_init(&multiRDMA_send_state->sem_sync, 0); + + for (i =3D 0; i < thread_count; i++) { + MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + p->quit =3D false; + p->id =3D i; + p->running =3D true; + p->name =3D g_strdup_printf("multiRDMASend_%d", i); + + qemu_thread_create(&p->thread, p->name, multiRDMA_send_thread, p, + QEMU_THREAD_JOINABLE); + atomic_inc(&multiRDMA_send_state->count); + } + + return 0; +} + +static void multiRDMA_send_terminate_threads(void) +{ + int i; + int thread_count =3D migrate_multiRDMA_channels(); + + for (i =3D 0; i < thread_count; i++) { + MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + } +} + +int multiRDMA_save_cleanup(void) +{ + int i; + int ret =3D 0; + int thread_count =3D migrate_multiRDMA_channels(); + + if (!migrate_use_multiRDMA()) { + return 0; + } + + /* prevent double free */ + if (multiRDMA_send_state =3D=3D NULL) { + return 0; + } + + /* notify multi RDMA threads to exit */ + multiRDMA_send_terminate_threads(); + + /* wait for multi RDMA send threads to be exit */ + for (i =3D 0; i < thread_count; i++) { + MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; + + qemu_thread_join(&p->thread); + } + + for (i =3D 0; i < thread_count; i++) { + MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem); + g_free(p->name); + p->name =3D NULL; + } + + qemu_sem_destroy(&multiRDMA_send_state->sem_sync); + g_free(multiRDMA_send_state); + multiRDMA_send_state =3D NULL; + + return ret; +} + +static void multiRDMA_recv_terminate_threads(void) +{ + int i; + int thread_count =3D migrate_multiRDMA_channels(); + + for (i =3D 0; i < thread_count; i++) { + MultiRDMARecvParams *p =3D &multiRDMA_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + } +} + +int multiRDMA_load_cleanup(void) +{ + int i; + int ret =3D 0; + int thread_count =3D migrate_multiRDMA_channels(); + + if (!migrate_use_multiRDMA()) { + return 0; + } + + /* prevent double free */ + if (multiRDMA_recv_state =3D=3D NULL) { + return 0; + } + + /* notify multi RDMA recv threads to exit */ + multiRDMA_recv_terminate_threads(); + + /* wait for multi RDMA threads to be exit */ + for (i =3D 0; i < thread_count; i++) { + MultiRDMARecvParams *p =3D &multiRDMA_recv_state->params[i]; + + qemu_thread_join(&p->thread); + } + + for (i =3D 0; i < thread_count; i++) { + MultiRDMARecvParams *p =3D &multiRDMA_recv_state->params[i]; + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem); + g_free(p->name); + p->name =3D NULL; + } + + qemu_sem_destroy(&multiRDMA_recv_state->sem_sync); + g_free(multiRDMA_recv_state); + multiRDMA_recv_state =3D NULL; + + return ret; } =20 void rdma_start_outgoing_migration(void *opaque, @@ -4111,10 +4386,18 @@ void rdma_start_outgoing_migration(void *opaque, =20 trace_rdma_start_outgoing_migration_after_rdma_connect(); =20 + if (migrate_use_multiRDMA()) { + if (multiRDMA_save_setup(host_port, errp) !=3D 0) { + ERROR(errp, "init multiRDMA channels failure!"); + goto err; + } + } + s->to_dst_file =3D qemu_fopen_rdma(rdma, "wb"); migrate_fd_connect(s, NULL); return; err: g_free(rdma); g_free(rdma_return_path); + multiRDMA_save_cleanup(); } --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564299; cv=none; d=zohomail.com; s=zohoarc; b=eDtLwaDVPjzDGCcFXAuOUVQpgZQHN2LLtdyqkFfNe2G88Ith7cNnHI1hIWVa0PkIRxZOOtuZiFEjS3VnvbopyXM8FabhKZoc//MpY9jsLeUgfnNng1wKAKSwyF2NjzXeC40CETRzY2f2ISlXLJOFMLUjqW0nVYIy0xZzqAJzk1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eN60L8KEHv+Q/VxqQqay+yPkOq6od7YhgQBQK8JRR5o=; b=BvHNCN/v+u8VS3heioPJ21M6TehIdPydh37lveaxhIw4dSkk1yD9m+Cl4oqVOXq9kLqj9sv16wxbd8FXrSYNgMyY8PfcaXT3uR8sUiZuszbgWviG412yvMa9f9r8UgdSM+2Axr1eUn/MZpMwj+QZrnbEpHH0RaiJfEAvzerNPeo= ARC-Authentication-Results: i=1; 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 1578564299537447.6202484651045; Thu, 9 Jan 2020 02:04:59 -0800 (PST) Received: from localhost ([::1]:57700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUgT-0003tl-S6 for importer@patchew.org; Thu, 09 Jan 2020 05:04:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42308) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvD-00010I-Df for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvA-0001Ji-9W for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2291 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPv9-000176-IJ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:48 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D38A774056829795602E; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:33 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 05/12] migration/rdma: Create the multiRDMA channels Date: Thu, 9 Jan 2020 12:59:15 +0800 Message-ID: <20200109045922.904-6-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin In both sides. We still don't transmit anything through them, and we only build the RDMA connections. Signed-off-by: fengzhimin --- migration/rdma.c | 253 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 223 insertions(+), 30 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 992e5abfed..5b780bef36 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -403,6 +403,10 @@ typedef struct { char *name; /* channel thread id */ QemuThread thread; + /* RDMAContext channel */ + RDMAContext *rdma; + /* communication channel */ + QEMUFile *file; /* sem where to wait for more work */ QemuSemaphore sem; /* this mutex protects the following parameters */ @@ -429,6 +433,10 @@ typedef struct { char *name; /* channel thread id */ QemuThread thread; + /* RDMAContext channel */ + RDMAContext *rdma; + /* communication channel */ + QEMUFile *file; /* sem where to wait for more work */ QemuSemaphore sem; /* this mutex protects the following parameters */ @@ -3417,6 +3425,27 @@ 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_multiRDMA()) { + int thread_count; + int i; + RDMAContext *multi_rdma =3D NULL; + thread_count =3D migrate_multiRDMA_channels(); + /* create the multi Thread RDMA channels */ + for (i =3D 0; i < thread_count; i++) { + if (multiRDMA_recv_state->params[i].rdma->cm_id =3D=3D NULL) { + multi_rdma =3D multiRDMA_recv_state->params[i].rdma; + break; + } + } + + if (multi_rdma) { + qemu_set_fd_handler(rdma->channel->fd, + rdma_accept_incoming_migration, + NULL, (void *)(intptr_t)multi_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); @@ -4029,6 +4058,58 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, = const char *mode) return rioc->file; } =20 +static void *multiRDMA_recv_thread(void *opaque) +{ + MultiRDMARecvParams *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 multiRDMA_recv_new_channel(QEMUFile *f, int id) +{ + MultiRDMARecvParams *p; + Error *local_err =3D NULL; + + p =3D &multiRDMA_recv_state->params[id]; + if (p->file !=3D NULL) { + error_setg(&local_err, + "multiRDMA: received id '%d' already setup'", id); + return ; + } + p->file =3D f; + + qemu_thread_create(&p->thread, p->name, multiRDMA_recv_thread, p, + QEMU_THREAD_JOINABLE); + atomic_inc(&multiRDMA_recv_state->count); +} + +static void migration_multiRDMA_process_incoming(QEMUFile *f, RDMAContext = *rdma) +{ + MigrationIncomingState *mis =3D migration_incoming_get_current(); + + if (!mis->from_src_file) { + rdma->migration_started_on_destination =3D 1; + migration_incoming_setup(f); + migration_incoming_process(); + } else { + multiRDMA_recv_new_channel(f, multiRDMA_recv_state->count); + } +} + static void rdma_accept_incoming_migration(void *opaque) { RDMAContext *rdma =3D opaque; @@ -4057,29 +4138,13 @@ static void rdma_accept_incoming_migration(void *op= aque) return; } =20 - rdma->migration_started_on_destination =3D 1; - migration_fd_process_incoming(f); -} - -static void *multiRDMA_recv_thread(void *opaque) -{ - MultiRDMARecvParams *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); + if (migrate_use_multiRDMA()) { + /* build the multiRDMA channels */ + migration_multiRDMA_process_incoming(f, rdma); + } else { + rdma->migration_started_on_destination =3D 1; + migration_fd_process_incoming(f); } - - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - return NULL; } =20 static int multiRDMA_load_setup(const char *host_port, RDMAContext *rdma, @@ -4087,6 +4152,7 @@ static int multiRDMA_load_setup(const char *host_port= , RDMAContext *rdma, { uint8_t i; int thread_count; + int idx; =20 thread_count =3D migrate_multiRDMA_channels(); if (multiRDMA_recv_state =3D=3D NULL) { @@ -4099,15 +4165,21 @@ static int multiRDMA_load_setup(const char *host_po= rt, RDMAContext *rdma, for (i =3D 0; i < thread_count; i++) { MultiRDMARecvParams *p =3D &multiRDMA_recv_state->params[i]; =20 + p->rdma =3D qemu_rdma_data_init(host_port, errp); + for (idx =3D 0; idx < RDMA_WRID_MAX; idx++) { + p->rdma->wr_data[idx].control_len =3D 0; + p->rdma->wr_data[idx].control_curr =3D NULL; + } + /* the CM channel and CM id is shared */ + p->rdma->channel =3D rdma->channel; + p->rdma->listen_id =3D rdma->listen_id; + qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); p->quit =3D false; p->id =3D i; p->running =3D true; p->name =3D g_strdup_printf("multiRDMARecv_%d", i); - qemu_thread_create(&p->thread, p->name, multiRDMA_recv_thread, - p, QEMU_THREAD_JOINABLE); - atomic_inc(&multiRDMA_recv_state->count); } } =20 @@ -4155,6 +4227,7 @@ void rdma_start_incoming_migration(const char *host_p= ort, Error **errp) qemu_rdma_return_path_dest_init(rdma_return_path, rdma); } =20 + /* initialize the RDMAContext for multiRDMA */ if (migrate_use_multiRDMA()) { if (multiRDMA_load_setup(host_port, rdma, &local_err) !=3D 0) { ERROR(errp, "init multiRDMA failure!"); @@ -4193,10 +4266,29 @@ static void *multiRDMA_send_thread(void *opaque) return NULL; } =20 +static void multiRDMA_send_new_channel(QEMUFile *f, int id) +{ + MultiRDMASendParams *p; + Error *local_err =3D NULL; + + p =3D &multiRDMA_send_state->params[id]; + if (p->file !=3D NULL) { + error_setg(&local_err, + "multiRDMA: send id '%d' already setup'", id); + return ; + } + p->file =3D f; + + qemu_thread_create(&p->thread, p->name, multiRDMA_send_thread, + p, QEMU_THREAD_JOINABLE); + atomic_inc(&multiRDMA_send_state->count); +} + static int multiRDMA_save_setup(const char *host_port, Error **errp) { int thread_count; uint8_t i; + int ret; =20 thread_count =3D migrate_multiRDMA_channels(); multiRDMA_send_state =3D g_malloc0(sizeof(*multiRDMA_send_state)); @@ -4207,6 +4299,27 @@ static int multiRDMA_save_setup(const char *host_por= t, Error **errp) =20 for (i =3D 0; i < thread_count; i++) { MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; + QEMUFile *f =3D NULL; + + p->rdma =3D qemu_rdma_data_init(host_port, errp); + if (p->rdma =3D=3D NULL) { + ERROR(errp, "init RDMA data failure for multi channel %d!", i); + goto err; + } + + ret =3D qemu_rdma_source_init(p->rdma, migrate_use_rdma_pin_all(),= errp); + if (ret) { + ERROR(errp, "init RDMA source failure for multi channel %d!", = i); + goto err; + } + + ret =3D qemu_rdma_connect(p->rdma, errp); + if (ret) { + ERROR(errp, "connect multi channel %d failure!", i); + goto err; + } + + f =3D qemu_fopen_rdma(multiRDMA_send_state->params[i].rdma, "wb"); qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); p->quit =3D false; @@ -4214,12 +4327,20 @@ static int multiRDMA_save_setup(const char *host_po= rt, Error **errp) p->running =3D true; p->name =3D g_strdup_printf("multiRDMASend_%d", i); =20 - qemu_thread_create(&p->thread, p->name, multiRDMA_send_thread, p, - QEMU_THREAD_JOINABLE); - atomic_inc(&multiRDMA_send_state->count); + multiRDMA_send_new_channel(f, i); } =20 return 0; + +err: + for (i =3D 0; i < thread_count; i++) { + g_free(multiRDMA_send_state->params[i].rdma); + } + + g_free(multiRDMA_send_state->params); + g_free(multiRDMA_send_state); + + return -1; } =20 static void multiRDMA_send_terminate_threads(void) @@ -4268,6 +4389,8 @@ int multiRDMA_save_cleanup(void) qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; + qemu_rdma_cleanup(multiRDMA_send_state->params[i].rdma); + g_free(multiRDMA_send_state->params[i].rdma); } =20 qemu_sem_destroy(&multiRDMA_send_state->sem_sync); @@ -4292,6 +4415,71 @@ static void multiRDMA_recv_terminate_threads(void) } } =20 +static void qemu_multiRDMA_load_cleanup(RDMAContext *rdma) +{ + int idx; + + if (rdma->cm_id && rdma->connected) { + if ((rdma->error_state || + migrate_get_current()->state =3D=3D MIGRATION_STATUS_CANCELLI= NG) && + !rdma->received_error) { + RDMAControlHeader head =3D { .len =3D 0, + .type =3D RDMA_CONTROL_ERROR, + .repeat =3D 1, + }; + error_report("Early error. Sending error."); + qemu_rdma_post_send_control(rdma, NULL, &head); + } + + rdma_disconnect(rdma->cm_id); + trace_qemu_rdma_cleanup_disconnect(); + rdma->connected =3D false; + } + + g_free(rdma->dest_blocks); + rdma->dest_blocks =3D NULL; + + for (idx =3D 0; idx < RDMA_WRID_MAX; idx++) { + if (rdma->wr_data[idx].control_mr) { + rdma->total_registrations--; + ibv_dereg_mr(rdma->wr_data[idx].control_mr); + } + rdma->wr_data[idx].control_mr =3D NULL; + } + + if (rdma->local_ram_blocks.block) { + while (rdma->local_ram_blocks.nb_blocks) { + rdma_delete_block(rdma, &rdma->local_ram_blocks.block[0]); + } + } + + if (rdma->qp) { + rdma_destroy_qp(rdma->cm_id); + rdma->qp =3D NULL; + } + if (rdma->cq) { + ibv_destroy_cq(rdma->cq); + rdma->cq =3D NULL; + } + if (rdma->comp_channel) { + ibv_destroy_comp_channel(rdma->comp_channel); + rdma->comp_channel =3D NULL; + } + if (rdma->pd) { + ibv_dealloc_pd(rdma->pd); + rdma->pd =3D NULL; + } + if (rdma->cm_id) { + rdma_destroy_id(rdma->cm_id); + rdma->cm_id =3D NULL; + } + + rdma->listen_id =3D NULL; + rdma->channel =3D NULL; + g_free(rdma->host); + rdma->host =3D NULL; +} + int multiRDMA_load_cleanup(void) { int i; @@ -4323,6 +4511,8 @@ int multiRDMA_load_cleanup(void) qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; + qemu_multiRDMA_load_cleanup(multiRDMA_recv_state->params[i].rdma); + g_free(multiRDMA_recv_state->params[i].rdma); } =20 qemu_sem_destroy(&multiRDMA_recv_state->sem_sync); @@ -4386,15 +4576,18 @@ void rdma_start_outgoing_migration(void *opaque, =20 trace_rdma_start_outgoing_migration_after_rdma_connect(); =20 + s->to_dst_file =3D qemu_fopen_rdma(rdma, "wb"); + /* create multiRDMA channel */ if (migrate_use_multiRDMA()) { if (multiRDMA_save_setup(host_port, errp) !=3D 0) { ERROR(errp, "init multiRDMA channels failure!"); goto err; } + migrate_fd_connect(s, NULL); + } else { + migrate_fd_connect(s, NULL); } =20 - s->to_dst_file =3D qemu_fopen_rdma(rdma, "wb"); - migrate_fd_connect(s, NULL); return; err: g_free(rdma); --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564132; cv=none; d=zohomail.com; s=zohoarc; b=XRIvHABUIPwvpvY1f/CZf6HtcP/+FTksJ25T8WC5mDZ5g6zpo8Dl4XxWXnrx/yTP5MpPWu2xUNLyoZ/zxnvfHW6nOlsmPnyGzOy1d+JK31HRXsKtsU1/RiiV9ZXhm7o/N1q1PCv+zhMrA7fI/fOydJ/XGjxU15E60JLy3I4dWFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564132; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2Lcu/YMFia0WPWi66gAyjTVt/G5LhQzEhtUJxkVvA4s=; b=NOBJo9sXDzsfUoTcoCxiXvSnD2AezQPGyZEZxeCitD1pYQEG9//5/bDrIZMFelT3jGcUd1k4LMK4TPWRSQumUi9BRLNa/SCdEcXduuITNXSiTlu1LN+BKuhuHcLKfSu4v65kZ9SqGAkUEuMvucIBh7V1iOYld89YYyv1RNyEt54= ARC-Authentication-Results: i=1; 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 1578564132214728.0499677524476; Thu, 9 Jan 2020 02:02:12 -0800 (PST) Received: from localhost ([::1]:57674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUdm-00084B-AH for importer@patchew.org; Thu, 09 Jan 2020 05:02:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42713) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvF-00010n-Nm for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvC-0001Ou-LG for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:53 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2293 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvC-0001K3-1i for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:50 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DDE967ABED5B9696DBA0; Thu, 9 Jan 2020 12:59:40 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:34 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 06/12] migration/rdma: Transmit initial package Date: Thu, 9 Jan 2020 12:59:16 +0800 Message-ID: <20200109045922.904-7-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Transmit initial package through the multiRDMA channels, so that we can identify the main channel and multiRDMA channels. Signed-off-by: fengzhimin --- migration/rdma.c | 114 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 7 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 5b780bef36..db75a4372a 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -116,6 +116,16 @@ 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 +/* Define magic to distinguish multiRDMA and main RDMA */ +#define MULTIRDMA_MAGIC 0x11223344U +#define MAINRDMA_MAGIC 0x55667788U +#define ERROR_MAGIC 0xFFFFFFFFU + +#define MULTIRDMA_VERSION 1 +#define MAINRDMA_VERSION 1 + +#define UNUSED_ID 0xFFU + /* * RDMA migration protocol: * 1. RDMA Writes (data messages, i.e. RAM) @@ -167,6 +177,14 @@ enum { RDMA_CONTROL_UNREGISTER_FINISHED, /* unpinning finished */ }; =20 +/* + * Identify the MultiRDAM channel info + */ +typedef struct { + uint32_t magic; + uint32_t version; + uint8_t id; +} __attribute__((packed)) RDMAChannelInit_t; =20 /* * Memory and MR structures used to represent an IB Send/Recv work request. @@ -3430,7 +3448,7 @@ static int qemu_rdma_accept(RDMAContext *rdma) int i; RDMAContext *multi_rdma =3D NULL; thread_count =3D migrate_multiRDMA_channels(); - /* create the multi Thread RDMA channels */ + /* create the multiRDMA channels */ for (i =3D 0; i < thread_count; i++) { if (multiRDMA_recv_state->params[i].rdma->cm_id =3D=3D NULL) { multi_rdma =3D multiRDMA_recv_state->params[i].rdma; @@ -4058,6 +4076,48 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, = const char *mode) return rioc->file; } =20 +static RDMAChannelInit_t migration_rdma_recv_initial_packet(QEMUFile *f, + Error **errp) +{ + RDMAChannelInit_t msg; + int thread_count =3D migrate_multiRDMA_channels(); + qemu_get_buffer(f, (uint8_t *)&msg, sizeof(msg)); + be32_to_cpus(&msg.magic); + be32_to_cpus(&msg.version); + + if (msg.magic !=3D MULTIRDMA_MAGIC && + msg.magic !=3D MAINRDMA_MAGIC) { + error_setg(errp, "multiRDMA: received unrecognized " + "packet magic %x", msg.magic); + goto err; + } + + if (msg.magic =3D=3D MULTIRDMA_MAGIC + && msg.version !=3D MULTIRDMA_VERSION) { + error_setg(errp, "multiRDMA: received packet version " + "%d expected %d", msg.version, MULTIRDMA_VERSION); + goto err; + } + + if (msg.magic =3D=3D MAINRDMA_MAGIC && msg.version !=3D MAINRDMA_VERSI= ON) { + error_setg(errp, "multiRDMA: received packet version " + "%d expected %d", msg.version, MAINRDMA_VERSION); + goto err; + } + + if (msg.magic =3D=3D MULTIRDMA_MAGIC && msg.id > thread_count) { + error_setg(errp, "multiRDMA: received channel version %d " + "expected %d", msg.version, MULTIRDMA_VERSION); + goto err; + } + + return msg; +err: + msg.magic =3D ERROR_MAGIC; + msg.id =3D UNUSED_ID; + return msg; +} + static void *multiRDMA_recv_thread(void *opaque) { MultiRDMARecvParams *p =3D opaque; @@ -4100,13 +4160,34 @@ static void multiRDMA_recv_new_channel(QEMUFile *f,= int id) static void migration_multiRDMA_process_incoming(QEMUFile *f, RDMAContext = *rdma) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + Error *local_err =3D NULL; + RDMAChannelInit_t msg =3D migration_rdma_recv_initial_packet(f, &local= _err); + + switch (msg.magic) { + case MAINRDMA_MAGIC: + if (!mis->from_src_file) { + rdma->migration_started_on_destination =3D 1; + migration_incoming_setup(f); + migration_incoming_process(); + } + break; =20 - if (!mis->from_src_file) { - rdma->migration_started_on_destination =3D 1; - migration_incoming_setup(f); - migration_incoming_process(); - } else { - multiRDMA_recv_new_channel(f, multiRDMA_recv_state->count); + case MULTIRDMA_MAGIC: + multiRDMA_recv_new_channel(f, msg.id); + break; + + case ERROR_MAGIC: + default: + if (local_err) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, local_err); + if (s->state =3D=3D MIGRATION_STATUS_SETUP || + s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } + } + break; } } =20 @@ -4245,10 +4326,26 @@ err: multiRDMA_load_cleanup(); } =20 +static void migration_rdma_send_initial_packet(QEMUFile *f, uint8_t id) +{ + RDMAChannelInit_t msg; + + msg.magic =3D cpu_to_be32(id =3D=3D UNUSED_ID ? + MAINRDMA_MAGIC : MULTIRDMA_MAGIC); + msg.version =3D cpu_to_be32(id =3D=3D UNUSED_ID ? + MAINRDMA_VERSION : MULTIRDMA_VERSION); + msg.id =3D id; + qemu_put_buffer(f, (uint8_t *)&msg, sizeof(msg)); + qemu_fflush(f); +} + static void *multiRDMA_send_thread(void *opaque) { MultiRDMASendParams *p =3D opaque; =20 + /* send the multiRDMA channels magic */ + migration_rdma_send_initial_packet(p->file, p->id); + while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { @@ -4579,6 +4676,9 @@ void rdma_start_outgoing_migration(void *opaque, s->to_dst_file =3D qemu_fopen_rdma(rdma, "wb"); /* create multiRDMA channel */ if (migrate_use_multiRDMA()) { + /* send the main RDMA channel magic */ + migration_rdma_send_initial_packet(s->to_dst_file, UNUSED_ID); + if (multiRDMA_save_setup(host_port, errp) !=3D 0) { ERROR(errp, "init multiRDMA channels failure!"); goto err; --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564130; cv=none; d=zohomail.com; s=zohoarc; b=j84WXyv1GrHpxfUuipth6tVF/g3QEZ6uO58V/1jb3m+26lwo7uQQFUMH5roJ5Jp9G3ilPZAFwh3Obd7dKTx4H3PGbYy912wGW2CF6h4zPrAi7zR5Mq6VtD72pClKm5sZ2c7zGzzSn/8WdW3lzsVvZ/AJDzwNAHlDdjw9ezPVeQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564130; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=epML0JfhMhFLbJPAkRP1UlD/JzuK1nrnE1GT5tmn0kk=; b=GiHAjZVmOPYi0DewBD2cojLy4iwjlLjGX3KNdxS7UrjXNIBZl6QWIseEOJMBQzSwHOKCdzwDPyBLwpN0j8zXF9GMN0HHWVD5S2ILeFerz0QY90w3LJgFO9pHHY2bUIncQVLlQ+B5ctQcuPHXHYUdwwcZ9sK3O96KtuRuUg41uBw= ARC-Authentication-Results: i=1; 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 1578564130517103.01450459385558; Thu, 9 Jan 2020 02:02:10 -0800 (PST) Received: from localhost ([::1]:57670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUdk-0007sR-LN for importer@patchew.org; Thu, 09 Jan 2020 05:02:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42362) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvD-00010L-NA for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvB-0001N1-VJ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:51 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34928 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvB-0001Gp-FD for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:49 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EAFEF725F85CFF8656CE; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:35 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 07/12] migration/rdma: Be sure all channels are created Date: Thu, 9 Jan 2020 12:59:17 +0800 Message-ID: <20200109045922.904-8-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin We need to build all multiRDMA channels before we start migration. Signed-off-by: fengzhimin --- migration/rdma.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index db75a4372a..518a21b0fe 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -4076,6 +4076,38 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, = const char *mode) return rioc->file; } =20 +static bool multiRDMA_send_all_channels_created(void) +{ + int thread_count =3D migrate_multiRDMA_channels(); + + return thread_count =3D=3D atomic_read(&multiRDMA_send_state->count); +} + +static bool multiRDMA_recv_all_channels_created(void) +{ + int thread_count =3D migrate_multiRDMA_channels(); + + return thread_count =3D=3D atomic_read(&multiRDMA_recv_state->count); +} + +static bool migration_has_all_rdma_channels(void) +{ + bool all_channels; + if (multiRDMA_send_state) { + MigrationState *ms =3D migrate_get_current(); + all_channels =3D multiRDMA_send_all_channels_created(); + + return all_channels && ms->to_dst_file !=3D NULL; + } else { + MigrationIncomingState *mis =3D migration_incoming_get_current(); + all_channels =3D multiRDMA_recv_all_channels_created(); + + return all_channels && mis->from_src_file !=3D NULL; + } + + return false; +} + static RDMAChannelInit_t migration_rdma_recv_initial_packet(QEMUFile *f, Error **errp) { @@ -4168,7 +4200,6 @@ static void migration_multiRDMA_process_incoming(QEMU= File *f, RDMAContext *rdma) if (!mis->from_src_file) { rdma->migration_started_on_destination =3D 1; migration_incoming_setup(f); - migration_incoming_process(); } break; =20 @@ -4189,6 +4220,11 @@ static void migration_multiRDMA_process_incoming(QEM= UFile *f, RDMAContext *rdma) } break; } + + /* wait for all channels to be established */ + if (migration_has_all_rdma_channels()) { + migration_incoming_process(); + } } =20 static void rdma_accept_incoming_migration(void *opaque) @@ -4683,7 +4719,11 @@ void rdma_start_outgoing_migration(void *opaque, ERROR(errp, "init multiRDMA channels failure!"); goto err; } - migrate_fd_connect(s, NULL); + + /* wait for all channels to be established */ + if (migration_has_all_rdma_channels()) { + migrate_fd_connect(s, NULL); + } } else { migrate_fd_connect(s, NULL); } --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578563931; cv=none; d=zohomail.com; s=zohoarc; b=iWpDixtMil3BA68N6GhlMALWDZdn4r0LFOXPtbpe/Eif4AJOeu/cuaMJ1kHZm0BKpsX++bWEZVwAv52hdHnV6KGX6c3WJcMJjQLIctZa1n2KTZoNCylJu/s+HkFe1UAUsYBVGC4hTnWCz2wvvIIVA+MgETZOL52li6s9tou8y70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578563931; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0R5SLSp9L755vwyKPPfvXcfcBoCz4iWOwWBeP5Yqfrw=; b=MJ9u6cvNi2OF3kXIFJ/vQKeg230g1gaPd2cE8u2x5yjJDCGn1ukih2VgjP6gjW0LCvlWOqRzgDjeFMsrQflwT//I7WYkxbziPoTgYSFroc3yGJh7+Nm+y6bOTBlt4BLWVSPEvd+eeNc8m/cQN3L4ghkfEKXma0TfynaNzN2dXsE= ARC-Authentication-Results: i=1; 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 1578563931784553.1336426760124; Thu, 9 Jan 2020 01:58:51 -0800 (PST) Received: from localhost ([::1]:57624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUaX-0003vB-O0 for importer@patchew.org; Thu, 09 Jan 2020 04:58:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42619) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvF-00010e-7H for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvC-0001Nm-5F for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:53 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34920 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvB-0001Gq-B5 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:50 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DA2E65FB4C5DD70D1BED; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:35 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 08/12] migration/rdma: register memory for multiRDMA channels Date: Thu, 9 Jan 2020 12:59:18 +0800 Message-ID: <20200109045922.904-9-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin register memory for multiRDMA channels and transmit the destination the keys to source to use including the virtual addresses. Signed-off-by: fengzhimin --- migration/rdma.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 2 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 518a21b0fe..6ecc870844 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3847,6 +3847,15 @@ 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_multiRDMA()) { + int i; + int thread_count =3D migrate_multiRDMA_channels(); + /* Inform dest recv_thread to poll */ + for (i =3D 0; i < thread_count; i++) { + qemu_sem_post(&multiRDMA_recv_state->params[i].sem); + } + } + return qemu_rdma_registration_handle(f, opaque); =20 default: @@ -3920,6 +3929,17 @@ 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_multiRDMA()) { + /* + * Inform the multiRDMA channels to register memory + */ + int i; + int thread_count =3D migrate_multiRDMA_channels(); + for (i =3D 0; i < thread_count; i++) { + qemu_sem_post(&multiRDMA_send_state->params[i].sem); + } + } + /* * Make sure that we parallelize the pinning on both sides. * For very large guests, doing this serially takes a really @@ -3985,6 +4005,15 @@ 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_multiRDMA()) { + /* Inform src send_thread to send FINISHED signal */ + int i; + int thread_count =3D migrate_multiRDMA_channels(); + for (i =3D 0; i < thread_count; i++) { + qemu_sem_post(&multiRDMA_send_state->params[i].sem); + } + } + if (ret < 0) { goto err; } @@ -4150,18 +4179,119 @@ err: return msg; } =20 +static int qemu_multiRDMA_registration_handle(void *opaque) +{ + RDMAControlHeader blocks =3D { .type =3D RDMA_CONTROL_RAM_BLOCKS_RESUL= T, + .repeat =3D 1 }; + MultiRDMARecvParams *p =3D opaque; + RDMAContext *rdma =3D p->rdma; + RDMALocalBlocks *local =3D &rdma->local_ram_blocks; + RDMAControlHeader head; + int ret =3D 0; + int i =3D 0; + + CHECK_ERROR_STATE(); + + do { + ret =3D qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE); + + if (ret < 0) { + break; + } + + if (head.repeat > RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE) { + error_report("rdma: Too many requests in this message (%d)." + "Bailing.", head.repeat); + ret =3D -EIO; + break; + } + + switch (head.type) { + case RDMA_CONTROL_REGISTER_FINISHED: + goto out; + case RDMA_CONTROL_RAM_BLOCKS_REQUEST: + qsort(rdma->local_ram_blocks.block, + rdma->local_ram_blocks.nb_blocks, + sizeof(RDMALocalBlock), dest_ram_sort_func); + + if (rdma->pin_all) { + ret =3D qemu_rdma_reg_whole_ram_blocks(rdma); + if (ret) { + error_report("rdma migration: error dest " + "registering ram blocks"); + goto out; + } + } + + for (i =3D 0; i < local->nb_blocks; i++) { + /* + * The multiRDMA threads only register ram block + * to send data, other blocks are sent by main RDMA thread. + */ + if (strcmp(local->block[i].block_name, "mach-virt.ram") = =3D=3D 0) { + rdma->dest_blocks[i].remote_host_addr =3D + (uintptr_t)(local->block[i].local_host_addr); + + if (rdma->pin_all) { + rdma->dest_blocks[i].remote_rkey =3D + local->block[i].mr->rkey; + } + + rdma->dest_blocks[i].offset =3D local->block[i].offset; + rdma->dest_blocks[i].length =3D local->block[i].length; + + dest_block_to_network(&rdma->dest_blocks[i]); + + break; + } + } + + blocks.len =3D rdma->local_ram_blocks.nb_blocks + * sizeof(RDMADestBlock); + + ret =3D qemu_rdma_post_send_control(rdma, + (uint8_t *) rdma->dest_block= s, + &blocks); + + if (ret < 0) { + error_report("rdma migration: error sending remote info"); + goto out; + } + + break; + default: + error_report("Unknown control message %s", control_desc(head.t= ype)); + ret =3D -EIO; + goto out; + } + } while (1); +out: + if (ret < 0) { + rdma->error_state =3D ret; + } + return ret; +} + static void *multiRDMA_recv_thread(void *opaque) { MultiRDMARecvParams *p =3D opaque; + int ret; =20 while (true) { + qemu_sem_wait(&p->sem); + qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } qemu_mutex_unlock(&p->mutex); - qemu_sem_wait(&p->sem); + + ret =3D qemu_multiRDMA_registration_handle(opaque); + if (ret < 0) { + qemu_file_set_error(p->file, ret); + break; + } } =20 qemu_mutex_lock(&p->mutex); @@ -4378,18 +4508,76 @@ static void migration_rdma_send_initial_packet(QEMU= File *f, uint8_t id) static void *multiRDMA_send_thread(void *opaque) { MultiRDMASendParams *p =3D opaque; + RDMAContext *rdma =3D p->rdma; + int ret; =20 /* send the multiRDMA channels magic */ migration_rdma_send_initial_packet(p->file, p->id); =20 + /* wait for semaphore notification to register memory */ + qemu_sem_wait(&p->sem); + + 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 }; + + 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) { + return NULL; + } + + nb_dest_blocks =3D resp.len / sizeof(RDMADestBlock); + + if (local->nb_blocks !=3D nb_dest_blocks) { + rdma->error_state =3D -EINVAL; + return NULL; + } + + 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++) { + /* + * The multiRDMA threads only register ram block + * to send data, other blocks are sent by main RDMA thread. + */ + if (strcmp(local->block[i].block_name, "mach-virt.ram") =3D=3D 0) { + 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; + return NULL; + } + 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_rk= ey; + break; + } + } + while (true) { + qemu_sem_wait(&p->sem); + 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(rdma, &head, NULL, NULL, NULL, NUL= L); + if (ret < 0) { + return NULL; + } } =20 qemu_mutex_lock(&p->mutex); --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564125; cv=none; d=zohomail.com; s=zohoarc; b=fQXpbfGFGOmyyIzjMaFVsdWKnLYbFS9zSbgGusmyggjuUAdxQHQSAjI8yXJOugfaeOTFWLlCryOFT9WsOClG3tEwjrg0KUuCAyVPHD8P6QwCHoyDy/xBc7VK9/qDEZwbAkWiGbSIjrr5gCJHBfW6MPzvJdinVBfBSgBoMva0gvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564125; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q4wrAWXWKxlEwydAZaf4uepocfqpJ+2y2BlVUFSoBTE=; b=Mvdw8VoxYyzaof3ERD0DQokpANc1rbh5AfuAkHbGm9abp+A9RvDDF5zwJMpSKL2+nWhBiFvWdaKc9uuhxUoAYXkY9fw2y1suQHxyVE8VPjvAfdxrkWa14o05LPVLkM7KusmpIdXbpXpHs7pdC4GDJF6SgdGMIwpmNvXaP1XD++0= ARC-Authentication-Results: i=1; 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 1578564125366240.45723252808182; Thu, 9 Jan 2020 02:02:05 -0800 (PST) Received: from localhost ([::1]:57668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUdd-0007jc-T0 for importer@patchew.org; Thu, 09 Jan 2020 05:02:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42336) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvD-00010K-Il for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvB-0001Mm-V5 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:51 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34926 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvB-0001Gs-B6 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:49 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D4B8ADE520CCB6F82A54; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:36 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 09/12] migration/rdma: Wait for all multiRDMA to complete registration Date: Thu, 9 Jan 2020 12:59:19 +0800 Message-ID: <20200109045922.904-10-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Signed-off-by: fengzhimin --- migration/rdma.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index 6ecc870844..425dfa709d 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -439,6 +439,10 @@ struct { MultiRDMASendParams *params; /* number of created threads */ int count; + /* this mutex protects the following parameters */ + QemuMutex mutex_sync; + /* number of registered multiRDMA channels */ + unsigned int reg_mr_channels; /* syncs main thread and channels */ QemuSemaphore sem_sync; } *multiRDMA_send_state; @@ -3998,6 +4002,11 @@ 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 multiRDMA channels to complete registration */ + if (migrate_use_multiRDMA()) { + qemu_sem_wait(&multiRDMA_send_state->sem_sync); + } } =20 trace_qemu_rdma_registration_stop(flags); @@ -4562,6 +4571,17 @@ static void *multiRDMA_send_thread(void *opaque) } } =20 + /* + * Inform the main RDMA thread to run when multiRDMA + * threads have completed registration. + */ + qemu_mutex_lock(&multiRDMA_send_state->mutex_sync); + if (++multiRDMA_send_state->reg_mr_channels =3D=3D + migrate_multiRDMA_channels()) { + qemu_sem_post(&multiRDMA_send_state->sem_sync); + } + qemu_mutex_unlock(&multiRDMA_send_state->mutex_sync); + while (true) { qemu_sem_wait(&p->sem); =20 @@ -4616,6 +4636,8 @@ static int multiRDMA_save_setup(const char *host_port= , Error **errp) multiRDMA_send_state->params =3D g_new0(MultiRDMASendParams, thread_count); atomic_set(&multiRDMA_send_state->count, 0); + atomic_set(&multiRDMA_send_state->reg_mr_channels, 0); + qemu_mutex_init(&multiRDMA_send_state->mutex_sync); qemu_sem_init(&multiRDMA_send_state->sem_sync, 0); =20 for (i =3D 0; i < thread_count; i++) { @@ -4714,6 +4736,7 @@ int multiRDMA_save_cleanup(void) g_free(multiRDMA_send_state->params[i].rdma); } =20 + qemu_mutex_destroy(&multiRDMA_send_state->mutex_sync); qemu_sem_destroy(&multiRDMA_send_state->sem_sync); g_free(multiRDMA_send_state); multiRDMA_send_state =3D NULL; --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564299; cv=none; d=zohomail.com; s=zohoarc; b=GExBAFdtx+6kQyj0blBiJTdk17NUUjdmQrhgByvvuM1IuZlB/l5NGt9XcwYvVlTavOvg5uZiQhbw5UL1EeXUY+EqrDrXgSBVe8EnnfXNSYMXOSQZCQsL4rpICBQMmvbiEXb367fhQasKkxZicv2IYw2MDgBI7BXfEx2I0GYHf+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HadsM4r919o/Q/N7uZvom+0Mk0F9p6CSeXtlcYm8h4s=; b=hlu/B1dq91lQQbmPwtDdrJpewFj+lERSc1MlTu2qwnJsQlHjfHAe5tukczwbOojLCTDw+T2mROQEhGTuXL7dECex3Hip0rAKeVAHON3HAfDXrVN9BZEEkmwq6s+6Wfop2g+hCjS85y9mk1Qnh5UFO5Zhd7z6AIn8tbPADO8Quq0= ARC-Authentication-Results: i=1; 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 1578564299820768.6852844046076; Thu, 9 Jan 2020 02:04:59 -0800 (PST) Received: from localhost ([::1]:57702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUgU-0003u7-A5 for importer@patchew.org; Thu, 09 Jan 2020 05:04:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42491) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvE-00010T-F8 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvB-0001Mg-Sz for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:52 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34922 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvB-0001Gr-Dk for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:49 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E5A532BA8A28ED572297; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:37 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 10/12] migration/rdma: use multiRDMA to send RAM block for rdma-pin-all mode Date: Thu, 9 Jan 2020 12:59:20 +0800 Message-ID: <20200109045922.904-11-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Send the RAM block through MultiRDMA channels for using rdma-pin-all option, and we choose the channel to send data through polling the MultiRDMA thread. Signed-off-by: fengzhimin --- migration/rdma.c | 66 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 425dfa709d..36261f1fc8 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -427,6 +427,8 @@ typedef struct { QEMUFile *file; /* sem where to wait for more work */ QemuSemaphore sem; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; /* this mutex protects the following parameters */ QemuMutex mutex; /* is this channel thread running */ @@ -439,6 +441,8 @@ struct { MultiRDMASendParams *params; /* number of created threads */ int count; + /* index of current RDMA channels */ + int current_RDMA_index; /* this mutex protects the following parameters */ QemuMutex mutex_sync; /* number of registered multiRDMA channels */ @@ -2043,6 +2047,18 @@ static int qemu_rdma_exchange_recv(RDMAContext *rdma= , RDMAControlHeader *head, return 0; } =20 +/* + * Get the multiRDMA channel used to send data. + */ +static int get_multiRDMA_channel(void) +{ + int thread_count =3D migrate_multiRDMA_channels(); + multiRDMA_send_state->current_RDMA_index++; + multiRDMA_send_state->current_RDMA_index %=3D thread_count; + + return multiRDMA_send_state->current_RDMA_index; +} + /* * Write an actual chunk of memory using RDMA. * @@ -2068,6 +2084,16 @@ static int qemu_rdma_write_one(QEMUFile *f, RDMACont= ext *rdma, .repeat =3D 1, }; =20 + if (migrate_use_multiRDMA() && + migrate_use_rdma_pin_all()) { + /* The multiRDMA threads only send ram block */ + if (strcmp(block->block_name, "mach-virt.ram") =3D=3D 0) { + int channel =3D get_multiRDMA_channel(); + rdma =3D multiRDMA_send_state->params[channel].rdma; + block =3D &(rdma->local_ram_blocks.block[current_index]); + } + } + retry: sge.addr =3D (uintptr_t)(block->local_host_addr + (current_addr - block->offset)); @@ -2285,8 +2311,22 @@ 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_multiRDMA() && + migrate_use_rdma_pin_all()) { + /* The multiRDMA threads only send ram block */ + RDMALocalBlock *block =3D NULL; + block =3D &(rdma->local_ram_blocks.block[rdma->current_index]); + if (strcmp(block->block_name, "mach-virt.ram") =3D=3D 0) { + int current_RDMA =3D multiRDMA_send_state->current_RDMA_in= dex; + multiRDMA_send_state->params[current_RDMA].rdma->nb_sent++; + } else { + rdma->nb_sent++; + trace_qemu_rdma_write_flush(rdma->nb_sent); + } + } else { + rdma->nb_sent++; + trace_qemu_rdma_write_flush(rdma->nb_sent); + } } =20 rdma->current_length =3D 0; @@ -4015,11 +4055,15 @@ 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_multiRDMA()) { - /* Inform src send_thread to send FINISHED signal */ + /* + * Inform src send_thread to send FINISHED signal. + * Wait for multiRDMA send threads to poll the CQE. + */ int i; int thread_count =3D migrate_multiRDMA_channels(); for (i =3D 0; i < thread_count; i++) { qemu_sem_post(&multiRDMA_send_state->params[i].sem); + qemu_sem_wait(&multiRDMA_send_state->params[i].sem_sync); } } =20 @@ -4592,12 +4636,25 @@ static void *multiRDMA_send_thread(void *opaque) } qemu_mutex_unlock(&p->mutex); =20 + /* To complete polling(CQE) */ + while (rdma->nb_sent) { + ret =3D qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, N= ULL); + if (ret < 0) { + error_report("multiRDMA migration: " + "complete polling error!"); + return NULL; + } + } + /* Send FINISHED to the destination */ head.type =3D RDMA_CONTROL_REGISTER_FINISHED; ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NUL= L); if (ret < 0) { return NULL; } + + /* sync main thread */ + qemu_sem_post(&p->sem_sync); } =20 qemu_mutex_lock(&p->mutex); @@ -4637,6 +4694,7 @@ static int multiRDMA_save_setup(const char *host_port= , Error **errp) thread_count); atomic_set(&multiRDMA_send_state->count, 0); atomic_set(&multiRDMA_send_state->reg_mr_channels, 0); + atomic_set(&multiRDMA_send_state->current_RDMA_index, 0); qemu_mutex_init(&multiRDMA_send_state->mutex_sync); qemu_sem_init(&multiRDMA_send_state->sem_sync, 0); =20 @@ -4665,6 +4723,7 @@ static int multiRDMA_save_setup(const char *host_port= , Error **errp) f =3D qemu_fopen_rdma(multiRDMA_send_state->params[i].rdma, "wb"); qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); + qemu_sem_init(&p->sem_sync, 0); p->quit =3D false; p->id =3D i; p->running =3D true; @@ -4730,6 +4789,7 @@ int multiRDMA_save_cleanup(void) MultiRDMASendParams *p =3D &multiRDMA_send_state->params[i]; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem); + qemu_sem_destroy(&p->sem_sync); g_free(p->name); p->name =3D NULL; qemu_rdma_cleanup(multiRDMA_send_state->params[i].rdma); --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564130; cv=none; d=zohomail.com; s=zohoarc; b=YZxkUvS8d0VNzVW+uQuBW6oMFS/uFB3cnj6mpTyR2Vqw+t5K1KTu8e3NoerdQfhgWR5hAVpixp1bOh1T7t1l16wZk7zEgcOCkItZkFzKfbkT9scBPvqMS/XI4jiLekrcb3q8KYxBruxQ3YRIrgNVvoLI8jC5nH/YS5G1pnne6T8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564130; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0sSeztZLH8V9KPRYdKkY8EXM74FGB3Qk7tboYBJuh5I=; b=N+FIDlABk7i+aQ405PWbCJigMsfgXcRc/+GL8ms3mXqvngkHNGo57cmu4mhAk7FdJ9bh7MMz3TjhNaiWeVnyrqp095gxcdkwDn4HKyJI5eycdB6BLZXy6luyzqXDMkfp/PF0kyTWaQ3aUv/PC/aKEzfY1H9lOSJrxSdjmjV++T8= ARC-Authentication-Results: i=1; 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 1578564130205220.16792766940603; Thu, 9 Jan 2020 02:02:10 -0800 (PST) Received: from localhost ([::1]:57672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUdk-0007tA-DE for importer@patchew.org; Thu, 09 Jan 2020 05:02:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42447) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvE-00010N-5w for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvC-0001Nw-63 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:52 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34924 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvB-0001Gt-Fg for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:50 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E03C13A71F11B0D96E00; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:37 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 11/12] migration/rdma: use multiRDMA to send RAM block for NOT rdma-pin-all mode Date: Thu, 9 Jan 2020 12:59:21 +0800 Message-ID: <20200109045922.904-12-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin Signed-off-by: fengzhimin --- migration/rdma.c | 109 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 36261f1fc8..0a150099e2 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2084,8 +2084,7 @@ static int qemu_rdma_write_one(QEMUFile *f, RDMAConte= xt *rdma, .repeat =3D 1, }; =20 - if (migrate_use_multiRDMA() && - migrate_use_rdma_pin_all()) { + if (migrate_use_multiRDMA()) { /* The multiRDMA threads only send ram block */ if (strcmp(block->block_name, "mach-virt.ram") =3D=3D 0) { int channel =3D get_multiRDMA_channel(); @@ -2311,8 +2310,7 @@ static int qemu_rdma_write_flush(QEMUFile *f, RDMACon= text *rdma) } =20 if (ret =3D=3D 0) { - if (migrate_use_multiRDMA() && - migrate_use_rdma_pin_all()) { + if (migrate_use_multiRDMA()) { /* The multiRDMA threads only send ram block */ RDMALocalBlock *block =3D NULL; block =3D &(rdma->local_ram_blocks.block[rdma->current_index]); @@ -4234,12 +4232,24 @@ err: =20 static int qemu_multiRDMA_registration_handle(void *opaque) { + RDMAControlHeader reg_resp =3D { .len =3D sizeof(RDMARegisterResult), + .type =3D RDMA_CONTROL_REGISTER_RESULT, + .repeat =3D 0, + }; RDMAControlHeader blocks =3D { .type =3D RDMA_CONTROL_RAM_BLOCKS_RESUL= T, .repeat =3D 1 }; MultiRDMARecvParams *p =3D opaque; RDMAContext *rdma =3D p->rdma; RDMALocalBlocks *local =3D &rdma->local_ram_blocks; RDMAControlHeader head; + RDMARegister *reg, *registers; + RDMACompress *comp; + RDMARegisterResult *reg_result; + static RDMARegisterResult results[RDMA_CONTROL_MAX_COMMANDS_PER_MESSAG= E]; + RDMALocalBlock *block; + void *host_addr; + int idx =3D 0; + int count =3D 0; int ret =3D 0; int i =3D 0; =20 @@ -4260,8 +4270,28 @@ static int qemu_multiRDMA_registration_handle(void *= opaque) } =20 switch (head.type) { + case RDMA_CONTROL_COMPRESS: + comp =3D (RDMACompress *) rdma->wr_data[idx].control_curr; + network_to_compress(comp); + + if (comp->block_idx >=3D rdma->local_ram_blocks.nb_blocks) { + error_report("rdma: 'compress' bad block index %u (vs %d)", + (unsigned int)comp->block_idx, + rdma->local_ram_blocks.nb_blocks); + ret =3D -EIO; + goto out; + } + block =3D &(rdma->local_ram_blocks.block[comp->block_idx]); + + host_addr =3D block->local_host_addr + + (comp->offset - block->offset); + + ram_handle_compressed(host_addr, comp->value, comp->length); + break; + case RDMA_CONTROL_REGISTER_FINISHED: goto out; + case RDMA_CONTROL_RAM_BLOCKS_REQUEST: qsort(rdma->local_ram_blocks.block, rdma->local_ram_blocks.nb_blocks, @@ -4310,8 +4340,79 @@ static int qemu_multiRDMA_registration_handle(void *= opaque) error_report("rdma migration: error sending remote info"); goto out; } + break; + + case RDMA_CONTROL_REGISTER_REQUEST: + reg_resp.repeat =3D head.repeat; + registers =3D (RDMARegister *) rdma->wr_data[idx].control_curr; =20 + for (count =3D 0; count < head.repeat; count++) { + uint64_t chunk; + uint8_t *chunk_start, *chunk_end; + + reg =3D ®isters[count]; + network_to_register(reg); + + reg_result =3D &results[count]; + + if (reg->current_index >=3D rdma->local_ram_blocks.nb_bloc= ks) { + error_report("rdma: 'register' bad block index %u (vs = %d)", + (unsigned int)reg->current_index, + rdma->local_ram_blocks.nb_blocks); + ret =3D -ENOENT; + goto out; + } + block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); + if (block->is_ram_block) { + if (block->offset > reg->key.current_addr) { + error_report("rdma: bad register address for block= %s" + " offset: %" PRIx64 " current_addr: %" PRI= x64, + block->block_name, block->offset, + reg->key.current_addr); + ret =3D -ERANGE; + goto out; + } + host_addr =3D (block->local_host_addr + + (reg->key.current_addr - block->offset)); + chunk =3D ram_chunk_index(block->local_host_addr, + (uint8_t *) host_addr); + } else { + chunk =3D reg->key.chunk; + host_addr =3D block->local_host_addr + + (reg->key.chunk * (1UL << RDMA_REG_CHUNK_SHIFT)); + /* Check for particularly bad chunk value */ + if (host_addr < (void *)block->local_host_addr) { + error_report("rdma: bad chunk for block %s" + " chunk: %" PRIx64, + block->block_name, reg->key.chunk); + ret =3D -ERANGE; + goto out; + } + } + chunk_start =3D ram_chunk_start(block, chunk); + chunk_end =3D ram_chunk_end(block, chunk + reg->chunks); + if (qemu_rdma_register_and_get_keys(rdma, block, + (uintptr_t)host_addr, NULL, ®_result->rkey, + chunk, chunk_start, chunk_end)) { + error_report("cannot get rkey"); + ret =3D -EINVAL; + goto out; + } + + reg_result->host_addr =3D (uintptr_t)block->local_host_add= r; + + result_to_network(reg_result); + } + + ret =3D qemu_rdma_post_send_control(rdma, + (uint8_t *) results, ®_resp); + + if (ret < 0) { + error_report("Failed to send control buffer"); + goto out; + } break; + default: error_report("Unknown control message %s", control_desc(head.t= ype)); ret =3D -EIO; --=20 2.19.1 From nobody Sun Apr 28 01:03:03 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 ARC-Seal: i=1; a=rsa-sha256; t=1578564462; cv=none; d=zohomail.com; s=zohoarc; b=FdQt70IQx6H1UWG+TyMhAo0v0Ke24CfJJkVyIJkIdN8QUg6mL4w2+arotQ7/qJCmh2883M5t7Kf2a5RXqi9lQKM82cqXKkOkKm0ThLXpK3vkAU49Hq8oDv7QVGNxQW56TcjPEmlCIiaLLUxNya/S164dS/h/ZUGu1fLfIZoAo8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578564462; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mb1VhsyLza+rb/vQBkhF+5LAGWEJqkmxqUWElzO7w18=; b=RbHcj3SwlxAWEKrrqcxVTrZQA8sctSnOakTxZ0obkLBP5KkEOlXNLjkkNO+kacSggG2xAGk3my66D+9woJl86kGzQS+JJsyphAMW7HqUAplRADLDsMUOiyGbE9Vum8GE/N5gGvqgqKJ3zVJ2XUx3EjW4iPNUGJWS3PUhEM1+6Vk= ARC-Authentication-Results: i=1; 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 1578564462303936.0361286684347; Thu, 9 Jan 2020 02:07:42 -0800 (PST) Received: from localhost ([::1]:57776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipUj7-0007iW-5A for importer@patchew.org; Thu, 09 Jan 2020 05:07:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43186) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipPvI-00011w-Dn for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipPvE-0001Sq-IZ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:56 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:34978 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ipPvD-0001Ns-Qs for qemu-devel@nongnu.org; Wed, 08 Jan 2020 23:59:52 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EFA7C28F611D0299523C; Thu, 9 Jan 2020 12:59:45 +0800 (CST) Received: from huawei.com (10.173.220.198) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 9 Jan 2020 12:59:38 +0800 From: Zhimin Feng To: , , , Subject: [PATCH RFC 12/12] migration/rdma: only register the virt-ram block for MultiRDMA Date: Thu, 9 Jan 2020 12:59:22 +0800 Message-ID: <20200109045922.904-13-fengzhimin1@huawei.com> X-Mailer: git-send-email 2.24.0.windows.2 In-Reply-To: <20200109045922.904-1-fengzhimin1@huawei.com> References: <20200109045922.904-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.32 X-Mailman-Approved-At: Thu, 09 Jan 2020 04:56:54 -0500 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, fengzhimin , 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" From: fengzhimin The virt-ram block is sent by MultiRDMA, so we only register it for MultiRDMA channels and main channel don't register the virt-ram block. Signed-off-by: fengzhimin --- migration/rdma.c | 140 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 112 insertions(+), 28 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 0a150099e2..1477fd509b 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -618,7 +618,9 @@ 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)); + int (*callback)(RDMAContext *rdma, + uint8_t id), + uint8_t id); =20 static inline uint64_t ram_chunk_index(const uint8_t *start, const uint8_t *host) @@ -1198,24 +1200,81 @@ static int qemu_rdma_alloc_qp(RDMAContext *rdma) return 0; } =20 -static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma) +/* + * Parameters: + * @id =3D=3D UNUSED_ID : + * This means that we register memory for the main RDMA channel, + * the main RDMA channel don't register the mach-virt.ram block + * when we use multiRDMA method to migrate. + * + * @id =3D=3D 0 or id =3D=3D 1 or ... : + * This means that we register memory for the multiRDMA channels, + * the multiRDMA channels only register memory for the mach-virt.ram + * block when we use multiRDAM method to migrate. + */ +static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma, uint8_t id) { int i; RDMALocalBlocks *local =3D &rdma->local_ram_blocks; =20 - for (i =3D 0; i < local->nb_blocks; i++) { - local->block[i].mr =3D - ibv_reg_mr(rdma->pd, - local->block[i].local_host_addr, - local->block[i].length, - IBV_ACCESS_LOCAL_WRITE | - IBV_ACCESS_REMOTE_WRITE - ); - if (!local->block[i].mr) { - perror("Failed to register local dest ram block!\n"); - break; + if (migrate_use_multiRDMA()) { + if (id =3D=3D UNUSED_ID) { + for (i =3D 0; i < local->nb_blocks; i++) { + /* main RDMA channel don't register the mach-virt.ram bloc= k */ + if (strcmp(local->block[i].block_name, "mach-virt.ram") = =3D=3D 0) { + continue; + } + + local->block[i].mr =3D + ibv_reg_mr(rdma->pd, + local->block[i].local_host_addr, + local->block[i].length, + IBV_ACCESS_LOCAL_WRITE | + IBV_ACCESS_REMOTE_WRITE + ); + if (!local->block[i].mr) { + perror("Failed to register local dest ram block!\n"); + break; + } + rdma->total_registrations++; + } + } else { + for (i =3D 0; i < local->nb_blocks; i++) { + /* + * The multiRDAM channels only register + * the mach-virt.ram block + */ + if (strcmp(local->block[i].block_name, "mach-virt.ram") = =3D=3D 0) { + local->block[i].mr =3D + ibv_reg_mr(rdma->pd, + local->block[i].local_host_addr, + local->block[i].length, + IBV_ACCESS_LOCAL_WRITE | + IBV_ACCESS_REMOTE_WRITE + ); + if (!local->block[i].mr) { + perror("Failed to register local dest ram block!\n= "); + break; + } + rdma->total_registrations++; + } + } + } + } else { + for (i =3D 0; i < local->nb_blocks; i++) { + local->block[i].mr =3D + ibv_reg_mr(rdma->pd, + local->block[i].local_host_addr, + local->block[i].length, + IBV_ACCESS_LOCAL_WRITE | + IBV_ACCESS_REMOTE_WRITE + ); + if (!local->block[i].mr) { + perror("Failed to register local dest ram block!\n"); + break; + } + rdma->total_registrations++; } - rdma->total_registrations++; } =20 if (i >=3D local->nb_blocks) { @@ -1223,8 +1282,10 @@ static int qemu_rdma_reg_whole_ram_blocks(RDMAContex= t *rdma) } =20 for (i--; i >=3D 0; i--) { - ibv_dereg_mr(local->block[i].mr); - rdma->total_registrations--; + if (local->block[i].mr) { + ibv_dereg_mr(local->block[i].mr); + rdma->total_registrations--; + } } =20 return -1; @@ -1446,7 +1507,7 @@ static int qemu_rdma_unregister_waiting(RDMAContext *= rdma) reg.key.chunk =3D chunk; register_to_network(rdma, ®); ret =3D qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®, - &resp, NULL, NULL); + &resp, NULL, NULL, UNUSED_ID); if (ret < 0) { return ret; } @@ -1915,11 +1976,17 @@ static void qemu_rdma_move_header(RDMAContext *rdma= , int idx, * The extra (optional) response is used during registration to us from ha= ving * to perform an *additional* exchange of message just to provide a respon= se by * instead piggy-backing on the acknowledgement. + * + * Parameters: + * @id : callback function need two parameters, id is the second parame= ter. + * */ static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *h= ead, uint8_t *data, RDMAControlHeader *resp, int *resp_idx, - int (*callback)(RDMAContext *rdma)) + int (*callback)(RDMAContext *rdma, + uint8_t id), + uint8_t id) { int ret =3D 0; =20 @@ -1973,7 +2040,7 @@ static int qemu_rdma_exchange_send(RDMAContext *rdma,= RDMAControlHeader *head, if (resp) { if (callback) { trace_qemu_rdma_exchange_send_issue_callback(); - ret =3D callback(rdma); + ret =3D callback(rdma, id); if (ret < 0) { return ret; } @@ -2168,7 +2235,7 @@ retry: =20 compress_to_network(rdma, &comp); ret =3D qemu_rdma_exchange_send(rdma, &head, - (uint8_t *) &comp, NULL, NULL, NULL); + (uint8_t *) &comp, NULL, NULL, NULL, UNUSE= D_ID); =20 if (ret < 0) { return -EIO; @@ -2195,7 +2262,7 @@ retry: =20 register_to_network(rdma, ®); ret =3D qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®, - &resp, ®_result_idx, NULL); + &resp, ®_result_idx, NULL, UNUSED_I= D); if (ret < 0) { return ret; } @@ -2828,7 +2895,8 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, head.len =3D len; head.type =3D RDMA_CONTROL_QEMU_FILE; =20 - ret =3D qemu_rdma_exchange_send(rdma, &head, data, NULL, NULL,= NULL); + ret =3D qemu_rdma_exchange_send(rdma, &head, data, NULL, + NULL, NULL, UNUSED_ID); =20 if (ret < 0) { rdma->error_state =3D ret; @@ -3660,7 +3728,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f,= void *opaque) } =20 if (rdma->pin_all) { - ret =3D qemu_rdma_reg_whole_ram_blocks(rdma); + ret =3D qemu_rdma_reg_whole_ram_blocks(rdma, UNUSED_ID); if (ret) { error_report("rdma migration: error dest " "registering ram blocks"); @@ -3675,6 +3743,15 @@ static int qemu_rdma_registration_handle(QEMUFile *f= , void *opaque) * their "local" descriptions with what was sent. */ for (i =3D 0; i < local->nb_blocks; i++) { + /* + * use the main RDMA channel to deliver the block of device + * use the multiRDMA channels to deliver the RAMBlock + */ + if (migrate_use_multiRDMA() && + strcmp(local->block[i].block_name, "mach-virt.ram") = =3D=3D 0) { + continue; + } + rdma->dest_blocks[i].remote_host_addr =3D (uintptr_t)(local->block[i].local_host_addr); =20 @@ -3992,7 +4069,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, */ ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, &resp, ®_result_idx, rdma->pin_all ? - qemu_rdma_reg_whole_ram_blocks : NULL); + qemu_rdma_reg_whole_ram_blocks : NULL, UNUSED_ID); if (ret < 0) { ERROR(errp, "receiving remote info!"); return ret; @@ -4025,6 +4102,11 @@ static int qemu_rdma_registration_stop(QEMUFile *f, = void *opaque, memcpy(rdma->dest_blocks, rdma->wr_data[reg_result_idx].control_curr, resp.len); for (i =3D 0; i < nb_dest_blocks; i++) { + if (migrate_use_multiRDMA() && + strcmp(local->block[i].block_name, "mach-virt.ram") =3D=3D= 0) { + continue; + } + network_to_dest_block(&rdma->dest_blocks[i]); =20 /* We require that the blocks are in the same order */ @@ -4050,7 +4132,8 @@ static int qemu_rdma_registration_stop(QEMUFile *f, v= oid *opaque, trace_qemu_rdma_registration_stop(flags); =20 head.type =3D RDMA_CONTROL_REGISTER_FINISHED; - ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL); + ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, + NULL, NULL, UNUSED_ID); =20 if (migrate_use_multiRDMA()) { /* @@ -4298,7 +4381,7 @@ static int qemu_multiRDMA_registration_handle(void *o= paque) sizeof(RDMALocalBlock), dest_ram_sort_func); =20 if (rdma->pin_all) { - ret =3D qemu_rdma_reg_whole_ram_blocks(rdma); + ret =3D qemu_rdma_reg_whole_ram_blocks(rdma, p->id); if (ret) { error_report("rdma migration: error dest " "registering ram blocks"); @@ -4680,7 +4763,7 @@ static void *multiRDMA_send_thread(void *opaque) =20 ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, &resp, ®_result_idx, rdma->pin_all ? - qemu_rdma_reg_whole_ram_blocks : NULL); + qemu_rdma_reg_whole_ram_blocks : NULL, p->id); if (ret < 0) { return NULL; } @@ -4749,7 +4832,8 @@ static void *multiRDMA_send_thread(void *opaque) =20 /* Send FINISHED to the destination */ head.type =3D RDMA_CONTROL_REGISTER_FINISHED; - ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NUL= L); + ret =3D qemu_rdma_exchange_send(rdma, &head, NULL, NULL, + NULL, NULL, p->id); if (ret < 0) { return NULL; } --=20 2.19.1