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; } }