|
|
9ae3a8 |
From 7b47ae208675e0da813f9f46838d9a8935c68a02 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 8 May 2014 10:58:41 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 06/31] Init the XBZRLE.lock in ram_mig_init
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1399546722-6350-4-git-send-email-dgilbert@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 58743
|
|
|
9ae3a8 |
O-Subject: [RHEL7.1/RHEL7.0.z qemu-kvm PATCH 3/4] Init the XBZRLE.lock in ram_mig_init
|
|
|
9ae3a8 |
Bugzilla: 1066338
|
|
|
9ae3a8 |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Initialising the XBZRLE.lock earlier simplifies the lock use.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Based on Markus's patch in:
|
|
|
9ae3a8 |
http://lists.gnu.org/archive/html/qemu-devel/2014-03/msg03879.html
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
|
|
|
9ae3a8 |
Reviewed-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit d97326eec2ca1313eaf0b5cffd69af5663b5af5d)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
arch_init.c | 61 +++++++++++++++++++++++++++++++------------------------------
|
|
|
9ae3a8 |
1 file changed, 31 insertions(+), 30 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
arch_init.c | 61 ++++++++++++++++++++++++++++++-----------------------------
|
|
|
9ae3a8 |
1 files changed, 31 insertions(+), 30 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/arch_init.c b/arch_init.c
|
|
|
9ae3a8 |
index 37c9f6d..80e48f2 100644
|
|
|
9ae3a8 |
--- a/arch_init.c
|
|
|
9ae3a8 |
+++ b/arch_init.c
|
|
|
9ae3a8 |
@@ -45,6 +45,7 @@
|
|
|
9ae3a8 |
#include "hw/audio/pcspk.h"
|
|
|
9ae3a8 |
#include "migration/page_cache.h"
|
|
|
9ae3a8 |
#include "qemu/config-file.h"
|
|
|
9ae3a8 |
+#include "qemu/error-report.h"
|
|
|
9ae3a8 |
#include "qmp-commands.h"
|
|
|
9ae3a8 |
#include "trace.h"
|
|
|
9ae3a8 |
#include "exec/cpu-all.h"
|
|
|
9ae3a8 |
@@ -167,11 +168,8 @@ static struct {
|
|
|
9ae3a8 |
/* Cache for XBZRLE, Protected by lock. */
|
|
|
9ae3a8 |
PageCache *cache;
|
|
|
9ae3a8 |
QemuMutex lock;
|
|
|
9ae3a8 |
-} XBZRLE = {
|
|
|
9ae3a8 |
- .encoded_buf = NULL,
|
|
|
9ae3a8 |
- .current_buf = NULL,
|
|
|
9ae3a8 |
- .cache = NULL,
|
|
|
9ae3a8 |
-};
|
|
|
9ae3a8 |
+} XBZRLE;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
/* buffer used for XBZRLE decoding */
|
|
|
9ae3a8 |
static uint8_t *xbzrle_decoded_buf;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -187,41 +185,44 @@ static void XBZRLE_cache_unlock(void)
|
|
|
9ae3a8 |
qemu_mutex_unlock(&XBZRLE.lock);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * called from qmp_migrate_set_cache_size in main thread, possibly while
|
|
|
9ae3a8 |
+ * a migration is in progress.
|
|
|
9ae3a8 |
+ * A running migration maybe using the cache and might finish during this
|
|
|
9ae3a8 |
+ * call, hence changes to the cache are protected by XBZRLE.lock().
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
int64_t xbzrle_cache_resize(int64_t new_size)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- PageCache *new_cache, *cache_to_free;
|
|
|
9ae3a8 |
+ PageCache *new_cache;
|
|
|
9ae3a8 |
+ int64_t ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (new_size < TARGET_PAGE_SIZE) {
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* no need to lock, the current thread holds qemu big lock */
|
|
|
9ae3a8 |
+ XBZRLE_cache_lock();
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (XBZRLE.cache != NULL) {
|
|
|
9ae3a8 |
- /* check XBZRLE.cache again later */
|
|
|
9ae3a8 |
if (pow2floor(new_size) == migrate_xbzrle_cache_size()) {
|
|
|
9ae3a8 |
- return pow2floor(new_size);
|
|
|
9ae3a8 |
+ goto out_new_size;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
new_cache = cache_init(new_size / TARGET_PAGE_SIZE,
|
|
|
9ae3a8 |
TARGET_PAGE_SIZE);
|
|
|
9ae3a8 |
if (!new_cache) {
|
|
|
9ae3a8 |
- DPRINTF("Error creating cache\n");
|
|
|
9ae3a8 |
- return -1;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- XBZRLE_cache_lock();
|
|
|
9ae3a8 |
- /* the XBZRLE.cache may have be destroyed, check it again */
|
|
|
9ae3a8 |
- if (XBZRLE.cache != NULL) {
|
|
|
9ae3a8 |
- cache_to_free = XBZRLE.cache;
|
|
|
9ae3a8 |
- XBZRLE.cache = new_cache;
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- cache_to_free = new_cache;
|
|
|
9ae3a8 |
+ error_report("Error creating cache");
|
|
|
9ae3a8 |
+ ret = -1;
|
|
|
9ae3a8 |
+ goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- XBZRLE_cache_unlock();
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- cache_fini(cache_to_free);
|
|
|
9ae3a8 |
+ cache_fini(XBZRLE.cache);
|
|
|
9ae3a8 |
+ XBZRLE.cache = new_cache;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- return pow2floor(new_size);
|
|
|
9ae3a8 |
+out_new_size:
|
|
|
9ae3a8 |
+ ret = pow2floor(new_size);
|
|
|
9ae3a8 |
+out:
|
|
|
9ae3a8 |
+ XBZRLE_cache_unlock();
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* accounting for migration statistics */
|
|
|
9ae3a8 |
@@ -735,28 +736,27 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
|
|
|
9ae3a8 |
dirty_rate_high_cnt = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (migrate_use_xbzrle()) {
|
|
|
9ae3a8 |
- qemu_mutex_lock_iothread();
|
|
|
9ae3a8 |
+ XBZRLE_cache_lock();
|
|
|
9ae3a8 |
XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
|
|
|
9ae3a8 |
TARGET_PAGE_SIZE,
|
|
|
9ae3a8 |
TARGET_PAGE_SIZE);
|
|
|
9ae3a8 |
if (!XBZRLE.cache) {
|
|
|
9ae3a8 |
- qemu_mutex_unlock_iothread();
|
|
|
9ae3a8 |
- DPRINTF("Error creating cache\n");
|
|
|
9ae3a8 |
+ XBZRLE_cache_unlock();
|
|
|
9ae3a8 |
+ error_report("Error creating cache");
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- qemu_mutex_init(&XBZRLE.lock);
|
|
|
9ae3a8 |
- qemu_mutex_unlock_iothread();
|
|
|
9ae3a8 |
+ XBZRLE_cache_unlock();
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* We prefer not to abort if there is no memory */
|
|
|
9ae3a8 |
XBZRLE.encoded_buf = g_try_malloc0(TARGET_PAGE_SIZE);
|
|
|
9ae3a8 |
if (!XBZRLE.encoded_buf) {
|
|
|
9ae3a8 |
- DPRINTF("Error allocating encoded_buf\n");
|
|
|
9ae3a8 |
+ error_report("Error allocating encoded_buf");
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
XBZRLE.current_buf = g_try_malloc(TARGET_PAGE_SIZE);
|
|
|
9ae3a8 |
if (!XBZRLE.current_buf) {
|
|
|
9ae3a8 |
- DPRINTF("Error allocating current_buf\n");
|
|
|
9ae3a8 |
+ error_report("Error allocating current_buf");
|
|
|
9ae3a8 |
g_free(XBZRLE.encoded_buf);
|
|
|
9ae3a8 |
XBZRLE.encoded_buf = NULL;
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
@@ -1110,6 +1110,7 @@ static SaveVMHandlers savevm_ram_handlers = {
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
void ram_mig_init(void)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
+ qemu_mutex_init(&XBZRLE.lock);
|
|
|
9ae3a8 |
register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|