{"id":2233224,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2233224/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260505202640.1011006-13-peterx@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.1/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":"<20260505202640.1011006-13-peterx@redhat.com>","date":"2026-05-05T20:26:29","name":"[PULL,12/23] migration: Introduce a helper to return switchover bw estimate","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"40910d22baa7354680a125e81bcdbdcb5281a2b6","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/1.1/people/67717/?format=json","name":"Peter Xu","email":"peterx@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260505202640.1011006-13-peterx@redhat.com/mbox/","series":[{"id":502897,"url":"http://patchwork.ozlabs.org/api/1.1/series/502897/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502897","date":"2026-05-05T20:26:17","name":"[PULL,01/23] migration: Fix blocking in POSTCOPY_DEVICE during package load","version":1,"mbox":"http://patchwork.ozlabs.org/series/502897/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233224/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233224/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=IRbRDovx;\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=fWZlqEiI;\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=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [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 4g999X4QJFz1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 06:29:52 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wKMMN-0004br-JQ; Tue, 05 May 2026 16:27:15 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1wKMMD-0004Te-Hl\n for qemu-devel@nongnu.org; Tue, 05 May 2026 16:27:05 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.133.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 1wKMMB-0002cx-El\n for qemu-devel@nongnu.org; Tue, 05 May 2026 16:27:05 -0400","from mail-qv1-f72.google.com (mail-qv1-f72.google.com\n [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-300-Z3rVoT83MVOe8zBejjIHgg-1; Tue, 05 May 2026 16:27:00 -0400","by mail-qv1-f72.google.com with SMTP id\n 6a1803df08f44-8b7e68098dcso69803716d6.3\n for <qemu-devel@nongnu.org>; Tue, 05 May 2026 13:27:00 -0700 (PDT)","from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8b53c6b8123sm155283806d6.35.2026.05.05.13.26.57\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 05 May 2026 13:26:57 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778012821;\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=c7J+3/zQgM5oGZ4jYYw3SGbSGgqkUYRSROV8mmjeY+Y=;\n b=IRbRDovxjg16SX11ozbx72hRhrBsAEj48SqXKWCKNhrLSau2JsaNG0kV6pET/7UvsSIFiL\n rjvozN4cWPEl/4IcnKBFxvyEaTxDyl7a9jce1ocgRD8325eOc6rV5voc3XSxsi2L9cSVm4\n MJER4GIVbckz3mcvoXTVtAMrk/T/9D0=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1778012819; x=1778617619; 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=c7J+3/zQgM5oGZ4jYYw3SGbSGgqkUYRSROV8mmjeY+Y=;\n b=fWZlqEiIPFsfRPJSy0kZZZnNKm+JLtuqhSoXZxEwrpEGmMhZaxvL9zt7ZI7nN1FZow\n PU4OY6KSSsXIt4DsBE3un7NEu0JqtzM4yCZUKzr978EV3BXn5WPf47prcomsIbu7+dEw\n lsNwytI6qudamJc4W3AH3608kxWIuuIGW1mSst1WlbOvMD3OP2KhklPI4T4z3WnuZvL7\n kab0zhoefA2m7sYE9DGwkIqMyfTHG2k/bI9//0iIBU280TdbeB4agP6WInlM3NGRPugK\n gDrpgIn0cBrc+6yZMGSu3henpcUQIyQYomFUzRVpuDG99KHwRJ+bYgZOFP3o87Ezp0KN\n 8U1A=="],"X-MC-Unique":"Z3rVoT83MVOe8zBejjIHgg-1","X-Mimecast-MFC-AGG-ID":"Z3rVoT83MVOe8zBejjIHgg_1778012819","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778012819; x=1778617619;\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=c7J+3/zQgM5oGZ4jYYw3SGbSGgqkUYRSROV8mmjeY+Y=;\n b=gb5sBKwkwMjheVIA85Y45PAtDbqLuTEvxX9uqQTn9IuFD7vWIFck2rSJHLBdwwTSAn\n 6R2OD5EgWN6VBwbneZzZgPB0SY77FP1sDzw5tfLeTkV3BC6Io4XkmRudUvl019+Q1ie5\n aNgXcte45ujsZP2qObmndLKbWvNFZaej/g5mXu0+KW2LnoEqD0VTx5ZYn5GS3nv2EOgd\n GP/U2DSVouIfQbZRmgKZPPWeW6UME0gC8lfCT6kwfzbmoOhu3ZRXFLOIWO7QoTquHUWU\n rBlD0DCyF9aOwwR7hejS5JG9FjqdHbl1QkXib7dKRuYUv77j1+vXw7OEnozo3zN43d0c\n YKvQ==","X-Gm-Message-State":"AOJu0Yzx+6ko6+Qd82dl+tsIvxPDsbZSgxp1as1aGAR6yIfJaCxyvZeK\n +aj9a9kL+jQhQJKljv2TjDGspj51mKcSTz4njK6jOPCVsZieKunZOfv6KVvBWBE/eB+eZBqhzjI\n 5vjUYIunrgvF2/J5qRnJmqGL5jE707uZzFvBaJBvvZ6k3eFxKdjOPdu1XMue2OnyUKK+HncnRBg\n ZJL7fgH67z6H0sg26fl/niIxj3P+3fNxwf0bz0jw==","X-Gm-Gg":"AeBDievptcF5OvarxcbtfYk2MY9szAe1ByMJirsEvXlSpouBUwmUPHJVFfJs0g/hh0O\n /YwZij3TTn152a1WnJed3IUrkEvS0iGHXmod8xs6aNi1VIbQu/2enxJbIOfa5m+NFZd0icle8Au\n 1vVJfFUOY9fHpsTBgAS9xGFH1JdHaeIR9kHlRAQgx9GPyupB0IlVR31oRWc6zns0NltKfjBzHHT\n BNniX2PHPmQAbgRSm9HNqq6I5wkR99iUT5IK/Sw0CiVjYgDrkPnC85c4/1Q3alrGJKasroEP07t\n 7eRje5l7COwokN8EpB+fV6GCRhOLVImLQ79ptTyMkCSD3ukebJkITYnQ6LekWDEZqvFIO5qAs3h\n vAqwtoc6AmXzTuewdSXk6gwDT7c0QG4Ajx5JLjYqzMZEnfcXBNVAXJpc=","X-Received":["by 2002:a05:6214:763:b0:8b4:a0be:4b50 with SMTP id\n 6a1803df08f44-8bc4517a7f1mr4398636d6.33.1778012819059;\n Tue, 05 May 2026 13:26:59 -0700 (PDT)","by 2002:a05:6214:763:b0:8b4:a0be:4b50 with SMTP id\n 6a1803df08f44-8bc4517a7f1mr4397866d6.33.1778012818351;\n Tue, 05 May 2026 13:26:58 -0700 (PDT)"],"From":"Peter Xu <peterx@redhat.com>","To":"qemu-devel@nongnu.org","Cc":"Fabiano Rosas <farosas@suse.de>, Paolo Bonzini <pbonzini@redhat.com>,\n Peter Xu <peterx@redhat.com>, Juraj Marcin <jmarcin@redhat.com>","Subject":"[PULL 12/23] migration: Introduce a helper to return switchover bw\n estimate","Date":"Tue,  5 May 2026 16:26:29 -0400","Message-ID":"<20260505202640.1011006-13-peterx@redhat.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260505202640.1011006-1-peterx@redhat.com>","References":"<20260505202640.1011006-1-peterx@redhat.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com","X-Spam_score_int":"-24","X-Spam_score":"-2.5","X-Spam_bar":"--","X-Spam_report":"(-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.443,\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_H5=0.001, RCVD_IN_MSPIKE_WL=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":"Add a helper migration_get_switchover_bw() to return an estimate of\nswitchover bandwidth.  Use it to simplify the current code.\n\nThis will be used in later to remove expected_downtime.\n\nWhen at it, remove two qatomic_read() to shrink the lines because atomic\nops are not needed when it's always the same thread who does the updates.\n\nReviewed-by: Juraj Marcin <jmarcin@redhat.com>\nLink: https://lore.kernel.org/r/20260421202110.306051-11-peterx@redhat.com\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n migration/migration.c | 48 +++++++++++++++++++++----------------------\n 1 file changed, 24 insertions(+), 24 deletions(-)","diff":"diff --git a/migration/migration.c b/migration/migration.c\nindex 8abc7e0327..4e19fe3409 100644\n--- a/migration/migration.c\n+++ b/migration/migration.c\n@@ -984,6 +984,21 @@ void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t value)\n     migrate_send_rp_message(mis, MIG_RP_MSG_RESUME_ACK, sizeof(buf), &buf);\n }\n \n+/*\n+ * Returns the estimated switchover bandwidth (unit: bytes / seconds)\n+ */\n+static double migration_get_switchover_bw(MigrationState *s)\n+{\n+    uint64_t switchover_bw = migrate_avail_switchover_bandwidth();\n+\n+    if (switchover_bw) {\n+        /* If user specified, prioritize this value and don't estimate */\n+        return (double)switchover_bw;\n+    }\n+\n+    return s->mbps / 8 * 1000 * 1000;\n+}\n+\n bool migration_is_running(void)\n {\n     MigrationState *s = current_migration;\n@@ -3130,37 +3145,22 @@ static void migration_update_counters(MigrationState *s,\n {\n     uint64_t transferred, transferred_pages, time_spent;\n     uint64_t current_bytes; /* bytes transferred since the beginning */\n-    uint64_t switchover_bw;\n-    /* Expected bandwidth when switching over to destination QEMU */\n-    double expected_bw_per_ms;\n-    double bandwidth;\n+    double switchover_bw_per_ms;\n \n     if (current_time < s->iteration_start_time + BUFFER_DELAY) {\n         return;\n     }\n \n-    switchover_bw = migrate_avail_switchover_bandwidth();\n     current_bytes = migration_transferred_bytes();\n     transferred = current_bytes - s->iteration_initial_bytes;\n     time_spent = current_time - s->iteration_start_time;\n-    bandwidth = (double)transferred / time_spent;\n-\n-    if (switchover_bw) {\n-        /*\n-         * If the user specified a switchover bandwidth, let's trust the\n-         * user so that can be more accurate than what we estimated.\n-         */\n-        expected_bw_per_ms = (double)switchover_bw / 1000;\n-    } else {\n-        /* If the user doesn't specify bandwidth, we use the estimated */\n-        expected_bw_per_ms = bandwidth;\n-    }\n-\n-    s->threshold_size = expected_bw_per_ms * migrate_downtime_limit();\n-\n     s->mbps = (((double) transferred * 8.0) /\n                ((double) time_spent / 1000.0)) / 1000.0 / 1000.0;\n \n+    /* NOTE: only update this after bandwidth (s->mbps) updated */\n+    switchover_bw_per_ms = migration_get_switchover_bw(s) / 1000;\n+    s->threshold_size = switchover_bw_per_ms * migrate_downtime_limit();\n+\n     transferred_pages = ram_get_total_transferred_pages() -\n                             s->iteration_initial_pages;\n     s->pages_per_second = (double) transferred_pages /\n@@ -3170,10 +3170,9 @@ static void migration_update_counters(MigrationState *s,\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 (qatomic_read(&mig_stats.dirty_pages_rate) &&\n-        transferred > 10000) {\n+    if (mig_stats.dirty_pages_rate && transferred > 10000) {\n         s->expected_downtime =\n-            qatomic_read(&mig_stats.dirty_bytes_last_sync) / expected_bw_per_ms;\n+            mig_stats.dirty_bytes_last_sync / switchover_bw_per_ms;\n     }\n \n     migration_rate_reset();\n@@ -3182,7 +3181,8 @@ static void migration_update_counters(MigrationState *s,\n \n     trace_migrate_transferred(transferred, time_spent,\n                               /* Both in unit bytes/ms */\n-                              bandwidth, switchover_bw / 1000,\n+                              (uint64_t)s->mbps,\n+                              (uint64_t)switchover_bw_per_ms,\n                               s->threshold_size);\n }\n \n","prefixes":["PULL","12/23"]}