a7b9285
From 0d9d4a5c179f09bd801ba3470b97e1fd3f184ce2 Mon Sep 17 00:00:00 2001
Alon Levy 408bdb5
From: Juan Quintela <quintela@redhat.com>
Alon Levy 408bdb5
Date: Fri, 1 Feb 2013 13:22:37 +0100
a7b9285
Subject: [PATCH] migration: calculate expected_downtime
Alon Levy 408bdb5
Alon Levy 408bdb5
We removed the calculation in commit e4ed1541ac9413eac494a03532e34beaf8a7d1c5
Alon Levy 408bdb5
Alon Levy 408bdb5
Now we add it back.  We need to create dirty_bytes_rate because we
Alon Levy 408bdb5
can't include cpu-all.h from migration.c, and there is no other way to
Alon Levy 408bdb5
include TARGET_PAGE_SIZE.
Alon Levy 408bdb5
Alon Levy 408bdb5
Signed-off-by: Juan Quintela <quintela@redhat.com>
Alon Levy 408bdb5
Alon Levy 408bdb5
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
a7b9285
(cherry picked from commit 90f8ae724a575861f093fbdbfd49a925bcfec327)
Alon Levy 408bdb5
---
Alon Levy 408bdb5
 arch_init.c                   | 1 +
Alon Levy 408bdb5
 include/migration/migration.h | 1 +
Alon Levy 408bdb5
 migration.c                   | 5 +++++
Alon Levy 408bdb5
 3 files changed, 7 insertions(+)
Alon Levy 408bdb5
Alon Levy 408bdb5
diff --git a/arch_init.c b/arch_init.c
Alon Levy 408bdb5
index 8da868b..8daeafa 100644
Alon Levy 408bdb5
--- a/arch_init.c
Alon Levy 408bdb5
+++ b/arch_init.c
Alon Levy 408bdb5
@@ -414,6 +414,7 @@ static void migration_bitmap_sync(void)
Alon Levy 408bdb5
     if (end_time > start_time + 1000) {
Alon Levy 408bdb5
         s->dirty_pages_rate = num_dirty_pages_period * 1000
Alon Levy 408bdb5
             / (end_time - start_time);
Alon Levy 408bdb5
+        s->dirty_bytes_rate = s->dirty_pages_rate * TARGET_PAGE_SIZE;
Alon Levy 408bdb5
         start_time = end_time;
Alon Levy 408bdb5
         num_dirty_pages_period = 0;
Alon Levy 408bdb5
     }
Alon Levy 408bdb5
diff --git a/include/migration/migration.h b/include/migration/migration.h
Alon Levy 408bdb5
index a8c9639..d121409 100644
Alon Levy 408bdb5
--- a/include/migration/migration.h
Alon Levy 408bdb5
+++ b/include/migration/migration.h
Alon Levy 408bdb5
@@ -51,6 +51,7 @@ struct MigrationState
Alon Levy 408bdb5
     int64_t downtime;
Alon Levy 408bdb5
     int64_t expected_downtime;
Alon Levy 408bdb5
     int64_t dirty_pages_rate;
Alon Levy 408bdb5
+    int64_t dirty_bytes_rate;
Alon Levy 408bdb5
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
Alon Levy 408bdb5
     int64_t xbzrle_cache_size;
Alon Levy 408bdb5
     bool complete;
Alon Levy 408bdb5
diff --git a/migration.c b/migration.c
Alon Levy 408bdb5
index ebfbbde..59e479d 100644
Alon Levy 408bdb5
--- a/migration.c
Alon Levy 408bdb5
+++ b/migration.c
Alon Levy 408bdb5
@@ -738,6 +738,11 @@ static void *buffered_file_thread(void *opaque)
Alon Levy 408bdb5
             DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
Alon Levy 408bdb5
                     " bandwidth %g max_size %" PRId64 "\n",
Alon Levy 408bdb5
                     transferred_bytes, time_spent, bandwidth, max_size);
Alon Levy 408bdb5
+            /* if we haven't sent anything, we don't want to recalculate
Alon Levy 408bdb5
+               10000 is a small enough number for our purposes */
Alon Levy 408bdb5
+            if (s->dirty_bytes_rate && transferred_bytes > 10000) {
Alon Levy 408bdb5
+                s->expected_downtime = s->dirty_bytes_rate / bandwidth;
Alon Levy 408bdb5
+            }
Alon Levy 408bdb5
 
Alon Levy 408bdb5
             s->bytes_xfer = 0;
Alon Levy 408bdb5
             sleep_time = 0;