From patchwork Tue Aug 21 08:10:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10571205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8BDC1579 for ; Tue, 21 Aug 2018 08:15:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB1E527F91 for ; Tue, 21 Aug 2018 08:15:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDC6029B47; Tue, 21 Aug 2018 08:15:49 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 632C227F91 for ; Tue, 21 Aug 2018 08:15:49 +0000 (UTC) Received: from localhost ([::1]:51490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs1pM-0000GT-CP for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Aug 2018 04:15:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs1kr-0003yY-4G for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:11:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fs1kn-0004fy-Vr for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:11:09 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:33989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fs1kn-0004ff-N4 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 04:11:05 -0400 Received: by mail-pg1-x543.google.com with SMTP id y5-v6so8105803pgv.1 for ; Tue, 21 Aug 2018 01:11:05 -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=9aVx/9MXIX8chFdQ0nNGdumPNvIXauKoEQdqfl233Qw=; b=lsFpKXqjMyEpvQwXohEcz/fgRiYW2aH4F7zLB2m648UhLgt5HfsF6+TNf5zWLZu6XL BKF1llJ0ul7G2Kxosfq7QoG6kpd3HhTDZ7fPbnIq5gE1uLaRwA/SssljTIZ5YRhICrlX 6F5kPUuREaWWg+e48GcrRNdgbJ5Pom7o+pUo879KybTfdUE64gfYtFawMyO7wdDz9drw 0ITF/JpeOWzqlBOU3hnHxacZltERWLVxcx+FtqT0Od4kTlRddyN5i8QOr0ndDg2ExEps L+0/oYYfVTId7UOns/lTNbjzLHlgIrntI/aK7wpb4+lY2u6vTqz+a1bTkF8LCHnVxaqy NH7Q== 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=9aVx/9MXIX8chFdQ0nNGdumPNvIXauKoEQdqfl233Qw=; b=DkE54C7M6dwMU0W9Q9hRbWk2+EuomEn119wgrzFwVD+Za1BJklamyLP2dbBW0Mih/T BvppjvvHl7jU4C72StgvJA8lcV81mcxSl3By8ThuB4+bNBAHUxjrSIjhlijKwIBvWBsg nxFhxEO9R1bFMKrQD07Lg5x4RE0oSeFBerOzYGibXllXxYTq+DRBHYTOwD6R/JLQxJVZ GZq9lUAIlVZucJUdeXVo4AfRI/+TYyBJ1CiTCWvcKZnNamh+Jrg0UQ/HxJi39oJYgR4g kkwFdzK9OhCQswBYbf7vx5P2BIPWJZtRNX4zTDuo/NTSW++DiscTsiDf94u5Ngg8/+zV dKwQ== X-Gm-Message-State: AOUpUlGEcQVVw3eF0wrkm+fcel5IszK4dkqb8U5XPcl/ipUaBdmsh38e KnMl+yalNaVUeQKW4TSchIKV1l5t X-Google-Smtp-Source: AA+uWPyqb9BWmUu/C3oPARoLUwDy7/ggJLgff7L+b5HrrVQ2PDPpwH4iIkHDnC+xPdbIetINUcTenQ== X-Received: by 2002:a63:de10:: with SMTP id f16-v6mr45715875pgg.97.1534839064981; Tue, 21 Aug 2018 01:11:04 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id r64-v6sm20644023pfk.157.2018.08.21.01.11.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Aug 2018 01:11:04 -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: Tue, 21 Aug 2018 16:10:25 +0800 Message-Id: <20180821081029.26121-7-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180821081029.26121-1-xiaoguangrong@tencent.com> References: <20180821081029.26121-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v4 06/10] migration: hold the lock only if it is really needed 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong Try to hold src_page_req_mutex only if the queue is not empty Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Signed-off-by: Xiao Guangrong Reviewed-by: Juan Quintela --- include/qemu/queue.h | 1 + migration/ram.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index 59fd1203a1..ac418efc43 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -341,6 +341,7 @@ struct { \ /* * Simple queue access methods. */ +#define QSIMPLEQ_EMPTY_ATOMIC(head) (atomic_read(&((head)->sqh_first)) == NULL) #define QSIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL) #define QSIMPLEQ_FIRST(head) ((head)->sqh_first) #define QSIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) diff --git a/migration/ram.c b/migration/ram.c index d804d01aae..99ecf9b315 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2026,6 +2026,10 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset) { RAMBlock *block = NULL; + if (QSIMPLEQ_EMPTY_ATOMIC(&rs->src_page_requests)) { + return NULL; + } + qemu_mutex_lock(&rs->src_page_req_mutex); if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) { struct RAMSrcPageRequest *entry =