From nobody Wed Nov 27 21:34:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1697722838; cv=none; d=zohomail.com; s=zohoarc; b=XE8f5tB5xOob2HTMq0fDv74XQBy3AvaENqyC+KLtUwjxASreR2kOoicYW455wkXem9g5cv2nZn0wG8sw9thhRsdjlnw93jdRoDP9GwCQiVK3/aZxVhGVfnjToaesNPAPYOHIB7jTFUorGUpzOwJ/8nnjABZfDaBnVHwTyzRW5TE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697722838; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B5WKTLGR0C/mdRljHvjNKTqcCmvmCfBKWla0g4eitfg=; b=Ke5YKrL2VprU8YehKzkZAK9/+RgYoJ6P4drC4ypborqYmzc1f3nd6o4mMUfOVhorCJH1vIWRfLL7Y55xcZ1GB0I1kqiOVUGRQb4VOzl7yNxqImT2KckcHqJY331nBkn3jP/Xx4XgyOEGbFUWxqptaa9740DAREOqST14Etoemes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1697722838628960.4531156498763; Thu, 19 Oct 2023 06:40:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtTF0-0001Cd-Jz; Thu, 19 Oct 2023 09:39:11 -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 1qtNyn-0003BP-2u for qemu-devel@nongnu.org; Thu, 19 Oct 2023 04:02:06 -0400 Received: from mgamail.intel.com ([192.55.52.93]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtNyk-0006MG-OX for qemu-devel@nongnu.org; Thu, 19 Oct 2023 04:02:04 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2023 01:01:59 -0700 Received: from sae-gw02.sh.intel.com (HELO localhost) ([10.239.45.110]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2023 01:01:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697702522; x=1729238522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DROmFsTvSKbYJNdAP2qUwrPECgNR/OTTq/y6dYy22uI=; b=LtdJ7MIAulyyKE5NlsAqtg1EGTyZ42SirzjQdZDlR41AZQ7VAodHCsvR vBfZ8Ht3wYag4MnJi59wilfsiOZf6QYRKwqFfWZHqNqPNRRfVyl2smZI5 fKEeglQ+yI1zjjOJV9balKSpV+R0iISMdiV954m52Z5T/I1q2I/ANiMb0 QCZJPpXwyEvbN1A63UpzncM31o8LdT5WoYGkdCYwyWD9f6QduLv5bmoB+ 3rW0lLadGBClrCy7zuLmx4JrkR6Ca+tlfEkv4+e7maZD+cRqFowX6CjL2 zJssGnrB+rVX7+v6uvlY0ocrtDJHmSIJF63eTGA8C4cFD8G8OaSz59WZs A==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="383418479" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="383418479" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="1004134854" X-IronPort-AV: E=Sophos;i="6.03,236,1694761200"; d="scan'208";a="1004134854" From: Yuan Liu To: quintela@redhat.com, peterx@redhat.com, farosas@suse.de, leobras@redhat.com Cc: qemu-devel@nongnu.org, yuan1.liu@intel.com, nanhai.zou@intel.com Subject: [PATCH 3/5] ram compress: Refactor ram compression functions Date: Thu, 19 Oct 2023 06:12:22 +0800 Message-Id: <20231018221224.599065-4-yuan1.liu@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231018221224.599065-1-yuan1.liu@intel.com> References: <20231018221224.599065-1-yuan1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.55.52.93; envelope-from=yuan1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_06_12=1.543, 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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 19 Oct 2023 09:38:26 -0400 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 @intel.com) X-ZM-MESSAGEID: 1697722839005100009 Content-Type: text/plain; charset="utf-8" Refactor legacy RAM compression functions to support both IAA compression and CPU compression. Signed-off-by: Yuan Liu Reviewed-by: Nanhai Zou --- migration/migration.c | 6 +-- migration/ram-compress.c | 81 ++++++++++++++++++++++++++++++++-------- migration/ram-compress.h | 10 ++--- migration/ram.c | 18 ++++++--- 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 585d3c8f55..08a9c313d0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -237,7 +237,7 @@ void migration_incoming_state_destroy(void) struct MigrationIncomingState *mis =3D migration_incoming_get_current(= ); =20 multifd_load_cleanup(); - compress_threads_load_cleanup(); + ram_compress_load_cleanup(); =20 if (mis->to_src_file) { /* Tell source that we are done */ @@ -524,7 +524,7 @@ process_incoming_migration_co(void *opaque) =20 assert(mis->from_src_file); =20 - if (compress_threads_load_setup(mis->from_src_file)) { + if (ram_compress_load_setup(mis->from_src_file)) { error_report("Failed to setup decompress threads"); goto fail; } @@ -577,7 +577,7 @@ fail: qemu_fclose(mis->from_src_file); =20 multifd_load_cleanup(); - compress_threads_load_cleanup(); + ram_compress_load_cleanup(); =20 exit(EXIT_FAILURE); } diff --git a/migration/ram-compress.c b/migration/ram-compress.c index 06254d8c69..47357352f7 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -105,11 +105,11 @@ static void *do_data_compress(void *opaque) return NULL; } =20 -void compress_threads_save_cleanup(void) +static void compress_threads_save_cleanup(void) { int i, thread_count; =20 - if (!migrate_compress() || !comp_param) { + if (!comp_param) { return; } =20 @@ -144,13 +144,10 @@ void compress_threads_save_cleanup(void) comp_param =3D NULL; } =20 -int compress_threads_save_setup(void) +static int compress_threads_save_setup(void) { int i, thread_count; =20 - 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); @@ -370,6 +367,11 @@ int wait_for_decompress_done(void) return 0; } =20 + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + return 0; + } + thread_count =3D migrate_decompress_threads(); qemu_mutex_lock(&decomp_done_lock); for (idx =3D 0; idx < thread_count; idx++) { @@ -381,13 +383,10 @@ int wait_for_decompress_done(void) return qemu_file_get_error(decomp_file); } =20 -void compress_threads_load_cleanup(void) +static void compress_threads_load_cleanup(void) { int i, thread_count; =20 - if (!migrate_compress()) { - return; - } thread_count =3D migrate_decompress_threads(); for (i =3D 0; i < thread_count; i++) { /* @@ -422,14 +421,10 @@ void compress_threads_load_cleanup(void) decomp_file =3D NULL; } =20 -int compress_threads_load_setup(QEMUFile *f) +static int compress_threads_load_setup(QEMUFile *f) { int i, thread_count; =20 - 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); @@ -457,7 +452,7 @@ exit: return -1; } =20 -void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len) +static void decompress_data_with_multi_threads(QEMUFile *f, void *host, in= t len) { int idx, thread_count; =20 @@ -483,3 +478,57 @@ void decompress_data_with_multi_threads(QEMUFile *f, v= oid *host, int len) } } } + +int ram_compress_save_setup(void) +{ + if (!migrate_compress()) { + return 0; + } + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + return 0; + } + return compress_threads_save_setup(); +} + +void ram_compress_save_cleanup(void) +{ + if (!migrate_compress()) { + return; + } + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + return; + } + compress_threads_save_cleanup(); +} + +void ram_decompress_data(QEMUFile *f, void *host, int len) +{ + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + } + decompress_data_with_multi_threads(f, host, len); +} + +int ram_compress_load_setup(QEMUFile *f) +{ + if (!migrate_compress()) { + return 0; + } + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + } + return compress_threads_load_setup(f); +} + +void ram_compress_load_cleanup(void) +{ + if (!migrate_compress()) { + return; + } + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + } + compress_threads_load_cleanup(); +} diff --git a/migration/ram-compress.h b/migration/ram-compress.h index 6f7fe2f472..382083acf6 100644 --- a/migration/ram-compress.h +++ b/migration/ram-compress.h @@ -55,16 +55,16 @@ struct CompressParam { }; typedef struct CompressParam CompressParam; =20 -void compress_threads_save_cleanup(void); -int compress_threads_save_setup(void); +void ram_compress_save_cleanup(void); +int ram_compress_save_setup(void); =20 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 *))); =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); +void ram_compress_load_cleanup(void); +int ram_compress_load_setup(QEMUFile *f); +void ram_decompress_data(QEMUFile *f, void *host, int len); =20 #endif diff --git a/migration/ram.c b/migration/ram.c index e4bfd39f08..34ee1de332 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1347,6 +1347,10 @@ static void ram_flush_compressed_data(RAMState *rs) if (!save_page_use_compression(rs)) { return; } + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + return; + } =20 flush_compressed_data(send_queued_data); } @@ -2099,6 +2103,10 @@ static bool save_compress_page(RAMState *rs, PageSea= rchStatus *pss, return false; } =20 + if (migrate_compress_with_iaa()) { + /* Implement in next patch */ + return true; + } if (compress_page_with_multi_thread(block, offset, send_queued_data) >= 0) { return true; } @@ -2498,7 +2506,7 @@ static void ram_save_cleanup(void *opaque) } =20 xbzrle_cleanup(); - compress_threads_save_cleanup(); + ram_compress_save_cleanup(); ram_state_cleanup(rsp); g_free(migration_ops); migration_ops =3D NULL; @@ -3023,14 +3031,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque) RAMBlock *block; int ret; =20 - if (compress_threads_save_setup()) { + if (ram_compress_save_setup()) { return -1; } =20 /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) { if (ram_init_all(rsp) !=3D 0) { - compress_threads_save_cleanup(); + ram_compress_save_cleanup(); return -1; } } @@ -3753,7 +3761,7 @@ int ram_load_postcopy(QEMUFile *f, int channel) ret =3D -EINVAL; break; } - decompress_data_with_multi_threads(f, page_buffer, len); + ram_decompress_data(f, page_buffer, len); break; case RAM_SAVE_FLAG_MULTIFD_FLUSH: multifd_recv_sync_main(); @@ -4022,7 +4030,7 @@ static int ram_load_precopy(QEMUFile *f) ret =3D -EINVAL; break; } - decompress_data_with_multi_threads(f, host, len); + ram_decompress_data(f, host, len); break; =20 case RAM_SAVE_FLAG_XBZRLE: --=20 2.39.3