From patchwork Mon Jun 4 09:55:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 924922 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="UCEiPKwP"; 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 40zr8c44GJz9rxs for ; Mon, 4 Jun 2018 20:02:40 +1000 (AEST) Received: from localhost ([::1]:38642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmJy-00043P-69 for incoming@patchwork.ozlabs.org; Mon, 04 Jun 2018 06:02:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmDz-0007g9-LS for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPmDy-0001Dd-RQ for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:27 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:33370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPmDy-0001DS-Ks for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:26 -0400 Received: by mail-pl0-x243.google.com with SMTP id n10-v6so19388158plp.0 for ; Mon, 04 Jun 2018 02:56:26 -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=GWPTn5Zn3pO7uqSBhl34CPShONRtaV8vyCn3yu3F3wo=; b=UCEiPKwPHBRiZrCyUE5lqIJFVq3v6KtpWZ1fTRK1jUwVjsChCUjmIrhlyhKUW3KwRV SU4nzHb1O46acXr+jV7QFcQ5NZVeDozFaASfhHm4FtsIl3gPYH4AQRJfH0L79NcaA8by 7dKvMevc+YqHuLYmcIQzfdziVivFq8rocZb2G2hWc/vFnmpfcEujevOdLuP6FJr/DMHn hMKaQt89PZK/mfr6yu9BXELYlCnFU8GjA2DqkDTwegtd4ZY+Up1H4hK0+oN9NPu6NKLB b+6XsvtZEyT+fgeQWxXuDmE8UXlOLN8xWyaacbWjHs41IU4z+sqIAZtmJf3fAFQIpWlj 2FdA== 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=GWPTn5Zn3pO7uqSBhl34CPShONRtaV8vyCn3yu3F3wo=; b=dZcvbKzsT7pGfEIWrj/6Wr4tHwqgIvOQ9kbbtf4a1uu7yeugIALHIk/sfuLJUGPxF7 wL8YFlVJyssW2ZAoN4Ogoi+j5n/8RXUiAOUq8n2bUYLXVR4Kdil3YesDkI8LBR62YBu0 0Cho5+IpFr0i1bTIJjt5kaW5dpYwW0KHR9yLREIou644i+mMJM6hQkMeyds03UymLNVg uikcixGsog+++PiXly7r4ZLI3gm3LifvXtlmn4uOa1dGLJ7Pm17OZU7pMK6lChLpR+sw tErF51YtPQ9NbxOTmd5wuR0Tj8Y7b6PSONG8pOeTK63vPGDVYmhKH9HiG8ZJ49fXVdeP hFMg== X-Gm-Message-State: APt69E2PjFb36mPrP+/QHqkncpzBCcGhXjArPDx4XglIC/1c9B918JAx PZuRQZh7imXXiy0ifrztm6Q= X-Google-Smtp-Source: ADUXVKJFXAZ8Plutfh9jyIaaSIo+osOppw7aqNIXVlKj1sL/YvQ7mGWwHd9klqk+CMQ+ARJzjR+3mg== X-Received: by 2002:a17:902:b582:: with SMTP id a2-v6mr9032712pls.335.1528106185831; Mon, 04 Jun 2018 02:56:25 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 02:56:25 -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:15 +0800 Message-Id: <20180604095520.8563-8-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:c01::243 Subject: [Qemu-devel] [PATCH 07/12] 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 Signed-off-by: Xiao Guangrong Reviewed-by: Dr. David Alan Gilbert --- 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 15b20d3f70..f9a8646520 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1550,6 +1550,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 =