From nobody Tue Nov 26 14:24:04 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=1706697212; cv=none; d=zohomail.com; s=zohoarc; b=Q3CotPYNCb9QfbsMB8IaUL0GaYwaUgTEqxv+Cznc6VhhU0Vimkgnu2lhMg9av/Z5LSq3YrdPszPRjtyz8e4WWhJxtoel6Syh3P+Q80DTw6SROTO9TvXLNgbjZ7aRNoKeBhs6ZOElyvaZd4/0AbDL5bhTuJEoRHdoC8tzMkWZfRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697212; 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=qzb46DUZSTMJoNeVIqZsw/shF+U8HEgAIFp5xpwtBDY=; b=FUXjVmWcljvefRIz5+X05OBs7WQg+JJu+K/njgf/mx1eB23nDt6fStAjC871rxN9qNI7KzaAYJc44LfwfTvpEjbL9abHvT8zd9SonlQhGYEnHbmy1KWrckNimojp45BlxnGDG5GIc4Lv3xiJ8hoig+xeX9DqEA8U22yQ2neufLs= 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 1706697212421563.4480311952278; Wed, 31 Jan 2024 02:33:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sU-00054y-58; Wed, 31 Jan 2024 05:31:34 -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 1rV7sQ-00052L-FH for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7sO-0005Zy-3A for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:29 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-B2wYEq4VNMWf3OzQbJOBHA-1; Wed, 31 Jan 2024 05:31:23 -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 379861C068D3; Wed, 31 Jan 2024 10:31:23 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3695D1BDB1; Wed, 31 Jan 2024 10:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697087; 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=qzb46DUZSTMJoNeVIqZsw/shF+U8HEgAIFp5xpwtBDY=; b=FpMSR3jH7HLKvU/LPpw9tU+RUi0hjc4ignY0D2Uc52fINLzO29W08LRmGrr66R45rA7L+g KENISHYf64qmf6RWPYAF83OH4xs6LW3euEFLFDYJ8QDynVQPy+XKEwMLDx1wX7TIow1pqL dy3rV82Vs7/Dzi8y10Su6mOirTRvQQE= X-MC-Unique: B2wYEq4VNMWf3OzQbJOBHA-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 01/14] migration/multifd: Drop stale comment for multifd zero copy Date: Wed, 31 Jan 2024 18:30:58 +0800 Message-ID: <20240131103111.306523-2-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.129.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_H4=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: 1706697212906100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu We've already done that with multifd_flush_after_each_section, for multifd in general. Drop the stale "TODO-like" comment. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/multifd.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 25cbc6dc6b..eee2586770 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -598,17 +598,6 @@ int multifd_send_sync_main(void) } } =20 - /* - * When using zero-copy, it's necessary to flush the pages before any = of - * the pages can be sent again, so we'll make sure the new version of = the - * pages will always arrive _later_ than the old pages. - * - * Currently we achieve this by flushing the zero-page requested writes - * per ram iteration, but in the future we could potentially optimize = it - * to be less frequent, e.g. only after we finished one whole scanning= of - * all the dirty bitmaps. - */ - flush_zero_copy =3D migrate_zero_copy_send(); =20 for (i =3D 0; i < migrate_multifd_channels(); i++) { --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697115; cv=none; d=zohomail.com; s=zohoarc; b=D5F75bdpokFJLNov8O71GCz+HNcgy5WPSPTGKZxt6MxnEGCE7KmfJCnj0zO9CeVJzVjdlyGS0jHOV2MXHbr8XZmFR52THAu2SUp0lYmM9j2rlbf0MSWV0NCdlk8lXnjQBbktSCSvufuBVq7/q45B7V5dSAdWaj4zHs6Y2saDtws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697115; 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=SMVA61FG00o5F2sgpzvPDSC3j1syRcvDYKyMGntilGw=; b=MRotsO3l0daeFdIcrlhwobTokhRGcLeeMWfyp4sjCkPdifIoAoq5+Yl6MCG9AQ2I3eekJuOIVGPzBnwVjfR5wuuqg8YTNuTuK0hK7S3sSurDPgtoqIrEfKAc9A6I2kuAsgOgSMa2rBjJxh/ZKmjuAZj2Q4UEyN0kg4O6yMfFQWk= 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 1706697115286460.86803413220343; Wed, 31 Jan 2024 02:31:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sU-00055V-R8; Wed, 31 Jan 2024 05:31:34 -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 1rV7sS-000542-La for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7sQ-0005aP-W6 for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:32 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-Ut7W_kosN9S4j-kDh3G0eQ-1; Wed, 31 Jan 2024 05:31:28 -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 E3B431C05154; Wed, 31 Jan 2024 10:31:27 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 018801BDB1; Wed, 31 Jan 2024 10:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697090; 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=SMVA61FG00o5F2sgpzvPDSC3j1syRcvDYKyMGntilGw=; b=dRWjTHXnEcrLbQCOhUKLF+PYn3LEhS5/tfXHnmGvB4WJyhbX4Of5ds0PtuI0y3/yudD8Fa JZsOsleq8yVlk35lMx43Hm3EB+p4nvXFu14H6nu3IioKkvB1O4SH7gvNAnW7fYJXFR6Mi5 BKTCWRyk9GxIyeUt9EJlIcknGRZMX6A= X-MC-Unique: Ut7W_kosN9S4j-kDh3G0eQ-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 02/14] migration/multifd: multifd_send_kick_main() Date: Wed, 31 Jan 2024 18:30:59 +0800 Message-ID: <20240131103111.306523-3-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.129.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_H4=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: 1706697116999100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu When a multifd sender thread hit errors, it always needs to kick the main thread by kicking all the semaphores that it can be waiting upon. Provide a helper for it and deduplicate the code. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/multifd.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index eee2586770..b8d2c96533 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -372,6 +372,18 @@ struct { MultiFDMethods *ops; } *multifd_send_state; =20 +/* + * The migration thread can wait on either of the two semaphores. This + * function can be used to kick the main thread out of waiting on either of + * them. Should mostly only be called when something wrong happened with + * the current multifd send thread. + */ +static void multifd_send_kick_main(MultiFDSendParams *p) +{ + qemu_sem_post(&p->sem_sync); + qemu_sem_post(&multifd_send_state->channels_ready); +} + /* * How we use multifd_send_state->pages and channel->pages? * @@ -739,8 +751,7 @@ out: assert(local_err); trace_multifd_send_error(p->id); multifd_send_terminate_threads(local_err); - qemu_sem_post(&p->sem_sync); - qemu_sem_post(&multifd_send_state->channels_ready); + multifd_send_kick_main(p); error_free(local_err); } =20 @@ -781,8 +792,7 @@ static void multifd_tls_outgoing_handshake(QIOTask *tas= k, * is not created, and then tell who pay attention to me. */ p->quit =3D true; - qemu_sem_post(&multifd_send_state->channels_ready); - qemu_sem_post(&p->sem_sync); + multifd_send_kick_main(p); error_free(err); } =20 @@ -852,8 +862,7 @@ static void multifd_new_send_channel_cleanup(MultiFDSen= dParams *p, { migrate_set_error(migrate_get_current(), err); /* Error happen, we need to tell who pay attention to me */ - qemu_sem_post(&multifd_send_state->channels_ready); - qemu_sem_post(&p->sem_sync); + multifd_send_kick_main(p); /* * Although multifd_send_thread is not created, but main migration * thread need to judge whether it is running, so we need to mark --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697142; cv=none; d=zohomail.com; s=zohoarc; b=MpCpkwqRgqpGlYpakKoPj3Uh43YXWiqJhg98/v5Uc1QRO3J5k5eQ3NnLy7+ABw9dF1okgFLhPLQzqOkm1fwQSIo7NbkHmcSa1nzfHQXfBXNzWtQDRnxE1bqpWQV2RKSjdNORLhijLKgY1Yq3pppbHq6mt9VDrMTTMfBk+WWugDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697142; 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=a9GwF5wr+IkbZjgGSvzhOPqUroVN/4alXq1fUUQ0DrU=; b=NN6BR0awj7CyKao8ugZSPHYDXt6U8GCGCseLNcEG4weZq+Uv7V5wNnwFxEa/ZU9KkTdgGxQr/0r7Mq7yFJ+S9iJBsB1O8sEf6j7E8IruGEh0pWVLd8iigLyskLEAor9gmE0dlsF32L0BmqgWd8eINMJl3sYCVCy/7ihKp8I+B/Y= 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 1706697142593539.1237160372257; Wed, 31 Jan 2024 02:32:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sb-00056D-9v; Wed, 31 Jan 2024 05:31:41 -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 1rV7sY-000560-CW for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:38 -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 1rV7sW-0005bm-JD for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:38 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-z-phsNPsMR2m5wVdrVohHA-1; Wed, 31 Jan 2024 05:31:33 -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 79D343813F2D; Wed, 31 Jan 2024 10:31:32 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5752107BD; Wed, 31 Jan 2024 10:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697095; 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=a9GwF5wr+IkbZjgGSvzhOPqUroVN/4alXq1fUUQ0DrU=; b=bVaQyuJD8ZkRskgSQvRYWUcsdgN/7/pR2S77jYr5JeNyWNlIIaXRl4pb1L7X7GPnbqppsd 0uYKY9RjZh9AT2QzeDxcJPwSY07DjEEYaQusMiVVR3z1/eTCid6Ecl9kxNHveetQPfkj+S fobFrOfwKi3ta2/g8hftVH46xhX0GAo= X-MC-Unique: z-phsNPsMR2m5wVdrVohHA-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 03/14] migration/multifd: Drop MultiFDSendParams.quit, cleanup error paths Date: Wed, 31 Jan 2024 18:31:00 +0800 Message-ID: <20240131103111.306523-4-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: 1706697144846100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Multifd send side has two fields to indicate error quits: - MultiFDSendParams.quit - &multifd_send_state->exiting Merge them into the global one. The replacement is done by changing all p->quit checks into the global var check. The global check doesn't need any lock. A few more things done on top of this altogether: - multifd_send_terminate_threads() Moving the xchg() of &multifd_send_state->exiting upper, so as to cover the tracepoint, migrate_set_error() and migrate_set_state(). - multifd_send_sync_main() In the 2nd loop, add one more check over the global var to make sure we don't keep the looping if QEMU already decided to quit. - multifd_tls_outgoing_handshake() Use multifd_send_terminate_threads() to set the error state. That has a benefit of updating MigrationState.error to that error too, so we can persist that 1st error we hit in that specific channel. - multifd_new_send_channel_async() Take similar approach like above, drop the migrate_set_error() because multifd_send_terminate_threads() already covers that. Unwrap the helper multifd_new_send_channel_cleanup() along the way; not really needed. Signed-off-by: Peter Xu Suggested-by: Fabiano Rosas --- migration/multifd.h | 2 -- migration/multifd.c | 85 ++++++++++++++++++--------------------------- 2 files changed, 33 insertions(+), 54 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 35d11f103c..7c040cb85a 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -95,8 +95,6 @@ typedef struct { QemuMutex mutex; /* is this channel thread running */ bool running; - /* should this thread finish */ - bool quit; /* multifd flags for each packet */ uint32_t flags; /* global number of generated multifd packets */ diff --git a/migration/multifd.c b/migration/multifd.c index b8d2c96533..2c98023d67 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -372,6 +372,11 @@ struct { MultiFDMethods *ops; } *multifd_send_state; =20 +static bool multifd_send_should_exit(void) +{ + return qatomic_read(&multifd_send_state->exiting); +} + /* * The migration thread can wait on either of the two semaphores. This * function can be used to kick the main thread out of waiting on either of @@ -409,7 +414,7 @@ static int multifd_send_pages(void) MultiFDSendParams *p =3D NULL; /* make happy gcc */ MultiFDPages_t *pages =3D multifd_send_state->pages; =20 - if (qatomic_read(&multifd_send_state->exiting)) { + if (multifd_send_should_exit()) { return -1; } =20 @@ -421,14 +426,11 @@ static int multifd_send_pages(void) */ next_channel %=3D migrate_multifd_channels(); for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { - p =3D &multifd_send_state->params[i]; - - qemu_mutex_lock(&p->mutex); - if (p->quit) { - error_report("%s: channel %d has already quit!", __func__, i); - qemu_mutex_unlock(&p->mutex); + if (multifd_send_should_exit()) { return -1; } + p =3D &multifd_send_state->params[i]; + qemu_mutex_lock(&p->mutex); if (!p->pending_job) { p->pending_job++; next_channel =3D (i + 1) % migrate_multifd_channels(); @@ -483,6 +485,16 @@ static void multifd_send_terminate_threads(Error *err) { int i; =20 + /* + * We don't want to exit each threads twice. Depending on where + * we get the error, or if there are two independent errors in two + * threads at the same time, we can end calling this function + * twice. + */ + if (qatomic_xchg(&multifd_send_state->exiting, 1)) { + return; + } + trace_multifd_send_terminate_threads(err !=3D NULL); =20 if (err) { @@ -497,26 +509,13 @@ static void multifd_send_terminate_threads(Error *err) } } =20 - /* - * We don't want to exit each threads twice. Depending on where - * we get the error, or if there are two independent errors in two - * threads at the same time, we can end calling this function - * twice. - */ - if (qatomic_xchg(&multifd_send_state->exiting, 1)) { - return; - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 - qemu_mutex_lock(&p->mutex); - p->quit =3D true; qemu_sem_post(&p->sem); if (p->c) { qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } - qemu_mutex_unlock(&p->mutex); } } =20 @@ -615,16 +614,13 @@ int multifd_send_sync_main(void) for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 - trace_multifd_send_sync_main_signal(p->id); - - qemu_mutex_lock(&p->mutex); - - if (p->quit) { - error_report("%s: channel %d has already quit", __func__, i); - qemu_mutex_unlock(&p->mutex); + if (multifd_send_should_exit()) { return -1; } =20 + trace_multifd_send_sync_main_signal(p->id); + + qemu_mutex_lock(&p->mutex); p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; @@ -634,6 +630,10 @@ int multifd_send_sync_main(void) for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 + if (multifd_send_should_exit()) { + return -1; + } + qemu_sem_wait(&multifd_send_state->channels_ready); trace_multifd_send_sync_main_wait(p->id); qemu_sem_wait(&p->sem_sync); @@ -671,7 +671,7 @@ static void *multifd_send_thread(void *opaque) qemu_sem_post(&multifd_send_state->channels_ready); qemu_sem_wait(&p->sem); =20 - if (qatomic_read(&multifd_send_state->exiting)) { + if (multifd_send_should_exit()) { break; } qemu_mutex_lock(&p->mutex); @@ -786,12 +786,7 @@ static void multifd_tls_outgoing_handshake(QIOTask *ta= sk, =20 trace_multifd_tls_outgoing_handshake_error(ioc, error_get_pretty(err)); =20 - migrate_set_error(migrate_get_current(), err); - /* - * Error happen, mark multifd_send_thread status as 'quit' although it - * is not created, and then tell who pay attention to me. - */ - p->quit =3D true; + multifd_send_terminate_threads(err); multifd_send_kick_main(p); error_free(err); } @@ -857,22 +852,6 @@ static bool multifd_channel_connect(MultiFDSendParams = *p, return true; } =20 -static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, - QIOChannel *ioc, Error *err) -{ - migrate_set_error(migrate_get_current(), err); - /* Error happen, we need to tell who pay attention to me */ - multifd_send_kick_main(p); - /* - * Although multifd_send_thread is not created, but main migration - * thread need to judge whether it is running, so we need to mark - * its status. - */ - p->quit =3D true; - object_unref(OBJECT(ioc)); - error_free(err); -} - static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) { MultiFDSendParams *p =3D opaque; @@ -889,7 +868,10 @@ static void multifd_new_send_channel_async(QIOTask *ta= sk, gpointer opaque) } =20 trace_multifd_new_send_channel_async_error(p->id, local_err); - multifd_new_send_channel_cleanup(p, ioc, local_err); + multifd_send_terminate_threads(local_err); + multifd_send_kick_main(p); + object_unref(OBJECT(ioc)); + error_free(local_err); } =20 static void multifd_new_send_channel_create(gpointer opaque) @@ -921,7 +903,6 @@ int multifd_save_setup(Error **errp) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); - p->quit =3D false; p->pending_job =3D 0; p->id =3D i; p->pages =3D multifd_pages_init(page_count); --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697288; cv=none; d=zohomail.com; s=zohoarc; b=Uw4q9cYx21oAO0ExcRhur6rtNe4uVoKUg+/1XOdizjkxgQvdbdIhIMmZf1AoARZeSz2dAPGv+wEjNR0PnQCU4oaQtbe7OCZiRE17AvOkNtxRnnL2YwaEpMUuj47Rnd6dCgL0jgLMugRCQnVMGc9SP0pcz0yZWsfHjkWVk5593SQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697288; 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=SwHgcXak6f0c39lwCzp0MixPyETODVkVeT/4fsRBecQ=; b=k1ZNOmFHAsJGb5eoBY1qc1KcC2GCWgSOPAA1ixSVzJhQlrkg/KEkqKRi2pR77pOy8pFJt3QeHUQwGk6JtYqIo1bGQ0cWcgR9xyjG7ONcr09aC5Kx1xhVtYVHOAeEINQFnwucsUbk25B2oL3A/zoviGC9mcKBzESQJaXR8hQ8q9Q= 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 1706697288841203.99764607149632; Wed, 31 Jan 2024 02:34:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sf-00056k-CH; Wed, 31 Jan 2024 05:31:45 -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 1rV7sd-00056b-KH for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7sa-0005dV-H3 for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:42 -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-599-HC0VeBBvPqW8Kn_Ld-AKGQ-1; Wed, 31 Jan 2024 05:31:37 -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 CD41C8B3966; Wed, 31 Jan 2024 10:31:36 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F0CE10EA6; Wed, 31 Jan 2024 10:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697099; 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=SwHgcXak6f0c39lwCzp0MixPyETODVkVeT/4fsRBecQ=; b=S/ZOjfvApNERjpgfJzf0P4Tiqel47/sdShfiljWvbNURioo3ca0WKqOxrGqtltoWxZ3D/f 1is6LjnPMA8lZOVkDLU6p4GFLd/5BTqS4ia7hv6jJcE0WUkO36GrTd897IH242P5aA7Y/z HENWB2GWyDNsIVuBPTV/FeF9DUqUpTc= X-MC-Unique: HC0VeBBvPqW8Kn_Ld-AKGQ-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 04/14] migration/multifd: Postpone reset of MultiFDPages_t Date: Wed, 31 Jan 2024 18:31:01 +0800 Message-ID: <20240131103111.306523-5-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.129.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_H4=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: 1706697289143100004 Content-Type: text/plain; charset="utf-8" From: Peter Xu Now we reset MultiFDPages_t object in the multifd sender thread in the middle of the sending job. That's not necessary, because the "*pages" struct will not be reused anyway until pending_job is cleared. Move that to the end after the job is completed, provide a helper to reset a "*pages" object. Use that same helper when free the object too. This prepares us to keep using p->pages in the follow up patches, where we may drop p->normal[]. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 2c98023d67..5633ac245a 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -172,6 +172,17 @@ void multifd_register_ops(int method, MultiFDMethods *= ops) multifd_ops[method] =3D ops; } =20 +/* Reset a MultiFDPages_t* object for the next use */ +static void multifd_pages_reset(MultiFDPages_t *pages) +{ + /* + * We don't need to touch offset[] array, because it will be + * overwritten later when reused. + */ + pages->num =3D 0; + pages->block =3D NULL; +} + static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) { MultiFDInit_t msg =3D {}; @@ -248,9 +259,8 @@ static MultiFDPages_t *multifd_pages_init(uint32_t n) =20 static void multifd_pages_clear(MultiFDPages_t *pages) { - pages->num =3D 0; + multifd_pages_reset(pages); pages->allocated =3D 0; - pages->block =3D NULL; g_free(pages->offset); pages->offset =3D NULL; g_free(pages); @@ -704,8 +714,6 @@ static void *multifd_send_thread(void *opaque) p->flags =3D 0; p->num_packets++; p->total_normal_pages +=3D p->normal_num; - p->pages->num =3D 0; - p->pages->block =3D NULL; qemu_mutex_unlock(&p->mutex); =20 trace_multifd_send(p->id, packet_num, p->normal_num, flags, @@ -732,6 +740,8 @@ static void *multifd_send_thread(void *opaque) =20 stat64_add(&mig_stats.multifd_bytes, p->next_packet_size + p->packet_len); + + multifd_pages_reset(p->pages); p->next_packet_size =3D 0; qemu_mutex_lock(&p->mutex); p->pending_job--; --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697144; cv=none; d=zohomail.com; s=zohoarc; b=QY25YICD/ut/UxJEVEebgn0aesImD5Z6pA0K+eJvxtRP0IGOtSWjghtTIHilh9xiW3KDo8bVfJXy7yI7C4GISdnxv4eKL2LWdd0BZzz8Ffst+hf4pU2sRPAgGBJVBPdcJOHn5mcpF88lrsdwD23HC4HrV6mDnmMqs04fSHOJKU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697144; 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=ElajTl0KQDTZfk5JDAySHNwJ/Mkh9oGo9gAC5F2I/Ns=; b=mUH8KdDvEx2LtbOcYLv7zMdTF8Wft5KXJ6X8Um06Dpus59TFtqUE+Q7uN2TLxEYlGbMkMm9mugeYmF8XCXlb62nnzogLwbt4wGH/16crNmYhu2Xb7tbvCHokJjAMnqX9CYl9sreENNViB0qW6ZsbvBiemxLj2672ykQ0NHyMoIs= 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 1706697144869985.178790184387; Wed, 31 Jan 2024 02:32:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sw-0005Kd-PI; Wed, 31 Jan 2024 05:32:02 -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 1rV7su-0005GE-PM for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:00 -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 1rV7sh-0005eU-7d for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:00 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-k1DTx1JcOzKHsvqamHt9AQ-1; Wed, 31 Jan 2024 05:31:41 -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 5522A2825BAD; Wed, 31 Jan 2024 10:31:41 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FD6F1BDB1; Wed, 31 Jan 2024 10:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697106; 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=ElajTl0KQDTZfk5JDAySHNwJ/Mkh9oGo9gAC5F2I/Ns=; b=Cbm17MMKtF5l3F47aM7k+ccOgJ8ZjcqWTk8BqQ4GcXR1/CK3ZJc84/DiKgPq/FISq310me ui5sHzAwfpZ/Dcvs65dB+BVtuIxVSG+RZwVqqLdBqonxZsKh1TaMXcCWqMOlUwXhvUPLkH d9Gzc60XITR+1lw1YxoDMJ68htqj+zE= X-MC-Unique: k1DTx1JcOzKHsvqamHt9AQ-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 05/14] migration/multifd: Drop MultiFDSendParams.normal[] array Date: Wed, 31 Jan 2024 18:31:02 +0800 Message-ID: <20240131103111.306523-6-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, 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: 1706697146788100007 Content-Type: text/plain; charset="utf-8" From: Peter Xu This array is redundant when p->pages exists. Now we extended the life of p->pages to the whole period where pending_job is set, it should be safe to always use p->pages->offset[] rather than p->normal[]. Drop the array. Alongside, the normal_num is also redundant, which is the same to p->pages->num. This doesn't apply to recv side, because there's no extra buffering on recv side, so p->normal[] array is still needed. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.h | 4 ---- migration/multifd-zlib.c | 7 ++++--- migration/multifd-zstd.c | 7 ++++--- migration/multifd.c | 33 +++++++++++++-------------------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 7c040cb85a..3920bdbcf1 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -122,10 +122,6 @@ typedef struct { struct iovec *iov; /* number of iovs used */ uint32_t iovs_num; - /* Pages that are not zero */ - ram_addr_t *normal; - /* num of non zero pages */ - uint32_t normal_num; /* used for compression methods */ void *data; } MultiFDSendParams; diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 37ce48621e..100809abc1 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -116,17 +116,18 @@ static void zlib_send_cleanup(MultiFDSendParams *p, E= rror **errp) */ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { + MultiFDPages_t *pages =3D p->pages; struct zlib_data *z =3D p->data; z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; int ret; uint32_t i; =20 - for (i =3D 0; i < p->normal_num; i++) { + for (i =3D 0; i < pages->num; i++) { uint32_t available =3D z->zbuff_len - out_size; int flush =3D Z_NO_FLUSH; =20 - if (i =3D=3D p->normal_num - 1) { + if (i =3D=3D pages->num - 1) { flush =3D Z_SYNC_FLUSH; } =20 @@ -135,7 +136,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) * with compression. zlib does not guarantee that this is safe, * therefore copy the page before calling deflate(). */ - memcpy(z->buf, p->pages->block->host + p->normal[i], p->page_size); + memcpy(z->buf, p->pages->block->host + pages->offset[i], p->page_s= ize); zs->avail_in =3D p->page_size; zs->next_in =3D z->buf; =20 diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index b471daadcd..2023edd8cc 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -113,6 +113,7 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Err= or **errp) */ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { + MultiFDPages_t *pages =3D p->pages; struct zstd_data *z =3D p->data; int ret; uint32_t i; @@ -121,13 +122,13 @@ static int zstd_send_prepare(MultiFDSendParams *p, Er= ror **errp) z->out.size =3D z->zbuff_len; z->out.pos =3D 0; =20 - for (i =3D 0; i < p->normal_num; i++) { + for (i =3D 0; i < pages->num; i++) { ZSTD_EndDirective flush =3D ZSTD_e_continue; =20 - if (i =3D=3D p->normal_num - 1) { + if (i =3D=3D pages->num - 1) { flush =3D ZSTD_e_flush; } - z->in.src =3D p->pages->block->host + p->normal[i]; + z->in.src =3D p->pages->block->host + pages->offset[i]; z->in.size =3D p->page_size; z->in.pos =3D 0; =20 diff --git a/migration/multifd.c b/migration/multifd.c index 5633ac245a..8bb1fd95cf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -90,13 +90,13 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Er= ror **errp) { MultiFDPages_t *pages =3D p->pages; =20 - for (int i =3D 0; i < p->normal_num; i++) { - p->iov[p->iovs_num].iov_base =3D pages->block->host + p->normal[i]; + for (int i =3D 0; i < pages->num; i++) { + p->iov[p->iovs_num].iov_base =3D pages->block->host + pages->offse= t[i]; p->iov[p->iovs_num].iov_len =3D p->page_size; p->iovs_num++; } =20 - p->next_packet_size =3D p->normal_num * p->page_size; + p->next_packet_size =3D pages->num * p->page_size; p->flags |=3D MULTIFD_FLAG_NOCOMP; return 0; } @@ -269,21 +269,22 @@ static void multifd_pages_clear(MultiFDPages_t *pages) static void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; + MultiFDPages_t *pages =3D p->pages; int i; =20 packet->flags =3D cpu_to_be32(p->flags); packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); - packet->normal_pages =3D cpu_to_be32(p->normal_num); + packet->normal_pages =3D cpu_to_be32(pages->num); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); packet->packet_num =3D cpu_to_be64(p->packet_num); =20 - if (p->pages->block) { - strncpy(packet->ramblock, p->pages->block->idstr, 256); + if (pages->block) { + strncpy(packet->ramblock, pages->block->idstr, 256); } =20 - for (i =3D 0; i < p->normal_num; i++) { + for (i =3D 0; i < pages->num; i++) { /* there are architectures where ram_addr_t is 32 bit */ - uint64_t temp =3D p->normal[i]; + uint64_t temp =3D pages->offset[i]; =20 packet->offset[i] =3D cpu_to_be64(temp); } @@ -570,8 +571,6 @@ void multifd_save_cleanup(void) p->packet =3D NULL; g_free(p->iov); p->iov =3D NULL; - g_free(p->normal); - p->normal =3D NULL; multifd_send_state->ops->send_cleanup(p, &local_err); if (local_err) { migrate_set_error(migrate_get_current(), local_err); @@ -688,8 +687,8 @@ static void *multifd_send_thread(void *opaque) =20 if (p->pending_job) { uint64_t packet_num =3D p->packet_num; + MultiFDPages_t *pages =3D p->pages; uint32_t flags; - p->normal_num =3D 0; =20 if (use_zero_copy_send) { p->iovs_num =3D 0; @@ -697,12 +696,7 @@ static void *multifd_send_thread(void *opaque) p->iovs_num =3D 1; } =20 - for (int i =3D 0; i < p->pages->num; i++) { - p->normal[p->normal_num] =3D p->pages->offset[i]; - p->normal_num++; - } - - if (p->normal_num) { + if (pages->num) { ret =3D multifd_send_state->ops->send_prepare(p, &local_er= r); if (ret !=3D 0) { qemu_mutex_unlock(&p->mutex); @@ -713,10 +707,10 @@ static void *multifd_send_thread(void *opaque) flags =3D p->flags; p->flags =3D 0; p->num_packets++; - p->total_normal_pages +=3D p->normal_num; + p->total_normal_pages +=3D pages->num; qemu_mutex_unlock(&p->mutex); =20 - trace_multifd_send(p->id, packet_num, p->normal_num, flags, + trace_multifd_send(p->id, packet_num, pages->num, flags, p->next_packet_size); =20 if (use_zero_copy_send) { @@ -924,7 +918,6 @@ int multifd_save_setup(Error **errp) p->name =3D g_strdup_printf("multifdsend_%d", i); /* We need one extra place for the packet header */ p->iov =3D g_new0(struct iovec, page_count + 1); - p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; =20 --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697290; cv=none; d=zohomail.com; s=zohoarc; b=VWcuE6/26vOvQNUE5/4eMaeNotYKXboEBMIu2hX+g4OLFhJC5cRGLCeb+hlx+YHZsK2zdcmgU0h8TWgnr3h+S/0FhF7NPLSkDzGxjNgtoC/nJT51bPbV0lXmfAY3Yp9Y3GpefuKUZ/Hrc1Zf6Uu2vCVejG6VxnjPy96XPSSniaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697290; 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=Xofmvl7UFAPSUm/4IrKBV85TkZhO+SISSyvdHG9E+DU=; b=i//EAF8jUWzTe7X/jxqsPXn2gGzHmWPPZFzXiJSAtGw8oHFHGyQV6xbnfhl4WVmsY6ZiUGp27ATj5itZmVif9El5BGMHWMnp61L3IjCJ4mCnZqTbeb5tPlsPMVAjXTemC1Kq0Y29/Kd9xZttBrpIOnKvT5H6VedfisgNJoS5ZH0= 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 1706697290289544.3030458860206; Wed, 31 Jan 2024 02:34:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sq-0005F0-Pj; Wed, 31 Jan 2024 05:31:56 -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 1rV7sn-0005Af-OR for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7sk-0005en-6n for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:52 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-kHa6tFXyNxajaeM4W0-Bgg-1; Wed, 31 Jan 2024 05:31:46 -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 0E1ED1C05154; Wed, 31 Jan 2024 10:31:46 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27B721BDB1; Wed, 31 Jan 2024 10:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697109; 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=Xofmvl7UFAPSUm/4IrKBV85TkZhO+SISSyvdHG9E+DU=; b=CgiamVG6KJBWd0n4nIjWMgvoYTLnzyaqKNPWABm8+MNJzdUk2OzKbZ/GGvSb/q170s9LSy yyBLWTc9FW6kMSr1J3xeaO9yRY2BFw9N8F75A6RQLicbLJUKKhZGGu6kRTwscgJr+/7yMh htcxfAK3xHMMHMg9OSBBCswWEOEUOfw= X-MC-Unique: kHa6tFXyNxajaeM4W0-Bgg-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 06/14] migration/multifd: Separate SYNC request with normal jobs Date: Wed, 31 Jan 2024 18:31:03 +0800 Message-ID: <20240131103111.306523-7-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.129.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_H4=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: 1706697291193100021 Content-Type: text/plain; charset="utf-8" From: Peter Xu Multifd provide a threaded model for processing jobs. On sender side, there can be two kinds of job: (1) a list of pages to send, or (2) a sync request. The sync request is a very special kind of job. It never contains a page array, but only a multifd packet telling the dest side to synchronize with sent pages. Before this patch, both requests use the pending_job field, no matter what the request is, it will boost pending_job, while multifd sender thread will decrement it after it finishes one job. However this should be racy, because SYNC is special in that it needs to set p->flags with MULTIFD_FLAG_SYNC, showing that this is a sync request. Consider a sequence of operations where: - migration thread enqueue a job to send some pages, pending_job++ (0->1) - [...before the selected multifd sender thread wakes up...] - migration thread enqueue another job to sync, pending_job++ (1->2), setup p->flags=3DMULTIFD_FLAG_SYNC - multifd sender thread wakes up, found pending_job=3D=3D2 - send the 1st packet with MULTIFD_FLAG_SYNC and list of pages - send the 2nd packet with flags=3D=3D0 and no pages This is not expected, because MULTIFD_FLAG_SYNC should hopefully be done after all the pages are received. Meanwhile, the 2nd packet will be completely useless, which contains zero information. I didn't verify above, but I think this issue is still benign in that at least on the recv side we always receive pages before handling MULTIFD_FLAG_SYNC. However that's not always guaranteed and just tricky. One other reason I want to separate it is using p->flags to communicate between the two threads is also not clearly defined, it's very hard to read and understand why accessing p->flags is always safe; see the current impl of multifd_send_thread() where we tried to cache only p->flags. It doesn't need to be that complicated. This patch introduces pending_sync, a separate flag just to show that the requester needs a sync. Alongside, we remove the tricky caching of p->flags now because after this patch p->flags should only be used by multifd sender thread now, which will be crystal clear. So it is always thread safe to access p->flags. With that, we can also safely convert the pending_job into a boolean, because we don't support >1 pending jobs anyway. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.h | 13 +++++++++++-- migration/multifd.c | 29 ++++++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 3920bdbcf1..08f26ef3fe 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -99,8 +99,17 @@ typedef struct { uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; - /* thread has work to do */ - int pending_job; + /* + * The sender thread has work to do if either of below boolean is set. + * + * @pending_job: a job is pending + * @pending_sync: a sync request is pending + * + * For both of these fields, they're only set by the requesters, and + * cleared by the multifd sender threads. + */ + bool pending_job; + bool pending_sync; /* array of pages to sent. * The owner of 'pages' depends of 'pending_job' value: * pending_job =3D=3D 0 -> migration_thread can use it. diff --git a/migration/multifd.c b/migration/multifd.c index 8bb1fd95cf..6a4863edd2 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -443,7 +443,7 @@ static int multifd_send_pages(void) p =3D &multifd_send_state->params[i]; qemu_mutex_lock(&p->mutex); if (!p->pending_job) { - p->pending_job++; + p->pending_job =3D true; next_channel =3D (i + 1) % migrate_multifd_channels(); break; } @@ -631,8 +631,7 @@ int multifd_send_sync_main(void) =20 qemu_mutex_lock(&p->mutex); p->packet_num =3D multifd_send_state->packet_num++; - p->flags |=3D MULTIFD_FLAG_SYNC; - p->pending_job++; + p->pending_sync =3D true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); } @@ -688,7 +687,6 @@ static void *multifd_send_thread(void *opaque) if (p->pending_job) { uint64_t packet_num =3D p->packet_num; MultiFDPages_t *pages =3D p->pages; - uint32_t flags; =20 if (use_zero_copy_send) { p->iovs_num =3D 0; @@ -704,13 +702,11 @@ static void *multifd_send_thread(void *opaque) } } multifd_send_fill_packet(p); - flags =3D p->flags; - p->flags =3D 0; p->num_packets++; p->total_normal_pages +=3D pages->num; qemu_mutex_unlock(&p->mutex); =20 - trace_multifd_send(p->id, packet_num, pages->num, flags, + trace_multifd_send(p->id, packet_num, pages->num, p->flags, p->next_packet_size); =20 if (use_zero_copy_send) { @@ -738,12 +734,23 @@ static void *multifd_send_thread(void *opaque) multifd_pages_reset(p->pages); p->next_packet_size =3D 0; qemu_mutex_lock(&p->mutex); - p->pending_job--; + p->pending_job =3D false; qemu_mutex_unlock(&p->mutex); - - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&p->sem_sync); + } else if (p->pending_sync) { + p->flags =3D MULTIFD_FLAG_SYNC; + multifd_send_fill_packet(p); + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + qemu_mutex_unlock(&p->mutex); + break; } + /* p->next_packet_size will always be zero for a SYNC packet */ + stat64_add(&mig_stats.multifd_bytes, p->packet_len); + p->flags =3D 0; + p->pending_sync =3D false; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem_sync); } else { qemu_mutex_unlock(&p->mutex); /* sometimes there are spurious wakeups */ --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697288; cv=none; d=zohomail.com; s=zohoarc; b=CMLFq5FjWjVbUuJkpQPfV4QtTLuvESi+cYx45hqQx8O7azk5YGso+Iy4XJluWuV9aii3O/qD5qgXe2VxypAxoQ8CCYvBeU34tUoq48emJIulebe+1RRlUXiKcy00xO26LDrToQly6sFZVXcaOduMJ7WjvSFMaGb8vVQgkhHYnso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697288; 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=14HBcwus+qwKczG43PdMeM13AKTcXtuWl/N5uwY+Yu8=; b=PuSPotN0xXBOdWEfdTQt9C2vcS9vhiGX+lHVm7IcaswRkzvC24Qjh4ur5WxrpCvwwm19ruge38ZfY9DYO3sIIq93f5lmPW1x37aLLXvr/PpE2S9LiWgVUonvZjqUHjRpwbEYZU1cmArOwWQtgYD69gdH82a7L0bHnYrTLdWqtEI= 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 170669728873978.03282023009376; Wed, 31 Jan 2024 02:34:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sr-0005F7-CP; Wed, 31 Jan 2024 05:31:57 -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 1rV7sq-0005Ep-EJ for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:56 -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 1rV7so-0005f4-Jk for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:31:56 -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-300-502OBX22PaK-tgN-E-saYA-1; Wed, 31 Jan 2024 05:31:51 -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 F1519185A782; Wed, 31 Jan 2024 10:31:50 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE5EE107BD; Wed, 31 Jan 2024 10:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697113; 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=14HBcwus+qwKczG43PdMeM13AKTcXtuWl/N5uwY+Yu8=; b=bZzNEKFjU3nX2BkimZFODoC4LTCeeamzusK+stuYSUSmHllAAjeQzxyo1n61DFy7XUhxUZ RPEfUUBfimgsebJAmPn7i9Dm1XLrbj8Qxh3ueg9ENzRv7BWAQQdBU4Ez/qO9/yhMW5qPFz DK3R+1iRJobOVP7vnSgESO9Xjw3gGuI= X-MC-Unique: 502OBX22PaK-tgN-E-saYA-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 07/14] migration/multifd: Simplify locking in sender thread Date: Wed, 31 Jan 2024 18:31:04 +0800 Message-ID: <20240131103111.306523-8-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: 1706697289143100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu The sender thread will yield the p->mutex before IO starts, trying to not block the requester thread. This may be unnecessary lock optimizations, because the requester can already read pending_job safely even without the lock, because the requester is currently the only one who can assign a task. Drop that lock complication on both sides: (1) in the sender thread, always take the mutex until job done (2) in the requester thread, check pending_job clear lockless Signed-off-by: Peter Xu --- migration/multifd.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 6a4863edd2..4dc5af0a15 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -429,7 +429,9 @@ static int multifd_send_pages(void) return -1; } =20 + /* We wait here, until at least one channel is ready */ qemu_sem_wait(&multifd_send_state->channels_ready); + /* * next_channel can remain from a previous migration that was * using more channels, so ensure it doesn't overflow if the @@ -441,17 +443,26 @@ static int multifd_send_pages(void) return -1; } p =3D &multifd_send_state->params[i]; - qemu_mutex_lock(&p->mutex); + /* + * Lockless read to p->pending_job is safe, because only multifd + * sender thread can clear it. + */ if (!p->pending_job) { - p->pending_job =3D true; next_channel =3D (i + 1) % migrate_multifd_channels(); break; } - qemu_mutex_unlock(&p->mutex); } + + qemu_mutex_lock(&p->mutex); + /* + * Double check on pending_job=3D=3Dfalse with the lock. In the futur= e if + * we can have >1 requester thread, we can replace this with a "goto + * retry", but that is for later. + */ + assert(p->pending_job =3D=3D false); + p->pending_job =3D true; assert(!p->pages->num); assert(!p->pages->block); - p->packet_num =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; @@ -704,8 +715,6 @@ static void *multifd_send_thread(void *opaque) multifd_send_fill_packet(p); p->num_packets++; p->total_normal_pages +=3D pages->num; - qemu_mutex_unlock(&p->mutex); - trace_multifd_send(p->id, packet_num, pages->num, p->flags, p->next_packet_size); =20 @@ -725,6 +734,7 @@ static void *multifd_send_thread(void *opaque) 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) { + qemu_mutex_unlock(&p->mutex); break; } =20 @@ -733,7 +743,6 @@ static void *multifd_send_thread(void *opaque) =20 multifd_pages_reset(p->pages); p->next_packet_size =3D 0; - qemu_mutex_lock(&p->mutex); p->pending_job =3D false; qemu_mutex_unlock(&p->mutex); } else if (p->pending_sync) { --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697155; cv=none; d=zohomail.com; s=zohoarc; b=AmLhRKBJe5BXysspOGmlClM5Qi1D0Xg7AVMusXkRZ92SzIZe5yT8G+wIDCCfjhiIAOfIaLaoCV6a1r7fzU7euOHK5ekGwzCGK/6ya1nipZJ/gO91INQZ/NVKT3+p6VFWvcGzHLFJq4UKumvxeYJJT9DLVwNhpXlc1F6Y8pBNz2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697155; 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=zSMjDHIjz4SVEldI6/XMGGHue3rPHaCVGqGmRE1m57A=; b=JVkf7ZPZdgjf1bhd4HhNJtfZOGX1GvfJfcrW/Hl0Y8zzPav6W5yAoT/oOhN+jbkK201WJJfolFy0LjttYv1Fq/xSld9zW0XTuYXl3ltpYCcfAF//WpsmsV2jBefG8t4blHXwL6zCyfiunMIAXdxaKNXOcCf+4FoEK0351+Cn1tM= 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 1706697155412822.1100287817851; Wed, 31 Jan 2024 02:32:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7sy-0005TY-Ou; Wed, 31 Jan 2024 05:32:04 -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 1rV7sx-0005NU-1U for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7su-0005fH-Ey for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:02 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-gdGO8FtCOkWl2xYbD27JQQ-1; Wed, 31 Jan 2024 05:31:56 -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 A68902825BA5; Wed, 31 Jan 2024 10:31:55 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4A3C1BDB1; Wed, 31 Jan 2024 10:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697119; 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=zSMjDHIjz4SVEldI6/XMGGHue3rPHaCVGqGmRE1m57A=; b=SChEaGxIWI1gAel706YNCTSdGCUdZ7fgKcaOTIDckC7uPzFuUZNya42ilAnqqRuaNySDdn skO9U2Y5TEUBP6O5/2oyk2BfmBLkKv2TcaNAenwNxsveDvHIfIfbvkTxVaFbfAwH9ivj1F iKHNEM/wI6IN33Tn33GD0Xdk3VOqIyo= X-MC-Unique: gdGO8FtCOkWl2xYbD27JQQ-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 08/14] migration/multifd: Drop pages->num check in sender thread Date: Wed, 31 Jan 2024 18:31:05 +0800 Message-ID: <20240131103111.306523-9-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.129.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_H4=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: 1706697156825100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Now with a split SYNC handler, we always have pages->num set for pending_job=3D=3Dtrue. Assert it instead. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 4dc5af0a15..2d12de01a1 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -705,13 +705,14 @@ static void *multifd_send_thread(void *opaque) p->iovs_num =3D 1; } =20 - if (pages->num) { - ret =3D multifd_send_state->ops->send_prepare(p, &local_er= r); - if (ret !=3D 0) { - qemu_mutex_unlock(&p->mutex); - break; - } + assert(pages->num); + + ret =3D multifd_send_state->ops->send_prepare(p, &local_err); + if (ret !=3D 0) { + qemu_mutex_unlock(&p->mutex); + break; } + multifd_send_fill_packet(p); p->num_packets++; p->total_normal_pages +=3D pages->num; --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697290; cv=none; d=zohomail.com; s=zohoarc; b=hTTrzBju4x+kvOCI9tRmgDFkSetEtshL6TjEZAmXRWDQbpT4aJTFlDpV/kXgpC+tWcCmfpl7GKqiGJr28CbZhaLS+a09M92/V3MiUpXAnbunrAXyQNVecj6jjy1VvKUU1z0UvFdudj2ixjzas+8x1pEMVlznqS3dBEMqpGyyGsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697290; 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=j8ffq9UlqLrAbGescpfzkK/SsU9D755Q4edLpGh6v/g=; b=QbCsPnhZW4sPe4fV/FVIOZjnRUIHpQtY8AedPfdTRyi/fltxePpGoWMhV/nCzxIPhI23PPH0oIQj09Az6WAZ8rxazXGbCzpshz3e6HLEBX3ekkHdVDo/IZZN2xbJgKAM4cX5W/m7rSnb3yrqHxr8OTSlZFxFGj4tp5SN+xikhTU= 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 1706697290438938.5981170610254; Wed, 31 Jan 2024 02:34:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tD-00067r-9x; Wed, 31 Jan 2024 05:32:19 -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 1rV7tC-00067J-2N for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV7sy-0005fX-3v for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:17 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-HCwPEJUOOa-AXcTP4cJ5QQ-1; Wed, 31 Jan 2024 05:32:01 -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 927F83C1E9C2; Wed, 31 Jan 2024 10:32:00 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AED81BDB1; Wed, 31 Jan 2024 10:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697123; 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=j8ffq9UlqLrAbGescpfzkK/SsU9D755Q4edLpGh6v/g=; b=J0KcXhFkc5ds3VPdSPDkvc9hvKimgz4fhaGxKWrhO2Gp+jWnX/jsoXhtRWnz8zr4vjKHxG 8AWLf7tC88V7/voaFE4dpmEv9PioF02CVYlPeHm/YO7yrcMTzQ5paEO87cdZrFk29FWtlE kVyOcItRWqwv/GFkl7bJfLrQYMolF5E= X-MC-Unique: HCwPEJUOOa-AXcTP4cJ5QQ-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 09/14] migration/multifd: Rename p->num_packets and clean it up Date: Wed, 31 Jan 2024 18:31:06 +0800 Message-ID: <20240131103111.306523-10-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.129.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, 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: 1706697291190100020 Content-Type: text/plain; charset="utf-8" From: Peter Xu This field, no matter whether on src or dest, is only used for debugging purpose. They can even be removed already, unless it still more or less provide some accounting on "how many packets are sent/recved for this thread". The other more important one is called packet_num, which is embeded in the multifd packet headers (MultiFDPacket_t). So let's keep them for now, but make them much easier to understand, by doing below: - Rename both of them to packets_sent / packets_recved, the old name (num_packets) are waaay too confusing when we already have MultiFDPacket_t.packets_num. - Avoid worrying on the "initial packet": we know we will send it, that's good enough. The accounting won't matter a great deal to start with 0 or with 1. - Move them to where we send/recv the packets. They're: - multifd_send_fill_packet() for senders. - multifd_recv_unfill_packet() for receivers. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.h | 6 +++--- migration/multifd.c | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 08f26ef3fe..2e4ad0dc56 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -124,7 +124,7 @@ typedef struct { /* size of the next packet that contains pages */ uint32_t next_packet_size; /* packets sent through this channel */ - uint64_t num_packets; + uint64_t packets_sent; /* non zero pages sent through this channel */ uint64_t total_normal_pages; /* buffers to send */ @@ -174,8 +174,8 @@ typedef struct { MultiFDPacket_t *packet; /* size of the next packet that contains pages */ uint32_t next_packet_size; - /* packets sent through this channel */ - uint64_t num_packets; + /* packets received through this channel */ + uint64_t packets_recved; /* ramblock */ RAMBlock *block; /* ramblock host address */ diff --git a/migration/multifd.c b/migration/multifd.c index 2d12de01a1..abc2746b6e 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -288,6 +288,8 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) =20 packet->offset[i] =3D cpu_to_be64(temp); } + + p->packets_sent++; } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -335,6 +337,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) =20 p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); p->packet_num =3D be64_to_cpu(packet->packet_num); + p->packets_recved++; =20 if (p->normal_num =3D=3D 0) { return 0; @@ -683,8 +686,6 @@ static void *multifd_send_thread(void *opaque) ret =3D -1; goto out; } - /* initial packet */ - p->num_packets =3D 1; =20 while (true) { qemu_sem_post(&multifd_send_state->channels_ready); @@ -714,7 +715,6 @@ static void *multifd_send_thread(void *opaque) } =20 multifd_send_fill_packet(p); - p->num_packets++; p->total_normal_pages +=3D pages->num; trace_multifd_send(p->id, packet_num, pages->num, p->flags, p->next_packet_size); @@ -782,7 +782,7 @@ out: =20 rcu_unregister_thread(); migration_threads_remove(thread); - trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_send_thread_end(p->id, p->packets_sent, p->total_normal_= pages); =20 return NULL; } @@ -1120,7 +1120,6 @@ static void *multifd_recv_thread(void *opaque) p->flags &=3D ~MULTIFD_FLAG_SYNC; trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, p->next_packet_size); - p->num_packets++; p->total_normal_pages +=3D p->normal_num; qemu_mutex_unlock(&p->mutex); =20 @@ -1146,7 +1145,7 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->num_packets, p->total_normal_p= ages); + trace_multifd_recv_thread_end(p->id, p->packets_recved, p->total_norma= l_pages); =20 return NULL; } @@ -1248,8 +1247,6 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) } p->c =3D ioc; object_ref(OBJECT(ioc)); - /* initial packet */ - p->num_packets =3D 1; =20 p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697162; cv=none; d=zohomail.com; s=zohoarc; b=AaATueOZraHK4oaYsFpaieV44UXwcrjlm3LeWZptVQ+FtOz5YTrrEAXjJL6TkJ2ws6fjmHKa24/5AVTZDe5H9lVaMC3bjgi5JGuRAgPN/dpGSMD7Fon3OZv1wT5kwZzsyfin+NvQ7+4JBdKw+TsbvNLGP0rppF8H88Uwu1rB62o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697162; 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=uiIa/jKvfwNJQzKyTudycqJLp+wxA2ShD1h/QYR0ECM=; b=SxsjanUolGItxA+sUcEO8zuLyGmLbGe5WcWKFj4wNr+PB/3p+wIaIHHUJQjWLAGdnkIG3TBrN/ltOOYgcaZKZ2773ZemEAXT5SuX+iS+Z1F/9FW3k4jBcaAicVpr3GnSduoA/T2KS9ohAlz7wAsMaJ3iXT502NTFyFizoPUqOtY= 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 1706697162698967.9426684900335; Wed, 31 Jan 2024 02:32:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tB-00067A-PA; Wed, 31 Jan 2024 05:32:17 -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 1rV7tA-00065e-ES for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:16 -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 1rV7t8-0005fk-VO for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:16 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-C6U1Bii-MXqHO41gmp-n_Q-1; Wed, 31 Jan 2024 05:32:05 -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 199F41C068CB; Wed, 31 Jan 2024 10:32:05 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EB811BDB1; Wed, 31 Jan 2024 10:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697131; 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=uiIa/jKvfwNJQzKyTudycqJLp+wxA2ShD1h/QYR0ECM=; b=Jyhrepf3/znO5d4lTNa9Ww92bpq5KCiws+haudgX4CtZxKyt6g8BTaLNHMoV8p0S2exSOj CKFo+6naQQs1DETVCIWXfLIEPUkhXnS9mlCFDy5FI/+8T1//QLVpIYbIs5duv1peTOpegS FG0RvQt4EbNBFycfKfHY4PZjs/+Vn3s= X-MC-Unique: C6U1Bii-MXqHO41gmp-n_Q-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 10/14] migration/multifd: Move total_normal_pages accounting Date: Wed, 31 Jan 2024 18:31:07 +0800 Message-ID: <20240131103111.306523-11-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: 1706697164780100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Just like the previous patch, move the accounting for total_normal_pages on both src/dst sides into the packet fill/unfill procedures. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index abc2746b6e..2224dc9833 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -290,6 +290,7 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) } =20 p->packets_sent++; + p->total_normal_pages +=3D pages->num; } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -338,6 +339,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); p->packet_num =3D be64_to_cpu(packet->packet_num); p->packets_recved++; + p->total_normal_pages +=3D p->normal_num; =20 if (p->normal_num =3D=3D 0) { return 0; @@ -715,7 +717,6 @@ static void *multifd_send_thread(void *opaque) } =20 multifd_send_fill_packet(p); - p->total_normal_pages +=3D pages->num; trace_multifd_send(p->id, packet_num, pages->num, p->flags, p->next_packet_size); =20 @@ -1120,7 +1121,6 @@ static void *multifd_recv_thread(void *opaque) p->flags &=3D ~MULTIFD_FLAG_SYNC; trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, p->next_packet_size); - p->total_normal_pages +=3D p->normal_num; qemu_mutex_unlock(&p->mutex); =20 if (p->normal_num) { --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697288; cv=none; d=zohomail.com; s=zohoarc; b=IbdMJW1s7c73m6XWv0m+h9yIWsRF8NNN7pngiQrUuQkGME7PZLOwNX+OI7uutOWkWbmbc+WQUhWE7v38nJUWSBiNC0uefRp1tYvsIq2ct7vibWCk6B1Gb64bsQtsJSOt2aV33m7N89Nec2Ohjh1SgHVZG/+N3/dbXc/EET0bQf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697288; 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=pAbM2I4PLCzJOZnd4l6vSC4JlVsKJSWJBy5RnuhHv1o=; b=ecVvtXz3QVC3Kek6otSfxA71BghxzYaJTMLGlhFxoYhLHtGxTp+5/c1fYb7J3y8TsUEmXx/o7rC0QoruSDPjLXAU90CxiZsGfao5m+8+VFf2h3BLxYqoLo/4RgIWHshAJm3vG+WCylB+RCiAt7iMWsyBn/neZVENidsmp2HcJDQ= 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 1706697288407645.1917596997993; Wed, 31 Jan 2024 02:34:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tC-00067h-I7; Wed, 31 Jan 2024 05:32:18 -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 1rV7tB-000679-LG for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:17 -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 1rV7t8-0005fs-Vd for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:17 -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-526-JJm-hNcCM_KmRoV_iM_k6g-1; Wed, 31 Jan 2024 05:32:10 -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 C6E548945A0; Wed, 31 Jan 2024 10:32:09 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id C931F10EA6; Wed, 31 Jan 2024 10:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697133; 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=pAbM2I4PLCzJOZnd4l6vSC4JlVsKJSWJBy5RnuhHv1o=; b=fWwPU/54FYec/yfJpPH32wNTDHk36xshHG/I7PByBf2gwL9pc9A4y8S5jx7BkScu8cgjq+ j+14hLYb8AOLmZx2lVu1o4XPUxhd1QHpn5HiHjvnH/dOrljfTP+0om4E8viCFZmjvHv4bH LCYv4GkHQmOFCeUSVb+uepthjUUZRIE= X-MC-Unique: JJm-hNcCM_KmRoV_iM_k6g-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 11/14] migration/multifd: Move trace_multifd_send|recv() Date: Wed, 31 Jan 2024 18:31:08 +0800 Message-ID: <20240131103111.306523-12-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: 1706697289143100005 Content-Type: text/plain; charset="utf-8" From: Peter Xu Move them into fill/unfill of packets. With that, we can further cleanup the send/recv thread procedure, and remove one more temp var. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 2224dc9833..8d4b80f365 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -291,6 +291,9 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) =20 p->packets_sent++; p->total_normal_pages +=3D pages->num; + + trace_multifd_send(p->id, p->packet_num, pages->num, p->flags, + p->next_packet_size); } =20 static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -341,6 +344,9 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) p->packets_recved++; p->total_normal_pages +=3D p->normal_num; =20 + trace_multifd_recv(p->id, p->packet_num, p->normal_num, p->flags, + p->next_packet_size); + if (p->normal_num =3D=3D 0) { return 0; } @@ -699,7 +705,6 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); =20 if (p->pending_job) { - uint64_t packet_num =3D p->packet_num; MultiFDPages_t *pages =3D p->pages; =20 if (use_zero_copy_send) { @@ -717,8 +722,6 @@ static void *multifd_send_thread(void *opaque) } =20 multifd_send_fill_packet(p); - trace_multifd_send(p->id, packet_num, pages->num, p->flags, - p->next_packet_size); =20 if (use_zero_copy_send) { /* Send header first, without zerocopy */ @@ -1119,8 +1122,6 @@ static void *multifd_recv_thread(void *opaque) flags =3D p->flags; /* recv methods don't know how to handle the SYNC flag */ p->flags &=3D ~MULTIFD_FLAG_SYNC; - trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, - p->next_packet_size); qemu_mutex_unlock(&p->mutex); =20 if (p->normal_num) { --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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=1706697290; cv=none; d=zohomail.com; s=zohoarc; b=PS2JmZ2qNtCJPex/j20eHlIzaT1Gm2NrvZDC4esHshnsx9mF4JLu5otNoBoZrJVIEuiUL9VIqYXEvI+5/UfZFgP70qmA7Joxt2mscllgwyEgQWDLx85IXmFLIygtZMrBT2L4wIPiKTtRpSaXB8d8BEZw2ko0lR+6GdaOkWiP5Is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697290; 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=HItvWTBtuA8FYgr9X67VP5r885DjM/aVflysOooJ0tY=; b=m1Ki1J8gnHCQE7YFDdRpkWhas0f+G2kKl2sDmiuAMBf9QtqLKgV/CTlhx43pQ7zt5YWiNP0JEJGzsZUjbkz5ZedGX6IPAm6qQGUtoNyxaAiun4VLZBnVHGu0o2vne2O33O3bMi6wIuKgvmXyk7EWGzDFeFH339nDXT2nZ9A7joU= 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 1706697290156930.7191216360479; Wed, 31 Jan 2024 02:34:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tI-0006LP-M2; Wed, 31 Jan 2024 05:32:25 -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 1rV7tF-0006GQ-AS for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:21 -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 1rV7tD-0005ht-KY for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:21 -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-284-l-4GCL5eNbWGcMqx_dvLLw-1; Wed, 31 Jan 2024 05:32:15 -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 B2E5A8B3960; Wed, 31 Jan 2024 10:32:14 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BF31107BD; Wed, 31 Jan 2024 10:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697139; 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=HItvWTBtuA8FYgr9X67VP5r885DjM/aVflysOooJ0tY=; b=ZFmWyE7YhMjPQtedeDs59kyUWrUgSMAFByjmcuZNKRnNaOjr0b2leIz45LHWmYNT94/5io awZilmhironf6NMC2gPxDodAaLAes0bfR8+9DrDcQFDEdk0I543LscesLKlHNomVy1STPR J6uZF3hnclK8p75piJoJdu3erFngJl4= X-MC-Unique: l-4GCL5eNbWGcMqx_dvLLw-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 12/14] migration/multifd: multifd_send_prepare_header() Date: Wed, 31 Jan 2024 18:31:09 +0800 Message-ID: <20240131103111.306523-13-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: 1706697291178100019 Content-Type: text/plain; charset="utf-8" From: Peter Xu Introduce a helper multifd_send_prepare_header() to setup the header packet for multifd sender. It's fine to setup the IOV[0] _before_ send_prepare() because the packet buffer is already ready, even if the content is to be filled in. With this helper, we can already slightly clean up the zero copy path. Note that I explicitly put it into multifd.h, because I want it inlined directly into multifd*.c where necessary later. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.h | 8 ++++++++ migration/multifd.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 2e4ad0dc56..4ec005f53f 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -209,5 +209,13 @@ typedef struct { =20 void multifd_register_ops(int method, MultiFDMethods *ops); =20 +static inline void multifd_send_prepare_header(MultiFDSendParams *p) +{ + p->iov[0].iov_len =3D p->packet_len; + p->iov[0].iov_base =3D p->packet; + p->iovs_num++; +} + + #endif =20 diff --git a/migration/multifd.c b/migration/multifd.c index 8d4b80f365..1b0035787e 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -707,10 +707,14 @@ static void *multifd_send_thread(void *opaque) if (p->pending_job) { MultiFDPages_t *pages =3D p->pages; =20 - if (use_zero_copy_send) { - p->iovs_num =3D 0; - } else { - p->iovs_num =3D 1; + 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); } =20 assert(pages->num); @@ -730,10 +734,6 @@ static void *multifd_send_thread(void *opaque) if (ret !=3D 0) { break; } - } else { - /* Send header using the same writev call */ - p->iov[0].iov_len =3D p->packet_len; - p->iov[0].iov_base =3D p->packet; } =20 ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, --=20 2.43.0 From nobody Tue Nov 26 14:24:04 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 From nobody Tue Nov 26 14:24:04 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=1706697203; cv=none; d=zohomail.com; s=zohoarc; b=llB3yuoVYspa2STZjnzQUUZUAgndthCLx4ttVdZHpD8dwVU1NF1m6nqGxxDYazyOTbjulDnDDVinMmKU663+qVPVTdOuRvlXSMZ5aBnIvoqchYvk6sEualXa7x1nkfIhMnDlaVN+fr+uPxka6jXGcayxg0xHiF45cjTVMliRhR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706697203; 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=E5BznSsUeQgE8jqC5Fqg/VQQUrmZ60X5UizbN/zWa8g=; b=CrIxfI72T2TC7wd2xe7QX0htVgDbTR5tRlMcMRNvngAMtU77wQ8BfqO/Xf9lKviWeqzTKRLVslQC2l2mPYArYV2fyN8VYz1S3GQsSPrQCHPuraIAH4700etmPwS35kcSbDgCBK1IZf7HAX8KzL2F1Y3y4dFWOS9zd5sf1ntfxsc= 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 1706697203530922.8538350396924; Wed, 31 Jan 2024 02:33:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rV7tU-0006eV-R5; Wed, 31 Jan 2024 05:32:36 -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 1rV7tN-0006Y1-JA for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:30 -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 1rV7tL-0005iK-JR for qemu-devel@nongnu.org; Wed, 31 Jan 2024 05:32:28 -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-636-s4Bcl2GHP66-LulmabqxAg-1; Wed, 31 Jan 2024 05:32:24 -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 128D5185A782; Wed, 31 Jan 2024 10:32:24 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27EFE1BDB1; Wed, 31 Jan 2024 10:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706697146; 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=E5BznSsUeQgE8jqC5Fqg/VQQUrmZ60X5UizbN/zWa8g=; b=eTDiCD+fuLzqFcCoLief1vefwzY6ThJsGNMmCprxO5hSeMhuffK93isjhU1+dZFX2K6YSz Q84ngcYzsENczEy6XUuJq2n4REF1zx27gJmcsZtCw2QEcJV4EE88SZnEfhN4cPwv2h+Tfl rFYQOiGvQHshKwSJiK6Iw5eSBEjm7S8= X-MC-Unique: s4Bcl2GHP66-LulmabqxAg-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 14/14] migration/multifd: Forbid spurious wakeups Date: Wed, 31 Jan 2024 18:31:11 +0800 Message-ID: <20240131103111.306523-15-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: 1706697204874100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Now multifd's logic is designed to have no spurious wakeup. I still remember a talk to Juan and he seems to agree we should drop it now, and if my memory was right it was there because multifd used to hit that when still debugging. Let's drop it and see what can explode; as long as it's not reaching soft-freeze. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/multifd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 0f22646f95..bd0e3ea1a5 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -766,9 +766,6 @@ static void *multifd_send_thread(void *opaque) p->pending_sync =3D false; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem_sync); - } else { - qemu_mutex_unlock(&p->mutex); - /* sometimes there are spurious wakeups */ } } =20 --=20 2.43.0