[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 42/46] Start up a postcopy/listener thread ready for
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH 42/46] Start up a postcopy/listener thread ready for incoming page data |
Date: |
Fri, 4 Jul 2014 18:41:53 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
The loading of a device state (during postcopy) may access guest
memory that's still on the source machine and thus might need
a page fill; split off a separate thread that handles the incoming
page data so that the original incoming migration code can finish
off the device data.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/migration.h | 4 +++
migration.c | 6 +++++
savevm.c | 63 +++++++++++++++++++++++++++++++++++++++++--
3 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 46fc37b..3313b3c 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -89,6 +89,10 @@ struct MigrationIncomingState {
QemuThread fault_thread;
QemuSemaphore fault_thread_sem;
+ bool have_listen_thread;
+ QemuThread listen_thread;
+ QemuSemaphore listen_thread_sem;
+
int userfault_fd;
QEMUFile *return_path;
diff --git a/migration.c b/migration.c
index 66d281b..fc8911d 100644
--- a/migration.c
+++ b/migration.c
@@ -1045,6 +1045,12 @@ static int postcopy_start(MigrationState *ms)
*/
QEMUFile *fb = qemu_bufopen("w", NULL);
+ /*
+ * Make sure the receiver can get incoming pages before we send the rest
+ * of the state
+ */
+ qemu_savevm_send_postcopy_ram_listen(fb);
+
qemu_savevm_state_complete(fb);
DPRINTF("postcopy_start: sending req 3\n");
qemu_savevm_send_reqack(fb, 3);
diff --git a/savevm.c b/savevm.c
index 1d5375c..f4907db 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1259,9 +1259,46 @@ static int
loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis,
return 0;
}
+typedef struct ram_listen_thread_data {
+ QEMUFile *f;
+ LoadStateEntry_Head *lh;
+} ram_listen_thread_data;
+
+/*
+ * Triggered by a postcopy_listen command; this thread takes over reading
+ * the input stream, leaving the main thread free to carry on loading the rest
+ * of the device state (from RAM).
+ * (TODO:This could do with being in a postcopy file - but there again it's
+ * just another input loop, not that postcopy specific)
+ */
+static void *postcopy_ram_listen_thread(void *opaque)
+{
+ ram_listen_thread_data *rltd = opaque;
+ int load_res;
+
+ qemu_sem_post(&rltd->f->mis->listen_thread_sem);
+ DPRINTF("postcopy_ram_listen_thread start");
+
+ load_res = qemu_loadvm_state_main(rltd->f, rltd->lh);
+
+ DPRINTF("postcopy_ram_listen_thread exiting");
+ if (load_res) {
+ error_report("%s: loadvm failed: %d", __func__, load_res);
+ qemu_file_set_error(rltd->f, load_res);
+ }
+ /* TODO: Find somewhere better for this! */
+ close(rltd->f->mis->userfault_fd);
+ postcopy_ram_incoming_cleanup(rltd->f->mis);
+ g_free(rltd);
+
+ return NULL;
+}
+
/* After this message we must be able to immediately receive page data */
static int loadvm_postcopy_ram_handle_listen(MigrationIncomingState *mis)
{
+ ram_listen_thread_data *rltd = g_malloc(sizeof(ram_listen_thread_data));
+
DPRINTF("%s", __func__);
if (mis->postcopy_ram_state != POSTCOPY_RAM_INCOMING_ADVISE) {
error_report("CMD_POSTCOPY_RAM_LISTEN in wrong postcopy state (%d)",
@@ -1280,8 +1317,25 @@ static int
loadvm_postcopy_ram_handle_listen(MigrationIncomingState *mis)
return -1;
}
- /* TODO start up the postcopy listening thread */
- return 0;
+ if (mis->have_listen_thread) {
+ error_report("CMD_POSTCOPY_RAM_LISTEN already has a listen thread");
+ return -1;
+ }
+
+ mis->have_listen_thread = true;
+ /* Start up the listening thread and wait for it to signal ready */
+ qemu_sem_init(&mis->listen_thread_sem, 0);
+ rltd->f = mis->file;
+ rltd->lh = &loadvm_handlers;
+ qemu_thread_create(&mis->listen_thread, "postcopy/listen",
+ postcopy_ram_listen_thread, rltd, QEMU_THREAD_JOINABLE);
+ qemu_sem_wait(&mis->listen_thread_sem);
+
+ /*
+ * all good - cause the loop that handled this command to exit because
+ * the new thread is taking over
+ */
+ return LOADVM_EXITCODE_QUITPARENT | LOADVM_EXITCODE_KEEPHANDLERS;
}
/* After all discards we can start running and asking for pages */
@@ -1596,6 +1650,11 @@ int qemu_loadvm_state(QEMUFile *f)
QLIST_INIT(&loadvm_handlers);
ret = qemu_loadvm_state_main(f, &loadvm_handlers);
+ if (f->mis->have_listen_thread) {
+ /* Listen thread still going, can't clean up yet */
+ return ret;
+ }
+
if (ret == 0) {
cpu_synchronize_all_post_init();
}
--
1.9.3
- [Qemu-devel] [PATCH 40/46] qemu_ram_block_from_host, (continued)
- [Qemu-devel] [PATCH 40/46] qemu_ram_block_from_host, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 21/46] postcopy: OS support test, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 22/46] Migration parameters: Add qmp/hmp commands for setting/viewing, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 19/46] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 20/46] Allow savevm handlers to state whether they could go into postcopy, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 41/46] Handle userfault requests (although userfaultfd not done yet), Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 13/46] qemu_loadvm debug, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 14/46] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 18/46] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream, Dr. David Alan Gilbert (git), 2014/07/04
- [Qemu-devel] [PATCH 42/46] Start up a postcopy/listener thread ready for incoming page data,
Dr. David Alan Gilbert (git) <=
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Paolo Bonzini, 2014/07/05
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert, 2014/07/07
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Paolo Bonzini, 2014/07/07
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert, 2014/07/07
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert, 2014/07/10
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Eric Blake, 2014/07/10
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert, 2014/07/10
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Andrea Arcangeli, 2014/07/10
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Dr. David Alan Gilbert, 2014/07/10
- Re: [Qemu-devel] [PATCH 00/46] Postcopy implementation, Sanidhya Kashyap, 2014/07/11