From nobody Mon May 13 03:06:43 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=1683559726; cv=none; d=zohomail.com; s=zohoarc; b=VvyQXiLrMIaui0Xgss8o6YyzJBO5W5gGNUnoqqSbfu2cQln0m1BwFiBtdbYuBBs1E/L7KR9r+B+MgHBYFUBd6zoVnsEpwD3T2gYu3gafzm/nULodscQR0V/arXt6KKdlhRlhgG9aKTf/r5bSLxl8gtmPXL/Ej7tya97ioM1Of/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559726; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mw2gc87GQUfje3cPwRddhZZV2DpPyXBDcUoDgrja9Mg=; b=d+CNOykxx6j+Sr3vTsDyk8BbEK5kMJo2siXtBHiKj5HoYp3gH4F//oL9DMQI7xvE5lPDwLPD5TOQK2tJbZW9brNpPDRfe0zXn6M6/kurmQG2Clmu9lixm3YXXZYS1JABuDSbf1Li5jkCmkVG5yftJ8pyvfXybPqlrfljl4oYdCQ= 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 1683559726826775.7513197273444; Mon, 8 May 2023 08:28:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lY-0004SK-Ad; Mon, 08 May 2023 11:27:08 -0400 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 1pw2lW-0004Rt-JN for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:06 -0400 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 1pw2lV-0004Xt-1j for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:06 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-ISs7XmjXO1Ktnh0rXXdHCw-1; Mon, 08 May 2023 11:27:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A988384AF35; Mon, 8 May 2023 15:27:01 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2105040C6F41; Mon, 8 May 2023 15:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559624; 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=mw2gc87GQUfje3cPwRddhZZV2DpPyXBDcUoDgrja9Mg=; b=AgJhJeG30t3dwDwPzQmHAYqwSrsuG7e3n8SCEX0vWZmwqBBhAa5/JRiLesjRR4evu39aNn eLf4m7GswmbE8Fb3d3TTEIoLqgZPhJP5PQGOpFBhdoLz/0a5wWzONECJ4kPmUyP83V/LEm uchcPF5iycJsFAreoeOmA/W7Af1uxQ4= X-MC-Unique: ISs7XmjXO1Ktnh0rXXdHCw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 01/13] qtest/migration-test.c: Add tests with compress enabled Date: Mon, 8 May 2023 17:26:45 +0200 Message-Id: <20230508152657.66701-2-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559728157100006 Content-Type: text/plain; charset="utf-8" From: Lukas Straub There has never been tests for migration with compress enabled. Add suitable tests, testing with compress-wait-thread =3D false too. Signed-off-by: Lukas Straub Acked-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- tests/qtest/migration-test.c | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index be73ec3c06..ea0d3fad2a 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -406,6 +406,41 @@ static void migrate_set_parameter_str(QTestState *who,= const char *parameter, migrate_check_parameter_str(who, parameter, value); } =20 +static long long migrate_get_parameter_bool(QTestState *who, + const char *parameter) +{ + QDict *rsp; + int result; + + rsp =3D wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); + result =3D qdict_get_bool(rsp, parameter); + qobject_unref(rsp); + return !!result; +} + +static void migrate_check_parameter_bool(QTestState *who, const char *para= meter, + int value) +{ + int result; + + result =3D migrate_get_parameter_bool(who, parameter); + g_assert_cmpint(result, =3D=3D, value); +} + +static void migrate_set_parameter_bool(QTestState *who, const char *parame= ter, + int value) +{ + QDict *rsp; + + rsp =3D qtest_qmp(who, + "{ 'execute': 'migrate-set-parameters'," + "'arguments': { %s: %i } }", + parameter, value); + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); + migrate_check_parameter_bool(who, parameter, value); +} + static void migrate_ensure_non_converge(QTestState *who) { /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */ @@ -1524,6 +1559,70 @@ static void test_precopy_unix_xbzrle(void) test_precopy_common(&args); } =20 +static void * +test_migrate_compress_start(QTestState *from, + QTestState *to) +{ + migrate_set_parameter_int(from, "compress-level", 1); + migrate_set_parameter_int(from, "compress-threads", 4); + migrate_set_parameter_bool(from, "compress-wait-thread", true); + migrate_set_parameter_int(to, "decompress-threads", 4); + + migrate_set_capability(from, "compress", true); + migrate_set_capability(to, "compress", true); + + return NULL; +} + +static void test_precopy_unix_compress(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D uri, + .start_hook =3D test_migrate_compress_start, + /* + * Test that no invalid thread state is left over from + * the previous iteration. + */ + .iterations =3D 2, + }; + + test_precopy_common(&args); +} + +static void * +test_migrate_compress_nowait_start(QTestState *from, + QTestState *to) +{ + migrate_set_parameter_int(from, "compress-level", 9); + migrate_set_parameter_int(from, "compress-threads", 1); + migrate_set_parameter_bool(from, "compress-wait-thread", false); + migrate_set_parameter_int(to, "decompress-threads", 1); + + migrate_set_capability(from, "compress", true); + migrate_set_capability(to, "compress", true); + + return NULL; +} + +static void test_precopy_unix_compress_nowait(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D uri, + .start_hook =3D test_migrate_compress_nowait_start, + /* + * Test that no invalid thread state is left over from + * the previous iteration. + */ + .iterations =3D 2, + }; + + test_precopy_common(&args); +} + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -2537,6 +2636,16 @@ int main(int argc, char **argv) qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbz= rle); + /* + * Compression fails from time to time. + * Put test here but don't enable it until everything is fixed. + */ + if (getenv("QEMU_TEST_FLAKY_TESTS")) { + qtest_add_func("/migration/precopy/unix/compress/wait", + test_precopy_unix_compress); + qtest_add_func("/migration/precopy/unix/compress/nowait", + test_precopy_unix_compress_nowait); + } #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559687; cv=none; d=zohomail.com; s=zohoarc; b=n08IaPgUKPqRsIA2WsYs0+7JWra0G1y44uaqhqHyWBmOTVx4zK3hvm0gQOzpzKto/X9BtWJ75OnAP+UpaTFjxM4SkNds58MwPefUVOGASRnhRWttEgZqI7o3gfnf4zSYmb8d388wRKvEVHk6aLRpKcxCIOh/J1lxZGbbo+f7bX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559687; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sk8840cRsyBLlJUbP42YuaREGqNT2920nPNsu+n0ets=; b=bD7G2aRzApPmrwFHSyeaLZH+kz/HaM0OslQFJtYFnyO1xZsA6lxQQnWTpbcL9VPRAnsXueAEtGr5dmuzs431zuHGykc4xVUQmqPwvYDAYKClbLcPgfQyuEQv8FW+kgv0HU3Igg3c3OEfBIykoBYOl5Rhxab7pJ6kUlxpS7dS+vQ= 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 1683559687526828.9741037108153; Mon, 8 May 2023 08:28:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lc-0004Sn-8G; Mon, 08 May 2023 11:27:12 -0400 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 1pw2lX-0004S1-Aw for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:07 -0400 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 1pw2lV-0004Y0-Os for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:07 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-171-di0GMXIDM56iwgltNw6-0g-1; Mon, 08 May 2023 11:27:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86FB41C075B3; Mon, 8 May 2023 15:27:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED7FB40C6F42; Mon, 8 May 2023 15:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559625; 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=sk8840cRsyBLlJUbP42YuaREGqNT2920nPNsu+n0ets=; b=Ck3wkGWfh8Z7dVh2P4hueKrsm48+6jiVwKj/8dzQq1tq2dnRk11aN9dcpMTLq6/NyIK22x KogCoqDNwYUsr5apUTJvPTgNXc5dV8LlO1cMJ/bTqmk5QlESKPYso9QAj4Bjo1AomdCtxo UXxxV2YCHkqriZUF+e7WvFQJXceiocc= X-MC-Unique: di0GMXIDM56iwgltNw6-0g-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 02/13] qtest/migration-test.c: Add postcopy tests with compress enabled Date: Mon, 8 May 2023 17:26:46 +0200 Message-Id: <20230508152657.66701-3-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559687889100001 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Add postcopy tests with compress enabled to ensure nothing breaks with the refactoring in the next commits. preempt+compress is blocked, so no test needed for that case. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- tests/qtest/migration-test.c | 85 +++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index ea0d3fad2a..8a5df84624 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1127,6 +1127,36 @@ test_migrate_tls_x509_finish(QTestState *from, #endif /* CONFIG_TASN1 */ #endif /* CONFIG_GNUTLS */ =20 +static void * +test_migrate_compress_start(QTestState *from, + QTestState *to) +{ + migrate_set_parameter_int(from, "compress-level", 1); + migrate_set_parameter_int(from, "compress-threads", 4); + migrate_set_parameter_bool(from, "compress-wait-thread", true); + migrate_set_parameter_int(to, "decompress-threads", 4); + + migrate_set_capability(from, "compress", true); + migrate_set_capability(to, "compress", true); + + return NULL; +} + +static void * +test_migrate_compress_nowait_start(QTestState *from, + QTestState *to) +{ + migrate_set_parameter_int(from, "compress-level", 9); + migrate_set_parameter_int(from, "compress-threads", 1); + migrate_set_parameter_bool(from, "compress-wait-thread", false); + migrate_set_parameter_int(to, "decompress-threads", 1); + + migrate_set_capability(from, "compress", true); + migrate_set_capability(to, "compress", true); + + return NULL; +} + static int migrate_postcopy_prepare(QTestState **from_ptr, QTestState **to_ptr, MigrateCommon *args) @@ -1204,6 +1234,15 @@ static void test_postcopy(void) test_postcopy_common(&args); } =20 +static void test_postcopy_compress(void) +{ + MigrateCommon args =3D { + .start_hook =3D test_migrate_compress_start + }; + + test_postcopy_common(&args); +} + static void test_postcopy_preempt(void) { MigrateCommon args =3D { @@ -1305,6 +1344,15 @@ static void test_postcopy_recovery(void) test_postcopy_recovery_common(&args); } =20 +static void test_postcopy_recovery_compress(void) +{ + MigrateCommon args =3D { + .start_hook =3D test_migrate_compress_start + }; + + test_postcopy_recovery_common(&args); +} + #ifdef CONFIG_GNUTLS static void test_postcopy_recovery_tls_psk(void) { @@ -1338,6 +1386,7 @@ static void test_postcopy_preempt_all(void) =20 test_postcopy_recovery_common(&args); } + #endif =20 static void test_baddest(void) @@ -1559,21 +1608,6 @@ static void test_precopy_unix_xbzrle(void) test_precopy_common(&args); } =20 -static void * -test_migrate_compress_start(QTestState *from, - QTestState *to) -{ - migrate_set_parameter_int(from, "compress-level", 1); - migrate_set_parameter_int(from, "compress-threads", 4); - migrate_set_parameter_bool(from, "compress-wait-thread", true); - migrate_set_parameter_int(to, "decompress-threads", 4); - - migrate_set_capability(from, "compress", true); - migrate_set_capability(to, "compress", true); - - return NULL; -} - static void test_precopy_unix_compress(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); @@ -1591,21 +1625,6 @@ static void test_precopy_unix_compress(void) test_precopy_common(&args); } =20 -static void * -test_migrate_compress_nowait_start(QTestState *from, - QTestState *to) -{ - migrate_set_parameter_int(from, "compress-level", 9); - migrate_set_parameter_int(from, "compress-threads", 1); - migrate_set_parameter_bool(from, "compress-wait-thread", false); - migrate_set_parameter_int(to, "decompress-threads", 1); - - migrate_set_capability(from, "compress", true); - migrate_set_capability(to, "compress", true); - - return NULL; -} - static void test_precopy_unix_compress_nowait(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); @@ -2631,6 +2650,12 @@ int main(int argc, char **argv) qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_= preempt); qtest_add_func("/migration/postcopy/preempt/recovery/plain", test_postcopy_preempt_recovery); + if (getenv("QEMU_TEST_FLAKY_TESTS")) { + qtest_add_func("/migration/postcopy/compress/plain", + test_postcopy_compress); + qtest_add_func("/migration/postcopy/recovery/compress/plain", + test_postcopy_recovery_compress); + } } =20 qtest_add_func("/migration/bad_dest", test_baddest); --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559729; cv=none; d=zohomail.com; s=zohoarc; b=LMgLbmaxDb0A41xrxutXtD71fwkwpWlkOXFuxUIPjEqkJIAp7ibNX6SltXXanwNLfYU4dKk8xQEQVKAb/ArJ09VLtsAL4PDmhUs4q0DHH/CzQuBYRBPgYqpNFU/Aet+BdLCBi4BERlKL07Raoq3rhQYgYdSG79FJ8xL/UMyLkxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559729; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SNQZqH/V5/yjuWgzsCvXimxX0HrZV6tqFOd/0HJYxGs=; b=GArLlSHSrmINhwb8E8jX9ytlultOko7QIMLbNI+CQ1lvyWiExsyb4d8GFVAVwhNf2zGPX7c0t9GMFwJ+XaTjSyQpeNpk3gsGBvFLN+tmfSIrsKuHOq0wqLIjxlKw1tjc48UyOcKDOqaHl7VwboxbkfcKvson15BVBh8mbdHCKnI= 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 1683559729903448.94553387261817; Mon, 8 May 2023 08:28:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lh-0004Wt-Av; Mon, 08 May 2023 11:27:17 -0400 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 1pw2lb-0004Se-Dc for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:11 -0400 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 1pw2lZ-0004YP-LP for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:11 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675--1LVbaOQNdKhXcTS5mxCKA-1; Mon, 08 May 2023 11:27:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42CC186795E; Mon, 8 May 2023 15:27:05 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8DB740E8B26; Mon, 8 May 2023 15:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559628; 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=SNQZqH/V5/yjuWgzsCvXimxX0HrZV6tqFOd/0HJYxGs=; b=Dc9VK/c+fhlNJZG3mulaFU8QiM4bV/euUQH9MBYZihIu805VPrfh+NYkGhVvryupTx86Kx GguH0OaasoEVHHdkRw0KiOpgSuZByu9RhtRp9cWpQeE/WLqdmfvZwd3XVxZybUjjhlbmP9 wKzjIViOq/Yk7uNRaxRmN2MG7GVdISc= X-MC-Unique: -1LVbaOQNdKhXcTS5mxCKA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 03/13] ram.c: Let the compress threads return a CompressResult enum Date: Mon, 8 May 2023 17:26:47 +0200 Message-Id: <20230508152657.66701-4-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559731229100021 Content-Type: text/plain; charset="utf-8" From: Lukas Straub This will be used in the next commits to move save_page_header() out of compress code. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 5e7bf20ca5..7bc05fc034 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -482,10 +482,17 @@ MigrationOps *migration_ops; =20 CompressionStats compression_counters; =20 +enum CompressResult { + RES_NONE =3D 0, + RES_ZEROPAGE =3D 1, + RES_COMPRESS =3D 2 +}; +typedef enum CompressResult CompressResult; + struct CompressParam { bool done; bool quit; - bool zero_page; + CompressResult result; QEMUFile *file; QemuMutex mutex; QemuCond cond; @@ -527,8 +534,9 @@ static QemuCond decomp_done_cond; =20 static int ram_save_host_page_urgent(PageSearchStatus *pss); =20 -static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, - ram_addr_t offset, uint8_t *source_buf); +static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, + RAMBlock *block, ram_addr_t off= set, + uint8_t *source_buf); =20 /* NOTE: page is the PFN not real ram_addr_t. */ static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) @@ -553,7 +561,7 @@ static void *do_data_compress(void *opaque) CompressParam *param =3D opaque; RAMBlock *block; ram_addr_t offset; - bool zero_page; + CompressResult result; =20 qemu_mutex_lock(¶m->mutex); while (!param->quit) { @@ -563,12 +571,12 @@ static void *do_data_compress(void *opaque) param->block =3D NULL; qemu_mutex_unlock(¶m->mutex); =20 - zero_page =3D do_compress_ram_page(param->file, ¶m->stream, - block, offset, param->originb= uf); + result =3D do_compress_ram_page(param->file, ¶m->stream, + block, offset, param->originbuf); =20 qemu_mutex_lock(&comp_done_lock); param->done =3D true; - param->zero_page =3D zero_page; + param->result =3D result; qemu_cond_signal(&comp_done_cond); qemu_mutex_unlock(&comp_done_lock); =20 @@ -1452,8 +1460,9 @@ static int ram_save_multifd_page(QEMUFile *file, RAMB= lock *block, return 1; } =20 -static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, - ram_addr_t offset, uint8_t *source_buf) +static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, + RAMBlock *block, ram_addr_t off= set, + uint8_t *source_buf) { RAMState *rs =3D ram_state; PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; @@ -1461,7 +1470,7 @@ static bool do_compress_ram_page(QEMUFile *f, z_strea= m *stream, RAMBlock *block, int ret; =20 if (save_zero_page_to_file(pss, f, block, offset)) { - return true; + return RES_ZEROPAGE; } =20 save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); @@ -1476,8 +1485,9 @@ static bool do_compress_ram_page(QEMUFile *f, z_strea= m *stream, RAMBlock *block, if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); + return RES_NONE; } - return false; + return RES_COMPRESS; } =20 static void @@ -1485,7 +1495,7 @@ update_compress_thread_counts(const CompressParam *pa= ram, int bytes_xmit) { ram_transferred_add(bytes_xmit); =20 - if (param->zero_page) { + if (param->result =3D=3D RES_ZEROPAGE) { stat64_add(&mig_stats.zero_pages, 1); return; } --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559727; cv=none; d=zohomail.com; s=zohoarc; b=UVf4nHeawZ5kmp+pljBDBqI+iM7FwX+jjUGC6fNjyEhXzfkI9MIm4l3OcvBxwuTYg0CSxSiY3ALIOPXrUNgUJ1hWt7G6r8KTJL54eJ3QY5xosL6PIeEwXcBAPu4d1Yp/o9cti7s7iT+vm21yZ+NAdpJu+JMrHab2j/WRYHs8DEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559727; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lANJAnuQcfwj3tIvtmJW8wGJt/YsnwLqI/q4w1snX5o=; b=BAjqWLYKrBD0H0eLjGKUC2+pqjfxRgpnxV+ttRmTJZ/L2+l+MJ77OKN6QSio39kT5kAqPWJPIhwChfIHDNWf3/rw7hL0MQKU1sJ7dE88tNwO2Y4oPGcnu0NgF2tbE9fNqLNTuJi1eNUtyui+oyh9JrXK1z4e1SPSS6x9Lnh6WZU= 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 1683559727537977.6636895143262; Mon, 8 May 2023 08:28:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2li-0004Zd-1h; Mon, 08 May 2023 11:27:18 -0400 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 1pw2ld-0004TB-4W for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:14 -0400 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 1pw2lb-0004Yb-GC for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:12 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-498-piTl1iThN_CC7pEisfER1g-1; Mon, 08 May 2023 11:27:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F01FB1C075B3; Mon, 8 May 2023 15:27:08 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8449540C6F41; Mon, 8 May 2023 15:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559630; 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=lANJAnuQcfwj3tIvtmJW8wGJt/YsnwLqI/q4w1snX5o=; b=MifqZc7UsgMWtvYAzgjeTpTQPcEKMTmTzChepsKTuCQNGOH2GE24OpWaGoFcLvcSRUiRH/ ScSexXqUaT/1u9FDykZs7hPTVln3qCmGuAAjDyizMO8fBDLaBAEpgHxdXtDGwo1E6VvOh4 kbOIGlkU/kps1DjpW1HYHqJXh1Lak2E= X-MC-Unique: piTl1iThN_CC7pEisfER1g-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 04/13] ram.c: Dont change param->block in the compress thread Date: Mon, 8 May 2023 17:26:48 +0200 Message-Id: <20230508152657.66701-5-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559729665100013 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Instead introduce a extra parameter to trigger the compress thread. Now, when the compress thread is done, we know what RAMBlock and offset it did compress. This will be used in the next commits to move save_page_header() out of compress code. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7bc05fc034..b552a9e538 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -492,6 +492,7 @@ typedef enum CompressResult CompressResult; struct CompressParam { bool done; bool quit; + bool trigger; CompressResult result; QEMUFile *file; QemuMutex mutex; @@ -565,10 +566,10 @@ static void *do_data_compress(void *opaque) =20 qemu_mutex_lock(¶m->mutex); while (!param->quit) { - if (param->block) { + if (param->trigger) { block =3D param->block; offset =3D param->offset; - param->block =3D NULL; + param->trigger =3D false; qemu_mutex_unlock(¶m->mutex); =20 result =3D do_compress_ram_page(param->file, ¶m->stream, @@ -1545,6 +1546,7 @@ static inline void set_compress_params(CompressParam = *param, RAMBlock *block, { param->block =3D block; param->offset =3D offset; + param->trigger =3D true; } =20 static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set) --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559728; cv=none; d=zohomail.com; s=zohoarc; b=XN5j5Y8O/E6EkfOBoMG+YR8xIBRSZIElsQcqvVAqGv4y+8Z6ORh6tvNbWBizoq8DgZVSW/WGMXwVvN0LBfFuzsHOZB+RliA70JQ5SJTmmLJ/L36QQUSBGwwx7CcI9xN15N+rDpJa7BmRW6RNY4iuLlbIeCRX0t3foHyYn3JhvWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559728; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aK/Bi+9ummnPzvwITUO6ZTsthFw23cO8qAA9Zcc0/Rg=; b=HpPlwHmi6S1ybE68x5kKoEz3Ot7gRw8mWtE2ndlTMyaOVmloSAo7iUbmj7VyfAl0mcr+/6JptdDb9lBPnyA1m/ubVtnAa6kaXPeiVbVFqY3286bD79cFA4AhvRKuyN/7TxGcNOJez+fX/kAU5HXvPBkIPBbnz/B0rAHkk5NvqeA= 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 1683559728500703.475079559261; Mon, 8 May 2023 08:28:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2li-0004be-PW; Mon, 08 May 2023 11:27:18 -0400 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 1pw2lg-0004Wc-R5 for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:16 -0400 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 1pw2lc-0004Ys-R1 for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:14 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-524-B8FXqV0AMiyCnxyuHx6fjg-1; Mon, 08 May 2023 11:27:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD0872807D7B; Mon, 8 May 2023 15:27:10 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41E1040C6F41; Mon, 8 May 2023 15:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559632; 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=aK/Bi+9ummnPzvwITUO6ZTsthFw23cO8qAA9Zcc0/Rg=; b=cnbq42BqoIEn3yRpYeiOXmQ7xmqdyQrGSHjoTs8HxZWqlapZJs87mq1vesOpV6TpSwx99X lwDxg6S0jMacGWsxvp9lOFr1HbAvi4IMNSAh1V7i1Mp46zCwPcU9/u2yKpk3zLvheHBty5 ryxrqPt238dCbFEdUQQdnHFflxRKDuQ= X-MC-Unique: B8FXqV0AMiyCnxyuHx6fjg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 05/13] ram.c: Reset result after sending queued data Date: Mon, 8 May 2023 17:26:49 +0200 Message-Id: <20230508152657.66701-6-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559729204100011 Content-Type: text/plain; charset="utf-8" From: Lukas Straub And take the param->mutex lock for the whole section to ensure thread-safety. Now, it is explicitly clear if there is no queued data to send. Before, this was handled by param->file stream being empty and thus qemu_put_qemu_file() not sending anything. This will be used in the next commits to move save_page_header() out of compress code. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index b552a9e538..4e14e3bb94 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1508,6 +1508,13 @@ update_compress_thread_counts(const CompressParam *p= aram, int bytes_xmit) =20 static bool save_page_use_compression(RAMState *rs); =20 +static inline void compress_reset_result(CompressParam *param) +{ + param->result =3D RES_NONE; + param->block =3D NULL; + param->offset =3D 0; +} + static void flush_compressed_data(RAMState *rs) { MigrationState *ms =3D migrate_get_current(); @@ -1529,13 +1536,16 @@ static void flush_compressed_data(RAMState *rs) for (idx =3D 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len =3D qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].fi= le); + CompressParam *param =3D &comp_param[idx]; + len =3D qemu_put_qemu_file(ms->to_dst_file, param->file); + compress_reset_result(param); + /* * it's safe to fetch zero_page without holding comp_done_lock * as there is no further request submitted to the thread, * i.e, the thread should be waiting for a request at this poi= nt. */ - update_compress_thread_counts(&comp_param[idx], len); + update_compress_thread_counts(param, len); } qemu_mutex_unlock(&comp_param[idx].mutex); } @@ -1560,15 +1570,17 @@ static int compress_page_with_multi_thread(RAMBlock= *block, ram_addr_t offset) retry: for (idx =3D 0; idx < thread_count; idx++) { if (comp_param[idx].done) { - comp_param[idx].done =3D false; - bytes_xmit =3D qemu_put_qemu_file(ms->to_dst_file, - comp_param[idx].file); - qemu_mutex_lock(&comp_param[idx].mutex); - set_compress_params(&comp_param[idx], block, offset); - qemu_cond_signal(&comp_param[idx].cond); - qemu_mutex_unlock(&comp_param[idx].mutex); + CompressParam *param =3D &comp_param[idx]; + qemu_mutex_lock(¶m->mutex); + param->done =3D false; + bytes_xmit =3D qemu_put_qemu_file(ms->to_dst_file, param->file= ); + compress_reset_result(param); + set_compress_params(param, block, offset); + + update_compress_thread_counts(param, bytes_xmit); + qemu_cond_signal(¶m->cond); + qemu_mutex_unlock(¶m->mutex); pages =3D 1; - update_compress_thread_counts(&comp_param[idx], bytes_xmit); break; } } --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559730; cv=none; d=zohomail.com; s=zohoarc; b=QRxmXt2qxHzqhrNsApAS7zieFfe3f/oqM8Y8QZcEpcKaCy81azivCqkmo69vOeZH5Sga9Mnui2TDQHTtKI+3BN4RDeF8rhzGyefAlyIH6pzFUoWlvO4rteSvxztMBALlVkdDkxWttAVnTNCPv8ipN8sfy/aYM/UXYOnr0d/760M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559730; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yXARo6F2GozGH5ZiS7RDUGuSpDE3GjQfYaFMomR8jIU=; b=Zeel8urb/kMvfEOiUErfr6jJeAV8djqA0Z9VlhvdKNChAZ1KXuOyXGEGYgQqkyHWgmby0/MVt/LwerANwJtKN4sN+0IcZ3cFYWIlgISr89/3qChA+degm0sbCJ50X3G7JBuP8Vw2lM06KN25GJjdCC8dxi2nRz7yscwulVBQxDM= 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 1683559730891940.9589375442907; Mon, 8 May 2023 08:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lj-0004ch-Sy; Mon, 08 May 2023 11:27:19 -0400 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 1pw2li-0004aP-76 for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:18 -0400 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 1pw2lf-0004Z8-FV for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:17 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-dpzVXr1CPT2wreuv43eGAg-1; Mon, 08 May 2023 11:27:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64EBC38123C9; Mon, 8 May 2023 15:27:12 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF11840BC783; Mon, 8 May 2023 15:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559633; 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=yXARo6F2GozGH5ZiS7RDUGuSpDE3GjQfYaFMomR8jIU=; b=Z44A6xnpzn+58tasEElnDesYWddP6kS+1Oke7g2CCQoqg6gO8DThj8V7/NcyJtnLLs5rIC V9PkrzbzDWKucpjqeMe7r8k7AvwWDQ7IdAkv0MPa8XsOZs8hyTKbtsveg/L/ksRCJeMtzW r/bn4ermCxxWcKXkEU51nrAjcjEE4Q8= X-MC-Unique: dpzVXr1CPT2wreuv43eGAg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 06/13] ram.c: Do not call save_page_header() from compress threads Date: Mon, 8 May 2023 17:26:50 +0200 Message-Id: <20230508152657.66701-7-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559732138100026 Content-Type: text/plain; charset="utf-8" From: Lukas Straub save_page_header() accesses several global variables, so calling it from multiple threads is pretty ugly. Instead, call save_page_header() before writing out the compressed data from the compress buffer to the migration stream. This also makes the core compress code more independend from ram.c. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 4e14e3bb94..c52602b70d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1465,17 +1465,13 @@ static CompressResult do_compress_ram_page(QEMUFile= *f, z_stream *stream, RAMBlock *block, ram_addr_t off= set, uint8_t *source_buf) { - RAMState *rs =3D ram_state; - PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; uint8_t *p =3D block->host + offset; int ret; =20 - if (save_zero_page_to_file(pss, f, block, offset)) { + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { return RES_ZEROPAGE; } =20 - save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); - /* * copy it to a internal buffer to avoid it being modified by VM * so that we can catch up the error during compression and @@ -1515,9 +1511,40 @@ static inline void compress_reset_result(CompressPar= am *param) param->offset =3D 0; } =20 +static int send_queued_data(CompressParam *param) +{ + PageSearchStatus *pss =3D &ram_state->pss[RAM_CHANNEL_PRECOPY]; + MigrationState *ms =3D migrate_get_current(); + QEMUFile *file =3D ms->to_dst_file; + int len =3D 0; + + RAMBlock *block =3D param->block; + ram_addr_t offset =3D param->offset; + + if (param->result =3D=3D RES_NONE) { + return 0; + } + + assert(block =3D=3D pss->last_sent_block); + + if (param->result =3D=3D RES_ZEROPAGE) { + len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG= _ZERO); + qemu_put_byte(file, 0); + len +=3D 1; + ram_release_page(block->idstr, offset); + } else if (param->result =3D=3D RES_COMPRESS) { + len +=3D save_page_header(pss, file, block, + offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + len +=3D qemu_put_qemu_file(file, param->file); + } else { + abort(); + } + + return len; +} + static void flush_compressed_data(RAMState *rs) { - MigrationState *ms =3D migrate_get_current(); int idx, len, thread_count; =20 if (!save_page_use_compression(rs)) { @@ -1537,7 +1564,7 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { CompressParam *param =3D &comp_param[idx]; - len =3D qemu_put_qemu_file(ms->to_dst_file, param->file); + len =3D send_queued_data(param); compress_reset_result(param); =20 /* @@ -1563,7 +1590,6 @@ static int compress_page_with_multi_thread(RAMBlock *= block, ram_addr_t offset) { int idx, thread_count, bytes_xmit =3D -1, pages =3D -1; bool wait =3D migrate_compress_wait_thread(); - MigrationState *ms =3D migrate_get_current(); =20 thread_count =3D migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1573,7 +1599,7 @@ retry: CompressParam *param =3D &comp_param[idx]; qemu_mutex_lock(¶m->mutex); param->done =3D false; - bytes_xmit =3D qemu_put_qemu_file(ms->to_dst_file, param->file= ); + bytes_xmit =3D send_queued_data(param); compress_reset_result(param); set_compress_params(param, block, offset); =20 --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559739; cv=none; d=zohomail.com; s=zohoarc; b=IqlT7pvpsndhGpPyBgXcFT3/5u5t+PV7tF8mGVE+un0T4kWxn6fZEeB+UjDjFR1LdJUfIc09580+yXagBsZ7qyC72yJ+xo7tJdn38NWVlWd8tE1rf6ZhqxeeVD5h+oS+DzHOe5a03FF9igA6xxWy9pUMovCwJThfR5hdkG549L0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559739; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xfOBNK+tDhIb0G9eekF2FCdBLWQtalEDSqGtCBcyEUs=; b=ZmXukwJGOtdgABD9ALXCIPvIg7Y0ItzB2gcIxy//a1w5BonyQIbblBZms4xwleWvpc+RLYGZH++TyahDYC/r+uVpUMK/xLcrvLcR+4IQVJOc7u9OthmMeX9SC46ykk5N4V2F7t8gZAJ6BcgX06MHyzU6g9kLqSjidkJ8B7RXROQ= 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 1683559739549685.2686474607975; Mon, 8 May 2023 08:28:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2ll-0004dE-CX; Mon, 08 May 2023 11:27:21 -0400 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 1pw2lj-0004cf-NT for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:19 -0400 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 1pw2li-0004ZQ-7Y for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:19 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-NZArdAJBPUmeGRvq5VDJSQ-1; Mon, 08 May 2023 11:27:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1ADC2807D7F; Mon, 8 May 2023 15:27:13 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id A836640C6F41; Mon, 8 May 2023 15:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559637; 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=xfOBNK+tDhIb0G9eekF2FCdBLWQtalEDSqGtCBcyEUs=; b=fZAcbY0Tl6PsPhkIaD85L6webr7wZJioysV7NrlRiEZAdiondky8zJ0GTV1EFNKXMb/lt+ V5k2FdeMFD+KBiw7BwMew0SJeBsOce60H6xCY33Ss6E4wdPndF0Qmadf+CZBe9+eHFYM1z rK1boXKFg4i9J4h0R41BCh0jdDfSs80= X-MC-Unique: NZArdAJBPUmeGRvq5VDJSQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 07/13] ram.c: Call update_compress_thread_counts from compress_send_queued_data Date: Mon, 8 May 2023 17:26:51 +0200 Message-Id: <20230508152657.66701-8-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559740180100001 Content-Type: text/plain; charset="utf-8" From: Lukas Straub This makes the core compress code more independend from ram.c. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c52602b70d..d1c24eff21 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1540,12 +1540,14 @@ static int send_queued_data(CompressParam *param) abort(); } =20 + update_compress_thread_counts(param, len); + return len; } =20 static void flush_compressed_data(RAMState *rs) { - int idx, len, thread_count; + int idx, thread_count; =20 if (!save_page_use_compression(rs)) { return; @@ -1564,15 +1566,8 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { CompressParam *param =3D &comp_param[idx]; - len =3D send_queued_data(param); + send_queued_data(param); compress_reset_result(param); - - /* - * it's safe to fetch zero_page without holding comp_done_lock - * as there is no further request submitted to the thread, - * i.e, the thread should be waiting for a request at this poi= nt. - */ - update_compress_thread_counts(param, len); } qemu_mutex_unlock(&comp_param[idx].mutex); } @@ -1588,7 +1583,7 @@ static inline void set_compress_params(CompressParam = *param, RAMBlock *block, =20 static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set) { - int idx, thread_count, bytes_xmit =3D -1, pages =3D -1; + int idx, thread_count, pages =3D -1; bool wait =3D migrate_compress_wait_thread(); =20 thread_count =3D migrate_compress_threads(); @@ -1599,11 +1594,10 @@ retry: CompressParam *param =3D &comp_param[idx]; qemu_mutex_lock(¶m->mutex); param->done =3D false; - bytes_xmit =3D send_queued_data(param); + send_queued_data(param); compress_reset_result(param); set_compress_params(param, block, offset); =20 - update_compress_thread_counts(param, bytes_xmit); qemu_cond_signal(¶m->cond); qemu_mutex_unlock(¶m->mutex); pages =3D 1; --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559730; cv=none; d=zohomail.com; s=zohoarc; b=e5CuUAPvgzGQHcPjus29Xvtgq+rSrSODg2K0A5OahFFh1TZ/MER5iWS/Z00788IIo0CKtmVBQWy09gL56rqjrpV0MaPodhMwgNQ6DezAA7izETlt8UeGmK7aCUY6MFqqwxZ+Hri7YeytqNpf0XPQ+Klum4N2cr0E53e47c/RuhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559730; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZsAszCv2Znv8XYa+Yya1icirpmADK8iZ/befENQlM/Q=; b=Gg0Td8pLDAAB9z1pMBP7hYwi6tLmyw6abF3gpUPM9Qy0DduWFvBG6wivyHzutUkOqamqv2+VPqtGTVKv5wcUkGBEHKtDpWl3m2aY6Vjd76xq2OeSBzgkG87Lexv36OQXQkm0lcl54liMASvT8TS3HoAA5/7NFDqzVBY0y4iSejM= 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 1683559730941262.527723328909; Mon, 8 May 2023 08:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2ln-0004dc-I7; Mon, 08 May 2023 11:27:23 -0400 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 1pw2lk-0004d5-W2 for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:21 -0400 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 1pw2lj-0004Zi-0H for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:20 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-FZDo1maaO3SNZ1vlnvU8lw-1; Mon, 08 May 2023 11:27:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CBA8B85A588; Mon, 8 May 2023 15:27:15 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40C7E40C6F41; Mon, 8 May 2023 15:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559638; 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=ZsAszCv2Znv8XYa+Yya1icirpmADK8iZ/befENQlM/Q=; b=i4dyBKXEgOiDX7Z+Yve35/XYEteL81EwMlSamQrXZ709WuE71Wz6ieEJgxo97Jnn1WmUiv BZ1YVCDQWoDBXYaZdn8KXCnt6CR1imPzpeybxJmZ7tQg8cZXQaW10ZYdWZmjGsjC3hivba 487ypXWSzN7O76yty59Yj4Nm1bHC27g= X-MC-Unique: FZDo1maaO3SNZ1vlnvU8lw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 08/13] ram.c: Remove last ram.c dependency from the core compress code Date: Mon, 8 May 2023 17:26:52 +0200 Message-Id: <20230508152657.66701-9-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559732157100027 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Make compression interfaces take send_queued_data() as an argument. Remove save_page_use_compression() from flush_compressed_data(). This removes the last ram.c dependency from the core compress code. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d1c24eff21..0cce65dfa5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1545,13 +1545,10 @@ static int send_queued_data(CompressParam *param) return len; } =20 -static void flush_compressed_data(RAMState *rs) +static void flush_compressed_data(int (send_queued_data(CompressParam *))) { int idx, thread_count; =20 - if (!save_page_use_compression(rs)) { - return; - } thread_count =3D migrate_compress_threads(); =20 qemu_mutex_lock(&comp_done_lock); @@ -1573,6 +1570,15 @@ static void flush_compressed_data(RAMState *rs) } } =20 +static void ram_flush_compressed_data(RAMState *rs) +{ + if (!save_page_use_compression(rs)) { + return; + } + + flush_compressed_data(send_queued_data); +} + static inline void set_compress_params(CompressParam *param, RAMBlock *blo= ck, ram_addr_t offset) { @@ -1581,7 +1587,8 @@ static inline void set_compress_params(CompressParam = *param, RAMBlock *block, param->trigger =3D true; } =20 -static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set) +static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set, + int (send_queued_data(CompressParam *))) { int idx, thread_count, pages =3D -1; bool wait =3D migrate_compress_wait_thread(); @@ -1672,7 +1679,7 @@ static int find_dirty_block(RAMState *rs, PageSearchS= tatus *pss) * Also If xbzrle is on, stop using the data compression at th= is * point. In theory, xbzrle can do better than compression. */ - flush_compressed_data(rs); + ram_flush_compressed_data(rs); =20 /* Hit the end of the list */ pss->block =3D QLIST_FIRST_RCU(&ram_list.blocks); @@ -2362,11 +2369,11 @@ static bool save_compress_page(RAMState *rs, PageSe= archStatus *pss, * much CPU resource. */ if (block !=3D pss->last_sent_block) { - flush_compressed_data(rs); + ram_flush_compressed_data(rs); return false; } =20 - if (compress_page_with_multi_thread(block, offset) > 0) { + if (compress_page_with_multi_thread(block, offset, send_queued_data) >= 0) { return true; } =20 @@ -3412,7 +3419,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) * page is sent in one chunk. */ if (migrate_postcopy_ram()) { - flush_compressed_data(rs); + ram_flush_compressed_data(rs); } =20 /* @@ -3507,7 +3514,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) } qemu_mutex_unlock(&rs->bitmap_mutex); =20 - flush_compressed_data(rs); + ram_flush_compressed_data(rs); ram_control_after_iterate(f, RAM_CONTROL_FINISH); } =20 --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559727; cv=none; d=zohomail.com; s=zohoarc; b=BjGkwv9+h2mS9drXkWggMbz5Ky5WSGBjNmj0G+Ur0VAAJWDydg9L9zej0tkmG2DtU2P4ze+OMmEHkhcCuL1QrkQ/DcWDBTynBBTUaRi5/D5Bqj+rHS1mLas5/teD+4uW6mqdifogAhGXnbz3BGH4KJLDve53qLQGjINcyIie0eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559727; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Fq76tmPrJPBcPW49bmZAsD72CI5AzI24xpLoJkFzm/c=; b=QbdGEQO4nSZkHgdCzK6HZFN6lJkndeIbvt0qPUNbQ9O7lv0CZuan6OvC25RJV17oxqJ7s5Hm4omy4AHSyo5RXLto9gBnv72JLQFDM3gk1H2H8HPi5shbBRqz+QNbm1R6My11AKLl/C+DY0boxawCaCMN1coZbO/u5NVtLM0dEwU= 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 1683559727769919.5850112231901; Mon, 8 May 2023 08:28:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lp-0004e0-Tg; Mon, 08 May 2023 11:27:25 -0400 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 1pw2lo-0004ds-U1 for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:24 -0400 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 1pw2lm-0004aC-DC for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:24 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-SsuqUktFM5uvwavKdijnUw-1; Mon, 08 May 2023 11:27:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28BBE867956; Mon, 8 May 2023 15:27:18 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1741140C6F42; Mon, 8 May 2023 15:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559641; 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=Fq76tmPrJPBcPW49bmZAsD72CI5AzI24xpLoJkFzm/c=; b=gjUGGG+3IsvwHFkzMU5ybIIegCrcrvLOYksSAN2o3xmLknUn2pqYZefS27CeNG4xoseVxZ +XNDAbd1+jHeGh1Jtf27nQecQWG67GvPdcf3+HJ/2ZLA8XGtGKkOyg6K8IOGFAT2l91s/Y hDUmOIM5VtDdikNuVON56rj42wAa9wg= X-MC-Unique: SsuqUktFM5uvwavKdijnUw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 09/13] ram.c: Move core compression code into its own file Date: Mon, 8 May 2023 17:26:53 +0200 Message-Id: <20230508152657.66701-10-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559728062100002 Content-Type: text/plain; charset="utf-8" From: Lukas Straub No functional changes intended. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/meson.build | 5 +- migration/ram-compress.c | 274 +++++++++++++++++++++++++++++++++++++++ migration/ram-compress.h | 65 ++++++++++ migration/ram.c | 262 +------------------------------------ 4 files changed, 344 insertions(+), 262 deletions(-) create mode 100644 migration/ram-compress.c create mode 100644 migration/ram-compress.h diff --git a/migration/meson.build b/migration/meson.build index da1897fadf..2090af8e85 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -38,4 +38,7 @@ endif softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c')) =20 specific_ss.add(when: 'CONFIG_SOFTMMU', - if_true: files('dirtyrate.c', 'ram.c', 'target.c')) + if_true: files('dirtyrate.c', + 'ram.c', + 'ram-compress.c', + 'target.c')) diff --git a/migration/ram-compress.c b/migration/ram-compress.c new file mode 100644 index 0000000000..d9bc67d075 --- /dev/null +++ b/migration/ram-compress.c @@ -0,0 +1,274 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2011-2015 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" + +#include "ram-compress.h" + +#include "qemu/error-report.h" +#include "migration.h" +#include "options.h" +#include "io/channel-null.h" +#include "exec/ram_addr.h" + +CompressionStats compression_counters; + +static CompressParam *comp_param; +static QemuThread *compress_threads; +/* comp_done_cond is used to wake up the migration thread when + * one of the compression threads has finished the compression. + * comp_done_lock is used to co-work with comp_done_cond. + */ +static QemuMutex comp_done_lock; +static QemuCond comp_done_cond; + +static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, + RAMBlock *block, ram_addr_t off= set, + uint8_t *source_buf); + +static void *do_data_compress(void *opaque) +{ + CompressParam *param =3D opaque; + RAMBlock *block; + ram_addr_t offset; + CompressResult result; + + qemu_mutex_lock(¶m->mutex); + while (!param->quit) { + if (param->trigger) { + block =3D param->block; + offset =3D param->offset; + param->trigger =3D false; + qemu_mutex_unlock(¶m->mutex); + + result =3D do_compress_ram_page(param->file, ¶m->stream, + block, offset, param->originbuf); + + qemu_mutex_lock(&comp_done_lock); + param->done =3D true; + param->result =3D result; + qemu_cond_signal(&comp_done_cond); + qemu_mutex_unlock(&comp_done_lock); + + qemu_mutex_lock(¶m->mutex); + } else { + qemu_cond_wait(¶m->cond, ¶m->mutex); + } + } + qemu_mutex_unlock(¶m->mutex); + + return NULL; +} + +void compress_threads_save_cleanup(void) +{ + int i, thread_count; + + if (!migrate_compress() || !comp_param) { + return; + } + + thread_count =3D migrate_compress_threads(); + for (i =3D 0; i < thread_count; i++) { + /* + * we use it as a indicator which shows if the thread is + * properly init'd or not + */ + if (!comp_param[i].file) { + break; + } + + qemu_mutex_lock(&comp_param[i].mutex); + comp_param[i].quit =3D true; + qemu_cond_signal(&comp_param[i].cond); + qemu_mutex_unlock(&comp_param[i].mutex); + + qemu_thread_join(compress_threads + i); + qemu_mutex_destroy(&comp_param[i].mutex); + qemu_cond_destroy(&comp_param[i].cond); + deflateEnd(&comp_param[i].stream); + g_free(comp_param[i].originbuf); + qemu_fclose(comp_param[i].file); + comp_param[i].file =3D NULL; + } + qemu_mutex_destroy(&comp_done_lock); + qemu_cond_destroy(&comp_done_cond); + g_free(compress_threads); + g_free(comp_param); + compress_threads =3D NULL; + comp_param =3D NULL; +} + +int compress_threads_save_setup(void) +{ + int i, thread_count; + + if (!migrate_compress()) { + return 0; + } + thread_count =3D migrate_compress_threads(); + compress_threads =3D g_new0(QemuThread, thread_count); + comp_param =3D g_new0(CompressParam, thread_count); + qemu_cond_init(&comp_done_cond); + qemu_mutex_init(&comp_done_lock); + for (i =3D 0; i < thread_count; i++) { + comp_param[i].originbuf =3D g_try_malloc(TARGET_PAGE_SIZE); + if (!comp_param[i].originbuf) { + goto exit; + } + + if (deflateInit(&comp_param[i].stream, + migrate_compress_level()) !=3D Z_OK) { + g_free(comp_param[i].originbuf); + goto exit; + } + + /* comp_param[i].file is just used as a dummy buffer to save data, + * set its ops to empty. + */ + comp_param[i].file =3D qemu_file_new_output( + QIO_CHANNEL(qio_channel_null_new())); + comp_param[i].done =3D true; + comp_param[i].quit =3D false; + qemu_mutex_init(&comp_param[i].mutex); + qemu_cond_init(&comp_param[i].cond); + qemu_thread_create(compress_threads + i, "compress", + do_data_compress, comp_param + i, + QEMU_THREAD_JOINABLE); + } + return 0; + +exit: + compress_threads_save_cleanup(); + return -1; +} + +static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, + RAMBlock *block, ram_addr_t off= set, + uint8_t *source_buf) +{ + uint8_t *p =3D block->host + offset; + int ret; + + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { + return RES_ZEROPAGE; + } + + /* + * copy it to a internal buffer to avoid it being modified by VM + * so that we can catch up the error during compression and + * decompression + */ + memcpy(source_buf, p, TARGET_PAGE_SIZE); + ret =3D qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_S= IZE); + if (ret < 0) { + qemu_file_set_error(migrate_get_current()->to_dst_file, ret); + error_report("compressed data failed!"); + return RES_NONE; + } + return RES_COMPRESS; +} + +static inline void compress_reset_result(CompressParam *param) +{ + param->result =3D RES_NONE; + param->block =3D NULL; + param->offset =3D 0; +} + +void flush_compressed_data(int (send_queued_data(CompressParam *))) +{ + int idx, thread_count; + + thread_count =3D migrate_compress_threads(); + + qemu_mutex_lock(&comp_done_lock); + for (idx =3D 0; idx < thread_count; idx++) { + while (!comp_param[idx].done) { + qemu_cond_wait(&comp_done_cond, &comp_done_lock); + } + } + qemu_mutex_unlock(&comp_done_lock); + + for (idx =3D 0; idx < thread_count; idx++) { + qemu_mutex_lock(&comp_param[idx].mutex); + if (!comp_param[idx].quit) { + CompressParam *param =3D &comp_param[idx]; + send_queued_data(param); + compress_reset_result(param); + } + qemu_mutex_unlock(&comp_param[idx].mutex); + } +} + +static inline void set_compress_params(CompressParam *param, RAMBlock *blo= ck, + ram_addr_t offset) +{ + param->block =3D block; + param->offset =3D offset; + param->trigger =3D true; +} + +int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, + int (send_queued_data(CompressParam *))) +{ + int idx, thread_count, pages =3D -1; + bool wait =3D migrate_compress_wait_thread(); + + thread_count =3D migrate_compress_threads(); + qemu_mutex_lock(&comp_done_lock); +retry: + for (idx =3D 0; idx < thread_count; idx++) { + if (comp_param[idx].done) { + CompressParam *param =3D &comp_param[idx]; + qemu_mutex_lock(¶m->mutex); + param->done =3D false; + send_queued_data(param); + compress_reset_result(param); + set_compress_params(param, block, offset); + + qemu_cond_signal(¶m->cond); + qemu_mutex_unlock(¶m->mutex); + pages =3D 1; + break; + } + } + + /* + * wait for the free thread if the user specifies 'compress-wait-threa= d', + * otherwise we will post the page out in the main thread as normal pa= ge. + */ + if (pages < 0 && wait) { + qemu_cond_wait(&comp_done_cond, &comp_done_lock); + goto retry; + } + qemu_mutex_unlock(&comp_done_lock); + + return pages; +} diff --git a/migration/ram-compress.h b/migration/ram-compress.h new file mode 100644 index 0000000000..06570a799c --- /dev/null +++ b/migration/ram-compress.h @@ -0,0 +1,65 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2011-2015 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef QEMU_MIGRATION_COMPRESS_H +#define QEMU_MIGRATION_COMPRESS_H + +#include "qemu-file.h" + +enum CompressResult { + RES_NONE =3D 0, + RES_ZEROPAGE =3D 1, + RES_COMPRESS =3D 2 +}; +typedef enum CompressResult CompressResult; + +struct CompressParam { + bool done; + bool quit; + bool trigger; + CompressResult result; + QEMUFile *file; + QemuMutex mutex; + QemuCond cond; + RAMBlock *block; + ram_addr_t offset; + + /* internally used fields */ + z_stream stream; + uint8_t *originbuf; +}; +typedef struct CompressParam CompressParam; + +void compress_threads_save_cleanup(void); +int compress_threads_save_setup(void); + +void flush_compressed_data(int (send_queued_data(CompressParam *))); +int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, + int (send_queued_data(CompressParam *))); + +#endif diff --git a/migration/ram.c b/migration/ram.c index 0cce65dfa5..d01d1773d0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -32,8 +32,8 @@ #include "qemu/bitmap.h" #include "qemu/madvise.h" #include "qemu/main-loop.h" -#include "io/channel-null.h" #include "xbzrle.h" +#include "ram-compress.h" #include "ram.h" #include "migration.h" #include "migration-stats.h" @@ -480,32 +480,6 @@ typedef struct MigrationOps MigrationOps; =20 MigrationOps *migration_ops; =20 -CompressionStats compression_counters; - -enum CompressResult { - RES_NONE =3D 0, - RES_ZEROPAGE =3D 1, - RES_COMPRESS =3D 2 -}; -typedef enum CompressResult CompressResult; - -struct CompressParam { - bool done; - bool quit; - bool trigger; - CompressResult result; - QEMUFile *file; - QemuMutex mutex; - QemuCond cond; - RAMBlock *block; - ram_addr_t offset; - - /* internally used fields */ - z_stream stream; - uint8_t *originbuf; -}; -typedef struct CompressParam CompressParam; - struct DecompressParam { bool done; bool quit; @@ -518,15 +492,6 @@ struct DecompressParam { }; typedef struct DecompressParam DecompressParam; =20 -static CompressParam *comp_param; -static QemuThread *compress_threads; -/* comp_done_cond is used to wake up the migration thread when - * one of the compression threads has finished the compression. - * comp_done_lock is used to co-work with comp_done_cond. - */ -static QemuMutex comp_done_lock; -static QemuCond comp_done_cond; - static QEMUFile *decomp_file; static DecompressParam *decomp_param; static QemuThread *decompress_threads; @@ -535,10 +500,6 @@ static QemuCond decomp_done_cond; =20 static int ram_save_host_page_urgent(PageSearchStatus *pss); =20 -static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, - RAMBlock *block, ram_addr_t off= set, - uint8_t *source_buf); - /* NOTE: page is the PFN not real ram_addr_t. */ static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) { @@ -557,123 +518,6 @@ static bool pss_overlap(PageSearchStatus *pss1, PageS= earchStatus *pss2) (pss1->host_page_start =3D=3D pss2->host_page_start); } =20 -static void *do_data_compress(void *opaque) -{ - CompressParam *param =3D opaque; - RAMBlock *block; - ram_addr_t offset; - CompressResult result; - - qemu_mutex_lock(¶m->mutex); - while (!param->quit) { - if (param->trigger) { - block =3D param->block; - offset =3D param->offset; - param->trigger =3D false; - qemu_mutex_unlock(¶m->mutex); - - result =3D do_compress_ram_page(param->file, ¶m->stream, - block, offset, param->originbuf); - - qemu_mutex_lock(&comp_done_lock); - param->done =3D true; - param->result =3D result; - qemu_cond_signal(&comp_done_cond); - qemu_mutex_unlock(&comp_done_lock); - - qemu_mutex_lock(¶m->mutex); - } else { - qemu_cond_wait(¶m->cond, ¶m->mutex); - } - } - qemu_mutex_unlock(¶m->mutex); - - return NULL; -} - -static void compress_threads_save_cleanup(void) -{ - int i, thread_count; - - if (!migrate_compress() || !comp_param) { - return; - } - - thread_count =3D migrate_compress_threads(); - for (i =3D 0; i < thread_count; i++) { - /* - * we use it as a indicator which shows if the thread is - * properly init'd or not - */ - if (!comp_param[i].file) { - break; - } - - qemu_mutex_lock(&comp_param[i].mutex); - comp_param[i].quit =3D true; - qemu_cond_signal(&comp_param[i].cond); - qemu_mutex_unlock(&comp_param[i].mutex); - - qemu_thread_join(compress_threads + i); - qemu_mutex_destroy(&comp_param[i].mutex); - qemu_cond_destroy(&comp_param[i].cond); - deflateEnd(&comp_param[i].stream); - g_free(comp_param[i].originbuf); - qemu_fclose(comp_param[i].file); - comp_param[i].file =3D NULL; - } - qemu_mutex_destroy(&comp_done_lock); - qemu_cond_destroy(&comp_done_cond); - g_free(compress_threads); - g_free(comp_param); - compress_threads =3D NULL; - comp_param =3D NULL; -} - -static int compress_threads_save_setup(void) -{ - int i, thread_count; - - if (!migrate_compress()) { - return 0; - } - thread_count =3D migrate_compress_threads(); - compress_threads =3D g_new0(QemuThread, thread_count); - comp_param =3D g_new0(CompressParam, thread_count); - qemu_cond_init(&comp_done_cond); - qemu_mutex_init(&comp_done_lock); - for (i =3D 0; i < thread_count; i++) { - comp_param[i].originbuf =3D g_try_malloc(TARGET_PAGE_SIZE); - if (!comp_param[i].originbuf) { - goto exit; - } - - if (deflateInit(&comp_param[i].stream, - migrate_compress_level()) !=3D Z_OK) { - g_free(comp_param[i].originbuf); - goto exit; - } - - /* comp_param[i].file is just used as a dummy buffer to save data, - * set its ops to empty. - */ - comp_param[i].file =3D qemu_file_new_output( - QIO_CHANNEL(qio_channel_null_new())); - comp_param[i].done =3D true; - comp_param[i].quit =3D false; - qemu_mutex_init(&comp_param[i].mutex); - qemu_cond_init(&comp_param[i].cond); - qemu_thread_create(compress_threads + i, "compress", - do_data_compress, comp_param + i, - QEMU_THREAD_JOINABLE); - } - return 0; - -exit: - compress_threads_save_cleanup(); - return -1; -} - /** * save_page_header: write page header to wire * @@ -1461,32 +1305,6 @@ static int ram_save_multifd_page(QEMUFile *file, RAM= Block *block, return 1; } =20 -static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, - RAMBlock *block, ram_addr_t off= set, - uint8_t *source_buf) -{ - uint8_t *p =3D block->host + offset; - int ret; - - if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - return RES_ZEROPAGE; - } - - /* - * copy it to a internal buffer to avoid it being modified by VM - * so that we can catch up the error during compression and - * decompression - */ - memcpy(source_buf, p, TARGET_PAGE_SIZE); - ret =3D qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_S= IZE); - if (ret < 0) { - qemu_file_set_error(migrate_get_current()->to_dst_file, ret); - error_report("compressed data failed!"); - return RES_NONE; - } - return RES_COMPRESS; -} - static void update_compress_thread_counts(const CompressParam *param, int bytes_xmit) { @@ -1504,13 +1322,6 @@ update_compress_thread_counts(const CompressParam *p= aram, int bytes_xmit) =20 static bool save_page_use_compression(RAMState *rs); =20 -static inline void compress_reset_result(CompressParam *param) -{ - param->result =3D RES_NONE; - param->block =3D NULL; - param->offset =3D 0; -} - static int send_queued_data(CompressParam *param) { PageSearchStatus *pss =3D &ram_state->pss[RAM_CHANNEL_PRECOPY]; @@ -1545,31 +1356,6 @@ static int send_queued_data(CompressParam *param) return len; } =20 -static void flush_compressed_data(int (send_queued_data(CompressParam *))) -{ - int idx, thread_count; - - thread_count =3D migrate_compress_threads(); - - qemu_mutex_lock(&comp_done_lock); - for (idx =3D 0; idx < thread_count; idx++) { - while (!comp_param[idx].done) { - qemu_cond_wait(&comp_done_cond, &comp_done_lock); - } - } - qemu_mutex_unlock(&comp_done_lock); - - for (idx =3D 0; idx < thread_count; idx++) { - qemu_mutex_lock(&comp_param[idx].mutex); - if (!comp_param[idx].quit) { - CompressParam *param =3D &comp_param[idx]; - send_queued_data(param); - compress_reset_result(param); - } - qemu_mutex_unlock(&comp_param[idx].mutex); - } -} - static void ram_flush_compressed_data(RAMState *rs) { if (!save_page_use_compression(rs)) { @@ -1579,52 +1365,6 @@ static void ram_flush_compressed_data(RAMState *rs) flush_compressed_data(send_queued_data); } =20 -static inline void set_compress_params(CompressParam *param, RAMBlock *blo= ck, - ram_addr_t offset) -{ - param->block =3D block; - param->offset =3D offset; - param->trigger =3D true; -} - -static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set, - int (send_queued_data(CompressParam *))) -{ - int idx, thread_count, pages =3D -1; - bool wait =3D migrate_compress_wait_thread(); - - thread_count =3D migrate_compress_threads(); - qemu_mutex_lock(&comp_done_lock); -retry: - for (idx =3D 0; idx < thread_count; idx++) { - if (comp_param[idx].done) { - CompressParam *param =3D &comp_param[idx]; - qemu_mutex_lock(¶m->mutex); - param->done =3D false; - send_queued_data(param); - compress_reset_result(param); - set_compress_params(param, block, offset); - - qemu_cond_signal(¶m->cond); - qemu_mutex_unlock(¶m->mutex); - pages =3D 1; - break; - } - } - - /* - * wait for the free thread if the user specifies 'compress-wait-threa= d', - * otherwise we will post the page out in the main thread as normal pa= ge. - */ - if (pages < 0 && wait) { - qemu_cond_wait(&comp_done_cond, &comp_done_lock); - goto retry; - } - qemu_mutex_unlock(&comp_done_lock); - - return pages; -} - #define PAGE_ALL_CLEAN 0 #define PAGE_TRY_AGAIN 1 #define PAGE_DIRTY_FOUND 2 --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559771; cv=none; d=zohomail.com; s=zohoarc; b=S3wq0XguapHELQVlHCG8ZwclHDZ7QvszldFhbYAwDSS09rQ/lTZhCO0AfibfKjo2ERm3nw1mhV2UNiMs0K70i1lEe/hhSBe7EHyh2+U8HxBijiQ/wfD7HJyoIBIE9KvszITxd5pWlgSf3Dx0qCl6DL9PQqD7vLtSdeHhG6/u6jQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559771; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RwYOVge2NEBtRUpP8ZC3O8m80kO6lJPkm+g3YsbrJ9s=; b=gIbnw70ducc1AInVKctw79ULQ7iEB3APw7w/I2EcZehuDVq1ZHkUn7WdlvCDLEwfcI+rF6N9lQ9ZqyGpE2OZsvFqjZsDXkeDnX/13TTzjK3qDeE/HbENeJNAIkqyVQO03fLyPSomZa9N9F59pgfxM7GjV7X36neokShn9+yq4YQ= 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 16835597715641007.0863855987576; Mon, 8 May 2023 08:29:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2mA-0005Wq-0f; Mon, 08 May 2023 11:27:46 -0400 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 1pw2m7-0005G5-AQ for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:43 -0400 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 1pw2ly-0004bi-5M for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-eFs5HE7nN1C4LW6fU2g-pw-1; Mon, 08 May 2023 11:27:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AC1C18E530C; Mon, 8 May 2023 15:27:20 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EADA40C6F41; Mon, 8 May 2023 15:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RwYOVge2NEBtRUpP8ZC3O8m80kO6lJPkm+g3YsbrJ9s=; b=d4lQOnNIP/m54jErfoNNA+cu8GWoB/OTeKLfWnOOuDkH4Ivyx1iqZsZNAErJoYm/WyiuZg ytUvqs9FycZJ71cbjIP07qOZcboijU0k0wikK7HkfYx3IhdawnOJ1NBLpTVJINarzEJzpc RQTHXKGW4LXevhEd8N1UTBr/MJASZKw= X-MC-Unique: eFs5HE7nN1C4LW6fU2g-pw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 10/13] ram.c: Move core decompression code into its own file Date: Mon, 8 May 2023 17:26:54 +0200 Message-Id: <20230508152657.66701-11-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559772487100001 From: Lukas Straub No functional changes intended. Signed-off-by: Lukas Straub Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram-compress.c | 203 ++++++++++++++++++++++++++++++++++++++ migration/ram-compress.h | 5 + migration/ram.c | 204 --------------------------------------- 3 files changed, 208 insertions(+), 204 deletions(-) diff --git a/migration/ram-compress.c b/migration/ram-compress.c index d9bc67d075..c25562f12d 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -48,6 +48,24 @@ static QemuThread *compress_threads; static QemuMutex comp_done_lock; static QemuCond comp_done_cond; =20 +struct DecompressParam { + bool done; + bool quit; + QemuMutex mutex; + QemuCond cond; + void *des; + uint8_t *compbuf; + int len; + z_stream stream; +}; +typedef struct DecompressParam DecompressParam; + +static QEMUFile *decomp_file; +static DecompressParam *decomp_param; +static QemuThread *decompress_threads; +static QemuMutex decomp_done_lock; +static QemuCond decomp_done_cond; + static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, ram_addr_t off= set, uint8_t *source_buf); @@ -272,3 +290,188 @@ retry: =20 return pages; } + +/* return the size after decompression, or negative value on error */ +static int +qemu_uncompress_data(z_stream *stream, uint8_t *dest, size_t dest_len, + const uint8_t *source, size_t source_len) +{ + int err; + + err =3D inflateReset(stream); + if (err !=3D Z_OK) { + return -1; + } + + stream->avail_in =3D source_len; + stream->next_in =3D (uint8_t *)source; + stream->avail_out =3D dest_len; + stream->next_out =3D dest; + + err =3D inflate(stream, Z_NO_FLUSH); + if (err !=3D Z_STREAM_END) { + return -1; + } + + return stream->total_out; +} + +static void *do_data_decompress(void *opaque) +{ + DecompressParam *param =3D opaque; + unsigned long pagesize; + uint8_t *des; + int len, ret; + + qemu_mutex_lock(¶m->mutex); + while (!param->quit) { + if (param->des) { + des =3D param->des; + len =3D param->len; + param->des =3D 0; + qemu_mutex_unlock(¶m->mutex); + + pagesize =3D TARGET_PAGE_SIZE; + + ret =3D qemu_uncompress_data(¶m->stream, des, pagesize, + param->compbuf, len); + if (ret < 0 && migrate_get_current()->decompress_error_check) { + error_report("decompress data failed"); + qemu_file_set_error(decomp_file, ret); + } + + qemu_mutex_lock(&decomp_done_lock); + param->done =3D true; + qemu_cond_signal(&decomp_done_cond); + qemu_mutex_unlock(&decomp_done_lock); + + qemu_mutex_lock(¶m->mutex); + } else { + qemu_cond_wait(¶m->cond, ¶m->mutex); + } + } + qemu_mutex_unlock(¶m->mutex); + + return NULL; +} + +int wait_for_decompress_done(void) +{ + int idx, thread_count; + + if (!migrate_compress()) { + return 0; + } + + thread_count =3D migrate_decompress_threads(); + qemu_mutex_lock(&decomp_done_lock); + for (idx =3D 0; idx < thread_count; idx++) { + while (!decomp_param[idx].done) { + qemu_cond_wait(&decomp_done_cond, &decomp_done_lock); + } + } + qemu_mutex_unlock(&decomp_done_lock); + return qemu_file_get_error(decomp_file); +} + +void compress_threads_load_cleanup(void) +{ + int i, thread_count; + + if (!migrate_compress()) { + return; + } + thread_count =3D migrate_decompress_threads(); + for (i =3D 0; i < thread_count; i++) { + /* + * we use it as a indicator which shows if the thread is + * properly init'd or not + */ + if (!decomp_param[i].compbuf) { + break; + } + + qemu_mutex_lock(&decomp_param[i].mutex); + decomp_param[i].quit =3D true; + qemu_cond_signal(&decomp_param[i].cond); + qemu_mutex_unlock(&decomp_param[i].mutex); + } + for (i =3D 0; i < thread_count; i++) { + if (!decomp_param[i].compbuf) { + break; + } + + qemu_thread_join(decompress_threads + i); + qemu_mutex_destroy(&decomp_param[i].mutex); + qemu_cond_destroy(&decomp_param[i].cond); + inflateEnd(&decomp_param[i].stream); + g_free(decomp_param[i].compbuf); + decomp_param[i].compbuf =3D NULL; + } + g_free(decompress_threads); + g_free(decomp_param); + decompress_threads =3D NULL; + decomp_param =3D NULL; + decomp_file =3D NULL; +} + +int compress_threads_load_setup(QEMUFile *f) +{ + int i, thread_count; + + if (!migrate_compress()) { + return 0; + } + + thread_count =3D migrate_decompress_threads(); + decompress_threads =3D g_new0(QemuThread, thread_count); + decomp_param =3D g_new0(DecompressParam, thread_count); + qemu_mutex_init(&decomp_done_lock); + qemu_cond_init(&decomp_done_cond); + decomp_file =3D f; + for (i =3D 0; i < thread_count; i++) { + if (inflateInit(&decomp_param[i].stream) !=3D Z_OK) { + goto exit; + } + + decomp_param[i].compbuf =3D g_malloc0(compressBound(TARGET_PAGE_SI= ZE)); + qemu_mutex_init(&decomp_param[i].mutex); + qemu_cond_init(&decomp_param[i].cond); + decomp_param[i].done =3D true; + decomp_param[i].quit =3D false; + qemu_thread_create(decompress_threads + i, "decompress", + do_data_decompress, decomp_param + i, + QEMU_THREAD_JOINABLE); + } + return 0; +exit: + compress_threads_load_cleanup(); + return -1; +} + +void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len) +{ + int idx, thread_count; + + thread_count =3D migrate_decompress_threads(); + QEMU_LOCK_GUARD(&decomp_done_lock); + while (true) { + for (idx =3D 0; idx < thread_count; idx++) { + if (decomp_param[idx].done) { + decomp_param[idx].done =3D false; + qemu_mutex_lock(&decomp_param[idx].mutex); + qemu_get_buffer(f, decomp_param[idx].compbuf, len); + decomp_param[idx].des =3D host; + decomp_param[idx].len =3D len; + qemu_cond_signal(&decomp_param[idx].cond); + qemu_mutex_unlock(&decomp_param[idx].mutex); + break; + } + } + if (idx < thread_count) { + break; + } else { + qemu_cond_wait(&decomp_done_cond, &decomp_done_lock); + } + } +} diff --git a/migration/ram-compress.h b/migration/ram-compress.h index 06570a799c..6f7fe2f472 100644 --- a/migration/ram-compress.h +++ b/migration/ram-compress.h @@ -62,4 +62,9 @@ void flush_compressed_data(int (send_queued_data(Compress= Param *))); int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, int (send_queued_data(CompressParam *))); =20 +int wait_for_decompress_done(void); +void compress_threads_load_cleanup(void); +int compress_threads_load_setup(QEMUFile *f); +void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len); + #endif diff --git a/migration/ram.c b/migration/ram.c index d01d1773d0..009681d213 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -480,24 +480,6 @@ typedef struct MigrationOps MigrationOps; =20 MigrationOps *migration_ops; =20 -struct DecompressParam { - bool done; - bool quit; - QemuMutex mutex; - QemuCond cond; - void *des; - uint8_t *compbuf; - int len; - z_stream stream; -}; -typedef struct DecompressParam DecompressParam; - -static QEMUFile *decomp_file; -static DecompressParam *decomp_param; -static QemuThread *decompress_threads; -static QemuMutex decomp_done_lock; -static QemuCond decomp_done_cond; - static int ram_save_host_page_urgent(PageSearchStatus *pss); =20 /* NOTE: page is the PFN not real ram_addr_t. */ @@ -3465,192 +3447,6 @@ void ram_handle_compressed(void *host, uint8_t ch, = uint64_t size) } } =20 -/* return the size after decompression, or negative value on error */ -static int -qemu_uncompress_data(z_stream *stream, uint8_t *dest, size_t dest_len, - const uint8_t *source, size_t source_len) -{ - int err; - - err =3D inflateReset(stream); - if (err !=3D Z_OK) { - return -1; - } - - stream->avail_in =3D source_len; - stream->next_in =3D (uint8_t *)source; - stream->avail_out =3D dest_len; - stream->next_out =3D dest; - - err =3D inflate(stream, Z_NO_FLUSH); - if (err !=3D Z_STREAM_END) { - return -1; - } - - return stream->total_out; -} - -static void *do_data_decompress(void *opaque) -{ - DecompressParam *param =3D opaque; - unsigned long pagesize; - uint8_t *des; - int len, ret; - - qemu_mutex_lock(¶m->mutex); - while (!param->quit) { - if (param->des) { - des =3D param->des; - len =3D param->len; - param->des =3D 0; - qemu_mutex_unlock(¶m->mutex); - - pagesize =3D TARGET_PAGE_SIZE; - - ret =3D qemu_uncompress_data(¶m->stream, des, pagesize, - param->compbuf, len); - if (ret < 0 && migrate_get_current()->decompress_error_check) { - error_report("decompress data failed"); - qemu_file_set_error(decomp_file, ret); - } - - qemu_mutex_lock(&decomp_done_lock); - param->done =3D true; - qemu_cond_signal(&decomp_done_cond); - qemu_mutex_unlock(&decomp_done_lock); - - qemu_mutex_lock(¶m->mutex); - } else { - qemu_cond_wait(¶m->cond, ¶m->mutex); - } - } - qemu_mutex_unlock(¶m->mutex); - - return NULL; -} - -static int wait_for_decompress_done(void) -{ - int idx, thread_count; - - if (!migrate_compress()) { - return 0; - } - - thread_count =3D migrate_decompress_threads(); - qemu_mutex_lock(&decomp_done_lock); - for (idx =3D 0; idx < thread_count; idx++) { - while (!decomp_param[idx].done) { - qemu_cond_wait(&decomp_done_cond, &decomp_done_lock); - } - } - qemu_mutex_unlock(&decomp_done_lock); - return qemu_file_get_error(decomp_file); -} - -static void compress_threads_load_cleanup(void) -{ - int i, thread_count; - - if (!migrate_compress()) { - return; - } - thread_count =3D migrate_decompress_threads(); - for (i =3D 0; i < thread_count; i++) { - /* - * we use it as a indicator which shows if the thread is - * properly init'd or not - */ - if (!decomp_param[i].compbuf) { - break; - } - - qemu_mutex_lock(&decomp_param[i].mutex); - decomp_param[i].quit =3D true; - qemu_cond_signal(&decomp_param[i].cond); - qemu_mutex_unlock(&decomp_param[i].mutex); - } - for (i =3D 0; i < thread_count; i++) { - if (!decomp_param[i].compbuf) { - break; - } - - qemu_thread_join(decompress_threads + i); - qemu_mutex_destroy(&decomp_param[i].mutex); - qemu_cond_destroy(&decomp_param[i].cond); - inflateEnd(&decomp_param[i].stream); - g_free(decomp_param[i].compbuf); - decomp_param[i].compbuf =3D NULL; - } - g_free(decompress_threads); - g_free(decomp_param); - decompress_threads =3D NULL; - decomp_param =3D NULL; - decomp_file =3D NULL; -} - -static int compress_threads_load_setup(QEMUFile *f) -{ - int i, thread_count; - - if (!migrate_compress()) { - return 0; - } - - thread_count =3D migrate_decompress_threads(); - decompress_threads =3D g_new0(QemuThread, thread_count); - decomp_param =3D g_new0(DecompressParam, thread_count); - qemu_mutex_init(&decomp_done_lock); - qemu_cond_init(&decomp_done_cond); - decomp_file =3D f; - for (i =3D 0; i < thread_count; i++) { - if (inflateInit(&decomp_param[i].stream) !=3D Z_OK) { - goto exit; - } - - decomp_param[i].compbuf =3D g_malloc0(compressBound(TARGET_PAGE_SI= ZE)); - qemu_mutex_init(&decomp_param[i].mutex); - qemu_cond_init(&decomp_param[i].cond); - decomp_param[i].done =3D true; - decomp_param[i].quit =3D false; - qemu_thread_create(decompress_threads + i, "decompress", - do_data_decompress, decomp_param + i, - QEMU_THREAD_JOINABLE); - } - return 0; -exit: - compress_threads_load_cleanup(); - return -1; -} - -static void decompress_data_with_multi_threads(QEMUFile *f, - void *host, int len) -{ - int idx, thread_count; - - thread_count =3D migrate_decompress_threads(); - QEMU_LOCK_GUARD(&decomp_done_lock); - while (true) { - for (idx =3D 0; idx < thread_count; idx++) { - if (decomp_param[idx].done) { - decomp_param[idx].done =3D false; - qemu_mutex_lock(&decomp_param[idx].mutex); - qemu_get_buffer(f, decomp_param[idx].compbuf, len); - decomp_param[idx].des =3D host; - decomp_param[idx].len =3D len; - qemu_cond_signal(&decomp_param[idx].cond); - qemu_mutex_unlock(&decomp_param[idx].mutex); - break; - } - } - if (idx < thread_count) { - break; - } else { - qemu_cond_wait(&decomp_done_cond, &decomp_done_lock); - } - } -} - static void colo_init_ram_state(void) { ram_state_init(&ram_state); --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559727; cv=none; d=zohomail.com; s=zohoarc; b=CHzhllefs/Spj66iTHoOV358ulmuHL64v9sYwr2gwKPantxz6jeuJnAaXsV7/BavYPw3fBoE41m+upKtVlZvDyyXq8xfEz4puuGeRtfJ/kQUeLijP3oULSQwMHujIJOqTe+IurflPSJd9Mhpbeh9mWEg4dtXu2en6VtnmnTbrlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559727; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SYscSa5qs0TT7ug+FUN3WGUBOgborh0kKbtoRyk62KQ=; b=JhRPRuTBHRfg2VR5Pj/PRvrHpw5PzMsNFWwCyQvr3CjVNcsWqMJvx82kuf9YreDya0Ns9C2e4AUdNkU9an1aROP7xIC+J95DPRf7MakAs2ZKlHdJJoJgDS9EKmEQBLtdPi+Ow/0LVejkj4zLPnB92MPcFdfZx0I8tpo9wdHgs2A= 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 1683559727979563.3896628444289; Mon, 8 May 2023 08:28:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lt-0004ex-40; Mon, 08 May 2023 11:27:29 -0400 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 1pw2lr-0004eM-Br for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:27 -0400 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 1pw2lp-0004aa-OJ for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-306-rhR6UnhjOt-ujsgbuaQlgA-1; Mon, 08 May 2023 11:27:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9BEC91011579; Mon, 8 May 2023 15:27:21 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FEF340C6F41; Mon, 8 May 2023 15:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559645; 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=SYscSa5qs0TT7ug+FUN3WGUBOgborh0kKbtoRyk62KQ=; b=gREjheduTzuhqq5pTkIjrOMsE7gJHOQ5ij/R0yXJUEN8qkciJz6svtfWKznjdnpPimNdsL hF4SyapcGura/MS1sVsWdcq7MisQUsXK7e+y2vL0a4H+8w5Qp+460Xry8FnhbQTIOBmRZv Xm3MKh8F+gehfYFK5nCn8lVvs8FafVU= X-MC-Unique: rhR6UnhjOt-ujsgbuaQlgA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 11/13] ram compress: Assert that the file buffer matches the result Date: Mon, 8 May 2023 17:26:55 +0200 Message-Id: <20230508152657.66701-12-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H2=-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: 1683559729677100014 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Before this series, "nothing to send" was handled by the file buffer being empty. Now it is tracked via param->result. Assert that the file buffer state matches the result. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/qemu-file.c | 11 +++++++++++ migration/qemu-file.h | 1 + migration/ram-compress.c | 5 +++++ migration/ram.c | 2 ++ 4 files changed, 19 insertions(+) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index f4cfd05c67..61fb580342 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -870,6 +870,17 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_sr= c) return len; } =20 +/* + * Check if the writable buffer is empty + */ + +bool qemu_file_buffer_empty(QEMUFile *file) +{ + assert(qemu_file_is_writable(file)); + + return !file->iovcnt; +} + /* * Get a string whose length is determined by a single preceding byte * A preallocated 256 byte buffer must be passed in. diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 4f26bf6961..4ee58a87dd 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -113,6 +113,7 @@ size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMU= File *f, uint8_t **buf, s ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, const uint8_t *p, size_t size); int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src); +bool qemu_file_buffer_empty(QEMUFile *file); =20 /* * Note that you can only peek continuous bytes from where the current poi= nter diff --git a/migration/ram-compress.c b/migration/ram-compress.c index c25562f12d..3d2a4a6329 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -194,6 +194,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f,= z_stream *stream, uint8_t *p =3D block->host + offset; int ret; =20 + assert(qemu_file_buffer_empty(f)); + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { return RES_ZEROPAGE; } @@ -208,6 +210,7 @@ static CompressResult do_compress_ram_page(QEMUFile *f,= z_stream *stream, if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); + qemu_fflush(f); return RES_NONE; } return RES_COMPRESS; @@ -239,6 +242,7 @@ void flush_compressed_data(int (send_queued_data(Compre= ssParam *))) if (!comp_param[idx].quit) { CompressParam *param =3D &comp_param[idx]; send_queued_data(param); + assert(qemu_file_buffer_empty(param->file)); compress_reset_result(param); } qemu_mutex_unlock(&comp_param[idx].mutex); @@ -268,6 +272,7 @@ retry: qemu_mutex_lock(¶m->mutex); param->done =3D false; send_queued_data(param); + assert(qemu_file_buffer_empty(param->file)); compress_reset_result(param); set_compress_params(param, block, offset); =20 diff --git a/migration/ram.c b/migration/ram.c index 009681d213..ee4ab31f25 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1321,11 +1321,13 @@ static int send_queued_data(CompressParam *param) assert(block =3D=3D pss->last_sent_block); =20 if (param->result =3D=3D RES_ZEROPAGE) { + assert(qemu_file_buffer_empty(param->file)); len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG= _ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(block->idstr, offset); } else if (param->result =3D=3D RES_COMPRESS) { + assert(!qemu_file_buffer_empty(param->file)); len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); len +=3D qemu_put_qemu_file(file, param->file); --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559742; cv=none; d=zohomail.com; s=zohoarc; b=WnY/uyIKt4ucDfcbaXK7vJG8F/M6bqr3cSoMwXQTvjHLhbBZ03EB8N/BcC6SDmb556yr6uGzCxIIawldd8cQGDpQx/YiIXhaPUBdRqyP6sCdRmrG8q/Ud19Z4kHMeG524TUaditOCis1pHtPoHV2i0YsE472f42/2JROUUmwL7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559742; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cqRiOcVsnq1dkPr7YEiysrQqEMeOB41ddSA57KdHrJY=; b=RKo0ZFXFKA5oZnmpJP+OWNcfQonJTeyeeHCBrF4gdc0BO0PqhgT6/BlL+PY7Xm9V1cAO7SIkn1fs8Hl6Byl2IAyJVNkZpgRmNlku4uttCfw7J31ExBg7/9xzNdv3DPC1wzOYIm5WPJAFBoSBCs7FQzfMr+NYnv7sYfaRqvmkJJ8= 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 1683559742499207.81506069312627; Mon, 8 May 2023 08:29:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lv-0004in-6W; Mon, 08 May 2023 11:27:31 -0400 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 1pw2lt-0004f1-1w for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:29 -0400 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 1pw2lr-0004as-Dk for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:28 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-Z08uUU7MNMGFf-Qt6hajTQ-1; Mon, 08 May 2023 11:27:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A02A101A55C; Mon, 8 May 2023 15:27:23 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0E6040C6F41; Mon, 8 May 2023 15:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cqRiOcVsnq1dkPr7YEiysrQqEMeOB41ddSA57KdHrJY=; b=U6ENHe8KtMkAFvFeYW9cCxKzFsLAnFD5Zn+B0sjdhyXNymHRO+LxtiQyk9iLFwdpCC2boL xVWc4KcsVVfNT0ixuaqukZSnbRB/ccc1ENXktVWWdhkr8+rZOcb6EkOaOFfHY0PXm2F2Ff vSFYIyQ2lWDb6w3Xpdeo+rlQxmeWA40= X-MC-Unique: Z08uUU7MNMGFf-Qt6hajTQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 12/13] ram-compress.c: Make target independent Date: Mon, 8 May 2023 17:26:56 +0200 Message-Id: <20230508152657.66701-13-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559744190100003 From: Lukas Straub Make ram-compress.c target independent. Signed-off-by: Lukas Straub Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/meson.build | 3 ++- migration/ram-compress.c | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/migration/meson.build b/migration/meson.build index 2090af8e85..75de868bb7 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -23,6 +23,8 @@ softmmu_ss.add(files( 'migration.c', 'multifd.c', 'multifd-zlib.c', + 'multifd-zlib.c', + 'ram-compress.c', 'options.c', 'postcopy-ram.c', 'savevm.c', @@ -40,5 +42,4 @@ softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c= ')) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files('dirtyrate.c', 'ram.c', - 'ram-compress.c', 'target.c')) diff --git a/migration/ram-compress.c b/migration/ram-compress.c index 3d2a4a6329..06254d8c69 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -35,7 +35,8 @@ #include "migration.h" #include "options.h" #include "io/channel-null.h" -#include "exec/ram_addr.h" +#include "exec/target_page.h" +#include "exec/ramblock.h" =20 CompressionStats compression_counters; =20 @@ -156,7 +157,7 @@ int compress_threads_save_setup(void) qemu_cond_init(&comp_done_cond); qemu_mutex_init(&comp_done_lock); for (i =3D 0; i < thread_count; i++) { - comp_param[i].originbuf =3D g_try_malloc(TARGET_PAGE_SIZE); + comp_param[i].originbuf =3D g_try_malloc(qemu_target_page_size()); if (!comp_param[i].originbuf) { goto exit; } @@ -192,11 +193,12 @@ static CompressResult do_compress_ram_page(QEMUFile *= f, z_stream *stream, uint8_t *source_buf) { uint8_t *p =3D block->host + offset; + size_t page_size =3D qemu_target_page_size(); int ret; =20 assert(qemu_file_buffer_empty(f)); =20 - if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { + if (buffer_is_zero(p, page_size)) { return RES_ZEROPAGE; } =20 @@ -205,8 +207,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f,= z_stream *stream, * so that we can catch up the error during compression and * decompression */ - memcpy(source_buf, p, TARGET_PAGE_SIZE); - ret =3D qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_S= IZE); + memcpy(source_buf, p, page_size); + ret =3D qemu_put_compression_data(f, stream, source_buf, page_size); if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); @@ -336,7 +338,7 @@ static void *do_data_decompress(void *opaque) param->des =3D 0; qemu_mutex_unlock(¶m->mutex); =20 - pagesize =3D TARGET_PAGE_SIZE; + pagesize =3D qemu_target_page_size(); =20 ret =3D qemu_uncompress_data(¶m->stream, des, pagesize, param->compbuf, len); @@ -439,7 +441,8 @@ int compress_threads_load_setup(QEMUFile *f) goto exit; } =20 - decomp_param[i].compbuf =3D g_malloc0(compressBound(TARGET_PAGE_SI= ZE)); + size_t compbuf_size =3D compressBound(qemu_target_page_size()); + decomp_param[i].compbuf =3D g_malloc0(compbuf_size); qemu_mutex_init(&decomp_param[i].mutex); qemu_cond_init(&decomp_param[i].cond); decomp_param[i].done =3D true; --=20 2.40.0 From nobody Mon May 13 03:06:43 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=1683559742; cv=none; d=zohomail.com; s=zohoarc; b=D3P1jBs7xc5g5kemcgkRRz3kc9O24iY6jCAGEZajpT0NtfuIPAu0fLEmcDN0mHInWB/cKxC9PGn1yI+LnrasM2GWKbUf5nxTXoWO4tlwn394a1A3oGvtJshDlGa8gapQDnYnJRSUlHg5a4LlkuWZ+bld04q1AJAaJkxkIPI903w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683559742; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6fr72npxk3VbFKkJAIjukWDpU+SeAk6cP5eGQLIX/Y4=; b=QUncwDNCeMEwum/X779mWe+4cysAEQC1XZd9DLqzWVF3gICtd6QzVit3tocdxXYPsFJAq5e4frHL1HWqE+dNKdKmtTHvL91GtC2uMs+xOmDmIbDQ7EzN8TaEJQlzw5aRW3wnvxmYQKx5bRC2d1n+B6duiHIxLd/FiEaxtzltfBI= 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 1683559742926347.6195400168326; Mon, 8 May 2023 08:29:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pw2lw-0004kO-Ft; Mon, 08 May 2023 11:27:32 -0400 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 1pw2lu-0004g1-Ix for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:30 -0400 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 1pw2ls-0004b7-Vu for qemu-devel@nongnu.org; Mon, 08 May 2023 11:27:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-Y5e6AtpZNKqlvh5d-ZpBiQ-1; Mon, 08 May 2023 11:27:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E57C5811E7C; Mon, 8 May 2023 15:27:24 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BBFF40C6F41; Mon, 8 May 2023 15:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683559648; 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=6fr72npxk3VbFKkJAIjukWDpU+SeAk6cP5eGQLIX/Y4=; b=RYUr0Gzg2LnUe/jCBH57IY6eVgWTSmeUZE3nXEabbsk0bONlQgMDbMH2f+saE0BEsqmbcX UzhWHeueXKiQBQ/bJ3CPLi8Zpgq3KumUBHxrgE1gNdzZgfPazPsXZ0OTP+o7PYei+n/ltI YVdzhRdw5Mta9gKNxa4IzyBFZIhemBA= X-MC-Unique: Y5e6AtpZNKqlvh5d-ZpBiQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Thomas Huth , Juan Quintela , Paolo Bonzini , Peter Xu , Laurent Vivier , Leonardo Bras , Lukas Straub Subject: [PATCH 13/13] migration: Initialize and cleanup decompression in migration.c Date: Mon, 8 May 2023 17:26:57 +0200 Message-Id: <20230508152657.66701-14-quintela@redhat.com> In-Reply-To: <20230508152657.66701-1-quintela@redhat.com> References: <20230508152657.66701-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: 1683559744206100004 Content-Type: text/plain; charset="utf-8" From: Lukas Straub This fixes compress with colo. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 9 +++++++++ migration/ram.c | 5 ----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 232e387109..0ee07802a5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -26,6 +26,7 @@ #include "sysemu/cpu-throttle.h" #include "rdma.h" #include "ram.h" +#include "ram-compress.h" #include "migration/global_state.h" #include "migration/misc.h" #include "migration.h" @@ -228,6 +229,7 @@ void migration_incoming_state_destroy(void) struct MigrationIncomingState *mis =3D migration_incoming_get_current(= ); =20 multifd_load_cleanup(); + compress_threads_load_cleanup(); =20 if (mis->to_src_file) { /* Tell source that we are done */ @@ -500,6 +502,12 @@ process_incoming_migration_co(void *opaque) Error *local_err =3D NULL; =20 assert(mis->from_src_file); + + if (compress_threads_load_setup(mis->from_src_file)) { + error_report("Failed to setup decompress threads"); + goto fail; + } + mis->migration_incoming_co =3D qemu_coroutine_self(); mis->largest_page_size =3D qemu_ram_pagesize_largest(); postcopy_state_set(POSTCOPY_INCOMING_NONE); @@ -565,6 +573,7 @@ fail: qemu_fclose(mis->from_src_file); =20 multifd_load_cleanup(); + compress_threads_load_cleanup(); =20 exit(EXIT_FAILURE); } diff --git a/migration/ram.c b/migration/ram.c index ee4ab31f25..f78e9912cd 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3558,10 +3558,6 @@ void colo_release_ram_cache(void) */ static int ram_load_setup(QEMUFile *f, void *opaque) { - if (compress_threads_load_setup(f)) { - return -1; - } - xbzrle_load_setup(); ramblock_recv_map_init(); =20 @@ -3577,7 +3573,6 @@ static int ram_load_cleanup(void *opaque) } =20 xbzrle_load_cleanup(); - compress_threads_load_cleanup(); =20 RAMBLOCK_FOREACH_NOT_IGNORED(rb) { g_free(rb->receivedmap); --=20 2.40.0