aboutsummaryrefslogtreecommitdiff
path: root/arch_init.c
diff options
context:
space:
mode:
authorJuan Quintela <quintela@redhat.com>2012-10-18 13:56:35 +0200
committerJuan Quintela <quintela@redhat.com>2012-12-20 23:09:40 +0100
commit3f7d7b098194ec893efa037491f6231687ff043a (patch)
tree2e42dcc90a46d18ebc419bdb75a60d198ae2f0d5 /arch_init.c
parent4c8ae0f60e63478aea0a1741cca95474b68fb949 (diff)
ram: account the amount of transferred ram better
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'arch_init.c')
-rw-r--r--arch_init.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/arch_init.c b/arch_init.c
index 74dc9c8c51..4015bfd8c5 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -265,16 +265,21 @@ uint64_t xbzrle_mig_pages_overflow(void)
return acct_info.xbzrle_overflows;
}
-static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
- int cont, int flag)
+static size_t save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
+ int cont, int flag)
{
- qemu_put_be64(f, offset | cont | flag);
- if (!cont) {
- qemu_put_byte(f, strlen(block->idstr));
- qemu_put_buffer(f, (uint8_t *)block->idstr,
- strlen(block->idstr));
- }
+ size_t size;
+
+ qemu_put_be64(f, offset | cont | flag);
+ size = 8;
+ if (!cont) {
+ qemu_put_byte(f, strlen(block->idstr));
+ qemu_put_buffer(f, (uint8_t *)block->idstr,
+ strlen(block->idstr));
+ size += 1 + strlen(block->idstr);
+ }
+ return size;
}
#define ENCODING_FLAG_XBZRLE 0x1
@@ -321,11 +326,11 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
}
/* Send XBZRLE based compressed page */
- save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
+ bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
qemu_put_be16(f, encoded_len);
qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
- bytes_sent = encoded_len + 1 + 2;
+ bytes_sent += encoded_len + 1 + 2;
acct_info.xbzrle_pages++;
acct_info.xbzrle_bytes += bytes_sent;
@@ -457,9 +462,10 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
if (is_dup_page(p)) {
acct_info.dup_pages++;
- save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
+ bytes_sent = save_block_hdr(f, block, offset, cont,
+ RAM_SAVE_FLAG_COMPRESS);
qemu_put_byte(f, *p);
- bytes_sent = 1;
+ bytes_sent += 1;
} else if (migrate_use_xbzrle()) {
current_addr = block->offset + offset;
bytes_sent = save_xbzrle_page(f, p, current_addr, block,
@@ -471,9 +477,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
/* either we didn't send yet (we may have had XBZRLE overflow) */
if (bytes_sent == -1) {
- save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
+ bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
- bytes_sent = TARGET_PAGE_SIZE;
+ bytes_sent += TARGET_PAGE_SIZE;
acct_info.norm_pages++;
}