[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/26] savevm: split the process of different stages
From: |
Jason Wang |
Subject: |
[Qemu-devel] [PULL 13/26] savevm: split the process of different stages for loadvm/savevm |
Date: |
Mon, 15 Oct 2018 16:46:13 +0800 |
From: Zhang Chen <address@hidden>
There are several stages during loadvm/savevm process. In different stage,
migration incoming processes different types of sections.
We want to control these stages more accuracy, it will benefit COLO
performance, we don't have to save type of QEMU_VM_SECTION_START
sections everytime while do checkpoint, besides, we want to separate
the process of saving/loading memory and devices state.
So we add three new helper functions: qemu_load_device_state() and
qemu_savevm_live_state() to achieve different process during migration.
Besides, we make qemu_loadvm_state_main() and qemu_save_device_state()
public, and simplify the codes of qemu_save_device_state() by calling the
wrapper qemu_savevm_state_header().
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
Signed-off-by: Zhang Chen <address@hidden>
Signed-off-by: Zhang Chen <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Signed-off-by: Jason Wang <address@hidden>
---
migration/colo.c | 41 ++++++++++++++++++++++++++++++++---------
migration/savevm.c | 36 +++++++++++++++++++++++++++++-------
migration/savevm.h | 4 ++++
3 files changed, 65 insertions(+), 16 deletions(-)
diff --git a/migration/colo.c b/migration/colo.c
index 94c4e09..59bb507 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -30,6 +30,7 @@
#include "block/block.h"
#include "qapi/qapi-events-migration.h"
#include "qapi/qmp/qerror.h"
+#include "sysemu/cpus.h"
static bool vmstate_loading;
static Notifier packets_compare_notifier;
@@ -401,24 +402,35 @@ static int colo_do_checkpoint_transaction(MigrationState
*s,
/* Disable block migration */
migrate_set_block_enabled(false, &local_err);
- qemu_savevm_state_header(fb);
- qemu_savevm_state_setup(fb);
qemu_mutex_lock_iothread();
replication_do_checkpoint_all(&local_err);
if (local_err) {
qemu_mutex_unlock_iothread();
goto out;
}
- qemu_savevm_state_complete_precopy(fb, false, false);
- qemu_mutex_unlock_iothread();
-
- qemu_fflush(fb);
colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
if (local_err) {
+ qemu_mutex_unlock_iothread();
+ goto out;
+ }
+ /* Note: device state is saved into buffer */
+ ret = qemu_save_device_state(fb);
+
+ qemu_mutex_unlock_iothread();
+ if (ret < 0) {
goto out;
}
/*
+ * Only save VM's live state, which not including device state.
+ * TODO: We may need a timeout mechanism to prevent COLO process
+ * to be blocked here.
+ */
+ qemu_savevm_live_state(s->to_dst_file);
+
+ qemu_fflush(fb);
+
+ /*
* We need the size of the VMstate data in Secondary side,
* With which we can decide how much data should be read.
*/
@@ -635,6 +647,7 @@ void *colo_process_incoming_thread(void *opaque)
uint64_t total_size;
uint64_t value;
Error *local_err = NULL;
+ int ret;
rcu_register_thread();
qemu_sem_init(&mis->colo_incoming_sem, 0);
@@ -708,6 +721,16 @@ void *colo_process_incoming_thread(void *opaque)
goto out;
}
+ qemu_mutex_lock_iothread();
+ cpu_synchronize_all_pre_loadvm();
+ ret = qemu_loadvm_state_main(mis->from_src_file, mis);
+ qemu_mutex_unlock_iothread();
+
+ if (ret < 0) {
+ error_report("Load VM's live state (ram) error");
+ goto out;
+ }
+
value = colo_receive_message_value(mis->from_src_file,
COLO_MESSAGE_VMSTATE_SIZE, &local_err);
if (local_err) {
@@ -739,10 +762,10 @@ void *colo_process_incoming_thread(void *opaque)
}
qemu_mutex_lock_iothread();
- qemu_system_reset(SHUTDOWN_CAUSE_NONE);
vmstate_loading = true;
- if (qemu_loadvm_state(fb) < 0) {
- error_report("COLO: loadvm failed");
+ ret = qemu_load_device_state(fb);
+ if (ret < 0) {
+ error_report("COLO: load device state failed");
qemu_mutex_unlock_iothread();
goto out;
}
diff --git a/migration/savevm.c b/migration/savevm.c
index 288b807..e4caff9 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1378,13 +1378,21 @@ done:
return ret;
}
-static int qemu_save_device_state(QEMUFile *f)
+void qemu_savevm_live_state(QEMUFile *f)
{
- SaveStateEntry *se;
+ /* save QEMU_VM_SECTION_END section */
+ qemu_savevm_state_complete_precopy(f, true, false);
+ qemu_put_byte(f, QEMU_VM_EOF);
+}
- qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
- qemu_put_be32(f, QEMU_VM_FILE_VERSION);
+int qemu_save_device_state(QEMUFile *f)
+{
+ SaveStateEntry *se;
+ if (!migration_in_colo_state()) {
+ qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
+ qemu_put_be32(f, QEMU_VM_FILE_VERSION);
+ }
cpu_synchronize_all_states();
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
@@ -1440,8 +1448,6 @@ enum LoadVMExitCodes {
LOADVM_QUIT = 1,
};
-static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
-
/* ------ incoming postcopy messages ------ */
/* 'advise' arrives before any transfers just to tell us that a postcopy
* *might* happen - it might be skipped if precopy transferred everything
@@ -2247,7 +2253,7 @@ static bool
postcopy_pause_incoming(MigrationIncomingState *mis)
return true;
}
-static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis)
+int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis)
{
uint8_t section_type;
int ret = 0;
@@ -2418,6 +2424,22 @@ int qemu_loadvm_state(QEMUFile *f)
return ret;
}
+int qemu_load_device_state(QEMUFile *f)
+{
+ MigrationIncomingState *mis = migration_incoming_get_current();
+ int ret;
+
+ /* Load QEMU_VM_SECTION_FULL section */
+ ret = qemu_loadvm_state_main(f, mis);
+ if (ret < 0) {
+ error_report("Failed to load device state: %d", ret);
+ return ret;
+ }
+
+ cpu_synchronize_all_post_init();
+ return 0;
+}
+
int save_snapshot(const char *name, Error **errp)
{
BlockDriverState *bs, *bs1;
diff --git a/migration/savevm.h b/migration/savevm.h
index 8373c2f..51a4b9c 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -56,8 +56,12 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f,
const char *name,
uint64_t *start_list,
uint64_t *length_list);
void qemu_savevm_send_colo_enable(QEMUFile *f);
+void qemu_savevm_live_state(QEMUFile *f);
+int qemu_save_device_state(QEMUFile *f);
int qemu_loadvm_state(QEMUFile *f);
void qemu_loadvm_state_cleanup(void);
+int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
+int qemu_load_device_state(QEMUFile *f);
#endif
--
2.5.0
- [Qemu-devel] [PULL 08/26] ram/COLO: Record the dirty pages that SVM received, (continued)
- [Qemu-devel] [PULL 08/26] ram/COLO: Record the dirty pages that SVM received, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 11/26] qapi/migration.json: Rename COLO unknown mode to none mode., Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 04/26] COLO: integrate colo compare with colo frame, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 10/26] qmp event: Add COLO_EXIT event to notify users while exited COLO, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 05/26] COLO: Add block replication into colo process, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 14/26] COLO: flush host dirty ram from cache, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 18/26] COLO: quick failover process by kick COLO thread, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 03/26] colo-compare: use notifier to notify packets comparing result, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 15/26] filter: Add handle_event method for NetFilterClass, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 19/26] docs: Add COLO status diagram to COLO-FT.txt, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 13/26] savevm: split the process of different stages for loadvm/savevm,
Jason Wang <=
- [Qemu-devel] [PULL 12/26] qapi: Add new command to query colo status, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 17/26] COLO: notify net filters about checkpoint/failover event, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 07/26] COLO: Load dirty pages into SVM's RAM cache firstly, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 20/26] clean up callback when del virtqueue, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 06/26] COLO: Remove colo_state migration struct, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 22/26] rtl8139: fix possible out of bound access, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 24/26] net: ignore packet size greater than INT_MAX, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 16/26] filter-rewriter: handle checkpoint and failover event, Jason Wang, 2018/10/15
- [Qemu-devel] [PULL 21/26] ne2000: fix possible out of bound access in ne2000_receive, Jason Wang, 2018/10/15