Introduce monitor functions to use QEMU to compute baseline cpu
from an input of two cpu models.
Signed-off-by: Chris Venteicher <cventeic(a)redhat.com>
---
src/qemu/qemu_monitor.c | 12 ++++++++
src/qemu/qemu_monitor.h | 6 ++++
src/qemu/qemu_monitor_json.c | 60 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 6 ++++
4 files changed, 84 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 2071c6e846..edbaee1a53 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4495,3 +4495,15 @@ qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
virHashFree(info);
return ret;
}
+
+
+int
+qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+ qemuMonitorCPUModelInfoPtr model_a,
+ qemuMonitorCPUModelInfoPtr model_b,
+ qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model_baseline);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index d3efd37099..d46e9378ea 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1196,4 +1196,10 @@ struct _qemuMonitorPRManagerInfo {
int qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
virHashTablePtr *retinfo);
+int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+ qemuMonitorCPUModelInfoPtr model_a,
+ qemuMonitorCPUModelInfoPtr model_b,
+ qemuMonitorCPUModelInfoPtr *model_baseline)
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+
#endif /* QEMU_MONITOR_H */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2eabfdac70..84da721f8d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8464,3 +8464,63 @@ qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
return ret;
}
+
+
+int
+qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+ qemuMonitorCPUModelInfoPtr model_a,
+ qemuMonitorCPUModelInfoPtr model_b,
+ qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+ int ret = -1;
+ virJSONValuePtr cmd = NULL;
+ virJSONValuePtr reply = NULL;
+ virJSONValuePtr data = NULL;
+ virJSONValuePtr modela = NULL;
+ virJSONValuePtr modelb = NULL;
+ virJSONValuePtr cpu_model = NULL;
+
+ *model_baseline = NULL;
+
+ if (!(modela = qemuMonitorJSONBuildCPUModelInfoToJSON(model_a)) ||
+ !(modelb = qemuMonitorJSONBuildCPUModelInfoToJSON(model_b)))
+ goto cleanup;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
+ "a:modela", &modela,
+ "a:modelb", &modelb,
+ NULL)))
+ goto cleanup;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("QEMU doesn't support baseline or recognize model %s or
%s"),
+ model_a->name,
+ model_b->name);
+ goto cleanup;
+ }
+
+ data = virJSONValueObjectGetObject(reply, "return");
+
+ if (!(cpu_model = virJSONValueObjectGetObject(data, "model"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-cpu-model-baseline reply data was missing
'model'"));
+ goto cleanup;
+ }
+
+ if (!(*model_baseline = qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_model)))
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ virJSONValueFree(modela);
+ virJSONValueFree(modelb);
+
+ return ret;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 2d5679094e..117a4a6cd0 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -577,4 +577,10 @@ int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
virHashTablePtr info)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+ qemuMonitorCPUModelInfoPtr model_a,
+ qemuMonitorCPUModelInfoPtr model_b,
+ qemuMonitorCPUModelInfoPtr *model_baseline)
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+
#endif /* QEMU_MONITOR_JSON_H */
--
2.17.1