From nobody Wed Nov 5 08:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533633726885830.2021392718242; Tue, 7 Aug 2018 02:22:06 -0700 (PDT) Received: from localhost ([::1]:38063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmyBp-0002RD-Pd for importer@patchew.org; Tue, 07 Aug 2018 05:22:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmy32-0003Hc-V3 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmy31-00059s-Mn for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:13:00 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:39881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmy31-00059Y-F6 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 05:12:59 -0400 Received: by mail-pl0-x244.google.com with SMTP id w14-v6so1273406plp.6 for ; Tue, 07 Aug 2018 02:12:59 -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) 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=X4GKuuq9QYFWpy+sDDjM8aBDlB2bbevaJUTy91a713b5XVKuwNpaT45bCKQ7dyoVGR numJRC1jlsysrhnvtC0a0Z4e7qYR+8INP71hDXLoZq6HkmdxMpAiQPnT0PofYaP7fsnM kllQUtUAB3EAjCy3IDtMrCBhNa459RHrE3d9G1Z5ebKFDEi8AQCXibEe5p/q1rxlqllp RmHzNPHv3U57ep6bBPwjbMeSnU3ic261zAuvUjNmfx1moqq5xElPnKaFtL+XykYNJlOr +fEmMVIglUmi4y1Wa2n2SPhOl05Bke9BNnVToGOeQxklRaB/IgBxbDnxnUt7oFa7cz/0 TGlg== X-Gm-Message-State: AOUpUlGlTCBRjW+9o1gxFeV+sUqdFjj4ivCYlDKQ3LC6K9tUOMW62MBB 0NgxsaJ7wD0vXy09xm4NATQwQXZF 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) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com 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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH v3 06/10] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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)) =3D= =3D NULL) #define QSIMPLEQ_EMPTY(head) ((head)->sqh_first =3D=3D 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 =3D NULL; =20 + 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 =3D --=20 2.14.4