From: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
Extend qemuDomainGetVcpus for getting dirty page rate upper
limit info so 'virsh vcpuinfo' api can display it.
Signed-off-by: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
---
include/libvirt/libvirt-domain.h | 2 ++
src/qemu/qemu_driver.c | 55 ++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index df7deffaa9..4c63d0be7c 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2395,6 +2395,8 @@ struct _virVcpuInfo {
int state; /* value from virVcpuState */
unsigned long long cpuTime; /* CPU time used, in nanoseconds */
int cpu; /* real CPU number, or one of the values from
virVcpuHostCpuState */
+ unsigned long long limit; /* virtual cpu dirty page rate upper limit in MB/s */
+ unsigned long long current; /* current virtual cpu dirty page rate in MB/s */
};
/**
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 61b992fc51..f7ff3b7098 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4599,6 +4599,57 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
return ret;
}
+static int
+qemuDomainGetVcpuDirtyLimit(virDomainObj *vm,
+ virVcpuInfoPtr info,
+ int maxinfo)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ qemuMonitorVcpuDirtyLimitInfo dirtylimit_info;
+ size_t cpuinfo_idx = 0;
+ size_t i;
+ int ret = -1;
+
+ if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VCPU_DIRTY_LIMIT))
+ return 0;
+
+ if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
+ goto endjob;
+
+ if (virDomainObjCheckActive(vm) < 0)
+ goto endjob;
+
+ qemuDomainObjEnterMonitor(vm);
+ if (qemuMonitorQueryVcpuDirtyLimit(priv->mon, &dirtylimit_info) < 0) {
+ qemuDomainObjExitMonitor(vm);
+ goto endjob;
+ }
+ qemuDomainObjExitMonitor(vm);
+
+ while (cpuinfo_idx < maxinfo) {
+ virVcpuInfoPtr vcpuinfo = info + cpuinfo_idx;
+ for (i = 0; i < dirtylimit_info.nvcpus &&
+ i < virDomainDefGetVcpusMax(vm->def); i++) {
+ /* skip the offline virtual CPU */
+ virDomainVcpuDef *vcpu = virDomainDefGetVcpu(vm->def, i);
+ if (!vcpu->online)
+ continue;
+
+ /* match the index of virtual CPU */
+ if (vcpuinfo->number == dirtylimit_info.limits[i].idx) {
+ vcpuinfo->current = dirtylimit_info.limits[i].current;
+ vcpuinfo->limit = dirtylimit_info.limits[i].limit;
+ }
+ }
+ cpuinfo_idx++;
+ }
+ ret = 0;
+
+ endjob:
+ virDomainObjEndJob(vm);
+ return ret;
+}
+
static int
qemuDomainGetVcpus(virDomainPtr dom,
virVcpuInfoPtr info,
@@ -4623,6 +4674,10 @@ qemuDomainGetVcpus(virDomainPtr dom,
ret = qemuDomainHelperGetVcpus(vm, info, NULL, NULL, maxinfo, cpumaps, maplen);
+ /* append dirty limit data to vcpu info */
+ if (qemuDomainGetVcpuDirtyLimit(vm, info, maxinfo) < 0)
+ goto cleanup;
+
cleanup:
virDomainObjEndAPI(&vm);
return ret;
--
2.38.5