From nobody Sat Nov 15 17:17:24 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=1749496517; cv=none; d=zohomail.com; s=zohoarc; b=O+Br+cI40q5atWqX5OQ37WgoDphhKytggNSJ7CzVBA8pgi4LXyzX1xZ6YOTVa1vLnktkAd5dx3/BxzLtTBZ2oBLi2xg2+2gvU/paLrCS9lYzJt5yDxZGlahAjG/geapLxPuSHSC3Ilvom5dmCXx3+Z2XTSUPuuvFr8G1t2bMr3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496517; 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=nuuxlpF6kmP4FbMQaNgYdl91CZnlicaZb4EJhierK2hMWl2mvBAty4PFd3MzhfMZCegkwYB5l8LFHRsWi36i8Wu5+cveWJiqk82dlRlaeWcbDpTOAy1c3kca3SJpwqvz9p1rwQ9e/dVfGRItHLjBvYG4Se449OxpMquV2T1yWDI= 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 1749496517061293.27868580988195; Mon, 9 Jun 2025 12:15:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvl-0006Lf-HS; Mon, 09 Jun 2025 15:13:13 -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 1uOhvh-0006Kq-EW for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:09 -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 1uOhvf-0000ok-Us for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:09 -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-679-Q3YSRhm2NBG33xUOtRHzIw-1; Mon, 09 Jun 2025 15:13:05 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6faf265c3c5so72120916d6.2 for ; Mon, 09 Jun 2025 12:13:05 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496386; 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=cqCd0OoIn+ErY9gZDkWszwPfgQmEHf+iGdD5StBiK4+UsUYjRG16otuC5EAGoswdRxKI0s MpAm00+lKHJQXo4b2FJn6xBvLf0ZQ9n8YGIRGO8f36fXn6+JuL/XIGHsRYnxAxDIlee5EW +p/yszMMATFnkcRQW32LBgmK/iGPbBY= X-MC-Unique: Q3YSRhm2NBG33xUOtRHzIw-1 X-Mimecast-MFC-AGG-ID: Q3YSRhm2NBG33xUOtRHzIw_1749496385 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496384; x=1750101184; 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=gpx+vFCay6ZIcuL/Q1NYB7stPYBibXLKgZd/G5V4L/XVqUMDq9/F1lvldAqijApXaF 0ez26gN+oKzrfx3MOcbTvvjE8d8gcm3oboRGG6IxboGf05V3VfQZjUCGDXZRqRsRGad1 9nJujknfv6gyt2HarSa2zi/1vzW8TE0/Dw4hPbmCEPmQAWLxjEMktXAJgqYbs//jiOot X0il8Ne0u4j0L7nbSH/sAyxtDyqYaZrvIY/QbZi+IejRHsHh/mkLHTe+E83MnKrL/ktM JjscJHkNpTVwODgxtA21E7X7mZnpTXmSWRecv1b64q4sMWKQIlsIniyxElFyrU67uHkU KKow== X-Gm-Message-State: AOJu0YwibMTPlV415OqH+dQ8lqy+9dsJHpT7Wvjdv/3qrwNIMoZ1CYMv epquOc2tjXYF9HAG6Ax5LfdMLKXRs78iIX8DmCRJwR2h+IMqQQ6b10U6Fzhb9BD/DhG9fWKnpLv 95YJsl6cmY3GQ+dBhmvnV2CAGU7yKG54Sog97i8Wh1IRID/V/uH6XAwQI2zrINVQNaR/C+cLFN5 EGkouFEFIliriw5ipeMij/hTvBaJfqKKtJDFFKTA== X-Gm-Gg: ASbGncs8yph3tCAYAnTVG0XYFUGcBHNOGwmE3fr+Vk5issQyOF0tK6EmGC6xiaJ94pn gGRCm58hTlj8Xj314vKenzMPPCoSs1CVUjAA5G8oGtm0FsMEJYm7HhT8FqvauymfXHECu9BG9YG c4/SxqeacQ7gDcsMQB/ewSnFgSzBWkXTl4e7/dOyWb8mKDSLL5lFxVqACLeHTKCkeCiKP4QXx6c sev8g8oCaQ2gJe65Z8RM8e6f1yHXAIBbZbZB64WqTptXcPODXmXFO8CSNqpsDee5QuDp28J45AE 0FtcpouUbOIZxg== X-Received: by 2002:a05:6214:29cc:b0:6fa:c81a:6229 with SMTP id 6a1803df08f44-6fb08fcc259mr226146546d6.43.1749496384623; Mon, 09 Jun 2025 12:13:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFijfW9CUUQN92l3iNNEySwnpRNvuqGz3LPJQKj4Wl/cWm/l47MLB15yYT0zHThl2MUyA57EQ== X-Received: by 2002:a05:6214:29cc:b0:6fa:c81a:6229 with SMTP id 6a1803df08f44-6fb08fcc259mr226145986d6.43.1749496384019; Mon, 09 Jun 2025 12:13:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 01/13] migration: Add option to set postcopy-blocktime Date: Mon, 9 Jun 2025 15:12:47 -0400 Message-ID: <20250609191259.9053-2-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496517623116600 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 17:17:24 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=1749496475; cv=none; d=zohomail.com; s=zohoarc; b=af5g1jTpsuVkXlvlXKx+abJo3ih9OqzZz0VKNBnyoPcqnKDNfW+ok2IQqkdUmjQc0EynVaFAXdWcqn2ksRMQRfvUeWB14MVJ2Tj6IVcbZD8zFs5J9kS0OTwWAxIbRiA0lUMJWYWBqFlnTC390nuUD5Gj6gnEfn+F8uUfk6aY4aY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496475; 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=/eVrH2YKgcbkel/msblrk3JAeJ/hj/ZC+JOJooa/doo=; b=jXDF53rucqRjUaLvFKCuCADcvqd0BBxP7XztTAZeMcnFdGYw7Unfg5QolLZym5fJ5Iyzm/LnvtL9YMSlScS/xhV5bTo7uA6od1wZzQvtcStcGZfu9zeGsWJCuMOV55FdNLsXu3TQZHiHnahwqGtlSAG1daSv9fG9CY7uBxUK/ac= 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 174949647589595.67848148077223; Mon, 9 Jun 2025 12:14:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvl-0006M5-VV; Mon, 09 Jun 2025 15:13:14 -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 1uOhvj-0006L5-Bm for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:11 -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 1uOhvg-0000oq-GQ for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:10 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-2VOs_hxDO_i7jLEGNT9Pmg-1; Mon, 09 Jun 2025 15:13:06 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7c5bb68b386so461528585a.3 for ; Mon, 09 Jun 2025 12:13:06 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496387; 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=/eVrH2YKgcbkel/msblrk3JAeJ/hj/ZC+JOJooa/doo=; b=Iqqe/qPLDYHRvut3aJSYebBnpOgKm37AXyTeCDv2KW810nsih5sIM0aMHGYPUiiym58EPs 6WhAEiZ/r6uWDi+Cd2ZDedm2x/xSvDBMFRN+25eX9tOafDV0d9wV9mBZ3S6Pv3mRXzjnvI 9qk0QyF2OwePiL+tHo8kSN043MO12xo= X-MC-Unique: 2VOs_hxDO_i7jLEGNT9Pmg-1 X-Mimecast-MFC-AGG-ID: 2VOs_hxDO_i7jLEGNT9Pmg_1749496386 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496386; x=1750101186; 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=/eVrH2YKgcbkel/msblrk3JAeJ/hj/ZC+JOJooa/doo=; b=VfDiS63/v6+kSDhG9AMS2kIBWAgCFO7zEJNVGZxfdOoCrS+B0eZDu5Ehgx0aykXx5G SuHtFL49IFeDbtm9O9pvwoWpd7XKLDCllZTTUG3ji7w9P+B15YBQ5OiDDk3JNJr+CsfM 9ocApuf+yI9luHj4jTJMMYzBH6rhSZnlBe/NFkhrGu8i5+rgE8tkxT9bmzu7L3Uzgr4y cHEQKgjgU61/Xyg6ThRCAVuWWuzQQzdyRwTPq9GSIW4bR6wV8It9PTYlchHPqdtx22/W /4BdVaMN97RN0qyGHXCauWRqeBS+J0buaSBx+KplaAc/QpsDXyK8HErta2+TFaUuzE/n Xqeg== X-Gm-Message-State: AOJu0YzLLcDQO8TrUymLclSTS5ZfdUUqqFnVejAdie1AbblRoLr4mmFe 7fDiImNws6ViGGdb1cjDIgsGT5mwzCciM4mCRCXofU369Nb+a7yrYwNmUJMmaVPdMfcshHs0/P4 CrsXJXrJRMe9FcJ00SM1mm0qrZHtSSyOSius8FWReZpvCNbD4GtCdscmIFdJdwWa+kgSrc2Hi3j HuaAZazDRD8mgG7HDaf/iBkHKyEYonvyNTGMfMxg== X-Gm-Gg: ASbGncs18qSd9VOv+HGDLMN+qhOEYXf9+RND3rp0bu6feDxPGKXKEraMuQF+ud7uyt8 V79/Vn5WWIfisJTBh0i4HIzAFDdI1g5tWPlcgxfTl7E4UPdm3DKWAVn3SFT/Opgcda2Ab4JDkW4 JPOR29mEOaQ2w4dnZfAYFzjudjDOZypNgdya8ezCp2w0Jv2zrbl72AsNxKnDmq5NyxUA9EdMjT3 i5QqDosa/Q/XuXzIBYsGXcB5mjg1ao/ctVYMGSNgtgvNTzLfUw/33P7i74yvgdAOy1322oiNmga 3Wc= X-Received: by 2002:a05:6214:1d05:b0:6ea:d033:2846 with SMTP id 6a1803df08f44-6fb08fff923mr259022106d6.25.1749496385573; Mon, 09 Jun 2025 12:13:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUljpiabaM9q02SILGFQqEh0hQoy6lUYwcBtIzoYmFOYukE+7IdzxqagVCpQ/fFpBqxO7SPQ== X-Received: by 2002:a05:6214:1d05:b0:6ea:d033:2846 with SMTP id 6a1803df08f44-6fb08fff923mr259021636d6.25.1749496385072; Mon, 09 Jun 2025 12:13:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 02/13] migration/postcopy: Push blocktime start/end into page req mutex Date: Mon, 9 Jun 2025 15:12:48 -0400 Message-ID: <20250609191259.9053-3-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496477427116600 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 | 24 ++++++++++------- migration/postcopy-ram.c | 56 +++++++++++++++++++++------------------- migration/trace-events | 2 +- 5 files changed, 47 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 1a26a4bfef..6c0f0a66a3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -576,22 +576,26 @@ 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 f= ound. + */ + 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 17:17:24 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=1749496416; cv=none; d=zohomail.com; s=zohoarc; b=P0cL5n0I5POqnt0xtbU7IFbrHz0R2smPUj+aGmxGBalzZ7bDyBTzE1ISjic0RM2ia080LucOXXO290rIX+iLW2o5V4FZZOMpvDTwSEPM+ylv/duMO9kXGwoOEjL8AxYK4iiTY2iKVUJcddvBJbXI3s8FmPMjpF44ndfR2Ctjwpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496416; 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=FQED25kLj+S3SfwODgZYW0bgA4URNZ4KBUL4u/EQb80gFQClIcwXnQMlmz6fgVpsNwPy8QEFerzp445gaRvh4L5VYsam3iJWWGNDee1S12h4r77Ae4OYxtyVFqju6sFbcSDzqh1wjed69BbBRGmximcCTC4xcW/8cEk7fwRZDTY= 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 1749496416423651.0241601921488; Mon, 9 Jun 2025 12:13:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvn-0006MU-BG; Mon, 09 Jun 2025 15:13:15 -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 1uOhvl-0006La-BQ for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:13 -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 1uOhvj-0000pP-Bx for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:13 -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-94-GshyWNFsP62ScvLKgBKTyg-1; Mon, 09 Jun 2025 15:13:08 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6fad5f1e70fso88544536d6.0 for ; Mon, 09 Jun 2025 12:13:08 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496389; 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=IIWuMmlVERJ67z3hmkM69x1Ik+x7U3JMMvOxUSzzr+R97vTLuydmJLJ2YGok0rbflofOjT 9TLQTQCIpwzn6YentNg14xJ+fmD2OYFXsjM8pRaWvSKrsbG0vHAGqccJhWclmxXjSzbzL5 dY9/N/zEyLxsAMJRUGjWmSZmg+uuWdA= X-MC-Unique: GshyWNFsP62ScvLKgBKTyg-1 X-Mimecast-MFC-AGG-ID: GshyWNFsP62ScvLKgBKTyg_1749496388 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496387; x=1750101187; 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=FD3//AWmPu/I3uGopXltL3UDdPt7yQP4pqQUkPKKCF9RVzR0rNYPznpKTe1w/+nGig eynYdHxWz2Qpxfeg9dVvhbBJh+fEAydTGVp5ovmnveWR3N7FPM4dYJe+9LZuXcXVWg1i bQS3rnxnJ7MpB8n8P4YFgiXMAZqkzA+1hOxN+iJKi+tHkQy4FX34U0UIV1qDRIFcP3Nu qH9Mj4peiu9r6P8rCRydlx+BHaCy2zTp2wMp0ykRWpJmg84uCxtlgm1hBOonvzB9xWS9 TL1kIck0XJXR6M6+si+D6nqWFZ7C1Ide7XA5YWIcVDHmcxv/nfilr75p8A46jyfrAx/+ 5PBA== X-Gm-Message-State: AOJu0YxskjYdl6KanE/3mAOpUqEJnwU6zCDaPlWpLGiH/aSPOFXdjn7N bl5IRaYQYKItagi/ofiwlXXwV9UbzsPiJatN5qtXLKkXVJ8of0ZYKTJk/yNcymkhmyhq8WFtc04 humpUwQEAeMR2jgMl7dtXoPHsuBtmOcPpLDPW7G61vIn9m8J8T9tC7d4/066W+s8jQ2KLD5VlhY MkG16E+EQGoVwvvKu1LUPtT5oaUoTBuidwcHvccQ== X-Gm-Gg: ASbGnctKgPhN0PfT26RQ6RuWNB0Cma9NbFgnCERARQqTPC745RGQLju2VEXH3zeGQIK qwJrXNYBEMOljBbsG33iKlUiOqQ+LFwFC3d7NoihLtoyaLA8nMjmCEOjyZrgUD0OBBnPTKoj/Fj DLm4NXkccqs0uSZcslCegAsnbmP+6tEsdHdGjnP5up+M0mHs9s1NmS4OnXsNKHWo09zpI8cA/Lh XQx4CBgl5i4k9j8tVq4Av8XPxyeTjSEjCOLO2Mo6/VsZaPNrNvn5iT7O0KZi4PKLDTJL2HMljUl +j8= X-Received: by 2002:a05:6214:212c:b0:6fa:cce8:3bdd with SMTP id 6a1803df08f44-6fb08fe3710mr266978306d6.36.1749496387259; Mon, 09 Jun 2025 12:13:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtjP+VLSZY/RFudtU0Y4JXbKGU5irGTdlhtNaorDw1G1fIpzVgev9zs/YHdNi6B3eNCMAYsQ== X-Received: by 2002:a05:6214:212c:b0:6fa:cce8:3bdd with SMTP id 6a1803df08f44-6fb08fe3710mr266977746d6.36.1749496386705; Mon, 09 Jun 2025 12:13:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 03/13] migration/postcopy: Drop all atomic ops in blocktime feature Date: Mon, 9 Jun 2025 15:12:49 -0400 Message-ID: <20250609191259.9053-4-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496418704116600 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 17:17:24 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=1749496561; cv=none; d=zohomail.com; s=zohoarc; b=MEcUMZgJvdqtW5JRK2vmrCK4KPxrHsIcty4EvIOr1cFF5ILM/UpI2s8fhcwZWKp7ZVFRpexlgrFtYQ1mi2J5XOPD4xUcafUAg2SWTLHmpJl/GQN7oZonjP3Aaohti66qmaRfIr41OCgiTh2KF7nBXGM4b5ZxGczqcEtZyOzOBGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496561; 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=j5Y1MphT1azK0xX7US7xUGIbvmBeO02UVH98udssAnkP1LSkUdDuNk293qsFCk2MrH5VV5EQi8VVIC+XrDVTfsbVDbVEqkFI/rH1xzHwsPOHDLNgFljdG85SqBC7QW2JpY6hqXDalniVcvWXlftd9SFMrIaLJlMpe4XwxrGxFgc= 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 1749496561463375.16018624676803; Mon, 9 Jun 2025 12:16:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhw0-0006PU-P7; Mon, 09 Jun 2025 15:13:28 -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 1uOhvz-0006PC-F3 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:27 -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 1uOhvx-0000rb-I0 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:27 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-POLaEHfCOuuwyrGC3_QjXg-1; Mon, 09 Jun 2025 15:13:21 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7c7c30d8986so1434177285a.2 for ; Mon, 09 Jun 2025 12:13:21 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496403; 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=fEkxNTiFn7ZPaiocuKGcciWNp9Wt8TVU4pjg1OA1BCSjb6DfojM25lCp0nqCZsEFFZF/Y5 W9KfixRt/wxs/EOwO4LRL2X1QYLGmmv0mHjp7aAkpX7cZq8FCNdBc6iSA46wzw12OYgTzu pom5lpvnttT0Vkq7YgLEe6CmQlRPht4= X-MC-Unique: POLaEHfCOuuwyrGC3_QjXg-1 X-Mimecast-MFC-AGG-ID: POLaEHfCOuuwyrGC3_QjXg_1749496401 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496400; x=1750101200; 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=TMrKzOpm2mKdY/QhTjJpvAN8TA0X3G79qq+AM+SYfoeMjfyJQ1ZMtXBWkmC9bK7VK+ d6JS+faYPdGU69q9MPXmweFJ0j28EEuGclDGDFg041Bllp/NyWa+SQwn5WJfGVGZLsN3 z/JV1fpD7HoU87wWtNocHgb1gyGnaEqwO98UOXNlIfLSRpQxmQzbzSjXWVe75uz2ye/L uIPowdPvGiv6pS2uqtxd9IKMl5LtY5jPfNvquYWoFO5STk9jfacMRF0ZRqwVgTCXzklf cj1tmxy2AF/SjYsjQXL4Ee94VA1Wjw/4V46uiQO8H1insVBOAsVkOaFV7ypfrHcVAxdy jQVg== X-Gm-Message-State: AOJu0YyD/wTnQ1+zJERddkf96pXur/J/XqvMcTXx4DZt7pxnkSuiPNUe DzNWRetKnAIG1Es4xbQdRXUFSgXkfKB3yfO3X1wTNP/3dr6QMr5pySVgciQElqiuAwls2iCZrxO VMfuZIgvdUGuLNB0wiJE6WHybOAijwQ6UqT/x8xcvcMWHzmAuu1KgCIGdZx4TxLa8i8trBiUpUH g1mbyduCPkxFXYWNQEcXJIVgiwS8BWmfsq5m7gLw== X-Gm-Gg: ASbGncu22rKRHCThxmKOtPG4aJc/bljG8Bug3dOh7kC0+5pMtHNEqU94HlAnCuwc3eB WuMfdQqM55lULLPycmT+yL6qcS/FKFd6hOlNJRjS+Nm6bPBanQao1VxJbtL6VOHrPAxs47Q6FuZ GOye++mGqj+HYSLFdYGHG4UhpiqRZYpE4zXbwaKJKxyLjC+ICJeL4QYfd2yLU5pXiBhxJfd2OuO S3wf/J3Y7UInYlbopvr6irmrRg96d28aLE6KBXSJ3InuY0iLw3EeEMg9lPZ0lMpTXhkLjqivv9u ZL9UUT6JyILiVw== X-Received: by 2002:a05:620a:3188:b0:7d3:8df8:cc04 with SMTP id af79cd13be357-7d38df8cc8fmr1166166885a.35.1749496399697; Mon, 09 Jun 2025 12:13:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/t/iwfAJwZEd4OBGNX8Vme/mUbVmLCF6eTxEvks9FzYmmmiO1c/rAqu2nmJJDdcf8RHEprA== X-Received: by 2002:a05:6214:dae:b0:6fa:d976:1977 with SMTP id 6a1803df08f44-6fb09058391mr229843896d6.41.1749496388251; Mon, 09 Jun 2025 12:13:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 04/13] migration/postcopy: Make all blocktime vars 64bits Date: Mon, 9 Jun 2025 15:12:50 -0400 Message-ID: <20250609191259.9053-5-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496562647116600 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 17:17:24 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=1749496435; cv=none; d=zohomail.com; s=zohoarc; b=d0EYYVX36aGJsFrxsLp23qXE+GJrDoaJmjvVicTTNTUNqK3oyYEgNTSal3ZKJfs4rQAvN4K0cJRwhgN3ot8KZlEB6sCC/ixazqQ98uQ55RV48x0OVmC2y2AlmRj+ZsrYjOLMBRVUkGpzHi/Ea31QPzXBVJHLmrIjKlr3VXYuODo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496435; 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=H9shalK/Bz8dnzvomsAx2vRRqvzB/doXaNLFOu3QyMlZcdeXRXyzSET4/dV30MSnwhW1J+SsB/FvcbeEIhM5F62R8Rxwi76sOD7eMZFZX1iNG8PC1pDXwFnQaNzrGQXnYP6ZWRa7F/FmGVaaflcjc6yyswFIEuEu70k7HypzVAQ= 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 1749496435903725.6050130212901; Mon, 9 Jun 2025 12:13:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvu-0006OE-C8; Mon, 09 Jun 2025 15:13:22 -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 1uOhvs-0006NW-4A for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:20 -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 1uOhvk-0000pj-De for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:19 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-SIdxoNnUMpKjuvpUR4SZTw-1; Mon, 09 Jun 2025 15:13:10 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7d21fc72219so323009185a.1 for ; Mon, 09 Jun 2025 12:13:10 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496391; 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=X6pvGyzzoNgKYnB87uHW1fAW643oRKWvN06UEhFOpN+Oyx4IsridfqtFoHhmraGUAJPFUR ChKI2Sq2QBT1P43OVRdPvTggwQoKmVnDqo/Vzv6SSRd0Gg/KyuUdwxX32V7nkBr0XgAnON d196OvSsQTQKJIcTZQBZSjV4TtQ6WYg= X-MC-Unique: SIdxoNnUMpKjuvpUR4SZTw-1 X-Mimecast-MFC-AGG-ID: SIdxoNnUMpKjuvpUR4SZTw_1749496390 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496390; x=1750101190; 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=jpJ5SKw02yN0Ughaw8dit/RP79MDD+/RLrQeELrON1GnZrpqSwWpBnbtcIEZqPkIRJ 4qzifEQoQSfSUPlI7bNB2CHOJf8P2gjVZOTvRNIWYjb9kDq/pi+ynkKENpQ1vHbADBkX A8ZyMdbW9h1loZbFKsNoGZ3Frpt8EFdNP6syxGmsN6dNK3odLeUFhhR3s7dxLVkrE/vO 4yu9qRXdkaHwupuDKTrmx1O4SKyLwjJVSltd45dv5oZdrqCpapDx6AGdXmKPfbYAqsXb bPWcW8mFrhNlGdtz+h1d/g6eHaMprOHMo3hfS1wbMZsK+DP8tGZ8ppemEFj/KiA0l/pb 3m3w== X-Gm-Message-State: AOJu0YwqIHa9gX8jh0Bm3RaUDeRYpn1USUXtBDtOU7Hx4RtaqvV8cFPe uhAJbfRgKUN05am7Lw3gfq8wbdMN5eKL2LeXFWASW2zZf2vC5893mtgtS2f+rHccmZA4wpYSjih 3+AhXb7ZSd1/uhHBszBRgq8VkQDqgq6jBbSSpKZXiYpzFrnno0lJgnfPEFgIQ8gufpP6fiW0Ero +HTiEmBOdKQLeG0oOsk2WQC65Pz90COvgrDm4YDQ== X-Gm-Gg: ASbGncuokVPaW2/Fo/feF7lhiCRrcwYGavDOD8efMT97/jL2f5elpGwO0CCNm+AcrgY XZpAtsTB474cxfpNuvf1/Pc8tJwpoqnszUDUpSiD6+hFzI0rUJ14b49ugDVPjNImh59SXf3RmRW 85NvNS7pf1QGXEhW3WOuSP71+e7+qv7jL6dr0IsoYkk0Kxz1lUR2zNJbHaJeSF0Wnta2wqviQFL Iu+hao7WoLd22nwJ1Gqv6p1gb78daGI5xnE2BpyNLKwgoL4IgBVe9ffYz45P9hLwU6FYk3OoyZ/ LaA= X-Received: by 2002:a05:620a:2496:b0:7c5:6678:ab18 with SMTP id af79cd13be357-7d2299b1ebdmr2006940585a.42.1749496389800; Mon, 09 Jun 2025 12:13:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0Qsb1PKl+U09/IS69Dg7ONXcI42UiKTGzh4v1Eb2J5b1ZHxDhEP85ILim6lKoIDT+j1Ihkw== X-Received: by 2002:a05:620a:2496:b0:7c5:6678:ab18 with SMTP id af79cd13be357-7d2299b1ebdmr2006936185a.42.1749496389390; Mon, 09 Jun 2025 12:13:09 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 05/13] migration/postcopy: Drop PostcopyBlocktimeContext.start_time Date: Mon, 9 Jun 2025 15:12:51 -0400 Message-ID: <20250609191259.9053-6-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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_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: 1749496437029116600 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 17:17:24 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=1749496582; cv=none; d=zohomail.com; s=zohoarc; b=EEdWCqVCbK1S64N+GE8ch/fkkpfXuDOu9X617GuvhrckXiC4ttRgty4JY6Sl+jpoHR0kGiKWLL232lEDEEsmCZ1EsnV1fxdDu51rDbIc0C4ESVnptdb+ETuMHF448IQEaS7KOhbP87PahXFWYpvIXnAlsybqth8uIRQuh4zbi1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496582; 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=wDmfUIQxVF5pSgvWN390nZRIsyCmDGidl1i9aKjf6yg=; b=hTZseoroVG+HtZYEazmb+0ZNxWXgjPBMi7iua24+Bq13Dth3ROv5hJE27pqtPvwalRN2b+2onmi0PYWwThqsXx7PJ+IO36l7W7nvBXskd87epMqkhl0+2AylyfRZOTsaIRrnDQjfGI9aJw0p+3/391yvTy8STZPpv68XOqjFWtA= 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 174949658283893.03287342092301; Mon, 9 Jun 2025 12:16:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhw3-0006QO-IT; Mon, 09 Jun 2025 15:13:31 -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 1uOhw1-0006PV-0L for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:29 -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 1uOhvy-0000rz-EV for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:28 -0400 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-daxjYR9ENp2ZUBQlCFOUDg-1; Mon, 09 Jun 2025 15:13:24 -0400 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-739f234f60dso533584a34.0 for ; Mon, 09 Jun 2025 12:13:24 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496405; 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=wDmfUIQxVF5pSgvWN390nZRIsyCmDGidl1i9aKjf6yg=; b=JWgtQ7FDNb6Djrxexcy9LJKcc01paBPnLYyGXvFTmpkrSecRxMvZwzG242V+UtekZlYRXA nvKDzz860ggOttvscffnc5UBsxNgSetTGo+Mcjkey3CxDYglLl9HbzaRAbbQw1+OwBJpLe 8EF6EzORB4UprWRCcPh8CYm7h1O/7QU= X-MC-Unique: daxjYR9ENp2ZUBQlCFOUDg-1 X-Mimecast-MFC-AGG-ID: daxjYR9ENp2ZUBQlCFOUDg_1749496404 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496403; x=1750101203; 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=wDmfUIQxVF5pSgvWN390nZRIsyCmDGidl1i9aKjf6yg=; b=qKh5Pq4QVtCNv8QV4uzoO+a0E1oNGsQP3WOrgDUYKaBwhB81ifDy8Ee8gRdQ4orErR du43M8WZmPrmN8fQoLq5krAiHyRX/M2OkMHl50NAVN2Oy7i1hj+fQ5rYLwFj/SoyMg3h FhC7J9u8QrQlyiFtZcaL2ZcplDnnC+Ojew/KUWogGbKaZnlGuBzTsRkRgBXUMM81S6E2 G0AVPdm/ZXl5Jntps0jza1OLOLM/EQnkPwJnpVxSWuVgHvpIgMj7kkZTdufTNS+LN4KO R7LUeDVUn71rFlueqWJc6hi9tAlRVBzT5bGNxZEjqQcL7xEfel4lzFsR/hUdzeVOKyQQ SEaQ== X-Gm-Message-State: AOJu0Yx8MZwZ7Z1/VmRyDYE3BknoRCwOqfkWv8MY6CeSexqkpaDIwGvX cWnDoZPWwgA8UWU/zirEzHpk651KefovFc30x/+d1rfxGoe1h2CCwkvbaBhtyV9CLWQu6kI4mXy uSyRPb0L3ff6vbk4Toi7Mn3DFNOY9MqilO0STXYXREaaBZMYlcg9Qd7B4K+HkHa8arsXP2BUFLg ITrYE6lIo34e9KizTq5RLbLV5lZa0tF7fs+U1I8w== X-Gm-Gg: ASbGncsP9H/PDV9Pw0HCiiV7UeYxmY1sR1X0UcIRK6phy/FH8hcQW21Onq21fDipXy2 wTSawTAFg1qXqu+sC0k+TD+Accmz5DhaBcLxhx3xC3DuPtnDBtigMuSoLWw77nuqMp7IQY0jvxE ZfPgGPpFz1+dW49u3+QeeV+TKPudMeZBiuBUw5J07JhjwlTo+uJUNfqDT0a6qLOnsJNMr8fPGlV n/FkqRoiVbzPC7ycOT13XYRFzj2dav3VmEgb30e1aKYWvX/PQQsUTXcDLx8z2sji5gOPT767mIJ 8o10ZNHUkr6fOA== X-Received: by 2002:a05:6830:7317:b0:72a:48d4:290b with SMTP id 46e09a7af769-73888f1e784mr11289609a34.26.1749496403161; Mon, 09 Jun 2025 12:13:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhWQyxm8K2zsSZ0qCFvR1AIeJlCw0Hzz7aJ+zv4y8P/GGyUbvv8qFyg/JTuICTg0NEP/KLNA== X-Received: by 2002:a05:6214:21e4:b0:6e8:9b52:7a1d with SMTP id 6a1803df08f44-6fb08f627a4mr243976546d6.8.1749496390789; Mon, 09 Jun 2025 12:13:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 06/13] migration/postcopy: Bring blocktime layer to us level Date: Mon, 9 Jun 2025 15:12:52 -0400 Message-ID: <20250609191259.9053-7-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496584525116600 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 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e9acb4ef6e..f79fb7663c 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 microseconds (us) */ typedef struct PostcopyBlocktimeContext { /* time when page fault initiated per vCPU */ uint64_t *vcpu_blocktime_start; @@ -168,7 +169,8 @@ 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]); + QAPI_LIST_PREPEND( + list, (uint32_t)(ctx->vcpu_blocktime_total[i] / 1000)); } =20 return list; @@ -191,7 +193,7 @@ 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; + info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / 1000); info->has_postcopy_vcpu_blocktime =3D true; info->postcopy_vcpu_blocktime =3D get_vcpu_blocktime_list(bc); } @@ -816,9 +818,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_us(void) { - return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + return (uint64_t)qemu_clock_get_us(QEMU_CLOCK_REALTIME); } =20 /* @@ -835,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; - uint64_t low_time_offset; + uint64_t current_us; =20 if (!dc || ptid =3D=3D 0) { return; @@ -845,13 +847,13 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, ui= nt32_t ptid, return; } =20 - low_time_offset =3D get_low_time_offset(); + current_us =3D get_current_us(); 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_us; + dc->vcpu_blocktime_start[cpu] =3D current_us; dc->vcpu_addr[cpu] =3D addr; =20 /* @@ -899,13 +901,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_us; =20 if (!dc) { return; } =20 - low_time_offset =3D get_low_time_offset(); + current_us =3D get_current_us(); /* lookup cpu, to clear it, * that algorithm looks straightforward, but it's not * optimal, more optimal algorithm is keeping tree or hash @@ -918,7 +920,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_us - 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 +934,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_us - dc->last_begin; } trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime, affected_cpu); --=20 2.49.0 From nobody Sat Nov 15 17:17:24 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=1749496575; cv=none; d=zohomail.com; s=zohoarc; b=g3kS1bEhzvqMTT/i1RyY+1AdoRPY6eRPuzVFqPFmbU0aeUqlVnt90ucK6xXnc0777CmuAAb0V20iuxGAKIVHZ2uYF4M3N/yVTzUa9v2vEY8paRSxdDajFQPUiv1AlL7fRLiapdIiialNB6ZMYm+pYP4o/6UhZWthDKDhKM5Q6xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496575; 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=PtJswxUgI+FVYadSfpkgF96burKPZXr5ACVFgqgHl7U=; b=j9V+G5S8FbGqyG+C7ccx3LTZvrIq2gxweHnSHbTJE+RcEHJVucAVG2gSwBsAb9nKr5awxK53eqOQ39UTKhlo5N49bHqFlyjhbOp7O5NIkWk84haFky82PkySf7wv/ka76mN1b/g7Ur97yoQJTJdcy/x51/RMmUzknz2RSIWBELA= 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 1749496575940703.2949024695703; Mon, 9 Jun 2025 12:16:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvs-0006Ng-7f; Mon, 09 Jun 2025 15:13:20 -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 1uOhvq-0006Ml-Lb for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:18 -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 1uOhvn-0000pz-D9 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:18 -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-538-_gaiZA8gNganKV89GnBVvg-1; Mon, 09 Jun 2025 15:13:13 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6facb96d553so77531686d6.0 for ; Mon, 09 Jun 2025 12:13:13 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496394; 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=PtJswxUgI+FVYadSfpkgF96burKPZXr5ACVFgqgHl7U=; b=iBpaK77FG19R+1MFU4qDt12tZ42j/GQzkDRe9jktDOo8PV0S7gNdn4kREKLvijsE31/M3R XnZeZrPNRm0ExCLG5zaNe5yaG2pHPefr3fx7A+jTPOunsgtId74V2oBhS8dlh1pmSj+JaV ITawd+O9yLvYAtgh70bV4RC5c/dKiqs= X-MC-Unique: _gaiZA8gNganKV89GnBVvg-1 X-Mimecast-MFC-AGG-ID: _gaiZA8gNganKV89GnBVvg_1749496393 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496392; x=1750101192; 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=PtJswxUgI+FVYadSfpkgF96burKPZXr5ACVFgqgHl7U=; b=DGVauD1PaISsR1xIqkF0wt5NBKDhNtJw8Jy3J3QdZv8sJXqKeOu6hxP+fy9IUhVGHa kym8fPlMEXbuAvjWpQHIgJNlgzXFW+LarFfbMYhnYCAhynBTlqXneoPAGqfF4N4CrV7Z qtPzJXRq2yizsxiKpNMPIX4wUiXJH9M7rXZ8Dfwg7th5dwe70xuDhkX2EKYFsfmzZIQk 7PQGDpByFn3DkmAtKelZ8oLXCHQ8K3nyQ1/3NPgJeaxPJ8QHnvPYRPtD1fYoGKe7f5V7 GW/GpqAT87kouza4JZeCGDwlrGv31gfdb5XLCLKUZIuc/XNEutNIDUaRk1APRhi978SX INag== X-Gm-Message-State: AOJu0YxZuFMga/ohCuzUwJwLTVgroNVeHx+/KOzgqVWEQf9+ZcSquY3a YlbTPDvjI3tUnuSSCcoQ0uB0N12Fi3yvN7JlJdirY+pWzoB+rHpdkchYqK+KR0TqBG+SuUZHex6 +fnDOCXzj6W/McZwLkAlcLYiIa4erBbA42fwcGOdV/4XAnfD2YUOHiVwRNf4WnFR+hRCQhs9TWs M+BEbFeeQjJkaD/RqTq9TQ2/KIPRy9N8FRD+7dAA== X-Gm-Gg: ASbGncu/+PkYToricSZwO9MgHNW1s42TqmBUOVNnTXTva1IkyynlFYUOcjzzkvZ1PM1 d8ufnpIe+Yc4ktZVw6s1yaR3z6RvRr6hI/Wr6yvWH9tZdqLKNRsWexG1oiAfR305cjY2CSmJ6zA 3fxsSCRAuTt5pnLujvbPJrisVR51F7ckYAIZs5i8/VEmdUgixZLugcow+lnc1ZmmkCNzGTPpvtS Lr04dlUvHb4m1kKV8xeb4xOmdmdp5EXpA3APrUz8+YyOyJeDAJGuGIpIOSe4IHr4C6z9GpkpVDh fRE= X-Received: by 2002:a05:6214:2349:b0:6f8:ad11:276a with SMTP id 6a1803df08f44-6fb2396b66amr11889346d6.19.1749496392428; Mon, 09 Jun 2025 12:13:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYWpum/slEmCYdYNTa9qXPKaGlBs8X6UmS1CIkB+eSQ34Khe1k+Q2zlX18zoTkzBmVqLIZyA== X-Received: by 2002:a05:6214:2349:b0:6f8:ad11:276a with SMTP id 6a1803df08f44-6fb2396b66amr11889016d6.19.1749496391971; Mon, 09 Jun 2025 12:13:11 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 07/13] migration/postcopy: Add blocktime fault counts per-vcpu Date: Mon, 9 Jun 2025 15:12:53 -0400 Message-ID: <20250609191259.9053-8-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496576589116600 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 f79fb7663c..f5c58a6ca7 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); @@ -855,6 +859,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint= 32_t ptid, dc->last_begin =3D current_us; dc->vcpu_blocktime_start[cpu] =3D current_us; 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 17:17:24 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=1749496586; cv=none; d=zohomail.com; s=zohoarc; b=BqEb5Ix+R3K91QnuDRDB+He0EUT90by2K1i1C+0gLyuJVm/j7efFkZ7c0RzAhUWRi3Njyc9J13YkXFD8mfD53dFridPFxQbbxwX+V+C34TpXGAj5CTQA7n4YEDGCoJBY6j//OnvfeGIvNXPMj6ksSXm/S/BXLwERVgzVwvmIjDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496586; 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=VcVyp4UEqvWfTRq2gNYvpZME1z/wOcKZB/CmIJX+Bks=; b=dXlMkQma+MrEzx1QJc6RuMEbz9sYSqhVGfwBnaBVvWKIsmb2X6QYuK2JX0DqlUHlaoKh5UsJDOtiyVH5g8O3J6I6M2cvDtqWp8DJBVjn9UhT3u2k8XT0c5bAyY8cRVvFC08N5kluT7si+ma0zOFHSWdCMidIQ/gvlmj5WZW9Tsg= 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 1749496586700990.5484843788546; Mon, 9 Jun 2025 12:16:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvs-0006NX-8B; Mon, 09 Jun 2025 15:13:20 -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 1uOhvq-0006Mo-Pb for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:18 -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 1uOhvo-0000qE-Dx for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:18 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-Ljqi6bS7Mieyte5NviyG9w-1; Mon, 09 Jun 2025 15:13:14 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7c53e316734so724763185a.2 for ; Mon, 09 Jun 2025 12:13:14 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496395; 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=VcVyp4UEqvWfTRq2gNYvpZME1z/wOcKZB/CmIJX+Bks=; b=E2lQ1409zuOQxV57KPzcCV3CQ4AG/hbSYRomGNPKg+++bYgLwWtasK9+lLrXn96F7amkbq Hi2+vOBfeS/21XWKRa4uT74eUdquuioTW6ssksJiwdLvUGX7FR/5M63+A7nOdCQywXvW/T P3uvjX6z+/WN0LReQkhr6rmoxa3Pkuc= X-MC-Unique: Ljqi6bS7Mieyte5NviyG9w-1 X-Mimecast-MFC-AGG-ID: Ljqi6bS7Mieyte5NviyG9w_1749496394 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496394; x=1750101194; 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=VcVyp4UEqvWfTRq2gNYvpZME1z/wOcKZB/CmIJX+Bks=; b=RStBuWs8VQqyTlMWWJ5xFX4RrWJK7pdw7SVnECVNUXkK5agtWF4zsfHz8AS3iCkxIV AXzZJ3u0CgPcmEpy1hb5KmTJQ5ok17gs5Ry6WRb6HRmQOtlHcPgHKheLI/GVPrEh6G/j dQQYod8aiWwI04Fquf3dVQmmgSVnCYAJMIxkHot/EjOqFBys9s48osu5hteZUPubFIxH 8I6V7AoIqtrsynaxLBfpWrUjrS+XZGzKZ5IGQMCXtbo9qZnd0sinkUOm9guF2nPq2I8n bRJuDSuTnRTDmLxQVtphnsQW5qMeI3bs7PUhbScebJPAb8OAM0cv3uFC4wt3ysGbkk71 nl/w== X-Gm-Message-State: AOJu0YyAyOc9TH9YD+FvyuA99lqv25oPYXpzfAx73mhh1pSVylM8Ocvg 3mX1+0f4dTChrkYTNav30L5lOiCZqC8MGbQNyzrlD8uTu1Z620LPRkm7V9YsYN5MerdttG7BMow xvSeTAJ6/Afr9jSYE3fMq66nB/12v2Wj2bBqGaddXZzUG7ekY1IkNl64eQsBDbZSoCJD7We1tbk FQo/LxmZT+G+t4dBDW8uMtM2CEw/RomLYXbGsC3Q== X-Gm-Gg: ASbGncuLdc9iUVYaUCf20IovrHXraatlJMF2bhkCT2y1xhtw8nVR30vQVAx3Lyv5Xk+ czVoX/sirgY7JxYEwOf40b4J56iqMA3eQkm+l0hA6m818JnlzfTB0ydIWGQm/HDte2lntgNXiwT ELqVm880CTJ3oWdFXwKoSDO1gPjhud3iiuqoY5h+j+ZY0A9FxDFHBPE7zfSAcE0ZILkRWch9+PK Up2wRV6Y1gKxhMe/hG1uWognP+w5ee0qSD1FedUSOuqZaKXlFSzXazYu9MDuL5LbxA2XWCJmDT8 ZYvaibZUQThiUQ== X-Received: by 2002:a05:620a:c54:b0:7cd:145:d652 with SMTP id af79cd13be357-7d2298484e9mr2125722785a.12.1749496393810; Mon, 09 Jun 2025 12:13:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGT3mtxYQa9FbaQuXJ4uq+DGn1cqqyx7act6udAIlcvIo+ZBgR9ytoBWA7fZrx5RKC4e09/vQ== X-Received: by 2002:a05:620a:c54:b0:7cd:145:d652 with SMTP id af79cd13be357-7d2298484e9mr2125718685a.12.1749496393387; Mon, 09 Jun 2025 12:13:13 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas , Markus Armbruster Subject: [PATCH v2 08/13] migration/postcopy: Report fault latencies in blocktime Date: Mon, 9 Jun 2025 15:12:54 -0400 Message-ID: <20250609191259.9053-9-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496588748116600 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 Signed-off-by: Peter Xu --- qapi/migration.json | 13 +++++ migration/migration-hmp-cmds.c | 68 ++++++++++++++++++--------- migration/postcopy-ram.c | 48 +++++++++++++------ tests/qtest/migration/migration-qmp.c | 3 ++ 4 files changed, 96 insertions(+), 36 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 4963f6ca12..e95b7402cb 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 us). 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 +# us). 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) # @@ -275,6 +286,8 @@ '*blocked-reasons': ['str'], '*postcopy-blocktime': 'uint32', '*postcopy-vcpu-blocktime': ['uint32'], + '*postcopy-latency': 'uint64', + '*postcopy-vcpu-latency': ['uint64'], '*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 6c36e202a0..600b0f8071 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -52,6 +52,52 @@ 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 (us): %" PRIu64 "\n", + info->postcopy_latency); + } + + if (info->has_postcopy_vcpu_latency) { + uint64List *item =3D info->postcopy_vcpu_latency; + int count =3D 0; + + monitor_printf(mon, "Postcopy vCPU Latencies (us): \n ["); + + while (item) { + monitor_printf(mon, "%"PRIu64", ", item->value); + item =3D item->next; + /* Each line 10 vcpu results, newline if there's more */ + if ((++count % 10 =3D=3D 0) && item) { + monitor_printf(mon, "\n "); + } + } + monitor_printf(mon, "\b\b]\n"); + } +} + void hmp_info_migrate(Monitor *mon, const QDict *qdict) { bool show_all =3D qdict_get_try_bool(qdict, "all", false); @@ -202,27 +248,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 f5c58a6ca7..98d4c29532 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -166,20 +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--) { - QAPI_LIST_PREPEND( - list, (uint32_t)(ctx->vcpu_blocktime_total[i] / 1000)); - } - - return list; -} - /* * This function just populates MigrationInfo from postcopy's * blocktime context. It will not populate MigrationInfo, @@ -191,15 +177,47 @@ 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; + + /* This is in milliseconds */ + QAPI_LIST_PREPEND(list_blocktime, + (uint32_t)(bc->vcpu_blocktime_total[i] / 1000)); + + /* The rest in microseconds */ + 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; info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / 1000); 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 17:17:24 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=1749496521; cv=none; d=zohomail.com; s=zohoarc; b=UN1uTSF5n/iXmxkUc3pKiohoO/pHhBgFtdWuvIbl9j4OwvhckmPfNLD7cVsmPwguYHw4XhfzF0AEQF0YVdh/fM7ZYKPGC0vZyBh7/GASzrCg5I3WL0JEjI24dwRiWDfYmb1CRcLeql3sMzpMTVMOEa16SE0j4f77T1ESBrS0Qwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496521; 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=Uggx0LWnDXw25MvWp6nsAnmpm2psyW3qEQ4EOTJZ55E=; b=iUgr6GSyDuwaPWc0zF8YzwoUw4GfSTT/2hQNN/uwif4g1slcvATSHkfrGhcCb5k7MMCCByKzBXUryjho+uXjT0ED9KZUAdowZL8TZmW6N2zOHoD4min8G7ZIM7z74crOEPbrdjCJBhPyNk96VV1vXx3/P2RM6yNJnE/QGbQKkew= 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 1749496521087870.677632066328; Mon, 9 Jun 2025 12:15:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvv-0006OS-Fh; Mon, 09 Jun 2025 15:13:23 -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 1uOhvt-0006OC-VF for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:21 -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 1uOhvs-0000r8-D4 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:21 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-ITbYZNghOoy9w_mY6WVJCQ-1; Mon, 09 Jun 2025 15:13:16 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6fad49f42cbso73764546d6.3 for ; Mon, 09 Jun 2025 12:13:16 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496399; 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=Uggx0LWnDXw25MvWp6nsAnmpm2psyW3qEQ4EOTJZ55E=; b=PIRQcILTXzYTltQdj2fRd/molCop0z/kGbRiU8gzHUYHhTzqAz/YGv3WKbWNS7o25sQ9// lB1orpudhJ6UkSc/O/XLczLr7sOCCbyCk57vDQ4fg6XDDguRys1Ok1dzIwhzFoyx9fr4pe e/XxJejTmKxEV4LmGpGtS6LwnLmIpOg= X-MC-Unique: ITbYZNghOoy9w_mY6WVJCQ-1 X-Mimecast-MFC-AGG-ID: ITbYZNghOoy9w_mY6WVJCQ_1749496396 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496395; x=1750101195; 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=Uggx0LWnDXw25MvWp6nsAnmpm2psyW3qEQ4EOTJZ55E=; b=RRLbifMn90RkivDlubgIF+n9lXUOA13vWTzwwKkCr3V+/baXVD7FyI7sI/LEXJatzj ULngXQnKQQnWUSwgG7cMMO8JGLaOld4K2XPQYrI5Aqs9XwxkTdX71hUKvrD9ehZjrl8N vX8+zR7KVSkWPsEctJ6X0Ml8HoTLFrMzin+jK79AIvTJXneGBP5DVqfcHALvS/eg6vzX Dul5ZMOL73a+iSFO+g6ZNEu/YSiGZPDCO/0/aORUUa9vjt6onvEy2K8PXnR+Rr2TFUzt yKfgeG+REy5CyiqollzZhorSeG8L98RUbKvczu345YvF5rAPAbkwbN/Fgi4rfJQrhsDY pHGQ== X-Gm-Message-State: AOJu0YwiJ7axxeK9Focx2i4j7sxgaHuuoiejzxcJT6tQNv2oL9UUvujp eWgvTyLEOm2qjbZlmIYHqtqhRcr9lJ6vfqrU2RirqED4XM2Oojv+yo+ZrWJGsFhbQacqLDHqpDd Lfl9IQf3IlEFwDJr0Y5FNgJp+zAbjFqDtiU6YXKSTMR5Zmwid347Awu5ipgi+/fk+/el6U6MXtq nlvAB5K3xWw5ZMCBEp3GwNBrDExPOOJWIdUvSy6w== X-Gm-Gg: ASbGncsZY1XgIU7hGnT6NcVAIpobZBUteVABc78CY9icXSOq7FH5W5BCtgeDPtD9P+a aVXXPtO8PP3W2dVXRatMkm8gN1hKBGg0/9+9b9SCVmajMOWnqQOcXZg9USem6BPki30pkWXWYja mHW0PSVdfzayBKqywK9vk5fqKjczWgBsWXBUERV3BpLp7/7cVA8q5uCDjdXU3h81C+aO+LW4O88 FZ5H/xacADMXis8ABEAkEdBntkLLS7Yy7lTuIOHGEvYgQf5hvCmliApVMocZZIBvYPasu790geM MekDKkyofmSzhA== X-Received: by 2002:a05:6214:29ee:b0:6f9:201a:c05d with SMTP id 6a1803df08f44-6fb08fbb38cmr236865716d6.33.1749496395370; Mon, 09 Jun 2025 12:13:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDn+ir+hW3TIaA3GbOILz2nlMFk6p8PnSGGTI/oGIjj9++F+I+OVoJ20havcr/iKCIvtfAGg== X-Received: by 2002:a05:6214:29ee:b0:6f9:201a:c05d with SMTP id 6a1803df08f44-6fb08fbb38cmr236865296d6.33.1749496394902; Mon, 09 Jun 2025 12:13:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 09/13] migration/postcopy: Initialize blocktime context only until listen Date: Mon, 9 Jun 2025 15:12:55 -0400 Message-ID: <20250609191259.9053-10-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496521717116600 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 98d4c29532..6ed4546744 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -324,13 +324,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 @@ -1238,6 +1238,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 17:17:24 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=1749496445; cv=none; d=zohomail.com; s=zohoarc; b=Y5JSJIM9AG6aUldNKrk+44clfAZFVgXN9XC5ikphL7QwHk67BhBcv4wH01vi8cdFzRREhWPEkdCXj4jOLsiUIUyoPjuO6/wcwKsf/dHjJp8bJ7SWK77tM0uN5H+GFyW+S0Q8aP6MhlDRaoKr6TDhnBlYPBBT+blVaHDIOINgurE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496445; 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=23L5yPZvHG4Cl7o3uwV6lHe0CI7eepSc2KOqycRd62o=; b=JjlyIsQDzAQguvifYmZtea6NLE30h0Oxc+OT3cFz2hLtxx1kG+A6hMmmBdVKpfOuOAR1C93hpg9VXEeztyQTXIbaOnhxCPukySrGN76kPmLgsQflDROiGIrSJk+ILGRYWUwE9Et9Sp6UEhSK06ip35emJo1jzejhq9/KXKHbQJc= 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 1749496445415832.597493261879; Mon, 9 Jun 2025 12: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 1uOhwC-0006Us-VH; Mon, 09 Jun 2025 15:13:40 -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 1uOhwB-0006Ug-Rv for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:39 -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 1uOhw9-0000t1-SF for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:39 -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-45-mvvtdy2bMtiJHXhAcf4-vw-1; Mon, 09 Jun 2025 15:13:34 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6faca0f2677so130862716d6.1 for ; Mon, 09 Jun 2025 12:13:34 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496416; 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=23L5yPZvHG4Cl7o3uwV6lHe0CI7eepSc2KOqycRd62o=; b=ecf9L0GoIairV+52xAvaIsg8leJiRp6EoTUjl9VxqE4vT3x91TW+8VD1SXVGAPKXMcvpm/ 4mykBZlE/ue6ibxSh7b89UHQRQ+c/3dQfl0DsofmlQ3C2bixiqqr+tjV9pYBApu4SYQVos 4WKzs8zlExDFP15YdIgS4ZDEP/pvOjw= X-MC-Unique: mvvtdy2bMtiJHXhAcf4-vw-1 X-Mimecast-MFC-AGG-ID: mvvtdy2bMtiJHXhAcf4-vw_1749496413 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496413; x=1750101213; 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=23L5yPZvHG4Cl7o3uwV6lHe0CI7eepSc2KOqycRd62o=; b=SKRqU7XxnGwN1wNT4ZS+XG2HMZDFeb8VMGu66S5LfCgLMjjUUf9gj4EhmP5XUQEsmd 4fe0/kKa1rHT2tjk7xH/EVXacVsFbd/iQJDis5dTv6v9fYaljYCmPm7ryv7+WYCrEs00 tE+0kwjnTKv59ik9r6/K/Cw2wqNJSlLKEcN3C3ZkSYzzTrRsFKdEItnOC7EHw/hNDhkx 6CGbStV6ENIphbyVy+TBvwwDUayYY9lGQCqmbVVOVc6ON5gxIm/eiT480qMV+xVix08W dhQMZ6R7ptIqIAsVRC28xV+rS9119SSm8OPsChqFczO7mKvFng/6hOplNycydtL+rWzr RVAw== X-Gm-Message-State: AOJu0YzpYg/w6ZsjumKciGU8ZaKpG/delXodBfWu8B0LSodMZMmkQgLh Wj5r6P9dJZZnwyKJmzdll9nLDS7qnI8Kz2D6bmZsniyFhXS+pUeouCoAQ7uNqMX9GUcW873aPSo +xfZS0Ol96GCM22DBORmmquVA4Pt4pEvemprlTSgYx/s4g3864oEdENjzt8JRz+p40kFFRkMekL /Y2hZ9X9MPxPG3YJDa5v4BCJCUKYyVSHE4yWmXFw== X-Gm-Gg: ASbGncu4nERifnhC+ug/Hzy0chc91uyW6u5Y6PpOoLefdi7yuusvJoT4NhaLW/ZOHKJ xlJnVoCqwJFFRMWwqKTx5AKQbNjyvEph9u4zv58cCC/fGLM0ubJX8EBkAPN08/EpBv//IeldDbU qdkiK8DsUDu+lMTKfc4DbkDMUGudZmayTxrbpZIRVqkK2T6Qeo7P8INYKof8f+slMrfo2QxhIcu 9Uc7rI1+Zhn8kO4R+GNxC3XenNPCvxMT/mqAYdty5XuR9vAEt32r08AwiDjx32O8cbF/nXQg38t NvM= X-Received: by 2002:a05:6214:27ec:b0:6fa:c44f:2ae6 with SMTP id 6a1803df08f44-6fb09054ff9mr257225746d6.38.1749496412707; Mon, 09 Jun 2025 12:13:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHF96GhhxhC92Zns2AttJG0MFbA1nfpHLr3jh80NrwM9NjgrLAy87gpg+uUg5Zm/RSUhFB9HQ== X-Received: by 2002:a05:6214:4106:b0:6fa:cb97:9722 with SMTP id 6a1803df08f44-6fb0903b447mr242966006d6.34.1749496396377; Mon, 09 Jun 2025 12:13:16 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 10/13] migration/postcopy: Cache the tid->vcpu mapping for blocktime Date: Mon, 9 Jun 2025 15:12:56 -0400 Message-ID: <20250609191259.9053-11-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496447046116600 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 6ed4546744..494bfbab71 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 @@ -826,18 +870,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_us(void) @@ -864,8 +911,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 17:17:24 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=1749496541; cv=none; d=zohomail.com; s=zohoarc; b=Y+lc3uoDuEduyNHaZC2HXRESeWL9MH49cHGStmBjD2h0G19r5nqxKJl1GThXt64lGBw2VL9e5fvVvdRUxfvEb9nYKuD5wCvQvwWT7wvbt+ESspTgtyUk7JFXVA2BwTYhhjW/UQ0wQMRaLkIKh170KfFzZKiMX92YEPLUIJ/Pu/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496541; 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=iq7xbPIA+CJC8vrhFn6C8E+xdY4lZ0qyjDI51Wr01Ds=; b=AyiFyHwgOaUw+LrAr5vYTW+wybu9KgOH3J0aBWrrbFU4dVl0OvbjvD5YeYAiJ1UbwuzvayRYaTEcdDDJGrCOv52Lqvbt9w4LK7nOdSieq/KOzLTC3kDSernMW+uaQAp+1ufVDpgkYW6aAucGUb0okFPO3zdWWdB415P2675wVyM= 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 1749496541303820.7950529285209; Mon, 9 Jun 2025 12:15:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhw7-0006Qw-1Z; Mon, 09 Jun 2025 15:13:35 -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 1uOhw5-0006Qm-Em for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:33 -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 1uOhw3-0000sr-Rj for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:33 -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-314-ps7BqtPTPeSuZVDqb3h4hg-1; Mon, 09 Jun 2025 15:13:30 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4a6fb9bbbc9so50102201cf.0 for ; Mon, 09 Jun 2025 12:13:30 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496411; 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=iq7xbPIA+CJC8vrhFn6C8E+xdY4lZ0qyjDI51Wr01Ds=; b=XpCSnjSa/gRdbEcnBKIwKm6cU1eD5+I9Kkb/Pho3yrofMG5bfPNgqJv5Nk1V3GCrJa7kfw vy9+u5mXLaZvsdgqoSif9I5/FwO/dHbNC8UrWxak9e/BrJnE3Ci30WqrKNk89Tqqu+xeYK /Ea4ADpln0wd7/s7THxpV9JOB+vFJmE= X-MC-Unique: ps7BqtPTPeSuZVDqb3h4hg-1 X-Mimecast-MFC-AGG-ID: ps7BqtPTPeSuZVDqb3h4hg_1749496410 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496409; x=1750101209; 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=iq7xbPIA+CJC8vrhFn6C8E+xdY4lZ0qyjDI51Wr01Ds=; b=Oa1pzDn0g2m+NTlFx4OFZn5eLPkz36VK996BGFJxwCYvrRy0LiCQUTuLzskJq+FNU4 b8Y8Nz12qDgYg9P11adb2j1Ewn/5+Lb74G56uswnbYBZP/0HIp9hBfFdrjOWz/mkKIwB h+yKKaHgT7l+XGua5sAKJxr2MsRkPKmQbmGMLy+iNfaIjRMsmK4aoLnOHkiPvcjRC+Ex tpgvMQvSsKLqjhi7IMsF+OQ6EyyMyfjnsqoMZENuPcEu43g8BDvc6ZX+0cOge76ihV17 oV/JKN9Zfh/IIJAnJD9Iw8CvwQriqN3pavKSIlIX5MYGV7ol6x8jR7Wui3xeaQxquMs+ 7AyQ== X-Gm-Message-State: AOJu0YzGOBrF38mN0gC1IJX6MHNaCnkAdwDtFq6DDitPxcqLYhSWXkYC ychTPz1LTXMfpC6SFgWtvWCOpPfv4b6cYh6WtrtGVD09RDVyr85IEtRV7sOlTYoGRIP9z9zlb09 ZAQEcZyvdL/PMVHdtyYwxqyBkGNL1fDqfOkgJxTH36CkxHKlm8e7fqd+eYnnaevztKhBNCNcGN6 n0ZTSjkBMrUeVvTJOR4s10PhVgZBkZNWEsQVeN7w== X-Gm-Gg: ASbGnct8kYNGHv3ze1OqO8Czv8kRM6SOL5MDWVw5Renbi5g3tNlH2nWClYaNGo2g+1y cgZbWiHfB3+EirdA2o2GTYZ+Nbcpw8N/FJjo/buglJ/ChtGbci62FaBPxVdXCNKgq8xJUsuHf1m CK8vEfTA/LNJfNzYh6bVnT4H2hmlN4VtX9+VVrtm9YKyUKAm++6AZSvtbymHqZluEfvo89D8R3j 1lukwP1uZ3xkNazCMRd6KfAYiQXEDTeTuG1KpuWnHeKYpkQI2fphLelc98THQ1qV8/+ui9ai7Tg Gq8= X-Received: by 2002:a05:622a:5984:b0:4a4:2d7a:994b with SMTP id d75a77b69052e-4a5b9a436c6mr293068441cf.19.1749496409255; Mon, 09 Jun 2025 12:13:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVFP7RKaP8qjzzj/qm8SQhdvvZeGhwHLlxFYLVPRYHFLP1P6x/L+0ucwCY3M7uPzPpl+30XA== X-Received: by 2002:a05:6214:cc5:b0:6fa:ce21:cad with SMTP id 6a1803df08f44-6fb08ff4381mr223557446d6.18.1749496397568; Mon, 09 Jun 2025 12:13:17 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 11/13] migration/postcopy: Cleanup the total blocktime accounting Date: Mon, 9 Jun 2025 15:12:57 -0400 Message-ID: <20250609191259.9053-12-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496542014116600 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 494bfbab71..f222239c7a 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -971,7 +971,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_us; =20 if (!dc) { @@ -993,20 +992,19 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) dc->vcpu_addr[i] =3D 0; vcpu_blocktime =3D current_us - 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_us - 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 17:17:24 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=1749496529; cv=none; d=zohomail.com; s=zohoarc; b=FEZIERVoplGr2szbcKyKO2MP+UuL+FLXUHjACGxi1vlW25MfqMvzOM4tpuI3ajipgHmyiEXtJKBkbixd+gB83IrujO79x7ik7ARDBmMljsGvAqqJRKW57lC7cY/0bA1xIluYdv1Dorq3has9NeQC3qRDpAHJgghQuZ44V3TwE6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496529; 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=kHz1ZiVNimjWbliZpLfjT529aWX8tmRyFQob+Z/E9kw=; b=Ti4uAG7iDsFDIPoLcjlHISi434O15zJ2OAgv5TqdyH2YvFyUGstc7LsLzr4Ul4f0e0iD085XYkM8VW1Ml7rqINYmi0XK48SoUU9izwvHZ3t8DZEnRmMVG+dzCNX19i1ElzISQkW5UpiFrMobbiRjtFfB3nm33hMg0GJxY+AopVA= 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 1749496529651201.74488924522188; Mon, 9 Jun 2025 12:15:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhvy-0006Ov-R6; Mon, 09 Jun 2025 15:13:26 -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 1uOhvx-0006Ol-L5 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:25 -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 1uOhvv-0000rR-2v for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:25 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-pFKHgP0SOjm1Uf1IBZGYBg-1; Mon, 09 Jun 2025 15:13:21 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6fac71417c2so77106606d6.0 for ; Mon, 09 Jun 2025 12:13:21 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496402; 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=kHz1ZiVNimjWbliZpLfjT529aWX8tmRyFQob+Z/E9kw=; b=eZoOhj0ScPzVhlQIjPECwLHKtSVpw3HQ3cb/B+1ggqN7NQaBvlKMaIkHohsAa3cEe1H4a0 KvKtNwikgZSl58UlGAG6iVk5yJ1doKmROJMGNDvQdi+v7MOA7E3NgHfDLOEAuAtPwTXlXs Q/Rq9YqcuSbunHJPTsFx4/47W0U0CcE= X-MC-Unique: pFKHgP0SOjm1Uf1IBZGYBg-1 X-Mimecast-MFC-AGG-ID: pFKHgP0SOjm1Uf1IBZGYBg_1749496401 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496400; x=1750101200; 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=kHz1ZiVNimjWbliZpLfjT529aWX8tmRyFQob+Z/E9kw=; b=F8CXga9Nxz8J9NHF4MckktmqaMmSbgRnEruJX9mqnndd/2Anlj1rGvA+U0wOH2O4+N upX5JojZzZhyd07Noixod8CZ9/vV+bsKr9admcge2hHfyiP2FghxiXfs4UA8xRu7foy/ EcF13dCt0lav+b2HWBF0i/QhcTozALLBGsLYflNHlz+yBKVQFglb8xl9AWnXSQsnZVUe SmN4B5OXIKtG2XbQsDspFV/4h2RmuvrUtd2auMKthSrOq4l1PSXBIoLh2H9ax7agoRaa VUmgDKonbdJMMuRIli+6I5w1JBZZb/dZEqb/1PmqHWCsBvtLtrZU4jTnC407cmQqifbG CfWA== X-Gm-Message-State: AOJu0Yzl5p+lt9vY9Fjf3HRGYIC8KC70bE/cI51W0DYLPgasQ7/Eg07Y l/5PBXN5YNCx/07nDqmeJ976EIW9fL0m/ejSegiDlV5YtaD1ix18o9Mb8x+KJ1yzqjJIPnhGGBj aIt1lkOvcfYmXTJyLUgyFAOOwj1an2I5/ZfSnnrv0KrOnpj9U2me40+hVv0ofekbsm6Ty8BAZWp w9myEKU1SJ4RRYV2Pwjr+VVxaR0JRpVHn0gcgFeQ== X-Gm-Gg: ASbGnctY0H2vVd4ODuM6LWEMtzl9MPTOie+uq/3TfESeR6kRIk3Z15qSb8DQQt9lku+ YqyXczVO4Uzu/Fue526gjGG0arh1Xdofg+q5RUlJtbRYuoFGNGjHb54yJI5A9evCSwrVWbHNt5P 7u9lbXStZYKRXdTvf6QgLSRNpEzho/YULLz2u49Ia5T0iLRVjJD6fNm4owYAFBDk3op+VtUPE6k waCSjR+7chm90NC688uVnRzlwWxhVGHaN4tSjbpczQPkbkWJFAUUvgje9m/UgTDZy4tuKbZ5JuQ wkBo1cLUTZ9rBA== X-Received: by 2002:ad4:4529:0:b0:6fa:ac51:bbda with SMTP id 6a1803df08f44-6fb08f63facmr163691436d6.26.1749496399357; Mon, 09 Jun 2025 12:13:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiYOyA7VSNhTO72Ney1P5YTsJPhjlbBSxYrRMih3UJ2vlhIqxPwQJhLECGWllAlICrTYTjxA== X-Received: by 2002:ad4:4529:0:b0:6fa:ac51:bbda with SMTP id 6a1803df08f44-6fb08f63facmr163691026d6.26.1749496398741; Mon, 09 Jun 2025 12:13:18 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas Subject: [PATCH v2 12/13] migration/postcopy: Optimize blocktime fault tracking with hashtable Date: Mon, 9 Jun 2025 15:12:58 -0400 Message-ID: <20250609191259.9053-13-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496531964116600 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 f222239c7a..fe0c2ce225 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 microseconds (us) */ 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 @@ -892,6 +982,39 @@ static uint64_t get_current_us(void) return (uint64_t)qemu_clock_get_us(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. @@ -911,30 +1034,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_us =3D get_current_us(); 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_us; + } + + /* 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_us =3D get_current_us(); - if (dc->vcpu_addr[cpu] =3D=3D 0) { - dc->smp_cpus_down++; - } + blocktime_fault_inject(dc, addr, cpu, current_us); +} =20 - dc->last_begin =3D current_us; - dc->vcpu_blocktime_start[cpu] =3D current_us; - dc->vcpu_addr[cpu] =3D addr; - dc->vcpu_faults_count[cpu]++; +typedef struct { + PostcopyBlocktimeContext *ctx; + uint64_t current_us; + 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_us >=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_us - entry->faul= t_time; + 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 /* @@ -970,43 +1137,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_us; + BlockTimeVCPUIter iter =3D { + .current_us =3D get_current_us(), + .affected_cpus =3D 0, + .ctx =3D dc, + }; + gpointer key =3D (gpointer)addr; + GHashTable *table; + GList *list; =20 if (!dc) { return; } =20 - current_us =3D get_current_us(); - /* 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_us - 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_us - dc->last_begin; + if (dc->smp_cpus_down =3D=3D smp_cpus && iter.affected_cpus) { + dc->total_blocktime +=3D iter.current_us - 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_us, 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 17:17:24 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=1749496519; cv=none; d=zohomail.com; s=zohoarc; b=kpjWg7B4WYt0yyUByUkqvQVKNhLQeh9OBczrLFbTTCXyUqzDKXYxUzu4q6t8zf0GsbfQiG8N8LprYmA+znDXX4zegyuNjlW+o+sK0emys9lYW3K3zqPLxZ3LwAg8FXCqBg64BGYn2mnvxzN5UFbY8dAzuzbLzMgVDv3AV4cfoKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749496519; 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=H+0dxBgcrJD05UEZ9RtM2gpVlmr//hQAVm1OfgwPSoM=; b=ZdpRWXCl/4c8UPjP5hlXvOegbyfvX9dfQvM70TnXo+ifQSjocPZcAJCAKCwzksMLFfTEjboqX/A1owT2BNuraOUojkGubbVZTy+en/Z+Togs5BPA2PmRjkZTyL3yo951AhPNmLA+xaqd8F8i//1ax14A+w+Micz6EVWD9R9KoqU= 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 1749496519429275.2474220395469; Mon, 9 Jun 2025 12:15:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uOhw4-0006QW-AD; Mon, 09 Jun 2025 15:13:32 -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 1uOhw1-0006PX-Ag for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:29 -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 1uOhvx-0000ri-L0 for qemu-devel@nongnu.org; Mon, 09 Jun 2025 15:13:29 -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-573-IIl2SZHEPYGg_vaVI7c6hg-1; Mon, 09 Jun 2025 15:13:23 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6fb1c6b5ea7so21570146d6.0 for ; Mon, 09 Jun 2025 12:13:23 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb09b1cc24sm55178856d6.72.2025.06.09.12.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749496404; 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=H+0dxBgcrJD05UEZ9RtM2gpVlmr//hQAVm1OfgwPSoM=; b=JEFB8qyp0p5E3ONPgMTDRmDpu8xZ8jClMwbzPw2go8Lu7TEpeUQuZVKPwZFN61KrSsaHaC iOWmq6U6Bky9uutxNP8ukuaAnVMZn4kBickA5Ll1SFNubrCapNu6UvPTDV6smc0R85FRmR uKrBPo8+c6l1afrwK4N0jaCAQPtg1Ns= X-MC-Unique: IIl2SZHEPYGg_vaVI7c6hg-1 X-Mimecast-MFC-AGG-ID: IIl2SZHEPYGg_vaVI7c6hg_1749496403 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749496402; x=1750101202; 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=H+0dxBgcrJD05UEZ9RtM2gpVlmr//hQAVm1OfgwPSoM=; b=nDxUzZlWA+4QZPXV+BrmltFuiB8VgicnVZDQC81ehVtFON90tBnBD479wtBcJ70RXx ETsJ4pieoo9mrphhgCoGofuFYGwc42FP/aguKEIHGaBeUWIlJMyqMCaZAlM4sGfa6hUB GsWAhJtEfe1ZhHmyFS3hWc9xPrXu0yc9XFpRQ/bh7BT/aBo0P7MZc0fmDYdz0gJVbN9W QJ0cnuLjTpkS9oebvFNg33WUBpT3rJF4MnCvY1sBWohkp9H0lFzAJCsq0KtrrlAz/kSa boqEvvl9h4ierksIQHH/JEyd36I3q+gpL1j1wx+mTxAkZDOGhSueEtqmQ8vhRUnE/314 9Hgg== X-Gm-Message-State: AOJu0YxRHBYn/Z22cDv6ND4jUWZgFKaoLqDqCcWIlyEyMDeUAFtdPmRo UE01EIyNmyCdryGsRCuuffiZA+A86AHFAjgKaFmblg5tMIbwWKcfviviLEdKvxfdVxOrYnrj5nS KrYhrv0ny7oX6sW7Ocklw+yVLRwUEcp6vZJQ+FhuXi91CghsGS9e1Mt9mjHSL/Cn7rPrIDXQH/k xsjtTFzOBBX+HkuC23NLeW3BUvfKHywV6iY9ujQQ== X-Gm-Gg: ASbGncvtHr5u+IrQKtLN3HqPOGtlBDBkxyI51OKY7DuwDnee4xBMPYwpjyunGuuiPC/ 2wX+sQt88CLjKkJX62MGAB7rqOedItPUNQbd6Ua0TFFXkeeV1VI1oF86exNMkC8MrfdfNmhuudh s4Wjj7ybKryXTmLOrKet7saqvjFhlnkKral8uKfDc9OfNAHC2XAoon2Q/dvua6KVbPi0CpJQZNu 4WJcrzT56/nkyW1M5kqKpzoMHcwJoNTP17W3S/ITpRBFaDFKSpyEChyjDghvxedqIhZisOhW15L iBjDkfjhVZXhjQ== X-Received: by 2002:a05:6214:1d02:b0:6fa:c45e:34cb with SMTP id 6a1803df08f44-6fb08f4f424mr220899166d6.5.1749496402457; Mon, 09 Jun 2025 12:13:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSfmD8FfGk6IDmZYYwqE/naqggarJRNB/qS7CjmEcJuWUkdH70aGMZQ0vtqtwML4KUd8VpjQ== X-Received: by 2002:a05:6214:1d02:b0:6fa:c45e:34cb with SMTP id 6a1803df08f44-6fb08f4f424mr220898706d6.5.1749496401879; Mon, 09 Jun 2025 12:13:21 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexey Perevalov , Juraj Marcin , "Dr . David Alan Gilbert" , peterx@redhat.com, Fabiano Rosas , Markus Armbruster Subject: [PATCH v2 13/13] migration/postcopy: blocktime allows track / report non-vCPU faults Date: Mon, 9 Jun 2025 15:12:59 -0400 Message-ID: <20250609191259.9053-14-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609191259.9053-1-peterx@redhat.com> References: <20250609191259.9053-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: 1749496521966116600 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 Signed-off-by: Peter Xu --- qapi/migration.json | 7 +++ 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, 64 insertions(+), 15 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index e95b7402cb..cc680dda46 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 us). 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) # @@ -288,6 +294,7 @@ '*postcopy-vcpu-blocktime': ['uint32'], '*postcopy-latency': 'uint64', '*postcopy-vcpu-latency': ['uint64'], + '*postcopy-non-vcpu-latency': 'uint64', '*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 600b0f8071..4445d6404f 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 (us): %" PRIu64 "= \n", + info->postcopy_non_vcpu_latency); + } + if (info->has_postcopy_vcpu_latency) { uint64List *item =3D info->postcopy_vcpu_latency; int count =3D 0; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index fe0c2ce225..23332ef3dd 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; info->postcopy_blocktime =3D (uint32_t)(bc->total_blocktime / 1000); info->has_postcopy_vcpu_blocktime =3D true; @@ -982,7 +993,10 @@ static uint64_t get_current_us(void) return (uint64_t)qemu_clock_get_us(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) { @@ -1065,9 +1079,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_us); @@ -1077,6 +1099,7 @@ typedef struct { PostcopyBlocktimeContext *ctx; uint64_t current_us; int affected_cpus; + int affected_non_cpus; } BlockTimeVCPUIter; =20 static void blocktime_cpu_list_iter_fn(gpointer data, gpointer user_data) @@ -1084,6 +1107,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 /* @@ -1091,17 +1115,27 @@ static void blocktime_cpu_list_iter_fn(gpointer dat= a, gpointer user_data) * later than when it was faulted. */ assert(iter->current_us >=3D entry->fault_time); + time_passed =3D iter->current_us - 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_us - entry->faul= t_time; - 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 /* @@ -1140,6 +1174,7 @@ static void mark_postcopy_blocktime_end(uintptr_t add= r) BlockTimeVCPUIter iter =3D { .current_us =3D get_current_us(), .affected_cpus =3D 0, + .affected_non_cpus =3D 0, .ctx =3D dc, }; gpointer key =3D (gpointer)addr; @@ -1173,7 +1208,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_us, iter.affected_cpus= ); + trace_postcopy_blocktime_end(addr, iter.current_us, 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