[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 32/34] ram: refactor ram_save_block() return value
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 32/34] ram: refactor ram_save_block() return value |
Date: |
Wed, 19 Dec 2012 13:33:55 +0100 |
It could only return 0 if we only found dirty xbzrle pages that hadn't
changed (i.e. they were written with the same content). We don't care
about that case, it is the same than nothing dirty.
So now the return of the function is how much have it written, nothing
else. Adjust callers.
And we also made ram_save_iterate() return the number of transferred
bytes, not the number of transferred pages.
Signed-off-by: Juan Quintela <address@hidden>
---
arch_init.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 43a5b9e..588561b 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -422,9 +422,8 @@ static void migration_bitmap_sync(void)
/*
* ram_save_block: Writes a page of memory to the stream f
*
- * Returns: 0: if the page hasn't changed
- * -1: if there are no more dirty pages
- * n: the amount of bytes written in other case
+ * Returns: The number of bytes written.
+ * 0 means no dirty pages
*/
static int ram_save_block(QEMUFile *f, bool last_stage)
@@ -432,7 +431,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
RAMBlock *block = last_seen_block;
ram_addr_t offset = last_offset;
bool complete_round = false;
- int bytes_sent = -1;
+ int bytes_sent = 0;
MemoryRegion *mr;
ram_addr_t current_addr;
@@ -460,6 +459,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
p = memory_region_get_ram_ptr(mr) + offset;
+ /* In doubt sent page as normal */
+ bytes_sent = -1;
if (is_dup_page(p)) {
acct_info.dup_pages++;
bytes_sent = save_block_hdr(f, block, offset, cont,
@@ -475,7 +476,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
}
}
- /* either we didn't send yet (we may have had XBZRLE overflow) */
+ /* XBZRLE overflow or normal page */
if (bytes_sent == -1) {
bytes_sent = save_block_hdr(f, block, offset, cont,
RAM_SAVE_FLAG_PAGE);
qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
@@ -484,7 +485,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
}
/* if page is unmodified, continue to the next */
- if (bytes_sent != 0) {
+ if (bytes_sent > 0) {
last_sent_block = block;
break;
}
@@ -605,6 +606,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
int ret;
int i;
int64_t t0;
+ int total_sent = 0;
qemu_mutex_lock_ramlist();
@@ -619,10 +621,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
bytes_sent = ram_save_block(f, false);
/* no more blocks to sent */
- if (bytes_sent < 0) {
+ if (bytes_sent == 0) {
break;
}
- bytes_transferred += bytes_sent;
+ total_sent += bytes_sent;
acct_info.iterations++;
/* we want to check in the 1st loop, just in case it was the 1st time
and we had to sync the dirty bitmap.
@@ -641,13 +643,16 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
}
if (ret < 0) {
+ bytes_transferred += total_sent;
return ret;
}
qemu_mutex_unlock_ramlist();
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+ total_sent += 8;
+ bytes_transferred += total_sent;
- return i;
+ return total_sent;
}
static int ram_save_complete(QEMUFile *f, void *opaque)
@@ -664,7 +669,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
bytes_sent = ram_save_block(f, true);
/* no more blocks to sent */
- if (bytes_sent < 0) {
+ if (bytes_sent == 0) {
break;
}
bytes_transferred += bytes_sent;
--
1.7.11.7
- [Qemu-devel] [PATCH 26/34] ram: rename last_block to last_seen_block, (continued)
- [Qemu-devel] [PATCH 26/34] ram: rename last_block to last_seen_block, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 19/34] buffered_file: unfold buffered_append in buffered_put_buffer, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 12/34] migration: make qemu_fopen_ops_buffered() return void, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 20/34] savevm: New save live migration method: pending, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 23/34] migration: move migration_fd_put_ready(), Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 21/34] migration: move buffered_file.c code into migration.c, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 24/34] migration: Inline qemu_fopen_ops_buffered into migrate_fd_connect, Juan Quintela, 2012/12/19
- Re: [Qemu-devel] [PATCH 00/34] migration thread and queue, Paolo Bonzini, 2012/12/19
- [Qemu-devel] [PATCH 27/34] ram: Add last_sent_block, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 31/34] ram: account the amount of transferred ram better, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 32/34] ram: refactor ram_save_block() return value,
Juan Quintela <=
- [Qemu-devel] [PATCH 33/34] migration: fix qemu_get_fd for BufferedFile, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 29/34] ram: Use memory_region_test_and_clear_dirty, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 34/34] migration: merge QEMUFileBuffered into MigrationState, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 30/34] ram: optimize migration bitmap walking, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 25/34] migration: move migration notifier, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 28/34] memory: introduce memory_region_test_and_clear_dirty, Juan Quintela, 2012/12/19