[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 31/42] Page request: Process incoming page reques
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v7 31/42] Page request: Process incoming page request |
Date: |
Tue, 16 Jun 2015 11:26:44 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
On receiving MIG_RPCOMM_REQ_PAGES look up the address and
queue the page.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/migration.h | 21 +++++++++++++++
migration/migration.c | 36 +++++++++++++++++++++++++
migration/ram.c | 63 +++++++++++++++++++++++++++++++++++++++++++
trace-events | 1 +
4 files changed, 121 insertions(+)
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 8742d53..20d1b39 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -88,6 +88,18 @@ MigrationIncomingState *migration_incoming_get_current(void);
MigrationIncomingState *migration_incoming_state_new(QEMUFile *f);
void migration_incoming_state_destroy(void);
+/*
+ * An outstanding page request, on the source, having been received
+ * and queued
+ */
+struct MigrationSrcPageRequest {
+ RAMBlock *rb;
+ hwaddr offset;
+ hwaddr len;
+
+ QSIMPLEQ_ENTRY(MigrationSrcPageRequest) next_req;
+};
+
struct MigrationState
{
int64_t bandwidth_limit;
@@ -131,6 +143,12 @@ struct MigrationState
* of the postcopy phase
*/
unsigned long *sentmap;
+
+ /* Queue of outstanding page requests from the destination */
+ QemuMutex src_page_req_mutex;
+ QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest)
src_page_requests;
+ /* The RAMBlock used in the last src_page_request */
+ RAMBlock *last_req_rb;
};
void process_incoming_migration(QEMUFile *f);
@@ -272,6 +290,9 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t
block_offset,
void ram_mig_init(void);
void savevm_skip_section_footers(void);
+int ram_save_queue_pages(MigrationState *ms, const char *rbname,
+ ram_addr_t start, ram_addr_t len);
+
PostcopyState postcopy_state_get(MigrationIncomingState *mis);
/* Set the state and return the old state */
diff --git a/migration/migration.c b/migration/migration.c
index 0373b77..7fa982e 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -26,6 +26,8 @@
#include "qemu/thread.h"
#include "qmp-commands.h"
#include "trace.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
#define MAX_THROTTLE (32 << 20) /* Migration speed throttling */
@@ -57,6 +59,7 @@ static bool deferred_incoming;
/* For outgoing */
MigrationState *migrate_get_current(void)
{
+ static bool once;
static MigrationState current_migration = {
.state = MIGRATION_STATUS_NONE,
.bandwidth_limit = MAX_THROTTLE,
@@ -70,6 +73,10 @@ MigrationState *migrate_get_current(void)
DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT,
};
+ if (!once) {
+ qemu_mutex_init(¤t_migration.src_page_req_mutex);
+ once = true;
+ }
return ¤t_migration;
}
@@ -584,6 +591,15 @@ static void migrate_fd_cleanup(void *opaque)
migrate_fd_cleanup_src_rp(s);
+ /* This queue generally should be empty - but in the case of a failed
+ * migration might have some droppings in.
+ */
+ struct MigrationSrcPageRequest *mspr, *next_mspr;
+ QSIMPLEQ_FOREACH_SAFE(mspr, &s->src_page_requests, next_req, next_mspr) {
+ QSIMPLEQ_REMOVE_HEAD(&s->src_page_requests, next_req);
+ g_free(mspr);
+ }
+
if (s->file) {
trace_migrate_fd_cleanup();
qemu_mutex_unlock_iothread();
@@ -713,6 +729,8 @@ MigrationState *migrate_init(const MigrationParams *params)
s->state = MIGRATION_STATUS_SETUP;
trace_migrate_set_state(MIGRATION_STATUS_SETUP);
+ QSIMPLEQ_INIT(&s->src_page_requests);
+
s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
return s;
}
@@ -976,7 +994,25 @@ static void source_return_path_bad(MigrationState *s)
static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
ram_addr_t start, ram_addr_t len)
{
+ long our_host_ps = getpagesize();
+
trace_migrate_handle_rp_req_pages(rbname, start, len);
+
+ /*
+ * Since we currently insist on matching page sizes, just sanity check
+ * we're being asked for whole host pages.
+ */
+ if (start & (our_host_ps-1) ||
+ (len & (our_host_ps-1))) {
+ error_report("%s: Misaligned page request, start: " RAM_ADDR_FMT
+ " len: " RAM_ADDR_FMT, __func__, start, len);
+ source_return_path_bad(ms);
+ return;
+ }
+
+ if (ram_save_queue_pages(ms, rbname, start, len)) {
+ source_return_path_bad(ms);
+ }
}
/*
diff --git a/migration/ram.c b/migration/ram.c
index f7d957e..da3e9ea 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -924,6 +924,69 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock
*block,
}
/**
+ * Queue the pages for transmission, e.g. a request from postcopy destination
+ * ms: MigrationStatus in which the queue is held
+ * rbname: The RAMBlock the request is for - may be NULL (to mean reuse last)
+ * start: Offset from the start of the RAMBlock
+ * len: Length (in bytes) to send
+ * Return: 0 on success
+ */
+int ram_save_queue_pages(MigrationState *ms, const char *rbname,
+ ram_addr_t start, ram_addr_t len)
+{
+ RAMBlock *ramblock;
+
+ rcu_read_lock();
+ if (!rbname) {
+ /* Reuse last RAMBlock */
+ ramblock = ms->last_req_rb;
+
+ if (!ramblock) {
+ /*
+ * Shouldn't happen, we can't reuse the last RAMBlock if
+ * it's the 1st request.
+ */
+ error_report("ram_save_queue_pages no previous block");
+ goto err;
+ }
+ } else {
+ ramblock = ram_find_block(rbname);
+
+ if (!ramblock) {
+ /* We shouldn't be asked for a non-existent RAMBlock */
+ error_report("ram_save_queue_pages no block '%s'", rbname);
+ goto err;
+ }
+ }
+ trace_ram_save_queue_pages(ramblock->idstr, start, len);
+ if (start+len > ramblock->used_length) {
+ error_report("%s request overrun start=%zx len=%zx blocklen=%zx",
+ __func__, start, len, ramblock->used_length);
+ goto err;
+ }
+
+ struct MigrationSrcPageRequest *new_entry =
+ g_malloc0(sizeof(struct MigrationSrcPageRequest));
+ new_entry->rb = ramblock;
+ new_entry->offset = start;
+ new_entry->len = len;
+ ms->last_req_rb = ramblock;
+
+ qemu_mutex_lock(&ms->src_page_req_mutex);
+ memory_region_ref(ramblock->mr);
+ QSIMPLEQ_INSERT_TAIL(&ms->src_page_requests, new_entry, next_req);
+ qemu_mutex_unlock(&ms->src_page_req_mutex);
+ rcu_read_unlock();
+
+ return 0;
+
+err:
+ rcu_read_unlock();
+ return -1;
+}
+
+
+/**
* ram_find_and_save_block: Finds a dirty page and sends it to f
*
* Called within an RCU critical section.
diff --git a/trace-events b/trace-events
index 328d64c..04f6682 100644
--- a/trace-events
+++ b/trace-events
@@ -1232,6 +1232,7 @@ migration_bitmap_sync_start(void) ""
migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64""
migration_throttle(void) ""
ram_postcopy_send_discard_bitmap(void) ""
+ram_save_queue_pages(const char *rbname, size_t start, size_t len) "%s: start:
%zx len: %zx"
# hw/display/qxl.c
disable qxl_interface_set_mm_time(int qid, uint32_t mm_time) "%d %d"
--
2.4.3
- [Qemu-devel] [PATCH v7 22/42] migrate_start_postcopy: Command to trigger transition to postcopy, (continued)
- [Qemu-devel] [PATCH v7 22/42] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 21/42] postcopy: OS support test, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 23/42] MIGRATION_STATUS_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 24/42] Add qemu_savevm_state_complete_postcopy, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 26/42] postcopy: Incoming initialisation, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 25/42] Postcopy: Maintain sentmap and calculate discard, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 28/42] Postcopy: Postcopy startup in migration thread, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 29/42] Postcopy end in migration_thread, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 27/42] postcopy: ram_enable_notify to switch on userfault, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 30/42] Page request: Add MIG_RP_MSG_REQ_PAGES reverse command, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 31/42] Page request: Process incoming page request,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v7 33/42] postcopy_ram.c: place_page and helpers, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 32/42] Page request: Consume pages off the post-copy queue, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 34/42] Postcopy: Use helpers to map pages during migration, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 35/42] Don't sync dirty bitmaps in postcopy, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 36/42] Host page!=target page: Cleanup bitmaps, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 37/42] Postcopy; Handle userfault requests, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 38/42] Start up a postcopy/listener thread ready for incoming page data, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 39/42] postcopy: Wire up loadvm_postcopy_handle_ commands, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 40/42] End of migration for postcopy, Dr. David Alan Gilbert (git), 2015/06/16
- [Qemu-devel] [PATCH v7 41/42] Disable mlock around incoming postcopy, Dr. David Alan Gilbert (git), 2015/06/16