From nobody Tue Nov 26 16:47:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706697234; cv=none; d=zohomail.com; s=zohoarc; b=ZqeeBUGdB+bXNMiGFatH5HEtgywAY/DRz6tz5+uVv0dNIFBFQgIdWzqkXOhK+lc4/zKVPZ+qxdJtH2qUWHnMW+0swy/M8m5bqkyIGkAjcdh2VZ00LRa9PS9KP5Zqxgc40ctLva5D2LwD6jc/+AEq+LbSKVv0hZMLUwIAi0e5h/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697234; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rIA1XY+uOOYAsKHWK0tJQW8VgD2YTa//k+OTB1l/q0U=; b=Jp9OaIa7tIn/NNhdvVZdcV+50C79yl4C//1F822xnAF7skL3A4T/qVql7WK2A4H2CjK+ZrTmQDZKkvgDhMBlViJ9R9QjDUsuDfCq0tBv7g5XRuZzNLh88jWIOM3sc7ag1tdg7cbSwvrGG40GYAT8QunyaUd4uu68JmgZa6/qRW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706697234026876.3974022625061; Wed, 31 Jan 2024 02:33:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tM-0006SQ-E7; Wed, 31 Jan 2024 05:32:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7tI-0006NE-L3 for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7tG-0005i6-Mm for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:24 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-K_Uhcw_MNEujR9AxGPtkcw-1; Wed, 31 Jan 2024 05:32:19 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 523A31064C64; Wed, 31 Jan 2024 10:32:19 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70B5210EA6; Wed, 31 Jan 2024 10:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rIA1XY+uOOYAsKHWK0tJQW8VgD2YTa//k+OTB1l/q0U=; b=GEXjKZVvO4nH1CTRLcbuorSU+Lvee+lhCIKZMNxzTEptuDbJ7C9DKLeaJtI9N5NYr6JlFo SUdnEq7ezHKyOSrEoQxG6bCUwkd5rYG4UonhzcrIFKC2VCLlQj8ileHEGd4XOf+Ya84hMV VPMJYhvKvKpBnt1zVe/h5uR3ChJZY44= X-MC-Unique: K_Uhcw_MNEujR9AxGPtkcw-1 From: peterx@redhat.com To: qemu-devel@nongnu.org Cc: Bryan Zhang , Prasad Pandit , Fabiano Rosas , peterx@redhat.com, Yuan Liu , Avihai Horon , Hao Xiang Subject: [PATCH 13/14] migration/multifd: Move header prepare/fill into send_prepare() Date: Wed, 31 Jan 2024 18:31:10 +0800 Message-ID: <20240131103111.306523-14-peterx@redhat.com> In-Reply-To: <20240131103111.306523-1-peterx@redhat.com> References: <20240131103111.306523-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706697234971100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu This patch redefines the interfacing of ->send_prepare(). It further simplifies multifd_send_thread() especially on zero copy. Now with the new interface, we require the hook to do all the work for preparing the IOVs to send. After it's completed, the IOVs should be ready to be dumped into the specific multifd QIOChannel later. So now the API looks like: p->pages -----------> send_prepare() -------------> IOVs This also prepares for the case where the input can be extended to even not any p->pages. But that's for later. This patch will achieve similar goal of what Fabiano used to propose here: https://lore.kernel.org/r/20240126221943.26628-1-farosas@suse.de However the send() interface may not be necessary. I'm boldly attaching a "Co-developed-by" for Fabiano. Co-developed-by: Fabiano Rosas Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.h | 1 + migration/multifd-zlib.c | 4 ++++ migration/multifd-zstd.c | 4 ++++ migration/multifd.c | 45 ++++++++++++++++++++-------------------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 4ec005f53f..34a2ecb9f4 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -208,6 +208,7 @@ typedef struct { } MultiFDMethods; =20 void multifd_register_ops(int method, MultiFDMethods *ops); +void multifd_send_fill_packet(MultiFDSendParams *p); =20 static inline void multifd_send_prepare_header(MultiFDSendParams *p) { diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 100809abc1..012e3bdea1 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -123,6 +123,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) int ret; uint32_t i; =20 + multifd_send_prepare_header(p); + for (i =3D 0; i < pages->num; i++) { uint32_t available =3D z->zbuff_len - out_size; int flush =3D Z_NO_FLUSH; @@ -172,6 +174,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) p->next_packet_size =3D out_size; p->flags |=3D MULTIFD_FLAG_ZLIB; =20 + multifd_send_fill_packet(p); + return 0; } =20 diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index 2023edd8cc..dc8fe43e94 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -118,6 +118,8 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) int ret; uint32_t i; =20 + multifd_send_prepare_header(p); + z->out.dst =3D z->zbuff; z->out.size =3D z->zbuff_len; z->out.pos =3D 0; @@ -161,6 +163,8 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) p->next_packet_size =3D z->out.pos; p->flags |=3D MULTIFD_FLAG_ZSTD; =20 + multifd_send_fill_packet(p); + return 0; } =20 diff --git a/migration/multifd.c b/migration/multifd.c index 1b0035787e..0f22646f95 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -88,7 +88,17 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Er= ror **errp) */ static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) { + bool use_zero_copy_send =3D migrate_zero_copy_send(); MultiFDPages_t *pages =3D p->pages; + int ret; + + if (!use_zero_copy_send) { + /* + * Only !zero_copy needs the header in IOV; zerocopy will + * send it separately. + */ + multifd_send_prepare_header(p); + } =20 for (int i =3D 0; i < pages->num; i++) { p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; @@ -98,6 +108,18 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Er= ror **errp) =20 p->next_packet_size =3D pages->num * p->page_size; p->flags |=3D MULTIFD_FLAG_NOCOMP; + + multifd_send_fill_packet(p); + + if (use_zero_copy_send) { + /* Send header first, without zerocopy */ + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, errp); + if (ret !=3D 0) { + return -1; + } + } + return 0; } =20 @@ -266,7 +288,7 @@ static void multifd_pages_clear(MultiFDPages_t *pages) g_free(pages); } =20 -static void multifd_send_fill_packet(MultiFDSendParams *p) +void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; MultiFDPages_t *pages =3D p->pages; @@ -683,7 +705,6 @@ static void *multifd_send_thread(void *opaque) MigrationThread *thread =3D NULL; Error *local_err =3D NULL; int ret =3D 0; - bool use_zero_copy_send =3D migrate_zero_copy_send(); =20 thread =3D migration_threads_add(p->name, qemu_get_thread_id()); =20 @@ -708,15 +729,6 @@ static void *multifd_send_thread(void *opaque) MultiFDPages_t *pages =3D p->pages; =20 p->iovs_num =3D 0; - - if (!use_zero_copy_send) { - /* - * Only !zero_copy needs the header in IOV; zerocopy will - * send it separately. - */ - multifd_send_prepare_header(p); - } - assert(pages->num); =20 ret =3D multifd_send_state->ops->send_prepare(p, &local_err); @@ -725,17 +737,6 @@ static void *multifd_send_thread(void *opaque) break; } =20 - multifd_send_fill_packet(p); - - if (use_zero_copy_send) { - /* Send header first, without zerocopy */ - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret !=3D 0) { - break; - } - } - ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, 0, p->write_flags, &local_er= r); if (ret !=3D 0) { --=20 2.43.0