Signed-off-by: Benoit Hudzia <benoit.hud...@sap.com> Signed-off-by: Petter Svard <pett...@cs.umu.se> Signed-off-by: Aidan Shribman <aidan.shrib...@sap.com> Signed-off-by: Orit Wasserman <owass...@redhat.com> --- arch_init.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++- hmp.c | 13 ++++++++++ migration.c | 12 +++++++++ migration.h | 9 +++++++ qapi-schema.json | 27 +++++++++++++++++++-- qmp-commands.hx | 28 ++++++++++++++++++++++ 6 files changed, 153 insertions(+), 4 deletions(-)
diff --git a/arch_init.c b/arch_init.c index 08fe040..fa2ba83 100644 --- a/arch_init.c +++ b/arch_init.c @@ -201,8 +201,66 @@ void xbzrle_cache_resize(int64_t new_size) } } +/* accounting */ +typedef struct AccountingInfo { + uint64_t dup_pages; + uint64_t norm_pages; + uint64_t xbzrle_bytes; + uint64_t xbzrle_pages; + uint64_t xbzrle_cache_miss; + uint64_t iterations; + uint64_t xbzrle_overflows; +} AccountingInfo; + +static AccountingInfo acct_info; + +static void acct_clear(void) +{ + memset(&acct_info, 0, sizeof(acct_info)); +} + +uint64_t dup_mig_bytes_transferred(void) +{ + return acct_info.dup_pages * TARGET_PAGE_SIZE; +} + +uint64_t dup_mig_pages_transferred(void) +{ + return acct_info.dup_pages; +} + +uint64_t norm_mig_bytes_transferred(void) +{ + return acct_info.norm_pages * TARGET_PAGE_SIZE; +} + +uint64_t norm_mig_pages_transferred(void) +{ + return acct_info.norm_pages; +} + +uint64_t xbzrle_mig_bytes_transferred(void) +{ + return acct_info.xbzrle_bytes; +} + +uint64_t xbzrle_mig_pages_transferred(void) +{ + return acct_info.xbzrle_pages; +} + +uint64_t xbzrle_mig_pages_cache_miss(void) +{ + return acct_info.xbzrle_cache_miss; +} + +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) + int cont, int flag) { qemu_put_be64(f, offset | cont | flag); if (!cont) { @@ -233,6 +291,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, if (stage == 1 || !cache_is_cached(XBZRLE.cache, current_addr)) { cache_insert(XBZRLE.cache, current_addr, g_memdup(current_data, TARGET_PAGE_SIZE)); + acct_info.xbzrle_cache_miss++; return -1; } @@ -247,6 +306,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, return 0; } else if (encoded_len == -1) { DPRINTF("Overflow\n"); + acct_info.xbzrle_overflows++; /* update data in the cache */ memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE); return -1; @@ -266,7 +326,9 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, qemu_put_byte(f, hdr.xh_flags); qemu_put_be16(f, hdr.xh_len); qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len); + acct_info.xbzrle_pages++; bytes_sent = encoded_len + sizeof(hdr); + acct_info.xbzrle_bytes += bytes_sent; return bytes_sent; } @@ -300,6 +362,7 @@ static int ram_save_block(QEMUFile *f, int stage) p = memory_region_get_ram_ptr(mr) + offset; if (is_dup_page(p)) { + acct_info.dup_pages++; save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(f, *p); bytes_sent = 1; @@ -321,6 +384,7 @@ static int ram_save_block(QEMUFile *f, int stage) save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); qemu_put_buffer(f, p, TARGET_PAGE_SIZE); bytes_sent = TARGET_PAGE_SIZE; + acct_info.norm_pages++; } /* if page is unmodified lets continue to the next */ @@ -457,6 +521,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque) return -1; } XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE); + acct_clear(); } /* Make sure all dirty bits are set */ @@ -491,6 +556,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque) bytes_sent -1 represent no more blocks*/ if (bytes_sent > 0) { bytes_transferred += bytes_sent; + acct_info.iterations++; } else if (bytes_sent == -1) { /* no more blocks */ break; } diff --git a/hmp.c b/hmp.c index 38f9067..13e032e 100644 --- a/hmp.c +++ b/hmp.c @@ -164,6 +164,19 @@ void hmp_info_migrate(Monitor *mon) info->disk->total >> 10); } + if (info->has_cache) { + monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", + info->cache->cache_size); + monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", + info->cache->xbzrle_bytes >> 10); + monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", + info->cache->xbzrle_pages); + monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", + info->cache->xbzrle_cache_miss); + monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", + info->cache->xbzrle_overflow); + } + qapi_free_MigrationInfo(info); } diff --git a/migration.c b/migration.c index 16d47c0..fe9556d 100644 --- a/migration.c +++ b/migration.c @@ -148,6 +148,8 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->ram->transferred = ram_bytes_transferred(); info->ram->remaining = ram_bytes_remaining(); info->ram->total = ram_bytes_total(); + info->ram->duplicate = dup_mig_pages_transferred(); + info->ram->norm = norm_mig_pages_transferred(); if (blk_mig_active()) { info->has_disk = true; @@ -156,6 +158,16 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->disk->remaining = blk_mig_bytes_remaining(); info->disk->total = blk_mig_bytes_total(); } + + if (migrate_use_xbzrle()) { + info->has_cache = true; + info->cache = g_malloc0(sizeof(*info->cache)); + info->cache->cache_size = migrate_xbzrle_cache_size(); + info->cache->xbzrle_bytes = xbzrle_mig_bytes_transferred(); + info->cache->xbzrle_pages = xbzrle_mig_pages_transferred(); + info->cache->xbzrle_cache_miss = xbzrle_mig_pages_cache_miss(); + info->cache->xbzrle_overflow = xbzrle_mig_pages_overflow(); + } break; case MIG_STATE_COMPLETED: info->has_status = true; diff --git a/migration.h b/migration.h index cc7b433..7443fe5 100644 --- a/migration.h +++ b/migration.h @@ -83,6 +83,15 @@ uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_transferred(void); uint64_t ram_bytes_total(void); +uint64_t dup_mig_bytes_transferred(void); +uint64_t dup_mig_pages_transferred(void); +uint64_t norm_mig_bytes_transferred(void); +uint64_t norm_mig_pages_transferred(void); +uint64_t xbzrle_mig_bytes_transferred(void); +uint64_t xbzrle_mig_pages_transferred(void); +uint64_t xbzrle_mig_pages_overflow(void); +uint64_t xbzrle_mig_pages_cache_miss(void); + int ram_save_live(QEMUFile *f, int stage, void *opaque); int ram_load(QEMUFile *f, void *opaque, int version_id); diff --git a/qapi-schema.json b/qapi-schema.json index ca12542..75eb62e 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -263,7 +263,28 @@ # Since: 0.14.0. ## { 'type': 'MigrationStats', - 'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' } } + 'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int', 'duplicate': 'int', 'norm': 'int' } } + +## +# @CacheStats +# +# Detailed XBZRLE migration cache statistics +# +# @cache_size: XBZRLE cache size +# +# @xbzrle_bytes: amount of bytes already transferred to the target VM +# +# @xbzrle_pages: amount of pages transferred to the target VM +# +# @xbzrle_cache_miss: numer of cache miss +# +# @xbzrle_overflow: number of overflows +# +# Since: 1.1 +## +{ 'type': 'CacheStats', + 'data': {'cache_size': 'int', 'xbzrle_bytes': 'int', 'xbzrle_pages': 'int', + 'xbzrle_cache_miss': 'int', 'xbzrle_overflow': 'int' } } ## # @MigrationInfo @@ -286,8 +307,8 @@ ## { 'type': 'MigrationInfo', 'data': {'*status': 'str', '*ram': 'MigrationStats', - '*disk': 'MigrationStats', '*params': ['MigrationCapabilityInfo']} } - + '*disk': 'MigrationStats', '*params': ['MigrationCapabilityInfo'], + '*cache': 'CacheStats'} } ## # @query-migrate # diff --git a/qmp-commands.hx b/qmp-commands.hx index 7a10d4f..008be78 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2098,6 +2098,13 @@ The main json-object contains the following: - "transferred": amount transferred (json-int) - "remaining": amount remaining (json-int) - "total": total (json-int) +- "cache": only present if "status" and XBZRLE is active. + it is a json-object with the following XBZRLE information: + - "cache size": XBZRLE cache size + - "xbzrle_bytes": total XBZRLE bytes transferred + - "xbzrle_pages": number of XBZRLE compressed pages + - "cache_miss": number of cache misses + - "overflow": number of XBZRLE overflows Examples: @@ -2149,6 +2156,27 @@ Examples: } } +5. Migration is being performed and XBZRLE is active: + +-> { "execute": "query-migrate" } +<- { + "return":{ + "status":"active", + "ram":{ + "total":1057024, + "remaining":1053304, + "transferred":3720 + }, + "cache":{ + "size": 1024 + "xbzrle_transferred":20971520, + "xbzrle_pages":2444343, + "xbzrle_cache_miss:2244, + "xbzrle_overflow":34434 + } + } + } + EQMP { -- 1.7.7.6