From patchwork Tue Aug 7 09:12:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 954425 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="D66JwiKx"; 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 41l8CF4J0cz9rxx for ; Tue, 7 Aug 2018 19:21:13 +1000 (AEST) Received: from localhost ([::1]:38057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmyAx-0001hI-7s for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2018 05:21:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy32-0003Hc-V3 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmy31-00059s-Mn for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:00 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:39881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmy31-00059Y-F6 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:12:59 -0400 Received: by mail-pl0-x244.google.com with SMTP id w14-v6so1273406plp.6 for ; Tue, 07 Aug 2018 02:12:59 -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=D66JwiKxPbOHM+l+HIaPUG71Jmp8lx7gbvddX/owjF9HDjU2CIv+UGoyG6D28C/jRp pupggEPtbKm6Ev5TQkNmeJhFJOebDl3wPA8G217S3KpHZkezNuz1YFcpg5cPZyc5p4Yg WrCNYWRSaA4LFU4vMrToZMdagSUFOkayuwX6ZdpLM/jDSVJDKDdapSVOTTvvElUPpzRt crI7IVy6UnsP08A3l5lLg//ZXmaVuu6gw3g7WFYQERKCKu2I3FQBoUKu8JY4F79RJfbc vc6FkfluxMiyKOK3ARokMnsVD9HBFPhQ8jRG1Yx4Y25hK9Z7CzNjXRyJzvwVJNPl8r7J CEiQ== 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=X4GKuuq9QYFWpy+sDDjM8aBDlB2bbevaJUTy91a713b5XVKuwNpaT45bCKQ7dyoVGR numJRC1jlsysrhnvtC0a0Z4e7qYR+8INP71hDXLoZq6HkmdxMpAiQPnT0PofYaP7fsnM kllQUtUAB3EAjCy3IDtMrCBhNa459RHrE3d9G1Z5ebKFDEi8AQCXibEe5p/q1rxlqllp RmHzNPHv3U57ep6bBPwjbMeSnU3ic261zAuvUjNmfx1moqq5xElPnKaFtL+XykYNJlOr +fEmMVIglUmi4y1Wa2n2SPhOl05Bke9BNnVToGOeQxklRaB/IgBxbDnxnUt7oFa7cz/0 TGlg== X-Gm-Message-State: AOUpUlGlTCBRjW+9o1gxFeV+sUqdFjj4ivCYlDKQ3LC6K9tUOMW62MBB 0NgxsaJ7wD0vXy09xm4NATQwQXZF X-Google-Smtp-Source: AAOMgpcYryFkcGrdLRww1vEazllSMKHCkLpyH2ua5ICy4PRTiTbWqnOkeNDdSsPK6AwwbD9OeTsQCg== X-Received: by 2002:a17:902:8d91:: with SMTP id v17-v6mr17339480plo.9.1533633178727; Tue, 07 Aug 2018 02:12:58 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id z4-v6sm2159645pfl.11.2018.08.07.02.12.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 02:12:58 -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, 7 Aug 2018 17:12:05 +0800 Message-Id: <20180807091209.13531-7-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180807091209.13531-1-xiaoguangrong@tencent.com> References: <20180807091209.13531-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH v3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 =