From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824045; cv=none; d=zohomail.com; s=zohoarc; b=JOFE2QvH2mUqMspKDJs9qtnBMecnl0/ULTpqOEP9z9hHxCq9U3t9mXmctIgPrP7CukeAIspUrwtwfYTutFhcyV6jQxjBu2oKPCF5tCgHWC8ZrxUPjErx618/JCewac9ggSR0LQ+XeqRU8LGwZ24odiomCtRBnCVpsIbmjG0jJ4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824045; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EeJM+ShIS0TMolEwKNgTvE0T6ihxo6U4DD+hKUlZmKc=; b=nf+yceMPeInRwPOMpNIbNiyCZHP+GClKELHTVAw2KldZR74rS/iqRgcnNabt6/mCwBEfYC/5tyo6rVUfTmDOcyJ6yTnyuh7IgvdJU0/aRM5XZNR3aQroy3M6WbQjJIoo/7W4peMLOfs5n6cs6B4Km/mznAY13rBRekFfYtGUMjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824045892992.0787336938915; Fri, 13 Jun 2025 07:14:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59H-0003yu-SC; Fri, 13 Jun 2025 10:12:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ599-0003sw-3d for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002Jw-Nz for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:42 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-viFtTmpMPeiyjexH-B5zDA-1; Fri, 13 Jun 2025 10:12:34 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4a58cd9b142so38804421cf.0 for ; Fri, 13 Jun 2025 07:12:34 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EeJM+ShIS0TMolEwKNgTvE0T6ihxo6U4DD+hKUlZmKc=; b=g+ZH2WZLFYuMggC3WEVsfTEfveeKbN+hECxtcawBF8P7FnlRKvJs++GaXMw6HvXzCuEF5H bTr8YwDt3ojbDxFigesx9V0EwgpKfsTagYiizpRJmIlUpnZybnujz2r9zY6rIUO6GOgYvY 0UPssbbCosXnmLqs1PYd/rHQx1yw0mE= X-MC-Unique: viFtTmpMPeiyjexH-B5zDA-1 X-Mimecast-MFC-AGG-ID: viFtTmpMPeiyjexH-B5zDA_1749823954 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823953; x=1750428753; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EeJM+ShIS0TMolEwKNgTvE0T6ihxo6U4DD+hKUlZmKc=; b=QWKp8NhKfFySGph0Ngua7EDpSf5vyv9+ufcd4RFpw92cINm4SLOkT4lKrWcO4bHm0H 0d8cRpqZFSUa5XovcY9QRd75S35tAuQlXfIxxDf+WKJg/Rvf6URMiULsmPePscCVDKz8 sUQuwmunU8SYc+TNnFwcNpBDl6sb0vfgw77ME03cgS44DyQX8CMvd2u7Y3NK8HLui00W 2+FKBW3LujKprEfeJ7SIRMwBdefpRoH6NbCCJLtqZfortw/XJtO3QI1dB4EHv7PcIDM1 9exmY9XDkp103DDcBDx3mQCWfY8OQieT9ki/cy/miPdixjMO01eWbL7WOLcZdoNx8PrU T/Og== X-Gm-Message-State: AOJu0YyDtxCINU7Oa833IycA6SfdXnyML0TxnW1EWIMZmWpM33Us8ao9 gtPDoYFQWIjePwfFkFpuXX22DWVSVc24LSfrsPUDR+rXAu2S65i+PUocZ0Zhxi+lqNOiqiNAv8I 7ilF8kX7eDMHeW+Mw+T2XyYLrlTSrtxEcJxg7qQJxOZrgdGuZCtu7XGO8g1fqHg0rUNHzilPPfd KLv1se7uZwnxEi9fVSL4G62EHAG7/OYVUULaeuJA== X-Gm-Gg: ASbGncvDXayh3lLYbldBQkT8hVZr7GLlh2gO6LivWnD0EHvQnVFzYxgIO6SdcWLjsCz e2rp8DkuhKhivmbz5I1mmhP5rdk3YX7tvXHsr6NUALrcq7+rT9vi18Y2g3kqaNraHr7nmlinx/+ cCFCpUCm7i8P13xMFSA8Vv188kNNmgRZqOk4B7bcI2WjYZ92/RYJufeEqFelf772zcmgEPYB4S1 1U1+zku+LEsyiSMyiGbmH2f/vldI7U/64ZEXRbq8iq0LRmHD2XRxQLfTBFZAoV3ObqGePVr1fqF DGBF+qtqlWk= X-Received: by 2002:a05:622a:1f1a:b0:4a4:40a5:f789 with SMTP id d75a77b69052e-4a72fe5b363mr39878521cf.9.1749823953427; Fri, 13 Jun 2025 07:12:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEl6RIW8wR3NoPg/iqr74ECaHamdyhKHALQCdE37d/SZZ+TMKk1ufUGgq8slysL/5vDDWLWkg== X-Received: by 2002:a05:622a:1f08:b0:4a4:327f:1d0d with SMTP id d75a77b69052e-4a72ff366e3mr57631591cf.30.1749823941582; Fri, 13 Jun 2025 07:12:21 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 01/14] migration: Add option to set postcopy-blocktime Date: Fri, 13 Jun 2025 10:12:04 -0400 Message-ID: <20250613141217.474825-2-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824046332116600 Content-Type: text/plain; charset="utf-8" Add a global property to allow enabling postcopy-blocktime feature. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/options.c b/migration/options.c index 162c72cda4..4e923a2e07 100644 --- a/migration/options.c +++ b/migration/options.c @@ -187,6 +187,8 @@ const Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-postcopy-ram", MIGRATION_CAPABILITY_POSTCOPY_RA= M), DEFINE_PROP_MIG_CAP("x-postcopy-preempt", MIGRATION_CAPABILITY_POSTCOPY_PREEMPT), + DEFINE_PROP_MIG_CAP("postcopy-blocktime", + MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME), DEFINE_PROP_MIG_CAP("x-colo", MIGRATION_CAPABILITY_X_COLO), DEFINE_PROP_MIG_CAP("x-release-ram", MIGRATION_CAPABILITY_RELEASE_RAM), DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824048; cv=none; d=zohomail.com; s=zohoarc; b=gfYXVzkE/F9manjhY2dR7m8k9h1WSIryJO28nbvA0JC8lZiWmryGG3KiTAp5bxu0RKNzfRztomHyPFq1pueZ53/T4l4ct/6OfR+pDzNCi29YNqPudap756jJrNQJWznebqCnt5VAJlYvrihc9vjdvEi/i9bQE6uL/XI6er83KhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824048; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0Az667joB4gI82vBdp1u3ODjK+SK+os4hYO97NJz8d8=; b=Bf6d/HbIPuWRPt8NiTyOva6UjM2+il4VCCw0kfd8E2YDOAar7fH09ihW9uhR99cYb5eKqaeJIdfaIbX0jtrhjU8A5a4qlLA1AoHthA08GnqKn9Dpph8Z6pgcrTcGIuYfQsmLbTpagaDzHfoVUe8se6eCdZA29KFdJOI7ErjI/eE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824048591524.245861893804; Fri, 13 Jun 2025 07:14:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59J-0003zu-Cn; Fri, 13 Jun 2025 10:12:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003vk-NX for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002J0-NW for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:43 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-obcCNvy0OGyNCUTCZAIysA-1; Fri, 13 Jun 2025 10:12:24 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4a587a96f0aso58798251cf.3 for ; Fri, 13 Jun 2025 07:12:24 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Az667joB4gI82vBdp1u3ODjK+SK+os4hYO97NJz8d8=; b=CAVt8Smc5wuR2Zq/eaf5sKAuL5Lqym8U4OXusqFIMi/Vgt5s0qXiT2hFtvFIYiwqwBM6sX kEwZfHFql8hIEKq18DaqWSkukaQDf7foMuujG/0bgqqNmnZnA9yLsRR5Psm53HtVv8NkR2 u5GoJ7wK/rCNy75IsaBdsLF0iAGZAsI= X-MC-Unique: obcCNvy0OGyNCUTCZAIysA-1 X-Mimecast-MFC-AGG-ID: obcCNvy0OGyNCUTCZAIysA_1749823944 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823944; x=1750428744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Az667joB4gI82vBdp1u3ODjK+SK+os4hYO97NJz8d8=; b=LhA8AlO+l5l/Ebvi9y2Zmmlza4S1Mp7rM+a+2Hg+wa1tQD2R8Syrrxgjw4EM07eLU/ PGfekzpeFk8UTLi5W5jhB+9TfB3d01AN3AcsSOlXFKnycqolk8xm7t+3sEazvZqDBOTF RydXgFz6u+AvrViq0crWAq4giyHzmYxerXiLP9nWbal8PG9HutvPYimF3R4DriAELoBY IBvxP83P/RPjBRqod97K7yE3kyRhsbtIs7ofQORtFJOyKM4QpS9/dki1bmN+K5nvilOT yZi+Ff0wz7OEQzsuDy3gnjeZ+hgfB9lNiApwmJ8p36vkestU3zshM4FJNvkufYikjzL5 umvg== X-Gm-Message-State: AOJu0YxNNoqHJiye0kN+cqTfPs4ocsIznA8ANQ+HY/lV9GD0qX7dJoO5 WbQStPuLOxdd6tZkQGTA5hy0kmNQtTzlEWSTMF5N9+Hd5waWpHtgsgi7IRzxQUUss+YS9Cq1Pf2 oiNCud+o9v6ggYIfRZanTTnuYELRftsWRtGN0XJpDsyBWuNZ/JD9L+k1GEQBZPGudJ1al7qitHn xDu+xKjakTjZpBJYxsIHZbr/WU2wV48EmBpStdvw== X-Gm-Gg: ASbGncvy+7STiD3qBrxTfvmhLQ/gwWiC+Mu0m3I6l1a4hBDgnuruSO6Q6XdV6yb5DBC T3o1feNaG1JoDeJONQl2HhLIQW5V1/TQkFmqAGIelwfbUsU7lD1761d1bXD4IZlKxbDXrly78A3 58B7TmM8wVIkJzpj9s5gIoYKJkTryNWxwaw01U4xBhnWOSQJi/uTtsKIGqFbDEO7xvOSscrFG4g 3gsxuh+RNpuhqr7p8A9AB/V/gA8p1hzrTPf9iY6pKTK298aF0QnYGIQHxSvFWVDDp1bAnxPOLcN FhzTusvjKmE= X-Received: by 2002:a05:622a:191d:b0:4a5:aa42:49e9 with SMTP id d75a77b69052e-4a72fe9f8fbmr34453891cf.9.1749823943518; Fri, 13 Jun 2025 07:12:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDaWfgk1OhjD9d6TgsebZpLyZRctw5Vf1Fu9fHwjVu+hqh8vrKzCeXxPv6NYXFQSQHZglnLw== X-Received: by 2002:a05:622a:191d:b0:4a5:aa42:49e9 with SMTP id d75a77b69052e-4a72fe9f8fbmr34453371cf.9.1749823942687; Fri, 13 Jun 2025 07:12:22 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 02/14] migration/postcopy: Push blocktime start/end into page req mutex Date: Fri, 13 Jun 2025 10:12:05 -0400 Message-ID: <20250613141217.474825-3-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824050785116600 Content-Type: text/plain; charset="utf-8" The postcopy blocktime feature was tricky that it used quite some atomic operations over quite a few arrays and vars, without explaining how that would be thread safe. The thread safety here is about concurrency between the fault thread and the fault resolution threads, possible to access the same chunk of data. All these atomic ops can be expensive too before knowing clearly how it works. OTOH, postcopy has one page_request_mutex used to serialize the received bitmap updates. So far it's ok - we don't yet have a lot of threads contending the lock. It might change after multifd will be supported, but that's a separate story. What is important is, with that mutex, it's pretty lightweight to move all the blocktime maintenance into the mutex critical section. It's because the blocktime layer is lightweighted: almost "remember which vcpu faulted on which address", and "ok we get some fault resolved, calculate how long it takes". It's also an optional feature for now (but I have thought of changing that, maybe in the future). Let's push the blocktime layer into the mutex, so that it's always thread-safe even without any atomic ops. To achieve that, I'll need to add a tid parameter on fault path so that it'll start to pass the faulted thread ID into deeper the stack, but not too deep. When at it, add a comment for the shared fault handler (for example, vhost-user devices running with postcopy), to mention a TODO. One reason it might not be trivial is that vhost-user's userfaultfds should be opened by vhost-user process, so it's pretty hard to control making sure the TID feature will be around. It wasn't supported before, so keep it like that for now. Now we should be as ease when everything is protected by a mutex that we always take anyway. One side effect: we can finally remove one ramblock_recv_bitmap_test() in mark_postcopy_blocktime_begin(), which was pretty weird and which also includes a weird (but maybe necessary.. but maybe not?) operation to inject a blocktime entry then quickly erase it.. When we're with the mutex, and when we make sure it's invoked after checking the receive bitmap, it's not needed anymore. Instead, we assert. As another side effect, this paves way for removing all atomic ops in all the mem accesses in blocktime layer. Note that we need a stub for mark_postcopy_blocktime_begin() for Windows builds. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/migration.h | 2 +- migration/postcopy-ram.h | 2 ++ migration/migration.c | 25 +++++++++++------- migration/postcopy-ram.c | 56 +++++++++++++++++++++------------------- migration/trace-events | 2 +- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 739289de93..01329bf824 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -546,7 +546,7 @@ void migrate_send_rp_shut(MigrationIncomingState *mis, void migrate_send_rp_pong(MigrationIncomingState *mis, uint32_t value); int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb, - ram_addr_t start, uint64_t haddr); + ram_addr_t start, uint64_t haddr, uint32_t t= id); int migrate_send_rp_message_req_pages(MigrationIncomingState *mis, RAMBlock *rb, ram_addr_t start); void migrate_send_rp_recv_bitmap(MigrationIncomingState *mis, diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index a6df1b2811..3852141d7e 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -196,5 +196,7 @@ void postcopy_preempt_new_channel(MigrationIncomingStat= e *mis, QEMUFile *file); void postcopy_preempt_setup(MigrationState *s); int postcopy_preempt_establish_channel(MigrationState *s); bool postcopy_is_paused(MigrationStatus status); +void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid, + RAMBlock *rb); =20 #endif diff --git a/migration/migration.c b/migration/migration.c index 923400f801..10c216d25d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -576,22 +576,27 @@ int migrate_send_rp_message_req_pages(MigrationIncomi= ngState *mis, } =20 int migrate_send_rp_req_pages(MigrationIncomingState *mis, - RAMBlock *rb, ram_addr_t start, uint64_t had= dr) + RAMBlock *rb, ram_addr_t start, uint64_t had= dr, + uint32_t tid) { void *aligned =3D (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesi= ze(rb)); bool received =3D false; =20 WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { received =3D ramblock_recv_bitmap_test_byte_offset(rb, start); - if (!received && !g_tree_lookup(mis->page_requested, aligned)) { - /* - * The page has not been received, and it's not yet in the page - * request list. Queue it. Set the value of element to 1, so= that - * things like g_tree_lookup() will return TRUE (1) when found. - */ - g_tree_insert(mis->page_requested, aligned, (gpointer)1); - qatomic_inc(&mis->page_requested_count); - trace_postcopy_page_req_add(aligned, mis->page_requested_count= ); + if (!received) { + if (!g_tree_lookup(mis->page_requested, aligned)) { + /* + * The page has not been received, and it's not yet in the + * page request list. Queue it. Set the value of element + * to 1, so that things like g_tree_lookup() will return + * TRUE (1) when found. + */ + g_tree_insert(mis->page_requested, aligned, (gpointer)1); + qatomic_inc(&mis->page_requested_count); + trace_postcopy_page_req_add(aligned, mis->page_requested_c= ount); + } + mark_postcopy_blocktime_begin(haddr, tid, rb); } } =20 diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 75fd310fb2..32fa06dabd 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -752,8 +752,12 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, pagesize); } =20 +/* + * NOTE: @tid is only used when postcopy-blocktime feature is enabled, and + * also optional: when zero is provided, the fault accounting will be igno= red. + */ static int postcopy_request_page(MigrationIncomingState *mis, RAMBlock *rb, - ram_addr_t start, uint64_t haddr) + ram_addr_t start, uint64_t haddr, uint32_= t tid) { void *aligned =3D (void *)(uintptr_t)ROUND_DOWN(haddr, qemu_ram_pagesi= ze(rb)); =20 @@ -772,7 +776,7 @@ static int postcopy_request_page(MigrationIncomingState= *mis, RAMBlock *rb, return received ? 0 : postcopy_place_page_zero(mis, aligned, rb); } =20 - return migrate_send_rp_req_pages(mis, rb, start, haddr); + return migrate_send_rp_req_pages(mis, rb, start, haddr, tid); } =20 /* @@ -793,7 +797,8 @@ int postcopy_request_shared_page(struct PostCopyFD *pcf= d, RAMBlock *rb, qemu_ram_get_idstr(rb), rb_offset); return postcopy_wake_shared(pcfd, client_addr, rb); } - postcopy_request_page(mis, rb, aligned_rbo, client_addr); + /* TODO: support blocktime tracking */ + postcopy_request_page(mis, rb, aligned_rbo, client_addr, 0); return 0; } =20 @@ -819,17 +824,17 @@ static uint32_t get_low_time_offset(PostcopyBlocktime= Context *dc) } =20 /* - * This function is being called when pagefault occurs. It - * tracks down vCPU blocking time. + * This function is being called when pagefault occurs. It tracks down vCPU + * blocking time. It's protected by @page_request_mutex. * * @addr: faulted host virtual address * @ptid: faulted process thread id * @rb: ramblock appropriate to addr */ -static void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid, - RAMBlock *rb) +void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid, + RAMBlock *rb) { - int cpu, already_received; + int cpu; MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; uint32_t low_time_offset; @@ -852,24 +857,19 @@ static void mark_postcopy_blocktime_begin(uintptr_t a= ddr, uint32_t ptid, qatomic_xchg(&dc->vcpu_addr[cpu], addr); =20 /* - * check it here, not at the beginning of the function, - * due to, check could occur early than bitmap_set in - * qemu_ufd_copy_ioctl + * The caller should only inject a blocktime entry when the page is + * yet missing. */ - already_received =3D ramblock_recv_bitmap_test(rb, (void *)addr); - if (already_received) { - qatomic_xchg(&dc->vcpu_addr[cpu], 0); - qatomic_xchg(&dc->page_fault_vcpu_time[cpu], 0); - qatomic_dec(&dc->smp_cpus_down); - } + assert(!ramblock_recv_bitmap_test(rb, (void *)addr)); + trace_mark_postcopy_blocktime_begin(addr, dc, dc->page_fault_vcpu_time= [cpu], - cpu, already_received); + cpu); } =20 /* - * This function just provide calculated blocktime per cpu and trace it. - * Total blocktime is calculated in mark_postcopy_blocktime_end. - * + * This function just provide calculated blocktime per cpu and trace it. + * Total blocktime is calculated in mark_postcopy_blocktime_end. It's + * protected by @page_request_mutex. * * Assume we have 3 CPU * @@ -1068,17 +1068,14 @@ static void *postcopy_ram_fault_thread(void *opaque) qemu_ram_get_idstr(rb), rb_offset, msg.arg.pagefault.feat.pti= d); - mark_postcopy_blocktime_begin( - (uintptr_t)(msg.arg.pagefault.address), - msg.arg.pagefault.feat.ptid, rb); - retry: /* * Send the request to the source - we want to request one * of our host page sizes (which is >=3D TPS) */ ret =3D postcopy_request_page(mis, rb, rb_offset, - msg.arg.pagefault.address); + msg.arg.pagefault.address, + msg.arg.pagefault.feat.ptid); if (ret) { /* May be network failure, try to wait for recovery */ postcopy_pause_fault_thread(mis); @@ -1299,8 +1296,8 @@ static int qemu_ufd_copy_ioctl(MigrationIncomingState= *mis, void *host_addr, qemu_cond_signal(&mis->page_request_cond); } } - qemu_mutex_unlock(&mis->page_request_mutex); mark_postcopy_blocktime_end((uintptr_t)host_addr); + qemu_mutex_unlock(&mis->page_request_mutex); } return ret; } @@ -1430,6 +1427,11 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, { g_assert_not_reached(); } + +void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid, + RAMBlock *rb) +{ +} #endif =20 /* -----------------------------------------------------------------------= -- */ diff --git a/migration/trace-events b/migration/trace-events index dcd8fe9a0c..917f521e88 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -285,7 +285,7 @@ postcopy_nhp_range(const char *ramblock, void *host_add= r, size_t offset, size_t postcopy_place_page(void *host_addr) "host=3D%p" postcopy_place_page_zero(void *host_addr) "host=3D%p" postcopy_ram_enable_notify(void) "" -mark_postcopy_blocktime_begin(uint64_t addr, void *dd, uint32_t time, int = cpu, int received) "addr: 0x%" PRIx64 ", dd: %p, time: %u, cpu: %d, already= _received: %d" +mark_postcopy_blocktime_begin(uint64_t addr, void *dd, uint32_t time, int = cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, cpu: %d" mark_postcopy_blocktime_end(uint64_t addr, void *dd, uint32_t time, int af= fected_cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, affected_cpu: %d" postcopy_pause_fault_thread(void) "" postcopy_pause_fault_thread_continued(void) "" --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824050; cv=none; d=zohomail.com; s=zohoarc; b=dlnxEMTfmqcDmGKy0r9yWnGbEzddIqrxe1RIDjAJOu1wWm0nqQOlHEtVZUzn3hM2qa4JJWTaYsmp+aLglSOhj9awfgMT0NFFTN1Nr8gzgqLbBwZ7xAEt0WxiDu3kYkXRw9S/3Ifs+TJmBmhjkXXflnPi4ubTITCQdJrhsZxmNTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824050; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zNCKiYlI5hKeIag9Xbo3Ck8I0JoyXUXuzmM9e2pEd+Y=; b=ZYSxGTxlS7YJPNqAuMCWGdppX5KQa/jGHHmeZYgmkzE6ikX2x001LezFtqlbZWwqrEkqH43ol2Oj+O6T0t9ByKffDA/8db8PFfFKRraDKlKYgXcCuq0WhXk+5HtgwkSBFdOMU0xFFaxE7at+zp2Rqp5C1Ja9Cc95CySWw0KahhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824050127186.22782291746068; Fri, 13 Jun 2025 07:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59M-00041y-4S; Fri, 13 Jun 2025 10:12:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003vd-Lh for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ591-0002J1-Ry for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:43 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-22hkobuYPXOgTjF5iA6drg-1; Fri, 13 Jun 2025 10:12:25 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4a6f89098cfso46552051cf.0 for ; Fri, 13 Jun 2025 07:12:25 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zNCKiYlI5hKeIag9Xbo3Ck8I0JoyXUXuzmM9e2pEd+Y=; b=a/qkvQLmgPpq68XC3QWbq/SVit02GcIshhmM5AbrqR2TmKXnZW+c3iBBj5mEVW7NsQ9x6s /O3Hj/WozS4uocBakS88CtldtG+trcuS3lDjrngjPVsAmmGFe+BzA48biqKlpMFmiINsdm zvQv97t/MBx1Sqz/VrJ81ZopP7i7vFk= X-MC-Unique: 22hkobuYPXOgTjF5iA6drg-1 X-Mimecast-MFC-AGG-ID: 22hkobuYPXOgTjF5iA6drg_1749823945 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823944; x=1750428744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zNCKiYlI5hKeIag9Xbo3Ck8I0JoyXUXuzmM9e2pEd+Y=; b=N45wzE6NK1usgGRykG505kJtFawy8uMdlUXFvdUTXvGqB+vBXNCP2URV5JOsdPtHOb wwLD1MhcZLvmM5ixgdLacHthD1/ETVxrDnh004Py8QOWYiALdueRoL72LCrD0LcnC8+Y LSnD6dMmihaROofJmNnACktLsmZLT0Cox+pZlQJZyuRz/czhtxbZZRdB5POApN4uKmLC gB0yAUAOh2C76SahlH0yKfB9gxV7TX3nV29bdTBHRiEMMNy4vFep6goP4lZqpDoUt5+5 WOdy9uQ+UQ0RasmYyeNeCb1n8W4PCkJ6we1ESU/27nRHoQMtkNgOgDSl3oTh+wacX5DH BzAA== X-Gm-Message-State: AOJu0YzRMso9s7enBJCzuOIStPfgEClvm8WXBIrvciDP8JcegvPbObjz 1aaiVD0360w5a5/yA9wmX4FtDQcI6RBk8MlvJXpWwlc9ZbDxcRA0RbRF05MUlVihKzCVJNz2Sne zwHD/BsCCheZEa3KN+IEp+w5KLwEIlSSBk48Jpzhi7t6RQYp9atgy1j/PeoZ6DvioAsZNQoMhaB MhSWxWJ7WvCpAYZd8tQihMgISTRjURXfj+/yRVtQ== X-Gm-Gg: ASbGnctXSLnif6MhpJL85OmWsZHwmst5n7qpLpOeW1yrCIh1Y3DJUcT8MAUWFVdYRs1 2BoNehdttzF+aNEFsjdHwXpdeE9F/wmg1idKCHOXF9RKApJ74s5PlgXmll8J6w+mXcw9f4AIZGS DbBsjYvQsfCsZDp+SHJ7acV0ZZL7ISNmy4fqvJPe55p6Qa6Op4tGv/A0MOWCtPaCt9lo/ADUMaq DwRlq5qQrHjeBypxUAOw1LIbd1rpcimf3se+BYNDupYObjzw4Gd9GdTroI2X9uzJIpVhJYLcn6Z vySP/lkDF/M= X-Received: by 2002:a05:622a:4d4b:b0:4a3:6cbf:1fb4 with SMTP id d75a77b69052e-4a72ff0d5a6mr50272231cf.29.1749823944302; Fri, 13 Jun 2025 07:12:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiXoOpPm01lpb47ZmlqFFoRtHHkNpqpNWhlhHDDapWkfbGuzsXXgwIQnsrFityAnIwjRLXSg== X-Received: by 2002:a05:622a:4d4b:b0:4a3:6cbf:1fb4 with SMTP id d75a77b69052e-4a72ff0d5a6mr50271711cf.29.1749823943631; Fri, 13 Jun 2025 07:12:23 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 03/14] migration/postcopy: Drop all atomic ops in blocktime feature Date: Fri, 13 Jun 2025 10:12:06 -0400 Message-ID: <20250613141217.474825-4-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824052550116600 Content-Type: text/plain; charset="utf-8" Now with the mutex protection it's not needed anymore. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 32fa06dabd..81925532de 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -849,12 +849,12 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, ui= nt32_t ptid, =20 low_time_offset =3D get_low_time_offset(dc); if (dc->vcpu_addr[cpu] =3D=3D 0) { - qatomic_inc(&dc->smp_cpus_down); + dc->smp_cpus_down++; } =20 - qatomic_xchg(&dc->last_begin, low_time_offset); - qatomic_xchg(&dc->page_fault_vcpu_time[cpu], low_time_offset); - qatomic_xchg(&dc->vcpu_addr[cpu], addr); + dc->last_begin =3D low_time_offset; + dc->page_fault_vcpu_time[cpu] =3D low_time_offset; + dc->vcpu_addr[cpu] =3D addr; =20 /* * The caller should only inject a blocktime entry when the page is @@ -915,29 +915,26 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) for (i =3D 0; i < smp_cpus; i++) { uint32_t vcpu_blocktime =3D 0; =20 - read_vcpu_time =3D qatomic_fetch_add(&dc->page_fault_vcpu_time[i],= 0); - if (qatomic_fetch_add(&dc->vcpu_addr[i], 0) !=3D addr || - read_vcpu_time =3D=3D 0) { + read_vcpu_time =3D dc->page_fault_vcpu_time[i]; + if (dc->vcpu_addr[i] !=3D addr || read_vcpu_time =3D=3D 0) { continue; } - qatomic_xchg(&dc->vcpu_addr[i], 0); + dc->vcpu_addr[i] =3D 0; vcpu_blocktime =3D low_time_offset - read_vcpu_time; affected_cpu +=3D 1; /* we need to know is that mark_postcopy_end was due to * faulted page, another possible case it's prefetched * page and in that case we shouldn't be here */ - if (!vcpu_total_blocktime && - qatomic_fetch_add(&dc->smp_cpus_down, 0) =3D=3D smp_cpus) { + if (!vcpu_total_blocktime && dc->smp_cpus_down =3D=3D smp_cpus) { vcpu_total_blocktime =3D true; } /* continue cycle, due to one page could affect several vCPUs */ dc->vcpu_blocktime[i] +=3D vcpu_blocktime; } =20 - qatomic_sub(&dc->smp_cpus_down, affected_cpu); + dc->smp_cpus_down -=3D affected_cpu; if (vcpu_total_blocktime) { - dc->total_blocktime +=3D low_time_offset - qatomic_fetch_add( - &dc->last_begin, 0); + dc->total_blocktime +=3D low_time_offset - dc->last_begin; } trace_mark_postcopy_blocktime_end(addr, dc, dc->total_blocktime, affected_cpu); --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824003; cv=none; d=zohomail.com; s=zohoarc; b=PAfcak6kMSiiQX7VafBhUKPbrbS2P5zWvOk602all2arcwGHHeyqWcqrArOmoM2OJTORw2LqwB7jaglGwGyka8h4bq610Hf1UkvK6dpjk7Sv/ieElqMeE8+1+WRRl7X/4NnnYlBR9svitKSmGZLnaqMy1ZGMy0iwD11cXUpM6Ds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824003; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NfDiLFsnA6dZl9kxkmwj0QVEEsOtGZ66FVveHBAm7ew=; b=U8V3CsZXVcWg4OkBwA0zkABdrwjIzFcFfXUflWDBlx4RKp4kIkqGA+1y2wiMOVi75uR2U84VwwBot1V5bfOwtyBYoN9iMH4pKFRoPo6QUOhrUImT/xQ9BW/sIk/PwOFkvLgLoqv/MvuEc/Z5LhTHsYxrLDX6K7EZyIb9xW0V+kQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824003517742.062272322942; Fri, 13 Jun 2025 07:13:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003uG-Eq; Fri, 13 Jun 2025 10:12:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ597-0003si-Mp for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002JO-N5 for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:41 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-258-9DXSpzx0MR-qyDOeQ1kPhw-1; Fri, 13 Jun 2025 10:12:26 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4a43988c314so42710981cf.2 for ; Fri, 13 Jun 2025 07:12:26 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NfDiLFsnA6dZl9kxkmwj0QVEEsOtGZ66FVveHBAm7ew=; b=dKykqnY4kW51ayF1Bw5niTqGKH54H80/W7XLfUBuaG3Cib9WZLWlof5FvGnqBH7HRs5orE BUlLE0X8c87OY6PEoN9L6YuWZjYDxHWuhh4fKiLunQiQTdNHUNBMk7PVkhXkPnFqjcmOVT haRGNsJEhShLVihi8nNL03rhWKFugxs= X-MC-Unique: 9DXSpzx0MR-qyDOeQ1kPhw-1 X-Mimecast-MFC-AGG-ID: 9DXSpzx0MR-qyDOeQ1kPhw_1749823946 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823945; x=1750428745; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NfDiLFsnA6dZl9kxkmwj0QVEEsOtGZ66FVveHBAm7ew=; b=kKAQDjjvcQqbF4JASbqtk8HaeHX5kqc2Cpg6w+0YxPWcNl/PGmspQ+XPFLQFBwFonc JIkoAoILW9MU1M4oLgemFyPtWZVl8Djzq2FsxRjvV4WIpcyfY4QIv5oTYesZ8TnE/GKW k9hYx4NFBunWlPq34u9XQBtrGINtDeDR0tOdGSYOMXvho+34GLIlPTmNK1hsyjmso4pO 81IJxVp5XA6RT/Zml4FVZnHdvwIXIEofGo2vsX+r6/OrWHlVPHA9MNHpsMhIYDGrDv0E e3m36sB+5FihUDvjGETia1xgi0LeX0D8ohS/RJqyGC/IlNZ9xiEQcEBgRqix0EdcU0/j Nd+Q== X-Gm-Message-State: AOJu0YzGFVqGl0QWWsd9rANow78l0E1OZYHXh5K4MNAORTPcYMWoUwG2 eiP7aB80+r6f4Cmo0kF3Js2n8ffvAnzmOhvxRWyBDG/u0tDugGu+FgGJwBb03I5/4jKU8pHAIda 4JG9+zRwNfk7D59Gf2XTdZX5Bze4sDoRLRr7AaooDH8AZPCkQ3KHaje8wdNqQvJ4MaT+/nh7MOH etUvti4/tVMfQClAWh8RprpI9679WD5zM1nXnF+w== X-Gm-Gg: ASbGncuH3qctmmVTph2Ra+Uo1jvJhTXvokkXZA92M+TKJbQ8pM+NePPgP7wKwr30++Z HngVo9a6xtiC8XlSAZ2BZEPgLgfRI3rj4a/tJhLYZawwGKqoAo7eFFRzn8iet4KlDEBMfkKFUdI TBv4zdiwfBZ3d+B1/fxHQQRkkML0MEuZvWQ35etojvq0dOP+d+UgjSQN/U6qqNfFhw5d5aN4927 fFlRVDrtHciR000QNU78qeXlkOD5qCLc6D0FsHZUnFZcJXJfVN1MWG695UJGV40uqOsAL/n4+6z U18B4plJ5es= X-Received: by 2002:a05:622a:1144:b0:4a4:4165:ed60 with SMTP id d75a77b69052e-4a72fe810aamr58523101cf.3.1749823945169; Fri, 13 Jun 2025 07:12:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWGYrZgpa1RTj8jp6ORf/NfMI9mePxEncRzQJVzpyWRTS/48+dppDujNvAlbqvpO68D1qONQ== X-Received: by 2002:a05:622a:1144:b0:4a4:4165:ed60 with SMTP id d75a77b69052e-4a72fe810aamr58522401cf.3.1749823944579; Fri, 13 Jun 2025 07:12:24 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 04/14] migration/postcopy: Make all blocktime vars 64bits Date: Fri, 13 Jun 2025 10:12:07 -0400 Message-ID: <20250613141217.474825-5-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824006622116600 Content-Type: text/plain; charset="utf-8" I am guessing it was used to be 32bits because of the atomic ops. Now all the atomic ops are gone and we're protected by a mutex instead, it's ok we can switch to 64 bits. Reasons to move over: - Allow further patches to change the unit from ms to us: with postcopy preempt mode, we're really into hundreds of microseconds level on blocktime. We'd better be able to trap those. - This also paves way for some other tricks that the original version used to avoid overflows, e.g., start_time was almost only useful before to make sure the sampled timestamp won't overflow a 32-bit field. - This prepares further reports on top of existing data collected, e.g. average page fault latencies. When average operation is taken into account, milliseconds are simply too coarse grained. When at it: - Rename page_fault_vcpu_time to vcpu_blocktime_start. - Rename vcpu_blocktime to vcpu_blocktime_total. - Touch up the trace-events to not dump blocktime ctx pointer Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 50 ++++++++++++++++++++-------------------- migration/trace-events | 4 ++-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 81925532de..ec91821b85 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -112,14 +112,15 @@ void postcopy_thread_create(MigrationIncomingState *m= is, =20 typedef struct PostcopyBlocktimeContext { /* time when page fault initiated per vCPU */ - uint32_t *page_fault_vcpu_time; + uint64_t *vcpu_blocktime_start; + /* blocktime per vCPU */ + uint64_t *vcpu_blocktime_total; /* page address per vCPU */ uintptr_t *vcpu_addr; - uint32_t total_blocktime; - /* blocktime per vCPU */ - uint32_t *vcpu_blocktime; + /* total blocktime when all vCPUs are stopped */ + uint64_t total_blocktime; /* point in time when last page fault was initiated */ - uint32_t last_begin; + uint64_t last_begin; /* number of vCPU are suspended */ int smp_cpus_down; uint64_t start_time; @@ -133,9 +134,9 @@ typedef struct PostcopyBlocktimeContext { =20 static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx) { - g_free(ctx->page_fault_vcpu_time); + g_free(ctx->vcpu_blocktime_start); + g_free(ctx->vcpu_blocktime_total); g_free(ctx->vcpu_addr); - g_free(ctx->vcpu_blocktime); g_free(ctx); } =20 @@ -151,13 +152,14 @@ static struct PostcopyBlocktimeContext *blocktime_con= text_new(void) MachineState *ms =3D MACHINE(qdev_get_machine()); unsigned int smp_cpus =3D ms->smp.cpus; PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); - ctx->page_fault_vcpu_time =3D g_new0(uint32_t, smp_cpus); - ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); - ctx->vcpu_blocktime =3D g_new0(uint32_t, smp_cpus); =20 + ctx->vcpu_blocktime_start =3D g_new0(uint64_t, smp_cpus); + ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); + ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); ctx->exit_notifier.notify =3D migration_exit_cb; ctx->start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); qemu_add_exit_notifier(&ctx->exit_notifier); + return ctx; } =20 @@ -168,7 +170,7 @@ static uint32List *get_vcpu_blocktime_list(PostcopyBloc= ktimeContext *ctx) int i; =20 for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - QAPI_LIST_PREPEND(list, ctx->vcpu_blocktime[i]); + QAPI_LIST_PREPEND(list, (uint32_t)ctx->vcpu_blocktime_total[i]); } =20 return list; @@ -191,12 +193,12 @@ void fill_destination_postcopy_migration_info(Migrati= onInfo *info) } =20 info->has_postcopy_blocktime =3D true; - info->postcopy_blocktime =3D bc->total_blocktime; + info->postcopy_blocktime =3D (uint32_t)bc->total_blocktime; info->has_postcopy_vcpu_blocktime =3D true; info->postcopy_vcpu_blocktime =3D get_vcpu_blocktime_list(bc); } =20 -static uint32_t get_postcopy_total_blocktime(void) +static uint64_t get_postcopy_total_blocktime(void) { MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *bc =3D mis->blocktime_ctx; @@ -816,11 +818,9 @@ static int get_mem_fault_cpu_index(uint32_t pid) return -1; } =20 -static uint32_t get_low_time_offset(PostcopyBlocktimeContext *dc) +static uint64_t get_low_time_offset(PostcopyBlocktimeContext *dc) { - int64_t start_time_offset =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - - dc->start_time; - return start_time_offset < 1 ? 1 : start_time_offset & UINT32_MAX; + return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - dc->start_ti= me; } =20 /* @@ -837,7 +837,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, int cpu; MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; - uint32_t low_time_offset; + uint64_t low_time_offset; =20 if (!dc || ptid =3D=3D 0) { return; @@ -853,7 +853,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, } =20 dc->last_begin =3D low_time_offset; - dc->page_fault_vcpu_time[cpu] =3D low_time_offset; + dc->vcpu_blocktime_start[cpu] =3D low_time_offset; dc->vcpu_addr[cpu] =3D addr; =20 /* @@ -862,7 +862,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, */ assert(!ramblock_recv_bitmap_test(rb, (void *)addr)); =20 - trace_mark_postcopy_blocktime_begin(addr, dc, dc->page_fault_vcpu_time= [cpu], + trace_mark_postcopy_blocktime_begin(addr, dc->vcpu_blocktime_start[cpu= ], cpu); } =20 @@ -901,7 +901,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) unsigned int smp_cpus =3D ms->smp.cpus; int i, affected_cpu =3D 0; bool vcpu_total_blocktime =3D false; - uint32_t read_vcpu_time, low_time_offset; + uint64_t read_vcpu_time, low_time_offset; =20 if (!dc) { return; @@ -913,9 +913,9 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) * optimal, more optimal algorithm is keeping tree or hash * where key is address value is a list of */ for (i =3D 0; i < smp_cpus; i++) { - uint32_t vcpu_blocktime =3D 0; + uint64_t vcpu_blocktime =3D 0; =20 - read_vcpu_time =3D dc->page_fault_vcpu_time[i]; + read_vcpu_time =3D dc->vcpu_blocktime_start[i]; if (dc->vcpu_addr[i] !=3D addr || read_vcpu_time =3D=3D 0) { continue; } @@ -929,14 +929,14 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) vcpu_total_blocktime =3D true; } /* continue cycle, due to one page could affect several vCPUs */ - dc->vcpu_blocktime[i] +=3D vcpu_blocktime; + dc->vcpu_blocktime_total[i] +=3D vcpu_blocktime; } =20 dc->smp_cpus_down -=3D affected_cpu; if (vcpu_total_blocktime) { dc->total_blocktime +=3D low_time_offset - dc->last_begin; } - trace_mark_postcopy_blocktime_end(addr, dc, dc->total_blocktime, + trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, affected_cpu); } =20 diff --git a/migration/trace-events b/migration/trace-events index 917f521e88..02cdb6e7cc 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -285,8 +285,8 @@ postcopy_nhp_range(const char *ramblock, void *host_add= r, size_t offset, size_t postcopy_place_page(void *host_addr) "host=3D%p" postcopy_place_page_zero(void *host_addr) "host=3D%p" postcopy_ram_enable_notify(void) "" -mark_postcopy_blocktime_begin(uint64_t addr, void *dd, uint32_t time, int = cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, cpu: %d" -mark_postcopy_blocktime_end(uint64_t addr, void *dd, uint32_t time, int af= fected_cpu) "addr: 0x%" PRIx64 ", dd: %p, time: %u, affected_cpu: %d" +mark_postcopy_blocktime_begin(uint64_t addr, uint64_t time, int cpu) "addr= : 0x%" PRIx64 ", time: %" PRIu64 ", cpu: %d" +mark_postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu= ) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus: %d" postcopy_pause_fault_thread(void) "" postcopy_pause_fault_thread_continued(void) "" postcopy_pause_fast_load(void) "" --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749823991; cv=none; d=zohomail.com; s=zohoarc; b=I7lb/n7B/jcaN9O0vtW1H8W7hHHMYYL5of5MEXZTS4NdVcMa0aKdYjQPTncw4bmUtLLIP6mkhQUVU/n4Znl7WkK3jXUr7hJ06dOuvjiWz8rJa0tpUz8vILv0y7if/M2Z4/Gv5wsAXpilQAKBHpK6XKurOePAun9xXAXDmHC9Pn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749823991; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IV12Wf4LkVZLaVKBOcF5oGfPlhOljDoxLX6j8/o5TFE=; b=IoJ6BvgqVypKeXGz16qjOfK6OoNryyeKtUguLo9+WAkpzxiaZ9NqFWi1QdRdlQpkFQECCZvCS3f5Jm/bBXDmdWdvYQOQInhWiGOzwx/DZKxZsmTeU+wxEFGUIAUUBOMo2FO3679cwm2h7/iI8+N6lRQMUa3KkqwFsz27gWAVCJQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174982399114395.80837768155516; Fri, 13 Jun 2025 07:13:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003sr-Dd; Fri, 13 Jun 2025 10:12:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ597-0003sa-9G for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002JE-Nu for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:41 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-7OO_Ifa2O5iE7H7NmHeexg-1; Fri, 13 Jun 2025 10:12:27 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4a584d0669fso41165061cf.2 for ; Fri, 13 Jun 2025 07:12:27 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IV12Wf4LkVZLaVKBOcF5oGfPlhOljDoxLX6j8/o5TFE=; b=DhP8I0hSsXy1w+sEYyT0eKKfl+Ee5+f7F6kRLUMV8cfhjgj/9Nrz491fedfOcqKxAUU+kM YvHY3GKm9JYtNUwyRFFNqIAiuYgNTylM8CLB9fkkVcT97lExsE4DTMjutJic/p6OEJH5wS A5jq4qAv6CSk+W29xh48kgISyET60zg= X-MC-Unique: 7OO_Ifa2O5iE7H7NmHeexg-1 X-Mimecast-MFC-AGG-ID: 7OO_Ifa2O5iE7H7NmHeexg_1749823947 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823946; x=1750428746; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IV12Wf4LkVZLaVKBOcF5oGfPlhOljDoxLX6j8/o5TFE=; b=d2KprCvCbVeqAdgAHNWgtP/g96T1JKCkQiEJrZy/zDxoeMPdQmVINuPmYrXCXZXHGU aWZSsNeq+cZgvvfJS4JJksXnpVQ7VkVevyjriT4juhju04udtbxHjHEWPFWrD060zQsb 1y2U+wRphdL7jkCO8wQvB+wb49UXJ4L+9PMaopg5A660hbOdhXQuq4TNH4cmCfz13vt7 2q9H43zK+Rgjp/MGzidx09cQIqBKSxC+Sukq/kcz6LRvfdc8gP++YdAyevja9ueMTput rRtmLqRePwkarE7Yml9hv1LC4ine8rTtvzyWVzb6DcUGkJ6ObUWMDnSHicBK3c8edBmh Cu2Q== X-Gm-Message-State: AOJu0YyS41+79o0FxzuQChAByi43VVL5SE8ydzYyDhblSfebfB88Sj28 4eAMv0OANDKXNnP2Ke4GtE3MVtUpg8dtt029Ych0dGi/0ICMp+LC1Pq7Z/5ydQ3U4tZlsnkUGok f4EeIfT5mQ+6PRJ3d0wg6q4pl4vt5sKqax9rCbL9R8zGLnNW4fVFKrKWK/zj/AO3FsS0RFAkCZe /qpVBle3cDU6zm+LW6PUkDGV4m1hN6+apnIf3jAg== X-Gm-Gg: ASbGnct84kbEcKUbkjTRh5MwXGRADmJJKhiEk1FNET4OJSrooDtY3pUZZqCqvaIIXC9 kQ6hdhY9olxEHGEh3d/Yktf4UG4QI+W3s8vPZHr2aSESZ18BBoJvHSF6LtrANUti2j/Y6CYqw/i M9ooH2V9VZWYkicjaYxmu30laLpy0wpGalYqMG4ji+femyX5OdVq2jKer9sQD5C+sdA7rzqWwEg 0tS3PtTdOmerhyp//xnOKG73pa4r6i5hiZTmPi6vjs+onwF25uKQxNh7TerunpPG6QEPuVEWwOo 0uQl7ci5VBI= X-Received: by 2002:a05:622a:1f91:b0:4a4:3079:55e7 with SMTP id d75a77b69052e-4a72fe7a666mr55132531cf.17.1749823946385; Fri, 13 Jun 2025 07:12:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiFvSXbiq1MSDlD/nc6Ke+ac2OT7uSdaNAkB4ZP4hRa0OtTreUsfpZ+bMPckjfJas84kbLGA== X-Received: by 2002:a05:622a:1f91:b0:4a4:3079:55e7 with SMTP id d75a77b69052e-4a72fe7a666mr55131991cf.17.1749823945818; Fri, 13 Jun 2025 07:12:25 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 05/14] migration/postcopy: Drop PostcopyBlocktimeContext.start_time Date: Fri, 13 Jun 2025 10:12:08 -0400 Message-ID: <20250613141217.474825-6-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749823991970116600 Content-Type: text/plain; charset="utf-8" Now with 64bits, the offseting using start_time is not needed anymore, because the array can always remember the whole timestamp. Then drop the unused parameter in get_low_time_offset() altogether. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index ec91821b85..e9acb4ef6e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -123,7 +123,6 @@ typedef struct PostcopyBlocktimeContext { uint64_t last_begin; /* number of vCPU are suspended */ int smp_cpus_down; - uint64_t start_time; =20 /* * Handler for exit event, necessary for @@ -157,7 +156,6 @@ static struct PostcopyBlocktimeContext *blocktime_conte= xt_new(void) ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); ctx->exit_notifier.notify =3D migration_exit_cb; - ctx->start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); qemu_add_exit_notifier(&ctx->exit_notifier); =20 return ctx; @@ -818,9 +816,9 @@ static int get_mem_fault_cpu_index(uint32_t pid) return -1; } =20 -static uint64_t get_low_time_offset(PostcopyBlocktimeContext *dc) +static uint64_t get_low_time_offset(void) { - return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - dc->start_ti= me; + return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME); } =20 /* @@ -847,7 +845,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, return; } =20 - low_time_offset =3D get_low_time_offset(dc); + low_time_offset =3D get_low_time_offset(); if (dc->vcpu_addr[cpu] =3D=3D 0) { dc->smp_cpus_down++; } @@ -907,7 +905,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) return; } =20 - low_time_offset =3D get_low_time_offset(dc); + low_time_offset =3D get_low_time_offset(); /* lookup cpu, to clear it, * that algorithm looks straightforward, but it's not * optimal, more optimal algorithm is keeping tree or hash --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824102; cv=none; d=zohomail.com; s=zohoarc; b=P401//Q0Wp8xqX9DJ12QSBl6+p8NmKHTz8MGq0noxQ0yG4aw+0KBaI5/ol+4QBMMYO08Zk/D5vERgWZg/FibxXz+KvnPfjKsGz/V82OHHMo1A2Oqq7aIhn0Cyga+OOVPli7DXu2ovcmBbIaiVEyV6axyXvbyHodQNHWmAtuZszI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A2Y/VxjR0SJSPRQDE9vrJyR5mQKGwsPyvRKvKMkiT1A=; b=ducrtxl9oAMRSXnqTuUTQnaUavUW+GIl6ioZBn3kZjikpmvo5h+cQU1Q86FTHjd6kWkzx6pZTd61VV50FA1rCt3EdgNqTHzyFPnzqxVChyLb4bzJUSRxHC1YlS0DHaVxsky2WyGtfrnoKyqVHkb/M/At0ywmwF3c9j6sccpdaIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174982410276524.428101286231254; Fri, 13 Jun 2025 07:15:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59P-00044E-KV; Fri, 13 Jun 2025 10:12:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ599-0003su-1K for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002JJ-NW for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:42 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-jxedrYASPIKFrsGblLsu2g-1; Fri, 13 Jun 2025 10:12:28 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4a585dc5f6aso47500331cf.3 for ; Fri, 13 Jun 2025 07:12:28 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A2Y/VxjR0SJSPRQDE9vrJyR5mQKGwsPyvRKvKMkiT1A=; b=A8O/mpZVLIWgNOCY31r/ryRxsKUtKr+YdEnY5GoA8StOBCoYcQtfS/NEBxPdfTSjcDR1pF CEz4MG5h/k61FPCd5fkS7lEVOLjSO79psV61GHNyjO/xVYEpxvZWtG99GPBkwT3Q+fq1Bz dPW4dRliZ1FQCA5wJUNSorJDHoUd/p8= X-MC-Unique: jxedrYASPIKFrsGblLsu2g-1 X-Mimecast-MFC-AGG-ID: jxedrYASPIKFrsGblLsu2g_1749823948 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823948; x=1750428748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A2Y/VxjR0SJSPRQDE9vrJyR5mQKGwsPyvRKvKMkiT1A=; b=XeWrsZTWxvQmFqkAzgAZZ5E657NpmsSVBXJbM/UHRsq9x378kEOFCdSrazhsx+SGxa yKhoMU+0F6UphFzlGzjE7XCLcctMJUQADN50sjbDMYRvj+2D0+vbDmgqOeSptwXbC5kY pgzmeB305hWpHgahj8tLYyG7R0MO/uuFTPofnZy2Rn187pVm8xAL1KhRtksP3jlg8BFm kja7DetR35DS1pIpZoWmdvpZiqiu0XiO0IJEdBk30JLM7MhvHk+hvXxu5mgyex5yPWu6 NPPjgW9Aql18q90OM/vgcze2xcirP8pcibdCMvdvCMnzX7dXsCK51l+ci9tzYg9qxdLs cB2A== X-Gm-Message-State: AOJu0YwuwwgbuzeFkiW13qVMJCrAyymJU6t1FxOVmRlNH5ESQXGNTuu/ eYsGuaPJu8+GB4QOHDgs9PlxbYR4+SM885JDHZQQyUAsL99kr0001N5Ve3gO7177NA1Cy2uJ7Ig rQdCxAS6nnHTWNw8p43E+iAtnwaPPXmqRfumOUSQ7GMb+3POmM79VKJ1savxMIWI6PeFAlJfoSL rZj4LSq5NnZAVxoMH+DKDXog6I422gljc/SI9/Tg== X-Gm-Gg: ASbGnctExp28ZLxgukmN3Gc4gMLVfGhYkEEXluUR0+ZHGsIRcCbRnKkb5ApMZFU43EW UdSduJ9QaFrk4T5h3loR5pDjHNVf7q61YXrwIs3qmUr3p7Ztiv3eZilRVx/ThFP+ALDfy4SNfAo uYsK7FpurPwS3RkbnYVWXCbaJkplr9NQKkXNS+wd9gwr3zoBuBD+oTXjzkXNj36jfnCMMG9Gab+ i5PjMxt8M456R4jOn+ZVwF0ATM0WuhtZNbstb6GLwfUfOyirOJx+F3NCfYxtPuznfbAaovYNcRw 3FIshS8+PEo= X-Received: by 2002:a05:622a:1248:b0:4a4:3449:2b82 with SMTP id d75a77b69052e-4a72fe9229emr60593261cf.13.1749823947582; Fri, 13 Jun 2025 07:12:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbwblsb0vk78EWJhH6nHdp6FSb35/FKAe/uVfS0m1qT6wBgYAqkpluLYqBY6xZ2YNpvWzUUw== X-Received: by 2002:a05:622a:1248:b0:4a4:3449:2b82 with SMTP id d75a77b69052e-4a72fe9229emr60592581cf.13.1749823946868; Fri, 13 Jun 2025 07:12:26 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 06/14] migration/postcopy: Bring blocktime layer to ns level Date: Fri, 13 Jun 2025 10:12:09 -0400 Message-ID: <20250613141217.474825-7-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824103947116600 Content-Type: text/plain; charset="utf-8" With 64-bit fields, it is trivial. The caution is when exposing any values in QMP, it was still declared with milliseconds (ms). Hence it's needed to do the convertion when exporting the values to existing QMP queries. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e9acb4ef6e..9dfa92a62d 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -110,6 +110,7 @@ void postcopy_thread_create(MigrationIncomingState *mis, #include #include =20 +/* All the time records are in unit of nanoseconds */ typedef struct PostcopyBlocktimeContext { /* time when page fault initiated per vCPU */ uint64_t *vcpu_blocktime_start; @@ -168,7 +169,9 @@ static uint32List *get_vcpu_blocktime_list(PostcopyBloc= ktimeContext *ctx) int i; =20 for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - QAPI_LIST_PREPEND(list, (uint32_t)ctx->vcpu_blocktime_total[i]); + /* Convert ns -> ms */ + QAPI_LIST_PREPEND( + list, (uint32_t)(ctx->vcpu_blocktime_total[i] / SCALE_MS)); } =20 return list; @@ -191,7 +194,8 @@ void fill_destination_postcopy_migration_info(Migration= Info *info) } =20 info->has_postcopy_blocktime =3D true; - info->postcopy_blocktime =3D (uint32_t)bc->total_blocktime; + /* Convert ns -> ms */ + info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / SCALE_MS= ); info->has_postcopy_vcpu_blocktime =3D true; info->postcopy_vcpu_blocktime =3D get_vcpu_blocktime_list(bc); } @@ -816,9 +820,9 @@ static int get_mem_fault_cpu_index(uint32_t pid) return -1; } =20 -static uint64_t get_low_time_offset(void) +static uint64_t get_current_ns(void) { - return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + return (uint64_t)qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 /* @@ -835,7 +839,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, int cpu; MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; - uint64_t low_time_offset; + uint64_t current; =20 if (!dc || ptid =3D=3D 0) { return; @@ -845,13 +849,13 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, ui= nt32_t ptid, return; } =20 - low_time_offset =3D get_low_time_offset(); + current =3D get_current_ns(); if (dc->vcpu_addr[cpu] =3D=3D 0) { dc->smp_cpus_down++; } =20 - dc->last_begin =3D low_time_offset; - dc->vcpu_blocktime_start[cpu] =3D low_time_offset; + dc->last_begin =3D current; + dc->vcpu_blocktime_start[cpu] =3D current; dc->vcpu_addr[cpu] =3D addr; =20 /* @@ -899,13 +903,13 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) unsigned int smp_cpus =3D ms->smp.cpus; int i, affected_cpu =3D 0; bool vcpu_total_blocktime =3D false; - uint64_t read_vcpu_time, low_time_offset; + uint64_t read_vcpu_time, current; =20 if (!dc) { return; } =20 - low_time_offset =3D get_low_time_offset(); + current =3D get_current_ns(); /* lookup cpu, to clear it, * that algorithm looks straightforward, but it's not * optimal, more optimal algorithm is keeping tree or hash @@ -918,7 +922,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) continue; } dc->vcpu_addr[i] =3D 0; - vcpu_blocktime =3D low_time_offset - read_vcpu_time; + vcpu_blocktime =3D current - read_vcpu_time; affected_cpu +=3D 1; /* we need to know is that mark_postcopy_end was due to * faulted page, another possible case it's prefetched @@ -932,7 +936,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) =20 dc->smp_cpus_down -=3D affected_cpu; if (vcpu_total_blocktime) { - dc->total_blocktime +=3D low_time_offset - dc->last_begin; + dc->total_blocktime +=3D current - dc->last_begin; } trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, affected_cpu); --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824045; cv=none; d=zohomail.com; s=zohoarc; b=cGFSt3zV7i0pWTdWuVmxJRPKEquYHLTKpiOoHUDeOpcDGUURXBJLl77PiTfhKsMpRazqLDspzWvvP7rMtJofrTPGxLgDjrAEjw9lXXDY7VM9tp49s8aBVxa3LTa96EawC4J+HpGJ6jVPp8/XwdjXZeWbVHEbJxrYcMziJsqta/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824045; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lFbnej612dzDYBb7f39MwYrjr48oz8ZqDhNDlugW4Ys=; b=jLXP34WLG1ML8cRdErgaYPXARxRgwcJCzwmmPiSsvC4tps6MIMfY3bIbPc71rRQ+8pEWQOi/MQ75E0U0nUoTD3ZQxQtrSIv7NczzHbqUWHzA3b/Kn8agKmPmcpICG4XsNY8YAJR7bPLn4x36zDHUPMJ6Damcxqv78hqkjuJ5ovA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824045789735.9082028977028; Fri, 13 Jun 2025 07:14:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59H-0003yo-9S; Fri, 13 Jun 2025 10:12:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ598-0003ss-Lj for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002JQ-Nv for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:42 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-v_MendHYMlyu78ulwJpLIQ-1; Fri, 13 Jun 2025 10:12:29 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4a43988c314so42712271cf.2 for ; Fri, 13 Jun 2025 07:12:29 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lFbnej612dzDYBb7f39MwYrjr48oz8ZqDhNDlugW4Ys=; b=MwbQ+1a0PMf7mc9VgseB9Y9gdUFS5I9wP2erUfE/Njf2yZHVaKPISqBAO6Nz35n6v6JJEY tJM4rALdzwNMCG06ihUGSKdJLQ+OeQHN72hiMeRRLjmmFyGhLuGlJDwTrc+j26zZ17LW7o CwEORAFUAYHQA9pY97FXbvLidoo2SFI= X-MC-Unique: v_MendHYMlyu78ulwJpLIQ-1 X-Mimecast-MFC-AGG-ID: v_MendHYMlyu78ulwJpLIQ_1749823949 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823949; x=1750428749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lFbnej612dzDYBb7f39MwYrjr48oz8ZqDhNDlugW4Ys=; b=voWc8dPHMwPVE6KIoeYY5ir1Iz8tF/XBpGbErAuVZ2HA71hC8hI3Pn81Q7ezURY//5 E7/QI0PVKJC4TyqcYgJIHFpnHQRPtk5vESAPxCAShOa5HzY0rtNzqgL8jvAj8RsiH9qI W1QQ8jkXUaZrLTWuFXoY5Is8nBO19dwd2abMX8NFDFHhlyLKIVJgl1VE48gN5BB9GRaC 5j3QatoZQVnSEKQuwuWqj0pkBiPlE/D2soOBzVZSbc76hzf7fzhDVjeZy5AMeeQ6d5te cjU4aH6T7tn7d9W9TM/2eT45ypOTUAdI1OullHdYPlS+/WQy4eEmZGh9n5ERMzikeyoR hQuA== X-Gm-Message-State: AOJu0YydZumnKgtZgeiUkI844pH1RMN+Yy80l4gTnC7ksS2rZ5PTf0GX S13/yqKunT0cfBDztfA7cUhlfX4UqqN/r+phh5qWlQz8YWZSKYuDn7Ed2/KL13gM68uflnzBNeA pLECWQEakI7MhidjZfM69C0+lzVP2NvYYShDMr1oznzG/KY90aRFfklxmdv0a3nTpsMszPSxWXD SY8PkV/FoBwc3/eIcI95IyOfhM7XDJ500RBD7JaQ== X-Gm-Gg: ASbGncvE5bfQ/sEpsH0E7CuM3VBuaKZsf6meUMeUyFBwksXcNGcp88D6VQT6C0CWj6+ sOSFGfBK16tj3RIgsE5pJOZ/MlztiFv9L5+wVqGqGDNWtNN6X/Buj8g2mupXW8FiTx0Fv2XlftC eIXp57sAi3edCBz+S0hKFH5mkAV8L8YVPuOd+/8zZubh34qfXXujO5PLTlzuU+Gf3iMSoDZhyfz JcVcnhArqX+3j+CXvxBACnXMz7ZZsSu5kL43/QuBrmeWuw9BIiu2dvP9cy8sCQTGWb8GAlueWMD wKVxmHnUSRM= X-Received: by 2002:a05:622a:4c11:b0:4a4:3e89:d5bb with SMTP id d75a77b69052e-4a72ff5b926mr58332631cf.49.1749823948486; Fri, 13 Jun 2025 07:12:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3jBCezMjHKwh5TelEMcSngXaYWXkfoSK2+cU1VU07vH371KUmOjYuGXxA6rrEyislU89FTw== X-Received: by 2002:a05:622a:4c11:b0:4a4:3e89:d5bb with SMTP id d75a77b69052e-4a72ff5b926mr58331721cf.49.1749823947899; Fri, 13 Jun 2025 07:12:27 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 07/14] migration/postcopy: Add blocktime fault counts per-vcpu Date: Fri, 13 Jun 2025 10:12:10 -0400 Message-ID: <20250613141217.474825-8-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824046407116600 Content-Type: text/plain; charset="utf-8" Add a field to count how many remote faults one vCPU has taken. So far it's still not used, but will be soon. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 9dfa92a62d..15ea106910 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -116,6 +116,8 @@ typedef struct PostcopyBlocktimeContext { uint64_t *vcpu_blocktime_start; /* blocktime per vCPU */ uint64_t *vcpu_blocktime_total; + /* count of faults per vCPU */ + uint64_t *vcpu_faults_count; /* page address per vCPU */ uintptr_t *vcpu_addr; /* total blocktime when all vCPUs are stopped */ @@ -136,6 +138,7 @@ static void destroy_blocktime_context(struct PostcopyBl= ocktimeContext *ctx) { g_free(ctx->vcpu_blocktime_start); g_free(ctx->vcpu_blocktime_total); + g_free(ctx->vcpu_faults_count); g_free(ctx->vcpu_addr); g_free(ctx); } @@ -155,6 +158,7 @@ static struct PostcopyBlocktimeContext *blocktime_conte= xt_new(void) =20 ctx->vcpu_blocktime_start =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); + ctx->vcpu_faults_count =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); ctx->exit_notifier.notify =3D migration_exit_cb; qemu_add_exit_notifier(&ctx->exit_notifier); @@ -857,6 +861,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, dc->last_begin =3D current; dc->vcpu_blocktime_start[cpu] =3D current; dc->vcpu_addr[cpu] =3D addr; + dc->vcpu_faults_count[cpu]++; =20 /* * The caller should only inject a blocktime entry when the page is --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824049; cv=none; d=zohomail.com; s=zohoarc; b=KWDPizAc2iDc5VPBWwycqrv8h03XjcMr4xUo5o2waJeJp1226qwIcDfYbZhsF4J1oSz+ehh1AryuPqs75RXGZTXUjK3C8UoHKw7fbRQmG/gH3URbmqXzXKxjkJIzGELwxus03AVuRdbNgRNP2pIfas3Fq2hJG7i3XFCx1lUpMQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824049; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lALLJ7Kl3re5bx4CP7gHC1WJgi0gwi4Ei0KzYYTmm/0=; b=PW3GLbBH3UDSV2GlGMmsjR1YqsZc1nWyRe2Y80A0inSYchtw5URBo73wWG+UbA9b7s40W09McmN3gIDyYv3eqCJ6aL1rG5HKa67YOW6fVm9b6oQVKvQ/wD/ebJ7/wjc3MBPtOtGGekLr+Wf4qaVgD4LreW+vTZkV6dgJsjrQLnQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824049746481.7711159743559; Fri, 13 Jun 2025 07:14:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59Q-00044u-L4; Fri, 13 Jun 2025 10:13:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59N-00043c-7J for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59L-0002ON-6i for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:56 -0400 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-vH3WNZSWPhquQTqWDedQxQ-1; Fri, 13 Jun 2025 10:12:53 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6fad5f1e70fso41611596d6.0 for ; Fri, 13 Jun 2025 07:12:53 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lALLJ7Kl3re5bx4CP7gHC1WJgi0gwi4Ei0KzYYTmm/0=; b=HFv47X0g04wZUMDcYJwYEWWpC5zei4aaUgvcItWJinf931cgGGx6NWc3ATagA9waZPjV3I MeeTkyhp1yJGoD6EYKejJMfYXJ75RxCCqYqe00yKmzv94CU9xU64wMCbAO/+PIsuLiA+CE afJO12DFJXjd8Lg4v4v/pYSBUxppAiw= X-MC-Unique: vH3WNZSWPhquQTqWDedQxQ-1 X-Mimecast-MFC-AGG-ID: vH3WNZSWPhquQTqWDedQxQ_1749823973 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823972; x=1750428772; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lALLJ7Kl3re5bx4CP7gHC1WJgi0gwi4Ei0KzYYTmm/0=; b=Vwc65VLOVuokf7MF6CMrnlJwKEhGkC6dPlu3KJxrY8q6tO3LQwarb4ViI22rUuNMrW YEAFr3kvwHSZtohZDGZ4MawvN3QsqO1WT2Ap9OnO5+D7qBV5PqEzMd4G6mjCV6AH7EIZ frH5og7PmWAAz2DkFtse0FP5qkDDiJs2jirLQC/a8eZ2M0Kdn0/ULcP1tm4o/urv7368 J0nLW+8OjDbZ4Du7lBp+ZDbhRS+4kUKj0ZfTS87fxGhRANOD2J0P1n26/4TCq50ryzhF vuMwuXD6maGvRAWEcqCacm6HiiGLKpQZHAa7yvutWlhwBI4bqgVob4tlM43ZTy0lqp1J OCOQ== X-Gm-Message-State: AOJu0YxsZ8OxZAVTdQdidZDmy0BsN2viZGn8RZtAsk4/mX85W11P0Qpj /B3V7oZD1Iv5HUPO2q74A82KVRDK56TlHz4moJnj4QyBg5Qa6P7EZNybbduMb8BQqmQ7DIy+nHq VPlp2q/e8GZiSbqvO965KWk093eMjNz9Ix6xISe1zOpyfqa9XyNfDGfBUTZ+OHjELzFv4E2aKW6 GEVS7ynqL0NLGmolKLDYJwjXETsd6C5Anc4A+Dhw== X-Gm-Gg: ASbGnctdKMaKVS45Nub2OTfga6yN4OKNWTd+Q5Tr4Cm3Tc4IhPN1wLB1BJM/7HJtJgz K3gTt32DnaBr+zHRHBA9yQukfbtxmfmCfG6WbPndfBXUyISfsy2AOJS8JyvzLB3hNih4Kw5iA9D MvULwih0kZAC6p0B6rvsB8DhQwo5ZH+cC7rVNIAT5rYnZL+siE3BSfGsYG3pmAxaVEbB4jHIMMN O9E2HeTh3wcuEqP2o/fK1lVc2y1Ig8EldmUjK5xk+PvQIfGVrVrhk5xBpt1QSMlxV69nPXEvcwJ 8YXedny2Uvw= X-Received: by 2002:a05:620a:3728:b0:7d3:914b:abe8 with SMTP id af79cd13be357-7d3bc4475a7mr733714685a.36.1749823961534; Fri, 13 Jun 2025 07:12:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOFH6Xe24yS4mdBYS244wk5LxRKfc20GE18H6DDrXaDAxQzl530gEL326/3Vc8Xmx/CTvyOw== X-Received: by 2002:a05:622a:6117:b0:490:8ffd:8f02 with SMTP id d75a77b69052e-4a72ff521a6mr53590621cf.37.1749823948984; Fri, 13 Jun 2025 07:12:28 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas , Markus Armbruster Subject: [PATCH v3 08/14] migration/postcopy: Report fault latencies in blocktime Date: Fri, 13 Jun 2025 10:12:11 -0400 Message-ID: <20250613141217.474825-9-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824050719116600 Content-Type: text/plain; charset="utf-8" Blocktime so far only cares about the time one vcpu (or the whole system) got blocked. It would be also be helpful if it can also report the latency of page requests, which could be very sensitive during postcopy. Blocktime itself is sometimes not very important, especially when one thinks about KVM async PF support, which means vCPUs are literally almost not blocked at all because the guest OS is smart enough to switch to another task when a remote fault is needed. However, latency is still sensitive and important because even if the guest vCPU is running on threads that do not need a remote fault, the workload that accesses some missing page is still affected. Add two entries to the report, showing how long it takes to resolve a remote fault. Mention in the QAPI doc that this is not the real average fault latency, but only the ones that was requested for a remote fault. Unwrap get_vcpu_blocktime_list() so we don't need to walk the list twice, meanwhile add the entry checks in qtests for all postcopy tests. Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Reviewed-by: Fabiano Rosas Tested-by: Mario Casquero Signed-off-by: Peter Xu --- qapi/migration.json | 20 ++++++++ migration/migration-hmp-cmds.c | 67 ++++++++++++++++++--------- migration/postcopy-ram.c | 49 +++++++++++++------- tests/qtest/migration/migration-qmp.c | 3 ++ 4 files changed, 102 insertions(+), 37 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 4963f6ca12..30302f36cf 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -236,6 +236,17 @@ # This is only present when the postcopy-blocktime migration # capability is enabled. (Since 3.0) # +# @postcopy-latency: average remote page fault latency (in ns). Note that +# this doesn't include all faults, but only the ones that require a +# remote page request. So it should be always bigger than the real +# average page fault latency. This is only present when the +# postcopy-blocktime migration capability is enabled. (Since 10.1) +# +# @postcopy-vcpu-latency: average remote page fault latency per vCPU (in +# ns). It has the same definition of @postcopy-latency, but instead +# this is the per-vCPU statistics. This is only present when the +# postcopy-blocktime migration capability is enabled. (Since 10.1) +# # @socket-address: Only used for tcp, to know what the real port is # (Since 4.0) # @@ -260,6 +271,11 @@ # average memory load of the virtual CPU indirectly. Note that # zero means guest doesn't dirty memory. (Since 8.1) # +# Features: +# +# @unstable: Members @postcopy-latency, @postcopy-vcpu-latency are +# experimental. +# # Since: 0.14 ## { 'struct': 'MigrationInfo', @@ -275,6 +291,10 @@ '*blocked-reasons': ['str'], '*postcopy-blocktime': 'uint32', '*postcopy-vcpu-blocktime': ['uint32'], + '*postcopy-latency': { + 'type': 'uint64', 'features': [ 'unstable' ] }, + '*postcopy-vcpu-latency': { + 'type': ['uint64'], 'features': [ 'unstable' ] }, '*socket-address': ['SocketAddress'], '*dirty-limit-throttle-time-per-round': 'uint64', '*dirty-limit-ring-full-time': 'uint64'} } diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 867e017b32..8b3846dab5 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -52,6 +52,51 @@ static void migration_global_dump(Monitor *mon) ms->clear_bitmap_shift); } =20 +static void migration_dump_blocktime(Monitor *mon, MigrationInfo *info) +{ + if (info->has_postcopy_blocktime) { + monitor_printf(mon, "Postcopy Blocktime (ms): %" PRIu32 "\n", + info->postcopy_blocktime); + } + + if (info->has_postcopy_vcpu_blocktime) { + uint32List *item =3D info->postcopy_vcpu_blocktime; + const char *sep =3D ""; + int count =3D 0; + + monitor_printf(mon, "Postcopy vCPU Blocktime (ms):\n ["); + + while (item) { + monitor_printf(mon, "%s%"PRIu32, sep, item->value); + item =3D item->next; + /* Each line 10 vcpu results, newline if there's more */ + sep =3D ((++count % 10 =3D=3D 0) && item) ? ",\n " : ", "; + } + monitor_printf(mon, "]\n"); + } + + if (info->has_postcopy_latency) { + monitor_printf(mon, "Postcopy Latency (ns): %" PRIu64 "\n", + info->postcopy_latency); + } + + if (info->has_postcopy_vcpu_latency) { + uint64List *item =3D info->postcopy_vcpu_latency; + const char *sep =3D ""; + int count =3D 0; + + monitor_printf(mon, "Postcopy vCPU Latencies (ns):\n ["); + + while (item) { + monitor_printf(mon, "%s%"PRIu64, sep, item->value); + item =3D item->next; + /* Each line 10 vcpu results, newline if there's more */ + sep =3D ((++count % 10 =3D=3D 0) && item) ? ",\n " : ", "; + } + monitor_printf(mon, "]\n"); + } +} + void hmp_info_migrate(Monitor *mon, const QDict *qdict) { bool show_all =3D qdict_get_try_bool(qdict, "all", false); @@ -202,27 +247,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) info->dirty_limit_ring_full_time); } =20 - if (info->has_postcopy_blocktime) { - monitor_printf(mon, "Postcopy Blocktime (ms): %" PRIu32 "\n", - info->postcopy_blocktime); - } - - if (info->has_postcopy_vcpu_blocktime) { - uint32List *item =3D info->postcopy_vcpu_blocktime; - const char *sep =3D ""; - int count =3D 0; - - monitor_printf(mon, "Postcopy vCPU Blocktime (ms):\n ["); - - while (item) { - monitor_printf(mon, "%s%"PRIu32, sep, item->value); - item =3D item->next; - /* Each line 10 vcpu results, newline if there's more */ - sep =3D ((++count % 10 =3D=3D 0) && item) ? ",\n " : ", "; - } - monitor_printf(mon, "]\n"); - } - + migration_dump_blocktime(mon, info); out: qapi_free_MigrationInfo(info); } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 15ea106910..fe940f89b9 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -166,21 +166,6 @@ static struct PostcopyBlocktimeContext *blocktime_cont= ext_new(void) return ctx; } =20 -static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx) -{ - MachineState *ms =3D MACHINE(qdev_get_machine()); - uint32List *list =3D NULL; - int i; - - for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - /* Convert ns -> ms */ - QAPI_LIST_PREPEND( - list, (uint32_t)(ctx->vcpu_blocktime_total[i] / SCALE_MS)); - } - - return list; -} - /* * This function just populates MigrationInfo from postcopy's * blocktime context. It will not populate MigrationInfo, @@ -192,16 +177,48 @@ void fill_destination_postcopy_migration_info(Migrati= onInfo *info) { MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyBlocktimeContext *bc =3D mis->blocktime_ctx; + MachineState *ms =3D MACHINE(qdev_get_machine()); + uint64_t latency_total =3D 0, faults =3D 0; + uint32List *list_blocktime =3D NULL; + uint64List *list_latency =3D NULL; + int i; =20 if (!bc) { return; } =20 + for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { + uint64_t latency, total, count; + + /* Convert ns -> ms */ + QAPI_LIST_PREPEND(list_blocktime, + (uint32_t)(bc->vcpu_blocktime_total[i] / SCALE_M= S)); + + /* The rest in nanoseconds */ + total =3D bc->vcpu_blocktime_total[i]; + latency_total +=3D total; + count =3D bc->vcpu_faults_count[i]; + faults +=3D count; + + if (count) { + latency =3D total / count; + } else { + /* No fault detected */ + latency =3D 0; + } + + QAPI_LIST_PREPEND(list_latency, latency); + } + info->has_postcopy_blocktime =3D true; /* Convert ns -> ms */ info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / SCALE_MS= ); info->has_postcopy_vcpu_blocktime =3D true; - info->postcopy_vcpu_blocktime =3D get_vcpu_blocktime_list(bc); + info->postcopy_vcpu_blocktime =3D list_blocktime; + info->has_postcopy_latency =3D true; + info->postcopy_latency =3D faults ? (latency_total / faults) : 0; + info->has_postcopy_vcpu_latency =3D true; + info->postcopy_vcpu_latency =3D list_latency; } =20 static uint64_t get_postcopy_total_blocktime(void) diff --git a/tests/qtest/migration/migration-qmp.c b/tests/qtest/migration/= migration-qmp.c index fb59741b2c..1a5ab2d229 100644 --- a/tests/qtest/migration/migration-qmp.c +++ b/tests/qtest/migration/migration-qmp.c @@ -358,6 +358,9 @@ void read_blocktime(QTestState *who) =20 rsp_return =3D migrate_query_not_failed(who); g_assert(qdict_haskey(rsp_return, "postcopy-blocktime")); + g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-blocktime")); + g_assert(qdict_haskey(rsp_return, "postcopy-latency")); + g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-latency")); qobject_unref(rsp_return); } =20 --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824030; cv=none; d=zohomail.com; s=zohoarc; b=Zg05l/WHASsp8itfMoO81actZO/kgzlXJMQcTmedwJV3JpIrfpo7+rBAu9t4qnZO35QxNyFR9oMZHEAmfDwrq6I/tKyRn4b9zf2VOUcAf3FmDKsUqFE2DIFoK5oSyXg4XUn/907BZBc28tAeIdvq1AdrggW3TU9mGXGi6WdzTXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aVKgBQMfxhddBxPyaKNixg5DSYmgqFw6jW8hSbO1LhE=; b=TmoCT7xd69saKsNCxSEEdas7qxLo8enjpmxvryn7MUbyFA/0PSisRyVG8FwjnAZOZiMS2Td3Hg1qG8zoQaE/Zoevh0NtKQoDaBooi97Itqs1Ck5XIy5tDWAdFxbuXnf0CAWSRFVr/C5j1ZSAMUKGKTiUSS4FB0y7BT2aZmWPv+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824030468776.3000316242619; Fri, 13 Jun 2025 07:13:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59I-0003z5-Aj; Fri, 13 Jun 2025 10:12:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003vm-Nn for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002Jl-N5 for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:43 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-dp2ERQOSP5eVjdoFi6QIhw-1; Fri, 13 Jun 2025 10:12:32 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4a6e9182fbaso57370361cf.1 for ; Fri, 13 Jun 2025 07:12:32 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aVKgBQMfxhddBxPyaKNixg5DSYmgqFw6jW8hSbO1LhE=; b=KbjTiELoB6FyyYFf9dnAcktVHnT041mpD/1dBB0LG2HEijAzOr75pg2JDTZI1fBvjrnWto 41bkf3CzK71J5cYwFBvliIh/BURHJ6xYXVBIeBXw7NvKgygHVEc9Avj7ftrwF5T8/cHx/Y vhmD4kT+vg8cBG3mRkqcnY9fFn+LNjI= X-MC-Unique: dp2ERQOSP5eVjdoFi6QIhw-1 X-Mimecast-MFC-AGG-ID: dp2ERQOSP5eVjdoFi6QIhw_1749823952 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823951; x=1750428751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aVKgBQMfxhddBxPyaKNixg5DSYmgqFw6jW8hSbO1LhE=; b=QR6wO8IoMhRwaBjxnPCKGIqLFdhfOKZ9EzB2kyf5TbUnQis9c7AA8tp3ykqfEzA5EV sb9aULfQQpiHNF3WtC/uCfz7ye3fsXpqNxLt/It2XRAkna0WE2RK7vaJeXerlXq9bTLv cINhKmC8cbUwJMbp3TSc/YIXagOuTX0B3kGeZ6ys1Y8AKyaKZ2ggGXBUMAkadrCcffAy +v9vHl62oWuw5zXtDNSyPuRKGgg7sJeWcv8FoQJWJUqE47be6JlsclGX6piLIaUVfn1x BK/bqEynt9Ttefgzw5exIiZpiy5RVABOwOt6X3R/yJUmjxh/yt5Ci3u3BvYhQEA9ogG1 D/6A== X-Gm-Message-State: AOJu0YwoYyBEKo0keQvhea846m+5x28iUhkHylFXGK5R8CpUUNtlTOT7 cIoIdYSDQLkBbiCVFfkoc9fsboNkAuKcpIbpKWXeDUxpSiReanO9LEoiW2BR+MiV/Uz40AV9Zsl F11zAUcSOtk8LbMiu08ZgnAEp0YTOaJax1hW06nCBlZHCRIHLRe/ETacQ7ik7ozIJyDP+zH1th8 99VojzNeVf/nXrIeS1cvj56BjJzJ0QOsNI5KLi7A== X-Gm-Gg: ASbGncujRhfPE1dolI/GRyz63MshLVC+Amt20lDseoi5PWR/bRYSMx16MKCv1OwaV0n Kn3RJqn8/v+KEIjmIYH/uva0s+l+/cDH0BjXO64nXjbbgenPtH8662rZqj1PW7Zbacy5fBG+w39 WZYZguPuSXkFxH9TOJ7zOzM+5EMZGtbkWe//F1YWhfO+ZD4blD+pSBU3hbQpTPAfvVkFF4w3ZyK yTpGJKb9CwVpWR5O7vLCtjwPSxRCEr5nsoiLGvasUN239CjiKn5OE9mj8otqKfXSupK8hSJuqRs /MMqtXluK50= X-Received: by 2002:ac8:5a84:0:b0:49a:4fc0:56ff with SMTP id d75a77b69052e-4a73910fe61mr14844021cf.12.1749823951297; Fri, 13 Jun 2025 07:12:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQnsKlqpqOyfpH7oDmt/WafmFK07fx6niGHh2XSU7PI6ivB8SSWmqVMV1huPyddAucUMBteQ== X-Received: by 2002:ac8:5a84:0:b0:49a:4fc0:56ff with SMTP id d75a77b69052e-4a73910fe61mr14843181cf.12.1749823950584; Fri, 13 Jun 2025 07:12:30 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 09/14] migration/postcopy: Initialize blocktime context only until listen Date: Fri, 13 Jun 2025 10:12:12 -0400 Message-ID: <20250613141217.474825-10-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824032362116600 Content-Type: text/plain; charset="utf-8" Before this patch, the blocktime context can be created very early, because postcopy_ram_supported_by_host() <- migrate_caps_check() can happen during migration object init. The trick here is the blocktime context needs system vCPU information, which seems to be possible to change after that point. I didn't verify it, but it doesn't sound right. Now move it out and initialize the context only when postcopy listen starts. That is already during a migration so it should be guaranteed the vCPU topology can never change on both sides. While at it, assert that the ctx isn't created instead this time; the old "if" trick isn't needed when we're sure it will only happen once now. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index fe940f89b9..dd3615663f 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -325,13 +325,13 @@ static bool ufd_check_and_apply(int ufd, MigrationInc= omingState *mis, } =20 #ifdef UFFD_FEATURE_THREAD_ID + /* + * Postcopy blocktime conditionally needs THREAD_ID feature (introduced + * to Linux in 2017). Always try to enable it when QEMU is compiled + * with such environment. + */ if (UFFD_FEATURE_THREAD_ID & supported_features) { asked_features |=3D UFFD_FEATURE_THREAD_ID; - if (migrate_postcopy_blocktime()) { - if (!mis->blocktime_ctx) { - mis->blocktime_ctx =3D blocktime_context_new(); - } - } } #endif =20 @@ -1239,6 +1239,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingSta= te *mis) return -1; } =20 + if (migrate_postcopy_blocktime()) { + assert(mis->blocktime_ctx =3D=3D NULL); + mis->blocktime_ctx =3D blocktime_context_new(); + } + /* Now an eventfd we use to tell the fault-thread to quit */ mis->userfault_event_fd =3D eventfd(0, EFD_CLOEXEC); if (mis->userfault_event_fd =3D=3D -1) { --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824140; cv=none; d=zohomail.com; s=zohoarc; b=B5jXMvSKFq0aJWrpnrF0SfXXBwSHrcSELnqut4nHDLIPzRfzAN9NqiBD/vq4g9PSiU1Gz1a8iasNuNDDLaq93VMSxqHSBp0kyVBcUfT1pYSxNAOCHqnVGyG5RPy4Onxcty3nHWfS4KxvfyxFwi9fLEJ3sW/5C6uZ9V5aTpnyyVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824140; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WoyVijN1yRvTAaSZuMNvRxWVoxh2shcYGdBrpGC1Skg=; b=K/Z/GxySzjGFNOhTbnfgiLptwYPsyiwjuXWSuayvIHBkyh6NfhU2399gWT5kVJrBt/o+TLC+pLW3vFuXt+Jf+Et+8wOG7kSYVUfA6SO3ea+NfcCPtB0Q7xxvE++Vf67c0mZUvkhe88F96dbq1eoBJHPdqakmuQUXLnT3jpczOf8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824140266396.16824889858276; Fri, 13 Jun 2025 07:15:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59I-0003zD-KL; Fri, 13 Jun 2025 10:12:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59G-0003wB-9n for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0002MD-Aa for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:49 -0400 Received: from mail-oa1-f72.google.com (mail-oa1-f72.google.com [209.85.160.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-oinI28isMT6yEq2m4q9C5g-1; Fri, 13 Jun 2025 10:12:44 -0400 Received: by mail-oa1-f72.google.com with SMTP id 586e51a60fabf-2e43c3e66d1so1717228fac.1 for ; Fri, 13 Jun 2025 07:12:44 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WoyVijN1yRvTAaSZuMNvRxWVoxh2shcYGdBrpGC1Skg=; b=CsZaAQx/SNrQmka65taFrOmODeblKtEZIdTSpjP5mPJodujC8PXF4+V/5k4OaSOobKfhmF nJspJ6p8zxDuRxc7WVY4oh+Z24QZ8dZC3VFs0SoFL/8eybDNDFB9pAMo61dGbL4o4ibk1y y93o9TK0+jvBmwQyzo5D9BIvZu6Sjgg= X-MC-Unique: oinI28isMT6yEq2m4q9C5g-1 X-Mimecast-MFC-AGG-ID: oinI28isMT6yEq2m4q9C5g_1749823963 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823963; x=1750428763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WoyVijN1yRvTAaSZuMNvRxWVoxh2shcYGdBrpGC1Skg=; b=tv/D+iufGkQ5bGiks29SjojP8GWoTeAVcHLPej/7vw1140uvuGxdJ4SRmlwfDqbA8Z Jx0P1ZbkOUR209UfCpO8OFgt3kU13OsbEULFKZ6TCcAHXiLQuM2AbByy9R54LOD7QORd PafbevQKv6nc8gfqIsNoyiN4kTDSA85hbj7FgsOASGOyfvbXfx4wc/29qrwCbW04owNp BGg2dthVUgVIu1AwTBtv5ucajSx8cPuiHUYG7IzOPj2yacQMLnbG00xPPp32dof9FX0G 6esrcTdwC2lrder5KpIfY//29iu/aXVyuuiBch1IL/bDsjXBbXPnr1VjV9FLX6viI+jO p7CQ== X-Gm-Message-State: AOJu0Yxny0kT3llobCNVEpr7l1/fIJqknSFYmPCSaiWgIO0oMg8ow3db kkiOvbTwS9Xfb/8lsThWDAKedHji4QZxazbOP0kkd+bUKSgiSOD5ZUuRlRu5S+IVfroQXqRGKrJ NKwxEaB4d/LqT2QsN9U5K3vzzmT2ZpLRpLF3zMDCXkLQj5Wokk4JzqQoABIIGBxf0ueTMPHS6nh jmM6uM5ELjdvkI7sKkLzgiQ4OaWxW3Kjxuvy+/QQ== X-Gm-Gg: ASbGncvwIY4hyp67YO+uWyjOTx+IoTVBgflvIhRM+m9c8FBHJ0LZn+o+hYyunHwaCgU mhjqWolv0cwIeE3re7nfRJx+APRtiGQv8elM0U01Hvh6Q4HpALDHu1TjvFg8Hhe2Auc+fcJHJcf mfTg8wZxWsVX4AQd5Au5lnIzEVR0pxprXLpn8XrS4Q0nzx/ef8HW6GpDnscULLOyqBzrm/kfWs2 Vi6ePWsi1qohhXrTxY6nsFciyP37yE8KNcwP5YpVkB8dYcrGDQkY55Ch3MI6BqNtwNWmZloRqci fllfns70irs= X-Received: by 2002:a05:6870:600a:20b0:2d4:7cfa:6f3 with SMTP id 586e51a60fabf-2ead50802d6mr1226820fac.20.1749823963005; Fri, 13 Jun 2025 07:12:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4sUd5B0w4oGaKA64X0MBwRFiOrkJbrG4K9/SIGvbWADKmFyZsYGptyk6ai1SetBxBhEh1cQ== X-Received: by 2002:a05:622a:8ce:b0:4a6:f3f7:4c2b with SMTP id d75a77b69052e-4a72ff335camr48454221cf.51.1749823951563; Fri, 13 Jun 2025 07:12:31 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 10/14] migration/postcopy: Cache the tid->vcpu mapping for blocktime Date: Fri, 13 Jun 2025 10:12:13 -0400 Message-ID: <20250613141217.474825-11-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824142527116600 Content-Type: text/plain; charset="utf-8" Looking up the vCPU index for each fault can be expensive when there're hundreds of vCPUs. Provide a cache for tid->vcpu instead with a hash table, then lookup from there. When at it, add another counter to record how many non-vCPU faults it gets. For example, the main thread can also access a guest page that was missing. These kind of faults are not accounted by blocktime so far. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 68 ++++++++++++++++++++++++++++++++++------ migration/trace-events | 3 +- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index dd3615663f..bf65d6035c 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -127,6 +127,17 @@ typedef struct PostcopyBlocktimeContext { /* number of vCPU are suspended */ int smp_cpus_down; =20 + /* + * Fast path for looking up vcpu_index from tid. NOTE: this result + * only reflects the vcpu setup when postcopy is running. It may not + * always match with the current vcpu setup because vcpus can be hot + * attached/detached after migration completes. However this should be + * stable when blocktime is using the structure. + */ + GHashTable *tid_to_vcpu_hash; + /* Count of non-vCPU faults. This is only for debugging purpose. */ + uint64_t non_vcpu_faults; + /* * Handler for exit event, necessary for * releasing whole blocktime_ctx @@ -136,6 +147,7 @@ typedef struct PostcopyBlocktimeContext { =20 static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx) { + g_hash_table_destroy(ctx->tid_to_vcpu_hash); g_free(ctx->vcpu_blocktime_start); g_free(ctx->vcpu_blocktime_total); g_free(ctx->vcpu_faults_count); @@ -150,6 +162,36 @@ static void migration_exit_cb(Notifier *n, void *data) destroy_blocktime_context(ctx); } =20 +static GHashTable *blocktime_init_tid_to_vcpu_hash(void) +{ + /* + * TID as an unsigned int can be directly used as the key. However, + * CPU index can NOT be directly used as value, because CPU index can + * be 0, which means NULL. Then when lookup we can never know whether + * it's 0 or "not found". Hence use an indirection for CPU index. + */ + GHashTable *table =3D g_hash_table_new_full(g_direct_hash, g_direct_eq= ual, + NULL, g_free); + CPUState *cpu; + + /* + * Initialize the tid->cpu_id mapping for lookups. The caller needs to + * make sure when reaching here the CPU topology is frozen and will be + * stable for the whole blocktime trapping period. + */ + CPU_FOREACH(cpu) { + int *value =3D g_new(int, 1); + + *value =3D cpu->cpu_index; + g_hash_table_insert(table, + GUINT_TO_POINTER((uint32_t)cpu->thread_id), + value); + trace_postcopy_blocktime_tid_cpu_map(cpu->cpu_index, cpu->thread_i= d); + } + + return table; +} + static struct PostcopyBlocktimeContext *blocktime_context_new(void) { MachineState *ms =3D MACHINE(qdev_get_machine()); @@ -160,6 +202,8 @@ static struct PostcopyBlocktimeContext *blocktime_conte= xt_new(void) ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_faults_count =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); + ctx->tid_to_vcpu_hash =3D blocktime_init_tid_to_vcpu_hash(); + ctx->exit_notifier.notify =3D migration_exit_cb; qemu_add_exit_notifier(&ctx->exit_notifier); =20 @@ -827,18 +871,21 @@ int postcopy_request_shared_page(struct PostCopyFD *p= cfd, RAMBlock *rb, return 0; } =20 -static int get_mem_fault_cpu_index(uint32_t pid) +static int blocktime_get_vcpu(PostcopyBlocktimeContext *ctx, uint32_t tid) { - CPUState *cpu_iter; + int *found; =20 - CPU_FOREACH(cpu_iter) { - if (cpu_iter->thread_id =3D=3D pid) { - trace_get_mem_fault_cpu_index(cpu_iter->cpu_index, pid); - return cpu_iter->cpu_index; - } + found =3D g_hash_table_lookup(ctx->tid_to_vcpu_hash, GUINT_TO_POINTER(= tid)); + if (!found) { + /* + * NOTE: this is possible, because QEMU's non-vCPU threads can + * also access a missing page. Or, when KVM async pf is enabled, a + * fault can even happen from a kworker.. + */ + return -1; } - trace_get_mem_fault_cpu_index(-1, pid); - return -1; + + return *found; } =20 static uint64_t get_current_ns(void) @@ -865,8 +912,9 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, if (!dc || ptid =3D=3D 0) { return; } - cpu =3D get_mem_fault_cpu_index(ptid); + cpu =3D blocktime_get_vcpu(dc, ptid); if (cpu < 0) { + dc->non_vcpu_faults++; return; } =20 diff --git a/migration/trace-events b/migration/trace-events index 02cdb6e7cc..9c1f3b7044 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -310,8 +310,7 @@ postcopy_preempt_tls_handshake(void) "" postcopy_preempt_new_channel(void) "" postcopy_preempt_thread_entry(void) "" postcopy_preempt_thread_exit(void) "" - -get_mem_fault_cpu_index(int cpu, uint32_t pid) "cpu: %d, pid: %u" +postcopy_blocktime_tid_cpu_map(int cpu, uint32_t tid) "cpu: %d, tid: %u" =20 # exec.c migration_exec_outgoing(const char *cmd) "cmd=3D%s" --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824094; cv=none; d=zohomail.com; s=zohoarc; b=eRmTng6wKNuzu791Ec5adOtFN9NoPVzQwnoTTTipt3z/Obx7liyyPIz87eKjrwwb8uKzkqVlo9mImo80qzrIWZ06/GM3gwI3rW0qRHZyOr5/Wy9R3bg88gKBxUwMN/GNJ81BvqUyAxZL9up/SsLjrIlSyJMnntFycZ4i6CnLEDI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824094; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0cax0HF/e3FLRBTL6vfyxA7ugDSdkEzjc448UZATJ/g=; b=PDLpx94OOwLWOZyPdLaGgUMZBk7n8wO16EqY5FX8DhDLgJbr5i4HdbwR3uSK3TCesl8HnbQGq0iZm/bRR3DCXwpi/oHJNYmy8de/y63kUEZTmxWbySshUGPqCo8Dhj6sJ0fRK5wFgIqNrgVQ+qFOwjdSViA+Ugn/sZcomTwCWOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824094071450.4509071040691; Fri, 13 Jun 2025 07:14:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59M-00042p-JH; Fri, 13 Jun 2025 10:12:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ598-0003st-PD for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ595-0002Jy-Nn for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:42 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-1ag2WnTUMUmp73I77sLflg-1; Fri, 13 Jun 2025 10:12:34 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4a587c85a60so43410371cf.2 for ; Fri, 13 Jun 2025 07:12:34 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0cax0HF/e3FLRBTL6vfyxA7ugDSdkEzjc448UZATJ/g=; b=cIWjcwwFmV9OJpjYRILOF9dX836+aEsQmaTbrIopDNxV2hCwWVsGx0iBshtvDWNpXzP9HE QLlUVSixDNSVnuc7k/lZQaXWa/huInmWLUA1B8War/91e44dgyfd89eVX1ybO9lAKf/PYJ 830hBWHam0xaBe/25+e3W0BkX5cMtdg= X-MC-Unique: 1ag2WnTUMUmp73I77sLflg-1 X-Mimecast-MFC-AGG-ID: 1ag2WnTUMUmp73I77sLflg_1749823954 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823954; x=1750428754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0cax0HF/e3FLRBTL6vfyxA7ugDSdkEzjc448UZATJ/g=; b=Nn+s7gZLcrXAVvpCmT/5DHtfOExWbH58mjRh6RAElpZlSC82cAWoTKu/1sMpOaq0Ab OSjSYn0Ve3qPzLXVlmFXM1H94cFEsqLwcFCNIE3/7nx8xk91CslTVwDkuQaVvQe12V6t JKZciAbq2Jmkcz+CcX/LMELHjrUhemuA+PQSdJtRBlrPAWdidiaLtSY0V336AeQIE01z lytEkzJweHCTkVm+AMyl/VESKmj5iLJnc9zgmHQd2NFU1UxUghWhGQ7Ajq8Gqgrd+WJQ vaYQcpSEqGHpQ6J6/XIHPac+toHjAYGP7M0820DIEVBcaIWV0WR0wFWtTm/WZ6VwH8bb NDlA== X-Gm-Message-State: AOJu0YyrqkAH6bncNjQ42W8eifc0thtx3xbEX2JzhgKk0I23U2FTEk04 gFwH2S0k/0SI1OWNjkHigksUMciuNJjxDzSlfI8gXeQHD0U0CJQyar+AVP3+FoiLKXjuEs5jQS4 98JCv5FDW050UdE3tP3/JT+vEkHPRiHa1fEW3APkWA1EC04apgUfqW1ie2OW641wTIbNuY3i/uX OIzSYaJ6UFuWQMdS9vmYfhybHiLbNoHcFyeeXlVw== X-Gm-Gg: ASbGncs0GsL535adWdG0aMZuNdtWXQ+vMt4f/jzrfuoQamBrIzBbzs3egO1+7ASBlxc ofPrzX5svdbMvjHLHeDgTGta+EqY+J4xs3qKMzgsShfiIJkIFHXWSN8qhnUZUN3YkOxyGl+f9+Z DetOMw4WW6cbz0bFKb3NAcXgQeslBZEKPd4gVhB0fW9dCP2UN6hDRc9egYmmZcWetaw3VztZMP0 MfuPH/bjBQTEkwuhGulnnLdMiApK+bhCfgu67J3gMs2rGpVh/cJBJBUP0lGuRTA4ml6caGe0e5/ 0zx5lMknvfw= X-Received: by 2002:a05:622a:1bab:b0:4a5:a96d:6068 with SMTP id d75a77b69052e-4a72ff14f67mr51978121cf.37.1749823953719; Fri, 13 Jun 2025 07:12:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWGTu7xfM196+tmFJUPgVdX3/G/Y269iBTqvgxx1Q3GV16Y12YHNQJOzRgQ0tzJ2WZsKoRng== X-Received: by 2002:a05:622a:1bab:b0:4a5:a96d:6068 with SMTP id d75a77b69052e-4a72ff14f67mr51977651cf.37.1749823952984; Fri, 13 Jun 2025 07:12:32 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 11/14] migration/postcopy: Cleanup the total blocktime accounting Date: Fri, 13 Jun 2025 10:12:14 -0400 Message-ID: <20250613141217.474825-12-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824095676116600 Content-Type: text/plain; charset="utf-8" The variable vcpu_total_blocktime isn't easy to follow. In reality, it wants to capture the case where all vCPUs are stopped, and now there will be some vCPUs starts running. The name now starts to conflict with vcpu_blocktime_total[], meanwhile it's actually not necessary to have the variable at all: since nobody is touching smp_cpus_down except ourselves, we can safely do the calculation at the end before decrementing smp_cpus_down. Hopefully this makes the logic easier to read, side benefit is we drop one temp var. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index bf65d6035c..fd6c0bdb1e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -972,7 +972,6 @@ static void mark_postcopy_blocktime_end(uintptr_t addr) MachineState *ms =3D MACHINE(qdev_get_machine()); unsigned int smp_cpus =3D ms->smp.cpus; int i, affected_cpu =3D 0; - bool vcpu_total_blocktime =3D false; uint64_t read_vcpu_time, current; =20 if (!dc) { @@ -994,20 +993,19 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) dc->vcpu_addr[i] =3D 0; vcpu_blocktime =3D current - read_vcpu_time; affected_cpu +=3D 1; - /* we need to know is that mark_postcopy_end was due to - * faulted page, another possible case it's prefetched - * page and in that case we shouldn't be here */ - if (!vcpu_total_blocktime && dc->smp_cpus_down =3D=3D smp_cpus) { - vcpu_total_blocktime =3D true; - } /* continue cycle, due to one page could affect several vCPUs */ dc->vcpu_blocktime_total[i] +=3D vcpu_blocktime; } =20 - dc->smp_cpus_down -=3D affected_cpu; - if (vcpu_total_blocktime) { + /* + * If all vCPUs used to be down, and copying this page would free some + * vCPUs, then the system-level blocktime ends here. + */ + if (dc->smp_cpus_down =3D=3D smp_cpus && affected_cpu) { dc->total_blocktime +=3D current - dc->last_begin; } + dc->smp_cpus_down -=3D affected_cpu; + trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, affected_cpu); } --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824077; cv=none; d=zohomail.com; s=zohoarc; b=aGwp/YsnXIn2v0b2rgidZuMaD2/Sx6Nc1Aytz+HyMVhE1ZDcRaYk4LgpeR1HsU1esKyMbJ9qmMJAZvkjKURf9jBrZ2DcYfrUkixLRaykkK7TXIiBC4B/2HDCqgLJ4+kD8YWrtWVHB6L/bXeKlmZNeBIrLke/fk8RYPsVUWhTVVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824077; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=x8Gw+BTHpy8tDPl2z+QzTac4pD6yWKzSjSxRkcwCm+M=; b=TEnL6iB3RWxnH9WfQ+VToY6vCUwuTYgJ3ewj3dobSjKiXOXYWWrkG7GfR+JkLIrnd73QYjL1WrhsOYW1v3Qnk1yKwb7Drz33bcgblO591pgy9A2evSb2KzfOlP7GmQExp61p5BcZzPOaGjgJwwKn7ZHP6E1tVnNjbSqkQxd3fO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824077557232.08320711150975; Fri, 13 Jun 2025 07:14:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59P-00044S-Kn; Fri, 13 Jun 2025 10:12:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003vg-N7 for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ596-0002KT-8Q for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:45 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-36wEH9aVOiia75AI8Ef61w-1; Fri, 13 Jun 2025 10:12:37 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4a6f89098cfso46555401cf.0 for ; Fri, 13 Jun 2025 07:12:37 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x8Gw+BTHpy8tDPl2z+QzTac4pD6yWKzSjSxRkcwCm+M=; b=GBpW9HUGXl7PCLBB1j50JqTtCTH82qd3qJbU6cH3FJFnzyE2dOiI/W1uaTORgrBfc6CMDJ 8E9wp4mCXaszd9D2eZs83GSXVGmtiPBiXtpR+J9Oy6DgrmdIHLzuZYUYQM1RWVll1Gpguo UdBFsMpERZbkK5XFeKqErzUpKLdXPmA= X-MC-Unique: 36wEH9aVOiia75AI8Ef61w-1 X-Mimecast-MFC-AGG-ID: 36wEH9aVOiia75AI8Ef61w_1749823957 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823956; x=1750428756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x8Gw+BTHpy8tDPl2z+QzTac4pD6yWKzSjSxRkcwCm+M=; b=w7XdllsVXoKnmtFn4MQhQNvYpKIt/lGMcIrwO5TIHIHpScIZSnVjYWqqeqMS4gACSu EqoY/iu7uV0s9EJS5q8WmXL9mJCvyXv+vkvqBIgwgtZXTWiR9cohPO6/fKSkxE7E8/zk k6xp/vsRNMFLCOuB0JyqgG6l5G4SuY7Ja7rnXI5i7dayYq8FMuWv0Bwk1RDWD/7gPnji iGoU7uYcz+ugEIo5dg2BvWAXLeYAs3a9zUwlPc2lBlDy5PS6nasrZvu9yc67ZLCFtFCo u2Ir80iaFjeTiNEJy1SQgpTaFYwKx96m09CIn8OqRlYKseVt1nBS1LP+0/LHwXjvLZHP uFsw== X-Gm-Message-State: AOJu0YwP7xuTZss6foIbnQCgg7T/2169xcaxDl2V9iyteT18mRBeRG5a uOjKl6+I5szuXCiwECZTKs6zhpV8zxjG6p7S9Xnhl5RWoCrqnT4pB4yjNDefe5JOC9CMIrF/Zdc GpJIeMGJIBLIzm4yts2V2YwN1N6Kdt/Y4DoV0Ejd/K28NXnDP+z3wSf34TEHJ/AHLt3ACgMsSXT KcyTtqkoRk/b4sy4SO3aykDrRYibee/vy3wUGLIA== X-Gm-Gg: ASbGncv4YIFO7eOTAGetxR8LppxiCchcbBBDix2Q1D7CZfkZy8xC6DpNmXA3vi3IDLY pTW2uJGmPM5qZR/6b27X03yzsnIVXTl+5csPYTR7Rcxmiiw0a1boP0UcEkzQUm2mZI1n3zAat8D ZgWssz5UtjrAobKBIIGyg7o70NQYW3XXwPm6UA1hoNDdztSO0q1isolxYk1d3n/p00KrnNDwBkl +WSv540K26gWugr311ju/0997sjeMB5jfbMACTWpqIyAZfkeOT5cj0NFr8MYlIFvGAsCSGAn2Yn aoLjaVqYC0M= X-Received: by 2002:a05:622a:1dca:b0:4a4:41c5:b89c with SMTP id d75a77b69052e-4a72ff36d78mr55012941cf.2.1749823956230; Fri, 13 Jun 2025 07:12:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFky9xTTUQMTStfZVGcluVnf9/f+ZVuy63C/r0AkeSyjdF1ys3mDY+5sMnkY6kk52mwE9a1nw== X-Received: by 2002:a05:622a:1dca:b0:4a4:41c5:b89c with SMTP id d75a77b69052e-4a72ff36d78mr55012321cf.2.1749823955444; Fri, 13 Jun 2025 07:12:35 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas Subject: [PATCH v3 12/14] migration/postcopy: Optimize blocktime fault tracking with hashtable Date: Fri, 13 Jun 2025 10:12:15 -0400 Message-ID: <20250613141217.474825-13-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824079542116600 Content-Type: text/plain; charset="utf-8" Currently, the postcopy blocktime feature maintains vCPU fault information using an array (vcpu_addr[]). It has two issues. Issue 1: Performance Concern =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D The old algorithm was almost OK and fast on inserts, except that the lookup is slow and won't scale if there are a lot of vCPUs: when a page is copied during postcopy, mark_postcopy_blocktime_end() will walk the whole array trying to find which vCPUs are blocked by the address. So it needs constant O(N) walk for each page resolution. Alexey (the author of postcopy blocktime) mentioned the perf issue and how to optimize it in a piece of comment in the page resolution path. The comment was (interestingly..) not complete, but it's relatively clear what he wanted to say about this perf issue. Issue 2: Wrong Accounting on re-entrancies =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D People might think that each vCPU should only and always get one fault at a time, so that when the blocktime layer captured one fault on one vCPU, we should never see another fault message on this vCPU. It's almost correct, except in some extreme rare cases. Case 1: it's possible the fault thread processes the userfaultfd messages too fast so it can see >1 messages on one vCPU before the previous one was resolved. Case 2: it's theoretically also possible one vCPU can get even more than one message on the same fault address if a fault is retried by the kernel (e.g., handle_userfault() got interrupted before page resolution). As this info might be important, instead of using commit message, I put more details into the code as comment, when introducing an array maintaining concurrent faults on one vCPU. Please refer to the comments for details on both cases, especially case 1 which can be tricky. Case 1 sounds rare, but it can be easily reproduced locally for me when we run blocktime together with the migration-test on the vanilla postcopy. New Design =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This patch should do almost what Alexey mentioned, but slightly differently: instead of having an array to maintain vCPU fault addresses, for each of the fault message we push a message into a hash, indexed by the fault address. With the hash, it can replace the old two structs: both the vcpu_addr[] array, and also the array to store the start time of the fault. However due to above we need one more counter array to account concurrent faults on the same vCPU - that should even be needed in the old code, it's just that the old code was buggy and it will blindly overwrite an existing entry.. now we'll start to really track everything. The hash structure might be more efficient than tree to maintain such addr->(cpu, fault_time) information, so that the insert() and lookup() paths should ideally both be ~O(1). After all, we do not need to sort. Here we need to do one remove() though after the lookup(). It could be slow but only if many vCPUs faulted exactly on the same address (so when the list of cpu entries is long), which should be unlikely. Even with that, it's still a worst case O(N) (consider 400 vCPUs faulted on the same address and how likely is it..) rather than a constant O(N) complexity. When at it, touch up the tracepoints to make them slightly more useful. One tracepoint is added when walking all the fault entries. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/postcopy-ram.c | 259 ++++++++++++++++++++++++++++++++------- migration/trace-events | 5 +- 2 files changed, 216 insertions(+), 48 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index fd6c0bdb1e..91c23b446e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -112,14 +112,69 @@ void postcopy_thread_create(MigrationIncomingState *m= is, =20 /* All the time records are in unit of nanoseconds */ typedef struct PostcopyBlocktimeContext { - /* time when page fault initiated per vCPU */ - uint64_t *vcpu_blocktime_start; /* blocktime per vCPU */ uint64_t *vcpu_blocktime_total; /* count of faults per vCPU */ uint64_t *vcpu_faults_count; - /* page address per vCPU */ - uintptr_t *vcpu_addr; + /* + * count of currently blocked faults per vCPU. + * + * NOTE: Normally there should only be one fault in-progress per vCPU + * thread, so logically it _seems_ vcpu_faults_count[] for any vCPU + * should be either zero or one. However, there can be reasons we see + * >1 faults on the same vCPU thread. + * + * CASE (1): since the process to resolve faults (ioctl(UFFDIO_COPY), + * for example) is done before taking the mutex that protects the + * blocktime context, it can happen that we read more than one faulted + * addresses per vCPU. + * + * One example when we can see >1 faulted addresses for one vCPU: + * + * vcpu1 thread fault thread resolve thread + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * faulted on addr1 + * read uffd msg (addr1) + * MUTEX_LOCK + * add entry (cpu1, addr1) + * MUTEX_UNLOCK + * request remote fault (addr1) + * resolve fault (addr1) + * addr1 resolved, continue.. + * faulted on addr2 + * read uffd msg (addr2) + * MUTEX_LOCK + * add entry (cpu1, addr2) <--------------- [A] + * MUTEX_UNLOCK + * MUTEX_LOCK + * remove entry (cpu1, addr1) + * MUTEX_UNLOCK + * + * In above case, we may see (cpu1, addr1) and (cpu1, addr2) entries to + * appear together at [A], when it gets the lock before the resolve + * thread. Use this counter to maintain such case, and only when it + * reaches zero we know the vCPU is not blocked anymore. + * + * CASE (2): theoretically (the author admit to not have verified + * this..), one vCPU thread can also generate more than one userfaultfd + * message on the same address. It can happen e.g. for whatever reason + * the fault got retried before a resolution arrives. In that extremely + * rare case, we could also see two (cpu1, addr1) entries. + * + * In all cases, be prepared with such re-entrancies with this array. + * + * Using uint8_t should be far enough for now. For example, when + * there're only one resolve thread (postcopy ram listening thread), + * the max (concurrent fault entries) should be two. + */ + uint8_t *vcpu_faults_current; + /* + * The hash that contains addr1->[(cpu1,ts1),(cpu2,ts2) ...] mappings. + * Each of the entry is a tuple of (CPU index, fault timestamp) showing + * that a fault was requested. + */ + GHashTable *vcpu_addr_hash; /* total blocktime when all vCPUs are stopped */ uint64_t total_blocktime; /* point in time when last page fault was initiated */ @@ -145,13 +200,38 @@ typedef struct PostcopyBlocktimeContext { Notifier exit_notifier; } PostcopyBlocktimeContext; =20 +typedef struct { + /* The time the fault was triggered */ + uint64_t fault_time; + /* The vCPU index that was blocked */ + int cpu; +} BlocktimeVCPUEntry; + +/* Alloc an entry to record a vCPU fault */ +static BlocktimeVCPUEntry * +blocktime_vcpu_entry_alloc(int cpu, uint64_t fault_time) +{ + BlocktimeVCPUEntry *entry =3D g_new(BlocktimeVCPUEntry, 1); + + entry->fault_time =3D fault_time; + entry->cpu =3D cpu; + + return entry; +} + +/* Free a @GList of @BlocktimeVCPUEntry */ +static void blocktime_vcpu_list_free(gpointer data) +{ + g_list_free_full(data, g_free); +} + static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx) { g_hash_table_destroy(ctx->tid_to_vcpu_hash); - g_free(ctx->vcpu_blocktime_start); + g_hash_table_destroy(ctx->vcpu_addr_hash); g_free(ctx->vcpu_blocktime_total); g_free(ctx->vcpu_faults_count); - g_free(ctx->vcpu_addr); + g_free(ctx->vcpu_faults_current); g_free(ctx); } =20 @@ -198,12 +278,22 @@ static struct PostcopyBlocktimeContext *blocktime_con= text_new(void) unsigned int smp_cpus =3D ms->smp.cpus; PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); =20 - ctx->vcpu_blocktime_start =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_faults_count =3D g_new0(uint64_t, smp_cpus); - ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); + ctx->vcpu_faults_current =3D g_new0(uint8_t, smp_cpus); ctx->tid_to_vcpu_hash =3D blocktime_init_tid_to_vcpu_hash(); =20 + /* + * The key (host virtual addresses) will always be gpointer-sized on + * either 32bits or 64bits systems, so it'll fit as a direct key. + * + * The value will be a list of BlocktimeVCPUEntry entries. + */ + ctx->vcpu_addr_hash =3D g_hash_table_new_full(g_direct_hash, + g_direct_equal, + NULL, + blocktime_vcpu_list_free); + ctx->exit_notifier.notify =3D migration_exit_cb; qemu_add_exit_notifier(&ctx->exit_notifier); =20 @@ -893,6 +983,39 @@ static uint64_t get_current_ns(void) return (uint64_t)qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 +/* Inject an (cpu, fault_time) entry into the database, using addr as key = */ +static void blocktime_fault_inject(PostcopyBlocktimeContext *ctx, + uintptr_t addr, int cpu, uint64_t time) +{ + BlocktimeVCPUEntry *entry =3D blocktime_vcpu_entry_alloc(cpu, time); + GHashTable *table =3D ctx->vcpu_addr_hash; + gpointer key =3D (gpointer)addr; + GList *head, *list; + gboolean result; + + head =3D g_hash_table_lookup(table, key); + if (head) { + /* + * If existed, steal the @head for list operation rather than + * freeing it, making sure steal succeeded. + */ + result =3D g_hash_table_steal(table, key); + assert(result =3D=3D TRUE); + } + + /* + * Now the key is guaranteed to be absent. Two cases: + * + * (1) There's no existing entry, list contains the only one. Insert. + * (2) There're existing entries, after stealing we own it, prepend the + * result and re-insert. + */ + list =3D g_list_prepend(head, entry); + g_hash_table_insert(table, key, list); + + trace_postcopy_blocktime_begin(addr, time, cpu, !!head); +} + /* * This function is being called when pagefault occurs. It tracks down vCPU * blocking time. It's protected by @page_request_mutex. @@ -912,30 +1035,74 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, u= int32_t ptid, if (!dc || ptid =3D=3D 0) { return; } + + /* + * The caller should only inject a blocktime entry when the page is + * yet missing. + */ + assert(!ramblock_recv_bitmap_test(rb, (void *)addr)); + + current =3D get_current_ns(); cpu =3D blocktime_get_vcpu(dc, ptid); - if (cpu < 0) { + + if (cpu >=3D 0) { + /* How many faults on this vCPU in total? */ + dc->vcpu_faults_count[cpu]++; + + /* + * Account how many concurrent faults on this vCPU we trapped. See + * comments above vcpu_faults_current[] on why it can be more than= one. + */ + if (dc->vcpu_faults_current[cpu]++ =3D=3D 0) { + dc->smp_cpus_down++; + /* + * We use last_begin to cover (1) the 1st fault on this specif= ic + * vCPU, but meanwhile (2) the last vCPU that got blocked. It= 's + * only used to calculate system-wide blocktime. + */ + dc->last_begin =3D current; + } + + /* Making sure it won't overflow - it really should never! */ + assert(dc->vcpu_faults_current[cpu] <=3D 255); + } else { + /* We do not support non-vCPU thread tracking yet */ dc->non_vcpu_faults++; return; } =20 - current =3D get_current_ns(); - if (dc->vcpu_addr[cpu] =3D=3D 0) { - dc->smp_cpus_down++; - } + blocktime_fault_inject(dc, addr, cpu, current); +} =20 - dc->last_begin =3D current; - dc->vcpu_blocktime_start[cpu] =3D current; - dc->vcpu_addr[cpu] =3D addr; - dc->vcpu_faults_count[cpu]++; +typedef struct { + PostcopyBlocktimeContext *ctx; + uint64_t current; + int affected_cpus; +} BlockTimeVCPUIter; + +static void blocktime_cpu_list_iter_fn(gpointer data, gpointer user_data) +{ + BlockTimeVCPUIter *iter =3D user_data; + PostcopyBlocktimeContext *ctx =3D iter->ctx; + BlocktimeVCPUEntry *entry =3D data; + int cpu =3D entry->cpu; =20 /* - * The caller should only inject a blocktime entry when the page is - * yet missing. + * Time should never go back.. so when the fault is resolved it must be + * later than when it was faulted. */ - assert(!ramblock_recv_bitmap_test(rb, (void *)addr)); + assert(iter->current >=3D entry->fault_time); + + /* + * If we resolved all pending faults on one vCPU due to this page + * resolution, take a note. + */ + if (--ctx->vcpu_faults_current[cpu] =3D=3D 0) { + ctx->vcpu_blocktime_total[cpu] +=3D iter->current - entry->fault_t= ime; + iter->affected_cpus +=3D 1; + } =20 - trace_mark_postcopy_blocktime_begin(addr, dc->vcpu_blocktime_start[cpu= ], - cpu); + trace_postcopy_blocktime_end_one(cpu, ctx->vcpu_faults_current[cpu]); } =20 /* @@ -971,43 +1138,43 @@ static void mark_postcopy_blocktime_end(uintptr_t ad= dr) PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; MachineState *ms =3D MACHINE(qdev_get_machine()); unsigned int smp_cpus =3D ms->smp.cpus; - int i, affected_cpu =3D 0; - uint64_t read_vcpu_time, current; + BlockTimeVCPUIter iter =3D { + .current =3D get_current_ns(), + .affected_cpus =3D 0, + .ctx =3D dc, + }; + gpointer key =3D (gpointer)addr; + GHashTable *table; + GList *list; =20 if (!dc) { return; } =20 - current =3D get_current_ns(); - /* lookup cpu, to clear it, - * that algorithm looks straightforward, but it's not - * optimal, more optimal algorithm is keeping tree or hash - * where key is address value is a list of */ - for (i =3D 0; i < smp_cpus; i++) { - uint64_t vcpu_blocktime =3D 0; - - read_vcpu_time =3D dc->vcpu_blocktime_start[i]; - if (dc->vcpu_addr[i] !=3D addr || read_vcpu_time =3D=3D 0) { - continue; - } - dc->vcpu_addr[i] =3D 0; - vcpu_blocktime =3D current - read_vcpu_time; - affected_cpu +=3D 1; - /* continue cycle, due to one page could affect several vCPUs */ - dc->vcpu_blocktime_total[i] +=3D vcpu_blocktime; + table =3D dc->vcpu_addr_hash; + /* the address wasn't tracked at all? */ + list =3D g_hash_table_lookup(table, key); + if (!list) { + return; } =20 + /* + * Loop over the set of vCPUs that got blocked on this addr, do the + * blocktime accounting. After that, remove the whole list. + */ + g_list_foreach(list, blocktime_cpu_list_iter_fn, &iter); + g_hash_table_remove(table, key); + /* * If all vCPUs used to be down, and copying this page would free some * vCPUs, then the system-level blocktime ends here. */ - if (dc->smp_cpus_down =3D=3D smp_cpus && affected_cpu) { - dc->total_blocktime +=3D current - dc->last_begin; + if (dc->smp_cpus_down =3D=3D smp_cpus && iter.affected_cpus) { + dc->total_blocktime +=3D iter.current - dc->last_begin; } - dc->smp_cpus_down -=3D affected_cpu; + dc->smp_cpus_down -=3D iter.affected_cpus; =20 - trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, - affected_cpu); + trace_postcopy_blocktime_end(addr, iter.current, iter.affected_cpus); } =20 static void postcopy_pause_fault_thread(MigrationIncomingState *mis) diff --git a/migration/trace-events b/migration/trace-events index 9c1f3b7044..a36a78f01a 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -285,8 +285,6 @@ postcopy_nhp_range(const char *ramblock, void *host_add= r, size_t offset, size_t postcopy_place_page(void *host_addr) "host=3D%p" postcopy_place_page_zero(void *host_addr) "host=3D%p" postcopy_ram_enable_notify(void) "" -mark_postcopy_blocktime_begin(uint64_t addr, uint64_t time, int cpu) "addr= : 0x%" PRIx64 ", time: %" PRIu64 ", cpu: %d" -mark_postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu= ) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus: %d" postcopy_pause_fault_thread(void) "" postcopy_pause_fault_thread_continued(void) "" postcopy_pause_fast_load(void) "" @@ -311,6 +309,9 @@ postcopy_preempt_new_channel(void) "" postcopy_preempt_thread_entry(void) "" postcopy_preempt_thread_exit(void) "" postcopy_blocktime_tid_cpu_map(int cpu, uint32_t tid) "cpu: %d, tid: %u" +postcopy_blocktime_begin(uint64_t addr, uint64_t time, int cpu, bool exist= s) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", cpu: %d, exist: %d" +postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu) "ad= dr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus: %d" +postcopy_blocktime_end_one(int cpu, uint8_t left_faults) "cpu: %d, left_fa= ults: %" PRIu8 =20 # exec.c migration_exec_outgoing(const char *cmd) "cmd=3D%s" --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824100; cv=none; d=zohomail.com; s=zohoarc; b=DERxrKl32HRxeqh6nK6YLZg4WjjtveZCM8AWTxBpMos0QmwUx2Srx3hmdOrqhvfYvjSMiLJJsfI8l+DBnNUy7xFYmuVgHRjOX86yy5acx+Tr2TO4WHBxbrDgENzNkT5GdJqU3FJIFzP/whjbpdjhHfULweehx++J1zcXn+ncMvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824100; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2Ovn9cHFbbOnzTL416BsSHaOjwFIm9cgFfee3HTO6y8=; b=E+mIaNiS7CuHQpN83b7LthiDHqTji4fp6nNVm/Aj54HkkSIZEbz/zRFnnX1L8Xzg7YoDsE/41TBkoOCjKwAyiecklKffu+PCY1MAh7HnohyQAHOtfqyLZPllWOIQhrqoyBjRIPFAFcnZGlsEhx+l4lLhkEcCcYHX0hE/nUl07SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824100968584.6648457070696; Fri, 13 Jun 2025 07:15:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59P-00044D-JX; Fri, 13 Jun 2025 10:12:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0003vi-Nk for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ596-0002Kk-N1 for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:45 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-q77b4VOKPl2HlPp3McsalA-1; Fri, 13 Jun 2025 10:12:39 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4a57fea76beso44151141cf.0 for ; Fri, 13 Jun 2025 07:12:39 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Ovn9cHFbbOnzTL416BsSHaOjwFIm9cgFfee3HTO6y8=; b=Q5qzH6CW9vOZy948uh0yo+RSLcPuekiI6dv2vyl81dlb9Irw6h7vjs+9hcDvB2m0GIHeoR QhTCPCY2ZZIBy6l2i2oTdvwS2WKh6lCqRdM2MgIZwyDtNuk0USpa4ACXXnozYpF0B/+CRv AnGJFwNLLzrUa1Z0fz7c8rcy92nJfOc= X-MC-Unique: q77b4VOKPl2HlPp3McsalA-1 X-Mimecast-MFC-AGG-ID: q77b4VOKPl2HlPp3McsalA_1749823958 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823958; x=1750428758; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Ovn9cHFbbOnzTL416BsSHaOjwFIm9cgFfee3HTO6y8=; b=O6xcONZxR5iZYnQ8Amfe2toI3TX6QKG8frD+yrUW7Err4V/wZkucdTZyTttMwhSSie LybD2SIzuKUPHBQtNPu0zh3gnYwW7DpdRsxV/M77JHq8X4K+XEC9YKyX51Ckpr1HKyal WlQJyMwX8tztU6RC+UV6ctVuw63QdBINtXhTWrGb7hd5hWd9wRQ+O2oFzaq+N/rr0n1v n2tPCxceFpxJVX8bq8aZW2RfOsEoQnZP/1iCaebp23kH+Ru7CG9Is6DR0ahF+tPwvYqf IaBRluDUeZYffXy57k5CR42oBOD/jGJIbwvHaBRNlke+DcY+tL96OeJidb9gxJph7KON QsNA== X-Gm-Message-State: AOJu0YwMusoHHFan47d7aXOjkhHa7Zl3WouJXsAEoFHKoZRbCkkDOUr8 m9jJE8RGrsmQFqapV0BJn6bKDFE0ZbhsAwxh5EGsnM+tt5aR+J2lE/iExWwG92gopsgkYiSafwc tEAtYFNncapZIUUjuxNt00yrwEowu5EMGy+C8hscNBO1gueYdPkePh4xlLGMfhDykBh+ZCLgtAB RvpyAtVUop2PTNzyoejj3Aj1uu6plnnD0Y0jx2cQ== X-Gm-Gg: ASbGncuB37hT+3YcxjHy5v5W9lzXFUYOHrURLedCHSifO/klOKe+CFdUscG83llgu6h xvjysjAkGF3Kt49eixBC+0Kk7vzTaKiOkM3lR+//JjcyfgNZFrvRPV4HHCP+zETOVviVlTC4j9V Z9OIrcSYYTC4f30F9QkpJJjT8EwMRxUv/03DNh/gULrBB3I9m4EFOYZR+luJS3KwbNNDzMKeIif b2OMPuLqScbFsNnPVDlQDoEXndf/GEnHu/2Z2ZUCfoPHQSlouV3CuJHQAsFPUvwKL1FAVrrfZXK p1n9Pvu0n6Q= X-Received: by 2002:a05:622a:580e:b0:4a6:eac8:58c6 with SMTP id d75a77b69052e-4a72fe7ac63mr65133621cf.13.1749823957439; Fri, 13 Jun 2025 07:12:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH/mc9he0aMumbb2nGu2xGorOI+nQbc920mlrtz3aeGfGomLV9dX5oLkQ7B/gtIjTlI/2XnA== X-Received: by 2002:a05:622a:580e:b0:4a6:eac8:58c6 with SMTP id d75a77b69052e-4a72fe7ac63mr65132811cf.13.1749823956507; Fri, 13 Jun 2025 07:12:36 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas , Markus Armbruster Subject: [PATCH v3 13/14] migration/postcopy: blocktime allows track / report non-vCPU faults Date: Fri, 13 Jun 2025 10:12:16 -0400 Message-ID: <20250613141217.474825-14-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824102088116600 Content-Type: text/plain; charset="utf-8" When used to report page fault latencies, the blocktime feature can be almost useless when KVM async page fault is enabled, because in most cases such remote fault will kickoff async page faults, then it's not trackable from blocktime layer. After all these recent rewrites to blocktime layer, it's finally so easy to also support tracking non-vCPU faults. It'll be even faster if we could always index fault records with TIDs, unfortunately we need to maintain the blocktime API which report things in vCPU indexes. Of course this can work not only for kworkers, but also any guest accesses that may reach a missing page, for example, very likely when in the QEMU main thread too (and all other threads whenever applicable). In this case, we don't care about "how long the threads are blocked", but we only care about "how long the fault will be resolved". Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Reviewed-by: Fabiano Rosas Tested-by: Mario Casquero Signed-off-by: Peter Xu --- qapi/migration.json | 12 ++++- migration/migration-hmp-cmds.c | 5 +++ migration/postcopy-ram.c | 64 +++++++++++++++++++++------ tests/qtest/migration/migration-qmp.c | 1 + migration/trace-events | 2 +- 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 30302f36cf..0f5b2d914c 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -247,6 +247,12 @@ # this is the per-vCPU statistics. This is only present when the # postcopy-blocktime migration capability is enabled. (Since 10.1) # +# @postcopy-non-vcpu-latency: average remote page fault latency for all +# faults happend in non-vCPU threads (in ns). It has the same +# definition of @postcopy-latency but this only provides statistics to +# non-vCPU faults. This is only present when the postcopy-blocktime +# migration capability is enabled. (Since 10.1) +# # @socket-address: Only used for tcp, to know what the real port is # (Since 4.0) # @@ -273,8 +279,8 @@ # # Features: # -# @unstable: Members @postcopy-latency, @postcopy-vcpu-latency are -# experimental. +# @unstable: Members @postcopy-latency, @postcopy-vcpu-latency, +# @postcopy-non-vcpu-latency are experimental. # # Since: 0.14 ## @@ -295,6 +301,8 @@ 'type': 'uint64', 'features': [ 'unstable' ] }, '*postcopy-vcpu-latency': { 'type': ['uint64'], 'features': [ 'unstable' ] }, + '*postcopy-non-vcpu-latency': { + 'type': 'uint64', 'features': [ 'unstable' ] }, '*socket-address': ['SocketAddress'], '*dirty-limit-throttle-time-per-round': 'uint64', '*dirty-limit-ring-full-time': 'uint64'} } diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 8b3846dab5..e1f9530520 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -80,6 +80,11 @@ static void migration_dump_blocktime(Monitor *mon, Migra= tionInfo *info) info->postcopy_latency); } =20 + if (info->has_postcopy_non_vcpu_latency) { + monitor_printf(mon, "Postcopy non-vCPU Latencies (ns): %" PRIu64 "= \n", + info->postcopy_non_vcpu_latency); + } + if (info->has_postcopy_vcpu_latency) { uint64List *item =3D info->postcopy_vcpu_latency; const char *sep =3D ""; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 91c23b446e..f4cb23b3e0 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -192,6 +192,8 @@ typedef struct PostcopyBlocktimeContext { GHashTable *tid_to_vcpu_hash; /* Count of non-vCPU faults. This is only for debugging purpose. */ uint64_t non_vcpu_faults; + /* total blocktime when a non-vCPU thread is stopped */ + uint64_t non_vcpu_blocktime_total; =20 /* * Handler for exit event, necessary for @@ -203,7 +205,10 @@ typedef struct PostcopyBlocktimeContext { typedef struct { /* The time the fault was triggered */ uint64_t fault_time; - /* The vCPU index that was blocked */ + /* + * The vCPU index that was blocked, when cpu=3D=3D-1, it means it's a + * fault from non-vCPU threads. + */ int cpu; } BlocktimeVCPUEntry; =20 @@ -344,6 +349,12 @@ void fill_destination_postcopy_migration_info(Migratio= nInfo *info) QAPI_LIST_PREPEND(list_latency, latency); } =20 + latency_total +=3D bc->non_vcpu_blocktime_total; + faults +=3D bc->non_vcpu_faults; + + info->has_postcopy_non_vcpu_latency =3D true; + info->postcopy_non_vcpu_latency =3D bc->non_vcpu_faults ? + (bc->non_vcpu_blocktime_total / bc->non_vcpu_faults) : 0; info->has_postcopy_blocktime =3D true; /* Convert ns -> ms */ info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / SCALE_MS= ); @@ -983,7 +994,10 @@ static uint64_t get_current_ns(void) return (uint64_t)qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 -/* Inject an (cpu, fault_time) entry into the database, using addr as key = */ +/* + * Inject an (cpu, fault_time) entry into the database, using addr as key. + * When cpu=3D=3D-1, it means it's a non-vCPU fault. + */ static void blocktime_fault_inject(PostcopyBlocktimeContext *ctx, uintptr_t addr, int cpu, uint64_t time) { @@ -1066,9 +1080,17 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, u= int32_t ptid, /* Making sure it won't overflow - it really should never! */ assert(dc->vcpu_faults_current[cpu] <=3D 255); } else { - /* We do not support non-vCPU thread tracking yet */ + /* + * For non-vCPU thread faults, we don't care about tid or cpu index + * or time the thread is blocked (e.g., a kworker trying to help + * KVM when async_pf=3Don is OK to be blocked and not affect guest + * responsiveness), but we care about latency. Track it with + * cpu=3D-1. + * + * Note that this will NOT affect blocktime reports on vCPU being + * blocked, but only about system-wide latency reports. + */ dc->non_vcpu_faults++; - return; } =20 blocktime_fault_inject(dc, addr, cpu, current); @@ -1078,6 +1100,7 @@ typedef struct { PostcopyBlocktimeContext *ctx; uint64_t current; int affected_cpus; + int affected_non_cpus; } BlockTimeVCPUIter; =20 static void blocktime_cpu_list_iter_fn(gpointer data, gpointer user_data) @@ -1085,6 +1108,7 @@ static void blocktime_cpu_list_iter_fn(gpointer data,= gpointer user_data) BlockTimeVCPUIter *iter =3D user_data; PostcopyBlocktimeContext *ctx =3D iter->ctx; BlocktimeVCPUEntry *entry =3D data; + uint64_t time_passed; int cpu =3D entry->cpu; =20 /* @@ -1092,17 +1116,27 @@ static void blocktime_cpu_list_iter_fn(gpointer dat= a, gpointer user_data) * later than when it was faulted. */ assert(iter->current >=3D entry->fault_time); + time_passed =3D iter->current - entry->fault_time; =20 - /* - * If we resolved all pending faults on one vCPU due to this page - * resolution, take a note. - */ - if (--ctx->vcpu_faults_current[cpu] =3D=3D 0) { - ctx->vcpu_blocktime_total[cpu] +=3D iter->current - entry->fault_t= ime; - iter->affected_cpus +=3D 1; + if (cpu >=3D 0) { + /* + * If we resolved all pending faults on one vCPU due to this page + * resolution, take a note. + */ + if (--ctx->vcpu_faults_current[cpu] =3D=3D 0) { + ctx->vcpu_blocktime_total[cpu] +=3D time_passed; + iter->affected_cpus +=3D 1; + } + trace_postcopy_blocktime_end_one(cpu, ctx->vcpu_faults_current[cpu= ]); + } else { + iter->affected_non_cpus++; + ctx->non_vcpu_blocktime_total +=3D time_passed; + /* + * We do not maintain how many pending non-vCPU faults because we + * do not care about blocktime, only latency. + */ + trace_postcopy_blocktime_end_one(-1, 0); } - - trace_postcopy_blocktime_end_one(cpu, ctx->vcpu_faults_current[cpu]); } =20 /* @@ -1141,6 +1175,7 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) BlockTimeVCPUIter iter =3D { .current =3D get_current_ns(), .affected_cpus =3D 0, + .affected_non_cpus =3D 0, .ctx =3D dc, }; gpointer key =3D (gpointer)addr; @@ -1174,7 +1209,8 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) } dc->smp_cpus_down -=3D iter.affected_cpus; =20 - trace_postcopy_blocktime_end(addr, iter.current, iter.affected_cpus); + trace_postcopy_blocktime_end(addr, iter.current, iter.affected_cpus, + iter.affected_non_cpus); } =20 static void postcopy_pause_fault_thread(MigrationIncomingState *mis) diff --git a/tests/qtest/migration/migration-qmp.c b/tests/qtest/migration/= migration-qmp.c index 1a5ab2d229..67a67d4bd6 100644 --- a/tests/qtest/migration/migration-qmp.c +++ b/tests/qtest/migration/migration-qmp.c @@ -361,6 +361,7 @@ void read_blocktime(QTestState *who) g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-blocktime")); g_assert(qdict_haskey(rsp_return, "postcopy-latency")); g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-latency")); + g_assert(qdict_haskey(rsp_return, "postcopy-non-vcpu-latency")); qobject_unref(rsp_return); } =20 diff --git a/migration/trace-events b/migration/trace-events index a36a78f01a..706db97def 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -310,7 +310,7 @@ postcopy_preempt_thread_entry(void) "" postcopy_preempt_thread_exit(void) "" postcopy_blocktime_tid_cpu_map(int cpu, uint32_t tid) "cpu: %d, tid: %u" postcopy_blocktime_begin(uint64_t addr, uint64_t time, int cpu, bool exist= s) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", cpu: %d, exist: %d" -postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu) "ad= dr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus: %d" +postcopy_blocktime_end(uint64_t addr, uint64_t time, int affected_cpu, int= affected_non_cpus) "addr: 0x%" PRIx64 ", time: %" PRIu64 ", affected_cpus:= %d, affected_non_cpus: %d" postcopy_blocktime_end_one(int cpu, uint8_t left_faults) "cpu: %d, left_fa= ults: %" PRIu8 =20 # exec.c --=20 2.49.0 From nobody Sat Nov 15 15:41:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1749824018; cv=none; d=zohomail.com; s=zohoarc; b=fifYCcOqQ1u4CZ9tVQa8BIJ20u4vR/FLfErP6sqguMC41j39bEzJ4D7aReV83vKMGVhbQQ0wvcyaan1mMP1QhciBzE1z9yCRBbGxJPfQyrny+112MFBMC+KCsyaPud57Jz6fqUIWwlqlrDzselKVtN+9y5B1E7RIM4rxubm69Us= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749824018; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3i05mM5Kf5Mf9n3r0qpk8pmYqkJYk9eZcgiq02HTyoE=; b=IxlXEZJqUMdmjtolXOxxy5RAWogEHAuhBjMFvTHXygsA/HlITI/820Mx+vWvlZelaYPurGDYZ75Sx+DcgyQHwx/v56gR15fORpSbgnC+23HneEOOv0WIe/Tz+CXUtS+HFA+JeTktQhD+7/p4ySttnnghTwoSvhVQeKNmfELic8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749824018430878.1479947603245; Fri, 13 Jun 2025 07:13:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uQ59J-0003zw-LD; Fri, 13 Jun 2025 10:12:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59H-0003yw-VY for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQ59E-0002MP-FW for qemu-devel@nongnu.org; Fri, 13 Jun 2025 10:12:51 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-Nv_kLPq5NxW7m72BremU9A-1; Fri, 13 Jun 2025 10:12:41 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4a5882b7339so25650011cf.2 for ; Fri, 13 Jun 2025 07:12:41 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a72a526cc6sm17141641cf.79.2025.06.13.07.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 07:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749823965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3i05mM5Kf5Mf9n3r0qpk8pmYqkJYk9eZcgiq02HTyoE=; b=UQM+3PIhE1V19ReYVrR1AQjz/SubhL8nX/2a3LIhp64JfgsnTcopDl2IaCVN4fcLiKUNI+ tlUHzNnADn9L1ASVrWMUQNzbW4177h7TtQZh/M7zR2ZrxjEQi187KKfCMUrBWy2x8L6BCH i77SzEITmzit7rWzckC28V5v7nqQvBk= X-MC-Unique: Nv_kLPq5NxW7m72BremU9A-1 X-Mimecast-MFC-AGG-ID: Nv_kLPq5NxW7m72BremU9A_1749823960 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749823960; x=1750428760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3i05mM5Kf5Mf9n3r0qpk8pmYqkJYk9eZcgiq02HTyoE=; b=THvQW0brj/Lu19hcThNr6O5I1sGOR6vYyvgRmKqOuz3joQLziWs0Z3pDlTF38W58Vq KhfniMR3ZFSQXXsiaiDNAv4e6hj/kylSV9Oobqxqy4TcTL8rdOUt3gkcquzp01jR3pyy Fad5401Q3tyVrQCfQK+FflqjBlp0dgnCz9nM2++QAQ0i5hmHAvkCYTO0GtIttKhc9tYN QRQI0gcCoFuG5AdWFgYSZ9V/ypMCZ8vW16a12PmjmtO3lJMzlaO2TRRipd3bOt9DtQnq nN8sG7vL1hWovmt2lEdrwM41z/xc9KLrwRJVHBsyqp+alL/zNgpDJmvVs2EpeNZOrsWL MrOw== X-Gm-Message-State: AOJu0YzsMbjsq6Py9APBctSqILyf3bw2BaQe4inrdG6/dG2BI+2QXAZy OFwEXVPY4gqvDL+z8sjvoPXftSYmBSrC0e7ctOHD9/I+PC+LzOgPTj84BMJnkfPpnIW0/dQSrIV xC4A/chl0i7FFzKU2EqcdvfqW1LV1hMomYJmBrQ8OunK/zQWybq0IfH7wojD++ET8cBx7XE9jpB z+Ww8WMXsHJGJyT9S566PkmH2UgULaobZ1mPcmMQ== X-Gm-Gg: ASbGncu4/G1g8o05BLrCmDkjLdMDuhw6JMysdqYH0IcICJIZMZGgoZomQhj2qVAV8CT dOI61SqsVHui17C0RdcRQJEzMgw/fdfg39TA0ZY7xhcfAwITMFBdNqBTZ/F26bQscBIS8vVLjlB MFHzdxrdLlahwAhJdg9b7GtnOHv+vfhfhnfTbdRr+86U4Q9BtSiTa1mQ/2V9T/KB/xB5NllpZoH itYXzT7LENduT9X2e9LFSlwdJbcCj3to4j/BGP+SXN9rQ1WMCAlzEQTw5V+QYdTYYVuMo/+6vcB 6MMizeViwy4= X-Received: by 2002:ac8:5cd0:0:b0:4a7:14c4:2385 with SMTP id d75a77b69052e-4a72ff1c496mr44385601cf.42.1749823958825; Fri, 13 Jun 2025 07:12:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEM4VKkG3eFF/XRZsyNegzjZLfmIEDQQdj8yUhuoeLUmZXRuneVPxLmZPtzuh7uOa5S5di6/g== X-Received: by 2002:ac8:5cd0:0:b0:4a7:14c4:2385 with SMTP id d75a77b69052e-4a72ff1c496mr44384921cf.42.1749823958041; Fri, 13 Jun 2025 07:12:38 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Mario Casquero , Alexey Perevalov , "Dr . David Alan Gilbert" , peterx@redhat.com, Juraj Marcin , Fabiano Rosas , Markus Armbruster Subject: [PATCH v3 14/14] migration/postcopy: Add latency distribution report for blocktime Date: Fri, 13 Jun 2025 10:12:17 -0400 Message-ID: <20250613141217.474825-15-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613141217.474825-1-peterx@redhat.com> References: <20250613141217.474825-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1749824020588116600 Content-Type: text/plain; charset="utf-8" Add the latency distribution too for blocktime, using order-of-two buckets. It accounts for all the faults, from either vCPU or non-vCPU threads. With prior rework, it's very easy to achieve by adding an array to account for faults in each buckets. Sample output for HMP (while for QMP it's simply an array): Postcopy Latency Distribution: [ 1 us - 2 us ]: 0 [ 2 us - 4 us ]: 0 [ 4 us - 8 us ]: 1 [ 8 us - 16 us ]: 2 [ 16 us - 32 us ]: 2 [ 32 us - 64 us ]: 3 [ 64 us - 128 us ]: 10169 [ 128 us - 256 us ]: 50151 [ 256 us - 512 us ]: 12876 [ 512 us - 1 ms ]: 97 [ 1 ms - 2 ms ]: 42 [ 2 ms - 4 ms ]: 44 [ 4 ms - 8 ms ]: 93 [ 8 ms - 16 ms ]: 138 [ 16 ms - 32 ms ]: 0 [ 32 ms - 65 ms ]: 0 [ 65 ms - 131 ms ]: 0 [ 131 ms - 262 ms ]: 0 [ 262 ms - 524 ms ]: 0 [ 524 ms - 1 sec ]: 0 [ 1 sec - 2 sec ]: 0 [ 2 sec - 4 sec ]: 0 [ 4 sec - 8 sec ]: 0 [ 8 sec - 16 sec ]: 0 Cc: Markus Armbruster Acked-by: Dr. David Alan Gilbert Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- qapi/migration.json | 12 ++++++- migration/migration-hmp-cmds.c | 32 +++++++++++++++++++ migration/postcopy-ram.c | 46 +++++++++++++++++++++++++++ tests/qtest/migration/migration-qmp.c | 1 + 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/qapi/migration.json b/qapi/migration.json index 0f5b2d914c..d3016c0b94 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -242,6 +242,14 @@ # average page fault latency. This is only present when the # postcopy-blocktime migration capability is enabled. (Since 10.1) # +# @postcopy-latency-dist: remote page fault latency distributions. Each +# element of the array is the number of faults that fall into the +# bucket period. For the N-th bucket (N>=3D0), the latency window is +# [2^Nus, 2^(N+1)us). For example, the 8th element stores how many +# remote faults got resolved within [256us, 512us) window. This is only +# present when the postcopy-blocktime migration capability is enabled. +# (Since 10.1) +# # @postcopy-vcpu-latency: average remote page fault latency per vCPU (in # ns). It has the same definition of @postcopy-latency, but instead # this is the per-vCPU statistics. This is only present when the @@ -280,7 +288,7 @@ # Features: # # @unstable: Members @postcopy-latency, @postcopy-vcpu-latency, -# @postcopy-non-vcpu-latency are experimental. +# @postcopy-latency-dist, @postcopy-non-vcpu-latency are experimental. # # Since: 0.14 ## @@ -299,6 +307,8 @@ '*postcopy-vcpu-blocktime': ['uint32'], '*postcopy-latency': { 'type': 'uint64', 'features': [ 'unstable' ] }, + '*postcopy-latency-dist': { + 'type': ['uint64'], 'features': [ 'unstable' ] }, '*postcopy-vcpu-latency': { 'type': ['uint64'], 'features': [ 'unstable' ] }, '*postcopy-non-vcpu-latency': { diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index e1f9530520..cef5608210 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -52,6 +52,21 @@ static void migration_global_dump(Monitor *mon) ms->clear_bitmap_shift); } =20 +static const gchar *format_time_str(uint64_t us) +{ + const char *units[] =3D {"us", "ms", "sec"}; + int index =3D 0; + + while (us > 1000) { + us /=3D 1000; + if (++index >=3D (sizeof(units) - 1)) { + break; + } + } + + return g_strdup_printf("%"PRIu64" %s", us, units[index]); +} + static void migration_dump_blocktime(Monitor *mon, MigrationInfo *info) { if (info->has_postcopy_blocktime) { @@ -100,6 +115,23 @@ static void migration_dump_blocktime(Monitor *mon, Mig= rationInfo *info) } monitor_printf(mon, "]\n"); } + + if (info->has_postcopy_latency_dist) { + uint64List *item =3D info->postcopy_latency_dist; + int count =3D 0; + + monitor_printf(mon, "Postcopy Latency Distribution:\n"); + + while (item) { + g_autofree const gchar *from =3D format_time_str(1UL << count); + g_autofree const gchar *to =3D format_time_str(1UL << (count += 1)); + + monitor_printf(mon, " [ %8s - %8s ]: %10"PRIu64"\n", + from, to, item->value); + item =3D item->next; + count++; + } + } } =20 void hmp_info_migrate(Monitor *mon, const QDict *qdict) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index f4cb23b3e0..45af9a361e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -110,6 +110,15 @@ void postcopy_thread_create(MigrationIncomingState *mi= s, #include #include =20 +/* + * Here we use 24 buckets, which means the last bucket will cover [2^24 us, + * 2^25 us) ~=3D [16, 32) seconds. It should be far enough to record even + * extreme (perf-wise broken) 1G pages moving over, which can sometimes + * take a few seconds due to various reasons. Anything more than that + * might be unsensible to account anymore. + */ +#define BLOCKTIME_LATENCY_BUCKET_N (24) + /* All the time records are in unit of nanoseconds */ typedef struct PostcopyBlocktimeContext { /* blocktime per vCPU */ @@ -175,6 +184,11 @@ typedef struct PostcopyBlocktimeContext { * that a fault was requested. */ GHashTable *vcpu_addr_hash; + /* + * Each bucket stores the count of faults that were resolved within the + * bucket window [2^N us, 2^(N+1) us). + */ + uint64_t latency_buckets[BLOCKTIME_LATENCY_BUCKET_N]; /* total blocktime when all vCPUs are stopped */ uint64_t total_blocktime; /* point in time when last page fault was initiated */ @@ -283,6 +297,9 @@ static struct PostcopyBlocktimeContext *blocktime_conte= xt_new(void) unsigned int smp_cpus =3D ms->smp.cpus; PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); =20 + /* Initialize all counters to be zeros */ + memset(ctx->latency_buckets, 0, sizeof(ctx->latency_buckets)); + ctx->vcpu_blocktime_total =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_faults_count =3D g_new0(uint64_t, smp_cpus); ctx->vcpu_faults_current =3D g_new0(uint8_t, smp_cpus); @@ -320,6 +337,7 @@ void fill_destination_postcopy_migration_info(Migration= Info *info) uint64_t latency_total =3D 0, faults =3D 0; uint32List *list_blocktime =3D NULL; uint64List *list_latency =3D NULL; + uint64List *latency_buckets =3D NULL; int i; =20 if (!bc) { @@ -349,6 +367,10 @@ void fill_destination_postcopy_migration_info(Migratio= nInfo *info) QAPI_LIST_PREPEND(list_latency, latency); } =20 + for (i =3D BLOCKTIME_LATENCY_BUCKET_N - 1; i >=3D 0; i--) { + QAPI_LIST_PREPEND(latency_buckets, bc->latency_buckets[i]); + } + latency_total +=3D bc->non_vcpu_blocktime_total; faults +=3D bc->non_vcpu_faults; =20 @@ -364,6 +386,8 @@ void fill_destination_postcopy_migration_info(Migration= Info *info) info->postcopy_latency =3D faults ? (latency_total / faults) : 0; info->has_postcopy_vcpu_latency =3D true; info->postcopy_vcpu_latency =3D list_latency; + info->has_postcopy_latency_dist =3D true; + info->postcopy_latency_dist =3D latency_buckets; } =20 static uint64_t get_postcopy_total_blocktime(void) @@ -1096,6 +1120,25 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, u= int32_t ptid, blocktime_fault_inject(dc, addr, cpu, current); } =20 +static void blocktime_latency_account(PostcopyBlocktimeContext *ctx, + uint64_t time_us) +{ + /* + * Convert time (in us) to bucket index it belongs. Take extra caution + * of time_us=3D=3D0 even if normally rare - when happens put into buc= ket 0. + */ + int index =3D time_us ? (63 - clz64(time_us)) : 0; + + assert(index >=3D 0); + + /* If it's too large, put into top bucket */ + if (index >=3D BLOCKTIME_LATENCY_BUCKET_N) { + index =3D BLOCKTIME_LATENCY_BUCKET_N - 1; + } + + ctx->latency_buckets[index]++; +} + typedef struct { PostcopyBlocktimeContext *ctx; uint64_t current; @@ -1118,6 +1161,9 @@ static void blocktime_cpu_list_iter_fn(gpointer data,= gpointer user_data) assert(iter->current >=3D entry->fault_time); time_passed =3D iter->current - entry->fault_time; =20 + /* Latency buckets are in microseconds */ + blocktime_latency_account(ctx, time_passed / SCALE_US); + if (cpu >=3D 0) { /* * If we resolved all pending faults on one vCPU due to this page diff --git a/tests/qtest/migration/migration-qmp.c b/tests/qtest/migration/= migration-qmp.c index 67a67d4bd6..66dd369ba7 100644 --- a/tests/qtest/migration/migration-qmp.c +++ b/tests/qtest/migration/migration-qmp.c @@ -360,6 +360,7 @@ void read_blocktime(QTestState *who) g_assert(qdict_haskey(rsp_return, "postcopy-blocktime")); g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-blocktime")); g_assert(qdict_haskey(rsp_return, "postcopy-latency")); + g_assert(qdict_haskey(rsp_return, "postcopy-latency-dist")); g_assert(qdict_haskey(rsp_return, "postcopy-vcpu-latency")); g_assert(qdict_haskey(rsp_return, "postcopy-non-vcpu-latency")); qobject_unref(rsp_return); --=20 2.49.0