From patchwork Thu Jul 19 12:15:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 946243 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="fGm5D8VW"; 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 41WY9v5gcBz9s0n for ; Thu, 19 Jul 2018 22:24:51 +1000 (AEST) Received: from localhost ([::1]:42112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7zF-0008Fb-F0 for incoming@patchwork.ozlabs.org; Thu, 19 Jul 2018 08:24:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7qt-0002HV-UK for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg7qo-0005Yr-38 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:11 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:39245) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fg7qn-0005YM-RH for qemu-devel@nongnu.org; Thu, 19 Jul 2018 08:16:05 -0400 Received: by mail-pg1-x544.google.com with SMTP id g2-v6so3589063pgs.6 for ; Thu, 19 Jul 2018 05:16: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=wu/nz6fAWAIdK88AMQKiO9Vg+H9xHdRSbNE5knvlfxw=; b=fGm5D8VWrWiY4jf+i9Y7ttG1ZqYNfCUDlwbBpK+y4nAdSyMyVK/2O45qT5UR6pxi+F eTqjKV8KM1QERSTk0cW+vzlc7WQIplEOTGnQ+NsTmydMcr0EvjcI66Yktnu3AClFeEd3 4lFYjnbp3B127dx8PLhihg8bodczZx5eYW8MxZ7JFdeSC5C7f9DnoPlZbqztHm+UrI2b afTLxqCpkoW0vOv2LjhYuuWwvVTlORXNyR214VowCRyEb4dSWxgk76LR784l1/Y72uYv d8LzxsvlorU077Uy8oYsG/KeZ6gLSDsmwRPfpEjWp3Uf3q9hy3SXLzlpXYD6Kyzp5vzy QmXw== 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=wu/nz6fAWAIdK88AMQKiO9Vg+H9xHdRSbNE5knvlfxw=; b=r4NL7awyaojXs4VxUITmDbFCb1w1hyDnM0gMd8aYd4P0IAJ3SOwfjsV4MhfiIaNDJa C28tyZZFUVU98DK5MEt7gjIoNWp6s+f6xdz0wYBaH9QKtgZwGAruMlTj+xi5ulku/wSR 3pDJFSs27OkDXkHV1Zc7zmIJMPOt+HRuGwVM6b1rDgUawRereJa8V4aZdX1Ui8k2DHEd N3yKAABgC11h8dBtu5OckKoP1mAe0Fv0G+LfGVaQH5smi3rjVzcnxNzs9razossdRtN2 dHl0JxYvCQkn5W7LZcn2I4pYm6/DejT6QYz8BP8be5A+pAKAPmSqBWjzbbBmt0ydIygw Vutg== X-Gm-Message-State: AOUpUlFrrbT1x1uMjSoCsoAg77ozCbhVsbmp17QhDF98TjA4/RhUeUTU h5hWac1wR2udTOQvL4ngL6Q= X-Google-Smtp-Source: AAOMgpekGQoYhSNEF1w+YESeZ33Ab1TQ3nomKIYrZpUHxfDAVivj2JyBtVSieunVFGCtWi7u3FweNg== X-Received: by 2002:a63:ba10:: with SMTP id k16-v6mr9933706pgf.145.1532002565175; Thu, 19 Jul 2018 05:16:05 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id h190-v6sm21270456pge.85.2018.07.19.05.16.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 05:16: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: Thu, 19 Jul 2018 20:15:19 +0800 Message-Id: <20180719121520.30026-8-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180719121520.30026-1-xiaoguangrong@tencent.com> References: <20180719121520.30026-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::544 Subject: [Qemu-devel] [PATCH v2 7/8] 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 Signed-off-by: Xiao Guangrong Reviewed-by: Peter Xu --- 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 e1909502da..89305c7af5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2062,6 +2062,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 =