Patchwork [21/22] Add XBZRLE statistics

login
register
mail settings
Submitter Juan Quintela
Date July 13, 2012, 7:23 a.m.
Message ID <1342164224-32709-22-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/170811/
State New
Headers show

Comments

Juan Quintela - July 13, 2012, 7:23 a.m.
From: Orit Wasserman <owasserm@redhat.com>

Signed-off-by: Benoit Hudzia <benoit.hudzia@sap.com>
Signed-off-by: Petter Svard <petters@cs.umu.se>
Signed-off-by: Aidan Shribman <aidan.shribman@sap.com>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.c            |   13 +++++++++++
 migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
 migration.h      |    9 ++++++++
 qapi-schema.json |   37 +++++++++++++++++++++++++-----
 qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
 6 files changed, 203 insertions(+), 6 deletions(-)
Luiz Capitulino - July 23, 2012, 7:33 p.m.
On Fri, 13 Jul 2012 09:23:43 +0200
Juan Quintela <quintela@redhat.com> wrote:

> From: Orit Wasserman <owasserm@redhat.com>
> 
> Signed-off-by: Benoit Hudzia <benoit.hudzia@sap.com>
> Signed-off-by: Petter Svard <petters@cs.umu.se>
> Signed-off-by: Aidan Shribman <aidan.shribman@sap.com>
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hmp.c            |   13 +++++++++++
>  migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
>  migration.h      |    9 ++++++++
>  qapi-schema.json |   37 +++++++++++++++++++++++++-----
>  qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
>  6 files changed, 203 insertions(+), 6 deletions(-)
> 
> diff --git a/arch_init.c b/arch_init.c
> index d972d84..ab3fb2c 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -202,6 +202,64 @@ int64_t xbzrle_cache_resize(int64_t new_size)
>      return pow2floor(new_size);
>  }
> 
> +/* accounting for migration statistics */
> +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)
>  {
> @@ -230,6 +288,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
>      if (!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;
>      }
> 
> @@ -244,6 +303,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;
> @@ -263,7 +323,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;
>  }
> @@ -303,6 +365,7 @@ static int ram_save_block(QEMUFile *f)
>              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;
> @@ -318,6 +381,7 @@ static int ram_save_block(QEMUFile *f)
>                  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, continue to the next */
> @@ -437,6 +501,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
>              return -1;
>          }
>          XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
> +        acct_clear();
>      }
> 
>      QLIST_FOREACH(block, &ram_list.blocks, next) {
> @@ -484,6 +549,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>              break;
>          }
>          bytes_transferred += 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.
>             qemu_get_clock_ns() is a bit expensive, so we only check each some
> diff --git a/hmp.c b/hmp.c
> index 99ad00a..0d7333b 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -168,6 +168,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 d134bf6..e11f451 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -137,6 +137,17 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>              info->capabilities->value->state = s->enabled_capabilities[i];
>              info->capabilities->next = NULL;
>          }
> +
> +        /* display xbzrle cache size */
> +        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();
> +        }

Why do you need this in MIG_STATE_SETUP? I think having it only in
MIG_STATE_ACTIVE is enough (and probably that's what we want).

>          break;
>      case MIG_STATE_ACTIVE:
>          for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
> @@ -161,6 +172,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>          info->ram->total = ram_bytes_total();
>          info->ram->total_time = qemu_get_clock_ms(rt_clock)
>              - s->total_time;
> +        info->ram->duplicate = dup_mig_pages_transferred();
> +        info->ram->normal = norm_mig_pages_transferred();

Can we do this extension in a different patch?

> 
>          if (blk_mig_active()) {
>              info->has_disk = true;
> @@ -169,6 +182,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:
>          for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
> @@ -183,6 +206,32 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>              info->capabilities->next = NULL;
>          }
> 
> +        info->has_ram = true;
> +        info->ram = g_malloc0(sizeof(*info->ram));
> +        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->normal = norm_mig_pages_transferred();

This hunk is probably bad copy & paste, as this code already exists.

> +
> +        if (blk_mig_active()) {
> +            info->has_disk = true;
> +            info->disk = g_malloc0(sizeof(*info->disk));
> +            info->disk->transferred = blk_mig_bytes_transferred();
> +            info->disk->remaining = blk_mig_bytes_remaining();
> +            info->disk->total = blk_mig_bytes_total();
> +        }

Why are you doing this, bad copy & paste too?

> +
> +        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();
> +        }
> +
>          info->has_status = true;
>          info->status = g_strdup("completed");
> 
> diff --git a/migration.h b/migration.h
> index 337e225..a9852fc 100644
> --- a/migration.h
> +++ b/migration.h
> @@ -87,6 +87,15 @@ uint64_t ram_bytes_total(void);
> 
>  extern SaveVMHandlers savevm_ram_handlers;
> 
> +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);
> +
>  /**
>   * @migrate_add_blocker - prevent migration from proceeding
>   *
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a0f0f95..961810b 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -264,11 +264,35 @@
>  #        migration has ended, it returns the total migration
>  #        time. (since 1.2)
>  #
> -# Since: 0.14.0.
> +# @duplicate: #optional, number of duplicate pages
> +#
> +# @normal : #optional, number of normal pages
> +#
> +# Since: 0.14.0, 'duplicate' and 'normal' since 1.2

Please, put 'since' in the same line of the field, like this:

 @normal : #optional, number of normal pages (since 1.2)

>  ##
>  { 'type': 'MigrationStats',
>    'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
> -           'total_time': 'int' } }
> +           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
> +##
> +# @CacheStats

This is specific to xbzrle, right? So this should be called XBZRLECacheStats,
or something.

> +#
> +# 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: number of cache miss
> +#
> +# @xbzrle_overflow: number of overflows
> +#
> +# Since: 1.2
> +##
> +{ 'type': 'CacheStats',
> +  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
> +           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
> 
>  ##
>  # @MigrationInfo
> @@ -291,13 +315,16 @@
>  # @capabilities: #optional a list describing all the migration capabilities
>  #                state
>  #
> -# Since: 0.14.0, 'capabilities' since 1.2
> +# @cache: #optional @MigrationStats containing detailed XBZRLE migration
> +#         statistics

xbzrle-cache.

> +#
> +# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
>  ##
>  { 'type': 'MigrationInfo',
>    'data': {'*status': 'str', '*ram': 'MigrationStats',
>             '*disk': 'MigrationStats',
> -           '*capabilities': ['MigrationCapabilityInfo']} }
> -
> +           '*capabilities': ['MigrationCapabilityInfo'],
> +           '*cache': 'CacheStats'} }
>  ##
>  # @query-migrate
>  #
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index a3d57ce..34d4675 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -2093,6 +2093,8 @@ The main json-object contains the following:
>           - "transferred": amount transferred (json-int)
>           - "remaining": amount remaining (json-int)
>           - "total": total (json-int)
> +	 - "duplicate": number of duplicated pages (json-int)
> +	 - "normal" : number of normal pages transferred (json-int)
>  - "disk": only present if "status" is "active" and it is a block migration,
>    it is a json-object with the following disk information (in bytes):
>           - "transferred": amount transferred (json-int)
> @@ -2100,10 +2102,17 @@ The main json-object contains the following:
>           - "total": total (json-int)
>  - "capabilities": migration capabilities state
>           - "xbzrle" : XBZRLE state (json-bool)
> +- "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:
> 
>  1. Before the first migration
> -
>  -> { "execute": "query-migrate" }
>  <- { "return": {
>          "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
> @@ -2164,6 +2173,30 @@ Examples:
>        }
>     }
> 
> +6. Migration is being performed and XBZRLE is active:
> +
> +-> { "execute": "query-migrate" }
> +<- {
> +      "return":{
> +         "status":"active",
> +         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
> +         "ram":{
> +            "total":1057024,
> +            "remaining":1053304,
> +            "transferred":3720,
> +            "duplicate": 10,
> +            "normal" : 3333
> +         },
> +         "cache":{
> +            "cache-size": 1024
> +            "xbzrle-transferred":20971520,
> +            "xbzrle-pages":2444343,
> +            "xbzrle-cache-miss":2244,
> +            "xbzrle-overflow":34434
> +         }
> +      }
> +   }
> +
>  EQMP
> 
>      {
Orit Wasserman - July 24, 2012, 6:32 a.m.
On 07/23/2012 10:33 PM, Luiz Capitulino wrote:
> On Fri, 13 Jul 2012 09:23:43 +0200
> Juan Quintela <quintela@redhat.com> wrote:
> 
>> From: Orit Wasserman <owasserm@redhat.com>
>>
>> Signed-off-by: Benoit Hudzia <benoit.hudzia@sap.com>
>> Signed-off-by: Petter Svard <petters@cs.umu.se>
>> Signed-off-by: Aidan Shribman <aidan.shribman@sap.com>
>> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  arch_init.c      |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  hmp.c            |   13 +++++++++++
>>  migration.c      |   49 ++++++++++++++++++++++++++++++++++++++++
>>  migration.h      |    9 ++++++++
>>  qapi-schema.json |   37 +++++++++++++++++++++++++-----
>>  qmp-commands.hx  |   35 ++++++++++++++++++++++++++++-
>>  6 files changed, 203 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index d972d84..ab3fb2c 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -202,6 +202,64 @@ int64_t xbzrle_cache_resize(int64_t new_size)
>>      return pow2floor(new_size);
>>  }
>>
>> +/* accounting for migration statistics */
>> +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)
>>  {
>> @@ -230,6 +288,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
>>      if (!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;
>>      }
>>
>> @@ -244,6 +303,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;
>> @@ -263,7 +323,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;
>>  }
>> @@ -303,6 +365,7 @@ static int ram_save_block(QEMUFile *f)
>>              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;
>> @@ -318,6 +381,7 @@ static int ram_save_block(QEMUFile *f)
>>                  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, continue to the next */
>> @@ -437,6 +501,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
>>              return -1;
>>          }
>>          XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
>> +        acct_clear();
>>      }
>>
>>      QLIST_FOREACH(block, &ram_list.blocks, next) {
>> @@ -484,6 +549,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>>              break;
>>          }
>>          bytes_transferred += 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.
>>             qemu_get_clock_ns() is a bit expensive, so we only check each some
>> diff --git a/hmp.c b/hmp.c
>> index 99ad00a..0d7333b 100644
>> --- a/hmp.c
>> +++ b/hmp.c
>> @@ -168,6 +168,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 d134bf6..e11f451 100644
>> --- a/migration.c
>> +++ b/migration.c
>> @@ -137,6 +137,17 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>>              info->capabilities->value->state = s->enabled_capabilities[i];
>>              info->capabilities->next = NULL;
>>          }
>> +
>> +        /* display xbzrle cache size */
>> +        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();
>> +        }
> 
> Why do you need this in MIG_STATE_SETUP? I think having it only in
> MIG_STATE_ACTIVE is enough (and probably that's what we want).
you are right we just need the cache size (which can be set before the migration).
> 
>>          break;
>>      case MIG_STATE_ACTIVE:
>>          for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
>> @@ -161,6 +172,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>>          info->ram->total = ram_bytes_total();
>>          info->ram->total_time = qemu_get_clock_ms(rt_clock)
>>              - s->total_time;
>> +        info->ram->duplicate = dup_mig_pages_transferred();
>> +        info->ram->normal = norm_mig_pages_transferred();
> 
> Can we do this extension in a different patch?
ok
> 
>>
>>          if (blk_mig_active()) {
>>              info->has_disk = true;
>> @@ -169,6 +182,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:
>>          for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
>> @@ -183,6 +206,32 @@ MigrationInfo *qmp_query_migrate(Error **errp)
>>              info->capabilities->next = NULL;
>>          }
>>
>> +        info->has_ram = true;
>> +        info->ram = g_malloc0(sizeof(*info->ram));
>> +        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->normal = norm_mig_pages_transferred();
> 
> This hunk is probably bad copy & paste, as this code already exists.
looks like a bad merge I will remove it
> 
>> +
>> +        if (blk_mig_active()) {
>> +            info->has_disk = true;
>> +            info->disk = g_malloc0(sizeof(*info->disk));
>> +            info->disk->transferred = blk_mig_bytes_transferred();
>> +            info->disk->remaining = blk_mig_bytes_remaining();
>> +            info->disk->total = blk_mig_bytes_total();
>> +        }
> 
> Why are you doing this, bad copy & paste too?
looks like a bad merge I will remove it
> 
>> +
>> +        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();
>> +        }
>> +
>>          info->has_status = true;
>>          info->status = g_strdup("completed");
>>
>> diff --git a/migration.h b/migration.h
>> index 337e225..a9852fc 100644
>> --- a/migration.h
>> +++ b/migration.h
>> @@ -87,6 +87,15 @@ uint64_t ram_bytes_total(void);
>>
>>  extern SaveVMHandlers savevm_ram_handlers;
>>
>> +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);
>> +
>>  /**
>>   * @migrate_add_blocker - prevent migration from proceeding
>>   *
>> diff --git a/qapi-schema.json b/qapi-schema.json
>> index a0f0f95..961810b 100644
>> --- a/qapi-schema.json
>> +++ b/qapi-schema.json
>> @@ -264,11 +264,35 @@
>>  #        migration has ended, it returns the total migration
>>  #        time. (since 1.2)
>>  #
>> -# Since: 0.14.0.
>> +# @duplicate: #optional, number of duplicate pages
>> +#
>> +# @normal : #optional, number of normal pages
>> +#
>> +# Since: 0.14.0, 'duplicate' and 'normal' since 1.2
> 
> Please, put 'since' in the same line of the field, like this:
> 
>  @normal : #optional, number of normal pages (since 1.2)
ok
> 
>>  ##
>>  { 'type': 'MigrationStats',
>>    'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
>> -           'total_time': 'int' } }
>> +           'total_time': 'int', '*duplicate': 'int', '*normal': 'int' } }
>> +##
>> +# @CacheStats
> 
> This is specific to xbzrle, right? So this should be called XBZRLECacheStats,
> or something.
sure
> 
>> +#
>> +# 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: number of cache miss
>> +#
>> +# @xbzrle_overflow: number of overflows
>> +#
>> +# Since: 1.2
>> +##
>> +{ 'type': 'CacheStats',
>> +  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
>> +           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }
>>
>>  ##
>>  # @MigrationInfo
>> @@ -291,13 +315,16 @@
>>  # @capabilities: #optional a list describing all the migration capabilities
>>  #                state
>>  #
>> -# Since: 0.14.0, 'capabilities' since 1.2
>> +# @cache: #optional @MigrationStats containing detailed XBZRLE migration
>> +#         statistics
> 
> xbzrle-cache.
ok

Thanks,
Orit
> 
>> +#
>> +# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
>>  ##
>>  { 'type': 'MigrationInfo',
>>    'data': {'*status': 'str', '*ram': 'MigrationStats',
>>             '*disk': 'MigrationStats',
>> -           '*capabilities': ['MigrationCapabilityInfo']} }
>> -
>> +           '*capabilities': ['MigrationCapabilityInfo'],
>> +           '*cache': 'CacheStats'} }
>>  ##
>>  # @query-migrate
>>  #
>> diff --git a/qmp-commands.hx b/qmp-commands.hx
>> index a3d57ce..34d4675 100644
>> --- a/qmp-commands.hx
>> +++ b/qmp-commands.hx
>> @@ -2093,6 +2093,8 @@ The main json-object contains the following:
>>           - "transferred": amount transferred (json-int)
>>           - "remaining": amount remaining (json-int)
>>           - "total": total (json-int)
>> +	 - "duplicate": number of duplicated pages (json-int)
>> +	 - "normal" : number of normal pages transferred (json-int)
>>  - "disk": only present if "status" is "active" and it is a block migration,
>>    it is a json-object with the following disk information (in bytes):
>>           - "transferred": amount transferred (json-int)
>> @@ -2100,10 +2102,17 @@ The main json-object contains the following:
>>           - "total": total (json-int)
>>  - "capabilities": migration capabilities state
>>           - "xbzrle" : XBZRLE state (json-bool)
>> +- "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:
>>
>>  1. Before the first migration
>> -
>>  -> { "execute": "query-migrate" }
>>  <- { "return": {
>>          "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
>> @@ -2164,6 +2173,30 @@ Examples:
>>        }
>>     }
>>
>> +6. Migration is being performed and XBZRLE is active:
>> +
>> +-> { "execute": "query-migrate" }
>> +<- {
>> +      "return":{
>> +         "status":"active",
>> +         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
>> +         "ram":{
>> +            "total":1057024,
>> +            "remaining":1053304,
>> +            "transferred":3720,
>> +            "duplicate": 10,
>> +            "normal" : 3333
>> +         },
>> +         "cache":{
>> +            "cache-size": 1024
>> +            "xbzrle-transferred":20971520,
>> +            "xbzrle-pages":2444343,
>> +            "xbzrle-cache-miss":2244,
>> +            "xbzrle-overflow":34434
>> +         }
>> +      }
>> +   }
>> +
>>  EQMP
>>
>>      {
>

Patch

diff --git a/arch_init.c b/arch_init.c
index d972d84..ab3fb2c 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -202,6 +202,64 @@  int64_t xbzrle_cache_resize(int64_t new_size)
     return pow2floor(new_size);
 }

+/* accounting for migration statistics */
+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)
 {
@@ -230,6 +288,7 @@  static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
     if (!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;
     }

@@ -244,6 +303,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;
@@ -263,7 +323,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;
 }
@@ -303,6 +365,7 @@  static int ram_save_block(QEMUFile *f)
             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;
@@ -318,6 +381,7 @@  static int ram_save_block(QEMUFile *f)
                 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, continue to the next */
@@ -437,6 +501,7 @@  static int ram_save_setup(QEMUFile *f, void *opaque)
             return -1;
         }
         XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
+        acct_clear();
     }

     QLIST_FOREACH(block, &ram_list.blocks, next) {
@@ -484,6 +549,7 @@  static int ram_save_iterate(QEMUFile *f, void *opaque)
             break;
         }
         bytes_transferred += 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.
            qemu_get_clock_ns() is a bit expensive, so we only check each some
diff --git a/hmp.c b/hmp.c
index 99ad00a..0d7333b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -168,6 +168,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 d134bf6..e11f451 100644
--- a/migration.c
+++ b/migration.c
@@ -137,6 +137,17 @@  MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->value->state = s->enabled_capabilities[i];
             info->capabilities->next = NULL;
         }
+
+        /* display xbzrle cache size */
+        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_ACTIVE:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
@@ -161,6 +172,8 @@  MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->total = ram_bytes_total();
         info->ram->total_time = qemu_get_clock_ms(rt_clock)
             - s->total_time;
+        info->ram->duplicate = dup_mig_pages_transferred();
+        info->ram->normal = norm_mig_pages_transferred();

         if (blk_mig_active()) {
             info->has_disk = true;
@@ -169,6 +182,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:
         for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
@@ -183,6 +206,32 @@  MigrationInfo *qmp_query_migrate(Error **errp)
             info->capabilities->next = NULL;
         }

+        info->has_ram = true;
+        info->ram = g_malloc0(sizeof(*info->ram));
+        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->normal = norm_mig_pages_transferred();
+
+        if (blk_mig_active()) {
+            info->has_disk = true;
+            info->disk = g_malloc0(sizeof(*info->disk));
+            info->disk->transferred = blk_mig_bytes_transferred();
+            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();
+        }
+
         info->has_status = true;
         info->status = g_strdup("completed");

diff --git a/migration.h b/migration.h
index 337e225..a9852fc 100644
--- a/migration.h
+++ b/migration.h
@@ -87,6 +87,15 @@  uint64_t ram_bytes_total(void);

 extern SaveVMHandlers savevm_ram_handlers;

+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);
+
 /**
  * @migrate_add_blocker - prevent migration from proceeding
  *
diff --git a/qapi-schema.json b/qapi-schema.json
index a0f0f95..961810b 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -264,11 +264,35 @@ 
 #        migration has ended, it returns the total migration
 #        time. (since 1.2)
 #
-# Since: 0.14.0.
+# @duplicate: #optional, number of duplicate pages
+#
+# @normal : #optional, number of normal pages
+#
+# Since: 0.14.0, 'duplicate' and 'normal' since 1.2
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
-           'total_time': 'int' } }
+           'total_time': 'int', '*duplicate': 'int', '*normal': '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: number of cache miss
+#
+# @xbzrle_overflow: number of overflows
+#
+# Since: 1.2
+##
+{ 'type': 'CacheStats',
+  'data': {'cache-size': 'int', 'xbzrle-bytes': 'int', 'xbzrle-pages': 'int',
+           'xbzrle-cache-miss': 'int', 'xbzrle-overflow': 'int' } }

 ##
 # @MigrationInfo
@@ -291,13 +315,16 @@ 
 # @capabilities: #optional a list describing all the migration capabilities
 #                state
 #
-# Since: 0.14.0, 'capabilities' since 1.2
+# @cache: #optional @MigrationStats containing detailed XBZRLE migration
+#         statistics
+#
+# Since: 0.14.0, 'capabilities' and 'cache' since 1.2
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
-           '*capabilities': ['MigrationCapabilityInfo']} }
-
+           '*capabilities': ['MigrationCapabilityInfo'],
+           '*cache': 'CacheStats'} }
 ##
 # @query-migrate
 #
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a3d57ce..34d4675 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2093,6 +2093,8 @@  The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
+	 - "duplicate": number of duplicated pages (json-int)
+	 - "normal" : number of normal pages transferred (json-int)
 - "disk": only present if "status" is "active" and it is a block migration,
   it is a json-object with the following disk information (in bytes):
          - "transferred": amount transferred (json-int)
@@ -2100,10 +2102,17 @@  The main json-object contains the following:
          - "total": total (json-int)
 - "capabilities": migration capabilities state
          - "xbzrle" : XBZRLE state (json-bool)
+- "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:

 1. Before the first migration
-
 -> { "execute": "query-migrate" }
 <- { "return": {
         "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
@@ -2164,6 +2173,30 @@  Examples:
       }
    }

+6. Migration is being performed and XBZRLE is active:
+
+-> { "execute": "query-migrate" }
+<- {
+      "return":{
+         "status":"active",
+         "capabilities" : [ { "capability": "xbzrle", "state" : true } ],
+         "ram":{
+            "total":1057024,
+            "remaining":1053304,
+            "transferred":3720,
+            "duplicate": 10,
+            "normal" : 3333
+         },
+         "cache":{
+            "cache-size": 1024
+            "xbzrle-transferred":20971520,
+            "xbzrle-pages":2444343,
+            "xbzrle-cache-miss":2244,
+            "xbzrle-overflow":34434
+         }
+      }
+   }
+
 EQMP

     {