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: 10558423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2460713B4 for ; Tue, 7 Aug 2018 09:13:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144D226538 for ; Tue, 7 Aug 2018 09:13:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08BD727F3E; Tue, 7 Aug 2018 09:13:01 +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 A2CCF26538 for ; Tue, 7 Aug 2018 09:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733147AbeHGL0W (ORCPT ); Tue, 7 Aug 2018 07:26:22 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44646 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727533AbeHGL0V (ORCPT ); Tue, 7 Aug 2018 07:26:21 -0400 Received: by mail-pl0-f67.google.com with SMTP id ba4-v6so6852611plb.11 for ; Tue, 07 Aug 2018 02:12:58 -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=Uh5CtUtf2PBynnKqyjRYlpFAJ3bxUsbr0rpihC9QzHMRtKuRQCHy9LfUBpDOR9UPg6 CkUPqCtc7Z9qkYUGP6fiSrs1XVNzROAsx3SxpJo4SZQv0vbT3A4L4moTm+uinOkRR0X2 sW32K07PWOxP7pMKboj5HnYhdWHeyac4E+RhyQ391F/lpHL+s3RjIVYO8CDmLlb7j8f/ PD7UhiNOvFfGhBtAw4NWpnj/x1b0L0iXSG1e7EMKLGPdcgl+h0mUU2mDwhJA1B9I4T4Y l6uy/p40NyslJfGT+8VvyY5FwVjxILjOaAyMnK2ryKDGAJYW+s9lxGs46THNgd+jo+TH BkAg== X-Gm-Message-State: AOUpUlFnBBc1BelfEcPjvVaUDbh2U+XJgEd5y8JnoAVNn3LqmOmKy41W dqW88wPxoNsxgmt/gBs6C7o= 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn, eblake@redhat.com, Xiao Guangrong Subject: [PATCH v3 06/10] migration: hold the lock only if it is really needed 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> 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 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 =