From: Peter Krempa Date: Mon, 21 Nov 2016 13:54:35 +0000 (+0100) Subject: qemu: monitor: Extract halted state to a bitmap indexed by cpu id X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5d885f4ff35bb451e3864cd6d1b96cb977d774a0;p=libvirt.git qemu: monitor: Extract halted state to a bitmap indexed by cpu id 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. --- diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0bfc1a852b..3ff31e49f7 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 49d43bce78..100730bae4 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);