From cc283e3bf04d2f64eb6ec2ee5bcd36edd779fe89 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Fri, 1 Feb 2013 11:12:26 +0100 Subject: [PATCH 1/4] migration: change initial value of expected_downtime 0 is a very bad initial value, what we are trying to get is max_downtime, so that is a much better estimation. Signed-off-by: Juan Quintela Reviewed-by: Orit Wasserman --- migration.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration.c b/migration.c index b1ebb01145..b3f5ba41f5 100644 --- a/migration.c +++ b/migration.c @@ -774,6 +774,8 @@ void migrate_fd_connect(MigrationState *s) s->buffer = NULL; s->buffer_size = 0; s->buffer_capacity = 0; + /* This is a best 1st approximation. ns to ms */ + s->expected_downtime = max_downtime/1000000; s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO; s->complete = false; From a3e879cd51c4f614f702117c4b1449f0218c00f3 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Fri, 1 Feb 2013 12:39:08 +0100 Subject: [PATCH 2/4] migration: calculate end time after we have sent the data Signed-off-by: Juan Quintela Reviewed-by: Orit Wasserman --- migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration.c b/migration.c index b3f5ba41f5..b8e412fcc5 100644 --- a/migration.c +++ b/migration.c @@ -673,7 +673,7 @@ static void *buffered_file_thread(void *opaque) qemu_mutex_unlock_iothread(); while (true) { - int64_t current_time = qemu_get_clock_ms(rt_clock); + int64_t current_time; uint64_t pending_size; qemu_mutex_lock_iothread(); @@ -727,6 +727,7 @@ static void *buffered_file_thread(void *opaque) } } qemu_mutex_unlock_iothread(); + current_time = qemu_get_clock_ms(rt_clock); if (current_time >= initial_time + BUFFER_DELAY) { uint64_t transferred_bytes = s->bytes_xfer; uint64_t time_spent = current_time - initial_time; From 7161082c8d8cf167c508976887a0a63f4db92b51 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Fri, 1 Feb 2013 12:41:38 +0100 Subject: [PATCH 3/4] migration: don't account sleep time for calculating bandwidth While we are sleeping we are not sending, so we should not use that time to estimate our bandwidth. Signed-off-by: Juan Quintela Reviewed-by: Orit Wasserman --- migration.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration.c b/migration.c index b8e412fcc5..6649e3a689 100644 --- a/migration.c +++ b/migration.c @@ -658,6 +658,7 @@ static void *buffered_file_thread(void *opaque) { MigrationState *s = opaque; int64_t initial_time = qemu_get_clock_ms(rt_clock); + int64_t sleep_time = 0; int64_t max_size = 0; bool last_round = false; int ret; @@ -730,7 +731,7 @@ static void *buffered_file_thread(void *opaque) current_time = qemu_get_clock_ms(rt_clock); if (current_time >= initial_time + BUFFER_DELAY) { uint64_t transferred_bytes = s->bytes_xfer; - uint64_t time_spent = current_time - initial_time; + uint64_t time_spent = current_time - initial_time - sleep_time; double bandwidth = transferred_bytes / time_spent; max_size = bandwidth * migrate_max_downtime() / 1000000; @@ -739,11 +740,13 @@ static void *buffered_file_thread(void *opaque) transferred_bytes, time_spent, bandwidth, max_size); s->bytes_xfer = 0; + sleep_time = 0; initial_time = current_time; } if (!last_round && (s->bytes_xfer >= s->xfer_limit)) { /* usleep expects microseconds */ g_usleep((initial_time + BUFFER_DELAY - current_time)*1000); + sleep_time += qemu_get_clock_ms(rt_clock) - current_time; } ret = buffered_flush(s); if (ret < 0) { From 90f8ae724a575861f093fbdbfd49a925bcfec327 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Fri, 1 Feb 2013 13:22:37 +0100 Subject: [PATCH 4/4] migration: calculate expected_downtime We removed the calculation in commit e4ed1541ac9413eac494a03532e34beaf8a7d1c5 Now we add it back. We need to create dirty_bytes_rate because we can't include cpu-all.h from migration.c, and there is no other way to include TARGET_PAGE_SIZE. Signed-off-by: Juan Quintela Reviewed-by: Orit Wasserman --- arch_init.c | 1 + include/migration/migration.h | 1 + migration.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/arch_init.c b/arch_init.c index 8da868b988..8daeafaf5c 100644 --- a/arch_init.c +++ b/arch_init.c @@ -414,6 +414,7 @@ static void migration_bitmap_sync(void) if (end_time > start_time + 1000) { s->dirty_pages_rate = num_dirty_pages_period * 1000 / (end_time - start_time); + s->dirty_bytes_rate = s->dirty_pages_rate * TARGET_PAGE_SIZE; start_time = end_time; num_dirty_pages_period = 0; } diff --git a/include/migration/migration.h b/include/migration/migration.h index a8c9639732..d1214097fe 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -51,6 +51,7 @@ struct MigrationState int64_t downtime; int64_t expected_downtime; int64_t dirty_pages_rate; + int64_t dirty_bytes_rate; bool enabled_capabilities[MIGRATION_CAPABILITY_MAX]; int64_t xbzrle_cache_size; bool complete; diff --git a/migration.c b/migration.c index 6649e3a689..11725ae3fc 100644 --- a/migration.c +++ b/migration.c @@ -738,6 +738,11 @@ static void *buffered_file_thread(void *opaque) DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 "\n", transferred_bytes, time_spent, bandwidth, max_size); + /* if we haven't sent anything, we don't want to recalculate + 10000 is a small enough number for our purposes */ + if (s->dirty_bytes_rate && transferred_bytes > 10000) { + s->expected_downtime = s->dirty_bytes_rate / bandwidth; + } s->bytes_xfer = 0; sleep_time = 0;