Re: [libvirt] [PATCH v3 5/6] qemu_driver: BaselineHypervisorCPU support for S390

2018-10-03 Thread Jiri Denemark
On Thu, Sep 27, 2018 at 16:26:44 -0500, Chris Venteicher wrote:
> Libvirt can compute baseline hypervisor cpu from list of S390 cpu models
> by using QEMU QMP messages to compute baseline within QEMU.
> 
> QEMU only baselines one pair of CPU models per query so a sequence of
> multiple QMP queries are needed if more than two CPU models are
> baselined.
> 
> Full expansion of baseline S390 model supported using QEMU QMP messages to
> compute expansion within QEMU.
> 
> Introduces qemuMonitorCPUModelInfoRemovePropByBoolValue to remove props
> by value as required to convert between cpu model property lists that
> indicate if property is or isn't include in model with true / false
> value and the form of cpu model property lists that only enumerate
> properties that are actually included in the model.
> 
> Introduces functions for virCPUDef / qemuMonitorCPUModelInfo conversion.

Again, several logical changes squashed in a single hard to follow
patch.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 5/6] qemu_driver: BaselineHypervisorCPU support for S390

2018-09-27 Thread Chris Venteicher
Libvirt can compute baseline hypervisor cpu from list of S390 cpu models
by using QEMU QMP messages to compute baseline within QEMU.

QEMU only baselines one pair of CPU models per query so a sequence of
multiple QMP queries are needed if more than two CPU models are
baselined.

Full expansion of baseline S390 model supported using QEMU QMP messages to
compute expansion within QEMU.

Introduces qemuMonitorCPUModelInfoRemovePropByBoolValue to remove props
by value as required to convert between cpu model property lists that
indicate if property is or isn't include in model with true / false
value and the form of cpu model property lists that only enumerate
properties that are actually included in the model.

Introduces functions for virCPUDef / qemuMonitorCPUModelInfo conversion.

Signed-off-by: Chris Venteicher 
---
 src/qemu/qemu_capabilities.c | 128 +--
 src/qemu/qemu_capabilities.h |   4 +
 src/qemu/qemu_driver.c   | 143 +--
 src/qemu/qemu_monitor.c  |  41 ++
 src/qemu/qemu_monitor.h  |  10 +++
 src/qemu/qemu_monitor_json.c |  60 +++
 src/qemu/qemu_monitor_json.h |   7 ++
 7 files changed, 365 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5b1e4f1bbd..c5bf04993b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2785,7 +2785,8 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
 virCPUDefPtr cpu,
 bool migratable)
 {
-size_t i;
+virCPUDefPtr tmp = NULL;
+int ret = -1;
 
 if (!modelInfo) {
 if (type == VIR_DOMAIN_VIRT_KVM) {
@@ -2798,32 +2799,18 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
 return 2;
 }
 
-if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
-VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
-return -1;
-
-cpu->nfeatures_max = modelInfo->nprops;
-cpu->nfeatures = 0;
-
-for (i = 0; i < modelInfo->nprops; i++) {
-virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
-qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+if (!(tmp = virQEMUCapsCPUModelInfoToCPUDef(migratable, modelInfo)))
+goto cleanup;
 
-if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
-continue;
+/* Free original then copy over model, vendor, vendor_id and features */
+virCPUDefStealModel(cpu, tmp, true);
 
-if (VIR_STRDUP(feature->name, prop->name) < 0)
-return -1;
+ret = 0;
 
-if (!prop->value.boolean ||
-(migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
-feature->policy = VIR_CPU_FEATURE_DISABLE;
-else
-feature->policy = VIR_CPU_FEATURE_REQUIRE;
-cpu->nfeatures++;
-}
+ cleanup:
+virCPUDefFree(tmp);
 
-return 0;
+return ret;
 }
 
 
@@ -3620,6 +3607,101 @@ virQEMUCapsLoadCache(virArch hostArch,
 return ret;
 }
 
+/* virCPUDef model=> qemuMonitorCPUModelInfo name
+ * virCPUDef features => qemuMonitorCPUModelInfo boolean properties */
+qemuMonitorCPUModelInfoPtr
+virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef)
+{
+size_t i;
+qemuMonitorCPUModelInfoPtr cpuModel = NULL;
+qemuMonitorCPUModelInfoPtr ret = NULL;
+
+if (!cpuDef || (VIR_ALLOC(cpuModel) < 0))
+goto cleanup;
+
+VIR_DEBUG("cpuDef->model = %s", NULLSTR(cpuDef->model));
+
+if (VIR_STRDUP(cpuModel->name, cpuDef->model) < 0 ||
+VIR_ALLOC_N(cpuModel->props, cpuDef->nfeatures) < 0)
+goto cleanup;
+
+cpuModel->nprops = 0;
+
+for (i = 0; i < cpuDef->nfeatures; i++) {
+qemuMonitorCPUPropertyPtr prop = &(cpuModel->props[cpuModel->nprops]);
+virCPUFeatureDefPtr feature = &(cpuDef->features[i]);
+
+if (!(feature->name) ||
+VIR_STRDUP(prop->name, feature->name) < 0)
+goto cleanup;
+
+prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
+
+prop->value.boolean = feature->policy == -1 || /* policy undefined */
+  feature->policy == VIR_CPU_FEATURE_FORCE ||
+  feature->policy == VIR_CPU_FEATURE_REQUIRE;
+
+ cpuModel->nprops++;
+}
+
+VIR_STEAL_PTR(ret, cpuModel);
+
+ cleanup:
+qemuMonitorCPUModelInfoFree(cpuModel);
+return ret;
+}
+
+
+/* qemuMonitorCPUModelInfo name   => virCPUDef model
+ * qemuMonitorCPUModelInfo boolean properties => virCPUDef features
+ *
+ * migratable true: mark non-migratable features as disabled
+ *false: allow all features as required
+ */
+virCPUDefPtr
+virQEMUCapsCPUModelInfoToCPUDef(bool migratable, qemuMonitorCPUModelInfoPtr 
model)
+{
+virCPUDefPtr cpu = NULL;
+virCPUDefPtr ret = NULL;
+size_t i;
+
+if (!model || VIR_ALLOC(cpu) < 0)
+goto cleanup;
+
+VIR_DEBUG("model->name= %s", NULLSTR(model->name)