[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 33/47] Postcopy: Rework migration thread for post
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v3 33/47] Postcopy: Rework migration thread for postcopy mode |
Date: |
Thu, 28 Aug 2014 16:03:50 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
Switch to postcopy if:
1) There's still a significant amount to transfer
2) Postcopy is enabled
3) migrate_postcopy_start has been issued.
and change the cleanup at the end of migration to match.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
migration.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 74 insertions(+), 16 deletions(-)
diff --git a/migration.c b/migration.c
index 1ae5b7d..623a056 100644
--- a/migration.c
+++ b/migration.c
@@ -991,16 +991,36 @@ static int postcopy_start(MigrationState *ms)
static void *migration_thread(void *opaque)
{
MigrationState *s = opaque;
+ /* Used by the bandwidth calcs, updated later */
int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST);
int64_t initial_bytes = 0;
int64_t max_size = 0;
int64_t start_time = initial_time;
+
bool old_vm_running = false;
+ /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
+ enum MigrationPhase current_active_type = MIG_STATE_ACTIVE;
+
qemu_savevm_state_begin(s->file, &s->params);
+ if (migrate_postcopy_ram()) {
+ /* Now tell the dest that it should open it's end so it can reply */
+ qemu_savevm_send_openrp(s->file);
+
+ /* And ask it to send an ack that will make stuff easier to debug */
+ qemu_savevm_send_reqack(s->file, 1);
+
+ /* Tell the destination that we *might* want to do postcopy later;
+ * if the other end can't do postcopy it should fail now, nice and
+ * early.
+ */
+ qemu_savevm_send_postcopy_ram_advise(s->file);
+ }
+
s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
+ current_active_type = MIG_STATE_ACTIVE;
migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
DPRINTF("setup complete\n");
@@ -1021,37 +1041,74 @@ static void *migration_thread(void *opaque)
" nonpost=%" PRIu64 ")\n",
pending_size, max_size, pend_post, pend_nonpost);
if (pending_size && pending_size >= max_size) {
+ /* Still a significant amount to transfer */
+
+ current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+ if (migrate_postcopy_ram() &&
+ s->state != MIG_STATE_POSTCOPY_ACTIVE &&
+ pend_nonpost == 0 && s->start_postcopy) {
+
+ if (!postcopy_start(s)) {
+ current_active_type = MIG_STATE_POSTCOPY_ACTIVE;
+ }
+
+ continue;
+ }
+ /* Just another iteration step */
qemu_savevm_state_iterate(s->file);
} else {
int ret;
- DPRINTF("done iterating\n");
- qemu_mutex_lock_iothread();
- start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
- old_vm_running = runstate_is_running();
+ DPRINTF("done iterating pending size %" PRIu64 "\n",
+ pending_size);
+
+ if (s->state == MIG_STATE_ACTIVE) {
+ qemu_mutex_lock_iothread();
+ start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+ qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+ old_vm_running = runstate_is_running();
+
+ ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+ if (ret >= 0) {
+ qemu_file_set_rate_limit(s->file, INT64_MAX);
+ qemu_savevm_state_complete(s->file);
+ }
+ qemu_mutex_unlock_iothread();
+
+ if (ret < 0) {
+ migrate_set_state(s, current_active_type,
+ MIG_STATE_ERROR);
+ break;
+ }
+ } else if (s->state == MIG_STATE_POSTCOPY_ACTIVE) {
+ DPRINTF("postcopy end\n");
+
+ qemu_savevm_state_postcopy_complete(s->file);
+ DPRINTF("postcopy end after complete\n");
- ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
- if (ret >= 0) {
- qemu_file_set_rate_limit(s->file, INT64_MAX);
- qemu_savevm_state_complete(s->file);
}
- qemu_mutex_unlock_iothread();
- if (ret < 0) {
- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
- break;
+ /*
+ * If rp was opened we must clean up the thread before
+ * cleaning everything else up.
+ * Postcopy opens rp if enabled (even if it's not avtivated)
+ */
+ if (migrate_postcopy_ram()) {
+ DPRINTF("before rp close");
+ await_outgoing_return_path_close(s);
+ DPRINTF("after rp close");
}
-
if (!qemu_file_get_error(s->file)) {
- migrate_set_state(s, MIG_STATE_ACTIVE,
MIG_STATE_COMPLETED);
+ migrate_set_state(s, current_active_type,
+ MIG_STATE_COMPLETED);
break;
}
}
}
if (qemu_file_get_error(s->file)) {
- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
+ migrate_set_state(s, current_active_type, MIG_STATE_ERROR);
+ DPRINTF("migration_thread: file is in error state\n");
break;
}
current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
@@ -1082,6 +1139,7 @@ static void *migration_thread(void *opaque)
}
}
+ DPRINTF("migration_thread: After loop");
qemu_mutex_lock_iothread();
if (s->state == MIG_STATE_COMPLETED) {
int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
--
1.9.3
- [Qemu-devel] [PATCH v3 24/47] migrate_start_postcopy: Command to trigger transition to postcopy, (continued)
- [Qemu-devel] [PATCH v3 24/47] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 25/47] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 27/47] Postcopy: Maintain sentmap during postcopy pre phase, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 28/47] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 29/47] postcopy: Add incoming_init/cleanup functions, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 26/47] qemu_savevm_state_complete: Postcopy changes, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 15/47] qemu_loadvm errors and debug, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 19/47] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages., Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 31/47] postcopy: ram_enable_notify to switch on userfault, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 34/47] mig fd_connect: open return path, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 33/47] Postcopy: Rework migration thread for postcopy mode,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v3 32/47] Postcopy: postcopy_start, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 36/47] Page request: Add MIG_RPCOMM_REQPAGES reverse command, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 37/47] Page request: Process incoming page request, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 39/47] Add assertion to check migration_dirty_pages, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 38/47] Page request: Consume pages off the post-copy queue, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 41/47] Postcopy: Use helpers to map pages during migration, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 42/47] qemu_ram_block_from_host, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 43/47] Don't sync dirty bitmaps in postcopy, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 44/47] Postcopy; Handle userfault requests, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 46/47] postcopy: Wire up loadvm_postcopy_ram_handle_{run, end} commands, Dr. David Alan Gilbert (git), 2014/08/28