1be5c7
From 82637509cc9197ad9d1e1b286a608bf0da04b7b3 Mon Sep 17 00:00:00 2001
1be5c7
From: David Edmondson <david.edmondson@oracle.com>
1be5c7
Date: Tue, 21 Dec 2021 09:34:41 +0000
1be5c7
Subject: [PATCH 2/9] migration: Tally pre-copy, downtime and post-copy bytes
1be5c7
 independently
1be5c7
MIME-Version: 1.0
1be5c7
Content-Type: text/plain; charset=UTF-8
1be5c7
Content-Transfer-Encoding: 8bit
1be5c7
1be5c7
RH-Author: Leonardo Brás <leobras@redhat.com>
1be5c7
RH-MergeRequest: 201: Zero-copy-send fixes + improvements
1be5c7
RH-Commit: [2/8] 7d1bf37a3d93da88da6525d70fc1fce1abb92b83
1be5c7
RH-Bugzilla: 2110203
1be5c7
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1be5c7
RH-Acked-by: Peter Xu <peterx@redhat.com>
1be5c7
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
1be5c7
1be5c7
Provide information on the number of bytes copied in the pre-copy,
1be5c7
downtime and post-copy phases of migration.
1be5c7
1be5c7
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
1be5c7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
1be5c7
Reviewed-by: Juan Quintela <quintela@redhat.com>
1be5c7
Signed-off-by: Juan Quintela <quintela@redhat.com>
1be5c7
(cherry picked from commit ae6806688016711bb9ec7541266d76ab511c5e3b)
1be5c7
Signed-off-by: Leonardo Bras <leobras@redhat.com>
1be5c7
---
1be5c7
 migration/migration.c |  3 +++
1be5c7
 migration/ram.c       |  7 +++++++
1be5c7
 monitor/hmp-cmds.c    | 12 ++++++++++++
1be5c7
 qapi/migration.json   | 13 ++++++++++++-
1be5c7
 4 files changed, 34 insertions(+), 1 deletion(-)
1be5c7
1be5c7
diff --git a/migration/migration.c b/migration/migration.c
1be5c7
index 616c3ff32e..e100b30f00 100644
1be5c7
--- a/migration/migration.c
1be5c7
+++ b/migration/migration.c
1be5c7
@@ -1016,6 +1016,9 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)
1be5c7
     info->ram->page_size = page_size;
1be5c7
     info->ram->multifd_bytes = ram_counters.multifd_bytes;
1be5c7
     info->ram->pages_per_second = s->pages_per_second;
1be5c7
+    info->ram->precopy_bytes = ram_counters.precopy_bytes;
1be5c7
+    info->ram->downtime_bytes = ram_counters.downtime_bytes;
1be5c7
+    info->ram->postcopy_bytes = ram_counters.postcopy_bytes;
1be5c7
 
1be5c7
     if (migrate_use_xbzrle()) {
1be5c7
         info->has_xbzrle_cache = true;
1be5c7
diff --git a/migration/ram.c b/migration/ram.c
1be5c7
index 3e82c4ff46..e7173da217 100644
1be5c7
--- a/migration/ram.c
1be5c7
+++ b/migration/ram.c
1be5c7
@@ -393,6 +393,13 @@ MigrationStats ram_counters;
1be5c7
 
1be5c7
 static void ram_transferred_add(uint64_t bytes)
1be5c7
 {
1be5c7
+    if (runstate_is_running()) {
1be5c7
+        ram_counters.precopy_bytes += bytes;
1be5c7
+    } else if (migration_in_postcopy()) {
1be5c7
+        ram_counters.postcopy_bytes += bytes;
1be5c7
+    } else {
1be5c7
+        ram_counters.downtime_bytes += bytes;
1be5c7
+    }
1be5c7
     ram_counters.transferred += bytes;
1be5c7
 }
1be5c7
 
1be5c7
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
1be5c7
index 2669156b28..8c384dc1b2 100644
1be5c7
--- a/monitor/hmp-cmds.c
1be5c7
+++ b/monitor/hmp-cmds.c
1be5c7
@@ -293,6 +293,18 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
1be5c7
             monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
1be5c7
                            info->ram->postcopy_requests);
1be5c7
         }
1be5c7
+        if (info->ram->precopy_bytes) {
1be5c7
+            monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n",
1be5c7
+                           info->ram->precopy_bytes >> 10);
1be5c7
+        }
1be5c7
+        if (info->ram->downtime_bytes) {
1be5c7
+            monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n",
1be5c7
+                           info->ram->downtime_bytes >> 10);
1be5c7
+        }
1be5c7
+        if (info->ram->postcopy_bytes) {
1be5c7
+            monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n",
1be5c7
+                           info->ram->postcopy_bytes >> 10);
1be5c7
+        }
1be5c7
     }
1be5c7
 
1be5c7
     if (info->has_disk) {
1be5c7
diff --git a/qapi/migration.json b/qapi/migration.json
1be5c7
index fe70a0c4b2..c8ec260ab0 100644
1be5c7
--- a/qapi/migration.json
1be5c7
+++ b/qapi/migration.json
1be5c7
@@ -46,6 +46,15 @@
1be5c7
 # @pages-per-second: the number of memory pages transferred per second
1be5c7
 #                    (Since 4.0)
1be5c7
 #
1be5c7
+# @precopy-bytes: The number of bytes sent in the pre-copy phase
1be5c7
+#                 (since 7.0).
1be5c7
+#
1be5c7
+# @downtime-bytes: The number of bytes sent while the guest is paused
1be5c7
+#                  (since 7.0).
1be5c7
+#
1be5c7
+# @postcopy-bytes: The number of bytes sent during the post-copy phase
1be5c7
+#                  (since 7.0).
1be5c7
+#
1be5c7
 # Since: 0.14
1be5c7
 ##
1be5c7
 { 'struct': 'MigrationStats',
1be5c7
@@ -54,7 +63,9 @@
1be5c7
            'normal-bytes': 'int', 'dirty-pages-rate' : 'int',
1be5c7
            'mbps' : 'number', 'dirty-sync-count' : 'int',
1be5c7
            'postcopy-requests' : 'int', 'page-size' : 'int',
1be5c7
-           'multifd-bytes' : 'uint64', 'pages-per-second' : 'uint64' } }
1be5c7
+           'multifd-bytes' : 'uint64', 'pages-per-second' : 'uint64',
1be5c7
+           'precopy-bytes' : 'uint64', 'downtime-bytes' : 'uint64',
1be5c7
+           'postcopy-bytes' : 'uint64' } }
1be5c7
 
1be5c7
 ##
1be5c7
 # @XBZRLECacheStats:
1be5c7
-- 
1be5c7
2.31.1
1be5c7