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: 10534277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E67F601D2 for ; Thu, 19 Jul 2018 12:25:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E84F2958D for ; Thu, 19 Jul 2018 12:25:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FE04295C2; Thu, 19 Jul 2018 12:25:18 +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 281782958D for ; Thu, 19 Jul 2018 12:25:18 +0000 (UTC) Received: from localhost ([::1]:42121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg7zh-00012r-ED for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Jul 2018 08:25:17 -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+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 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 =