[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 30/36] Init the XBZRLE.lock in ram_mig_init
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 30/36] Init the XBZRLE.lock in ram_mig_init |
Date: |
Mon, 5 May 2014 22:30:28 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
Initialising the XBZRLE.lock earlier simplifies the lock use.
Based on Markus's patch in:
http://lists.gnu.org/archive/html/qemu-devel/2014-03/msg03879.html
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Gonglei <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
arch_init.c | 61 +++++++++++++++++++++++++++++++------------------------------
1 file changed, 31 insertions(+), 30 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index aeebb8e..5e20228 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -45,6 +45,7 @@
#include "hw/audio/pcspk.h"
#include "migration/page_cache.h"
#include "qemu/config-file.h"
+#include "qemu/error-report.h"
#include "qmp-commands.h"
#include "trace.h"
#include "exec/cpu-all.h"
@@ -167,11 +168,8 @@ static struct {
/* Cache for XBZRLE, Protected by lock. */
PageCache *cache;
QemuMutex lock;
-} XBZRLE = {
- .encoded_buf = NULL,
- .current_buf = NULL,
- .cache = NULL,
-};
+} XBZRLE;
+
/* buffer used for XBZRLE decoding */
static uint8_t *xbzrle_decoded_buf;
@@ -187,41 +185,44 @@ static void XBZRLE_cache_unlock(void)
qemu_mutex_unlock(&XBZRLE.lock);
}
+/*
+ * called from qmp_migrate_set_cache_size in main thread, possibly while
+ * a migration is in progress.
+ * A running migration maybe using the cache and might finish during this
+ * call, hence changes to the cache are protected by XBZRLE.lock().
+ */
int64_t xbzrle_cache_resize(int64_t new_size)
{
- PageCache *new_cache, *cache_to_free;
+ PageCache *new_cache;
+ int64_t ret;
if (new_size < TARGET_PAGE_SIZE) {
return -1;
}
- /* no need to lock, the current thread holds qemu big lock */
+ XBZRLE_cache_lock();
+
if (XBZRLE.cache != NULL) {
- /* check XBZRLE.cache again later */
if (pow2floor(new_size) == migrate_xbzrle_cache_size()) {
- return pow2floor(new_size);
+ goto out_new_size;
}
new_cache = cache_init(new_size / TARGET_PAGE_SIZE,
TARGET_PAGE_SIZE);
if (!new_cache) {
- DPRINTF("Error creating cache\n");
- return -1;
- }
-
- XBZRLE_cache_lock();
- /* the XBZRLE.cache may have be destroyed, check it again */
- if (XBZRLE.cache != NULL) {
- cache_to_free = XBZRLE.cache;
- XBZRLE.cache = new_cache;
- } else {
- cache_to_free = new_cache;
+ error_report("Error creating cache");
+ ret = -1;
+ goto out;
}
- XBZRLE_cache_unlock();
- cache_fini(cache_to_free);
+ cache_fini(XBZRLE.cache);
+ XBZRLE.cache = new_cache;
}
- return pow2floor(new_size);
+out_new_size:
+ ret = pow2floor(new_size);
+out:
+ XBZRLE_cache_unlock();
+ return ret;
}
/* accounting for migration statistics */
@@ -732,28 +733,27 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
dirty_rate_high_cnt = 0;
if (migrate_use_xbzrle()) {
- qemu_mutex_lock_iothread();
+ XBZRLE_cache_lock();
XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
TARGET_PAGE_SIZE,
TARGET_PAGE_SIZE);
if (!XBZRLE.cache) {
- qemu_mutex_unlock_iothread();
- DPRINTF("Error creating cache\n");
+ XBZRLE_cache_unlock();
+ error_report("Error creating cache");
return -1;
}
- qemu_mutex_init(&XBZRLE.lock);
- qemu_mutex_unlock_iothread();
+ XBZRLE_cache_unlock();
/* We prefer not to abort if there is no memory */
XBZRLE.encoded_buf = g_try_malloc0(TARGET_PAGE_SIZE);
if (!XBZRLE.encoded_buf) {
- DPRINTF("Error allocating encoded_buf\n");
+ error_report("Error allocating encoded_buf");
return -1;
}
XBZRLE.current_buf = g_try_malloc(TARGET_PAGE_SIZE);
if (!XBZRLE.current_buf) {
- DPRINTF("Error allocating current_buf\n");
+ error_report("Error allocating current_buf");
g_free(XBZRLE.encoded_buf);
XBZRLE.encoded_buf = NULL;
return -1;
@@ -1119,6 +1119,7 @@ static SaveVMHandlers savevm_ram_handlers = {
void ram_mig_init(void)
{
+ qemu_mutex_init(&XBZRLE.lock);
register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
}
--
1.9.0
- [Qemu-devel] [PATCH 17/36] zaurus: fix buffer overrun on invalid state load, (continued)
- [Qemu-devel] [PATCH 17/36] zaurus: fix buffer overrun on invalid state load, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 21/36] savevm: Ignore minimum_version_id_old if there is no load_state_old, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 22/36] ssi-sd: fix buffer overrun on invalid state load, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 19/36] vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 23/36] openpic: avoid buffer overrun on incoming migration, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 20/36] usb: sanity check setup_index+setup_len in post_load, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 24/36] virtio-net: out-of-bounds buffer write on load, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 27/36] Make qemu_peek_buffer loop until it gets it's data, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 26/36] Disallow outward migration while awaiting incoming migration, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 25/36] virtio: validate config_len on load, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 30/36] Init the XBZRLE.lock in ram_mig_init,
Juan Quintela <=
- [Qemu-devel] [PATCH 28/36] Count used RAMBlock pages for migration_dirty_pages, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 29/36] Provide init function for ram migration, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 31/36] Coverity: Fix failure path for qemu_accept in migration, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 32/36] migration: remove duplicate code, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 33/36] XBZRLE: Fix one XBZRLE corruption issues, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 34/36] migration: Add counts of updating the dirty bitmap, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 35/36] migration: expose the bitmap_sync_count to the end, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 36/36] migration: expose xbzrle cache miss rate, Juan Quintela, 2014/05/05
- [Qemu-devel] [PATCH 02/36] vmstate: add VMS_MUST_EXIST, Juan Quintela, 2014/05/05
- Re: [Qemu-devel] [PULL 00/36] migration queue, Peter Maydell, 2014/05/07