From patchwork Sun Apr 2 17:56:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DF2AC76196 for ; Sun, 2 Apr 2023 17:57:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wF-0006kh-LV; Sun, 02 Apr 2023 13:56: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 1pj1w8-0006jO-J0 for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:20 -0400 Received: from mout.web.de ([217.72.192.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1w2-00040y-OX for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458164; i=lukasstraub2@web.de; bh=ZCK/7ZYmCiEjL9Cwf/dMpYNe7dkpCS2X0vJu+4hpjQU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=UHDAEzl8RmVuCHHcUOQbGQj9RIMWREvH07e5GJg9Qg65T+ljNF2GJ6qH9/u+nUOsi /WB1xPm2SkCEAd37sdZKNX7LdLFX1m9aJrlB2IWDLJmyNG5Mx+EL3IvMTSLs4uESnp dqvqYxMa3pbcq7PohvaABQk5OzcTAGCuAY9pvFDAK9SXlYiKLJdNHw9W06nz0p5gEe eZI/xkMV5yM6A4EXhSgdrY6mmvBdpH2BMujbThaOJYr0YakgsRFK9M1rKQ8wPwY0m6 lFgxqMtPdKRXY1m6sxs9WD3lId4WQXbQ1LuzJt4mZ5fZnOYPJxJQSg/mEy4EILug09 A2xvCzQRbR13w== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M9qhD-1poH7h23PB-005hJe; Sun, 02 Apr 2023 19:56:04 +0200 Date: Sun, 2 Apr 2023 17:56:03 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 01/14] ram.c: Let the compress threads return a CompressResult enum Message-ID: <18ad4a56517e3d63411e7cb8df6b47fe0162c406.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:mfpCIEednmULyaZH8OtD7/hcp09240tYwpdhOEI8oIWbnAVja/L FxQIZdldxdxG8Ewpa+/5awLsTl0tem6QgXSY7nSGqFtYb/3GzyZuIr41xjsTQl8xJVzKl3k RyMBKsqOJ2iGzKiSpjQ86kOyQPdHNaxoeRySujdkhENXUNVm0KS83xoInCqnG2pCZ3X5/EJ uKemm+fIeWDHVzNWRj1zg== UI-OutboundReport: notjunk:1;M01:P0:6xegMPjaibY=;FDKNT39eI3r37TeC5Yhu3R355S7 YHb0alnh3uymM5B235rt/Mu/0Xsl1P4elh1FPrhPHbwPwOF32xDDlDJgH0gxDY0YG4DAxDe3w iYlrmmAHuQ1HEAry6W8VkZ3k9ay617317PVhz5qOJEY633ePnH+WTSmWLX4YVxHio4dUfqdQq D8kZCk0V1egZFhZaim84VnnYItIas//8dclpnPQ+5GazSB93kFnc1FXETPzJEZyf1xsAaeY55 M0Zy/IiPhEW2Qi5aSBbuG0GFcqI7XdKiP4T0zoOkNipKnoDoDFRIROmqgh7OTL89lJYhUXIUJ ZI8HRjTyy8FaU5yteWSY3jOAY1llzd5kGoRvAvjfikQphSaRkyN1C0izxqMi8z2A9SimOdTQS M29g1ltyVCWzNa51fqud/f1sCLRYACZ83dzCzf7rqwRJ3T3kBKy/trRzF7XfuocqdzMluS/zA fj7ipNpKwSycr5oqtolLfaL1EZmsYCPEmdu4spoSM295kAl8jCqS0r3RDG7Yps7GjQdvqpvmP mv2VPaXxEq5/TUvZVJaEM0xnF4jn5EWIJKnAA4K7xhhKrCutryFcu07PdXIuLxOhyXwIzjRvC KH7erqwOUVu/4Z8LmAtK4LyCKj+LTggUz/kPGU7yM+eWHF/WF7/ZikkJANtLcHl8GV1zcutku 5iaIlo656ha9bS8Mk+cNx7l0A8t9tUZMG1d8Nz8Rrk34pdaVRJIfDVIxfU4VhPo4W/NsbZPrm mWV2tkh8DpIJPz7KpLENBqJIyBZnzdNmfSUBE544+s1J/7nt0tEYO2JVtiICX7pBNeODVcO8T sANAe7fnz2fJ2QVkgGEGbLm985Fk1lffhMXN/6ZLjpY/4k83FPxM9eSvmhG3U9KJWSvBgLtrn 6Qa0MiMmYZb6q3J9Ag0RgL3PYuezy9sjslLSFEdSibiVjigXNzULth3D02lvOc+53yjXGE7Tx vsnTjkoX1n4eFu8K4JgHJXW2XBw= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This will be used in the next commits to move save_page_header() out of compress code. Signed-off-by: Lukas Straub --- migration/ram.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 9d1817ab7b..ca561e62bd 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -493,10 +493,17 @@ MigrationOps *migration_ops; CompressionStats compression_counters; +enum CompressResult { + RES_NONE = 0, + RES_ZEROPAGE = 1, + RES_COMPRESS = 2 +}; +typedef enum CompressResult CompressResult; + struct CompressParam { bool done; bool quit; - bool zero_page; + CompressResult result; QEMUFile *file; QemuMutex mutex; QemuCond cond; @@ -538,8 +545,9 @@ static QemuCond decomp_done_cond; static int ram_save_host_page_urgent(PageSearchStatus *pss); -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 offset, + 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) @@ -564,7 +572,7 @@ static void *do_data_compress(void *opaque) CompressParam *param = opaque; RAMBlock *block; ram_addr_t offset; - bool zero_page; + CompressResult result; qemu_mutex_lock(¶m->mutex); while (!param->quit) { @@ -574,12 +582,12 @@ static void *do_data_compress(void *opaque) param->block = NULL; qemu_mutex_unlock(¶m->mutex); - zero_page = do_compress_ram_page(param->file, ¶m->stream, - block, offset, param->originbuf); + result = do_compress_ram_page(param->file, ¶m->stream, + block, offset, param->originbuf); qemu_mutex_lock(&comp_done_lock); param->done = true; - param->zero_page = zero_page; + param->result = result; qemu_cond_signal(&comp_done_cond); qemu_mutex_unlock(&comp_done_lock); @@ -1463,8 +1471,9 @@ static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block, return 1; } -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 offset, + uint8_t *source_buf) { RAMState *rs = ram_state; PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY]; @@ -1472,7 +1481,7 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, int ret; if (save_zero_page_to_file(pss, f, block, offset)) { - return true; + return RES_ZEROPAGE; } save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); @@ -1487,8 +1496,9 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *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; } static void @@ -1496,7 +1506,7 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit) { ram_transferred_add(bytes_xmit); - if (param->zero_page) { + if (param->result == RES_ZEROPAGE) { stat64_add(&ram_atomic_counters.duplicate, 1); return; } From patchwork Sun Apr 2 17:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A59BC7619A for ; Sun, 2 Apr 2023 17:56:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wJ-0006l0-Pd; Sun, 02 Apr 2023 13:56: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 1pj1w8-0006jP-JT for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:20 -0400 Received: from mout.web.de ([217.72.192.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1w4-00041X-Kh for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458168; i=lukasstraub2@web.de; bh=SghmMtF+k67qN3g6avmGYkcYWDV7UwGxn9JjAkaB19Q=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=I/qF6dw+//FyS/W4DnLtCUua3KYzzQHheTMq7uul+rD5Y4KfchNf4PeyBxr28V9GS WzOiLEAE83x0rh6qtts08RKszh9tKL/P+oS7ZE7KeymM91FuwbyQ1YWe5ie2mht5i2 Hv/zX73Vod+Xxn7fNz4w1ElaxJh+IiBPZr88pJbVgypcsQCJtgSKT3JEr4Q7DOt8ih uhSTF1wRSyu36yC7n8yWL8lsymywHgRNNFBub4kuavDahgWAYwNuFbWxtHLfXMLnFg VWZKwr7zmc2V42L4nIZk8mHDI/WrLPMWfNv1YBDQpUH6Dd0z3bzh9qpTy9NoTqmgfD p3n3DQO1B5Kww== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MPrPV-1q5FmN2Ifj-00MoWy; Sun, 02 Apr 2023 19:56:08 +0200 Date: Sun, 2 Apr 2023 17:56:07 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 02/14] ram.c: Dont change param->block in the compress thread Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:GZSaNbf0FvnGQL74srCUl7otgBc1ZtCfWT2x5ZaHx6aP45xQh/S MW9p18/ZDQq2PqoScqW2lYMk0h0sauHiIoIXWJUe+QhnenzGQNeUunWTGpbPvrbzM1DicS4 p5eKfg4DeH2+HxaQPDuDEIb+E54S3T+MslNgCjMgu1CLXg0Jlm8Ddvmh0NxqpyAHTL95gdO 9TY7qJ3GY35733v/ucL8Q== UI-OutboundReport: notjunk:1;M01:P0:KGX0jphtKmY=;A4NhxOeqBuOKfqKXHueMJ8KD2v2 67maMttj1hu8yLtQhRoDisXmn3CLXJtvlvSQlUdLshbSLC+Sb1XGnI+d2iIlYsTnXMPx7LJuF qBuDDb13ZZff/tLNIYuKj83M9n7NTpendsM6HisKdaShM5LbEsOf+OlSOSPpm88nZWjUeF2fy YgYG6t/TiDvPqzZW8ljh3mpRla8HQ+uw0NoKCEXDdHm22GWbCx2ykL+/6kjwuqZgMq0kNOwbP s3DiE3mVbBsNlcMqK6ay2aTbRoZnqUgOrnxGwzcG14TCw1EtYzhUyBofEi4IkZGNaIc0n5Tdf +YopDOLaLGyi6qqcZAyqKfM70+PJGbRHOODHENbWPj0wgTasMkxcoVQGNYhklm8GfnWDg18f7 a+UFAjlWnQyCSsDvnhHEF5BsX+hccjed7diPYNNjLkWqXw/UfvckeW6Yj8GDDJIs1NlMVbeWx l2b+q/7pZm/u3OxDD+wonxAJRoixbSK3hXczynqmu/7exPvoqc6RUUSRCn7LbbzvTlHb4nGi7 ++zztpkFOLyS7+7ooop8Tl8NJO6ncYwIHtqRdQGHLav4sFnUa9ujSNN3wQPS8rhl1TdIWCugb N3ThifCh8rRRlPKYhPMuMW+0Qxr8W+zyH3dSS2JIhhmZ4zOtAr+YJqtIUzrs7kKuQ3f4uo/D7 k3srvEGEN1+2NsxAZc+EsZCGedm+fgkEaWc2YcAMmoV0n8g/PhU7DepUVgJcvtJlvdcc1sk5K IklYw3OSThOD+QiHZWu+cfLvWKlvqHB3HUQ76xU3mINy4NI1MyTLfgkYDIJnOzfV+gGvlZxow rUqPY5ZrxriGCXg8Wacvey1qt7tpsnJRWK8vNBq8RYhrBv5FOffBfZUEwsledhs9B0dqnT/60 6PMiciLRFCGt+w7csdyA5kQPCHIgE+U3gSgwMXQt/IFAFwmnHvcIAjKOHeoRoDrXzWg3ftRcD b4rnLOFB+oB09PuwoC+o/FwGUus= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- migration/ram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index ca561e62bd..3c9fac086d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -503,6 +503,7 @@ typedef enum CompressResult CompressResult; struct CompressParam { bool done; bool quit; + bool trigger; CompressResult result; QEMUFile *file; QemuMutex mutex; @@ -576,10 +577,10 @@ static void *do_data_compress(void *opaque) qemu_mutex_lock(¶m->mutex); while (!param->quit) { - if (param->block) { + if (param->trigger) { block = param->block; offset = param->offset; - param->block = NULL; + param->trigger = false; qemu_mutex_unlock(¶m->mutex); result = do_compress_ram_page(param->file, ¶m->stream, @@ -1556,6 +1557,7 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block, { param->block = block; param->offset = offset; + param->trigger = true; } static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) From patchwork Sun Apr 2 17:56:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9086DC7619A for ; Sun, 2 Apr 2023 17:57:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wN-0006le-Jt; Sun, 02 Apr 2023 13:56: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 1pj1wC-0006ja-Al for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:20 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1w8-00041x-JG for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458172; i=lukasstraub2@web.de; bh=Zl43xFvhmrHL02KVD0T64DTHYdt1e2LpEi37q1WQFJE=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=HqUjGos8bNIatz1hZR0vYld93WB7QmlZAHHGhia+6csJt5yDuF2PLhE9Ay+D+9Olc ZFvexuKogXbSiM0hKZXmUUlE9plWieeGegM+3f5SoOUssDyukgeXQUMJvb9DEwf0DQ mK6w9m+QAhBK1kHdC58x+5O9IeP9bgVyl9PGLP06HD8W7ZxVUaV4xKajLqCxTGUCEY WX2Zufy9G7ljmXyB3gTWZSutDBSUW/KiAOj3jvfS8kOzfn4ZZ6N5d+/5fRQ/Fr2xan +iLMSvp75EjKY1o8uZjQ+fXQvMVbtedCYkkoxtkrzkUfBdn8S3V/RPUeQv/BmMVs0m AHQnMuC/0O+Ww== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MlLE7-1q7xgH0EEH-00lIiG; Sun, 02 Apr 2023 19:56:12 +0200 Date: Sun, 2 Apr 2023 17:56:10 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 03/14] ram.c: Reset result after sending queued data Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:auJw3zuiq/zuUpAOTlg6tp3Jm04DEHGN7dGXULIYk1PkFl3rVKv o0LR5xo+ex3QGWVCOpasGyCAEd61q+3/8jMz8Hjx2v/xJOiTJb13odiAjLjuoE/rUBReoo6 0zXoK846dh9DAxjlFs+xBoGopg/yvdwp9tG6mcfTOBEJzeaFagITD0VZ9HKldzjj7HLwoIW 7lyjVM6gpYaKhKNvMEuIw== UI-OutboundReport: notjunk:1;M01:P0:ds5IlzkpFRU=;OBTzctP5QEZspK8e2+PRMiH2Sc3 0ZspVyeafGwNVSIzBPr6Qe4udSNto9TpUkYoMaatR6Ig5RoJr/lZvkxIIWeDLSLx6Ohq/0moC cbliX951mx+AcTahJFxOOH6pVhemTciDp49HYRB5DPnliib1SzqCTXAagzkCgCUJckQTBKCP/ nl3YiIPjl9W9fOLSLKIots3fb87EnKOQH8PX7EvgfuiIURw/S24ja95iKV38veEl500IOs+/4 h878MjVaT1qoRgJ2LLFQrqjSTznDWrcyMZIP9EShyhW0LpQXJFU0unD4PbetI+7B7h1+CZNNW Vg8GVJYTgYlgulxnh141/V8RUaIojVs9LZLB4I8n4nI+ICxK4qbL0kiZ6Br5wIniHnk7n9I9Q /N0RiJAMxb4RZhfNCj5AEhaiqpLVgbS2rjCwMJhcCfLQaCoKQMlk3uIVVHkVziFEk8TwhPM+/ W/VcBmJj272uC8DguJzl7ThZqMshjSv1CVD22BGBq1yBus+d692d1I7zO9eQBodIuxUZUrHBk S9S4N0hCFypijrj0RlSzdkPNxDfDkP+IfrHvTVld1st1FsR7HX/1OhTTJREVm2kvKhZEfCLHA 4zKbr0I5aLRwLsFJmww5+774+lOARMNYPcQwHuthqB7dKAPZEoLnU9DirwDmR6mbVmG/GjN85 ijKle7Qj0JQ9loHUgktmXkgLLU03lcKs/von3FIxCcwiPcSTnGUV9D3r6GCXGYljnGBtbLQbs dRgGGPHOFdOvx6TUksjGDR5sG5U6m+yNZAsWetp9L0x9NIiaYBOvvYQAHXukEWC9ntTandsPU pmIotvreCDsUXrLUhWvU12xTT0XxhWEdQYExj6/f3yySOO4+Egb947xY31tUWz9lVDZXJQImx nKkoIm88R8uJ8MS6SrXtCn4b3zK31Rd4U3WkbjIAEIksVl1l8VFfTb16zo13F4ZnrK1oA1dd1 5vjRGkHHELNqnMYOU8W3b5Ajaz8= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- migration/ram.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 3c9fac086d..bef6292ef7 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1519,6 +1519,13 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit) static bool save_page_use_compression(RAMState *rs); +static inline void compress_reset_result(CompressParam *param) +{ + param->result = RES_NONE; + param->block = NULL; + param->offset = 0; +} + static void flush_compressed_data(RAMState *rs) { MigrationState *ms = migrate_get_current(); @@ -1540,13 +1547,16 @@ static void flush_compressed_data(RAMState *rs) for (idx = 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len = qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].file); + CompressParam *param = &comp_param[idx]; + len = 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 point. */ - update_compress_thread_counts(&comp_param[idx], len); + update_compress_thread_counts(param, len); } qemu_mutex_unlock(&comp_param[idx].mutex); } @@ -1571,15 +1581,17 @@ static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) retry: for (idx = 0; idx < thread_count; idx++) { if (comp_param[idx].done) { - comp_param[idx].done = false; - bytes_xmit = 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 = &comp_param[idx]; + qemu_mutex_lock(¶m->mutex); + param->done = false; + bytes_xmit = 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 = 1; - update_compress_thread_counts(&comp_param[idx], bytes_xmit); break; } } From patchwork Sun Apr 2 17:56:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7538BC7619A for ; Sun, 2 Apr 2023 17:57:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wQ-0006mI-VP; Sun, 02 Apr 2023 13:56:35 -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 1pj1wD-0006kE-RW for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:21 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wC-00042H-6C for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458175; i=lukasstraub2@web.de; bh=slryEM/KfdNssQs2kFX/9l5ju/cyu0e1bXrkTCTexkA=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=m3DgZ+zCjg007FFQxWtlhh1FAx0QLF+6WoSmpq1jFvVrENQAbdT8haF8yu5a0lgDN T8eNC+W/452pLAdGG/b6KsfGpLexgTsfsYpu2cqElq90wuuISctd1CO66iU34FXPOp s2C9yHL/x0d3PPiUbSl6rjgupIOxvo5Cue9XIOHT0Tk+Bv6Doy4IF51HgGYYJVJm3B JkOHTychZMaDjKqa/4xNmRIWVAPP8jDJjToB9YQh26O84D3ywfU46Sk733hUmlUBb7 Z53zc9GM1oqWzGwyfO15+2TguAMMLveWTwUJ15NgUDtqSZZd1RFsRHdcDwx6najBOy EgmR8VymzQM3g== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MjgX3-1q7PS01SPr-00kkMJ; Sun, 02 Apr 2023 19:56:15 +0200 Date: Sun, 2 Apr 2023 17:56:14 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 04/14] ram.c: Do not call save_page_header() from compress threads Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:68JzcP+JH1RVqCHvoPAnTMK0tLao+wxzIAFdoQ9Jm2G8a0iC0ua t27gszZbu8+rVnykrb9QvNnOg5QSA7bAPQmxtik/ZVwSgCVRLHYswzWzOTR1SGbc+ZNrMZw 0cwB1idB69nanS5vurggGEGo7A33GaMbNEDDnE/rV8JmNKghiPto1Ovw/N7kpb4obe1coM9 7agmYCgpOKmTa9j15a9CA== UI-OutboundReport: notjunk:1;M01:P0:a/RB3+C6GZI=;KHom+0Yf6AjCu+9jSCnR8QxJlNp r8j6Piy7Ro4gtlQXX2kw+t3QBArRc9WWeK89oMokayeWz0bYW9TjFo50bR6BS+MvET2B06oM5 zO2LP4Ue9pZSlF0LVb+G7siW3ivb8IFSOP7meTDjC/VjiqD/jEKvXnOg84fmDyFcBNnJyrLNG voq4u/am+psvdFLYwPXmlkPWb+1556ytatGI0/p52pFWKse8rdkQq+Z2+I8+MliuBf3Spt9T6 LQSkmcGoK5CQUk+prhE5P6QBmkPFKnERqQmc98rsHHssM1QaP0Pu6mfGO4YXywsH8EUlZoHNB ydAZpOYXg/ct5sIOf7yZrPxfAIr+NU9x68dlLmz+5MP+cBbb13kqjXzrrtZCNfsC2oYeed3qJ nXCWTCjwu7zvya8rUA4OHuO6x0hMql50ToO0gRFNIOvDIvZmFHg3apAWjjR2ZjjvTpDA98FcJ ryiNSN7/rAC3Sp4RBJzJzRRNg5FFI7KToeyhlT4f1q7bEzDK6ZvQrGff4yvGICETEYg0uCnUY qWJrSg4H9OP2XDspw1+27tsvaE7Oosnx9xpKepAgzi6YRzdwd1vtz80IPOh8DTJPz+oET3l49 KsTyAErA/S0YABCSD/bdpkASy1OPWxl5B1tgNMkJzTJ3N/z2dwWW+pOmm4Y4GJS7b53WqT01B 7i4wahs3M+MqOwdlemkjzB9lZpDo5HCwk92NdPHuDWjNNLhuviYKic99QT24YIZQokq6ZkGBy gnviu1Ct95v607K8ZFSPhMhQnTYcQl0nG+8sy4ak09r0ckElPxYYZOvuEd9XgJmeo0PhHsesc XlGjzStFUTryXZEOnRxVUv33bAJ10Q2ii56wXuuRTGVIFxRxYmof5HUEni8gjMx/OxRHygMVv lBkd+2V6shF6cWgzZFuBJvwANFwIioR9ESjSUrlj3BJlcI6K9azwxGnRWSk/LPH2b/4u4W8Q+ aHSYMWJUUUYQ2Lv14Q96dg57igI= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- migration/ram.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index bef6292ef7..7ab008145b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1476,17 +1476,13 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, ram_addr_t offset, uint8_t *source_buf) { - RAMState *rs = ram_state; - PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY]; uint8_t *p = block->host + offset; int ret; - if (save_zero_page_to_file(pss, f, block, offset)) { + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { return RES_ZEROPAGE; } - 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 @@ -1526,9 +1522,40 @@ static inline void compress_reset_result(CompressParam *param) param->offset = 0; } -static void flush_compressed_data(RAMState *rs) +static int send_queued_data(CompressParam *param) { + PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_PRECOPY]; MigrationState *ms = migrate_get_current(); + QEMUFile *file = ms->to_dst_file; + int len = 0; + + RAMBlock *block = param->block; + ram_addr_t offset = param->offset; + + if (param->result == RES_NONE) { + return 0; + } + + assert(block == pss->last_sent_block); + + if (param->result == RES_ZEROPAGE) { + len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO); + qemu_put_byte(file, 0); + len += 1; + ram_release_page(block->idstr, offset); + } else if (param->result == RES_COMPRESS) { + len += save_page_header(pss, file, block, + offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + len += qemu_put_qemu_file(file, param->file); + } else { + abort(); + } + + return len; +} + +static void flush_compressed_data(RAMState *rs) +{ int idx, len, thread_count; if (!save_page_use_compression(rs)) { @@ -1548,7 +1575,7 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { CompressParam *param = &comp_param[idx]; - len = qemu_put_qemu_file(ms->to_dst_file, param->file); + len = send_queued_data(param); compress_reset_result(param); /* @@ -1574,7 +1601,6 @@ static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) { int idx, thread_count, bytes_xmit = -1, pages = -1; bool wait = migrate_compress_wait_thread(); - MigrationState *ms = migrate_get_current(); thread_count = migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1584,7 +1610,7 @@ retry: CompressParam *param = &comp_param[idx]; qemu_mutex_lock(¶m->mutex); param->done = false; - bytes_xmit = qemu_put_qemu_file(ms->to_dst_file, param->file); + bytes_xmit = send_queued_data(param); compress_reset_result(param); set_compress_params(param, block, offset); From patchwork Sun Apr 2 17:56:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F44FC77B6E for ; Sun, 2 Apr 2023 17:58:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wR-0006mN-DR; Sun, 02 Apr 2023 13:56:37 -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 1pj1wG-0006l2-Lc for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:26 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wF-00042m-0s for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458179; i=lukasstraub2@web.de; bh=E/gR4Jf5Nf3Qa1UNaMPS2dXFHp11a7smLFb8Et5TmiU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=uqvEMOj+HZ9k/Zc08yxrqXqX41w92j1epAKIqU/LXKR8jegdc92aPt+S6eu6Z7iqw nVitkb5N/rbaoedXaZTIfxHf5Pn9WIPEv5RLJVmVSAVexhJw5YSvgjOT8s4rAtXF7+ tPKDni3ePtDxbKayC4aV4PEu9NLftsSYTfTOt0qSr1UMR1T5SP3rpuiQ+OmK7A+iGK g2z90p2UKBi5O7oD+Youfr6fO/su86lCllFmYeS273micFReE0uGpI0+nZEVSc+EGE 7V+pmbu50ikNMYyChlJ5/mJ8h4zaOaats4Mna54ADuwsXe3X+l4SZbLLJJ7B+KpE8B rRgctce9+0ciQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mw9xG-1qaixD0DVE-00sHy5; Sun, 02 Apr 2023 19:56:19 +0200 Date: Sun, 2 Apr 2023 17:56:17 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 05/14] ram.c: Call update_compress_thread_counts from compress_send_queued_data Message-ID: <3b5bd7f0d654e6409dfbc993d323292a845ff811.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:EbPxqyUDacwnk2hQi58XP7lJUg0rouj4hcvES+yX0OofNJNiLrZ um1BDvY9plai14YDz5k4YMOeVAjiEjw3uEuDOgKyBoe6X2qnzxarEFGrAa/aEWm6r4inrzs JrXvNXr3+LsW0FKAC4DI00QAlfTzwf9e+NohhGZefHqTacwps8bX1QlOIZ5nPpx0hL1iwyr 2OYm2T7NgnOm2F7EkCLvA== UI-OutboundReport: notjunk:1;M01:P0:xgqyU1G0AVI=;5H3fSMP4bAJ7XYZKmDJBCsxz0fA RlAo7s77bRg3Mwj0B7+6verq26jXZ96kcnBO+7IEyZTNtw3QtR5xzsaH5CfdvNiKkKChyQxsr b2ezFRm+rEVx7mmqYWDHwIsWEiF2/kK46dpK/wGlcuKzfU6aZfcepD+6YsSMSOZZ42Q0EOs6A qxzgelPBYDOrrquC5NEhGtcy/nGR1xunZJ0I5acxQAEjlZOcoRrMMOTUCEf3zlYBaCPYEvohN TF8XMGGYfxztscuCrMBHw5bFnvbXVs/xSszk1J6NOr2MrqOvHmyDQYaFH0I0AnTDwJbmUOLJq cQ6JXI3Hz5YL4GWJGFmqaIfB4xQyZBT33vv7mS8O4joy4o65OUrMGIV//IpFmCSE6pSy4ygly jH0HG9VkC6n83trSUaoLU+HjAX9hws2P7IQhrkUhQyQTifWj5ccVOJ12d+HGfL4FcnZoqp/ho 0DkdddIp5Cbc/vyOnEIBx5AjOvVtVc9+tFXHV2wKOTD6y8iyne/GOaMAfMiK2VvD3ZaJtyS2T w1uErO101rq6fZfTJ3MvsP5Xk21GGjAv4ZNZ/nmbNgvv76umFMTPltQu+hEghvzao6nUUlUFt oXI3/c/czWYGT2GmEvyLEUHM/eYy1Kr9eY6OXSNcLyuDU+QxFHCTqV5uPO9bHALVh7VwMkaqc gA6RGC5qPHv29ODRjqC7zS5qdPi7dxtk3dqfrSZTYu8ml7/FRSug47K2bMuFRw7XSHTHwSVLW iher9dHlDWD18u88cDIAVS8OrfFs7EX4FZ/xNiO1OumZ6o16loPYtd9ZVkVNTNwBGNUMxHydv s17tfqqN3BPxevB9TMIaOTbCGF4Bf3pNH/kF9Bes+xxF52uf3Ktcn69n5ihLxsKQZ5hgGEtdc XbbkzoKL7xUhkP60Bn74mbNcPARJCgC+zTjDWEPKGY1nX5exxv5BE6XApwE625NVgu24abx4R VkDZgV8EkHJK1aNFU3CGYBTOMfA= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This makes the core compress code more independend from ram.c. Signed-off-by: Lukas Straub --- migration/ram.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 7ab008145b..f55eb0e587 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1551,12 +1551,14 @@ static int send_queued_data(CompressParam *param) abort(); } + update_compress_thread_counts(param, len); + return len; } static void flush_compressed_data(RAMState *rs) { - int idx, len, thread_count; + int idx, thread_count; if (!save_page_use_compression(rs)) { return; @@ -1575,15 +1577,8 @@ static void flush_compressed_data(RAMState *rs) qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { CompressParam *param = &comp_param[idx]; - len = 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 point. - */ - update_compress_thread_counts(param, len); } qemu_mutex_unlock(&comp_param[idx].mutex); } @@ -1599,7 +1594,7 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block, static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) { - int idx, thread_count, bytes_xmit = -1, pages = -1; + int idx, thread_count, pages = -1; bool wait = migrate_compress_wait_thread(); thread_count = migrate_compress_threads(); @@ -1610,11 +1605,10 @@ retry: CompressParam *param = &comp_param[idx]; qemu_mutex_lock(¶m->mutex); param->done = false; - bytes_xmit = send_queued_data(param); + send_queued_data(param); 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 = 1; From patchwork Sun Apr 2 17:56:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CA7BC77B70 for ; Sun, 2 Apr 2023 17:58:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wQ-0006mG-VN; Sun, 02 Apr 2023 13:56:35 -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 1pj1wL-0006lX-EP for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:29 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wJ-00043A-Ny for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458183; i=lukasstraub2@web.de; bh=e2XBwHQYkP9RiP5KdODNOl+mStbytDh0Oe+Nqmiewxo=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=iIILrW2WagbhdkMSIEZ+NTokQWt4Lw6G28tO+arX/BSzro27mgUidJGXjXK70KZot vr4C7DuEZHVmWT81b1/4Dg6gXcHpNy0mQ3jiFdN2Ylhwg1jN9R28maG1fbVgy4Xpza d7R69P6iwzd3nYi7/1CjABRnTbmRZihFMJZDak7J/9iLVNcf39n+w2rF1d0tb+9Wj/ 1855x2I7bex9JhwMDk4FkfZ/tpoGnMNc2f7RnPqaFUvwnTW0ReWNrP8O6hdcCt+uip NCZbHG5puPhm1FHy/48fNIEsf60fQoAHvixyA8ZJ6BNBDzWVmwkcEbogbkyS+yUVQG NJr/5KBBas5ww== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MpCqb-1qCvmr3E6h-00qGn8; Sun, 02 Apr 2023 19:56:22 +0200 Date: Sun, 2 Apr 2023 17:56:21 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 06/14] ram.c: Remove last ram.c dependency from the core compress code Message-ID: <736329ce81b99e0e1cb6aa9683dbae0d39a235bf.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:9vsTi2epGLxGxhj8b6v6ue58lBkyQYqy9XADsrGjH8hIOA4DfAP XJQ7IgnRSzuqVPlnXAcR2JnmHrAoJtJmwXsRAbUfVTbc4gdFMnZEvp0KuAoCmiIf0pJMIAP q8ed/7d7QVKyxv8nNIfTUKSaPRGRlRe0UczgexaSdMtBKZDdPvpXKX96tmwf/19oxsPZxY+ nfO4OplwNMUolrxwIZvqw== UI-OutboundReport: notjunk:1;M01:P0:K4Ae7fw1IcQ=;y0AHcwI0z6P0ILtiL9+KNqNY/1f aVPBO4AxeVYAG1o3iODfb1GiZtSSzu9qsf3tmnIOu4YgCFCuOY6PCAwxd0uxBcMLi71W6gEKG G7Il+m3KCIscduH0knoaRUtYjru2hXc7g+vD1GBVbqAlJ3ZbkIvSzN3RG/MKNhdJ7aqk8zXTZ Zp41kmgPhS+dT5qL6HvPSXeSLZ/q2iwngLpd/nb3asQVSB7JePcPZ57+ONomoiuvDflc92uUL huLm58lTCTytSU/JKMNrIG9bS7E/43mxui3yiIDTN3LT/s0u38DS033ACWjJQzgW297AO6iH1 HjyapEAEPCHFdh19b1iQtinGM/HInyillAHlwBJoq7uA8kyfcEX+QNFTJqVVQmds6bYe9ZONq 5l8VcwaeISVkpmnJTJwyJ1gI/f9iSIt/hNgt2xyrJ6+YEd508avrHUF/DHscHBr8iKtUKUYLe M0WCUK69gCus7pG0N1O58mg/oYT+tGpxDM8BqtvOfYL51XxhQlpYkU51KxmEJvQAw4lXrbJxs gaJ10kyk1nwQ+TlhnmTTZ2U2B4wcOkIvK7fWyx2ipDulaWFVbpgehuegjWEc50xUpj+3qI6kz EvTr95sl7+lVWqB+4pv62ng4xGBCAHZvEURg4vCui2QoHorefC/BbrWT1vPw/qVXrVW1mR62d jA6hFmVcFCF65+N9p08AXM8usArQt6EBbydB01ogwWpQmA26S8k5wmQwSGG2//fDRwEOJOKDI mqXjqrbDPkedkbbSVfTC/WsvOkm+I/jSv9HZQjYYjE6B1Mi+SJNgarWkbsbhE3cyEJp5nS/zM JcLp8WOtfwtRGu1wqPMp2NLfePIpCGq8NCD3o78XVwv/ULChGRGSWkm23TjB/+V6hp3oHL3Vr 8peqj+zFYHbYS8ZQR1Lb17wutfscI7cg03jOr2M3zDOn5ly4FO5OlF/YENkCG3n11wDNkc03W 1Es7sqTEY7v8INHj/NdljvLxP6Y= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- migration/ram.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index f55eb0e587..20428ccf42 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1556,13 +1556,10 @@ static int send_queued_data(CompressParam *param) return len; } -static void flush_compressed_data(RAMState *rs) +static void flush_compressed_data(int (send_queued_data(CompressParam *))) { int idx, thread_count; - if (!save_page_use_compression(rs)) { - return; - } thread_count = migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1584,6 +1581,15 @@ static void flush_compressed_data(RAMState *rs) } } +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 *block, ram_addr_t offset) { @@ -1592,7 +1598,8 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block, param->trigger = true; } -static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) +static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, + int (send_queued_data(CompressParam *))) { int idx, thread_count, pages = -1; bool wait = migrate_compress_wait_thread(); @@ -1673,7 +1680,7 @@ static int find_dirty_block(RAMState *rs, PageSearchStatus *pss) * Also If xbzrle is on, stop using the data compression at this * point. In theory, xbzrle can do better than compression. */ - flush_compressed_data(rs); + ram_flush_compressed_data(rs); /* Hit the end of the list */ pss->block = QLIST_FIRST_RCU(&ram_list.blocks); @@ -2363,11 +2370,11 @@ static bool save_compress_page(RAMState *rs, PageSearchStatus *pss, * much CPU resource. */ if (block != pss->last_sent_block) { - flush_compressed_data(rs); + ram_flush_compressed_data(rs); return false; } - if (compress_page_with_multi_thread(block, offset) > 0) { + if (compress_page_with_multi_thread(block, offset, send_queued_data) > 0) { return true; } @@ -3419,7 +3426,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); } /* @@ -3512,7 +3519,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) } qemu_mutex_unlock(&rs->bitmap_mutex); - flush_compressed_data(rs); + ram_flush_compressed_data(rs); ram_control_after_iterate(f, RAM_CONTROL_FINISH); } From patchwork Sun Apr 2 17:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A2ACC7619A for ; Sun, 2 Apr 2023 17:58:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wX-0006ne-2Y; Sun, 02 Apr 2023 13:56:41 -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 1pj1wO-0006ly-88 for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:33 -0400 Received: from mout.web.de ([217.72.192.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wM-00043Q-NH for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458186; i=lukasstraub2@web.de; bh=IAGnIZLHOuSuLfG9XAUm8ETSUqR6wgi7NR8ianLxB3E=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=sFCgUJUD6A2p9anqdX0kj3wT583jXfvg7oHJ3PZjdO3OfJwy7FVN6Cbyntz2NFtkA E6mQ5Q9vD+w69T8GwHTTUwqUV3o1wypacid/6mHsuCKUlm/l01XUpyCSLvmetpnSxt tQv3jqEu0uWgMsRsYWXpeRAt09PPnocOMr3XIrbuw5xhG8FLIbNfgip0+sI/IdV6/P VVWf2W+0eZ1VLfHE0oCu8MQObcxzq/MbvL8o8b7RQ8v+uY6TVkJRlmnADHLioAxBZF LTw7PTlRR6NkAB6LTrY+fbppCzAeFz1k1Z0M5NG3wtolb1cgSLXU7xHWb4/dDy0BiY 7rc1hc1XjE/NA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MWi5i-1pu1MA1kW8-00XV2w; Sun, 02 Apr 2023 19:56:26 +0200 Date: Sun, 2 Apr 2023 17:56:25 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 07/14] ram.c: Introduce whitespace (squash with next patch) Message-ID: <1a748d9034abc42ce5fbb501e7317fa55da36744.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:m6qFgWIXVpx/1o10in5lom77EJhSn8w3WYCQ+eod545xJx5r+9H O9oCjZvA4B6A9lVVBo8wy6AW55OTnWfaf868fXbdxiL8QJ6G0JzINgYh0FzwZbZeG+NVe3t e4r8O0fGJGwlzdfIFRIKePUp0ECWUNR7wF6SOIT77PIjDRmLBjwKZbehdmSdV8HShuHHbEz yaZ9ZtENFMwTnpgUjXI4Q== UI-OutboundReport: notjunk:1;M01:P0:zxyCdYtlu9g=;XGKuNIgsU9KgTs1dVR45fN+C9Ap qBpf0tZQ7RgObBkSwjueiXMyP0HpF8jF6Y25q+euoUSuniqqbskSUGyW2hChFpQvBMw6iOLkn C8ccClcR6fC/bK6w2X9PGhPwA1Htux6OU5HFpcuQ4PBNfNa2MZ60et/GrRd3Klsapi+TSV/NR 6yvmfvpV8j6y8h4BeOnSs6ycIP0ek8nqoIVpaFhJ8s8pMmMl6XTjkM4IKIEYR95adLaIbPw8y ozxpOgAv4dlp1P9g3rZ2I8fJCX1gcfbAnhNIwqP+dUpF0RoirPJuX+ZwGWjefesfEIphBrVvo TAkDmjm8XDBoSBUPNVlDF7iLELzvBRB4Cbh8dag37gFKOANUwucVRdaVBqvpd4GMBz/nS5JWi ZMTlvqH/ABzNflW3OGMRJizfnlMTjrT3xIYzEc1mPhwogCOJmW5gvw8CsO5uTY5aI04tXC0BS DV4mj2VqFdOyw7pKivkHVXqah9T8G8OSS67zEVtidxmqvjKIn0tXXpztBHk2I1056tRGpa06e tqxGob9P07NIm87LhJsWmlbnNFFIMUqs3CLVkSY3RWkItyeNdC4a2xHh94W94P3a7WEk5Hnlk U+qzUmXU7+sDyD5ogysMQm3VDK8pmTz7Obneo+queMuzlMpyz4SBfX9GEr735PxVY/Bswnx1R xvcoYMWXSf3bBk/WMaEHRiZuCyNRwziqdeT3N6CGjpmAdZ2WPHjcMb5/lXutasdlIjiIdZVbX N1KGYjuB064tMk3C/42VBOfV8m0m261LAqubLr/woP2V2DEaRMFAnvXQCyWWXVOiy/wie5igt TWA+2DWBKjp7yjXI870/AuMKcI0AGWPId9u8oxN8KNyydUlrNQbsTeqEWy/cUvx6OeTl3DIUI pmVJmGb8ITeIMHCKbgm/6S5QCQ2h8n5VEr6Etsqomb2t1Gg6V+ZmoNN+NGUwtQLOAJyb3cuba UTkgDGsnqHh5Wo7tAxzdBBa/p5s= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce whitespace to make it easier to reroll the series. Signed-off-by: Lukas Straub --- migration/ram.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 20428ccf42..475c04a18b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -602,6 +602,12 @@ static void *do_data_compress(void *opaque) return NULL; } + + +/* split */ + + + static void compress_threads_save_cleanup(void) { int i, thread_count; @@ -641,6 +647,12 @@ static void compress_threads_save_cleanup(void) comp_param = NULL; } + + +/* split */ + + + static int compress_threads_save_setup(void) { int i, thread_count; From patchwork Sun Apr 2 17:56:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BFDAC7619A for ; Sun, 2 Apr 2023 17:57:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wW-0006nS-Cu; Sun, 02 Apr 2023 13:56:40 -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 1pj1wS-0006mh-ML for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:37 -0400 Received: from mout.web.de ([212.227.17.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wQ-00043o-0W for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458190; i=lukasstraub2@web.de; bh=XKpglTA6owmd537ugJcEj92M/s2rh7Eom5QGAWKbQ6o=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=Ktt7/GDehJXbd9v08QBdxo5546p0QqDcQuvFyB7O8OTHUH5UdoizQ0rGaM61RoMei VFvRSVA2d7VtK7Qw5Ls/s/MOGRPB5xmF8/OXwikxympYcr72l23ccFBS+SrJFltkJn y9KA/+6V9Ea8W663QP/hRgV0LnAMxYK7V599bPRnayicbbUba6lGKKqCtZa+CEUv1o WCUQH12wwurQ4/fg7G9UkK9o7rw1wdmzAucCkbVU4hrhUWUy9UPpm00BHNBFlQQVpg RpE4JRQT8EwkWAQthx/pazyADsjliP1OdUpEOyqxWNKhe9vr6uE3nD65fjTXIGHSTv F7ZLulQfB37oA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MKuKF-1pzCHA3u6H-00KueF; Sun, 02 Apr 2023 19:56:30 +0200 Date: Sun, 2 Apr 2023 17:56:28 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 08/14] ram.c: Move core compression code into its own file Message-ID: <15e26fb46da7826061fd47b0d58943f3279c149b.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:NSFHLn3l3BwlqSvzuU5igoVunj6T+a9dA9+bD5f0Q6kyTHQjybJ V1FuWM1KEMikFjLRZ7nPQkmldTIZxGnQJ3SWOpRFwv6kCvJBlI5Z3o4zVPZWKyPShAMnTK9 h5RPPdRK6St9KRB+HbgWX87s20w38DZPMUvy86ZQZ7PF9iYOvqapkXxj7CU33gmiCC092QK LvXe8rnLNH60Be3+ideTg== UI-OutboundReport: notjunk:1;M01:P0:V4lC6v6sKMM=;oQHthH925q7pzzI8LoaYWmPFUIg bUTfnciLHDoiFwJeL+hll524BCcVNCmIPlIcdb5Y+v9BI7tnrkRfmBmAWZ1puI+m3I472fStl ALyEJ06TVlmYJWBcPnE/L8uj4hhqfwLKrm2nUp+nNVt/WuGclPU1UnJ0WqMrHFnNhr1XoyHHI cbV/IS0Wv28zP6vgUL4DTpZUb1JGzBwOMfzvytL8Yw6jpjfheyVt8OaWPFftYcJtvuS1VYp58 BWw1yNs9zm50Bfzk9zUX3unwZWghsr0fCgy9PkBKxZF7deeaJmG8jFwwz+Fv7zUgXKQzQG3jF phOU3xgqtqOqssTX1NPd/5/TygPn0VX1iaJmvuM7aqnR/HfFTYShUEgFje51mHMhb5KLUTZW9 szp5ixZzn2lhYVTBN8kusv+mYLiDwzLVdjK0akyFtLjm5cX2gZJUNwIVxOoc4Jj62WEk5iKLi 4sRmiqsYeslFuiEL67Lxgr0iPIZz499R5KxWbov3hsScjQfMRhely96Vd2HaSx8WrFoJVvwhX qZwHevCmSLpJlDBqOHh9ABm6Ii2G8p1UI1+mHWzldiY2/Dlmy0RUamJtrWWeA7dIoXUzJ2Vj1 jNQLa572c55qt/WsrYyLBxHFZcmkTCE0jnOiI4VuEVMlLUraBR6hshx4ZJTAXhQLg3IjABTtr exdwff1p5+6wTP8vBhOfSUI6sivnP/M93wZOkkEMKAp6/HFRmIbRFFvpjzaJ2G9AuNsd0Zlzp zXJG7y9sgC7x2sVKpXDQuU6QHiBGD0OxKDrCg3gomQ9NTBPY70Kv3uQcPJ6lA2ff+rxJOfm1B ksiZj4+oIAOoQHM0aY625Zs2b9N92MBjYPWgmKlQGwqpCOsK5feTs++5jVthpPyFvHpaU3yyj U1Ad6MRSTQvnYCo1Ke0vTTDSq6PLp+uEF6Q4UJdAiABYJWvXs08GMAs9ifEsr65wFOElB/tR7 C6wytUt/PuKBOvedxZH/K3s63wo= Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org No functional changes intended. Signed-off-by: Lukas Straub --- migration/meson.build | 5 +- migration/ram-compress.c | 273 +++++++++++++++++++++++++++++++++++++++ migration/ram-compress.h | 65 ++++++++++ migration/ram.c | 255 +----------------------------------- 4 files changed, 343 insertions(+), 255 deletions(-) create mode 100644 migration/ram-compress.c create mode 100644 migration/ram-compress.h -- 2.30.2 diff --git a/migration/meson.build b/migration/meson.build index 0d1bb9f96e..262e3c9754 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -36,4 +36,7 @@ endif softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c')) 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..77902a1d65 --- /dev/null +++ b/migration/ram-compress.c @@ -0,0 +1,273 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 "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 offset, + uint8_t *source_buf); + +static void *do_data_compress(void *opaque) +{ + CompressParam *param = opaque; + RAMBlock *block; + ram_addr_t offset; + CompressResult result; + + qemu_mutex_lock(¶m->mutex); + while (!param->quit) { + if (param->trigger) { + block = param->block; + offset = param->offset; + param->trigger = false; + qemu_mutex_unlock(¶m->mutex); + + result = do_compress_ram_page(param->file, ¶m->stream, + block, offset, param->originbuf); + + qemu_mutex_lock(&comp_done_lock); + param->done = true; + param->result = 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_use_compression() || !comp_param) { + return; + } + + thread_count = migrate_compress_threads(); + for (i = 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 = 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 = NULL; + } + qemu_mutex_destroy(&comp_done_lock); + qemu_cond_destroy(&comp_done_cond); + g_free(compress_threads); + g_free(comp_param); + compress_threads = NULL; + comp_param = NULL; +} + +int compress_threads_save_setup(void) +{ + int i, thread_count; + + if (!migrate_use_compression()) { + return 0; + } + thread_count = migrate_compress_threads(); + compress_threads = g_new0(QemuThread, thread_count); + comp_param = g_new0(CompressParam, thread_count); + qemu_cond_init(&comp_done_cond); + qemu_mutex_init(&comp_done_lock); + for (i = 0; i < thread_count; i++) { + comp_param[i].originbuf = g_try_malloc(TARGET_PAGE_SIZE); + if (!comp_param[i].originbuf) { + goto exit; + } + + if (deflateInit(&comp_param[i].stream, + migrate_compress_level()) != 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 = qemu_file_new_output( + QIO_CHANNEL(qio_channel_null_new())); + comp_param[i].done = true; + comp_param[i].quit = 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 offset, + uint8_t *source_buf) +{ + uint8_t *p = 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 = qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_SIZE); + 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 = RES_NONE; + param->block = NULL; + param->offset = 0; +} + +void flush_compressed_data(int (send_queued_data(CompressParam *))) +{ + int idx, thread_count; + + thread_count = migrate_compress_threads(); + + qemu_mutex_lock(&comp_done_lock); + for (idx = 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 = 0; idx < thread_count; idx++) { + qemu_mutex_lock(&comp_param[idx].mutex); + if (!comp_param[idx].quit) { + CompressParam *param = &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 *block, + ram_addr_t offset) +{ + param->block = block; + param->offset = offset; + param->trigger = true; +} + +int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, + int (send_queued_data(CompressParam *))) +{ + int idx, thread_count, pages = -1; + bool wait = migrate_compress_wait_thread(); + + thread_count = migrate_compress_threads(); + qemu_mutex_lock(&comp_done_lock); +retry: + for (idx = 0; idx < thread_count; idx++) { + if (comp_param[idx].done) { + CompressParam *param = &comp_param[idx]; + qemu_mutex_lock(¶m->mutex); + param->done = 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 = 1; + break; + } + } + + /* + * wait for the free thread if the user specifies 'compress-wait-thread', + * otherwise we will post the page out in the main thread as normal page. + */ + 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 = 0, + RES_ZEROPAGE = 1, + RES_COMPRESS = 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 475c04a18b..114901241e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -34,6 +34,7 @@ #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/register.h" @@ -491,32 +492,6 @@ typedef struct MigrationOps MigrationOps; MigrationOps *migration_ops; -CompressionStats compression_counters; - -enum CompressResult { - RES_NONE = 0, - RES_ZEROPAGE = 1, - RES_COMPRESS = 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; @@ -529,15 +504,6 @@ struct DecompressParam { }; typedef struct DecompressParam DecompressParam; -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; @@ -546,10 +512,6 @@ static QemuCond decomp_done_cond; static int ram_save_host_page_urgent(PageSearchStatus *pss); -static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, - RAMBlock *block, ram_addr_t offset, - 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) { @@ -568,39 +530,7 @@ static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2) (pss1->host_page_start == pss2->host_page_start); } -static void *do_data_compress(void *opaque) -{ - CompressParam *param = opaque; - RAMBlock *block; - ram_addr_t offset; - CompressResult result; - qemu_mutex_lock(¶m->mutex); - while (!param->quit) { - if (param->trigger) { - block = param->block; - offset = param->offset; - param->trigger = false; - qemu_mutex_unlock(¶m->mutex); - - result = do_compress_ram_page(param->file, ¶m->stream, - block, offset, param->originbuf); - - qemu_mutex_lock(&comp_done_lock); - param->done = true; - param->result = 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; -} @@ -608,44 +538,7 @@ static void *do_data_compress(void *opaque) -static void compress_threads_save_cleanup(void) -{ - int i, thread_count; - - if (!migrate_use_compression() || !comp_param) { - return; - } - - thread_count = migrate_compress_threads(); - for (i = 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 = 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 = NULL; - } - qemu_mutex_destroy(&comp_done_lock); - qemu_cond_destroy(&comp_done_cond); - g_free(compress_threads); - g_free(comp_param); - compress_threads = NULL; - comp_param = NULL; -} @@ -653,49 +546,7 @@ static void compress_threads_save_cleanup(void) -static int compress_threads_save_setup(void) -{ - int i, thread_count; - if (!migrate_use_compression()) { - return 0; - } - thread_count = migrate_compress_threads(); - compress_threads = g_new0(QemuThread, thread_count); - comp_param = g_new0(CompressParam, thread_count); - qemu_cond_init(&comp_done_cond); - qemu_mutex_init(&comp_done_lock); - for (i = 0; i < thread_count; i++) { - comp_param[i].originbuf = g_try_malloc(TARGET_PAGE_SIZE); - if (!comp_param[i].originbuf) { - goto exit; - } - - if (deflateInit(&comp_param[i].stream, - migrate_compress_level()) != 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 = qemu_file_new_output( - QIO_CHANNEL(qio_channel_null_new())); - comp_param[i].done = true; - comp_param[i].quit = 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 @@ -1484,32 +1335,6 @@ static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block, return 1; } -static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, - RAMBlock *block, ram_addr_t offset, - uint8_t *source_buf) -{ - uint8_t *p = 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 = qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_SIZE); - 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) { @@ -1527,13 +1352,6 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit) static bool save_page_use_compression(RAMState *rs); -static inline void compress_reset_result(CompressParam *param) -{ - param->result = RES_NONE; - param->block = NULL; - param->offset = 0; -} - static int send_queued_data(CompressParam *param) { PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_PRECOPY]; @@ -1568,31 +1386,6 @@ static int send_queued_data(CompressParam *param) return len; } -static void flush_compressed_data(int (send_queued_data(CompressParam *))) -{ - int idx, thread_count; - - thread_count = migrate_compress_threads(); - - qemu_mutex_lock(&comp_done_lock); - for (idx = 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 = 0; idx < thread_count; idx++) { - qemu_mutex_lock(&comp_param[idx].mutex); - if (!comp_param[idx].quit) { - CompressParam *param = &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)) { @@ -1602,52 +1395,6 @@ static void ram_flush_compressed_data(RAMState *rs) flush_compressed_data(send_queued_data); } -static inline void set_compress_params(CompressParam *param, RAMBlock *block, - ram_addr_t offset) -{ - param->block = block; - param->offset = offset; - param->trigger = true; -} - -static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, - int (send_queued_data(CompressParam *))) -{ - int idx, thread_count, pages = -1; - bool wait = migrate_compress_wait_thread(); - - thread_count = migrate_compress_threads(); - qemu_mutex_lock(&comp_done_lock); -retry: - for (idx = 0; idx < thread_count; idx++) { - if (comp_param[idx].done) { - CompressParam *param = &comp_param[idx]; - qemu_mutex_lock(¶m->mutex); - param->done = 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 = 1; - break; - } - } - - /* - * wait for the free thread if the user specifies 'compress-wait-thread', - * otherwise we will post the page out in the main thread as normal page. - */ - 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 From patchwork Sun Apr 2 17:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B25FC77B6D for ; Sun, 2 Apr 2023 17:58:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wY-0006oT-FI; Sun, 02 Apr 2023 13:56:42 -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 1pj1wU-0006n7-Ku for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:39 -0400 Received: from mout.web.de ([217.72.192.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wT-000442-6E for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458193; i=lukasstraub2@web.de; bh=k64E8thNSVxnLjVte7TZElBP4kSPwtJup2zBMDdaP2k=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=q/39LIWSos0GKsysQh/FHdoHlvku/9LN+C3DOERIHW24z/RLWvNQH5+OBXrBh/E+h ptOoMuxd963mCggE2x9PoUYBLquh2eiFZys6hv1iVHhQrVbTDJTsqNyClK6J3ortOo UK6Z4+HEs3saJVQZfGJmyrAb6/3NiUy07a886YEXteaISan8mEAP6RkbqnW5+SrL62 TglRkyABdFKqWLu1TNYJIfKiH0LTzMSFBNivLVCvUdYM55ukWgNEppHwhoZ9o/aS8Z DkhE/x95FACwPoONVkxuldZLZvdQpF0vWExSUKU9X5EGeIatSAoWWZYvzbA0WnmluH 0zNPdecEev6yQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MeDQj-1qJTDq0vhv-00atb1; Sun, 02 Apr 2023 19:56:33 +0200 Date: Sun, 2 Apr 2023 17:56:32 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 09/14] ram.c: Remove whitespace (squash with previous patch) Message-ID: <8faee1623c20f0aa44b3abc4432c3b94f15b8a91.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:zPzPMwuqsh9rXYFAyA6stN2oBEtsBFHKCNRECa/mzaYWTmq+Ik+ c5YLQoJLFGcMeawdPJV2Ouv+K6rpAAFNeY6XQNv4HjwBPDURrjN2BsKOn1FTZPiHScFrCdF KHaCRoR28WDUCZ9D5HLs3ukmW/BA5h9Z30eNd5iJhrMt0egv7NCBZw6vw1RXanipAulA2KY 2TMgJzhzzt5YFkMY5OF+w== UI-OutboundReport: notjunk:1;M01:P0:VQNWhqnhwzc=;IPu5JpvWA0FI27VWHMYcrFvv2DB HF+0+Lwb4z/HI5fSldrS6RRBJxJ1SgAMwM5zk9gP5mz0HFb+awRGxoniOV3UCBRq6yTYFiE6d Bvjs3pPrG4I+wxxi0ylEaOciHjvBnWLLvc5bOoZqKb8DXgD9LfkW/1PvKY5eyX6YQtfWJFJQj U16h5Bw1RsvQ8OXJYJAY6b/VSrk+e3Doz3zrVpOslDBKuY4Z+IUjhQ3e1GBEE6EQa/tHDyuF3 xhTym0ND2oj8GOxErgRaXc0Bxrtv1os1ft9MwgqHwPkgvBB2tk5VCGCul6UoUfK2GfWI6Y9FA YmK+OTiyMN3tKBza63OAbG4jXuHD1G7odqdDkqEKqwyEvw6zCwCaLXo9I2f1g0Yvhbw7oH7Tc thTu0NHh3fpWTPaRDyt3RFFC1vAytvUbuKX5RcUKjgDq3yYJv96rmEK2uZGuMmZPTrd4dVImf jAIpHKJvfWxHVY20BGgAcNQBNp8RlWdp54EsGzCS0ahGweGsPoXu4p9Hg0ovuIPbDM9nQPkR/ KVCjeTS9EWO8KH8lrx8h5UPZ1O+cvHuI2FSyOAImDKmtAcrqJfKA88j2kbEC3EYq/zssvd45g CokGAvEg5U4VRh5Ansi5Y7lYi3RXeupJSH7wcTiNQafuOMGP2coh6Mfl32KTAxDrbgIUo2MFs vxq9OfXy7xZ8/2CP7DLsD3NBCsU21fvFyGhAtLb64lL36+PCb4PwApo2BWojm4rBJQ83TDnT9 9NuVhXY7QSNJm10cba/JVTqZ1OShgTA+FBs6inKuv0Z8g0AyGdY2WAXo8ESDrM5IxqUgDEZNL 0ESPODGs2F4f/zL9Izp4/COhrbDbd+5Nf+EQMyagDx13Vn1SOJXExFlU+BnDKc7RHBSQsC6ko 73zOa1w+LtygOZ/mylSYy7xR7NUwdJnhu3kjsdjUv6cQlbBSH0ExwxR+1IJ/mR6Yyz22Wf7os nPtzMaSwsKTxzV7dFj/3cWfB62E= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Lukas Straub --- migration/ram.c | 18 ------------------ 1 file changed, 18 deletions(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 114901241e..31b9b0b9ec 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -530,24 +530,6 @@ static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2) (pss1->host_page_start == pss2->host_page_start); } - - - - -/* split */ - - - - - - - -/* split */ - - - - - /** * save_page_header: write page header to wire * From patchwork Sun Apr 2 17:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41B4FC76196 for ; Sun, 2 Apr 2023 17:58:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wc-0006p4-5Y; Sun, 02 Apr 2023 13:56: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 1pj1wZ-0006oc-AO for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:43 -0400 Received: from mout.web.de ([212.227.17.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wX-00044Q-13 for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458196; i=lukasstraub2@web.de; bh=TBYuBZEdHM9itefC6FEFGIchlHsJurZstc3lDoPhNX8=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=WFz6bcsjbuRhzSK+AmoKeZVrLw79YejE+15zKwy2nuT5AAkN+i3ioiOlO2OMIKA0H T+lKmfs4nwDo+Go3nM3f0aGtZhT0MjUnKxGIyxHughBVo/wVTUaL+X/E4+dyfJo6e2 nOXi8Im6JU5bex6nFSTE5K68SLHyUplnDoWcEqu2Pytllr03tzl+e63ZNdmKSrdoEU 6dvSekRv/5Poz97iCu/w7G/b3CCIzqeV96UOZou/MbVmy35POyfEgaFfC9cpYFkzac Udvl8T/7OO+YerOB00npWGL26QH/fl9CUYgbnYCmMVcTZQJ1MM69ohIS0J8UiWLJPD VsFWn5dVd4qJg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N45xz-1qQZxF2psH-00zprQ; Sun, 02 Apr 2023 19:56:36 +0200 Date: Sun, 2 Apr 2023 17:56:35 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 10/14] ram.c: Move core decompression code into its own file Message-ID: <2af9a607c95a9b543a213c7123be5c8f131e922c.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:BQJnpT5XPmoh82m+VPTKKT3XVYx2JVmWEfy23RI6qD82cw5hyAM uskcG5xkjB6X2/8o9njONJ9q4dXNVLad3GW/ZwHl8QE1USI5LquVCFsX0ujW9yAQeewtQT3 qzXmZoBscqx8ak++qpvWDAX86mhKGjrh092vbQQsGHs9UinE0Dhvic0duwzjPM2Dehs5dOt 9tnOdINxbzAvIJ00r0hVQ== UI-OutboundReport: notjunk:1;M01:P0:vbmtOslda68=;0mpP3qqzNpRz24opK1+Umwbe6Y5 DS2A3uEpXBvyfIXy2jQ/vGfxy2BeLYHhIU5D7iGhAnYSb3noXKjbzR08Ghb/+vkqRW5c1+8cR 2ma+mdCwQOt+rVBV/rBDsEonkPCypZRt9tyG1rYnrfUFrHnNov9LxhrrDPIpsBTITbPA/JHg2 OPXt0LUQanNZefHxsr2+sUa68lyTr5QU7v3zYh1D9PkUyL+aEAQTwcU0Hr/mYP4j1wS+b4KHE HnHW/A7lbUTOPpqqkJy2gBQMgJZNSUc+VQk1HcWkGv/9EsywcWowri1x2faUv0PaWjS+TgUrD qKAFskCnDjOkJdYaGHL9XZ+I3YlUYelbE1s7Ogi0oFfK6Aaj6/orUjhKOuHF485d6U26WFbIS bltibsY6hRKvFyOJcWfZJQZNc3j4IvbAbdFSS6pLMLr2r4EYGpkPo/lIAVWlI3DbGNDWvjuYO 4VTfRwOc4omVmzivdZK/9AGXKSIYXKwoMwroUTqU8dfU7UIpDnlMFaABw+Ki7KdYw6MCVJ9WI s3Ql3WWQ6FWah1zgbvP2mdytbKrT5u+umDfNTE9dUtEiJyFeJtqB8hxYoHvCjJ3rSmI6qOCJr zLallzc0Y55n2DaLZZ6LAsbf3mVLTubeFrwNpO+LlSRt9tjaro+PGrHEK7LdQTWXNQcg2Ssf9 YDArlPvZ9Zo1GYAxkkQLrdPyZyF4BewnEBAkZyqlJtXuKoyrTG5ITNItpXzRhFDbWCauxEIZA JyFQk6YqOTgWa51L0EGbBJui5yhp3lm0WFgs6TaNi8YT7Y/gKkz5WHswTly0X7i1bcVrDZGWu yga4fWlkN1nkLlUR8oPUch5yitSf2KPs5oUtWp4QrvBACsBf3eQNowvT/V2Xr9PMDHfJt7DHo uJxnaNc2E8ERmTfz+mRNoddWVZ4j0zgyJHohsDY/IBDk5240KkPeOImvlRkiScRcpd1uW7Hxo 7JI90qIyhGiq59/T5jVnJpzKVlI= Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org No functional changes intended. Signed-off-by: Lukas Straub Reviewed-by: Philippe Mathieu-Daudé --- migration/ram-compress.c | 203 ++++++++++++++++++++++++++++++++++++++ migration/ram-compress.h | 5 + migration/ram.c | 204 --------------------------------------- 3 files changed, 208 insertions(+), 204 deletions(-) -- 2.30.2 diff --git a/migration/ram-compress.c b/migration/ram-compress.c index 77902a1d65..f75b8c3079 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -47,6 +47,24 @@ static QemuThread *compress_threads; static QemuMutex comp_done_lock; static QemuCond comp_done_cond; +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 offset, uint8_t *source_buf); @@ -271,3 +289,188 @@ retry: 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 = inflateReset(stream); + if (err != Z_OK) { + return -1; + } + + stream->avail_in = source_len; + stream->next_in = (uint8_t *)source; + stream->avail_out = dest_len; + stream->next_out = dest; + + err = inflate(stream, Z_NO_FLUSH); + if (err != Z_STREAM_END) { + return -1; + } + + return stream->total_out; +} + +static void *do_data_decompress(void *opaque) +{ + DecompressParam *param = opaque; + unsigned long pagesize; + uint8_t *des; + int len, ret; + + qemu_mutex_lock(¶m->mutex); + while (!param->quit) { + if (param->des) { + des = param->des; + len = param->len; + param->des = 0; + qemu_mutex_unlock(¶m->mutex); + + pagesize = TARGET_PAGE_SIZE; + + ret = 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 = 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_use_compression()) { + return 0; + } + + thread_count = migrate_decompress_threads(); + qemu_mutex_lock(&decomp_done_lock); + for (idx = 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_use_compression()) { + return; + } + thread_count = migrate_decompress_threads(); + for (i = 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 = true; + qemu_cond_signal(&decomp_param[i].cond); + qemu_mutex_unlock(&decomp_param[i].mutex); + } + for (i = 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 = NULL; + } + g_free(decompress_threads); + g_free(decomp_param); + decompress_threads = NULL; + decomp_param = NULL; + decomp_file = NULL; +} + +int compress_threads_load_setup(QEMUFile *f) +{ + int i, thread_count; + + if (!migrate_use_compression()) { + return 0; + } + + thread_count = migrate_decompress_threads(); + decompress_threads = g_new0(QemuThread, thread_count); + decomp_param = g_new0(DecompressParam, thread_count); + qemu_mutex_init(&decomp_done_lock); + qemu_cond_init(&decomp_done_cond); + decomp_file = f; + for (i = 0; i < thread_count; i++) { + if (inflateInit(&decomp_param[i].stream) != Z_OK) { + goto exit; + } + + decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE)); + qemu_mutex_init(&decomp_param[i].mutex); + qemu_cond_init(&decomp_param[i].cond); + decomp_param[i].done = true; + decomp_param[i].quit = 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 = migrate_decompress_threads(); + QEMU_LOCK_GUARD(&decomp_done_lock); + while (true) { + for (idx = 0; idx < thread_count; idx++) { + if (decomp_param[idx].done) { + decomp_param[idx].done = false; + qemu_mutex_lock(&decomp_param[idx].mutex); + qemu_get_buffer(f, decomp_param[idx].compbuf, len); + decomp_param[idx].des = host; + decomp_param[idx].len = 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(CompressParam *))); int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, int (send_queued_data(CompressParam *))); +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 31b9b0b9ec..5a2486bf89 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -492,24 +492,6 @@ typedef struct MigrationOps MigrationOps; MigrationOps *migration_ops; -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); /* NOTE: page is the PFN not real ram_addr_t. */ @@ -3467,192 +3449,6 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size) } } -/* 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 = inflateReset(stream); - if (err != Z_OK) { - return -1; - } - - stream->avail_in = source_len; - stream->next_in = (uint8_t *)source; - stream->avail_out = dest_len; - stream->next_out = dest; - - err = inflate(stream, Z_NO_FLUSH); - if (err != Z_STREAM_END) { - return -1; - } - - return stream->total_out; -} - -static void *do_data_decompress(void *opaque) -{ - DecompressParam *param = opaque; - unsigned long pagesize; - uint8_t *des; - int len, ret; - - qemu_mutex_lock(¶m->mutex); - while (!param->quit) { - if (param->des) { - des = param->des; - len = param->len; - param->des = 0; - qemu_mutex_unlock(¶m->mutex); - - pagesize = TARGET_PAGE_SIZE; - - ret = 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 = 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_use_compression()) { - return 0; - } - - thread_count = migrate_decompress_threads(); - qemu_mutex_lock(&decomp_done_lock); - for (idx = 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_use_compression()) { - return; - } - thread_count = migrate_decompress_threads(); - for (i = 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 = true; - qemu_cond_signal(&decomp_param[i].cond); - qemu_mutex_unlock(&decomp_param[i].mutex); - } - for (i = 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 = NULL; - } - g_free(decompress_threads); - g_free(decomp_param); - decompress_threads = NULL; - decomp_param = NULL; - decomp_file = NULL; -} - -static int compress_threads_load_setup(QEMUFile *f) -{ - int i, thread_count; - - if (!migrate_use_compression()) { - return 0; - } - - thread_count = migrate_decompress_threads(); - decompress_threads = g_new0(QemuThread, thread_count); - decomp_param = g_new0(DecompressParam, thread_count); - qemu_mutex_init(&decomp_done_lock); - qemu_cond_init(&decomp_done_cond); - decomp_file = f; - for (i = 0; i < thread_count; i++) { - if (inflateInit(&decomp_param[i].stream) != Z_OK) { - goto exit; - } - - decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE)); - qemu_mutex_init(&decomp_param[i].mutex); - qemu_cond_init(&decomp_param[i].cond); - decomp_param[i].done = true; - decomp_param[i].quit = 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 = migrate_decompress_threads(); - QEMU_LOCK_GUARD(&decomp_done_lock); - while (true) { - for (idx = 0; idx < thread_count; idx++) { - if (decomp_param[idx].done) { - decomp_param[idx].done = false; - qemu_mutex_lock(&decomp_param[idx].mutex); - qemu_get_buffer(f, decomp_param[idx].compbuf, len); - decomp_param[idx].des = host; - decomp_param[idx].len = 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); From patchwork Sun Apr 2 17:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD0FEC77B62 for ; Sun, 2 Apr 2023 17:58:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wg-0006rq-Fh; Sun, 02 Apr 2023 13:56:50 -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 1pj1wc-0006p9-Lr for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:46 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wa-00046U-0B for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458200; i=lukasstraub2@web.de; bh=gakdj9MuRP2kmr9tpcbl0VTtVwaDkY+EO+nYuW3YLiU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=wZ2EK//+zMH1zYWQeTcdkSwoRy5mf9Xrojkp6kIXhcLtwNtakCkKZT2+LSEY8EETE Nj6K8V/IOKNqjLprDFriAk0Lcw9NkdYdtVAYYFCGWJOrlr6nh08h71JnuKJ6eeJoGT IS/kv4u/jOienfRoM/VXsgeutHxrtVm+ic+rTAMK88kopDGbDmWBqSfRHyruLD+Icq Vxsnp2yNGMh9RJ1oi8Mc5u6yvKI6PFND96ZhzfbfY4ISnfDP3i9WMm8O9PMSf2J2NW aaiqdxOPKJ6T6yMWLHLCbGSUMU7XlfbvY2Src9vnDKyH2bCeDTWH58UTglz0qWUhyp WZwj9tB2fhgHw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MA4bA-1pYct80bAg-00By3I; Sun, 02 Apr 2023 19:56:40 +0200 Date: Sun, 2 Apr 2023 17:56:39 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 11/14] ram compress: Assert that the file buffer matches the result Message-ID: <929d6df4337b8a206cfbc201b5d350a324d66b02.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:5gSpBR/4RVf4RiBuFq1kJjb403pqUxpInx8MPhGiHXPrlbSJj3/ /TQ+TodjwiKKvklzd6xVKrKU2cB1/djRpqz0Nw2wkQS7OmHHDv7M3w40I4AjkPb8obwH4ao UzRQiV3E0bfD53w3RtGtuwGMrRUsHXJQwQrw5MP8oK+GeZ/aaiIFm7JDDouXsNaBZCTzh/m y+7NIECErIARoTxoD/qVg== UI-OutboundReport: notjunk:1;M01:P0:DHDwzci6qds=;oN6s4vYFEsetkXpiGPmORZ+Ikmc w/l2j/XEj1WYyOsHPhKBO7sQhCqV6Zr7jo64TZ65T/Q+jS9niCNSiI+XWcQCWBZHl/q4PCscW 9dMEjrnNTYhNd5tSFhPHPt02T2Lg5QFkub7/U1XCMcrzfpqifWIYQHYFDHQCgQYUtgqMA6rU6 Mh3/zKm49Jax/C+3LZgJiKUfKBOFAc8L2AZNt/AQHOESHOuu3UnaaWOGXL69WehlRyPBbmejv 3wBWyyXOpXh1f1CLSbSYhT+qPzHY0dsLCM0TOAYl21yWnmKDuXUm3qXBl9WdeqsHTZLMPqxWo AtuzWS2M1OP6Pr1VAS6WAFNOyXIppQ0aguqoitqqxyPk4+XQfef5W8cKX2ZkhaqaDFIRlhmGt 79OmeotdSIgWGUo0M+cKWjYLAuS8fOlKOB+ph3Gd3Qapb48QI2pmwZG7j5AQOiIw0C+b01QPX bEzhlNHvMXYTzx7IfF15ihIgaAeB+6ZpK0dGOCdpOhTxHge0jkQrxlDSggEvPyPOPv9x8BBC+ LUk0j+zuUMA27L8mqpZBpfSOD9i/v4zPPaj56kjTfg90ePOFOj039lYSGx05SIYos31TW8soe g3zcQRozJhtko/XLbS5/+FASM55VpxXKBnVSHrAEzlFpH5XK8zkkNWSs6erkYC4JG8sOk9Y0v fTtJkiMgH5ZXFg5fV5HTEhmN4HkBLm3/dlh/zs6Z8MWEW6S6Nf+YEVA7cwIgepaKW3S/PwwKX 59d+jgTHJhAGxHRLkVZM7srMxaKkkbM9J6+IdiPH+xtoS3wTyDEH3GrqTSHrUPvRj34iKOFBB NTulDia63BczFY1TVv5NtdRiS7aYQ9BZ/vhExCdwa18i09rX5Th3Gpa5oSZs936de9XfxQnbd FuZFrVg5QJG3TP8eKhcXJ5FsJFgTKPNK5r4w1XDHzPJG0ooSTFMJVG3SOADrDs08HPjpCiIy3 OEUp47T4MGLu33YInHm7FWRPGeI= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- migration/qemu-file.c | 11 +++++++++++ migration/qemu-file.h | 1 + migration/ram-compress.c | 5 +++++ migration/ram.c | 2 ++ 4 files changed, 19 insertions(+) -- 2.30.2 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 102ab3b439..2b3f3f8549 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -887,6 +887,17 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src) return len; } +/* + * 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 9d0155a2a1..15e5f189f0 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -113,6 +113,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size); 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); /* * Note that you can only peek continuous bytes from where the current pointer diff --git a/migration/ram-compress.c b/migration/ram-compress.c index f75b8c3079..b75a9d2b9a 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -193,6 +193,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, uint8_t *p = block->host + offset; int ret; + assert(qemu_file_buffer_empty(f)); + if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { return RES_ZEROPAGE; } @@ -207,6 +209,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; @@ -238,6 +241,7 @@ void flush_compressed_data(int (send_queued_data(CompressParam *))) if (!comp_param[idx].quit) { CompressParam *param = &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); @@ -267,6 +271,7 @@ retry: qemu_mutex_lock(¶m->mutex); param->done = false; send_queued_data(param); + assert(qemu_file_buffer_empty(param->file)); compress_reset_result(param); set_compress_params(param, block, offset); diff --git a/migration/ram.c b/migration/ram.c index 5a2486bf89..7a8f540737 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1333,11 +1333,13 @@ static int send_queued_data(CompressParam *param) assert(block == pss->last_sent_block); if (param->result == RES_ZEROPAGE) { + assert(qemu_file_buffer_empty(param->file)); len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO); qemu_put_byte(file, 0); len += 1; ram_release_page(block->idstr, offset); } else if (param->result == RES_COMPRESS) { + assert(!qemu_file_buffer_empty(param->file)); len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); len += qemu_put_qemu_file(file, param->file); From patchwork Sun Apr 2 17:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B1E3C76196 for ; Sun, 2 Apr 2023 17:58:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wh-0006s6-1G; Sun, 02 Apr 2023 13:56:51 -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 1pj1wf-0006rd-Cs for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:49 -0400 Received: from mout.web.de ([212.227.17.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wd-00049E-SD for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458203; i=lukasstraub2@web.de; bh=EB8VaRAWBK0oXLR+71tIM6tqF5W0FQ15mCpwJS4kA3U=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=ZumiD/YCehugIaWecE1yeLgz01JrBqthWXCSKovTJyAHhKLMBBVnx5+1WVW6VozCZ dFD4tB4Kv8PU5+KvBIhr3RcmFKN3JDjV6wQJGYRIQGVShfSDydvKl6kIF9ODzOxmoJ gsMdnlO0H6oAvmA/qogPLwPhqJENzOTw7QpOUoAAXLP5+u7khLatGkxh6gcc603fXn 0XUkCNrzj2Yhx9/3XrhT2IPnf0e8YLMpxvImpvsb86f2mVOhcIMlvTJ85uD9eGV/wI uFrBxpa8V6z641VPwrg1mYeR/WuAJsSwpWuYRBruVu20ZSxTVAoe16ZD2x7wZ8cwt0 frpJOyOpvOiMg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MfKtN-1qKakC1d8N-00ga7n; Sun, 02 Apr 2023 19:56:43 +0200 Date: Sun, 2 Apr 2023 17:56:42 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 12/14] ram.c: Remove unused include after moving out code Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:WQgbku5LHYMz+D+yNvZHdlYu/sFOdpCOtCWza8BOacZmQMLwq6V 6NdJiQ+Bysdbjk0rNoln5HL1lAMjQ00RTEabHsf9D0jttjCeiuIVwfU7DLE9MI+mTexzF64 f5XpaHjVMP3KlSVS8PX5KoYf1NK4E2ejTl1Uxc0SrqHqo2Np6uvQ3VhPCyoHrLQB50GtsAh 6Dw59DRqKZJFZbO2rUPTg== UI-OutboundReport: notjunk:1;M01:P0:cajR0OPTqdw=;LsQgOTQPanAafeOcI9rpw4PKwU6 eU5uqjrgktDiCUlvWAE5QTDtS2w/MYWXx4BDmDMQF66X4In8GWguiqp+n+NEG4i3A1F5ZchxG qVNFonJZfCNMPIZEjmuXr5pRCoCd2mK8wsxgxzRmuOqnyC8cCSMbbxIpB7HgULCkEjiTwmOnu nuPj3DAKIdf2THomTO9jnQHUu7ngdcNmpnTUgJiUH4Vk47iiKJ+DZ2hxe+01DN9eTPQOJT9L/ 66M2PyNx8guZveZH23SdbmieTxr1+rQR/8/CoD+KsgI11ICtnKy+AHlfQcGEzX4jBj8GgfXI0 apqk52L4dPu2o3O1UVSDBHMetwx4lxiSvbTGxon9SwemAZfsvPOKYbsczXe68WOFJMr8X3TAr +ZSdP8T+4dCkzfl9dH12adXL4p6xThTM0oxnI0dbFpxpcxgYccSGfIrehgG1Nw/63tB0UXc4b W1vJKtu8TmeJf6t1sX4sTUNq8OagiyovDBuTlGHf0VzhikXkexpuVtKkX5FmwAFZ9isufS+ry teH16p58P19WGejjHqE3RLfxJZe2Bt/Fl9sJHOS62GevMnjCoANkJIxuI6cx46FKbrlEC2ZvB HwiOxpY5W04NdX9kUyUoSetHxJBRXStyCWA7Plto5RiAFWK2/huHOwPn1kjTqv3jc1GM/qvoY WipqYA7B5z+4qs1SMYvZOhZjsTey1E0HQdVAbSpU2IE2aiV6a8rBA3+2NnBt8Lm40LARwdBaK 4JR3DPDEemdJu6Sne4yf3HZWfS2Yu4HhaGPEdrViMLrtjL46jGegwrasUFRs9V6hpWa9DTnk2 akH0rOjSaXDS5mdaVOW3DHvelxw7G+XOA0QtSY/t+ZgkCazkvva7WE+TRqdcXcOt21RCDcYle LBeXx62JrCpPw4zwrWwfKiIfv8y6zLPxCwLlxBk/bwF/uJeQnX0oSXFo5bqC6fEvDze6rmfLo twIphIElRX56zl+w0te7hP6akvQ= Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Lukas Straub --- migration/ram.c | 1 - 1 file changed, 1 deletion(-) -- 2.30.2 diff --git a/migration/ram.c b/migration/ram.c index 7a8f540737..9072d70f7c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -32,7 +32,6 @@ #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" From patchwork Sun Apr 2 17:56:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10F08C761AF for ; Sun, 2 Apr 2023 17:58:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wk-0006um-H1; Sun, 02 Apr 2023 13:56:54 -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 1pj1wj-0006sP-C2 for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:53 -0400 Received: from mout.web.de ([212.227.17.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wh-0004CX-2E for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458207; i=lukasstraub2@web.de; bh=ltaKt3HMk8MWhVsUmGjKWgv3LRNgQ6mpm6WvnlbaEBE=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=M1giuJx8NXv66wGa7qiTnW8t2oy09ufM47rXKi1bSEhlwaV8096dqJ9biWjgmF6De HlhUYTNBiRphs8fqRrnm5lbUShgPfCc9M0SGER2d+wXtVUoSZrDA3yVZQV8BBuxNkA 77VR5STa/aYyZD2FzvxvmsvfN3BxzoZ53wBnxrzWGSojwqcMJGlKFFevMTjIdgXHtk LJva0irTup+i3IPcw4rBUgA6wOd9A8sVOmsegnoYg1o0CQH6ql+G7DhV7i5JpEaVfo SI6DQm8g+J0kVCr9/GgIkY86RsLUIRaZjRdplmS02szV17/xdAnnwlwj/shcMfWAuR ZGcDLkD7uIzKw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N7gXQ-1qVp9B0CBO-014ux9; Sun, 02 Apr 2023 19:56:47 +0200 Date: Sun, 2 Apr 2023 17:56:45 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 13/14] ram-compress.c: Make target independent Message-ID: <8c89bab01953f658b44cd67df2c75657ccbff5a4.1680457764.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:/FV1zBwsSN1PKTB1oPZr8oaSCLEGQAbEVkSUGBRnnaRcpFokhDU 6F93avRnaeYngXGHUnwUk7yGm9nMcfz+1m8pahJT5R3hxA5tnNxz/PwxWyHKPNFF+BR6FIL RWmvkQOyTy0s7+qsc2Hdrr3qFcPwaROZ78AayClRQsdzc7tXK9gdt1XCdWJpasoOlO3gt0d zgNpLZ8E1NmDSUYrD4EDA== UI-OutboundReport: notjunk:1;M01:P0:J1gdBN05i2o=;ENH7+LB7bYGXS8xXlF7E4AAzEpd DuoJ4A1XHV0TFRk6HCMtixo7U+Ih8e3vDMtmUdSzdKSQ4f7mx72eaUD+hv7h5I47jy25RNeOc zB0kr9BsgRQNeky/2JP6lSMAZTYJBFnKZMxLtfaQrzWKNrv5U9Zw7bZGERclSQwGe23qvMv15 7ShP6Mc3SGdoFIJUTqkS2adAjlzyLs6wd9IMA9VrlsuTM1X0LfxYTgc5JXji7Cb5FBiE6LJbe OHoHMZs5uWRodifT34KmNg/JRNUaP1OoGM8BqDxzytI5UmZgGcraNX/K6jcpgEEflVKFbQB7s Gf57O14Tzr1nOjsO0qxuGG9n6CBmx2QcvF9SU9s8Lj6FgOCtc1s3jQZP9MZrw7DUOHGliydpn W9Dkp3sEmn8cieA1PvuifUWex+cJqtkBIAmn+cgYGrzkf/BLE54LEvwA48+QRIa3Y1hOqc+gR w08GJ6n6cIYnxVJPLFmxCTtPsBuJFfRFj089Y9xIdZhc0FECRIUG30HhKjdCjUeN/t/rlTLLn KxP0StJMah1HSivpXLgYvlW0745h9J9oPn00qpBOGYCWzqZOhBk4Hd+lvVxvMw1ErpEdjd15U y74K48eASQN5j4I6uCX3fqE59tVZt20OME9i4uNKw8w4/8otVYJthx28a+p99aY+bStOMn2Yn MMpSFjRfoO/sr+KEZcPh2xhygMctYpo7iicm/RAvuA+X4Epr7JCKBEryI+kzEfuzQv+V0JSx+ 1q7t0AIbOHO+FwbXyAwSMayAPlE38q+nWyrBtJxwoHq0J6YoET8z/a2yg92odAUR5KZv/thZM k2GdTS+v/+s4lrk1wJCZwSpoSIwEGGrI9Iom5t5+ioyUiFQcDlkGkIUkzOJ9hFYf04RsWJGeu D8S0/dEAnsFvTmxynayRawkqTjFih97veR4s5xcLsfLStfOwCdiem/tF0VsJLTcdUfTbrdk4L DIGEEuPi3g4+F0Hy5ka+GvtK6oM= Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Make ram-compress.c target independent. Signed-off-by: Lukas Straub Reviewed-by: Philippe Mathieu-Daudé --- migration/meson.build | 2 +- migration/ram-compress.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) -- 2.30.2 diff --git a/migration/meson.build b/migration/meson.build index 262e3c9754..16f642031c 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -22,6 +22,7 @@ softmmu_ss.add(files( 'migration.c', 'multifd.c', 'multifd-zlib.c', + 'ram-compress.c', 'postcopy-ram.c', 'savevm.c', 'socket.c', @@ -38,5 +39,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 b75a9d2b9a..a75c6e0573 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -34,7 +34,8 @@ #include "qemu/error-report.h" #include "migration.h" #include "io/channel-null.h" -#include "exec/ram_addr.h" +#include "exec/target_page.h" +#include "exec/ramblock.h" CompressionStats compression_counters; @@ -155,7 +156,7 @@ int compress_threads_save_setup(void) qemu_cond_init(&comp_done_cond); qemu_mutex_init(&comp_done_lock); for (i = 0; i < thread_count; i++) { - comp_param[i].originbuf = g_try_malloc(TARGET_PAGE_SIZE); + comp_param[i].originbuf = g_try_malloc(qemu_target_page_size()); if (!comp_param[i].originbuf) { goto exit; } @@ -195,7 +196,7 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream, assert(qemu_file_buffer_empty(f)); - if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { + if (buffer_is_zero(p, qemu_target_page_size())) { return RES_ZEROPAGE; } @@ -204,8 +205,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 = qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_SIZE); + memcpy(source_buf, p, qemu_target_page_size()); + ret = qemu_put_compression_data(f, stream, source_buf, qemu_target_page_size()); if (ret < 0) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); error_report("compressed data failed!"); @@ -335,7 +336,7 @@ static void *do_data_decompress(void *opaque) param->des = 0; qemu_mutex_unlock(¶m->mutex); - pagesize = TARGET_PAGE_SIZE; + pagesize = qemu_target_page_size(); ret = qemu_uncompress_data(¶m->stream, des, pagesize, param->compbuf, len); @@ -438,7 +439,8 @@ int compress_threads_load_setup(QEMUFile *f) goto exit; } - decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE)); + size_t compbuf_size = compressBound(qemu_target_page_size()); + decomp_param[i].compbuf = g_malloc0(compbuf_size); qemu_mutex_init(&decomp_param[i].mutex); qemu_cond_init(&decomp_param[i].cond); decomp_param[i].done = true; From patchwork Sun Apr 2 17:56:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 13197517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A13BC76196 for ; Sun, 2 Apr 2023 17:58:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pj1wo-00071e-81; Sun, 02 Apr 2023 13:56:58 -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 1pj1wm-0006wK-8Y for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:56 -0400 Received: from mout.web.de ([217.72.192.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pj1wk-0004Cv-Ma for qemu-devel@nongnu.org; Sun, 02 Apr 2023 13:56:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1680458210; i=lukasstraub2@web.de; bh=uD0yPQy46Dhm1GKDNQ2Z+mjWaN0hh4FDx8761C9QICQ=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=PU22aoKWcrvyWyuWPebtjdgie0VjsDxTbqdSi1jrHbef0oqdxRXJ73ojtZPWYG8/B uglmDPOb9tM9Zp/sep5KrdioOPbddBZxT5AQkHQInfcSiiMCbOqgxhEY4tQm4mS0dK v3iEM6SlL85dHqg/ZeTFdER5PWgaD6hysgskerYCgL/3SSWMWA/k3z7+ZHDDrz5Rmv pezdkbv9thf8BAfOuJ20Zhw9PGOFhHaVnP+DOoREaAbLvBcS70sNMvmJyVAen3KtW4 HIV8oL6fCp7hqI4N++QLscW1bRTPcJe5YsQ4nBQgkyEjY4TuO9x9GRSFOWbI1Bsjza lco1PKYcxL8VA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from gecko.fritz.box ([82.207.254.111]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M28WJ-1pgYyR2tgH-002NHv; Sun, 02 Apr 2023 19:56:50 +0200 Date: Sun, 2 Apr 2023 17:56:49 +0000 From: Lukas Straub To: qemu-devel Cc: "Dr. David Alan Gilbert" , Juan Quintela , Peter Xu Subject: [PATCH 14/14] migration: Initialize and cleanup decompression in migration.c Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:mDmYvNswxKOqH0dcZX//2ZFAwptpKBTmBsyp0L1gJ9m1pmDd7EP e92Zcf7wS3ZpCiEHVa/Syvamq+5ZcZQJl990n4/vWx1qWKWIHQb9a05Xbo9uOHDM3GfZl53 gGmlzEeJ0ypyTMGg7JRUON0dyf7QwWStryAHOkLw5joG9YFle937yPKuJDBj6AgyYTURG7S bgbBBNKUvqvZxfz2xNVhA== UI-OutboundReport: notjunk:1;M01:P0:RYlcS/pKWSM=;GpBwB0pe33Lk0NCOaO9mimXwSXg dDHqLKlDPFpoGG5WATc6DnoZdYDWSjAbUNlATXQBTBFoJDhEbdrxKv1IR0UIOjdMJXScqCpif nXp2Tc8/FGsQu48ce2z8+b+Me5n2pi19bIROJ8s4wHU7HhnAi1BG6wURqIh8txkygY6L6ePkT ZrQmywrXSOs1Nn2jfDF27LHapRdUrkwk5z5ot1B6n/9gSJa8fyAymsUt56jGZkUA9xMKWkGnS VIjdc+I3neZjzsKjMYFCr3IQ9+o5L5s+WKWeWH2FAShRKaEKyese6KZd9c9Dt9jKc6oi5E0CW vLM2S0ojWIa+HHhcz4iH1UZrKHVictKb0eVXP4QEAMyaSm66dSKk3TnPTosqyD5nd7lylr3G4 lCc1Zi5nLtic1+OkN+LLu2ZblHzQDKc9cbaV5jcS0ZIxKk3TY0rJtJhmggN2jeSUoKgHV8r3e NBPn43iimlXP6ulwFTWxR0t6g2XZlMQ3XwdKR/NPaewMYBrkx9I/SynlUQ4L8maKPhSjIdzd8 mpT85C+gg6fKCMjusQv6Yti0ZS/yeiXKmjY6orhtoTXSpeujgR8+6YCTB2nsMv1qIg844OhPo K0yP2baR/5BJYpwRNqqXc5AGvIC6M0tR09dxVRsPiYm5pbwPgmGlRGWQiKVEQwMxRyZYe2vQk Rlxs8EvnuuJqIHpDVRsuoDW7Qx+RdVJ60piDCwXmypjrgyTsVe+00F+yUS9/s6Gg49szvzAWe vENIsIqUtX22jrrh9PjzKxfL6DgGIIE3PmySEcj/8AFbquI/u5qpnCFmZ9Xp6isrBF69OOzN5 AVhn2OYWAWHUZ1pE47mC3TkOqDHKWYSgoZVSaaKps1B+r/lFLHg4HI8kqbGYuSlpnfNH5l3Vc LelF4k7LcI+cayjXkc2+8pQCoKoFY7zEcyQXppwTTqOarAIYcSufpBN4+fOaTis7Vd4Tj7LIl 1iuQZGUUpQFa0N51PJ+fSI8CsfM= Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This fixes compress with colo. Signed-off-by: Lukas Straub --- migration/migration.c | 9 +++++++++ migration/ram.c | 5 ----- 2 files changed, 9 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/migration/migration.c b/migration/migration.c index ae2025d9d8..cbdc10b840 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" @@ -316,6 +317,7 @@ void migration_incoming_state_destroy(void) struct MigrationIncomingState *mis = migration_incoming_get_current(); multifd_load_cleanup(); + compress_threads_load_cleanup(); if (mis->to_src_file) { /* Tell source that we are done */ @@ -598,6 +600,12 @@ process_incoming_migration_co(void *opaque) Error *local_err = NULL; 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 = qemu_coroutine_self(); mis->largest_page_size = qemu_ram_pagesize_largest(); postcopy_state_set(POSTCOPY_INCOMING_NONE); @@ -663,6 +671,7 @@ fail: qemu_fclose(mis->from_src_file); multifd_load_cleanup(); + compress_threads_load_cleanup(); exit(EXIT_FAILURE); } diff --git a/migration/ram.c b/migration/ram.c index 9072d70f7c..e9a295fab9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3559,10 +3559,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(); @@ -3578,7 +3574,6 @@ static int ram_load_cleanup(void *opaque) } xbzrle_load_cleanup(); - compress_threads_load_cleanup(); RAMBLOCK_FOREACH_NOT_IGNORED(rb) { g_free(rb->receivedmap);