2 ===================================================================
3 --- new.orig/arch_init.c 2012-02-09 13:15:26.000000000 +0100
4 +++ new/arch_init.c 2012-02-09 13:22:53.000000000 +0100
6 uint64_t bytes_transferred_last;
8 uint64_t expected_time = 0;
9 + static int64_t starttime = 0;
15 qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
16 qemu_put_be64(f, block->length);
19 + starttime = qemu_get_clock_ns(rt_clock);
22 - bytes_transferred_last = bytes_transferred;
23 - bwidth = qemu_get_clock_ns(rt_clock);
25 while ((ret = qemu_file_rate_limit(f)) == 0) {
31 - bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
32 - bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
33 + timediff = qemu_get_clock_ns(rt_clock) - starttime;
34 + bwidth = bytes_transferred / timediff;
36 /* if we haven't transferred anything this round, force expected_time to a
37 * a very high value, but without crashing */
40 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
42 + if ((stage == 2) && (bytes_transferred > 2*ram_bytes_total())) {
46 expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
48 return (stage == 2) && (expected_time <= migrate_max_downtime());