From patchwork Mon Jun 4 09:55:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10446167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1D7C60284 for ; Mon, 4 Jun 2018 09:56:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D218A28BC6 for ; Mon, 4 Jun 2018 09:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6D5328BD0; Mon, 4 Jun 2018 09:56:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65D9728BC6 for ; Mon, 4 Jun 2018 09:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752379AbeFDJ4J (ORCPT ); Mon, 4 Jun 2018 05:56:09 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:38969 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbeFDJ4H (ORCPT ); Mon, 4 Jun 2018 05:56:07 -0400 Received: by mail-pg0-f45.google.com with SMTP id w12-v6so13037292pgc.6 for ; Mon, 04 Jun 2018 02:56:07 -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=LtVm4N6tUczhOE0VdqwcQsfHbL9agTZqXb5Gl7wwE3S3U6I22HzA43zwZgYxJ3P2vM LBpTKvT25qZA/dxQ3AOdaxj6O+CDv/mr1m2lxeNJ97zLGnNVrm1C0+Q8lHH/e9/CnecJ l7ELV49IKK8cFJn8gd/ONLu6Hw4dkdujtfMolBLba8fwjtZE5mpPy1KPwU0EzezKe+es NM2CJ5yGCwuPQecRrVnyLBfvODm49aTYfX5e5lmd5Z8cLag90qTNjRGxLdrjSfUZ8CMs gt/arQ8/2sUSU7o0qxIowUZqDU939FXoTY8gqQczuGnqgJPkVLiXGP4/6Mb6PjeV0TPr 9dZQ== X-Gm-Message-State: ALKqPwekCPsirdylTVQThoP8BZjRvRJWSuPqRXfNuqXbCUBIO/Wp4Exj WHgtpLbpkkDeM+3jFGTR9xE= 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) 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) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, jiang.biao2@zte.com.cn, wei.w.wang@intel.com, Xiao Guangrong Subject: [PATCH 01/12] migration: do not wait if no free thread 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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, thread_count = migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); - while (true) { - for (idx = 0; idx < thread_count; idx++) { - if (comp_param[idx].done) { - comp_param[idx].done = false; - bytes_xmit = 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 = 1; - ram_counters.normal++; - ram_counters.transferred += bytes_xmit; - break; - } - } - if (pages > 0) { + for (idx = 0; idx < thread_count; idx++) { + if (comp_param[idx].done) { + comp_param[idx].done = false; + bytes_xmit = 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 = 1; + ram_counters.normal++; + ram_counters.transferred += 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, PageSearchStatus *pss, * CPU resource. */ if (block == rs->last_sent_block && save_page_use_compression(rs)) { - return compress_page_with_multi_thread(rs, block, offset); + res = compress_page_with_multi_thread(rs, block, offset); + if (res > 0) { + return res; + } } return ram_save_page(rs, pss, last_stage);