From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: aarcange@redhat.com, yamahata@private.email.ne.jp,
lilei@linux.vnet.ibm.com, quintela@redhat.com
Subject: [Qemu-devel] [PATCH v2 24/43] Postcopy page-map-incoming (PMI) structure
Date: Mon, 11 Aug 2014 15:29:40 +0100 [thread overview]
Message-ID: <1407767399-3030-25-git-send-email-dgilbert@redhat.com> (raw)
In-Reply-To: <1407767399-3030-1-git-send-email-dgilbert@redhat.com>
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
The PMI holds the state of each page on the incoming side,
so that we can tell if the page is missing, already received
or there is a request outstanding for it.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
include/migration/migration.h | 18 +++++
include/migration/postcopy-ram.h | 10 +++
include/qemu/typedefs.h | 1 +
postcopy-ram.c | 139 +++++++++++++++++++++++++++++++++++++++
4 files changed, 168 insertions(+)
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 627c95a..0ed3790 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -58,6 +58,23 @@ struct MigrationRetPathState {
typedef struct MigrationState MigrationState;
+/* Postcopy page-map-incoming - data about each page on the inbound side */
+
+typedef enum {
+ POSTCOPY_PMI_MISSING, /* page hasn't yet been received */
+ POSTCOPY_PMI_REQUESTED, /* Kernel asked for a page, but we've not got it */
+ POSTCOPY_PMI_RECEIVED /* We've got the page */
+} PostcopyPMIState;
+
+struct PostcopyPMI {
+ /* TODO: I'm expecting to rework this using some atomic compare-exchange
+ * thing, which will require merging the maps together
+ */
+ QemuMutex mutex;
+ unsigned long *received_map; /* Pages that we have received */
+ unsigned long *requested_map; /* Pages that we're sending a request for */
+};
+
/* State for the incoming migration */
struct MigrationIncomingState {
QEMUFile *file;
@@ -72,6 +89,7 @@ struct MigrationIncomingState {
QEMUFile *return_path;
QemuMutex rp_mutex; /* We send replies from multiple threads */
+ PostcopyPMI postcopy_pmi;
};
MigrationIncomingState *migration_incoming_get_current(void);
diff --git a/include/migration/postcopy-ram.h b/include/migration/postcopy-ram.h
index fe89a3c..e06cb45 100644
--- a/include/migration/postcopy-ram.h
+++ b/include/migration/postcopy-ram.h
@@ -36,4 +36,14 @@ int postcopy_ram_discard_range(MigrationIncomingState *mis, uint8_t *start,
int postcopy_send_discard_bm_ram(MigrationState *ms, const char *name,
unsigned long start, unsigned long end);
+/*
+ * In 'advise' mode record that a page has been received.
+ */
+void postcopy_hook_early_receive(MigrationIncomingState *mis,
+ size_t bitmap_index);
+
+void postcopy_pmi_destroy(MigrationIncomingState *mis);
+void postcopy_pmi_discard_range(MigrationIncomingState *mis,
+ size_t start, size_t npages);
+
#endif
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 8539de6..61b330c 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -77,6 +77,7 @@ typedef struct QEMUSGList QEMUSGList;
typedef struct SHPCDevice SHPCDevice;
typedef struct FWCfgState FWCfgState;
typedef struct PcGuestInfo PcGuestInfo;
+typedef struct PostcopyPMI PostcopyPMI;
typedef struct Range Range;
typedef struct AdapterInfo AdapterInfo;
diff --git a/postcopy-ram.c b/postcopy-ram.c
index ff6bdd6..b41fec8 100644
--- a/postcopy-ram.c
+++ b/postcopy-ram.c
@@ -23,6 +23,8 @@
#include "qemu-common.h"
#include "migration/migration.h"
#include "migration/postcopy-ram.h"
+#include "qemu/bitmap.h"
+#include "qemu/error-report.h"
#include "sysemu/sysemu.h"
//#define DEBUG_POSTCOPY
@@ -66,6 +68,135 @@
#define __NR_remap_anon_pages 317
#endif
+/* ---------------------------------------------------------------------- */
+/* Postcopy pagemap-inbound (pmi) - data structures that record the */
+/* state of each page used by the inbound postcopy */
+
+static void postcopy_pmi_init(MigrationIncomingState *mis, size_t ram_pages)
+{
+ qemu_mutex_init(&mis->postcopy_pmi.mutex);
+ mis->postcopy_pmi.received_map = bitmap_new(ram_pages);
+ mis->postcopy_pmi.requested_map = bitmap_new(ram_pages);
+ bitmap_clear(mis->postcopy_pmi.received_map, 0, ram_pages);
+ bitmap_clear(mis->postcopy_pmi.requested_map, 0, ram_pages);
+}
+
+void postcopy_pmi_destroy(MigrationIncomingState *mis)
+{
+ if (mis->postcopy_pmi.received_map) {
+ g_free(mis->postcopy_pmi.received_map);
+ mis->postcopy_pmi.received_map = NULL;
+ }
+ if (mis->postcopy_pmi.requested_map) {
+ g_free(mis->postcopy_pmi.requested_map);
+ mis->postcopy_pmi.requested_map = NULL;
+ }
+ qemu_mutex_destroy(&mis->postcopy_pmi.mutex);
+}
+
+/*
+ * Mark a set of pages in the PMI as being clear; this is used by the discard
+ * at the start of postcopy, and before the postcopy stream starts.
+ */
+void postcopy_pmi_discard_range(MigrationIncomingState *mis,
+ size_t start, size_t npages)
+{
+ bitmap_clear(mis->postcopy_pmi.received_map, start, npages);
+}
+
+/*
+ * Retrieve the state of the given page
+ * Note: This version for use by callers already holding the lock
+ */
+static PostcopyPMIState postcopy_pmi_get_state_nolock(
+ MigrationIncomingState *mis,
+ size_t bitmap_index)
+{
+ bool received, requested;
+
+ received = test_bit(bitmap_index, mis->postcopy_pmi.received_map);
+ requested = test_bit(bitmap_index, mis->postcopy_pmi.requested_map);
+
+ if (received) {
+ assert(!requested);
+ return POSTCOPY_PMI_RECEIVED;
+ } else {
+ return requested ? POSTCOPY_PMI_REQUESTED : POSTCOPY_PMI_MISSING;
+ }
+}
+
+/* Retrieve the state of the given page */
+static PostcopyPMIState postcopy_pmi_get_state(MigrationIncomingState *mis,
+ size_t bitmap_index)
+{
+ PostcopyPMIState ret;
+ qemu_mutex_lock(&mis->postcopy_pmi.mutex);
+ ret = postcopy_pmi_get_state_nolock(mis, bitmap_index);
+ qemu_mutex_unlock(&mis->postcopy_pmi.mutex);
+
+ return ret;
+}
+
+/*
+ * Set the page state to the given state if the previous state was as expected
+ * Return the actual previous state.
+ */
+static PostcopyPMIState postcopy_pmi_change_state(MigrationIncomingState *mis,
+ size_t bitmap_index,
+ PostcopyPMIState expected_state,
+ PostcopyPMIState new_state)
+{
+ PostcopyPMIState old_state;
+
+ qemu_mutex_lock(&mis->postcopy_pmi.mutex);
+ old_state = postcopy_pmi_get_state_nolock(mis, bitmap_index);
+
+ if (old_state == expected_state) {
+ switch (new_state) {
+ case POSTCOPY_PMI_MISSING:
+ assert(0); /* This shouldn't actually happen - use discard_range */
+ break;
+
+ case POSTCOPY_PMI_REQUESTED:
+ assert(old_state == POSTCOPY_PMI_MISSING);
+ set_bit(bitmap_index, mis->postcopy_pmi.requested_map);
+ break;
+
+ case POSTCOPY_PMI_RECEIVED:
+ assert(old_state == POSTCOPY_PMI_MISSING ||
+ old_state == POSTCOPY_PMI_REQUESTED);
+ set_bit(bitmap_index, mis->postcopy_pmi.received_map);
+ clear_bit(bitmap_index, mis->postcopy_pmi.requested_map);
+ break;
+ }
+ }
+
+ qemu_mutex_unlock(&mis->postcopy_pmi.mutex);
+ return old_state;
+}
+
+static void postcopy_pmi_dump(MigrationIncomingState *mis)
+{
+ fprintf(stderr, "postcopy_pmi_dump: requested\n");
+ ram_debug_dump_bitmap(mis->postcopy_pmi.requested_map, false);
+ fprintf(stderr, "postcopy_pmi_dump: received\n");
+ ram_debug_dump_bitmap(mis->postcopy_pmi.received_map, true);
+}
+
+/* Called by ram_load prior to mapping the page */
+void postcopy_hook_early_receive(MigrationIncomingState *mis,
+ size_t bitmap_index)
+{
+ if (mis->postcopy_ram_state == POSTCOPY_RAM_INCOMING_ADVISE) {
+ /*
+ * If we're in precopy-advise mode we need to track received pages even
+ * though we don't need to place pages atomically yet.
+ * In advise mode there's only a single thread, so don't need locks
+ */
+ set_bit(bitmap_index, mis->postcopy_pmi.received_map);
+ }
+}
+
int postcopy_ram_hosttest(void)
{
/* TODO: Needs guarding with CONFIG_ once we have libc's that have the defs
@@ -147,6 +278,14 @@ int postcopy_ram_discard_range(MigrationIncomingState *mis, void *start,
error_report("postcopy_ram_discard_range: No OS support");
return -1;
}
+
+/* Called by ram_load prior to mapping the page */
+void postcopy_hook_early_receive(MigrationIncomingState *mis,
+ size_t bitmap_index)
+{
+ /* We don't support postcopy so don't care */
+}
+
#endif
/* ------------------------------------------------------------------------- */
--
1.9.3
next prev parent reply other threads:[~2014-08-11 14:31 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-11 14:29 [Qemu-devel] [PATCH v2 00/43] Postcopy implementation Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 01/43] qemu_ram_foreach_block: pass up error value, and down the ramblock name Dr. David Alan Gilbert (git)
2014-08-11 18:29 ` Eric Blake
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 02/43] improve DPRINTF macros, add to savevm Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 03/43] Add qemu_get_counted_string to read a string prefixed by a count byte Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 04/43] Create MigrationIncomingState Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 05/43] Return path: Open a return path on QEMUFile for sockets Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 06/43] Return path: socket_writev_buffer: Block even on non-blocking fd's Dr. David Alan Gilbert (git)
2014-08-12 2:13 ` [Qemu-devel] 答复: " chenliang (T)
2014-08-12 9:36 ` [Qemu-devel] ????: [PATCH v2 06/43] Return path: socket_writev_buffer:?Block " Dr. David Alan Gilbert
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 07/43] Migration commands Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 08/43] Return path: Control commands Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 09/43] Return path: Send responses from destination to source Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 10/43] Return path: Source handling of return path Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 11/43] qemu_loadvm errors and debug Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 12/43] ram_debug_dump_bitmap: Dump a migration bitmap as text Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 13/43] Rework loadvm path for subloops Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 14/43] Add migration-capability boolean for postcopy-ram Dr. David Alan Gilbert (git)
2014-08-11 16:47 ` Eric Blake
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 15/43] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 16/43] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 17/43] migrate_init: Call from savevm Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 18/43] Allow savevm handlers to state whether they could go into postcopy Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 19/43] postcopy: OS support test Dr. David Alan Gilbert (git)
2014-08-12 5:32 ` zhanghailiang
2014-08-12 8:18 ` Dr. David Alan Gilbert
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 20/43] migrate_start_postcopy: Command to trigger transition to postcopy Dr. David Alan Gilbert (git)
2014-08-11 17:01 ` Eric Blake
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 21/43] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 22/43] qemu_savevm_state_complete: Postcopy changes Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 23/43] Postcopy: Maintain sentmap during postcopy pre phase Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` Dr. David Alan Gilbert (git) [this message]
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 25/43] postcopy: Add incoming_init/cleanup functions Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 26/43] postcopy: Incoming initialisation Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 27/43] postcopy: ram_enable_notify to switch on userfault Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 28/43] Postcopy: postcopy_start Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 29/43] Postcopy: Rework migration thread for postcopy mode Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 30/43] mig fd_connect: open return path Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 31/43] Postcopy: Create a fault handler thread before marking the ram as userfault Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 32/43] Page request: Add MIG_RPCOMM_REQPAGES reverse command Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 33/43] Page request: Process incoming page request Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 34/43] Page request: Consume pages off the post-copy queue Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 35/43] Add assertion to check migration_dirty_pages Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 36/43] postcopy_ram.c: place_page and helpers Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 37/43] Postcopy: Use helpers to map pages during migration Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 38/43] qemu_ram_block_from_host Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 39/43] Postcopy; Handle userfault requests Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 40/43] Start up a postcopy/listener thread ready for incoming page data Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 41/43] postcopy: Wire up loadvm_postcopy_ram_handle_{run, end} commands Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 42/43] End of migration for postcopy Dr. David Alan Gilbert (git)
2014-08-11 14:29 ` [Qemu-devel] [PATCH v2 43/43] Start documenting how postcopy works Dr. David Alan Gilbert (git)
2014-08-11 17:19 ` Eric Blake
2014-08-11 17:58 ` Dr. David Alan Gilbert
2014-08-12 1:50 ` [Qemu-devel] [PATCH v2 00/43] Postcopy implementation zhanghailiang
2014-08-12 9:19 ` Dr. David Alan Gilbert
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=1407767399-3030-25-git-send-email-dgilbert@redhat.com \
--to=dgilbert@redhat.com \
--cc=aarcange@redhat.com \
--cc=lilei@linux.vnet.ibm.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).