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: 924920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JUqtzMwo"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40zr7z3pVWz9ryk for ; Mon, 4 Jun 2018 20:02:06 +1000 (AEST) Received: from localhost ([::1]:38639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmJQ-0003Yn-4z for incoming@patchwork.ozlabs.org; Mon, 04 Jun 2018 06:02:04 -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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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);