{"id":2221042,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2221042/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260408165559.157108-12-peterx@redhat.com>","date":"2026-04-08T16:55:55","name":"[11/14] migration: Calculate expected downtime on demand","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e25c974a47da0c412cf401d593616b5e94eef7b9","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/1.0/people/67717/?format=json","name":"Peter Xu","email":"peterx@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260408165559.157108-12-peterx@redhat.com/mbox/","series":[{"id":499176,"url":"http://patchwork.ozlabs.org/api/1.0/series/499176/?format=json","date":"2026-04-08T16:55:55","name":"migration/vfio: Fix a few issues on API misuse or statistic reports","version":1,"mbox":"http://patchwork.ozlabs.org/series/499176/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221042/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=U90wPZhb;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=IAqHhfWb;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (unknown [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frWpD1CwTz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 04:30:28 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wAXeq-00057d-SE; Wed, 08 Apr 2026 14:29:44 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1wAXeo-00055c-Ep\n for qemu-devel@nongnu.org; Wed, 08 Apr 2026 14:29:42 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1wAWCT-00029N-I7\n for qemu-devel@nongnu.org; Wed, 08 Apr 2026 12:56:22 -0400","from mail-qt1-f199.google.com (mail-qt1-f199.google.com\n [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-265-qlLnRnFiOZ-h2m5az8N7Pg-1; Wed, 08 Apr 2026 12:56:19 -0400","by mail-qt1-f199.google.com with SMTP id\n d75a77b69052e-50d9a6a853bso3467411cf.0\n for <qemu-devel@nongnu.org>; Wed, 08 Apr 2026 09:56:19 -0700 (PDT)","from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id\n d75a77b69052e-50d712c2617sm130491901cf.31.2026.04.08.09.56.16\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 08 Apr 2026 09:56:17 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775667381;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=35aD6ayAqevDc5Cl045Lui2nxa5WaJZTNVeaUyAZbPM=;\n b=U90wPZhb/Lp9X+QRuoYSWx0hVboxfS8AfPrnspXepUpmsZqSaAFtscsSogPrcElX1PHTXL\n V5peRqRrGF8maZrmz03p3pWEatKIlrW7yna8I17MERmUq5kcWaoEMDyZ6x8z5NsnF9wZXt\n iWDa3MaFz0WQYq747exa07kjmpJ2BJY=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1775667379; x=1776272179; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=35aD6ayAqevDc5Cl045Lui2nxa5WaJZTNVeaUyAZbPM=;\n b=IAqHhfWbObbWPBaN4v2oYeuPnZHWpjIl0Rh+RXuTdFVyNzL/daxHgeGEwnr7O/xsUs\n NlzjTw/GaAXOTq2dBT00zmIK++xkk47CdSm3CHEXhHrQP7PoP/I7fqjKwG2Gc3Q0JzAb\n 0G5bZsRnM3b6HgLOJXW8SmoEgCANlRjsDw0ojf/KG+4FNxF0aKJzmjTCBKzIQ7mQks7t\n I0ORukbAJ7gG/cKdZO6z9iht/xa9U6zTpFyD3mHXBNea3CBOyg11xsezK0qHKyCgkzgW\n OvRwGkmWN+dXFGGLp3J7eyzUsMW5bZCmrwwQEPUTmw4Muq8pUg9q05s9wPUlTQhw810l\n D3IA=="],"X-MC-Unique":"qlLnRnFiOZ-h2m5az8N7Pg-1","X-Mimecast-MFC-AGG-ID":"qlLnRnFiOZ-h2m5az8N7Pg_1775667379","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775667379; x=1776272179;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=35aD6ayAqevDc5Cl045Lui2nxa5WaJZTNVeaUyAZbPM=;\n b=mdVv09qvLVwgpZc0g3kNB7mHpVoMnacyFXaVvPu+5frTCuJ2ITA4VpuUpQ7DEL4QPh\n 2PYoyOtgqgKCzMMYlQm0Ddp2lTnkKGfgg6K3/pdZtF2PRhxJbEQEYT63RFCyc+qIOcvu\n IEuRS4b3EZoy6QOFrcjNeNZH2vVTQKV4OrKvo1bBNdp3pzyL2iLb9OTKGMzDjXkCU4Ay\n 22kOFK8Xd+qUMimQhTWCv1HiKE8lD/UHZvPFRdhQnh0KjmLuk2sZIjLfLha73hyEoJBM\n sKmffeLL5CMfWHnYeEdlmOEO4YST5g5hcLGop8jtcHxnlc3eB8vknB/lObdboCvWx6pb\n 3v+g==","X-Gm-Message-State":"AOJu0YxkkKy/8nCfYipONB3tVGm6+OilpANBSihn0nB/+3EQmyjY05g5\n RyEDstxDqCmN5fq2xoROu9sm0bpr3lR6B1eNYILjgs5gv9ObonY3W0CDAvfsxBstc24pDGOu+c3\n rbQ5+bhp3GPC1qV+NJkzwkSMJxyOuuqK0p0bhIUe8aVdJzo9sZL+6d9s9Wu/bqVSbKnUKNay7jZ\n mrvgJa6mTfEoV/Jh1MbFSDGO8Opq09yHfw/Xez5g==","X-Gm-Gg":"AeBDietrbi54zcZv5Qihg88Xx7SMwS1EsiFchAZRW6ogXBZUoq75O/nDfgdSOXtb/57\n ktf3dE+fREJ6YXUvE/pacJmjKX4hrvofP1NJO0vDz540UZ3ddAs+dyHouE2a3zByam1F5na8AbU\n 0tkbsht+7JAnRvH5r8u7UQUt91dImV38UcTshfC9f9R9xvSWvTR05xAJvSj9yuZoo7N2rESlkZO\n xcMnQNzEu1c79j/hKmdvkFespIL9baRk0Sr+lH4nLwnTFtB0wtNA4/2lAgliwT9jz4/jQoNeWnO\n WDnIk4nQf/sdC6YIShW6A6OXo3hi8PtrYtfK1329RYjyBFHUZGYllWJBZQsJODXl1nyos/dk6sZ\n ElVIhK9YQ0mXPEyB0iiRaft2nRXiuK1+xEmem4HI/zotu","X-Received":["by 2002:ac8:5f13:0:b0:50d:6f78:39b2 with SMTP id\n d75a77b69052e-50d6f7842efmr289883931cf.38.1775667378697;\n Wed, 08 Apr 2026 09:56:18 -0700 (PDT)","by 2002:ac8:5f13:0:b0:50d:6f78:39b2 with SMTP id\n d75a77b69052e-50d6f7842efmr289882911cf.38.1775667377834;\n Wed, 08 Apr 2026 09:56:17 -0700 (PDT)"],"From":"Peter Xu <peterx@redhat.com>","To":"qemu-devel@nongnu.org","Cc":"\"Maciej S . Szmigiero\" <mail@maciej.szmigiero.name>, =?utf-8?q?Daniel_P_?=\n\t=?utf-8?q?=2E_Berrang=C3=A9?= <berrange@redhat.com>,\n Zhiyi Guo <zhguo@redhat.com>, Juraj Marcin <jmarcin@redhat.com>,\n Peter Xu <peterx@redhat.com>, Prasad Pandit <ppandit@redhat.com>,\n Avihai Horon <avihaih@nvidia.com>, Kirti Wankhede <kwankhede@nvidia.com>,\n\t=?utf-8?q?C=C3=A9dric_Le_Goater?= <clg@redhat.com>,\n Fabiano Rosas <farosas@suse.de>, Joao Martins <joao.m.martins@oracle.com>,\n Markus Armbruster <armbru@redhat.com>, Alex Williamson <alex@shazbot.org>","Subject":"[PATCH 11/14] migration: Calculate expected downtime on demand","Date":"Wed,  8 Apr 2026 12:55:55 -0400","Message-ID":"<20260408165559.157108-12-peterx@redhat.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260408165559.157108-1-peterx@redhat.com>","References":"<20260408165559.157108-1-peterx@redhat.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com","X-Spam_score_int":"-25","X-Spam_score":"-2.6","X-Spam_bar":"--","X-Spam_report":"(-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-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":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"This value does not need to be calculated as frequent.  Only calculate it\non demand when query-migrate happened.  With that we can remove the\nvariable in MigrationState.\n\nThis paves way for fixing this value to include all modules (not only RAM\nbut others too).\n\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n migration/migration.h |  2 +-\n migration/migration.c | 25 ++++++++++++-------------\n 2 files changed, 13 insertions(+), 14 deletions(-)","diff":"diff --git a/migration/migration.h b/migration/migration.h\nindex e504df6915..32543800b6 100644\n--- a/migration/migration.h\n+++ b/migration/migration.h\n@@ -359,7 +359,6 @@ struct MigrationState {\n     /* Timestamp when VM is down (ms) to migrate the last stuff */\n     int64_t downtime_start;\n     int64_t downtime;\n-    int64_t expected_downtime;\n     bool capabilities[MIGRATION_CAPABILITY__MAX];\n     int64_t setup_time;\n \n@@ -594,6 +593,7 @@ void migration_cancel(void);\n void migration_populate_vfio_info(MigrationInfo *info);\n void migration_reset_vfio_bytes_transferred(void);\n void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page);\n+int64_t migration_downtime_calc_expected(MigrationState *s);\n \n /*\n  * Migration thread waiting for return path thread.  Return non-zero if an\ndiff --git a/migration/migration.c b/migration/migration.c\nindex a1a02e3a9f..f12cd9efd3 100644\n--- a/migration/migration.c\n+++ b/migration/migration.c\n@@ -1041,6 +1041,17 @@ static bool migrate_show_downtime(MigrationState *s)\n     return (s->state == MIGRATION_STATUS_COMPLETED) || migration_in_postcopy();\n }\n \n+/* Return expected downtime (unit: milliseconds) */\n+int64_t migration_downtime_calc_expected(MigrationState *s)\n+{\n+    if (mig_stats.dirty_sync_count <= 1) {\n+        return migrate_downtime_limit();\n+    }\n+\n+    return mig_stats.dirty_bytes_last_sync /\n+        migration_get_switchover_bw(s) * 1000;\n+}\n+\n static void populate_time_info(MigrationInfo *info, MigrationState *s)\n {\n     info->has_status = true;\n@@ -1061,7 +1072,7 @@ static void populate_time_info(MigrationInfo *info, MigrationState *s)\n         info->downtime = s->downtime;\n     } else {\n         info->has_expected_downtime = true;\n-        info->expected_downtime = s->expected_downtime;\n+        info->expected_downtime = migration_downtime_calc_expected(s);\n     }\n }\n \n@@ -1649,7 +1660,6 @@ int migrate_init(MigrationState *s, Error **errp)\n     s->mbps = 0.0;\n     s->pages_per_second = 0.0;\n     s->downtime = 0;\n-    s->expected_downtime = 0;\n     s->setup_time = 0;\n     s->start_postcopy = false;\n     s->migration_thread_running = false;\n@@ -3162,15 +3172,6 @@ static void migration_update_counters(MigrationState *s,\n     s->pages_per_second = (double) transferred_pages /\n                              (((double) time_spent / 1000.0));\n \n-    /*\n-     * if we haven't sent anything, we don't want to\n-     * recalculate. 10000 is a small enough number for our purposes\n-     */\n-    if (mig_stats.dirty_pages_rate && transferred > 10000) {\n-        s->expected_downtime =\n-            mig_stats.dirty_bytes_last_sync / switchover_bw_per_ms;\n-    }\n-\n     migration_rate_reset();\n \n     update_iteration_initial_status(s);\n@@ -3816,8 +3817,6 @@ void migration_start_outgoing(MigrationState *s)\n     bool resume = (s->state == MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP);\n     int ret;\n \n-    s->expected_downtime = migrate_downtime_limit();\n-\n     if (resume) {\n         /* This is a resumed migration */\n         rate_limit = migrate_max_postcopy_bandwidth();\n","prefixes":["11/14"]}