]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: monitor: Extract halted state to a bitmap indexed by cpu id
authorPeter Krempa <pkrempa@redhat.com>
Mon, 21 Nov 2016 13:54:35 +0000 (14:54 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 21 Nov 2016 16:19:48 +0000 (17:19 +0100)
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
src/qemu/qemu_monitor.h

index 0bfc1a852bb7cafb53ed2d660871737c3775103b..3ff31e49f73d1fda6146b5f2b90550ea05fe9632 100644 (file)
@@ -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,
index 49d43bce785384e6fc380e258cbc9c2c7d1f388e..100730bae45db05033f01b21f71072cf3c86a10b 100644 (file)
@@ -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);