From nobody Sun Mar 22 15:40:01 2026 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=1773962051; cv=none; d=zohomail.com; s=zohoarc; b=XTxmhWxutx9l70UFVvWoBUZba5z9WkxMa1fQxcsazDo0iFoF1E5cacCQUTmsU/dOOVhlajrZOga2wEA/Hz3d/Gjl8MWsbC+IF7wGbhUugdWnd4qNc1tYG2SVPj4mZ5U0Avnq9JgsmUFG73BQ1ifWXyRbZh8xynMm8s2zJiRHRPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773962051; 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=1ZTk3pexOhw1yn+1jhPOuPpjgi4ezlZc3e3A0v5mt6c=; b=XDoYS7Ev45qNE14oZFyTUDEHztlPjbVFuBtYaW1YKoEFhDttSx8VOkepbv0xaZ4VoeMkgd4kg82NsLpiatDW3OmiV2/5EMWZlbS8A24GQTNpsL3r6cvDGVbrvhp+8UQLc2MafiZGCmV6Mhows8v81dxcjLF+St9BHsv8/OUlfY0= 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 1773962051003716.739499205539; Thu, 19 Mar 2026 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 1w3MYY-0001QB-TR; Thu, 19 Mar 2026 19:13:34 -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 1w3MYX-0001Pk-I6 for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:13:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3MYV-0001c4-V4 for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:13:33 -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-348-NbPma5CCPAy7x8ilbiBhmA-1; Thu, 19 Mar 2026 19:13:30 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-50911c94db1so83492001cf.0 for ; Thu, 19 Mar 2026 16:13:30 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b36e5bee3sm6717161cf.21.2026.03.19.16.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 16:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773962011; 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=1ZTk3pexOhw1yn+1jhPOuPpjgi4ezlZc3e3A0v5mt6c=; b=HrdFn5/kaIA0AUgp9xh9QkcdksrGfdoaArTtJjn7thFfNzqK2IjyyvYhep6HjYb5XEqSLC u4g/OInhhzFlqiouiy/e6+dbSKuTPNRo1HgavLV4fEvb9FZ56U0h40y+JHfWaWUh+pVTRt /synGlJ9lyjFbdWjcSf+vJn3rIFX4VY= X-MC-Unique: NbPma5CCPAy7x8ilbiBhmA-1 X-Mimecast-MFC-AGG-ID: NbPma5CCPAy7x8ilbiBhmA_1773962010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773962009; x=1774566809; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ZTk3pexOhw1yn+1jhPOuPpjgi4ezlZc3e3A0v5mt6c=; b=i8AdNrnFJNpRYwuRJfl6gEXiUD1H9FHvfmeqAvZoHr0Eq7osfPmN3A6IXa4sI/kSUT Rq3k6POBy75nC6MEDo0ywveuTsX4+8LUjkg/9QDPCn1umem2qirKt9XKsdxHU17OVGdK uSQGUgmKjqRWRTvMw202M4AkXWweQw+cu9DplpUXJC8des/tOwhRRbpv2ywQsquhcPn8 IiR2TZQolcQrCHPHR3FAgh81Yoka4AbvfKwtW7CfhDt2MIWgF7lkq/mrKaC2aegoT2xT s4KcZ4AoocDH0CaDY/ThKAovjMhx9MIqHpXo7WNjYZVPwnZIF1qXlLnDUQUljz+lWqN/ P+iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773962009; x=1774566809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1ZTk3pexOhw1yn+1jhPOuPpjgi4ezlZc3e3A0v5mt6c=; b=bqwT3Tdjwec/TxWkd91DJBrhej072iYOau7mHTXHa7SiKxloleaCPnP52TWZSbHaPF xSEeWcG0KzU4c6EPJKduSnDWbDe7m+Jk2gWe8WqmyzxtPmRXdwb4TXUruKxqSRnphjlz 3GndJxFwQW1aGgxcprgyrg6675UqJztExCgZQAky3CsXcW2yt53qvBjdhA4nXJrozRC8 1K0FirHboG/ya8W8isXATuH+jlLYq3CL4Lw6hNxHc+pNxGGX+Kbc63E5xwdo4sAF51sg zK3mV74v3jd1Y6bKAV6N3AB5Ij6eqQLHptK3jrApV0wz1QHQK9LYPa4uXzmdtNWGqqLv uKWg== X-Gm-Message-State: AOJu0YyEbheKd67l4g1ha/AznCzTj2DqLCFw/zWU3X+hKfWjgCqht3AC +i9+7CKaV/gLQ4N1ApC9SCvpRWkp/Gfg1rd7FfYiDCAXBtAHTN+MpY9hDCxvTZIwU7OgTq7V97/ O43iDLU2PHBXqhQv5q+EqeLK7iJfoT7fDEpY41hVGbwOy5IhhJNqMoLuM0IlwywOF39UE++ZWU/ jOmznOA9RNqZ2OG4u4aJT1EX0ycLcAUDnlB5NM1g== X-Gm-Gg: ATEYQzwadT5OVcrXACnd4sBPMUQsL5UoUp1hv3NrClN8yZ96fR3wKTgHkQ9VyEgeV+H 07opwkg88Ghhh+0xhaH5OGV+LqL814OZN8Xuooa85rE/D4TDuzAuX/fYT7eRcEeCUuKcTnNu1lJ oa0VL6kw/mxMMJ2oZRW3SRInrFT2gazZlXjzA7ScnRoXTzIJxY7vLicyylHp4PgCcq/l5ETHzwj Rbz7/ZCLjZV700BxH+5V3dLFLG9vjN+a1zUiL8bOjjIQq6P7Bmajr8LEbwqasyu+nkfGzNitYjB B0Dg9rTPoYGcbBP2LEBkx8s/Pcl00YPVYbuCUVpaT85ZtEa042C73jShfk5zjdTrO2LZkcjhrpc Gs1dGmQ2IoENZZg== X-Received: by 2002:a05:622a:1e0b:b0:4ee:13d0:d02b with SMTP id d75a77b69052e-50b37500cdamr14681651cf.50.1773962009566; Thu, 19 Mar 2026 16:13:29 -0700 (PDT) X-Received: by 2002:a05:622a:1e0b:b0:4ee:13d0:d02b with SMTP id d75a77b69052e-50b37500cdamr14681241cf.50.1773962009073; Thu, 19 Mar 2026 16:13:29 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Kirti Wankhede , "Maciej S . Szmigiero" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Joao Martins , Alex Williamson , Yishai Hadas , Fabiano Rosas , Pranav Tyagi , peterx@redhat.com, Zhiyi Guo , Markus Armbruster , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH RFC 10/12] migration: Introduce a helper to return switchover bw estimate Date: Thu, 19 Mar 2026 19:13:00 -0400 Message-ID: <20260319231302.123135-11-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260319231302.123135-1-peterx@redhat.com> References: <20260319231302.123135-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: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1773962053236158500 Content-Type: text/plain; charset="utf-8" Add a helper to be able to return an estimate of switchover bw, called migration_get_switchover_bw(). Use it to sligitly simplify the current code. This will be used in new codes later to remove expected_downtime. Signed-off-by: Peter Xu --- migration/migration.h | 1 + migration/migration.c | 43 ++++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index b6888daced..bf3ee6cc07 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -586,6 +586,7 @@ void migration_cancel(void); void migration_populate_vfio_info(MigrationInfo *info); void migration_reset_vfio_bytes_transferred(void); void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page); +int64_t migration_downtime_calc_expected(MigrationState *s); =20 /* * Migration thread waiting for return path thread. Return non-zero if an diff --git a/migration/migration.c b/migration/migration.c index ad8a824585..56d605ede9 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -984,6 +984,21 @@ void migrate_send_rp_resume_ack(MigrationIncomingState= *mis, uint32_t value) migrate_send_rp_message(mis, MIG_RP_MSG_RESUME_ACK, sizeof(buf), &buf); } =20 +/* + * Returns the estimated switchover bandwidth (unit: bytes / seconds) + */ +static double migration_get_switchover_bw(MigrationState *s) +{ + uint64_t switchover_bw =3D migrate_avail_switchover_bandwidth(); + + if (switchover_bw) { + /* If user specified, prioritize this value and don't estimate */ + return (double)switchover_bw; + } + + return s->mbps / 8 * 1000 * 1000; +} + bool migration_is_running(void) { MigrationState *s =3D current_migration; @@ -3126,37 +3141,22 @@ static void migration_update_counters(MigrationStat= e *s, { uint64_t transferred, transferred_pages, time_spent; uint64_t current_bytes; /* bytes transferred since the beginning */ - uint64_t switchover_bw; - /* Expected bandwidth when switching over to destination QEMU */ - double expected_bw_per_ms; - double bandwidth; + double switchover_bw; =20 if (current_time < s->iteration_start_time + BUFFER_DELAY) { return; } =20 - switchover_bw =3D migrate_avail_switchover_bandwidth(); current_bytes =3D migration_transferred_bytes(); transferred =3D current_bytes - s->iteration_initial_bytes; time_spent =3D current_time - s->iteration_start_time; - bandwidth =3D (double)transferred / time_spent; - - if (switchover_bw) { - /* - * If the user specified a switchover bandwidth, let's trust the - * user so that can be more accurate than what we estimated. - */ - expected_bw_per_ms =3D (double)switchover_bw / 1000; - } else { - /* If the user doesn't specify bandwidth, we use the estimated */ - expected_bw_per_ms =3D bandwidth; - } - - s->threshold_size =3D expected_bw_per_ms * migrate_downtime_limit(); - s->mbps =3D (((double) transferred * 8.0) / ((double) time_spent / 1000.0)) / 1000.0 / 1000.0; =20 + /* NOTE: only update this after bandwidth (s->mbps) updated */ + switchover_bw =3D migration_get_switchover_bw(s) / 1000; + s->threshold_size =3D switchover_bw * migrate_downtime_limit(); + transferred_pages =3D ram_get_total_transferred_pages() - s->iteration_initial_pages; s->pages_per_second =3D (double) transferred_pages / @@ -3178,7 +3178,8 @@ static void migration_update_counters(MigrationState = *s, =20 trace_migrate_transferred(transferred, time_spent, /* Both in unit bytes/ms */ - bandwidth, switchover_bw / 1000, + (uint64_t)s->mbps, + (uint64_t)switchover_bw, s->threshold_size); } =20 --=20 2.50.1