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: 10534253 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 C0AF7600F4 for ; Thu, 19 Jul 2018 12:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF918293A6 for ; Thu, 19 Jul 2018 12:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3DA1294BB; Thu, 19 Jul 2018 12:16:07 +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 568AB293A6 for ; Thu, 19 Jul 2018 12:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731569AbeGSM66 (ORCPT ); Thu, 19 Jul 2018 08:58:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36177 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731538AbeGSM66 (ORCPT ); Thu, 19 Jul 2018 08:58:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id s7-v6so152542pgv.3 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=LmAfEUlJJ8njkeVrDnJeFw+X+umzAM96FbQK6qxca5PxSWxjfd/EziSud9SVU3F+U2 E8VcPlCMb3e9uOCD2p6nhQKh26Aj0g8qG0B243te3w4fzMcPoC/XTVNZ77dk2aQ0ZPfj f3BRADQkTPzmaMiLF8XVEeG4bpes1Rcz68Ww5j/a+i/FeFMZepYFcOlGrMnTTtYWvB4E W5GkF/8iqBvpbSfEZewJDc7rIQhQqXk6ocaGEoBYKCZ4PiElT1ndI/2dc8nyuzyNtmW/ Q6N7rZqoSfmny/VAVrUQ/dA8IzcWwCJjVgeaJ7M74fkhmKCMyKNXpKEaUwZLCLi4YnqG y0Zw== X-Gm-Message-State: AOUpUlEhv6Oke2Va0PR/kZf7LkJvULfJXZ79vt95VhovuZewpZoQeBtV 9MWVflFgeI0FSCW7bqwKbeE= 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 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 v2 7/8] migration: hold the lock only if it is really needed 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> 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 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 =