We don't need to call qemuMonitorGetCPUInfo which is very inefficient to get data required to update the vcpu 'halted' state.
Add a monitor helper that will retrieve the halted state and return it in a bitmap so that it can be indexed easily. --- src/qemu/qemu_monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.h | 1 + 2 files changed, 41 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0bfc1a8..3ff31e4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1952,6 +1952,46 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon, } +/** + * qemuMonitorGetCpuHalted: + * + * Returns a bitmap of vcpu id's that are halted. The id's correspond to the + * 'CPU' field as reported by query-cpus'. + */ +virBitmapPtr +qemuMonitorGetCpuHalted(qemuMonitorPtr mon, + size_t maxvcpus) +{ + struct qemuMonitorQueryCpusEntry *cpuentries = NULL; + size_t ncpuentries = 0; + size_t i; + int rc; + virBitmapPtr ret = NULL; + + QEMU_CHECK_MONITOR_NULL(mon); + + if (mon->json) + rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries); + else + rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); + + if (rc < 0) + goto cleanup; + + if (!(ret = virBitmapNew(maxvcpus))) + goto cleanup; + + for (i = 0; i < ncpuentries; i++) { + if (cpuentries[i].halted) + ignore_value(virBitmapSetBit(ret, cpuentries[i].qemu_id)); + } + + cleanup: + qemuMonitorQueryCpusFree(cpuentries, ncpuentries); + return ret; +} + + int qemuMonitorSetLink(qemuMonitorPtr mon, const char *name, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 49d43bc..100730b 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -456,6 +456,7 @@ int qemuMonitorGetCPUInfo(qemuMonitorPtr mon, qemuMonitorCPUInfoPtr *vcpus, size_t maxvcpus, bool hotplug); +virBitmapPtr qemuMonitorGetCpuHalted(qemuMonitorPtr mon, size_t maxvcpus); int qemuMonitorGetVirtType(qemuMonitorPtr mon, virDomainVirtType *virtType); -- 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list