From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: aarcange@redhat.com, yamahata@private.email.ne.jp,
quintela@redhat.com, liang.z.li@intel.com, luis@cs.umu.se,
amit.shah@redhat.com, pbonzini@redhat.com,
david@gibson.dropbear.id.au
Subject: [Qemu-devel] [PATCH v7 38/42] Start up a postcopy/listener thread ready for incoming page data
Date: Tue, 16 Jun 2015 11:26:51 +0100 [thread overview]
Message-ID: <1434450415-11339-39-git-send-email-dgilbert@redhat.com> (raw)
In-Reply-To: <1434450415-11339-1-git-send-email-dgilbert@redhat.com>
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
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 <dgilbert@redhat.com>
---
include/migration/migration.h | 4 +++
migration/migration.c | 6 ++++
migration/savevm.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
trace-events | 2 ++
4 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 4f954ca..da6529d 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -75,6 +75,10 @@ struct MigrationIncomingState {
QemuThread fault_thread;
QemuSemaphore fault_thread_sem;
+ bool have_listen_thread;
+ QemuThread listen_thread;
+ QemuSemaphore listen_thread_sem;
+
/* For the kernel to send us notifications */
int userfault_fd;
/* To tell the fault_thread to quit */
diff --git a/migration/migration.c b/migration/migration.c
index 7fa982e..e908b50 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1222,6 +1222,12 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running)
goto fail;
}
+ /*
+ * Make sure the receiver can get incoming pages before we send the rest
+ * of the state
+ */
+ qemu_savevm_send_postcopy_listen(fb);
+
qemu_savevm_state_complete_precopy(fb);
qemu_savevm_send_ping(fb, 3);
diff --git a/migration/savevm.c b/migration/savevm.c
index b87238a..258c551 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1314,6 +1314,65 @@ static int loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis,
return 0;
}
+/*
+ * 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)
+{
+ QEMUFile *f = opaque;
+ MigrationIncomingState *mis = migration_incoming_get_current();
+ int load_res;
+
+ qemu_sem_post(&mis->listen_thread_sem);
+ trace_postcopy_ram_listen_thread_start();
+
+ /*
+ * Because we're a thread and not a coroutine we can't yield
+ * in qemu_file, and thus we must be blocking now.
+ */
+ qemu_file_change_blocking(f, true);
+ load_res = qemu_loadvm_state_main(f, mis);
+ /* And non-blocking again so we don't block in any cleanup */
+ qemu_file_change_blocking(f, false);
+
+ trace_postcopy_ram_listen_thread_exit();
+ if (load_res < 0) {
+ error_report("%s: loadvm failed: %d", __func__, load_res);
+ qemu_file_set_error(f, load_res);
+ } else {
+ /*
+ * This looks good, but it's possible that the device loading in the
+ * main thread hasn't finished yet, and so we might not be in 'RUN'
+ * state yet; wait for the end of the main thread.
+ */
+ qemu_event_wait(&mis->main_thread_load_event);
+ }
+ postcopy_ram_incoming_cleanup(mis);
+ /*
+ * If everything has worked fine, then the main thread has waited
+ * for us to start, and we're the last use of the mis.
+ * (If something broke then qemu will have to exit anyway since it's
+ * got a bad migration state).
+ */
+ migration_incoming_state_destroy();
+
+ if (load_res < 0) {
+ /*
+ * If something went wrong then we have a bad state so exit;
+ * depending how far we got it might be possible at this point
+ * to leave the guest running and fire MCEs for pages that never
+ * arrived as a desperate recovery step.
+ */
+ exit(EXIT_FAILURE);
+ }
+
+ return NULL;
+}
+
/* After this message we must be able to immediately receive postcopy data */
static int loadvm_postcopy_handle_listen(MigrationIncomingState *mis)
{
@@ -1333,7 +1392,20 @@ static int loadvm_postcopy_handle_listen(MigrationIncomingState *mis)
return -1;
}
- /* TODO start up the postcopy listening thread */
+ 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);
+ qemu_thread_create(&mis->listen_thread, "postcopy/listen",
+ postcopy_ram_listen_thread, mis->file,
+ QEMU_THREAD_JOINABLE);
+ qemu_sem_wait(&mis->listen_thread_sem);
+ qemu_sem_destroy(&mis->listen_thread_sem);
+
return 0;
}
@@ -1657,6 +1729,11 @@ int qemu_loadvm_state(QEMUFile *f)
qemu_event_set(&mis->main_thread_load_event);
trace_qemu_loadvm_state_post_main(ret);
+ if (mis->have_listen_thread) {
+ /* Listen thread still going, can't clean up yet */
+ return ret;
+ }
+
if (ret == 0) {
int file_error_after_eof = qemu_file_get_error(f);
diff --git a/trace-events b/trace-events
index ab201f9..a6c7839 100644
--- a/trace-events
+++ b/trace-events
@@ -1199,6 +1199,8 @@ loadvm_postcopy_ram_handle_discard_end(void) ""
loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud"
loadvm_process_command(uint16_t com, uint16_t len) "com=0x%x len=%d"
loadvm_process_command_ping(uint32_t val) "%x"
+postcopy_ram_listen_thread_exit(void) ""
+postcopy_ram_listen_thread_start(void) ""
qemu_savevm_send_postcopy_advise(void) ""
qemu_savevm_send_postcopy_ram_discard(const char *id, uint16_t len) "%s: %ud"
savevm_section_start(const char *id, unsigned int section_id) "%s, section_id %u"
--
2.4.3
next prev parent reply other threads:[~2015-06-16 10:28 UTC|newest]
Thread overview: 209+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-16 10:26 [Qemu-devel] [PATCH v7 00/42] Postcopy implementation Dr. David Alan Gilbert (git)
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 01/42] Start documenting how postcopy works Dr. David Alan Gilbert (git)
2015-06-17 11:42 ` Juan Quintela
2015-06-17 12:30 ` Dr. David Alan Gilbert
2015-06-18 7:50 ` Li, Liang Z
2015-06-18 8:10 ` Dr. David Alan Gilbert
2015-06-18 8:28 ` Paolo Bonzini
2015-06-19 17:52 ` Dr. David Alan Gilbert
2015-06-26 6:46 ` Yang Hongyang
2015-06-26 7:53 ` zhanghailiang
2015-06-26 8:00 ` Yang Hongyang
2015-06-26 8:10 ` Dr. David Alan Gilbert
2015-06-26 8:19 ` Yang Hongyang
2015-08-04 5:20 ` Amit Shah
2015-08-05 12:21 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 02/42] Provide runtime Target page information Dr. David Alan Gilbert (git)
2015-06-17 11:43 ` Juan Quintela
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 03/42] Init page sizes in qtest Dr. David Alan Gilbert (git)
2015-06-17 11:49 ` Juan Quintela
2015-07-06 6:14 ` Amit Shah
2015-08-04 5:23 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 04/42] qemu_ram_block_from_host Dr. David Alan Gilbert (git)
2015-06-17 11:54 ` Juan Quintela
2015-07-10 8:36 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 05/42] Add qemu_get_buffer_less_copy to avoid copies some of the time Dr. David Alan Gilbert (git)
2015-06-17 11:57 ` Juan Quintela
2015-06-17 12:33 ` Dr. David Alan Gilbert
2015-07-13 9:08 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 06/42] Add wrapper for setting blocking status on a QEMUFile Dr. David Alan Gilbert (git)
2015-06-17 11:59 ` Juan Quintela
2015-06-17 12:34 ` Dr. David Alan Gilbert
2015-06-17 12:57 ` Juan Quintela
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 07/42] ram_debug_dump_bitmap: Dump a migration bitmap as text Dr. David Alan Gilbert (git)
2015-06-17 12:17 ` Juan Quintela
2015-06-19 17:04 ` Dr. David Alan Gilbert
2015-07-13 10:15 ` Juan Quintela
2015-07-13 9:12 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 08/42] migrate_init: Call from savevm Dr. David Alan Gilbert (git)
2015-06-17 12:18 ` Juan Quintela
2015-07-13 9:13 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 09/42] Rename save_live_complete to save_live_complete_precopy Dr. David Alan Gilbert (git)
2015-06-17 12:20 ` Juan Quintela
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 10/42] Return path: Open a return path on QEMUFile for sockets Dr. David Alan Gilbert (git)
2015-06-17 12:23 ` Juan Quintela
2015-06-17 17:07 ` Dr. David Alan Gilbert
2015-07-13 10:12 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 11/42] Return path: socket_writev_buffer: Block even on non-blocking fd's Dr. David Alan Gilbert (git)
2015-06-17 12:28 ` Juan Quintela
2015-06-19 17:18 ` Dr. David Alan Gilbert
2015-07-13 12:37 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 12/42] Migration commands Dr. David Alan Gilbert (git)
2015-06-17 12:31 ` Juan Quintela
2015-06-19 17:38 ` Dr. David Alan Gilbert
2015-07-13 12:45 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 13/42] Return path: Control commands Dr. David Alan Gilbert (git)
2015-06-17 12:49 ` Juan Quintela
2015-06-23 18:57 ` Dr. David Alan Gilbert
2015-07-13 12:55 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 14/42] Return path: Send responses from destination to source Dr. David Alan Gilbert (git)
2015-06-17 16:30 ` Juan Quintela
2015-06-19 18:42 ` Dr. David Alan Gilbert
2015-07-01 9:29 ` Juan Quintela
2015-08-06 12:18 ` Dr. David Alan Gilbert
2015-07-15 7:31 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 15/42] Return path: Source handling of return path Dr. David Alan Gilbert (git)
2015-07-13 10:29 ` Juan Quintela
2015-08-18 10:23 ` Dr. David Alan Gilbert
2015-07-15 7:50 ` Amit Shah
2015-07-16 11:32 ` Dr. David Alan Gilbert
2015-08-05 8:06 ` zhanghailiang
2015-08-18 10:45 ` Dr. David Alan Gilbert
2015-08-18 11:29 ` zhanghailiang
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 16/42] Rework loadvm path for subloops Dr. David Alan Gilbert (git)
2015-07-13 10:33 ` Juan Quintela
2015-07-15 9:34 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 17/42] Add migration-capability boolean for postcopy-ram Dr. David Alan Gilbert (git)
2015-06-16 15:43 ` Eric Blake
2015-06-16 15:58 ` Dr. David Alan Gilbert
2015-07-15 9:39 ` Amit Shah
2015-07-13 10:35 ` Juan Quintela
2015-07-15 9:40 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 18/42] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages Dr. David Alan Gilbert (git)
2015-07-13 11:02 ` Juan Quintela
2015-07-20 10:13 ` Amit Shah
2015-08-26 14:48 ` Dr. David Alan Gilbert
2015-07-20 10:06 ` Amit Shah
2015-07-27 9:55 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 19/42] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream Dr. David Alan Gilbert (git)
2015-07-13 11:07 ` Juan Quintela
2015-07-21 6:11 ` Amit Shah
2015-07-27 17:28 ` Dr. David Alan Gilbert
2015-08-04 5:27 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 20/42] Modify save_live_pending for postcopy Dr. David Alan Gilbert (git)
2015-07-13 11:12 ` Juan Quintela
2015-07-31 16:13 ` Dr. David Alan Gilbert
2015-07-21 6:17 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 21/42] postcopy: OS support test Dr. David Alan Gilbert (git)
2015-07-13 11:20 ` Juan Quintela
2015-07-13 16:31 ` Dr. David Alan Gilbert
2015-07-21 7:29 ` Amit Shah
2015-07-27 17:38 ` Dr. David Alan Gilbert
2015-08-04 5:28 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 22/42] migrate_start_postcopy: Command to trigger transition to postcopy Dr. David Alan Gilbert (git)
2015-07-13 11:23 ` Juan Quintela
2015-07-13 17:13 ` Dr. David Alan Gilbert
2015-07-13 18:07 ` Juan Quintela
2015-07-21 7:40 ` Amit Shah
2015-09-24 9:59 ` Dr. David Alan Gilbert
2015-09-24 14:20 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 23/42] MIGRATION_STATUS_POSTCOPY_ACTIVE: Add new migration state Dr. David Alan Gilbert (git)
2015-07-13 11:27 ` Juan Quintela
2015-07-13 15:53 ` Dr. David Alan Gilbert
2015-07-13 16:26 ` Juan Quintela
2015-07-13 16:48 ` Dr. David Alan Gilbert
2015-07-13 18:05 ` Juan Quintela
2015-07-21 10:33 ` Amit Shah
2015-09-23 17:04 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 24/42] Add qemu_savevm_state_complete_postcopy Dr. David Alan Gilbert (git)
2015-07-13 11:35 ` Juan Quintela
2015-07-13 15:33 ` Dr. David Alan Gilbert
2015-07-21 10:42 ` Amit Shah
2015-07-27 17:58 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 25/42] Postcopy: Maintain sentmap and calculate discard Dr. David Alan Gilbert (git)
2015-07-13 11:47 ` Juan Quintela
2015-09-15 17:01 ` Dr. David Alan Gilbert
2015-07-21 11:36 ` Amit Shah
2015-07-31 16:51 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 26/42] postcopy: Incoming initialisation Dr. David Alan Gilbert (git)
2015-07-13 12:04 ` Juan Quintela
2015-09-23 19:06 ` Dr. David Alan Gilbert
2015-07-22 6:19 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 27/42] postcopy: ram_enable_notify to switch on userfault Dr. David Alan Gilbert (git)
2015-07-13 12:10 ` Juan Quintela
2015-07-13 17:36 ` Dr. David Alan Gilbert
2015-07-23 5:22 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 28/42] Postcopy: Postcopy startup in migration thread Dr. David Alan Gilbert (git)
2015-07-13 12:56 ` Juan Quintela
2015-07-13 17:56 ` Dr. David Alan Gilbert
2015-07-13 18:09 ` Juan Quintela
2015-09-23 17:56 ` Dr. David Alan Gilbert
2015-07-23 5:53 ` Amit Shah
2015-07-23 5:55 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 29/42] Postcopy end in migration_thread Dr. David Alan Gilbert (git)
2015-07-13 13:15 ` Juan Quintela
2015-07-23 6:41 ` Amit Shah
2015-08-04 11:31 ` Dr. David Alan Gilbert
2015-07-23 6:41 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 30/42] Page request: Add MIG_RP_MSG_REQ_PAGES reverse command Dr. David Alan Gilbert (git)
2015-07-13 13:24 ` Juan Quintela
2015-08-06 14:15 ` Dr. David Alan Gilbert
2015-07-23 6:50 ` Amit Shah
2015-08-06 14:21 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 31/42] Page request: Process incoming page request Dr. David Alan Gilbert (git)
2015-07-14 9:18 ` Juan Quintela
2015-08-06 10:45 ` Dr. David Alan Gilbert
2015-10-20 10:29 ` Juan Quintela
2015-07-23 12:23 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 32/42] Page request: Consume pages off the post-copy queue Dr. David Alan Gilbert (git)
2015-07-14 9:40 ` Juan Quintela
2015-09-16 18:36 ` Dr. David Alan Gilbert
2015-07-27 6:05 ` Amit Shah
2015-09-16 18:48 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 33/42] postcopy_ram.c: place_page and helpers Dr. David Alan Gilbert (git)
2015-07-14 10:05 ` Juan Quintela
2015-07-27 6:11 ` Amit Shah
2015-09-23 16:45 ` Dr. David Alan Gilbert
2015-07-27 6:11 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 34/42] Postcopy: Use helpers to map pages during migration Dr. David Alan Gilbert (git)
2015-07-14 12:34 ` Juan Quintela
2015-07-17 17:31 ` Dr. David Alan Gilbert
2015-07-27 7:39 ` Amit Shah
2015-08-06 11:22 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 35/42] Don't sync dirty bitmaps in postcopy Dr. David Alan Gilbert (git)
2015-07-14 12:36 ` Juan Quintela
2015-07-14 13:13 ` Dr. David Alan Gilbert
2015-07-27 7:43 ` Amit Shah
2015-07-31 9:50 ` Dr. David Alan Gilbert
2015-08-04 5:46 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 36/42] Host page!=target page: Cleanup bitmaps Dr. David Alan Gilbert (git)
2015-07-14 15:01 ` Juan Quintela
2015-07-31 15:53 ` Dr. David Alan Gilbert
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 37/42] Postcopy; Handle userfault requests Dr. David Alan Gilbert (git)
2015-07-14 15:10 ` Juan Quintela
2015-07-14 15:15 ` Dr. David Alan Gilbert
2015-07-14 15:25 ` Juan Quintela
2015-07-27 14:29 ` Amit Shah
2015-06-16 10:26 ` Dr. David Alan Gilbert (git) [this message]
2015-07-14 15:12 ` [Qemu-devel] [PATCH v7 38/42] Start up a postcopy/listener thread ready for incoming page data Juan Quintela
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 39/42] postcopy: Wire up loadvm_postcopy_handle_ commands Dr. David Alan Gilbert (git)
2015-07-14 15:14 ` Juan Quintela
2015-07-28 5:53 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 40/42] End of migration for postcopy Dr. David Alan Gilbert (git)
2015-07-14 15:15 ` Juan Quintela
2015-07-28 5:55 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 41/42] Disable mlock around incoming postcopy Dr. David Alan Gilbert (git)
2015-07-14 15:22 ` Juan Quintela
2015-07-28 6:02 ` Amit Shah
2015-07-28 11:32 ` Juan Quintela
2015-08-06 14:55 ` Dr. David Alan Gilbert
2015-08-07 3:05 ` zhanghailiang
2015-09-24 10:36 ` Dr. David Alan Gilbert
2015-07-28 6:02 ` Amit Shah
2015-06-16 10:26 ` [Qemu-devel] [PATCH v7 42/42] Inhibit ballooning during postcopy Dr. David Alan Gilbert (git)
2015-07-14 15:24 ` Juan Quintela
2015-07-28 6:15 ` Amit Shah
2015-07-28 9:08 ` Dr. David Alan Gilbert
2015-07-28 10:01 ` Amit Shah
2015-07-28 11:16 ` Dr. David Alan Gilbert
2015-07-28 6:21 ` [Qemu-devel] [PATCH v7 00/42] Postcopy implementation Amit Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434450415-11339-39-git-send-email-dgilbert@redhat.com \
--to=dgilbert@redhat.com \
--cc=aarcange@redhat.com \
--cc=amit.shah@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=liang.z.li@intel.com \
--cc=luis@cs.umu.se \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=yamahata@private.email.ne.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).