Received: by 2002:a17:906:fc07:b0:9bd:85f7:2662 with SMTP id ov7csp2038681ejb; Tue, 24 Oct 2023 06:15:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNiFPD3PUVdMaxdlgSSH50rXAtc/bmV0BeumbTjYPOQLc+Yh4HwcyF5zEVPjJ8bqZW2B0D X-Received: by 2002:a05:6102:51:b0:450:c666:fe14 with SMTP id k17-20020a056102005100b00450c666fe14mr10593492vsp.30.1698153326341; Tue, 24 Oct 2023 06:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698153326; cv=none; d=google.com; s=arc-20160816; b=vsJcv74DydNVmAiz0CUDUo7lSGWh9kycskdPsUqDqabUSVk+PrzIL8u9R56wqTQqgl 88G0Kr+XEYGQY04pQlwFw/BZqoEKuHn0vKADxBIthLFcgyS6SPv5L3Fx2szKZ76leBXT Yv38iIJsowdAZYq7z/yArK9l7p+Y/bgmC0ib7ZoMHPRLokP+MfLqhioJrG8HS8rBA/Df V9Bl6fHxWqJJMFLnHUEve/G9j1YzYpN4Rc4Bf6B8RPKsIahubCnOvhgDqkaYfkyRquDO wDJLMr4BVuLttREZ4LIZqL8fanAk6FKs2fwZO0395Ss7IO6gV3f2LTL4YMxYfDYXGmkv dyyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=v07XEObK+8HRkY6PIJKRF8OCoGMMogRwRKEZtGkEDCc=; fh=0DRGwfQymzNSinv+CnmU35FvXClR1k5Tnpw/bIUVe6k=; b=fbV9OzWiWSzGtddYV349bBm3QTklhmnPmz8FCHUHtURExFdjdap4U3H+fup10TTQyK bmtzhvVSPkzjltGAuu1y+nAtLj8bCF9cxGlAPC2ZivaEcajZVbGeGHnx4IRpQfNTdxJC HMjL4/nydkCZy9C5yeVmjORVLrBb0aQ/4G/fEGYQrEi9avnLlcBca8jszn+hVdaU8T/K ywMOT3MwCb25mPLqi+psaHHC1MSS08EDDAnb/pX6wJGEk4olzgy6mWkjGheL4q3V4BUy XNqqS6zovJ/dFguGPRJlCbjJ5boRsr902JqeFZ5EEzIm51haCmEv8hOAE/cIn/I1N3H3 AzHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bCLaDOJ8; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v11-20020a056102302b00b00450a77583f2si899953vsa.126.2023.10.24.06.15.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2023 06:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bCLaDOJ8; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvHFG-0005xG-5c; Tue, 24 Oct 2023 09:14: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 1qvHF2-0005Eg-B7 for qemu-arm@nongnu.org; Tue, 24 Oct 2023 09:14:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvHF0-0001Gs-Bw for qemu-arm@nongnu.org; Tue, 24 Oct 2023 09:14:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698153277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v07XEObK+8HRkY6PIJKRF8OCoGMMogRwRKEZtGkEDCc=; b=bCLaDOJ846pc0RDTcMOHXi1E2DJueODLRciH5m98rLSAVqgE/ipoDfAYxuxAAQIvUQuPdN J8xtceKJgVcUp2gLsflgH+LiT7+Lrs9uQlK+Bw+aXdQdS0kAGkPD2TyU8ApC1QYPDfqjMI DEiTdl8aOBrBgUIvt7W3TNmYyr/pu5M= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-nZAzMYCaPfWnk0UUY_Q8AQ-1; Tue, 24 Oct 2023 09:14:29 -0400 X-MC-Unique: nZAzMYCaPfWnk0UUY_Q8AQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B0E983C1ACD6; Tue, 24 Oct 2023 13:14:27 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 653D31C060AE; Tue, 24 Oct 2023 13:14:21 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Eric Blake , Richard Henderson , Corey Minyard , Li Zhijian , Marcel Apfelbaum , Hanna Reitz , John Snow , David Gibson , Gerd Hoffmann , Stefan Hajnoczi , Halil Pasic , Peter Maydell , Corey Minyard , Mark Cave-Ayland , Kevin Wolf , qemu-s390x@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-arm@nongnu.org, libvir-list@redhat.com, Stefan Weil , Nicholas Piggin , Daniel Henrique Barboza , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Peter Xu , Leonardo Bras , Jason Wang , Fam Zheng , Christian Borntraeger , David Hildenbrand , Thomas Huth , Fabiano Rosas , Ilya Leoshkevich , Harsh Prateek Bora , Samuel Thibault , Eric Farman , Juan Quintela , Markus Armbruster , Stefan Berger , qemu-ppc@nongnu.org, "Michael S. Tsirkin" , qemu-block@nongnu.org, Lukas Straub Subject: [PULL 11/39] migration: Simplify compress_page_with_multithread() Date: Tue, 24 Oct 2023 15:12:37 +0200 Message-ID: <20231024131305.87468-12-quintela@redhat.com> In-Reply-To: <20231024131305.87468-1-quintela@redhat.com> References: <20231024131305.87468-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: +VuuTvPCW9lc Move the goto to a while true. Reviewed-by: Lukas Straub Reviewed-by: Fabiano Rosas Signed-off-by: Juan Quintela Message-ID: <20231019110724.15324-6-quintela@redhat.com> --- migration/ram-compress.c | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/migration/ram-compress.c b/migration/ram-compress.c index ef03d60a6d..a991b15b7a 100644 --- a/migration/ram-compress.c +++ b/migration/ram-compress.c @@ -271,35 +271,35 @@ bool compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset, thread_count = migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); -retry: - for (int i = 0; i < thread_count; i++) { - if (comp_param[i].done) { - CompressParam *param = &comp_param[i]; - 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); - qemu_cond_signal(¶m->cond); - qemu_mutex_unlock(¶m->mutex); + while (true) { + for (int i = 0; i < thread_count; i++) { + if (comp_param[i].done) { + CompressParam *param = &comp_param[i]; + 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); + + qemu_cond_signal(¶m->cond); + qemu_mutex_unlock(¶m->mutex); + qemu_mutex_unlock(&comp_done_lock); + return true; + } + } + if (!wait) { qemu_mutex_unlock(&comp_done_lock); - return true; + return false; } - } - - /* - * 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 (wait) { + /* + * wait for a free thread if the user specifies + * 'compress-wait-thread', otherwise we will post the page out + * in the main thread as normal page. + */ qemu_cond_wait(&comp_done_cond, &comp_done_lock); - goto retry; } - qemu_mutex_unlock(&comp_done_lock); - - return false; } /* return the size after decompression, or negative value on error */ -- 2.41.0