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: 10446185 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 97E46603D7 for ; Mon, 4 Jun 2018 09:56:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A39328BC6 for ; Mon, 4 Jun 2018 09:56:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F13728BD9; Mon, 4 Jun 2018 09:56:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2935728BC6 for ; Mon, 4 Jun 2018 09:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbeFDJ4j (ORCPT ); Mon, 4 Jun 2018 05:56:39 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35387 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752292AbeFDJ40 (ORCPT ); Mon, 4 Jun 2018 05:56:26 -0400 Received: by mail-pl0-f67.google.com with SMTP id i5-v6so19392162plt.2 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=WljNArzVbzxf96lR2Nvry2Ft3+dR6+j2to62Zdh4OYTk8o1yHVipm+n28Ew4L/jtAl luBHhZaq+rhM+hOAC5hCQw538TWx9nVk943bNI424liA2pKJ0p26A74IEoCinISru/EX Yl0aV04JwD8WMomPi1csDvvElfhpMCTGQbyzzkUz5CNWmDRVXrkuLo4oMLm9yE5Sxbcq 4Vr+vj4k71CQMud9r3Lo4wm7oNKDlDTMwj8hAxn+inwfYdvPI/vXxBhK3LPTWC58em69 k52YoaQXrMaTr9bMEN/mD5OGu9Q0ti1RfySkWo3cvM6dH8UMIsy17G67lp4i/fgK1baA cktg== X-Gm-Message-State: APt69E0vr87BK/Pm62RPkK55L/9fANd6Mbvwq7nd8be70B1fJQLsFmE6 VrmLjMYcWWTp/2mBPllBjVk= 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, jiang.biao2@zte.com.cn, wei.w.wang@intel.com, Xiao Guangrong Subject: [PATCH 07/12] migration: hold the lock only if it is really needed 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 =