From nobody Mon Nov 3 00:27:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528106616927485.3998379143111; Mon, 4 Jun 2018 03:03:36 -0700 (PDT) Received: from localhost ([::1]:38645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmKq-0004n9-JY for importer@patchew.org; Mon, 04 Jun 2018 06:03:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmDh-0007QU-RF for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPmDf-00014f-OZ for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:09 -0400 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]:32926) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPmDf-000140-IN for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:07 -0400 Received: by mail-pg0-x232.google.com with SMTP id e11-v6so5057011pgq.0 for ; Mon, 04 Jun 2018 02:56:07 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id h130-v6sm124502105pfc.98.2018.06.04.02.56.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 02:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4NIs+2JTEEmrVtAr14UHoODFpxYdQG+ZGBzKV/b+En0=; b=JUqtzMwoK8OIQ2zXjDjw/gPvSTBNR149j0HnxNt+n5NPU4X5qSPZBzJDOL0pm6F1Hn rWVrZnJgC9zcJzgBcIKNHq+qqpSCnnpeoBVoveag5EVhV0dVF9v2iSHiwffLm4BztQWM sLuv0abq7SaEzu/klW10T1kzyQBR1po8D4569rNwx9cxd2ZrRZEN9GOJAfDpHSc0SFcZ cVFDV9+br6l/qgRIS2/dDu0Zhr5Ge5BLCdq33HdAkMn4a62UwdZ5D/MXahsw7fxi8zUq MuiNj6LwHedeM8O29J9yfb36/IcTfbxYlW02JmAlVAxEeJRgaMg/mb2AJfO3ze2x26zk 6V1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4NIs+2JTEEmrVtAr14UHoODFpxYdQG+ZGBzKV/b+En0=; b=aiAfNPbnoVcOUgyOgCEYbwrA0Fv3BuBvu2/R/zOLxvzziIYZGVHGHDm2hcmFnW3jUr 0JIBHqDT40c2i/XASpqgMFHe4+x9zmeKBzZ48Cl3Tw+1WTnixVhc+SySL16/9C252W8f nzVUYYuN3HiEcgEXukj+aezQ/4kh4ZljqDqnD1xvwnfaJucx3dgLOM9CTUOtkAatx9v+ I+sSUh/dIlax9ydOnVZFJOZugM/pVUENS+4UUEos11KpkhwcB/opEQW2d5rHvRQFnF/5 CdCyrSh4QmWcAfqQnpwQvubRZXbqZtxJuDgiYbdKdAOcma7u4lXjVsue8aeFzYp3q6m3 1iYw== X-Gm-Message-State: ALKqPwdKs6IbqdB4DknHGrK0S//o69SjV7h5X8DzW7UZLCVN9iLSJcfN /980DdBFmeefPPMxaS91580= X-Google-Smtp-Source: ADUXVKJPcLauB3ICQHlHZSxFaoCbTBY4/cr8yMPCtbx/ih7x8HhRvWEKp4kuPrf1bi7AxHKG20kAHw== X-Received: by 2002:a63:931c:: with SMTP id b28-v6mr16451502pge.167.1528106166667; Mon, 04 Jun 2018 02:56:06 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Mon, 4 Jun 2018 17:55:09 +0800 Message-Id: <20180604095520.8563-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180604095520.8563-1-xiaoguangrong@tencent.com> References: <20180604095520.8563-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::232 Subject: [Qemu-devel] [PATCH 01/12] migration: do not wait if no free thread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Guangrong Instead of putting the main thread to sleep state to wait for free compression thread, we can directly post it out as normal page that reduces the latency and uses CPUs more efficiently Signed-off-by: Xiao Guangrong --- migration/ram.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 5bcbf7a9f9..0caf32ab0a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1423,25 +1423,18 @@ static int compress_page_with_multi_thread(RAMState= *rs, RAMBlock *block, =20 thread_count =3D migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); - while (true) { - for (idx =3D 0; idx < thread_count; idx++) { - if (comp_param[idx].done) { - comp_param[idx].done =3D false; - bytes_xmit =3D qemu_put_qemu_file(rs->f, comp_param[idx].f= ile); - 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); - pages =3D 1; - ram_counters.normal++; - ram_counters.transferred +=3D bytes_xmit; - break; - } - } - if (pages > 0) { + for (idx =3D 0; idx < thread_count; idx++) { + if (comp_param[idx].done) { + comp_param[idx].done =3D false; + bytes_xmit =3D qemu_put_qemu_file(rs->f, 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); + pages =3D 1; + ram_counters.normal++; + ram_counters.transferred +=3D bytes_xmit; break; - } else { - qemu_cond_wait(&comp_done_cond, &comp_done_lock); } } qemu_mutex_unlock(&comp_done_lock); @@ -1755,7 +1748,10 @@ static int ram_save_target_page(RAMState *rs, PageSe= archStatus *pss, * CPU resource. */ if (block =3D=3D rs->last_sent_block && save_page_use_compression(rs))= { - return compress_page_with_multi_thread(rs, block, offset); + res =3D compress_page_with_multi_thread(rs, block, offset); + if (res > 0) { + return res; + } } =20 return ram_save_page(rs, pss, last_stage); --=20 2.14.4