From nobody Tue Dec 16 09:10:58 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=1748387720; cv=none; d=zohomail.com; s=zohoarc; b=dxwOZAZVlkM4LTw54GTMhGxil6Rdikf9fzFV71tq6TX8tlTBovRNlHrSOKvjjPzmRCBPNtoF1yM4ea6dBqqcWT1brPt/pDi/BLHXFELvVwSluYdqXU+zA2szzAWM76fsFXon5HspgM1VljftY6iysAIXuQTyqWs7OYfbM6/ZORg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387720; 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=0Y53I0D3GZiFTm9LYMIu17qA08t/JehTcfVK9hw98nA=; b=Lyk+0UAthGyBXfkPAvnbuIUi63CIerXe87veCj1Pmeq4q9v6x+Zzz86qefFjBxin+YdF92R2otqLhxGtchGze3Wn6WJg/sx0UrP6LKxXvd2AHiyT2ZmnPJkJ2Ja2QEV+8wfvfh09UqxubdMw0WhkxNNB0ISfnDlibejGDAnsHco= 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 1748387720099514.7302827150805; Tue, 27 May 2025 16:15:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tr-0003ID-H6; Tue, 27 May 2025 19:13:11 -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 1uK3Tq-0003I5-6S for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:10 -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 1uK3To-0001DG-QJ for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:09 -0400 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-YwTxTaKFPFGk3_WoukrV7w-1; Tue, 27 May 2025 19:13:07 -0400 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-400b3a7e434so2888769b6e.0 for ; Tue, 27 May 2025 16:13:06 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387588; 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=0Y53I0D3GZiFTm9LYMIu17qA08t/JehTcfVK9hw98nA=; b=DXCY5xbB+faIQkX/OU25Y9MYSCsq0SHeKEEsAXAfB8ToqjEQTdgAF04OvB2MiSYYPok9Au GgVifw1XCZGJXbeYTVjCO65mqZX0SiNf1BPDLywUPiSqIK+k/sGX5NM6ppvTNAInIW/Qv7 spUxfaCP+ZdNH5ROmlPdGjmhBCyDO+k= X-MC-Unique: YwTxTaKFPFGk3_WoukrV7w-1 X-Mimecast-MFC-AGG-ID: YwTxTaKFPFGk3_WoukrV7w_1748387586 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387585; x=1748992385; 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=0Y53I0D3GZiFTm9LYMIu17qA08t/JehTcfVK9hw98nA=; b=gFnOQHtaeVwt1ZxPm11431tvBIoRAnUD7K/RVDcqnG+CRXiRrfqKI0IDvGHPg+eTZH 3F3lo5BE9URObwRhkFRjIVgrVbzC42EuQ1jVFnTn28Y3RVt5Qcv70MQGVKD2Byv27o9X SBTKRzzbwjJr1X70cuiF7q3qRNnpWhl15IiR7yVd//M6GlzSHLUgGhWQNzpxEuk8n5bo Sn2P4Rl19IbUV70+CpUj2FFUARKFCwEgHjNOXcrghMdu05RQal1uDbyjbguPVfQ9bSjR 3IlDYaW3ZC2fsG7vHISjeHJCZTHPKwBzXzrRP8NEiNIjUmlQbBIGjO4XEsfCTPGyF/FP uNnQ== X-Gm-Message-State: AOJu0YzrwGWieiCnKLgBgvoArXp7qJ+1Ea2Kxl18PeXlW/dGtDGpo9eV WPtwzN66fe6tO/wxZ1i58EEKCVUTAM+D0qB5L3gI8hVdDx4CTiEY9A7xwo0pswaMLGaXf9cpBcY S9cmUq/KBaQym1wW2z53noaF/bVGNRSECBD/lHd0kin3t66Q1vWr3Hk+UyaYv/0NV17HADT3qRN ExCQsMkAXW7oieBZC8YwrPSY3oHjrfo6ijvcm1YA== X-Gm-Gg: ASbGncu0C7UBQwUrIyV359I04rF1BESayQKnCQdlmoQz1QuAHi1/3CYeZkQ7H9mkr/O zhilpdLP0rwhoiS7ClbhUbFvtEz7hU16mJp/Swc043f2y/cZToZEYja1J9ZfvKFnZze3QeiB00m NoRLSX+4dcDPey6RmbhBxGXAj/js54yKTeedZHDJCArZEB7aZPfZU6WCIvhTCqJdHZDxJNggPfr hY+pyGOiMw47iy+6QF9+WsWXjsqL3pCquiFQDray7tGg77wydOXQb6YC88suW7+Svw+8Y6Flloz X-Received: by 2002:a05:6808:318f:b0:403:3814:b2b1 with SMTP id 5614622812f47-4064682751dmr8762698b6e.10.1748387585270; Tue, 27 May 2025 16:13:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEP9asC+b1CGOqCs53Y2ROuUFZ4oTQhVTQ2s7c+MiaL48nwy8im1wz38Im1fnvPR4snHD/OXg== X-Received: by 2002:a05:622a:4248:b0:490:8fdf:3df with SMTP id d75a77b69052e-49f485aa63emr248990761cf.32.1748387574318; Tue, 27 May 2025 16:12:54 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 01/13] migration: Add option to set postcopy-blocktime Date: Tue, 27 May 2025 19:12:36 -0400 Message-ID: <20250527231248.1279174-2-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387722243116600 Content-Type: text/plain; charset="utf-8" Add a global property to allow enabling postcopy-blocktime feature. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 Tue Dec 16 09:10:58 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=1748387652; cv=none; d=zohomail.com; s=zohoarc; b=lgKs2Xfyh77SvhBqjbuG8d/2Ad4qz3p2Z04/4o0CzV6r2wu/tbg+w/MX1H6z/y1tXj33YWOIanFeB8Bakmfh2lPZZq5tK9xV8SSCpZXQ2/M++mbpGFjsuaaMTWyhLj+aeSzcjbT/HHn+38qanKh/xE9O+fuXT9kjrFiCpugiLQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387652; 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=GPNhVLR75Cb8vTsSD3XAsBeRSsMz6hlXzXW6otJ5R2E=; b=Rdnef7wnk9bD3dIYq7LOU9QLYe8AUJFSTi1V1mY99L4ThJYU6FCyGp3GWUokPNkx1PCO6ByjlmRmwt+75XHkPaUZNwCA29T/9CJYC3FwtRUaiFBbKpJewRKapH0ufV3najnKSzp6ogSv/rq7ds1i/Eo3heHcwn8kCokcNK4b8po= 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 1748387652294241.64336126985938; Tue, 27 May 2025 16:14:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tj-0003GK-Mn; Tue, 27 May 2025 19:13:03 -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 1uK3Th-0003Fo-P3 for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:02 -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 1uK3Tf-0001C8-GX for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:01 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-zdBqzLWEN7qY0HCYTWIozw-1; Tue, 27 May 2025 19:12:57 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4a35b701385so1422521cf.0 for ; Tue, 27 May 2025 16:12:57 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387578; 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=GPNhVLR75Cb8vTsSD3XAsBeRSsMz6hlXzXW6otJ5R2E=; b=LTvpSZf7OcHwDkSe8L7ZQLby2VJoo0WJjugWF3o6CLMvxcHduVY7/5ojfJescCViH9Wk+D az4VkzbnwOmboHXcm3uzszzcIw3GU4ocT9ZcrJniU4YZAqc4nuj9zwex7ypiy0dRspd0YS F80tuJiFf49OQwHULX4xFD7P86TuFiQ= X-MC-Unique: zdBqzLWEN7qY0HCYTWIozw-1 X-Mimecast-MFC-AGG-ID: zdBqzLWEN7qY0HCYTWIozw_1748387577 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387576; x=1748992376; 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=GPNhVLR75Cb8vTsSD3XAsBeRSsMz6hlXzXW6otJ5R2E=; b=i/vTzvVhm7EKelgXE+uW8TOs3y375y/qFmLtmXtJRZyKLOV9ZxEcEDRJ6uwty4tJHB DP/MhaV4NYJQJhSrJfnIthMjZsVW/52jk7TVm3XJt73FB8gAXRLDdXm7d/NPcAhNhkUE ESCNWeCwoUP32n2nqLy2q/81DTDhk4trGLIyubLN+yEI/kvMXfWm0M0v7YTwugR9/DVS sUBjOI7nh+/guJvR2gl8RQar7+M0jgqJBpjwOErqjX4lsTwZb+a2bO+9Vo6v/dyEn8BC 0STdUrlKno6tfSFCQ80JLV7ypBgR0/YJ9QXLIujh6TogCyl7UytMa0VhOCrwuK81VugS 2ikQ== X-Gm-Message-State: AOJu0Yza8jbdAO+23daxGu0dXmdbGPJCzo58rrsSX1oGhnzQCD6lrG3V JggLknfYt9yXFwmRFTm4OmDhPtOAbcBCbPXmP0yToFqJrvpgmqn70UnFI/TtWyke4+HBL3+pt80 McZzhvXsGkR1Rka7Aw9mwwEb+kO0dXpoztpiUMtUtwZx5Ht+9A88YPMsF/jyLKnN4TKBZVKsAbS tZQ8hFf6YCmONXVdcbTWnf37eBA3XHTMOJhBznQg== X-Gm-Gg: ASbGncvYeE+nqYUGF84XDBcPTr+2UPZCyTOivpJXIuwEYSG+yTwgLr9IXldbP6TeQdT sU1DtZLhSMg9omKvSwTYKYMVHuS58vDqUyRz4TdBmvABYEb9GPSiudzJEXN9eBcVJDnllRn4hF6 XP3nlPCoxhlep+dCKuRnit9Ppe/9bY90O0U5NgFbuom0D2bajNfagkrDBX5AKzrCcVQUlDpz98E KsR7MOf8Kg6ktASPjIiPDm8Ibjmqt1brb2AQoHSrrXDMVCLefMk96hNojLj8xAlPvwklOI9peUt X-Received: by 2002:a05:622a:429a:b0:477:1f2f:1717 with SMTP id d75a77b69052e-49f4655c2d9mr249432561cf.20.1748387576389; Tue, 27 May 2025 16:12:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTTxkqA8KF2AvbpsAMbmz4mHmx/wEn/wh4aJfJXImP/2HRpgjXO9mHl7PlXrUO/dq/9g35HA== X-Received: by 2002:a05:622a:429a:b0:477:1f2f:1717 with SMTP id d75a77b69052e-49f4655c2d9mr249432101cf.20.1748387575862; Tue, 27 May 2025 16:12:55 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 02/13] migration/postcopy: Push blocktime start/end into page req mutex Date: Tue, 27 May 2025 19:12:37 -0400 Message-ID: <20250527231248.1279174-3-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387653700116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 d53f7cad84..9ca2b21459 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 e542c09755..4e917b5fb0 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 995614b38c..9db3eefec4 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 Tue Dec 16 09:10:58 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=1748387673; cv=none; d=zohomail.com; s=zohoarc; b=ewIn14guDZHL89qb7XuXQ25zTa4eBP1QA8fZmtLvWUiJq6apDY0vExylqzB47Wsazb+4LQcqpK+gzUIu+zNj/BnlaVNAQS6bQ+8ONZV8h1JbnfI+BlAVwbMvWIZLMsP/N+apQwgeHqezyvI1nCTnoeKZVxTLwWto8ZXhhkIQTY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387673; 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=w/hTimLfZ82o3Gbt7wDLVs4TTZZVjdvxyDmBoPsW1WQ=; b=Yn84gbbrtdvMan2CUPS1FCEf6PxebEF+r8rGpJ0nZnxTnM3wiks+Yr3DW5ed86Y9UmRgcQSPjyIsvsSymeLA0EwDylt/cTMejFKXtYOYq9HnaDfitzrpN6HTizNCKKXsgy9S7Dau2Wmk43KSQGMoUUhfjbqylljXSngBHd/WTQM= 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 1748387673287948.0085697511546; Tue, 27 May 2025 16:14:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tk-0003Ge-61; Tue, 27 May 2025 19:13:04 -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 1uK3Ti-0003Fw-J3 for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:02 -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 1uK3Th-0001CK-5Q for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:02 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-sbDKvI0hMtqWe9G_aYU5dA-1; Tue, 27 May 2025 19:12:59 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4767e6b4596so65624201cf.2 for ; Tue, 27 May 2025 16:12:59 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387580; 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=w/hTimLfZ82o3Gbt7wDLVs4TTZZVjdvxyDmBoPsW1WQ=; b=Y5EiyNisnsa5I/AbyDXQ7InidwJdUw1lcTRkzzhk6ehSVykNvdjRMFGnNL36V+WWypRzNS vPrX1CkB+vQXjHZf5vlnvQ+kTkjAWjXxD0mFCmBZQjdOjVSXKbNz1DvbhHydbezohHed2O 8z/j0MAPl+KxXotirsukYHJEK3LiGrU= X-MC-Unique: sbDKvI0hMtqWe9G_aYU5dA-1 X-Mimecast-MFC-AGG-ID: sbDKvI0hMtqWe9G_aYU5dA_1748387579 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387578; x=1748992378; 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=w/hTimLfZ82o3Gbt7wDLVs4TTZZVjdvxyDmBoPsW1WQ=; b=NCQ6Oul8oXLeHbVnQ3wrzjIewwg/KVw44Blyzlftn6KxqgF1wcVzKRbJgCjjejqIt2 8Baf885tp9maj0UwmfX/FbgTrX3loNdfeCxRii4NzhJJQvhHW0tysyceNoV/ZyZ90C0E v43sVOndQbTrWzlrbpLng08Lzq9NvpGnT3DBjktxgRDr5nQTO54PETnnOg99opgKf1Vh Rwo+fxY6oSEkZr6YuUthYzBm4h51EfbOPGM0PufFB/6UN2toF6Mz4LzAwiaqLDSvsq5M rZI3ibqJpGoAcbJPxv//mfVfLsyTXDa6HbKu/vA2Zn17umtYKEa06FJ3HR/INSw97ODe xrbA== X-Gm-Message-State: AOJu0YwxHTNAXsb3uku5L/gZl0iVzy2bz3YcFqbxPRDh77VaiMVguyEh A7vLcag75peW9hUS47enO1/9h9dbGI1Y1ACKpdvLQ432WpaXJPID75yxOv1kMGjXKpD6o/PK+EP kawIvx7iA4Zt0CuiHyUFKQjqVmPKOYiFWxgI5n6oqdZniVldoEEzIEZi/N47zR8JJeC7s06S3N+ xg8wXmiAgvdlFRo2Bbux6BsyPiX/Y69sJ2pg+t1g== X-Gm-Gg: ASbGncv8pnZzYDu58PwW2Nz95PrGhE1jKF35hhZy8/4QxPOGGz+CDoR4yTFGyxeLdpl ErFn6ddWk2xgyK9mdhEMl/Hy8b9SacfgVQAzel5upEItqpoMcchduGL9Ob3MF8PRrdbjEa7QfZV RdM+zNvsQ96DvmGvdAi9vljNajp1MA7Usu9whUeuLxiE4sC+7oDqw7PPus8yQ2wP7N3L1Xtkqwj 0/dPpV8F4pwo1gA54frT5Or7544d4xzw2h4EGai6Yi4eI11mBdRUTpJ2U3ot87iq1/h1QSwOi/Y X-Received: by 2002:a05:622a:5a92:b0:494:771a:9b48 with SMTP id d75a77b69052e-49f47fd22edmr278737311cf.50.1748387578421; Tue, 27 May 2025 16:12:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkmxz03xZq2YTkX+OfVoEMdFkZJ/d8LrbKsA27FpDAo0eX3C2wreaoMlBfZ6G7wFIKYqgO4w== X-Received: by 2002:a05:622a:5a92:b0:494:771a:9b48 with SMTP id d75a77b69052e-49f47fd22edmr278736821cf.50.1748387577966; Tue, 27 May 2025 16:12:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 03/13] migration/postcopy: Drop all atomic ops in blocktime feature Date: Tue, 27 May 2025 19:12:38 -0400 Message-ID: <20250527231248.1279174-4-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387673702116600 Content-Type: text/plain; charset="utf-8" Now with the mutex protection it's not needed anymore. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 9db3eefec4..0b4efdb7fe 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 Tue Dec 16 09:10:58 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=1748387650; cv=none; d=zohomail.com; s=zohoarc; b=ScmRa15BRunpvuMTWftVn5UHXFR+PTawsO8CJX77759QrwWYwdelbzr4Ojxp8yrcPx+m1+YQK1E/W8J3x6pTw+Rng/dpb/eTJk+3yYpZZJ5GOf5CmhotkYtjSvzJPHKdw0d8iB5NUf6qcEiXQMHzgQyiKfY5xtS8ez30SttbHmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387650; 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=waqYVisExF/u90qvIovGoOtwdbCVAl6FBk52fEUH0mI=; b=GHxB6RIbMzfhcyie0CqcJoeiitjOxfk8yEs8z1IiKbmnY+UdfZXdOyVKbCtM3xpPIOBdF0EKK3Z6MWDAeJQfThI1+N41O8TM90jte/+l1wPSmbVwX/Ym0gI7wCm8RPodmKt1IGHib5G/OT/Cq5mITRRHv1czgEnMnnrUuqleygs= 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 1748387650554836.753120671026; Tue, 27 May 2025 16:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tm-0003HL-R4; Tue, 27 May 2025 19:13:06 -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 1uK3Tk-0003Gi-NA for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:04 -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 1uK3Ti-0001CX-Sf for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:04 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-M37mS82WOfmLgjqp9PfaGg-1; Tue, 27 May 2025 19:13:00 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-47693206f16so63477911cf.1 for ; Tue, 27 May 2025 16:13:00 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387582; 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=waqYVisExF/u90qvIovGoOtwdbCVAl6FBk52fEUH0mI=; b=ORkx98ONZl7fsVbfHG76qEBcDunhjxiYpKsVfG/hMrxREWOuHCHqDZCk1pyIYrbmN2vWS8 rsFmUogPfqV2TenXqC646OS3kUABNdS46tnUw7UKcAV/zEXbarPCU1vLyoR/YN54lUOHHd a9LzjJYPKuIlbUREdwCDaCrLrxb8xoE= X-MC-Unique: M37mS82WOfmLgjqp9PfaGg-1 X-Mimecast-MFC-AGG-ID: M37mS82WOfmLgjqp9PfaGg_1748387580 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387580; x=1748992380; 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=waqYVisExF/u90qvIovGoOtwdbCVAl6FBk52fEUH0mI=; b=f7kR0/87p9nFMmtyrNUC8PnpnU8XIXKK1IDr5n1JuDByM0bL4ZizKXM8AhmzHuyS7i PRI7gwt9mtP7nSI2iYpup3LQm2dXcov18+51479Iy1sLkohyYivQzui1XigeN1VJAS3O VPlqmad6fBqtf1sH4RW/RXi4KjC6pl/bdvBCw3ZbPFv7YOYbjnBoFjYQRzhW05TWnDb7 pfr1wIt5IpWB3NlJRh9EjL0miL0/sA9tRP8Q9S+fece5f5z63xK1X+QORCO9/9JNHq4a 1+63ReYHtdBCBwXYBQJDzzbkYMrAwmKa15uz7Z3zJEwRutIIbScNOtMuP+u6UBSCpCcS +07g== X-Gm-Message-State: AOJu0Yywue4R9Di/Wsd6pt1VjXFKapn3/ngxLfzsHzpJjwDQ9QKjpMDn CV7Xz1PQzCaYGeVDChBMInuOvZvvsknP+i/4UoJX29oP+3jhYERM7HDv/nyba6RfkwaYpnKVkP7 0B5x6eQAO0D31xePtP6WYoRqWpYaROIbRRGxKIEuD/2pjuF2DGNjl1rcVVoT21g4DeLqzphP3Zk sdQWe10UWLT9lZNIXDbyQHX+jJZKMW1prg84+enw== X-Gm-Gg: ASbGncsgrIsQ2BR5hOuCyQQ0lX00hW4DytY6Uzs0bEHBqlJlj2dAGwZ1kqATWdr7l65 URo5rW1kA4qC4LIjfme6QELWbSjlHlqAAVPOsicQPAvc5Cf7TT9YpEXr6CIv4PfRzeu0OH7jYOC xnD3Kg23HNNgxHvRS7ZFb4yVW+Y35lK3UOwfavyaj5zcUiav4LIZmfOI1phKQnmyYzxq/v3sQTz Wrd8quSVwJBAq24Bmf3mzlPeXn3qiaV/egWshG3BbDRVRzO0OERnewwigmfIAtO5SxvWGz/6kIC X-Received: by 2002:a05:622a:5c1b:b0:476:ff0d:ed6c with SMTP id d75a77b69052e-49f47b04329mr226099751cf.40.1748387579934; Tue, 27 May 2025 16:12:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9YHpxW+egSS4NdTNrHBleoRkd827aLFfHMRdKGwS5kTr4TXrNG3pbIANj601xQBwzZnhCNA== X-Received: by 2002:a05:622a:5c1b:b0:476:ff0d:ed6c with SMTP id d75a77b69052e-49f47b04329mr226099341cf.40.1748387579499; Tue, 27 May 2025 16:12:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 04/13] migration/postcopy: Make all blocktime vars 64bits Date: Tue, 27 May 2025 19:12:39 -0400 Message-ID: <20250527231248.1279174-5-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387651789116600 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 Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 0b4efdb7fe..72f9075e69 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 Tue Dec 16 09:10:58 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=1748387652; cv=none; d=zohomail.com; s=zohoarc; b=fhhwLnWlenoJTTkjkgUB0H9GbInR48pmqCWeDSCcVK2a1B0Qmk2C1ssFQd46Nm1kJKUuKzEF1sFtAimh2DQoEp75bIzj4AabLCr8shTSzmtr6UYj2g/RNk1TN/zjRwCa/xXnIKcEJWqdWNm2GbOcosluEg7Y4VmYqji6UeWCcGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387652; 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=dYaOLKI31H08Zvy+UoVHhAgs+xU9FR4gz/0hfnp6VKA=; b=gJE6s+u5jV+wjF2K3tV4wNsZybIkJLGNPLqs0KEIBfgFZEJ878Y8GcK9w6gfdnhyuF8KnKBPTssua3d16O+ZyT12dKhfjY1NUNJsuAHZh4G0p7g6306tvR2PCwfLrjsFBZ3aNbMHpEuXyC6hOcEW8cAYp1wdVLma2rGC+ngoD2k= 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 1748387652736865.7707605652768; Tue, 27 May 2025 16:14:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3To-0003HX-8T; Tue, 27 May 2025 19:13:08 -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 1uK3Tm-0003HJ-KP for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:06 -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 1uK3Tl-0001Ci-4b for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:06 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-pvKUvSJ4MXGzeSP8cjFCCA-1; Tue, 27 May 2025 19:13:02 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-47682f9e7b9so59097121cf.2 for ; Tue, 27 May 2025 16:13:02 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387584; 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=dYaOLKI31H08Zvy+UoVHhAgs+xU9FR4gz/0hfnp6VKA=; b=JUomJIW9WjgUtPB8CxFsIiEC6lQ6pMXzygizNb2XeqlpWy7eWr1Yc4Cv0wWuRzGvGQzR+M X0uWQnWjHGea/rRB5vW9qejzpazQgIn5fLHrnwbU5kG3pcJOVg7h4RTIwfeBRLRiHko7pQ tyRxaIGzqKra6ZQyXhCDMCSURHiy2wE= X-MC-Unique: pvKUvSJ4MXGzeSP8cjFCCA-1 X-Mimecast-MFC-AGG-ID: pvKUvSJ4MXGzeSP8cjFCCA_1748387582 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387581; x=1748992381; 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=dYaOLKI31H08Zvy+UoVHhAgs+xU9FR4gz/0hfnp6VKA=; b=cMWyPQAWXC5/f5/E8dzk2hferkr+3yVJfYUgI3G01B84tO8MiLzh1ULKhHYHb5oqrs tNPXEvOd8ds6WEsQPIL/Eosnv9DdRjMC3qh0RPc7iJwdK9aaCPapYx2pSwK07VmRyerv Pato2e3K0opqOAVpr86LWZycxiBSh1Upgo8/z40l6keyf8Llzm8+wTe7/Y9IHL1hoAxo bWvAOWVII/YYRmqiUsL3deXcM1SOHs0IN+wVaYRmW9YCapnIs7h409skpp8f9ATB+RBu 9FoTEPp5zwextkv7H7je/qiRfcGnp5bgv7tCjwsCrBzmphLxQNEErbYA1YvWkW7WT9LH BZuw== X-Gm-Message-State: AOJu0Yx26Jnzaebzd6ZQoqfZNWDjosRsa4InsI3GUSFCw0tUQjMxnYfZ P3mpP+F27shRw1i9YfSqjkOzp3q6eFtodI+T4J+OjpGKucp6haQQOg9ILcaayAYHwufVk//I+pS hQqw5cFcN6HoWn9smH8hXYNYERQZPjbYgHbKTFFnv+7QCvI0vyWoqywFc6pXBPUfCfeZa8zYpk7 vTAjHOxrt3vLdDmZcNFlDQCnaHu/eQutaz2/6Yag== X-Gm-Gg: ASbGnctzYgN/mhh4jexOYKJqt2MN6UULEpb+j3Rq8nOMKSxogjfu+1M47vQzxoMoexp leMqb9NNybyNJ8RAcWcYudbMX60Ks3O9R+kkt7mJqIcVAyGXm8Ovbjm1x9t32U4zdoW0hHUTe92 iSKdmXybWlDQQwVxMLGjOZJvRnLhAYDpB0q/Ytu9J4KbAZYktaFTPJ8zK5YcjYGSDFQ/dtv3K2C Fill8RAWi5nzhKfGUatBKA1J+GUs91VFo4N9keWs3+tPKtKsfYG1NjFlq0SWBDiprapYTfEHY7N X-Received: by 2002:a05:622a:5a91:b0:476:b33f:6694 with SMTP id d75a77b69052e-49f46e38eb6mr255105651cf.28.1748387581603; Tue, 27 May 2025 16:13:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1hxrqzKQsmcKq07EZ41BjRKi+q6mO95EKIxsYxwKUpQ7vRgHXxxiHFPjv7XvoFst4P/F+OQ== X-Received: by 2002:a05:622a:5a91:b0:476:b33f:6694 with SMTP id d75a77b69052e-49f46e38eb6mr255105221cf.28.1748387581230; Tue, 27 May 2025 16:13:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 05/13] migration/postcopy: Drop PostcopyBlocktimeContext.start_time Date: Tue, 27 May 2025 19:12:40 -0400 Message-ID: <20250527231248.1279174-6-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387653502116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 72f9075e69..c6ae4b650c 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 Tue Dec 16 09:10:58 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=1748387650; cv=none; d=zohomail.com; s=zohoarc; b=WZtTA/ZTuzMWpH2YeHKsbqzyc7VXHHFYsVtfCdm3W+oHgASPrWuXgel06cBryoS76VtESYKiA/ZiX4Abr34Jnd9/kfsutxEa/JS6BtNJDQiibuKHERxyJCFcfk/+UmtQnTR1l2Yhx18HxKAV0nMu9f5R4fk+l9PlW+QaRWZLiZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387650; 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=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=ZAjXMffbmQ36LLCC5M8X/iunj3XjLDl3AagxlNjTSaOQBOS3a/K3UyqIkFSIt4ptO0nLrauH8t7zqnpTlhtxf2LR2fez4pjheo52BlkxdHDU03F0PBR4adu4zjH15CxcGVyOZ+C9IYDkSS0CuxIq93o+xhiZGWt0H3P8RUgoM1A= 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 1748387650337847.5334656583742; Tue, 27 May 2025 16:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tp-0003I3-Qs; Tue, 27 May 2025 19:13:09 -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 1uK3To-0003HT-4H for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:08 -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 1uK3Tm-0001Cq-ED for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:07 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-5xrCPdwzPimLhucV3kSV-w-1; Tue, 27 May 2025 19:13:04 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4853364ad97so33691991cf.0 for ; Tue, 27 May 2025 16:13:04 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387585; 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=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=ASUFeaXpkEluFXUw5/IOp3Tz3Y0z7cwylyZKjgLTVoiJzT0TxQz8rQTMWwIQl7XiWkAKeS lLDtl4VZOBc63d6Tdql/0q+HvwnP4laYQlwqh3tZHlKOkjPXcO7t64Wf7g+GYoWb+xkuPZ nMIgMK1lXoK3lKjTu2n12hDKL5O9T6Y= X-MC-Unique: 5xrCPdwzPimLhucV3kSV-w-1 X-Mimecast-MFC-AGG-ID: 5xrCPdwzPimLhucV3kSV-w_1748387584 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387583; x=1748992383; 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=0FVFBOHDyRMLEfjUsQ8+u7RDvtWgplGxeHp+3xgYqh8=; b=fAVjHFhZYsXS5O5BPFORGkZ8DAq1XnvjDudd49lvpwCjJz6LTm3pAqixeTqOyhJhp5 /emr47y+PmkyUyoGgHcwyZpzgjez0gNni2CGM0lZJ+I1lEvJvN1k+IK8pZZA3vjfOnxn UkedtNUm3WQ8cj1ncykcH+ev56S9pfnGVIbaO0cj0XGFSayosb5ECCcxVqd2p5Pp+1HN dARfxWGmDwPypxAq0H40UBrofJwHSf2k2M8GXorgr+IDz+7W8PNnWzPiZFwRn1DUGwad qn1rMJjfE3UbodRgsCKMt03IDHzdqwFuJjFEM9/SJHDbmZsW0QXZTuj6yYRUj5siJipb w6gg== X-Gm-Message-State: AOJu0YwmIPNRgkZKTEo2YYNi55GBkMsLRHhnUzrO1iO6fCkaPQ0i0p6K e8ksW+j/SPmb9JsqrOXZloJ/4kz9hr3iCwoD9F92lyVB7S8t7ifDpiZuwBdmBCoUJiJXf20bOxr S33PEJEIgxYrrdQA4X246fa6GrNQBxoYfrKt3MSsNRHWsIoUpaLbVBC5tRtaSfGfxTTaE1kCVDy XY4E/e1xqyBa+keKywphtl8iqgxKQGj2ZwINatfA== X-Gm-Gg: ASbGncsP+99DqDJFxzSsDQmJdj90BBjnVtbEUbu8pfnDtPMjj6lBeMEACdo9CLtgmOl MSzqT7bY5H3yKtmq6yryozeid8Idzfmo4XuOQ119eHc5IKtI6tIgbhFl57VbH0QN3ubKFTJpdxO oZMXf537ET6mPZ1dsnbJvmEBMCgCS/TYYiJYMRBVZBc3XLHHA4qzt6Or5dj+cfCEOU5rNynW6em Bo8ghtTZGJXbAZVh239KWfZnrT21qzt6TiW/uLEh4rGKkZycnp7hmFT9pvYTwXdze5O4R/soE6N X-Received: by 2002:a05:622a:6992:b0:494:b3eb:a4cc with SMTP id d75a77b69052e-49f480c8fb9mr191276031cf.47.1748387583404; Tue, 27 May 2025 16:13:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcszs9WQN3XMO00PhJlsqDs0Xu5sp8AY4+mIIMVWYKYOFs1zcjsRrU9G0xxdlQnXMUPkBxag== X-Received: by 2002:a05:622a:6992:b0:494:b3eb:a4cc with SMTP id d75a77b69052e-49f480c8fb9mr191275671cf.47.1748387582916; Tue, 27 May 2025 16:13:02 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 06/13] migration/postcopy: Bring blocktime layer to us level Date: Tue, 27 May 2025 19:12:41 -0400 Message-ID: <20250527231248.1279174-7-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387651696116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 c6ae4b650c..5cbc7aa77e 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 Tue Dec 16 09:10:58 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=1748387655; cv=none; d=zohomail.com; s=zohoarc; b=TifTtyrNc1Oi2tZNbKT8eIoxfiVyMqRlCWklr20AbG4huql15HPF3NJFL/updXx/2xE7Yz9A9KfTJ7Tr5RtYlGjFksPZq51xLxAbhjUxvectfxoEla3Uye1kRDrNKPeq7Io2CLJra7C9uQnIEO4GZWc3Vy69CLC5DO6Y4crdd34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387655; 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=Fnl0jufKoCdqJWKPPonqmHJMaxm0iVprfOvoshe4GEw=; b=KWylOtdhMbUzYZpftI391lHP5NLcAEUrLCtoFW3cvKgLRa6498t7VfZl/GQvUu5yWIP9xKprbUKNAn6FZihWv00IKJTtJv7qOOOzElZc2C4ShQ/MxrMHngiinuGwxTarxE4rW/gKraRDpGojcRyWeafKRyVjYl5R3peO9rYRILg= 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 1748387655167108.47762799943962; Tue, 27 May 2025 16:14:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tr-0003IF-Kc; Tue, 27 May 2025 19:13:11 -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 1uK3Tp-0003Hw-ET for qemu-devel@nongnu.org; Tue, 27 May 2025 19: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 1uK3Tn-0001D3-W8 for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:09 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-eH28219XMAGvUCjS8pflkw-1; Tue, 27 May 2025 19:13:06 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4767348e239so59445271cf.0 for ; Tue, 27 May 2025 16:13:06 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387587; 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=Fnl0jufKoCdqJWKPPonqmHJMaxm0iVprfOvoshe4GEw=; b=H3YG6e2NcH1mwyyIqT1Af6UCVmRLJb0KS7oBYL9wFaxXID+7XpGOMCUtf+jm9UuVmYiDOM xqQYDgvInlW2iS3dhQJxx0KEJ0p8ecrjZdmLkme4s03c5rib3cNFLhDiL4GrTSB+GyCHTp Ahq4IJrm3NM7UfUKsInrskd28jJJGfY= X-MC-Unique: eH28219XMAGvUCjS8pflkw-1 X-Mimecast-MFC-AGG-ID: eH28219XMAGvUCjS8pflkw_1748387585 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387585; x=1748992385; 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=Fnl0jufKoCdqJWKPPonqmHJMaxm0iVprfOvoshe4GEw=; b=MhNpUquxnSDjdaAtiXkY5yPOLxPOAefSyTBEbHazqIXURHE+ihleVbHMmoAPwRAxl9 Sa8vWJoZEFleZ1IR0N2+XMQB2t8bRxppDM9lULAAWqcr6X/kaTTSIvDelo1PKbeRSChg zCTR6plWZ9XczlZCjy6IcSVFqLv0Fz/WTC2qYzNPOG/DL15xG9NXXpo8vQO4Soczzkcq EMTmystDG3Mj72bsRcidLxHDUzdztWwXgN20J4nu94qQD2l7dps1aD0k+cGXS+eNYN3v ncpWzFdyCZi5amcH1gMSTnM0gqmIZ/mJOfuAXyh1Tzr9Hv3OGzuKmBOyG7vMUMnuuXYD S9+A== X-Gm-Message-State: AOJu0YykwYQlATuYXI50vICEfPQxJnbNsO/c0SUMx8NIhBKW4+oF8uUg TmPhSxZOVn34mp2IP+3v4OTfInKbPmT5RLZAAyT5uFRtPd3WUPh7U/mxjid5dx/HjXNLKTdpp12 +Lzc3vThfJyOtZbi/wzonyhLykpI2rCqs2S14HQ4hUljjFxLO2kh6tpb0DxDTFEUZGKiq7Oc8hf ajiNEiNzo3vGqwW+QMCxM1odzCCv1Lud94qg6Byw== X-Gm-Gg: ASbGnct6tW9d+wliyWFG/MPrwZR+PiKKuQEo+0x+oKXixm0u+GXopL/Pt9V3SEyMcPE fYawBCLoWfIl0gspf0v+/8ToS0o+pQ0dJSsTEzUMZG+kqB7PUX7nXI8D3WEkRMJTSvookFZLrzp GtysmHy8U37VL5Rq23T62FCuCqUnXobeBw9L51VzBvnm2Txf+WIpOAnU99G0kNAvYpA2ydIZUOc c9uB8miSiaab9Ui0+cvbnyoGrpMKTSuolSiVsJ47Oy4ZyVdg2zGNJ4fHdzNV44T63mRhQYJCTAI X-Received: by 2002:a05:622a:544a:b0:499:1f1e:ddf3 with SMTP id d75a77b69052e-49f467532e4mr270546541cf.19.1748387584978; Tue, 27 May 2025 16:13:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETs+Kl5GYcefT1FqlI0lZOmFcbTsQEYEEOATUDxERn6C+RN4ZxOT6Od6l8gfncUULNgs3SNw== X-Received: by 2002:a05:622a:544a:b0:499:1f1e:ddf3 with SMTP id d75a77b69052e-49f467532e4mr270546131cf.19.1748387584597; Tue, 27 May 2025 16:13:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 07/13] migration/postcopy: Add blocktime fault counts per-vcpu Date: Tue, 27 May 2025 19:12:42 -0400 Message-ID: <20250527231248.1279174-8-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387655508116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/postcopy-ram.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 5cbc7aa77e..46a8fdb6c2 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 Tue Dec 16 09:10:58 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=1748387662; cv=none; d=zohomail.com; s=zohoarc; b=ib9bIVPCfdm/zcGqHkQVzzSpruXmdhfkLfeWvE04xhet25LAM9Z4mmA1eqs1gpBEEgJPhiugN8HXzF0g7x++NJh5yte1mbsLbzNeavDCOQWZp2d3G+jjFbXxGhuhsLpJHXIqewwGQuo2Tmilo4PkxJi8Ha2mWY/qiRZ/TswZV7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387662; 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=L8xxihyV1kwj1WX+SgxHrTlMY975PGImx8ozXT5u7mk=; b=cZoKX1g2AHQibX8SRlXFMHGLmTgdONza0njLDPQ5JVQnPG5vlWf6FZX5FWmiTmJ1cfW7d0+tQT/7ED6dWHf3XYfKfKszwstW5y8ffsVpTt9u3MTO9V0kXDlMAfaYqzjQXG0Vvd56Z8lQc7eTY+V4oWHGx6r5Ajvqks4vnVZZZ/4= 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 1748387662400532.8428391779075; Tue, 27 May 2025 16:14:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tv-0003Jj-FL; Tue, 27 May 2025 19: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 1uK3Ts-0003Ib-SL for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:13 -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 1uK3Tq-0001Dv-UC for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:12 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-Iu4NqknGN2OjgOOIh0dbAw-1; Tue, 27 May 2025 19:13:08 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-478f78ff9beso116118981cf.1 for ; Tue, 27 May 2025 16:13:08 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387590; 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=L8xxihyV1kwj1WX+SgxHrTlMY975PGImx8ozXT5u7mk=; b=M9GpP/B6Aszmg4shXrGyXElJXh+HHngMHdHJsKQxFsL93RQ4W6JcgktGebmOziC4PSXB+z XDWln+SQIPr+jIIqslaIuEmLz74vcfH8z7B2xRcSNnfWFvcsurDsBMTZU2iFdW+8AIjrsU f809ogBFKuIfPWOyBXY/Kp4j+Cztlh0= X-MC-Unique: Iu4NqknGN2OjgOOIh0dbAw-1 X-Mimecast-MFC-AGG-ID: Iu4NqknGN2OjgOOIh0dbAw_1748387588 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387587; x=1748992387; 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=L8xxihyV1kwj1WX+SgxHrTlMY975PGImx8ozXT5u7mk=; b=ubGXlD7LxVYwimoUVCI+OAjvc/WYbHEoUVpwG4lKnd/djQhXXWpioGvdb5e6T3DbHS jBK0GAW7wDI38bVu1agO91hTslq/Z52JvYdk9WQsSdOmAySSTe8fRIWjnqoSzP5f9RRu f3gVw0KpGZSL6f835qQZRSbpgho3+/RNJtuGmsl2M71nvKT6QNQS3VKGmT9YQL84lVVJ CuCq+I79sO4sOpLit/cIRC/m5Kwn9AagSWSXZFGK6yg+DATaVrCIjX0X8ca+vp2vxX1N 4QyGjuhg1ZWgKF293FKTI4mxmWrOLTCt55aDZSy1fq9o1PM7ZN5Ei/BheMku22KKEWDX r4QQ== X-Gm-Message-State: AOJu0YzQ1Yo8NzcosjRJMfkqasbOx2imSyc60WvZRFHOmXmY7WuioAV1 R6yAwHFRl0KTylvkdgM/KG4SNJ8aN5NZMw90tlKaxQuNL6p95OgeORHsiarr4o9BYUn/VMBjyc3 Ua8Hxlrr/NjJPMoFOCNeFlyeWKncRAIc4ieVTKJIR8ye5u9caFebdXOP+3lMvqCVCEJqb+58IF9 fknG5zaRuyJx2uUDA1xpBdXKY2+EejU3IFLrR2CA== X-Gm-Gg: ASbGncsEKJHZObhzsCd20ZG2uZWU46nuJyRp8ib5BW18Fl/g/U8w/W3c5vDgqFEpOoN r+y+bT7DsE3zlXlBjR005PYvoGrdyCDKP02QeHG0Gyv3jJzr7Xv5QOPqwcKs3KejxNuvhAq/uGY MOrlxObKchfNHEhV4tB7mN3KsNCNmN0qUEq/ub6PfU8PhbQ4S9fGn2nLvGt3V9I5BnmlQ8yZSv4 AN0NMRq458TF1EezW6u/fbcF4OUVS/UMjygwpxgzMEWVPTgb9tgNfEXCmqnSgnyEyANeQUYZfKv X-Received: by 2002:a05:622a:4c0e:b0:48d:7c95:4878 with SMTP id d75a77b69052e-49f46e3b379mr236342641cf.29.1748387587549; Tue, 27 May 2025 16:13:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1sxba2rgi/DbE8hy//0giKNyhhtBIrget6BSYEYRHm6fbQONqdiKkdz2qg3Okp6dp6mXDog== X-Received: by 2002:a05:622a:4c0e:b0:48d:7c95:4878 with SMTP id d75a77b69052e-49f46e3b379mr236342301cf.29.1748387587183; Tue, 27 May 2025 16:13:07 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin , Markus Armbruster Subject: [PATCH 08/13] migration/postcopy: Report fault latencies in blocktime Date: Tue, 27 May 2025 19:12:43 -0400 Message-ID: <20250527231248.1279174-9-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387663814116600 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 Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- qapi/migration.json | 13 +++++ migration/migration-hmp-cmds.c | 70 ++++++++++++++++++--------- migration/postcopy-ram.c | 48 ++++++++++++------ tests/qtest/migration/migration-qmp.c | 3 ++ 4 files changed, 97 insertions(+), 37 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 8b9c53595c..8b13cea169 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 3cf890b887..a18049a7e8 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -52,6 +52,53 @@ 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; + int count =3D 0; + + monitor_printf(mon, "Postcopy vCPU Blocktime (ms): \n ["); + + while (item) { + monitor_printf(mon, "%"PRIu32", ", 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"); + } + + 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,28 +249,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; - int count =3D 0; - - monitor_printf(mon, "Postcopy vCPU Blocktime (ms): \n ["); - - while (item) { - monitor_printf(mon, "%"PRIu32", ", 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"); - } - + migration_dump_blocktime(mon, info); out: qapi_free_MigrationInfo(info); } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 46a8fdb6c2..2aca41b3d7 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 Tue Dec 16 09:10:58 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=1748387734; cv=none; d=zohomail.com; s=zohoarc; b=MR5oN7ycDd8qaYea+H9ZC78tIBkRIH5TJut9QGzSAsXJMozi6dNi8HNr5z1BTLNeQUjemIdbcEktxWE1hJ3JArjmExkDu/sDdPJoxa+hlgFMHwxz34x9zMBdNYpAmRPZYl0oj+HYzRDI57Tr/Xzx/OK7bqwd5KtgiDo0p9VmTKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387734; 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=e0bhbecsmzeOLXe9dkL8LSOz4qm8m26wuFzD/NSoKEY=; b=X6uksxCPHeo5vZVwshckqkyR54HzNEhGCg/xhghbTQA/P4QnNL/K9k7/x54vZmNS5UDHU9xz/ymJ7OjC1+WYXoJNkKARavSHLsPHk19Zfbkv++4zBRdnknwqv8M2iktqczfKhZLePzI7MYDKP/GvV5QOh8wGC+ydnbZgF/Cm6G8= 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 1748387734106123.899730544254; Tue, 27 May 2025 16:15:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tu-0003JN-3j; Tue, 27 May 2025 19: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 1uK3Ts-0003Ig-Vi for qemu-devel@nongnu.org; Tue, 27 May 2025 19: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 1uK3Tr-0001E7-GB for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:12 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-J9W93IK8Pdy-O3yLCUTJww-1; Tue, 27 May 2025 19:13:09 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4768d63b1dcso5496611cf.1 for ; Tue, 27 May 2025 16:13:09 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387591; 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=e0bhbecsmzeOLXe9dkL8LSOz4qm8m26wuFzD/NSoKEY=; b=Mej4WPp7j9hKCyM4+GM0eJd+8lbUgfP9umRirYyw5qY3nuKkFFlY7fOSL6yMqPeGQDfcKh dDIZhLYctLWtEH5Xoj+p50MNHt7YQlA+rfrx2af3UKWQBJHtEx3v6Yeee/UYcHPQCO9a5G 1WTZQQgM7Y/SAG6ufwkPj9kgS1z+1Tg= X-MC-Unique: J9W93IK8Pdy-O3yLCUTJww-1 X-Mimecast-MFC-AGG-ID: J9W93IK8Pdy-O3yLCUTJww_1748387589 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387589; x=1748992389; 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=e0bhbecsmzeOLXe9dkL8LSOz4qm8m26wuFzD/NSoKEY=; b=U/5mdQQTS0JgwhR/pAs3p8eYBTCyas3ruXFqX0w60NlvZd9vkFCwlAdRcKgCBWrXhB iRtnoXwa36BQL8AWDINfRQU83vS+oV8wQabFOK+haiqEl/rNJYRGMjkF7i5Tn4BTlqyI 75cfgMh8fbMCAbT3yUZqvIXRU/4FZzhtP6+z8x+xlM8gKB0pcPjBWUeOmF5tLcSDu4qJ 8zBBZaX1RzxlX4Eihiwg0mrhgWxaHVIYlXQJTNuhLFbBpol0VQPUmaNc7qbsApbuxCSz aHe20gCvGo0u49+/p8jJSGxzUrXUUvbyCl4z5cf5O+YvucAEERA8VSiJk1I00wYhuB+u JGVA== X-Gm-Message-State: AOJu0YzTB0fnzpVHJ9ZKLDUBfgkVx5DQhUjIf2vVmrWmywno2jOYP2op sZOjUd+8jM/ChndqEr0nPztMwoGlf635Ie2G7U6XxTcX7Rnc1J4FcDz63//77URpNzYU5s7eeFo RvWgchyDlvXS/Fukn8kaNqPOVsoWgf40mTS0otEbAvCOJRss9k/A0KkzAN9CEWH7Ty4ToDzsbXb yCuJDZ44kE6fOcqEOqOI05Up6fALAjsL0csPqnRw== X-Gm-Gg: ASbGnct76ujHvoeUXeI0Hz9EekXimuhCMyY7Zr07ve4/aHZv/shzXrn0afBycRywnN9 uIwk0tPtBADbtMqSYIEDCW6fDNUByt/G62d8tYdynsk5XhsbvPPm9B+w3eyN7uTLWZournz/3uo 1f0X60SjHmO9v91MB7MwO/qPYdPxvAynHveJ0801iyxGWNApMf6xsEV+efOEG3GFeTqZev9BRgu w3S3Flfsx/lHtbSp6agWHjiwp1bydMp6q46NIwS9XwVkdcBbhh8+Yfi25EgDvLerAhYDset1zab X-Received: by 2002:a05:622a:244c:b0:48d:66ee:662a with SMTP id d75a77b69052e-4a2f52fcd28mr42988451cf.26.1748387589025; Tue, 27 May 2025 16:13:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLs72MzepzXmA3vk1RLSkqhrEba0KURDIVug8ClPX+AubGrlpgj3ljrU4tUmG7AiE6XDWKow== X-Received: by 2002:a05:622a:244c:b0:48d:66ee:662a with SMTP id d75a77b69052e-4a2f52fcd28mr42988001cf.26.1748387588640; Tue, 27 May 2025 16:13:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 09/13] migration/postcopy: Initialize blocktime context only until listen Date: Tue, 27 May 2025 19:12:44 -0400 Message-ID: <20250527231248.1279174-10-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387736406116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 2aca41b3d7..e73f5d1cc7 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 Tue Dec 16 09:10:58 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=1748387660; cv=none; d=zohomail.com; s=zohoarc; b=ZflZwdbkpoqd6ZMrLUreFwwSU+Nyhs7utxaQnNr3/efhD4HpE0udviHqX9aOm1zAI2vKtyTAYQCerLzufyJJvUlReiyJukKWSJ1ulm7zlCLhixdWfQKXL5s5vVYKNzY0ZzvpKb4yzvZf6qEdg7jS8h2+6JRE8xEpeq1Y8TOc6jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387660; 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=CN1Hn3+Uw7/ALbIafIFeVK7MaEfBIWOZWsDHjGTYDrs=; b=C8N3fnxt9+TWfxroKU893LXxzAifv7yYVWwUrBny8+jAOdcvwb0c95j34gAQerrfm9B0OjU1l4L6loRHwgSumYH68aSYTWY3mK+biWn7hkfBb1Yg7c5c9hDaKwe8rCUeGdiXFfK2Lb1gcs2EBZn6LTDbKqzNNZ8tiR2/jZjlTFY= 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 1748387660472288.30108799341883; Tue, 27 May 2025 16:14:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Tx-0003Kd-VZ; Tue, 27 May 2025 19:13:17 -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 1uK3Tv-0003Jt-MW for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:15 -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 1uK3Tt-0001EX-9v for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:14 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-dsN6Ef0FNSGdZcIq25jBlA-1; Tue, 27 May 2025 19:13:11 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4770cbdb9c7so79665961cf.1 for ; Tue, 27 May 2025 16:13:11 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387592; 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=CN1Hn3+Uw7/ALbIafIFeVK7MaEfBIWOZWsDHjGTYDrs=; b=J/H2HQm6Sg9uaigbGn/+m7nqI5I8IvHWDPI44DBAtWO4CwGDXm/YBJA27Ctryv5UUGmY67 CP8ByHE19TwDF8QH2EIM5Wg38i2Nb+6TTt/syvXh1iDhs25+WtpwikN4pf4HsMHcxoVOkj Bp5kYstSNDXdlwJNsuulynlRkv+bgOA= X-MC-Unique: dsN6Ef0FNSGdZcIq25jBlA-1 X-Mimecast-MFC-AGG-ID: dsN6Ef0FNSGdZcIq25jBlA_1748387591 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387590; x=1748992390; 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=CN1Hn3+Uw7/ALbIafIFeVK7MaEfBIWOZWsDHjGTYDrs=; b=d5HzgeN7kBysWju+war5hVvZi9PfdPeQNtf6RVQzL70G4NGgzDWAKsWKs1SwBgnyuu lWiRSIMwC26f5lyG1pNfc+ACSMsvXWTVUGPMO4BSdPrGtCvLfyxyd3HGrLylrqO9oiVA EZwmAms5R4SQX3QBjbHYP4nuqqcZCOb6bBbOaFqpknWPygvb7+eqV2KLkhkof4HTbcOo 5YV24qeykMeguA5FTjAG59cBbLneL4WZxoWzsFU67OIpRmMGN9R2cC26vKcWeDYayLL9 tERP1gT/C4ulYGRFEhIeztW0cq6cVqjE8sUbN4LqCKjyR72ha9PNpjfqNcEEvPUloIhD W6kA== X-Gm-Message-State: AOJu0YxjGPAM2P2orXAwGeirNkjFrcwhaLk+z1tfWXjFQFEchZQQVkEB xeWT7MjlGU0QAdz6pkwMhrXu4+lQp2pxQKqau9zWj+GFr+kFoSx7bhZOQIfoPHdRuARxw4bXxo0 OuVCyVRVbKlvhxrGfkCsyUdzsFX5PerPg8KRL/4XgPCQANuwu+ipsOLe7bofVy378uUrZoNI7pC cbi5sgdn4BNlEezvsE3OYq573cC8t/vFrnEkCM+g== X-Gm-Gg: ASbGncuPcp5mNazhmfsGen4uWKC1RcXnpHjvtXTNnzc+TbQsL6vAXAVXYHNtTJFQ2r9 0lWPaEtjm1L+PfdvYHYubn/ox7hljHa14hXtsTSF66KEFLG0ik5niIBcHTLGVe/tLQA6VQkYXvO v1bIAUu9dC8mkfTmoxL51sQuuu3GnBrC16p5ubRv88kPdkxMlS1IxWThuf8dt5chCljjzpJD1M7 drsNwxTj4M7xq0OmyIx43FinfPaxjF3hAwfXsfRGAnm4O4IB5s3AtJwvhlzyWXr3CYaN5CV/iuE X-Received: by 2002:a05:622a:4ac4:b0:475:16db:b911 with SMTP id d75a77b69052e-4a38c7e0c09mr1188661cf.52.1748387590399; Tue, 27 May 2025 16:13:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhW5UjgGIFP8Pm19xZOrD1s8F3ZJTbdBPDl0HxqELKV+dhCRfZesWfTJR/UNDH//29fAj0hw== X-Received: by 2002:a05:622a:4ac4:b0:475:16db:b911 with SMTP id d75a77b69052e-4a38c7e0c09mr1188341cf.52.1748387589998; Tue, 27 May 2025 16:13:09 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 10/13] migration/postcopy: Cache the tid->vcpu mapping for blocktime Date: Tue, 27 May 2025 19:12:45 -0400 Message-ID: <20250527231248.1279174-11-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387661813116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 e73f5d1cc7..4fb1d92d7b 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 Tue Dec 16 09:10:58 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=1748387651; cv=none; d=zohomail.com; s=zohoarc; b=UBmLi9YfZBg04gUnygXGc5BWlK+3Zu8NrsjEQ8JLZ6DLZvTGmVBUWeQnm19jC1YSDf0XabF3XiGQ4tjgexHhppsWCmLHLeNHjzghI2qx9bQ8nYK3Iv4DxBWmaryUD4wwytyatv9GdUBAlp+MJ1u5GobvKttVsd2vz33VSVhsqyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387651; 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=dkow7bJAoDRkD+7zEweB6Ohhgw4J10hl2WnPvcpjD+M=; b=f569uUFmgAHWCeGwjFz6bwdtmBleZXzPmfPP9upfrwYl8eoMahAqreW1oD7MII13sMFRCT1GxSS2lvX3m2Vv0LQ0mrtRLak9srvbebMp1EsLvKd6z5PUQSxAaAk9sSeh3k45EGOqk9OANz6DGxQxLKU+b0ttbpq/trp4dQCujvw= 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 1748387651009857.0106255103774; Tue, 27 May 2025 16:14:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3Ty-0003Kf-Gi; Tue, 27 May 2025 19:13:18 -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 1uK3Tw-0003K2-Ee for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:16 -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 1uK3Tu-0001FB-Nn for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:16 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-oXgp6TKLOrSwR8XzZth-BA-1; Tue, 27 May 2025 19:13:13 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4767bab171dso34759001cf.1 for ; Tue, 27 May 2025 16:13:13 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387594; 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=dkow7bJAoDRkD+7zEweB6Ohhgw4J10hl2WnPvcpjD+M=; b=JOgJpJh+U8DFUrQbFRcP3/I12X4Ni+8XnyagfZuUoUs8YiAsfN4aE3l9/NUgYbRWKhxZ6z UFy6CW/uR+ICW3Frlb/XtSSp3EKh86sG+hox1Ri1lxD/+2HcVEJPar8+Sam1nJWU4C0uzK kKJaR/BaSRtN7RYqgrfoYeQ1lwwkCd4= X-MC-Unique: oXgp6TKLOrSwR8XzZth-BA-1 X-Mimecast-MFC-AGG-ID: oXgp6TKLOrSwR8XzZth-BA_1748387592 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387592; x=1748992392; 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=dkow7bJAoDRkD+7zEweB6Ohhgw4J10hl2WnPvcpjD+M=; b=CnTMJiMaVGaNLdiTjGqM4Ckk247vQ/3CEkDhsCCSiOqEIlBTytLY5v0AOZz4tr9kby /AAah+BuFdzogpwppprIyzUYDynD9Z/ElSMb+iteaHcGGzeDL86ITCyyBEkaLzRoXpYV vXNq+JKGd41dti0GdMmUj+HhSGSSGnl/utPe4ukifMHcP+G74LqPhHcmbGzXic6xItsV 6KgmmhvgrKC7xu8x7+icEKFvozZXei9+JXsnm5J/3Q4RwGZehoJpR6j+NWnhJSref+Lz qNyOm4DKHQQ9aSkdPA/22F8DXIEyuTa+GfU2U6FOJbJ+QTak8T4GP+nYPGaDIS/Ew4m4 y8Hw== X-Gm-Message-State: AOJu0Ywei6IkITYca3n0qbm+J+jFLQCZBVKg1M8dhkfIHwa8AWZaKjMh +7dzzi2sTYbogFxz5/q/AazkbeiGJhVJrWLpdyqQjZyv2333MhpxQGh+/Rk+xDU3h/v/d8GNf0q Fi6vyc8dKwEbeua/9dAHzSnlBBMVMdUxh3EKjeoblVHDwGtZAoYXuoer2ALZvQm0gb78rcdS7AE KVulEz1fSnAOeGH0fP6FmDFulHH/bQ/ZpAXvJhvg== X-Gm-Gg: ASbGncuh5M5jND+L1XMJZghOMylK0sTP1QUx1Lw+dfuxcnUY6xB/ld594k5geFq4kTm arOqnaUZnpxreL9E54ROvOUhbVSV5L/f/D6mcpSIMKwuajKR8BUXRsluk7Y3HFsl30Us5Tg7YZf iB0mujhmnwKIUoYclhucHlTyhWJOO03DpsI4nMGDwVHSGS3q5++1SlG+M9h3s1ak7iKOl0ZHPnY b+VvXI0s3D9LsXkEN5XnYBReV6LtO2v8ntyU0bWNML1k6bkx4QaFGEdCNb2l68v8NKs1NqQQw+/ X-Received: by 2002:ac8:5f50:0:b0:476:c650:9839 with SMTP id d75a77b69052e-49f480c8e90mr205323581cf.51.1748387591984; Tue, 27 May 2025 16:13:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrB994MjlBWSyEW7RUmyuJQ+6qdDxjFvly9oZdxyaUfj5ov5EhCdPrDH/CveqGnLlmOvG8lA== X-Received: by 2002:ac8:5f50:0:b0:476:c650:9839 with SMTP id d75a77b69052e-49f480c8e90mr205323191cf.51.1748387591536; Tue, 27 May 2025 16:13:11 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 11/13] migration/postcopy: Cleanup the total blocktime accounting Date: Tue, 27 May 2025 19:12:46 -0400 Message-ID: <20250527231248.1279174-12-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387651645116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 4fb1d92d7b..b76ce6b363 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 Tue Dec 16 09:10:58 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=1748387680; cv=none; d=zohomail.com; s=zohoarc; b=m5VcVoGq1oUofbQE0ZaEAZ/za7vazRXcgCknI1xKbFjWvaBRXA5kusWhrSETxFub1617MuTOrNcmrhadvHDCpZ61RY/7+xuWh0YZEYtQA6rNNNLkJhdTfJ5ot41neRqhtGeOdkXdl36vmlNP74Wr93IFBhJ1yK7Xeo9NdTu7JOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387680; 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=RDEIv3XkAN69zBX6H8l2UW+2/aRfaws90yLU60SIP4Q=; b=Xpj5KYIfnMi7Wv5kuPpQv8TtWP0+RFuKxkSSfML0fJODsboQDaJ8lBy6Lcnjj0eXZa/iqcyDUnvuJ8HCfhrNE1qud3hPWBZ/Q3UlzZAUE8HPpBKOQnl3MjzCTR7K4n0hMoueJV2JuTgchP/6UrepI+zOZqP6OFONiQ9tBEAHJbI= 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 1748387680115652.0120180599492; Tue, 27 May 2025 16:14:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3U0-0003LD-OU; Tue, 27 May 2025 19: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 1uK3Tz-0003Km-2L for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:19 -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 1uK3Tw-0001Fm-NB for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:18 -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-654-rytdjg9sOtGNFGby0sO-GQ-1; Tue, 27 May 2025 19:13:14 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-476b2179079so61295281cf.1 for ; Tue, 27 May 2025 16:13:14 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387596; 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=RDEIv3XkAN69zBX6H8l2UW+2/aRfaws90yLU60SIP4Q=; b=PPRzwJrz6xpQr03YWyQgIxr2sTt3wr9QHO8RkG0/zg9LKrLjdGcr2gJMgMVJDSZjyRY/8Z lgzNAnkK/e7o++14T7yvVz6TxvIdd0edZqTO0RLeDNeU5z2bEz1WV3y2YzzY1WFx8ZB5ce WYzj7f5Mn5fEluTvXgHrMS4fus0Zc7w= X-MC-Unique: rytdjg9sOtGNFGby0sO-GQ-1 X-Mimecast-MFC-AGG-ID: rytdjg9sOtGNFGby0sO-GQ_1748387594 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387594; x=1748992394; 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=RDEIv3XkAN69zBX6H8l2UW+2/aRfaws90yLU60SIP4Q=; b=WTNW7fVJ+roSFjUd6tGLY6pXx2FFvWWQYjwNLe+2J30O39qQqK0tS42Jlg/Q1z8/XM 8IaLXAVDuKx/OUFzdpr/Z4XbTkUWOokPfGZiAjdULVWcH08K2z+iax2dC8shVRw56VMS d7fXIirgvVHDWg8cH0JWlxK3A5PZ/2hGZNuTfl4Y5ExDu5Zka/SWQWCEpPdj793cOz9T Yzu0SvISFciJlD2qtOkjOtWoUO/zYeReR5vovMjna+Az9EBNHrh7AGpmJ43DJ29gowAb vhyfLAgTMuei1TipogMEhqGL/qkhbBpq5zj2yeaRUjiLQo2SY6NP+cUgmcQ/fC8Zzpzw 1IsA== X-Gm-Message-State: AOJu0Yx4Q5mEUAelfz1wZWnmFG1llJidWUDr4vcQf69DtAPc4Ijpna+p GFEjaKF6LBiItwU2sisP/iVKDVu8ipC8b9SScEuqhg9qJAAXlQchmnxx1Q5MswanXgqWWsV4KRy ZlrhQumBh9AJ9U07qd7Q45EhWPkoulDinay5Zlx1TPhMh9phveBuFu/oKdWKMw6o3C3QYqWaJxb GZ6w1QkMZV20KPEexwDOxIeNPmbkr84uIbUEtGWA== X-Gm-Gg: ASbGnctyeS1cn/XbObQcfHvZHCSwJR2Mp/QCoIcehzlKZIt9N07RyjCJmpIWiK6lrzg IoY3stSPI0Tie0jIKyC9Iv4rKAdfvRPvKfv8ESF8HiYf1szG5ujV++X2tdHnOiXjtHJnQD6qZRZ I1o7T+D1yI7yWmTM1e1s9Y00ZabEr6kijuwwA1QJchIXsJOv4GPSXkCapNtM+6pYsrMs+qrICzY g8D7MY0Bi/ozg5rYUshlLUI1vOdKaH4CjOxOVwUFvtR536FUpxeZefACrQXg4SkcEEtOJU5Y1Pm X-Received: by 2002:a05:622a:90b:b0:476:abd1:7101 with SMTP id d75a77b69052e-49f47fd119dmr221556141cf.46.1748387593831; Tue, 27 May 2025 16:13:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfdH8JhtcLOIg/jOohb2u7GshWY6iVBzZX1Tb9JQZ8JuB3snuv1JhPdrvtuDdc2SfNVL97WQ== X-Received: by 2002:a05:622a:90b:b0:476:abd1:7101 with SMTP id d75a77b69052e-49f47fd119dmr221555731cf.46.1748387593234; Tue, 27 May 2025 16:13:13 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin Subject: [PATCH 12/13] migration/postcopy: Optimize blocktime fault tracking with hashtable Date: Tue, 27 May 2025 19:12:47 -0400 Message-ID: <20250527231248.1279174-13-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387681985116600 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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 b76ce6b363..066dc9f3ce 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-wise 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 Tue Dec 16 09:10:58 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=1748387665; cv=none; d=zohomail.com; s=zohoarc; b=FbtEA66u+IYbW6lUIf2IfI+hMiaPbqpNx8Mb//SI5r/x2Ooqrdpj+bMsIKgQ0JGvznnau6fY4ZdceWD0F1+HVFJfutM7ovcCQzaQtlDqR9hhVKzwp4hTYZgCWaaWJlYdGQDY3fi5oALzoyrGHWYyThoOZkIfuz960oQtYAt93IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748387665; 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=almEcPBg42VMuICV9qumc+0V+ZU5Aoz/MV/O8MQua0c=; b=CYxZFPQvmJxWXSj9vwahqfMZrSUjulKB/0wewlsJMLj63zYG2a1Yw1mKyI77yDP92qrG4JcCE/IHjXRIXvK/s2svn/ORSqgjOcDd/Hu2KKVOnQNjSyi0HvtEQJphunifV4KCP52m4lNyv6FnE+r83JJLkV1OBTg3M8L7SouSWbE= 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 1748387665123942.3589033210438; Tue, 27 May 2025 16:14:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uK3U2-0003LO-AH; Tue, 27 May 2025 19: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 1uK3U1-0003LF-6d for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:21 -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 1uK3Tz-0001GU-5w for qemu-devel@nongnu.org; Tue, 27 May 2025 19:13:20 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-8sZa0iaMM3-tQj9cKylQ0w-1; Tue, 27 May 2025 19:13:17 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4767bab171dso34760021cf.1 for ; Tue, 27 May 2025 16:13:17 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a2f939cad3sm1984441cf.79.2025.05.27.16.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 16:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748387598; 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=almEcPBg42VMuICV9qumc+0V+ZU5Aoz/MV/O8MQua0c=; b=UWp6XFsHbIg5gK8e33tn7j278CZmd7l/Wr7qOzR3b8HeSpYwm7pTJDOnXn+DM6BBHxVX9L F0bHlLZHGaIhA+sC48z5YJ26I1Ekb8mQpvfXvf6qAqLYfSbSlceE57AvW2ubhGCxCdz9W/ Yb9THSHoFnnPj8smb4kAZHVFjEsVhC0= X-MC-Unique: 8sZa0iaMM3-tQj9cKylQ0w-1 X-Mimecast-MFC-AGG-ID: 8sZa0iaMM3-tQj9cKylQ0w_1748387597 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748387596; x=1748992396; 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=almEcPBg42VMuICV9qumc+0V+ZU5Aoz/MV/O8MQua0c=; b=bBY1aW4fmQUMs7IaYuuk/K5vsjz1y4okB7ruBrkmnSIrRAAcGQmD8mlTgKryKbCb7j 5hY/sEBKr/TTkulaPP/TP+/Or+/KE74855/N1ezSnRJIGDKFAv+G2YgsoALaK0Aj6lfl TAXuPfmKUK6BWnuil3J6CJSVaTjyvYFzfFEzO2coSq8knmwiKz82ewtYqpjXxuDUsZ+k 9A3faLZO1syx+WEDaLghqQ4VbNP94PpbCEg5ChDNyFP4eE6i9A0vDgQFyDMxht/epStT wdJcK7Ef3V/BVev80sccOw6Vxu1XAFLPLZ6kFilqRXB4pGDLkACpqF2aUBSZVTSoQGEE O0Iw== X-Gm-Message-State: AOJu0YyB3Gqm2DCJpjNkgA7D4DNmJvt68Tfw4fDKw+SOW0AhHgBevbit 5W1qwT4M0LTbwyU6KKhcQeVA2wrq7b6EOjztOEPTOVnV93eJEzhiQfsOZtAa61tYWDGQZhuUOXX XIKe1H7wwhUimesGmwkrsqYxhzdVXGLiC7tZ+FHy49Moci5BSUIzE149f5DJUz8UbUte7eqnFhs eiUmYbHaedECjAvY5rdn8t7t7y1uyKK7Nd1LuMFw== X-Gm-Gg: ASbGncstG5HtEZbw3y1cnztNyfT7SNm6z49aK7vG4rL0p0jix+OPtilJ8rnzAnU2WYE DjcvHHSUW2FnloMXlPlSW+oGUjRIq963jJwY6yxkj68ktxH3xgP8b0D2odtsKE3cet6fA5BpdAo 1JyLO19JoUEsDUQziZbX74WOYFcqCZ6rBGU1kP9+fzzOk+Ua54Mw5N3SdW9MikTaALs0uODZQSN h9ZHGI5NdAufNdEAGGxXp/xqNTmhTBMq4M+I8IfZHCAYassjNcBHNYODZD1/ie2vruFWcP9jqXQ X-Received: by 2002:a05:622a:4c0e:b0:494:af82:7804 with SMTP id d75a77b69052e-49f46e41135mr249614721cf.29.1748387596409; Tue, 27 May 2025 16:13:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoMTD7dUUuRYmBAE0vc91/Zv+uXWyW7DnzrG018RVhE03Et2KM56h7btdPmdL1oNzXDhmnjA== X-Received: by 2002:a05:622a:4c0e:b0:494:af82:7804 with SMTP id d75a77b69052e-49f46e41135mr249614141cf.29.1748387595875; Tue, 27 May 2025 16:13:15 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Alexey Perevalov , Fabiano Rosas , Juraj Marcin , Markus Armbruster Subject: [PATCH 13/13] migration/postcopy: blocktime allows track / report non-vCPU faults Date: Tue, 27 May 2025 19:12:48 -0400 Message-ID: <20250527231248.1279174-14-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com> References: <20250527231248.1279174-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.907, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748387665766116600 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 Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 8b13cea169..f59c473842 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 a18049a7e8..bdfc754d70 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -81,6 +81,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 066dc9f3ce..bc6736f262 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-wise 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