From 3f4914e03ceb9c5c110888e15f52b668e435d9cc Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Thu, 15 Nov 2018 15:25:46 +0100 Subject: [PATCH] qemu: Add support for postcopy-requests migration statistics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QEMU can report how many times during post-copy migration the domain running on the destination host tried to access a page which has not been migrated yet. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko --- include/libvirt/libvirt-domain.h | 10 ++++++++++ src/qemu/qemu_domain.c | 5 ++++- src/qemu/qemu_migration_cookie.c | 5 +++++ src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 2 ++ tools/virsh-domain.c | 8 ++++++++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 6a7494198f..6125d45008 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3422,6 +3422,16 @@ typedef enum { */ # define VIR_DOMAIN_JOB_MEMORY_ITERATION "memory_iteration" +/** + * VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS: + * + * virDomainGetJobStats field: number page requests received from the + * destination host during post-copy migration, as VIR_TYPED_PARAM_ULLONG. + * This counter is incremented whenever the migrated domain tries to access + * a memory page which has not been transferred from the source host yet. + */ +# define VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS "memory_postcopy_requests" + /** * VIR_DOMAIN_JOB_DISK_TOTAL: * diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 05ea128525..6f10235b43 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -607,7 +607,10 @@ qemuDomainMigrationJobInfoToParams(qemuDomainJobInfoPtr jobInfo, stats->ram_dirty_rate) < 0 || virTypedParamsAddULLong(&par, &npar, &maxpar, VIR_DOMAIN_JOB_MEMORY_ITERATION, - stats->ram_iteration) < 0) + stats->ram_iteration) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS, + stats->ram_postcopy_reqs) < 0) goto error; if (stats->ram_page_size > 0 && diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index 295e28ae30..d62352cb6e 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -703,6 +703,9 @@ qemuMigrationCookieStatisticsXMLFormat(virBufferPtr buf, virBufferAsprintf(buf, "<%1$s>%2$llu\n", VIR_DOMAIN_JOB_MEMORY_ITERATION, stats->ram_iteration); + virBufferAsprintf(buf, "<%1$s>%2$llu\n", + VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS, + stats->ram_postcopy_reqs); virBufferAsprintf(buf, "<%1$s>%2$llu\n", VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE, @@ -1102,6 +1105,8 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt) ctxt, &stats->ram_dirty_rate); virXPathULongLong("string(./" VIR_DOMAIN_JOB_MEMORY_ITERATION "[1])", ctxt, &stats->ram_iteration); + virXPathULongLong("string(./" VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS "[1])", + ctxt, &stats->ram_postcopy_reqs); virXPathULongLong("string(./" VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE "[1])", ctxt, &stats->ram_page_size); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index fef537c90e..824c3e6845 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -703,6 +703,7 @@ struct _qemuMonitorMigrationStats { unsigned long long ram_dirty_rate; unsigned long long ram_page_size; unsigned long long ram_iteration; + unsigned long long ram_postcopy_reqs; unsigned long long disk_transferred; unsigned long long disk_remaining; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1c0245534c..e148cae8f0 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3294,6 +3294,8 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply, &stats->ram_page_size)); ignore_value(virJSONValueObjectGetNumberUlong(ram, "dirty-sync-count", &stats->ram_iteration)); + ignore_value(virJSONValueObjectGetNumberUlong(ram, "postcopy-requests", + &stats->ram_postcopy_reqs)); disk = virJSONValueObjectGetObject(ret, "disk"); if (disk) { diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4ee6ddf956..4d9f06586a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6233,6 +6233,14 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) } else if (rc) { vshPrint(ctl, "%-17s %-12llu\n", _("Iteration:"), value); } + + if ((rc = virTypedParamsGetULLong(params, nparams, + VIR_DOMAIN_JOB_MEMORY_POSTCOPY_REQS, + &value)) < 0) { + goto save_error; + } else if (rc) { + vshPrint(ctl, "%-17s %-12llu\n", _("Postcopy requests:"), value); + } } if (info.fileTotal || info.fileRemaining || info.fileProcessed) {